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 (C) 2018-2023 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, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#include <wx/colour.h>
25#include <wx/tokenzr.h>
26#include <wx/dc.h>
27#include <wx/settings.h>
28#include <wx/event.h> // Needed for textentry.h on MSW
29#include <wx/textentry.h>
30
31#include <widgets/wx_grid.h>
32#include <widgets/ui_common.h>
33#include <algorithm>
34#include <core/kicad_algo.h>
35#include <gal/color4d.h>
36#include <kiplatform/ui.h>
37
38#include <pgm_base.h>
40
41
42wxGridCellAttr* WX_GRID_TABLE_BASE::enhanceAttr( wxGridCellAttr* aInputAttr, int aRow, int aCol,
43 wxGridCellAttr::wxAttrKind aKind )
44{
45 wxGridCellAttr* attr = aInputAttr;
46
47 if( wxGridCellAttrProvider* provider = GetAttrProvider() )
48 {
49 wxGridCellAttr* providerAttr = provider->GetAttr( aRow, aCol, aKind );
50
51 if( providerAttr )
52 {
53 attr = new wxGridCellAttr;
54 attr->SetKind( wxGridCellAttr::Merged );
55
56 if( aInputAttr )
57 {
58 attr->MergeWith( aInputAttr );
59 aInputAttr->DecRef();
60 }
61
62 attr->MergeWith( providerAttr );
63 providerAttr->DecRef();
64 }
65 }
66
67 return attr;
68}
69
70
71#define MIN_GRIDCELL_MARGIN FromDIP( 3 )
72
73
74void WX_GRID::CellEditorSetMargins( wxTextEntryBase* aEntry )
75{
76 // This is consistent with wxGridCellTextEditor. But works differently across platforms or course.
77 aEntry->SetMargins( 0, 0 );
78}
79
80
82{
83#if defined( __WXMSW__ ) || defined( __WXGTK__ )
84 aRect.Deflate( 2 );
85#endif
86}
87
88
90{
91 KIGFX::COLOR4D bg = wxSystemSettings::GetColour( wxSYS_COLOUR_FRAMEBK );
92 KIGFX::COLOR4D fg = wxSystemSettings::GetColour( wxSYS_COLOUR_ACTIVEBORDER );
93 KIGFX::COLOR4D border = fg.Mix( bg, 0.50 );
94 return border.ToColour();
95}
96
97
98class WX_GRID_CORNER_HEADER_RENDERER : public wxGridCornerHeaderRendererDefault
99{
100public:
101 void DrawBorder( const wxGrid& grid, wxDC& dc, wxRect& rect ) const override
102 {
103 wxDCBrushChanger SetBrush( dc, *wxTRANSPARENT_BRUSH );
104 wxDCPenChanger SetPen( dc, wxPen( getBorderColour(), 1 ) );
105
106 rect.SetTop( rect.GetTop() + 1 );
107 rect.SetLeft( rect.GetLeft() + 1 );
108 rect.SetBottom( rect.GetBottom() - 1 );
109 rect.SetRight( rect.GetRight() - 1 );
110 dc.DrawRectangle( rect );
111 }
112};
113
114
115class WX_GRID_COLUMN_HEADER_RENDERER : public wxGridColumnHeaderRendererDefault
116{
117public:
118 void DrawBorder( const wxGrid& grid, wxDC& dc, wxRect& rect ) const override
119 {
120 wxDCBrushChanger SetBrush( dc, *wxTRANSPARENT_BRUSH );
121 wxDCPenChanger SetPen( dc, wxPen( getBorderColour(), 1 ) );
122
123 rect.SetTop( rect.GetTop() + 1 );
124 rect.SetLeft( rect.GetLeft() );
125 rect.SetBottom( rect.GetBottom() - 1 );
126 rect.SetRight( rect.GetRight() - 1 );
127 dc.DrawRectangle( rect );
128 }
129};
130
131
132class WX_GRID_ROW_HEADER_RENDERER : public wxGridRowHeaderRendererDefault
133{
134public:
135 void DrawBorder( const wxGrid& grid, wxDC& dc, wxRect& rect ) const override
136 {
137 wxDCBrushChanger SetBrush( dc, *wxTRANSPARENT_BRUSH );
138 wxDCPenChanger SetPen( dc, wxPen( getBorderColour(), 1 ) );
139
140 rect.SetTop( rect.GetTop() + 1 );
141 rect.SetLeft( rect.GetLeft() + 1 );
142 rect.SetBottom( rect.GetBottom() - 1 );
143 rect.SetRight( rect.GetRight() );
144 dc.DrawRectangle( rect );
145 }
146};
147
148
153class WX_GRID_ALT_ROW_COLOR_PROVIDER : public wxGridCellAttrProvider
154{
155public:
156 WX_GRID_ALT_ROW_COLOR_PROVIDER( const wxColor& aBaseColor ) : wxGridCellAttrProvider(),
157 m_attrOdd( new wxGridCellAttr() )
158 {
159 UpdateColors( aBaseColor );
160 }
161
162
163 void UpdateColors( const wxColor& aBaseColor )
164 {
165 // Choose the default color, taking into account if the dark mode theme is enabled
166 wxColor rowColor = aBaseColor.ChangeLightness( KIPLATFORM::UI::IsDarkTheme() ? 105 : 95 );
167
168 m_attrOdd->SetBackgroundColour( rowColor );
169 }
170
171
172 wxGridCellAttr* GetAttr( int row, int col,
173 wxGridCellAttr::wxAttrKind kind ) const override
174 {
175 wxGridCellAttrPtr cellAttr( wxGridCellAttrProvider::GetAttr( row, col, kind ) );
176
177 // Just pass through the cell attribute on even rows
178 if( row % 2 )
179 return cellAttr.release();
180
181 if( !cellAttr )
182 {
183 cellAttr = m_attrOdd;
184 }
185 else
186 {
187 if( !cellAttr->HasBackgroundColour() )
188 {
189 cellAttr = cellAttr->Clone();
190 cellAttr->SetBackgroundColour( m_attrOdd->GetBackgroundColour() );
191 }
192 }
193
194 return cellAttr.release();
195 }
196
197private:
198 wxGridCellAttrPtr m_attrOdd;
199};
200
201
202WX_GRID::WX_GRID( wxWindow *parent, wxWindowID id, const wxPoint& pos, const wxSize& size,
203 long style, const wxString& name ) :
204 wxGrid( parent, id, pos, size, style, name ),
205 m_weOwnTable( false )
206{
207 SetDefaultCellOverflow( false );
208
209 // Make sure the GUI font scales properly
210 SetDefaultCellFont( KIUI::GetControlFont( this ) );
212
213 if( GetColLabelSize() > 0 )
214 SetColLabelSize( GetColLabelSize() + FromDIP( 4 ) );
215
216 Connect( wxEVT_DPI_CHANGED, wxDPIChangedEventHandler( WX_GRID::onDPIChanged ), nullptr, this );
217 Connect( wxEVT_GRID_EDITOR_SHOWN, wxGridEventHandler( WX_GRID::onCellEditorShown ), nullptr, this );
218 Connect( wxEVT_GRID_EDITOR_HIDDEN, wxGridEventHandler( WX_GRID::onCellEditorHidden ), nullptr, this );
219}
220
221
223{
224 if( m_weOwnTable )
225 DestroyTable( GetTable() );
226
227 Disconnect( wxEVT_GRID_EDITOR_SHOWN, wxGridEventHandler( WX_GRID::onCellEditorShown ), nullptr, this );
228 Disconnect( wxEVT_GRID_EDITOR_HIDDEN, wxGridEventHandler( WX_GRID::onCellEditorHidden ), nullptr, this );
229 Disconnect( wxEVT_DPI_CHANGED, wxDPIChangedEventHandler( WX_GRID::onDPIChanged ), nullptr, this );
230}
231
232
233void WX_GRID::onDPIChanged(wxDPIChangedEvent& aEvt)
234{
237#ifndef __WXMAC__
238 aEvt.Skip();
239#endif
240}
241
242
243void WX_GRID::SetColLabelSize( int aHeight )
244{
245 if( aHeight == 0 )
246 {
247 wxGrid::SetColLabelSize( 0 );
248 return;
249 }
250
251 // Correct wxFormBuilder height for large fonts
252 int minHeight = GetLabelFont().GetPixelSize().y + 2 * MIN_GRIDCELL_MARGIN;
253 wxGrid::SetColLabelSize( std::max( aHeight, minHeight ) );
254}
255
256
257void WX_GRID::SetLabelFont( const wxFont& aFont )
258{
259 wxGrid::SetLabelFont( KIUI::GetControlFont( this ) );
260}
261
262
263void WX_GRID::SetTable( wxGridTableBase* aTable, bool aTakeOwnership )
264{
265 // wxGrid::SetTable() messes up the column widths from wxFormBuilder so we have to save
266 // and restore them.
267 int numberCols = GetNumberCols();
268 int* formBuilderColWidths = new int[numberCols];
269
270 for( int i = 0; i < numberCols; ++i )
271 formBuilderColWidths[ i ] = GetColSize( i );
272
273 wxGrid::SetTable( aTable );
274
275 // wxGrid::SetTable() may change the number of columns, so prevent out-of-bounds access
276 // to formBuilderColWidths
277 numberCols = std::min( numberCols, GetNumberCols() );
278
279 for( int i = 0; i < numberCols; ++i )
280 {
281 // correct wxFormBuilder width for large fonts and/or long translations
282 int headingWidth = GetTextExtent( GetColLabelValue( i ) ).x + 2 * MIN_GRIDCELL_MARGIN;
283
284 SetColSize( i, std::max( formBuilderColWidths[ i ], headingWidth ) );
285 }
286
287 delete[] formBuilderColWidths;
288
289 EnableAlternateRowColors( Pgm().GetCommonSettings()->m_Appearance.grid_striping );
290
291 Connect( wxEVT_GRID_COL_MOVE, wxGridEventHandler( WX_GRID::onGridColMove ), nullptr, this );
292 Connect( wxEVT_GRID_SELECT_CELL, wxGridEventHandler( WX_GRID::onGridCellSelect ), nullptr, this );
293
294 m_weOwnTable = aTakeOwnership;
295}
296
297
299{
300 wxGridTableBase* table = wxGrid::GetTable();
301
302 wxCHECK_MSG( table, /* void */,
303 "Tried to enable alternate row colors without a table assigned to the grid" );
304
305 if( aEnable )
306 {
307 wxColor color = wxGrid::GetDefaultCellBackgroundColour();
308 table->SetAttrProvider( new WX_GRID_ALT_ROW_COLOR_PROVIDER( color ) );
309 }
310 else
311 {
312 table->SetAttrProvider( nullptr );
313 }
314}
315
316
317void WX_GRID::onGridCellSelect( wxGridEvent& aEvent )
318{
319 // Highlight the selected cell.
320 // Calling SelectBlock() allows a visual effect when cells are selected by tab or arrow keys.
321 // Otherwise, one cannot really know what actual cell is selected.
322 int row = aEvent.GetRow();
323 int col = aEvent.GetCol();
324
325 if( row >= 0 && row < GetNumberRows() && col >= 0 && col < GetNumberCols() )
326 {
327 if( GetSelectionMode() == wxGrid::wxGridSelectCells )
328 {
329 SelectBlock( row, col, row, col, false );
330 }
331 else if( GetSelectionMode() == wxGrid::wxGridSelectRows
332 || GetSelectionMode() == wxGrid::wxGridSelectRowsOrColumns )
333 {
334 SelectBlock( row, 0, row, GetNumberCols() - 1, false );
335 }
336 else if( GetSelectionMode() == wxGrid::wxGridSelectColumns )
337 {
338 SelectBlock( 0, col, GetNumberRows() - 1, col, false );
339 }
340 }
341}
342
343
344void WX_GRID::onCellEditorShown( wxGridEvent& aEvent )
345{
346 if( alg::contains( m_autoEvalCols, aEvent.GetCol() ) )
347 {
348 int row = aEvent.GetRow();
349 int col = aEvent.GetCol();
350
351 const std::pair<wxString, wxString>& beforeAfter = m_evalBeforeAfter[ { row, col } ];
352
353 if( GetCellValue( row, col ) == beforeAfter.second )
354 SetCellValue( row, col, beforeAfter.first );
355 }
356}
357
358
359void WX_GRID::onCellEditorHidden( wxGridEvent& aEvent )
360{
361 if( alg::contains( m_autoEvalCols, aEvent.GetCol() ) )
362 {
363 UNITS_PROVIDER* unitsProvider = m_unitsProviders[ aEvent.GetCol() ];
364
365 if( !unitsProvider )
366 unitsProvider = m_unitsProviders.begin()->second;
367
368 m_eval->SetDefaultUnits( unitsProvider->GetUserUnits() );
369
370 int row = aEvent.GetRow();
371 int col = aEvent.GetCol();
372
373 CallAfter(
374 [this, row, col, unitsProvider]()
375 {
376 wxString stringValue = GetCellValue( row, col );
377
378 if( m_eval->Process( stringValue ) )
379 {
380 int val = unitsProvider->ValueFromString( m_eval->Result() );
381 wxString evalValue = unitsProvider->StringFromValue( val, true );
382
383 if( stringValue != evalValue )
384 {
385 SetCellValue( row, col, evalValue );
386 m_evalBeforeAfter[ { row, col } ] = { stringValue, evalValue };
387 }
388 }
389 } );
390 }
391
392 aEvent.Skip();
393}
394
395
396void WX_GRID::DestroyTable( wxGridTableBase* aTable )
397{
398 // wxGrid's destructor will crash trying to look up the cell attr if the edit control
399 // is left open. Normally it's closed in Validate(), but not if the user hit Cancel.
400 CommitPendingChanges( true /* quiet mode */ );
401
402 Disconnect( wxEVT_GRID_COL_MOVE, wxGridEventHandler( WX_GRID::onGridColMove ), nullptr, this );
403 Disconnect( wxEVT_GRID_SELECT_CELL, wxGridEventHandler( WX_GRID::onGridCellSelect ), nullptr, this );
404
405 wxGrid::SetTable( nullptr );
406 delete aTable;
407}
408
409
411{
412 wxString shownColumns;
413
414 for( int i = 0; i < GetNumberCols(); ++i )
415 {
416 if( IsColShown( i ) )
417 {
418 if( shownColumns.Length() )
419 shownColumns << wxT( " " );
420
421 shownColumns << i;
422 }
423 }
424
425 return shownColumns;
426}
427
428
430{
431 std::bitset<64> shownColumns;
432
433 for( int ii = 0; ii < GetNumberCols(); ++ii )
434 shownColumns[ii] = IsColShown( ii );
435
436 return shownColumns;
437}
438
439
440void WX_GRID::ShowHideColumns( const wxString& shownColumns )
441{
442 for( int i = 0; i < GetNumberCols(); ++i )
443 HideCol( i );
444
445 wxStringTokenizer shownTokens( shownColumns );
446
447 while( shownTokens.HasMoreTokens() )
448 {
449 long colNumber;
450 shownTokens.GetNextToken().ToLong( &colNumber );
451
452 if( colNumber >= 0 && colNumber < GetNumberCols() )
453 ShowCol( (int) colNumber );
454 }
455}
456
457
458void WX_GRID::ShowHideColumns( const std::bitset<64>& aShownColumns )
459{
460 for( int ii = 0; ii < GetNumberCols(); ++ ii )
461 {
462 if( aShownColumns[ii] )
463 ShowCol( ii );
464 else
465 HideCol( ii );
466 }
467}
468
469
471{
472 if( m_nativeColumnLabels )
473 wxGrid::DrawCornerLabel( dc );
474
475 wxRect rect( wxSize( m_rowLabelWidth, m_colLabelHeight ) );
476
478
479 // It is reported that we need to erase the background to avoid display
480 // artifacts, see #12055.
481 {
482 wxDCBrushChanger setBrush( dc, m_colLabelWin->GetBackgroundColour() );
483 wxDCPenChanger setPen( dc, m_colLabelWin->GetBackgroundColour() );
484 dc.DrawRectangle( rect.Inflate( 1 ) );
485 }
486
487 rend.DrawBorder( *this, dc, rect );
488}
489
490
491void WX_GRID::DrawColLabel( wxDC& dc, int col )
492{
493 if( m_nativeColumnLabels )
494 wxGrid::DrawColLabel( dc, col );
495
496 if( GetColWidth( col ) <= 0 || m_colLabelHeight <= 0 )
497 return;
498
499 wxRect rect( GetColLeft( col ), 0, GetColWidth( col ), m_colLabelHeight );
500
502
503 // It is reported that we need to erase the background to avoid display
504 // artifacts, see #12055.
505 {
506 wxDCBrushChanger setBrush( dc, m_colLabelWin->GetBackgroundColour() );
507 wxDCPenChanger setPen( dc, m_colLabelWin->GetBackgroundColour() );
508 dc.DrawRectangle( rect.Inflate( 1 ) );
509 }
510
511 rend.DrawBorder( *this, dc, rect );
512
513 // Make sure fonts get scaled correctly on GTK HiDPI monitors
514 dc.SetFont( GetLabelFont() );
515
516 int hAlign, vAlign;
517 GetColLabelAlignment( &hAlign, &vAlign );
518 const int orient = GetColLabelTextOrientation();
519
520 if( col == 0 )
521 hAlign = wxALIGN_LEFT;
522
523 if( hAlign == wxALIGN_LEFT )
524 rect.SetLeft( rect.GetLeft() + MIN_GRIDCELL_MARGIN );
525
526 rend.DrawLabel( *this, dc, GetColLabelValue( col ), rect, hAlign, vAlign, orient );
527}
528
529
530void WX_GRID::DrawRowLabel( wxDC& dc, int row )
531{
532 if ( GetRowHeight( row ) <= 0 || m_rowLabelWidth <= 0 )
533 return;
534
535 wxRect rect( 0, GetRowTop( row ), m_rowLabelWidth, GetRowHeight( row ) );
536
537 static WX_GRID_ROW_HEADER_RENDERER rend;
538
539 // It is reported that we need to erase the background to avoid display
540 // artifacts, see #12055.
541 {
542 wxDCBrushChanger setBrush( dc, m_colLabelWin->GetBackgroundColour() );
543 wxDCPenChanger setPen( dc, m_colLabelWin->GetBackgroundColour() );
544 dc.DrawRectangle( rect.Inflate( 1 ) );
545 }
546
547 rend.DrawBorder( *this, dc, rect );
548
549 // Make sure fonts get scaled correctly on GTK HiDPI monitors
550 dc.SetFont( GetLabelFont() );
551
552 int hAlign, vAlign;
553 GetRowLabelAlignment(&hAlign, &vAlign);
554
555 if( hAlign == wxALIGN_LEFT )
556 rect.SetLeft( rect.GetLeft() + MIN_GRIDCELL_MARGIN );
557
558 rend.DrawLabel( *this, dc, GetRowLabelValue( row ), rect, hAlign, vAlign, wxHORIZONTAL );
559}
560
561
563{
564 if( !IsCellEditControlEnabled() )
565 return true;
566
567 HideCellEditControl();
568
569 // do it after HideCellEditControl()
570 m_cellEditCtrlEnabled = false;
571
572 int row = m_currentCellCoords.GetRow();
573 int col = m_currentCellCoords.GetCol();
574
575 wxString oldval = GetCellValue( row, col );
576 wxString newval;
577
578 wxGridCellAttr* attr = GetCellAttr( row, col );
579 wxGridCellEditor* editor = attr->GetEditor( this, row, col );
580
581 editor->EndEdit( row, col, this, oldval, &newval );
582
583 editor->DecRef();
584 attr->DecRef();
585
586 return true;
587}
588
589
590bool WX_GRID::CommitPendingChanges( bool aQuietMode )
591{
592 if( !IsCellEditControlEnabled() )
593 return true;
594
595 if( !aQuietMode && SendEvent( wxEVT_GRID_EDITOR_HIDDEN ) == -1 )
596 return false;
597
598 HideCellEditControl();
599
600 // do it after HideCellEditControl()
601 m_cellEditCtrlEnabled = false;
602
603 int row = m_currentCellCoords.GetRow();
604 int col = m_currentCellCoords.GetCol();
605
606 wxString oldval = GetCellValue( row, col );
607 wxString newval;
608
609 wxGridCellAttr* attr = GetCellAttr( row, col );
610 wxGridCellEditor* editor = attr->GetEditor( this, row, col );
611
612 bool changed = editor->EndEdit( row, col, this, oldval, &newval );
613
614 editor->DecRef();
615 attr->DecRef();
616
617 if( changed )
618 {
619 if( !aQuietMode && SendEvent( wxEVT_GRID_CELL_CHANGING, newval ) == -1 )
620 return false;
621
622 editor->ApplyEdit( row, col, this );
623
624 // for compatibility reasons dating back to wx 2.8 when this event
625 // was called wxEVT_GRID_CELL_CHANGE and wxEVT_GRID_CELL_CHANGING
626 // didn't exist we allow vetoing this one too
627 if( !aQuietMode && SendEvent( wxEVT_GRID_CELL_CHANGED, oldval ) == -1 )
628 {
629 // Event has been vetoed, set the data back.
630 SetCellValue( row, col, oldval );
631 return false;
632 }
633 }
634
635 return true;
636}
637
638
639void WX_GRID::SetUnitsProvider( UNITS_PROVIDER* aProvider, int aCol )
640{
641 m_unitsProviders[ aCol ] = aProvider;
642
643 if( !m_eval )
644 m_eval = std::make_unique<NUMERIC_EVALUATOR>( aProvider->GetUserUnits() );
645}
646
647
648int WX_GRID::GetUnitValue( int aRow, int aCol )
649{
650 UNITS_PROVIDER* unitsProvider = m_unitsProviders[ aCol ];
651
652 if( !unitsProvider )
653 unitsProvider = m_unitsProviders.begin()->second;
654
655 wxString stringValue = GetCellValue( aRow, aCol );
656
657 if( alg::contains( m_autoEvalCols, aCol ) )
658 {
659 m_eval->SetDefaultUnits( unitsProvider->GetUserUnits() );
660
661 if( m_eval->Process( stringValue ) )
662 stringValue = m_eval->Result();
663 }
664
665 return unitsProvider->ValueFromString( stringValue );
666}
667
668
669void WX_GRID::SetUnitValue( int aRow, int aCol, int aValue )
670{
671 UNITS_PROVIDER* unitsProvider = m_unitsProviders[ aCol ];
672
673 if( !unitsProvider )
674 unitsProvider = m_unitsProviders.begin()->second;
675
676 SetCellValue( aRow, aCol, unitsProvider->StringFromValue( aValue, true ) );
677}
678
679
680void WX_GRID::onGridColMove( wxGridEvent& aEvent )
681{
682 // wxWidgets won't move an open editor, so better just to close it
683 CommitPendingChanges( true );
684}
685
686
687int WX_GRID::GetVisibleWidth( int aCol, bool aHeader, bool aContents, bool aKeep )
688{
689 int size = 0;
690
691 if( aCol < 0 )
692 {
693 if( aKeep )
694 size = GetRowLabelSize();
695
696 for( int row = 0; aContents && row < GetNumberRows(); row++ )
697 size = std::max( size, int( GetTextExtent( GetRowLabelValue( row ) + wxS( "M" ) ).x ) );
698 }
699 else
700 {
701 if( aKeep )
702 size = GetColSize( aCol );
703
704 // 'M' is generally the widest character, so we buffer the column width by default to
705 // ensure we don't write a continuous line of text at the column header
706 if( aHeader )
707 {
709
710 size = std::max( size, int( GetTextExtent( GetColLabelValue( aCol ) + wxS( "M" ) ).x ) );
711 }
712
713 for( int row = 0; aContents && row < GetNumberRows(); row++ )
714 {
715 // If we have text, get the size. Otherwise, use a placeholder for the checkbox
716 if( GetTable()->CanGetValueAs( row, aCol, wxGRID_VALUE_STRING ) )
717 size = std::max( size, GetTextExtent( GetCellValue( row, aCol ) + wxS( "M" ) ).x );
718 else
719 size = std::max( size, GetTextExtent( "MM" ).x );
720 }
721 }
722
723 return size;
724}
725
726
728{
729 int line_height = int( GetTextExtent( "Mj" ).y ) + 3;
730 int row_height = GetColLabelSize();
731 int initial_row_height = row_height;
732
733 // Headers can be multiline. Fix the Column Label Height to show the full header
734 // However GetTextExtent does not work on multiline strings,
735 // and do not return the full text height (only the height of one line)
736 for( int col = 0; col < GetNumberCols(); col++ )
737 {
738 int nl_count = GetColLabelValue( col ).Freq( '\n' );
739
740 if( nl_count )
741 {
742 // Col Label height must be able to show nl_count+1 lines
743 if( row_height < line_height * ( nl_count+1 ) )
744 row_height += line_height * nl_count;
745 }
746 }
747
748 // Update the column label size, but only if needed, to avoid generating useless
749 // and perhaps annoying UI events when the size does not change
750 if( initial_row_height != row_height )
751 SetColLabelSize( row_height );
752}
int color
Definition: DXF_plotter.cpp:58
const char * name
Definition: DXF_plotter.cpp:57
A color representation with 4 components: red, green, blue, alpha.
Definition: color4d.h:104
wxColour ToColour() const
Definition: color4d.cpp:220
COLOR4D Mix(const COLOR4D &aColor, double aFactor) const
Return a color that is mixed with the input by a factor.
Definition: color4d.h:295
EDA_UNITS GetUserUnits() const
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:154
WX_GRID_ALT_ROW_COLOR_PROVIDER(const wxColor &aBaseColor)
Definition: wx_grid.cpp:156
wxGridCellAttr * GetAttr(int row, int col, wxGridCellAttr::wxAttrKind kind) const override
Definition: wx_grid.cpp:172
void UpdateColors(const wxColor &aBaseColor)
Definition: wx_grid.cpp:163
wxGridCellAttrPtr m_attrOdd
Definition: wx_grid.cpp:198
void DrawBorder(const wxGrid &grid, wxDC &dc, wxRect &rect) const override
Definition: wx_grid.cpp:118
void DrawBorder(const wxGrid &grid, wxDC &dc, wxRect &rect) const override
Definition: wx_grid.cpp:101
void DrawBorder(const wxGrid &grid, wxDC &dc, wxRect &rect) const override
Definition: wx_grid.cpp:135
wxGridCellAttr * enhanceAttr(wxGridCellAttr *aInputAttr, int aRow, int aCol, wxGridCellAttr::wxAttrKind aKind)
Definition: wx_grid.cpp:42
int GetVisibleWidth(int aCol, bool aHeader=true, bool aContents=true, bool aKeep=false)
Calculates the specified column based on the actual size of the text on screen.
Definition: wx_grid.cpp:687
void onGridCellSelect(wxGridEvent &aEvent)
Definition: wx_grid.cpp:317
~WX_GRID() override
Definition: wx_grid.cpp:222
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:257
bool m_weOwnTable
Definition: wx_grid.h:206
void onDPIChanged(wxDPIChangedEvent &event)
Definition: wx_grid.cpp:233
void ShowHideColumns(const wxString &shownColumns)
Show/hide the grid columns based on a tokenized string of shown column indexes.
Definition: wx_grid.cpp:440
std::map< int, UNITS_PROVIDER * > m_unitsProviders
Definition: wx_grid.h:208
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:263
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:396
bool CancelPendingChanges()
Definition: wx_grid.cpp:562
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:243
void SetUnitValue(int aRow, int aCol, int aValue)
Set a unitized cell's value.
Definition: wx_grid.cpp:669
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:202
int GetUnitValue(int aRow, int aCol)
Apply standard KiCad unit and eval services to a numeric cell.
Definition: wx_grid.cpp:648
std::vector< int > m_autoEvalCols
Definition: wx_grid.h:210
std::map< std::pair< int, int >, std::pair< wxString, wxString > > m_evalBeforeAfter
Definition: wx_grid.h:212
void DrawCornerLabel(wxDC &dc) override
A re-implementation of wxGrid::DrawCornerLabel which draws flat borders.
Definition: wx_grid.cpp:470
void onCellEditorHidden(wxGridEvent &aEvent)
Definition: wx_grid.cpp:359
void onGridColMove(wxGridEvent &aEvent)
Definition: wx_grid.cpp:680
void onCellEditorShown(wxGridEvent &aEvent)
Definition: wx_grid.cpp:344
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition: wx_grid.cpp:727
wxString GetShownColumnsAsString()
Get a tokenized string containing the shown column indexes.
Definition: wx_grid.cpp:410
void DrawRowLabel(wxDC &dc, int row) override
A re-implementation of wxGrid::DrawRowLabel which draws flat borders.
Definition: wx_grid.cpp:530
std::bitset< 64 > GetShownColumns()
Definition: wx_grid.cpp:429
static void CellEditorSetMargins(wxTextEntryBase *aEntry)
A helper function to set OS-specific margins for text-based cell editors.
Definition: wx_grid.cpp:74
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:298
void SetUnitsProvider(UNITS_PROVIDER *aProvider, int aCol=0)
Set a UNITS_PROVIDER to enable use of unit- and eval-based Getters.
Definition: wx_grid.cpp:639
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:590
std::unique_ptr< NUMERIC_EVALUATOR > m_eval
Definition: wx_grid.h:209
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:491
static void CellEditorTransformSizeRect(wxRect &aRect)
A helper function to tweak sizes of text-based cell editors depending on OS.
Definition: wx_grid.cpp:81
bool IsDarkTheme()
Determine if the desktop interface is currently using a dark theme or a light theme.
Definition: gtk/ui.cpp:48
KICOMMON_API wxFont GetControlFont(wxWindow *aWindow)
Definition: ui_common.cpp:160
bool contains(const _Container &__container, _Value __value)
Returns true if the container contains the given value.
Definition: kicad_algo.h:100
PGM_BASE & Pgm()
The global Program "get" accessor.
Definition: pgm_base.cpp:1059
see class PGM_BASE
Functions to provide common constants and other functions to assist in making a consistent UI.
wxColour getBorderColour()
Definition: wx_grid.cpp:89
#define MIN_GRIDCELL_MARGIN
Definition: wx_grid.cpp:71