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