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)
 
void SetTooltipEnable (int aCol, bool aEnable=true)
 Enable the tooltip for a column. More...
 
bool GetTooltipEnabled (int aCol)
 Query if the tooltip for a column is enabled. More...
 

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)
 
void onGridMotion (wxMouseEvent &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
 
std::bitset< GRIDTRICKS_MAX_COLm_tooltipEnabled
 

Detailed Description

Definition at line 241 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 244 of file panel_fp_lib_table.cpp.

244  :
245  GRID_TRICKS( aGrid ),
246  m_dialog( aParent )
247  { }
GRID_TRICKS(WX_GRID *aGrid)
Definition: grid_tricks.cpp:40
DIALOG_EDIT_LIBRARY_TABLES * m_dialog

Member Function Documentation

◆ cutcopy()

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

Definition at line 649 of file grid_tricks.cpp.

650 {
651  wxLogNull doNotLog; // disable logging of failed clipboard actions
652 
653  if( doCopy && !wxTheClipboard->Open() )
654  return;
655 
656  wxGridTableBase* tbl = m_grid->GetTable();
657  wxString txt;
658 
659  // fill txt with a format that is compatible with most spreadsheets
660  for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
661  {
662  for( int col = m_sel_col_start; col < m_sel_col_start + m_sel_col_count; ++col )
663  {
664  if( !m_grid->IsColShown( col ) )
665  continue;
666 
667  txt += tbl->GetValue( row, col );
668 
669  if( col < m_sel_col_start + m_sel_col_count - 1 ) // that was not last column
670  txt += COL_SEP;
671 
672  if( doDelete )
673  {
674  if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_STRING ) )
675  tbl->SetValue( row, col, wxEmptyString );
676  }
677  }
678 
679  txt += ROW_SEP;
680  }
681 
682  if( doCopy )
683  {
684  wxTheClipboard->SetData( new wxTextDataObject( txt ) );
685  wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
686  wxTheClipboard->Close();
687  }
688 
689  if( doDelete )
690  m_grid->ForceRefresh();
691 }
int m_sel_row_count
Definition: grid_tricks.h:115
int m_sel_col_start
Definition: grid_tricks.h:114
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109
int m_sel_col_count
Definition: grid_tricks.h:116
int m_sel_row_start
Definition: grid_tricks.h:113
#define ROW_SEP
Definition: grid_tricks.cpp:37
#define COL_SEP
Definition: grid_tricks.cpp:36

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 295 of file panel_fp_lib_table.cpp.

296  {
297  if( event.GetId() == MYID_OPTIONS_EDITOR )
298  optionsEditor( m_grid->GetGridCursorRow() );
299  else
301  }
#define MYID_OPTIONS_EDITOR
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109
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 204 of file grid_tricks.cpp.

205 {
206  wxGridCellCoordsArray topLeft = m_grid->GetSelectionBlockTopLeft();
207  wxGridCellCoordsArray botRight = m_grid->GetSelectionBlockBottomRight();
208 
209  wxArrayInt cols = m_grid->GetSelectedCols();
210  wxArrayInt rows = m_grid->GetSelectedRows();
211 
212  if( topLeft.Count() && botRight.Count() )
213  {
214  m_sel_row_start = topLeft[0].GetRow();
215  m_sel_col_start = topLeft[0].GetCol();
216 
217  m_sel_row_count = botRight[0].GetRow() - m_sel_row_start + 1;
218  m_sel_col_count = botRight[0].GetCol() - m_sel_col_start + 1;
219  }
220  else if( cols.Count() )
221  {
222  m_sel_col_start = cols[0];
223  m_sel_col_count = cols.Count();
224  m_sel_row_start = 0;
225  m_sel_row_count = m_grid->GetNumberRows();
226  }
227  else if( rows.Count() )
228  {
229  m_sel_col_start = 0;
230  m_sel_col_count = m_grid->GetNumberCols();
231  m_sel_row_start = rows[0];
232  m_sel_row_count = rows.Count();
233  }
234  else
235  {
236  m_sel_row_start = m_grid->GetGridCursorRow();
237  m_sel_col_start = m_grid->GetGridCursorCol();
238  m_sel_row_count = m_sel_row_start >= 0 ? 1 : 0;
239  m_sel_col_count = m_sel_col_start >= 0 ? 1 : 0;
240  }
241 }
int m_sel_row_count
Definition: grid_tricks.h:115
int m_sel_col_start
Definition: grid_tricks.h:114
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109
int m_sel_col_count
Definition: grid_tricks.h:116
int m_sel_row_start
Definition: grid_tricks.h:113

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().

◆ GetTooltipEnabled()

bool GRID_TRICKS::GetTooltipEnabled ( int  aCol)
inlineinherited

Query if the tooltip for a column is enabled.

Parameters
aColis the column to query
Returns
if the tooltip is enabled for the column

Definition at line 79 of file grid_tricks.h.

80  {
81  return m_tooltipEnabled[aCol];
82  }
std::bitset< GRIDTRICKS_MAX_COL > m_tooltipEnabled
Definition: grid_tricks.h:118

References GRID_TRICKS::m_tooltipEnabled.

◆ handleDoubleClick()

bool FP_GRID_TRICKS::handleDoubleClick ( wxGridEvent &  aEvent)
inlineoverrideprotectedvirtual

Reimplemented from GRID_TRICKS.

Definition at line 273 of file panel_fp_lib_table.cpp.

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

References COL_OPTIONS, and optionsEditor().

◆ onGridCellLeftClick()

void GRID_TRICKS::onGridCellLeftClick ( wxGridEvent &  event)
protectedinherited

Definition at line 148 of file grid_tricks.cpp.

149 {
150  int row = aEvent.GetRow();
151  int col = aEvent.GetCol();
152 
153  // Don't make users click twice to toggle a checkbox or edit a text cell
154  if( !aEvent.GetModifiers() )
155  {
156  if( toggleCell( row, col ) )
157  return;
158 
159  if( showEditor( row, col ) )
160  return;
161  }
162 
163  aEvent.Skip();
164 }
bool toggleCell(int aRow, int aCol, bool aPreserveSelection=false)
Definition: grid_tricks.cpp:70
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 167 of file grid_tricks.cpp.

168 {
169  if( !handleDoubleClick( aEvent ) )
170  onGridCellLeftClick( aEvent );
171 }
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 244 of file grid_tricks.cpp.

245 {
246  wxMenu menu;
247 
248  showPopupMenu( menu );
249 }
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 252 of file grid_tricks.cpp.

253 {
255 
256  aEvent.Skip();
257 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:190

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 260 of file grid_tricks.cpp.

261 {
262  wxMenu menu;
263 
264  for( int i = 0; i < m_grid->GetNumberCols(); ++i )
265  {
266  int id = GRIDTRICKS_FIRST_SHOWHIDE + i;
267  menu.AppendCheckItem( id, m_grid->GetColLabelValue( i ) );
268  menu.Check( id, m_grid->IsColShown( i ) );
269  }
270 
271  m_grid->PopupMenu( &menu );
272 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109

References GRIDTRICKS_FIRST_SHOWHIDE, and GRID_TRICKS::m_grid.

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ onGridMotion()

void GRID_TRICKS::onGridMotion ( wxMouseEvent &  event)
protectedinherited

Definition at line 174 of file grid_tricks.cpp.

175 {
176  // Always skip the event
177  aEvent.Skip();
178 
179  wxPoint pt = aEvent.GetPosition();
180  wxPoint pos = m_grid->CalcScrolledPosition( wxPoint( pt.x, pt.y ) );
181 
182  int col = m_grid->XToCol( pos.x );
183  int row = m_grid->YToRow( pos.y );
184 
185  // Empty tooltip if the cell doesn't exist or the column doesn't have tooltips
186  if( ( col == wxNOT_FOUND ) || ( row == wxNOT_FOUND ) || !m_tooltipEnabled[col] )
187  {
188  m_grid->GetGridWindow()->SetToolTip( "" );
189  return;
190  }
191 
192  // Set the tooltip to the string contained in the cell
193  m_grid->GetGridWindow()->SetToolTip( m_grid->GetCellValue( row, col ) );
194 }
std::bitset< GRIDTRICKS_MAX_COL > m_tooltipEnabled
Definition: grid_tricks.h:118
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109

References GRID_TRICKS::m_grid, and GRID_TRICKS::m_tooltipEnabled.

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ onKeyDown()

void GRID_TRICKS::onKeyDown ( wxKeyEvent &  ev)
protectedinherited

Definition at line 361 of file grid_tricks.cpp.

362 {
363  if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'A' )
364  {
365  m_grid->SelectAll();
366  return;
367  }
368  else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'C' )
369  {
370  getSelectedArea();
371  cutcopy( true, false );
372  return;
373  }
374  else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'V' )
375  {
376  getSelectedArea();
377  paste_clipboard();
378  return;
379  }
380  else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'X' )
381  {
382  getSelectedArea();
383  cutcopy( true, true );
384  return;
385  }
386  else if( !ev.GetModifiers() && ev.GetKeyCode() == WXK_DELETE )
387  {
388  getSelectedArea();
389  cutcopy( false, true );
390  return;
391  }
392 
393  // space-bar toggling of checkboxes
394  if( ev.GetKeyCode() == ' ' )
395  {
396  bool retVal = false;
397 
398  // If only rows can be selected, only toggle the first cell in a row
399  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
400  {
401  wxArrayInt rowSel = m_grid->GetSelectedRows();
402 
403  for( unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
404  {
405  retVal |= toggleCell( rowSel[rowInd], 0, true );
406  }
407  }
408 
409  // If only columns can be selected, only toggle the first cell in a column
410  else if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectColumns )
411  {
412  wxArrayInt colSel = m_grid->GetSelectedCols();
413 
414  for( unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
415  {
416  retVal |= toggleCell( 0, colSel[colInd], true );
417  }
418  }
419 
420  // If the user can select the individual cells, toggle each cell selected
421  else if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectCells )
422  {
423  wxArrayInt rowSel = m_grid->GetSelectedRows();
424  wxArrayInt colSel = m_grid->GetSelectedCols();
425  wxGridCellCoordsArray cellSel = m_grid->GetSelectedCells();
426  wxGridCellCoordsArray topLeft = m_grid->GetSelectionBlockTopLeft();
427  wxGridCellCoordsArray botRight = m_grid->GetSelectionBlockBottomRight();
428 
429  // Iterate over every individually selected cell and try to toggle it
430  for( unsigned int cellInd = 0; cellInd < cellSel.GetCount(); cellInd++ )
431  {
432  retVal |= toggleCell( cellSel[cellInd].GetRow(), cellSel[cellInd].GetCol(), true );
433  }
434 
435  // Iterate over every column and try to toggle each cell in it
436  for( unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
437  {
438  for( int row = 0; row < m_grid->GetNumberRows(); row++ )
439  {
440  retVal |= toggleCell( row, colSel[colInd], true );
441  }
442  }
443 
444  // Iterate over every row and try to toggle each cell in it
445  for( unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
446  {
447  for( int col = 0; col < m_grid->GetNumberCols(); col++ )
448  {
449  retVal |= toggleCell( rowSel[rowInd], col, true );
450  }
451  }
452 
453  // Iterate over the selection blocks
454  for( unsigned int blockInd = 0; blockInd < topLeft.GetCount(); blockInd++ )
455  {
456  wxGridCellCoords start = topLeft[blockInd];
457  wxGridCellCoords end = botRight[blockInd];
458 
459  for( int row = start.GetRow(); row <= end.GetRow(); row++ )
460  {
461  for( int col = start.GetCol(); col <= end.GetCol(); col++ )
462  {
463  retVal |= toggleCell( row, col, true );
464  }
465  }
466  }
467  }
468  else
469  {
470  }
471 
472  // Return if there were any cells toggled
473  if( retVal )
474  return;
475  }
476 
477  // ctrl-tab for exit grid
478 #ifdef __APPLE__
479  bool ctrl = ev.RawControlDown();
480 #else
481  bool ctrl = ev.ControlDown();
482 #endif
483 
484  if( ctrl && ev.GetKeyCode() == WXK_TAB )
485  {
486  wxWindow* test = m_grid->GetNextSibling();
487 
488  if( !test )
489  test = m_grid->GetParent()->GetNextSibling();
490 
491  while( test && !test->IsTopLevel() )
492  {
493  test->SetFocus();
494 
495  if( test->HasFocus() )
496  break;
497 
498  if( !test->GetChildren().empty() )
499  {
500  test = test->GetChildren().front();
501  }
502  else if( test->GetNextSibling() )
503  {
504  test = test->GetNextSibling();
505  }
506  else
507  {
508  while( test )
509  {
510  test = test->GetParent();
511 
512  if( test && test->IsTopLevel() )
513  {
514  break;
515  }
516  else if( test && test->GetNextSibling() )
517  {
518  test = test->GetNextSibling();
519  break;
520  }
521  }
522  }
523  }
524 
525  return;
526  }
527 
528  ev.Skip( true );
529 }
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:109
bool toggleCell(int aRow, int aCol, bool aPreserveSelection=false)
Definition: grid_tricks.cpp:70
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 312 of file grid_tricks.cpp.

313 {
314  doPopupSelection( event );
315 }
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 694 of file grid_tricks.cpp.

695 {
696  // Respect ROW selectionMode when moving cursor
697 
698  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
699  {
700  int cursorRow = m_grid->GetGridCursorRow();
701  bool cursorInSelectedRow = false;
702 
703  for( int row : m_grid->GetSelectedRows() )
704  {
705  if( row == cursorRow )
706  {
707  cursorInSelectedRow = true;
708  break;
709  }
710  }
711 
712  if( !cursorInSelectedRow && cursorRow >= 0 )
713  m_grid->SelectRow( cursorRow );
714  }
715 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109

References GRID_TRICKS::m_grid.

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ optionsEditor()

void FP_GRID_TRICKS::optionsEditor ( int  aRow)
inlineprotected

Definition at line 252 of file panel_fp_lib_table.cpp.

253  {
254  FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) m_grid->GetTable();
255 
256  if( tbl->GetNumberRows() > aRow )
257  {
258  LIB_TABLE_ROW* row = tbl->at( (size_t) aRow );
259  const wxString& options = row->GetOptions();
260  wxString result = options;
261 
262  InvokePluginOptionsEditor( m_dialog, row->GetNickName(), row->GetType(), options,
263  &result );
264 
265  if( options != result )
266  {
267  row->SetOptions( result );
268  m_grid->Refresh();
269  }
270  }
271  }
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:109
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 532 of file grid_tricks.cpp.

533 {
534  wxLogNull doNotLog; // disable logging of failed clipboard actions
535 
536  if( wxTheClipboard->Open() )
537  {
538  if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
539  {
540  wxTextDataObject data;
541 
542  wxTheClipboard->GetData( data );
543 
544  paste_text( data.GetText() );
545  }
546 
547  wxTheClipboard->Close();
548  m_grid->ForceRefresh();
549  }
550 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109
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 305 of file panel_fp_lib_table.cpp.

306  {
307  FP_LIB_TABLE_GRID* tbl = (FP_LIB_TABLE_GRID*) m_grid->GetTable();
308  size_t ndx = cb_text.find( "(fp_lib_table" );
309 
310  if( ndx != std::string::npos )
311  {
312  // paste the FP_LIB_TABLE_ROWs of s-expression (fp_lib_table), starting
313  // at column 0 regardless of current cursor column.
314 
315  STRING_LINE_READER slr( TO_UTF8( cb_text ), "Clipboard" );
316  LIB_TABLE_LEXER lexer( &slr );
317  FP_LIB_TABLE tmp_tbl;
318  bool parsed = true;
319 
320  try
321  {
322  tmp_tbl.Parse( &lexer );
323  }
324  catch( PARSE_ERROR& pe )
325  {
326  DisplayError( m_dialog, pe.What() );
327  parsed = false;
328  }
329 
330  if( parsed )
331  {
332  // make sure the table is big enough...
333  if( tmp_tbl.GetCount() > (unsigned) tbl->GetNumberRows() )
334  tbl->AppendRows( tmp_tbl.GetCount() - tbl->GetNumberRows() );
335 
336  for( unsigned i = 0; i < tmp_tbl.GetCount(); ++i )
337  tbl->rows.replace( i, tmp_tbl.At( i ).clone() );
338  }
339 
340  m_grid->AutoSizeColumns( false );
341  }
342  else
343  {
344  // paste spreadsheet formatted text.
345  GRID_TRICKS::paste_text( cb_text );
346 
347  m_grid->AutoSizeColumns( false );
348  }
349  }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:279
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:109
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:30
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:240

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().

◆ SetTooltipEnable()

void GRID_TRICKS::SetTooltipEnable ( int  aCol,
bool  aEnable = true 
)
inlineinherited

Enable the tooltip for a column.

The tooltip is read from the string contained in the cell data.

Parameters
aColis the column to use
aEnableis true to enable the tooltip (default)

Definition at line 68 of file grid_tricks.h.

69  {
70  m_tooltipEnabled[aCol] = aEnable;
71  }
std::bitset< GRIDTRICKS_MAX_COL > m_tooltipEnabled
Definition: grid_tricks.h:118

References GRID_TRICKS::m_tooltipEnabled.

Referenced by PANEL_FP_PROPERTIES_3D_MODEL::PANEL_FP_PROPERTIES_3D_MODEL().

◆ showEditor()

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

Definition at line 113 of file grid_tricks.cpp.

114 {
115  if( m_grid->GetGridCursorRow() != aRow || m_grid->GetGridCursorCol() != aCol )
116  m_grid->SetGridCursor( aRow, aCol );
117 
118  if( m_grid->IsEditable() && !m_grid->IsReadOnly( aRow, aCol ) )
119  {
120  m_grid->ClearSelection();
121 
122  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
123  {
124  wxArrayInt rows = m_grid->GetSelectedRows();
125 
126  if( rows.size() != 1 || rows.Item( 0 ) != aRow )
127  m_grid->SelectRow( aRow );
128  }
129 
130  // For several reasons we can't enable the control here. There's the whole
131  // SetInSetFocus() issue/hack in wxWidgets, and there's also wxGrid's MouseUp
132  // handler which doesn't notice it's processing a MouseUp until after it has
133  // disabled the editor yet again. So we re-use wxWidgets' slow-click hack,
134  // which is processed later in the MouseUp handler.
135  //
136  // It should be pointed out that the fact that it's wxWidgets' hack doesn't
137  // make it any less of a hack. Be extra careful with any modifications here.
138  // See, in particular, https://bugs.launchpad.net/kicad/+bug/1817965.
140 
141  return true;
142  }
143 
144  return false;
145 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109
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 284 of file panel_fp_lib_table.cpp.

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

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 70 of file grid_tricks.cpp.

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

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 250 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

◆ m_tooltipEnabled

std::bitset<GRIDTRICKS_MAX_COL> GRID_TRICKS::m_tooltipEnabled
protectedinherited

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