KiCad PCB EDA Suite
Loading...
Searching...
No Matches
grid_tricks.h
Go to the documentation of this file.
1/*
2 * This program source code file is part of KiCad, a free EDA CAD application.
3 *
4 * Copyright (C) 2012 SoftPLC Corporation, Dick Hollenbeck <[email protected]>
5 * Copyright The KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
21#ifndef _GRID_TRICKS_H_
22#define _GRID_TRICKS_H_
23
24#include <kicommon.h>
25#include <bitset>
26#include <functional>
27#include <utility>
28#include <vector>
29
30#include <wx/grid.h>
31#include <wx/event.h>
32#include <wx/menu.h>
33#include <widgets/wx_grid.h>
34
35#define GRIDTRICKS_MAX_COL 50
36
37enum
38{
45
46 GRIDTRICKS_FIRST_CLIENT_ID = 1101, // reserve IDs for sub-classes
48
49 GRIDTRICKS_FIRST_SHOWHIDE, // reserve IDs for show/hide-column-n
50
52};
53
54
55class wxComboCtrl;
56
60class KICOMMON_API GRID_TRICKS : public wxEvtHandler
61{
62public:
63 explicit GRID_TRICKS( WX_GRID* aGrid );
64
65 GRID_TRICKS( WX_GRID* aGrid, std::function<void( wxCommandEvent& )> aAddHandler );
66
72 void EnableColumnBulkEdit( bool aEnable = true )
73 {
75 m_grid->SetUseNativeSelection( aEnable );
76 }
77
86 void SetTooltipEnable( int aCol, bool aEnable = true )
87 {
88 m_tooltipEnabled[aCol] = aEnable;
89 }
90
97 bool GetTooltipEnabled( int aCol )
98 {
99 return m_tooltipEnabled[aCol];
100 }
101
102protected:
104 friend class SCINTILLA_TRICKS;
105
107 void init();
108
110 void getSelectedArea();
111
112 virtual void onGridCellLeftClick( wxGridEvent& event );
113 void onGridCellLeftDClick( wxGridEvent& event );
114 void onGridCellRightClick( wxGridEvent& event );
115 void onGridLabelLeftClick( wxGridEvent& event );
116 void onGridLabelRightClick( wxGridEvent& event );
117 void onPopupSelection( wxCommandEvent& event );
118 void onKeyDown( wxKeyEvent& event );
119 virtual void onCharHook( wxKeyEvent& event );
120 void onUpdateUI( wxUpdateUIEvent& event );
121 void onGridMotion( wxMouseEvent& event );
122
123 void onGridCellChanging( wxGridEvent& aEvent );
124 void onGridCellChanged( wxGridEvent& aEvent );
125 void onGridEditorCreated( wxGridEditorCreatedEvent& aEvent );
126 void onGridEditorShown( wxGridEvent& aEvent );
127 void onGridEditorHidden( wxGridEvent& aEvent );
128 void onEditorInput( wxCommandEvent& aEvent );
129 void onEditorKeyDown( wxKeyEvent& aEvent );
130 void onEditorTextEnter( wxCommandEvent& aEvent );
131 void onEditorDropdownOpened( wxCommandEvent& aEvent );
132 void onEditorDropdownClosed( wxCommandEvent& aEvent );
133 void finishDropdown();
134 wxComboCtrl* shownGenericPopup( const wxKeyEvent& aEnterKey );
135 bool finishEditor( bool aCancel, bool aMoveDown = false );
136
137 virtual bool handleDoubleClick( wxGridEvent& aEvent );
138 virtual void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent );
139 virtual void appendPopupMenuItems( wxMenu& aMenu ) {}
140 virtual void doPopupSelection( wxCommandEvent& event );
141
142 bool isTextEntry( int aRow, int aCol );
143 bool isChoiceEditor( int aRow, int aCol );
144 bool isCheckbox( int aRow, int aCol );
145 bool isReadOnly( int aRow, int aCol );
146
147 virtual bool toggleCell( int aRow, int aCol, bool aPreserveSelection = false );
148 bool showEditor( int aRow, int aCol );
149
150 virtual void paste_clipboard();
151 virtual void paste_text( const wxString& cb_text );
152 virtual void cutcopy( bool doCopy, bool doDelete );
153
154protected:
156 {
157 void Begin( const wxGridCellCoords& aSource )
158 {
159 const unsigned int generation = Generation + 1;
160 *this = {};
161 Source = aSource;
162 Generation = generation;
163 }
164
165 wxGridCellCoords Source;
166 std::vector<int> Rows;
167 std::vector<wxGridBlockCoords> Selection;
168 unsigned int Generation = 0;
169 bool Commit = false;
170 bool Input = false;
171 bool TextInitialized = false;
172 bool KeyboardNavigation = false;
173 wxKeyEvent PopupKey;
174 };
175
177
178 // row & col "selection" acquisition
179 // selected area by cell coordinate and count
184
185 std::function<void( wxCommandEvent& )> m_addHandler;
186
187 std::bitset<GRIDTRICKS_MAX_COL> m_tooltipEnabled;
188
192 wxGridCellCoords m_bulkEditSource;
194 std::vector<std::pair<int, wxString>> m_bulkEditRows;
199};
200
201#endif // _GRID_TRICKS_H_
wxGridCellCoords m_bulkEditSource
void onGridMotion(wxMouseEvent &event)
void onGridLabelLeftClick(wxGridEvent &event)
void init()
Shared initialization for various ctors.
void onGridEditorShown(wxGridEvent &aEvent)
std::vector< std::pair< int, wxString > > m_bulkEditRows
void getSelectedArea()
Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above.
bool m_multiCellEditEnabled
GRID_TRICKS(WX_GRID *aGrid)
void onGridEditorHidden(wxGridEvent &aEvent)
void EnableColumnBulkEdit(bool aEnable=true)
Apply an edit to every selected cell in the edited cell's column.
Definition grid_tricks.h:72
bool m_bulkEditorClosing
bool m_bulkEditorOpening
void onKeyDown(wxKeyEvent &event)
BULK_EDIT_SESSION m_bulkEditor
void onPopupSelection(wxCommandEvent &event)
void onEditorInput(wxCommandEvent &aEvent)
void onEditorKeyDown(wxKeyEvent &aEvent)
void onGridCellChanged(wxGridEvent &aEvent)
bool m_enableSingleClickEdit
void onGridCellChanging(wxGridEvent &aEvent)
bool GetTooltipEnabled(int aCol)
Query if the tooltip for a column is enabled.
Definition grid_tricks.h:97
std::function< void(wxCommandEvent &)> m_addHandler
bool m_bulkEditorEnterHandled
void onEditorDropdownOpened(wxCommandEvent &aEvent)
virtual void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent)
int m_sel_row_start
std::bitset< GRIDTRICKS_MAX_COL > m_tooltipEnabled
wxString m_bulkEditValue
wxComboCtrl * shownGenericPopup(const wxKeyEvent &aEnterKey)
void onEditorTextEnter(wxCommandEvent &aEvent)
void onUpdateUI(wxUpdateUIEvent &event)
friend class SCINTILLA_TRICKS
Allow various conspiracies between the two tricks handlers.
void onGridCellRightClick(wxGridEvent &event)
virtual void appendPopupMenuItems(wxMenu &aMenu)
WX_GRID * m_grid
I don't own the grid, but he owns me.
int m_sel_row_count
void onGridEditorCreated(wxGridEditorCreatedEvent &aEvent)
void onGridCellLeftDClick(wxGridEvent &event)
bool m_columnBulkEditEnabled
void SetTooltipEnable(int aCol, bool aEnable=true)
Enable the tooltip for a column.
Definition grid_tricks.h:86
virtual void onGridCellLeftClick(wxGridEvent &event)
void finishDropdown()
virtual bool handleDoubleClick(wxGridEvent &aEvent)
int m_sel_col_count
virtual void onCharHook(wxKeyEvent &event)
void onEditorDropdownClosed(wxCommandEvent &aEvent)
bool finishEditor(bool aCancel, bool aMoveDown=false)
int m_sel_col_start
void onGridLabelRightClick(wxGridEvent &event)
#define GRIDTRICKS_MAX_COL
Definition grid_tricks.h:35
@ GRIDTRICKS_ID_PASTE
Definition grid_tricks.h:43
@ GRIDTRICKS_FIRST_ID
Definition grid_tricks.h:39
@ GRID_TRICKS_LAST_CLIENT_ID
Definition grid_tricks.h:47
@ GRIDTRICKS_FIRST_SHOWHIDE
Definition grid_tricks.h:49
@ GRIDTRICKS_ID_SELECT
Definition grid_tricks.h:44
@ GRIDTRICKS_ID_CUT
Definition grid_tricks.h:40
@ GRIDTRICKS_LAST_ID
Definition grid_tricks.h:51
@ GRIDTRICKS_ID_COPY
Definition grid_tricks.h:41
@ GRIDTRICKS_ID_DELETE
Definition grid_tricks.h:42
@ GRIDTRICKS_FIRST_CLIENT_ID
Definition grid_tricks.h:46
#define KICOMMON_API
Definition kicommon.h:27
std::vector< wxGridBlockCoords > Selection
void Begin(const wxGridCellCoords &aSource)