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

463 {
464  if( wxTheClipboard->Open() )
465  {
466  wxGridTableBase* tbl = m_grid->GetTable();
467  wxString txt;
468 
469  // fill txt with a format that is compatible with most spreadsheets
470  for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
471  {
472  for( int col = m_sel_col_start; col < m_sel_col_start + m_sel_col_count; ++col )
473  {
474  txt += tbl->GetValue( row, col );
475 
476  if( col < m_sel_col_start + m_sel_col_count - 1 ) // that was not last column
477  txt += COL_SEP;
478 
479  if( doCut )
480  tbl->SetValue( row, col, wxEmptyString );
481  }
482  txt += ROW_SEP;
483  }
484 
485  wxTheClipboard->SetData( new wxTextDataObject( txt ) );
486  wxTheClipboard->Close();
487 
488  if( doCut )
489  m_grid->ForceRefresh();
490  }
491 }
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 271 of file grid_tricks.cpp.

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

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

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 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 showEditor(), and toggleCell().

Referenced by GRID_TRICKS(), and onGridCellLeftDClick().

◆ onGridCellLeftDClick()

void GRID_TRICKS::onGridCellLeftDClick ( wxGridEvent &  event)
protected

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

Referenced by GRID_TRICKS().

◆ onGridCellRightClick()

void GRID_TRICKS::onGridCellRightClick ( wxGridEvent &  event)
protected

Definition at line 204 of file grid_tricks.cpp.

205 {
206  wxMenu menu;
207 
208  showPopupMenu( menu );
209 }
virtual void showPopupMenu(wxMenu &menu)

References showPopupMenu().

Referenced by GRID_TRICKS().

◆ onGridLabelLeftClick()

void GRID_TRICKS::onGridLabelLeftClick ( wxGridEvent &  event)
protected

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 m_grid.

Referenced by GRID_TRICKS().

◆ onGridLabelRightClick()

void GRID_TRICKS::onGridLabelRightClick ( wxGridEvent &  event)
protected

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 m_grid.

Referenced by GRID_TRICKS().

◆ onKeyDown()

void GRID_TRICKS::onKeyDown ( wxKeyEvent &  ev)
protected

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  // shift-return (Mac default) or Ctrl-Return (GTK) for OK
344  if( ev.GetKeyCode() == WXK_RETURN && ( ev.ShiftDown() || ev.ControlDown() ) )
345  {
346  wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
347  return;
348  }
349 
350  ev.Skip( true );
351 }
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 265 of file grid_tricks.cpp.

266 {
267  doPopupSelection( event );
268 }
virtual void doPopupSelection(wxCommandEvent &event)

References doPopupSelection().

Referenced by GRID_TRICKS().

◆ onUpdateUI()

void GRID_TRICKS::onUpdateUI ( wxUpdateUIEvent &  event)
protected

Definition at line 494 of file grid_tricks.cpp.

495 {
496  // Respect ROW selectionMode when moving cursor
497 
498  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
499  {
500  int cursorRow = m_grid->GetGridCursorRow();
501  bool cursorInSelectedRow = false;
502 
503  for( int row : m_grid->GetSelectedRows() )
504  {
505  if( row == cursorRow )
506  {
507  cursorInSelectedRow = true;
508  break;
509  }
510  }
511 
512  if( !cursorInSelectedRow )
513  m_grid->SelectRow( cursorRow );
514  }
515 }
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 354 of file grid_tricks.cpp.

355 {
356  if( wxTheClipboard->Open() )
357  {
358  if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
359  {
360  wxTextDataObject data;
361 
362  wxTheClipboard->GetData( data );
363 
364  paste_text( data.GetText() );
365  }
366 
367  wxTheClipboard->Close();
368  m_grid->ForceRefresh();
369  }
370 }
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 373 of file grid_tricks.cpp.

374 {
375  wxGridTableBase* tbl = m_grid->GetTable();
376 
377  const int cur_row = m_grid->GetGridCursorRow();
378  const int cur_col = m_grid->GetGridCursorCol();
379  int start_row;
380  int end_row;
381  int start_col;
382  int end_col;
383  bool is_selection = false;
384 
385  if( cur_row < 0 || cur_col < 0 )
386  {
387  wxBell();
388  return;
389  }
390 
391  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
392  {
393  if( m_sel_row_count > 1 )
394  is_selection = true;
395  }
396  else
397  {
398  if( m_grid->IsSelection() )
399  is_selection = true;
400  }
401 
402  wxStringTokenizer rows( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
403 
404  // If selection of cells is present
405  // then a clipboard pastes to selected cells only.
406  if( is_selection )
407  {
408  start_row = m_sel_row_start;
409  end_row = m_sel_row_start + m_sel_row_count;
410  start_col = m_sel_col_start;
411  end_col = m_sel_col_start + m_sel_col_count;
412  }
413  // Otherwise, paste whole clipboard
414  // starting from cell with cursor.
415  else
416  {
417  start_row = cur_row;
418  end_row = cur_row + rows.CountTokens();
419 
420  if( end_row > tbl->GetNumberRows() )
421  end_row = tbl->GetNumberRows();
422 
423  start_col = cur_col;
424  end_col = start_col; // end_col actual value calculates later
425  }
426 
427  for( int row = start_row; row < end_row; ++row )
428  {
429  // If number of selected rows bigger than count of rows in
430  // the clipboard, paste from the clipboard again and again
431  // while end of the selection is reached.
432  if( !rows.HasMoreTokens() )
433  rows.SetString( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
434 
435  wxString rowTxt = rows.GetNextToken();
436 
437  wxStringTokenizer cols( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
438 
439  if( !is_selection )
440  {
441  end_col = cur_col + cols.CountTokens();
442 
443  if( end_col > tbl->GetNumberCols() )
444  end_col = tbl->GetNumberCols();
445  }
446 
447  for( int col = start_col; col < end_col; ++col )
448  {
449  // If number of selected columns bigger than count of columns in
450  // the clipboard, paste from the clipboard again and again while
451  // end of the selection is reached.
452  if( !cols.HasMoreTokens() )
453  cols.SetString( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
454 
455  wxString cellTxt = cols.GetNextToken();
456  tbl->SetValue( row, col, cellTxt );
457  }
458  }
459 }
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 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 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 235 of file grid_tricks.cpp.

236 {
237  menu.Append( GRIDTRICKS_ID_CUT, _( "Cut\tCTRL+X" ), _( "Clear selected cells placing original contents on clipboard" ) );
238  menu.Append( GRIDTRICKS_ID_COPY, _( "Copy\tCTRL+C" ), _( "Copy selected cells to clipboard" ) );
239  menu.Append( GRIDTRICKS_ID_PASTE, _( "Paste\tCTRL+V" ), _( "Paste clipboard cells to matrix at current cell" ) );
240  menu.Append( GRIDTRICKS_ID_SELECT, _( "Select All\tCTRL+A" ), _( "Select all cells" ) );
241 
242  getSelectedArea();
243 
244  // if nothing is selected, disable cut and copy.
246  {
247  menu.Enable( GRIDTRICKS_ID_CUT, false );
248  menu.Enable( GRIDTRICKS_ID_COPY, false );
249  }
250 
251  menu.Enable( GRIDTRICKS_ID_PASTE, false );
252 
253  if( wxTheClipboard->Open() )
254  {
255  if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
256  menu.Enable( GRIDTRICKS_ID_PASTE, true );
257 
258  wxTheClipboard->Close();
259  }
260 
261  m_grid->PopupMenu( &menu );
262 }
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

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->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 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: