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