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