]> git.saurik.com Git - wxWidgets.git/blob - samples/newgrid/griddemo.h
b450ef6e00d8e445cab60d5e7f15fc952ac5071c
[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 SetRowLabelHorizAlignment( wxCommandEvent& );
48 void SetRowLabelVertAlignment( wxCommandEvent& );
49 void SetColLabelHorizAlignment( wxCommandEvent& );
50 void SetColLabelVertAlignment( wxCommandEvent& );
51 void SetGridLineColour( wxCommandEvent& );
52
53 void SetCellFgColour(wxCommandEvent &);
54 void SetCellBgColour(wxCommandEvent &);
55
56 void InsertRow( wxCommandEvent& );
57 void InsertCol( wxCommandEvent& );
58 void DeleteSelectedRows( wxCommandEvent& );
59 void DeleteSelectedCols( wxCommandEvent& );
60 void ClearGrid( wxCommandEvent& );
61 void SelectCells( wxCommandEvent& );
62 void SelectRows( wxCommandEvent& );
63 void SelectCols( wxCommandEvent& );
64
65 void DeselectCell(wxCommandEvent& event);
66 void DeselectCol(wxCommandEvent& event);
67 void DeselectRow(wxCommandEvent& event);
68 void DeselectAll(wxCommandEvent& event);
69 void SelectCell(wxCommandEvent& event);
70 void SelectCol(wxCommandEvent& event);
71 void SelectRow(wxCommandEvent& event);
72 void SelectAll(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 public:
86 GridFrame();
87 ~GridFrame();
88
89 void OnQuit( wxCommandEvent& );
90 void About( wxCommandEvent& );
91 void OnVTable( wxCommandEvent& );
92 void OnBugsTable( wxCommandEvent& );
93
94 enum
95 {
96 ID_TOGGLEROWLABELS = 100,
97 ID_TOGGLECOLLABELS,
98 ID_TOGGLEEDIT,
99 ID_TOGGLEROWSIZING,
100 ID_TOGGLECOLSIZING,
101 ID_TOGGLEGRIDSIZING,
102 ID_TOGGLEGRIDLINES,
103 ID_AUTOSIZECOLS,
104 ID_SETLABELCOLOUR,
105 ID_SETLABELTEXTCOLOUR,
106 ID_ROWLABELALIGN,
107 ID_ROWLABELHORIZALIGN,
108 ID_ROWLABELVERTALIGN,
109 ID_COLLABELALIGN,
110 ID_COLLABELHORIZALIGN,
111 ID_COLLABELVERTALIGN,
112 ID_GRIDLINECOLOUR,
113 ID_INSERTROW,
114 ID_INSERTCOL,
115 ID_DELETEROW,
116 ID_DELETECOL,
117 ID_CLEARGRID,
118 ID_CHANGESEL,
119 ID_SELCELLS,
120 ID_SELROWS,
121 ID_SELCOLS,
122 ID_SET_CELL_FG_COLOUR,
123 ID_SET_CELL_BG_COLOUR,
124 ID_ABOUT,
125 ID_VTABLE,
126 ID_BUGS_TABLE,
127 ID_SELECT_ALL,
128 ID_SELECT_ROW,
129 ID_SELECT_COL,
130 ID_SELECT_CELL,
131 ID_DESELECT_ALL,
132 ID_DESELECT_ROW,
133 ID_DESELECT_COL,
134 ID_DESELECT_CELL,
135
136 ID_TESTFUNC
137 };
138
139 wxLog *m_logOld;
140
141 DECLARE_EVENT_TABLE()
142 };
143
144 class MyGridCellRenderer : public wxGridCellStringRenderer
145 {
146 public:
147 virtual void Draw(wxGrid& grid,
148 wxGridCellAttr& attr,
149 wxDC& dc,
150 const wxRect& rect,
151 int row, int col,
152 bool isSelected);
153 };
154
155 // ----------------------------------------------------------------------------
156 // demonstration of virtual table which doesn't store all of its data in
157 // memory
158 // ----------------------------------------------------------------------------
159
160 class BigGridTable : public wxGridTableBase
161 {
162 public:
163 BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; }
164
165 int GetNumberRows() { return m_sizeGrid; }
166 int GetNumberCols() { return m_sizeGrid; }
167 wxString GetValue( int row, int col )
168 {
169 return wxString::Format("(%d, %d)", row, col);
170 }
171
172 void SetValue( int , int , const wxString& ) { /* ignore */ }
173 bool IsEmptyCell( int , int ) { return FALSE; }
174
175 private:
176 long m_sizeGrid;
177 };
178
179 class BigGridFrame : public wxFrame
180 {
181 public:
182 BigGridFrame(long sizeGrid);
183
184 private:
185 wxGrid* m_grid;
186 BigGridTable* m_table;
187 };
188
189 // ----------------------------------------------------------------------------
190 // an example of custom attr provider: this one makes all odd rows appear grey
191 // ----------------------------------------------------------------------------
192
193 class MyGridCellAttrProvider : public wxGridCellAttrProvider
194 {
195 public:
196 MyGridCellAttrProvider();
197 virtual ~MyGridCellAttrProvider();
198
199 virtual wxGridCellAttr *GetAttr(int row, int col) const;
200
201 private:
202 wxGridCellAttr *m_attrForOddRows;
203 };
204
205 // ----------------------------------------------------------------------------
206 // another, more realistic, grid example: shows typed columns and more
207 // ----------------------------------------------------------------------------
208
209 class BugsGridTable : public wxGridTableBase
210 {
211 public:
212 BugsGridTable();
213
214 virtual int GetNumberRows();
215 virtual int GetNumberCols();
216 virtual bool IsEmptyCell( int row, int col );
217 virtual wxString GetValue( int row, int col );
218 virtual void SetValue( int row, int col, const wxString& value );
219
220 virtual wxString GetColLabelValue( int col );
221
222 virtual wxString GetTypeName( int row, int col );
223 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
224 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
225
226 virtual long GetValueAsLong( int row, int col );
227 virtual bool GetValueAsBool( int row, int col );
228
229 virtual void SetValueAsLong( int row, int col, long value );
230 virtual void SetValueAsBool( int row, int col, bool value );
231 };
232
233 class BugsGridFrame : public wxFrame
234 {
235 public:
236 BugsGridFrame();
237 };
238
239 #endif // griddemo_h
240