KiCad PCB EDA Suite
FP_GRID_TRICKS Class Reference
Inheritance diagram for FP_GRID_TRICKS:
GRID_TRICKS

Public Member Functions

 FP_GRID_TRICKS (DIALOG_EDIT_LIBRARY_TABLES *aParent, WX_GRID *aGrid)
 

Protected Member Functions

void optionsEditor (int aRow)
 
bool handleDoubleClick (wxGridEvent &aEvent) override
 
void showPopupMenu (wxMenu &menu) override
 
void doPopupSelection (wxCommandEvent &event) override
 
void paste_text (const wxString &cb_text) override
 handle specialized clipboard text, with leading "(fp_lib_table", OR spreadsheet formatted text. More...
 
void getSelectedArea ()
 Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above. More...
 
void onGridCellLeftClick (wxGridEvent &event)
 
void onGridCellLeftDClick (wxGridEvent &event)
 
void onGridCellRightClick (wxGridEvent &event)
 
void onGridLabelLeftClick (wxGridEvent &event)
 
void onGridLabelRightClick (wxGridEvent &event)
 
void onPopupSelection (wxCommandEvent &event)
 
void onKeyDown (wxKeyEvent &ev)
 
void onUpdateUI (wxUpdateUIEvent &event)
 
bool toggleCell (int aRow, int aCol, bool aPreserveSelection=false)
 
bool showEditor (int aRow, int aCol)
 
virtual void paste_clipboard ()
 
virtual void cutcopy (bool doCopy, bool doDelete)
 

Protected Attributes

DIALOG_EDIT_LIBRARY_TABLESm_dialog
 
WX_GRIDm_grid
 I don't own the grid, but he owns me. More...
 
int m_sel_row_start
 
int m_sel_col_start
 
int m_sel_row_count
 
int m_sel_col_count
 

Detailed Description

Definition at line 239 of file panel_fp_lib_table.cpp.

Constructor & Destructor Documentation

◆ FP_GRID_TRICKS()

FP_GRID_TRICKS::FP_GRID_TRICKS ( DIALOG_EDIT_LIBRARY_TABLES aParent,
WX_GRID aGrid 
)
inline

Definition at line 242 of file panel_fp_lib_table.cpp.

242  :
243  GRID_TRICKS( aGrid ),
244  m_dialog( aParent )
245  { }
GRID_TRICKS(WX_GRID *aGrid)
Definition: grid_tricks.cpp:38
DIALOG_EDIT_LIBRARY_TABLES * m_dialog

Member Function Documentation

◆ cutcopy()

void GRID_TRICKS::cutcopy ( bool  doCopy,
bool  doDelete 
)
protectedvirtualinherited

Definition at line 606 of file grid_tricks.cpp.

607 {
608  wxLogNull doNotLog; // disable logging of failed clipboard actions
609 
610  if( doCopy && !wxTheClipboard->Open() )
611  return;
612 
613  wxGridTableBase* tbl = m_grid->GetTable();
614  wxString txt;
615 
616  // fill txt with a format that is compatible with most spreadsheets
617  for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
618  {
619  for( int col = m_sel_col_start; col < m_sel_col_start + m_sel_col_count; ++col )
620  {
621  txt += tbl->GetValue( row, col );
622 
623  if( col < m_sel_col_start + m_sel_col_count - 1 ) // that was not last column
624  txt += COL_SEP;
625 
626  if( doDelete )
627  {
628  if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_STRING ) )
629  tbl->SetValue( row, col, wxEmptyString );
630  }
631  }
632 
633  txt += ROW_SEP;
634  }
635 
636  if( doCopy )
637  {
638  wxTheClipboard->SetData( new wxTextDataObject( txt ) );
639  wxTheClipboard->Close();
640  }
641 
642  if( doDelete )
643  m_grid->ForceRefresh();
644 }
int m_sel_row_count
Definition: grid_tricks.h:87
int m_sel_col_start
Definition: grid_tricks.h:86
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:81
int m_sel_col_count
Definition: grid_tricks.h:88
int m_sel_row_start
Definition: grid_tricks.h:85
#define ROW_SEP
Definition: grid_tricks.cpp:35
#define COL_SEP
Definition: grid_tricks.cpp:34

References COL_SEP, GRID_TRICKS::m_grid, GRID_TRICKS::m_sel_col_count, GRID_TRICKS::m_sel_col_start, GRID_TRICKS::m_sel_row_count, GRID_TRICKS::m_sel_row_start, and ROW_SEP.

Referenced by GRID_TRICKS::doPopupSelection(), and GRID_TRICKS::onKeyDown().

◆ doPopupSelection()

void FP_GRID_TRICKS::doPopupSelection ( wxCommandEvent &  event)
inlineoverrideprotectedvirtual

Reimplemented from GRID_TRICKS.

Definition at line 293 of file panel_fp_lib_table.cpp.

294  {
295  if( event.GetId() == MYID_OPTIONS_EDITOR )
296  optionsEditor( m_grid->GetGridCursorRow() );
297  else
299  }
#define MYID_OPTIONS_EDITOR
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:81
void optionsEditor(int aRow)
virtual void doPopupSelection(wxCommandEvent &event)

References GRID_TRICKS::doPopupSelection(), GRID_TRICKS::m_grid, MYID_OPTIONS_EDITOR, and optionsEditor().

◆ getSelectedArea()

void GRID_TRICKS::getSelectedArea ( )
protectedinherited

Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above.

Definition at line 168 of file grid_tricks.cpp.

169 {
170  wxGridCellCoordsArray topLeft = m_grid->GetSelectionBlockTopLeft();
171  wxGridCellCoordsArray botRight = m_grid->GetSelectionBlockBottomRight();
172 
173  wxArrayInt cols = m_grid->GetSelectedCols();
174  wxArrayInt rows = m_grid->GetSelectedRows();
175 
176  if( topLeft.Count() && botRight.Count() )
177  {
178  m_sel_row_start = topLeft[0].GetRow();
179  m_sel_col_start = topLeft[0].GetCol();
180 
181  m_sel_row_count = botRight[0].GetRow() - m_sel_row_start + 1;
182  m_sel_col_count = botRight[0].GetCol() - m_sel_col_start + 1;
183  }
184  else if( cols.Count() )
185  {
186  m_sel_col_start = cols[0];
187  m_sel_col_count = cols.Count();
188  m_sel_row_start = 0;
189  m_sel_row_count = m_grid->GetNumberRows();
190  }
191  else if( rows.Count() )
192  {
193  m_sel_col_start = 0;
194  m_sel_col_count = m_grid->GetNumberCols();
195  m_sel_row_start = rows[0];
196  m_sel_row_count = rows.Count();
197  }
198  else
199  {
200  m_sel_row_start = m_grid->GetGridCursorRow();
201  m_sel_col_start = m_grid->GetGridCursorCol();
202  m_sel_row_count = m_sel_row_start >= 0 ? 1 : 0;
203  m_sel_col_count = m_sel_col_start >= 0 ? 1 : 0;
204  }
205 }
int m_sel_row_count
Definition: grid_tricks.h:87
int m_sel_col_start
Definition: grid_tricks.h:86
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:81
int m_sel_col_count
Definition: grid_tricks.h:88
int m_sel_row_start
Definition: grid_tricks.h:85

References GRID_TRICKS::m_grid, GRID_TRICKS::m_sel_col_count, GRID_TRICKS::m_sel_col_start, GRID_TRICKS::m_sel_row_count, and GRID_TRICKS::m_sel_row_start.

Referenced by GRID_TRICKS::onKeyDown(), and GRID_TRICKS::showPopupMenu().

◆ handleDoubleClick()

bool FP_GRID_TRICKS::handleDoubleClick ( wxGridEvent &  aEvent)
inlineoverrideprotectedvirtual

Reimplemented from GRID_TRICKS.

Definition at line 271 of file panel_fp_lib_table.cpp.

272  {
273  if( aEvent.GetCol() == COL_OPTIONS )
274  {
275  optionsEditor( aEvent.GetRow() );
276  return true;
277  }
278 
279  return false;
280  }
void optionsEditor(int aRow)

References COL_OPTIONS, and optionsEditor().

◆ onGridCellLeftClick()

void GRID_TRICKS::onGridCellLeftClick ( wxGridEvent &  event)
protectedinherited

Definition at line 135 of file grid_tricks.cpp.

136 {
137  int row = aEvent.GetRow();
138  int col = aEvent.GetCol();
139 
140  // Don't make users click twice to toggle a checkbox or edit a text cell
141  if( !aEvent.GetModifiers() )
142  {
143  if( toggleCell( row, col ) )
144  return;
145 
146  if( showEditor( row, col ) )
147  return;
148  }
149 
150  aEvent.Skip();
151 }
bool toggleCell(int aRow, int aCol, bool aPreserveSelection=false)
Definition: grid_tricks.cpp:57
bool showEditor(int aRow, int aCol)

References GRID_TRICKS::showEditor(), and GRID_TRICKS::toggleCell().

Referenced by GRID_TRICKS::GRID_TRICKS(), and GRID_TRICKS::onGridCellLeftDClick().

◆ onGridCellLeftDClick()

void GRID_TRICKS::onGridCellLeftDClick ( wxGridEvent &  event)
protectedinherited

Definition at line 154 of file grid_tricks.cpp.

155 {
156  if( !handleDoubleClick( aEvent ) )
157  onGridCellLeftClick( aEvent );
158 }
void onGridCellLeftClick(wxGridEvent &event)
virtual bool handleDoubleClick(wxGridEvent &aEvent)

References GRID_TRICKS::handleDoubleClick(), and GRID_TRICKS::onGridCellLeftClick().

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ onGridCellRightClick()

void GRID_TRICKS::onGridCellRightClick ( wxGridEvent &  event)
protectedinherited

Definition at line 208 of file grid_tricks.cpp.

209 {
210  wxMenu menu;
211 
212  showPopupMenu( menu );
213 }
virtual void showPopupMenu(wxMenu &menu)

References GRID_TRICKS::showPopupMenu().

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ onGridLabelLeftClick()

void GRID_TRICKS::onGridLabelLeftClick ( wxGridEvent &  event)
protectedinherited

Definition at line 216 of file grid_tricks.cpp.

217 {
219 
220  aEvent.Skip();
221 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:81
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:182

References WX_GRID::CommitPendingChanges(), and GRID_TRICKS::m_grid.

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ onGridLabelRightClick()

void GRID_TRICKS::onGridLabelRightClick ( wxGridEvent &  event)
protectedinherited

Definition at line 224 of file grid_tricks.cpp.

225 {
226  wxMenu menu;
227 
228  for( int i = 0; i < m_grid->GetNumberCols(); ++i )
229  {
230  int id = GRIDTRICKS_FIRST_SHOWHIDE + i;
231  menu.AppendCheckItem( id, m_grid->GetColLabelValue( i ) );
232  menu.Check( id, m_grid->IsColShown( i ) );
233  }
234 
235  m_grid->PopupMenu( &menu );
236 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:81

References GRIDTRICKS_FIRST_SHOWHIDE, and GRID_TRICKS::m_grid.

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ onKeyDown()

void GRID_TRICKS::onKeyDown ( wxKeyEvent &  ev)
protectedinherited

Definition at line 322 of file grid_tricks.cpp.

323 {
324  if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'A' )
325  {
326  m_grid->SelectAll();
327  return;
328  }
329  else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'C' )
330  {
331  getSelectedArea();
332  cutcopy( true, false );
333  return;
334  }
335  else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'V' )
336  {
337  getSelectedArea();
338  paste_clipboard();
339  return;
340  }
341  else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'X' )
342  {
343  getSelectedArea();
344  cutcopy( true, true );
345  return;
346  }
347  else if( !ev.GetModifiers() && ev.GetKeyCode() == WXK_DELETE )
348  {
349  getSelectedArea();
350  cutcopy( false, true );
351  return;
352  }
353 
354  // space-bar toggling of checkboxes
355  if( ev.GetKeyCode() == ' ' )
356  {
357  bool retVal = false;
358 
359  // If only rows can be selected, only toggle the first cell in a row
360  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
361  {
362  wxArrayInt rowSel = m_grid->GetSelectedRows();
363 
364  for( unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
365  {
366  retVal |= toggleCell( rowSel[rowInd], 0, true );
367  }
368  }
369 
370  // If only columns can be selected, only toggle the first cell in a column
371  else if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectColumns )
372  {
373  wxArrayInt colSel = m_grid->GetSelectedCols();
374 
375  for( unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
376  {
377  retVal |= toggleCell( 0, colSel[colInd], true );
378  }
379  }
380 
381  // If the user can select the individual cells, toggle each cell selected
382  else if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectCells )
383  {
384  wxArrayInt rowSel = m_grid->GetSelectedRows();
385  wxArrayInt colSel = m_grid->GetSelectedCols();
386  wxGridCellCoordsArray cellSel = m_grid->GetSelectedCells();
387  wxGridCellCoordsArray topLeft = m_grid->GetSelectionBlockTopLeft();
388  wxGridCellCoordsArray botRight = m_grid->GetSelectionBlockBottomRight();
389 
390  // Iterate over every individually selected cell and try to toggle it
391  for( unsigned int cellInd = 0; cellInd < cellSel.GetCount(); cellInd++ )
392  {
393  retVal |= toggleCell( cellSel[cellInd].GetRow(), cellSel[cellInd].GetCol(), true );
394  }
395 
396  // Iterate over every column and try to toggle each cell in it
397  for( unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
398  {
399  for( int row = 0; row < m_grid->GetNumberRows(); row++ )
400  {
401  retVal |= toggleCell( row, colSel[colInd], true );
402  }
403  }
404 
405  // Iterate over every row and try to toggle each cell in it
406  for( unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
407  {
408  for( int col = 0; col < m_grid->GetNumberCols(); col++ )
409  {
410  retVal |= toggleCell( rowSel[rowInd], col, true );
411  }
412  }
413 
414  // Iterate over the selection blocks
415  for( unsigned int blockInd = 0; blockInd < topLeft.GetCount(); blockInd++ )
416  {
417  wxGridCellCoords start = topLeft[blockInd];
418  wxGridCellCoords end = botRight[blockInd];
419 
420  for( int row = start.GetRow(); row <= end.GetRow(); row++ )
421  {
422  for( int col = start.GetCol(); col <= end.GetCol(); col++ )
423  {
424  retVal |= toggleCell( row, col, true );
425  }
426  }
427  }
428  }
429  else
430  {
431  }
432 
433  // Return if there were any cells toggled
434  if( retVal )
435  return;
436  }
437 
438  // ctrl-tab for exit grid
439 #ifdef __APPLE__
440  bool ctrl = ev.RawControlDown();
441 #else
442  bool ctrl = ev.ControlDown();
443 #endif
444 
445  if( ctrl && ev.GetKeyCode() == WXK_TAB )
446  {
447  wxWindow* test = m_grid->GetNextSibling();
448 
449  if( !test )
450  test = m_grid->GetParent()->GetNextSibling();
451 
452  while( test && !test->IsTopLevel() )
453  {
454  test->SetFocus();
455 
456  if( test->HasFocus() )
457  break;
458 
459  if( !test->GetChildren().empty() )
460  test = test->GetChildren().front();
461  else if( test->GetNextSibling() )
462  test = test->GetNextSibling();
463  else
464  {
465  while( test )
466  {
467  test = test->GetParent();
468 
469  if( test && test->IsTopLevel() )
470  {
471  break;
472  }
473  else if( test && test->GetNextSibling() )
474  {
475  test = test->GetNextSibling();
476  break;
477  }
478  }
479  }
480  }
481 
482  return;
483  }
484 
485  ev.Skip( true );
486 }
void getSelectedArea()
Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above.
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:81
bool toggleCell(int aRow, int aCol, bool aPreserveSelection=false)
Definition: grid_tricks.cpp:57
virtual void cutcopy(bool doCopy, bool doDelete)
virtual void paste_clipboard()

References GRID_TRICKS::cutcopy(), GRID_TRICKS::getSelectedArea(), GRID_TRICKS::m_grid, GRID_TRICKS::paste_clipboard(), and GRID_TRICKS::toggleCell().

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ onPopupSelection()

void GRID_TRICKS::onPopupSelection ( wxCommandEvent &  event)
protectedinherited

Definition at line 273 of file grid_tricks.cpp.

274 {
275  doPopupSelection( event );
276 }
virtual void doPopupSelection(wxCommandEvent &event)

References GRID_TRICKS::doPopupSelection().

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ onUpdateUI()

void GRID_TRICKS::onUpdateUI ( wxUpdateUIEvent &  event)
protectedinherited

Definition at line 647 of file grid_tricks.cpp.

648 {
649  // Respect ROW selectionMode when moving cursor
650 
651  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
652  {
653  int cursorRow = m_grid->GetGridCursorRow();
654  bool cursorInSelectedRow = false;
655 
656  for( int row : m_grid->GetSelectedRows() )
657  {
658  if( row == cursorRow )
659  {
660  cursorInSelectedRow = true;
661  break;
662  }
663  }
664 
665  if( !cursorInSelectedRow && cursorRow >= 0 )
666  m_grid->SelectRow( cursorRow );
667  }
668 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:81

References GRID_TRICKS::m_grid.

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ optionsEditor()

void FP_GRID_TRICKS::optionsEditor ( int  aRow)
inlineprotected

Definition at line 250 of file panel_fp_lib_table.cpp.

251  {
252  FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) m_grid->GetTable();
253 
254  if( tbl->GetNumberRows() > aRow )
255  {
256  LIB_TABLE_ROW* row = tbl->at( (size_t) aRow );
257  const wxString& options = row->GetOptions();
258  wxString result = options;
259 
260  InvokePluginOptionsEditor( m_dialog, row->GetNickName(), row->GetType(), options,
261  &result );
262 
263  if( options != result )
264  {
265  row->SetOptions( result );
266  m_grid->Refresh();
267  }
268  }
269  }
const wxString & GetOptions() const
Return the options string, which may hold a password or anything else needed to instantiate the under...
void InvokePluginOptionsEditor(wxWindow *aCaller, const wxString &aNickname, const wxString &aPluginType, const wxString &aOptions, wxString *aResult)
Function InvokePluginOptionsEditor calls DIALOG_FP_PLUGIN_OPTIONS dialog so that plugin options set c...
Hold a record identifying a library accessed by the appropriate plug in object in the LIB_TABLE.
virtual const wxString GetType() const =0
Return the type of library represented by this row.
int GetNumberRows() override
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:81
const wxString & GetNickName() const
DIALOG_EDIT_LIBRARY_TABLES * m_dialog
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
void SetOptions(const wxString &aOptions)
Change the library options strings.
LIB_TABLE_ROW * at(size_t aIndex) override

References FP_LIB_TABLE_GRID::at(), LIB_TABLE_ROW::GetNickName(), LIB_TABLE_GRID::GetNumberRows(), LIB_TABLE_ROW::GetOptions(), LIB_TABLE_ROW::GetType(), InvokePluginOptionsEditor(), m_dialog, GRID_TRICKS::m_grid, and LIB_TABLE_ROW::SetOptions().

Referenced by doPopupSelection(), and handleDoubleClick().

◆ paste_clipboard()

void GRID_TRICKS::paste_clipboard ( )
protectedvirtualinherited

Definition at line 489 of file grid_tricks.cpp.

490 {
491  wxLogNull doNotLog; // disable logging of failed clipboard actions
492 
493  if( wxTheClipboard->Open() )
494  {
495  if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
496  {
497  wxTextDataObject data;
498 
499  wxTheClipboard->GetData( data );
500 
501  paste_text( data.GetText() );
502  }
503 
504  wxTheClipboard->Close();
505  m_grid->ForceRefresh();
506  }
507 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:81
virtual void paste_text(const wxString &cb_text)

References GRID_TRICKS::m_grid, and GRID_TRICKS::paste_text().

Referenced by GRID_TRICKS::doPopupSelection(), and GRID_TRICKS::onKeyDown().

◆ paste_text()

void FP_GRID_TRICKS::paste_text ( const wxString &  cb_text)
inlineoverrideprotectedvirtual

handle specialized clipboard text, with leading "(fp_lib_table", OR spreadsheet formatted text.

Reimplemented from GRID_TRICKS.

Definition at line 303 of file panel_fp_lib_table.cpp.

304  {
305  FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) m_grid->GetTable();
306  size_t ndx = cb_text.find( "(fp_lib_table" );
307 
308  if( ndx != std::string::npos )
309  {
310  // paste the FP_LIB_TABLE_ROWs of s-expression (fp_lib_table), starting
311  // at column 0 regardless of current cursor column.
312 
313  STRING_LINE_READER slr( TO_UTF8( cb_text ), "Clipboard" );
314  LIB_TABLE_LEXER lexer( &slr );
315  FP_LIB_TABLE tmp_tbl;
316  bool parsed = true;
317 
318  try
319  {
320  tmp_tbl.Parse( &lexer );
321  }
322  catch( PARSE_ERROR& pe )
323  {
324  DisplayError( m_dialog, pe.What() );
325  parsed = false;
326  }
327 
328  if( parsed )
329  {
330  // make sure the table is big enough...
331  if( tmp_tbl.GetCount() > (unsigned) tbl->GetNumberRows() )
332  tbl->AppendRows( tmp_tbl.GetCount() - tbl->GetNumberRows() );
333 
334  for( unsigned i = 0; i < tmp_tbl.GetCount(); ++i )
335  tbl->rows.replace( i, tmp_tbl.At( i ).clone() );
336  }
337 
338  m_grid->AutoSizeColumns( false );
339  }
340  else
341  {
342  // paste spreadsheet formatted text.
343  GRID_TRICKS::paste_text( cb_text );
344 
345  m_grid->AutoSizeColumns( false );
346  }
347  }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:252
unsigned GetCount() const
Get the number of rows contained in the table.
LIB_TABLE_ROWS rows
int GetNumberRows() override
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:81
virtual void paste_text(const wxString &cb_text)
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
LIB_TABLE_ROW * clone() const
virtual void Parse(LIB_TABLE_LEXER *aLexer) override
Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objec...
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:29
DIALOG_EDIT_LIBRARY_TABLES * m_dialog
bool AppendRows(size_t aNumRows=1) override
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:118
LIB_TABLE_ROW & At(unsigned aIndex)
Get the 'n'th LIB_TABLE_ROW object.
This class builds a wxGridTableBase by wrapping an FP_LIB_TABLE object.
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:237

References LIB_TABLE_GRID::AppendRows(), LIB_TABLE::At(), LIB_TABLE_ROW::clone(), DisplayError(), LIB_TABLE::GetCount(), LIB_TABLE_GRID::GetNumberRows(), m_dialog, GRID_TRICKS::m_grid, FP_LIB_TABLE::Parse(), GRID_TRICKS::paste_text(), LIB_TABLE::rows, TO_UTF8, and IO_ERROR::What().

◆ showEditor()

bool GRID_TRICKS::showEditor ( int  aRow,
int  aCol 
)
protectedinherited

Definition at line 100 of file grid_tricks.cpp.

101 {
102  if( m_grid->GetGridCursorRow() != aRow || m_grid->GetGridCursorCol() != aCol )
103  m_grid->SetGridCursor( aRow, aCol );
104 
105  if( m_grid->IsEditable() && !m_grid->IsReadOnly( aRow, aCol ) )
106  {
107  m_grid->ClearSelection();
108 
109  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
110  {
111  wxArrayInt rows = m_grid->GetSelectedRows();
112 
113  if( rows.size() != 1 || rows.Item( 0 ) != aRow )
114  m_grid->SelectRow( aRow );
115  }
116 
117  // For several reasons we can't enable the control here. There's the whole
118  // SetInSetFocus() issue/hack in wxWidgets, and there's also wxGrid's MouseUp
119  // handler which doesn't notice it's processing a MouseUp until after it has
120  // disabled the editor yet again. So we re-use wxWidgets' slow-click hack,
121  // which is processed later in the MouseUp handler.
122  //
123  // It should be pointed out that the fact that it's wxWidgets' hack doesn't
124  // make it any less of a hack. Be extra careful with any modifications here.
125  // See, in particular, https://bugs.launchpad.net/kicad/+bug/1817965.
127 
128  return true;
129  }
130 
131  return false;
132 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:81
void ShowEditorOnMouseUp()
WxWidgets has a bunch of bugs in its handling of wxGrid mouse events which close cell editors right a...
Definition: wx_grid.h:99

References GRID_TRICKS::m_grid, and WX_GRID::ShowEditorOnMouseUp().

Referenced by GRID_TRICKS::onGridCellLeftClick().

◆ showPopupMenu()

void FP_GRID_TRICKS::showPopupMenu ( wxMenu &  menu)
inlineoverrideprotectedvirtual

Reimplemented from GRID_TRICKS.

Definition at line 282 of file panel_fp_lib_table.cpp.

283  {
284  if( m_grid->GetGridCursorCol() == COL_OPTIONS )
285  {
286  menu.Append( MYID_OPTIONS_EDITOR, _( "Options Editor..." ), _( "Edit options" ) );
287  menu.AppendSeparator();
288  }
289 
291  }
#define MYID_OPTIONS_EDITOR
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:81
virtual void showPopupMenu(wxMenu &menu)
#define _(s)
Definition: 3d_actions.cpp:33

References _, COL_OPTIONS, GRID_TRICKS::m_grid, MYID_OPTIONS_EDITOR, and GRID_TRICKS::showPopupMenu().

◆ toggleCell()

bool GRID_TRICKS::toggleCell ( int  aRow,
int  aCol,
bool  aPreserveSelection = false 
)
protectedinherited

Definition at line 57 of file grid_tricks.cpp.

58 {
59  auto renderer = m_grid->GetCellRenderer( aRow, aCol );
60  bool isCheckbox = ( dynamic_cast<wxGridCellBoolRenderer*>( renderer ) != nullptr );
61  renderer->DecRef();
62 
63  if( isCheckbox )
64  {
65  if( !aPreserveSelection )
66  m_grid->ClearSelection();
67 
68  m_grid->SetGridCursor( aRow, aCol );
69 
70  wxGridTableBase* model = m_grid->GetTable();
71 
72  if( model->CanGetValueAs( aRow, aCol, wxGRID_VALUE_BOOL )
73  && model->CanSetValueAs( aRow, aCol, wxGRID_VALUE_BOOL ) )
74  {
75  model->SetValueAsBool( aRow, aCol, !model->GetValueAsBool( aRow, aCol ) );
76  }
77  else // fall back to string processing
78  {
79  if( model->GetValue( aRow, aCol ) == wxT( "1" ) )
80  model->SetValue( aRow, aCol, wxT( "0" ) );
81  else
82  model->SetValue( aRow, aCol, wxT( "1" ) );
83  }
84 
85  // Mac needs this for the keyboard events; Linux appears to always need it.
86  m_grid->ForceRefresh();
87 
88  // Let any clients know
89  wxGridEvent event( m_grid->GetId(), wxEVT_GRID_CELL_CHANGED, m_grid, aRow, aCol );
90  event.SetString( model->GetValue( aRow, aCol ) );
91  m_grid->GetEventHandler()->ProcessEvent( event );
92 
93  return true;
94  }
95 
96  return false;
97 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:81

References GRID_TRICKS::m_grid.

Referenced by GRID_TRICKS::onGridCellLeftClick(), and GRID_TRICKS::onKeyDown().

Member Data Documentation

◆ m_dialog

DIALOG_EDIT_LIBRARY_TABLES* FP_GRID_TRICKS::m_dialog
protected

Definition at line 248 of file panel_fp_lib_table.cpp.

Referenced by optionsEditor(), and paste_text().

◆ m_grid

◆ m_sel_col_count

int GRID_TRICKS::m_sel_col_count
protectedinherited

◆ m_sel_col_start

int GRID_TRICKS::m_sel_col_start
protectedinherited

◆ m_sel_row_count

int GRID_TRICKS::m_sel_row_count
protectedinherited

◆ m_sel_row_start

int GRID_TRICKS::m_sel_row_start
protectedinherited

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