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