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