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