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