]>
Commit | Line | Data |
---|---|---|
10434f3c MB |
1 | ///////////////////////////////////////////////////////////////////////////// |
2 | // Name: griddemo.cpp | |
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 | ///////////////////////////////////////////////////////////////////////////// | |
e442cc0d | 10 | |
ab79958a VZ |
11 | // ============================================================================ |
12 | // declarations | |
13 | // ============================================================================ | |
14 | ||
15 | // ---------------------------------------------------------------------------- | |
16 | // headers | |
17 | // ---------------------------------------------------------------------------- | |
18 | ||
e442cc0d | 19 | #ifdef __GNUG__ |
ab79958a VZ |
20 | #pragma implementation |
21 | #pragma interface | |
e442cc0d MB |
22 | #endif |
23 | ||
24 | // For compilers that support precompilation, includes "wx/wx.h". | |
25 | #include "wx/wxprec.h" | |
26 | ||
27 | #ifdef __BORLANDC__ | |
28 | #pragma hdrstop | |
29 | #endif | |
30 | ||
31 | #ifndef WX_PRECOMP | |
bf9adb3a | 32 | #include "wx/wx.h" |
e442cc0d MB |
33 | #endif |
34 | ||
2f6c54eb VZ |
35 | #include "wx/colordlg.h" |
36 | #include "wx/fontdlg.h" | |
37 | ||
e442cc0d | 38 | #include "wx/grid.h" |
d10f4bf9 | 39 | #include "wx/generic/gridctrl.h" |
e442cc0d MB |
40 | |
41 | #include "griddemo.h" | |
42 | ||
ab79958a VZ |
43 | // ---------------------------------------------------------------------------- |
44 | // wxWin macros | |
45 | // ---------------------------------------------------------------------------- | |
46 | ||
e442cc0d MB |
47 | IMPLEMENT_APP( GridApp ) |
48 | ||
ab79958a VZ |
49 | // ============================================================================ |
50 | // implementation | |
51 | // ============================================================================ | |
e442cc0d | 52 | |
ab79958a VZ |
53 | // ---------------------------------------------------------------------------- |
54 | // GridApp | |
55 | // ---------------------------------------------------------------------------- | |
e442cc0d MB |
56 | |
57 | bool GridApp::OnInit() | |
58 | { | |
59 | GridFrame *frame = new GridFrame; | |
60 | frame->Show( TRUE ); | |
f0102d2a | 61 | |
e442cc0d MB |
62 | return TRUE; |
63 | } | |
64 | ||
ab79958a VZ |
65 | // ---------------------------------------------------------------------------- |
66 | // GridFrame | |
67 | // ---------------------------------------------------------------------------- | |
e442cc0d MB |
68 | |
69 | BEGIN_EVENT_TABLE( GridFrame, wxFrame ) | |
70 | EVT_MENU( ID_TOGGLEROWLABELS, GridFrame::ToggleRowLabels ) | |
f0102d2a | 71 | EVT_MENU( ID_TOGGLECOLLABELS, GridFrame::ToggleColLabels ) |
f445b853 | 72 | EVT_MENU( ID_TOGGLEEDIT, GridFrame::ToggleEditing ) |
dd16fdae | 73 | EVT_MENU( ID_TOGGLEROWSIZING, GridFrame::ToggleRowSizing ) |
ea179c7b | 74 | EVT_MENU( ID_TOGGLECOLSIZING, GridFrame::ToggleColSizing ) |
4cfa5de6 | 75 | EVT_MENU( ID_TOGGLEGRIDSIZING, GridFrame::ToggleGridSizing ) |
f6bcfd97 BP |
76 | EVT_MENU( ID_TOGGLEGRIDLINES, GridFrame::ToggleGridLines ) |
77 | EVT_MENU( ID_AUTOSIZECOLS, GridFrame::AutoSizeCols ) | |
f0102d2a VZ |
78 | EVT_MENU( ID_SETLABELCOLOUR, GridFrame::SetLabelColour ) |
79 | EVT_MENU( ID_SETLABELTEXTCOLOUR, GridFrame::SetLabelTextColour ) | |
bf9adb3a | 80 | EVT_MENU( ID_SETLABEL_FONT, GridFrame::SetLabelFont ) |
f0102d2a VZ |
81 | EVT_MENU( ID_ROWLABELHORIZALIGN, GridFrame::SetRowLabelHorizAlignment ) |
82 | EVT_MENU( ID_ROWLABELVERTALIGN, GridFrame::SetRowLabelVertAlignment ) | |
83 | EVT_MENU( ID_COLLABELHORIZALIGN, GridFrame::SetColLabelHorizAlignment ) | |
84 | EVT_MENU( ID_COLLABELVERTALIGN, GridFrame::SetColLabelVertAlignment ) | |
e442cc0d | 85 | EVT_MENU( ID_GRIDLINECOLOUR, GridFrame::SetGridLineColour ) |
0eee5283 MB |
86 | EVT_MENU( ID_INSERTROW, GridFrame::InsertRow ) |
87 | EVT_MENU( ID_INSERTCOL, GridFrame::InsertCol ) | |
f445b853 MB |
88 | EVT_MENU( ID_DELETEROW, GridFrame::DeleteSelectedRows ) |
89 | EVT_MENU( ID_DELETECOL, GridFrame::DeleteSelectedCols ) | |
e442cc0d | 90 | EVT_MENU( ID_CLEARGRID, GridFrame::ClearGrid ) |
043d16b2 SN |
91 | EVT_MENU( ID_SELCELLS, GridFrame::SelectCells ) |
92 | EVT_MENU( ID_SELROWS, GridFrame::SelectRows ) | |
93 | EVT_MENU( ID_SELCOLS, GridFrame::SelectCols ) | |
f0102d2a | 94 | |
ab79958a VZ |
95 | EVT_MENU( ID_SET_CELL_FG_COLOUR, GridFrame::SetCellFgColour ) |
96 | EVT_MENU( ID_SET_CELL_BG_COLOUR, GridFrame::SetCellBgColour ) | |
97 | ||
e442cc0d MB |
98 | EVT_MENU( ID_ABOUT, GridFrame::About ) |
99 | EVT_MENU( wxID_EXIT, GridFrame::OnQuit ) | |
f97c9b5b | 100 | EVT_MENU( ID_VTABLE, GridFrame::OnVTable) |
35f97e95 | 101 | EVT_MENU( ID_BUGS_TABLE, GridFrame::OnBugsTable) |
671bcff5 | 102 | EVT_MENU( ID_SMALL_GRID, GridFrame::OnSmallGrid) |
e442cc0d | 103 | |
14e5a313 VZ |
104 | EVT_MENU( ID_DESELECT_CELL, GridFrame::DeselectCell) |
105 | EVT_MENU( ID_DESELECT_COL, GridFrame::DeselectCol) | |
106 | EVT_MENU( ID_DESELECT_ROW, GridFrame::DeselectRow) | |
107 | EVT_MENU( ID_DESELECT_ALL, GridFrame::DeselectAll) | |
108 | EVT_MENU( ID_SELECT_CELL, GridFrame::SelectCell) | |
109 | EVT_MENU( ID_SELECT_COL, GridFrame::SelectCol) | |
110 | EVT_MENU( ID_SELECT_ROW, GridFrame::SelectRow) | |
111 | EVT_MENU( ID_SELECT_ALL, GridFrame::SelectAll) | |
93521c94 | 112 | EVT_MENU( ID_SELECT_UNSELECT, GridFrame::OnAddToSelectToggle) |
14e5a313 | 113 | |
d2520c85 RD |
114 | EVT_MENU( ID_SET_HIGHLIGHT_WIDTH, GridFrame::OnSetHighlightWidth) |
115 | EVT_MENU( ID_SET_RO_HIGHLIGHT_WIDTH, GridFrame::OnSetROHighlightWidth) | |
116 | ||
5795d034 MB |
117 | EVT_GRID_LABEL_LEFT_CLICK( GridFrame::OnLabelLeftClick ) |
118 | EVT_GRID_CELL_LEFT_CLICK( GridFrame::OnCellLeftClick ) | |
119 | EVT_GRID_ROW_SIZE( GridFrame::OnRowSize ) | |
120 | EVT_GRID_COL_SIZE( GridFrame::OnColSize ) | |
c336585e | 121 | EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell ) |
5795d034 MB |
122 | EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected ) |
123 | EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged ) | |
b54ba671 VZ |
124 | |
125 | EVT_GRID_EDITOR_SHOWN( GridFrame::OnEditorShown ) | |
126 | EVT_GRID_EDITOR_HIDDEN( GridFrame::OnEditorHidden ) | |
e442cc0d MB |
127 | END_EVENT_TABLE() |
128 | ||
f0102d2a | 129 | |
e442cc0d MB |
130 | GridFrame::GridFrame() |
131 | : wxFrame( (wxFrame *)NULL, -1, "wxWindows grid class demo", | |
132 | wxDefaultPosition, | |
133 | wxDefaultSize ) | |
134 | { | |
135 | int gridW = 600, gridH = 300; | |
07296f0b | 136 | int logW = gridW, logH = 100; |
f0102d2a | 137 | |
e442cc0d | 138 | wxMenu *fileMenu = new wxMenu; |
43947979 | 139 | fileMenu->Append( ID_VTABLE, "&Virtual table test\tCtrl-V"); |
35f97e95 | 140 | fileMenu->Append( ID_BUGS_TABLE, "&Bugs table test\tCtrl-B"); |
671bcff5 | 141 | fileMenu->Append( ID_SMALL_GRID, "&Small Grid test\tCtrl-S"); |
f97c9b5b | 142 | fileMenu->AppendSeparator(); |
f0102d2a VZ |
143 | fileMenu->Append( wxID_EXIT, "E&xit\tAlt-X" ); |
144 | ||
e442cc0d MB |
145 | wxMenu *viewMenu = new wxMenu; |
146 | viewMenu->Append( ID_TOGGLEROWLABELS, "&Row labels", "", TRUE ); | |
147 | viewMenu->Append( ID_TOGGLECOLLABELS, "&Col labels", "", TRUE ); | |
f445b853 | 148 | viewMenu->Append( ID_TOGGLEEDIT, "&Editable", "", TRUE ); |
dd16fdae MB |
149 | viewMenu->Append( ID_TOGGLEROWSIZING, "Ro&w drag-resize", "", TRUE ); |
150 | viewMenu->Append( ID_TOGGLECOLSIZING, "C&ol drag-resize", "", TRUE ); | |
4cfa5de6 | 151 | viewMenu->Append( ID_TOGGLEGRIDSIZING, "&Grid drag-resize", "", TRUE ); |
f6bcfd97 | 152 | viewMenu->Append( ID_TOGGLEGRIDLINES, "&Grid Lines", "", TRUE ); |
d2520c85 RD |
153 | viewMenu->Append( ID_SET_HIGHLIGHT_WIDTH, "&Set Cell Highlight Width...", "" ); |
154 | viewMenu->Append( ID_SET_RO_HIGHLIGHT_WIDTH, "&Set Cell RO Highlight Width...", "" ); | |
f6bcfd97 | 155 | viewMenu->Append( ID_AUTOSIZECOLS, "&Auto-size cols" ); |
f0102d2a | 156 | |
e442cc0d MB |
157 | wxMenu *rowLabelMenu = new wxMenu; |
158 | ||
159 | viewMenu->Append( ID_ROWLABELALIGN, "R&ow label alignment", | |
160 | rowLabelMenu, | |
161 | "Change alignment of row labels" ); | |
162 | ||
163 | rowLabelMenu->Append( ID_ROWLABELHORIZALIGN, "&Horizontal" ); | |
f0102d2a VZ |
164 | rowLabelMenu->Append( ID_ROWLABELVERTALIGN, "&Vertical" ); |
165 | ||
e442cc0d MB |
166 | wxMenu *colLabelMenu = new wxMenu; |
167 | ||
168 | viewMenu->Append( ID_COLLABELALIGN, "Col l&abel alignment", | |
169 | colLabelMenu, | |
170 | "Change alignment of col labels" ); | |
171 | ||
172 | colLabelMenu->Append( ID_COLLABELHORIZALIGN, "&Horizontal" ); | |
173 | colLabelMenu->Append( ID_COLLABELVERTALIGN, "&Vertical" ); | |
174 | ||
ab79958a | 175 | wxMenu *colMenu = new wxMenu; |
bf9adb3a VZ |
176 | colMenu->Append( ID_SETLABELCOLOUR, "Set &label colour..." ); |
177 | colMenu->Append( ID_SETLABELTEXTCOLOUR, "Set label &text colour..." ); | |
178 | colMenu->Append( ID_SETLABEL_FONT, "Set label fo&nt..." ); | |
179 | colMenu->Append( ID_GRIDLINECOLOUR, "&Grid line colour..." ); | |
180 | colMenu->Append( ID_SET_CELL_FG_COLOUR, "Set cell &foreground colour..." ); | |
181 | colMenu->Append( ID_SET_CELL_BG_COLOUR, "Set cell &background colour..." ); | |
e442cc0d | 182 | |
0eee5283 MB |
183 | wxMenu *editMenu = new wxMenu; |
184 | editMenu->Append( ID_INSERTROW, "Insert &row" ); | |
185 | editMenu->Append( ID_INSERTCOL, "Insert &column" ); | |
f445b853 MB |
186 | editMenu->Append( ID_DELETEROW, "Delete selected ro&ws" ); |
187 | editMenu->Append( ID_DELETECOL, "Delete selected co&ls" ); | |
0eee5283 | 188 | editMenu->Append( ID_CLEARGRID, "Cl&ear grid cell contents" ); |
f0102d2a | 189 | |
14e5a313 | 190 | wxMenu *selectMenu = new wxMenu; |
93521c94 VZ |
191 | selectMenu->Append( ID_SELECT_UNSELECT, "Add new cells to the selection", |
192 | "When off, old selection is deselected before " | |
193 | "selecting the new cells", TRUE ); | |
14e5a313 VZ |
194 | selectMenu->Append( ID_SELECT_ALL, "Select all"); |
195 | selectMenu->Append( ID_SELECT_ROW, "Select row 2"); | |
196 | selectMenu->Append( ID_SELECT_COL, "Select col 2"); | |
197 | selectMenu->Append( ID_SELECT_CELL, "Select cell (3, 1)"); | |
198 | selectMenu->Append( ID_DESELECT_ALL, "Deselect all"); | |
199 | selectMenu->Append( ID_DESELECT_ROW, "Deselect row 2"); | |
200 | selectMenu->Append( ID_DESELECT_COL, "Deselect col 2"); | |
201 | selectMenu->Append( ID_DESELECT_CELL, "Deselect cell (3, 1)"); | |
043d16b2 | 202 | wxMenu *selectionMenu = new wxMenu; |
14e5a313 | 203 | selectMenu->Append( ID_CHANGESEL, "Change &selection mode", |
5c8fc7c1 SN |
204 | selectionMenu, |
205 | "Change selection mode" ); | |
043d16b2 SN |
206 | |
207 | selectionMenu->Append( ID_SELCELLS, "Select &Cells" ); | |
208 | selectionMenu->Append( ID_SELROWS, "Select &Rows" ); | |
209 | selectionMenu->Append( ID_SELCOLS, "Select C&ols" ); | |
210 | ||
14e5a313 | 211 | |
e442cc0d MB |
212 | wxMenu *helpMenu = new wxMenu; |
213 | helpMenu->Append( ID_ABOUT, "&About wxGrid demo" ); | |
f0102d2a | 214 | |
e442cc0d MB |
215 | wxMenuBar *menuBar = new wxMenuBar; |
216 | menuBar->Append( fileMenu, "&File" ); | |
217 | menuBar->Append( viewMenu, "&View" ); | |
ab79958a | 218 | menuBar->Append( colMenu, "&Colours" ); |
0eee5283 | 219 | menuBar->Append( editMenu, "&Edit" ); |
14e5a313 | 220 | menuBar->Append( selectMenu, "&Select" ); |
e442cc0d MB |
221 | menuBar->Append( helpMenu, "&Help" ); |
222 | ||
223 | SetMenuBar( menuBar ); | |
224 | ||
93521c94 VZ |
225 | m_addToSel = FALSE; |
226 | ||
e442cc0d MB |
227 | grid = new wxGrid( this, |
228 | -1, | |
229 | wxPoint( 0, 0 ), | |
230 | wxSize( 400, 300 ) ); | |
f0102d2a | 231 | |
e442cc0d MB |
232 | logWin = new wxTextCtrl( this, |
233 | -1, | |
234 | wxEmptyString, | |
235 | wxPoint( 0, gridH + 20 ), | |
236 | wxSize( logW, logH ), | |
237 | wxTE_MULTILINE ); | |
f0102d2a | 238 | |
e442cc0d | 239 | logger = new wxLogTextCtrl( logWin ); |
66b3609e | 240 | m_logOld = logger->SetActiveTarget( logger ); |
e442cc0d MB |
241 | logger->SetTimestamp( NULL ); |
242 | ||
243 | // this will create a grid and, by default, an associated grid | |
984ef9dc | 244 | // table for strings |
816be743 | 245 | grid->CreateGrid( 100, 100 ); |
f2d76237 | 246 | |
e442cc0d MB |
247 | grid->SetRowSize( 0, 60 ); |
248 | grid->SetCellValue( 0, 0, "Ctrl+Home\nwill go to\nthis cell" ); | |
f0102d2a | 249 | |
d10f4bf9 VZ |
250 | grid->SetCellValue( 0, 1, "A long piece of text to demonstrate wrapping." ); |
251 | grid->SetCellRenderer(0 , 1, new wxGridCellAutoWrapStringRenderer); | |
252 | grid->SetCellEditor( 0, 1 , new wxGridCellAutoWrapStringEditor); | |
671bcff5 | 253 | |
e442cc0d | 254 | grid->SetCellValue( 0, 2, "Blah" ); |
283b7808 VZ |
255 | grid->SetCellValue( 0, 3, "Read only" ); |
256 | grid->SetReadOnly( 0, 3 ); | |
671bcff5 | 257 | |
fe7b9ed6 | 258 | grid->SetCellValue( 0, 4, "Can veto edit this cell" ); |
e442cc0d MB |
259 | |
260 | grid->SetCellValue( 0, 5, "Press\nCtrl+arrow\nto skip over\ncells" ); | |
261 | ||
262 | grid->SetRowSize( 99, 60 ); | |
263 | grid->SetCellValue( 99, 99, "Ctrl+End\nwill go to\nthis cell" ); | |
f445b853 | 264 | |
b99be8fb | 265 | grid->SetCellValue(2, 2, "red"); |
ab79958a | 266 | |
b99be8fb | 267 | grid->SetCellTextColour(2, 2, *wxRED); |
2e9a6788 | 268 | grid->SetCellValue(3, 3, "green on grey"); |
b99be8fb | 269 | grid->SetCellTextColour(3, 3, *wxGREEN); |
2e9a6788 | 270 | grid->SetCellBackgroundColour(3, 3, *wxLIGHT_GREY); |
b99be8fb | 271 | |
ab79958a | 272 | grid->SetCellValue(4, 4, "a weird looking cell"); |
0767cb6f | 273 | grid->SetCellAlignment(4, 4, wxALIGN_CENTRE, wxALIGN_CENTRE); |
ab79958a VZ |
274 | grid->SetCellRenderer(4, 4, new MyGridCellRenderer); |
275 | ||
19d7140e | 276 | grid->SetCellValue(3, 0, "0"); |
508011ce VZ |
277 | grid->SetCellRenderer(3, 0, new wxGridCellBoolRenderer); |
278 | grid->SetCellEditor(3, 0, new wxGridCellBoolEditor); | |
279 | ||
758cbedf VZ |
280 | wxGridCellAttr *attr; |
281 | attr = new wxGridCellAttr; | |
282 | attr->SetTextColour(*wxBLUE); | |
283 | grid->SetColAttr(5, attr); | |
284 | attr = new wxGridCellAttr; | |
19d7140e | 285 | attr->SetBackgroundColour(*wxRED); |
758cbedf VZ |
286 | grid->SetRowAttr(5, attr); |
287 | ||
43947979 VZ |
288 | grid->SetCellValue(2, 4, "a wider column"); |
289 | grid->SetColSize(4, 120); | |
290 | grid->SetColMinimalWidth(4, 120); | |
283b7808 | 291 | |
19d7140e VZ |
292 | grid->SetCellTextColour(5, 8, *wxGREEN); |
293 | grid->SetCellValue(5, 8, "Bg from row attr\nText col from cell attr"); | |
294 | grid->SetCellValue(5, 5, "Bg from row attr\nText col from col attr"); | |
0b190b0f | 295 | |
19d7140e | 296 | grid->SetColFormatFloat(6); |
0b190b0f VZ |
297 | grid->SetCellValue(0, 6, "3.1415"); |
298 | grid->SetCellValue(1, 6, "1415"); | |
299 | grid->SetCellValue(2, 6, "12345.67890"); | |
300 | ||
19d7140e VZ |
301 | grid->SetColFormatFloat(7, 6, 2); |
302 | grid->SetCellValue(0, 7, "3.1415"); | |
303 | grid->SetCellValue(1, 7, "1415"); | |
304 | grid->SetCellValue(2, 7, "12345.67890"); | |
305 | ||
e442cc0d MB |
306 | wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL ); |
307 | topSizer->Add( grid, | |
308 | 1, | |
309 | wxEXPAND ); | |
f0102d2a | 310 | |
e442cc0d | 311 | topSizer->Add( logWin, |
f0102d2a | 312 | 0, |
e442cc0d | 313 | wxEXPAND ); |
f0102d2a | 314 | |
e442cc0d MB |
315 | SetAutoLayout( TRUE ); |
316 | SetSizer( topSizer ); | |
f0102d2a | 317 | |
e442cc0d MB |
318 | topSizer->Fit( this ); |
319 | topSizer->SetSizeHints( this ); | |
f0102d2a | 320 | |
e442cc0d MB |
321 | Centre(); |
322 | SetDefaults(); | |
323 | } | |
324 | ||
325 | ||
326 | GridFrame::~GridFrame() | |
327 | { | |
66b3609e | 328 | delete wxLog::SetActiveTarget(m_logOld); |
e442cc0d MB |
329 | } |
330 | ||
f445b853 | 331 | |
e442cc0d MB |
332 | void GridFrame::SetDefaults() |
333 | { | |
334 | GetMenuBar()->Check( ID_TOGGLEROWLABELS, TRUE ); | |
335 | GetMenuBar()->Check( ID_TOGGLECOLLABELS, TRUE ); | |
f445b853 | 336 | GetMenuBar()->Check( ID_TOGGLEEDIT, TRUE ); |
dd16fdae MB |
337 | GetMenuBar()->Check( ID_TOGGLEROWSIZING, TRUE ); |
338 | GetMenuBar()->Check( ID_TOGGLECOLSIZING, TRUE ); | |
4cfa5de6 | 339 | GetMenuBar()->Check( ID_TOGGLEGRIDSIZING, TRUE ); |
f6bcfd97 | 340 | GetMenuBar()->Check( ID_TOGGLEGRIDLINES, TRUE ); |
e442cc0d MB |
341 | } |
342 | ||
343 | ||
344 | void GridFrame::ToggleRowLabels( wxCommandEvent& WXUNUSED(ev) ) | |
345 | { | |
346 | if ( GetMenuBar()->IsChecked( ID_TOGGLEROWLABELS ) ) | |
347 | { | |
348 | grid->SetRowLabelSize( grid->GetDefaultRowLabelSize() ); | |
349 | } | |
350 | else | |
351 | { | |
352 | grid->SetRowLabelSize( 0 ); | |
353 | } | |
354 | } | |
355 | ||
356 | ||
357 | void GridFrame::ToggleColLabels( wxCommandEvent& WXUNUSED(ev) ) | |
358 | { | |
359 | if ( GetMenuBar()->IsChecked( ID_TOGGLECOLLABELS ) ) | |
360 | { | |
361 | grid->SetColLabelSize( grid->GetDefaultColLabelSize() ); | |
362 | } | |
363 | else | |
364 | { | |
365 | grid->SetColLabelSize( 0 ); | |
366 | } | |
367 | } | |
368 | ||
369 | ||
f445b853 | 370 | void GridFrame::ToggleEditing( wxCommandEvent& WXUNUSED(ev) ) |
e442cc0d | 371 | { |
f445b853 MB |
372 | grid->EnableEditing( |
373 | GetMenuBar()->IsChecked( ID_TOGGLEEDIT ) ); | |
e442cc0d MB |
374 | } |
375 | ||
376 | ||
dd16fdae MB |
377 | void GridFrame::ToggleRowSizing( wxCommandEvent& WXUNUSED(ev) ) |
378 | { | |
ea179c7b | 379 | grid->EnableDragRowSize( |
dd16fdae MB |
380 | GetMenuBar()->IsChecked( ID_TOGGLEROWSIZING ) ); |
381 | } | |
382 | ||
383 | ||
384 | void GridFrame::ToggleColSizing( wxCommandEvent& WXUNUSED(ev) ) | |
385 | { | |
ea179c7b | 386 | grid->EnableDragColSize( |
dd16fdae MB |
387 | GetMenuBar()->IsChecked( ID_TOGGLECOLSIZING ) ); |
388 | } | |
389 | ||
4cfa5de6 RD |
390 | void GridFrame::ToggleGridSizing( wxCommandEvent& WXUNUSED(ev) ) |
391 | { | |
392 | grid->EnableDragGridSize( | |
393 | GetMenuBar()->IsChecked( ID_TOGGLEGRIDSIZING ) ); | |
394 | } | |
395 | ||
dd16fdae | 396 | |
f6bcfd97 BP |
397 | void GridFrame::ToggleGridLines( wxCommandEvent& WXUNUSED(ev) ) |
398 | { | |
399 | grid->EnableGridLines( | |
400 | GetMenuBar()->IsChecked( ID_TOGGLEGRIDLINES ) ); | |
401 | } | |
402 | ||
d2520c85 RD |
403 | void GridFrame::OnSetHighlightWidth( wxCommandEvent& WXUNUSED(ev) ) |
404 | { | |
405 | wxString choices[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; | |
406 | ||
407 | wxSingleChoiceDialog dlg(this, "Choose the thickness of the highlight pen:", | |
408 | "Pen Width", 11, choices); | |
409 | ||
410 | int current = grid->GetCellHighlightPenWidth(); | |
411 | dlg.SetSelection(current); | |
412 | if (dlg.ShowModal() == wxID_OK) { | |
413 | grid->SetCellHighlightPenWidth(dlg.GetSelection()); | |
414 | } | |
415 | } | |
416 | ||
417 | void GridFrame::OnSetROHighlightWidth( wxCommandEvent& WXUNUSED(ev) ) | |
418 | { | |
419 | wxString choices[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"}; | |
420 | ||
421 | wxSingleChoiceDialog dlg(this, "Choose the thickness of the highlight pen:", | |
422 | "Pen Width", 11, choices); | |
423 | ||
424 | int current = grid->GetCellHighlightROPenWidth(); | |
425 | dlg.SetSelection(current); | |
426 | if (dlg.ShowModal() == wxID_OK) { | |
427 | grid->SetCellHighlightROPenWidth(dlg.GetSelection()); | |
428 | } | |
429 | } | |
430 | ||
431 | ||
f6bcfd97 BP |
432 | |
433 | void GridFrame::AutoSizeCols( wxCommandEvent& WXUNUSED(ev) ) | |
434 | { | |
435 | grid->AutoSizeColumns(); | |
436 | grid->Refresh(); | |
437 | } | |
438 | ||
439 | ||
e442cc0d MB |
440 | void GridFrame::SetLabelColour( wxCommandEvent& WXUNUSED(ev) ) |
441 | { | |
442 | wxColourDialog dlg( NULL ); | |
443 | if ( dlg.ShowModal() == wxID_OK ) | |
444 | { | |
445 | wxColourData retData; | |
446 | retData = dlg.GetColourData(); | |
447 | wxColour colour = retData.GetColour(); | |
448 | ||
449 | grid->SetLabelBackgroundColour( colour ); | |
450 | } | |
451 | } | |
452 | ||
453 | ||
454 | void GridFrame::SetLabelTextColour( wxCommandEvent& WXUNUSED(ev) ) | |
455 | { | |
456 | wxColourDialog dlg( NULL ); | |
457 | if ( dlg.ShowModal() == wxID_OK ) | |
458 | { | |
459 | wxColourData retData; | |
460 | retData = dlg.GetColourData(); | |
461 | wxColour colour = retData.GetColour(); | |
462 | ||
463 | grid->SetLabelTextColour( colour ); | |
464 | } | |
465 | } | |
466 | ||
bf9adb3a VZ |
467 | void GridFrame::SetLabelFont( wxCommandEvent& WXUNUSED(ev) ) |
468 | { | |
469 | wxFont font = wxGetFontFromUser(this); | |
470 | if ( font.Ok() ) | |
471 | { | |
472 | grid->SetLabelFont(font); | |
473 | } | |
474 | } | |
e442cc0d MB |
475 | |
476 | void GridFrame::SetRowLabelHorizAlignment( wxCommandEvent& WXUNUSED(ev) ) | |
477 | { | |
478 | int horiz, vert; | |
479 | grid->GetRowLabelAlignment( &horiz, &vert ); | |
f0102d2a | 480 | |
e442cc0d MB |
481 | switch ( horiz ) |
482 | { | |
0767cb6f MB |
483 | case wxALIGN_LEFT: |
484 | horiz = wxALIGN_CENTRE; | |
e442cc0d | 485 | break; |
f0102d2a | 486 | |
0767cb6f MB |
487 | case wxALIGN_CENTRE: |
488 | horiz = wxALIGN_RIGHT; | |
e442cc0d MB |
489 | break; |
490 | ||
0767cb6f MB |
491 | case wxALIGN_RIGHT: |
492 | horiz = wxALIGN_LEFT; | |
e442cc0d MB |
493 | break; |
494 | } | |
495 | ||
496 | grid->SetRowLabelAlignment( horiz, -1 ); | |
497 | } | |
498 | ||
499 | void GridFrame::SetRowLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) ) | |
500 | { | |
501 | int horiz, vert; | |
502 | grid->GetRowLabelAlignment( &horiz, &vert ); | |
f0102d2a | 503 | |
e442cc0d MB |
504 | switch ( vert ) |
505 | { | |
0767cb6f MB |
506 | case wxALIGN_TOP: |
507 | vert = wxALIGN_CENTRE; | |
e442cc0d | 508 | break; |
f0102d2a | 509 | |
0767cb6f MB |
510 | case wxALIGN_CENTRE: |
511 | vert = wxALIGN_BOTTOM; | |
e442cc0d MB |
512 | break; |
513 | ||
0767cb6f MB |
514 | case wxALIGN_BOTTOM: |
515 | vert = wxALIGN_TOP; | |
e442cc0d MB |
516 | break; |
517 | } | |
518 | ||
519 | grid->SetRowLabelAlignment( -1, vert ); | |
520 | } | |
521 | ||
522 | ||
523 | void GridFrame::SetColLabelHorizAlignment( wxCommandEvent& WXUNUSED(ev) ) | |
524 | { | |
525 | int horiz, vert; | |
526 | grid->GetColLabelAlignment( &horiz, &vert ); | |
f0102d2a | 527 | |
e442cc0d MB |
528 | switch ( horiz ) |
529 | { | |
0767cb6f MB |
530 | case wxALIGN_LEFT: |
531 | horiz = wxALIGN_CENTRE; | |
e442cc0d | 532 | break; |
f0102d2a | 533 | |
0767cb6f MB |
534 | case wxALIGN_CENTRE: |
535 | horiz = wxALIGN_RIGHT; | |
e442cc0d MB |
536 | break; |
537 | ||
0767cb6f MB |
538 | case wxALIGN_RIGHT: |
539 | horiz = wxALIGN_LEFT; | |
e442cc0d MB |
540 | break; |
541 | } | |
542 | ||
543 | grid->SetColLabelAlignment( horiz, -1 ); | |
544 | } | |
545 | ||
546 | ||
547 | void GridFrame::SetColLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) ) | |
548 | { | |
549 | int horiz, vert; | |
550 | grid->GetColLabelAlignment( &horiz, &vert ); | |
f0102d2a | 551 | |
e442cc0d MB |
552 | switch ( vert ) |
553 | { | |
0767cb6f MB |
554 | case wxALIGN_TOP: |
555 | vert = wxALIGN_CENTRE; | |
e442cc0d | 556 | break; |
f0102d2a | 557 | |
0767cb6f MB |
558 | case wxALIGN_CENTRE: |
559 | vert = wxALIGN_BOTTOM; | |
e442cc0d MB |
560 | break; |
561 | ||
0767cb6f MB |
562 | case wxALIGN_BOTTOM: |
563 | vert = wxALIGN_TOP; | |
e442cc0d MB |
564 | break; |
565 | } | |
566 | ||
567 | grid->SetColLabelAlignment( -1, vert ); | |
568 | } | |
569 | ||
570 | ||
571 | void GridFrame::SetGridLineColour( wxCommandEvent& WXUNUSED(ev) ) | |
572 | { | |
573 | wxColourDialog dlg( NULL ); | |
574 | if ( dlg.ShowModal() == wxID_OK ) | |
575 | { | |
576 | wxColourData retData; | |
577 | retData = dlg.GetColourData(); | |
578 | wxColour colour = retData.GetColour(); | |
579 | ||
580 | grid->SetGridLineColour( colour ); | |
581 | } | |
582 | } | |
583 | ||
584 | ||
0eee5283 MB |
585 | void GridFrame::InsertRow( wxCommandEvent& WXUNUSED(ev) ) |
586 | { | |
4e5b5abb | 587 | grid->InsertRows( grid->GetGridCursorRow(), 1 ); |
0eee5283 MB |
588 | } |
589 | ||
590 | ||
591 | void GridFrame::InsertCol( wxCommandEvent& WXUNUSED(ev) ) | |
592 | { | |
4e5b5abb | 593 | grid->InsertCols( grid->GetGridCursorCol(), 1 ); |
0eee5283 MB |
594 | } |
595 | ||
596 | ||
f445b853 | 597 | void GridFrame::DeleteSelectedRows( wxCommandEvent& WXUNUSED(ev) ) |
0eee5283 | 598 | { |
f445b853 MB |
599 | if ( grid->IsSelection() ) |
600 | { | |
f6bcfd97 BP |
601 | grid->BeginBatch(); |
602 | for ( int n = 0; n < grid->GetNumberRows(); ) | |
5c8fc7c1 SN |
603 | if ( grid->IsInSelection( n , 0 ) ) |
604 | grid->DeleteRows( n, 1 ); | |
2f6c54eb VZ |
605 | else |
606 | n++; | |
f6bcfd97 | 607 | grid->EndBatch(); |
f445b853 | 608 | } |
0eee5283 MB |
609 | } |
610 | ||
611 | ||
f445b853 | 612 | void GridFrame::DeleteSelectedCols( wxCommandEvent& WXUNUSED(ev) ) |
0eee5283 | 613 | { |
f445b853 MB |
614 | if ( grid->IsSelection() ) |
615 | { | |
f6bcfd97 BP |
616 | grid->BeginBatch(); |
617 | for ( int n = 0; n < grid->GetNumberCols(); ) | |
5c8fc7c1 SN |
618 | if ( grid->IsInSelection( 0 , n ) ) |
619 | grid->DeleteCols( n, 1 ); | |
2f6c54eb VZ |
620 | else |
621 | n++; | |
f6bcfd97 | 622 | grid->EndBatch(); |
f445b853 | 623 | } |
0eee5283 MB |
624 | } |
625 | ||
626 | ||
e442cc0d MB |
627 | void GridFrame::ClearGrid( wxCommandEvent& WXUNUSED(ev) ) |
628 | { | |
629 | grid->ClearGrid(); | |
630 | } | |
631 | ||
043d16b2 SN |
632 | void GridFrame::SelectCells( wxCommandEvent& WXUNUSED(ev) ) |
633 | { | |
634 | grid->SetSelectionMode( wxGrid::wxGridSelectCells ); | |
635 | } | |
636 | ||
637 | void GridFrame::SelectRows( wxCommandEvent& WXUNUSED(ev) ) | |
638 | { | |
639 | grid->SetSelectionMode( wxGrid::wxGridSelectRows ); | |
640 | } | |
641 | ||
642 | void GridFrame::SelectCols( wxCommandEvent& WXUNUSED(ev) ) | |
643 | { | |
644 | grid->SetSelectionMode( wxGrid::wxGridSelectColumns ); | |
645 | } | |
646 | ||
ab79958a VZ |
647 | void GridFrame::SetCellFgColour( wxCommandEvent& WXUNUSED(ev) ) |
648 | { | |
649 | wxColour col = wxGetColourFromUser(this); | |
650 | if ( col.Ok() ) | |
758cbedf | 651 | { |
ab79958a | 652 | grid->SetDefaultCellTextColour(col); |
758cbedf VZ |
653 | grid->Refresh(); |
654 | } | |
ab79958a VZ |
655 | } |
656 | ||
657 | void GridFrame::SetCellBgColour( wxCommandEvent& WXUNUSED(ev) ) | |
658 | { | |
659 | wxColour col = wxGetColourFromUser(this); | |
660 | if ( col.Ok() ) | |
758cbedf | 661 | { |
ab79958a | 662 | grid->SetDefaultCellBackgroundColour(col); |
758cbedf VZ |
663 | grid->Refresh(); |
664 | } | |
ab79958a | 665 | } |
e442cc0d | 666 | |
14e5a313 VZ |
667 | void GridFrame::DeselectCell(wxCommandEvent& WXUNUSED(event)) |
668 | { | |
669 | grid->DeselectCell(3, 1); | |
670 | } | |
671 | ||
672 | void GridFrame::DeselectCol(wxCommandEvent& WXUNUSED(event)) | |
673 | { | |
674 | grid->DeselectCol(2); | |
675 | } | |
676 | ||
677 | void GridFrame::DeselectRow(wxCommandEvent& WXUNUSED(event)) | |
678 | { | |
679 | grid->DeselectRow(2); | |
680 | } | |
681 | ||
682 | void GridFrame::DeselectAll(wxCommandEvent& WXUNUSED(event)) | |
683 | { | |
684 | grid->ClearSelection(); | |
685 | } | |
686 | ||
687 | void GridFrame::SelectCell(wxCommandEvent& WXUNUSED(event)) | |
688 | { | |
93521c94 | 689 | grid->SelectBlock(3, 1, 3, 1, m_addToSel); |
14e5a313 VZ |
690 | } |
691 | ||
692 | void GridFrame::SelectCol(wxCommandEvent& WXUNUSED(event)) | |
693 | { | |
93521c94 | 694 | grid->SelectCol(2, m_addToSel); |
14e5a313 VZ |
695 | } |
696 | ||
697 | void GridFrame::SelectRow(wxCommandEvent& WXUNUSED(event)) | |
698 | { | |
93521c94 | 699 | grid->SelectRow(2, m_addToSel); |
14e5a313 VZ |
700 | } |
701 | ||
702 | void GridFrame::SelectAll(wxCommandEvent& WXUNUSED(event)) | |
703 | { | |
704 | grid->SelectAll(); | |
705 | } | |
706 | ||
93521c94 VZ |
707 | void GridFrame::OnAddToSelectToggle(wxCommandEvent& event) |
708 | { | |
709 | m_addToSel = event.IsChecked(); | |
710 | } | |
711 | ||
e442cc0d MB |
712 | void GridFrame::OnLabelLeftClick( wxGridEvent& ev ) |
713 | { | |
714 | logBuf = ""; | |
715 | if ( ev.GetRow() != -1 ) | |
716 | { | |
c336585e | 717 | logBuf << "Left click on row label " << ev.GetRow(); |
e442cc0d MB |
718 | } |
719 | else if ( ev.GetCol() != -1 ) | |
720 | { | |
c336585e | 721 | logBuf << "Left click on col label " << ev.GetCol(); |
e442cc0d MB |
722 | } |
723 | else | |
724 | { | |
c336585e | 725 | logBuf << "Left click on corner label"; |
e442cc0d MB |
726 | } |
727 | ||
728 | if ( ev.ShiftDown() ) logBuf << " (shift down)"; | |
e32352cf | 729 | if ( ev.ControlDown() ) logBuf << " (control down)"; |
4693b20c | 730 | wxLogMessage( wxT("%s"), logBuf.c_str() ); |
f0102d2a | 731 | |
c336585e MB |
732 | // you must call event skip if you want default grid processing |
733 | // | |
e442cc0d MB |
734 | ev.Skip(); |
735 | } | |
736 | ||
737 | ||
738 | void GridFrame::OnCellLeftClick( wxGridEvent& ev ) | |
739 | { | |
740 | logBuf = ""; | |
c336585e | 741 | logBuf << "Left click at row " << ev.GetRow() |
e442cc0d | 742 | << " col " << ev.GetCol(); |
4693b20c | 743 | wxLogMessage( wxT("%s"), logBuf.c_str() ); |
0eee5283 | 744 | |
e442cc0d MB |
745 | // you must call event skip if you want default grid processing |
746 | // (cell highlighting etc.) | |
747 | // | |
748 | ev.Skip(); | |
749 | } | |
750 | ||
751 | ||
752 | void GridFrame::OnRowSize( wxGridSizeEvent& ev ) | |
753 | { | |
754 | logBuf = ""; | |
755 | logBuf << "Resized row " << ev.GetRowOrCol(); | |
4693b20c | 756 | wxLogMessage( wxT("%s"), logBuf.c_str() ); |
f0102d2a | 757 | |
e442cc0d MB |
758 | ev.Skip(); |
759 | } | |
760 | ||
761 | ||
762 | void GridFrame::OnColSize( wxGridSizeEvent& ev ) | |
763 | { | |
764 | logBuf = ""; | |
765 | logBuf << "Resized col " << ev.GetRowOrCol(); | |
4693b20c | 766 | wxLogMessage( wxT("%s"), logBuf.c_str() ); |
f0102d2a | 767 | |
e442cc0d MB |
768 | ev.Skip(); |
769 | } | |
770 | ||
c336585e MB |
771 | |
772 | void GridFrame::OnSelectCell( wxGridEvent& ev ) | |
773 | { | |
774 | logBuf = ""; | |
5c8fc7c1 SN |
775 | if ( ev.Selecting() ) |
776 | logBuf << "Selected "; | |
777 | else | |
778 | logBuf << "Deselected "; | |
779 | logBuf << "cell at row " << ev.GetRow() | |
d95b0c2b | 780 | << " col " << ev.GetCol() |
f41986da MB |
781 | << " ( ControlDown: "<< (ev.ControlDown() ? 'T':'F') |
782 | << ", ShiftDown: "<< (ev.ShiftDown() ? 'T':'F') | |
783 | << ", AltDown: "<< (ev.AltDown() ? 'T':'F') | |
784 | << ", MetaDown: "<< (ev.MetaDown() ? 'T':'F') << " )"; | |
4693b20c | 785 | wxLogMessage( wxT("%s"), logBuf.c_str() ); |
f0102d2a | 786 | |
c336585e MB |
787 | // you must call Skip() if you want the default processing |
788 | // to occur in wxGrid | |
789 | ev.Skip(); | |
790 | } | |
791 | ||
e442cc0d MB |
792 | void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev ) |
793 | { | |
794 | logBuf = ""; | |
5c8fc7c1 SN |
795 | if ( ev.Selecting() ) |
796 | logBuf << "Selected "; | |
797 | else | |
798 | logBuf << "Deselected "; | |
799 | logBuf << "cells from row " << ev.GetTopRow() | |
800 | << " col " << ev.GetLeftCol() | |
801 | << " to row " << ev.GetBottomRow() | |
d95b0c2b | 802 | << " col " << ev.GetRightCol() |
f41986da MB |
803 | << " ( ControlDown: "<< (ev.ControlDown() ? 'T':'F') |
804 | << ", ShiftDown: "<< (ev.ShiftDown() ? 'T':'F') | |
805 | << ", AltDown: "<< (ev.AltDown() ? 'T':'F') | |
806 | << ", MetaDown: "<< (ev.MetaDown() ? 'T':'F') << " )"; | |
4693b20c | 807 | wxLogMessage( wxT("%s"), logBuf.c_str() ); |
f0102d2a | 808 | |
e442cc0d MB |
809 | ev.Skip(); |
810 | } | |
811 | ||
812 | void GridFrame::OnCellValueChanged( wxGridEvent& ev ) | |
813 | { | |
814 | logBuf = ""; | |
815 | logBuf << "Value changed for cell at" | |
f0102d2a | 816 | << " row " << ev.GetRow() |
e442cc0d | 817 | << " col " << ev.GetCol(); |
f0102d2a | 818 | |
4693b20c | 819 | wxLogMessage( wxT("%s"), logBuf.c_str() ); |
f0102d2a | 820 | |
e442cc0d MB |
821 | ev.Skip(); |
822 | } | |
823 | ||
b54ba671 VZ |
824 | void GridFrame::OnEditorShown( wxGridEvent& ev ) |
825 | { | |
fe7b9ed6 VZ |
826 | |
827 | if ( (ev.GetCol() == 4) && | |
828 | (ev.GetRow() == 0) && | |
2f6c54eb VZ |
829 | (wxMessageBox(_T("Are you sure you wish to edit this cell"), |
830 | _T("Checking"),wxYES_NO) == wxNO ) ) { | |
fe7b9ed6 | 831 | |
2f6c54eb VZ |
832 | ev.Veto(); |
833 | return; | |
fe7b9ed6 | 834 | } |
2f6c54eb | 835 | |
4693b20c | 836 | wxLogMessage( wxT("Cell editor shown.") ); |
b54ba671 VZ |
837 | |
838 | ev.Skip(); | |
839 | } | |
840 | ||
841 | void GridFrame::OnEditorHidden( wxGridEvent& ev ) | |
842 | { | |
671bcff5 | 843 | |
fe7b9ed6 VZ |
844 | if ( (ev.GetCol() == 4) && |
845 | (ev.GetRow() == 0) && | |
2f6c54eb VZ |
846 | (wxMessageBox(_T("Are you sure you wish to finish editing this cell"), |
847 | _T("Checking"),wxYES_NO) == wxNO ) ) { | |
fe7b9ed6 | 848 | |
2f6c54eb VZ |
849 | ev.Veto(); |
850 | return; | |
fe7b9ed6 VZ |
851 | } |
852 | ||
4693b20c | 853 | wxLogMessage( wxT("Cell editor hidden.") ); |
b54ba671 VZ |
854 | |
855 | ev.Skip(); | |
856 | } | |
e442cc0d | 857 | |
f445b853 MB |
858 | void GridFrame::About( wxCommandEvent& WXUNUSED(ev) ) |
859 | { | |
860 | (void)wxMessageBox( "\n\nwxGrid demo \n\n" | |
861 | "Michael Bedward \n" | |
862 | "mbedward@ozemail.com.au \n\n", | |
863 | "About", | |
864 | wxOK ); | |
865 | } | |
866 | ||
867 | ||
868 | void GridFrame::OnQuit( wxCommandEvent& WXUNUSED(ev) ) | |
869 | { | |
870 | Close( TRUE ); | |
871 | } | |
872 | ||
35f97e95 VZ |
873 | void GridFrame::OnBugsTable(wxCommandEvent& ) |
874 | { | |
875 | BugsGridFrame *frame = new BugsGridFrame; | |
876 | frame->Show(TRUE); | |
877 | } | |
878 | ||
671bcff5 RD |
879 | void GridFrame::OnSmallGrid(wxCommandEvent& ) |
880 | { | |
881 | wxFrame* frame = new wxFrame(NULL, -1, "A Small Grid", | |
882 | wxDefaultPosition, wxSize(640, 480)); | |
883 | wxPanel* panel = new wxPanel(frame, -1); | |
884 | wxGrid* grid = new wxGrid(panel, -1, wxPoint(10,10), wxSize(400,400), | |
885 | wxWANTS_CHARS | wxSIMPLE_BORDER); | |
886 | grid->CreateGrid(3,3); | |
887 | frame->Show(TRUE); | |
888 | } | |
19d7140e | 889 | |
f97c9b5b RD |
890 | void GridFrame::OnVTable(wxCommandEvent& ) |
891 | { | |
1618dca7 VZ |
892 | static long s_sizeGrid = 10000; |
893 | ||
b0c8fc35 MB |
894 | #ifdef __WXMOTIF__ |
895 | // MB: wxGetNumberFromUser doesn't work properly for wxMotif | |
896 | wxString s; | |
897 | s << s_sizeGrid; | |
898 | s = wxGetTextFromUser( "Size of the table to create", | |
899 | "Size:", | |
900 | s ); | |
c4608a8a | 901 | |
b0c8fc35 | 902 | s.ToLong( &s_sizeGrid ); |
c4608a8a | 903 | |
b0c8fc35 | 904 | #else |
1618dca7 VZ |
905 | s_sizeGrid = wxGetNumberFromUser("Size of the table to create", |
906 | "Size: ", | |
907 | "wxGridDemo question", | |
908 | s_sizeGrid, | |
909 | 0, 32000, this); | |
b0c8fc35 | 910 | #endif |
c4608a8a | 911 | |
1618dca7 VZ |
912 | if ( s_sizeGrid != -1 ) |
913 | { | |
914 | BigGridFrame* win = new BigGridFrame(s_sizeGrid); | |
915 | win->Show(TRUE); | |
916 | } | |
f97c9b5b RD |
917 | } |
918 | ||
ab79958a VZ |
919 | // ---------------------------------------------------------------------------- |
920 | // MyGridCellRenderer | |
921 | // ---------------------------------------------------------------------------- | |
922 | ||
758cbedf VZ |
923 | // do something that the default renderer doesn't here just to show that it is |
924 | // possible to alter the appearance of the cell beyond what the attributes | |
925 | // allow | |
ab79958a | 926 | void MyGridCellRenderer::Draw(wxGrid& grid, |
f97c9b5b | 927 | wxGridCellAttr& attr, |
ab79958a VZ |
928 | wxDC& dc, |
929 | const wxRect& rect, | |
930 | int row, int col, | |
931 | bool isSelected) | |
932 | { | |
f97c9b5b | 933 | wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected); |
ab79958a VZ |
934 | |
935 | dc.SetPen(*wxGREEN_PEN); | |
936 | dc.SetBrush(*wxTRANSPARENT_BRUSH); | |
937 | dc.DrawEllipse(rect); | |
938 | } | |
f97c9b5b | 939 | |
f97c9b5b | 940 | // ---------------------------------------------------------------------------- |
a68c1246 | 941 | // MyGridCellAttrProvider |
f97c9b5b RD |
942 | // ---------------------------------------------------------------------------- |
943 | ||
a68c1246 VZ |
944 | MyGridCellAttrProvider::MyGridCellAttrProvider() |
945 | { | |
946 | m_attrForOddRows = new wxGridCellAttr; | |
947 | m_attrForOddRows->SetBackgroundColour(*wxLIGHT_GREY); | |
948 | } | |
949 | ||
950 | MyGridCellAttrProvider::~MyGridCellAttrProvider() | |
951 | { | |
952 | m_attrForOddRows->DecRef(); | |
953 | } | |
954 | ||
19d7140e VZ |
955 | wxGridCellAttr *MyGridCellAttrProvider::GetAttr(int row, int col, |
956 | wxGridCellAttr::wxAttrKind kind /* = wxGridCellAttr::Any */) const | |
a68c1246 | 957 | { |
19d7140e | 958 | wxGridCellAttr *attr = wxGridCellAttrProvider::GetAttr(row, col, kind); |
a68c1246 VZ |
959 | |
960 | if ( row % 2 ) | |
961 | { | |
962 | if ( !attr ) | |
963 | { | |
964 | attr = m_attrForOddRows; | |
965 | attr->IncRef(); | |
966 | } | |
967 | else | |
968 | { | |
969 | if ( !attr->HasBackgroundColour() ) | |
970 | { | |
971 | wxGridCellAttr *attrNew = attr->Clone(); | |
972 | attr->DecRef(); | |
973 | attr = attrNew; | |
974 | attr->SetBackgroundColour(*wxLIGHT_GREY); | |
975 | } | |
976 | } | |
977 | } | |
978 | ||
979 | return attr; | |
980 | } | |
981 | ||
982 | // ============================================================================ | |
983 | // BigGridFrame and BigGridTable: Sample of a non-standard table | |
984 | // ============================================================================ | |
985 | ||
1618dca7 VZ |
986 | BigGridFrame::BigGridFrame(long sizeGrid) |
987 | : wxFrame(NULL, -1, "Plugin Virtual Table", | |
988 | wxDefaultPosition, wxSize(500, 450)) | |
f97c9b5b RD |
989 | { |
990 | m_grid = new wxGrid(this, -1, wxDefaultPosition, wxDefaultSize); | |
1618dca7 | 991 | m_table = new BigGridTable(sizeGrid); |
a68c1246 VZ |
992 | |
993 | // VZ: I don't understand why this slows down the display that much, | |
994 | // must profile it... | |
995 | //m_table->SetAttrProvider(new MyGridCellAttrProvider); | |
996 | ||
f97c9b5b | 997 | m_grid->SetTable(m_table, TRUE); |
b0c8fc35 MB |
998 | |
999 | #if defined __WXMOTIF__ | |
1000 | // MB: the grid isn't getting a sensible default size under wxMotif | |
1001 | int cw, ch; | |
1002 | GetClientSize( &cw, &ch ); | |
1003 | m_grid->SetSize( cw, ch ); | |
1004 | #endif | |
f97c9b5b | 1005 | } |
35f97e95 | 1006 | |
a68c1246 | 1007 | // ============================================================================ |
35f97e95 | 1008 | // BugsGridFrame: a "realistic" table |
a68c1246 VZ |
1009 | // ============================================================================ |
1010 | ||
1011 | // ---------------------------------------------------------------------------- | |
1012 | // bugs table data | |
35f97e95 VZ |
1013 | // ---------------------------------------------------------------------------- |
1014 | ||
816be743 VZ |
1015 | enum Columns |
1016 | { | |
1017 | Col_Id, | |
1018 | Col_Summary, | |
1019 | Col_Severity, | |
1020 | Col_Priority, | |
1021 | Col_Platform, | |
1022 | Col_Opened, | |
1023 | Col_Max | |
1024 | }; | |
1025 | ||
1026 | enum Severity | |
1027 | { | |
1028 | Sev_Wish, | |
1029 | Sev_Minor, | |
1030 | Sev_Normal, | |
1031 | Sev_Major, | |
1032 | Sev_Critical, | |
1033 | Sev_Max | |
1034 | }; | |
1035 | ||
f6bcfd97 | 1036 | static const wxString severities[] = |
816be743 VZ |
1037 | { |
1038 | _T("wishlist"), | |
1039 | _T("minor"), | |
1040 | _T("normal"), | |
1041 | _T("major"), | |
1042 | _T("critical"), | |
1043 | }; | |
1044 | ||
1045 | static struct BugsGridData | |
1046 | { | |
1047 | int id; | |
9121bed2 | 1048 | wxChar summary[80]; |
816be743 VZ |
1049 | Severity severity; |
1050 | int prio; | |
9121bed2 | 1051 | wxChar platform[12]; |
816be743 | 1052 | bool opened; |
c4608a8a | 1053 | } gs_dataBugsGrid [] = |
816be743 VZ |
1054 | { |
1055 | { 18, _T("foo doesn't work"), Sev_Major, 1, _T("wxMSW"), TRUE }, | |
1056 | { 27, _T("bar crashes"), Sev_Critical, 1, _T("all"), FALSE }, | |
1057 | { 45, _T("printing is slow"), Sev_Minor, 3, _T("wxMSW"), TRUE }, | |
1058 | { 68, _T("Rectangle() fails"), Sev_Normal, 1, _T("wxMSW"), FALSE }, | |
1059 | }; | |
1060 | ||
1061 | static const wxChar *headers[Col_Max] = | |
1062 | { | |
1063 | _T("Id"), | |
1064 | _T("Summary"), | |
1065 | _T("Severity"), | |
1066 | _T("Priority"), | |
1067 | _T("Platform"), | |
1068 | _T("Opened?"), | |
1069 | }; | |
1070 | ||
a68c1246 VZ |
1071 | // ---------------------------------------------------------------------------- |
1072 | // BugsGridTable | |
1073 | // ---------------------------------------------------------------------------- | |
1074 | ||
816be743 VZ |
1075 | wxString BugsGridTable::GetTypeName(int WXUNUSED(row), int col) |
1076 | { | |
1077 | switch ( col ) | |
1078 | { | |
1079 | case Col_Id: | |
1080 | case Col_Priority: | |
1081 | return wxGRID_VALUE_NUMBER;; | |
1082 | ||
1083 | case Col_Severity: | |
1084 | // fall thorugh (TODO should be a list) | |
1085 | ||
1086 | case Col_Summary: | |
c4608a8a VZ |
1087 | return wxString::Format(_T("%s:80"), wxGRID_VALUE_STRING); |
1088 | ||
816be743 | 1089 | case Col_Platform: |
c4608a8a | 1090 | return wxString::Format(_T("%s:all,MSW,GTK,other"), wxGRID_VALUE_CHOICE); |
816be743 VZ |
1091 | |
1092 | case Col_Opened: | |
1093 | return wxGRID_VALUE_BOOL; | |
1094 | } | |
1095 | ||
1096 | wxFAIL_MSG(_T("unknown column")); | |
1097 | ||
1098 | return wxEmptyString; | |
1099 | } | |
1100 | ||
e32352cf | 1101 | int BugsGridTable::GetNumberRows() |
816be743 VZ |
1102 | { |
1103 | return WXSIZEOF(gs_dataBugsGrid); | |
1104 | } | |
1105 | ||
e32352cf | 1106 | int BugsGridTable::GetNumberCols() |
35f97e95 | 1107 | { |
816be743 VZ |
1108 | return Col_Max; |
1109 | } | |
1110 | ||
1111 | bool BugsGridTable::IsEmptyCell( int row, int col ) | |
1112 | { | |
1113 | return FALSE; | |
1114 | } | |
1115 | ||
1116 | wxString BugsGridTable::GetValue( int row, int col ) | |
1117 | { | |
1118 | const BugsGridData& gd = gs_dataBugsGrid[row]; | |
1119 | ||
1120 | switch ( col ) | |
35f97e95 | 1121 | { |
816be743 VZ |
1122 | case Col_Id: |
1123 | case Col_Priority: | |
1124 | case Col_Opened: | |
1125 | wxFAIL_MSG(_T("unexpected column")); | |
1126 | break; | |
1127 | ||
1128 | case Col_Severity: | |
1129 | return severities[gd.severity]; | |
1130 | ||
1131 | case Col_Summary: | |
1132 | return gd.summary; | |
1133 | ||
1134 | case Col_Platform: | |
1135 | return gd.platform; | |
1136 | } | |
1137 | ||
1138 | return wxEmptyString; | |
1139 | } | |
1140 | ||
1141 | void BugsGridTable::SetValue( int row, int col, const wxString& value ) | |
1142 | { | |
1143 | BugsGridData& gd = gs_dataBugsGrid[row]; | |
35f97e95 | 1144 | |
816be743 | 1145 | switch ( col ) |
35f97e95 | 1146 | { |
816be743 VZ |
1147 | case Col_Id: |
1148 | case Col_Priority: | |
1149 | case Col_Opened: | |
1150 | wxFAIL_MSG(_T("unexpected column")); | |
1151 | break; | |
1152 | ||
1153 | case Col_Severity: | |
1154 | { | |
1155 | size_t n; | |
1156 | for ( n = 0; n < WXSIZEOF(severities); n++ ) | |
1157 | { | |
1158 | if ( severities[n] == value ) | |
1159 | { | |
1160 | gd.severity = (Severity)n; | |
1161 | break; | |
1162 | } | |
1163 | } | |
1164 | ||
1165 | if ( n == WXSIZEOF(severities) ) | |
1166 | { | |
1167 | wxLogWarning(_T("Invalid severity value '%s'."), | |
1168 | value.c_str()); | |
1169 | gd.severity = Sev_Normal; | |
1170 | } | |
1171 | } | |
ed23853b | 1172 | break; |
816be743 VZ |
1173 | |
1174 | case Col_Summary: | |
9121bed2 | 1175 | wxStrncpy(gd.summary, value, WXSIZEOF(gd.summary)); |
816be743 | 1176 | break; |
35f97e95 | 1177 | |
816be743 | 1178 | case Col_Platform: |
9121bed2 | 1179 | wxStrncpy(gd.platform, value, WXSIZEOF(gd.platform)); |
816be743 VZ |
1180 | break; |
1181 | } | |
1182 | } | |
1183 | ||
1184 | bool BugsGridTable::CanGetValueAs( int WXUNUSED(row), int col, const wxString& typeName ) | |
1185 | { | |
1186 | if ( typeName == wxGRID_VALUE_STRING ) | |
35f97e95 | 1187 | { |
816be743 VZ |
1188 | return TRUE; |
1189 | } | |
1190 | else if ( typeName == wxGRID_VALUE_BOOL ) | |
1191 | { | |
1192 | return col == Col_Opened; | |
1193 | } | |
1194 | else if ( typeName == wxGRID_VALUE_NUMBER ) | |
1195 | { | |
1196 | return col == Col_Id || col == Col_Priority || col == Col_Severity; | |
1197 | } | |
1198 | else | |
35f97e95 | 1199 | { |
816be743 VZ |
1200 | return FALSE; |
1201 | } | |
1202 | } | |
1203 | ||
1204 | bool BugsGridTable::CanSetValueAs( int row, int col, const wxString& typeName ) | |
1205 | { | |
1206 | return CanGetValueAs(row, col, typeName); | |
1207 | } | |
1208 | ||
1209 | long BugsGridTable::GetValueAsLong( int row, int col ) | |
1210 | { | |
1211 | const BugsGridData& gd = gs_dataBugsGrid[row]; | |
35f97e95 | 1212 | |
816be743 | 1213 | switch ( col ) |
35f97e95 | 1214 | { |
816be743 VZ |
1215 | case Col_Id: |
1216 | return gd.id; | |
35f97e95 | 1217 | |
816be743 VZ |
1218 | case Col_Priority: |
1219 | return gd.prio; | |
35f97e95 | 1220 | |
816be743 VZ |
1221 | case Col_Severity: |
1222 | return gd.severity; | |
1223 | ||
1224 | default: | |
1225 | wxFAIL_MSG(_T("unexpected column")); | |
1226 | return -1; | |
1227 | } | |
1228 | } | |
1229 | ||
1230 | bool BugsGridTable::GetValueAsBool( int row, int col ) | |
1231 | { | |
1232 | if ( col == Col_Opened ) | |
1233 | { | |
1234 | return gs_dataBugsGrid[row].opened; | |
1235 | } | |
1236 | else | |
35f97e95 | 1237 | { |
816be743 VZ |
1238 | wxFAIL_MSG(_T("unexpected column")); |
1239 | ||
1240 | return FALSE; | |
35f97e95 | 1241 | } |
816be743 | 1242 | } |
35f97e95 | 1243 | |
816be743 VZ |
1244 | void BugsGridTable::SetValueAsLong( int row, int col, long value ) |
1245 | { | |
1246 | BugsGridData& gd = gs_dataBugsGrid[row]; | |
1247 | ||
1248 | switch ( col ) | |
35f97e95 | 1249 | { |
816be743 VZ |
1250 | case Col_Priority: |
1251 | gd.prio = value; | |
1252 | break; | |
1253 | ||
1254 | default: | |
1255 | wxFAIL_MSG(_T("unexpected column")); | |
35f97e95 | 1256 | } |
816be743 | 1257 | } |
35f97e95 | 1258 | |
816be743 VZ |
1259 | void BugsGridTable::SetValueAsBool( int row, int col, bool value ) |
1260 | { | |
1261 | if ( col == Col_Opened ) | |
1262 | { | |
1263 | gs_dataBugsGrid[row].opened = value; | |
1264 | } | |
1265 | else | |
1266 | { | |
1267 | wxFAIL_MSG(_T("unexpected column")); | |
1268 | } | |
1269 | } | |
1270 | ||
1271 | wxString BugsGridTable::GetColLabelValue( int col ) | |
1272 | { | |
1273 | return headers[col]; | |
1274 | } | |
1275 | ||
1276 | BugsGridTable::BugsGridTable() | |
1277 | { | |
1278 | } | |
1279 | ||
a68c1246 VZ |
1280 | // ---------------------------------------------------------------------------- |
1281 | // BugsGridFrame | |
1282 | // ---------------------------------------------------------------------------- | |
1283 | ||
816be743 VZ |
1284 | BugsGridFrame::BugsGridFrame() |
1285 | : wxFrame(NULL, -1, "Bugs table", | |
1286 | wxDefaultPosition, wxSize(500, 300)) | |
1287 | { | |
1288 | wxGrid *grid = new wxGrid(this, -1, wxDefaultPosition); | |
1289 | wxGridTableBase *table = new BugsGridTable(); | |
a68c1246 | 1290 | table->SetAttrProvider(new MyGridCellAttrProvider); |
35f97e95 | 1291 | grid->SetTable(table, TRUE); |
816be743 | 1292 | |
65e4e78e | 1293 | wxGridCellAttr *attrRO = new wxGridCellAttr, |
4ee5fc9c VZ |
1294 | *attrRangeEditor = new wxGridCellAttr, |
1295 | *attrCombo = new wxGridCellAttr; | |
1296 | ||
65e4e78e VZ |
1297 | attrRO->SetReadOnly(); |
1298 | attrRangeEditor->SetEditor(new wxGridCellNumberEditor(1, 5)); | |
4ee5fc9c VZ |
1299 | attrCombo->SetEditor(new wxGridCellChoiceEditor(WXSIZEOF(severities), |
1300 | severities)); | |
65e4e78e VZ |
1301 | |
1302 | grid->SetColAttr(Col_Id, attrRO); | |
1303 | grid->SetColAttr(Col_Priority, attrRangeEditor); | |
4ee5fc9c | 1304 | grid->SetColAttr(Col_Severity, attrCombo); |
65e4e78e | 1305 | |
266e8367 | 1306 | grid->SetMargins(0, 0); |
b0c8fc35 | 1307 | |
266e8367 | 1308 | grid->Fit(); |
d10f4bf9 | 1309 | SetClientSize(grid->GetSize()); |
35f97e95 | 1310 | } |
19d7140e VZ |
1311 | |
1312 |