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