]>
Commit | Line | Data |
---|---|---|
10434f3c MB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: griddemo.h | |
3 | // Purpose: Grid control wxWindows sample | |
4 | // Author: Michael Bedward | |
5 | // Modified by: | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) Michael Bedward, Julian Smart | |
8 | // Licence: wxWindows license | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
e442cc0d MB |
10 | |
11 | ||
12 | #ifndef griddemo_h | |
13 | #define griddemo_h | |
14 | ||
b99be8fb VZ |
15 | #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID) |
16 | #error "This sample requires the new wxGrid class." | |
17 | #endif | |
e442cc0d MB |
18 | |
19 | class wxGrid; | |
20 | ||
21 | class GridApp : public wxApp | |
22 | { | |
ab79958a | 23 | public: |
e442cc0d MB |
24 | bool OnInit(); |
25 | }; | |
26 | ||
27 | ||
28 | class GridFrame : public wxFrame | |
29 | { | |
30 | wxGrid *grid; | |
31 | wxTextCtrl *logWin; | |
32 | wxLogTextCtrl *logger; | |
33 | wxString logBuf; | |
34 | ||
35 | void SetDefaults(); | |
f445b853 | 36 | |
e442cc0d MB |
37 | void ToggleRowLabels( wxCommandEvent& ); |
38 | void ToggleColLabels( wxCommandEvent& ); | |
f445b853 | 39 | void ToggleEditing( wxCommandEvent& ); |
dd16fdae MB |
40 | void ToggleRowSizing( wxCommandEvent& ); |
41 | void ToggleColSizing( wxCommandEvent& ); | |
4cfa5de6 | 42 | void ToggleGridSizing( wxCommandEvent& ); |
f6bcfd97 BP |
43 | void ToggleGridLines( wxCommandEvent& ); |
44 | void AutoSizeCols( wxCommandEvent& ); | |
e442cc0d MB |
45 | void SetLabelColour( wxCommandEvent& ); |
46 | void SetLabelTextColour( wxCommandEvent& ); | |
47 | void SetRowLabelHorizAlignment( wxCommandEvent& ); | |
48 | void SetRowLabelVertAlignment( wxCommandEvent& ); | |
49 | void SetColLabelHorizAlignment( wxCommandEvent& ); | |
50 | void SetColLabelVertAlignment( wxCommandEvent& ); | |
51 | void SetGridLineColour( wxCommandEvent& ); | |
0eee5283 | 52 | |
ab79958a VZ |
53 | void SetCellFgColour(wxCommandEvent &); |
54 | void SetCellBgColour(wxCommandEvent &); | |
55 | ||
b99be8fb VZ |
56 | void InsertRow( wxCommandEvent& ); |
57 | void InsertCol( wxCommandEvent& ); | |
58 | void DeleteSelectedRows( wxCommandEvent& ); | |
59 | void DeleteSelectedCols( wxCommandEvent& ); | |
e442cc0d | 60 | void ClearGrid( wxCommandEvent& ); |
043d16b2 SN |
61 | void SelectCells( wxCommandEvent& ); |
62 | void SelectRows( wxCommandEvent& ); | |
63 | void SelectCols( wxCommandEvent& ); | |
e442cc0d | 64 | |
14e5a313 VZ |
65 | void DeselectCell(wxCommandEvent& event); |
66 | void DeselectCol(wxCommandEvent& event); | |
67 | void DeselectRow(wxCommandEvent& event); | |
68 | void DeselectAll(wxCommandEvent& event); | |
69 | void SelectCell(wxCommandEvent& event); | |
70 | void SelectCol(wxCommandEvent& event); | |
71 | void SelectRow(wxCommandEvent& event); | |
72 | void SelectAll(wxCommandEvent& event); | |
73 | ||
e442cc0d MB |
74 | void OnLabelLeftClick( wxGridEvent& ); |
75 | void OnCellLeftClick( wxGridEvent& ); | |
76 | void OnRowSize( wxGridSizeEvent& ); | |
77 | void OnColSize( wxGridSizeEvent& ); | |
c336585e | 78 | void OnSelectCell( wxGridEvent& ); |
e442cc0d MB |
79 | void OnRangeSelected( wxGridRangeSelectEvent& ); |
80 | void OnCellValueChanged( wxGridEvent& ); | |
b99be8fb | 81 | |
b54ba671 VZ |
82 | void OnEditorShown(wxGridEvent&); |
83 | void OnEditorHidden(wxGridEvent&); | |
84 | ||
ab79958a | 85 | public: |
e442cc0d MB |
86 | GridFrame(); |
87 | ~GridFrame(); | |
88 | ||
e442cc0d | 89 | void OnQuit( wxCommandEvent& ); |
f445b853 | 90 | void About( wxCommandEvent& ); |
f97c9b5b | 91 | void OnVTable( wxCommandEvent& ); |
35f97e95 | 92 | void OnBugsTable( wxCommandEvent& ); |
e442cc0d | 93 | |
ab79958a VZ |
94 | enum |
95 | { | |
96 | ID_TOGGLEROWLABELS = 100, | |
97 | ID_TOGGLECOLLABELS, | |
98 | ID_TOGGLEEDIT, | |
dd16fdae MB |
99 | ID_TOGGLEROWSIZING, |
100 | ID_TOGGLECOLSIZING, | |
4cfa5de6 | 101 | ID_TOGGLEGRIDSIZING, |
f6bcfd97 BP |
102 | ID_TOGGLEGRIDLINES, |
103 | ID_AUTOSIZECOLS, | |
ab79958a VZ |
104 | ID_SETLABELCOLOUR, |
105 | ID_SETLABELTEXTCOLOUR, | |
106 | ID_ROWLABELALIGN, | |
107 | ID_ROWLABELHORIZALIGN, | |
108 | ID_ROWLABELVERTALIGN, | |
109 | ID_COLLABELALIGN, | |
110 | ID_COLLABELHORIZALIGN, | |
111 | ID_COLLABELVERTALIGN, | |
112 | ID_GRIDLINECOLOUR, | |
113 | ID_INSERTROW, | |
114 | ID_INSERTCOL, | |
115 | ID_DELETEROW, | |
116 | ID_DELETECOL, | |
117 | ID_CLEARGRID, | |
043d16b2 SN |
118 | ID_CHANGESEL, |
119 | ID_SELCELLS, | |
120 | ID_SELROWS, | |
121 | ID_SELCOLS, | |
ab79958a VZ |
122 | ID_SET_CELL_FG_COLOUR, |
123 | ID_SET_CELL_BG_COLOUR, | |
124 | ID_ABOUT, | |
f97c9b5b | 125 | ID_VTABLE, |
35f97e95 | 126 | ID_BUGS_TABLE, |
14e5a313 VZ |
127 | ID_SELECT_ALL, |
128 | ID_SELECT_ROW, | |
129 | ID_SELECT_COL, | |
130 | ID_SELECT_CELL, | |
131 | ID_DESELECT_ALL, | |
132 | ID_DESELECT_ROW, | |
133 | ID_DESELECT_COL, | |
134 | ID_DESELECT_CELL, | |
ab79958a VZ |
135 | |
136 | ID_TESTFUNC | |
137 | }; | |
b99be8fb | 138 | |
66b3609e VZ |
139 | wxLog *m_logOld; |
140 | ||
e442cc0d MB |
141 | DECLARE_EVENT_TABLE() |
142 | }; | |
143 | ||
ab79958a VZ |
144 | class MyGridCellRenderer : public wxGridCellStringRenderer |
145 | { | |
146 | public: | |
147 | virtual void Draw(wxGrid& grid, | |
f97c9b5b | 148 | wxGridCellAttr& attr, |
ab79958a VZ |
149 | wxDC& dc, |
150 | const wxRect& rect, | |
151 | int row, int col, | |
152 | bool isSelected); | |
153 | }; | |
e442cc0d | 154 | |
1618dca7 VZ |
155 | // ---------------------------------------------------------------------------- |
156 | // demonstration of virtual table which doesn't store all of its data in | |
157 | // memory | |
158 | // ---------------------------------------------------------------------------- | |
f97c9b5b | 159 | |
1618dca7 VZ |
160 | class BigGridTable : public wxGridTableBase |
161 | { | |
f97c9b5b | 162 | public: |
1618dca7 VZ |
163 | BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; } |
164 | ||
e32352cf SN |
165 | int GetNumberRows() { return m_sizeGrid; } |
166 | int GetNumberCols() { return m_sizeGrid; } | |
1618dca7 VZ |
167 | wxString GetValue( int row, int col ) |
168 | { | |
169 | return wxString::Format("(%d, %d)", row, col); | |
f97c9b5b RD |
170 | } |
171 | ||
1618dca7 | 172 | void SetValue( int , int , const wxString& ) { /* ignore */ } |
f97c9b5b | 173 | bool IsEmptyCell( int , int ) { return FALSE; } |
1618dca7 VZ |
174 | |
175 | private: | |
176 | long m_sizeGrid; | |
f97c9b5b RD |
177 | }; |
178 | ||
1618dca7 VZ |
179 | class BigGridFrame : public wxFrame |
180 | { | |
f97c9b5b | 181 | public: |
1618dca7 | 182 | BigGridFrame(long sizeGrid); |
f97c9b5b RD |
183 | |
184 | private: | |
185 | wxGrid* m_grid; | |
186 | BigGridTable* m_table; | |
187 | }; | |
188 | ||
a68c1246 VZ |
189 | // ---------------------------------------------------------------------------- |
190 | // an example of custom attr provider: this one makes all odd rows appear grey | |
191 | // ---------------------------------------------------------------------------- | |
192 | ||
193 | class MyGridCellAttrProvider : public wxGridCellAttrProvider | |
194 | { | |
195 | public: | |
196 | MyGridCellAttrProvider(); | |
197 | virtual ~MyGridCellAttrProvider(); | |
198 | ||
199 | virtual wxGridCellAttr *GetAttr(int row, int col) const; | |
200 | ||
201 | private: | |
202 | wxGridCellAttr *m_attrForOddRows; | |
203 | }; | |
204 | ||
35f97e95 | 205 | // ---------------------------------------------------------------------------- |
816be743 | 206 | // another, more realistic, grid example: shows typed columns and more |
35f97e95 VZ |
207 | // ---------------------------------------------------------------------------- |
208 | ||
816be743 VZ |
209 | class BugsGridTable : public wxGridTableBase |
210 | { | |
211 | public: | |
212 | BugsGridTable(); | |
213 | ||
e32352cf SN |
214 | virtual int GetNumberRows(); |
215 | virtual int GetNumberCols(); | |
816be743 VZ |
216 | virtual bool IsEmptyCell( int row, int col ); |
217 | virtual wxString GetValue( int row, int col ); | |
218 | virtual void SetValue( int row, int col, const wxString& value ); | |
219 | ||
220 | virtual wxString GetColLabelValue( int col ); | |
221 | ||
222 | virtual wxString GetTypeName( int row, int col ); | |
223 | virtual bool CanGetValueAs( int row, int col, const wxString& typeName ); | |
224 | virtual bool CanSetValueAs( int row, int col, const wxString& typeName ); | |
225 | ||
226 | virtual long GetValueAsLong( int row, int col ); | |
227 | virtual bool GetValueAsBool( int row, int col ); | |
228 | ||
229 | virtual void SetValueAsLong( int row, int col, long value ); | |
230 | virtual void SetValueAsBool( int row, int col, bool value ); | |
231 | }; | |
232 | ||
35f97e95 VZ |
233 | class BugsGridFrame : public wxFrame |
234 | { | |
235 | public: | |
236 | BugsGridFrame(); | |
237 | }; | |
f97c9b5b | 238 | |
1618dca7 | 239 | #endif // griddemo_h |
e442cc0d | 240 |