KiCad PCB EDA Suite
FIELDS_GRID_TRICKS Class Reference

#include <fields_grid_table.h>

Inheritance diagram for FIELDS_GRID_TRICKS:
GRID_TRICKS

Public Member Functions

 FIELDS_GRID_TRICKS (WX_GRID *aGrid, DIALOG_SHIM *aDialog)
 
void SetTooltipEnable (int aCol, bool aEnable=true)
 Enable the tooltip for a column. More...
 
bool GetTooltipEnabled (int aCol)
 Query if the tooltip for a column is enabled. More...
 

Protected Member Functions

virtual void showPopupMenu (wxMenu &menu) override
 
virtual void doPopupSelection (wxCommandEvent &event) override
 
void getSelectedArea ()
 Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above. More...
 
void onGridCellLeftClick (wxGridEvent &event)
 
void onGridCellLeftDClick (wxGridEvent &event)
 
void onGridCellRightClick (wxGridEvent &event)
 
void onGridLabelLeftClick (wxGridEvent &event)
 
void onGridLabelRightClick (wxGridEvent &event)
 
void onPopupSelection (wxCommandEvent &event)
 
void onKeyDown (wxKeyEvent &ev)
 
void onUpdateUI (wxUpdateUIEvent &event)
 
void onGridMotion (wxMouseEvent &event)
 
virtual bool handleDoubleClick (wxGridEvent &aEvent)
 
bool toggleCell (int aRow, int aCol, bool aPreserveSelection=false)
 
bool showEditor (int aRow, int aCol)
 
virtual void paste_clipboard ()
 
virtual void paste_text (const wxString &cb_text)
 
virtual void cutcopy (bool doCopy, bool doDelete)
 

Protected Attributes

DIALOG_SHIMm_dlg
 
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
 
std::bitset< GRIDTRICKS_MAX_COLm_tooltipEnabled
 

Detailed Description

Definition at line 38 of file fields_grid_table.h.

Constructor & Destructor Documentation

◆ FIELDS_GRID_TRICKS()

FIELDS_GRID_TRICKS::FIELDS_GRID_TRICKS ( WX_GRID aGrid,
DIALOG_SHIM aDialog 
)
inline

Definition at line 41 of file fields_grid_table.h.

41  :
42  GRID_TRICKS( aGrid ),
43  m_dlg( aDialog )
44  {}
GRID_TRICKS(WX_GRID *aGrid)
Definition: grid_tricks.cpp:40

Member Function Documentation

◆ cutcopy()

void GRID_TRICKS::cutcopy ( bool  doCopy,
bool  doDelete 
)
protectedvirtualinherited

Definition at line 649 of file grid_tricks.cpp.

650 {
651  wxLogNull doNotLog; // disable logging of failed clipboard actions
652 
653  if( doCopy && !wxTheClipboard->Open() )
654  return;
655 
656  wxGridTableBase* tbl = m_grid->GetTable();
657  wxString txt;
658 
659  // fill txt with a format that is compatible with most spreadsheets
660  for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
661  {
662  for( int col = m_sel_col_start; col < m_sel_col_start + m_sel_col_count; ++col )
663  {
664  txt += tbl->GetValue( row, col );
665 
666  if( col < m_sel_col_start + m_sel_col_count - 1 ) // that was not last column
667  txt += COL_SEP;
668 
669  if( doDelete )
670  {
671  if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_STRING ) )
672  tbl->SetValue( row, col, wxEmptyString );
673  }
674  }
675 
676  txt += ROW_SEP;
677  }
678 
679  if( doCopy )
680  {
681  wxTheClipboard->SetData( new wxTextDataObject( txt ) );
682  wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
683  wxTheClipboard->Close();
684  }
685 
686  if( doDelete )
687  m_grid->ForceRefresh();
688 }
int m_sel_row_count
Definition: grid_tricks.h:115
int m_sel_col_start
Definition: grid_tricks.h:114
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109
int m_sel_col_count
Definition: grid_tricks.h:116
int m_sel_row_start
Definition: grid_tricks.h:113
#define ROW_SEP
Definition: grid_tricks.cpp:37
#define COL_SEP
Definition: grid_tricks.cpp:36

References COL_SEP, GRID_TRICKS::m_grid, GRID_TRICKS::m_sel_col_count, GRID_TRICKS::m_sel_col_start, GRID_TRICKS::m_sel_row_count, GRID_TRICKS::m_sel_row_start, and ROW_SEP.

Referenced by GRID_TRICKS::doPopupSelection(), and GRID_TRICKS::onKeyDown().

◆ doPopupSelection()

void FIELDS_GRID_TRICKS::doPopupSelection ( wxCommandEvent &  event)
overrideprotectedvirtual

Reimplemented from GRID_TRICKS.

Definition at line 616 of file fields_grid_table.cpp.

617 {
618  if( event.GetId() == MYID_SELECT_FOOTPRINT )
619  {
620  // pick a footprint using the footprint picker.
621  wxString fpid = m_grid->GetCellValue( FOOTPRINT_FIELD, FDC_VALUE );
623 
624  if( frame->ShowModal( &fpid, m_dlg ) )
625  m_grid->SetCellValue( FOOTPRINT_FIELD, FDC_VALUE, fpid );
626 
627  frame->Destroy();
628  }
629  else if (event.GetId() == MYID_SHOW_DATASHEET )
630  {
631  wxString datasheet_uri = m_grid->GetCellValue( DATASHEET_FIELD, FDC_VALUE );
632  GetAssociatedDocument( m_dlg, datasheet_uri, &m_dlg->Prj() );
633  }
634  else
635  {
637  }
638 }
virtual bool ShowModal(wxString *aResult=nullptr, wxWindow *aResultantFocusWindow=nullptr)
Show this wxFrame as if it were a modal dialog, with all other instantiated wxFrames disabled until t...
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject)
Open a document (file) with the suitable browser.
Definition: eda_doc.cpp:74
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:64
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:383
name of datasheet
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
virtual void doPopupSelection(wxCommandEvent &event)
bool Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
Field Name Module PCB, i.e. "16DIP300".

References DATASHEET_FIELD, KIWAY_PLAYER::Destroy(), GRID_TRICKS::doPopupSelection(), FDC_VALUE, FOOTPRINT_FIELD, FRAME_FOOTPRINT_VIEWER_MODAL, GetAssociatedDocument(), KIWAY_HOLDER::Kiway(), m_dlg, GRID_TRICKS::m_grid, MYID_SELECT_FOOTPRINT, MYID_SHOW_DATASHEET, KIWAY::Player(), KIWAY_HOLDER::Prj(), and KIWAY_PLAYER::ShowModal().

◆ getSelectedArea()

void GRID_TRICKS::getSelectedArea ( )
protectedinherited

Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above.

Definition at line 204 of file grid_tricks.cpp.

205 {
206  wxGridCellCoordsArray topLeft = m_grid->GetSelectionBlockTopLeft();
207  wxGridCellCoordsArray botRight = m_grid->GetSelectionBlockBottomRight();
208 
209  wxArrayInt cols = m_grid->GetSelectedCols();
210  wxArrayInt rows = m_grid->GetSelectedRows();
211 
212  if( topLeft.Count() && botRight.Count() )
213  {
214  m_sel_row_start = topLeft[0].GetRow();
215  m_sel_col_start = topLeft[0].GetCol();
216 
217  m_sel_row_count = botRight[0].GetRow() - m_sel_row_start + 1;
218  m_sel_col_count = botRight[0].GetCol() - m_sel_col_start + 1;
219  }
220  else if( cols.Count() )
221  {
222  m_sel_col_start = cols[0];
223  m_sel_col_count = cols.Count();
224  m_sel_row_start = 0;
225  m_sel_row_count = m_grid->GetNumberRows();
226  }
227  else if( rows.Count() )
228  {
229  m_sel_col_start = 0;
230  m_sel_col_count = m_grid->GetNumberCols();
231  m_sel_row_start = rows[0];
232  m_sel_row_count = rows.Count();
233  }
234  else
235  {
236  m_sel_row_start = m_grid->GetGridCursorRow();
237  m_sel_col_start = m_grid->GetGridCursorCol();
238  m_sel_row_count = m_sel_row_start >= 0 ? 1 : 0;
239  m_sel_col_count = m_sel_col_start >= 0 ? 1 : 0;
240  }
241 }
int m_sel_row_count
Definition: grid_tricks.h:115
int m_sel_col_start
Definition: grid_tricks.h:114
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109
int m_sel_col_count
Definition: grid_tricks.h:116
int m_sel_row_start
Definition: grid_tricks.h:113

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

◆ GetTooltipEnabled()

bool GRID_TRICKS::GetTooltipEnabled ( int  aCol)
inlineinherited

Query if the tooltip for a column is enabled.

Parameters
aColis the column to query
Returns
if the tooltip is enabled for the column

Definition at line 79 of file grid_tricks.h.

80  {
81  return m_tooltipEnabled[aCol];
82  }
std::bitset< GRIDTRICKS_MAX_COL > m_tooltipEnabled
Definition: grid_tricks.h:118

References GRID_TRICKS::m_tooltipEnabled.

◆ handleDoubleClick()

bool GRID_TRICKS::handleDoubleClick ( wxGridEvent &  aEvent)
protectedvirtualinherited

Reimplemented in FP_GRID_TRICKS.

Definition at line 197 of file grid_tricks.cpp.

198 {
199  // Double-click processing must be handled by specific sub-classes
200  return false;
201 }

Referenced by GRID_TRICKS::onGridCellLeftDClick().

◆ onGridCellLeftClick()

void GRID_TRICKS::onGridCellLeftClick ( wxGridEvent &  event)
protectedinherited

Definition at line 148 of file grid_tricks.cpp.

149 {
150  int row = aEvent.GetRow();
151  int col = aEvent.GetCol();
152 
153  // Don't make users click twice to toggle a checkbox or edit a text cell
154  if( !aEvent.GetModifiers() )
155  {
156  if( toggleCell( row, col ) )
157  return;
158 
159  if( showEditor( row, col ) )
160  return;
161  }
162 
163  aEvent.Skip();
164 }
bool toggleCell(int aRow, int aCol, bool aPreserveSelection=false)
Definition: grid_tricks.cpp:70
bool showEditor(int aRow, int aCol)

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

168 {
169  if( !handleDoubleClick( aEvent ) )
170  onGridCellLeftClick( aEvent );
171 }
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 244 of file grid_tricks.cpp.

245 {
246  wxMenu menu;
247 
248  showPopupMenu( menu );
249 }
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 252 of file grid_tricks.cpp.

253 {
255 
256  aEvent.Skip();
257 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:190

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

261 {
262  wxMenu menu;
263 
264  for( int i = 0; i < m_grid->GetNumberCols(); ++i )
265  {
266  int id = GRIDTRICKS_FIRST_SHOWHIDE + i;
267  menu.AppendCheckItem( id, m_grid->GetColLabelValue( i ) );
268  menu.Check( id, m_grid->IsColShown( i ) );
269  }
270 
271  m_grid->PopupMenu( &menu );
272 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109

References GRIDTRICKS_FIRST_SHOWHIDE, and GRID_TRICKS::m_grid.

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ onGridMotion()

void GRID_TRICKS::onGridMotion ( wxMouseEvent &  event)
protectedinherited

Definition at line 174 of file grid_tricks.cpp.

175 {
176  // Always skip the event
177  aEvent.Skip();
178 
179  wxPoint pt = aEvent.GetPosition();
180  wxPoint pos = m_grid->CalcScrolledPosition( wxPoint( pt.x, pt.y ) );
181 
182  int col = m_grid->XToCol( pos.x );
183  int row = m_grid->YToRow( pos.y );
184 
185  // Empty tooltip if the cell doesn't exist or the column doesn't have tooltips
186  if( ( col == wxNOT_FOUND ) || ( row == wxNOT_FOUND ) || !m_tooltipEnabled[col] )
187  {
188  m_grid->GetGridWindow()->SetToolTip( "" );
189  return;
190  }
191 
192  // Set the tooltip to the string contained in the cell
193  m_grid->GetGridWindow()->SetToolTip( m_grid->GetCellValue( row, col ) );
194 }
std::bitset< GRIDTRICKS_MAX_COL > m_tooltipEnabled
Definition: grid_tricks.h:118
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109

References GRID_TRICKS::m_grid, and GRID_TRICKS::m_tooltipEnabled.

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ onKeyDown()

void GRID_TRICKS::onKeyDown ( wxKeyEvent &  ev)
protectedinherited

Definition at line 361 of file grid_tricks.cpp.

362 {
363  if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'A' )
364  {
365  m_grid->SelectAll();
366  return;
367  }
368  else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'C' )
369  {
370  getSelectedArea();
371  cutcopy( true, false );
372  return;
373  }
374  else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'V' )
375  {
376  getSelectedArea();
377  paste_clipboard();
378  return;
379  }
380  else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'X' )
381  {
382  getSelectedArea();
383  cutcopy( true, true );
384  return;
385  }
386  else if( !ev.GetModifiers() && ev.GetKeyCode() == WXK_DELETE )
387  {
388  getSelectedArea();
389  cutcopy( false, true );
390  return;
391  }
392 
393  // space-bar toggling of checkboxes
394  if( ev.GetKeyCode() == ' ' )
395  {
396  bool retVal = false;
397 
398  // If only rows can be selected, only toggle the first cell in a row
399  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
400  {
401  wxArrayInt rowSel = m_grid->GetSelectedRows();
402 
403  for( unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
404  {
405  retVal |= toggleCell( rowSel[rowInd], 0, true );
406  }
407  }
408 
409  // If only columns can be selected, only toggle the first cell in a column
410  else if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectColumns )
411  {
412  wxArrayInt colSel = m_grid->GetSelectedCols();
413 
414  for( unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
415  {
416  retVal |= toggleCell( 0, colSel[colInd], true );
417  }
418  }
419 
420  // If the user can select the individual cells, toggle each cell selected
421  else if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectCells )
422  {
423  wxArrayInt rowSel = m_grid->GetSelectedRows();
424  wxArrayInt colSel = m_grid->GetSelectedCols();
425  wxGridCellCoordsArray cellSel = m_grid->GetSelectedCells();
426  wxGridCellCoordsArray topLeft = m_grid->GetSelectionBlockTopLeft();
427  wxGridCellCoordsArray botRight = m_grid->GetSelectionBlockBottomRight();
428 
429  // Iterate over every individually selected cell and try to toggle it
430  for( unsigned int cellInd = 0; cellInd < cellSel.GetCount(); cellInd++ )
431  {
432  retVal |= toggleCell( cellSel[cellInd].GetRow(), cellSel[cellInd].GetCol(), true );
433  }
434 
435  // Iterate over every column and try to toggle each cell in it
436  for( unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
437  {
438  for( int row = 0; row < m_grid->GetNumberRows(); row++ )
439  {
440  retVal |= toggleCell( row, colSel[colInd], true );
441  }
442  }
443 
444  // Iterate over every row and try to toggle each cell in it
445  for( unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
446  {
447  for( int col = 0; col < m_grid->GetNumberCols(); col++ )
448  {
449  retVal |= toggleCell( rowSel[rowInd], col, true );
450  }
451  }
452 
453  // Iterate over the selection blocks
454  for( unsigned int blockInd = 0; blockInd < topLeft.GetCount(); blockInd++ )
455  {
456  wxGridCellCoords start = topLeft[blockInd];
457  wxGridCellCoords end = botRight[blockInd];
458 
459  for( int row = start.GetRow(); row <= end.GetRow(); row++ )
460  {
461  for( int col = start.GetCol(); col <= end.GetCol(); col++ )
462  {
463  retVal |= toggleCell( row, col, true );
464  }
465  }
466  }
467  }
468  else
469  {
470  }
471 
472  // Return if there were any cells toggled
473  if( retVal )
474  return;
475  }
476 
477  // ctrl-tab for exit grid
478 #ifdef __APPLE__
479  bool ctrl = ev.RawControlDown();
480 #else
481  bool ctrl = ev.ControlDown();
482 #endif
483 
484  if( ctrl && ev.GetKeyCode() == WXK_TAB )
485  {
486  wxWindow* test = m_grid->GetNextSibling();
487 
488  if( !test )
489  test = m_grid->GetParent()->GetNextSibling();
490 
491  while( test && !test->IsTopLevel() )
492  {
493  test->SetFocus();
494 
495  if( test->HasFocus() )
496  break;
497 
498  if( !test->GetChildren().empty() )
499  {
500  test = test->GetChildren().front();
501  }
502  else if( test->GetNextSibling() )
503  {
504  test = test->GetNextSibling();
505  }
506  else
507  {
508  while( test )
509  {
510  test = test->GetParent();
511 
512  if( test && test->IsTopLevel() )
513  {
514  break;
515  }
516  else if( test && test->GetNextSibling() )
517  {
518  test = test->GetNextSibling();
519  break;
520  }
521  }
522  }
523  }
524 
525  return;
526  }
527 
528  ev.Skip( true );
529 }
void getSelectedArea()
Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above.
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109
bool toggleCell(int aRow, int aCol, bool aPreserveSelection=false)
Definition: grid_tricks.cpp:70
virtual void cutcopy(bool doCopy, bool doDelete)
virtual void paste_clipboard()

References GRID_TRICKS::cutcopy(), GRID_TRICKS::getSelectedArea(), 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 312 of file grid_tricks.cpp.

313 {
314  doPopupSelection( event );
315 }
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 691 of file grid_tricks.cpp.

692 {
693  // Respect ROW selectionMode when moving cursor
694 
695  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
696  {
697  int cursorRow = m_grid->GetGridCursorRow();
698  bool cursorInSelectedRow = false;
699 
700  for( int row : m_grid->GetSelectedRows() )
701  {
702  if( row == cursorRow )
703  {
704  cursorInSelectedRow = true;
705  break;
706  }
707  }
708 
709  if( !cursorInSelectedRow && cursorRow >= 0 )
710  m_grid->SelectRow( cursorRow );
711  }
712 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109

References GRID_TRICKS::m_grid.

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ paste_clipboard()

void GRID_TRICKS::paste_clipboard ( )
protectedvirtualinherited

Definition at line 532 of file grid_tricks.cpp.

533 {
534  wxLogNull doNotLog; // disable logging of failed clipboard actions
535 
536  if( wxTheClipboard->Open() )
537  {
538  if( wxTheClipboard->IsSupported( wxDF_TEXT ) )
539  {
540  wxTextDataObject data;
541 
542  wxTheClipboard->GetData( data );
543 
544  paste_text( data.GetText() );
545  }
546 
547  wxTheClipboard->Close();
548  m_grid->ForceRefresh();
549  }
550 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109
virtual void paste_text(const wxString &cb_text)

References GRID_TRICKS::m_grid, and GRID_TRICKS::paste_text().

Referenced by GRID_TRICKS::doPopupSelection(), and GRID_TRICKS::onKeyDown().

◆ paste_text()

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

Reimplemented in FP_GRID_TRICKS, and SYMBOL_GRID_TRICKS.

Definition at line 553 of file grid_tricks.cpp.

554 {
555  wxGridTableBase* tbl = m_grid->GetTable();
556 
557  const int cur_row = m_grid->GetGridCursorRow();
558  const int cur_col = m_grid->GetGridCursorCol();
559  int start_row;
560  int end_row;
561  int start_col;
562  int end_col;
563  bool is_selection = false;
564 
565  if( cur_row < 0 || cur_col < 0 )
566  {
567  wxBell();
568  return;
569  }
570 
571  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
572  {
573  if( m_sel_row_count > 1 )
574  is_selection = true;
575  }
576  else
577  {
578  if( m_grid->IsSelection() )
579  is_selection = true;
580  }
581 
582  wxStringTokenizer rows( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
583 
584  // If selection of cells is present
585  // then a clipboard pastes to selected cells only.
586  if( is_selection )
587  {
588  start_row = m_sel_row_start;
589  end_row = m_sel_row_start + m_sel_row_count;
590  start_col = m_sel_col_start;
591  end_col = m_sel_col_start + m_sel_col_count;
592  }
593  // Otherwise, paste whole clipboard
594  // starting from cell with cursor.
595  else
596  {
597  start_row = cur_row;
598  end_row = cur_row + rows.CountTokens();
599 
600  if( end_row > tbl->GetNumberRows() )
601  end_row = tbl->GetNumberRows();
602 
603  start_col = cur_col;
604  end_col = start_col; // end_col actual value calculates later
605  }
606 
607  for( int row = start_row; row < end_row; ++row )
608  {
609  // If number of selected rows bigger than count of rows in
610  // the clipboard, paste from the clipboard again and again
611  // while end of the selection is reached.
612  if( !rows.HasMoreTokens() )
613  rows.SetString( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
614 
615  wxString rowTxt = rows.GetNextToken();
616 
617  wxStringTokenizer cols( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
618 
619  if( !is_selection )
620  {
621  end_col = cur_col + cols.CountTokens();
622 
623  if( end_col > tbl->GetNumberCols() )
624  end_col = tbl->GetNumberCols();
625  }
626 
627  for( int col = start_col; col < end_col; ++col )
628  {
629  // If number of selected columns bigger than count of columns in
630  // the clipboard, paste from the clipboard again and again while
631  // end of the selection is reached.
632  if( !cols.HasMoreTokens() )
633  cols.SetString( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
634 
635  wxString cellTxt = cols.GetNextToken();
636 
637  if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_STRING ) )
638  {
639  tbl->SetValue( row, col, cellTxt );
640 
641  wxGridEvent evt( m_grid->GetId(), wxEVT_GRID_CELL_CHANGED, m_grid, row, col );
642  m_grid->GetEventHandler()->ProcessEvent( evt );
643  }
644  }
645  }
646 }
int m_sel_row_count
Definition: grid_tricks.h:115
int m_sel_col_start
Definition: grid_tricks.h:114
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109
int m_sel_col_count
Definition: grid_tricks.h:116
int m_sel_row_start
Definition: grid_tricks.h:113
#define ROW_SEP
Definition: grid_tricks.cpp:37
#define COL_SEP
Definition: grid_tricks.cpp:36

References COL_SEP, GRID_TRICKS::m_grid, GRID_TRICKS::m_sel_col_count, GRID_TRICKS::m_sel_col_start, GRID_TRICKS::m_sel_row_count, GRID_TRICKS::m_sel_row_start, and ROW_SEP.

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

◆ SetTooltipEnable()

void GRID_TRICKS::SetTooltipEnable ( int  aCol,
bool  aEnable = true 
)
inlineinherited

Enable the tooltip for a column.

The tooltip is read from the string contained in the cell data.

Parameters
aColis the column to use
aEnableis true to enable the tooltip (default)

Definition at line 68 of file grid_tricks.h.

69  {
70  m_tooltipEnabled[aCol] = aEnable;
71  }
std::bitset< GRIDTRICKS_MAX_COL > m_tooltipEnabled
Definition: grid_tricks.h:118

References GRID_TRICKS::m_tooltipEnabled.

Referenced by PANEL_FP_PROPERTIES_3D_MODEL::PANEL_FP_PROPERTIES_3D_MODEL().

◆ showEditor()

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

Definition at line 113 of file grid_tricks.cpp.

114 {
115  if( m_grid->GetGridCursorRow() != aRow || m_grid->GetGridCursorCol() != aCol )
116  m_grid->SetGridCursor( aRow, aCol );
117 
118  if( m_grid->IsEditable() && !m_grid->IsReadOnly( aRow, aCol ) )
119  {
120  m_grid->ClearSelection();
121 
122  if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
123  {
124  wxArrayInt rows = m_grid->GetSelectedRows();
125 
126  if( rows.size() != 1 || rows.Item( 0 ) != aRow )
127  m_grid->SelectRow( aRow );
128  }
129 
130  // For several reasons we can't enable the control here. There's the whole
131  // SetInSetFocus() issue/hack in wxWidgets, and there's also wxGrid's MouseUp
132  // handler which doesn't notice it's processing a MouseUp until after it has
133  // disabled the editor yet again. So we re-use wxWidgets' slow-click hack,
134  // which is processed later in the MouseUp handler.
135  //
136  // It should be pointed out that the fact that it's wxWidgets' hack doesn't
137  // make it any less of a hack. Be extra careful with any modifications here.
138  // See, in particular, https://bugs.launchpad.net/kicad/+bug/1817965.
140 
141  return true;
142  }
143 
144  return false;
145 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109
void ShowEditorOnMouseUp()
WxWidgets has a bunch of bugs in its handling of wxGrid mouse events which close cell editors right a...
Definition: wx_grid.h:99

References GRID_TRICKS::m_grid, and WX_GRID::ShowEditorOnMouseUp().

Referenced by GRID_TRICKS::onGridCellLeftClick().

◆ showPopupMenu()

void FIELDS_GRID_TRICKS::showPopupMenu ( wxMenu &  menu)
overrideprotectedvirtual

Reimplemented from GRID_TRICKS.

Definition at line 597 of file fields_grid_table.cpp.

598 {
599  if( m_grid->GetGridCursorRow() == FOOTPRINT_FIELD && m_grid->GetGridCursorCol() == FDC_VALUE )
600  {
601  menu.Append( MYID_SELECT_FOOTPRINT, _( "Select Footprint..." ),
602  _( "Browse for footprint" ) );
603  menu.AppendSeparator();
604  }
605  else if( m_grid->GetGridCursorRow() == DATASHEET_FIELD && m_grid->GetGridCursorCol() == FDC_VALUE )
606  {
607  menu.Append( MYID_SHOW_DATASHEET, _( "Show Datasheet" ),
608  _( "Show datasheet in browser" ) );
609  menu.AppendSeparator();
610  }
611 
613 }
name of datasheet
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109
#define _(s)
virtual void showPopupMenu(wxMenu &menu)
Field Name Module PCB, i.e. "16DIP300".

References _, DATASHEET_FIELD, FDC_VALUE, FOOTPRINT_FIELD, GRID_TRICKS::m_grid, MYID_SELECT_FOOTPRINT, MYID_SHOW_DATASHEET, and GRID_TRICKS::showPopupMenu().

◆ toggleCell()

bool GRID_TRICKS::toggleCell ( int  aRow,
int  aCol,
bool  aPreserveSelection = false 
)
protectedinherited

Definition at line 70 of file grid_tricks.cpp.

71 {
72  auto renderer = m_grid->GetCellRenderer( aRow, aCol );
73  bool isCheckbox = ( dynamic_cast<wxGridCellBoolRenderer*>( renderer ) != nullptr );
74  renderer->DecRef();
75 
76  if( isCheckbox )
77  {
78  if( !aPreserveSelection )
79  m_grid->ClearSelection();
80 
81  m_grid->SetGridCursor( aRow, aCol );
82 
83  wxGridTableBase* model = m_grid->GetTable();
84 
85  if( model->CanGetValueAs( aRow, aCol, wxGRID_VALUE_BOOL )
86  && model->CanSetValueAs( aRow, aCol, wxGRID_VALUE_BOOL ) )
87  {
88  model->SetValueAsBool( aRow, aCol, !model->GetValueAsBool( aRow, aCol ) );
89  }
90  else // fall back to string processing
91  {
92  if( model->GetValue( aRow, aCol ) == wxT( "1" ) )
93  model->SetValue( aRow, aCol, wxT( "0" ) );
94  else
95  model->SetValue( aRow, aCol, wxT( "1" ) );
96  }
97 
98  // Mac needs this for the keyboard events; Linux appears to always need it.
99  m_grid->ForceRefresh();
100 
101  // Let any clients know
102  wxGridEvent event( m_grid->GetId(), wxEVT_GRID_CELL_CHANGED, m_grid, aRow, aCol );
103  event.SetString( model->GetValue( aRow, aCol ) );
104  m_grid->GetEventHandler()->ProcessEvent( event );
105 
106  return true;
107  }
108 
109  return false;
110 }
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:109

References GRID_TRICKS::m_grid.

Referenced by GRID_TRICKS::onGridCellLeftClick(), and GRID_TRICKS::onKeyDown().

Member Data Documentation

◆ m_dlg

DIALOG_SHIM* FIELDS_GRID_TRICKS::m_dlg
protected

Definition at line 49 of file fields_grid_table.h.

Referenced by doPopupSelection().

◆ m_grid

◆ m_sel_col_count

int GRID_TRICKS::m_sel_col_count
protectedinherited

◆ m_sel_col_start

int GRID_TRICKS::m_sel_col_start
protectedinherited

◆ m_sel_row_count

int GRID_TRICKS::m_sel_row_count
protectedinherited

◆ m_sel_row_start

int GRID_TRICKS::m_sel_row_start
protectedinherited

◆ m_tooltipEnabled

std::bitset<GRIDTRICKS_MAX_COL> GRID_TRICKS::m_tooltipEnabled
protectedinherited

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