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)
 

Static Protected Member Functions

static bool isCtl (int aChar, const wxKeyEvent &e)
 

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

60  :
61  GRID_TRICKS( aGrid ),
62  m_dlg( aParent ),
63  m_fieldsCtrl( aFieldsCtrl )
64  {}
GRID_TRICKS(WX_GRID *aGrid)
Definition: grid_tricks.cpp:39

Member Function Documentation

◆ cutcopy()

void GRID_TRICKS::cutcopy ( bool  doCut)
protectedvirtualinherited

Definition at line 581 of file grid_tricks.cpp.

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

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

86  {
87  if( event.GetId() == MYID_SELECT_FOOTPRINT )
88  {
89  // pick a footprint using the footprint picker.
90  wxString fpid = m_grid->GetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT );
92 
93  if( frame->ShowModal( &fpid, m_dlg ) )
94  m_grid->SetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT, fpid );
95 
96  frame->Destroy();
97  }
98  else if (event.GetId() == MYID_SHOW_DATASHEET )
99  {
100  wxString datasheet_uri = m_grid->GetCellValue( m_grid->GetGridCursorRow(), DATASHEET );
101  GetAssociatedDocument( m_dlg, datasheet_uri, &m_dlg->Prj() );
102  }
103  else
104  {
106  }
107 
108  if( event.GetId() >= GRIDTRICKS_FIRST_SHOWHIDE && event.GetId() < GRIDTRICKS_LAST_ID )
109  {
110  if( !m_grid->IsColShown( REFERENCE ) )
111  {
112  DisplayError( m_dlg, _( "The Reference column cannot be hidden." ) );
113 
114  m_grid->ShowCol( REFERENCE );
115  }
116 
117  // Refresh Show checkboxes from grid columns
118  for( int i = 0; i < m_fieldsCtrl->GetItemCount(); ++i )
119  m_fieldsCtrl->SetToggleValue( m_grid->IsColShown( i ), i, 1 );
120  }
121  }
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:239
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject)
Function GetAssociatedDocument open a document (file) with the suitable browser.
Definition: eda_doc.cpp:80
KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of ...
Definition: kiway_player.h:59
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
Field Name Module PCB, i.e. "16DIP300".
Field Reference of part, i.e. "IC21".
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:58
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:341
PROJECT & Prj() const
Function Prj returns a reference to the PROJECT "associated with" this KIWAY.
virtual void doPopupSelection(wxCommandEvent &event)
#define _(s)
Definition: 3d_actions.cpp:33
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
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, KIWAY_PLAYER::Destroy(), DisplayError(), GRID_TRICKS::doPopupSelection(), FOOTPRINT, 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, 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 169 of file grid_tricks.cpp.

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

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

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

Referenced by GRID_TRICKS::onGridCellLeftDClick().

◆ isCtl()

static bool GRID_TRICKS::isCtl ( int  aChar,
const wxKeyEvent &  e 
)
inlinestaticprotectedinherited

Definition at line 70 of file grid_tricks.h.

71  {
72  return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() && !e.ShiftDown() && !e.MetaDown();
73  }

Referenced by GRID_TRICKS::onKeyDown().

◆ onGridCellLeftClick()

void GRID_TRICKS::onGridCellLeftClick ( wxGridEvent &  event)
protectedinherited

Definition at line 136 of file grid_tricks.cpp.

137 {
138  int row = aEvent.GetRow();
139  int col = aEvent.GetCol();
140 
141  // Don't make users click twice to toggle a checkbox or edit a text cell
142  if( !aEvent.GetModifiers() )
143  {
144  if( toggleCell( row, col ) )
145  return;
146 
147  if( showEditor( row, col ) )
148  return;
149  }
150 
151  aEvent.Skip();
152 }
bool toggleCell(int aRow, int aCol, bool aPreserveSelection=false)
Definition: grid_tricks.cpp:58
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 155 of file grid_tricks.cpp.

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

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

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

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

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

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

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

References GRID_TRICKS::cutcopy(), GRID_TRICKS::getSelectedArea(), GRID_TRICKS::isCtl(), 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 270 of file grid_tricks.cpp.

271 {
272  doPopupSelection( event );
273 }
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 613 of file grid_tricks.cpp.

614 {
615  // Respect ROW selectionMode when moving cursor
616 
617  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
618  {
619  int cursorRow = m_grid->GetGridCursorRow();
620  bool cursorInSelectedRow = false;
621 
622  for( int row : m_grid->GetSelectedRows() )
623  {
624  if( row == cursorRow )
625  {
626  cursorInSelectedRow = true;
627  break;
628  }
629  }
630 
631  if( !cursorInSelectedRow && cursorRow >= 0 )
632  m_grid->SelectRow( cursorRow );
633  }
634 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:58

References GRID_TRICKS::m_grid.

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ paste_clipboard()

void GRID_TRICKS::paste_clipboard ( )
protectedvirtualinherited

Definition at line 473 of file grid_tricks.cpp.

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

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

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

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

68  {
69  if( m_grid->GetGridCursorCol() == FOOTPRINT )
70  {
71  menu.Append( MYID_SELECT_FOOTPRINT, _( "Select Footprint..." ),
72  _( "Browse for footprint" ) );
73  menu.AppendSeparator();
74  }
75  else if( m_grid->GetGridCursorCol() == DATASHEET )
76  {
77  menu.Append( MYID_SHOW_DATASHEET, _( "Show Datasheet" ),
78  _( "Show datasheet in browser" ) );
79  menu.AppendSeparator();
80  }
81 
83  }
name of datasheet
Field Name Module PCB, i.e. "16DIP300".
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:58
virtual void showPopupMenu(wxMenu &menu)
#define _(s)
Definition: 3d_actions.cpp:33

References _, DATASHEET, FOOTPRINT, 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 58 of file grid_tricks.cpp.

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

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

Referenced by doPopupSelection().

◆ m_fieldsCtrl

wxDataViewListCtrl* FIELDS_EDITOR_GRID_TRICKS::m_fieldsCtrl
protected

Definition at line 124 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: