]> git.saurik.com Git - wxWidgets.git/blame - samples/grid/griddemo.h
Exclude zlib 3rd party sources from our checks too.
[wxWidgets.git] / samples / grid / griddemo.h
CommitLineData
f7556ff0
JS
1/////////////////////////////////////////////////////////////////////////////
2// Name: griddemo.h
be5a51fb 3// Purpose: Grid control wxWidgets sample
f7556ff0
JS
4// Author: Michael Bedward
5// Modified by:
f7556ff0 6// Copyright: (c) Michael Bedward, Julian Smart
526954c5 7// Licence: wxWindows licence
f7556ff0
JS
8/////////////////////////////////////////////////////////////////////////////
9
10
11#ifndef griddemo_h
12#define griddemo_h
13
f7556ff0
JS
14class wxGrid;
15
16class GridApp : public wxApp
17{
18public:
19 bool OnInit();
20};
21
22
23class GridFrame : public wxFrame
24{
25 wxGrid *grid;
f07941fc 26#if wxUSE_LOG
f7556ff0
JS
27 wxTextCtrl *logWin;
28 wxLogTextCtrl *logger;
f07941fc 29#endif // wxUSE_LOG
f7556ff0
JS
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& );
d4175745 38 void ToggleColMoving( wxCommandEvent& );
f7556ff0 39 void ToggleGridSizing( wxCommandEvent& );
79dbea21 40 void ToggleGridDragCell ( wxCommandEvent& );
ba9574c3
VZ
41 void SetNativeColHeader ( wxCommandEvent& );
42 void SetCustomColHeader( wxCommandEvent& );
43 void SetDefaultColHeader( wxCommandEvent& );
1dc17bca
VZ
44 void SetTabBehaviour( wxCommandEvent& );
45 void SetTabCustomHandler( wxCommandEvent& );
f7556ff0
JS
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& );
8a3e536c 70 void SelectRowsOrCols( wxCommandEvent& );
f7556ff0
JS
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
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
2328f468
VZ
90 void HideCol(wxCommandEvent& event);
91 void ShowCol(wxCommandEvent& event);
92 void HideRow(wxCommandEvent& event);
93 void ShowRow(wxCommandEvent& event);
94
95
f7556ff0
JS
96 void OnLabelLeftClick( wxGridEvent& );
97 void OnCellLeftClick( wxGridEvent& );
98 void OnRowSize( wxGridSizeEvent& );
99 void OnColSize( wxGridSizeEvent& );
6f58f3d7 100 void OnColAutoSize( wxGridSizeEvent& );
f7556ff0
JS
101 void OnSelectCell( wxGridEvent& );
102 void OnRangeSelected( wxGridRangeSelectEvent& );
763163a8 103 void OnCellValueChanging( wxGridEvent& );
f7556ff0 104 void OnCellValueChanged( wxGridEvent& );
79dbea21 105 void OnCellBeginDrag( wxGridEvent& );
f7556ff0
JS
106
107 void OnEditorShown(wxGridEvent&);
108 void OnEditorHidden(wxGridEvent&);
109
110 void OnSetHighlightWidth(wxCommandEvent&);
111 void OnSetROHighlightWidth(wxCommandEvent&);
112
1dc17bca
VZ
113 void OnGridCustomTab(wxGridEvent& event);
114
f7556ff0
JS
115public:
116 GridFrame();
117 ~GridFrame();
118
119 void OnQuit( wxCommandEvent& );
120 void About( wxCommandEvent& );
121 void OnVTable( wxCommandEvent& );
122 void OnBugsTable( wxCommandEvent& );
e7ae8a69 123 void OnTabularTable( wxCommandEvent& );
779e28da
VZ
124 void OnGridRender( wxCommandEvent& event );
125 void OnRenderPaint( wxPaintEvent& event );
f7556ff0
JS
126
127 enum
128 {
129 ID_TOGGLEROWLABELS = 100,
130 ID_TOGGLECOLLABELS,
131 ID_TOGGLEEDIT,
132 ID_TOGGLEROWSIZING,
133 ID_TOGGLECOLSIZING,
d4175745 134 ID_TOGGLECOLMOVING,
f7556ff0 135 ID_TOGGLEGRIDSIZING,
79dbea21 136 ID_TOGGLEGRIDDRAGCELL,
f7556ff0
JS
137 ID_TOGGLEGRIDLINES,
138 ID_AUTOSIZECOLS,
139 ID_CELLOVERFLOW,
2328f468
VZ
140 ID_HIDECOL,
141 ID_SHOWCOL,
142 ID_HIDEROW,
143 ID_SHOWROW,
f7556ff0
JS
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,
ba9574c3
VZ
154 ID_COLDEFAULTHEADER,
155 ID_COLNATIVEHEADER,
156 ID_COLCUSTOMHEADER,
1dc17bca
VZ
157 ID_TAB_STOP,
158 ID_TAB_WRAP,
159 ID_TAB_LEAVE,
160 ID_TAB_CUSTOM,
f7556ff0
JS
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,
8a3e536c 171 ID_SELROWSORCOLS,
f7556ff0
JS
172 ID_SET_CELL_FG_COLOUR,
173 ID_SET_CELL_BG_COLOUR,
f7556ff0
JS
174 ID_VTABLE,
175 ID_BUGS_TABLE,
e7ae8a69 176 ID_TABULAR_TABLE,
f7556ff0
JS
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,
733f486a
VZ
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,
f7556ff0
JS
193
194 ID_SET_HIGHLIGHT_WIDTH,
195 ID_SET_RO_HIGHLIGHT_WIDTH,
196
779e28da
VZ
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,
f7556ff0
JS
209 };
210
f07941fc 211#if wxUSE_LOG
f7556ff0 212 wxLog *m_logOld;
f07941fc 213#endif // wxUSE_LOG
f7556ff0
JS
214
215 // add the cells to selection when using commands from select menu?
216 bool m_addToSel;
217
779e28da
VZ
218 wxBitmap m_gridBitmap;
219
f7556ff0
JS
220 DECLARE_EVENT_TABLE()
221};
222
223class MyGridCellRenderer : public wxGridCellStringRenderer
224{
225public:
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
239class BigGridTable : public wxGridTableBase
240{
241public:
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 */ }
af870ed8 252 bool IsEmptyCell( int , int ) { return false; }
f7556ff0
JS
253
254private:
255 long m_sizeGrid;
256};
257
258class BigGridFrame : public wxFrame
259{
260public:
261 BigGridFrame(long sizeGrid);
262
263private:
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
272class MyGridCellAttrProvider : public wxGridCellAttrProvider
273{
274public:
275 MyGridCellAttrProvider();
276 virtual ~MyGridCellAttrProvider();
277
278 virtual wxGridCellAttr *GetAttr(int row, int col,
279 wxGridCellAttr::wxAttrKind kind) const;
280
281private:
282 wxGridCellAttr *m_attrForOddRows;
283};
284
285// ----------------------------------------------------------------------------
286// another, more realistic, grid example: shows typed columns and more
287// ----------------------------------------------------------------------------
288
289class BugsGridTable : public wxGridTableBase
290{
291public:
e7ae8a69 292 BugsGridTable() { }
f7556ff0
JS
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
313class BugsGridFrame : public wxFrame
314{
315public:
316 BugsGridFrame();
317};
318
319
320#endif // griddemo_h
321