rebaked everything, fixes problems with OpenGL samples makefiles
[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
111 enum
112 {
113 ID_TOGGLEROWLABELS = 100,
114 ID_TOGGLECOLLABELS,
115 ID_TOGGLEEDIT,
116 ID_TOGGLEROWSIZING,
117 ID_TOGGLECOLSIZING,
118 ID_TOGGLECOLMOVING,
119 ID_TOGGLEGRIDSIZING,
120 ID_TOGGLEGRIDDRAGCELL,
121 ID_TOGGLEGRIDLINES,
122 ID_AUTOSIZECOLS,
123 ID_CELLOVERFLOW,
124 ID_RESIZECELL,
125 ID_SETLABELCOLOUR,
126 ID_SETLABELTEXTCOLOUR,
127 ID_SETLABEL_FONT,
128 ID_ROWLABELALIGN,
129 ID_ROWLABELHORIZALIGN,
130 ID_ROWLABELVERTALIGN,
131 ID_COLLABELALIGN,
132 ID_COLLABELHORIZALIGN,
133 ID_COLLABELVERTALIGN,
134 ID_GRIDLINECOLOUR,
135 ID_INSERTROW,
136 ID_INSERTCOL,
137 ID_DELETEROW,
138 ID_DELETECOL,
139 ID_CLEARGRID,
140 ID_CHANGESEL,
141 ID_SELCELLS,
142 ID_SELROWS,
143 ID_SELCOLS,
144 ID_SET_CELL_FG_COLOUR,
145 ID_SET_CELL_BG_COLOUR,
146 ID_VTABLE,
147 ID_BUGS_TABLE,
148 ID_SMALL_GRID,
149 ID_SELECT_UNSELECT,
150 ID_SHOW_SELECTION,
151 ID_SELECT_ALL,
152 ID_SELECT_ROW,
153 ID_SELECT_COL,
154 ID_SELECT_CELL,
155 ID_DESELECT_ALL,
156 ID_DESELECT_ROW,
157 ID_DESELECT_COL,
158 ID_DESELECT_CELL,
159 ID_SIZE_ROW,
160 ID_SIZE_COL,
161 ID_SIZE_ROW_LABEL,
162 ID_SIZE_COL_LABEL,
163 ID_SIZE_LABELS_COL,
164 ID_SIZE_LABELS_ROW,
165 ID_SIZE_GRID,
166
167 ID_SET_HIGHLIGHT_WIDTH,
168 ID_SET_RO_HIGHLIGHT_WIDTH,
169
170 ID_TESTFUNC
171 };
172
173 #if wxUSE_LOG
174 wxLog *m_logOld;
175 #endif // wxUSE_LOG
176
177 // add the cells to selection when using commands from select menu?
178 bool m_addToSel;
179
180 DECLARE_EVENT_TABLE()
181 };
182
183 class MyGridCellRenderer : public wxGridCellStringRenderer
184 {
185 public:
186 virtual void Draw(wxGrid& grid,
187 wxGridCellAttr& attr,
188 wxDC& dc,
189 const wxRect& rect,
190 int row, int col,
191 bool isSelected);
192 };
193
194 // ----------------------------------------------------------------------------
195 // demonstration of virtual table which doesn't store all of its data in
196 // memory
197 // ----------------------------------------------------------------------------
198
199 class BigGridTable : public wxGridTableBase
200 {
201 public:
202 BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; }
203
204 int GetNumberRows() { return m_sizeGrid; }
205 int GetNumberCols() { return m_sizeGrid; }
206 wxString GetValue( int row, int col )
207 {
208 return wxString::Format(wxT("(%d, %d)"), row, col);
209 }
210
211 void SetValue( int , int , const wxString& ) { /* ignore */ }
212 bool IsEmptyCell( int , int ) { return false; }
213
214 private:
215 long m_sizeGrid;
216 };
217
218 class BigGridFrame : public wxFrame
219 {
220 public:
221 BigGridFrame(long sizeGrid);
222
223 private:
224 wxGrid* m_grid;
225 BigGridTable* m_table;
226 };
227
228 // ----------------------------------------------------------------------------
229 // an example of custom attr provider: this one makes all odd rows appear grey
230 // ----------------------------------------------------------------------------
231
232 class MyGridCellAttrProvider : public wxGridCellAttrProvider
233 {
234 public:
235 MyGridCellAttrProvider();
236 virtual ~MyGridCellAttrProvider();
237
238 virtual wxGridCellAttr *GetAttr(int row, int col,
239 wxGridCellAttr::wxAttrKind kind) const;
240
241 private:
242 wxGridCellAttr *m_attrForOddRows;
243 };
244
245 // ----------------------------------------------------------------------------
246 // another, more realistic, grid example: shows typed columns and more
247 // ----------------------------------------------------------------------------
248
249 class BugsGridTable : public wxGridTableBase
250 {
251 public:
252 BugsGridTable(){};
253
254 virtual int GetNumberRows();
255 virtual int GetNumberCols();
256 virtual bool IsEmptyCell( int row, int col );
257 virtual wxString GetValue( int row, int col );
258 virtual void SetValue( int row, int col, const wxString& value );
259
260 virtual wxString GetColLabelValue( int col );
261
262 virtual wxString GetTypeName( int row, int col );
263 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
264 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
265
266 virtual long GetValueAsLong( int row, int col );
267 virtual bool GetValueAsBool( int row, int col );
268
269 virtual void SetValueAsLong( int row, int col, long value );
270 virtual void SetValueAsBool( int row, int col, bool value );
271 };
272
273 class BugsGridFrame : public wxFrame
274 {
275 public:
276 BugsGridFrame();
277 };
278
279
280 #endif // griddemo_h
281