]>
Commit | Line | Data |
---|---|---|
f7556ff0 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: griddemo.h | |
be5a51fb | 3 | // Purpose: Grid control wxWidgets sample |
f7556ff0 JS |
4 | // Author: Michael Bedward |
5 | // Modified by: | |
6 | // RCS-ID: $Id$ | |
7 | // Copyright: (c) Michael Bedward, Julian Smart | |
8 | // Licence: wxWindows license | |
9 | ///////////////////////////////////////////////////////////////////////////// | |
10 | ||
11 | ||
12 | #ifndef griddemo_h | |
13 | #define griddemo_h | |
14 | ||
f7556ff0 JS |
15 | class wxGrid; |
16 | ||
17 | class GridApp : public wxApp | |
18 | { | |
19 | public: | |
20 | bool OnInit(); | |
21 | }; | |
22 | ||
23 | ||
24 | class GridFrame : public wxFrame | |
25 | { | |
26 | wxGrid *grid; | |
f07941fc | 27 | #if wxUSE_LOG |
f7556ff0 JS |
28 | wxTextCtrl *logWin; |
29 | wxLogTextCtrl *logger; | |
f07941fc | 30 | #endif // wxUSE_LOG |
f7556ff0 JS |
31 | |
32 | void SetDefaults(); | |
33 | ||
34 | void ToggleRowLabels( wxCommandEvent& ); | |
35 | void ToggleColLabels( wxCommandEvent& ); | |
36 | void ToggleEditing( wxCommandEvent& ); | |
37 | void ToggleRowSizing( wxCommandEvent& ); | |
38 | void ToggleColSizing( wxCommandEvent& ); | |
d4175745 | 39 | void ToggleColMoving( wxCommandEvent& ); |
f7556ff0 | 40 | void ToggleGridSizing( wxCommandEvent& ); |
79dbea21 | 41 | void ToggleGridDragCell ( wxCommandEvent& ); |
ba9574c3 VZ |
42 | void SetNativeColHeader ( wxCommandEvent& ); |
43 | void SetCustomColHeader( wxCommandEvent& ); | |
44 | void SetDefaultColHeader( wxCommandEvent& ); | |
f7556ff0 JS |
45 | void ToggleGridLines( wxCommandEvent& ); |
46 | void AutoSizeCols( wxCommandEvent& ); | |
47 | void CellOverflow( wxCommandEvent& ); | |
48 | void ResizeCell( wxCommandEvent& ); | |
49 | void SetLabelColour( wxCommandEvent& ); | |
50 | void SetLabelTextColour( wxCommandEvent& ); | |
51 | void SetLabelFont(wxCommandEvent &); | |
52 | void SetRowLabelHorizAlignment( wxCommandEvent& ); | |
53 | void SetRowLabelVertAlignment( wxCommandEvent& ); | |
54 | void SetColLabelHorizAlignment( wxCommandEvent& ); | |
55 | void SetColLabelVertAlignment( wxCommandEvent& ); | |
56 | void SetGridLineColour( wxCommandEvent& ); | |
57 | ||
58 | void SetCellFgColour(wxCommandEvent &); | |
59 | void SetCellBgColour(wxCommandEvent &); | |
60 | ||
61 | void InsertRow( wxCommandEvent& ); | |
62 | void InsertCol( wxCommandEvent& ); | |
63 | void DeleteSelectedRows( wxCommandEvent& ); | |
64 | void DeleteSelectedCols( wxCommandEvent& ); | |
65 | void ClearGrid( wxCommandEvent& ); | |
66 | void SelectCells( wxCommandEvent& ); | |
67 | void SelectRows( wxCommandEvent& ); | |
68 | void SelectCols( wxCommandEvent& ); | |
8a3e536c | 69 | void SelectRowsOrCols( wxCommandEvent& ); |
f7556ff0 JS |
70 | |
71 | void DeselectCell(wxCommandEvent& event); | |
72 | void DeselectCol(wxCommandEvent& event); | |
73 | void DeselectRow(wxCommandEvent& event); | |
74 | void DeselectAll(wxCommandEvent& event); | |
75 | void SelectCell(wxCommandEvent& event); | |
76 | void SelectCol(wxCommandEvent& event); | |
77 | void SelectRow(wxCommandEvent& event); | |
78 | void SelectAll(wxCommandEvent& event); | |
79 | void OnAddToSelectToggle(wxCommandEvent& event); | |
1ecf2613 | 80 | void OnShowSelection(wxCommandEvent& event); |
f7556ff0 | 81 | |
733f486a VZ |
82 | void AutoSizeRow(wxCommandEvent& event); |
83 | void AutoSizeCol(wxCommandEvent& event); | |
84 | void AutoSizeRowLabel(wxCommandEvent& event); | |
85 | void AutoSizeColLabel(wxCommandEvent& event); | |
86 | void AutoSizeLabelsCol(wxCommandEvent& event); | |
87 | void AutoSizeLabelsRow(wxCommandEvent& event); | |
88 | void AutoSizeTable(wxCommandEvent& event); | |
89 | ||
f7556ff0 JS |
90 | void OnLabelLeftClick( wxGridEvent& ); |
91 | void OnCellLeftClick( wxGridEvent& ); | |
92 | void OnRowSize( wxGridSizeEvent& ); | |
93 | void OnColSize( wxGridSizeEvent& ); | |
94 | void OnSelectCell( wxGridEvent& ); | |
95 | void OnRangeSelected( wxGridRangeSelectEvent& ); | |
763163a8 | 96 | void OnCellValueChanging( wxGridEvent& ); |
f7556ff0 | 97 | void OnCellValueChanged( wxGridEvent& ); |
79dbea21 | 98 | void OnCellBeginDrag( wxGridEvent& ); |
f7556ff0 JS |
99 | |
100 | void OnEditorShown(wxGridEvent&); | |
101 | void OnEditorHidden(wxGridEvent&); | |
102 | ||
103 | void OnSetHighlightWidth(wxCommandEvent&); | |
104 | void OnSetROHighlightWidth(wxCommandEvent&); | |
105 | ||
106 | public: | |
107 | GridFrame(); | |
108 | ~GridFrame(); | |
109 | ||
110 | void OnQuit( wxCommandEvent& ); | |
111 | void About( wxCommandEvent& ); | |
112 | void OnVTable( wxCommandEvent& ); | |
113 | void OnBugsTable( wxCommandEvent& ); | |
e7ae8a69 | 114 | void OnTabularTable( wxCommandEvent& ); |
f7556ff0 JS |
115 | |
116 | enum | |
117 | { | |
118 | ID_TOGGLEROWLABELS = 100, | |
119 | ID_TOGGLECOLLABELS, | |
120 | ID_TOGGLEEDIT, | |
121 | ID_TOGGLEROWSIZING, | |
122 | ID_TOGGLECOLSIZING, | |
d4175745 | 123 | ID_TOGGLECOLMOVING, |
f7556ff0 | 124 | ID_TOGGLEGRIDSIZING, |
79dbea21 | 125 | ID_TOGGLEGRIDDRAGCELL, |
f7556ff0 JS |
126 | ID_TOGGLEGRIDLINES, |
127 | ID_AUTOSIZECOLS, | |
128 | ID_CELLOVERFLOW, | |
129 | ID_RESIZECELL, | |
130 | ID_SETLABELCOLOUR, | |
131 | ID_SETLABELTEXTCOLOUR, | |
132 | ID_SETLABEL_FONT, | |
133 | ID_ROWLABELALIGN, | |
134 | ID_ROWLABELHORIZALIGN, | |
135 | ID_ROWLABELVERTALIGN, | |
136 | ID_COLLABELALIGN, | |
137 | ID_COLLABELHORIZALIGN, | |
138 | ID_COLLABELVERTALIGN, | |
ba9574c3 VZ |
139 | ID_COLDEFAULTHEADER, |
140 | ID_COLNATIVEHEADER, | |
141 | ID_COLCUSTOMHEADER, | |
f7556ff0 JS |
142 | ID_GRIDLINECOLOUR, |
143 | ID_INSERTROW, | |
144 | ID_INSERTCOL, | |
145 | ID_DELETEROW, | |
146 | ID_DELETECOL, | |
147 | ID_CLEARGRID, | |
148 | ID_CHANGESEL, | |
149 | ID_SELCELLS, | |
150 | ID_SELROWS, | |
151 | ID_SELCOLS, | |
8a3e536c | 152 | ID_SELROWSORCOLS, |
f7556ff0 JS |
153 | ID_SET_CELL_FG_COLOUR, |
154 | ID_SET_CELL_BG_COLOUR, | |
f7556ff0 JS |
155 | ID_VTABLE, |
156 | ID_BUGS_TABLE, | |
e7ae8a69 | 157 | ID_TABULAR_TABLE, |
f7556ff0 | 158 | ID_SELECT_UNSELECT, |
1ecf2613 | 159 | ID_SHOW_SELECTION, |
f7556ff0 JS |
160 | ID_SELECT_ALL, |
161 | ID_SELECT_ROW, | |
162 | ID_SELECT_COL, | |
163 | ID_SELECT_CELL, | |
164 | ID_DESELECT_ALL, | |
165 | ID_DESELECT_ROW, | |
166 | ID_DESELECT_COL, | |
167 | ID_DESELECT_CELL, | |
733f486a VZ |
168 | ID_SIZE_ROW, |
169 | ID_SIZE_COL, | |
170 | ID_SIZE_ROW_LABEL, | |
171 | ID_SIZE_COL_LABEL, | |
172 | ID_SIZE_LABELS_COL, | |
173 | ID_SIZE_LABELS_ROW, | |
174 | ID_SIZE_GRID, | |
f7556ff0 JS |
175 | |
176 | ID_SET_HIGHLIGHT_WIDTH, | |
177 | ID_SET_RO_HIGHLIGHT_WIDTH, | |
178 | ||
179 | ID_TESTFUNC | |
180 | }; | |
181 | ||
f07941fc | 182 | #if wxUSE_LOG |
f7556ff0 | 183 | wxLog *m_logOld; |
f07941fc | 184 | #endif // wxUSE_LOG |
f7556ff0 JS |
185 | |
186 | // add the cells to selection when using commands from select menu? | |
187 | bool m_addToSel; | |
188 | ||
189 | DECLARE_EVENT_TABLE() | |
190 | }; | |
191 | ||
192 | class MyGridCellRenderer : public wxGridCellStringRenderer | |
193 | { | |
194 | public: | |
195 | virtual void Draw(wxGrid& grid, | |
196 | wxGridCellAttr& attr, | |
197 | wxDC& dc, | |
198 | const wxRect& rect, | |
199 | int row, int col, | |
200 | bool isSelected); | |
201 | }; | |
202 | ||
203 | // ---------------------------------------------------------------------------- | |
204 | // demonstration of virtual table which doesn't store all of its data in | |
205 | // memory | |
206 | // ---------------------------------------------------------------------------- | |
207 | ||
208 | class BigGridTable : public wxGridTableBase | |
209 | { | |
210 | public: | |
211 | BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; } | |
212 | ||
213 | int GetNumberRows() { return m_sizeGrid; } | |
214 | int GetNumberCols() { return m_sizeGrid; } | |
215 | wxString GetValue( int row, int col ) | |
216 | { | |
217 | return wxString::Format(wxT("(%d, %d)"), row, col); | |
218 | } | |
219 | ||
220 | void SetValue( int , int , const wxString& ) { /* ignore */ } | |
af870ed8 | 221 | bool IsEmptyCell( int , int ) { return false; } |
f7556ff0 JS |
222 | |
223 | private: | |
224 | long m_sizeGrid; | |
225 | }; | |
226 | ||
227 | class BigGridFrame : public wxFrame | |
228 | { | |
229 | public: | |
230 | BigGridFrame(long sizeGrid); | |
231 | ||
232 | private: | |
233 | wxGrid* m_grid; | |
234 | BigGridTable* m_table; | |
235 | }; | |
236 | ||
237 | // ---------------------------------------------------------------------------- | |
238 | // an example of custom attr provider: this one makes all odd rows appear grey | |
239 | // ---------------------------------------------------------------------------- | |
240 | ||
241 | class MyGridCellAttrProvider : public wxGridCellAttrProvider | |
242 | { | |
243 | public: | |
244 | MyGridCellAttrProvider(); | |
245 | virtual ~MyGridCellAttrProvider(); | |
246 | ||
247 | virtual wxGridCellAttr *GetAttr(int row, int col, | |
248 | wxGridCellAttr::wxAttrKind kind) const; | |
249 | ||
250 | private: | |
251 | wxGridCellAttr *m_attrForOddRows; | |
252 | }; | |
253 | ||
254 | // ---------------------------------------------------------------------------- | |
255 | // another, more realistic, grid example: shows typed columns and more | |
256 | // ---------------------------------------------------------------------------- | |
257 | ||
258 | class BugsGridTable : public wxGridTableBase | |
259 | { | |
260 | public: | |
e7ae8a69 | 261 | BugsGridTable() { } |
f7556ff0 JS |
262 | |
263 | virtual int GetNumberRows(); | |
264 | virtual int GetNumberCols(); | |
265 | virtual bool IsEmptyCell( int row, int col ); | |
266 | virtual wxString GetValue( int row, int col ); | |
267 | virtual void SetValue( int row, int col, const wxString& value ); | |
268 | ||
269 | virtual wxString GetColLabelValue( int col ); | |
270 | ||
271 | virtual wxString GetTypeName( int row, int col ); | |
272 | virtual bool CanGetValueAs( int row, int col, const wxString& typeName ); | |
273 | virtual bool CanSetValueAs( int row, int col, const wxString& typeName ); | |
274 | ||
275 | virtual long GetValueAsLong( int row, int col ); | |
276 | virtual bool GetValueAsBool( int row, int col ); | |
277 | ||
278 | virtual void SetValueAsLong( int row, int col, long value ); | |
279 | virtual void SetValueAsBool( int row, int col, bool value ); | |
280 | }; | |
281 | ||
282 | class BugsGridFrame : public wxFrame | |
283 | { | |
284 | public: | |
285 | BugsGridFrame(); | |
286 | }; | |
287 | ||
288 | ||
289 | #endif // griddemo_h | |
290 |