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 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( GRIDTRICKS_FIRST_ID, GRIDTRICKS_LAST_ID, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler( GRID_TRICKS::onPopupSelection ), NULL, this );
52  aGrid->Connect( wxEVT_KEY_DOWN, wxKeyEventHandler( GRID_TRICKS::onKeyDown ), NULL, this );
53  aGrid->Connect( wxEVT_UPDATE_UI, wxUpdateUIEventHandler( GRID_TRICKS::onUpdateUI ), NULL, this );
54 }
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(), onGridLabelRightClick(), onKeyDown(), onPopupSelection(), and onUpdateUI().

Member Function Documentation

◆ cutcopy()

void GRID_TRICKS::cutcopy ( bool  doCut)
protectedvirtual

Definition at line 453 of file grid_tricks.cpp.

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

263 {
264  int menu_id = event.GetId();
265 
266  // assume getSelectedArea() was called by rightClickPopupMenu() and there's
267  // no way to have gotten here without that having been called.
268 
269  switch( menu_id )
270  {
271  case GRIDTRICKS_ID_CUT:
272  case GRIDTRICKS_ID_COPY:
273  cutcopy( menu_id == GRIDTRICKS_ID_CUT );
274  break;
275 
276  case GRIDTRICKS_ID_PASTE:
277  paste_clipboard();
278  break;
279 
281  m_grid->SelectAll();
282  break;
283 
284  default:
285  if( menu_id >= GRIDTRICKS_FIRST_SHOWHIDE )
286  {
287  int col = menu_id - GRIDTRICKS_FIRST_SHOWHIDE;
288 
289  if( m_grid->IsColShown( col ) )
290  m_grid->HideCol( col );
291  else
292  m_grid->ShowCol( col );
293  }
294  }
295 }
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 163 of file grid_tricks.cpp.

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

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

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

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

References showEditor(), and toggleCell().

Referenced by GRID_TRICKS(), and onGridCellLeftDClick().

◆ onGridCellLeftDClick()

void GRID_TRICKS::onGridCellLeftDClick ( wxGridEvent &  event)
protected

Definition at line 149 of file grid_tricks.cpp.

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

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

References showPopupMenu().

Referenced by GRID_TRICKS().

◆ onGridLabelRightClick()

void GRID_TRICKS::onGridLabelRightClick ( wxGridEvent &  event)
protected

Definition at line 211 of file grid_tricks.cpp.

212 {
213  wxMenu menu;
214 
215  for( int i = 0; i < m_grid->GetNumberCols(); ++i )
216  {
217  int id = GRIDTRICKS_FIRST_SHOWHIDE + i;
218  menu.AppendCheckItem( id, m_grid->GetColLabelValue( i ) );
219  menu.Check( id, m_grid->IsColShown( i ) );
220  }
221 
222  m_grid->PopupMenu( &menu );
223 }
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 298 of file grid_tricks.cpp.

299 {
300  if( isCtl( 'A', ev ) )
301  {
302  m_grid->SelectAll();
303  return;
304  }
305  else if( isCtl( 'C', ev ) )
306  {
307  getSelectedArea();
308  cutcopy( false );
309  return;
310  }
311  else if( isCtl( 'V', ev ) )
312  {
313  getSelectedArea();
314  paste_clipboard();
315  return;
316  }
317  else if( isCtl( 'X', ev ) )
318  {
319  getSelectedArea();
320  cutcopy( true );
321  return;
322  }
323 
324  // space-bar toggling of checkboxes
325  if( ev.GetKeyCode() == ' ' )
326  {
327  int row = m_grid->GetGridCursorRow();
328  int col = m_grid->GetGridCursorCol();
329 
330  if( m_grid->IsVisible( row, col ) && toggleCell( row, col ) )
331  return;
332  }
333 
334  // shift-return (Mac default) or Ctrl-Return (GTK) for OK
335  if( ev.GetKeyCode() == WXK_RETURN && ( ev.ShiftDown() || ev.ControlDown() ) )
336  {
337  wxPostEvent( this, wxCommandEvent( wxEVT_COMMAND_BUTTON_CLICKED, wxID_OK ) );
338  return;
339  }
340 
341  ev.Skip( true );
342 }
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:57
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 256 of file grid_tricks.cpp.

257 {
258  doPopupSelection( event );
259 }
virtual void doPopupSelection(wxCommandEvent &event)

References doPopupSelection().

Referenced by GRID_TRICKS().

◆ onUpdateUI()

void GRID_TRICKS::onUpdateUI ( wxUpdateUIEvent &  event)
protected

Definition at line 485 of file grid_tricks.cpp.

486 {
487  // Respect ROW selectionMode when moving cursor
488 
489  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
490  {
491  int cursorRow = m_grid->GetGridCursorRow();
492  bool cursorInSelectedRow = false;
493 
494  for( int row : m_grid->GetSelectedRows() )
495  {
496  if( row == cursorRow )
497  {
498  cursorInSelectedRow = true;
499  break;
500  }
501  }
502 
503  if( !cursorInSelectedRow )
504  m_grid->SelectRow( cursorRow );
505  }
506 }
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 345 of file grid_tricks.cpp.

346 {
347  if( wxTheClipboard->Open() )
348  {
349  if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
350  {
351  wxTextDataObject data;
352 
353  wxTheClipboard->GetData( data );
354 
355  paste_text( data.GetText() );
356  }
357 
358  wxTheClipboard->Close();
359  m_grid->ForceRefresh();
360  }
361 }
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 364 of file grid_tricks.cpp.

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

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

227 {
228  menu.Append( GRIDTRICKS_ID_CUT, _( "Cut\tCTRL+X" ), _( "Clear selected cells placing original contents on clipboard" ) );
229  menu.Append( GRIDTRICKS_ID_COPY, _( "Copy\tCTRL+C" ), _( "Copy selected cells to clipboard" ) );
230  menu.Append( GRIDTRICKS_ID_PASTE, _( "Paste\tCTRL+V" ), _( "Paste clipboard cells to matrix at current cell" ) );
231  menu.Append( GRIDTRICKS_ID_SELECT, _( "Select All\tCTRL+A" ), _( "Select all cells" ) );
232 
233  getSelectedArea();
234 
235  // if nothing is selected, disable cut and copy.
237  {
238  menu.Enable( GRIDTRICKS_ID_CUT, false );
239  menu.Enable( GRIDTRICKS_ID_COPY, false );
240  }
241 
242  menu.Enable( GRIDTRICKS_ID_PASTE, false );
243 
244  if( wxTheClipboard->Open() )
245  {
246  if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
247  menu.Enable( GRIDTRICKS_ID_PASTE, true );
248 
249  wxTheClipboard->Close();
250  }
251 
252  m_grid->PopupMenu( &menu );
253 }
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 57 of file grid_tricks.cpp.

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