gridsel.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /////////////////////////////////////////////////////////////////////////////
  2. // Name: wx/generic/gridsel.h
  3. // Purpose: wxGridSelection
  4. // Author: Stefan Neis
  5. // Modified by:
  6. // Created: 20/02/2000
  7. // Copyright: (c) Stefan Neis
  8. // Licence: wxWindows licence
  9. /////////////////////////////////////////////////////////////////////////////
  10. #ifndef _WX_GENERIC_GRIDSEL_H_
  11. #define _WX_GENERIC_GRIDSEL_H_
  12. #include "wx/defs.h"
  13. #if wxUSE_GRID
  14. #include "wx/grid.h"
  15. class WXDLLIMPEXP_ADV wxGridSelection
  16. {
  17. public:
  18. wxGridSelection(wxGrid *grid,
  19. wxGrid::wxGridSelectionModes sel = wxGrid::wxGridSelectCells);
  20. bool IsSelection();
  21. bool IsInSelection(int row, int col);
  22. bool IsInSelection(const wxGridCellCoords& coords)
  23. {
  24. return IsInSelection(coords.GetRow(), coords.GetCol());
  25. }
  26. void SetSelectionMode(wxGrid::wxGridSelectionModes selmode);
  27. wxGrid::wxGridSelectionModes GetSelectionMode() { return m_selectionMode; }
  28. void SelectRow(int row, const wxKeyboardState& kbd = wxKeyboardState());
  29. void SelectCol(int col, const wxKeyboardState& kbd = wxKeyboardState());
  30. void SelectBlock(int topRow, int leftCol,
  31. int bottomRow, int rightCol,
  32. const wxKeyboardState& kbd = wxKeyboardState(),
  33. bool sendEvent = true );
  34. void SelectBlock(const wxGridCellCoords& topLeft,
  35. const wxGridCellCoords& bottomRight,
  36. const wxKeyboardState& kbd = wxKeyboardState(),
  37. bool sendEvent = true )
  38. {
  39. SelectBlock(topLeft.GetRow(), topLeft.GetCol(),
  40. bottomRight.GetRow(), bottomRight.GetCol(),
  41. kbd, sendEvent);
  42. }
  43. void SelectCell(int row, int col,
  44. const wxKeyboardState& kbd = wxKeyboardState(),
  45. bool sendEvent = true);
  46. void SelectCell(const wxGridCellCoords& coords,
  47. const wxKeyboardState& kbd = wxKeyboardState(),
  48. bool sendEvent = true)
  49. {
  50. SelectCell(coords.GetRow(), coords.GetCol(), kbd, sendEvent);
  51. }
  52. void ToggleCellSelection(int row, int col,
  53. const wxKeyboardState& kbd = wxKeyboardState());
  54. void ToggleCellSelection(const wxGridCellCoords& coords,
  55. const wxKeyboardState& kbd = wxKeyboardState())
  56. {
  57. ToggleCellSelection(coords.GetRow(), coords.GetCol(), kbd);
  58. }
  59. void ClearSelection();
  60. void UpdateRows( size_t pos, int numRows );
  61. void UpdateCols( size_t pos, int numCols );
  62. private:
  63. int BlockContain( int topRow1, int leftCol1,
  64. int bottomRow1, int rightCol1,
  65. int topRow2, int leftCol2,
  66. int bottomRow2, int rightCol2 );
  67. // returns 1, if Block1 contains Block2,
  68. // -1, if Block2 contains Block1,
  69. // 0, otherwise
  70. int BlockContainsCell( int topRow, int leftCol,
  71. int bottomRow, int rightCol,
  72. int row, int col )
  73. // returns 1, if Block contains Cell,
  74. // 0, otherwise
  75. {
  76. return ( topRow <= row && row <= bottomRow &&
  77. leftCol <= col && col <= rightCol );
  78. }
  79. void SelectBlockNoEvent(int topRow, int leftCol,
  80. int bottomRow, int rightCol)
  81. {
  82. SelectBlock(topRow, leftCol, bottomRow, rightCol,
  83. wxKeyboardState(), false);
  84. }
  85. wxGridCellCoordsArray m_cellSelection;
  86. wxGridCellCoordsArray m_blockSelectionTopLeft;
  87. wxGridCellCoordsArray m_blockSelectionBottomRight;
  88. wxArrayInt m_rowSelection;
  89. wxArrayInt m_colSelection;
  90. wxGrid *m_grid;
  91. wxGrid::wxGridSelectionModes m_selectionMode;
  92. friend class WXDLLIMPEXP_FWD_ADV wxGrid;
  93. wxDECLARE_NO_COPY_CLASS(wxGridSelection);
  94. };
  95. #endif // wxUSE_GRID
  96. #endif // _WX_GENERIC_GRIDSEL_H_