KiCad PCB EDA Suite
SYMBOL_GRID_TRICKS Class Reference
Inheritance diagram for SYMBOL_GRID_TRICKS:
GRID_TRICKS

Public Member Functions

 SYMBOL_GRID_TRICKS (DIALOG_EDIT_LIBRARY_TABLES *aParent, WX_GRID *aGrid)
 

Protected Member Functions

virtual void paste_text (const wxString &cb_text) override
 handle specialized clipboard text, with leading "(sym_lib_table" or spreadsheet formatted text. More...
 
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 cutcopy (bool doCut)
 

Static Protected Member Functions

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

Protected Attributes

DIALOG_EDIT_LIBRARY_TABLESm_dialog
 
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 86 of file panel_sym_lib_table.cpp.

Constructor & Destructor Documentation

◆ SYMBOL_GRID_TRICKS()

SYMBOL_GRID_TRICKS::SYMBOL_GRID_TRICKS ( DIALOG_EDIT_LIBRARY_TABLES aParent,
WX_GRID aGrid 
)
inline

Definition at line 89 of file panel_sym_lib_table.cpp.

89  :
90  GRID_TRICKS( aGrid ),
91  m_dialog( aParent )
92  {
93  }
GRID_TRICKS(WX_GRID *aGrid)
Definition: grid_tricks.cpp:39
DIALOG_EDIT_LIBRARY_TABLES * m_dialog

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 GRID_TRICKS::doPopupSelection ( wxCommandEvent &  event)
protectedvirtualinherited

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 GRID_TRICKS::cutcopy(), GRIDTRICKS_FIRST_SHOWHIDE, GRIDTRICKS_ID_COPY, GRIDTRICKS_ID_CUT, GRIDTRICKS_ID_PASTE, GRIDTRICKS_ID_SELECT, GRID_TRICKS::m_grid, and GRID_TRICKS::paste_clipboard().

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

◆ 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()

virtual void SYMBOL_GRID_TRICKS::paste_text ( const wxString &  cb_text)
inlineoverrideprotectedvirtual

handle specialized clipboard text, with leading "(sym_lib_table" or spreadsheet formatted text.

Reimplemented from GRID_TRICKS.

Definition at line 100 of file panel_sym_lib_table.cpp.

101  {
102  SYMBOL_LIB_TABLE_GRID* tbl = (SYMBOL_LIB_TABLE_GRID*) m_grid->GetTable();
103  size_t ndx = cb_text.find( "(sym_lib_table" );
104 
105  if( ndx != std::string::npos )
106  {
107  // paste the SYMBOL_LIB_TABLE_ROWs of s-expression (sym_lib_table), starting
108  // at column 0 regardless of current cursor column.
109 
110  STRING_LINE_READER slr( TO_UTF8( cb_text ), "Clipboard" );
111  LIB_TABLE_LEXER lexer( &slr );
112  SYMBOL_LIB_TABLE tmp_tbl;
113  bool parsed = true;
114 
115  try
116  {
117  tmp_tbl.Parse( &lexer );
118  }
119  catch( PARSE_ERROR& pe )
120  {
121  DisplayError( m_dialog, pe.What() );
122  parsed = false;
123  }
124 
125  if( parsed )
126  {
127  // make sure the table is big enough...
128  if( tmp_tbl.GetCount() > (unsigned) tbl->GetNumberRows() )
129  tbl->AppendRows( tmp_tbl.GetCount() - tbl->GetNumberRows() );
130 
131  for( unsigned i = 0; i < tmp_tbl.GetCount(); ++i )
132  tbl->rows.replace( i, tmp_tbl.At( i ).clone() );
133  }
134 
135  m_grid->AutoSizeColumns( false );
136  }
137  else
138  {
139  // paste spreadsheet formatted text.
140  GRID_TRICKS::paste_text( cb_text );
141 
142  m_grid->AutoSizeColumns( false );
143  }
144  }
unsigned GetCount() const
Get the number of rows contained in the table.
LIB_TABLE_ROWS rows
int GetNumberRows() override
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)
#define TO_UTF8(wxstring)
Macro TO_UTF8 converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:48
LIB_TABLE_ROW * clone() const
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE object.
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:33
DIALOG_EDIT_LIBRARY_TABLES * m_dialog
bool AppendRows(size_t aNumRows=1) override
Struct PARSE_ERROR contains a filename or source description, a problem input line,...
Definition: ki_exception.h:123
LIB_TABLE_ROW & At(unsigned aIndex)
Get the 'n'th LIB_TABLE_ROW object.
virtual void Parse(LIB_TABLE_LEXER *aLexer) override
Parse the #LIB_TABLE_LEXER s-expression library table format into the appropriate LIB_TABLE_ROW objec...
size_t i
Definition: json11.cpp:597
Class STRING_LINE_READER is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:254
void DisplayError(wxWindow *parent, const wxString &text, int displaytime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:243

References LIB_TABLE_GRID::AppendRows(), LIB_TABLE::At(), LIB_TABLE_ROW::clone(), DisplayError(), LIB_TABLE::GetCount(), LIB_TABLE_GRID::GetNumberRows(), i, m_dialog, GRID_TRICKS::m_grid, SYMBOL_LIB_TABLE::Parse(), GRID_TRICKS::paste_text(), LIB_TABLE::rows, TO_UTF8, and IO_ERROR::What().

◆ 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 GRID_TRICKS::showPopupMenu ( wxMenu &  menu)
protectedvirtualinherited

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
#define _(s)

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

Referenced by GRID_TRICKS::onGridCellRightClick(), FIELDS_GRID_TRICKS::showPopupMenu(), FIELDS_EDITOR_GRID_TRICKS::showPopupMenu(), and FP_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_dialog

DIALOG_EDIT_LIBRARY_TABLES* SYMBOL_GRID_TRICKS::m_dialog
protected

Definition at line 96 of file panel_sym_lib_table.cpp.

Referenced by paste_text().

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