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#ifdef wxHAS_DPI_INDEPENDENT_PIXELS
303 const wxGridSizesInfo savedColSizes = GetColSizes();
304 const wxGridSizesInfo savedRowSizes = GetRowSizes();
305#endif
306
307 aEvt.Skip();
308
309#ifdef wxHAS_DPI_INDEPENDENT_PIXELS
310 CallAfter(
311 [this, savedColSizes, savedRowSizes]()
312 {
313 BeginBatch();
314
315 for( const auto& [col, size] : savedColSizes.m_customSizes )
316 {
317 if( size > 0 && static_cast<int>( col ) < GetNumberCols() )
318 SetColSize( col, size );
319 }
320
321 for( const auto& [row, size] : savedRowSizes.m_customSizes )
322 {
323 if( size > 0 && static_cast<int>( row ) < GetNumberRows() )
324 SetRowSize( row, size );
325 }
326
327 EndBatch();
328 } );
329#endif
330
331 if( !hiddenCols.empty() )
332 {
333 CallAfter(
334 [this, hiddenCols]()
335 {
336 for( int col : hiddenCols )
337 {
338 ShowCol( col );
339 HideCol( col );
340 }
341
342 ForceRefresh();
343 } );
344 }
345
346 CallAfter(
347 [this]()
348 {
349 wxGrid::SetColLabelSize( wxGRID_AUTOSIZE );
350 } );
351}
352
353
354void WX_GRID::SetColLabelSize( int aHeight )
355{
356 if( aHeight == 0 || aHeight == wxGRID_AUTOSIZE )
357 {
358 wxGrid::SetColLabelSize( aHeight );
359 return;
360 }
361
362 // Correct wxFormBuilder height for large fonts
363 int minHeight = GetCharHeight() + 2 * MIN_GRIDCELL_MARGIN;
364
365 wxGrid::SetColLabelSize( std::max( aHeight, minHeight ) );
366}
367
368
369void WX_GRID::SetLabelFont( const wxFont& aFont )
370{
371 wxGrid::SetLabelFont( KIUI::GetControlFont( this ) );
372}
373
374
375void WX_GRID::SetTable( wxGridTableBase* aTable, bool aTakeOwnership )
376{
377 // wxGrid::SetTable() messes up the column widths from wxFormBuilder so we have to save
378 // and restore them.
379 int numberCols = GetNumberCols();
380 int* formBuilderColWidths = new int[numberCols];
381
382 for( int i = 0; i < numberCols; ++i )
383 formBuilderColWidths[ i ] = GetColSize( i );
384
385 wxGrid::SetTable( aTable );
386
387 // wxGrid::SetTable() may change the number of columns, so prevent out-of-bounds access
388 // to formBuilderColWidths
389 numberCols = std::min( numberCols, GetNumberCols() );
390
391 for( int i = 0; i < numberCols; ++i )
392 {
393 // correct wxFormBuilder width for large fonts and/or long translations
394 int headingWidth = GetTextExtent( GetColLabelValue( i ) ).x + 2 * MIN_GRIDCELL_MARGIN;
395
396 SetColSize( i, std::max( formBuilderColWidths[ i ], headingWidth ) );
397 }
398
399 delete[] formBuilderColWidths;
400
401 EnableAlternateRowColors( Pgm().GetCommonSettings() && Pgm().GetCommonSettings()->m_Appearance.grid_striping );
402
403 Connect( wxEVT_GRID_COL_MOVE, wxGridEventHandler( WX_GRID::onGridColMove ), nullptr, this );
404 Connect( wxEVT_GRID_SELECT_CELL, wxGridEventHandler( WX_GRID::onGridCellSelect ), nullptr, this );
405
406#ifdef __WXMSW__
407 Connect( wxEVT_IDLE, wxIdleEventHandler( WX_GRID::onIdleRefreshHighlight ), nullptr, this );
408#endif
409
410 m_weOwnTable = aTakeOwnership;
411}
412
413
415{
416 wxGridTableBase* table = wxGrid::GetTable();
417
418 wxCHECK_MSG( table, /* void */, "Tried to enable alternate row colors without a table assigned to the grid" );
419
420 if( aEnable )
421 {
422 wxColor color = wxGrid::GetDefaultCellBackgroundColour();
423 table->SetAttrProvider( new WX_GRID_ALT_ROW_COLOR_PROVIDER( color ) );
424 }
425 else
426 {
427 table->SetAttrProvider( nullptr );
428 }
429}
430
431
432void WX_GRID::onGridCellSelect( wxGridEvent& aEvent )
433{
435 {
436 aEvent.Skip();
437 return;
438 }
439
440 // Highlight the selected cell.
441 // Calling SelectBlock() allows a visual effect when cells are selected by tab or arrow keys.
442 // Otherwise, one cannot really know what actual cell is selected.
443 int row = aEvent.GetRow();
444 int col = aEvent.GetCol();
445
446 if( row >= 0 && row < GetNumberRows() && col >= 0 && col < GetNumberCols() )
447 {
448 if( GetSelectionMode() == wxGrid::wxGridSelectCells )
449 {
450 SelectBlock( row, col, row, col, false );
451 }
452 else if( GetSelectionMode() == wxGrid::wxGridSelectRows
453 || GetSelectionMode() == wxGrid::wxGridSelectRowsOrColumns )
454 {
455 SelectBlock( row, 0, row, GetNumberCols() - 1, false );
456 }
457 else if( GetSelectionMode() == wxGrid::wxGridSelectColumns )
458 {
459 SelectBlock( 0, col, GetNumberRows() - 1, col, false );
460 }
461
463 ForceRefresh();
464 }
465}
466
467
468#ifdef __WXMSW__
469void WX_GRID::onIdleRefreshHighlight( wxIdleEvent& aEvent )
470{
471 aEvent.Skip();
472
473 // On Windows with wxWidgets 3.3+, the selection highlight is drawn with stale geometry the
474 // first time the grid is displayed, because wxGrid derives the highlight rectangle from a
475 // layout that isn't finalized until the grid is actually on screen. Wait until the grid is
476 // genuinely visible before forcing the corrective redraw, so a grid living on an inactive
477 // notebook page (e.g. opening the dialog on the "3D Models" page) is still corrected when the
478 // user switches to it. The handler removes itself once the one-time refresh has run.
479 if( !IsShownOnScreen() )
480 return;
481
482 Disconnect( wxEVT_IDLE, wxIdleEventHandler( WX_GRID::onIdleRefreshHighlight ), nullptr, this );
483 ForceRefresh();
484}
485#endif
486
487
488void WX_GRID::onCellEditorShown( wxGridEvent& aEvent )
489{
490 // wxGrid slides the editor of a partially visible cell left or up until it fits, covering
491 // the neighbouring cells, so scroll the whole cell into view before the editor is placed
492 MakeCellVisible( aEvent.GetRow(), aEvent.GetCol() );
493
494 if( alg::contains( m_autoEvalCols, aEvent.GetCol() ) )
495 {
496 int row = aEvent.GetRow();
497 int col = aEvent.GetCol();
498
499 const std::pair<wxString, wxString>& beforeAfter = m_evalBeforeAfter[ { row, col } ];
500
501 if( GetCellValue( row, col ) == beforeAfter.second )
502 SetCellValue( row, col, beforeAfter.first );
503 }
504}
505
506
507void WX_GRID::onCellEditorHidden( wxGridEvent& aEvent )
508{
509 EvaluateCell( aEvent.GetRow(), aEvent.GetCol() );
510 aEvent.Skip();
511}
512
513
514void WX_GRID::EvaluateCell( int aRow, int aCol )
515{
516 const int col = aCol;
517
518 if( alg::contains( m_autoEvalCols, col ) )
519 {
520 UNITS_PROVIDER* unitsProvider = getUnitsProvider( col );
521
522 auto cellUnitsData = getColumnUnits( col );
523 EDA_UNITS cellUnits = cellUnitsData.first;
524 EDA_DATA_TYPE cellDataType = cellUnitsData.second;
525
526 m_eval->SetDefaultUnits( cellUnits );
527
528 const int row = aRow;
529
530 // Determine if this cell is marked as holding nullable values
531 bool isNullable = false;
532 wxGridCellEditor* cellEditor = GetCellEditor( row, col );
533
534 if( cellEditor )
535 {
536 if( const GRID_CELL_NULLABLE_INTERFACE* nullable =
537 dynamic_cast<GRID_CELL_NULLABLE_INTERFACE*>( cellEditor ) )
538 isNullable = nullable->IsNullable();
539
540 cellEditor->DecRef();
541 }
542
543 CallAfter(
544 [this, row, col, isNullable, unitsProvider, cellDataType]()
545 {
546 // Careful; if called from CommitPendingChange() in a delete operation, the cell may
547 // no longer exist.
548 if( row >= GetNumberRows() || col >= GetNumberCols() )
549 return;
550
551 wxString stringValue = GetCellValue( row, col );
552 bool processedOk = true;
553
554 if( stringValue != UNITS_PROVIDER::NullUiString )
555 processedOk = m_eval->Process( stringValue );
556
557 if( processedOk )
558 {
559 wxString evalValue;
560
561 if( isNullable )
562 {
563 std::optional<int> val;
564
565 if( stringValue == UNITS_PROVIDER::NullUiString )
566 {
568 cellDataType );
569 }
570 else
571 {
572 val = unitsProvider->OptionalValueFromString( m_eval->Result(), cellDataType );
573 }
574
575 evalValue = unitsProvider->StringFromOptionalValue( val, true, cellDataType );
576 }
577 else
578 {
579 int val = unitsProvider->ValueFromString( m_eval->Result(), cellDataType );
580 evalValue = unitsProvider->StringFromValue( val, true, cellDataType );
581 }
582
583 if( stringValue != evalValue )
584 {
585 SetCellValue( row, col, evalValue );
586 m_evalBeforeAfter[{ row, col }] = { stringValue, evalValue };
587 }
588 }
589 } );
590 }
591}
592
593
594void WX_GRID::DestroyTable( wxGridTableBase* aTable )
595{
596 // wxGrid's destructor will crash trying to look up the cell attr if the edit control
597 // is left open. Normally it's closed in Validate(), but not if the user hit Cancel.
598 CommitPendingChanges( true /* quiet mode */ );
599
600 Disconnect( wxEVT_GRID_COL_MOVE, wxGridEventHandler( WX_GRID::onGridColMove ), nullptr, this );
601 Disconnect( wxEVT_GRID_SELECT_CELL, wxGridEventHandler( WX_GRID::onGridCellSelect ), nullptr, this );
602
603#ifdef __WXMSW__
604 Disconnect( wxEVT_IDLE, wxIdleEventHandler( WX_GRID::onIdleRefreshHighlight ), nullptr, this );
605#endif
606
607 wxGrid::SetTable( nullptr );
608 delete aTable;
609}
610
611
613{
614 wxString shownColumns;
615
616 for( int i = 0; i < GetNumberCols(); ++i )
617 {
618 if( IsColShown( i ) )
619 {
620 if( shownColumns.Length() )
621 shownColumns << wxT( " " );
622
623 shownColumns << i;
624 }
625 }
626
627 return shownColumns;
628}
629
630
632{
633 std::bitset<64> shownColumns;
634
635 for( int ii = 0; ii < GetNumberCols(); ++ii )
636 shownColumns[ii] = IsColShown( ii );
637
638 return shownColumns;
639}
640
641
642void WX_GRID::ShowHideColumns( const wxString& shownColumns )
643{
644 for( int i = 0; i < GetNumberCols(); ++i )
645 HideCol( i );
646
647 wxStringTokenizer shownTokens( shownColumns, " \t\r\n", wxTOKEN_STRTOK );
648
649 while( shownTokens.HasMoreTokens() )
650 {
651 long colNumber;
652 shownTokens.GetNextToken().ToLong( &colNumber );
653
654 if( colNumber >= 0 && colNumber < GetNumberCols() )
655 ShowCol( (int) colNumber );
656 }
657}
658
659
661{
662 if( m_nativeColumnLabels )
663 wxGrid::DrawCornerLabel( dc );
664
665 wxRect rect( wxSize( m_rowLabelWidth, m_colLabelHeight ) );
666
668
669 // It is reported that we need to erase the background to avoid display artifacts; see #12055.
670 {
671 wxDCBrushChanger setBrush( dc, m_colLabelWin->GetBackgroundColour() );
672 wxDCPenChanger setPen( dc, m_colLabelWin->GetBackgroundColour() );
673 dc.DrawRectangle( rect.Inflate( 1 ) );
674 }
675
676 rend.DrawBorder( *this, dc, rect );
677}
678
679
680void WX_GRID::DrawColLabel( wxDC& dc, int col )
681{
682 if( m_nativeColumnLabels )
683 wxGrid::DrawColLabel( dc, col );
684
685 if( GetColWidth( col ) <= 0 || m_colLabelHeight <= 0 )
686 return;
687
688 wxRect rect( GetColLeft( col ), 0, GetColWidth( col ), m_colLabelHeight );
689
691
692 // It is reported that we need to erase the background to avoid display artifacts; see #12055.
693 {
694 wxDCBrushChanger setBrush( dc, m_colLabelWin->GetBackgroundColour() );
695 wxDCPenChanger setPen( dc, m_colLabelWin->GetBackgroundColour() );
696 dc.DrawRectangle( rect.Inflate( 1 ) );
697 }
698
699 rend.DrawBorder( *this, dc, rect );
700
701 // Make sure fonts get scaled correctly on GTK HiDPI monitors
702 dc.SetFont( GetLabelFont() );
703
704 int hAlign, vAlign;
705 GetColLabelAlignment( &hAlign, &vAlign );
706 const int orient = GetColLabelTextOrientation();
707
708 if( col == 0 )
709 hAlign = wxALIGN_LEFT;
710
711 if( hAlign == wxALIGN_LEFT )
712 rect.SetLeft( rect.GetLeft() + MIN_GRIDCELL_MARGIN );
713
714 rend.DrawLabel( *this, dc, GetColLabelValue( col ), rect, hAlign, vAlign, orient );
715}
716
717
718void WX_GRID::DrawRowLabel( wxDC& dc, int row )
719{
720 if( GetRowHeight( row ) <= 0 || m_rowLabelWidth <= 0 )
721 return;
722
723 wxRect rect( 0, GetRowTop( row ), m_rowLabelWidth, GetRowHeight( row ) );
724
725 static WX_GRID_ROW_HEADER_RENDERER rend;
726
727 // It is reported that we need to erase the background to avoid display artifacts; see #12055.
728 {
729 wxDCBrushChanger setBrush( dc, m_colLabelWin->GetBackgroundColour() );
730 wxDCPenChanger setPen( dc, m_colLabelWin->GetBackgroundColour() );
731 dc.DrawRectangle( rect.Inflate( 1 ) );
732 }
733
734 rend.DrawBorder( *this, dc, rect );
735
736 if( auto* table = dynamic_cast<WX_GRID_TABLE_BASE*>( GetTable() ); table && table->HasRowLabelExpanders() )
737 {
738 ROW_STATE state = table->GetRowState( row );
739
740 if( IsRowCollapsed( state ) || IsRowExpanded( state ) )
741 {
742 wxBitmap bitmap = m_rowIconProvider->GetIndicatorIcon( IsRowCollapsed( state ) ? ROW_ICON_PROVIDER::CLOSED
744 bitmap.SetScaleFactor( KIPLATFORM::UI::GetPixelScaleFactor( this ) );
745
746 dc.DrawBitmap( bitmap, rect.GetLeft() + ( rect.GetWidth() - bitmap.GetLogicalWidth() ) / 2,
747 rect.GetTop() + ( rect.GetHeight() - bitmap.GetLogicalHeight() ) / 2, true );
748 }
749 else if( state == ROW_STATE::EXPANDED_CHILD )
750 {
751 // Keep the hierarchy in the gutter so all field text stays aligned.
752 wxDCPenChanger setPen( dc, wxPen( GetLabelTextColour(), FromDIP( 1 ) ) );
753 wxPoint center( rect.GetLeft() + rect.GetWidth() / 2, rect.GetTop() + rect.GetHeight() / 2 );
754 bool moreChildren = row + 1 < GetNumberRows()
755 && table->GetRowState( row + 1 ) == ROW_STATE::EXPANDED_CHILD;
756
757 dc.DrawLine( center.x, rect.GetTop(), center.x, moreChildren ? rect.GetBottom() + 1 : center.y );
758 dc.DrawLine( center.x, center.y, rect.GetRight() - FromDIP( 4 ), center.y );
759 }
760
761 return;
762 }
763
764 // Make sure fonts get scaled correctly on GTK HiDPI monitors
765 dc.SetFont( GetLabelFont() );
766
767 int hAlign, vAlign;
768 GetRowLabelAlignment(&hAlign, &vAlign);
769
770 if( hAlign == wxALIGN_LEFT )
771 rect.SetLeft( rect.GetLeft() + MIN_GRIDCELL_MARGIN );
772
773 rend.DrawLabel( *this, dc, GetRowLabelValue( row ), rect, hAlign, vAlign, wxHORIZONTAL );
774}
775
776
778{
779 if( !IsCellEditControlEnabled() )
780 return true;
781
782 HideCellEditControl();
783
784 // do it after HideCellEditControl()
785 m_cellEditCtrlEnabled = false;
786
787 int row = m_currentCellCoords.GetRow();
788 int col = m_currentCellCoords.GetCol();
789
790 wxString oldval = GetCellValue( row, col );
791 wxString newval;
792
793 wxGridCellAttr* attr = GetCellAttr( row, col );
794 wxGridCellEditor* editor = attr->GetEditor( this, row, col );
795
796 editor->EndEdit( row, col, this, oldval, &newval );
797
798 editor->DecRef();
799 attr->DecRef();
800
801 return true;
802}
803
804
805bool WX_GRID::CommitPendingChanges( bool aQuietMode )
806{
807 if( !IsCellEditControlEnabled() )
808 return true;
809
810 if( !aQuietMode && SendEvent( wxEVT_GRID_EDITOR_HIDDEN ) == -1 )
811 return false;
812
813 HideCellEditControl();
814
815 // do it after HideCellEditControl()
816 m_cellEditCtrlEnabled = false;
817
818 int row = m_currentCellCoords.GetRow();
819 int col = m_currentCellCoords.GetCol();
820
821 wxString oldval = GetCellValue( row, col );
822 wxString newval;
823
824 wxGridCellAttr* attr = GetCellAttr( row, col );
825 wxGridCellEditor* editor = attr->GetEditor( this, row, col );
826
827 bool changed = editor->EndEdit( row, col, this, oldval, &newval );
828
829 editor->DecRef();
830 attr->DecRef();
831
832 if( changed )
833 {
834 if( !aQuietMode && SendEvent( wxEVT_GRID_CELL_CHANGING, newval ) == -1 )
835 return false;
836
837 editor->ApplyEdit( row, col, this );
838
839 // for compatibility reasons dating back to wx 2.8 when this event
840 // was called wxEVT_GRID_CELL_CHANGE and wxEVT_GRID_CELL_CHANGING
841 // didn't exist we allow vetoing this one too
842 if( !aQuietMode && SendEvent( wxEVT_GRID_CELL_CHANGED, oldval ) == -1 )
843 {
844 // Event has been vetoed, set the data back.
845 SetCellValue( row, col, oldval );
846 return false;
847 }
848
849 if( DIALOG_SHIM* dlg = dynamic_cast<DIALOG_SHIM*>( wxGetTopLevelParent( this ) ) )
850 dlg->OnModify();
851 }
852
853 return true;
854}
855
856
857void WX_GRID::OnAddRow( const std::function<std::pair<int, int>()>& aAdder )
858{
859 if( !CommitPendingChanges() )
860 return;
861
862 auto [row, editCol] = aAdder();
863
864 // wx documentation is wrong, SetGridCursor does not make visible.
865 SetFocus();
866 MakeCellVisible( row, std::max( editCol, 0 ) );
867 SetGridCursor( row, std::max( editCol, 0 ) );
868
869 if( editCol >= 0 )
870 {
871 EnableCellEditControl( true );
872 ShowCellEditControl();
873 }
874}
875
876
877void WX_GRID::OnDeleteRows( const std::function<void( int row )>& aDeleter )
878{
880 []( int row )
881 {
882 return true;
883 },
884 aDeleter );
885}
886
887
888void WX_GRID::OnDeleteRows( const std::function<bool( int row )>& aFilter,
889 const std::function<void( int row )>& aDeleter )
890{
891 std::vector<int> selectedRows = GetSelectedRowIndices();
892
893 if( selectedRows.empty() )
894 return;
895
896 for( int row : selectedRows )
897 {
898 if( !aFilter( row ) )
899 return;
900 }
901
902 if( !CommitPendingChanges() )
903 return;
904
905 // Reverse sort so deleting a row doesn't change the indexes of the other rows.
906 std::sort( selectedRows.rbegin(), selectedRows.rend() );
907
908 int nextSelRow = selectedRows.back() - 1;
909
910 if( nextSelRow >= 0 )
911 {
912 GoToCell( nextSelRow, GetGridCursorCol() );
913 SetGridCursor( nextSelRow, GetGridCursorCol() );
914 }
915
916 for( int row : selectedRows )
917 aDeleter( row );
918}
919
920
921std::vector<int> WX_GRID::GetSelectedRowIndices() const
922{
923 std::vector<bool> selected( GetNumberRows(), false );
924
925 for( const wxGridBlockCoords& block : GetSelectedBlocks() )
926 {
927 for( int row = block.GetTopRow(); row <= block.GetBottomRow(); ++row )
928 selected[row] = true;
929 }
930
931 std::vector<int> rows;
932
933 for( int row = 0; row < GetNumberRows(); ++row )
934 {
935 if( selected[row] )
936 rows.push_back( row );
937 }
938
939 if( rows.empty() && GetGridCursorRow() >= 0 )
940 rows.push_back( GetGridCursorRow() );
941
942 return rows;
943}
944
945
946void WX_GRID::SwapRows( int aRowA, int aRowB )
947{
948 for( int col = 0; col < GetNumberCols(); ++col )
949 {
950 wxString temp = GetCellValue( aRowA, col );
951 SetCellValue( aRowA, col, GetCellValue( aRowB, col ) );
952 SetCellValue( aRowB, col, temp );
953 }
954}
955
956
957void WX_GRID::OnMoveRowUp( const std::function<void( int row )>& aMover )
958{
960 []( int row )
961 {
962 return true;
963 },
964 aMover );
965}
966
967
968void WX_GRID::OnMoveRowUp( const std::function<bool( int row )>& aFilter,
969 const std::function<void( int row )>& aMover )
970{
971 if( !CommitPendingChanges() )
972 return;
973
974 int i = GetGridCursorRow();
975
976 if( i > 0 && aFilter( i ) )
977 {
978 aMover( i );
979
980 SetGridCursor( i - 1, GetGridCursorCol() );
981 MakeCellVisible( GetGridCursorRow(), GetGridCursorCol() );
982 }
983 else
984 {
985 wxBell();
986 }
987}
988
989
990void WX_GRID::OnMoveRowDown( const std::function<void( int row )>& aMover )
991{
993 []( int row )
994 {
995 return true;
996 },
997 aMover );
998}
999
1000
1001void WX_GRID::OnMoveRowDown( const std::function<bool( int row )>& aFilter,
1002 const std::function<void( int row )>& aMover )
1003{
1004 if( !CommitPendingChanges() )
1005 return;
1006
1007 int i = GetGridCursorRow();
1008
1009 if( i + 1 < GetNumberRows() && aFilter( i ) )
1010 {
1011 aMover( i );
1012
1013 SetGridCursor( i + 1, GetGridCursorCol() );
1014 MakeCellVisible( GetGridCursorRow(), GetGridCursorCol() );
1015 }
1016 else
1017 {
1018 wxBell();
1019 }
1020}
1021
1022
1023void WX_GRID::SetUnitsProvider( UNITS_PROVIDER* aProvider, int aCol )
1024{
1025 m_unitsProviders[ aCol ] = aProvider;
1026
1027 if( !m_eval )
1028 m_eval = std::make_unique<NUMERIC_EVALUATOR>( aProvider->GetUserUnits() );
1029}
1030
1031
1032void WX_GRID::SetAutoEvalColUnits( const int col, EDA_UNITS aUnit, EDA_DATA_TYPE aUnitType )
1033{
1034 m_autoEvalColsUnits[col] = std::make_pair( aUnit, aUnitType );
1035}
1036
1037
1038void WX_GRID::SetAutoEvalColUnits( const int col, EDA_UNITS aUnit )
1039{
1040 const EDA_DATA_TYPE type = UNITS_PROVIDER::GetTypeFromUnits( aUnit );
1041 SetAutoEvalColUnits( col, aUnit, type );
1042}
1043
1044
1045int WX_GRID::GetUnitValue( int aRow, int aCol )
1046{
1047 wxString stringValue = GetCellValue( aRow, aCol );
1048
1049 auto [cellUnits, cellDataType] = getColumnUnits( aCol );
1050
1051 if( alg::contains( m_autoEvalCols, aCol ) )
1052 {
1053 m_eval->SetDefaultUnits( cellUnits );
1054
1055 if( m_eval->Process( stringValue ) )
1056 stringValue = m_eval->Result();
1057 }
1058
1059 return getUnitsProvider( aCol )->ValueFromString( stringValue, cellDataType );
1060}
1061
1062
1063std::optional<int> WX_GRID::GetOptionalUnitValue( int aRow, int aCol )
1064{
1065 wxString stringValue = GetCellValue( aRow, aCol );
1066
1067 auto [cellUnits, cellDataType] = getColumnUnits( aCol );
1068
1069 if( alg::contains( m_autoEvalCols, aCol ) )
1070 {
1071 m_eval->SetDefaultUnits( cellUnits );
1072
1073 if( stringValue != UNITS_PROVIDER::NullUiString && m_eval->Process( stringValue ) )
1074 stringValue = m_eval->Result();
1075 }
1076
1077 return getUnitsProvider( aCol )->OptionalValueFromString( stringValue, cellDataType );
1078}
1079
1080
1081void WX_GRID::SetUnitValue( int aRow, int aCol, int aValue )
1082{
1083 EDA_DATA_TYPE cellDataType;
1084
1085 if( m_autoEvalColsUnits.contains( aCol ) )
1086 cellDataType = m_autoEvalColsUnits[aCol].second;
1087 else
1088 cellDataType = EDA_DATA_TYPE::DISTANCE;
1089
1090 SetCellValue( aRow, aCol, getUnitsProvider( aCol )->StringFromValue( aValue, true, cellDataType ) );
1091}
1092
1093
1094void WX_GRID::SetOptionalUnitValue( int aRow, int aCol, std::optional<int> aValue )
1095{
1096 EDA_DATA_TYPE cellDataType;
1097
1098 if( m_autoEvalColsUnits.contains( aCol ) )
1099 cellDataType = m_autoEvalColsUnits[aCol].second;
1100 else
1101 cellDataType = EDA_DATA_TYPE::DISTANCE;
1102
1103 SetCellValue( aRow, aCol, getUnitsProvider( aCol )->StringFromOptionalValue( aValue, true, cellDataType ) );
1104}
1105
1106
1107void WX_GRID::onGridColMove( wxGridEvent& aEvent )
1108{
1109 // wxWidgets won't move an open editor, so better just to close it
1110 CommitPendingChanges( true );
1111}
1112
1113
1114int WX_GRID::GetVisibleWidth( int aCol, bool aHeader, bool aContents, bool aKeep )
1115{
1116 int size = 0;
1117
1118 if( aCol < 0 )
1119 {
1120 if( aKeep )
1121 size = GetRowLabelSize();
1122
1123 for( int row = 0; aContents && row < GetNumberRows(); row++ )
1124 size = std::max( size, int( GetTextExtent( GetRowLabelValue( row ) + wxS( "M" ) ).x ) );
1125 }
1126 else
1127 {
1128 if( aKeep )
1129 size = GetColSize( aCol );
1130
1131 // 'M' is generally the widest character, so we buffer the column width by default to
1132 // ensure we don't write a continuous line of text at the column header
1133 if( aHeader )
1134 {
1136
1137 size = std::max( size, int( GetTextExtent( GetColLabelValue( aCol ) + wxS( "M" ) ).x ) );
1138 }
1139
1140 for( int row = 0; aContents && row < GetNumberRows(); row++ )
1141 {
1142 // If we have text, get the size. Otherwise, use a placeholder for the checkbox
1143 if( GetTable()->CanGetValueAs( row, aCol, wxGRID_VALUE_STRING ) )
1144 size = std::max( size, GetTextExtent( GetCellValue( row, aCol ) + wxS( "M" ) ).x );
1145 else
1146 size = std::max( size, GetTextExtent( "MM" ).x );
1147 }
1148 }
1149
1150 return size;
1151}
1152
1153
1155{
1156 int line_height = int( GetTextExtent( "Mj" ).y ) + 3;
1157 int row_height = GetColLabelSize();
1158 int initial_row_height = row_height;
1159
1160 // Headers can be multiline. Fix the Column Label Height to show the full header
1161 // However GetTextExtent does not work on multiline strings,
1162 // and do not return the full text height (only the height of one line)
1163 for( int col = 0; col < GetNumberCols(); col++ )
1164 {
1165 int nl_count = GetColLabelValue( col ).Freq( '\n' );
1166
1167 if( nl_count )
1168 {
1169 // Col Label height must be able to show nl_count+1 lines
1170 if( row_height < line_height * ( nl_count+1 ) )
1171 row_height += line_height * nl_count;
1172 }
1173 }
1174
1175 // Update the column label size, but only if needed, to avoid generating useless
1176 // and perhaps annoying UI events when the size does not change
1177 if( initial_row_height != row_height )
1178 SetColLabelSize( row_height );
1179}
1180
1181
1182std::pair<EDA_UNITS, EDA_DATA_TYPE> WX_GRID::getColumnUnits( const int aCol ) const
1183{
1184 if( m_autoEvalColsUnits.contains( aCol ) )
1185 return { m_autoEvalColsUnits.at( aCol ).first, m_autoEvalColsUnits.at( aCol ).second };
1186
1187 // Legacy - default always DISTANCE
1189}
1190
1191
1192void WX_GRID::SetupColumnAutosizer( int aFlexibleCol )
1193{
1194 const int colCount = GetNumberCols();
1195
1196 for( int ii = 0; ii < GetNumberCols(); ++ii )
1197 m_autosizedCols[ii] = GetColSize( ii );
1198
1199 m_flexibleCol = aFlexibleCol;
1200
1201 wxASSERT_MSG( m_flexibleCol < colCount, "Flexible column index does not exist in grid" );
1202
1203 Bind( wxEVT_UPDATE_UI,
1204 [this]( wxUpdateUIEvent& aEvent )
1205 {
1207 aEvent.Skip();
1208 } );
1209
1210 Bind( wxEVT_SIZE,
1211 [this]( wxSizeEvent& aEvent )
1212 {
1213 onSizeEvent( aEvent );
1214 aEvent.Skip();
1215 } );
1216
1217 // Handles the case when the user changes the cell content to be longer than the current column size
1218 Bind( wxEVT_GRID_CELL_CHANGED,
1219 [this]( wxGridEvent& aEvent )
1220 {
1221 m_gridWidthsDirty = true;
1222 aEvent.Skip();
1223 } );
1224}
1225
1226
1228{
1229 if( m_gridWidthsDirty )
1230 {
1231 const int width = GetSize().GetX() - wxSystemSettings::GetMetric( wxSYS_VSCROLL_X );
1232
1233 std::optional<int> flexibleMinWidth;
1234
1235 for( const auto& [colIndex, minWidth] : m_autosizedCols )
1236 {
1237 if( GetColSize( colIndex ) != 0 )
1238 {
1239 AutoSizeColumn( colIndex );
1240 int colSize = GetColSize( colIndex );
1241
1242 // Give a bit more width to columns that have editors with graphic widgets
1243 if( GetNumberRows() > 0 )
1244 {
1245 if( wxGridCellEditor* editor = GetCellEditor( 0, colIndex ) )
1246 {
1247 if( dynamic_cast<wxGridCellChoiceEditor*>( editor )
1248 || dynamic_cast<GRID_CELL_TEXT_BUTTON*>( editor )
1249 || dynamic_cast<GRID_CELL_COMBOBOX*>( editor ) )
1250 {
1251 colSize += 40;
1252 }
1253
1254 editor->DecRef();
1255 }
1256 }
1257
1258 int minWidthScaled = FromDIP( minWidth );
1259 SetColSize( colIndex, std::max( minWidthScaled, colSize ) );
1260
1261 if( colIndex == m_flexibleCol )
1262 flexibleMinWidth = minWidthScaled;
1263 }
1264 }
1265
1266 // Gather all the widths except the flexi one
1267 int nonFlexibleWidth = 0;
1268
1269 for( int i = 0; i < GetNumberCols(); ++i )
1270 {
1271 if( i != m_flexibleCol )
1272 nonFlexibleWidth += GetColSize( i );
1273 }
1274
1275 if( GetColSize( m_flexibleCol ) != 0 )
1276 SetColSize( m_flexibleCol, std::max( flexibleMinWidth.value_or( 0 ), width - nonFlexibleWidth ) );
1277
1278 // Store the state for next time
1279 m_gridWidth = GetSize().GetX();
1280 m_gridWidthsDirty = false;
1281 }
1282}
1283
1284
1285void WX_GRID::onSizeEvent( wxSizeEvent& aEvent )
1286{
1287 const int width = aEvent.GetSize().GetX();
1288
1289 if( width != m_gridWidth )
1290 m_gridWidthsDirty = true;
1291}
const char * name
Dialog helper object to sit in the inheritance tree between wxDialog and any class written by wxFormB...
Definition dialog_shim.h:81
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:1114
int m_flexibleCol
Definition wx_grid.h:448
void EvaluateCell(int aRow, int aCol)
Definition wx_grid.cpp:514
void onGridCellSelect(wxGridEvent &aEvent)
Definition wx_grid.cpp:432
std::map< int, int > m_autosizedCols
Definition wx_grid.h:447
bool m_gridWidthsDirty
Definition wx_grid.h:450
~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:369
bool m_weOwnTable
Definition wx_grid.h:435
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:642
void OnMoveRowUp(const std::function< void(int row)> &aMover)
Definition wx_grid.cpp:957
std::map< int, UNITS_PROVIDER * > m_unitsProviders
Definition wx_grid.h:439
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:375
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:594
std::unordered_map< int, std::pair< EDA_UNITS, EDA_DATA_TYPE > > m_autoEvalColsUnits
Definition wx_grid.h:442
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:1032
bool CancelPendingChanges()
Definition wx_grid.cpp:777
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:354
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:946
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:1182
void SetUnitValue(int aRow, int aCol, int aValue)
Set a unitized cell's value.
Definition wx_grid.cpp:1081
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:1045
std::vector< int > m_autoEvalCols
Definition wx_grid.h:441
UNITS_PROVIDER * getUnitsProvider(int aCol) const
Definition wx_grid.h:418
std::map< std::pair< int, int >, std::pair< wxString, wxString > > m_evalBeforeAfter
Definition wx_grid.h:443
std::vector< int > GetSelectedRowIndices() const
Definition wx_grid.cpp:921
bool m_useNativeSelection
Definition wx_grid.h:437
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:660
bool m_cursorRowColumnHighlight
Definition wx_grid.h:436
ROW_ICON_PROVIDER * m_rowIconProvider
Definition wx_grid.h:453
void onCellEditorHidden(wxGridEvent &aEvent)
Definition wx_grid.cpp:507
void SetupColumnAutosizer(int aFlexibleCol)
Set autosize behaviour using wxFormBuilder column widths as minimums, with a single specified growabl...
Definition wx_grid.cpp:1192
void RecomputeGridWidths()
Definition wx_grid.cpp:1227
void OnMoveRowDown(const std::function< void(int row)> &aMover)
Definition wx_grid.cpp:990
void onGridColMove(wxGridEvent &aEvent)
Definition wx_grid.cpp:1107
void SetOptionalUnitValue(int aRow, int aCol, std::optional< int > aValue)
Set a unitized cell's optional value.
Definition wx_grid.cpp:1094
void onSizeEvent(wxSizeEvent &aEvent)
Definition wx_grid.cpp:1285
void onCellEditorShown(wxGridEvent &aEvent)
Definition wx_grid.cpp:488
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition wx_grid.cpp:1154
void OnDeleteRows(const std::function< void(int row)> &aDeleter)
Handles a row deletion event.
Definition wx_grid.cpp:877
wxString GetShownColumnsAsString()
Get a tokenized string containing the shown column indexes.
Definition wx_grid.cpp:612
void OnAddRow(const std::function< std::pair< int, int >()> &aAdder)
Definition wx_grid.cpp:857
int m_gridWidth
Definition wx_grid.h:451
void DrawRowLabel(wxDC &dc, int row) override
A re-implementation of wxGrid::DrawRowLabel which draws flat borders.
Definition wx_grid.cpp:718
std::bitset< 64 > GetShownColumns()
Definition wx_grid.cpp:631
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:1063
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:414
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:1023
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition wx_grid.cpp:805
std::unique_ptr< NUMERIC_EVALUATOR > m_eval
Definition wx_grid.h:440
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:680
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:45
double GetPixelScaleFactor(const wxWindow *aWindow)
Tries to determine the pixel scaling factor currently in use for the window.
Definition wxgtk/ui.cpp:457
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition wxgtk/ui.cpp:57
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
const int c_IndicatorSizeDIP
Definition ui_common.h:54
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
const std::string table
DATABASE_CONNECTION dc(odbcBackend(cs))
std::vector< DATABASE_CONNECTION::ROW > rows
VECTOR2I center
Functions to provide common constants and other functions to assist in making a consistent UI.
static PIECE rect(double aLeft, double aTop, double aRight, double aBottom, bool aMixed=false)
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