KiCad PCB EDA Suite
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 <dick@softplc.com>
5  * Copyright (C) 2012 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 
26 #include <wx/grid.h>
27 #include <wx/event.h>
28 
29 
34 class GRID_TRICKS : public wxEvtHandler
35 {
36 public:
37 
38  GRID_TRICKS( wxGrid* aGrid );
39 
40 
41 protected:
42  wxGrid* m_grid;
43 
44  // row & col "selection" acquisition
45  // selected area by cell coordinate and count
50 
53  int getCursorCol() const
54  {
55  return m_grid->GetGridCursorCol();
56  }
57 
60  int getCursorRow() const
61  {
62  return m_grid->GetGridCursorRow();
63  }
64 
66  void getSelectedArea();
67 
68  static bool isCtl( int aChar, const wxKeyEvent& e )
69  {
70  return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() && !e.ShiftDown() && !e.MetaDown();
71  }
72 
73  void onGridCellRightClick( wxGridEvent& event )
74  {
75  showPopupMenu();
76  }
77 
78  void onRightDown( wxMouseEvent& event )
79  {
80  showPopupMenu();
81  }
82 
83  virtual void showPopupMenu();
84 
85  // the user clicked on a popup menu choice:
86  void onPopupSelection( wxCommandEvent& event );
87 
88  void onKeyDown( wxKeyEvent& ev );
89 
90  virtual void paste_clipboard();
91 
92  virtual void paste_text( const wxString& cb_text );
93 
94  virtual void cutcopy( bool doCut );
95 };
96 
wxGrid * m_grid
I don't own the grid, but he owns me.
Definition: grid_tricks.h:42
int getCursorCol() const
If the cursor is not on a valid cell, because there are no rows at all, return -1, else return a 0 based column index.
Definition: grid_tricks.h:53
void getSelectedArea()
Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above...
Definition: grid_tricks.cpp:67
int m_sel_row_count
Definition: grid_tricks.h:48
GRID_TRICKS(wxGrid *aGrid)
Definition: grid_tricks.cpp:52
void onRightDown(wxMouseEvent &event)
Definition: grid_tricks.h:78
Class GRID_TRICKS is used to add cut, copy, and paste to an otherwise unmodied wxGrid instance...
Definition: grid_tricks.h:34
void onGridCellRightClick(wxGridEvent &event)
Definition: grid_tricks.h:73
int m_sel_col_start
Definition: grid_tricks.h:47
static bool isCtl(int aChar, const wxKeyEvent &e)
Definition: grid_tricks.h:68
virtual void paste_text(const wxString &cb_text)
void onPopupSelection(wxCommandEvent &event)
int m_sel_col_count
Definition: grid_tricks.h:49
int m_sel_row_start
Definition: grid_tricks.h:46
virtual void paste_clipboard()
int getCursorRow() const
If the cursor is not on a valid cell, because there are no rows at all, return -1, else return a 0 based row index.
Definition: grid_tricks.h:60
virtual void showPopupMenu()
virtual void cutcopy(bool doCut)
void onKeyDown(wxKeyEvent &ev)