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