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