]> git.saurik.com Git - wxWidgets.git/blob - samples/newgrid/griddemo.h
Added ability for tables, grids, editors and renderers to handle nonstring data.
[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 SetLabelColour( wxCommandEvent& );
41 void SetLabelTextColour( wxCommandEvent& );
42 void SetRowLabelHorizAlignment( wxCommandEvent& );
43 void SetRowLabelVertAlignment( wxCommandEvent& );
44 void SetColLabelHorizAlignment( wxCommandEvent& );
45 void SetColLabelVertAlignment( wxCommandEvent& );
46 void SetGridLineColour( wxCommandEvent& );
47
48 void SetCellFgColour(wxCommandEvent &);
49 void SetCellBgColour(wxCommandEvent &);
50
51 void InsertRow( wxCommandEvent& );
52 void InsertCol( wxCommandEvent& );
53 void DeleteSelectedRows( wxCommandEvent& );
54 void DeleteSelectedCols( wxCommandEvent& );
55 void ClearGrid( wxCommandEvent& );
56
57 void OnLabelLeftClick( wxGridEvent& );
58 void OnCellLeftClick( wxGridEvent& );
59 void OnRowSize( wxGridSizeEvent& );
60 void OnColSize( wxGridSizeEvent& );
61 void OnSelectCell( wxGridEvent& );
62 void OnRangeSelected( wxGridRangeSelectEvent& );
63 void OnCellValueChanged( wxGridEvent& );
64
65 void OnEditorShown(wxGridEvent&);
66 void OnEditorHidden(wxGridEvent&);
67
68 public:
69 GridFrame();
70 ~GridFrame();
71
72 void OnQuit( wxCommandEvent& );
73 void About( wxCommandEvent& );
74 void OnVTable( wxCommandEvent& );
75 void OnBugsTable( wxCommandEvent& );
76
77 enum
78 {
79 ID_TOGGLEROWLABELS = 100,
80 ID_TOGGLECOLLABELS,
81 ID_TOGGLEEDIT,
82 ID_SETLABELCOLOUR,
83 ID_SETLABELTEXTCOLOUR,
84 ID_ROWLABELALIGN,
85 ID_ROWLABELHORIZALIGN,
86 ID_ROWLABELVERTALIGN,
87 ID_COLLABELALIGN,
88 ID_COLLABELHORIZALIGN,
89 ID_COLLABELVERTALIGN,
90 ID_GRIDLINECOLOUR,
91 ID_INSERTROW,
92 ID_INSERTCOL,
93 ID_DELETEROW,
94 ID_DELETECOL,
95 ID_CLEARGRID,
96 ID_SET_CELL_FG_COLOUR,
97 ID_SET_CELL_BG_COLOUR,
98 ID_ABOUT,
99 ID_VTABLE,
100 ID_BUGS_TABLE,
101
102 ID_TESTFUNC
103 };
104
105 DECLARE_EVENT_TABLE()
106 };
107
108 class MyGridCellRenderer : public wxGridCellStringRenderer
109 {
110 public:
111 virtual void Draw(wxGrid& grid,
112 wxGridCellAttr& attr,
113 wxDC& dc,
114 const wxRect& rect,
115 int row, int col,
116 bool isSelected);
117 };
118
119 // ----------------------------------------------------------------------------
120 // demonstration of virtual table which doesn't store all of its data in
121 // memory
122 // ----------------------------------------------------------------------------
123
124 class SimpleTable : public wxGridStringTable {
125 public:
126 SimpleTable( int numRows, int numCols )
127 : wxGridStringTable( numRows, numCols ) {}
128
129 // override this to fake a row as all bools
130 wxString GetTypeName( int row, int col )
131 {
132 if (row == 8)
133 return wxT("bool");
134 else if (row == 9 && col == 1)
135 return wxT("unknown type"); // to test fallback
136 else
137 return wxGridStringTable::GetTypeName(row, col);
138 }
139
140 };
141
142 class BigGridTable : public wxGridTableBase
143 {
144 public:
145 BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; }
146
147 long GetNumberRows() { return m_sizeGrid; }
148 long GetNumberCols() { return m_sizeGrid; }
149 wxString GetValue( int row, int col )
150 {
151 return wxString::Format("(%d, %d)", row, col);
152 }
153
154 void SetValue( int , int , const wxString& ) { /* ignore */ }
155 bool IsEmptyCell( int , int ) { return FALSE; }
156
157 private:
158 long m_sizeGrid;
159 };
160
161 class BigGridFrame : public wxFrame
162 {
163 public:
164 BigGridFrame(long sizeGrid);
165
166 private:
167 wxGrid* m_grid;
168 BigGridTable* m_table;
169 };
170
171 // ----------------------------------------------------------------------------
172 // another, more realistic, grid example
173 // ----------------------------------------------------------------------------
174
175 class BugsGridFrame : public wxFrame
176 {
177 public:
178 BugsGridFrame();
179 };
180
181 #endif // griddemo_h
182