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 (C) 2012-2022 KiCad Developers, see change_log.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, you may find one here:
19 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
20 * or you may search the http://www.gnu.org website for the version 2 license,
21 * or you may write to the Free Software Foundation, Inc.,
22 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
23 */
24
25#ifndef _GRID_TRICKS_H_
26#define _GRID_TRICKS_H_
27
28
29#include <bitset>
30#include <functional>
31
32#include <wx/grid.h>
33#include <wx/event.h>
34#include <wx/menu.h>
35#include <widgets/wx_grid.h>
36
37#define GRIDTRICKS_MAX_COL 50
38
39enum
40{
47
48 GRIDTRICKS_FIRST_CLIENT_ID = 1101, // reserve IDs for sub-classes
50
51 GRIDTRICKS_FIRST_SHOWHIDE, // reserve IDs for show/hide-column-n
52
54};
55
56
60class 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
75 void SetTooltipEnable( int aCol, bool aEnable = true )
76 {
77 m_tooltipEnabled[aCol] = aEnable;
78 }
79
86 bool GetTooltipEnabled( int aCol )
87 {
88 return m_tooltipEnabled[aCol];
89 }
90
91protected:
93 void init();
94
96 void getSelectedArea();
97
98 void onGridCellLeftClick( wxGridEvent& event );
99 void onGridCellLeftDClick( wxGridEvent& event );
100 void onGridCellRightClick( wxGridEvent& event );
101 void onGridLabelLeftClick( wxGridEvent& event );
102 void onGridLabelRightClick( wxGridEvent& event );
103 void onPopupSelection( wxCommandEvent& event );
104 void onKeyDown( wxKeyEvent& event );
105 void onCharHook( wxKeyEvent& event );
106 void onUpdateUI( wxUpdateUIEvent& event );
107 void onGridMotion( wxMouseEvent& event );
108
109 virtual bool handleDoubleClick( wxGridEvent& aEvent );
110 virtual void showPopupMenu( wxMenu& menu, wxGridEvent& aEvent );
111 virtual void doPopupSelection( wxCommandEvent& event );
112
113 bool isTextEntry( int aRow, int aCol );
114 bool isCheckbox( int aRow, int aCol );
115 bool isReadOnly( int aRow, int aCol );
116
117 virtual bool toggleCell( int aRow, int aCol, bool aPreserveSelection = false );
118 bool showEditor( int aRow, int aCol );
119
120 virtual void paste_clipboard();
121 virtual void paste_text( const wxString& cb_text );
122 virtual void cutcopy( bool doCopy, bool doDelete );
123
124protected:
126
127 // row & col "selection" acquisition
128 // selected area by cell coordinate and count
133
134 std::function<void( wxCommandEvent& )> m_addHandler;
135
136 std::bitset<GRIDTRICKS_MAX_COL> m_tooltipEnabled;
137};
138
139#endif // _GRID_TRICKS_H_
Add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
Definition: grid_tricks.h:61
bool isReadOnly(int aRow, int aCol)
void onGridMotion(wxMouseEvent &event)
void onGridLabelLeftClick(wxGridEvent &event)
virtual void paste_text(const wxString &cb_text)
void init()
Shared initialization for various ctors.
Definition: grid_tricks.cpp:58
void getSelectedArea()
Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above.
void onKeyDown(wxKeyEvent &event)
void onPopupSelection(wxCommandEvent &event)
virtual void cutcopy(bool doCopy, bool doDelete)
virtual void doPopupSelection(wxCommandEvent &event)
bool isCheckbox(int aRow, int aCol)
bool GetTooltipEnabled(int aCol)
Query if the tooltip for a column is enabled.
Definition: grid_tricks.h:86
std::function< void(wxCommandEvent &)> m_addHandler
Definition: grid_tricks.h:134
virtual void showPopupMenu(wxMenu &menu, wxGridEvent &aEvent)
int m_sel_row_start
Definition: grid_tricks.h:129
std::bitset< GRIDTRICKS_MAX_COL > m_tooltipEnabled
Definition: grid_tricks.h:136
void onUpdateUI(wxUpdateUIEvent &event)
void onGridCellRightClick(wxGridEvent &event)
WX_GRID * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:125
int m_sel_row_count
Definition: grid_tricks.h:131
bool isTextEntry(int aRow, int aCol)
Definition: grid_tricks.cpp:91
void onGridCellLeftDClick(wxGridEvent &event)
void SetTooltipEnable(int aCol, bool aEnable=true)
Enable the tooltip for a column.
Definition: grid_tricks.h:75
void onGridCellLeftClick(wxGridEvent &event)
virtual bool handleDoubleClick(wxGridEvent &aEvent)
int m_sel_col_count
Definition: grid_tricks.h:132
void onCharHook(wxKeyEvent &event)
virtual void paste_clipboard()
bool showEditor(int aRow, int aCol)
int m_sel_col_start
Definition: grid_tricks.h:130
void onGridLabelRightClick(wxGridEvent &event)
virtual bool toggleCell(int aRow, int aCol, bool aPreserveSelection=false)
@ GRIDTRICKS_ID_PASTE
Definition: grid_tricks.h:45
@ GRIDTRICKS_FIRST_ID
Definition: grid_tricks.h:41
@ GRID_TRICKS_LAST_CLIENT_ID
Definition: grid_tricks.h:49
@ GRIDTRICKS_FIRST_SHOWHIDE
Definition: grid_tricks.h:51
@ GRIDTRICKS_ID_SELECT
Definition: grid_tricks.h:46
@ GRIDTRICKS_ID_CUT
Definition: grid_tricks.h:42
@ GRIDTRICKS_LAST_ID
Definition: grid_tricks.h:53
@ GRIDTRICKS_ID_COPY
Definition: grid_tricks.h:43
@ GRIDTRICKS_ID_DELETE
Definition: grid_tricks.h:44
@ GRIDTRICKS_FIRST_CLIENT_ID
Definition: grid_tricks.h:48
#define GRIDTRICKS_MAX_COL
Definition: grid_tricks.h:37