]> git.saurik.com Git - wxWidgets.git/blob - samples/newgrid/griddemo.cpp
492043c751ca1f0421208c5ab7589b255a52ff5f
[wxWidgets.git] / samples / newgrid / griddemo.cpp
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 /////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 #ifdef __GNUG__
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
37 #include "wx/grid.h"
38
39 #include "griddemo.h"
40
41 // ----------------------------------------------------------------------------
42 // wxWin macros
43 // ----------------------------------------------------------------------------
44
45 IMPLEMENT_APP( GridApp )
46
47 // ============================================================================
48 // implementation
49 // ============================================================================
50
51 // ----------------------------------------------------------------------------
52 // GridApp
53 // ----------------------------------------------------------------------------
54
55 bool GridApp::OnInit()
56 {
57 GridFrame *frame = new GridFrame;
58 frame->Show( TRUE );
59
60 return TRUE;
61 }
62
63 // ----------------------------------------------------------------------------
64 // GridFrame
65 // ----------------------------------------------------------------------------
66
67 BEGIN_EVENT_TABLE( GridFrame, wxFrame )
68 EVT_MENU( ID_TOGGLEROWLABELS, GridFrame::ToggleRowLabels )
69 EVT_MENU( ID_TOGGLECOLLABELS, GridFrame::ToggleColLabels )
70 EVT_MENU( ID_TOGGLEEDIT, GridFrame::ToggleEditing )
71 EVT_MENU( ID_SETLABELCOLOUR, GridFrame::SetLabelColour )
72 EVT_MENU( ID_SETLABELTEXTCOLOUR, GridFrame::SetLabelTextColour )
73 EVT_MENU( ID_ROWLABELHORIZALIGN, GridFrame::SetRowLabelHorizAlignment )
74 EVT_MENU( ID_ROWLABELVERTALIGN, GridFrame::SetRowLabelVertAlignment )
75 EVT_MENU( ID_COLLABELHORIZALIGN, GridFrame::SetColLabelHorizAlignment )
76 EVT_MENU( ID_COLLABELVERTALIGN, GridFrame::SetColLabelVertAlignment )
77 EVT_MENU( ID_GRIDLINECOLOUR, GridFrame::SetGridLineColour )
78 EVT_MENU( ID_INSERTROW, GridFrame::InsertRow )
79 EVT_MENU( ID_INSERTCOL, GridFrame::InsertCol )
80 EVT_MENU( ID_DELETEROW, GridFrame::DeleteSelectedRows )
81 EVT_MENU( ID_DELETECOL, GridFrame::DeleteSelectedCols )
82 EVT_MENU( ID_CLEARGRID, GridFrame::ClearGrid )
83
84 EVT_MENU( ID_SET_CELL_FG_COLOUR, GridFrame::SetCellFgColour )
85 EVT_MENU( ID_SET_CELL_BG_COLOUR, GridFrame::SetCellBgColour )
86
87 EVT_MENU( ID_ABOUT, GridFrame::About )
88 EVT_MENU( wxID_EXIT, GridFrame::OnQuit )
89 EVT_MENU( ID_VTABLE, GridFrame::OnVTable)
90 EVT_MENU( ID_BUGS_TABLE, GridFrame::OnBugsTable)
91
92 EVT_GRID_LABEL_LEFT_CLICK( GridFrame::OnLabelLeftClick )
93 EVT_GRID_CELL_LEFT_CLICK( GridFrame::OnCellLeftClick )
94 EVT_GRID_ROW_SIZE( GridFrame::OnRowSize )
95 EVT_GRID_COL_SIZE( GridFrame::OnColSize )
96 EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell )
97 EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected )
98 EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged )
99
100 EVT_GRID_EDITOR_SHOWN( GridFrame::OnEditorShown )
101 EVT_GRID_EDITOR_HIDDEN( GridFrame::OnEditorHidden )
102 END_EVENT_TABLE()
103
104
105 GridFrame::GridFrame()
106 : wxFrame( (wxFrame *)NULL, -1, "wxWindows grid class demo",
107 wxDefaultPosition,
108 wxDefaultSize )
109 {
110 int gridW = 600, gridH = 300;
111 int logW = gridW, logH = 100;
112
113 wxMenu *fileMenu = new wxMenu;
114 fileMenu->Append( ID_VTABLE, "&Virtual table test\tCtrl-V");
115 fileMenu->Append( ID_BUGS_TABLE, "&Bugs table test\tCtrl-B");
116 fileMenu->AppendSeparator();
117 fileMenu->Append( wxID_EXIT, "E&xit\tAlt-X" );
118
119 wxMenu *viewMenu = new wxMenu;
120 viewMenu->Append( ID_TOGGLEROWLABELS, "&Row labels", "", TRUE );
121 viewMenu->Append( ID_TOGGLECOLLABELS, "&Col labels", "", TRUE );
122 viewMenu->Append( ID_TOGGLEEDIT, "&Editable", "", TRUE );
123
124 wxMenu *rowLabelMenu = new wxMenu;
125
126 viewMenu->Append( ID_ROWLABELALIGN, "R&ow label alignment",
127 rowLabelMenu,
128 "Change alignment of row labels" );
129
130 rowLabelMenu->Append( ID_ROWLABELHORIZALIGN, "&Horizontal" );
131 rowLabelMenu->Append( ID_ROWLABELVERTALIGN, "&Vertical" );
132
133 wxMenu *colLabelMenu = new wxMenu;
134
135 viewMenu->Append( ID_COLLABELALIGN, "Col l&abel alignment",
136 colLabelMenu,
137 "Change alignment of col labels" );
138
139 colLabelMenu->Append( ID_COLLABELHORIZALIGN, "&Horizontal" );
140 colLabelMenu->Append( ID_COLLABELVERTALIGN, "&Vertical" );
141
142 wxMenu *colMenu = new wxMenu;
143 colMenu->Append( ID_SETLABELCOLOUR, "Set &label colour" );
144 colMenu->Append( ID_SETLABELTEXTCOLOUR, "Set label &text colour" );
145 colMenu->Append( ID_GRIDLINECOLOUR, "&Grid line colour" );
146 colMenu->Append( ID_SET_CELL_FG_COLOUR, "Set cell &foreground colour" );
147 colMenu->Append( ID_SET_CELL_BG_COLOUR, "Set cell &background colour" );
148
149 wxMenu *editMenu = new wxMenu;
150 editMenu->Append( ID_INSERTROW, "Insert &row" );
151 editMenu->Append( ID_INSERTCOL, "Insert &column" );
152 editMenu->Append( ID_DELETEROW, "Delete selected ro&ws" );
153 editMenu->Append( ID_DELETECOL, "Delete selected co&ls" );
154 editMenu->Append( ID_CLEARGRID, "Cl&ear grid cell contents" );
155
156 wxMenu *helpMenu = new wxMenu;
157 helpMenu->Append( ID_ABOUT, "&About wxGrid demo" );
158
159 wxMenuBar *menuBar = new wxMenuBar;
160 menuBar->Append( fileMenu, "&File" );
161 menuBar->Append( viewMenu, "&View" );
162 menuBar->Append( colMenu, "&Colours" );
163 menuBar->Append( editMenu, "&Edit" );
164 menuBar->Append( helpMenu, "&Help" );
165
166 SetMenuBar( menuBar );
167
168 grid = new wxGrid( this,
169 -1,
170 wxPoint( 0, 0 ),
171 wxSize( 400, 300 ) );
172
173 logWin = new wxTextCtrl( this,
174 -1,
175 wxEmptyString,
176 wxPoint( 0, gridH + 20 ),
177 wxSize( logW, logH ),
178 wxTE_MULTILINE );
179
180 logger = new wxLogTextCtrl( logWin );
181 logger->SetActiveTarget( logger );
182 logger->SetTimestamp( NULL );
183
184 // this will create a grid and, by default, an associated grid
185 // table for string data
186 //
187 //grid->CreateGrid( 100, 100 );
188 grid->SetTable(new SimpleTable(100, 100), TRUE);
189
190 // VZ: cell borders don't look nice otherwise :-) (for now...)
191 grid->SetDefaultCellBackgroundColour(wxColour(200, 200, 180));
192
193 grid->SetRowSize( 0, 60 );
194 grid->SetCellValue( 0, 0, "Ctrl+Home\nwill go to\nthis cell" );
195
196 grid->SetCellValue( 0, 1, "Blah" );
197 grid->SetCellValue( 0, 2, "Blah" );
198 grid->SetCellValue( 0, 3, "Read only" );
199 grid->SetReadOnly( 0, 3 );
200
201 grid->SetCellValue( 0, 5, "Press\nCtrl+arrow\nto skip over\ncells" );
202
203 grid->SetRowSize( 99, 60 );
204 grid->SetCellValue( 99, 99, "Ctrl+End\nwill go to\nthis cell" );
205
206 grid->SetCellValue(2, 2, "red");
207
208 grid->SetCellTextColour(2, 2, *wxRED);
209 grid->SetCellValue(3, 3, "green on grey");
210 grid->SetCellTextColour(3, 3, *wxGREEN);
211 grid->SetCellBackgroundColour(3, 3, *wxLIGHT_GREY);
212
213 grid->SetCellValue(4, 4, "a weird looking cell");
214 grid->SetCellAlignment(4, 4, wxCENTRE, wxCENTRE);
215 grid->SetCellRenderer(4, 4, new MyGridCellRenderer);
216
217 grid->SetCellValue(3, 0, "1");
218 grid->SetCellRenderer(3, 0, new wxGridCellBoolRenderer);
219 grid->SetCellEditor(3, 0, new wxGridCellBoolEditor);
220
221 wxGridCellAttr *attr;
222 attr = new wxGridCellAttr;
223 attr->SetTextColour(*wxBLUE);
224 grid->SetColAttr(5, attr);
225 attr = new wxGridCellAttr;
226 attr->SetBackgroundColour(*wxBLUE);
227 grid->SetRowAttr(5, attr);
228
229 grid->SetCellValue(2, 4, "a wider column");
230 grid->SetColSize(4, 120);
231 grid->SetColMinimalWidth(4, 120);
232
233 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
234 topSizer->Add( grid,
235 1,
236 wxEXPAND );
237
238 topSizer->Add( logWin,
239 0,
240 wxEXPAND );
241
242 SetAutoLayout( TRUE );
243 SetSizer( topSizer );
244
245 topSizer->Fit( this );
246 topSizer->SetSizeHints( this );
247
248 Centre();
249 SetDefaults();
250 }
251
252
253 GridFrame::~GridFrame()
254 {
255 }
256
257
258 void GridFrame::SetDefaults()
259 {
260 GetMenuBar()->Check( ID_TOGGLEROWLABELS, TRUE );
261 GetMenuBar()->Check( ID_TOGGLECOLLABELS, TRUE );
262 GetMenuBar()->Check( ID_TOGGLEEDIT, TRUE );
263 }
264
265
266 void GridFrame::ToggleRowLabels( wxCommandEvent& WXUNUSED(ev) )
267 {
268 if ( GetMenuBar()->IsChecked( ID_TOGGLEROWLABELS ) )
269 {
270 grid->SetRowLabelSize( grid->GetDefaultRowLabelSize() );
271 }
272 else
273 {
274 grid->SetRowLabelSize( 0 );
275 }
276 }
277
278
279 void GridFrame::ToggleColLabels( wxCommandEvent& WXUNUSED(ev) )
280 {
281 if ( GetMenuBar()->IsChecked( ID_TOGGLECOLLABELS ) )
282 {
283 grid->SetColLabelSize( grid->GetDefaultColLabelSize() );
284 }
285 else
286 {
287 grid->SetColLabelSize( 0 );
288 }
289 }
290
291
292 void GridFrame::ToggleEditing( wxCommandEvent& WXUNUSED(ev) )
293 {
294 grid->EnableEditing(
295 GetMenuBar()->IsChecked( ID_TOGGLEEDIT ) );
296 }
297
298
299 void GridFrame::SetLabelColour( wxCommandEvent& WXUNUSED(ev) )
300 {
301 wxColourDialog dlg( NULL );
302 if ( dlg.ShowModal() == wxID_OK )
303 {
304 wxColourData retData;
305 retData = dlg.GetColourData();
306 wxColour colour = retData.GetColour();
307
308 grid->SetLabelBackgroundColour( colour );
309 }
310 }
311
312
313 void GridFrame::SetLabelTextColour( wxCommandEvent& WXUNUSED(ev) )
314 {
315 wxColourDialog dlg( NULL );
316 if ( dlg.ShowModal() == wxID_OK )
317 {
318 wxColourData retData;
319 retData = dlg.GetColourData();
320 wxColour colour = retData.GetColour();
321
322 grid->SetLabelTextColour( colour );
323 }
324 }
325
326
327 void GridFrame::SetRowLabelHorizAlignment( wxCommandEvent& WXUNUSED(ev) )
328 {
329 int horiz, vert;
330 grid->GetRowLabelAlignment( &horiz, &vert );
331
332 switch ( horiz )
333 {
334 case wxLEFT:
335 horiz = wxCENTRE;
336 break;
337
338 case wxCENTRE:
339 horiz = wxRIGHT;
340 break;
341
342 case wxRIGHT:
343 horiz = wxLEFT;
344 break;
345 }
346
347 grid->SetRowLabelAlignment( horiz, -1 );
348 }
349
350 void GridFrame::SetRowLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) )
351 {
352 int horiz, vert;
353 grid->GetRowLabelAlignment( &horiz, &vert );
354
355 switch ( vert )
356 {
357 case wxTOP:
358 vert = wxCENTRE;
359 break;
360
361 case wxCENTRE:
362 vert = wxBOTTOM;
363 break;
364
365 case wxBOTTOM:
366 vert = wxTOP;
367 break;
368 }
369
370 grid->SetRowLabelAlignment( -1, vert );
371 }
372
373
374 void GridFrame::SetColLabelHorizAlignment( wxCommandEvent& WXUNUSED(ev) )
375 {
376 int horiz, vert;
377 grid->GetColLabelAlignment( &horiz, &vert );
378
379 switch ( horiz )
380 {
381 case wxLEFT:
382 horiz = wxCENTRE;
383 break;
384
385 case wxCENTRE:
386 horiz = wxRIGHT;
387 break;
388
389 case wxRIGHT:
390 horiz = wxLEFT;
391 break;
392 }
393
394 grid->SetColLabelAlignment( horiz, -1 );
395 }
396
397
398 void GridFrame::SetColLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) )
399 {
400 int horiz, vert;
401 grid->GetColLabelAlignment( &horiz, &vert );
402
403 switch ( vert )
404 {
405 case wxTOP:
406 vert = wxCENTRE;
407 break;
408
409 case wxCENTRE:
410 vert = wxBOTTOM;
411 break;
412
413 case wxBOTTOM:
414 vert = wxTOP;
415 break;
416 }
417
418 grid->SetColLabelAlignment( -1, vert );
419 }
420
421
422 void GridFrame::SetGridLineColour( wxCommandEvent& WXUNUSED(ev) )
423 {
424 wxColourDialog dlg( NULL );
425 if ( dlg.ShowModal() == wxID_OK )
426 {
427 wxColourData retData;
428 retData = dlg.GetColourData();
429 wxColour colour = retData.GetColour();
430
431 grid->SetGridLineColour( colour );
432 }
433 }
434
435
436 void GridFrame::InsertRow( wxCommandEvent& WXUNUSED(ev) )
437 {
438 grid->InsertRows( grid->GetGridCursorRow(), 1 );
439 }
440
441
442 void GridFrame::InsertCol( wxCommandEvent& WXUNUSED(ev) )
443 {
444 grid->InsertCols( grid->GetGridCursorCol(), 1 );
445 }
446
447
448 void GridFrame::DeleteSelectedRows( wxCommandEvent& WXUNUSED(ev) )
449 {
450 if ( grid->IsSelection() )
451 {
452 int topRow, bottomRow, leftCol, rightCol;
453 grid->GetSelection( &topRow, &leftCol, &bottomRow, &rightCol );
454 grid->DeleteRows( topRow, bottomRow - topRow + 1 );
455 }
456 }
457
458
459 void GridFrame::DeleteSelectedCols( wxCommandEvent& WXUNUSED(ev) )
460 {
461 if ( grid->IsSelection() )
462 {
463 int topRow, bottomRow, leftCol, rightCol;
464 grid->GetSelection( &topRow, &leftCol, &bottomRow, &rightCol );
465 grid->DeleteCols( leftCol, rightCol - leftCol + 1 );
466 }
467 }
468
469
470 void GridFrame::ClearGrid( wxCommandEvent& WXUNUSED(ev) )
471 {
472 grid->ClearGrid();
473 }
474
475 void GridFrame::SetCellFgColour( wxCommandEvent& WXUNUSED(ev) )
476 {
477 wxColour col = wxGetColourFromUser(this);
478 if ( col.Ok() )
479 {
480 grid->SetDefaultCellTextColour(col);
481 grid->Refresh();
482 }
483 }
484
485 void GridFrame::SetCellBgColour( wxCommandEvent& WXUNUSED(ev) )
486 {
487 wxColour col = wxGetColourFromUser(this);
488 if ( col.Ok() )
489 {
490 grid->SetDefaultCellBackgroundColour(col);
491 grid->Refresh();
492 }
493 }
494
495 void GridFrame::OnLabelLeftClick( wxGridEvent& ev )
496 {
497 logBuf = "";
498 if ( ev.GetRow() != -1 )
499 {
500 logBuf << "Left click on row label " << ev.GetRow();
501 }
502 else if ( ev.GetCol() != -1 )
503 {
504 logBuf << "Left click on col label " << ev.GetCol();
505 }
506 else
507 {
508 logBuf << "Left click on corner label";
509 }
510
511 if ( ev.ShiftDown() ) logBuf << " (shift down)";
512 wxLogMessage( "%s", logBuf.c_str() );
513
514 // you must call event skip if you want default grid processing
515 //
516 ev.Skip();
517 }
518
519
520 void GridFrame::OnCellLeftClick( wxGridEvent& ev )
521 {
522 logBuf = "";
523 logBuf << "Left click at row " << ev.GetRow()
524 << " col " << ev.GetCol();
525 wxLogMessage( "%s", logBuf.c_str() );
526
527 // you must call event skip if you want default grid processing
528 // (cell highlighting etc.)
529 //
530 ev.Skip();
531 }
532
533
534 void GridFrame::OnRowSize( wxGridSizeEvent& ev )
535 {
536 logBuf = "";
537 logBuf << "Resized row " << ev.GetRowOrCol();
538 wxLogMessage( "%s", logBuf.c_str() );
539
540 ev.Skip();
541 }
542
543
544 void GridFrame::OnColSize( wxGridSizeEvent& ev )
545 {
546 logBuf = "";
547 logBuf << "Resized col " << ev.GetRowOrCol();
548 wxLogMessage( "%s", logBuf.c_str() );
549
550 ev.Skip();
551 }
552
553
554 void GridFrame::OnSelectCell( wxGridEvent& ev )
555 {
556 logBuf = "";
557 logBuf << "Selected cell at row " << ev.GetRow()
558 << " col " << ev.GetCol();
559 wxLogMessage( "%s", logBuf.c_str() );
560
561 // you must call Skip() if you want the default processing
562 // to occur in wxGrid
563 ev.Skip();
564 }
565
566 void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev )
567 {
568 logBuf = "";
569 logBuf << "Selected cells from row " << ev.GetTopRow()
570 << " col " << ev.GetLeftCol()
571 << " to row " << ev.GetBottomRow()
572 << " col " << ev.GetRightCol();
573
574 wxLogMessage( "%s", logBuf.c_str() );
575
576 ev.Skip();
577 }
578
579 void GridFrame::OnCellValueChanged( wxGridEvent& ev )
580 {
581 logBuf = "";
582 logBuf << "Value changed for cell at"
583 << " row " << ev.GetRow()
584 << " col " << ev.GetCol();
585
586 wxLogMessage( "%s", logBuf.c_str() );
587
588 ev.Skip();
589 }
590
591 void GridFrame::OnEditorShown( wxGridEvent& ev )
592 {
593 wxLogMessage( "Cell editor shown." );
594
595 ev.Skip();
596 }
597
598 void GridFrame::OnEditorHidden( wxGridEvent& ev )
599 {
600 wxLogMessage( "Cell editor hidden." );
601
602 ev.Skip();
603 }
604
605 void GridFrame::About( wxCommandEvent& WXUNUSED(ev) )
606 {
607 (void)wxMessageBox( "\n\nwxGrid demo \n\n"
608 "Michael Bedward \n"
609 "mbedward@ozemail.com.au \n\n",
610 "About",
611 wxOK );
612 }
613
614
615 void GridFrame::OnQuit( wxCommandEvent& WXUNUSED(ev) )
616 {
617 Close( TRUE );
618 }
619
620 void GridFrame::OnBugsTable(wxCommandEvent& )
621 {
622 BugsGridFrame *frame = new BugsGridFrame;
623 frame->Show(TRUE);
624 }
625
626 void GridFrame::OnVTable(wxCommandEvent& )
627 {
628 static long s_sizeGrid = 10000;
629
630 s_sizeGrid = wxGetNumberFromUser("Size of the table to create",
631 "Size: ",
632 "wxGridDemo question",
633 s_sizeGrid,
634 0, 32000, this);
635 if ( s_sizeGrid != -1 )
636 {
637 BigGridFrame* win = new BigGridFrame(s_sizeGrid);
638 win->Show(TRUE);
639 }
640 }
641
642 // ----------------------------------------------------------------------------
643 // MyGridCellRenderer
644 // ----------------------------------------------------------------------------
645
646 // do something that the default renderer doesn't here just to show that it is
647 // possible to alter the appearance of the cell beyond what the attributes
648 // allow
649 void MyGridCellRenderer::Draw(wxGrid& grid,
650 wxGridCellAttr& attr,
651 wxDC& dc,
652 const wxRect& rect,
653 int row, int col,
654 bool isSelected)
655 {
656 wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
657
658 dc.SetPen(*wxGREEN_PEN);
659 dc.SetBrush(*wxTRANSPARENT_BRUSH);
660 dc.DrawEllipse(rect);
661 }
662
663
664 // ----------------------------------------------------------------------------
665 // BigGridFrame and BigGridTable: Sample of a non-standard table
666 // ----------------------------------------------------------------------------
667
668 BigGridFrame::BigGridFrame(long sizeGrid)
669 : wxFrame(NULL, -1, "Plugin Virtual Table",
670 wxDefaultPosition, wxSize(500, 450))
671 {
672 m_grid = new wxGrid(this, -1, wxDefaultPosition, wxDefaultSize);
673 m_table = new BigGridTable(sizeGrid);
674 m_grid->SetTable(m_table, TRUE);
675 }
676
677 // ----------------------------------------------------------------------------
678 // BugsGridFrame: a "realistic" table
679 // ----------------------------------------------------------------------------
680
681 BugsGridFrame::BugsGridFrame()
682 : wxFrame(NULL, -1, "Bugs table",
683 wxDefaultPosition, wxSize(500, 300))
684 {
685 enum Severity
686 {
687 Wish,
688 Minor,
689 Normal,
690 Major,
691 Critical
692 };
693
694 static const wxChar* severities[] =
695 {
696 _T("wishlist"),
697 _T("minor"),
698 _T("normal"),
699 _T("major"),
700 _T("critical"),
701 };
702
703 static const struct GridData
704 {
705 int id;
706 const wxChar *summary;
707 Severity severity;
708 int prio;
709 const wxChar *platform;
710 bool opened;
711 } data [] =
712 {
713 { 18, _T("foo doesn't work"), Major, 1, _T("wxMSW"), TRUE },
714 { 27, _T("bar crashes"), Critical, 1, _T("all"), FALSE },
715 { 45, _T("printing is slow"), Minor, 3, _T("wxMSW"), TRUE },
716 { 68, _T("Rectangle() fails"), Normal, 1, _T("wxMSW"), FALSE },
717 };
718
719 static const wxChar *headers[] =
720 {
721 _T("Id"),
722 _T("Summary"),
723 _T("Severity"),
724 _T("Priority"),
725 _T("Platform"),
726 _T("Opened?"),
727 };
728
729 // TODO the correct data type must be used for each column
730
731 wxGrid *grid = new wxGrid(this, -1, wxDefaultPosition);
732 wxGridTableBase *table =
733 new wxGridStringTable(WXSIZEOF(data), WXSIZEOF(headers));
734 for ( size_t row = 0; row < WXSIZEOF(data); row++ )
735 {
736 const GridData& gd = data[row];
737 table->SetValue(row, 0, wxString::Format("%d", gd.id));
738 table->SetValue(row, 1, gd.summary);
739 table->SetValue(row, 2, severities[gd.severity]);
740 table->SetValue(row, 3, wxString::Format("%d", gd.prio));
741 table->SetValue(row, 4, gd.platform);
742 table->SetValue(row, 5, gd.opened ? _T("True") : wxEmptyString);
743 }
744
745 for ( size_t col = 0; col < WXSIZEOF(headers); col++ )
746 {
747 table->SetColLabelValue(col, headers[col]);
748 }
749
750 grid->SetTable(table, TRUE);
751 }