]> git.saurik.com Git - wxWidgets.git/blob - samples/newgrid/griddemo.h
made wxLocale::GetSystemLanguage and wxLocale::AddLanguage static;
[wxWidgets.git] / samples / newgrid / griddemo.h
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 /////////////////////////////////////////////////////////////////////////////
10
11
12 #ifndef griddemo_h
13 #define griddemo_h
14
15 #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
16 #error "This sample requires the new wxGrid class."
17 #endif
18
19 class wxGrid;
20
21 class GridApp : public wxApp
22 {
23 public:
24 bool OnInit();
25 };
26
27
28 class GridFrame : public wxFrame
29 {
30 wxGrid *grid;
31 wxTextCtrl *logWin;
32 wxLogTextCtrl *logger;
33 wxString logBuf;
34
35 void SetDefaults();
36
37 void ToggleRowLabels( wxCommandEvent& );
38 void ToggleColLabels( wxCommandEvent& );
39 void ToggleEditing( wxCommandEvent& );
40 void ToggleRowSizing( wxCommandEvent& );
41 void ToggleColSizing( wxCommandEvent& );
42 void ToggleGridSizing( wxCommandEvent& );
43 void ToggleGridLines( wxCommandEvent& );
44 void AutoSizeCols( wxCommandEvent& );
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& );
52
53 void SetCellFgColour(wxCommandEvent &);
54 void SetCellBgColour(wxCommandEvent &);
55
56 void InsertRow( wxCommandEvent& );
57 void InsertCol( wxCommandEvent& );
58 void DeleteSelectedRows( wxCommandEvent& );
59 void DeleteSelectedCols( wxCommandEvent& );
60 void ClearGrid( wxCommandEvent& );
61 void SelectCells( wxCommandEvent& );
62 void SelectRows( wxCommandEvent& );
63 void SelectCols( wxCommandEvent& );
64
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);
73 void OnAddToSelectToggle(wxCommandEvent& event);
74
75 void OnLabelLeftClick( wxGridEvent& );
76 void OnCellLeftClick( wxGridEvent& );
77 void OnRowSize( wxGridSizeEvent& );
78 void OnColSize( wxGridSizeEvent& );
79 void OnSelectCell( wxGridEvent& );
80 void OnRangeSelected( wxGridRangeSelectEvent& );
81 void OnCellValueChanged( wxGridEvent& );
82
83 void OnEditorShown(wxGridEvent&);
84 void OnEditorHidden(wxGridEvent&);
85
86 public:
87 GridFrame();
88 ~GridFrame();
89
90 void OnQuit( wxCommandEvent& );
91 void About( wxCommandEvent& );
92 void OnVTable( wxCommandEvent& );
93 void OnBugsTable( wxCommandEvent& );
94
95 enum
96 {
97 ID_TOGGLEROWLABELS = 100,
98 ID_TOGGLECOLLABELS,
99 ID_TOGGLEEDIT,
100 ID_TOGGLEROWSIZING,
101 ID_TOGGLECOLSIZING,
102 ID_TOGGLEGRIDSIZING,
103 ID_TOGGLEGRIDLINES,
104 ID_AUTOSIZECOLS,
105 ID_SETLABELCOLOUR,
106 ID_SETLABELTEXTCOLOUR,
107 ID_ROWLABELALIGN,
108 ID_ROWLABELHORIZALIGN,
109 ID_ROWLABELVERTALIGN,
110 ID_COLLABELALIGN,
111 ID_COLLABELHORIZALIGN,
112 ID_COLLABELVERTALIGN,
113 ID_GRIDLINECOLOUR,
114 ID_INSERTROW,
115 ID_INSERTCOL,
116 ID_DELETEROW,
117 ID_DELETECOL,
118 ID_CLEARGRID,
119 ID_CHANGESEL,
120 ID_SELCELLS,
121 ID_SELROWS,
122 ID_SELCOLS,
123 ID_SET_CELL_FG_COLOUR,
124 ID_SET_CELL_BG_COLOUR,
125 ID_ABOUT,
126 ID_VTABLE,
127 ID_BUGS_TABLE,
128 ID_SELECT_UNSELECT,
129 ID_SELECT_ALL,
130 ID_SELECT_ROW,
131 ID_SELECT_COL,
132 ID_SELECT_CELL,
133 ID_DESELECT_ALL,
134 ID_DESELECT_ROW,
135 ID_DESELECT_COL,
136 ID_DESELECT_CELL,
137
138 ID_TESTFUNC
139 };
140
141 wxLog *m_logOld;
142
143 // add the cells to selection when using commands from select menu?
144 bool m_addToSel;
145
146 DECLARE_EVENT_TABLE()
147 };
148
149 class MyGridCellRenderer : public wxGridCellStringRenderer
150 {
151 public:
152 virtual void Draw(wxGrid& grid,
153 wxGridCellAttr& attr,
154 wxDC& dc,
155 const wxRect& rect,
156 int row, int col,
157 bool isSelected);
158 };
159
160 // ----------------------------------------------------------------------------
161 // demonstration of virtual table which doesn't store all of its data in
162 // memory
163 // ----------------------------------------------------------------------------
164
165 class BigGridTable : public wxGridTableBase
166 {
167 public:
168 BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; }
169
170 int GetNumberRows() { return m_sizeGrid; }
171 int GetNumberCols() { return m_sizeGrid; }
172 wxString GetValue( int row, int col )
173 {
174 return wxString::Format("(%d, %d)", row, col);
175 }
176
177 void SetValue( int , int , const wxString& ) { /* ignore */ }
178 bool IsEmptyCell( int , int ) { return FALSE; }
179
180 private:
181 long m_sizeGrid;
182 };
183
184 class BigGridFrame : public wxFrame
185 {
186 public:
187 BigGridFrame(long sizeGrid);
188
189 private:
190 wxGrid* m_grid;
191 BigGridTable* m_table;
192 };
193
194 // ----------------------------------------------------------------------------
195 // an example of custom attr provider: this one makes all odd rows appear grey
196 // ----------------------------------------------------------------------------
197
198 class MyGridCellAttrProvider : public wxGridCellAttrProvider
199 {
200 public:
201 MyGridCellAttrProvider();
202 virtual ~MyGridCellAttrProvider();
203
204 virtual wxGridCellAttr *GetAttr(int row, int col) const;
205
206 private:
207 wxGridCellAttr *m_attrForOddRows;
208 };
209
210 // ----------------------------------------------------------------------------
211 // another, more realistic, grid example: shows typed columns and more
212 // ----------------------------------------------------------------------------
213
214 class BugsGridTable : public wxGridTableBase
215 {
216 public:
217 BugsGridTable();
218
219 virtual int GetNumberRows();
220 virtual int GetNumberCols();
221 virtual bool IsEmptyCell( int row, int col );
222 virtual wxString GetValue( int row, int col );
223 virtual void SetValue( int row, int col, const wxString& value );
224
225 virtual wxString GetColLabelValue( int col );
226
227 virtual wxString GetTypeName( int row, int col );
228 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
229 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
230
231 virtual long GetValueAsLong( int row, int col );
232 virtual bool GetValueAsBool( int row, int col );
233
234 virtual void SetValueAsLong( int row, int col, long value );
235 virtual void SetValueAsBool( int row, int col, bool value );
236 };
237
238 class BugsGridFrame : public wxFrame
239 {
240 public:
241 BugsGridFrame();
242 };
243
244 #endif // griddemo_h
245