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