]> git.saurik.com Git - wxWidgets.git/blame - samples/newgrid/griddemo.cpp
applied patch 422308 (fixes for version info for wxWin DLL)
[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
19d7140e 265 grid->SetCellValue(3, 0, "0");
508011ce
VZ
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;
19d7140e 274 attr->SetBackgroundColour(*wxRED);
758cbedf
VZ
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
19d7140e
VZ
281 grid->SetCellTextColour(5, 8, *wxGREEN);
282 grid->SetCellValue(5, 8, "Bg from row attr\nText col from cell attr");
283 grid->SetCellValue(5, 5, "Bg from row attr\nText col from col attr");
0b190b0f 284
19d7140e 285 grid->SetColFormatFloat(6);
0b190b0f
VZ
286 grid->SetCellValue(0, 6, "3.1415");
287 grid->SetCellValue(1, 6, "1415");
288 grid->SetCellValue(2, 6, "12345.67890");
289
19d7140e
VZ
290 grid->SetColFormatFloat(7, 6, 2);
291 grid->SetCellValue(0, 7, "3.1415");
292 grid->SetCellValue(1, 7, "1415");
293 grid->SetCellValue(2, 7, "12345.67890");
294
e442cc0d
MB
295 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
296 topSizer->Add( grid,
297 1,
298 wxEXPAND );
f0102d2a 299
e442cc0d 300 topSizer->Add( logWin,
f0102d2a 301 0,
e442cc0d 302 wxEXPAND );
f0102d2a 303
e442cc0d
MB
304 SetAutoLayout( TRUE );
305 SetSizer( topSizer );
f0102d2a 306
e442cc0d
MB
307 topSizer->Fit( this );
308 topSizer->SetSizeHints( this );
f0102d2a 309
e442cc0d
MB
310 Centre();
311 SetDefaults();
312}
313
314
315GridFrame::~GridFrame()
316{
66b3609e 317 delete wxLog::SetActiveTarget(m_logOld);
e442cc0d
MB
318}
319
f445b853 320
e442cc0d
MB
321void GridFrame::SetDefaults()
322{
323 GetMenuBar()->Check( ID_TOGGLEROWLABELS, TRUE );
324 GetMenuBar()->Check( ID_TOGGLECOLLABELS, TRUE );
f445b853 325 GetMenuBar()->Check( ID_TOGGLEEDIT, TRUE );
dd16fdae
MB
326 GetMenuBar()->Check( ID_TOGGLEROWSIZING, TRUE );
327 GetMenuBar()->Check( ID_TOGGLECOLSIZING, TRUE );
4cfa5de6 328 GetMenuBar()->Check( ID_TOGGLEGRIDSIZING, TRUE );
f6bcfd97 329 GetMenuBar()->Check( ID_TOGGLEGRIDLINES, TRUE );
e442cc0d
MB
330}
331
332
333void GridFrame::ToggleRowLabels( wxCommandEvent& WXUNUSED(ev) )
334{
335 if ( GetMenuBar()->IsChecked( ID_TOGGLEROWLABELS ) )
336 {
337 grid->SetRowLabelSize( grid->GetDefaultRowLabelSize() );
338 }
339 else
340 {
341 grid->SetRowLabelSize( 0 );
342 }
343}
344
345
346void GridFrame::ToggleColLabels( wxCommandEvent& WXUNUSED(ev) )
347{
348 if ( GetMenuBar()->IsChecked( ID_TOGGLECOLLABELS ) )
349 {
350 grid->SetColLabelSize( grid->GetDefaultColLabelSize() );
351 }
352 else
353 {
354 grid->SetColLabelSize( 0 );
355 }
356}
357
358
f445b853 359void GridFrame::ToggleEditing( wxCommandEvent& WXUNUSED(ev) )
e442cc0d 360{
f445b853
MB
361 grid->EnableEditing(
362 GetMenuBar()->IsChecked( ID_TOGGLEEDIT ) );
e442cc0d
MB
363}
364
365
dd16fdae
MB
366void GridFrame::ToggleRowSizing( wxCommandEvent& WXUNUSED(ev) )
367{
ea179c7b 368 grid->EnableDragRowSize(
dd16fdae
MB
369 GetMenuBar()->IsChecked( ID_TOGGLEROWSIZING ) );
370}
371
372
373void GridFrame::ToggleColSizing( wxCommandEvent& WXUNUSED(ev) )
374{
ea179c7b 375 grid->EnableDragColSize(
dd16fdae
MB
376 GetMenuBar()->IsChecked( ID_TOGGLECOLSIZING ) );
377}
378
4cfa5de6
RD
379void GridFrame::ToggleGridSizing( wxCommandEvent& WXUNUSED(ev) )
380{
381 grid->EnableDragGridSize(
382 GetMenuBar()->IsChecked( ID_TOGGLEGRIDSIZING ) );
383}
384
dd16fdae 385
f6bcfd97
BP
386void GridFrame::ToggleGridLines( wxCommandEvent& WXUNUSED(ev) )
387{
388 grid->EnableGridLines(
389 GetMenuBar()->IsChecked( ID_TOGGLEGRIDLINES ) );
390}
391
d2520c85
RD
392void GridFrame::OnSetHighlightWidth( wxCommandEvent& WXUNUSED(ev) )
393{
394 wxString choices[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
395
396 wxSingleChoiceDialog dlg(this, "Choose the thickness of the highlight pen:",
397 "Pen Width", 11, choices);
398
399 int current = grid->GetCellHighlightPenWidth();
400 dlg.SetSelection(current);
401 if (dlg.ShowModal() == wxID_OK) {
402 grid->SetCellHighlightPenWidth(dlg.GetSelection());
403 }
404}
405
406void GridFrame::OnSetROHighlightWidth( wxCommandEvent& WXUNUSED(ev) )
407{
408 wxString choices[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "10"};
409
410 wxSingleChoiceDialog dlg(this, "Choose the thickness of the highlight pen:",
411 "Pen Width", 11, choices);
412
413 int current = grid->GetCellHighlightROPenWidth();
414 dlg.SetSelection(current);
415 if (dlg.ShowModal() == wxID_OK) {
416 grid->SetCellHighlightROPenWidth(dlg.GetSelection());
417 }
418}
419
420
f6bcfd97
BP
421
422void GridFrame::AutoSizeCols( wxCommandEvent& WXUNUSED(ev) )
423{
424 grid->AutoSizeColumns();
425 grid->Refresh();
426}
427
428
e442cc0d
MB
429void GridFrame::SetLabelColour( wxCommandEvent& WXUNUSED(ev) )
430{
431 wxColourDialog dlg( NULL );
432 if ( dlg.ShowModal() == wxID_OK )
433 {
434 wxColourData retData;
435 retData = dlg.GetColourData();
436 wxColour colour = retData.GetColour();
437
438 grid->SetLabelBackgroundColour( colour );
439 }
440}
441
442
443void GridFrame::SetLabelTextColour( wxCommandEvent& WXUNUSED(ev) )
444{
445 wxColourDialog dlg( NULL );
446 if ( dlg.ShowModal() == wxID_OK )
447 {
448 wxColourData retData;
449 retData = dlg.GetColourData();
450 wxColour colour = retData.GetColour();
451
452 grid->SetLabelTextColour( colour );
453 }
454}
455
456
457void GridFrame::SetRowLabelHorizAlignment( wxCommandEvent& WXUNUSED(ev) )
458{
459 int horiz, vert;
460 grid->GetRowLabelAlignment( &horiz, &vert );
f0102d2a 461
e442cc0d
MB
462 switch ( horiz )
463 {
0767cb6f
MB
464 case wxALIGN_LEFT:
465 horiz = wxALIGN_CENTRE;
e442cc0d 466 break;
f0102d2a 467
0767cb6f
MB
468 case wxALIGN_CENTRE:
469 horiz = wxALIGN_RIGHT;
e442cc0d
MB
470 break;
471
0767cb6f
MB
472 case wxALIGN_RIGHT:
473 horiz = wxALIGN_LEFT;
e442cc0d
MB
474 break;
475 }
476
477 grid->SetRowLabelAlignment( horiz, -1 );
478}
479
480void GridFrame::SetRowLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) )
481{
482 int horiz, vert;
483 grid->GetRowLabelAlignment( &horiz, &vert );
f0102d2a 484
e442cc0d
MB
485 switch ( vert )
486 {
0767cb6f
MB
487 case wxALIGN_TOP:
488 vert = wxALIGN_CENTRE;
e442cc0d 489 break;
f0102d2a 490
0767cb6f
MB
491 case wxALIGN_CENTRE:
492 vert = wxALIGN_BOTTOM;
e442cc0d
MB
493 break;
494
0767cb6f
MB
495 case wxALIGN_BOTTOM:
496 vert = wxALIGN_TOP;
e442cc0d
MB
497 break;
498 }
499
500 grid->SetRowLabelAlignment( -1, vert );
501}
502
503
504void GridFrame::SetColLabelHorizAlignment( wxCommandEvent& WXUNUSED(ev) )
505{
506 int horiz, vert;
507 grid->GetColLabelAlignment( &horiz, &vert );
f0102d2a 508
e442cc0d
MB
509 switch ( horiz )
510 {
0767cb6f
MB
511 case wxALIGN_LEFT:
512 horiz = wxALIGN_CENTRE;
e442cc0d 513 break;
f0102d2a 514
0767cb6f
MB
515 case wxALIGN_CENTRE:
516 horiz = wxALIGN_RIGHT;
e442cc0d
MB
517 break;
518
0767cb6f
MB
519 case wxALIGN_RIGHT:
520 horiz = wxALIGN_LEFT;
e442cc0d
MB
521 break;
522 }
523
524 grid->SetColLabelAlignment( horiz, -1 );
525}
526
527
528void GridFrame::SetColLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) )
529{
530 int horiz, vert;
531 grid->GetColLabelAlignment( &horiz, &vert );
f0102d2a 532
e442cc0d
MB
533 switch ( vert )
534 {
0767cb6f
MB
535 case wxALIGN_TOP:
536 vert = wxALIGN_CENTRE;
e442cc0d 537 break;
f0102d2a 538
0767cb6f
MB
539 case wxALIGN_CENTRE:
540 vert = wxALIGN_BOTTOM;
e442cc0d
MB
541 break;
542
0767cb6f
MB
543 case wxALIGN_BOTTOM:
544 vert = wxALIGN_TOP;
e442cc0d
MB
545 break;
546 }
547
548 grid->SetColLabelAlignment( -1, vert );
549}
550
551
552void GridFrame::SetGridLineColour( wxCommandEvent& WXUNUSED(ev) )
553{
554 wxColourDialog dlg( NULL );
555 if ( dlg.ShowModal() == wxID_OK )
556 {
557 wxColourData retData;
558 retData = dlg.GetColourData();
559 wxColour colour = retData.GetColour();
560
561 grid->SetGridLineColour( colour );
562 }
563}
564
565
0eee5283
MB
566void GridFrame::InsertRow( wxCommandEvent& WXUNUSED(ev) )
567{
4e5b5abb 568 grid->InsertRows( grid->GetGridCursorRow(), 1 );
0eee5283
MB
569}
570
571
572void GridFrame::InsertCol( wxCommandEvent& WXUNUSED(ev) )
573{
4e5b5abb 574 grid->InsertCols( grid->GetGridCursorCol(), 1 );
0eee5283
MB
575}
576
577
f445b853 578void GridFrame::DeleteSelectedRows( wxCommandEvent& WXUNUSED(ev) )
0eee5283 579{
f445b853
MB
580 if ( grid->IsSelection() )
581 {
f6bcfd97
BP
582 grid->BeginBatch();
583 for ( int n = 0; n < grid->GetNumberRows(); )
5c8fc7c1
SN
584 if ( grid->IsInSelection( n , 0 ) )
585 grid->DeleteRows( n, 1 );
f6bcfd97
BP
586 else
587 n++;
588 grid->EndBatch();
f445b853 589 }
0eee5283
MB
590}
591
592
f445b853 593void GridFrame::DeleteSelectedCols( wxCommandEvent& WXUNUSED(ev) )
0eee5283 594{
f445b853
MB
595 if ( grid->IsSelection() )
596 {
f6bcfd97
BP
597 grid->BeginBatch();
598 for ( int n = 0; n < grid->GetNumberCols(); )
5c8fc7c1
SN
599 if ( grid->IsInSelection( 0 , n ) )
600 grid->DeleteCols( n, 1 );
f6bcfd97
BP
601 else
602 n++;
603 grid->EndBatch();
f445b853 604 }
0eee5283
MB
605}
606
607
e442cc0d
MB
608void GridFrame::ClearGrid( wxCommandEvent& WXUNUSED(ev) )
609{
610 grid->ClearGrid();
611}
612
043d16b2
SN
613void GridFrame::SelectCells( wxCommandEvent& WXUNUSED(ev) )
614{
615 grid->SetSelectionMode( wxGrid::wxGridSelectCells );
616}
617
618void GridFrame::SelectRows( wxCommandEvent& WXUNUSED(ev) )
619{
620 grid->SetSelectionMode( wxGrid::wxGridSelectRows );
621}
622
623void GridFrame::SelectCols( wxCommandEvent& WXUNUSED(ev) )
624{
625 grid->SetSelectionMode( wxGrid::wxGridSelectColumns );
626}
627
ab79958a
VZ
628void GridFrame::SetCellFgColour( wxCommandEvent& WXUNUSED(ev) )
629{
630 wxColour col = wxGetColourFromUser(this);
631 if ( col.Ok() )
758cbedf 632 {
ab79958a 633 grid->SetDefaultCellTextColour(col);
758cbedf
VZ
634 grid->Refresh();
635 }
ab79958a
VZ
636}
637
638void GridFrame::SetCellBgColour( wxCommandEvent& WXUNUSED(ev) )
639{
640 wxColour col = wxGetColourFromUser(this);
641 if ( col.Ok() )
758cbedf 642 {
ab79958a 643 grid->SetDefaultCellBackgroundColour(col);
758cbedf
VZ
644 grid->Refresh();
645 }
ab79958a 646}
e442cc0d 647
14e5a313
VZ
648void GridFrame::DeselectCell(wxCommandEvent& WXUNUSED(event))
649{
650 grid->DeselectCell(3, 1);
651}
652
653void GridFrame::DeselectCol(wxCommandEvent& WXUNUSED(event))
654{
655 grid->DeselectCol(2);
656}
657
658void GridFrame::DeselectRow(wxCommandEvent& WXUNUSED(event))
659{
660 grid->DeselectRow(2);
661}
662
663void GridFrame::DeselectAll(wxCommandEvent& WXUNUSED(event))
664{
665 grid->ClearSelection();
666}
667
668void GridFrame::SelectCell(wxCommandEvent& WXUNUSED(event))
669{
93521c94 670 grid->SelectBlock(3, 1, 3, 1, m_addToSel);
14e5a313
VZ
671}
672
673void GridFrame::SelectCol(wxCommandEvent& WXUNUSED(event))
674{
93521c94 675 grid->SelectCol(2, m_addToSel);
14e5a313
VZ
676}
677
678void GridFrame::SelectRow(wxCommandEvent& WXUNUSED(event))
679{
93521c94 680 grid->SelectRow(2, m_addToSel);
14e5a313
VZ
681}
682
683void GridFrame::SelectAll(wxCommandEvent& WXUNUSED(event))
684{
685 grid->SelectAll();
686}
687
93521c94
VZ
688void GridFrame::OnAddToSelectToggle(wxCommandEvent& event)
689{
690 m_addToSel = event.IsChecked();
691}
692
e442cc0d
MB
693void GridFrame::OnLabelLeftClick( wxGridEvent& ev )
694{
695 logBuf = "";
696 if ( ev.GetRow() != -1 )
697 {
c336585e 698 logBuf << "Left click on row label " << ev.GetRow();
e442cc0d
MB
699 }
700 else if ( ev.GetCol() != -1 )
701 {
c336585e 702 logBuf << "Left click on col label " << ev.GetCol();
e442cc0d
MB
703 }
704 else
705 {
c336585e 706 logBuf << "Left click on corner label";
e442cc0d
MB
707 }
708
709 if ( ev.ShiftDown() ) logBuf << " (shift down)";
e32352cf 710 if ( ev.ControlDown() ) logBuf << " (control down)";
e442cc0d 711 wxLogMessage( "%s", logBuf.c_str() );
f0102d2a 712
c336585e
MB
713 // you must call event skip if you want default grid processing
714 //
e442cc0d
MB
715 ev.Skip();
716}
717
718
719void GridFrame::OnCellLeftClick( wxGridEvent& ev )
720{
721 logBuf = "";
c336585e 722 logBuf << "Left click at row " << ev.GetRow()
e442cc0d
MB
723 << " col " << ev.GetCol();
724 wxLogMessage( "%s", logBuf.c_str() );
0eee5283 725
e442cc0d
MB
726 // you must call event skip if you want default grid processing
727 // (cell highlighting etc.)
728 //
729 ev.Skip();
730}
731
732
733void GridFrame::OnRowSize( wxGridSizeEvent& ev )
734{
735 logBuf = "";
736 logBuf << "Resized row " << ev.GetRowOrCol();
737 wxLogMessage( "%s", logBuf.c_str() );
f0102d2a 738
e442cc0d
MB
739 ev.Skip();
740}
741
742
743void GridFrame::OnColSize( wxGridSizeEvent& ev )
744{
745 logBuf = "";
746 logBuf << "Resized col " << ev.GetRowOrCol();
747 wxLogMessage( "%s", logBuf.c_str() );
f0102d2a 748
e442cc0d
MB
749 ev.Skip();
750}
751
c336585e
MB
752
753void GridFrame::OnSelectCell( wxGridEvent& ev )
754{
755 logBuf = "";
5c8fc7c1
SN
756 if ( ev.Selecting() )
757 logBuf << "Selected ";
758 else
759 logBuf << "Deselected ";
760 logBuf << "cell at row " << ev.GetRow()
d95b0c2b 761 << " col " << ev.GetCol()
f41986da
MB
762 << " ( ControlDown: "<< (ev.ControlDown() ? 'T':'F')
763 << ", ShiftDown: "<< (ev.ShiftDown() ? 'T':'F')
764 << ", AltDown: "<< (ev.AltDown() ? 'T':'F')
765 << ", MetaDown: "<< (ev.MetaDown() ? 'T':'F') << " )";
c336585e 766 wxLogMessage( "%s", logBuf.c_str() );
f0102d2a 767
c336585e
MB
768 // you must call Skip() if you want the default processing
769 // to occur in wxGrid
770 ev.Skip();
771}
772
e442cc0d
MB
773void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev )
774{
775 logBuf = "";
5c8fc7c1
SN
776 if ( ev.Selecting() )
777 logBuf << "Selected ";
778 else
779 logBuf << "Deselected ";
780 logBuf << "cells from row " << ev.GetTopRow()
781 << " col " << ev.GetLeftCol()
782 << " to row " << ev.GetBottomRow()
d95b0c2b 783 << " col " << ev.GetRightCol()
f41986da
MB
784 << " ( ControlDown: "<< (ev.ControlDown() ? 'T':'F')
785 << ", ShiftDown: "<< (ev.ShiftDown() ? 'T':'F')
786 << ", AltDown: "<< (ev.AltDown() ? 'T':'F')
787 << ", MetaDown: "<< (ev.MetaDown() ? 'T':'F') << " )";
e442cc0d 788 wxLogMessage( "%s", logBuf.c_str() );
f0102d2a 789
e442cc0d
MB
790 ev.Skip();
791}
792
793void GridFrame::OnCellValueChanged( wxGridEvent& ev )
794{
795 logBuf = "";
796 logBuf << "Value changed for cell at"
f0102d2a 797 << " row " << ev.GetRow()
e442cc0d 798 << " col " << ev.GetCol();
f0102d2a 799
e442cc0d 800 wxLogMessage( "%s", logBuf.c_str() );
f0102d2a 801
e442cc0d
MB
802 ev.Skip();
803}
804
b54ba671
VZ
805void GridFrame::OnEditorShown( wxGridEvent& ev )
806{
807 wxLogMessage( "Cell editor shown." );
808
809 ev.Skip();
810}
811
812void GridFrame::OnEditorHidden( wxGridEvent& ev )
813{
814 wxLogMessage( "Cell editor hidden." );
815
816 ev.Skip();
817}
e442cc0d 818
f445b853
MB
819void GridFrame::About( wxCommandEvent& WXUNUSED(ev) )
820{
821 (void)wxMessageBox( "\n\nwxGrid demo \n\n"
822 "Michael Bedward \n"
823 "mbedward@ozemail.com.au \n\n",
824 "About",
825 wxOK );
826}
827
828
829void GridFrame::OnQuit( wxCommandEvent& WXUNUSED(ev) )
830{
831 Close( TRUE );
832}
833
35f97e95
VZ
834void GridFrame::OnBugsTable(wxCommandEvent& )
835{
836 BugsGridFrame *frame = new BugsGridFrame;
837 frame->Show(TRUE);
838}
839
19d7140e 840
f97c9b5b
RD
841void GridFrame::OnVTable(wxCommandEvent& )
842{
1618dca7
VZ
843 static long s_sizeGrid = 10000;
844
b0c8fc35
MB
845#ifdef __WXMOTIF__
846 // MB: wxGetNumberFromUser doesn't work properly for wxMotif
847 wxString s;
848 s << s_sizeGrid;
849 s = wxGetTextFromUser( "Size of the table to create",
850 "Size:",
851 s );
c4608a8a 852
b0c8fc35 853 s.ToLong( &s_sizeGrid );
c4608a8a 854
b0c8fc35 855#else
1618dca7
VZ
856 s_sizeGrid = wxGetNumberFromUser("Size of the table to create",
857 "Size: ",
858 "wxGridDemo question",
859 s_sizeGrid,
860 0, 32000, this);
b0c8fc35 861#endif
c4608a8a 862
1618dca7
VZ
863 if ( s_sizeGrid != -1 )
864 {
865 BigGridFrame* win = new BigGridFrame(s_sizeGrid);
866 win->Show(TRUE);
867 }
f97c9b5b
RD
868}
869
ab79958a
VZ
870// ----------------------------------------------------------------------------
871// MyGridCellRenderer
872// ----------------------------------------------------------------------------
873
758cbedf
VZ
874// do something that the default renderer doesn't here just to show that it is
875// possible to alter the appearance of the cell beyond what the attributes
876// allow
ab79958a 877void MyGridCellRenderer::Draw(wxGrid& grid,
f97c9b5b 878 wxGridCellAttr& attr,
ab79958a
VZ
879 wxDC& dc,
880 const wxRect& rect,
881 int row, int col,
882 bool isSelected)
883{
f97c9b5b 884 wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
ab79958a
VZ
885
886 dc.SetPen(*wxGREEN_PEN);
887 dc.SetBrush(*wxTRANSPARENT_BRUSH);
888 dc.DrawEllipse(rect);
889}
f97c9b5b 890
f97c9b5b 891// ----------------------------------------------------------------------------
a68c1246 892// MyGridCellAttrProvider
f97c9b5b
RD
893// ----------------------------------------------------------------------------
894
a68c1246
VZ
895MyGridCellAttrProvider::MyGridCellAttrProvider()
896{
897 m_attrForOddRows = new wxGridCellAttr;
898 m_attrForOddRows->SetBackgroundColour(*wxLIGHT_GREY);
899}
900
901MyGridCellAttrProvider::~MyGridCellAttrProvider()
902{
903 m_attrForOddRows->DecRef();
904}
905
19d7140e
VZ
906wxGridCellAttr *MyGridCellAttrProvider::GetAttr(int row, int col,
907 wxGridCellAttr::wxAttrKind kind /* = wxGridCellAttr::Any */) const
a68c1246 908{
19d7140e 909 wxGridCellAttr *attr = wxGridCellAttrProvider::GetAttr(row, col, kind);
a68c1246
VZ
910
911 if ( row % 2 )
912 {
913 if ( !attr )
914 {
915 attr = m_attrForOddRows;
916 attr->IncRef();
917 }
918 else
919 {
920 if ( !attr->HasBackgroundColour() )
921 {
922 wxGridCellAttr *attrNew = attr->Clone();
923 attr->DecRef();
924 attr = attrNew;
925 attr->SetBackgroundColour(*wxLIGHT_GREY);
926 }
927 }
928 }
929
930 return attr;
931}
932
933// ============================================================================
934// BigGridFrame and BigGridTable: Sample of a non-standard table
935// ============================================================================
936
1618dca7
VZ
937BigGridFrame::BigGridFrame(long sizeGrid)
938 : wxFrame(NULL, -1, "Plugin Virtual Table",
939 wxDefaultPosition, wxSize(500, 450))
f97c9b5b
RD
940{
941 m_grid = new wxGrid(this, -1, wxDefaultPosition, wxDefaultSize);
1618dca7 942 m_table = new BigGridTable(sizeGrid);
a68c1246
VZ
943
944 // VZ: I don't understand why this slows down the display that much,
945 // must profile it...
946 //m_table->SetAttrProvider(new MyGridCellAttrProvider);
947
f97c9b5b 948 m_grid->SetTable(m_table, TRUE);
b0c8fc35
MB
949
950#if defined __WXMOTIF__
951 // MB: the grid isn't getting a sensible default size under wxMotif
952 int cw, ch;
953 GetClientSize( &cw, &ch );
954 m_grid->SetSize( cw, ch );
955#endif
f97c9b5b 956}
35f97e95 957
a68c1246 958// ============================================================================
35f97e95 959// BugsGridFrame: a "realistic" table
a68c1246
VZ
960// ============================================================================
961
962// ----------------------------------------------------------------------------
963// bugs table data
35f97e95
VZ
964// ----------------------------------------------------------------------------
965
816be743
VZ
966enum Columns
967{
968 Col_Id,
969 Col_Summary,
970 Col_Severity,
971 Col_Priority,
972 Col_Platform,
973 Col_Opened,
974 Col_Max
975};
976
977enum Severity
978{
979 Sev_Wish,
980 Sev_Minor,
981 Sev_Normal,
982 Sev_Major,
983 Sev_Critical,
984 Sev_Max
985};
986
f6bcfd97 987static const wxString severities[] =
816be743
VZ
988{
989 _T("wishlist"),
990 _T("minor"),
991 _T("normal"),
992 _T("major"),
993 _T("critical"),
994};
995
996static struct BugsGridData
997{
998 int id;
9121bed2 999 wxChar summary[80];
816be743
VZ
1000 Severity severity;
1001 int prio;
9121bed2 1002 wxChar platform[12];
816be743 1003 bool opened;
c4608a8a 1004} gs_dataBugsGrid [] =
816be743
VZ
1005{
1006 { 18, _T("foo doesn't work"), Sev_Major, 1, _T("wxMSW"), TRUE },
1007 { 27, _T("bar crashes"), Sev_Critical, 1, _T("all"), FALSE },
1008 { 45, _T("printing is slow"), Sev_Minor, 3, _T("wxMSW"), TRUE },
1009 { 68, _T("Rectangle() fails"), Sev_Normal, 1, _T("wxMSW"), FALSE },
1010};
1011
1012static const wxChar *headers[Col_Max] =
1013{
1014 _T("Id"),
1015 _T("Summary"),
1016 _T("Severity"),
1017 _T("Priority"),
1018 _T("Platform"),
1019 _T("Opened?"),
1020};
1021
a68c1246
VZ
1022// ----------------------------------------------------------------------------
1023// BugsGridTable
1024// ----------------------------------------------------------------------------
1025
816be743
VZ
1026wxString BugsGridTable::GetTypeName(int WXUNUSED(row), int col)
1027{
1028 switch ( col )
1029 {
1030 case Col_Id:
1031 case Col_Priority:
1032 return wxGRID_VALUE_NUMBER;;
1033
1034 case Col_Severity:
1035 // fall thorugh (TODO should be a list)
1036
1037 case Col_Summary:
c4608a8a
VZ
1038 return wxString::Format(_T("%s:80"), wxGRID_VALUE_STRING);
1039
816be743 1040 case Col_Platform:
c4608a8a 1041 return wxString::Format(_T("%s:all,MSW,GTK,other"), wxGRID_VALUE_CHOICE);
816be743
VZ
1042
1043 case Col_Opened:
1044 return wxGRID_VALUE_BOOL;
1045 }
1046
1047 wxFAIL_MSG(_T("unknown column"));
1048
1049 return wxEmptyString;
1050}
1051
e32352cf 1052int BugsGridTable::GetNumberRows()
816be743
VZ
1053{
1054 return WXSIZEOF(gs_dataBugsGrid);
1055}
1056
e32352cf 1057int BugsGridTable::GetNumberCols()
35f97e95 1058{
816be743
VZ
1059 return Col_Max;
1060}
1061
1062bool BugsGridTable::IsEmptyCell( int row, int col )
1063{
1064 return FALSE;
1065}
1066
1067wxString BugsGridTable::GetValue( int row, int col )
1068{
1069 const BugsGridData& gd = gs_dataBugsGrid[row];
1070
1071 switch ( col )
35f97e95 1072 {
816be743
VZ
1073 case Col_Id:
1074 case Col_Priority:
1075 case Col_Opened:
1076 wxFAIL_MSG(_T("unexpected column"));
1077 break;
1078
1079 case Col_Severity:
1080 return severities[gd.severity];
1081
1082 case Col_Summary:
1083 return gd.summary;
1084
1085 case Col_Platform:
1086 return gd.platform;
1087 }
1088
1089 return wxEmptyString;
1090}
1091
1092void BugsGridTable::SetValue( int row, int col, const wxString& value )
1093{
1094 BugsGridData& gd = gs_dataBugsGrid[row];
35f97e95 1095
816be743 1096 switch ( col )
35f97e95 1097 {
816be743
VZ
1098 case Col_Id:
1099 case Col_Priority:
1100 case Col_Opened:
1101 wxFAIL_MSG(_T("unexpected column"));
1102 break;
1103
1104 case Col_Severity:
1105 {
1106 size_t n;
1107 for ( n = 0; n < WXSIZEOF(severities); n++ )
1108 {
1109 if ( severities[n] == value )
1110 {
1111 gd.severity = (Severity)n;
1112 break;
1113 }
1114 }
1115
1116 if ( n == WXSIZEOF(severities) )
1117 {
1118 wxLogWarning(_T("Invalid severity value '%s'."),
1119 value.c_str());
1120 gd.severity = Sev_Normal;
1121 }
1122 }
ed23853b 1123 break;
816be743
VZ
1124
1125 case Col_Summary:
9121bed2 1126 wxStrncpy(gd.summary, value, WXSIZEOF(gd.summary));
816be743 1127 break;
35f97e95 1128
816be743 1129 case Col_Platform:
9121bed2 1130 wxStrncpy(gd.platform, value, WXSIZEOF(gd.platform));
816be743
VZ
1131 break;
1132 }
1133}
1134
1135bool BugsGridTable::CanGetValueAs( int WXUNUSED(row), int col, const wxString& typeName )
1136{
1137 if ( typeName == wxGRID_VALUE_STRING )
35f97e95 1138 {
816be743
VZ
1139 return TRUE;
1140 }
1141 else if ( typeName == wxGRID_VALUE_BOOL )
1142 {
1143 return col == Col_Opened;
1144 }
1145 else if ( typeName == wxGRID_VALUE_NUMBER )
1146 {
1147 return col == Col_Id || col == Col_Priority || col == Col_Severity;
1148 }
1149 else
35f97e95 1150 {
816be743
VZ
1151 return FALSE;
1152 }
1153}
1154
1155bool BugsGridTable::CanSetValueAs( int row, int col, const wxString& typeName )
1156{
1157 return CanGetValueAs(row, col, typeName);
1158}
1159
1160long BugsGridTable::GetValueAsLong( int row, int col )
1161{
1162 const BugsGridData& gd = gs_dataBugsGrid[row];
35f97e95 1163
816be743 1164 switch ( col )
35f97e95 1165 {
816be743
VZ
1166 case Col_Id:
1167 return gd.id;
35f97e95 1168
816be743
VZ
1169 case Col_Priority:
1170 return gd.prio;
35f97e95 1171
816be743
VZ
1172 case Col_Severity:
1173 return gd.severity;
1174
1175 default:
1176 wxFAIL_MSG(_T("unexpected column"));
1177 return -1;
1178 }
1179}
1180
1181bool BugsGridTable::GetValueAsBool( int row, int col )
1182{
1183 if ( col == Col_Opened )
1184 {
1185 return gs_dataBugsGrid[row].opened;
1186 }
1187 else
35f97e95 1188 {
816be743
VZ
1189 wxFAIL_MSG(_T("unexpected column"));
1190
1191 return FALSE;
35f97e95 1192 }
816be743 1193}
35f97e95 1194
816be743
VZ
1195void BugsGridTable::SetValueAsLong( int row, int col, long value )
1196{
1197 BugsGridData& gd = gs_dataBugsGrid[row];
1198
1199 switch ( col )
35f97e95 1200 {
816be743
VZ
1201 case Col_Priority:
1202 gd.prio = value;
1203 break;
1204
1205 default:
1206 wxFAIL_MSG(_T("unexpected column"));
35f97e95 1207 }
816be743 1208}
35f97e95 1209
816be743
VZ
1210void BugsGridTable::SetValueAsBool( int row, int col, bool value )
1211{
1212 if ( col == Col_Opened )
1213 {
1214 gs_dataBugsGrid[row].opened = value;
1215 }
1216 else
1217 {
1218 wxFAIL_MSG(_T("unexpected column"));
1219 }
1220}
1221
1222wxString BugsGridTable::GetColLabelValue( int col )
1223{
1224 return headers[col];
1225}
1226
1227BugsGridTable::BugsGridTable()
1228{
1229}
1230
a68c1246
VZ
1231// ----------------------------------------------------------------------------
1232// BugsGridFrame
1233// ----------------------------------------------------------------------------
1234
816be743
VZ
1235BugsGridFrame::BugsGridFrame()
1236 : wxFrame(NULL, -1, "Bugs table",
1237 wxDefaultPosition, wxSize(500, 300))
1238{
1239 wxGrid *grid = new wxGrid(this, -1, wxDefaultPosition);
1240 wxGridTableBase *table = new BugsGridTable();
a68c1246 1241 table->SetAttrProvider(new MyGridCellAttrProvider);
35f97e95 1242 grid->SetTable(table, TRUE);
816be743 1243
65e4e78e 1244 wxGridCellAttr *attrRO = new wxGridCellAttr,
4ee5fc9c
VZ
1245 *attrRangeEditor = new wxGridCellAttr,
1246 *attrCombo = new wxGridCellAttr;
1247
65e4e78e
VZ
1248 attrRO->SetReadOnly();
1249 attrRangeEditor->SetEditor(new wxGridCellNumberEditor(1, 5));
4ee5fc9c
VZ
1250 attrCombo->SetEditor(new wxGridCellChoiceEditor(WXSIZEOF(severities),
1251 severities));
65e4e78e
VZ
1252
1253 grid->SetColAttr(Col_Id, attrRO);
1254 grid->SetColAttr(Col_Priority, attrRangeEditor);
4ee5fc9c 1255 grid->SetColAttr(Col_Severity, attrCombo);
65e4e78e 1256
266e8367 1257 grid->SetMargins(0, 0);
b0c8fc35 1258
266e8367 1259 grid->Fit();
0b190b0f
VZ
1260 wxSize size = grid->GetSize();
1261 size.x += 10;
1262 size.y += 10;
1263 SetClientSize(size);
35f97e95 1264}
19d7140e
VZ
1265
1266