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.

121 lines
3.8 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-2020 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 <bitset>
  27. #include <wx/grid.h>
  28. #include <wx/event.h>
  29. #include <wx/menu.h>
  30. #include <widgets/wx_grid.h>
  31. #define GRIDTRICKS_MAX_COL 20
  32. enum
  33. {
  34. GRIDTRICKS_FIRST_ID = 901,
  35. GRIDTRICKS_ID_CUT,
  36. GRIDTRICKS_ID_COPY,
  37. GRIDTRICKS_ID_DELETE,
  38. GRIDTRICKS_ID_PASTE,
  39. GRIDTRICKS_ID_SELECT,
  40. GRIDTRICKS_FIRST_SHOWHIDE = 979, // reserve IDs for show/hide-column-n
  41. GRIDTRICKS_LAST_ID = GRIDTRICKS_FIRST_SHOWHIDE + GRIDTRICKS_MAX_COL
  42. };
  43. /**
  44. * Add mouse and command handling (such as cut, copy, and paste) to a #WX_GRID instance.
  45. */
  46. class GRID_TRICKS : public wxEvtHandler
  47. {
  48. public:
  49. explicit GRID_TRICKS( WX_GRID* aGrid );
  50. /**
  51. * Enable the tooltip for a column.
  52. *
  53. * The tooltip is read from the string contained in the cell data.
  54. *
  55. * @param aCol is the column to use
  56. * @param aEnable is true to enable the tooltip (default)
  57. */
  58. void SetTooltipEnable( int aCol, bool aEnable = true )
  59. {
  60. m_tooltipEnabled[aCol] = aEnable;
  61. }
  62. /**
  63. * Query if the tooltip for a column is enabled
  64. *
  65. * @param aCol is the column to query
  66. * @return if the tooltip is enabled for the column
  67. */
  68. bool GetTooltipEnabled( int aCol )
  69. {
  70. return m_tooltipEnabled[aCol];
  71. }
  72. protected:
  73. /// Puts the selected area into a sensible rectangle of m_sel_{row,col}_{start,count} above.
  74. void getSelectedArea();
  75. void onGridCellLeftClick( wxGridEvent& event );
  76. void onGridCellLeftDClick( wxGridEvent& event );
  77. void onGridCellRightClick( wxGridEvent& event );
  78. void onGridLabelLeftClick( wxGridEvent& event );
  79. void onGridLabelRightClick( wxGridEvent& event );
  80. void onPopupSelection( wxCommandEvent& event );
  81. void onKeyDown( wxKeyEvent& ev );
  82. void onUpdateUI( wxUpdateUIEvent& event );
  83. void onGridMotion( wxMouseEvent& event );
  84. virtual bool handleDoubleClick( wxGridEvent& aEvent );
  85. virtual void showPopupMenu( wxMenu& menu );
  86. virtual void doPopupSelection( wxCommandEvent& event );
  87. bool toggleCell( int aRow, int aCol, bool aPreserveSelection = false );
  88. bool showEditor( int aRow, int aCol );
  89. virtual void paste_clipboard();
  90. virtual void paste_text( const wxString& cb_text );
  91. virtual void cutcopy( bool doCopy, bool doDelete );
  92. WX_GRID* m_grid; ///< I don't own the grid, but he owns me
  93. // row & col "selection" acquisition
  94. // selected area by cell coordinate and count
  95. int m_sel_row_start;
  96. int m_sel_col_start;
  97. int m_sel_row_count;
  98. int m_sel_col_count;
  99. std::bitset<GRIDTRICKS_MAX_COL> m_tooltipEnabled;
  100. };
  101. #endif // _GRID_TRICKS_H_