KiCad PCB EDA Suite
WX_GRID Class Reference

#include <wx_grid.h>

Inheritance diagram for WX_GRID:

Public Member Functions

 WX_GRID (wxWindow *parent, wxWindowID id, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxWANTS_CHARS, const wxString &name=wxGridNameStr)
 
 ~WX_GRID () override
 
void SetColLabelSize (int aHeight)
 Hide wxGrid's SetColLabelSize() method with one which makes sure the size is tall enough for the system GUI font. More...
 
wxString GetShownColumns ()
 Get a tokenized string containing the shown column indexes. More...
 
void ShowHideColumns (const wxString &shownColumns)
 Show/hide the grid columns based on a tokenized string of shown column indexes. More...
 
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 the table. More...
 
void DestroyTable (wxGridTableBase *aTable)
 Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was not closed. More...
 
bool CommitPendingChanges (bool aQuietMode=false)
 Close any open cell edit controls. More...
 
int GetVisibleWidth (int aCol, bool aHeader=true, bool aContents=false, bool aKeep=true)
 Calculates the specified column based on the actual size of the text on screen. More...
 
void EnsureColLabelsVisible ()
 Ensure the height of the row displaying the column labels is enough, even if labels are multiline texts. More...
 
void ShowEditorOnMouseUp ()
 WxWidgets has a bunch of bugs in its handling of wxGrid mouse events which close cell editors right after opening them. More...
 
void ClearRows ()
 wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number of rows (even if the delete count is 0). More...
 

Protected Member Functions

void DrawColLabel (wxDC &dc, int col) override
 A re-implementation of wxGrid::DrawColLabel which left-aligns the first column when there are no row labels. More...
 
void onGridColMove (wxGridEvent &aEvent)
 

Protected Attributes

bool m_weOwnTable
 

Detailed Description

Definition at line 29 of file wx_grid.h.

Constructor & Destructor Documentation

◆ WX_GRID()

WX_GRID::WX_GRID ( wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
long  style = wxWANTS_CHARS,
const wxString &  name = wxGridNameStr 
)

Definition at line 34 of file wx_grid.cpp.

35  :
36  wxGrid( parent, id, pos, size, style, name ),
37  m_weOwnTable( false )
38 {
39  SetDefaultCellOverflow( false );
40 
41  // Make sure the GUI font scales properly on GTK
42  SetDefaultCellFont( KIUI::GetControlFont( this ) );
43 }
bool m_weOwnTable
Definition: wx_grid.h:121
wxFont GetControlFont(wxWindow *aWindow)
Definition: ui_common.cpp:150
const char * name
Definition: DXF_plotter.cpp:56

References KIUI::GetControlFont().

◆ ~WX_GRID()

WX_GRID::~WX_GRID ( )
override

Definition at line 46 of file wx_grid.cpp.

47 {
48  if( m_weOwnTable )
49  DestroyTable( GetTable() );
50 }
bool m_weOwnTable
Definition: wx_grid.h:121
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:104

References DestroyTable(), and m_weOwnTable.

Member Function Documentation

◆ ClearRows()

void WX_GRID::ClearRows ( )
inline

wxWidgets recently added an ASSERT which fires if the position is greater than or equal to the number of rows (even if the delete count is 0).

Needless to say, this makes using DeleteRows for clearing a lot more cumbersome so we add a helper here.

Definition at line 106 of file wx_grid.h.

107  {
108  if( GetNumberRows() )
109  DeleteRows( 0, GetNumberRows() );
110  }

Referenced by DIALOG_CONFIGURE_PATHS::DIALOG_CONFIGURE_PATHS(), DIALOG_EDIT_SYMBOLS_LIBID::initDlg(), PANEL_TEXT_VARIABLES::PANEL_TEXT_VARIABLES(), PANEL_FP_LIB_TABLE::populateEnvironReadOnlyTable(), PANEL_SYM_LIB_TABLE::populateEnvironReadOnlyTable(), FOOTPRINT_WIZARD_FRAME::ReCreateParameterList(), PANEL_FP_PROPERTIES_3D_MODEL::ReloadModelsFromFootprint(), PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataToGrid(), PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow(), PANEL_SETUP_NETCLASSES::TransferDataToWindow(), and PANEL_SETUP_TRACKS_AND_VIAS::TransferDataToWindow().

◆ CommitPendingChanges()

bool WX_GRID::CommitPendingChanges ( bool  aQuietMode = false)

Close any open cell edit controls.

Parameters
aQuietModeif true don't send events (ie: for row/col delete operations)
Returns
false if validation failed

Definition at line 190 of file wx_grid.cpp.

191 {
192  if( !IsCellEditControlEnabled() )
193  return true;
194 
195  if( !aQuietMode && SendEvent( wxEVT_GRID_EDITOR_HIDDEN ) == -1 )
196  return false;
197 
198  HideCellEditControl();
199 
200  // do it after HideCellEditControl()
201  m_cellEditCtrlEnabled = false;
202 
203  int row = m_currentCellCoords.GetRow();
204  int col = m_currentCellCoords.GetCol();
205 
206  wxString oldval = GetCellValue( row, col );
207  wxString newval;
208 
209  wxGridCellAttr* attr = GetCellAttr( row, col );
210  wxGridCellEditor* editor = attr->GetEditor( this, row, col );
211 
212  bool changed = editor->EndEdit( row, col, this, oldval, &newval );
213 
214  editor->DecRef();
215  attr->DecRef();
216 
217  if( changed )
218  {
219  if( !aQuietMode && SendEvent( wxEVT_GRID_CELL_CHANGING, newval ) == -1 )
220  return false;
221 
222  editor->ApplyEdit( row, col, this );
223 
224  // for compatibility reasons dating back to wx 2.8 when this event
225  // was called wxEVT_GRID_CELL_CHANGE and wxEVT_GRID_CELL_CHANGING
226  // didn't exist we allow vetoing this one too
227  if( !aQuietMode && SendEvent( wxEVT_GRID_CELL_CHANGED, oldval ) == -1 )
228  {
229  // Event has been vetoed, set the data back.
230  SetCellValue( row, col, oldval );
231  return false;
232  }
233  }
234 
235  return true;
236 }

References editor.

Referenced by PANEL_FP_LIB_TABLE::appendRowHandler(), PANEL_SYM_LIB_TABLE::appendRowHandler(), PANEL_FP_LIB_TABLE::browseLibrariesHandler(), PANEL_SYM_LIB_TABLE::deleteRowHandler(), PANEL_FP_LIB_TABLE::deleteRowHandler(), DestroyTable(), PANEL_SETUP_NETCLASSES::doApplyFilters(), PANEL_SETUP_NETCLASSES::doAssignments(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::doValidate(), PANEL_SETUP_TEXT_AND_GRAPHICS::ImportSettingsFrom(), PANEL_SETUP_TRACKS_AND_VIAS::ImportSettingsFrom(), PANEL_SYM_LIB_TABLE::moveDownHandler(), PANEL_FP_LIB_TABLE::moveDownHandler(), PANEL_SYM_LIB_TABLE::moveUpHandler(), PANEL_FP_LIB_TABLE::moveUpHandler(), PANEL_FP_PROPERTIES_3D_MODEL::OnAdd3DModel(), PANEL_FP_PROPERTIES_3D_MODEL::OnAdd3DRow(), DIALOG_PIN_PROPERTIES::OnAddAlternate(), PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::OnAddButtonClick(), DIALOG_CONFIGURE_PATHS::OnAddEnvVar(), DIALOG_LIB_SYMBOL_PROPERTIES::OnAddField(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnAddField(), DIALOG_SHEET_PROPERTIES::OnAddField(), DIALOG_SYMBOL_PROPERTIES::OnAddField(), DIALOG_FOOTPRINT_PROPERTIES::OnAddField(), PANEL_SETUP_NETCLASSES::OnAddNetclassClick(), DIALOG_LIB_EDIT_PIN_TABLE::OnAddRow(), DIALOG_CONFIGURE_PATHS::OnAddSearchPath(), PANEL_FP_EDITOR_DEFAULTS::OnAddTextItem(), PANEL_TEXT_VARIABLES::OnAddTextVar(), DIALOG_FP_PLUGIN_OPTIONS::onAppendOption(), DIALOG_FP_PLUGIN_OPTIONS::onAppendRow(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::OnButtonAdd(), TEXT_BUTTON_FILE_BROWSER::OnButtonClick(), DIALOG_PAD_PRIMITIVE_POLY_PROPS::OnButtonDelete(), DIALOG_LIB_EDIT_PIN_TABLE::OnClose(), DIALOG_SYMBOL_FIELDS_TABLE::OnClose(), PANEL_SYM_LIB_TABLE::onConvertLegacyLibraries(), DIALOG_PIN_PROPERTIES::OnDeleteAlternate(), PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::OnDeleteButtonClick(), DIALOG_LIB_SYMBOL_PROPERTIES::OnDeleteField(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::OnDeleteField(), DIALOG_SHEET_PROPERTIES::OnDeleteField(), DIALOG_SYMBOL_PROPERTIES::OnDeleteField(), DIALOG_FOOTPRINT_PROPERTIES::OnDeleteField(), DIALOG_LIB_EDIT_PIN_TABLE::OnDeleteRow(), DIALOG_FP_PLUGIN_OPTIONS::onDeleteRow(), DIALOG_CONFIGURE_PATHS::OnDeleteSearchPath(), PANEL_FP_EDITOR_DEFAULTS::OnDeleteTextItem(), onGridColMove(), GRID_TRICKS::onGridLabelLeftClick(), DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveDown(), DIALOG_SHEET_PROPERTIES::OnMoveDown(), DIALOG_SYMBOL_PROPERTIES::OnMoveDown(), DIALOG_LIB_SYMBOL_PROPERTIES::OnMoveUp(), DIALOG_SHEET_PROPERTIES::OnMoveUp(), DIALOG_SYMBOL_PROPERTIES::OnMoveUp(), DIALOG_LIB_EDIT_PIN_TABLE::OnRebuildRows(), PANEL_FP_PROPERTIES_3D_MODEL::OnRemove3DModel(), DIALOG_CONFIGURE_PATHS::OnRemoveEnvVar(), PANEL_SETUP_NETCLASSES::OnRemoveNetclassClick(), PANEL_TEXT_VARIABLES::OnRemoveTextVar(), DIALOG_CONFIGURE_PATHS::OnSearchPathMoveDown(), DIALOG_CONFIGURE_PATHS::OnSearchPathMoveUp(), PANEL_SETUP_NETCLASSES::rebuildNetclassDropdowns(), PANEL_EESCHEMA_TEMPLATE_FIELDNAMES::TransferDataFromGrid(), PANEL_TEXT_VARIABLES::TransferDataFromWindow(), DIALOG_SWAP_LAYERS::TransferDataFromWindow(), PANEL_FP_LIB_TABLE::TransferDataFromWindow(), DIALOG_SYMBOL_FIELDS_TABLE::TransferDataFromWindow(), DIALOG_CONFIGURE_PATHS::TransferDataFromWindow(), PANEL_SETUP_TEXT_AND_GRAPHICS::TransferDataFromWindow(), DIALOG_LIB_SYMBOL_PROPERTIES::TransferDataFromWindow(), PANEL_SETUP_TRACKS_AND_VIAS::TransferDataFromWindow(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataFromWindow(), DIALOG_LIB_EDIT_PIN_TABLE::TransferDataFromWindow(), DIALOG_FOOTPRINT_PROPERTIES::TransferDataFromWindow(), DIALOG_PIN_PROPERTIES::TransferDataFromWindow(), PANEL_FP_PROPERTIES_3D_MODEL::TransferDataFromWindow(), PANEL_SYM_LIB_TABLE::TransferDataFromWindow(), DIALOG_SYMBOL_PROPERTIES::TransferDataFromWindow(), DIALOG_FP_PLUGIN_OPTIONS::TransferDataFromWindow(), PANEL_SETUP_NETCLASSES::Validate(), DIALOG_LIB_SYMBOL_PROPERTIES::Validate(), PANEL_SETUP_TRACKS_AND_VIAS::Validate(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::Validate(), DIALOG_FOOTPRINT_PROPERTIES::Validate(), DIALOG_SHEET_PROPERTIES::Validate(), DIALOG_SYMBOL_PROPERTIES::Validate(), PANEL_FP_EDITOR_DEFAULTS::validateData(), and DIALOG_EDIT_SYMBOLS_LIBID::validateLibIds().

◆ DestroyTable()

void WX_GRID::DestroyTable ( wxGridTableBase *  aTable)

Work-around for a bug in wxGrid which crashes when deleting the table if the cell edit control was not closed.

Definition at line 104 of file wx_grid.cpp.

105 {
106  // wxGrid's destructor will crash trying to look up the cell attr if the edit control
107  // is left open. Normally it's closed in Validate(), but not if the user hit Cancel.
108  CommitPendingChanges( true /* quiet mode */ );
109 
110  Disconnect( wxEVT_GRID_COL_MOVE, wxGridEventHandler( WX_GRID::onGridColMove ), nullptr, this );
111 
112  wxGrid::SetTable( nullptr );
113  delete aTable;
114 }
void onGridColMove(wxGridEvent &aEvent)
Definition: wx_grid.cpp:239
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:190

References CommitPendingChanges(), and onGridColMove().

Referenced by DIALOG_FOOTPRINT_PROPERTIES::~DIALOG_FOOTPRINT_PROPERTIES(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::~DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(), DIALOG_LIB_EDIT_PIN_TABLE::~DIALOG_LIB_EDIT_PIN_TABLE(), DIALOG_LIB_SYMBOL_PROPERTIES::~DIALOG_LIB_SYMBOL_PROPERTIES(), DIALOG_PIN_PROPERTIES::~DIALOG_PIN_PROPERTIES(), DIALOG_SHEET_PROPERTIES::~DIALOG_SHEET_PROPERTIES(), DIALOG_SWAP_LAYERS::~DIALOG_SWAP_LAYERS(), DIALOG_SYMBOL_PROPERTIES::~DIALOG_SYMBOL_PROPERTIES(), and ~WX_GRID().

◆ DrawColLabel()

void WX_GRID::DrawColLabel ( wxDC &  dc,
int  col 
)
overrideprotected

A re-implementation of wxGrid::DrawColLabel which left-aligns the first column when there are no row labels.

Definition at line 154 of file wx_grid.cpp.

155 {
156  if( GetColWidth( col ) <= 0 || m_colLabelHeight <= 0 )
157  return;
158 
159  int colLeft = GetColLeft( col );
160 
161  wxRect rect( colLeft, 0, GetColWidth( col ), m_colLabelHeight );
162  static wxGridColumnHeaderRendererDefault rend;
163 
164  // It is reported that we need to erase the background to avoid display
165  // artifacts, see #12055.
166  // wxWidgets renamed this variable between 3.1.2 and 3.1.3 ...
167 #if wxCHECK_VERSION( 3, 1, 3 )
168  wxDCBrushChanger setBrush( dc, m_colLabelWin->GetBackgroundColour() );
169 #else
170  wxDCBrushChanger setBrush( dc, m_colWindow->GetBackgroundColour() );
171 #endif
172  dc.DrawRectangle(rect);
173 
174  rend.DrawBorder( *this, dc, rect );
175 
176  // Make sure fonts get scaled correctly on GTK HiDPI monitors
177  dc.SetFont( GetLabelFont() );
178 
179  int hAlign, vAlign;
180  GetColLabelAlignment( &hAlign, &vAlign );
181  const int orient = GetColLabelTextOrientation();
182 
183  if( col == 0 && GetRowLabelSize() == 0 )
184  hAlign = wxALIGN_LEFT;
185 
186  rend.DrawLabel( *this, dc, GetColLabelValue( col ), rect, hAlign, vAlign, orient );
187 }

◆ EnsureColLabelsVisible()

void WX_GRID::EnsureColLabelsVisible ( )

Ensure the height of the row displaying the column labels is enough, even if labels are multiline texts.

Definition at line 291 of file wx_grid.cpp.

292 {
293  // The 1.1 scale factor is due to the fact row labels use a bold font, bigger than
294  // the normal font
295  // TODO: use a better way to evaluate the text size, for bold font
296  int line_height = int( GetTextExtent( "Mj" ).y * 1.1 ) + 3;
297  int row_height = GetColLabelSize();
298  int initial_row_height = row_height;
299 
300  // Headers can be multiline. Fix the Column Label Height to show the full header
301  // However GetTextExtent does not work on multiline strings,
302  // and do not return the full text height (only the height of one line)
303  for( int col = 0; col < GetNumberCols(); col++ )
304  {
305  int nl_count = GetColLabelValue( col ).Freq( '\n' );
306 
307  if( nl_count )
308  {
309  // Col Label height must be able to show nl_count+1 lines
310  if( row_height < line_height * ( nl_count+1 ) )
311  row_height += line_height * nl_count;
312  }
313  }
314 
315  // Update the column label size, but only if needed, to avoid generating useless
316  // and perhaps annoying UI events when the size does not change
317  if( initial_row_height != row_height )
318  SetColLabelSize( row_height );
319 }
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:53

References SetColLabelSize().

Referenced by GetVisibleWidth(), and PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES().

◆ GetShownColumns()

wxString WX_GRID::GetShownColumns ( )

Get a tokenized string containing the shown column indexes.

Tokens are separated by spaces.

Definition at line 117 of file wx_grid.cpp.

118 {
119  wxString shownColumns;
120 
121  for( int i = 0; i < GetNumberCols(); ++i )
122  {
123  if( IsColShown( i ) )
124  {
125  if( shownColumns.Length() )
126  shownColumns << wxT( " " );
127 
128  shownColumns << i;
129  }
130  }
131 
132  return shownColumns;
133 }

Referenced by DIALOG_LIB_SYMBOL_PROPERTIES::OnUpdateUI(), DIALOG_LIB_EDIT_PIN_TABLE::OnUpdateUI(), DIALOG_SHEET_PROPERTIES::OnUpdateUI(), DIALOG_SYMBOL_PROPERTIES::OnUpdateUI(), DIALOG_FOOTPRINT_PROPERTIES::~DIALOG_FOOTPRINT_PROPERTIES(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::~DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(), DIALOG_LIB_EDIT_PIN_TABLE::~DIALOG_LIB_EDIT_PIN_TABLE(), DIALOG_LIB_SYMBOL_PROPERTIES::~DIALOG_LIB_SYMBOL_PROPERTIES(), DIALOG_SHEET_PROPERTIES::~DIALOG_SHEET_PROPERTIES(), and DIALOG_SYMBOL_PROPERTIES::~DIALOG_SYMBOL_PROPERTIES().

◆ GetVisibleWidth()

int WX_GRID::GetVisibleWidth ( int  aCol,
bool  aHeader = true,
bool  aContents = false,
bool  aKeep = true 
)

Calculates the specified column based on the actual size of the text on screen.

Will return the maximum value of all calculated widths.

Parameters
aCol- Integer value of the column to resize. Specify -1 for the row labels.
aHeader- Include the header in the width calculation
aContents- Include the full contents of the column
aKeep- Use the current size as a minimum value
Returns
The new size of the column

Definition at line 246 of file wx_grid.cpp.

247 {
248  int size = 0;
249 
250  if( aCol < 0 )
251  {
252  if( aKeep )
253  size = GetRowLabelSize();
254 
255  // The 1.1 scale factor is due to the fact row labels use a bold font, bigger than
256  // the normal font.
257  // TODO: use a better way to evaluate the text size, for bold font
258  for( int row = 0; aContents && row < GetNumberRows(); row++ )
259  size = std::max( size, int( GetTextExtent( GetRowLabelValue( row ) + "M" ).x * 1.1 ) );
260  }
261  else
262  {
263  if( aKeep )
264  size = GetColSize( aCol );
265 
266  // 'M' is generally the widest character, so we buffer the column width by default to
267  // ensure we don't write a continuous line of text at the column header
268  if( aHeader )
269  {
271 
272  // The 1.1 scale factor is due to the fact headers use a bold font, bigger than
273  // the normal font.
274  size = std::max( size, int( GetTextExtent( GetColLabelValue( aCol ) + "M" ).x * 1.1 ) );
275  }
276 
277  for( int row = 0; aContents && row < GetNumberRows(); row++ )
278  {
279  // If we have text, get the size. Otherwise, use a placeholder for the checkbox
280  if( GetTable()->CanGetValueAs( row, aCol, wxGRID_VALUE_STRING ) )
281  size = std::max( size, GetTextExtent( GetCellValue( row, aCol ) + "M" ).x );
282  else
283  size = std::max( size, GetTextExtent( "MM" ).x );
284  }
285  }
286 
287  return size;
288 }
void EnsureColLabelsVisible()
Ensure the height of the row displaying the column labels is enough, even if labels are multiline tex...
Definition: wx_grid.cpp:291

References EnsureColLabelsVisible().

Referenced by DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::adjustGridColumns(), DIALOG_FOOTPRINT_PROPERTIES::adjustGridColumns(), PANEL_PACKAGES_VIEW::PANEL_PACKAGES_VIEW(), PANEL_SETUP_NETCLASSES::PANEL_SETUP_NETCLASSES(), PANEL_SETUP_TEXT_AND_GRAPHICS::PANEL_SETUP_TEXT_AND_GRAPHICS(), PANEL_SETUP_TRACKS_AND_VIAS::PANEL_SETUP_TRACKS_AND_VIAS(), PANEL_FP_PROPERTIES_3D_MODEL::ReloadModelsFromFootprint(), DIALOG_MANAGE_REPOSITORIES::setColumnWidths(), PANEL_PACKAGES_VIEW::setPackageDetails(), PANEL_PCBNEW_ACTION_PLUGINS::TransferDataToWindow(), PANEL_SETUP_TEXT_AND_GRAPHICS::TransferDataToWindow(), PANEL_FP_EDITOR_DEFAULTS::TransferDataToWindow(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::TransferDataToWindow(), DIALOG_FOOTPRINT_PROPERTIES::TransferDataToWindow(), and DIALOG_PCM::updatePendingActionsTab().

◆ onGridColMove()

void WX_GRID::onGridColMove ( wxGridEvent &  aEvent)
protected

Definition at line 239 of file wx_grid.cpp.

240 {
241  // wxWidgets won't move an open editor, so better just to close it
242  CommitPendingChanges( true );
243 }
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:190

References CommitPendingChanges().

Referenced by DestroyTable(), and SetTable().

◆ SetColLabelSize()

void WX_GRID::SetColLabelSize ( int  aHeight)

Hide wxGrid's SetColLabelSize() method with one which makes sure the size is tall enough for the system GUI font.

Parameters
height

Definition at line 53 of file wx_grid.cpp.

54 {
55  if( aHeight == 0 )
56  {
57  wxGrid::SetColLabelSize( 0 );
58  return;
59  }
60 
61  wxFont headingFont = KIUI::GetControlFont( this ).Bold();
62 
63  // Make sure the GUI font scales properly on GTK
64  SetLabelFont( headingFont );
65 
66  // Correct wxFormBuilder height for large fonts
67  int minHeight = headingFont.GetPixelSize().y + 2 * MIN_GRIDCELL_MARGIN;
68  wxGrid::SetColLabelSize( std::max( aHeight, minHeight ) );
69 }
wxFont GetControlFont(wxWindow *aWindow)
Definition: ui_common.cpp:150
#define MIN_GRIDCELL_MARGIN
Definition: wx_grid.cpp:31

References KIUI::GetControlFont(), and MIN_GRIDCELL_MARGIN.

Referenced by APPEARANCE_CONTROLS::APPEARANCE_CONTROLS(), APPEARANCE_CONTROLS_BASE::APPEARANCE_CONTROLS_BASE(), DIALOG_CONFIGURE_PATHS_BASE::DIALOG_CONFIGURE_PATHS_BASE(), DIALOG_EDIT_SYMBOLS_LIBID_BASE::DIALOG_EDIT_SYMBOLS_LIBID_BASE(), DIALOG_FOOTPRINT_PROPERTIES_BASE::DIALOG_FOOTPRINT_PROPERTIES_BASE(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR_BASE(), DIALOG_FP_PLUGIN_OPTIONS_BASE::DIALOG_FP_PLUGIN_OPTIONS_BASE(), DIALOG_LIB_EDIT_PIN_TABLE_BASE::DIALOG_LIB_EDIT_PIN_TABLE_BASE(), DIALOG_LIB_SYMBOL_PROPERTIES_BASE::DIALOG_LIB_SYMBOL_PROPERTIES_BASE(), DIALOG_MANAGE_REPOSITORIES_BASE::DIALOG_MANAGE_REPOSITORIES_BASE(), DIALOG_PAD_PRIMITIVE_POLY_PROPS_BASE::DIALOG_PAD_PRIMITIVE_POLY_PROPS_BASE(), DIALOG_PCM_BASE::DIALOG_PCM_BASE(), DIALOG_PIN_PROPERTIES_BASE::DIALOG_PIN_PROPERTIES_BASE(), DIALOG_SHEET_PROPERTIES_BASE::DIALOG_SHEET_PROPERTIES_BASE(), DIALOG_SWAP_LAYERS_BASE::DIALOG_SWAP_LAYERS_BASE(), DIALOG_SYMBOL_FIELDS_TABLE_BASE::DIALOG_SYMBOL_FIELDS_TABLE_BASE(), DIALOG_SYMBOL_PROPERTIES_BASE::DIALOG_SYMBOL_PROPERTIES_BASE(), EnsureColLabelsVisible(), FOOTPRINT_WIZARD_FRAME::initParameterGrid(), PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE::PANEL_EESCHEMA_TEMPLATE_FIELDNAMES_BASE(), PANEL_FP_EDITOR_DEFAULTS_BASE::PANEL_FP_EDITOR_DEFAULTS_BASE(), PANEL_FP_LIB_TABLE_BASE::PANEL_FP_LIB_TABLE_BASE(), PANEL_FP_PROPERTIES_3D_MODEL_BASE::PANEL_FP_PROPERTIES_3D_MODEL_BASE(), PANEL_PACKAGES_VIEW_BASE::PANEL_PACKAGES_VIEW_BASE(), PANEL_PCBNEW_ACTION_PLUGINS_BASE::PANEL_PCBNEW_ACTION_PLUGINS_BASE(), PANEL_SETUP_NETCLASSES_BASE::PANEL_SETUP_NETCLASSES_BASE(), PANEL_SETUP_TEXT_AND_GRAPHICS_BASE::PANEL_SETUP_TEXT_AND_GRAPHICS_BASE(), PANEL_SETUP_TRACKS_AND_VIAS_BASE::PANEL_SETUP_TRACKS_AND_VIAS_BASE(), PANEL_SYM_LIB_TABLE_BASE::PANEL_SYM_LIB_TABLE_BASE(), and PANEL_TEXT_VARIABLES_BASE::PANEL_TEXT_VARIABLES_BASE().

◆ SetTable()

void WX_GRID::SetTable ( wxGridTableBase *  table,
bool  aTakeOwnership = false 
)

Hide wxGrid's SetTable() method with one which doesn't mess up the grid column widths when setting the table.

Definition at line 72 of file wx_grid.cpp.

73 {
74  // wxGrid::SetTable() messes up the column widths from wxFormBuilder so we have to save
75  // and restore them.
76  int numberCols = GetNumberCols();
77  int* formBuilderColWidths = new int[numberCols];
78 
79  for( int i = 0; i < numberCols; ++i )
80  formBuilderColWidths[ i ] = GetColSize( i );
81 
82  wxGrid::SetTable( aTable );
83 
84  // wxGrid::SetTable() may change the number of columns, so prevent out-of-bounds access
85  // to formBuilderColWidths
86  numberCols = std::min( numberCols, GetNumberCols() );
87 
88  for( int i = 0; i < numberCols; ++i )
89  {
90  // correct wxFormBuilder width for large fonts and/or long translations
91  int headingWidth = GetTextExtent( GetColLabelValue( i ) ).x + 2 * MIN_GRIDCELL_MARGIN;
92 
93  SetColSize( i, std::max( formBuilderColWidths[ i ], headingWidth ) );
94  }
95 
96  delete[] formBuilderColWidths;
97 
98  Connect( wxEVT_GRID_COL_MOVE, wxGridEventHandler( WX_GRID::onGridColMove ), nullptr, this );
99 
100  m_weOwnTable = aTakeOwnership;
101 }
bool m_weOwnTable
Definition: wx_grid.h:121
#define MIN_GRIDCELL_MARGIN
Definition: wx_grid.cpp:31
void onGridColMove(wxGridEvent &aEvent)
Definition: wx_grid.cpp:239

References m_weOwnTable, MIN_GRIDCELL_MARGIN, and onGridColMove().

Referenced by APPEARANCE_CONTROLS::APPEARANCE_CONTROLS(), DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(), DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE(), DIALOG_LIB_SYMBOL_PROPERTIES::DIALOG_LIB_SYMBOL_PROPERTIES(), DIALOG_PIN_PROPERTIES::DIALOG_PIN_PROPERTIES(), DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES(), DIALOG_SWAP_LAYERS::DIALOG_SWAP_LAYERS(), DIALOG_SYMBOL_FIELDS_TABLE::DIALOG_SYMBOL_FIELDS_TABLE(), DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES(), PANEL_FP_EDITOR_DEFAULTS::PANEL_FP_EDITOR_DEFAULTS(), PANEL_FP_LIB_TABLE::PANEL_FP_LIB_TABLE(), and PANEL_SYM_LIB_TABLE::PANEL_SYM_LIB_TABLE().

◆ ShowEditorOnMouseUp()

void WX_GRID::ShowEditorOnMouseUp ( )
inline

WxWidgets has a bunch of bugs in its handling of wxGrid mouse events which close cell editors right after opening them.

Helpfully, it already has a bunch of work-arounds in place (such as the SetInSetFocus() hack), including one to make slow clicks work. We re-purpose this hack to work-around the bugs when we want to open an editor.

Definition at line 99 of file wx_grid.h.

99 { m_waitForSlowClick = true; }

Referenced by GRID_TRICKS::showEditor().

◆ ShowHideColumns()

void WX_GRID::ShowHideColumns ( const wxString &  shownColumns)

Show/hide the grid columns based on a tokenized string of shown column indexes.

Definition at line 136 of file wx_grid.cpp.

137 {
138  for( int i = 0; i < GetNumberCols(); ++i )
139  HideCol( i );
140 
141  wxStringTokenizer shownTokens( shownColumns );
142 
143  while( shownTokens.HasMoreTokens() )
144  {
145  long colNumber;
146  shownTokens.GetNextToken().ToLong( &colNumber );
147 
148  if( colNumber >= 0 && colNumber < GetNumberCols() )
149  ShowCol( colNumber );
150  }
151 }

Referenced by DIALOG_FOOTPRINT_PROPERTIES::DIALOG_FOOTPRINT_PROPERTIES(), DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR::DIALOG_FOOTPRINT_PROPERTIES_FP_EDITOR(), DIALOG_LIB_EDIT_PIN_TABLE::DIALOG_LIB_EDIT_PIN_TABLE(), DIALOG_LIB_SYMBOL_PROPERTIES::DIALOG_LIB_SYMBOL_PROPERTIES(), DIALOG_SHEET_PROPERTIES::DIALOG_SHEET_PROPERTIES(), and DIALOG_SYMBOL_PROPERTIES::DIALOG_SYMBOL_PROPERTIES().

Member Data Documentation

◆ m_weOwnTable

bool WX_GRID::m_weOwnTable
protected

Definition at line 121 of file wx_grid.h.

Referenced by SetTable(), and ~WX_GRID().


The documentation for this class was generated from the following files: