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