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