KiCad PCB EDA Suite
FIELDS_GRID_TRICKS Class Reference

#include <fields_grid_table.h>

Inheritance diagram for FIELDS_GRID_TRICKS:
GRID_TRICKS

Public Member Functions

 FIELDS_GRID_TRICKS (WX_GRID *aGrid, DIALOG_SHIM *aDialog)
 

Protected Member Functions

virtual void showPopupMenu (wxMenu &menu) override
 
virtual void doPopupSelection (wxCommandEvent &event) override
 
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)
 
virtual bool handleDoubleClick (wxGridEvent &aEvent)
 
bool toggleCell (int aRow, int aCol, bool aPreserveSelection=false)
 
bool showEditor (int aRow, int aCol)
 
virtual void paste_clipboard ()
 
virtual void paste_text (const wxString &cb_text)
 
virtual void cutcopy (bool doCopy, bool doDelete)
 

Protected Attributes

DIALOG_SHIMm_dlg
 
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 38 of file fields_grid_table.h.

Constructor & Destructor Documentation

◆ FIELDS_GRID_TRICKS()

FIELDS_GRID_TRICKS::FIELDS_GRID_TRICKS ( WX_GRID aGrid,
DIALOG_SHIM aDialog 
)
inline

Definition at line 41 of file fields_grid_table.h.

41  :
42  GRID_TRICKS( aGrid ),
43  m_dlg( aDialog )
44  {}
GRID_TRICKS(WX_GRID *aGrid)
Definition: grid_tricks.cpp:38

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 FIELDS_GRID_TRICKS::doPopupSelection ( wxCommandEvent &  event)
overrideprotectedvirtual

Reimplemented from GRID_TRICKS.

Definition at line 610 of file fields_grid_table.cpp.

611 {
612  if( event.GetId() == MYID_SELECT_FOOTPRINT )
613  {
614  // pick a footprint using the footprint picker.
615  wxString fpid = m_grid->GetCellValue( FOOTPRINT_FIELD, FDC_VALUE );
617 
618  if( frame->ShowModal( &fpid, m_dlg ) )
619  m_grid->SetCellValue( FOOTPRINT_FIELD, FDC_VALUE, fpid );
620 
621  frame->Destroy();
622  }
623  else if (event.GetId() == MYID_SHOW_DATASHEET )
624  {
625  wxString datasheet_uri = m_grid->GetCellValue( DATASHEET_FIELD, FDC_VALUE );
626  GetAssociatedDocument( m_dlg, datasheet_uri, &m_dlg->Prj() );
627  }
628  else
629  {
631  }
632 }
virtual bool ShowModal(wxString *aResult=nullptr, wxWindow *aResultantFocusWindow=nullptr)
Show this wxFrame as if it were a modal dialog, with all other instantiated wxFrames disabled until t...
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject)
Open a document (file) with the suitable browser.
Definition: eda_doc.cpp:79
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:61
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:56
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:357
name of datasheet
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:81
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
virtual void doPopupSelection(wxCommandEvent &event)
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
Field Name Module PCB, i.e. "16DIP300".

References DATASHEET_FIELD, KIWAY_PLAYER::Destroy(), GRID_TRICKS::doPopupSelection(), FDC_VALUE, FOOTPRINT_FIELD, FRAME_FOOTPRINT_VIEWER_MODAL, GetAssociatedDocument(), KIWAY_HOLDER::Kiway(), m_dlg, GRID_TRICKS::m_grid, MYID_SELECT_FOOTPRINT, MYID_SHOW_DATASHEET, KIWAY::Player(), KIWAY_HOLDER::Prj(), and KIWAY_PLAYER::ShowModal().

◆ 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 GRID_TRICKS::handleDoubleClick ( wxGridEvent &  aEvent)
protectedvirtualinherited

Reimplemented in FP_GRID_TRICKS.

Definition at line 161 of file grid_tricks.cpp.

162 {
163  // Double-click processing must be handled by specific sub-classes
164  return false;
165 }

Referenced by GRID_TRICKS::onGridCellLeftDClick().

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

◆ 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 GRID_TRICKS::paste_text ( const wxString &  cb_text)
protectedvirtualinherited

Reimplemented in FP_GRID_TRICKS, and SYMBOL_GRID_TRICKS.

Definition at line 510 of file grid_tricks.cpp.

511 {
512  wxGridTableBase* tbl = m_grid->GetTable();
513 
514  const int cur_row = m_grid->GetGridCursorRow();
515  const int cur_col = m_grid->GetGridCursorCol();
516  int start_row;
517  int end_row;
518  int start_col;
519  int end_col;
520  bool is_selection = false;
521 
522  if( cur_row < 0 || cur_col < 0 )
523  {
524  wxBell();
525  return;
526  }
527 
528  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
529  {
530  if( m_sel_row_count > 1 )
531  is_selection = true;
532  }
533  else
534  {
535  if( m_grid->IsSelection() )
536  is_selection = true;
537  }
538 
539  wxStringTokenizer rows( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
540 
541  // If selection of cells is present
542  // then a clipboard pastes to selected cells only.
543  if( is_selection )
544  {
545  start_row = m_sel_row_start;
546  end_row = m_sel_row_start + m_sel_row_count;
547  start_col = m_sel_col_start;
548  end_col = m_sel_col_start + m_sel_col_count;
549  }
550  // Otherwise, paste whole clipboard
551  // starting from cell with cursor.
552  else
553  {
554  start_row = cur_row;
555  end_row = cur_row + rows.CountTokens();
556 
557  if( end_row > tbl->GetNumberRows() )
558  end_row = tbl->GetNumberRows();
559 
560  start_col = cur_col;
561  end_col = start_col; // end_col actual value calculates later
562  }
563 
564  for( int row = start_row; row < end_row; ++row )
565  {
566  // If number of selected rows bigger than count of rows in
567  // the clipboard, paste from the clipboard again and again
568  // while end of the selection is reached.
569  if( !rows.HasMoreTokens() )
570  rows.SetString( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
571 
572  wxString rowTxt = rows.GetNextToken();
573 
574  wxStringTokenizer cols( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
575 
576  if( !is_selection )
577  {
578  end_col = cur_col + cols.CountTokens();
579 
580  if( end_col > tbl->GetNumberCols() )
581  end_col = tbl->GetNumberCols();
582  }
583 
584  for( int col = start_col; col < end_col; ++col )
585  {
586  // If number of selected columns bigger than count of columns in
587  // the clipboard, paste from the clipboard again and again while
588  // end of the selection is reached.
589  if( !cols.HasMoreTokens() )
590  cols.SetString( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
591 
592  wxString cellTxt = cols.GetNextToken();
593 
594  if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_STRING ) )
595  {
596  tbl->SetValue( row, col, cellTxt );
597 
598  wxGridEvent evt( m_grid->GetId(), wxEVT_GRID_CELL_CHANGED, m_grid, row, col );
599  m_grid->GetEventHandler()->ProcessEvent( evt );
600  }
601  }
602  }
603 }
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::paste_clipboard(), SYMBOL_GRID_TRICKS::paste_text(), and FP_GRID_TRICKS::paste_text().

◆ 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 FIELDS_GRID_TRICKS::showPopupMenu ( wxMenu &  menu)
overrideprotectedvirtual

Reimplemented from GRID_TRICKS.

Definition at line 591 of file fields_grid_table.cpp.

592 {
593  if( m_grid->GetGridCursorRow() == FOOTPRINT_FIELD && m_grid->GetGridCursorCol() == FDC_VALUE )
594  {
595  menu.Append( MYID_SELECT_FOOTPRINT, _( "Select Footprint..." ),
596  _( "Browse for footprint" ) );
597  menu.AppendSeparator();
598  }
599  else if( m_grid->GetGridCursorRow() == DATASHEET_FIELD && m_grid->GetGridCursorCol() == FDC_VALUE )
600  {
601  menu.Append( MYID_SHOW_DATASHEET, _( "Show Datasheet" ),
602  _( "Show datasheet in browser" ) );
603  menu.AppendSeparator();
604  }
605 
607 }
name of datasheet
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
Field Name Module PCB, i.e. "16DIP300".

References _, DATASHEET_FIELD, FDC_VALUE, FOOTPRINT_FIELD, GRID_TRICKS::m_grid, MYID_SELECT_FOOTPRINT, MYID_SHOW_DATASHEET, 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_dlg

DIALOG_SHIM* FIELDS_GRID_TRICKS::m_dlg
protected

Definition at line 49 of file fields_grid_table.h.

Referenced by doPopupSelection().

◆ 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 files: