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