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