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

Public Member Functions

 SYMBOL_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

virtual void paste_text (const wxString &cb_text) override
 handle specialized clipboard text, with leading "(sym_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 &event)
 
void onCharHook (wxKeyEvent &event)
 
void onUpdateUI (wxUpdateUIEvent &event)
 
void onGridMotion (wxMouseEvent &event)
 
virtual bool handleDoubleClick (wxGridEvent &aEvent)
 
virtual void showPopupMenu (wxMenu &menu)
 
virtual void doPopupSelection (wxCommandEvent &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 137 of file panel_sym_lib_table.cpp.

Constructor & Destructor Documentation

◆ SYMBOL_GRID_TRICKS()

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

Definition at line 140 of file panel_sym_lib_table.cpp.

140  :
141  GRID_TRICKS( aGrid ),
142  m_dialog( aParent )
143  {
144  }
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 687 of file grid_tricks.cpp.

688 {
689  wxLogNull doNotLog; // disable logging of failed clipboard actions
690 
691  if( doCopy && !wxTheClipboard->Open() )
692  return;
693 
694  wxGridTableBase* tbl = m_grid->GetTable();
695  wxString txt;
696 
697  // fill txt with a format that is compatible with most spreadsheets
698  for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
699  {
700  for( int col = m_sel_col_start; col < m_sel_col_start + m_sel_col_count; ++col )
701  {
702  if( !m_grid->IsColShown( col ) )
703  continue;
704 
705  txt += tbl->GetValue( row, col );
706 
707  if( col < m_sel_col_start + m_sel_col_count - 1 ) // that was not last column
708  txt += COL_SEP;
709 
710  if( doDelete )
711  {
712  if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_STRING ) )
713  tbl->SetValue( row, col, wxEmptyString );
714  }
715  }
716 
717  txt += ROW_SEP;
718  }
719 
720  if( doCopy )
721  {
722  wxTheClipboard->SetData( new wxTextDataObject( txt ) );
723  wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
724  wxTheClipboard->Close();
725  }
726 
727  if( doDelete )
728  m_grid->ForceRefresh();
729 }
int m_sel_row_count
Definition: grid_tricks.h:116
int m_sel_col_start
Definition: grid_tricks.h:115
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:110
int m_sel_col_count
Definition: grid_tricks.h:117
int m_sel_row_start
Definition: grid_tricks.h:114
#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 GRID_TRICKS::doPopupSelection ( wxCommandEvent &  event)
protectedvirtualinherited

Reimplemented in FP_GRID_TRICKS, FIELDS_EDITOR_GRID_TRICKS, and FIELDS_GRID_TRICKS.

Definition at line 322 of file grid_tricks.cpp.

323 {
324  int menu_id = event.GetId();
325 
326  // assume getSelectedArea() was called by rightClickPopupMenu() and there's
327  // no way to have gotten here without that having been called.
328 
329  switch( menu_id )
330  {
331  case GRIDTRICKS_ID_CUT:
332  cutcopy( true, true );
333  break;
334 
335  case GRIDTRICKS_ID_COPY:
336  cutcopy( true, false );
337  break;
338 
340  cutcopy( false, true );
341  break;
342 
343  case GRIDTRICKS_ID_PASTE:
344  paste_clipboard();
345  break;
346 
348  m_grid->SelectAll();
349  break;
350 
351  default:
352  if( menu_id >= GRIDTRICKS_FIRST_SHOWHIDE )
353  {
354  int col = menu_id - GRIDTRICKS_FIRST_SHOWHIDE;
355 
356  if( m_grid->IsColShown( col ) )
357  m_grid->HideCol( col );
358  else
359  m_grid->ShowCol( col );
360  }
361  }
362 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:110
virtual void cutcopy(bool doCopy, bool doDelete)
virtual void paste_clipboard()

References GRID_TRICKS::cutcopy(), GRIDTRICKS_FIRST_SHOWHIDE, GRIDTRICKS_ID_COPY, GRIDTRICKS_ID_CUT, GRIDTRICKS_ID_DELETE, GRIDTRICKS_ID_PASTE, GRIDTRICKS_ID_SELECT, GRID_TRICKS::m_grid, and GRID_TRICKS::paste_clipboard().

Referenced by FIELDS_GRID_TRICKS::doPopupSelection(), FIELDS_EDITOR_GRID_TRICKS::doPopupSelection(), FP_GRID_TRICKS::doPopupSelection(), and GRID_TRICKS::onPopupSelection().

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

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

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:119

References GRID_TRICKS::m_tooltipEnabled.

◆ handleDoubleClick()

bool GRID_TRICKS::handleDoubleClick ( wxGridEvent &  aEvent)
protectedvirtualinherited

Reimplemented in FP_GRID_TRICKS.

Definition at line 198 of file grid_tricks.cpp.

199 {
200  // Double-click processing must be handled by specific sub-classes
201  return false;
202 }

Referenced by GRID_TRICKS::onGridCellLeftDClick().

◆ onCharHook()

void GRID_TRICKS::onCharHook ( wxKeyEvent &  event)
protectedinherited

Definition at line 365 of file grid_tricks.cpp.

366 {
367  bool handled = false;
368 
369  if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'V' )
370  {
371  if( m_grid->IsCellEditControlShown() && wxTheClipboard->Open() )
372  {
373  if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
374  {
375  wxTextDataObject data;
376  wxTheClipboard->GetData( data );
377 
378  if( data.GetText().Contains( COL_SEP ) || data.GetText().Contains( ROW_SEP ) )
379  {
380  m_grid->CommitPendingChanges( true /* quiet mode */ );
381  paste_text( data.GetText() );
382  handled = true;
383  }
384  }
385 
386  wxTheClipboard->Close();
387  m_grid->ForceRefresh();
388  }
389  }
390 
391  if( !handled )
392  ev.Skip( true );
393 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:110
virtual void paste_text(const wxString &cb_text)
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:226
#define ROW_SEP
Definition: grid_tricks.cpp:37
#define COL_SEP
Definition: grid_tricks.cpp:36

References COL_SEP, WX_GRID::CommitPendingChanges(), GRID_TRICKS::m_grid, GRID_TRICKS::paste_text(), and ROW_SEP.

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ onGridCellLeftClick()

void GRID_TRICKS::onGridCellLeftClick ( wxGridEvent &  event)
protectedinherited

Definition at line 149 of file grid_tricks.cpp.

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

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

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

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

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

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

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

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

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

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ onKeyDown()

void GRID_TRICKS::onKeyDown ( wxKeyEvent &  event)
protectedinherited

Definition at line 396 of file grid_tricks.cpp.

397 {
398  if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'A' )
399  {
400  m_grid->SelectAll();
401  return;
402  }
403  else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'C' )
404  {
405  getSelectedArea();
406  cutcopy( true, false );
407  return;
408  }
409  else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'V' )
410  {
411  getSelectedArea();
412  paste_clipboard();
413  return;
414  }
415  else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'X' )
416  {
417  getSelectedArea();
418  cutcopy( true, true );
419  return;
420  }
421  else if( !ev.GetModifiers() && ev.GetKeyCode() == WXK_DELETE )
422  {
423  getSelectedArea();
424  cutcopy( false, true );
425  return;
426  }
427 
428  // space-bar toggling of checkboxes
429  if( ev.GetKeyCode() == ' ' )
430  {
431  bool retVal = false;
432 
433  // If only rows can be selected, only toggle the first cell in a row
434  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
435  {
436  wxArrayInt rowSel = m_grid->GetSelectedRows();
437 
438  for( unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
439  {
440  retVal |= toggleCell( rowSel[rowInd], 0, true );
441  }
442  }
443 
444  // If only columns can be selected, only toggle the first cell in a column
445  else if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectColumns )
446  {
447  wxArrayInt colSel = m_grid->GetSelectedCols();
448 
449  for( unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
450  {
451  retVal |= toggleCell( 0, colSel[colInd], true );
452  }
453  }
454 
455  // If the user can select the individual cells, toggle each cell selected
456  else if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectCells )
457  {
458  wxArrayInt rowSel = m_grid->GetSelectedRows();
459  wxArrayInt colSel = m_grid->GetSelectedCols();
460  wxGridCellCoordsArray cellSel = m_grid->GetSelectedCells();
461  wxGridCellCoordsArray topLeft = m_grid->GetSelectionBlockTopLeft();
462  wxGridCellCoordsArray botRight = m_grid->GetSelectionBlockBottomRight();
463 
464  // Iterate over every individually selected cell and try to toggle it
465  for( unsigned int cellInd = 0; cellInd < cellSel.GetCount(); cellInd++ )
466  {
467  retVal |= toggleCell( cellSel[cellInd].GetRow(), cellSel[cellInd].GetCol(), true );
468  }
469 
470  // Iterate over every column and try to toggle each cell in it
471  for( unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
472  {
473  for( int row = 0; row < m_grid->GetNumberRows(); row++ )
474  {
475  retVal |= toggleCell( row, colSel[colInd], true );
476  }
477  }
478 
479  // Iterate over every row and try to toggle each cell in it
480  for( unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
481  {
482  for( int col = 0; col < m_grid->GetNumberCols(); col++ )
483  {
484  retVal |= toggleCell( rowSel[rowInd], col, true );
485  }
486  }
487 
488  // Iterate over the selection blocks
489  for( unsigned int blockInd = 0; blockInd < topLeft.GetCount(); blockInd++ )
490  {
491  wxGridCellCoords start = topLeft[blockInd];
492  wxGridCellCoords end = botRight[blockInd];
493 
494  for( int row = start.GetRow(); row <= end.GetRow(); row++ )
495  {
496  for( int col = start.GetCol(); col <= end.GetCol(); col++ )
497  {
498  retVal |= toggleCell( row, col, true );
499  }
500  }
501  }
502  }
503  else
504  {
505  }
506 
507  // Return if there were any cells toggled
508  if( retVal )
509  return;
510  }
511 
512  // ctrl-tab for exit grid
513 #ifdef __APPLE__
514  bool ctrl = ev.RawControlDown();
515 #else
516  bool ctrl = ev.ControlDown();
517 #endif
518 
519  if( ctrl && ev.GetKeyCode() == WXK_TAB )
520  {
521  wxWindow* test = m_grid->GetNextSibling();
522 
523  if( !test )
524  test = m_grid->GetParent()->GetNextSibling();
525 
526  while( test && !test->IsTopLevel() )
527  {
528  test->SetFocus();
529 
530  if( test->HasFocus() )
531  break;
532 
533  if( !test->GetChildren().empty() )
534  {
535  test = test->GetChildren().front();
536  }
537  else if( test->GetNextSibling() )
538  {
539  test = test->GetNextSibling();
540  }
541  else
542  {
543  while( test )
544  {
545  test = test->GetParent();
546 
547  if( test && test->IsTopLevel() )
548  {
549  break;
550  }
551  else if( test && test->GetNextSibling() )
552  {
553  test = test->GetNextSibling();
554  break;
555  }
556  }
557  }
558  }
559 
560  return;
561  }
562 
563  ev.Skip( true );
564 }
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:110
bool toggleCell(int aRow, int aCol, bool aPreserveSelection=false)
Definition: grid_tricks.cpp:71
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 316 of file grid_tricks.cpp.

317 {
318  doPopupSelection( event );
319 }
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 732 of file grid_tricks.cpp.

733 {
734  // Respect ROW selectionMode when moving cursor
735 
736  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
737  {
738  int cursorRow = m_grid->GetGridCursorRow();
739  bool cursorInSelectedRow = false;
740 
741  for( int row : m_grid->GetSelectedRows() )
742  {
743  if( row == cursorRow )
744  {
745  cursorInSelectedRow = true;
746  break;
747  }
748  }
749 
750  if( !cursorInSelectedRow && cursorRow >= 0 )
751  m_grid->SelectRow( cursorRow );
752  }
753 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:110

References GRID_TRICKS::m_grid.

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ paste_clipboard()

void GRID_TRICKS::paste_clipboard ( )
protectedvirtualinherited

Definition at line 567 of file grid_tricks.cpp.

568 {
569  wxLogNull doNotLog; // disable logging of failed clipboard actions
570 
571  if( wxTheClipboard->Open() )
572  {
573  if( wxTheClipboard->IsSupported( wxDF_TEXT )
574  || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
575  {
576  wxTextDataObject data;
577 
578  wxTheClipboard->GetData( data );
579 
580  paste_text( data.GetText() );
581  }
582 
583  wxTheClipboard->Close();
584  m_grid->ForceRefresh();
585  }
586 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:110
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()

virtual void SYMBOL_GRID_TRICKS::paste_text ( const wxString &  cb_text)
inlineoverrideprotectedvirtual

handle specialized clipboard text, with leading "(sym_lib_table" or spreadsheet formatted text.

Reimplemented from GRID_TRICKS.

Definition at line 151 of file panel_sym_lib_table.cpp.

152  {
153  SYMBOL_LIB_TABLE_GRID* tbl = (SYMBOL_LIB_TABLE_GRID*) m_grid->GetTable();
154  size_t ndx = cb_text.find( "(sym_lib_table" );
155 
156  if( ndx != std::string::npos )
157  {
158  // paste the SYMBOL_LIB_TABLE_ROWs of s-expression (sym_lib_table), starting
159  // at column 0 regardless of current cursor column.
160 
161  STRING_LINE_READER slr( TO_UTF8( cb_text ), wxT( "Clipboard" ) );
162  LIB_TABLE_LEXER lexer( &slr );
163  SYMBOL_LIB_TABLE tmp_tbl;
164  bool parsed = true;
165 
166  try
167  {
168  tmp_tbl.Parse( &lexer );
169  }
170  catch( PARSE_ERROR& pe )
171  {
172  DisplayError( m_dialog, pe.What() );
173  parsed = false;
174  }
175 
176  if( parsed )
177  {
178  // make sure the table is big enough...
179  if( tmp_tbl.GetCount() > (unsigned) tbl->GetNumberRows() )
180  tbl->AppendRows( tmp_tbl.GetCount() - tbl->GetNumberRows() );
181 
182  for( unsigned i = 0; i < tmp_tbl.GetCount(); ++i )
183  tbl->rows.replace( i, tmp_tbl.At( i ).clone() );
184  }
185 
186  m_grid->AutoSizeColumns( false );
187  }
188  else
189  {
190  // paste spreadsheet formatted text.
191  GRID_TRICKS::paste_text( cb_text );
192 
193  m_grid->AutoSizeColumns( false );
194  }
195  }
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:110
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
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
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.
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...
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, SYMBOL_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:119

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

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

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

Referenced by GRID_TRICKS::onGridCellLeftClick().

◆ showPopupMenu()

void GRID_TRICKS::showPopupMenu ( wxMenu &  menu)
protectedvirtualinherited

Reimplemented in FP_GRID_TRICKS, FIELDS_EDITOR_GRID_TRICKS, and FIELDS_GRID_TRICKS.

Definition at line 276 of file grid_tricks.cpp.

277 {
278  menu.Append( GRIDTRICKS_ID_CUT, _( "Cut" ) + "\tCtrl+X",
279  _( "Clear selected cells placing original contents on clipboard" ) );
280  menu.Append( GRIDTRICKS_ID_COPY, _( "Copy" ) + "\tCtrl+C",
281  _( "Copy selected cells to clipboard" ) );
282  menu.Append( GRIDTRICKS_ID_PASTE, _( "Paste" ) + "\tCtrl+V",
283  _( "Paste clipboard cells to matrix at current cell" ) );
284  menu.Append( GRIDTRICKS_ID_DELETE, _( "Delete" ) + "\tDel", _( "Delete selected cells" ) );
285  menu.Append( GRIDTRICKS_ID_SELECT, _( "Select All" ) + "\tCtrl+A", _( "Select all cells" ) );
286 
287  getSelectedArea();
288 
289  // if nothing is selected, disable cut, copy and delete.
291  {
292  menu.Enable( GRIDTRICKS_ID_CUT, false );
293  menu.Enable( GRIDTRICKS_ID_COPY, false );
294  menu.Enable( GRIDTRICKS_ID_DELETE, false );
295  }
296 
297  menu.Enable( GRIDTRICKS_ID_PASTE, false );
298 
299  wxLogNull doNotLog; // disable logging of failed clipboard actions
300 
301  if( wxTheClipboard->Open() )
302  {
303  if( wxTheClipboard->IsSupported( wxDF_TEXT )
304  || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
305  {
306  menu.Enable( GRIDTRICKS_ID_PASTE, true );
307  }
308 
309  wxTheClipboard->Close();
310  }
311 
312  m_grid->PopupMenu( &menu );
313 }
void getSelectedArea()
Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above.
int m_sel_row_count
Definition: grid_tricks.h:116
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:110
int m_sel_col_count
Definition: grid_tricks.h:117
#define _(s)

References _, GRID_TRICKS::getSelectedArea(), GRIDTRICKS_ID_COPY, GRIDTRICKS_ID_CUT, GRIDTRICKS_ID_DELETE, GRIDTRICKS_ID_PASTE, GRIDTRICKS_ID_SELECT, GRID_TRICKS::m_grid, GRID_TRICKS::m_sel_col_count, and GRID_TRICKS::m_sel_row_count.

Referenced by GRID_TRICKS::onGridCellRightClick(), FIELDS_GRID_TRICKS::showPopupMenu(), FIELDS_EDITOR_GRID_TRICKS::showPopupMenu(), and FP_GRID_TRICKS::showPopupMenu().

◆ toggleCell()

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

Definition at line 71 of file grid_tricks.cpp.

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

References GRID_TRICKS::m_grid.

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

Member Data Documentation

◆ m_dialog

DIALOG_EDIT_LIBRARY_TABLES* SYMBOL_GRID_TRICKS::m_dialog
protected

Definition at line 147 of file panel_sym_lib_table.cpp.

Referenced by 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: