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.

132 lines
4.6 KiB

  1. /*
  2. * This program source code file is part of KiCad, a free EDA CAD application.
  3. *
  4. * Copyright (C) 2018 KiCad Developers, see AUTHORS.txt for contributors.
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License
  8. * as published by the Free Software Foundation; either version 3
  9. * of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, you may find one here:
  18. * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
  19. * or you may search the http://www.gnu.org website for the version 2 license,
  20. * or you may write to the Free Software Foundation, Inc.,
  21. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
  22. */
  23. #ifndef KICAD_WX_GRID_H
  24. #define KICAD_WX_GRID_H
  25. #include <wx/event.h>
  26. #include <wx/grid.h>
  27. #include <wx/version.h>
  28. class WX_GRID : public wxGrid
  29. {
  30. public:
  31. // Constructor has to be wxFormBuilder-compatible
  32. WX_GRID( wxWindow *parent, wxWindowID id,
  33. const wxPoint& pos = wxDefaultPosition, const wxSize& size = wxDefaultSize,
  34. long style = wxWANTS_CHARS, const wxString& name = wxGridNameStr );
  35. ~WX_GRID() override;
  36. /**
  37. * Hide wxGrid's SetColLabelSize() method with one which makes sure the size is tall
  38. * enough for the system GUI font.
  39. * @param height
  40. */
  41. void SetColLabelSize( int aHeight );
  42. /**
  43. * Get a tokenized string containing the shown column indexes.
  44. * Tokens are separated by spaces.
  45. */
  46. wxString GetShownColumns();
  47. /**
  48. * Show/hide the grid columns based on a tokenized string of shown column indexes.
  49. */
  50. void ShowHideColumns( const wxString& shownColumns );
  51. /**
  52. * Hide wxGrid's SetTable() method with one which doesn't mess up the grid column
  53. * widths when setting the table.
  54. */
  55. void SetTable( wxGridTableBase* table, bool aTakeOwnership = false );
  56. /**
  57. * Work-around for a bug in wxGrid which crashes when deleting the table if the
  58. * cell edit control was not closed.
  59. */
  60. void DestroyTable( wxGridTableBase* aTable );
  61. /**
  62. * Close any open cell edit controls.
  63. * @param aQuietMode if true don't send events (ie: for row/col delete operations)
  64. * @return false if validation failed
  65. */
  66. bool CommitPendingChanges( bool aQuietMode = false );
  67. /**
  68. * Calculates the specified column based on the actual size of the text
  69. * on screen. Will return the maximum value of all calculated widths.
  70. * @param aCol - Integer value of the column to resize. Specify -1 for the row labels.
  71. * @param aHeader - Include the header in the width calculation
  72. * @param aContents - Include the full contents of the column
  73. * @param aKeep - Use the current size as a minimum value
  74. * @return The new size of the column
  75. */
  76. int GetVisibleWidth( int aCol, bool aHeader = true, bool aContents = false, bool aKeep = true );
  77. /**
  78. * Ensure the height of the row displaying the column labels is enough, even
  79. * if labels are multiline texts
  80. */
  81. void EnsureColLabelsVisible();
  82. /**
  83. * WxWidgets has a bunch of bugs in its handling of wxGrid mouse events which close cell
  84. * editors right after opening them. Helpfully, it already has a bunch of work-arounds in
  85. * place (such as the SetInSetFocus() hack), including one to make slow clicks work. We
  86. * re-purpose this hack to work-around the bugs when we want to open an editor.
  87. */
  88. void ShowEditorOnMouseUp() { m_waitForSlowClick = true; }
  89. /**
  90. * wxWidgets recently added an ASSERT which fires if the position is greater than or equal
  91. * to the number of rows (even if the delete count is 0). Needless to say, this makes using
  92. * DeleteRows for clearing a lot more cumbersome so we add a helper here.
  93. */
  94. void ClearRows()
  95. {
  96. if( GetNumberRows() )
  97. DeleteRows( 0, GetNumberRows() );
  98. }
  99. protected:
  100. /**
  101. * A re-implementation of wxGrid::DrawColLabel which left-aligns the first column when
  102. * there are no row labels.
  103. */
  104. void DrawColLabel( wxDC& dc, int col ) override;
  105. void onGridColMove( wxGridEvent& aEvent );
  106. void onGridCellSelect( wxGridEvent& aEvent );
  107. #if wxCHECK_VERSION( 3, 1, 0 )
  108. void onDPIChanged(wxDPIChangedEvent& event);
  109. #endif
  110. bool m_weOwnTable;
  111. };
  112. #endif //KICAD_WX_GRID_H