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