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