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

Public Member Functions

 SYMBOL_GRID_TRICKS (DIALOG_EDIT_LIBRARY_TABLES *aParent, WX_GRID *aGrid)
 
void showPopupMenu (wxMenu &menu) override
 
void doPopupSelection (wxCommandEvent &event) override
 
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 paste_text (const wxString &cb_text) override
 handle specialized clipboard text, with leading "(sym_lib_table" or spreadsheet formatted text. More...
 
void init ()
 Shared initialization for various ctors. 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 &event)
 
void onCharHook (wxKeyEvent &event)
 
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 cutcopy (bool doCopy, bool doDelete)
 

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
 
std::function< void(wxCommandEvent &)> m_addHandler
 
std::bitset< GRIDTRICKS_MAX_COLm_tooltipEnabled
 

Private Types

enum  { LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED = GRIDTRICKS_FIRST_CLIENT_ID , LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED }
 

Detailed Description

Definition at line 136 of file panel_sym_lib_table.cpp.

Member Enumeration Documentation

◆ anonymous enum

anonymous enum
privateinherited
Enumerator
LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED 
LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED 

Definition at line 24 of file lib_table_grid_tricks.h.

Constructor & Destructor Documentation

◆ SYMBOL_GRID_TRICKS()

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

Definition at line 139 of file panel_sym_lib_table.cpp.

139 :
140 LIB_TABLE_GRID_TRICKS( aGrid ),
141 m_dialog( aParent )
142 {
143 }
LIB_TABLE_GRID_TRICKS(WX_GRID *aGrid)
DIALOG_EDIT_LIBRARY_TABLES * m_dialog

Member Function Documentation

◆ cutcopy()

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

Definition at line 745 of file grid_tricks.cpp.

746{
747 wxLogNull doNotLog; // disable logging of failed clipboard actions
748
749 if( doCopy && !wxTheClipboard->Open() )
750 return;
751
752 wxGridTableBase* tbl = m_grid->GetTable();
753 wxString txt;
754
755 // fill txt with a format that is compatible with most spreadsheets
756 for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
757 {
758 for( int col = m_sel_col_start; col < m_sel_col_start + m_sel_col_count; ++col )
759 {
760 if( !m_grid->IsColShown( col ) )
761 continue;
762
763 txt += tbl->GetValue( row, col );
764
765 if( col < m_sel_col_start + m_sel_col_count - 1 ) // that was not last column
766 txt += COL_SEP;
767
768 if( doDelete && m_grid->IsEditable() )
769 {
770 if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_STRING ) )
771 tbl->SetValue( row, col, wxEmptyString );
772 }
773 }
774
775 txt += ROW_SEP;
776 }
777
778 if( doCopy )
779 {
780 wxTheClipboard->SetData( new wxTextDataObject( txt ) );
781 wxTheClipboard->Flush(); // Allow data to be available after closing KiCad
782 wxTheClipboard->Close();
783 }
784
785 if( doDelete )
786 m_grid->ForceRefresh();
787}
int m_sel_row_start
Definition: grid_tricks.h:125
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:121
int m_sel_row_count
Definition: grid_tricks.h:127
int m_sel_col_count
Definition: grid_tricks.h:128
int m_sel_col_start
Definition: grid_tricks.h:126
#define COL_SEP
Definition: grid_tricks.cpp:36
#define ROW_SEP
Definition: grid_tricks.cpp:37

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 LIB_TABLE_GRID_TRICKS::doPopupSelection ( wxCommandEvent &  event)
overridevirtualinherited

Reimplemented from GRID_TRICKS.

Reimplemented in FP_GRID_TRICKS.

Definition at line 56 of file lib_table_grid_tricks.cpp.

57{
58 int menu_id = event.GetId();
61 {
62 LIB_TABLE_GRID* tbl = (LIB_TABLE_GRID*) m_grid->GetTable();
63
64 for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
65 {
67 }
68 }
69 else
70 {
72 }
73}
virtual void doPopupSelection(wxCommandEvent &event)
This abstract base class mixes any object derived from LIB_TABLE into wxGridTableBase so the result c...
void SetValueAsBool(int aRow, int aCol, bool aValue) override

References GRID_TRICKS::doPopupSelection(), LIB_TABLE_GRID_TRICKS::LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED, LIB_TABLE_GRID_TRICKS::LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED, GRID_TRICKS::m_grid, GRID_TRICKS::m_sel_row_count, GRID_TRICKS::m_sel_row_start, and LIB_TABLE_GRID::SetValueAsBool().

Referenced by FP_GRID_TRICKS::doPopupSelection().

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

253{
254 wxGridCellCoordsArray topLeft = m_grid->GetSelectionBlockTopLeft();
255 wxGridCellCoordsArray botRight = m_grid->GetSelectionBlockBottomRight();
256
257 wxArrayInt cols = m_grid->GetSelectedCols();
258 wxArrayInt rows = m_grid->GetSelectedRows();
259
260 if( topLeft.Count() && botRight.Count() )
261 {
262 m_sel_row_start = topLeft[0].GetRow();
263 m_sel_col_start = topLeft[0].GetCol();
264
265 m_sel_row_count = botRight[0].GetRow() - m_sel_row_start + 1;
266 m_sel_col_count = botRight[0].GetCol() - m_sel_col_start + 1;
267 }
268 else if( cols.Count() )
269 {
270 m_sel_col_start = cols[0];
271 m_sel_col_count = cols.Count();
272 m_sel_row_start = 0;
273 m_sel_row_count = m_grid->GetNumberRows();
274 }
275 else if( rows.Count() )
276 {
277 m_sel_col_start = 0;
278 m_sel_col_count = m_grid->GetNumberCols();
279 m_sel_row_start = rows[0];
280 m_sel_row_count = rows.Count();
281 }
282 else
283 {
284 m_sel_row_start = m_grid->GetGridCursorRow();
285 m_sel_col_start = m_grid->GetGridCursorCol();
286 m_sel_row_count = m_sel_row_start >= 0 ? 1 : 0;
287 m_sel_col_count = m_sel_col_start >= 0 ? 1 : 0;
288 }
289}

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::onGridCellLeftClick(), 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 86 of file grid_tricks.h.

87 {
88 return m_tooltipEnabled[aCol];
89 }
std::bitset< GRIDTRICKS_MAX_COL > m_tooltipEnabled
Definition: grid_tricks.h:132

References GRID_TRICKS::m_tooltipEnabled.

◆ handleDoubleClick()

bool GRID_TRICKS::handleDoubleClick ( wxGridEvent &  aEvent)
protectedvirtualinherited

Reimplemented in FP_GRID_TRICKS.

Definition at line 245 of file grid_tricks.cpp.

246{
247 // Double-click processing must be handled by specific sub-classes
248 return false;
249}

Referenced by GRID_TRICKS::onGridCellLeftDClick().

◆ init()

void GRID_TRICKS::init ( )
protectedinherited

Shared initialization for various ctors.

Definition at line 56 of file grid_tricks.cpp.

57{
62
63 m_grid->Connect( wxEVT_GRID_CELL_LEFT_CLICK,
64 wxGridEventHandler( GRID_TRICKS::onGridCellLeftClick ), nullptr, this );
65 m_grid->Connect( wxEVT_GRID_CELL_LEFT_DCLICK,
66 wxGridEventHandler( GRID_TRICKS::onGridCellLeftDClick ), nullptr, this );
67 m_grid->Connect( wxEVT_GRID_CELL_RIGHT_CLICK,
68 wxGridEventHandler( GRID_TRICKS::onGridCellRightClick ), nullptr, this );
69 m_grid->Connect( wxEVT_GRID_LABEL_RIGHT_CLICK,
70 wxGridEventHandler( GRID_TRICKS::onGridLabelRightClick ), nullptr, this );
71 m_grid->Connect( wxEVT_GRID_LABEL_LEFT_CLICK,
72 wxGridEventHandler( GRID_TRICKS::onGridLabelLeftClick ), nullptr, this );
73 m_grid->Connect( GRIDTRICKS_FIRST_ID, GRIDTRICKS_LAST_ID, wxEVT_COMMAND_MENU_SELECTED,
74 wxCommandEventHandler( GRID_TRICKS::onPopupSelection ), nullptr, this );
75 m_grid->Connect( wxEVT_CHAR_HOOK,
76 wxCharEventHandler( GRID_TRICKS::onCharHook ), nullptr, this );
77 m_grid->Connect( wxEVT_KEY_DOWN,
78 wxKeyEventHandler( GRID_TRICKS::onKeyDown ), nullptr, this );
79 m_grid->Connect( wxEVT_UPDATE_UI,
80 wxUpdateUIEventHandler( GRID_TRICKS::onUpdateUI ), nullptr, this );
81
82 // The handlers that control the tooltips must be on the actual grid window, not the grid
83 m_grid->GetGridWindow()->Connect( wxEVT_MOTION,
84 wxMouseEventHandler( GRID_TRICKS::onGridMotion ), nullptr,
85 this );
86}
void onGridMotion(wxMouseEvent &event)
void onGridLabelLeftClick(wxGridEvent &event)
void onKeyDown(wxKeyEvent &event)
void onPopupSelection(wxCommandEvent &event)
void onUpdateUI(wxUpdateUIEvent &event)
void onGridCellRightClick(wxGridEvent &event)
void onGridCellLeftDClick(wxGridEvent &event)
void onGridCellLeftClick(wxGridEvent &event)
void onCharHook(wxKeyEvent &event)
void onGridLabelRightClick(wxGridEvent &event)
@ GRIDTRICKS_FIRST_ID
Definition: grid_tricks.h:41
@ GRIDTRICKS_LAST_ID
Definition: grid_tricks.h:53

References GRIDTRICKS_FIRST_ID, GRIDTRICKS_LAST_ID, 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, GRID_TRICKS::onCharHook(), GRID_TRICKS::onGridCellLeftClick(), GRID_TRICKS::onGridCellLeftDClick(), GRID_TRICKS::onGridCellRightClick(), GRID_TRICKS::onGridLabelLeftClick(), GRID_TRICKS::onGridLabelRightClick(), GRID_TRICKS::onGridMotion(), GRID_TRICKS::onKeyDown(), GRID_TRICKS::onPopupSelection(), and GRID_TRICKS::onUpdateUI().

Referenced by GRID_TRICKS::GRID_TRICKS().

◆ onCharHook()

void GRID_TRICKS::onCharHook ( wxKeyEvent &  event)
protectedinherited

Definition at line 417 of file grid_tricks.cpp.

418{
419 bool handled = false;
420
421 if( ev.GetKeyCode() == WXK_RETURN && m_grid->GetGridCursorRow() == m_grid->GetNumberRows() - 1 )
422 {
424 {
425 wxCommandEvent dummy;
427 }
428 }
429 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'V' )
430 {
431 if( m_grid->IsCellEditControlShown() && wxTheClipboard->Open() )
432 {
433 if( wxTheClipboard->IsSupported( wxDF_TEXT )
434 || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
435 {
436 wxTextDataObject data;
437 wxTheClipboard->GetData( data );
438
439 if( data.GetText().Contains( COL_SEP ) || data.GetText().Contains( ROW_SEP ) )
440 {
441 m_grid->CommitPendingChanges( true /* quiet mode */ );
442 paste_text( data.GetText() );
443 handled = true;
444 }
445 }
446
447 wxTheClipboard->Close();
448 m_grid->ForceRefresh();
449 }
450 }
451
452 if( !handled )
453 ev.Skip( true );
454}
virtual void paste_text(const wxString &cb_text)
std::function< void(wxCommandEvent &)> m_addHandler
Definition: grid_tricks.h:130
bool CommitPendingChanges(bool aQuietMode=false)
Close any open cell edit controls.
Definition: wx_grid.cpp:280
static LIB_SYMBOL * dummy()
Used to draw a dummy shape when a LIB_SYMBOL is not found in library.
Definition: sch_symbol.cpp:74

References COL_SEP, WX_GRID::CommitPendingChanges(), dummy(), GRID_TRICKS::m_addHandler, GRID_TRICKS::m_grid, GRID_TRICKS::paste_text(), and ROW_SEP.

Referenced by GRID_TRICKS::init().

◆ onGridCellLeftClick()

void GRID_TRICKS::onGridCellLeftClick ( wxGridEvent &  event)
protectedinherited

Definition at line 168 of file grid_tricks.cpp.

169{
170 int row = aEvent.GetRow();
171 int col = aEvent.GetCol();
172
173 // Don't make users click twice to toggle a checkbox or edit a text cell
174 if( !aEvent.GetModifiers() )
175 {
176 bool toggled = false;
177
178 if( toggleCell( row, col, true ) )
179 toggled = true;
180 else if( showEditor( row, col ) )
181 return;
182
183 // Apply checkbox changes to multi-selection.
184 // Non-checkbox changes handled elsewhere
185 if( toggled )
186 {
188
189 // We only want to apply this to whole rows. If the grid allows selecting individual
190 // cells, and the selection contains dijoint cells, skip this logic.
191 if( !m_grid->GetSelectedCells().IsEmpty() || m_sel_row_count < 2 )
192 {
193 // We preserved the selection in toggleCell above; so clear it now that we know
194 // we aren't doing a multi-select edit
195 m_grid->ClearSelection();
196 return;
197 }
198
199 wxString newVal = m_grid->GetCellValue( row, col );
200
201 for( int affectedRow = m_sel_row_start; affectedRow < m_sel_row_count; ++affectedRow )
202 {
203 if( affectedRow == row )
204 continue;
205
206 m_grid->SetCellValue( affectedRow, col, newVal );
207 }
208 }
209 }
210
211 aEvent.Skip();
212}
void getSelectedArea()
Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above.
bool showEditor(int aRow, int aCol)
bool toggleCell(int aRow, int aCol, bool aPreserveSelection=false)
Definition: grid_tricks.cpp:89

References GRID_TRICKS::getSelectedArea(), GRID_TRICKS::m_grid, GRID_TRICKS::m_sel_row_count, GRID_TRICKS::m_sel_row_start, GRID_TRICKS::showEditor(), and GRID_TRICKS::toggleCell().

Referenced by GRID_TRICKS::init(), and GRID_TRICKS::onGridCellLeftDClick().

◆ onGridCellLeftDClick()

void GRID_TRICKS::onGridCellLeftDClick ( wxGridEvent &  event)
protectedinherited

Definition at line 215 of file grid_tricks.cpp.

216{
217 if( !handleDoubleClick( aEvent ) )
218 onGridCellLeftClick( aEvent );
219}
virtual bool handleDoubleClick(wxGridEvent &aEvent)

References GRID_TRICKS::handleDoubleClick(), and GRID_TRICKS::onGridCellLeftClick().

Referenced by GRID_TRICKS::init().

◆ onGridCellRightClick()

void GRID_TRICKS::onGridCellRightClick ( wxGridEvent &  event)
protectedinherited

Definition at line 292 of file grid_tricks.cpp.

293{
294 wxMenu menu;
295
296 showPopupMenu( menu );
297}
virtual void showPopupMenu(wxMenu &menu)

References GRID_TRICKS::showPopupMenu().

Referenced by GRID_TRICKS::init().

◆ onGridLabelLeftClick()

void GRID_TRICKS::onGridLabelLeftClick ( wxGridEvent &  event)
protectedinherited

Definition at line 300 of file grid_tricks.cpp.

301{
303
304 aEvent.Skip();
305}

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

Referenced by GRID_TRICKS::init().

◆ onGridLabelRightClick()

void GRID_TRICKS::onGridLabelRightClick ( wxGridEvent &  event)
protectedinherited

Definition at line 308 of file grid_tricks.cpp.

309{
310 wxMenu menu;
311
312 for( int i = 0; i < m_grid->GetNumberCols(); ++i )
313 {
314 int id = GRIDTRICKS_FIRST_SHOWHIDE + i;
315 menu.AppendCheckItem( id, m_grid->GetColLabelValue( i ) );
316 menu.Check( id, m_grid->IsColShown( i ) );
317 }
318
319 m_grid->PopupMenu( &menu );
320}
@ GRIDTRICKS_FIRST_SHOWHIDE
Definition: grid_tricks.h:51

References GRIDTRICKS_FIRST_SHOWHIDE, and GRID_TRICKS::m_grid.

Referenced by GRID_TRICKS::init().

◆ onGridMotion()

void GRID_TRICKS::onGridMotion ( wxMouseEvent &  event)
protectedinherited

Definition at line 222 of file grid_tricks.cpp.

223{
224 // Always skip the event
225 aEvent.Skip();
226
227 wxPoint pt = aEvent.GetPosition();
228 wxPoint pos = m_grid->CalcScrolledPosition( wxPoint( pt.x, pt.y ) );
229
230 int col = m_grid->XToCol( pos.x );
231 int row = m_grid->YToRow( pos.y );
232
233 // Empty tooltip if the cell doesn't exist or the column doesn't have tooltips
234 if( ( col == wxNOT_FOUND ) || ( row == wxNOT_FOUND ) || !m_tooltipEnabled[col] )
235 {
236 m_grid->GetGridWindow()->SetToolTip( "" );
237 return;
238 }
239
240 // Set the tooltip to the string contained in the cell
241 m_grid->GetGridWindow()->SetToolTip( m_grid->GetCellValue( row, col ) );
242}

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

Referenced by GRID_TRICKS::init().

◆ onKeyDown()

void GRID_TRICKS::onKeyDown ( wxKeyEvent &  event)
protectedinherited

Definition at line 457 of file grid_tricks.cpp.

458{
459 if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'A' )
460 {
461 m_grid->SelectAll();
462 return;
463 }
464 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'C' )
465 {
467 cutcopy( true, false );
468 return;
469 }
470 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'V' )
471 {
474 return;
475 }
476 else if( ev.GetModifiers() == wxMOD_CONTROL && ev.GetKeyCode() == 'X' )
477 {
479 cutcopy( true, true );
480 return;
481 }
482 else if( !ev.GetModifiers() && ev.GetKeyCode() == WXK_DELETE )
483 {
485 cutcopy( false, true );
486 return;
487 }
488
489 // space-bar toggling of checkboxes
490 if( m_grid->IsEditable() && ev.GetKeyCode() == ' ' )
491 {
492 bool retVal = false;
493
494 // If only rows can be selected, only toggle the first cell in a row
495 if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
496 {
497 wxArrayInt rowSel = m_grid->GetSelectedRows();
498
499 for( unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
500 {
501 retVal |= toggleCell( rowSel[rowInd], 0, true );
502 }
503 }
504
505 // If only columns can be selected, only toggle the first cell in a column
506 else if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectColumns )
507 {
508 wxArrayInt colSel = m_grid->GetSelectedCols();
509
510 for( unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
511 {
512 retVal |= toggleCell( 0, colSel[colInd], true );
513 }
514 }
515
516 // If the user can select the individual cells, toggle each cell selected
517 else if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectCells )
518 {
519 wxArrayInt rowSel = m_grid->GetSelectedRows();
520 wxArrayInt colSel = m_grid->GetSelectedCols();
521 wxGridCellCoordsArray cellSel = m_grid->GetSelectedCells();
522 wxGridCellCoordsArray topLeft = m_grid->GetSelectionBlockTopLeft();
523 wxGridCellCoordsArray botRight = m_grid->GetSelectionBlockBottomRight();
524
525 // Iterate over every individually selected cell and try to toggle it
526 for( unsigned int cellInd = 0; cellInd < cellSel.GetCount(); cellInd++ )
527 {
528 retVal |= toggleCell( cellSel[cellInd].GetRow(), cellSel[cellInd].GetCol(), true );
529 }
530
531 // Iterate over every column and try to toggle each cell in it
532 for( unsigned int colInd = 0; colInd < colSel.GetCount(); colInd++ )
533 {
534 for( int row = 0; row < m_grid->GetNumberRows(); row++ )
535 {
536 retVal |= toggleCell( row, colSel[colInd], true );
537 }
538 }
539
540 // Iterate over every row and try to toggle each cell in it
541 for( unsigned int rowInd = 0; rowInd < rowSel.GetCount(); rowInd++ )
542 {
543 for( int col = 0; col < m_grid->GetNumberCols(); col++ )
544 {
545 retVal |= toggleCell( rowSel[rowInd], col, true );
546 }
547 }
548
549 // Iterate over the selection blocks
550 for( unsigned int blockInd = 0; blockInd < topLeft.GetCount(); blockInd++ )
551 {
552 wxGridCellCoords start = topLeft[blockInd];
553 wxGridCellCoords end = botRight[blockInd];
554
555 for( int row = start.GetRow(); row <= end.GetRow(); row++ )
556 {
557 for( int col = start.GetCol(); col <= end.GetCol(); col++ )
558 {
559 retVal |= toggleCell( row, col, true );
560 }
561 }
562 }
563 }
564
565 // Return if there were any cells toggled
566 if( retVal )
567 return;
568 }
569
570 // ctrl-tab for exit grid
571#ifdef __APPLE__
572 bool ctrl = ev.RawControlDown();
573#else
574 bool ctrl = ev.ControlDown();
575#endif
576
577 if( ctrl && ev.GetKeyCode() == WXK_TAB )
578 {
579 wxWindow* test = m_grid->GetNextSibling();
580
581 if( !test )
582 test = m_grid->GetParent()->GetNextSibling();
583
584 while( test && !test->IsTopLevel() )
585 {
586 test->SetFocus();
587
588 if( test->HasFocus() )
589 break;
590
591 if( !test->GetChildren().empty() )
592 {
593 test = test->GetChildren().front();
594 }
595 else if( test->GetNextSibling() )
596 {
597 test = test->GetNextSibling();
598 }
599 else
600 {
601 while( test )
602 {
603 test = test->GetParent();
604
605 if( test && test->IsTopLevel() )
606 {
607 break;
608 }
609 else if( test && test->GetNextSibling() )
610 {
611 test = test->GetNextSibling();
612 break;
613 }
614 }
615 }
616 }
617
618 return;
619 }
620
621 ev.Skip( true );
622}
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::init().

◆ onPopupSelection()

void GRID_TRICKS::onPopupSelection ( wxCommandEvent &  event)
protectedinherited

Definition at line 368 of file grid_tricks.cpp.

369{
370 doPopupSelection( event );
371}

References GRID_TRICKS::doPopupSelection().

Referenced by GRID_TRICKS::init().

◆ onUpdateUI()

void GRID_TRICKS::onUpdateUI ( wxUpdateUIEvent &  event)
protectedinherited

Definition at line 790 of file grid_tricks.cpp.

791{
792 // Respect ROW selectionMode when moving cursor
793
794 if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
795 {
796 int cursorRow = m_grid->GetGridCursorRow();
797 bool cursorInSelectedRow = false;
798
799 for( int row : m_grid->GetSelectedRows() )
800 {
801 if( row == cursorRow )
802 {
803 cursorInSelectedRow = true;
804 break;
805 }
806 }
807
808 if( !cursorInSelectedRow && cursorRow >= 0 )
809 m_grid->SelectRow( cursorRow );
810 }
811}

References GRID_TRICKS::m_grid.

Referenced by GRID_TRICKS::init().

◆ paste_clipboard()

void GRID_TRICKS::paste_clipboard ( )
protectedvirtualinherited

Definition at line 625 of file grid_tricks.cpp.

626{
627 wxLogNull doNotLog; // disable logging of failed clipboard actions
628
629 if( m_grid->IsEditable() && wxTheClipboard->Open() )
630 {
631 if( wxTheClipboard->IsSupported( wxDF_TEXT )
632 || wxTheClipboard->IsSupported( wxDF_UNICODETEXT ) )
633 {
634 wxTextDataObject data;
635
636 wxTheClipboard->GetData( data );
637
638 paste_text( data.GetText() );
639 }
640
641 wxTheClipboard->Close();
642 m_grid->ForceRefresh();
643 }
644}

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

151 {
153 size_t ndx = cb_text.find( "(sym_lib_table" );
154
155 if( ndx != std::string::npos )
156 {
157 // paste the SYMBOL_LIB_TABLE_ROWs of s-expression (sym_lib_table), starting
158 // at column 0 regardless of current cursor column.
159
160 STRING_LINE_READER slr( TO_UTF8( cb_text ), "Clipboard" );
161 LIB_TABLE_LEXER lexer( &slr );
162 SYMBOL_LIB_TABLE tmp_tbl;
163 bool parsed = true;
164
165 try
166 {
167 tmp_tbl.Parse( &lexer );
168 }
169 catch( PARSE_ERROR& pe )
170 {
171 DisplayError( m_dialog, pe.What() );
172 parsed = false;
173 }
174
175 if( parsed )
176 {
177 // make sure the table is big enough...
178 if( tmp_tbl.GetCount() > (unsigned) tbl->GetNumberRows() )
179 tbl->AppendRows( tmp_tbl.GetCount() - tbl->GetNumberRows() );
180
181 for( unsigned i = 0; i < tmp_tbl.GetCount(); ++i )
182 tbl->rows.replace( i, tmp_tbl.At( i ).clone() );
183 }
184
185 m_grid->AutoSizeColumns( false );
186 }
187 else
188 {
189 // paste spreadsheet formatted text.
190 GRID_TRICKS::paste_text( cb_text );
191
192 m_grid->AutoSizeColumns( false );
193 }
194 }
virtual const wxString What() const
A composite of Problem() and Where()
Definition: exceptions.cpp:30
bool AppendRows(size_t aNumRows=1) override
int GetNumberRows() override
LIB_TABLE_ROW * clone() const
LIB_TABLE_ROW & At(unsigned aIndex)
Get the 'n'th LIB_TABLE_ROW object.
LIB_TABLE_ROWS rows
unsigned GetCount() const
Get the number of rows contained in the table.
Is a LINE_READER that reads from a multiline 8 bit wide std::string.
Definition: richio.h:241
Build a wxGridTableBase by wrapping an SYMBOL_LIB_TABLE 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...
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280
#define TO_UTF8(wxstring)
Convert a wxString to a UTF8 encoded C string for all wxWidgets build modes.
Definition: macros.h:96
A filename or source description, a problem input line, a line number, a byte offset,...
Definition: ki_exception.h:119

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

◆ 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 75 of file grid_tricks.h.

76 {
77 m_tooltipEnabled[aCol] = aEnable;
78 }

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

134{
135 if( m_grid->GetGridCursorRow() != aRow || m_grid->GetGridCursorCol() != aCol )
136 m_grid->SetGridCursor( aRow, aCol );
137
138 if( m_grid->IsEditable() && !m_grid->IsReadOnly( aRow, aCol ) )
139 {
140 m_grid->ClearSelection();
141
142 if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
143 {
144 wxArrayInt rows = m_grid->GetSelectedRows();
145
146 if( rows.size() != 1 || rows.Item( 0 ) != aRow )
147 m_grid->SelectRow( aRow );
148 }
149
150 // For several reasons we can't enable the control here. There's the whole
151 // SetInSetFocus() issue/hack in wxWidgets, and there's also wxGrid's MouseUp
152 // handler which doesn't notice it's processing a MouseUp until after it has
153 // disabled the editor yet again. So we re-use wxWidgets' slow-click hack,
154 // which is processed later in the MouseUp handler.
155 //
156 // It should be pointed out that the fact that it's wxWidgets' hack doesn't
157 // make it any less of a hack. Be extra careful with any modifications here.
158 // See, in particular, https://bugs.launchpad.net/kicad/+bug/1817965.
160
161 return true;
162 }
163
164 return false;
165}
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:126

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

Referenced by GRID_TRICKS::onGridCellLeftClick().

◆ showPopupMenu()

void LIB_TABLE_GRID_TRICKS::showPopupMenu ( wxMenu &  menu)
overridevirtualinherited

Reimplemented from GRID_TRICKS.

Reimplemented in FP_GRID_TRICKS.

Definition at line 27 of file lib_table_grid_tricks.cpp.

28{
29 bool showActivate = false;
30 bool showDeactivate = false;
31 LIB_TABLE_GRID* tbl = static_cast<LIB_TABLE_GRID*>( m_grid->GetTable() );
32
33 for( int row = m_sel_row_start; row < m_sel_row_start + m_sel_row_count; ++row )
34 {
35 if( tbl->GetValueAsBool( row, 0 ) )
36 {
37 showDeactivate = true;
38 }
39 else
40 {
41 showActivate = true;
42 }
43
44 if( showActivate && showDeactivate )
45 break;
46 }
47
48 if( showActivate )
49 menu.Append( LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED, _( "Activate selected" ) );
50 if( showDeactivate )
51 menu.Append( LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED, _( "Deactivate selected" ) );
52 menu.AppendSeparator();
54}
bool GetValueAsBool(int aRow, int aCol) override
#define _(s)

References _, LIB_TABLE_GRID::GetValueAsBool(), LIB_TABLE_GRID_TRICKS::LIB_TABLE_GRID_TRICKS_ACTIVATE_SELECTED, LIB_TABLE_GRID_TRICKS::LIB_TABLE_GRID_TRICKS_DEACTIVATE_SELECTED, GRID_TRICKS::m_grid, GRID_TRICKS::m_sel_row_count, GRID_TRICKS::m_sel_row_start, and GRID_TRICKS::showPopupMenu().

Referenced by FP_GRID_TRICKS::showPopupMenu().

◆ toggleCell()

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

Definition at line 89 of file grid_tricks.cpp.

90{
91 wxGridCellRenderer* renderer = m_grid->GetCellRenderer( aRow, aCol );
92 bool isCheckbox = ( dynamic_cast<wxGridCellBoolRenderer*>( renderer ) );
93 renderer->DecRef();
94
95 if( isCheckbox )
96 {
97 if( !aPreserveSelection )
98 {
99 m_grid->ClearSelection();
100 m_grid->SetGridCursor( aRow, aCol );
101 }
102
103 wxGridTableBase* model = m_grid->GetTable();
104
105 if( model->CanGetValueAs( aRow, aCol, wxGRID_VALUE_BOOL )
106 && model->CanSetValueAs( aRow, aCol, wxGRID_VALUE_BOOL ) )
107 {
108 model->SetValueAsBool( aRow, aCol, !model->GetValueAsBool( aRow, aCol ) );
109 }
110 else // fall back to string processing
111 {
112 if( model->GetValue( aRow, aCol ) == wxT( "1" ) )
113 model->SetValue( aRow, aCol, wxT( "0" ) );
114 else
115 model->SetValue( aRow, aCol, wxT( "1" ) );
116 }
117
118 // Mac needs this for the keyboard events; Linux appears to always need it.
119 m_grid->ForceRefresh();
120
121 // Let any clients know
122 wxGridEvent event( m_grid->GetId(), wxEVT_GRID_CELL_CHANGED, m_grid, aRow, aCol );
123 event.SetString( model->GetValue( aRow, aCol ) );
124 m_grid->GetEventHandler()->ProcessEvent( event );
125
126 return true;
127 }
128
129 return false;
130}

References GRID_TRICKS::m_grid.

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

Member Data Documentation

◆ m_addHandler

std::function<void( wxCommandEvent& )> GRID_TRICKS::m_addHandler
protectedinherited

Definition at line 130 of file grid_tricks.h.

Referenced by GRID_TRICKS::onCharHook().

◆ m_dialog

DIALOG_EDIT_LIBRARY_TABLES* SYMBOL_GRID_TRICKS::m_dialog
protected

Definition at line 146 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

◆ m_sel_row_start

◆ m_tooltipEnabled

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

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