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