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

Public Member Functions

 FIELDS_EDITOR_GRID_TRICKS (DIALOG_SHIM *aParent, WX_GRID *aGrid, wxDataViewListCtrl *aFieldsCtrl)
 
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 showPopupMenu (wxMenu &menu) override
 
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 &event)
 
void onCharHook (wxKeyEvent &event)
 
void onUpdateUI (wxUpdateUIEvent &event)
 
void onGridMotion (wxMouseEvent &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
 
wxDataViewListCtrl * m_fieldsCtrl
 
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 70 of file dialog_symbol_fields_table.cpp.

Constructor & Destructor Documentation

◆ FIELDS_EDITOR_GRID_TRICKS()

FIELDS_EDITOR_GRID_TRICKS::FIELDS_EDITOR_GRID_TRICKS ( DIALOG_SHIM aParent,
WX_GRID aGrid,
wxDataViewListCtrl *  aFieldsCtrl 
)
inline

Definition at line 73 of file dialog_symbol_fields_table.cpp.

74  :
75  GRID_TRICKS( aGrid ),
76  m_dlg( aParent ),
77  m_fieldsCtrl( aFieldsCtrl )
78  {}
GRID_TRICKS(WX_GRID *aGrid)
Definition: grid_tricks.cpp:40

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 FIELDS_EDITOR_GRID_TRICKS::doPopupSelection ( wxCommandEvent &  event)
inlineoverrideprotectedvirtual

Reimplemented from GRID_TRICKS.

Definition at line 99 of file dialog_symbol_fields_table.cpp.

100  {
101  if( event.GetId() == MYID_SELECT_FOOTPRINT )
102  {
103  // pick a footprint using the footprint picker.
104  wxString fpid = m_grid->GetCellValue( m_grid->GetGridCursorRow(),
105  FOOTPRINT_FIELD );
107  m_dlg );
108 
109  if( frame->ShowModal( &fpid, m_dlg ) )
110  m_grid->SetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT_FIELD, fpid );
111 
112  frame->Destroy();
113  }
114  else if (event.GetId() == MYID_SHOW_DATASHEET )
115  {
116  wxString datasheet_uri = m_grid->GetCellValue( m_grid->GetGridCursorRow(),
117  DATASHEET_FIELD );
118  GetAssociatedDocument( m_dlg, datasheet_uri, &m_dlg->Prj(), m_dlg->Prj().SchSearchS() );
119  }
120  else
121  {
123  }
124 
125  if( event.GetId() >= GRIDTRICKS_FIRST_SHOWHIDE && event.GetId() < GRIDTRICKS_LAST_ID )
126  {
127  if( !m_grid->IsColShown( REFERENCE_FIELD ) )
128  {
129  DisplayError( m_dlg, _( "The Reference column cannot be hidden." ) );
130 
131  m_grid->ShowCol( REFERENCE_FIELD );
132  }
133 
134  // Refresh Show checkboxes from grid columns
135  for( int i = 0; i < m_fieldsCtrl->GetItemCount(); ++i )
136  m_fieldsCtrl->SetToggleValue( m_grid->IsColShown( i ), i, 1 );
137  }
138  }
Field Reference of part, i.e. "IC21".
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...
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:279
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:64
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:393
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths)
Open a document (file) with the suitable browser.
Definition: eda_doc.cpp:74
name of datasheet
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:110
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
#define _(s)
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(), DisplayError(), GRID_TRICKS::doPopupSelection(), FOOTPRINT_FIELD, FRAME_FOOTPRINT_VIEWER_MODAL, GetAssociatedDocument(), GRIDTRICKS_FIRST_SHOWHIDE, GRIDTRICKS_LAST_ID, KIWAY_HOLDER::Kiway(), m_dlg, m_fieldsCtrl, GRID_TRICKS::m_grid, MYID_SELECT_FOOTPRINT, MYID_SHOW_DATASHEET, KIWAY::Player(), KIWAY_HOLDER::Prj(), REFERENCE_FIELD, 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 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()

void GRID_TRICKS::paste_text ( const wxString &  cb_text)
protectedvirtualinherited

Reimplemented in FP_GRID_TRICKS, and SYMBOL_GRID_TRICKS.

Definition at line 589 of file grid_tricks.cpp.

590 {
591  wxGridTableBase* tbl = m_grid->GetTable();
592 
593  const int cur_row = m_grid->GetGridCursorRow();
594  const int cur_col = m_grid->GetGridCursorCol();
595  int start_row;
596  int end_row;
597  int start_col;
598  int end_col;
599  bool is_selection = false;
600 
601  if( cur_row < 0 || cur_col < 0 )
602  {
603  wxBell();
604  return;
605  }
606 
607  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
608  {
609  if( m_sel_row_count > 1 )
610  is_selection = true;
611  }
612  else
613  {
614  if( m_grid->IsSelection() )
615  is_selection = true;
616  }
617 
618  wxStringTokenizer rows( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
619 
620  // If selection of cells is present
621  // then a clipboard pastes to selected cells only.
622  if( is_selection )
623  {
624  start_row = m_sel_row_start;
625  end_row = m_sel_row_start + m_sel_row_count;
626  start_col = m_sel_col_start;
627  end_col = m_sel_col_start + m_sel_col_count;
628  }
629  // Otherwise, paste whole clipboard
630  // starting from cell with cursor.
631  else
632  {
633  start_row = cur_row;
634  end_row = cur_row + rows.CountTokens();
635 
636  if( end_row > tbl->GetNumberRows() )
637  end_row = tbl->GetNumberRows();
638 
639  start_col = cur_col;
640  end_col = start_col; // end_col actual value calculates later
641  }
642 
643  for( int row = start_row; row < end_row; ++row )
644  {
645  // If number of selected rows is larger than the count of rows on the clipboard, paste
646  // again and again until the end of the selection is reached.
647  if( !rows.HasMoreTokens() )
648  rows.SetString( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
649 
650  wxString rowTxt = rows.GetNextToken();
651 
652  wxStringTokenizer cols( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
653 
654  if( !is_selection )
655  {
656  end_col = cur_col + cols.CountTokens();
657 
658  if( end_col > tbl->GetNumberCols() )
659  end_col = tbl->GetNumberCols();
660  }
661 
662  for( int col = start_col; col < end_col; ++col )
663  {
664  // Skip hidden columns
665  if( !m_grid->IsColShown( col ) )
666  continue;
667 
668  // If number of selected cols is larger than the count of cols on the clipboard,
669  // paste again and again until the end of the selection is reached.
670  if( !cols.HasMoreTokens() )
671  cols.SetString( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
672 
673  wxString cellTxt = cols.GetNextToken();
674 
675  if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_STRING ) )
676  {
677  tbl->SetValue( row, col, cellTxt );
678 
679  wxGridEvent evt( m_grid->GetId(), wxEVT_GRID_CELL_CHANGED, m_grid, row, col );
680  m_grid->GetEventHandler()->ProcessEvent( evt );
681  }
682  }
683  }
684 }
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::onCharHook(), GRID_TRICKS::paste_clipboard(), SYMBOL_GRID_TRICKS::paste_text(), and FP_GRID_TRICKS::paste_text().

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

Reimplemented from GRID_TRICKS.

Definition at line 81 of file dialog_symbol_fields_table.cpp.

82  {
83  if( m_grid->GetGridCursorCol() == FOOTPRINT_FIELD )
84  {
85  menu.Append( MYID_SELECT_FOOTPRINT, _( "Select Footprint..." ),
86  _( "Browse for footprint" ) );
87  menu.AppendSeparator();
88  }
89  else if( m_grid->GetGridCursorCol() == DATASHEET_FIELD )
90  {
91  menu.Append( MYID_SHOW_DATASHEET, _( "Show Datasheet" ),
92  _( "Show datasheet in browser" ) );
93  menu.AppendSeparator();
94  }
95 
97  }
name of datasheet
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:110
#define _(s)
virtual void showPopupMenu(wxMenu &menu)
Field Name Module PCB, i.e. "16DIP300".

References _, DATASHEET_FIELD, 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 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_dlg

DIALOG_SHIM* FIELDS_EDITOR_GRID_TRICKS::m_dlg
protected

Definition at line 140 of file dialog_symbol_fields_table.cpp.

Referenced by doPopupSelection().

◆ m_fieldsCtrl

wxDataViewListCtrl* FIELDS_EDITOR_GRID_TRICKS::m_fieldsCtrl
protected

Definition at line 141 of file dialog_symbol_fields_table.cpp.

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

◆ m_tooltipEnabled

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

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