]>
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& ); | |
bf9adb3a | 47 | void SetLabelFont(wxCommandEvent &); |
e442cc0d MB |
48 | void SetRowLabelHorizAlignment( wxCommandEvent& ); |
49 | void SetRowLabelVertAlignment( wxCommandEvent& ); | |
50 | void SetColLabelHorizAlignment( wxCommandEvent& ); | |
51 | void SetColLabelVertAlignment( wxCommandEvent& ); | |
52 | void SetGridLineColour( wxCommandEvent& ); | |
0eee5283 | 53 | |
ab79958a VZ |
54 | void SetCellFgColour(wxCommandEvent &); |
55 | void SetCellBgColour(wxCommandEvent &); | |
56 | ||
b99be8fb VZ |
57 | void InsertRow( wxCommandEvent& ); |
58 | void InsertCol( wxCommandEvent& ); | |
59 | void DeleteSelectedRows( wxCommandEvent& ); | |
60 | void DeleteSelectedCols( wxCommandEvent& ); | |
e442cc0d | 61 | void ClearGrid( wxCommandEvent& ); |
043d16b2 SN |
62 | void SelectCells( wxCommandEvent& ); |
63 | void SelectRows( wxCommandEvent& ); | |
64 | void SelectCols( wxCommandEvent& ); | |
e442cc0d | 65 | |
14e5a313 VZ |
66 | void DeselectCell(wxCommandEvent& event); |
67 | void DeselectCol(wxCommandEvent& event); | |
68 | void DeselectRow(wxCommandEvent& event); | |
69 | void DeselectAll(wxCommandEvent& event); | |
70 | void SelectCell(wxCommandEvent& event); | |
71 | void SelectCol(wxCommandEvent& event); | |
72 | void SelectRow(wxCommandEvent& event); | |
73 | void SelectAll(wxCommandEvent& event); | |
93521c94 | 74 | void OnAddToSelectToggle(wxCommandEvent& event); |
14e5a313 | 75 | |
e442cc0d MB |
76 | void OnLabelLeftClick( wxGridEvent& ); |
77 | void OnCellLeftClick( wxGridEvent& ); | |
78 | void OnRowSize( wxGridSizeEvent& ); | |
79 | void OnColSize( wxGridSizeEvent& ); | |
c336585e | 80 | void OnSelectCell( wxGridEvent& ); |
e442cc0d MB |
81 | void OnRangeSelected( wxGridRangeSelectEvent& ); |
82 | void OnCellValueChanged( wxGridEvent& ); | |
b99be8fb | 83 | |
b54ba671 VZ |
84 | void OnEditorShown(wxGridEvent&); |
85 | void OnEditorHidden(wxGridEvent&); | |
86 | ||
d2520c85 RD |
87 | void OnSetHighlightWidth(wxCommandEvent&); |
88 | void OnSetROHighlightWidth(wxCommandEvent&); | |
89 | ||
ab79958a | 90 | public: |
e442cc0d MB |
91 | GridFrame(); |
92 | ~GridFrame(); | |
93 | ||
e442cc0d | 94 | void OnQuit( wxCommandEvent& ); |
f445b853 | 95 | void About( wxCommandEvent& ); |
f97c9b5b | 96 | void OnVTable( wxCommandEvent& ); |
35f97e95 | 97 | void OnBugsTable( wxCommandEvent& ); |
671bcff5 | 98 | void OnSmallGrid( wxCommandEvent& ); |
e442cc0d | 99 | |
ab79958a VZ |
100 | enum |
101 | { | |
102 | ID_TOGGLEROWLABELS = 100, | |
103 | ID_TOGGLECOLLABELS, | |
104 | ID_TOGGLEEDIT, | |
dd16fdae MB |
105 | ID_TOGGLEROWSIZING, |
106 | ID_TOGGLECOLSIZING, | |
4cfa5de6 | 107 | ID_TOGGLEGRIDSIZING, |
f6bcfd97 BP |
108 | ID_TOGGLEGRIDLINES, |
109 | ID_AUTOSIZECOLS, | |
ab79958a VZ |
110 | ID_SETLABELCOLOUR, |
111 | ID_SETLABELTEXTCOLOUR, | |
bf9adb3a | 112 | ID_SETLABEL_FONT, |
ab79958a VZ |
113 | ID_ROWLABELALIGN, |
114 | ID_ROWLABELHORIZALIGN, | |
115 | ID_ROWLABELVERTALIGN, | |
116 | ID_COLLABELALIGN, | |
117 | ID_COLLABELHORIZALIGN, | |
118 | ID_COLLABELVERTALIGN, | |
119 | ID_GRIDLINECOLOUR, | |
120 | ID_INSERTROW, | |
121 | ID_INSERTCOL, | |
122 | ID_DELETEROW, | |
123 | ID_DELETECOL, | |
124 | ID_CLEARGRID, | |
93521c94 VZ |
125 | ID_CHANGESEL, |
126 | ID_SELCELLS, | |
127 | ID_SELROWS, | |
128 | ID_SELCOLS, | |
ab79958a VZ |
129 | ID_SET_CELL_FG_COLOUR, |
130 | ID_SET_CELL_BG_COLOUR, | |
131 | ID_ABOUT, | |
f97c9b5b | 132 | ID_VTABLE, |
35f97e95 | 133 | ID_BUGS_TABLE, |
671bcff5 | 134 | ID_SMALL_GRID, |
93521c94 | 135 | ID_SELECT_UNSELECT, |
14e5a313 VZ |
136 | ID_SELECT_ALL, |
137 | ID_SELECT_ROW, | |
138 | ID_SELECT_COL, | |
139 | ID_SELECT_CELL, | |
140 | ID_DESELECT_ALL, | |
141 | ID_DESELECT_ROW, | |
142 | ID_DESELECT_COL, | |
143 | ID_DESELECT_CELL, | |
ab79958a | 144 | |
d2520c85 RD |
145 | ID_SET_HIGHLIGHT_WIDTH, |
146 | ID_SET_RO_HIGHLIGHT_WIDTH, | |
147 | ||
ab79958a VZ |
148 | ID_TESTFUNC |
149 | }; | |
b99be8fb | 150 | |
66b3609e VZ |
151 | wxLog *m_logOld; |
152 | ||
93521c94 VZ |
153 | // add the cells to selection when using commands from select menu? |
154 | bool m_addToSel; | |
155 | ||
e442cc0d MB |
156 | DECLARE_EVENT_TABLE() |
157 | }; | |
158 | ||
ab79958a VZ |
159 | class MyGridCellRenderer : public wxGridCellStringRenderer |
160 | { | |
161 | public: | |
162 | virtual void Draw(wxGrid& grid, | |
f97c9b5b | 163 | wxGridCellAttr& attr, |
ab79958a VZ |
164 | wxDC& dc, |
165 | const wxRect& rect, | |
166 | int row, int col, | |
167 | bool isSelected); | |
168 | }; | |
e442cc0d | 169 | |
1618dca7 VZ |
170 | // ---------------------------------------------------------------------------- |
171 | // demonstration of virtual table which doesn't store all of its data in | |
172 | // memory | |
173 | // ---------------------------------------------------------------------------- | |
f97c9b5b | 174 | |
1618dca7 VZ |
175 | class BigGridTable : public wxGridTableBase |
176 | { | |
f97c9b5b | 177 | public: |
1618dca7 VZ |
178 | BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; } |
179 | ||
e32352cf SN |
180 | int GetNumberRows() { return m_sizeGrid; } |
181 | int GetNumberCols() { return m_sizeGrid; } | |
1618dca7 VZ |
182 | wxString GetValue( int row, int col ) |
183 | { | |
4693b20c | 184 | return wxString::Format(wxT("(%d, %d)"), row, col); |
f97c9b5b RD |
185 | } |
186 | ||
1618dca7 | 187 | void SetValue( int , int , const wxString& ) { /* ignore */ } |
f97c9b5b | 188 | bool IsEmptyCell( int , int ) { return FALSE; } |
1618dca7 VZ |
189 | |
190 | private: | |
191 | long m_sizeGrid; | |
f97c9b5b RD |
192 | }; |
193 | ||
1618dca7 VZ |
194 | class BigGridFrame : public wxFrame |
195 | { | |
f97c9b5b | 196 | public: |
1618dca7 | 197 | BigGridFrame(long sizeGrid); |
f97c9b5b RD |
198 | |
199 | private: | |
200 | wxGrid* m_grid; | |
201 | BigGridTable* m_table; | |
202 | }; | |
203 | ||
a68c1246 VZ |
204 | // ---------------------------------------------------------------------------- |
205 | // an example of custom attr provider: this one makes all odd rows appear grey | |
206 | // ---------------------------------------------------------------------------- | |
207 | ||
208 | class MyGridCellAttrProvider : public wxGridCellAttrProvider | |
209 | { | |
210 | public: | |
211 | MyGridCellAttrProvider(); | |
212 | virtual ~MyGridCellAttrProvider(); | |
213 | ||
19d7140e | 214 | virtual wxGridCellAttr *GetAttr(int row, int col, |
d10f4bf9 | 215 | wxGridCellAttr::wxAttrKind kind) const; |
a68c1246 VZ |
216 | |
217 | private: | |
218 | wxGridCellAttr *m_attrForOddRows; | |
219 | }; | |
220 | ||
35f97e95 | 221 | // ---------------------------------------------------------------------------- |
816be743 | 222 | // another, more realistic, grid example: shows typed columns and more |
35f97e95 VZ |
223 | // ---------------------------------------------------------------------------- |
224 | ||
816be743 VZ |
225 | class BugsGridTable : public wxGridTableBase |
226 | { | |
227 | public: | |
228 | BugsGridTable(); | |
229 | ||
e32352cf SN |
230 | virtual int GetNumberRows(); |
231 | virtual int GetNumberCols(); | |
816be743 VZ |
232 | virtual bool IsEmptyCell( int row, int col ); |
233 | virtual wxString GetValue( int row, int col ); | |
234 | virtual void SetValue( int row, int col, const wxString& value ); | |
235 | ||
236 | virtual wxString GetColLabelValue( int col ); | |
237 | ||
238 | virtual wxString GetTypeName( int row, int col ); | |
239 | virtual bool CanGetValueAs( int row, int col, const wxString& typeName ); | |
240 | virtual bool CanSetValueAs( int row, int col, const wxString& typeName ); | |
241 | ||
242 | virtual long GetValueAsLong( int row, int col ); | |
243 | virtual bool GetValueAsBool( int row, int col ); | |
244 | ||
245 | virtual void SetValueAsLong( int row, int col, long value ); | |
246 | virtual void SetValueAsBool( int row, int col, bool value ); | |
247 | }; | |
248 | ||
35f97e95 VZ |
249 | class BugsGridFrame : public wxFrame |
250 | { | |
251 | public: | |
252 | BugsGridFrame(); | |
253 | }; | |
f97c9b5b | 254 | |
19d7140e | 255 | |
1618dca7 | 256 | #endif // griddemo_h |
e442cc0d | 257 |