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

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

Member Function Documentation

◆ cutcopy()

void GRID_TRICKS::cutcopy ( bool  doCut)
protectedvirtualinherited

Definition at line 502 of file grid_tricks.cpp.

503 {
504  if( wxTheClipboard->Open() )
505  {
506  wxGridTableBase* tbl = m_grid->GetTable();
507  wxString txt;
508 
509  // fill txt with a format that is compatible with most spreadsheets
510  for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
511  {
512  for( int col = m_sel_col_start; col < m_sel_col_start + m_sel_col_count; ++col )
513  {
514  txt += tbl->GetValue( row, col );
515 
516  if( col < m_sel_col_start + m_sel_col_count - 1 ) // that was not last column
517  txt += COL_SEP;
518 
519  if( doCut )
520  tbl->SetValue( row, col, wxEmptyString );
521  }
522  txt += ROW_SEP;
523  }
524 
525  wxTheClipboard->SetData( new wxTextDataObject( txt ) );
526  wxTheClipboard->Close();
527 
528  if( doCut )
529  m_grid->ForceRefresh();
530  }
531 }
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 83 of file dialog_fields_editor_global.cpp.

84  {
85  if( event.GetId() == MYID_SELECT_FOOTPRINT )
86  {
87  // pick a footprint using the footprint picker.
88  wxString fpid = m_grid->GetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT );
90  m_dlg );
91 
92  if( frame->ShowModal( &fpid, m_dlg ) )
93  m_grid->SetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT, fpid );
94 
95  frame->Destroy();
96  }
97  else if (event.GetId() == MYID_SHOW_DATASHEET )
98  {
99  wxString datasheet_uri = m_grid->GetCellValue( m_grid->GetGridCursorRow(), DATASHEET );
100  GetAssociatedDocument( m_dlg, datasheet_uri );
101  }
102  else
103  {
105  }
106 
107  if( event.GetId() >= GRIDTRICKS_FIRST_SHOWHIDE && event.GetId() < GRIDTRICKS_LAST_ID )
108  {
109  if( !m_grid->IsColShown( REFERENCE ) )
110  {
111  DisplayError( m_dlg, _( "The Reference column cannot be hidden." ) );
112 
113  m_grid->ShowCol( REFERENCE );
114  }
115 
116  // Refresh Show checkboxes from grid columns
117  for( int i = 0; i < m_fieldsCtrl->GetItemCount(); ++i )
118  m_fieldsCtrl->SetToggleValue( m_grid->IsColShown( i ), i, 1 );
119  }
120  }
Class KIWAY_PLAYER is a wxFrame capable of the OpenProjectFiles function, meaning it can load a porti...
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
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, const wxPathList *aPaths)
Function GetAssociatedDocument open a document (file) with the suitable browser.
Definition: eda_doc.cpp:87
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:321
#define _(s)
virtual void doPopupSelection(wxCommandEvent &event)
size_t i
Definition: json11.cpp:597
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:243
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_PCB_MODULE_VIEWER_MODAL, GetAssociatedDocument(), GRIDTRICKS_FIRST_SHOWHIDE, GRIDTRICKS_LAST_ID, i, KIWAY_HOLDER::Kiway(), m_dlg, m_fieldsCtrl, GRID_TRICKS::m_grid, MYID_SELECT_FOOTPRINT, MYID_SHOW_DATASHEET, KIWAY::Player(), 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 164 of file grid_tricks.cpp.

165 {
166  wxGridCellCoordsArray topLeft = m_grid->GetSelectionBlockTopLeft();
167  wxGridCellCoordsArray botRight = m_grid->GetSelectionBlockBottomRight();
168 
169  wxArrayInt cols = m_grid->GetSelectedCols();
170  wxArrayInt rows = m_grid->GetSelectedRows();
171 
172  if( topLeft.Count() && botRight.Count() )
173  {
174  m_sel_row_start = topLeft[0].GetRow();
175  m_sel_col_start = topLeft[0].GetCol();
176 
177  m_sel_row_count = botRight[0].GetRow() - m_sel_row_start + 1;
178  m_sel_col_count = botRight[0].GetCol() - m_sel_col_start + 1;
179  }
180  else if( cols.Count() )
181  {
182  m_sel_col_start = cols[0];
183  m_sel_col_count = cols.Count();
184  m_sel_row_start = 0;
185  m_sel_row_count = m_grid->GetNumberRows();
186  }
187  else if( rows.Count() )
188  {
189  m_sel_col_start = 0;
190  m_sel_col_count = m_grid->GetNumberCols();
191  m_sel_row_start = rows[0];
192  m_sel_row_count = rows.Count();
193  }
194  else
195  {
196  m_sel_row_start = m_grid->GetGridCursorRow();
197  m_sel_col_start = m_grid->GetGridCursorCol();
198  m_sel_row_count = m_sel_row_start >= 0 ? 1 : 0;
199  m_sel_col_count = m_sel_col_start >= 0 ? 1 : 0;
200  }
201 }
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 157 of file grid_tricks.cpp.

158 {
159  // Double-click processing must be handled by specific sub-classes
160  return false;
161 }

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

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

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

151 {
152  if( !handleDoubleClick( aEvent ) )
153  onGridCellLeftClick( aEvent );
154 }
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 204 of file grid_tricks.cpp.

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

213 {
215 
216  aEvent.Skip();
217 }
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:167

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

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

References GRIDTRICKS_FIRST_SHOWHIDE, i, and GRID_TRICKS::m_grid.

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ onKeyDown()

void GRID_TRICKS::onKeyDown ( wxKeyEvent &  ev)
protectedinherited

Definition at line 307 of file grid_tricks.cpp.

308 {
309  if( isCtl( 'A', ev ) )
310  {
311  m_grid->SelectAll();
312  return;
313  }
314  else if( isCtl( 'C', ev ) )
315  {
316  getSelectedArea();
317  cutcopy( false );
318  return;
319  }
320  else if( isCtl( 'V', ev ) )
321  {
322  getSelectedArea();
323  paste_clipboard();
324  return;
325  }
326  else if( isCtl( 'X', ev ) )
327  {
328  getSelectedArea();
329  cutcopy( true );
330  return;
331  }
332 
333  // space-bar toggling of checkboxes
334  if( ev.GetKeyCode() == ' ' )
335  {
336  int row = m_grid->GetGridCursorRow();
337  int col = m_grid->GetGridCursorCol();
338 
339  if( m_grid->IsVisible( row, col ) && toggleCell( row, col ) )
340  return;
341  }
342 
343  // ctrl-tab for exit grid
344 #ifdef __APPLE__
345  bool ctrl = ev.RawControlDown();
346 #else
347  bool ctrl = ev.ControlDown();
348 #endif
349 
350  if( ctrl && ev.GetKeyCode() == WXK_TAB )
351  {
352  wxWindow* test = m_grid->GetNextSibling();
353 
354  if( !test )
355  test = m_grid->GetParent()->GetNextSibling();
356 
357  while( test && !test->IsTopLevel() )
358  {
359  test->SetFocus();
360 
361  if( test->HasFocus() )
362  break;
363 
364  if( !test->GetChildren().empty() )
365  test = test->GetChildren().front();
366  else if( test->GetNextSibling() )
367  test = test->GetNextSibling();
368  else
369  {
370  while( test )
371  {
372  test = test->GetParent();
373 
374  if( test && test->IsTopLevel() )
375  {
376  break;
377  }
378  else if( test && test->GetNextSibling() )
379  {
380  test = test->GetNextSibling();
381  break;
382  }
383  }
384  }
385  }
386 
387  return;
388  }
389 
390  ev.Skip( true );
391 }
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
bool toggleCell(int aRow, int aCol)
Definition: grid_tricks.cpp:58
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h: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 265 of file grid_tricks.cpp.

266 {
267  doPopupSelection( event );
268 }
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 534 of file grid_tricks.cpp.

535 {
536  // Respect ROW selectionMode when moving cursor
537 
538  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
539  {
540  int cursorRow = m_grid->GetGridCursorRow();
541  bool cursorInSelectedRow = false;
542 
543  for( int row : m_grid->GetSelectedRows() )
544  {
545  if( row == cursorRow )
546  {
547  cursorInSelectedRow = true;
548  break;
549  }
550  }
551 
552  if( !cursorInSelectedRow )
553  m_grid->SelectRow( cursorRow );
554  }
555 }
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 394 of file grid_tricks.cpp.

395 {
396  if( wxTheClipboard->Open() )
397  {
398  if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
399  {
400  wxTextDataObject data;
401 
402  wxTheClipboard->GetData( data );
403 
404  paste_text( data.GetText() );
405  }
406 
407  wxTheClipboard->Close();
408  m_grid->ForceRefresh();
409  }
410 }
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 413 of file grid_tricks.cpp.

414 {
415  wxGridTableBase* tbl = m_grid->GetTable();
416 
417  const int cur_row = m_grid->GetGridCursorRow();
418  const int cur_col = m_grid->GetGridCursorCol();
419  int start_row;
420  int end_row;
421  int start_col;
422  int end_col;
423  bool is_selection = false;
424 
425  if( cur_row < 0 || cur_col < 0 )
426  {
427  wxBell();
428  return;
429  }
430 
431  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
432  {
433  if( m_sel_row_count > 1 )
434  is_selection = true;
435  }
436  else
437  {
438  if( m_grid->IsSelection() )
439  is_selection = true;
440  }
441 
442  wxStringTokenizer rows( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
443 
444  // If selection of cells is present
445  // then a clipboard pastes to selected cells only.
446  if( is_selection )
447  {
448  start_row = m_sel_row_start;
449  end_row = m_sel_row_start + m_sel_row_count;
450  start_col = m_sel_col_start;
451  end_col = m_sel_col_start + m_sel_col_count;
452  }
453  // Otherwise, paste whole clipboard
454  // starting from cell with cursor.
455  else
456  {
457  start_row = cur_row;
458  end_row = cur_row + rows.CountTokens();
459 
460  if( end_row > tbl->GetNumberRows() )
461  end_row = tbl->GetNumberRows();
462 
463  start_col = cur_col;
464  end_col = start_col; // end_col actual value calculates later
465  }
466 
467  for( int row = start_row; row < end_row; ++row )
468  {
469  // If number of selected rows bigger than count of rows in
470  // the clipboard, paste from the clipboard again and again
471  // while end of the selection is reached.
472  if( !rows.HasMoreTokens() )
473  rows.SetString( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
474 
475  wxString rowTxt = rows.GetNextToken();
476 
477  wxStringTokenizer cols( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
478 
479  if( !is_selection )
480  {
481  end_col = cur_col + cols.CountTokens();
482 
483  if( end_col > tbl->GetNumberCols() )
484  end_col = tbl->GetNumberCols();
485  }
486 
487  for( int col = start_col; col < end_col; ++col )
488  {
489  // If number of selected columns bigger than count of columns in
490  // the clipboard, paste from the clipboard again and again while
491  // end of the selection is reached.
492  if( !cols.HasMoreTokens() )
493  cols.SetString( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
494 
495  wxString cellTxt = cols.GetNextToken();
496  tbl->SetValue( row, col, cellTxt );
497  }
498  }
499 }
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 98 of file grid_tricks.cpp.

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

66  {
67  if( m_grid->GetGridCursorCol() == FOOTPRINT )
68  {
69  menu.Append( MYID_SELECT_FOOTPRINT, _( "Select Footprint..." ),
70  _( "Browse for footprint" ) );
71  menu.AppendSeparator();
72  }
73  else if( m_grid->GetGridCursorCol() == DATASHEET )
74  {
75  menu.Append( MYID_SHOW_DATASHEET, _( "Show Datasheet" ),
76  _( "Show datasheet in browser" ) );
77  menu.AppendSeparator();
78  }
79 
81  }
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
#define _(s)
virtual void showPopupMenu(wxMenu &menu)

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 
)
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  m_grid->SetGridCursor( aRow, aCol );
67 
68  wxGridTableBase* model = m_grid->GetTable();
69 
70  if( model->CanGetValueAs( aRow, aCol, wxGRID_VALUE_BOOL )
71  && model->CanSetValueAs( aRow, aCol, wxGRID_VALUE_BOOL ))
72  {
73  model->SetValueAsBool( aRow, aCol, !model->GetValueAsBool( aRow, aCol ));
74  }
75  else // fall back to string processing
76  {
77  if( model->GetValue( aRow, aCol ) == wxT( "1" ) )
78  model->SetValue( aRow, aCol, wxT( "0" ) );
79  else
80  model->SetValue( aRow, aCol, wxT( "1" ) );
81  }
82 
83  // Mac needs this for the keyboard events; Linux appears to always need it.
84  m_grid->ForceRefresh();
85 
86  // Let any clients know
87  wxGridEvent event( m_grid->GetId(), wxEVT_GRID_CELL_CHANGED, m_grid, aRow, aCol );
88  event.SetString( model->GetValue( aRow, aCol ) );
89  m_grid->GetEventHandler()->ProcessEvent( event );
90 
91  return true;
92  }
93 
94  return false;
95 }
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 122 of file dialog_fields_editor_global.cpp.

Referenced by doPopupSelection().

◆ m_fieldsCtrl

wxDataViewListCtrl* FIELDS_EDITOR_GRID_TRICKS::m_fieldsCtrl
protected

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