KiCad PCB EDA Suite
Loading...
Searching...
No Matches
wx_grid.cpp
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 3
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#include <wx/colour.h>
21#include <wx/tokenzr.h>
22#include <wx/dc.h>
23#include <wx/settings.h>
24#include <wx/event.h> // Needed for textentry.h on MSW
25#include <wx/textentry.h>
26
29#include <widgets/wx_grid.h>
30#include <widgets/ui_common.h>
31#include <algorithm>
32#include <vector>
33#include <core/kicad_algo.h>
34#include <gal/color4d.h>
35#include <kiplatform/ui.h>
36#include <utility>
37
38#include <pgm_base.h>
40#include <dialog_shim.h>
41
42
43wxGridCellAttr* WX_GRID_TABLE_BASE::enhanceAttr( wxGridCellAttr* aInputAttr, int aRow, int aCol,
44 wxGridCellAttr::wxAttrKind aKind )
45{
46 wxGridCellAttr* attr = aInputAttr;
47
48 if( wxGridCellAttrProvider* provider = GetAttrProvider() )
49 {
50 wxGridCellAttr* providerAttr = provider->GetAttr( aRow, aCol, aKind );
51
52 if( providerAttr )
53 {
54 attr = new wxGridCellAttr;
55 attr->SetKind( wxGridCellAttr::Merged );
56
57 if( aInputAttr )
58 {
59 attr->MergeWith( aInputAttr );
60 aInputAttr->DecRef();
61 }
62
63 attr->MergeWith( providerAttr );
64 providerAttr->DecRef();
65 }
66 }
67
68 return attr;
69}
70
71
72#define MIN_GRIDCELL_MARGIN FromDIP( 2 )
73
74
75void WX_GRID::CellEditorSetMargins( wxTextEntryBase* aEntry )
76{
77 // This is consistent with wxGridCellTextEditor. But works differently across platforms of course.
78 aEntry->SetMargins( 0, 0 );
79}
80
81
83{
84#if defined( __WXMSW__ ) || defined( __WXGTK__ )
85 aRect.Deflate( 2 );
86#endif
87}
88
89
90int WX_GRID::CapHeightToVisibleRows( int aMinHeight, int aHeaderHeight,
91 const std::vector<int>& aRowHeights, int aMaxRows )
92{
93 if( aMaxRows < 0 )
94 return aMinHeight;
95
96 int rowsHeight = aHeaderHeight;
97 int count = std::min( aMaxRows, (int) aRowHeights.size() );
98
99 for( int row = 0; row < count; ++row )
100 rowsHeight += aRowHeights[row];
101
102 return std::min( aMinHeight, rowsHeight );
103}
105
106void WX_GRID::SetMinVisibleRows( wxWindow* aDialog, int aMinRows )
107{
108 aDialog->Layout();
109
110 std::vector<int> rowHeights;
111 rowHeights.reserve( GetNumberRows() );
112
113 int allRowsHeight = GetColLabelSize();
114
115 for( int row = 0; row < GetNumberRows(); ++row )
116 {
117 rowHeights.push_back( GetRowSize( row ) );
118 allRowsHeight += rowHeights.back();
119 }
120
121 // Floor the grid at a few rows, then re-derive the dialog's minimum so it can be shrunk down to
122 // that floor with the grid scrolling past it.
123 SetMinSize( wxSize( GetMinSize().x, CapHeightToVisibleRows( allRowsHeight, GetColLabelSize(),
124 rowHeights, aMinRows ) ) );
125
126 aDialog->SetMinSize( wxDefaultSize );
127 aDialog->InvalidateBestSize();
128 aDialog->SetMinSize( aDialog->GetBestSize() );
129
130 // Open tall enough to show every row; Show() clamps the result to the monitor work area.
131 int grow = allRowsHeight - GetSize().y;
132
133 if( grow > 0 )
134 aDialog->SetSize( aDialog->GetSize().x, aDialog->GetSize().y + grow );
135}
136
137
139{
140 KIGFX::COLOR4D bg = wxSystemSettings::GetColour( wxSYS_COLOUR_FRAMEBK );
141 KIGFX::COLOR4D fg = wxSystemSettings::GetColour( wxSYS_COLOUR_ACTIVEBORDER );
142 KIGFX::COLOR4D border = fg.Mix( bg, 0.50 );
143 return border.ToColour();
144}
145
146
147class WX_GRID_CORNER_HEADER_RENDERER : public wxGridCornerHeaderRendererDefault
148{
149public:
150 void DrawBorder( const wxGrid& grid, wxDC& dc, wxRect& rect ) const override
151 {
152 wxDCBrushChanger SetBrush( dc, *wxTRANSPARENT_BRUSH );
153 wxDCPenChanger SetPen( dc, wxPen( getBorderColour(), 1 ) );
154
155 rect.SetTop( rect.GetTop() + 1 );
156 rect.SetLeft( rect.GetLeft() + 1 );
157 rect.SetBottom( rect.GetBottom() - 1 );
158 rect.SetRight( rect.GetRight() - 1 );
159 dc.DrawRectangle( rect );
160 }
161};
162
163
164class WX_GRID_COLUMN_HEADER_RENDERER : public wxGridColumnHeaderRendererDefault
165{
166public:
167 void DrawBorder( const wxGrid& grid, wxDC& dc, wxRect& rect ) const override
168 {
169 wxDCBrushChanger SetBrush( dc, *wxTRANSPARENT_BRUSH );
170 wxDCPenChanger SetPen( dc, wxPen( getBorderColour(), 1 ) );
171
172 rect.SetTop( rect.GetTop() + 1 );
173 rect.SetLeft( rect.GetLeft() );
174 rect.SetBottom( rect.GetBottom() - 1 );
175 rect.SetRight( rect.GetRight() - 1 );
176 dc.DrawRectangle( rect );
177 }
178};
179
180
181class WX_GRID_ROW_HEADER_RENDERER : public wxGridRowHeaderRendererDefault
182{
183public:
184 void DrawBorder( const wxGrid& grid, wxDC& dc, wxRect& rect ) const override
185 {
186 wxDCBrushChanger SetBrush( dc, *wxTRANSPARENT_BRUSH );
187 wxDCPenChanger SetPen( dc, wxPen( getBorderColour(), 1 ) );
188
189 rect.SetTop( rect.GetTop() + 1 );
190 rect.SetLeft( rect.GetLeft() + 1 );
191 rect.SetBottom( rect.GetBottom() - 1 );
192 rect.SetRight( rect.GetRight() );
193 dc.DrawRectangle( rect );
194 }
195};
196
197
202class WX_GRID_ALT_ROW_COLOR_PROVIDER : public wxGridCellAttrProvider
203{
204public:
205 WX_GRID_ALT_ROW_COLOR_PROVIDER( const wxColor& aBaseColor ) :
206 wxGridCellAttrProvider(),
207 m_attrEven( new wxGridCellAttr() )
208 {
209 UpdateColors( aBaseColor );
210 }
211
212 void UpdateColors( const wxColor& aBaseColor )
213 {
214 // Choose the default color, taking into account if the dark mode theme is enabled
215 wxColor rowColor = aBaseColor.ChangeLightness( KIPLATFORM::UI::IsDarkTheme() ? 105 : 95 );
216
217 m_attrEven->SetBackgroundColour( rowColor );
218 }
219
220 wxGridCellAttr* GetAttr( int row, int col, wxGridCellAttr::wxAttrKind kind ) const override
221 {
222 wxGridCellAttrPtr cellAttr( wxGridCellAttrProvider::GetAttr( row, col, kind ) );
223
224 // Just pass through the cell attribute on odd rows (start normal to allow for the
225 // header row)
226 if( !( row % 2 ) )
227 return cellAttr.release();
228
229 if( !cellAttr )
230 {
231 cellAttr = m_attrEven;
232 }
233 else
234 {
235 if( !cellAttr->HasBackgroundColour() )
236 {
237 cellAttr = cellAttr->Clone();
238 cellAttr->SetBackgroundColour( m_attrEven->GetBackgroundColour() );
239 }
240 }
241
242 return cellAttr.release();
243 }
244
245private:
246 wxGridCellAttrPtr m_attrEven;
247};
248
249
250WX_GRID::WX_GRID( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size, long style,
251 const wxString& name ) :
252 wxGrid( parent, id, pos, size, style, name ),
253 m_weOwnTable( false )
254{
255 // Grids with comboboxes need a bit of extra height; other grids look better if they're consistent.
256 SetDefaultRowSize( GetDefaultRowSize() + FromDIP( 4 ) );
257
258 SetDefaultCellOverflow( false );
259
260 // Make sure the GUI font scales properly
261 SetDefaultCellFont( KIUI::GetControlFont( this ) );
263
265
266 Connect( wxEVT_DPI_CHANGED, wxDPIChangedEventHandler( WX_GRID::onDPIChanged ), nullptr, this );
267 Connect( wxEVT_GRID_EDITOR_SHOWN, wxGridEventHandler( WX_GRID::onCellEditorShown ), nullptr, this );
268 Connect( wxEVT_GRID_EDITOR_HIDDEN, wxGridEventHandler( WX_GRID::onCellEditorHidden ), nullptr, this );
269}
270
271
273{
274 if( m_weOwnTable )
275 DestroyTable( GetTable() );
276
277 delete m_rowIconProvider;
278
279 Disconnect( wxEVT_GRID_EDITOR_SHOWN, wxGridEventHandler( WX_GRID::onCellEditorShown ), nullptr, this );
280 Disconnect( wxEVT_GRID_EDITOR_HIDDEN, wxGridEventHandler( WX_GRID::onCellEditorHidden ), nullptr, this );
281 Disconnect( wxEVT_DPI_CHANGED, wxDPIChangedEventHandler( WX_GRID::onDPIChanged ), nullptr, this );
282}
283
284
285void WX_GRID::onDPIChanged(wxDPIChangedEvent& aEvt)
286{
287 // Workaround for wxWidgets bug where hidden column widths (stored as negative values)
288 // are not scaled during DPI changes, corrupting the internal m_colRights array.
289 // https://github.com/wxWidgets/wxWidgets/issues/26079
290 // Fix is to re-hide all hidden columns after the DPI change completes, which forces
291 // wxGrid to recalculate the column geometry correctly.
292
293 std::vector<int> hiddenCols;
294
295 for( int col = 0; col < GetNumberCols(); ++col )
296 {
297 if( !IsColShown( col ) )
298 hiddenCols.push_back( col );
299 }
300
301 aEvt.Skip();
302
303 if( !hiddenCols.empty() )
304 {
305 CallAfter(
306 [this, hiddenCols]()
307 {
308 for( int col : hiddenCols )
309 {
310 ShowCol( col );
311 HideCol( col );
312 }
313
314 ForceRefresh();
315 } );
316 }
317
318 CallAfter(
319 [this]()
320 {
321 wxGrid::SetColLabelSize( wxGRID_AUTOSIZE );
322 } );
323}
324
325
326void WX_GRID::SetColLabelSize( int aHeight )
327{
328 if( aHeight == 0 || aHeight == wxGRID_AUTOSIZE )
329 {
330 wxGrid::SetColLabelSize( aHeight );
331 return;
332 }
333
334 // Correct wxFormBuilder height for large fonts
335 int minHeight = GetCharHeight() + 2 * MIN_GRIDCELL_MARGIN;
336
337 wxGrid::SetColLabelSize( std::max( aHeight, minHeight ) );
338}
339
340
341void WX_GRID::SetLabelFont( const wxFont& aFont )
342{
343 wxGrid::SetLabelFont( KIUI::GetControlFont( this ) );
344}
345
346
347void WX_GRID::SetTable( wxGridTableBase* aTable, bool aTakeOwnership )
348{
349 // wxGrid::SetTable() messes up the column widths from wxFormBuilder so we have to save
350 // and restore them.
351 int numberCols = GetNumberCols();
352 int* formBuilderColWidths = new int[numberCols];
353
354 for( int i = 0; i < numberCols; ++i )
355 formBuilderColWidths[ i ] = GetColSize( i );
356
357 wxGrid::SetTable( aTable );
358
359 // wxGrid::SetTable() may change the number of columns, so prevent out-of-bounds access
360 // to formBuilderColWidths
361 numberCols = std::min( numberCols, GetNumberCols() );
362
363 for( int i = 0; i < numberCols; ++i )
364 {
365 // correct wxFormBuilder width for large fonts and/or long translations
366 int headingWidth = GetTextExtent( GetColLabelValue( i ) ).x + 2 * MIN_GRIDCELL_MARGIN;
367
368 SetColSize( i, std::max( formBuilderColWidths[ i ], headingWidth ) );
369 }
370
371 delete[] formBuilderColWidths;
372
373 EnableAlternateRowColors( Pgm().GetCommonSettings() && Pgm().GetCommonSettings()->m_Appearance.grid_striping );
374
375 Connect( wxEVT_GRID_COL_MOVE, wxGridEventHandler( WX_GRID::onGridColMove ), nullptr, this );
376 Connect( wxEVT_GRID_SELECT_CELL, wxGridEventHandler( WX_GRID::onGridCellSelect ), nullptr, this );
377
378#ifdef __WXMSW__
379 Connect( wxEVT_IDLE, wxIdleEventHandler( WX_GRID::onIdleRefreshHighlight ), nullptr, this );
380#endif
381
382 m_weOwnTable = aTakeOwnership;
383}
384
385
387{
388 wxGridTableBase* table = wxGrid::GetTable();
389
390 wxCHECK_MSG( table, /* void */, "Tried to enable alternate row colors without a table assigned to the grid" );
391
392 if( aEnable )
393 {
394 wxColor color = wxGrid::GetDefaultCellBackgroundColour();
395 table->SetAttrProvider( new WX_GRID_ALT_ROW_COLOR_PROVIDER( color ) );
396 }
397 else
398 {
399 table->SetAttrProvider( nullptr );
400 }
401}
402
403
404void WX_GRID::onGridCellSelect( wxGridEvent& aEvent )
405{
406 // Highlight the selected cell.
407 // Calling SelectBlock() allows a visual effect when cells are selected by tab or arrow keys.
408 // Otherwise, one cannot really know what actual cell is selected.
409 int row = aEvent.GetRow();
410 int col = aEvent.GetCol();
411
412 if( row >= 0 && row < GetNumberRows() && col >= 0 && col < GetNumberCols() )
413 {
414 if( GetSelectionMode() == wxGrid::wxGridSelectCells )
415 {
416 SelectBlock( row, col, row, col, false );
417 }
418 else if( GetSelectionMode() == wxGrid::wxGridSelectRows
419 || GetSelectionMode() == wxGrid::wxGridSelectRowsOrColumns )
420 {
421 SelectBlock( row, 0, row, GetNumberCols() - 1, false );
422 }
423 else if( GetSelectionMode() == wxGrid::wxGridSelectColumns )
424 {
425 SelectBlock( 0, col, GetNumberRows() - 1, col, false );
426 }
427
429 ForceRefresh();
430 }
431}
432
433
434#ifdef __WXMSW__
435void WX_GRID::onIdleRefreshHighlight( wxIdleEvent& aEvent )
436{
437 aEvent.Skip();
438
439 // On Windows with wxWidgets 3.3+, the selection highlight is drawn with stale geometry the
440 // first time the grid is displayed, because wxGrid derives the highlight rectangle from a
441 // layout that isn't finalized until the grid is actually on screen. Wait until the grid is
442 // genuinely visible before forcing the corrective redraw, so a grid living on an inactive
443 // notebook page (e.g. opening the dialog on the "3D Models" page) is still corrected when the
444 // user switches to it. The handler removes itself once the one-time refresh has run.
445 if( !IsShownOnScreen() )
446 return;
447
448 Disconnect( wxEVT_IDLE, wxIdleEventHandler( WX_GRID::onIdleRefreshHighlight ), nullptr, this );
449 ForceRefresh();
450}
451#endif
452
453
454void WX_GRID::onCellEditorShown( wxGridEvent& aEvent )
455{
456 if( alg::contains( m_autoEvalCols, aEvent.GetCol() ) )
457 {
458 int row = aEvent.GetRow();
459 int col = aEvent.GetCol();
460
461 const std::pair<wxString, wxString>& beforeAfter = m_evalBeforeAfter[ { row, col } ];
462
463 if( GetCellValue( row, col ) == beforeAfter.second )
464 SetCellValue( row, col, beforeAfter.first );
465 }
466}
467
468
469void WX_GRID::onCellEditorHidden( wxGridEvent& aEvent )
470{
471 const int col = aEvent.GetCol();
472
473 if( alg::contains( m_autoEvalCols, col ) )
474 {
475 UNITS_PROVIDER* unitsProvider = getUnitsProvider( col );
476
477 auto cellUnitsData = getColumnUnits( col );
478 EDA_UNITS cellUnits = cellUnitsData.first;
479 EDA_DATA_TYPE cellDataType = cellUnitsData.second;
480
481 m_eval->SetDefaultUnits( cellUnits );
482
483 const int row = aEvent.GetRow();
484
485 // Determine if this cell is marked as holding nullable values
486 bool isNullable = false;
487 wxGridCellEditor* cellEditor = GetCellEditor( row, col );
488
489 if( cellEditor )
490 {
491 if( const GRID_CELL_NULLABLE_INTERFACE* nullable =
492 dynamic_cast<GRID_CELL_NULLABLE_INTERFACE*>( cellEditor ) )
493 isNullable = nullable->IsNullable();
494
495 cellEditor->DecRef();
496 }
497
498 CallAfter(
499 [this, row, col, isNullable, unitsProvider, cellDataType]()
500 {
501 // Careful; if called from CommitPendingChange() in a delete operation, the cell may
502 // no longer exist.
503 if( row >= GetNumberRows() || col >= GetNumberCols() )
504 return;
505
506 wxString stringValue = GetCellValue( row, col );
507 bool processedOk = true;
508
509 if( stringValue != UNITS_PROVIDER::NullUiString )
510 processedOk = m_eval->Process( stringValue );
511
512 if( processedOk )
513 {
514 wxString evalValue;
515
516 if( isNullable )
517 {
518 std::optional<int> val;
519
520 if( stringValue == UNITS_PROVIDER::NullUiString )
521 {
523 cellDataType );
524 }
525 else
526 {
527 val = unitsProvider->OptionalValueFromString( m_eval->Result(), cellDataType );
528 }
529
530 evalValue = unitsProvider->StringFromOptionalValue( val, true, cellDataType );
531 }
532 else
533 {
534 int val = unitsProvider->ValueFromString( m_eval->Result(), cellDataType );
535 evalValue = unitsProvider->StringFromValue( val, true, cellDataType );
536 }
537
538 if( stringValue != evalValue )
539 {
540 SetCellValue( row, col, evalValue );
541 m_evalBeforeAfter[{ row, col }] = { stringValue, evalValue };
542 }
543 }
544 } );
545 }
546
547 aEvent.Skip();
548}
549
550
551void WX_GRID::DestroyTable( wxGridTableBase* aTable )
552{
553 // wxGrid's destructor will crash trying to look up the cell attr if the edit control
554 // is left open. Normally it's closed in Validate(), but not if the user hit Cancel.
555 CommitPendingChanges( true /* quiet mode */ );
556
557 Disconnect( wxEVT_GRID_COL_MOVE, wxGridEventHandler( WX_GRID::onGridColMove ), nullptr, this );
558 Disconnect( wxEVT_GRID_SELECT_CELL, wxGridEventHandler( WX_GRID::onGridCellSelect ), nullptr, this );
559
560#ifdef __WXMSW__
561 Disconnect( wxEVT_IDLE, wxIdleEventHandler( WX_GRID::onIdleRefreshHighlight ), nullptr, this );
562#endif
563
564 wxGrid::SetTable( nullptr );
565 delete aTable;
566}
567
568
570{
571 wxString shownColumns;
572
573 for( int i = 0; i < GetNumberCols(); ++i )
574 {
575 if( IsColShown( i ) )
576 {
577 if( shownColumns.Length() )
578 shownColumns << wxT( " " );
579
580 shownColumns << i;
581 }
582 }
583
584 return shownColumns;
585}
586
587
589{
590 std::bitset<64> shownColumns;
591
592 for( int ii = 0; ii < GetNumberCols(); ++ii )
593 shownColumns[ii] = IsColShown( ii );
594
595 return shownColumns;
596}
597
598
599void WX_GRID::ShowHideColumns( const wxString& shownColumns )
600{
601 for( int i = 0; i < GetNumberCols(); ++i )
602 HideCol( i );
603
604 wxStringTokenizer shownTokens( shownColumns, " \t\r\n", wxTOKEN_STRTOK );
605
606 while( shownTokens.HasMoreTokens() )
607 {
608 long colNumber;
609 shownTokens.GetNextToken().ToLong( &colNumber );
610
611 if( colNumber >= 0 && colNumber < GetNumberCols() )
612 ShowCol( (int) colNumber );
613 }
614}
615
616
618{
619 if( m_nativeColumnLabels )
620 wxGrid::DrawCornerLabel( dc );
621
622 wxRect rect( wxSize( m_rowLabelWidth, m_colLabelHeight ) );
623
625
626 // It is reported that we need to erase the background to avoid display artifacts; see #12055.
627 {
628 wxDCBrushChanger setBrush( dc, m_colLabelWin->GetBackgroundColour() );
629 wxDCPenChanger setPen( dc, m_colLabelWin->GetBackgroundColour() );
630 dc.DrawRectangle( rect.Inflate( 1 ) );
631 }
632
633 rend.DrawBorder( *this, dc, rect );
634}
635
636
637void WX_GRID::DrawColLabel( wxDC& dc, int col )
638{
639 if( m_nativeColumnLabels )
640 wxGrid::DrawColLabel( dc, col );
641
642 if( GetColWidth( col ) <= 0 || m_colLabelHeight <= 0 )
643 return;
644
645 wxRect rect( GetColLeft( col ), 0, GetColWidth( col ), m_colLabelHeight );
646
648
649 // It is reported that we need to erase the background to avoid display artifacts; see #12055.
650 {
651 wxDCBrushChanger setBrush( dc, m_colLabelWin->GetBackgroundColour() );
652 wxDCPenChanger setPen( dc, m_colLabelWin->GetBackgroundColour() );
653 dc.DrawRectangle( rect.Inflate( 1 ) );
654 }
655
656 rend.DrawBorder( *this, dc, rect );
657
658 // Make sure fonts get scaled correctly on GTK HiDPI monitors
659 dc.SetFont( GetLabelFont() );
660
661 int hAlign, vAlign;
662 GetColLabelAlignment( &hAlign, &vAlign );
663 const int orient = GetColLabelTextOrientation();
664
665 if( col == 0 )
666 hAlign = wxALIGN_LEFT;
667
668 if( hAlign == wxALIGN_LEFT )
669 rect.SetLeft( rect.GetLeft() + MIN_GRIDCELL_MARGIN );
670
671 rend.DrawLabel( *this, dc, GetColLabelValue( col ), rect, hAlign, vAlign, orient );
672}
673
674
675void WX_GRID::DrawRowLabel( wxDC& dc, int row )
676{
677 if( GetRowHeight( row ) <= 0 || m_rowLabelWidth <= 0 )
678 return;
679
680 wxRect rect( 0, GetRowTop( row ), m_rowLabelWidth, GetRowHeight( row ) );
681
682 static WX_GRID_ROW_HEADER_RENDERER rend;
683
684 // It is reported that we need to erase the background to avoid display artifacts; see #12055.
685 {
686 wxDCBrushChanger setBrush( dc, m_colLabelWin->GetBackgroundColour() );
687 wxDCPenChanger setPen( dc, m_colLabelWin->GetBackgroundColour() );
688 dc.DrawRectangle( rect.Inflate( 1 ) );
689 }
690
691 rend.DrawBorder( *this, dc, rect );
692
693 // Make sure fonts get scaled correctly on GTK HiDPI monitors
694 dc.SetFont( GetLabelFont() );
695
696 int hAlign, vAlign;
697 GetRowLabelAlignment(&hAlign, &vAlign);
698
699 if( hAlign == wxALIGN_LEFT )
700 rect.SetLeft( rect.GetLeft() + MIN_GRIDCELL_MARGIN );
701
702 rend.DrawLabel( *this, dc, GetRowLabelValue( row ), rect, hAlign, vAlign, wxHORIZONTAL );
703}
704
705
707{
708 if( !IsCellEditControlEnabled() )
709 return true;
710
711 HideCellEditControl();
712
713 // do it after HideCellEditControl()
714 m_cellEditCtrlEnabled = false;
715
716 int row = m_currentCellCoords.GetRow();
717 int col = m_currentCellCoords.GetCol();
718
719 wxString oldval = GetCellValue( row, col );
720 wxString newval;
721
722 wxGridCellAttr* attr = GetCellAttr( row, col );
723 wxGridCellEditor* editor = attr->GetEditor( this, row, col );
724
725 editor->EndEdit( row, col, this, oldval, &newval );
726
727 editor->DecRef();
728 attr->DecRef();
729
730 return true;
731}
732
733
734bool WX_GRID::CommitPendingChanges( bool aQuietMode )
735{
736 if( !IsCellEditControlEnabled() )
737 return true;
738
739 if( !aQuietMode && SendEvent( wxEVT_GRID_EDITOR_HIDDEN ) == -1 )
740 return false;
741
742 HideCellEditControl();
743
744 // do it after HideCellEditControl()
745 m_cellEditCtrlEnabled = false;
746
747 int row = m_currentCellCoords.GetRow();
748 int col = m_currentCellCoords.GetCol();
749
750 wxString oldval = GetCellValue( row, col );
751 wxString newval;
752
753 wxGridCellAttr* attr = GetCellAttr( row, col );
754 wxGridCellEditor* editor = attr->GetEditor( this, row, col );
755
756 bool changed = editor->EndEdit( row, col, this, oldval, &newval );
757
758 editor->DecRef();
759 attr->DecRef();
760
761 if( changed )
762 {
763 if( !aQuietMode && SendEvent( wxEVT_GRID_CELL_CHANGING, newval ) == -1 )
764 return false;
765
766 editor->ApplyEdit( row, col, this );
767
768 // for compatibility reasons dating back to wx 2.8 when this event
769 // was called wxEVT_GRID_CELL_CHANGE and wxEVT_GRID_CELL_CHANGING
770 // didn't exist we allow vetoing this one too
771 if( !aQuietMode && SendEvent( wxEVT_GRID_CELL_CHANGED, oldval ) == -1 )
772 {
773 // Event has been vetoed, set the data back.
774 SetCellValue( row, col, oldval );
775 return false;
776 }
777
778 if( DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( wxGetTopLevelParent( this ) ) )
779 dlg->OnModify();
780 }
781
782 return true;
783}
784
785
786void WX_GRID::OnAddRow( const std::function<std::pair<int, int>()>& aAdder )
787{
788 if( !CommitPendingChanges() )
789 return;
790
791 auto [row, editCol] = aAdder();
792
793 // wx documentation is wrong, SetGridCursor does not make visible.
794 SetFocus();
795 MakeCellVisible( row, std::max( editCol, 0 ) );
796 SetGridCursor( row, std::max( editCol, 0 ) );
797
798 if( editCol >= 0 )
799 {
800 EnableCellEditControl( true );
801 ShowCellEditControl();
802 }
803}
804
805
806void WX_GRID::OnDeleteRows( const std::function<void( int row )>& aDeleter )
807{
809 []( int row )
810 {
811 return true;
812 },
813 aDeleter );
814}
815
816
817void WX_GRID::OnDeleteRows( const std::function<bool( int row )>& aFilter,
818 const std::function<void( int row )>& aDeleter )
819{
820 wxArrayInt selectedRows = GetSelectedRows();
821
822 auto addSelectedRow = [&]( int row )
823 {
824 for( size_t i = 0; i < selectedRows.size(); ++i )
825 {
826 if( selectedRows[i] == row )
827 return;
828 }
829
830 selectedRows.push_back( row );
831 };
832
833 wxGridCellCoordsArray topLeft = GetSelectionBlockTopLeft();
834 wxGridCellCoordsArray botRight = GetSelectionBlockBottomRight();
835
836 for( size_t i = 0; i < std::min( topLeft.Count(), botRight.Count() ); ++i )
837 {
838 for( int row = topLeft[i].GetRow(); row <= botRight[i].GetRow(); ++row )
839 addSelectedRow( row );
840 }
841
842 wxGridCellCoordsArray cells = GetSelectedCells();
843
844 for( size_t i = 0; i < cells.Count(); ++i )
845 addSelectedRow( cells[i].GetRow() );
846
847 if( selectedRows.empty() && GetGridCursorRow() >= 0 )
848 selectedRows.push_back( GetGridCursorRow() );
849
850 if( selectedRows.empty() )
851 return;
852
853 for( int row : selectedRows )
854 {
855 if( !aFilter( row ) )
856 return;
857 }
858
859 if( !CommitPendingChanges() )
860 return;
861
862 // Reverse sort so deleting a row doesn't change the indexes of the other rows.
863 selectedRows.Sort(
864 []( int* first, int* second )
865 {
866 return *second - *first;
867 } );
868
869 int nextSelRow = selectedRows.back() - 1;
870
871 if( nextSelRow >= 0 )
872 {
873 GoToCell( nextSelRow, GetGridCursorCol() );
874 SetGridCursor( nextSelRow, GetGridCursorCol() );
875 }
876
877 for( int row : selectedRows )
878 aDeleter( row );
879}
880
881
882void WX_GRID::SwapRows( int aRowA, int aRowB )
883{
884 for( int col = 0; col < GetNumberCols(); ++col )
885 {
886 wxString temp = GetCellValue( aRowA, col );
887 SetCellValue( aRowA, col, GetCellValue( aRowB, col ) );
888 SetCellValue( aRowB, col, temp );
889 }
890}
891
892
893void WX_GRID::OnMoveRowUp( const std::function<void( int row )>& aMover )
894{
896 []( int row )
897 {
898 return true;
899 },
900 aMover );
901}
902
903
904void WX_GRID::OnMoveRowUp( const std::function<bool( int row )>& aFilter,
905 const std::function<void( int row )>& aMover )
906{
907 if( !CommitPendingChanges() )
908 return;
909
910 int i = GetGridCursorRow();
911
912 if( i > 0 && aFilter( i ) )
913 {
914 aMover( i );
915
916 SetGridCursor( i - 1, GetGridCursorCol() );
917 MakeCellVisible( GetGridCursorRow(), GetGridCursorCol() );
918 }
919 else
920 {
921 wxBell();
922 }
923}
924
925
926void WX_GRID::OnMoveRowDown( const std::function<void( int row )>& aMover )
927{
929 []( int row )
930 {
931 return true;
932 },
933 aMover );
934}
935
936
937void WX_GRID::OnMoveRowDown( const std::function<bool( int row )>& aFilter,
938 const std::function<void( int row )>& aMover )
939{
940 if( !CommitPendingChanges() )
941 return;
942
943 int i = GetGridCursorRow();
944
945 if( i + 1 < GetNumberRows() && aFilter( i ) )
946 {
947 aMover( i );
948
949 SetGridCursor( i + 1, GetGridCursorCol() );
950 MakeCellVisible( GetGridCursorRow(), GetGridCursorCol() );
951 }
952 else
953 {
954 wxBell();
955 }
956}
957
958
959void WX_GRID::SetUnitsProvider( UNITS_PROVIDER* aProvider, int aCol )
960{
961 m_unitsProviders[ aCol ] = aProvider;
962
963 if( !m_eval )
964 m_eval = std::make_unique<NUMERIC_EVALUATOR>( aProvider->GetUserUnits() );
965}
966
967
968void WX_GRID::SetAutoEvalColUnits( const int col, EDA_UNITS aUnit, EDA_DATA_TYPE aUnitType )
969{
970 m_autoEvalColsUnits[col] = std::make_pair( aUnit, aUnitType );
971}
972
973
974void WX_GRID::SetAutoEvalColUnits( const int col, EDA_UNITS aUnit )
975{
977 SetAutoEvalColUnits( col, aUnit, type );
978}
979
980
981int WX_GRID::GetUnitValue( int aRow, int aCol )
982{
983 wxString stringValue = GetCellValue( aRow, aCol );
984
985 auto [cellUnits, cellDataType] = getColumnUnits( aCol );
986
987 if( alg::contains( m_autoEvalCols, aCol ) )
988 {
989 m_eval->SetDefaultUnits( cellUnits );
990
991 if( m_eval->Process( stringValue ) )
992 stringValue = m_eval->Result();
993 }
994
995 return getUnitsProvider( aCol )->ValueFromString( stringValue, cellDataType );
996}
997
998
999std::optional<int> WX_GRID::GetOptionalUnitValue( int aRow, int aCol )
1000{
1001 wxString stringValue = GetCellValue( aRow, aCol );
1002
1003 auto [cellUnits, cellDataType] = getColumnUnits( aCol );
1004
1005 if( alg::contains( m_autoEvalCols, aCol ) )
1006 {
1007 m_eval->SetDefaultUnits( cellUnits );
1008
1009 if( stringValue != UNITS_PROVIDER::NullUiString && m_eval->Process( stringValue ) )
1010 stringValue = m_eval->Result();
1011 }
1012
1013 return getUnitsProvider( aCol )->OptionalValueFromString( stringValue, cellDataType );
1014}
1015
1016
1017void WX_GRID::SetUnitValue( int aRow, int aCol, int aValue )
1018{
1019 EDA_DATA_TYPE cellDataType;
1020
1021 if( m_autoEvalColsUnits.contains( aCol ) )
1022 cellDataType = m_autoEvalColsUnits[aCol].second;
1023 else
1024 cellDataType = EDA_DATA_TYPE::DISTANCE;
1025
1026 SetCellValue( aRow, aCol, getUnitsProvider( aCol )->StringFromValue( aValue, true, cellDataType ) );
1027}
1028
1029
1030void WX_GRID::SetOptionalUnitValue( int aRow, int aCol, std::optional<int> aValue )
1031{
1032 EDA_DATA_TYPE cellDataType;
1033
1034 if( m_autoEvalColsUnits.contains( aCol ) )
1035 cellDataType = m_autoEvalColsUnits[aCol].second;
1036 else
1037 cellDataType = EDA_DATA_TYPE::DISTANCE;
1038
1039 SetCellValue( aRow, aCol, getUnitsProvider( aCol )->StringFromOptionalValue( aValue, true, cellDataType ) );
1040}
1041
1042
1043void WX_GRID::onGridColMove( wxGridEvent& aEvent )
1044{
1045 // wxWidgets won't move an open editor, so better just to close it
1046 CommitPendingChanges( true );
1047}
1048
1049
1050int WX_GRID::GetVisibleWidth( int aCol, bool aHeader, bool aContents, bool aKeep )
1051{
1052 int size = 0;
1053
1054 if( aCol < 0 )
1055 {
1056 if( aKeep )
1057 size = GetRowLabelSize();
1058
1059 for( int row = 0; aContents && row < GetNumberRows(); row++ )
1060 size = std::max( size, int( GetTextExtent( GetRowLabelValue( row ) + wxS( "M" ) ).x ) );
1061 }
1062 else
1063 {
1064 if( aKeep )
1065 size = GetColSize( aCol );
1066
1067 // 'M' is generally the widest character, so we buffer the column width by default to
1068 // ensure we don't write a continuous line of text at the column header
1069 if( aHeader )
1070 {
1072
1073 size = std::max( size, int( GetTextExtent( GetColLabelValue( aCol ) + wxS( "M" ) ).x ) );
1074 }
1075
1076 for( int row = 0; aContents && row < GetNumberRows(); row++ )
1077 {
1078 // If we have text, get the size. Otherwise, use a placeholder for the checkbox
1079 if( GetTable()->CanGetValueAs( row, aCol, wxGRID_VALUE_STRING ) )
1080 size = std::max( size, GetTextExtent( GetCellValue( row, aCol ) + wxS( "M" ) ).x );
1081 else
1082 size = std::max( size, GetTextExtent( "MM" ).x );
1083 }
1084 }
1085
1086 return size;
1087}
1088
1089
1091{
1092 int line_height = int( GetTextExtent( "Mj" ).y ) + 3;
1093 int row_height = GetColLabelSize();
1094 int initial_row_height = row_height;
1095
1096 // Headers can be multiline. Fix the Column Label Height to show the full header
1097 // However GetTextExtent does not work on multiline strings,
1098 // and do not return the full text height (only the height of one line)
1099 for( int col = 0; col < GetNumberCols(); col++ )
1100 {
1101 int nl_count = GetColLabelValue( col ).Freq( '\n' );
1102
1103 if( nl_count )
1104 {
1105 // Col Label height must be able to show nl_count+1 lines
1106 if( row_height < line_height * ( nl_count+1 ) )
1107 row_height += line_height * nl_count;
1108 }
1109 }
1110
1111 // Update the column label size, but only if needed, to avoid generating useless
1112 // and perhaps annoying UI events when the size does not change
1113 if( initial_row_height != row_height )
1114 SetColLabelSize( row_height );
1115}
1116
1117
1118std::pair<EDA_UNITS, EDA_DATA_TYPE> WX_GRID::getColumnUnits( const int aCol ) const
1119{
1120 if( m_autoEvalColsUnits.contains( aCol ) )
1121 return { m_autoEvalColsUnits.at( aCol ).first, m_autoEvalColsUnits.at( aCol ).second };
1122
1123 // Legacy - default always DISTANCE
1125}
1126
1127
1128void WX_GRID::SetupColumnAutosizer( int aFlexibleCol )
1129{
1130 const int colCount = GetNumberCols();
1131
1132 for( int ii = 0; ii < GetNumberCols(); ++ii )
1133 m_autosizedCols[ii] = GetColSize( ii );
1134
1135 m_flexibleCol = aFlexibleCol;
1136
1137 wxASSERT_MSG( m_flexibleCol < colCount, "Flexible column index does not exist in grid" );
1138
1139 Bind( wxEVT_UPDATE_UI,
1140 [this]( wxUpdateUIEvent& aEvent )
1141 {
1143 aEvent.Skip();
1144 } );
1145
1146 Bind( wxEVT_SIZE,
1147 [this]( wxSizeEvent& aEvent )
1148 {
1149 onSizeEvent( aEvent );
1150 aEvent.Skip();
1151 } );
1152
1153 // Handles the case when the user changes the cell content to be longer than the current column size
1154 Bind( wxEVT_GRID_CELL_CHANGED,
1155 [this]( wxGridEvent& aEvent )
1156 {
1157 m_gridWidthsDirty = true;
1158 aEvent.Skip();
1159 } );
1160}
1161
1162
1164{
1165 if( m_gridWidthsDirty )
1166 {
1167 const int width = GetSize().GetX() - wxSystemSettings::GetMetric( wxSYS_VSCROLL_X );
1168
1169 std::optional<int> flexibleMinWidth;
1170
1171 for( const auto& [colIndex, minWidth] : m_autosizedCols )
1172 {
1173 if( GetColSize( colIndex ) != 0 )
1174 {
1175 AutoSizeColumn( colIndex );
1176 const int colSize = GetColSize( colIndex );
1177
1178 int minWidthScaled = FromDIP( minWidth );
1179 SetColSize( colIndex, std::max( minWidthScaled, colSize ) );
1180
1181 if( colIndex == m_flexibleCol )
1182 flexibleMinWidth = minWidthScaled;
1183 }
1184 }
1185
1186 // Gather all the widths except the flexi one
1187 int nonFlexibleWidth = 0;
1188
1189 for( int i = 0; i < GetNumberCols(); ++i )
1190 {
1191 if( i != m_flexibleCol )
1192 nonFlexibleWidth += GetColSize( i );
1193 }
1194
1195 if( GetColSize( m_flexibleCol ) != 0 )
1196 SetColSize( m_flexibleCol, std::max( flexibleMinWidth.value_or( 0 ), width - nonFlexibleWidth ) );
1197
1198 // Store the state for next time
1199 m_gridWidth = GetSize().GetX();
1200 m_gridWidthsDirty = false;
1201 }
1202}
1203
1204
1205void WX_GRID::onSizeEvent( wxSizeEvent& aEvent )
1206{
1207 const int width = aEvent.GetSize().GetX();
1208
1209 if( width != m_gridWidth )
1210 m_gridWidthsDirty = true;
1211}
const char * name
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition dialog_shim.h:80
A color representation with 4 components: red, green, blue, alpha.
Definition color4d.h:101
wxColour ToColour() const
Definition color4d.cpp:221
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
Definition color4d.h:292
Icon provider for the "standard" row indicators, for example in layer selection lists.
static const wxString NullUiString
The string that is used in the UI to represent a null value.
std::optional< int > OptionalValueFromString(const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
Converts aTextValue in aUnits to internal units used by the frame.
wxString StringFromOptionalValue(std::optional< int > aValue, bool aAddUnitLabel=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
Converts an optional aValue in internal units into a united string.
EDA_UNITS GetUserUnits() const
static EDA_DATA_TYPE GetTypeFromUnits(const EDA_UNITS aUnits)
Gets the inferred type from the given units.
wxString StringFromValue(double aValue, bool aAddUnitLabel=false, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
Converts aValue in internal units into a united string.
int ValueFromString(const wxString &aTextValue, EDA_DATA_TYPE aType=EDA_DATA_TYPE::DISTANCE) const
Converts aTextValue in aUnits to internal units used by the frame.
Attribute provider that provides attributes (or modifies the existing attribute) to alternate a row c...
Definition wx_grid.cpp:203
WX_GRID_ALT_ROW_COLOR_PROVIDER(const wxColor &aBaseColor)
Definition wx_grid.cpp:205
wxGridCellAttr * GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind) const override
Definition wx_grid.cpp:220
wxGridCellAttrPtr m_attrEven
Definition wx_grid.cpp:246
void UpdateColors(const wxColor &aBaseColor)
Definition wx_grid.cpp:212
void DrawBorder(const wxGrid &grid, wxDC &dc, wxRect &rect) const override
Definition wx_grid.cpp:167
void DrawBorder(const wxGrid &grid, wxDC &dc, wxRect &rect) const override
Definition wx_grid.cpp:150
void DrawBorder(const wxGrid &grid, wxDC &dc, wxRect &rect) const override
Definition wx_grid.cpp:184
wxGridCellAttr * enhanceAttr(wxGridCellAttr *aInputAttr, int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind)
Definition wx_grid.cpp:43
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=true, bool aKeep=false)
Calculate the specified column based on the actual size of the text on screen.
Definition wx_grid.cpp:1050
int m_flexibleCol
Definition wx_grid.h:416
void onGridCellSelect(wxGridEvent &aEvent)
Definition wx_grid.cpp:404
std::map< int, int > m_autosizedCols
Definition wx_grid.h:415
bool m_gridWidthsDirty
Definition wx_grid.h:418
~WX_GRID() override
Definition wx_grid.cpp:272
void SetLabelFont(const wxFont &aFont)
Hide wxGrid's SetLabelFont() because for some reason on MSW it's a one-shot and subsequent calls to i...
Definition wx_grid.cpp:341
bool m_weOwnTable
Definition wx_grid.h:404
void onDPIChanged(wxDPIChangedEvent &event)
Definition wx_grid.cpp:285
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition wx_grid.cpp:599
void OnMoveRowUp(const std::function< void(int row)> &aMover)
Definition wx_grid.cpp:893
std::map< int, UNITS_PROVIDER * > m_unitsProviders
Definition wx_grid.h:407
void SetTable(wxGridTableBase *table, bool aTakeOwnership=false)
Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting th...
Definition wx_grid.cpp:347
void DestroyTable(wxGridTableBase *aTable)
Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was no...
Definition wx_grid.cpp:551
std::unordered_map< int, std::pair< EDA_UNITS, EDA_DATA_TYPE > > m_autoEvalColsUnits
Definition wx_grid.h:410
void SetAutoEvalColUnits(int col, EDA_UNITS aUnit, EDA_DATA_TYPE aUnitType)
Set the unit and unit data type to use for a given column.
Definition wx_grid.cpp:968
bool CancelPendingChanges()
Definition wx_grid.cpp:706
void SetColLabelSize(int aHeight)
Hide wxGrid's SetColLabelSize() method with one which makes sure the size is tall enough for the syst...
Definition wx_grid.cpp:326
static int CapHeightToVisibleRows(int aMinHeight, int aHeaderHeight, const std::vector< int > &aRowHeights, int aMaxRows)
Height of aMaxRows data rows plus the column-label header, never more than aMinHeight.
Definition wx_grid.cpp:90
void SwapRows(int aRowA, int aRowB)
These aren't that tricky, but might as well share code.
Definition wx_grid.cpp:882
std::pair< EDA_UNITS, EDA_DATA_TYPE > getColumnUnits(int aCol) const
Returns the units and data type associated with a given column.
Definition wx_grid.cpp:1118
void SetUnitValue(int aRow, int aCol, int aValue)
Set a unitized cell's value.
Definition wx_grid.cpp:1017
WX_GRID(wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxWANTS_CHARS, const wxString &name=wxGridNameStr)
Definition wx_grid.cpp:250
int GetUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition wx_grid.cpp:981
std::vector< int > m_autoEvalCols
Definition wx_grid.h:409
UNITS_PROVIDER * getUnitsProvider(int aCol) const
Definition wx_grid.h:387
std::map< std::pair< int, int >, std::pair< wxString, wxString > > m_evalBeforeAfter
Definition wx_grid.h:411
void SetMinVisibleRows(wxWindow *aDialog, int aMinRows)
Floor this grid at aMinRows visible rows and grow aDialog so it opens tall enough to show every curre...
Definition wx_grid.cpp:106
void DrawCornerLabel(wxDC &dc) override
A re-implementation of wxGrid::DrawCornerLabel which draws flat borders.
Definition wx_grid.cpp:617
bool m_cursorRowColumnHighlight
Definition wx_grid.h:405
ROW_ICON_PROVIDER * m_rowIconProvider
Definition wx_grid.h:421
void onCellEditorHidden(wxGridEvent &aEvent)
Definition wx_grid.cpp:469
void SetupColumnAutosizer(int aFlexibleCol)
Set autosize behaviour using wxFormBuilder column widths as minimums, with a single specified growabl...
Definition wx_grid.cpp:1128
void RecomputeGridWidths()
Definition wx_grid.cpp:1163
void OnMoveRowDown(const std::function< void(int row)> &aMover)
Definition wx_grid.cpp:926
void onGridColMove(wxGridEvent &aEvent)
Definition wx_grid.cpp:1043
void SetOptionalUnitValue(int aRow, int aCol, std::optional< int > aValue)
Set a unitized cell's optional value.
Definition wx_grid.cpp:1030
void onSizeEvent(wxSizeEvent &aEvent)
Definition wx_grid.cpp:1205
void onCellEditorShown(wxGridEvent &aEvent)
Definition wx_grid.cpp:454
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition wx_grid.cpp:1090
void OnDeleteRows(const std::function< void(int row)> &aDeleter)
Handles a row deletion event.
Definition wx_grid.cpp:806
wxString GetShownColumnsAsString()
Get a tokenized string containing the shown column indexes.
Definition wx_grid.cpp:569
void OnAddRow(const std::function< std::pair< int, int >()> &aAdder)
Definition wx_grid.cpp:786
int m_gridWidth
Definition wx_grid.h:419
void DrawRowLabel(wxDC &dc, int row) override
A re-implementation of wxGrid::DrawRowLabel which draws flat borders.
Definition wx_grid.cpp:675
std::bitset< 64 > GetShownColumns()
Definition wx_grid.cpp:588
static void CellEditorSetMargins(wxTextEntryBase *aEntry)
A helper function to set OS-specific margins for text-based cell editors.
Definition wx_grid.cpp:75
std::optional< int > GetOptionalUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition wx_grid.cpp:999
void EnableAlternateRowColors(bool aEnable=true)
Enable alternate row highlighting, where every odd row has a different background color than the even...
Definition wx_grid.cpp:386
void SetUnitsProvider(UNITS_PROVIDER *aProvider, int aCol=0)
Set a EUNITS_PROVIDER to enable use of unit- and eval-based Getters.
Definition wx_grid.cpp:959
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition wx_grid.cpp:734
std::unique_ptr< NUMERIC_EVALUATOR > m_eval
Definition wx_grid.h:408
void DrawColLabel(wxDC &dc, int col) override
A re-implementation of wxGrid::DrawColLabel which left-aligns the first column and draws flat borders...
Definition wx_grid.cpp:637
static void CellEditorTransformSizeRect(wxRect &aRect)
A helper function to tweak sizes of text-based cell editors depending on OS.
Definition wx_grid.cpp:82
EDA_DATA_TYPE
The type of unit.
Definition eda_units.h:34
EDA_UNITS
Definition eda_units.h:44
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition wxgtk/ui.cpp:51
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
const int c_IndicatorSizeDIP
Definition ui_common.h:52
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition kicad_algo.h:96
PGM_BASE & Pgm()
The global program "get" accessor.
see class PGM_BASE
Functions to provide common constants and other functions to assist in making a consistent UI.
wxColour getBorderColour()
Definition wx_grid.cpp:138
#define MIN_GRIDCELL_MARGIN
Definition wx_grid.cpp:72