]> git.saurik.com Git - wxWidgets.git/blame - samples/newgrid/griddemo.h
bug in SetLastFocus corrected
[wxWidgets.git] / samples / newgrid / griddemo.h
CommitLineData
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
19class wxGrid;
20
21class GridApp : public wxApp
22{
ab79958a 23public:
e442cc0d
MB
24 bool OnInit();
25};
26
27
28class 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& );
f6bcfd97
BP
43 void ToggleGridLines( wxCommandEvent& );
44 void AutoSizeCols( wxCommandEvent& );
e442cc0d
MB
45 void SetLabelColour( wxCommandEvent& );
46 void SetLabelTextColour( wxCommandEvent& );
47 void SetRowLabelHorizAlignment( wxCommandEvent& );
48 void SetRowLabelVertAlignment( wxCommandEvent& );
49 void SetColLabelHorizAlignment( wxCommandEvent& );
50 void SetColLabelVertAlignment( wxCommandEvent& );
51 void SetGridLineColour( wxCommandEvent& );
0eee5283 52
ab79958a
VZ
53 void SetCellFgColour(wxCommandEvent &);
54 void SetCellBgColour(wxCommandEvent &);
55
b99be8fb
VZ
56 void InsertRow( wxCommandEvent& );
57 void InsertCol( wxCommandEvent& );
58 void DeleteSelectedRows( wxCommandEvent& );
59 void DeleteSelectedCols( wxCommandEvent& );
e442cc0d 60 void ClearGrid( wxCommandEvent& );
043d16b2
SN
61 void SelectCells( wxCommandEvent& );
62 void SelectRows( wxCommandEvent& );
63 void SelectCols( wxCommandEvent& );
e442cc0d 64
14e5a313
VZ
65 void DeselectCell(wxCommandEvent& event);
66 void DeselectCol(wxCommandEvent& event);
67 void DeselectRow(wxCommandEvent& event);
68 void DeselectAll(wxCommandEvent& event);
69 void SelectCell(wxCommandEvent& event);
70 void SelectCol(wxCommandEvent& event);
71 void SelectRow(wxCommandEvent& event);
72 void SelectAll(wxCommandEvent& event);
93521c94 73 void OnAddToSelectToggle(wxCommandEvent& event);
14e5a313 74
e442cc0d
MB
75 void OnLabelLeftClick( wxGridEvent& );
76 void OnCellLeftClick( wxGridEvent& );
77 void OnRowSize( wxGridSizeEvent& );
78 void OnColSize( wxGridSizeEvent& );
c336585e 79 void OnSelectCell( wxGridEvent& );
e442cc0d
MB
80 void OnRangeSelected( wxGridRangeSelectEvent& );
81 void OnCellValueChanged( wxGridEvent& );
b99be8fb 82
b54ba671
VZ
83 void OnEditorShown(wxGridEvent&);
84 void OnEditorHidden(wxGridEvent&);
85
d2520c85
RD
86 void OnSetHighlightWidth(wxCommandEvent&);
87 void OnSetROHighlightWidth(wxCommandEvent&);
88
ab79958a 89public:
e442cc0d
MB
90 GridFrame();
91 ~GridFrame();
92
e442cc0d 93 void OnQuit( wxCommandEvent& );
f445b853 94 void About( wxCommandEvent& );
f97c9b5b 95 void OnVTable( wxCommandEvent& );
35f97e95 96 void OnBugsTable( wxCommandEvent& );
e442cc0d 97
ab79958a
VZ
98 enum
99 {
100 ID_TOGGLEROWLABELS = 100,
101 ID_TOGGLECOLLABELS,
102 ID_TOGGLEEDIT,
dd16fdae
MB
103 ID_TOGGLEROWSIZING,
104 ID_TOGGLECOLSIZING,
4cfa5de6 105 ID_TOGGLEGRIDSIZING,
f6bcfd97
BP
106 ID_TOGGLEGRIDLINES,
107 ID_AUTOSIZECOLS,
ab79958a
VZ
108 ID_SETLABELCOLOUR,
109 ID_SETLABELTEXTCOLOUR,
110 ID_ROWLABELALIGN,
111 ID_ROWLABELHORIZALIGN,
112 ID_ROWLABELVERTALIGN,
113 ID_COLLABELALIGN,
114 ID_COLLABELHORIZALIGN,
115 ID_COLLABELVERTALIGN,
116 ID_GRIDLINECOLOUR,
117 ID_INSERTROW,
118 ID_INSERTCOL,
119 ID_DELETEROW,
120 ID_DELETECOL,
121 ID_CLEARGRID,
93521c94
VZ
122 ID_CHANGESEL,
123 ID_SELCELLS,
124 ID_SELROWS,
125 ID_SELCOLS,
ab79958a
VZ
126 ID_SET_CELL_FG_COLOUR,
127 ID_SET_CELL_BG_COLOUR,
128 ID_ABOUT,
f97c9b5b 129 ID_VTABLE,
35f97e95 130 ID_BUGS_TABLE,
93521c94 131 ID_SELECT_UNSELECT,
14e5a313
VZ
132 ID_SELECT_ALL,
133 ID_SELECT_ROW,
134 ID_SELECT_COL,
135 ID_SELECT_CELL,
136 ID_DESELECT_ALL,
137 ID_DESELECT_ROW,
138 ID_DESELECT_COL,
139 ID_DESELECT_CELL,
ab79958a 140
d2520c85
RD
141 ID_SET_HIGHLIGHT_WIDTH,
142 ID_SET_RO_HIGHLIGHT_WIDTH,
143
ab79958a
VZ
144 ID_TESTFUNC
145 };
b99be8fb 146
66b3609e
VZ
147 wxLog *m_logOld;
148
93521c94
VZ
149 // add the cells to selection when using commands from select menu?
150 bool m_addToSel;
151
e442cc0d
MB
152 DECLARE_EVENT_TABLE()
153};
154
ab79958a
VZ
155class MyGridCellRenderer : public wxGridCellStringRenderer
156{
157public:
158 virtual void Draw(wxGrid& grid,
f97c9b5b 159 wxGridCellAttr& attr,
ab79958a
VZ
160 wxDC& dc,
161 const wxRect& rect,
162 int row, int col,
163 bool isSelected);
164};
e442cc0d 165
1618dca7
VZ
166// ----------------------------------------------------------------------------
167// demonstration of virtual table which doesn't store all of its data in
168// memory
169// ----------------------------------------------------------------------------
f97c9b5b 170
1618dca7
VZ
171class BigGridTable : public wxGridTableBase
172{
f97c9b5b 173public:
1618dca7
VZ
174 BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; }
175
e32352cf
SN
176 int GetNumberRows() { return m_sizeGrid; }
177 int GetNumberCols() { return m_sizeGrid; }
1618dca7
VZ
178 wxString GetValue( int row, int col )
179 {
180 return wxString::Format("(%d, %d)", row, col);
f97c9b5b
RD
181 }
182
1618dca7 183 void SetValue( int , int , const wxString& ) { /* ignore */ }
f97c9b5b 184 bool IsEmptyCell( int , int ) { return FALSE; }
1618dca7
VZ
185
186private:
187 long m_sizeGrid;
f97c9b5b
RD
188};
189
1618dca7
VZ
190class BigGridFrame : public wxFrame
191{
f97c9b5b 192public:
1618dca7 193 BigGridFrame(long sizeGrid);
f97c9b5b
RD
194
195private:
196 wxGrid* m_grid;
197 BigGridTable* m_table;
198};
199
a68c1246
VZ
200// ----------------------------------------------------------------------------
201// an example of custom attr provider: this one makes all odd rows appear grey
202// ----------------------------------------------------------------------------
203
204class MyGridCellAttrProvider : public wxGridCellAttrProvider
205{
206public:
207 MyGridCellAttrProvider();
208 virtual ~MyGridCellAttrProvider();
209
19d7140e 210 virtual wxGridCellAttr *GetAttr(int row, int col,
d10f4bf9 211 wxGridCellAttr::wxAttrKind kind) const;
a68c1246
VZ
212
213private:
214 wxGridCellAttr *m_attrForOddRows;
215};
216
35f97e95 217// ----------------------------------------------------------------------------
816be743 218// another, more realistic, grid example: shows typed columns and more
35f97e95
VZ
219// ----------------------------------------------------------------------------
220
816be743
VZ
221class BugsGridTable : public wxGridTableBase
222{
223public:
224 BugsGridTable();
225
e32352cf
SN
226 virtual int GetNumberRows();
227 virtual int GetNumberCols();
816be743
VZ
228 virtual bool IsEmptyCell( int row, int col );
229 virtual wxString GetValue( int row, int col );
230 virtual void SetValue( int row, int col, const wxString& value );
231
232 virtual wxString GetColLabelValue( int col );
233
234 virtual wxString GetTypeName( int row, int col );
235 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
236 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
237
238 virtual long GetValueAsLong( int row, int col );
239 virtual bool GetValueAsBool( int row, int col );
240
241 virtual void SetValueAsLong( int row, int col, long value );
242 virtual void SetValueAsBool( int row, int col, bool value );
243};
244
35f97e95
VZ
245class BugsGridFrame : public wxFrame
246{
247public:
248 BugsGridFrame();
249};
f97c9b5b 250
19d7140e 251
1618dca7 252#endif // griddemo_h
e442cc0d 253