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)
 

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 &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 doCut)
 

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
 

Detailed Description

Definition at line 69 of file dialog_fields_editor_global.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 72 of file dialog_fields_editor_global.cpp.

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

Member Function Documentation

◆ cutcopy()

void GRID_TRICKS::cutcopy ( bool  doCut)
protectedvirtualinherited

Definition at line 586 of file grid_tricks.cpp.

587 {
588  if( wxTheClipboard->Open() )
589  {
590  wxGridTableBase* tbl = m_grid->GetTable();
591  wxString txt;
592 
593  // fill txt with a format that is compatible with most spreadsheets
594  for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
595  {
596  for( int col = m_sel_col_start; col < m_sel_col_start + m_sel_col_count; ++col )
597  {
598  txt += tbl->GetValue( row, col );
599 
600  if( col < m_sel_col_start + m_sel_col_count - 1 ) // that was not last column
601  txt += COL_SEP;
602 
603  if( doCut )
604  {
605  if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_STRING ) )
606  tbl->SetValue( row, col, wxEmptyString );
607  }
608  }
609  txt += ROW_SEP;
610  }
611 
612  wxTheClipboard->SetData( new wxTextDataObject( txt ) );
613  wxTheClipboard->Close();
614 
615  if( doCut )
616  m_grid->ForceRefresh();
617  }
618 }
int m_sel_row_count
Definition: grid_tricks.h:65
int m_sel_col_start
Definition: grid_tricks.h:64
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:59
int m_sel_col_count
Definition: grid_tricks.h:66
int m_sel_row_start
Definition: grid_tricks.h:63
#define ROW_SEP
Definition: grid_tricks.cpp:34
#define COL_SEP
Definition: grid_tricks.cpp:33

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 98 of file dialog_fields_editor_global.cpp.

99  {
100  if( event.GetId() == MYID_SELECT_FOOTPRINT )
101  {
102  // pick a footprint using the footprint picker.
103  wxString fpid = m_grid->GetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT_FIELD );
105 
106  if( frame->ShowModal( &fpid, m_dlg ) )
107  m_grid->SetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT_FIELD, fpid );
108 
109  frame->Destroy();
110  }
111  else if (event.GetId() == MYID_SHOW_DATASHEET )
112  {
113  wxString datasheet_uri = m_grid->GetCellValue( m_grid->GetGridCursorRow(), DATASHEET_FIELD );
114  GetAssociatedDocument( m_dlg, datasheet_uri, &m_dlg->Prj() );
115  }
116  else
117  {
119  }
120 
121  if( event.GetId() >= GRIDTRICKS_FIRST_SHOWHIDE && event.GetId() < GRIDTRICKS_LAST_ID )
122  {
123  if( !m_grid->IsColShown( REFERENCE_FIELD ) )
124  {
125  DisplayError( m_dlg, _( "The Reference column cannot be hidden." ) );
126 
127  m_grid->ShowCol( REFERENCE_FIELD );
128  }
129 
130  // Refresh Show checkboxes from grid columns
131  for( int i = 0; i < m_fieldsCtrl->GetItemCount(); ++i )
132  m_fieldsCtrl->SetToggleValue( m_grid->IsColShown( i ), i, 1 );
133  }
134  }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:240
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject)
Function GetAssociatedDocument open a document (file) with the suitable browser.
Definition: eda_doc.cpp:79
KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of ...
Definition: kiway_player.h:61
KIWAY & Kiway() const
Function Kiway returns a reference to the KIWAY that this object has an opportunity to participate in...
Definition: kiway_holder.h:56
name of datasheet
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:59
VTBL_ENTRY KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=NULL)
Function Player returns the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:345
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
Field Name Module PCB, i.e. "16DIP300".
virtual void doPopupSelection(wxCommandEvent &event)
#define _(s)
Definition: 3d_actions.cpp:33
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
Field Reference of part, i.e. "IC21".
virtual bool ShowModal(wxString *aResult=NULL, wxWindow *aResultantFocusWindow=NULL)
Function ShowModal puts up this wxFrame as if it were a modal dialog, with all other instantiated wxF...

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

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

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

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

Referenced by GRID_TRICKS::onGridCellLeftDClick().

◆ onGridCellLeftClick()

void GRID_TRICKS::onGridCellLeftClick ( wxGridEvent &  event)
protectedinherited

Definition at line 134 of file grid_tricks.cpp.

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

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

154 {
155  if( !handleDoubleClick( aEvent ) )
156  onGridCellLeftClick( aEvent );
157 }
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 207 of file grid_tricks.cpp.

208 {
209  wxMenu menu;
210 
211  showPopupMenu( menu );
212 }
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 215 of file grid_tricks.cpp.

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

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

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

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

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

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

269 {
270  doPopupSelection( event );
271 }
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 621 of file grid_tricks.cpp.

622 {
623  // Respect ROW selectionMode when moving cursor
624 
625  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
626  {
627  int cursorRow = m_grid->GetGridCursorRow();
628  bool cursorInSelectedRow = false;
629 
630  for( int row : m_grid->GetSelectedRows() )
631  {
632  if( row == cursorRow )
633  {
634  cursorInSelectedRow = true;
635  break;
636  }
637  }
638 
639  if( !cursorInSelectedRow && cursorRow >= 0 )
640  m_grid->SelectRow( cursorRow );
641  }
642 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:59

References GRID_TRICKS::m_grid.

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ paste_clipboard()

void GRID_TRICKS::paste_clipboard ( )
protectedvirtualinherited

Definition at line 471 of file grid_tricks.cpp.

472 {
473  if( wxTheClipboard->Open() )
474  {
475  if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
476  {
477  wxTextDataObject data;
478 
479  wxTheClipboard->GetData( data );
480 
481  paste_text( data.GetText() );
482  }
483 
484  wxTheClipboard->Close();
485  m_grid->ForceRefresh();
486  }
487 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:59
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 490 of file grid_tricks.cpp.

491 {
492  wxGridTableBase* tbl = m_grid->GetTable();
493 
494  const int cur_row = m_grid->GetGridCursorRow();
495  const int cur_col = m_grid->GetGridCursorCol();
496  int start_row;
497  int end_row;
498  int start_col;
499  int end_col;
500  bool is_selection = false;
501 
502  if( cur_row < 0 || cur_col < 0 )
503  {
504  wxBell();
505  return;
506  }
507 
508  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
509  {
510  if( m_sel_row_count > 1 )
511  is_selection = true;
512  }
513  else
514  {
515  if( m_grid->IsSelection() )
516  is_selection = true;
517  }
518 
519  wxStringTokenizer rows( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
520 
521  // If selection of cells is present
522  // then a clipboard pastes to selected cells only.
523  if( is_selection )
524  {
525  start_row = m_sel_row_start;
526  end_row = m_sel_row_start + m_sel_row_count;
527  start_col = m_sel_col_start;
528  end_col = m_sel_col_start + m_sel_col_count;
529  }
530  // Otherwise, paste whole clipboard
531  // starting from cell with cursor.
532  else
533  {
534  start_row = cur_row;
535  end_row = cur_row + rows.CountTokens();
536 
537  if( end_row > tbl->GetNumberRows() )
538  end_row = tbl->GetNumberRows();
539 
540  start_col = cur_col;
541  end_col = start_col; // end_col actual value calculates later
542  }
543 
544  for( int row = start_row; row < end_row; ++row )
545  {
546  // If number of selected rows bigger than count of rows in
547  // the clipboard, paste from the clipboard again and again
548  // while end of the selection is reached.
549  if( !rows.HasMoreTokens() )
550  rows.SetString( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
551 
552  wxString rowTxt = rows.GetNextToken();
553 
554  wxStringTokenizer cols( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
555 
556  if( !is_selection )
557  {
558  end_col = cur_col + cols.CountTokens();
559 
560  if( end_col > tbl->GetNumberCols() )
561  end_col = tbl->GetNumberCols();
562  }
563 
564  for( int col = start_col; col < end_col; ++col )
565  {
566  // If number of selected columns bigger than count of columns in
567  // the clipboard, paste from the clipboard again and again while
568  // end of the selection is reached.
569  if( !cols.HasMoreTokens() )
570  cols.SetString( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
571 
572  wxString cellTxt = cols.GetNextToken();
573 
574  if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_STRING ) )
575  {
576  tbl->SetValue( row, col, cellTxt );
577 
578  wxGridEvent evt( m_grid->GetId(), wxEVT_GRID_CELL_CHANGED, m_grid, row, col );
579  m_grid->GetEventHandler()->ProcessEvent( evt );
580  }
581  }
582  }
583 }
int m_sel_row_count
Definition: grid_tricks.h:65
int m_sel_col_start
Definition: grid_tricks.h:64
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:59
int m_sel_col_count
Definition: grid_tricks.h:66
int m_sel_row_start
Definition: grid_tricks.h:63
#define ROW_SEP
Definition: grid_tricks.cpp:34
#define COL_SEP
Definition: grid_tricks.cpp:33

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

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

Reimplemented from GRID_TRICKS.

Definition at line 80 of file dialog_fields_editor_global.cpp.

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

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

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

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 136 of file dialog_fields_editor_global.cpp.

Referenced by doPopupSelection().

◆ m_fieldsCtrl

wxDataViewListCtrl* FIELDS_EDITOR_GRID_TRICKS::m_fieldsCtrl
protected

Definition at line 137 of file dialog_fields_editor_global.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

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