]>
Commit | Line | Data |
---|---|---|
f7556ff0 JS |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: griddemo.h | |
be5a51fb | 3 | // Purpose: Grid control wxWidgets sample |
f7556ff0 JS |
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 | ||
f7556ff0 JS |
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; | |
f07941fc | 27 | #if wxUSE_LOG |
f7556ff0 JS |
28 | wxTextCtrl *logWin; |
29 | wxLogTextCtrl *logger; | |
f07941fc | 30 | #endif // wxUSE_LOG |
f7556ff0 JS |
31 | wxString logBuf; |
32 | ||
33 | void SetDefaults(); | |
34 | ||
35 | void ToggleRowLabels( wxCommandEvent& ); | |
36 | void ToggleColLabels( wxCommandEvent& ); | |
37 | void ToggleEditing( wxCommandEvent& ); | |
38 | void ToggleRowSizing( wxCommandEvent& ); | |
39 | void ToggleColSizing( wxCommandEvent& ); | |
40 | void ToggleGridSizing( wxCommandEvent& ); | |
41 | void ToggleGridLines( wxCommandEvent& ); | |
42 | void AutoSizeCols( wxCommandEvent& ); | |
43 | void CellOverflow( wxCommandEvent& ); | |
44 | void ResizeCell( 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 | void OnSmallGrid( wxCommandEvent& ); | |
99 | ||
100 | enum | |
101 | { | |
102 | ID_TOGGLEROWLABELS = 100, | |
103 | ID_TOGGLECOLLABELS, | |
104 | ID_TOGGLEEDIT, | |
105 | ID_TOGGLEROWSIZING, | |
106 | ID_TOGGLECOLSIZING, | |
107 | ID_TOGGLEGRIDSIZING, | |
108 | ID_TOGGLEGRIDLINES, | |
109 | ID_AUTOSIZECOLS, | |
110 | ID_CELLOVERFLOW, | |
111 | ID_RESIZECELL, | |
112 | ID_SETLABELCOLOUR, | |
113 | ID_SETLABELTEXTCOLOUR, | |
114 | ID_SETLABEL_FONT, | |
115 | ID_ROWLABELALIGN, | |
116 | ID_ROWLABELHORIZALIGN, | |
117 | ID_ROWLABELVERTALIGN, | |
118 | ID_COLLABELALIGN, | |
119 | ID_COLLABELHORIZALIGN, | |
120 | ID_COLLABELVERTALIGN, | |
121 | ID_GRIDLINECOLOUR, | |
122 | ID_INSERTROW, | |
123 | ID_INSERTCOL, | |
124 | ID_DELETEROW, | |
125 | ID_DELETECOL, | |
126 | ID_CLEARGRID, | |
127 | ID_CHANGESEL, | |
128 | ID_SELCELLS, | |
129 | ID_SELROWS, | |
130 | ID_SELCOLS, | |
131 | ID_SET_CELL_FG_COLOUR, | |
132 | ID_SET_CELL_BG_COLOUR, | |
133 | ID_ABOUT, | |
134 | ID_VTABLE, | |
135 | ID_BUGS_TABLE, | |
136 | ID_SMALL_GRID, | |
137 | ID_SELECT_UNSELECT, | |
138 | ID_SELECT_ALL, | |
139 | ID_SELECT_ROW, | |
140 | ID_SELECT_COL, | |
141 | ID_SELECT_CELL, | |
142 | ID_DESELECT_ALL, | |
143 | ID_DESELECT_ROW, | |
144 | ID_DESELECT_COL, | |
145 | ID_DESELECT_CELL, | |
146 | ||
147 | ID_SET_HIGHLIGHT_WIDTH, | |
148 | ID_SET_RO_HIGHLIGHT_WIDTH, | |
149 | ||
150 | ID_TESTFUNC | |
151 | }; | |
152 | ||
f07941fc | 153 | #if wxUSE_LOG |
f7556ff0 | 154 | wxLog *m_logOld; |
f07941fc | 155 | #endif // wxUSE_LOG |
f7556ff0 JS |
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 */ } | |
af870ed8 | 192 | bool IsEmptyCell( int , int ) { return false; } |
f7556ff0 JS |
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 |