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

Public Member Functions

 FIELDS_EDITOR_GRID_TRICKS (DIALOG_SHIM *aParent, WX_GRID *aGrid, wxDataViewListCtrl *aFieldsCtrl)
 
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

void showPopupMenu (wxMenu &menu) override
 
void doPopupSelection (wxCommandEvent &event) override
 
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 paste_text (const wxString &cb_text)
 
virtual void cutcopy (bool doCopy, bool doDelete)
 

Protected Attributes

DIALOG_SHIMm_dlg
 
wxDataViewListCtrl * m_fieldsCtrl
 
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
 

Detailed Description

Definition at line 71 of file dialog_symbol_fields_table.cpp.

Constructor & Destructor Documentation

◆ FIELDS_EDITOR_GRID_TRICKS()

FIELDS_EDITOR_GRID_TRICKS::FIELDS_EDITOR_GRID_TRICKS ( DIALOG_SHIM aParent,
WX_GRID aGrid,
wxDataViewListCtrl *  aFieldsCtrl 
)
inline

Definition at line 74 of file dialog_symbol_fields_table.cpp.

75 :
76 GRID_TRICKS( aGrid ),
77 m_dlg( aParent ),
78 m_fieldsCtrl( aFieldsCtrl )
79 {}
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 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 FIELDS_EDITOR_GRID_TRICKS::doPopupSelection ( wxCommandEvent &  event)
inlineoverrideprotectedvirtual

Reimplemented from GRID_TRICKS.

Definition at line 100 of file dialog_symbol_fields_table.cpp.

101 {
102 if( event.GetId() == MYID_SELECT_FOOTPRINT )
103 {
104 // pick a footprint using the footprint picker.
105 wxString fpid = m_grid->GetCellValue( m_grid->GetGridCursorRow(),
108 m_dlg );
109
110 if( frame->ShowModal( &fpid, m_dlg ) )
111 m_grid->SetCellValue( m_grid->GetGridCursorRow(), FOOTPRINT_FIELD, fpid );
112
113 frame->Destroy();
114 }
115 else if (event.GetId() == MYID_SHOW_DATASHEET )
116 {
117 wxString datasheet_uri = m_grid->GetCellValue( m_grid->GetGridCursorRow(),
119 GetAssociatedDocument( m_dlg, datasheet_uri, &m_dlg->Prj(), m_dlg->Prj().SchSearchS() );
120 }
121 else
122 {
124 }
125
126 if( event.GetId() >= GRIDTRICKS_FIRST_SHOWHIDE && event.GetId() < GRIDTRICKS_LAST_ID )
127 {
128 if( !m_grid->IsColShown( REFERENCE_FIELD ) )
129 {
130 DisplayError( m_dlg, _( "The Reference column cannot be hidden." ) );
131
132 m_grid->ShowCol( REFERENCE_FIELD );
133 }
134
135 // Refresh Show checkboxes from grid columns
136 for( int i = 0; i < m_fieldsCtrl->GetItemCount(); ++i )
137 m_fieldsCtrl->SetToggleValue( m_grid->IsColShown( i ), i, 1 );
138 }
139 }
virtual void doPopupSelection(wxCommandEvent &event)
PROJECT & Prj() const
Return a reference to the PROJECT associated with this KIWAY.
KIWAY & Kiway() const
Return a reference to the KIWAY that this object has an opportunity to participate in.
Definition: kiway_holder.h:53
A wxFrame capable of the OpenProjectFiles function, meaning it can load a portion of a KiCad project.
Definition: kiway_player.h:66
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 Destroy() override
Our version of Destroy() which is virtual from wxWidgets.
virtual KIWAY_PLAYER * Player(FRAME_T aFrameType, bool doCreate=true, wxTopLevelWindow *aParent=nullptr)
Return the KIWAY_PLAYER* given a FRAME_T.
Definition: kiway.cpp:394
void DisplayError(wxWindow *aParent, const wxString &aText, int aDisplayTime)
Display an error or warning message box with aMessage.
Definition: confirm.cpp:280
#define _(s)
bool GetAssociatedDocument(wxWindow *aParent, const wxString &aDocName, PROJECT *aProject, SEARCH_STACK *aPaths)
Open a document (file) with the suitable browser.
Definition: eda_doc.cpp:74
@ FRAME_FOOTPRINT_VIEWER_MODAL
Definition: frame_type.h:43
@ GRIDTRICKS_FIRST_SHOWHIDE
Definition: grid_tricks.h:51
@ GRIDTRICKS_LAST_ID
Definition: grid_tricks.h:53
@ DATASHEET_FIELD
name of datasheet
@ FOOTPRINT_FIELD
Field Name Module PCB, i.e. "16DIP300".
@ REFERENCE_FIELD
Field Reference of part, i.e. "IC21".

References _, DATASHEET_FIELD, KIWAY_PLAYER::Destroy(), DisplayError(), GRID_TRICKS::doPopupSelection(), FOOTPRINT_FIELD, FRAME_FOOTPRINT_VIEWER_MODAL, GetAssociatedDocument(), GRIDTRICKS_FIRST_SHOWHIDE, GRIDTRICKS_LAST_ID, KIWAY_HOLDER::Kiway(), m_dlg, m_fieldsCtrl, GRID_TRICKS::m_grid, MYID_SELECT_FOOTPRINT, MYID_SHOW_DATASHEET, KIWAY::Player(), KIWAY_HOLDER::Prj(), REFERENCE_FIELD, 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 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

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}

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

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

Reimplemented in SYMBOL_GRID_TRICKS, and FP_GRID_TRICKS.

Definition at line 647 of file grid_tricks.cpp.

648{
649 wxGridTableBase* tbl = m_grid->GetTable();
650
651 const int cur_row = m_grid->GetGridCursorRow();
652 const int cur_col = m_grid->GetGridCursorCol();
653 int start_row;
654 int end_row;
655 int start_col;
656 int end_col;
657 bool is_selection = false;
658
659 if( cur_row < 0 || cur_col < 0 )
660 {
661 wxBell();
662 return;
663 }
664
665 if( m_grid->GetSelectionMode() == wxGrid::wxGridSelectRows )
666 {
667 if( m_sel_row_count > 1 )
668 is_selection = true;
669 }
670 else
671 {
672 if( m_grid->IsSelection() )
673 is_selection = true;
674 }
675
676 wxStringTokenizer rows( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
677
678 // If selection of cells is present
679 // then a clipboard pastes to selected cells only.
680 if( is_selection )
681 {
682 start_row = m_sel_row_start;
684 start_col = m_sel_col_start;
686 }
687 // Otherwise, paste whole clipboard
688 // starting from cell with cursor.
689 else
690 {
691 start_row = cur_row;
692 end_row = cur_row + rows.CountTokens();
693
694 if( end_row > tbl->GetNumberRows() )
695 end_row = tbl->GetNumberRows();
696
697 start_col = cur_col;
698 end_col = start_col; // end_col actual value calculates later
699 }
700
701 for( int row = start_row; row < end_row; ++row )
702 {
703 // If number of selected rows is larger than the count of rows on the clipboard, paste
704 // again and again until the end of the selection is reached.
705 if( !rows.HasMoreTokens() )
706 rows.SetString( cb_text, ROW_SEP, wxTOKEN_RET_EMPTY );
707
708 wxString rowTxt = rows.GetNextToken();
709
710 wxStringTokenizer cols( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
711
712 if( !is_selection )
713 {
714 end_col = cur_col + cols.CountTokens();
715
716 if( end_col > tbl->GetNumberCols() )
717 end_col = tbl->GetNumberCols();
718 }
719
720 for( int col = start_col; col < end_col; ++col )
721 {
722 // Skip hidden columns
723 if( !m_grid->IsColShown( col ) )
724 continue;
725
726 // If number of selected cols is larger than the count of cols on the clipboard,
727 // paste again and again until the end of the selection is reached.
728 if( !cols.HasMoreTokens() )
729 cols.SetString( rowTxt, COL_SEP, wxTOKEN_RET_EMPTY );
730
731 wxString cellTxt = cols.GetNextToken();
732
733 if( tbl->CanSetValueAs( row, col, wxGRID_VALUE_STRING ) )
734 {
735 tbl->SetValue( row, col, cellTxt );
736
737 wxGridEvent evt( m_grid->GetId(), wxEVT_GRID_CELL_CHANGED, m_grid, row, col );
738 m_grid->GetEventHandler()->ProcessEvent( evt );
739 }
740 }
741 }
742}

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::onCharHook(), 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 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 FIELDS_EDITOR_GRID_TRICKS::showPopupMenu ( wxMenu &  menu)
inlineoverrideprotectedvirtual

Reimplemented from GRID_TRICKS.

Definition at line 82 of file dialog_symbol_fields_table.cpp.

83 {
84 if( m_grid->GetGridCursorCol() == FOOTPRINT_FIELD )
85 {
86 menu.Append( MYID_SELECT_FOOTPRINT, _( "Select Footprint..." ),
87 _( "Browse for footprint" ) );
88 menu.AppendSeparator();
89 }
90 else if( m_grid->GetGridCursorCol() == DATASHEET_FIELD )
91 {
92 menu.Append( MYID_SHOW_DATASHEET, _( "Show Datasheet" ),
93 _( "Show datasheet in browser" ) );
94 menu.AppendSeparator();
95 }
96
98 }

References _, DATASHEET_FIELD, 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 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_dlg

DIALOG_SHIM* FIELDS_EDITOR_GRID_TRICKS::m_dlg
protected

Definition at line 141 of file dialog_symbol_fields_table.cpp.

Referenced by doPopupSelection().

◆ m_fieldsCtrl

wxDataViewListCtrl* FIELDS_EDITOR_GRID_TRICKS::m_fieldsCtrl
protected

Definition at line 142 of file dialog_symbol_fields_table.cpp.

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

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