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