KiCad PCB EDA Suite
GRID_TRICKS Class Reference

Class GRID_TRICKS is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance. More...

#include <grid_tricks.h>

Inheritance diagram for GRID_TRICKS:
FIELDS_EDITOR_GRID_TRICKS FIELDS_GRID_TRICKS FP_GRID_TRICKS SYMBOL_GRID_TRICKS

Public Member Functions

 GRID_TRICKS (WX_GRID *aGrid)
 

Protected Member Functions

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)
 
virtual void showPopupMenu (wxMenu &menu)
 
virtual void doPopupSelection (wxCommandEvent &event)
 
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

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

Class GRID_TRICKS is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.

Definition at line 51 of file grid_tricks.h.

Constructor & Destructor Documentation

◆ GRID_TRICKS()

GRID_TRICKS::GRID_TRICKS ( WX_GRID aGrid)
explicit

Definition at line 39 of file grid_tricks.cpp.

39  :
40  m_grid( aGrid )
41 {
42  m_sel_row_start = 0;
43  m_sel_col_start = 0;
44  m_sel_row_count = 0;
45  m_sel_col_count = 0;
46 
47  aGrid->Connect( wxEVT_GRID_CELL_LEFT_CLICK, wxGridEventHandler( GRID_TRICKS::onGridCellLeftClick ), NULL, this );
48  aGrid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK, wxGridEventHandler( GRID_TRICKS::onGridCellLeftDClick ), NULL, this );
49  aGrid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK, wxGridEventHandler( GRID_TRICKS::onGridCellRightClick ), NULL, this );
50  aGrid->Connect( wxEVT_GRID_LABEL_RIGHT_CLICK, wxGridEventHandler( GRID_TRICKS::onGridLabelRightClick ), NULL, this );
51  aGrid->Connect( wxEVT_GRID_LABEL_LEFT_CLICK, wxGridEventHandler( GRID_TRICKS::onGridLabelLeftClick ), NULL, this );
52  aGrid->Connect( GRIDTRICKS_FIRST_ID, GRIDTRICKS_LAST_ID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( GRID_TRICKS::onPopupSelection ), NULL, this );
53  aGrid->Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( GRID_TRICKS::onKeyDown ), NULL, this );
54  aGrid->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( GRID_TRICKS::onUpdateUI ), NULL, this );
55 }
void onGridLabelLeftClick(wxGridEvent &event)
int m_sel_row_count
Definition: grid_tricks.h:64
void onGridCellLeftClick(wxGridEvent &event)
void onGridCellRightClick(wxGridEvent &event)
int m_sel_col_start
Definition: grid_tricks.h:63
void onGridCellLeftDClick(wxGridEvent &event)
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:58
void onPopupSelection(wxCommandEvent &event)
int m_sel_col_count
Definition: grid_tricks.h:65
int m_sel_row_start
Definition: grid_tricks.h:62
void onUpdateUI(wxUpdateUIEvent &event)
void onGridLabelRightClick(wxGridEvent &event)
void onKeyDown(wxKeyEvent &ev)

References GRIDTRICKS_FIRST_ID, GRIDTRICKS_LAST_ID, m_sel_col_count, m_sel_col_start, m_sel_row_count, m_sel_row_start, onGridCellLeftClick(), onGridCellLeftDClick(), onGridCellRightClick(), onGridLabelLeftClick(), onGridLabelRightClick(), onKeyDown(), onPopupSelection(), and onUpdateUI().

Member Function Documentation

◆ cutcopy()

void GRID_TRICKS::cutcopy ( bool  doCut)
protectedvirtual

Definition at line 505 of file grid_tricks.cpp.

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

Referenced by doPopupSelection(), and onKeyDown().

◆ doPopupSelection()

void GRID_TRICKS::doPopupSelection ( wxCommandEvent &  event)
protectedvirtual

Reimplemented in FP_GRID_TRICKS, FIELDS_EDITOR_GRID_TRICKS, and FIELDS_GRID_TRICKS.

Definition at line 274 of file grid_tricks.cpp.

275 {
276  int menu_id = event.GetId();
277 
278  // assume getSelectedArea() was called by rightClickPopupMenu() and there's
279  // no way to have gotten here without that having been called.
280 
281  switch( menu_id )
282  {
283  case GRIDTRICKS_ID_CUT:
284  case GRIDTRICKS_ID_COPY:
285  cutcopy( menu_id == GRIDTRICKS_ID_CUT );
286  break;
287 
288  case GRIDTRICKS_ID_PASTE:
289  paste_clipboard();
290  break;
291 
293  m_grid->SelectAll();
294  break;
295 
296  default:
297  if( menu_id >= GRIDTRICKS_FIRST_SHOWHIDE )
298  {
299  int col = menu_id - GRIDTRICKS_FIRST_SHOWHIDE;
300 
301  if( m_grid->IsColShown( col ) )
302  m_grid->HideCol( col );
303  else
304  m_grid->ShowCol( col );
305  }
306  }
307 }
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 cutcopy(), GRIDTRICKS_FIRST_SHOWHIDE, GRIDTRICKS_ID_COPY, GRIDTRICKS_ID_CUT, GRIDTRICKS_ID_PASTE, GRIDTRICKS_ID_SELECT, m_grid, and paste_clipboard().

Referenced by FIELDS_GRID_TRICKS::doPopupSelection(), FIELDS_EDITOR_GRID_TRICKS::doPopupSelection(), FP_GRID_TRICKS::doPopupSelection(), and onPopupSelection().

◆ getSelectedArea()

void GRID_TRICKS::getSelectedArea ( )
protected

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: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 m_grid, m_sel_col_count, m_sel_col_start, m_sel_row_count, and m_sel_row_start.

Referenced by onKeyDown(), and showPopupMenu().

◆ handleDoubleClick()

bool GRID_TRICKS::handleDoubleClick ( wxGridEvent &  aEvent)
protectedvirtual

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

◆ isCtl()

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

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

◆ onGridCellLeftClick()

void GRID_TRICKS::onGridCellLeftClick ( wxGridEvent &  event)
protected

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)
Definition: grid_tricks.cpp:58
bool showEditor(int aRow, int aCol)
Definition: grid_tricks.cpp:99

References showEditor(), and toggleCell().

Referenced by GRID_TRICKS(), and onGridCellLeftDClick().

◆ onGridCellLeftDClick()

void GRID_TRICKS::onGridCellLeftDClick ( wxGridEvent &  event)
protected

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 handleDoubleClick(), and onGridCellLeftClick().

Referenced by GRID_TRICKS().

◆ onGridCellRightClick()

void GRID_TRICKS::onGridCellRightClick ( wxGridEvent &  event)
protected

Definition at line 207 of file grid_tricks.cpp.

208 {
209  wxMenu menu;
210 
211  showPopupMenu( menu );
212 }
virtual void showPopupMenu(wxMenu &menu)

References showPopupMenu().

Referenced by GRID_TRICKS().

◆ onGridLabelLeftClick()

void GRID_TRICKS::onGridLabelLeftClick ( wxGridEvent &  event)
protected

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:58
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:172

References WX_GRID::CommitPendingChanges(), and m_grid.

Referenced by GRID_TRICKS().

◆ onGridLabelRightClick()

void GRID_TRICKS::onGridLabelRightClick ( wxGridEvent &  event)
protected

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:58
size_t i
Definition: json11.cpp:597

References GRIDTRICKS_FIRST_SHOWHIDE, i, and m_grid.

Referenced by GRID_TRICKS().

◆ onKeyDown()

void GRID_TRICKS::onKeyDown ( wxKeyEvent &  ev)
protected

Definition at line 310 of file grid_tricks.cpp.

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

Referenced by GRID_TRICKS().

◆ onPopupSelection()

void GRID_TRICKS::onPopupSelection ( wxCommandEvent &  event)
protected

Definition at line 268 of file grid_tricks.cpp.

269 {
270  doPopupSelection( event );
271 }
virtual void doPopupSelection(wxCommandEvent &event)

References doPopupSelection().

Referenced by GRID_TRICKS().

◆ onUpdateUI()

void GRID_TRICKS::onUpdateUI ( wxUpdateUIEvent &  event)
protected

Definition at line 537 of file grid_tricks.cpp.

538 {
539  // Respect ROW selectionMode when moving cursor
540 
541  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
542  {
543  int cursorRow = m_grid->GetGridCursorRow();
544  bool cursorInSelectedRow = false;
545 
546  for( int row : m_grid->GetSelectedRows() )
547  {
548  if( row == cursorRow )
549  {
550  cursorInSelectedRow = true;
551  break;
552  }
553  }
554 
555  if( !cursorInSelectedRow )
556  m_grid->SelectRow( cursorRow );
557  }
558 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:58

References m_grid.

Referenced by GRID_TRICKS().

◆ paste_clipboard()

void GRID_TRICKS::paste_clipboard ( )
protectedvirtual

Definition at line 397 of file grid_tricks.cpp.

398 {
399  if( wxTheClipboard->Open() )
400  {
401  if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
402  {
403  wxTextDataObject data;
404 
405  wxTheClipboard->GetData( data );
406 
407  paste_text( data.GetText() );
408  }
409 
410  wxTheClipboard->Close();
411  m_grid->ForceRefresh();
412  }
413 }
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 m_grid, and paste_text().

Referenced by doPopupSelection(), and onKeyDown().

◆ paste_text()

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

Reimplemented in FP_GRID_TRICKS, and SYMBOL_GRID_TRICKS.

Definition at line 416 of file grid_tricks.cpp.

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

Referenced by paste_clipboard(), SYMBOL_GRID_TRICKS::paste_text(), and FP_GRID_TRICKS::paste_text().

◆ showEditor()

bool GRID_TRICKS::showEditor ( int  aRow,
int  aCol 
)
protected

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: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 m_grid, and WX_GRID::ShowEditorOnMouseUp().

Referenced by onGridCellLeftClick().

◆ showPopupMenu()

void GRID_TRICKS::showPopupMenu ( wxMenu &  menu)
protectedvirtual

Reimplemented in FP_GRID_TRICKS, FIELDS_EDITOR_GRID_TRICKS, and FIELDS_GRID_TRICKS.

Definition at line 238 of file grid_tricks.cpp.

239 {
240  menu.Append( GRIDTRICKS_ID_CUT, _( "Cut\tCTRL+X" ), _( "Clear selected cells placing original contents on clipboard" ) );
241  menu.Append( GRIDTRICKS_ID_COPY, _( "Copy\tCTRL+C" ), _( "Copy selected cells to clipboard" ) );
242  menu.Append( GRIDTRICKS_ID_PASTE, _( "Paste\tCTRL+V" ), _( "Paste clipboard cells to matrix at current cell" ) );
243  menu.Append( GRIDTRICKS_ID_SELECT, _( "Select All\tCTRL+A" ), _( "Select all cells" ) );
244 
245  getSelectedArea();
246 
247  // if nothing is selected, disable cut and copy.
249  {
250  menu.Enable( GRIDTRICKS_ID_CUT, false );
251  menu.Enable( GRIDTRICKS_ID_COPY, false );
252  }
253 
254  menu.Enable( GRIDTRICKS_ID_PASTE, false );
255 
256  if( wxTheClipboard->Open() )
257  {
258  if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
259  menu.Enable( GRIDTRICKS_ID_PASTE, true );
260 
261  wxTheClipboard->Close();
262  }
263 
264  m_grid->PopupMenu( &menu );
265 }
void getSelectedArea()
Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above.
int m_sel_row_count
Definition: grid_tricks.h:64
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
#define _(s)

References _, getSelectedArea(), GRIDTRICKS_ID_COPY, GRIDTRICKS_ID_CUT, GRIDTRICKS_ID_PASTE, GRIDTRICKS_ID_SELECT, m_grid, m_sel_col_count, and m_sel_row_count.

Referenced by onGridCellRightClick(), FIELDS_GRID_TRICKS::showPopupMenu(), FIELDS_EDITOR_GRID_TRICKS::showPopupMenu(), and FP_GRID_TRICKS::showPopupMenu().

◆ toggleCell()

bool GRID_TRICKS::toggleCell ( int  aRow,
int  aCol 
)
protected

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->ClearSelection();
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:58

References m_grid.

Referenced by onGridCellLeftClick(), and onKeyDown().

Member Data Documentation

◆ m_grid

◆ m_sel_col_count

int GRID_TRICKS::m_sel_col_count
protected

Definition at line 65 of file grid_tricks.h.

Referenced by cutcopy(), getSelectedArea(), GRID_TRICKS(), paste_text(), and showPopupMenu().

◆ m_sel_col_start

int GRID_TRICKS::m_sel_col_start
protected

Definition at line 63 of file grid_tricks.h.

Referenced by cutcopy(), getSelectedArea(), GRID_TRICKS(), and paste_text().

◆ m_sel_row_count

int GRID_TRICKS::m_sel_row_count
protected

Definition at line 64 of file grid_tricks.h.

Referenced by cutcopy(), getSelectedArea(), GRID_TRICKS(), paste_text(), and showPopupMenu().

◆ m_sel_row_start

int GRID_TRICKS::m_sel_row_start
protected

Definition at line 62 of file grid_tricks.h.

Referenced by cutcopy(), getSelectedArea(), GRID_TRICKS(), and paste_text().


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