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}
104
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 }
428}
429
430
431#ifdef __WXMSW__
432void WX_GRID::onIdleRefreshHighlight( wxIdleEvent& aEvent )
433{
434 aEvent.Skip();
435
436 // On Windows with wxWidgets 3.3+, the selection highlight is drawn with stale geometry the
437 // first time the grid is displayed, because wxGrid derives the highlight rectangle from a
438 // layout that isn't finalized until the grid is actually on screen. Wait until the grid is
439 // genuinely visible before forcing the corrective redraw, so a grid living on an inactive
440 // notebook page (e.g. opening the dialog on the "3D Models" page) is still corrected when the
441 // user switches to it. The handler removes itself once the one-time refresh has run.
442 if( !IsShownOnScreen() )
443 return;
444
445 Disconnect( wxEVT_IDLE, wxIdleEventHandler( WX_GRID::onIdleRefreshHighlight ), nullptr, this );
446 ForceRefresh();
447}
448#endif
449
450
451void WX_GRID::onCellEditorShown( wxGridEvent& aEvent )
452{
453 if( alg::contains( m_autoEvalCols, aEvent.GetCol() ) )
454 {
455 int row = aEvent.GetRow();
456 int col = aEvent.GetCol();
457
458 const std::pair<wxString, wxString>& beforeAfter = m_evalBeforeAfter[ { row, col } ];
459
460 if( GetCellValue( row, col ) == beforeAfter.second )
461 SetCellValue( row, col, beforeAfter.first );
462 }
463}
464
465
466void WX_GRID::onCellEditorHidden( wxGridEvent& aEvent )
467{
468 const int col = aEvent.GetCol();
469
470 if( alg::contains( m_autoEvalCols, col ) )
471 {
472 UNITS_PROVIDER* unitsProvider = getUnitsProvider( col );
473
474 auto cellUnitsData = getColumnUnits( col );
475 EDA_UNITS cellUnits = cellUnitsData.first;
476 EDA_DATA_TYPE cellDataType = cellUnitsData.second;
477
478 m_eval->SetDefaultUnits( cellUnits );
479
480 const int row = aEvent.GetRow();
481
482 // Determine if this cell is marked as holding nullable values
483 bool isNullable = false;
484 wxGridCellEditor* cellEditor = GetCellEditor( row, col );
485
486 if( cellEditor )
487 {
488 if( const GRID_CELL_NULLABLE_INTERFACE* nullable =
489 dynamic_cast<GRID_CELL_NULLABLE_INTERFACE*>( cellEditor ) )
490 isNullable = nullable->IsNullable();
491
492 cellEditor->DecRef();
493 }
494
495 CallAfter(
496 [this, row, col, isNullable, unitsProvider, cellDataType]()
497 {
498 // Careful; if called from CommitPendingChange() in a delete operation, the cell may
499 // no longer exist.
500 if( row >= GetNumberRows() || col >= GetNumberCols() )
501 return;
502
503 wxString stringValue = GetCellValue( row, col );
504 bool processedOk = true;
505
506 if( stringValue != UNITS_PROVIDER::NullUiString )
507 processedOk = m_eval->Process( stringValue );
508
509 if( processedOk )
510 {
511 wxString evalValue;
512
513 if( isNullable )
514 {
515 std::optional<int> val;
516
517 if( stringValue == UNITS_PROVIDER::NullUiString )
518 {
520 cellDataType );
521 }
522 else
523 {
524 val = unitsProvider->OptionalValueFromString( m_eval->Result(), cellDataType );
525 }
526
527 evalValue = unitsProvider->StringFromOptionalValue( val, true, cellDataType );
528 }
529 else
530 {
531 int val = unitsProvider->ValueFromString( m_eval->Result(), cellDataType );
532 evalValue = unitsProvider->StringFromValue( val, true, cellDataType );
533 }
534
535 if( stringValue != evalValue )
536 {
537 SetCellValue( row, col, evalValue );
538 m_evalBeforeAfter[{ row, col }] = { stringValue, evalValue };
539 }
540 }
541 } );
542 }
543
544 aEvent.Skip();
545}
546
547
548void WX_GRID::DestroyTable( wxGridTableBase* aTable )
549{
550 // wxGrid's destructor will crash trying to look up the cell attr if the edit control
551 // is left open. Normally it's closed in Validate(), but not if the user hit Cancel.
552 CommitPendingChanges( true /* quiet mode */ );
553
554 Disconnect( wxEVT_GRID_COL_MOVE, wxGridEventHandler( WX_GRID::onGridColMove ), nullptr, this );
555 Disconnect( wxEVT_GRID_SELECT_CELL, wxGridEventHandler( WX_GRID::onGridCellSelect ), nullptr, this );
556
557#ifdef __WXMSW__
558 Disconnect( wxEVT_IDLE, wxIdleEventHandler( WX_GRID::onIdleRefreshHighlight ), nullptr, this );
559#endif
560
561 wxGrid::SetTable( nullptr );
562 delete aTable;
563}
564
565
567{
568 wxString shownColumns;
569
570 for( int i = 0; i < GetNumberCols(); ++i )
571 {
572 if( IsColShown( i ) )
573 {
574 if( shownColumns.Length() )
575 shownColumns << wxT( " " );
576
577 shownColumns << i;
578 }
579 }
580
581 return shownColumns;
582}
583
584
586{
587 std::bitset<64> shownColumns;
588
589 for( int ii = 0; ii < GetNumberCols(); ++ii )
590 shownColumns[ii] = IsColShown( ii );
591
592 return shownColumns;
593}
594
595
596void WX_GRID::ShowHideColumns( const wxString& shownColumns )
597{
598 for( int i = 0; i < GetNumberCols(); ++i )
599 HideCol( i );
600
601 wxStringTokenizer shownTokens( shownColumns, " \t\r\n", wxTOKEN_STRTOK );
602
603 while( shownTokens.HasMoreTokens() )
604 {
605 long colNumber;
606 shownTokens.GetNextToken().ToLong( &colNumber );
607
608 if( colNumber >= 0 && colNumber < GetNumberCols() )
609 ShowCol( (int) colNumber );
610 }
611}
612
613
615{
616 if( m_nativeColumnLabels )
617 wxGrid::DrawCornerLabel( dc );
618
619 wxRect rect( wxSize( m_rowLabelWidth, m_colLabelHeight ) );
620
622
623 // It is reported that we need to erase the background to avoid display artifacts; see #12055.
624 {
625 wxDCBrushChanger setBrush( dc, m_colLabelWin->GetBackgroundColour() );
626 wxDCPenChanger setPen( dc, m_colLabelWin->GetBackgroundColour() );
627 dc.DrawRectangle( rect.Inflate( 1 ) );
628 }
629
630 rend.DrawBorder( *this, dc, rect );
631}
632
633
634void WX_GRID::DrawColLabel( wxDC& dc, int col )
635{
636 if( m_nativeColumnLabels )
637 wxGrid::DrawColLabel( dc, col );
638
639 if( GetColWidth( col ) <= 0 || m_colLabelHeight <= 0 )
640 return;
641
642 wxRect rect( GetColLeft( col ), 0, GetColWidth( col ), m_colLabelHeight );
643
645
646 // It is reported that we need to erase the background to avoid display artifacts; see #12055.
647 {
648 wxDCBrushChanger setBrush( dc, m_colLabelWin->GetBackgroundColour() );
649 wxDCPenChanger setPen( dc, m_colLabelWin->GetBackgroundColour() );
650 dc.DrawRectangle( rect.Inflate( 1 ) );
651 }
652
653 rend.DrawBorder( *this, dc, rect );
654
655 // Make sure fonts get scaled correctly on GTK HiDPI monitors
656 dc.SetFont( GetLabelFont() );
657
658 int hAlign, vAlign;
659 GetColLabelAlignment( &hAlign, &vAlign );
660 const int orient = GetColLabelTextOrientation();
661
662 if( col == 0 )
663 hAlign = wxALIGN_LEFT;
664
665 if( hAlign == wxALIGN_LEFT )
666 rect.SetLeft( rect.GetLeft() + MIN_GRIDCELL_MARGIN );
667
668 rend.DrawLabel( *this, dc, GetColLabelValue( col ), rect, hAlign, vAlign, orient );
669}
670
671
672void WX_GRID::DrawRowLabel( wxDC& dc, int row )
673{
674 if( GetRowHeight( row ) <= 0 || m_rowLabelWidth <= 0 )
675 return;
676
677 wxRect rect( 0, GetRowTop( row ), m_rowLabelWidth, GetRowHeight( row ) );
678
679 static WX_GRID_ROW_HEADER_RENDERER rend;
680
681 // It is reported that we need to erase the background to avoid display artifacts; see #12055.
682 {
683 wxDCBrushChanger setBrush( dc, m_colLabelWin->GetBackgroundColour() );
684 wxDCPenChanger setPen( dc, m_colLabelWin->GetBackgroundColour() );
685 dc.DrawRectangle( rect.Inflate( 1 ) );
686 }
687
688 rend.DrawBorder( *this, dc, rect );
689
690 // Make sure fonts get scaled correctly on GTK HiDPI monitors
691 dc.SetFont( GetLabelFont() );
692
693 int hAlign, vAlign;
694 GetRowLabelAlignment(&hAlign, &vAlign);
695
696 if( hAlign == wxALIGN_LEFT )
697 rect.SetLeft( rect.GetLeft() + MIN_GRIDCELL_MARGIN );
698
699 rend.DrawLabel( *this, dc, GetRowLabelValue( row ), rect, hAlign, vAlign, wxHORIZONTAL );
700}
701
702
704{
705 if( !IsCellEditControlEnabled() )
706 return true;
707
708 HideCellEditControl();
709
710 // do it after HideCellEditControl()
711 m_cellEditCtrlEnabled = false;
712
713 int row = m_currentCellCoords.GetRow();
714 int col = m_currentCellCoords.GetCol();
715
716 wxString oldval = GetCellValue( row, col );
717 wxString newval;
718
719 wxGridCellAttr* attr = GetCellAttr( row, col );
720 wxGridCellEditor* editor = attr->GetEditor( this, row, col );
721
722 editor->EndEdit( row, col, this, oldval, &newval );
723
724 editor->DecRef();
725 attr->DecRef();
726
727 return true;
728}
729
730
731bool WX_GRID::CommitPendingChanges( bool aQuietMode )
732{
733 if( !IsCellEditControlEnabled() )
734 return true;
735
736 if( !aQuietMode && SendEvent( wxEVT_GRID_EDITOR_HIDDEN ) == -1 )
737 return false;
738
739 HideCellEditControl();
740
741 // do it after HideCellEditControl()
742 m_cellEditCtrlEnabled = false;
743
744 int row = m_currentCellCoords.GetRow();
745 int col = m_currentCellCoords.GetCol();
746
747 wxString oldval = GetCellValue( row, col );
748 wxString newval;
749
750 wxGridCellAttr* attr = GetCellAttr( row, col );
751 wxGridCellEditor* editor = attr->GetEditor( this, row, col );
752
753 bool changed = editor->EndEdit( row, col, this, oldval, &newval );
754
755 editor->DecRef();
756 attr->DecRef();
757
758 if( changed )
759 {
760 if( !aQuietMode && SendEvent( wxEVT_GRID_CELL_CHANGING, newval ) == -1 )
761 return false;
762
763 editor->ApplyEdit( row, col, this );
764
765 // for compatibility reasons dating back to wx 2.8 when this event
766 // was called wxEVT_GRID_CELL_CHANGE and wxEVT_GRID_CELL_CHANGING
767 // didn't exist we allow vetoing this one too
768 if( !aQuietMode && SendEvent( wxEVT_GRID_CELL_CHANGED, oldval ) == -1 )
769 {
770 // Event has been vetoed, set the data back.
771 SetCellValue( row, col, oldval );
772 return false;
773 }
774
775 if( DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( wxGetTopLevelParent( this ) ) )
776 dlg->OnModify();
777 }
778
779 return true;
780}
781
782
783void WX_GRID::OnAddRow( const std::function<std::pair<int, int>()>& aAdder )
784{
785 if( !CommitPendingChanges() )
786 return;
787
788 auto [row, editCol] = aAdder();
789
790 // wx documentation is wrong, SetGridCursor does not make visible.
791 SetFocus();
792 MakeCellVisible( row, std::max( editCol, 0 ) );
793 SetGridCursor( row, std::max( editCol, 0 ) );
794
795 if( editCol >= 0 )
796 {
797 EnableCellEditControl( true );
798 ShowCellEditControl();
799 }
800}
801
802
803void WX_GRID::OnDeleteRows( const std::function<void( int row )>& aDeleter )
804{
806 []( int row )
807 {
808 return true;
809 },
810 aDeleter );
811}
812
813
814void WX_GRID::OnDeleteRows( const std::function<bool( int row )>& aFilter,
815 const std::function<void( int row )>& aDeleter )
816{
817 wxArrayInt selectedRows = GetSelectedRows();
818
819 auto addSelectedRow = [&]( int row )
820 {
821 for( size_t i = 0; i < selectedRows.size(); ++i )
822 {
823 if( selectedRows[i] == row )
824 return;
825 }
826
827 selectedRows.push_back( row );
828 };
829
830 wxGridCellCoordsArray topLeft = GetSelectionBlockTopLeft();
831 wxGridCellCoordsArray botRight = GetSelectionBlockBottomRight();
832
833 for( size_t i = 0; i < std::min( topLeft.Count(), botRight.Count() ); ++i )
834 {
835 for( int row = topLeft[i].GetRow(); row <= botRight[i].GetRow(); ++row )
836 addSelectedRow( row );
837 }
838
839 wxGridCellCoordsArray cells = GetSelectedCells();
840
841 for( size_t i = 0; i < cells.Count(); ++i )
842 addSelectedRow( cells[i].GetRow() );
843
844 if( selectedRows.empty() && GetGridCursorRow() >= 0 )
845 selectedRows.push_back( GetGridCursorRow() );
846
847 if( selectedRows.empty() )
848 return;
849
850 for( int row : selectedRows )
851 {
852 if( !aFilter( row ) )
853 return;
854 }
855
856 if( !CommitPendingChanges() )
857 return;
858
859 // Reverse sort so deleting a row doesn't change the indexes of the other rows.
860 selectedRows.Sort(
861 []( int* first, int* second )
862 {
863 return *second - *first;
864 } );
865
866 int nextSelRow = selectedRows.back() - 1;
867
868 if( nextSelRow >= 0 )
869 {
870 GoToCell( nextSelRow, GetGridCursorCol() );
871 SetGridCursor( nextSelRow, GetGridCursorCol() );
872 }
873
874 for( int row : selectedRows )
875 aDeleter( row );
876}
877
878
879void WX_GRID::SwapRows( int aRowA, int aRowB )
880{
881 for( int col = 0; col < GetNumberCols(); ++col )
882 {
883 wxString temp = GetCellValue( aRowA, col );
884 SetCellValue( aRowA, col, GetCellValue( aRowB, col ) );
885 SetCellValue( aRowB, col, temp );
886 }
887}
888
889
890void WX_GRID::OnMoveRowUp( const std::function<void( int row )>& aMover )
891{
893 []( int row )
894 {
895 return true;
896 },
897 aMover );
898}
899
900
901void WX_GRID::OnMoveRowUp( const std::function<bool( int row )>& aFilter,
902 const std::function<void( int row )>& aMover )
903{
904 if( !CommitPendingChanges() )
905 return;
906
907 int i = GetGridCursorRow();
908
909 if( i > 0 && aFilter( i ) )
910 {
911 aMover( i );
912
913 SetGridCursor( i - 1, GetGridCursorCol() );
914 MakeCellVisible( GetGridCursorRow(), GetGridCursorCol() );
915 }
916 else
917 {
918 wxBell();
919 }
920}
921
922
923void WX_GRID::OnMoveRowDown( const std::function<void( int row )>& aMover )
924{
926 []( int row )
927 {
928 return true;
929 },
930 aMover );
931}
932
933
934void WX_GRID::OnMoveRowDown( const std::function<bool( int row )>& aFilter,
935 const std::function<void( int row )>& aMover )
936{
937 if( !CommitPendingChanges() )
938 return;
939
940 int i = GetGridCursorRow();
941
942 if( i + 1 < GetNumberRows() && aFilter( i ) )
943 {
944 aMover( i );
945
946 SetGridCursor( i + 1, GetGridCursorCol() );
947 MakeCellVisible( GetGridCursorRow(), GetGridCursorCol() );
948 }
949 else
950 {
951 wxBell();
952 }
953}
954
955
956void WX_GRID::SetUnitsProvider( UNITS_PROVIDER* aProvider, int aCol )
957{
958 m_unitsProviders[ aCol ] = aProvider;
959
960 if( !m_eval )
961 m_eval = std::make_unique<NUMERIC_EVALUATOR>( aProvider->GetUserUnits() );
962}
963
964
965void WX_GRID::SetAutoEvalColUnits( const int col, EDA_UNITS aUnit, EDA_DATA_TYPE aUnitType )
966{
967 m_autoEvalColsUnits[col] = std::make_pair( aUnit, aUnitType );
968}
969
970
971void WX_GRID::SetAutoEvalColUnits( const int col, EDA_UNITS aUnit )
972{
974 SetAutoEvalColUnits( col, aUnit, type );
975}
976
977
978int WX_GRID::GetUnitValue( int aRow, int aCol )
979{
980 wxString stringValue = GetCellValue( aRow, aCol );
981
982 auto [cellUnits, cellDataType] = getColumnUnits( aCol );
983
984 if( alg::contains( m_autoEvalCols, aCol ) )
985 {
986 m_eval->SetDefaultUnits( cellUnits );
987
988 if( m_eval->Process( stringValue ) )
989 stringValue = m_eval->Result();
990 }
991
992 return getUnitsProvider( aCol )->ValueFromString( stringValue, cellDataType );
993}
994
995
996std::optional<int> WX_GRID::GetOptionalUnitValue( int aRow, int aCol )
997{
998 wxString stringValue = GetCellValue( aRow, aCol );
999
1000 auto [cellUnits, cellDataType] = getColumnUnits( aCol );
1001
1002 if( alg::contains( m_autoEvalCols, aCol ) )
1003 {
1004 m_eval->SetDefaultUnits( cellUnits );
1005
1006 if( stringValue != UNITS_PROVIDER::NullUiString && m_eval->Process( stringValue ) )
1007 stringValue = m_eval->Result();
1008 }
1009
1010 return getUnitsProvider( aCol )->OptionalValueFromString( stringValue, cellDataType );
1011}
1012
1013
1014void WX_GRID::SetUnitValue( int aRow, int aCol, int aValue )
1015{
1016 EDA_DATA_TYPE cellDataType;
1017
1018 if( m_autoEvalColsUnits.contains( aCol ) )
1019 cellDataType = m_autoEvalColsUnits[aCol].second;
1020 else
1021 cellDataType = EDA_DATA_TYPE::DISTANCE;
1022
1023 SetCellValue( aRow, aCol, getUnitsProvider( aCol )->StringFromValue( aValue, true, cellDataType ) );
1024}
1025
1026
1027void WX_GRID::SetOptionalUnitValue( int aRow, int aCol, std::optional<int> aValue )
1028{
1029 EDA_DATA_TYPE cellDataType;
1030
1031 if( m_autoEvalColsUnits.contains( aCol ) )
1032 cellDataType = m_autoEvalColsUnits[aCol].second;
1033 else
1034 cellDataType = EDA_DATA_TYPE::DISTANCE;
1035
1036 SetCellValue( aRow, aCol, getUnitsProvider( aCol )->StringFromOptionalValue( aValue, true, cellDataType ) );
1037}
1038
1039
1040void WX_GRID::onGridColMove( wxGridEvent& aEvent )
1041{
1042 // wxWidgets won't move an open editor, so better just to close it
1043 CommitPendingChanges( true );
1044}
1045
1046
1047int WX_GRID::GetVisibleWidth( int aCol, bool aHeader, bool aContents, bool aKeep )
1048{
1049 int size = 0;
1050
1051 if( aCol < 0 )
1052 {
1053 if( aKeep )
1054 size = GetRowLabelSize();
1055
1056 for( int row = 0; aContents && row < GetNumberRows(); row++ )
1057 size = std::max( size, int( GetTextExtent( GetRowLabelValue( row ) + wxS( "M" ) ).x ) );
1058 }
1059 else
1060 {
1061 if( aKeep )
1062 size = GetColSize( aCol );
1063
1064 // 'M' is generally the widest character, so we buffer the column width by default to
1065 // ensure we don't write a continuous line of text at the column header
1066 if( aHeader )
1067 {
1069
1070 size = std::max( size, int( GetTextExtent( GetColLabelValue( aCol ) + wxS( "M" ) ).x ) );
1071 }
1072
1073 for( int row = 0; aContents && row < GetNumberRows(); row++ )
1074 {
1075 // If we have text, get the size. Otherwise, use a placeholder for the checkbox
1076 if( GetTable()->CanGetValueAs( row, aCol, wxGRID_VALUE_STRING ) )
1077 size = std::max( size, GetTextExtent( GetCellValue( row, aCol ) + wxS( "M" ) ).x );
1078 else
1079 size = std::max( size, GetTextExtent( "MM" ).x );
1080 }
1081 }
1082
1083 return size;
1084}
1085
1086
1088{
1089 int line_height = int( GetTextExtent( "Mj" ).y ) + 3;
1090 int row_height = GetColLabelSize();
1091 int initial_row_height = row_height;
1092
1093 // Headers can be multiline. Fix the Column Label Height to show the full header
1094 // However GetTextExtent does not work on multiline strings,
1095 // and do not return the full text height (only the height of one line)
1096 for( int col = 0; col < GetNumberCols(); col++ )
1097 {
1098 int nl_count = GetColLabelValue( col ).Freq( '\n' );
1099
1100 if( nl_count )
1101 {
1102 // Col Label height must be able to show nl_count+1 lines
1103 if( row_height < line_height * ( nl_count+1 ) )
1104 row_height += line_height * nl_count;
1105 }
1106 }
1107
1108 // Update the column label size, but only if needed, to avoid generating useless
1109 // and perhaps annoying UI events when the size does not change
1110 if( initial_row_height != row_height )
1111 SetColLabelSize( row_height );
1112}
1113
1114
1115std::pair<EDA_UNITS, EDA_DATA_TYPE> WX_GRID::getColumnUnits( const int aCol ) const
1116{
1117 if( m_autoEvalColsUnits.contains( aCol ) )
1118 return { m_autoEvalColsUnits.at( aCol ).first, m_autoEvalColsUnits.at( aCol ).second };
1119
1120 // Legacy - default always DISTANCE
1122}
1123
1124
1125void WX_GRID::SetupColumnAutosizer( int aFlexibleCol )
1126{
1127 const int colCount = GetNumberCols();
1128
1129 for( int ii = 0; ii < GetNumberCols(); ++ii )
1130 m_autosizedCols[ii] = GetColSize( ii );
1131
1132 m_flexibleCol = aFlexibleCol;
1133
1134 wxASSERT_MSG( m_flexibleCol < colCount, "Flexible column index does not exist in grid" );
1135
1136 Bind( wxEVT_UPDATE_UI,
1137 [this]( wxUpdateUIEvent& aEvent )
1138 {
1140 aEvent.Skip();
1141 } );
1142
1143 Bind( wxEVT_SIZE,
1144 [this]( wxSizeEvent& aEvent )
1145 {
1146 onSizeEvent( aEvent );
1147 aEvent.Skip();
1148 } );
1149
1150 // Handles the case when the user changes the cell content to be longer than the current column size
1151 Bind( wxEVT_GRID_CELL_CHANGED,
1152 [this]( wxGridEvent& aEvent )
1153 {
1154 m_gridWidthsDirty = true;
1155 aEvent.Skip();
1156 } );
1157}
1158
1159
1161{
1162 if( m_gridWidthsDirty )
1163 {
1164 const int width = GetSize().GetX() - wxSystemSettings::GetMetric( wxSYS_VSCROLL_X );
1165
1166 std::optional<int> flexibleMinWidth;
1167
1168 for( const auto& [colIndex, minWidth] : m_autosizedCols )
1169 {
1170 if( GetColSize( colIndex ) != 0 )
1171 {
1172 AutoSizeColumn( colIndex );
1173 const int colSize = GetColSize( colIndex );
1174
1175 int minWidthScaled = FromDIP( minWidth );
1176 SetColSize( colIndex, std::max( minWidthScaled, colSize ) );
1177
1178 if( colIndex == m_flexibleCol )
1179 flexibleMinWidth = minWidthScaled;
1180 }
1181 }
1182
1183 // Gather all the widths except the flexi one
1184 int nonFlexibleWidth = 0;
1185
1186 for( int i = 0; i < GetNumberCols(); ++i )
1187 {
1188 if( i != m_flexibleCol )
1189 nonFlexibleWidth += GetColSize( i );
1190 }
1191
1192 if( GetColSize( m_flexibleCol ) != 0 )
1193 SetColSize( m_flexibleCol, std::max( flexibleMinWidth.value_or( 0 ), width - nonFlexibleWidth ) );
1194
1195 // Store the state for next time
1196 m_gridWidth = GetSize().GetX();
1197 m_gridWidthsDirty = false;
1198 }
1199}
1200
1201
1202void WX_GRID::onSizeEvent( wxSizeEvent& aEvent )
1203{
1204 const int width = aEvent.GetSize().GetX();
1205
1206 if( width != m_gridWidth )
1207 m_gridWidthsDirty = true;
1208}
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:1047
int m_flexibleCol
Definition wx_grid.h:400
void onGridCellSelect(wxGridEvent &aEvent)
Definition wx_grid.cpp:404
std::map< int, int > m_autosizedCols
Definition wx_grid.h:399
bool m_gridWidthsDirty
Definition wx_grid.h:402
~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:389
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:596
void OnMoveRowUp(const std::function< void(int row)> &aMover)
Definition wx_grid.cpp:890
std::map< int, UNITS_PROVIDER * > m_unitsProviders
Definition wx_grid.h:391
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:548
std::unordered_map< int, std::pair< EDA_UNITS, EDA_DATA_TYPE > > m_autoEvalColsUnits
Definition wx_grid.h:394
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:965
bool CancelPendingChanges()
Definition wx_grid.cpp:703
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:879
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:1115
void SetUnitValue(int aRow, int aCol, int aValue)
Set a unitized cell's value.
Definition wx_grid.cpp:1014
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:978
std::vector< int > m_autoEvalCols
Definition wx_grid.h:393
UNITS_PROVIDER * getUnitsProvider(int aCol) const
Definition wx_grid.h:372
std::map< std::pair< int, int >, std::pair< wxString, wxString > > m_evalBeforeAfter
Definition wx_grid.h:395
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:614
ROW_ICON_PROVIDER * m_rowIconProvider
Definition wx_grid.h:405
void onCellEditorHidden(wxGridEvent &aEvent)
Definition wx_grid.cpp:466
void SetupColumnAutosizer(int aFlexibleCol)
Set autosize behaviour using wxFormBuilder column widths as minimums, with a single specified growabl...
Definition wx_grid.cpp:1125
void RecomputeGridWidths()
Definition wx_grid.cpp:1160
void OnMoveRowDown(const std::function< void(int row)> &aMover)
Definition wx_grid.cpp:923
void onGridColMove(wxGridEvent &aEvent)
Definition wx_grid.cpp:1040
void SetOptionalUnitValue(int aRow, int aCol, std::optional< int > aValue)
Set a unitized cell's optional value.
Definition wx_grid.cpp:1027
void onSizeEvent(wxSizeEvent &aEvent)
Definition wx_grid.cpp:1202
void onCellEditorShown(wxGridEvent &aEvent)
Definition wx_grid.cpp:451
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition wx_grid.cpp:1087
void OnDeleteRows(const std::function< void(int row)> &aDeleter)
Handles a row deletion event.
Definition wx_grid.cpp:803
wxString GetShownColumnsAsString()
Get a tokenized string containing the shown column indexes.
Definition wx_grid.cpp:566
void OnAddRow(const std::function< std::pair< int, int >()> &aAdder)
Definition wx_grid.cpp:783
int m_gridWidth
Definition wx_grid.h:403
void DrawRowLabel(wxDC &dc, int row) override
A re-implementation of wxGrid::DrawRowLabel which draws flat borders.
Definition wx_grid.cpp:672
std::bitset< 64 > GetShownColumns()
Definition wx_grid.cpp:585
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:996
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:956
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition wx_grid.cpp:731
std::unique_ptr< NUMERIC_EVALUATOR > m_eval
Definition wx_grid.h:392
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:634
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