1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Grid control wxWidgets sample
4 // Author: Michael Bedward
5 // Modified by: Santiago Palacios
7 // Copyright: (c) Michael Bedward, Julian Smart, Vadim Zeitlin
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
11 // ============================================================================
13 // ============================================================================
15 // ----------------------------------------------------------------------------
17 // ----------------------------------------------------------------------------
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
30 #include "wx/colordlg.h"
31 #include "wx/fontdlg.h"
32 #include "wx/numdlg.h"
35 #include "wx/generic/gridctrl.h"
39 // ----------------------------------------------------------------------------
41 // ----------------------------------------------------------------------------
43 IMPLEMENT_APP( GridApp
)
45 // ============================================================================
47 // ============================================================================
49 // ----------------------------------------------------------------------------
51 // ----------------------------------------------------------------------------
53 bool GridApp::OnInit()
55 GridFrame
*frame
= new GridFrame
;
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
65 BEGIN_EVENT_TABLE( GridFrame
, wxFrame
)
66 EVT_MENU( ID_TOGGLEROWLABELS
, GridFrame::ToggleRowLabels
)
67 EVT_MENU( ID_TOGGLECOLLABELS
, GridFrame::ToggleColLabels
)
68 EVT_MENU( ID_TOGGLEEDIT
, GridFrame::ToggleEditing
)
69 EVT_MENU( ID_TOGGLEROWSIZING
, GridFrame::ToggleRowSizing
)
70 EVT_MENU( ID_TOGGLECOLSIZING
, GridFrame::ToggleColSizing
)
71 EVT_MENU( ID_TOGGLECOLMOVING
, GridFrame::ToggleColMoving
)
72 EVT_MENU( ID_TOGGLEGRIDSIZING
, GridFrame::ToggleGridSizing
)
73 EVT_MENU( ID_TOGGLEGRIDDRAGCELL
, GridFrame::ToggleGridDragCell
)
74 EVT_MENU( ID_TOGGLEGRIDLINES
, GridFrame::ToggleGridLines
)
75 EVT_MENU( ID_AUTOSIZECOLS
, GridFrame::AutoSizeCols
)
76 EVT_MENU( ID_CELLOVERFLOW
, GridFrame::CellOverflow
)
77 EVT_MENU( ID_RESIZECELL
, GridFrame::ResizeCell
)
78 EVT_MENU( ID_SETLABELCOLOUR
, GridFrame::SetLabelColour
)
79 EVT_MENU( ID_SETLABELTEXTCOLOUR
, GridFrame::SetLabelTextColour
)
80 EVT_MENU( ID_SETLABEL_FONT
, GridFrame::SetLabelFont
)
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
)
85 EVT_MENU( ID_GRIDLINECOLOUR
, GridFrame::SetGridLineColour
)
86 EVT_MENU( ID_INSERTROW
, GridFrame::InsertRow
)
87 EVT_MENU( ID_INSERTCOL
, GridFrame::InsertCol
)
88 EVT_MENU( ID_DELETEROW
, GridFrame::DeleteSelectedRows
)
89 EVT_MENU( ID_DELETECOL
, GridFrame::DeleteSelectedCols
)
90 EVT_MENU( ID_CLEARGRID
, GridFrame::ClearGrid
)
91 EVT_MENU( ID_SELCELLS
, GridFrame::SelectCells
)
92 EVT_MENU( ID_SELROWS
, GridFrame::SelectRows
)
93 EVT_MENU( ID_SELCOLS
, GridFrame::SelectCols
)
95 EVT_MENU( ID_SET_CELL_FG_COLOUR
, GridFrame::SetCellFgColour
)
96 EVT_MENU( ID_SET_CELL_BG_COLOUR
, GridFrame::SetCellBgColour
)
98 EVT_MENU( wxID_ABOUT
, GridFrame::About
)
99 EVT_MENU( wxID_EXIT
, GridFrame::OnQuit
)
100 EVT_MENU( ID_VTABLE
, GridFrame::OnVTable
)
101 EVT_MENU( ID_BUGS_TABLE
, GridFrame::OnBugsTable
)
102 EVT_MENU( ID_SMALL_GRID
, GridFrame::OnSmallGrid
)
104 EVT_MENU( ID_DESELECT_CELL
, GridFrame::DeselectCell
)
105 EVT_MENU( ID_DESELECT_COL
, GridFrame::DeselectCol
)
106 EVT_MENU( ID_DESELECT_ROW
, GridFrame::DeselectRow
)
107 EVT_MENU( ID_DESELECT_ALL
, GridFrame::DeselectAll
)
108 EVT_MENU( ID_SELECT_CELL
, GridFrame::SelectCell
)
109 EVT_MENU( ID_SELECT_COL
, GridFrame::SelectCol
)
110 EVT_MENU( ID_SELECT_ROW
, GridFrame::SelectRow
)
111 EVT_MENU( ID_SELECT_ALL
, GridFrame::SelectAll
)
112 EVT_MENU( ID_SELECT_UNSELECT
, GridFrame::OnAddToSelectToggle
)
113 EVT_MENU( ID_SHOW_SELECTION
, GridFrame::OnShowSelection
)
115 EVT_MENU( ID_SIZE_ROW
, GridFrame::AutoSizeRow
)
116 EVT_MENU( ID_SIZE_COL
, GridFrame::AutoSizeCol
)
117 EVT_MENU( ID_SIZE_ROW_LABEL
, GridFrame::AutoSizeRowLabel
)
118 EVT_MENU( ID_SIZE_COL_LABEL
, GridFrame::AutoSizeColLabel
)
119 EVT_MENU( ID_SIZE_LABELS_COL
, GridFrame::AutoSizeLabelsCol
)
120 EVT_MENU( ID_SIZE_LABELS_ROW
, GridFrame::AutoSizeLabelsRow
)
121 EVT_MENU( ID_SIZE_GRID
, GridFrame::AutoSizeTable
)
123 EVT_MENU( ID_SET_HIGHLIGHT_WIDTH
, GridFrame::OnSetHighlightWidth
)
124 EVT_MENU( ID_SET_RO_HIGHLIGHT_WIDTH
, GridFrame::OnSetROHighlightWidth
)
126 EVT_GRID_LABEL_LEFT_CLICK( GridFrame::OnLabelLeftClick
)
127 EVT_GRID_CELL_LEFT_CLICK( GridFrame::OnCellLeftClick
)
128 EVT_GRID_ROW_SIZE( GridFrame::OnRowSize
)
129 EVT_GRID_COL_SIZE( GridFrame::OnColSize
)
130 EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell
)
131 EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected
)
132 EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged
)
133 EVT_GRID_CELL_BEGIN_DRAG( GridFrame::OnCellBeginDrag
)
135 EVT_GRID_EDITOR_SHOWN( GridFrame::OnEditorShown
)
136 EVT_GRID_EDITOR_HIDDEN( GridFrame::OnEditorHidden
)
140 GridFrame::GridFrame()
141 : wxFrame( (wxFrame
*)NULL
, wxID_ANY
, _T("wxWidgets grid class demo"),
145 wxMenu
*fileMenu
= new wxMenu
;
146 fileMenu
->Append( ID_VTABLE
, _T("&Virtual table test\tCtrl-V"));
147 fileMenu
->Append( ID_BUGS_TABLE
, _T("&Bugs table test\tCtrl-B"));
148 fileMenu
->Append( ID_SMALL_GRID
, _T("&Small Grid test\tCtrl-S"));
149 fileMenu
->AppendSeparator();
150 fileMenu
->Append( wxID_EXIT
, _T("E&xit\tAlt-X") );
152 wxMenu
*viewMenu
= new wxMenu
;
153 viewMenu
->Append( ID_TOGGLEROWLABELS
, _T("&Row labels"), wxEmptyString
, wxITEM_CHECK
);
154 viewMenu
->Append( ID_TOGGLECOLLABELS
, _T("&Col labels"), wxEmptyString
, wxITEM_CHECK
);
155 viewMenu
->Append( ID_TOGGLEEDIT
, _T("&Editable"), wxEmptyString
, wxITEM_CHECK
);
156 viewMenu
->Append( ID_TOGGLEROWSIZING
, _T("Ro&w drag-resize"), wxEmptyString
, wxITEM_CHECK
);
157 viewMenu
->Append( ID_TOGGLECOLSIZING
, _T("C&ol drag-resize"), wxEmptyString
, wxITEM_CHECK
);
158 viewMenu
->Append( ID_TOGGLECOLMOVING
, _T("Col drag-&move"), wxEmptyString
, wxITEM_CHECK
);
159 viewMenu
->Append( ID_TOGGLEGRIDSIZING
, _T("&Grid drag-resize"), wxEmptyString
, wxITEM_CHECK
);
160 viewMenu
->Append( ID_TOGGLEGRIDDRAGCELL
, _T("&Grid drag-cell"), wxEmptyString
, wxITEM_CHECK
);
161 viewMenu
->Append( ID_TOGGLEGRIDLINES
, _T("&Grid Lines"), wxEmptyString
, wxITEM_CHECK
);
162 viewMenu
->Append( ID_SET_HIGHLIGHT_WIDTH
, _T("&Set Cell Highlight Width...") );
163 viewMenu
->Append( ID_SET_RO_HIGHLIGHT_WIDTH
, _T("&Set Cell RO Highlight Width...") );
164 viewMenu
->Append( ID_AUTOSIZECOLS
, _T("&Auto-size cols") );
165 viewMenu
->Append( ID_CELLOVERFLOW
, _T("&Overflow cells"), wxEmptyString
, wxITEM_CHECK
);
166 viewMenu
->Append( ID_RESIZECELL
, _T("&Resize cell (7,1)"), wxEmptyString
, wxITEM_CHECK
);
168 wxMenu
*rowLabelMenu
= new wxMenu
;
170 viewMenu
->Append( ID_ROWLABELALIGN
, _T("R&ow label alignment"),
172 _T("Change alignment of row labels") );
174 rowLabelMenu
->Append( ID_ROWLABELHORIZALIGN
, _T("&Horizontal") );
175 rowLabelMenu
->Append( ID_ROWLABELVERTALIGN
, _T("&Vertical") );
177 wxMenu
*colLabelMenu
= new wxMenu
;
179 viewMenu
->Append( ID_COLLABELALIGN
, _T("Col l&abel alignment"),
181 _T("Change alignment of col labels") );
183 colLabelMenu
->Append( ID_COLLABELHORIZALIGN
, _T("&Horizontal") );
184 colLabelMenu
->Append( ID_COLLABELVERTALIGN
, _T("&Vertical") );
186 wxMenu
*colMenu
= new wxMenu
;
187 colMenu
->Append( ID_SETLABELCOLOUR
, _T("Set &label colour...") );
188 colMenu
->Append( ID_SETLABELTEXTCOLOUR
, _T("Set label &text colour...") );
189 colMenu
->Append( ID_SETLABEL_FONT
, _T("Set label fo&nt...") );
190 colMenu
->Append( ID_GRIDLINECOLOUR
, _T("&Grid line colour...") );
191 colMenu
->Append( ID_SET_CELL_FG_COLOUR
, _T("Set cell &foreground colour...") );
192 colMenu
->Append( ID_SET_CELL_BG_COLOUR
, _T("Set cell &background colour...") );
194 wxMenu
*editMenu
= new wxMenu
;
195 editMenu
->Append( ID_INSERTROW
, _T("Insert &row") );
196 editMenu
->Append( ID_INSERTCOL
, _T("Insert &column") );
197 editMenu
->Append( ID_DELETEROW
, _T("Delete selected ro&ws") );
198 editMenu
->Append( ID_DELETECOL
, _T("Delete selected co&ls") );
199 editMenu
->Append( ID_CLEARGRID
, _T("Cl&ear grid cell contents") );
201 wxMenu
*selectMenu
= new wxMenu
;
202 selectMenu
->Append( ID_SELECT_UNSELECT
, _T("Add new cells to the selection"),
203 _T("When off, old selection is deselected before ")
204 _T("selecting the new cells"), wxITEM_CHECK
);
205 selectMenu
->Append( ID_SHOW_SELECTION
,
206 _T("&Show current selection\tCtrl-Alt-S"));
207 selectMenu
->AppendSeparator();
208 selectMenu
->Append( ID_SELECT_ALL
, _T("Select all"));
209 selectMenu
->Append( ID_SELECT_ROW
, _T("Select row 2"));
210 selectMenu
->Append( ID_SELECT_COL
, _T("Select col 2"));
211 selectMenu
->Append( ID_SELECT_CELL
, _T("Select cell (3, 1)"));
212 selectMenu
->AppendSeparator();
213 selectMenu
->Append( ID_DESELECT_ALL
, _T("Deselect all"));
214 selectMenu
->Append( ID_DESELECT_ROW
, _T("Deselect row 2"));
215 selectMenu
->Append( ID_DESELECT_COL
, _T("Deselect col 2"));
216 selectMenu
->Append( ID_DESELECT_CELL
, _T("Deselect cell (3, 1)"));
217 wxMenu
*selectionMenu
= new wxMenu
;
218 selectMenu
->Append( ID_CHANGESEL
, _T("Change &selection mode"),
220 _T("Change selection mode") );
222 selectionMenu
->Append( ID_SELCELLS
, _T("Select &Cells") );
223 selectionMenu
->Append( ID_SELROWS
, _T("Select &Rows") );
224 selectionMenu
->Append( ID_SELCOLS
, _T("Select C&ols") );
226 wxMenu
*autosizeMenu
= new wxMenu
;
227 autosizeMenu
->Append( ID_SIZE_ROW
, _T("Selected &row data") );
228 autosizeMenu
->Append( ID_SIZE_COL
, _T("Selected &column data") );
229 autosizeMenu
->Append( ID_SIZE_ROW_LABEL
, _T("Selected row la&bel") );
230 autosizeMenu
->Append( ID_SIZE_COL_LABEL
, _T("Selected column &label") );
231 autosizeMenu
->Append( ID_SIZE_LABELS_COL
, _T("Column la&bels") );
232 autosizeMenu
->Append( ID_SIZE_LABELS_ROW
, _T("Row label&s") );
233 autosizeMenu
->Append( ID_SIZE_GRID
, _T("Entire &grid") );
235 wxMenu
*helpMenu
= new wxMenu
;
236 helpMenu
->Append( wxID_ABOUT
, _T("&About wxGrid demo") );
238 wxMenuBar
*menuBar
= new wxMenuBar
;
239 menuBar
->Append( fileMenu
, _T("&File") );
240 menuBar
->Append( viewMenu
, _T("&View") );
241 menuBar
->Append( colMenu
, _T("&Colours") );
242 menuBar
->Append( editMenu
, _T("&Edit") );
243 menuBar
->Append( selectMenu
, _T("&Select") );
244 menuBar
->Append( autosizeMenu
, _T("&Autosize") );
245 menuBar
->Append( helpMenu
, _T("&Help") );
247 SetMenuBar( menuBar
);
251 grid
= new wxGrid( this,
254 wxSize( 400, 300 ) );
257 int gridW
= 600, gridH
= 300;
258 int logW
= gridW
, logH
= 100;
260 logWin
= new wxTextCtrl( this,
263 wxPoint( 0, gridH
+ 20 ),
264 wxSize( logW
, logH
),
267 logger
= new wxLogTextCtrl( logWin
);
268 m_logOld
= wxLog::SetActiveTarget( logger
);
269 wxLog::DisableTimestamp();
272 // this will create a grid and, by default, an associated grid
274 grid
->CreateGrid( 0, 0 );
275 grid
->AppendRows(100);
276 grid
->AppendCols(100);
278 int ir
= grid
->GetNumberRows();
279 grid
->DeleteRows(0, ir
);
280 grid
->AppendRows(ir
);
282 grid
->SetRowSize( 0, 60 );
283 grid
->SetCellValue( 0, 0, _T("Ctrl+Home\nwill go to\nthis cell") );
285 grid
->SetCellValue( 0, 1, _T("A long piece of text to demonstrate wrapping.") );
286 grid
->SetCellRenderer(0 , 1, new wxGridCellAutoWrapStringRenderer
);
287 grid
->SetCellEditor( 0, 1 , new wxGridCellAutoWrapStringEditor
);
289 grid
->SetCellValue( 0, 2, _T("Blah") );
290 grid
->SetCellValue( 0, 3, _T("Read only") );
291 grid
->SetReadOnly( 0, 3 );
293 grid
->SetCellValue( 0, 4, _T("Can veto edit this cell") );
295 grid
->SetCellValue( 0, 5, _T("Press\nCtrl+arrow\nto skip over\ncells") );
297 grid
->SetRowSize( 99, 60 );
298 grid
->SetCellValue( 99, 99, _T("Ctrl+End\nwill go to\nthis cell") );
299 grid
->SetCellValue( 1, 0, _T("This default cell will overflow into neighboring cells, but not if you turn overflow off."));
301 grid
->SetCellTextColour(1, 2, *wxRED
);
302 grid
->SetCellBackgroundColour(1, 2, *wxGREEN
);
304 grid
->SetCellValue( 1, 4, _T("I'm in the middle"));
306 grid
->SetCellValue(2, 2, _T("red"));
308 grid
->SetCellTextColour(2, 2, *wxRED
);
309 grid
->SetCellValue(3, 3, _T("green on grey"));
310 grid
->SetCellTextColour(3, 3, *wxGREEN
);
311 grid
->SetCellBackgroundColour(3, 3, *wxLIGHT_GREY
);
313 grid
->SetCellValue(4, 4, _T("a weird looking cell"));
314 grid
->SetCellAlignment(4, 4, wxALIGN_CENTRE
, wxALIGN_CENTRE
);
315 grid
->SetCellRenderer(4, 4, new MyGridCellRenderer
);
317 grid
->SetCellValue(3, 0, _T("0"));
318 grid
->SetCellRenderer(3, 0, new wxGridCellBoolRenderer
);
319 grid
->SetCellEditor(3, 0, new wxGridCellBoolEditor
);
321 wxGridCellAttr
*attr
;
322 attr
= new wxGridCellAttr
;
323 attr
->SetTextColour(*wxBLUE
);
324 grid
->SetColAttr(5, attr
);
325 attr
= new wxGridCellAttr
;
326 attr
->SetBackgroundColour(*wxRED
);
327 grid
->SetRowAttr(5, attr
);
329 grid
->SetCellValue(2, 4, _T("a wider column"));
330 grid
->SetColSize(4, 120);
331 grid
->SetColMinimalWidth(4, 120);
333 grid
->SetCellTextColour(5, 8, *wxGREEN
);
334 grid
->SetCellValue(5, 8, _T("Bg from row attr\nText col from cell attr"));
335 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"));
337 grid
->SetColFormatFloat(6);
338 grid
->SetCellValue(0, 6, _T("3.1415"));
339 grid
->SetCellValue(1, 6, _T("1415"));
340 grid
->SetCellValue(2, 6, _T("12345.67890"));
342 grid
->SetColFormatFloat(7, 6, 2);
343 grid
->SetCellValue(0, 7, _T("3.1415"));
344 grid
->SetCellValue(1, 7, _T("1415"));
345 grid
->SetCellValue(2, 7, _T("12345.67890"));
347 const wxString choices
[] =
349 _T("Please select a choice"),
350 _T("This takes two cells"),
351 _T("Another choice"),
353 grid
->SetCellEditor(4, 0, new wxGridCellChoiceEditor(WXSIZEOF(choices
), choices
));
354 grid
->SetCellSize(4, 0, 1, 2);
355 grid
->SetCellValue(4, 0, choices
[0]);
356 grid
->SetCellOverflow(4, 0, false);
358 grid
->SetCellSize(7, 1, 3, 4);
359 grid
->SetCellAlignment(7, 1, wxALIGN_CENTRE
, wxALIGN_CENTRE
);
360 grid
->SetCellValue(7, 1, _T("Big box!"));
362 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
368 topSizer
->Add( logWin
,
374 SetSizer( topSizer
);
376 topSizer
->Fit( this );
383 GridFrame::~GridFrame()
386 delete wxLog::SetActiveTarget(m_logOld
);
391 void GridFrame::SetDefaults()
393 GetMenuBar()->Check( ID_TOGGLEROWLABELS
, true );
394 GetMenuBar()->Check( ID_TOGGLECOLLABELS
, true );
395 GetMenuBar()->Check( ID_TOGGLEEDIT
, true );
396 GetMenuBar()->Check( ID_TOGGLEROWSIZING
, true );
397 GetMenuBar()->Check( ID_TOGGLECOLSIZING
, true );
398 GetMenuBar()->Check( ID_TOGGLECOLMOVING
, false );
399 GetMenuBar()->Check( ID_TOGGLEGRIDSIZING
, true );
400 GetMenuBar()->Check( ID_TOGGLEGRIDDRAGCELL
, false );
401 GetMenuBar()->Check( ID_TOGGLEGRIDLINES
, true );
402 GetMenuBar()->Check( ID_CELLOVERFLOW
, true );
406 void GridFrame::ToggleRowLabels( wxCommandEvent
& WXUNUSED(ev
) )
408 if ( GetMenuBar()->IsChecked( ID_TOGGLEROWLABELS
) )
410 grid
->SetRowLabelSize( grid
->GetDefaultRowLabelSize() );
414 grid
->SetRowLabelSize( 0 );
419 void GridFrame::ToggleColLabels( wxCommandEvent
& WXUNUSED(ev
) )
421 if ( GetMenuBar()->IsChecked( ID_TOGGLECOLLABELS
) )
423 grid
->SetColLabelSize( grid
->GetDefaultColLabelSize() );
427 grid
->SetColLabelSize( 0 );
432 void GridFrame::ToggleEditing( wxCommandEvent
& WXUNUSED(ev
) )
435 GetMenuBar()->IsChecked( ID_TOGGLEEDIT
) );
439 void GridFrame::ToggleRowSizing( wxCommandEvent
& WXUNUSED(ev
) )
441 grid
->EnableDragRowSize(
442 GetMenuBar()->IsChecked( ID_TOGGLEROWSIZING
) );
446 void GridFrame::ToggleColSizing( wxCommandEvent
& WXUNUSED(ev
) )
448 grid
->EnableDragColSize(
449 GetMenuBar()->IsChecked( ID_TOGGLECOLSIZING
) );
452 void GridFrame::ToggleColMoving( wxCommandEvent
& WXUNUSED(ev
) )
454 grid
->EnableDragColMove(
455 GetMenuBar()->IsChecked( ID_TOGGLECOLMOVING
) );
458 void GridFrame::ToggleGridSizing( wxCommandEvent
& WXUNUSED(ev
) )
460 grid
->EnableDragGridSize(
461 GetMenuBar()->IsChecked( ID_TOGGLEGRIDSIZING
) );
464 void GridFrame::ToggleGridDragCell( wxCommandEvent
& WXUNUSED(ev
) )
466 grid
->EnableDragCell(
467 GetMenuBar()->IsChecked( ID_TOGGLEGRIDDRAGCELL
) );
470 void GridFrame::ToggleGridLines( wxCommandEvent
& WXUNUSED(ev
) )
472 grid
->EnableGridLines(
473 GetMenuBar()->IsChecked( ID_TOGGLEGRIDLINES
) );
476 void GridFrame::OnSetHighlightWidth( wxCommandEvent
& WXUNUSED(ev
) )
478 wxString choices
[] = { _T("0"), _T("1"), _T("2"), _T("3"), _T("4"), _T("5"), _T("6"), _T("7"), _T("8"), _T("9"), _T("10")};
480 wxSingleChoiceDialog
dlg(this, _T("Choose the thickness of the highlight pen:"),
481 _T("Pen Width"), 11, choices
);
483 int current
= grid
->GetCellHighlightPenWidth();
484 dlg
.SetSelection(current
);
485 if (dlg
.ShowModal() == wxID_OK
) {
486 grid
->SetCellHighlightPenWidth(dlg
.GetSelection());
490 void GridFrame::OnSetROHighlightWidth( wxCommandEvent
& WXUNUSED(ev
) )
492 wxString choices
[] = { _T("0"), _T("1"), _T("2"), _T("3"), _T("4"), _T("5"), _T("6"), _T("7"), _T("8"), _T("9"), _T("10")};
494 wxSingleChoiceDialog
dlg(this, _T("Choose the thickness of the highlight pen:"),
495 _T("Pen Width"), 11, choices
);
497 int current
= grid
->GetCellHighlightROPenWidth();
498 dlg
.SetSelection(current
);
499 if (dlg
.ShowModal() == wxID_OK
) {
500 grid
->SetCellHighlightROPenWidth(dlg
.GetSelection());
506 void GridFrame::AutoSizeCols( wxCommandEvent
& WXUNUSED(ev
) )
508 grid
->AutoSizeColumns();
512 void GridFrame::CellOverflow( wxCommandEvent
& ev
)
514 grid
->SetDefaultCellOverflow(ev
.IsChecked());
518 void GridFrame::ResizeCell( wxCommandEvent
& ev
)
521 grid
->SetCellSize( 7, 1, 5, 5 );
523 grid
->SetCellSize( 7, 1, 1, 5 );
527 void GridFrame::SetLabelColour( wxCommandEvent
& WXUNUSED(ev
) )
529 wxColourDialog
dlg( NULL
);
530 if ( dlg
.ShowModal() == wxID_OK
)
532 wxColourData retData
;
533 retData
= dlg
.GetColourData();
534 wxColour colour
= retData
.GetColour();
536 grid
->SetLabelBackgroundColour( colour
);
541 void GridFrame::SetLabelTextColour( wxCommandEvent
& WXUNUSED(ev
) )
543 wxColourDialog
dlg( NULL
);
544 if ( dlg
.ShowModal() == wxID_OK
)
546 wxColourData retData
;
547 retData
= dlg
.GetColourData();
548 wxColour colour
= retData
.GetColour();
550 grid
->SetLabelTextColour( colour
);
554 void GridFrame::SetLabelFont( wxCommandEvent
& WXUNUSED(ev
) )
556 wxFont font
= wxGetFontFromUser(this);
559 grid
->SetLabelFont(font
);
563 void GridFrame::SetRowLabelHorizAlignment( wxCommandEvent
& WXUNUSED(ev
) )
566 grid
->GetRowLabelAlignment( &horiz
, &vert
);
571 horiz
= wxALIGN_CENTRE
;
575 horiz
= wxALIGN_RIGHT
;
579 horiz
= wxALIGN_LEFT
;
583 grid
->SetRowLabelAlignment( horiz
, vert
);
586 void GridFrame::SetRowLabelVertAlignment( wxCommandEvent
& WXUNUSED(ev
) )
589 grid
->GetRowLabelAlignment( &horiz
, &vert
);
594 vert
= wxALIGN_CENTRE
;
598 vert
= wxALIGN_BOTTOM
;
606 grid
->SetRowLabelAlignment( horiz
, vert
);
610 void GridFrame::SetColLabelHorizAlignment( wxCommandEvent
& WXUNUSED(ev
) )
613 grid
->GetColLabelAlignment( &horiz
, &vert
);
618 horiz
= wxALIGN_CENTRE
;
622 horiz
= wxALIGN_RIGHT
;
626 horiz
= wxALIGN_LEFT
;
630 grid
->SetColLabelAlignment( horiz
, vert
);
634 void GridFrame::SetColLabelVertAlignment( wxCommandEvent
& WXUNUSED(ev
) )
637 grid
->GetColLabelAlignment( &horiz
, &vert
);
642 vert
= wxALIGN_CENTRE
;
646 vert
= wxALIGN_BOTTOM
;
654 grid
->SetColLabelAlignment( horiz
, vert
);
658 void GridFrame::SetGridLineColour( wxCommandEvent
& WXUNUSED(ev
) )
660 wxColourDialog
dlg( NULL
);
661 if ( dlg
.ShowModal() == wxID_OK
)
663 wxColourData retData
;
664 retData
= dlg
.GetColourData();
665 wxColour colour
= retData
.GetColour();
667 grid
->SetGridLineColour( colour
);
672 void GridFrame::InsertRow( wxCommandEvent
& WXUNUSED(ev
) )
674 grid
->InsertRows( grid
->GetGridCursorRow(), 1 );
678 void GridFrame::InsertCol( wxCommandEvent
& WXUNUSED(ev
) )
680 grid
->InsertCols( grid
->GetGridCursorCol(), 1 );
684 void GridFrame::DeleteSelectedRows( wxCommandEvent
& WXUNUSED(ev
) )
686 if ( grid
->IsSelection() )
688 wxGridUpdateLocker
locker(grid
);
689 for ( int n
= 0; n
< grid
->GetNumberRows(); )
691 if ( grid
->IsInSelection( n
, 0 ) )
692 grid
->DeleteRows( n
, 1 );
700 void GridFrame::AutoSizeRow(wxCommandEvent
& WXUNUSED(event
))
702 wxGridUpdateLocker
locker(grid
);
703 const wxArrayInt sels
= grid
->GetSelectedRows();
704 for ( size_t n
= 0, count
= sels
.size(); n
< count
; n
++ )
706 grid
->AutoSizeRow( sels
[n
], false );
710 void GridFrame::AutoSizeCol(wxCommandEvent
& WXUNUSED(event
))
712 wxGridUpdateLocker
locker(grid
);
713 const wxArrayInt sels
= grid
->GetSelectedCols();
714 for ( size_t n
= 0, count
= sels
.size(); n
< count
; n
++ )
716 grid
->AutoSizeColumn( sels
[n
], false );
720 void GridFrame::AutoSizeRowLabel(wxCommandEvent
& WXUNUSED(event
))
722 wxGridUpdateLocker
locker(grid
);
723 const wxArrayInt sels
= grid
->GetSelectedRows();
724 for ( size_t n
= 0, count
= sels
.size(); n
< count
; n
++ )
726 grid
->AutoSizeRowLabelSize( sels
[n
] );
730 void GridFrame::AutoSizeColLabel(wxCommandEvent
& WXUNUSED(event
))
732 wxGridUpdateLocker
locker(grid
);
733 const wxArrayInt sels
= grid
->GetSelectedCols();
734 for ( size_t n
= 0, count
= sels
.size(); n
< count
; n
++ )
736 grid
->AutoSizeColLabelSize( sels
[n
] );
740 void GridFrame::AutoSizeLabelsCol(wxCommandEvent
& WXUNUSED(event
))
742 grid
->SetColLabelSize( wxGRID_AUTOSIZE
);
745 void GridFrame::AutoSizeLabelsRow(wxCommandEvent
& WXUNUSED(event
))
747 grid
->SetRowLabelSize( wxGRID_AUTOSIZE
);
750 void GridFrame::AutoSizeTable(wxCommandEvent
& WXUNUSED(event
))
756 void GridFrame::DeleteSelectedCols( wxCommandEvent
& WXUNUSED(ev
) )
758 if ( grid
->IsSelection() )
760 wxGridUpdateLocker
locker(grid
);
761 for ( int n
= 0; n
< grid
->GetNumberCols(); )
763 if ( grid
->IsInSelection( 0 , n
) )
764 grid
->DeleteCols( n
, 1 );
772 void GridFrame::ClearGrid( wxCommandEvent
& WXUNUSED(ev
) )
777 void GridFrame::SelectCells( wxCommandEvent
& WXUNUSED(ev
) )
779 grid
->SetSelectionMode( wxGrid::wxGridSelectCells
);
782 void GridFrame::SelectRows( wxCommandEvent
& WXUNUSED(ev
) )
784 grid
->SetSelectionMode( wxGrid::wxGridSelectRows
);
787 void GridFrame::SelectCols( wxCommandEvent
& WXUNUSED(ev
) )
789 grid
->SetSelectionMode( wxGrid::wxGridSelectColumns
);
792 void GridFrame::SetCellFgColour( wxCommandEvent
& WXUNUSED(ev
) )
794 wxColour col
= wxGetColourFromUser(this);
797 grid
->SetDefaultCellTextColour(col
);
802 void GridFrame::SetCellBgColour( wxCommandEvent
& WXUNUSED(ev
) )
804 wxColour col
= wxGetColourFromUser(this);
807 // Check the new Refresh function by passing it a rectangle
808 // which exactly fits the grid.
810 wxRect
r(pt
, grid
->GetSize());
811 grid
->SetDefaultCellBackgroundColour(col
);
812 grid
->Refresh(true, &r
);
816 void GridFrame::DeselectCell(wxCommandEvent
& WXUNUSED(event
))
818 grid
->DeselectCell(3, 1);
821 void GridFrame::DeselectCol(wxCommandEvent
& WXUNUSED(event
))
823 grid
->DeselectCol(2);
826 void GridFrame::DeselectRow(wxCommandEvent
& WXUNUSED(event
))
828 grid
->DeselectRow(2);
831 void GridFrame::DeselectAll(wxCommandEvent
& WXUNUSED(event
))
833 grid
->ClearSelection();
836 void GridFrame::SelectCell(wxCommandEvent
& WXUNUSED(event
))
838 grid
->SelectBlock(3, 1, 3, 1, m_addToSel
);
841 void GridFrame::SelectCol(wxCommandEvent
& WXUNUSED(event
))
843 grid
->SelectCol(2, m_addToSel
);
846 void GridFrame::SelectRow(wxCommandEvent
& WXUNUSED(event
))
848 grid
->SelectRow(2, m_addToSel
);
851 void GridFrame::SelectAll(wxCommandEvent
& WXUNUSED(event
))
856 void GridFrame::OnAddToSelectToggle(wxCommandEvent
& event
)
858 m_addToSel
= event
.IsChecked();
861 void GridFrame::OnLabelLeftClick( wxGridEvent
& ev
)
864 if ( ev
.GetRow() != -1 )
866 logBuf
<< _T("Left click on row label ") << ev
.GetRow();
868 else if ( ev
.GetCol() != -1 )
870 logBuf
<< _T("Left click on col label ") << ev
.GetCol();
874 logBuf
<< _T("Left click on corner label");
877 if ( ev
.ShiftDown() )
878 logBuf
<< _T(" (shift down)");
879 if ( ev
.ControlDown() )
880 logBuf
<< _T(" (control down)");
881 wxLogMessage( wxT("%s"), logBuf
.c_str() );
883 // you must call event skip if you want default grid processing
889 void GridFrame::OnCellLeftClick( wxGridEvent
& ev
)
891 wxLogMessage(_T("Left click at row %d, col %d"), ev
.GetRow(), ev
.GetCol());
893 // you must call event skip if you want default grid processing
894 // (cell highlighting etc.)
900 void GridFrame::OnRowSize( wxGridSizeEvent
& ev
)
902 wxLogMessage(_T("Resized row %d"), ev
.GetRowOrCol());
908 void GridFrame::OnColSize( wxGridSizeEvent
& ev
)
910 wxLogMessage(_T("Resized col %d"), ev
.GetRowOrCol());
916 void GridFrame::OnShowSelection(wxCommandEvent
& WXUNUSED(event
))
918 // max number of elements to dump -- otherwise it can take too much time
919 static const size_t countMax
= 100;
923 switch ( grid
->GetSelectionMode() )
925 case wxGrid::wxGridSelectCells
:
927 const wxGridCellCoordsArray
cells(grid
->GetSelectedCells());
928 size_t count
= cells
.size();
929 wxLogMessage(_T("%lu cells selected:"), (unsigned long)count
);
930 if ( count
> countMax
)
932 wxLogMessage(_T("[too many selected cells, ")
933 _T("showing only the first %lu]"),
934 (unsigned long)countMax
);
938 for ( size_t n
= 0; n
< count
; n
++ )
940 const wxGridCellCoords
& c
= cells
[n
];
941 wxLogMessage(_T(" selected cell %lu: (%d, %d)"),
942 (unsigned long)n
, c
.GetCol(), c
.GetRow());
947 case wxGrid::wxGridSelectRows
:
951 case wxGrid::wxGridSelectColumns
:
953 const wxChar
*plural
, *single
;
961 plural
= _T("columns");
962 single
= _T("column");
965 const wxArrayInt
sels(rows
? grid
->GetSelectedRows()
966 : grid
->GetSelectedCols());
967 size_t count
= sels
.size();
968 wxLogMessage(_T("%lu %s selected:"),
969 (unsigned long)count
, plural
);
970 if ( count
> countMax
)
972 wxLogMessage(_T("[too many selected %s, ")
973 _T("showing only the first %lu]"),
974 plural
, (unsigned long)countMax
);
978 for ( size_t n
= 0; n
< count
; n
++ )
980 wxLogMessage(_T(" selected %s %lu: %d"),
981 single
, (unsigned long)n
, sels
[n
]);
987 wxFAIL_MSG( _T("unknown wxGrid selection mode") );
992 void GridFrame::OnSelectCell( wxGridEvent
& ev
)
995 if ( ev
.Selecting() )
996 logBuf
<< _T("Selected ");
998 logBuf
<< _T("Deselected ");
999 logBuf
<< _T("cell at row ") << ev
.GetRow()
1000 << _T(" col ") << ev
.GetCol()
1001 << _T(" ( ControlDown: ")<< (ev
.ControlDown() ? 'T':'F')
1002 << _T(", ShiftDown: ")<< (ev
.ShiftDown() ? 'T':'F')
1003 << _T(", AltDown: ")<< (ev
.AltDown() ? 'T':'F')
1004 << _T(", MetaDown: ")<< (ev
.MetaDown() ? 'T':'F') << _T(" )");
1006 //Indicate whether this column was moved
1007 if ( ((wxGrid
*)ev
.GetEventObject())->GetColPos( ev
.GetCol() ) != ev
.GetCol() )
1008 logBuf
<< _T(" *** Column moved, current position: ") << ((wxGrid
*)ev
.GetEventObject())->GetColPos( ev
.GetCol() );
1010 wxLogMessage( wxT("%s"), logBuf
.c_str() );
1012 // you must call Skip() if you want the default processing
1013 // to occur in wxGrid
1017 void GridFrame::OnRangeSelected( wxGridRangeSelectEvent
& ev
)
1020 if ( ev
.Selecting() )
1021 logBuf
<< _T("Selected ");
1023 logBuf
<< _T("Deselected ");
1024 logBuf
<< _T("cells from row ") << ev
.GetTopRow()
1025 << _T(" col ") << ev
.GetLeftCol()
1026 << _T(" to row ") << ev
.GetBottomRow()
1027 << _T(" col ") << ev
.GetRightCol()
1028 << _T(" ( ControlDown: ")<< (ev
.ControlDown() ? 'T':'F')
1029 << _T(", ShiftDown: ")<< (ev
.ShiftDown() ? 'T':'F')
1030 << _T(", AltDown: ")<< (ev
.AltDown() ? 'T':'F')
1031 << _T(", MetaDown: ")<< (ev
.MetaDown() ? 'T':'F') << _T(" )");
1032 wxLogMessage( wxT("%s"), logBuf
.c_str() );
1037 void GridFrame::OnCellValueChanged( wxGridEvent
& ev
)
1039 int row
= ev
.GetRow(),
1042 wxLogMessage(_T("Value changed for cell at row %d, col %d: now \"%s\""),
1043 row
, col
, grid
->GetCellValue(row
, col
).c_str());
1048 void GridFrame::OnCellBeginDrag( wxGridEvent
& ev
)
1050 wxLogMessage(_T("Got request to drag cell at row %d, col %d"),
1051 ev
.GetRow(), ev
.GetCol());
1056 void GridFrame::OnEditorShown( wxGridEvent
& ev
)
1059 if ( (ev
.GetCol() == 4) &&
1060 (ev
.GetRow() == 0) &&
1061 (wxMessageBox(_T("Are you sure you wish to edit this cell"),
1062 _T("Checking"),wxYES_NO
) == wxNO
) ) {
1068 wxLogMessage( wxT("Cell editor shown.") );
1073 void GridFrame::OnEditorHidden( wxGridEvent
& ev
)
1076 if ( (ev
.GetCol() == 4) &&
1077 (ev
.GetRow() == 0) &&
1078 (wxMessageBox(_T("Are you sure you wish to finish editing this cell"),
1079 _T("Checking"),wxYES_NO
) == wxNO
) ) {
1085 wxLogMessage( wxT("Cell editor hidden.") );
1090 void GridFrame::About( wxCommandEvent
& WXUNUSED(ev
) )
1092 (void)wxMessageBox( _T("\n\nwxGrid demo \n\n")
1093 _T("Michael Bedward, Julian Smart, Vadim Zeitlin"),
1099 void GridFrame::OnQuit( wxCommandEvent
& WXUNUSED(ev
) )
1104 void GridFrame::OnBugsTable(wxCommandEvent
& )
1106 BugsGridFrame
*frame
= new BugsGridFrame
;
1110 void GridFrame::OnSmallGrid(wxCommandEvent
& )
1112 wxFrame
* frame
= new wxFrame(NULL
, wxID_ANY
, _T("A Small Grid"),
1113 wxDefaultPosition
, wxSize(640, 480));
1114 wxPanel
* panel
= new wxPanel(frame
, wxID_ANY
);
1115 wxGrid
* grid
= new wxGrid(panel
, wxID_ANY
, wxPoint(10,10), wxSize(400,400),
1116 wxWANTS_CHARS
| wxSIMPLE_BORDER
);
1117 grid
->CreateGrid(3,3);
1121 void GridFrame::OnVTable(wxCommandEvent
& )
1123 static long s_sizeGrid
= 10000;
1126 // MB: wxGetNumberFromUser doesn't work properly for wxMotif
1129 s
= wxGetTextFromUser( _T("Size of the table to create"),
1133 s
.ToLong( &s_sizeGrid
);
1136 s_sizeGrid
= wxGetNumberFromUser(_T("Size of the table to create"),
1138 _T("wxGridDemo question"),
1143 if ( s_sizeGrid
!= -1 )
1145 BigGridFrame
* win
= new BigGridFrame(s_sizeGrid
);
1150 // ----------------------------------------------------------------------------
1151 // MyGridCellRenderer
1152 // ----------------------------------------------------------------------------
1154 // do something that the default renderer doesn't here just to show that it is
1155 // possible to alter the appearance of the cell beyond what the attributes
1157 void MyGridCellRenderer::Draw(wxGrid
& grid
,
1158 wxGridCellAttr
& attr
,
1164 wxGridCellStringRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
1166 dc
.SetPen(*wxGREEN_PEN
);
1167 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1168 dc
.DrawEllipse(rect
);
1171 // ----------------------------------------------------------------------------
1172 // MyGridCellAttrProvider
1173 // ----------------------------------------------------------------------------
1175 MyGridCellAttrProvider::MyGridCellAttrProvider()
1177 m_attrForOddRows
= new wxGridCellAttr
;
1178 m_attrForOddRows
->SetBackgroundColour(*wxLIGHT_GREY
);
1181 MyGridCellAttrProvider::~MyGridCellAttrProvider()
1183 m_attrForOddRows
->DecRef();
1186 wxGridCellAttr
*MyGridCellAttrProvider::GetAttr(int row
, int col
,
1187 wxGridCellAttr::wxAttrKind kind
/* = wxGridCellAttr::Any */) const
1189 wxGridCellAttr
*attr
= wxGridCellAttrProvider::GetAttr(row
, col
, kind
);
1195 attr
= m_attrForOddRows
;
1200 if ( !attr
->HasBackgroundColour() )
1202 wxGridCellAttr
*attrNew
= attr
->Clone();
1205 attr
->SetBackgroundColour(*wxLIGHT_GREY
);
1213 // ============================================================================
1214 // BigGridFrame and BigGridTable: Sample of a non-standard table
1215 // ============================================================================
1217 BigGridFrame::BigGridFrame(long sizeGrid
)
1218 : wxFrame(NULL
, wxID_ANY
, _T("Plugin Virtual Table"),
1219 wxDefaultPosition
, wxSize(500, 450))
1221 m_grid
= new wxGrid(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
);
1222 m_table
= new BigGridTable(sizeGrid
);
1224 // VZ: I don't understand why this slows down the display that much,
1225 // must profile it...
1226 //m_table->SetAttrProvider(new MyGridCellAttrProvider);
1228 m_grid
->SetTable(m_table
, true);
1230 #if defined __WXMOTIF__
1231 // MB: the grid isn't getting a sensible default size under wxMotif
1233 GetClientSize( &cw
, &ch
);
1234 m_grid
->SetSize( cw
, ch
);
1238 // ============================================================================
1239 // BugsGridFrame: a "realistic" table
1240 // ============================================================================
1242 // ----------------------------------------------------------------------------
1244 // ----------------------------------------------------------------------------
1267 static const wxString severities
[] =
1276 static struct BugsGridData
1282 wxChar platform
[12];
1284 } gs_dataBugsGrid
[] =
1286 { 18, _T("foo doesn't work"), Sev_Major
, 1, _T("wxMSW"), true },
1287 { 27, _T("bar crashes"), Sev_Critical
, 1, _T("all"), false },
1288 { 45, _T("printing is slow"), Sev_Minor
, 3, _T("wxMSW"), true },
1289 { 68, _T("Rectangle() fails"), Sev_Normal
, 1, _T("wxMSW"), false },
1292 static const wxChar
*headers
[Col_Max
] =
1302 // ----------------------------------------------------------------------------
1304 // ----------------------------------------------------------------------------
1306 wxString
BugsGridTable::GetTypeName(int WXUNUSED(row
), int col
)
1312 return wxGRID_VALUE_NUMBER
;;
1315 // fall thorugh (TODO should be a list)
1318 return wxString::Format(_T("%s:80"), wxGRID_VALUE_STRING
);
1321 return wxString::Format(_T("%s:all,MSW,GTK,other"), wxGRID_VALUE_CHOICE
);
1324 return wxGRID_VALUE_BOOL
;
1327 wxFAIL_MSG(_T("unknown column"));
1329 return wxEmptyString
;
1332 int BugsGridTable::GetNumberRows()
1334 return WXSIZEOF(gs_dataBugsGrid
);
1337 int BugsGridTable::GetNumberCols()
1342 bool BugsGridTable::IsEmptyCell( int WXUNUSED(row
), int WXUNUSED(col
) )
1347 wxString
BugsGridTable::GetValue( int row
, int col
)
1349 const BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1354 return wxString::Format(_T("%d"), gd
.id
);
1357 return wxString::Format(_T("%d"), gd
.prio
);
1360 return gd
.opened
? _T("1") : _T("0");
1363 return severities
[gd
.severity
];
1372 return wxEmptyString
;
1375 void BugsGridTable::SetValue( int row
, int col
, const wxString
& value
)
1377 BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1384 wxFAIL_MSG(_T("unexpected column"));
1390 for ( n
= 0; n
< WXSIZEOF(severities
); n
++ )
1392 if ( severities
[n
] == value
)
1394 gd
.severity
= (Severity
)n
;
1399 if ( n
== WXSIZEOF(severities
) )
1401 wxLogWarning(_T("Invalid severity value '%s'."),
1403 gd
.severity
= Sev_Normal
;
1409 wxStrncpy(gd
.summary
, value
, WXSIZEOF(gd
.summary
));
1413 wxStrncpy(gd
.platform
, value
, WXSIZEOF(gd
.platform
));
1419 BugsGridTable::CanGetValueAs(int WXUNUSED(row
),
1421 const wxString
& typeName
)
1423 if ( typeName
== wxGRID_VALUE_STRING
)
1427 else if ( typeName
== wxGRID_VALUE_BOOL
)
1429 return col
== Col_Opened
;
1431 else if ( typeName
== wxGRID_VALUE_NUMBER
)
1433 return col
== Col_Id
|| col
== Col_Priority
|| col
== Col_Severity
;
1441 bool BugsGridTable::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
1443 return CanGetValueAs(row
, col
, typeName
);
1446 long BugsGridTable::GetValueAsLong( int row
, int col
)
1448 const BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1462 wxFAIL_MSG(_T("unexpected column"));
1467 bool BugsGridTable::GetValueAsBool( int row
, int col
)
1469 if ( col
== Col_Opened
)
1471 return gs_dataBugsGrid
[row
].opened
;
1475 wxFAIL_MSG(_T("unexpected column"));
1481 void BugsGridTable::SetValueAsLong( int row
, int col
, long value
)
1483 BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1492 wxFAIL_MSG(_T("unexpected column"));
1496 void BugsGridTable::SetValueAsBool( int row
, int col
, bool value
)
1498 if ( col
== Col_Opened
)
1500 gs_dataBugsGrid
[row
].opened
= value
;
1504 wxFAIL_MSG(_T("unexpected column"));
1508 wxString
BugsGridTable::GetColLabelValue( int col
)
1510 return headers
[col
];
1513 // ----------------------------------------------------------------------------
1515 // ----------------------------------------------------------------------------
1517 BugsGridFrame::BugsGridFrame()
1518 : wxFrame(NULL
, wxID_ANY
, _T("Bugs table"))
1520 wxGrid
*grid
= new wxGrid(this, wxID_ANY
, wxDefaultPosition
);
1521 wxGridTableBase
*table
= new BugsGridTable();
1522 table
->SetAttrProvider(new MyGridCellAttrProvider
);
1523 grid
->SetTable(table
, true);
1525 wxGridCellAttr
*attrRO
= new wxGridCellAttr
,
1526 *attrRangeEditor
= new wxGridCellAttr
,
1527 *attrCombo
= new wxGridCellAttr
;
1529 attrRO
->SetReadOnly();
1530 attrRangeEditor
->SetEditor(new wxGridCellNumberEditor(1, 5));
1531 attrCombo
->SetEditor(new wxGridCellChoiceEditor(WXSIZEOF(severities
),
1534 grid
->SetColAttr(Col_Id
, attrRO
);
1535 grid
->SetColAttr(Col_Priority
, attrRangeEditor
);
1536 grid
->SetColAttr(Col_Severity
, attrCombo
);
1539 SetClientSize(grid
->GetSize());