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