]> git.saurik.com Git - wxWidgets.git/blame - samples/grid/griddemo.h
fix wxMenu leak (reopened #9089)
[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
8// Licence: wxWindows license
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& );
f7556ff0
JS
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);
1ecf2613 76 void OnShowSelection(wxCommandEvent& event);
f7556ff0 77
733f486a
VZ
78 void AutoSizeRow(wxCommandEvent& event);
79 void AutoSizeCol(wxCommandEvent& event);
80 void AutoSizeRowLabel(wxCommandEvent& event);
81 void AutoSizeColLabel(wxCommandEvent& event);
82 void AutoSizeLabelsCol(wxCommandEvent& event);
83 void AutoSizeLabelsRow(wxCommandEvent& event);
84 void AutoSizeTable(wxCommandEvent& event);
85
f7556ff0
JS
86 void OnLabelLeftClick( wxGridEvent& );
87 void OnCellLeftClick( wxGridEvent& );
88 void OnRowSize( wxGridSizeEvent& );
89 void OnColSize( wxGridSizeEvent& );
90 void OnSelectCell( wxGridEvent& );
91 void OnRangeSelected( wxGridRangeSelectEvent& );
92 void OnCellValueChanged( wxGridEvent& );
79dbea21 93 void OnCellBeginDrag( wxGridEvent& );
f7556ff0
JS
94
95 void OnEditorShown(wxGridEvent&);
96 void OnEditorHidden(wxGridEvent&);
97
98 void OnSetHighlightWidth(wxCommandEvent&);
99 void OnSetROHighlightWidth(wxCommandEvent&);
100
101public:
102 GridFrame();
103 ~GridFrame();
104
105 void OnQuit( wxCommandEvent& );
106 void About( wxCommandEvent& );
107 void OnVTable( wxCommandEvent& );
108 void OnBugsTable( wxCommandEvent& );
109 void OnSmallGrid( wxCommandEvent& );
71cf399f 110 void OnTabularGrid( wxCommandEvent& );
f7556ff0
JS
111
112 enum
113 {
114 ID_TOGGLEROWLABELS = 100,
115 ID_TOGGLECOLLABELS,
116 ID_TOGGLEEDIT,
117 ID_TOGGLEROWSIZING,
118 ID_TOGGLECOLSIZING,
d4175745 119 ID_TOGGLECOLMOVING,
f7556ff0 120 ID_TOGGLEGRIDSIZING,
79dbea21 121 ID_TOGGLEGRIDDRAGCELL,
f7556ff0
JS
122 ID_TOGGLEGRIDLINES,
123 ID_AUTOSIZECOLS,
124 ID_CELLOVERFLOW,
125 ID_RESIZECELL,
126 ID_SETLABELCOLOUR,
127 ID_SETLABELTEXTCOLOUR,
128 ID_SETLABEL_FONT,
129 ID_ROWLABELALIGN,
130 ID_ROWLABELHORIZALIGN,
131 ID_ROWLABELVERTALIGN,
132 ID_COLLABELALIGN,
133 ID_COLLABELHORIZALIGN,
134 ID_COLLABELVERTALIGN,
135 ID_GRIDLINECOLOUR,
136 ID_INSERTROW,
137 ID_INSERTCOL,
138 ID_DELETEROW,
139 ID_DELETECOL,
140 ID_CLEARGRID,
141 ID_CHANGESEL,
142 ID_SELCELLS,
143 ID_SELROWS,
144 ID_SELCOLS,
145 ID_SET_CELL_FG_COLOUR,
146 ID_SET_CELL_BG_COLOUR,
f7556ff0
JS
147 ID_VTABLE,
148 ID_BUGS_TABLE,
149 ID_SMALL_GRID,
71cf399f 150 ID_TABULAR_GRID,
f7556ff0 151 ID_SELECT_UNSELECT,
1ecf2613 152 ID_SHOW_SELECTION,
f7556ff0
JS
153 ID_SELECT_ALL,
154 ID_SELECT_ROW,
155 ID_SELECT_COL,
156 ID_SELECT_CELL,
157 ID_DESELECT_ALL,
158 ID_DESELECT_ROW,
159 ID_DESELECT_COL,
160 ID_DESELECT_CELL,
733f486a
VZ
161 ID_SIZE_ROW,
162 ID_SIZE_COL,
163 ID_SIZE_ROW_LABEL,
164 ID_SIZE_COL_LABEL,
165 ID_SIZE_LABELS_COL,
166 ID_SIZE_LABELS_ROW,
167 ID_SIZE_GRID,
f7556ff0
JS
168
169 ID_SET_HIGHLIGHT_WIDTH,
170 ID_SET_RO_HIGHLIGHT_WIDTH,
171
172 ID_TESTFUNC
173 };
174
f07941fc 175#if wxUSE_LOG
f7556ff0 176 wxLog *m_logOld;
f07941fc 177#endif // wxUSE_LOG
f7556ff0
JS
178
179 // add the cells to selection when using commands from select menu?
180 bool m_addToSel;
181
182 DECLARE_EVENT_TABLE()
183};
184
185class MyGridCellRenderer : public wxGridCellStringRenderer
186{
187public:
188 virtual void Draw(wxGrid& grid,
189 wxGridCellAttr& attr,
190 wxDC& dc,
191 const wxRect& rect,
192 int row, int col,
193 bool isSelected);
194};
195
196// ----------------------------------------------------------------------------
197// demonstration of virtual table which doesn't store all of its data in
198// memory
199// ----------------------------------------------------------------------------
200
201class BigGridTable : public wxGridTableBase
202{
203public:
204 BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; }
205
206 int GetNumberRows() { return m_sizeGrid; }
207 int GetNumberCols() { return m_sizeGrid; }
208 wxString GetValue( int row, int col )
209 {
210 return wxString::Format(wxT("(%d, %d)"), row, col);
211 }
212
213 void SetValue( int , int , const wxString& ) { /* ignore */ }
af870ed8 214 bool IsEmptyCell( int , int ) { return false; }
f7556ff0
JS
215
216private:
217 long m_sizeGrid;
218};
219
220class BigGridFrame : public wxFrame
221{
222public:
223 BigGridFrame(long sizeGrid);
224
225private:
226 wxGrid* m_grid;
227 BigGridTable* m_table;
228};
229
230// ----------------------------------------------------------------------------
231// an example of custom attr provider: this one makes all odd rows appear grey
232// ----------------------------------------------------------------------------
233
234class MyGridCellAttrProvider : public wxGridCellAttrProvider
235{
236public:
237 MyGridCellAttrProvider();
238 virtual ~MyGridCellAttrProvider();
239
240 virtual wxGridCellAttr *GetAttr(int row, int col,
241 wxGridCellAttr::wxAttrKind kind) const;
242
243private:
244 wxGridCellAttr *m_attrForOddRows;
245};
246
247// ----------------------------------------------------------------------------
248// another, more realistic, grid example: shows typed columns and more
249// ----------------------------------------------------------------------------
250
251class BugsGridTable : public wxGridTableBase
252{
253public:
925e9792 254 BugsGridTable(){};
f7556ff0
JS
255
256 virtual int GetNumberRows();
257 virtual int GetNumberCols();
258 virtual bool IsEmptyCell( int row, int col );
259 virtual wxString GetValue( int row, int col );
260 virtual void SetValue( int row, int col, const wxString& value );
261
262 virtual wxString GetColLabelValue( int col );
263
264 virtual wxString GetTypeName( int row, int col );
265 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
266 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
267
268 virtual long GetValueAsLong( int row, int col );
269 virtual bool GetValueAsBool( int row, int col );
270
271 virtual void SetValueAsLong( int row, int col, long value );
272 virtual void SetValueAsBool( int row, int col, bool value );
273};
274
275class BugsGridFrame : public wxFrame
276{
277public:
278 BugsGridFrame();
279};
280
281
282#endif // griddemo_h
283