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