]> git.saurik.com Git - wxWidgets.git/blob - samples/grid/griddemo.h
Add test for Push/PopStatusText().
[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 license
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 ToggleNativeHeader ( wxCommandEvent& );
43 void ToggleGridLines( wxCommandEvent& );
44 void AutoSizeCols( wxCommandEvent& );
45 void CellOverflow( wxCommandEvent& );
46 void ResizeCell( wxCommandEvent& );
47 void SetLabelColour( wxCommandEvent& );
48 void SetLabelTextColour( wxCommandEvent& );
49 void SetLabelFont(wxCommandEvent &);
50 void SetRowLabelHorizAlignment( wxCommandEvent& );
51 void SetRowLabelVertAlignment( wxCommandEvent& );
52 void SetColLabelHorizAlignment( wxCommandEvent& );
53 void SetColLabelVertAlignment( wxCommandEvent& );
54 void SetGridLineColour( wxCommandEvent& );
55
56 void SetCellFgColour(wxCommandEvent &);
57 void SetCellBgColour(wxCommandEvent &);
58
59 void InsertRow( wxCommandEvent& );
60 void InsertCol( wxCommandEvent& );
61 void DeleteSelectedRows( wxCommandEvent& );
62 void DeleteSelectedCols( wxCommandEvent& );
63 void ClearGrid( wxCommandEvent& );
64 void SelectCells( wxCommandEvent& );
65 void SelectRows( wxCommandEvent& );
66 void SelectCols( wxCommandEvent& );
67 void SelectRowsOrCols( wxCommandEvent& );
68
69 void DeselectCell(wxCommandEvent& event);
70 void DeselectCol(wxCommandEvent& event);
71 void DeselectRow(wxCommandEvent& event);
72 void DeselectAll(wxCommandEvent& event);
73 void SelectCell(wxCommandEvent& event);
74 void SelectCol(wxCommandEvent& event);
75 void SelectRow(wxCommandEvent& event);
76 void SelectAll(wxCommandEvent& event);
77 void OnAddToSelectToggle(wxCommandEvent& event);
78 void OnShowSelection(wxCommandEvent& event);
79
80 void AutoSizeRow(wxCommandEvent& event);
81 void AutoSizeCol(wxCommandEvent& event);
82 void AutoSizeRowLabel(wxCommandEvent& event);
83 void AutoSizeColLabel(wxCommandEvent& event);
84 void AutoSizeLabelsCol(wxCommandEvent& event);
85 void AutoSizeLabelsRow(wxCommandEvent& event);
86 void AutoSizeTable(wxCommandEvent& event);
87
88 void OnLabelLeftClick( wxGridEvent& );
89 void OnCellLeftClick( wxGridEvent& );
90 void OnRowSize( wxGridSizeEvent& );
91 void OnColSize( wxGridSizeEvent& );
92 void OnSelectCell( wxGridEvent& );
93 void OnRangeSelected( wxGridRangeSelectEvent& );
94 void OnCellValueChanging( wxGridEvent& );
95 void OnCellValueChanged( wxGridEvent& );
96 void OnCellBeginDrag( wxGridEvent& );
97
98 void OnEditorShown(wxGridEvent&);
99 void OnEditorHidden(wxGridEvent&);
100
101 void OnSetHighlightWidth(wxCommandEvent&);
102 void OnSetROHighlightWidth(wxCommandEvent&);
103
104 public:
105 GridFrame();
106 ~GridFrame();
107
108 void OnQuit( wxCommandEvent& );
109 void About( wxCommandEvent& );
110 void OnVTable( wxCommandEvent& );
111 void OnBugsTable( wxCommandEvent& );
112 void OnTabularTable( wxCommandEvent& );
113
114 enum
115 {
116 ID_TOGGLEROWLABELS = 100,
117 ID_TOGGLECOLLABELS,
118 ID_TOGGLEEDIT,
119 ID_TOGGLEROWSIZING,
120 ID_TOGGLECOLSIZING,
121 ID_TOGGLECOLMOVING,
122 ID_TOGGLEGRIDSIZING,
123 ID_TOGGLEGRIDDRAGCELL,
124 ID_TOGGLENATIVEHEADER,
125 ID_TOGGLEGRIDLINES,
126 ID_AUTOSIZECOLS,
127 ID_CELLOVERFLOW,
128 ID_RESIZECELL,
129 ID_SETLABELCOLOUR,
130 ID_SETLABELTEXTCOLOUR,
131 ID_SETLABEL_FONT,
132 ID_ROWLABELALIGN,
133 ID_ROWLABELHORIZALIGN,
134 ID_ROWLABELVERTALIGN,
135 ID_COLLABELALIGN,
136 ID_COLLABELHORIZALIGN,
137 ID_COLLABELVERTALIGN,
138 ID_GRIDLINECOLOUR,
139 ID_INSERTROW,
140 ID_INSERTCOL,
141 ID_DELETEROW,
142 ID_DELETECOL,
143 ID_CLEARGRID,
144 ID_CHANGESEL,
145 ID_SELCELLS,
146 ID_SELROWS,
147 ID_SELCOLS,
148 ID_SELROWSORCOLS,
149 ID_SET_CELL_FG_COLOUR,
150 ID_SET_CELL_BG_COLOUR,
151 ID_VTABLE,
152 ID_BUGS_TABLE,
153 ID_TABULAR_TABLE,
154 ID_SELECT_UNSELECT,
155 ID_SHOW_SELECTION,
156 ID_SELECT_ALL,
157 ID_SELECT_ROW,
158 ID_SELECT_COL,
159 ID_SELECT_CELL,
160 ID_DESELECT_ALL,
161 ID_DESELECT_ROW,
162 ID_DESELECT_COL,
163 ID_DESELECT_CELL,
164 ID_SIZE_ROW,
165 ID_SIZE_COL,
166 ID_SIZE_ROW_LABEL,
167 ID_SIZE_COL_LABEL,
168 ID_SIZE_LABELS_COL,
169 ID_SIZE_LABELS_ROW,
170 ID_SIZE_GRID,
171
172 ID_SET_HIGHLIGHT_WIDTH,
173 ID_SET_RO_HIGHLIGHT_WIDTH,
174
175 ID_TESTFUNC
176 };
177
178 #if wxUSE_LOG
179 wxLog *m_logOld;
180 #endif // wxUSE_LOG
181
182 // add the cells to selection when using commands from select menu?
183 bool m_addToSel;
184
185 DECLARE_EVENT_TABLE()
186 };
187
188 class MyGridCellRenderer : public wxGridCellStringRenderer
189 {
190 public:
191 virtual void Draw(wxGrid& grid,
192 wxGridCellAttr& attr,
193 wxDC& dc,
194 const wxRect& rect,
195 int row, int col,
196 bool isSelected);
197 };
198
199 // ----------------------------------------------------------------------------
200 // demonstration of virtual table which doesn't store all of its data in
201 // memory
202 // ----------------------------------------------------------------------------
203
204 class BigGridTable : public wxGridTableBase
205 {
206 public:
207 BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; }
208
209 int GetNumberRows() { return m_sizeGrid; }
210 int GetNumberCols() { return m_sizeGrid; }
211 wxString GetValue( int row, int col )
212 {
213 return wxString::Format(wxT("(%d, %d)"), row, col);
214 }
215
216 void SetValue( int , int , const wxString& ) { /* ignore */ }
217 bool IsEmptyCell( int , int ) { return false; }
218
219 private:
220 long m_sizeGrid;
221 };
222
223 class BigGridFrame : public wxFrame
224 {
225 public:
226 BigGridFrame(long sizeGrid);
227
228 private:
229 wxGrid* m_grid;
230 BigGridTable* m_table;
231 };
232
233 // ----------------------------------------------------------------------------
234 // an example of custom attr provider: this one makes all odd rows appear grey
235 // ----------------------------------------------------------------------------
236
237 class MyGridCellAttrProvider : public wxGridCellAttrProvider
238 {
239 public:
240 MyGridCellAttrProvider();
241 virtual ~MyGridCellAttrProvider();
242
243 virtual wxGridCellAttr *GetAttr(int row, int col,
244 wxGridCellAttr::wxAttrKind kind) const;
245
246 private:
247 wxGridCellAttr *m_attrForOddRows;
248 };
249
250 // ----------------------------------------------------------------------------
251 // another, more realistic, grid example: shows typed columns and more
252 // ----------------------------------------------------------------------------
253
254 class BugsGridTable : public wxGridTableBase
255 {
256 public:
257 BugsGridTable() { }
258
259 virtual int GetNumberRows();
260 virtual int GetNumberCols();
261 virtual bool IsEmptyCell( int row, int col );
262 virtual wxString GetValue( int row, int col );
263 virtual void SetValue( int row, int col, const wxString& value );
264
265 virtual wxString GetColLabelValue( int col );
266
267 virtual wxString GetTypeName( int row, int col );
268 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
269 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
270
271 virtual long GetValueAsLong( int row, int col );
272 virtual bool GetValueAsBool( int row, int col );
273
274 virtual void SetValueAsLong( int row, int col, long value );
275 virtual void SetValueAsBool( int row, int col, bool value );
276 };
277
278 class BugsGridFrame : public wxFrame
279 {
280 public:
281 BugsGridFrame();
282 };
283
284
285 #endif // griddemo_h
286