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