]>
Commit | Line | Data |
---|---|---|
10434f3c MB |
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 | ///////////////////////////////////////////////////////////////////////////// | |
e442cc0d MB |
10 | |
11 | ||
12 | #ifndef griddemo_h | |
13 | #define griddemo_h | |
14 | ||
b99be8fb VZ |
15 | #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID) |
16 | #error "This sample requires the new wxGrid class." | |
17 | #endif | |
e442cc0d MB |
18 | |
19 | class wxGrid; | |
20 | ||
21 | class GridApp : public wxApp | |
22 | { | |
ab79958a | 23 | public: |
e442cc0d MB |
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(); | |
f445b853 | 36 | |
e442cc0d MB |
37 | void ToggleRowLabels( wxCommandEvent& ); |
38 | void ToggleColLabels( wxCommandEvent& ); | |
f445b853 | 39 | void ToggleEditing( wxCommandEvent& ); |
dd16fdae MB |
40 | void ToggleRowSizing( wxCommandEvent& ); |
41 | void ToggleColSizing( wxCommandEvent& ); | |
4cfa5de6 | 42 | void ToggleGridSizing( wxCommandEvent& ); |
e442cc0d MB |
43 | void SetLabelColour( wxCommandEvent& ); |
44 | void SetLabelTextColour( wxCommandEvent& ); | |
45 | void SetRowLabelHorizAlignment( wxCommandEvent& ); | |
46 | void SetRowLabelVertAlignment( wxCommandEvent& ); | |
47 | void SetColLabelHorizAlignment( wxCommandEvent& ); | |
48 | void SetColLabelVertAlignment( wxCommandEvent& ); | |
49 | void SetGridLineColour( wxCommandEvent& ); | |
0eee5283 | 50 | |
ab79958a VZ |
51 | void SetCellFgColour(wxCommandEvent &); |
52 | void SetCellBgColour(wxCommandEvent &); | |
53 | ||
b99be8fb VZ |
54 | void InsertRow( wxCommandEvent& ); |
55 | void InsertCol( wxCommandEvent& ); | |
56 | void DeleteSelectedRows( wxCommandEvent& ); | |
57 | void DeleteSelectedCols( wxCommandEvent& ); | |
e442cc0d | 58 | void ClearGrid( wxCommandEvent& ); |
043d16b2 SN |
59 | void SelectCells( wxCommandEvent& ); |
60 | void SelectRows( wxCommandEvent& ); | |
61 | void SelectCols( wxCommandEvent& ); | |
e442cc0d | 62 | |
e442cc0d MB |
63 | void OnLabelLeftClick( wxGridEvent& ); |
64 | void OnCellLeftClick( wxGridEvent& ); | |
65 | void OnRowSize( wxGridSizeEvent& ); | |
66 | void OnColSize( wxGridSizeEvent& ); | |
c336585e | 67 | void OnSelectCell( wxGridEvent& ); |
e442cc0d MB |
68 | void OnRangeSelected( wxGridRangeSelectEvent& ); |
69 | void OnCellValueChanged( wxGridEvent& ); | |
b99be8fb | 70 | |
b54ba671 VZ |
71 | void OnEditorShown(wxGridEvent&); |
72 | void OnEditorHidden(wxGridEvent&); | |
73 | ||
ab79958a | 74 | public: |
e442cc0d MB |
75 | GridFrame(); |
76 | ~GridFrame(); | |
77 | ||
e442cc0d | 78 | void OnQuit( wxCommandEvent& ); |
f445b853 | 79 | void About( wxCommandEvent& ); |
f97c9b5b | 80 | void OnVTable( wxCommandEvent& ); |
35f97e95 | 81 | void OnBugsTable( wxCommandEvent& ); |
e442cc0d | 82 | |
ab79958a VZ |
83 | enum |
84 | { | |
85 | ID_TOGGLEROWLABELS = 100, | |
86 | ID_TOGGLECOLLABELS, | |
87 | ID_TOGGLEEDIT, | |
dd16fdae MB |
88 | ID_TOGGLEROWSIZING, |
89 | ID_TOGGLECOLSIZING, | |
4cfa5de6 | 90 | ID_TOGGLEGRIDSIZING, |
ab79958a VZ |
91 | ID_SETLABELCOLOUR, |
92 | ID_SETLABELTEXTCOLOUR, | |
93 | ID_ROWLABELALIGN, | |
94 | ID_ROWLABELHORIZALIGN, | |
95 | ID_ROWLABELVERTALIGN, | |
96 | ID_COLLABELALIGN, | |
97 | ID_COLLABELHORIZALIGN, | |
98 | ID_COLLABELVERTALIGN, | |
99 | ID_GRIDLINECOLOUR, | |
100 | ID_INSERTROW, | |
101 | ID_INSERTCOL, | |
102 | ID_DELETEROW, | |
103 | ID_DELETECOL, | |
104 | ID_CLEARGRID, | |
043d16b2 SN |
105 | ID_CHANGESEL, |
106 | ID_SELCELLS, | |
107 | ID_SELROWS, | |
108 | ID_SELCOLS, | |
ab79958a VZ |
109 | ID_SET_CELL_FG_COLOUR, |
110 | ID_SET_CELL_BG_COLOUR, | |
111 | ID_ABOUT, | |
f97c9b5b | 112 | ID_VTABLE, |
35f97e95 | 113 | ID_BUGS_TABLE, |
ab79958a VZ |
114 | |
115 | ID_TESTFUNC | |
116 | }; | |
b99be8fb | 117 | |
66b3609e VZ |
118 | wxLog *m_logOld; |
119 | ||
e442cc0d MB |
120 | DECLARE_EVENT_TABLE() |
121 | }; | |
122 | ||
ab79958a VZ |
123 | class MyGridCellRenderer : public wxGridCellStringRenderer |
124 | { | |
125 | public: | |
126 | virtual void Draw(wxGrid& grid, | |
f97c9b5b | 127 | wxGridCellAttr& attr, |
ab79958a VZ |
128 | wxDC& dc, |
129 | const wxRect& rect, | |
130 | int row, int col, | |
131 | bool isSelected); | |
132 | }; | |
e442cc0d | 133 | |
1618dca7 VZ |
134 | // ---------------------------------------------------------------------------- |
135 | // demonstration of virtual table which doesn't store all of its data in | |
136 | // memory | |
137 | // ---------------------------------------------------------------------------- | |
f97c9b5b | 138 | |
1618dca7 VZ |
139 | class BigGridTable : public wxGridTableBase |
140 | { | |
f97c9b5b | 141 | public: |
1618dca7 VZ |
142 | BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; } |
143 | ||
144 | long GetNumberRows() { return m_sizeGrid; } | |
145 | long GetNumberCols() { return m_sizeGrid; } | |
1618dca7 VZ |
146 | wxString GetValue( int row, int col ) |
147 | { | |
148 | return wxString::Format("(%d, %d)", row, col); | |
f97c9b5b RD |
149 | } |
150 | ||
1618dca7 | 151 | void SetValue( int , int , const wxString& ) { /* ignore */ } |
f97c9b5b | 152 | bool IsEmptyCell( int , int ) { return FALSE; } |
1618dca7 VZ |
153 | |
154 | private: | |
155 | long m_sizeGrid; | |
f97c9b5b RD |
156 | }; |
157 | ||
1618dca7 VZ |
158 | class BigGridFrame : public wxFrame |
159 | { | |
f97c9b5b | 160 | public: |
1618dca7 | 161 | BigGridFrame(long sizeGrid); |
f97c9b5b RD |
162 | |
163 | private: | |
164 | wxGrid* m_grid; | |
165 | BigGridTable* m_table; | |
166 | }; | |
167 | ||
a68c1246 VZ |
168 | // ---------------------------------------------------------------------------- |
169 | // an example of custom attr provider: this one makes all odd rows appear grey | |
170 | // ---------------------------------------------------------------------------- | |
171 | ||
172 | class MyGridCellAttrProvider : public wxGridCellAttrProvider | |
173 | { | |
174 | public: | |
175 | MyGridCellAttrProvider(); | |
176 | virtual ~MyGridCellAttrProvider(); | |
177 | ||
178 | virtual wxGridCellAttr *GetAttr(int row, int col) const; | |
179 | ||
180 | private: | |
181 | wxGridCellAttr *m_attrForOddRows; | |
182 | }; | |
183 | ||
35f97e95 | 184 | // ---------------------------------------------------------------------------- |
816be743 | 185 | // another, more realistic, grid example: shows typed columns and more |
35f97e95 VZ |
186 | // ---------------------------------------------------------------------------- |
187 | ||
816be743 VZ |
188 | class BugsGridTable : public wxGridTableBase |
189 | { | |
190 | public: | |
191 | BugsGridTable(); | |
192 | ||
193 | virtual long GetNumberRows(); | |
194 | virtual long GetNumberCols(); | |
195 | virtual bool IsEmptyCell( int row, int col ); | |
196 | virtual wxString GetValue( int row, int col ); | |
197 | virtual void SetValue( int row, int col, const wxString& value ); | |
198 | ||
199 | virtual wxString GetColLabelValue( int col ); | |
200 | ||
201 | virtual wxString GetTypeName( int row, int col ); | |
202 | virtual bool CanGetValueAs( int row, int col, const wxString& typeName ); | |
203 | virtual bool CanSetValueAs( int row, int col, const wxString& typeName ); | |
204 | ||
205 | virtual long GetValueAsLong( int row, int col ); | |
206 | virtual bool GetValueAsBool( int row, int col ); | |
207 | ||
208 | virtual void SetValueAsLong( int row, int col, long value ); | |
209 | virtual void SetValueAsBool( int row, int col, bool value ); | |
210 | }; | |
211 | ||
35f97e95 VZ |
212 | class BugsGridFrame : public wxFrame |
213 | { | |
214 | public: | |
215 | BugsGridFrame(); | |
216 | }; | |
f97c9b5b | 217 | |
1618dca7 | 218 | #endif // griddemo_h |
e442cc0d | 219 |