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