You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

96 lines
3.1 KiB

  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. #ifndef _GRID_TRICKS_H_
  25. #define _GRID_TRICKS_H_
  26. #include <wx/grid.h>
  27. #include <wx/event.h>
  28. #include <widgets/wx_grid.h>
  29. enum
  30. {
  31. GRIDTRICKS_FIRST_ID = 901,
  32. GRIDTRICKS_ID_CUT,
  33. GRIDTRICKS_ID_COPY,
  34. GRIDTRICKS_ID_PASTE,
  35. GRIDTRICKS_ID_SELECT,
  36. GRIDTRICKS_FIRST_SHOWHIDE = 979, // reserve 20 IDs for show/hide-column-n
  37. GRIDTRICKS_LAST_ID = 999
  38. };
  39. /**
  40. * GRID_TRICKS
  41. * is used to add mouse and command handling (such as cut, copy, and paste) to a WX_GRID instance.
  42. */
  43. class GRID_TRICKS : public wxEvtHandler
  44. {
  45. public:
  46. explicit GRID_TRICKS( WX_GRID* aGrid );
  47. protected:
  48. WX_GRID* m_grid; ///< I don't own the grid, but he owns me
  49. // row & col "selection" acquisition
  50. // selected area by cell coordinate and count
  51. int m_sel_row_start;
  52. int m_sel_col_start;
  53. int m_sel_row_count;
  54. int m_sel_col_count;
  55. /// Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above.
  56. void getSelectedArea();
  57. static bool isCtl( int aChar, const wxKeyEvent& e )
  58. {
  59. return e.GetKeyCode() == aChar && e.ControlDown() && !e.AltDown() && !e.ShiftDown() && !e.MetaDown();
  60. }
  61. void onGridCellLeftClick( wxGridEvent& event );
  62. void onGridCellLeftDClick( wxGridEvent& event );
  63. void onGridCellRightClick( wxGridEvent& event );
  64. void onGridLabelLeftClick( wxGridEvent& event );
  65. void onGridLabelRightClick( wxGridEvent& event );
  66. void onPopupSelection( wxCommandEvent& event );
  67. void onKeyDown( wxKeyEvent& ev );
  68. void onUpdateUI( wxUpdateUIEvent& event );
  69. virtual bool handleDoubleClick( wxGridEvent& aEvent );
  70. virtual void showPopupMenu( wxMenu& menu );
  71. virtual void doPopupSelection( wxCommandEvent& event );
  72. bool toggleCell( int aRow, int aCol, bool aPreserveSelection = false );
  73. bool showEditor( int aRow, int aCol );
  74. virtual void paste_clipboard();
  75. virtual void paste_text( const wxString& cb_text );
  76. virtual void cutcopy( bool doCut );
  77. };
  78. #endif // _GRID_TRICKS_H_