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
->SetCellRenderer(3, 0, new wxGridCellBoolRenderer
);
318 grid
->SetCellEditor(3, 0, new wxGridCellBoolEditor
);
320 wxGridCellAttr
*attr
;
321 attr
= new wxGridCellAttr
;
322 attr
->SetTextColour(*wxBLUE
);
323 grid
->SetColAttr(5, attr
);
324 attr
= new wxGridCellAttr
;
325 attr
->SetBackgroundColour(*wxRED
);
326 grid
->SetRowAttr(5, attr
);
328 grid
->SetCellValue(2, 4, _T("a wider column"));
329 grid
->SetColSize(4, 120);
330 grid
->SetColMinimalWidth(4, 120);
332 grid
->SetCellTextColour(5, 8, *wxGREEN
);
333 grid
->SetCellValue(5, 8, _T("Bg from row attr\nText col from cell attr"));
334 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"));
336 grid
->SetColFormatFloat(6);
337 grid
->SetCellValue(0, 6, _T("3.1415"));
338 grid
->SetCellValue(1, 6, _T("1415"));
339 grid
->SetCellValue(2, 6, _T("12345.67890"));
341 grid
->SetColFormatFloat(7, 6, 2);
342 grid
->SetCellValue(0, 7, _T("3.1415"));
343 grid
->SetCellValue(1, 7, _T("1415"));
344 grid
->SetCellValue(2, 7, _T("12345.67890"));
346 const wxString choices
[] =
348 _T("Please select a choice"),
349 _T("This takes two cells"),
350 _T("Another choice"),
352 grid
->SetCellEditor(4, 0, new wxGridCellChoiceEditor(WXSIZEOF(choices
), choices
));
353 grid
->SetCellSize(4, 0, 1, 2);
354 grid
->SetCellValue(4, 0, choices
[0]);
355 grid
->SetCellOverflow(4, 0, false);
357 grid
->SetCellSize(7, 1, 3, 4);
358 grid
->SetCellAlignment(7, 1, wxALIGN_CENTRE
, wxALIGN_CENTRE
);
359 grid
->SetCellValue(7, 1, _T("Big box!"));
361 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
367 topSizer
->Add( logWin
,
373 SetSizer( topSizer
);
375 topSizer
->Fit( this );
382 GridFrame::~GridFrame()
385 delete wxLog::SetActiveTarget(m_logOld
);
390 void GridFrame::SetDefaults()
392 GetMenuBar()->Check( ID_TOGGLEROWLABELS
, true );
393 GetMenuBar()->Check( ID_TOGGLECOLLABELS
, true );
394 GetMenuBar()->Check( ID_TOGGLEEDIT
, true );
395 GetMenuBar()->Check( ID_TOGGLEROWSIZING
, true );
396 GetMenuBar()->Check( ID_TOGGLECOLSIZING
, true );
397 GetMenuBar()->Check( ID_TOGGLECOLMOVING
, false );
398 GetMenuBar()->Check( ID_TOGGLEGRIDSIZING
, true );
399 GetMenuBar()->Check( ID_TOGGLEGRIDDRAGCELL
, false );
400 GetMenuBar()->Check( ID_TOGGLEGRIDLINES
, true );
401 GetMenuBar()->Check( ID_CELLOVERFLOW
, true );
405 void GridFrame::ToggleRowLabels( wxCommandEvent
& WXUNUSED(ev
) )
407 if ( GetMenuBar()->IsChecked( ID_TOGGLEROWLABELS
) )
409 grid
->SetRowLabelSize( grid
->GetDefaultRowLabelSize() );
413 grid
->SetRowLabelSize( 0 );
418 void GridFrame::ToggleColLabels( wxCommandEvent
& WXUNUSED(ev
) )
420 if ( GetMenuBar()->IsChecked( ID_TOGGLECOLLABELS
) )
422 grid
->SetColLabelSize( grid
->GetDefaultColLabelSize() );
426 grid
->SetColLabelSize( 0 );
431 void GridFrame::ToggleEditing( wxCommandEvent
& WXUNUSED(ev
) )
434 GetMenuBar()->IsChecked( ID_TOGGLEEDIT
) );
438 void GridFrame::ToggleRowSizing( wxCommandEvent
& WXUNUSED(ev
) )
440 grid
->EnableDragRowSize(
441 GetMenuBar()->IsChecked( ID_TOGGLEROWSIZING
) );
445 void GridFrame::ToggleColSizing( wxCommandEvent
& WXUNUSED(ev
) )
447 grid
->EnableDragColSize(
448 GetMenuBar()->IsChecked( ID_TOGGLECOLSIZING
) );
451 void GridFrame::ToggleColMoving( wxCommandEvent
& WXUNUSED(ev
) )
453 grid
->EnableDragColMove(
454 GetMenuBar()->IsChecked( ID_TOGGLECOLMOVING
) );
457 void GridFrame::ToggleGridSizing( wxCommandEvent
& WXUNUSED(ev
) )
459 grid
->EnableDragGridSize(
460 GetMenuBar()->IsChecked( ID_TOGGLEGRIDSIZING
) );
463 void GridFrame::ToggleGridDragCell( wxCommandEvent
& WXUNUSED(ev
) )
465 grid
->EnableDragCell(
466 GetMenuBar()->IsChecked( ID_TOGGLEGRIDDRAGCELL
) );
469 void GridFrame::ToggleGridLines( wxCommandEvent
& WXUNUSED(ev
) )
471 grid
->EnableGridLines(
472 GetMenuBar()->IsChecked( ID_TOGGLEGRIDLINES
) );
475 void GridFrame::OnSetHighlightWidth( wxCommandEvent
& WXUNUSED(ev
) )
477 wxString choices
[] = { _T("0"), _T("1"), _T("2"), _T("3"), _T("4"), _T("5"), _T("6"), _T("7"), _T("8"), _T("9"), _T("10")};
479 wxSingleChoiceDialog
dlg(this, _T("Choose the thickness of the highlight pen:"),
480 _T("Pen Width"), 11, choices
);
482 int current
= grid
->GetCellHighlightPenWidth();
483 dlg
.SetSelection(current
);
484 if (dlg
.ShowModal() == wxID_OK
) {
485 grid
->SetCellHighlightPenWidth(dlg
.GetSelection());
489 void GridFrame::OnSetROHighlightWidth( wxCommandEvent
& WXUNUSED(ev
) )
491 wxString choices
[] = { _T("0"), _T("1"), _T("2"), _T("3"), _T("4"), _T("5"), _T("6"), _T("7"), _T("8"), _T("9"), _T("10")};
493 wxSingleChoiceDialog
dlg(this, _T("Choose the thickness of the highlight pen:"),
494 _T("Pen Width"), 11, choices
);
496 int current
= grid
->GetCellHighlightROPenWidth();
497 dlg
.SetSelection(current
);
498 if (dlg
.ShowModal() == wxID_OK
) {
499 grid
->SetCellHighlightROPenWidth(dlg
.GetSelection());
505 void GridFrame::AutoSizeCols( wxCommandEvent
& WXUNUSED(ev
) )
507 grid
->AutoSizeColumns();
511 void GridFrame::CellOverflow( wxCommandEvent
& ev
)
513 grid
->SetDefaultCellOverflow(ev
.IsChecked());
517 void GridFrame::ResizeCell( wxCommandEvent
& ev
)
520 grid
->SetCellSize( 7, 1, 5, 5 );
522 grid
->SetCellSize( 7, 1, 1, 5 );
526 void GridFrame::SetLabelColour( wxCommandEvent
& WXUNUSED(ev
) )
528 wxColourDialog
dlg( NULL
);
529 if ( dlg
.ShowModal() == wxID_OK
)
531 wxColourData retData
;
532 retData
= dlg
.GetColourData();
533 wxColour colour
= retData
.GetColour();
535 grid
->SetLabelBackgroundColour( colour
);
540 void GridFrame::SetLabelTextColour( wxCommandEvent
& WXUNUSED(ev
) )
542 wxColourDialog
dlg( NULL
);
543 if ( dlg
.ShowModal() == wxID_OK
)
545 wxColourData retData
;
546 retData
= dlg
.GetColourData();
547 wxColour colour
= retData
.GetColour();
549 grid
->SetLabelTextColour( colour
);
553 void GridFrame::SetLabelFont( wxCommandEvent
& WXUNUSED(ev
) )
555 wxFont font
= wxGetFontFromUser(this);
558 grid
->SetLabelFont(font
);
562 void GridFrame::SetRowLabelHorizAlignment( wxCommandEvent
& WXUNUSED(ev
) )
565 grid
->GetRowLabelAlignment( &horiz
, &vert
);
570 horiz
= wxALIGN_CENTRE
;
574 horiz
= wxALIGN_RIGHT
;
578 horiz
= wxALIGN_LEFT
;
582 grid
->SetRowLabelAlignment( horiz
, vert
);
585 void GridFrame::SetRowLabelVertAlignment( wxCommandEvent
& WXUNUSED(ev
) )
588 grid
->GetRowLabelAlignment( &horiz
, &vert
);
593 vert
= wxALIGN_CENTRE
;
597 vert
= wxALIGN_BOTTOM
;
605 grid
->SetRowLabelAlignment( horiz
, vert
);
609 void GridFrame::SetColLabelHorizAlignment( wxCommandEvent
& WXUNUSED(ev
) )
612 grid
->GetColLabelAlignment( &horiz
, &vert
);
617 horiz
= wxALIGN_CENTRE
;
621 horiz
= wxALIGN_RIGHT
;
625 horiz
= wxALIGN_LEFT
;
629 grid
->SetColLabelAlignment( horiz
, vert
);
633 void GridFrame::SetColLabelVertAlignment( wxCommandEvent
& WXUNUSED(ev
) )
636 grid
->GetColLabelAlignment( &horiz
, &vert
);
641 vert
= wxALIGN_CENTRE
;
645 vert
= wxALIGN_BOTTOM
;
653 grid
->SetColLabelAlignment( horiz
, vert
);
657 void GridFrame::SetGridLineColour( wxCommandEvent
& WXUNUSED(ev
) )
659 wxColourDialog
dlg( NULL
);
660 if ( dlg
.ShowModal() == wxID_OK
)
662 wxColourData retData
;
663 retData
= dlg
.GetColourData();
664 wxColour colour
= retData
.GetColour();
666 grid
->SetGridLineColour( colour
);
671 void GridFrame::InsertRow( wxCommandEvent
& WXUNUSED(ev
) )
673 grid
->InsertRows( grid
->GetGridCursorRow(), 1 );
677 void GridFrame::InsertCol( wxCommandEvent
& WXUNUSED(ev
) )
679 grid
->InsertCols( grid
->GetGridCursorCol(), 1 );
683 void GridFrame::DeleteSelectedRows( wxCommandEvent
& WXUNUSED(ev
) )
685 if ( grid
->IsSelection() )
687 wxGridUpdateLocker
locker(grid
);
688 for ( int n
= 0; n
< grid
->GetNumberRows(); )
690 if ( grid
->IsInSelection( n
, 0 ) )
691 grid
->DeleteRows( n
, 1 );
699 void GridFrame::AutoSizeRow(wxCommandEvent
& WXUNUSED(event
))
701 wxGridUpdateLocker
locker(grid
);
702 const wxArrayInt sels
= grid
->GetSelectedRows();
703 for ( size_t n
= 0, count
= sels
.size(); n
< count
; n
++ )
705 grid
->AutoSizeRow( sels
[n
], false );
709 void GridFrame::AutoSizeCol(wxCommandEvent
& WXUNUSED(event
))
711 wxGridUpdateLocker
locker(grid
);
712 const wxArrayInt sels
= grid
->GetSelectedCols();
713 for ( size_t n
= 0, count
= sels
.size(); n
< count
; n
++ )
715 grid
->AutoSizeColumn( sels
[n
], false );
719 void GridFrame::AutoSizeRowLabel(wxCommandEvent
& WXUNUSED(event
))
721 wxGridUpdateLocker
locker(grid
);
722 const wxArrayInt sels
= grid
->GetSelectedRows();
723 for ( size_t n
= 0, count
= sels
.size(); n
< count
; n
++ )
725 grid
->AutoSizeRowLabelSize( sels
[n
] );
729 void GridFrame::AutoSizeColLabel(wxCommandEvent
& WXUNUSED(event
))
731 wxGridUpdateLocker
locker(grid
);
732 const wxArrayInt sels
= grid
->GetSelectedCols();
733 for ( size_t n
= 0, count
= sels
.size(); n
< count
; n
++ )
735 grid
->AutoSizeColLabelSize( sels
[n
] );
739 void GridFrame::AutoSizeLabelsCol(wxCommandEvent
& WXUNUSED(event
))
741 grid
->SetColLabelSize( wxGRID_AUTOSIZE
);
744 void GridFrame::AutoSizeLabelsRow(wxCommandEvent
& WXUNUSED(event
))
746 grid
->SetRowLabelSize( wxGRID_AUTOSIZE
);
749 void GridFrame::AutoSizeTable(wxCommandEvent
& WXUNUSED(event
))
755 void GridFrame::DeleteSelectedCols( wxCommandEvent
& WXUNUSED(ev
) )
757 if ( grid
->IsSelection() )
759 wxGridUpdateLocker
locker(grid
);
760 for ( int n
= 0; n
< grid
->GetNumberCols(); )
762 if ( grid
->IsInSelection( 0 , n
) )
763 grid
->DeleteCols( n
, 1 );
771 void GridFrame::ClearGrid( wxCommandEvent
& WXUNUSED(ev
) )
776 void GridFrame::SelectCells( wxCommandEvent
& WXUNUSED(ev
) )
778 grid
->SetSelectionMode( wxGrid::wxGridSelectCells
);
781 void GridFrame::SelectRows( wxCommandEvent
& WXUNUSED(ev
) )
783 grid
->SetSelectionMode( wxGrid::wxGridSelectRows
);
786 void GridFrame::SelectCols( wxCommandEvent
& WXUNUSED(ev
) )
788 grid
->SetSelectionMode( wxGrid::wxGridSelectColumns
);
791 void GridFrame::SetCellFgColour( wxCommandEvent
& WXUNUSED(ev
) )
793 wxColour col
= wxGetColourFromUser(this);
796 grid
->SetDefaultCellTextColour(col
);
801 void GridFrame::SetCellBgColour( wxCommandEvent
& WXUNUSED(ev
) )
803 wxColour col
= wxGetColourFromUser(this);
806 // Check the new Refresh function by passing it a rectangle
807 // which exactly fits the grid.
809 wxRect
r(pt
, grid
->GetSize());
810 grid
->SetDefaultCellBackgroundColour(col
);
811 grid
->Refresh(true, &r
);
815 void GridFrame::DeselectCell(wxCommandEvent
& WXUNUSED(event
))
817 grid
->DeselectCell(3, 1);
820 void GridFrame::DeselectCol(wxCommandEvent
& WXUNUSED(event
))
822 grid
->DeselectCol(2);
825 void GridFrame::DeselectRow(wxCommandEvent
& WXUNUSED(event
))
827 grid
->DeselectRow(2);
830 void GridFrame::DeselectAll(wxCommandEvent
& WXUNUSED(event
))
832 grid
->ClearSelection();
835 void GridFrame::SelectCell(wxCommandEvent
& WXUNUSED(event
))
837 grid
->SelectBlock(3, 1, 3, 1, m_addToSel
);
840 void GridFrame::SelectCol(wxCommandEvent
& WXUNUSED(event
))
842 grid
->SelectCol(2, m_addToSel
);
845 void GridFrame::SelectRow(wxCommandEvent
& WXUNUSED(event
))
847 grid
->SelectRow(2, m_addToSel
);
850 void GridFrame::SelectAll(wxCommandEvent
& WXUNUSED(event
))
855 void GridFrame::OnAddToSelectToggle(wxCommandEvent
& event
)
857 m_addToSel
= event
.IsChecked();
860 void GridFrame::OnLabelLeftClick( wxGridEvent
& ev
)
863 if ( ev
.GetRow() != -1 )
865 logBuf
<< _T("Left click on row label ") << ev
.GetRow();
867 else if ( ev
.GetCol() != -1 )
869 logBuf
<< _T("Left click on col label ") << ev
.GetCol();
873 logBuf
<< _T("Left click on corner label");
876 if ( ev
.ShiftDown() )
877 logBuf
<< _T(" (shift down)");
878 if ( ev
.ControlDown() )
879 logBuf
<< _T(" (control down)");
880 wxLogMessage( wxT("%s"), logBuf
.c_str() );
882 // you must call event skip if you want default grid processing
888 void GridFrame::OnCellLeftClick( wxGridEvent
& ev
)
890 wxLogMessage(_T("Left click at row %d, col %d"), ev
.GetRow(), ev
.GetCol());
892 // you must call event skip if you want default grid processing
893 // (cell highlighting etc.)
899 void GridFrame::OnRowSize( wxGridSizeEvent
& ev
)
901 wxLogMessage(_T("Resized row %d"), ev
.GetRowOrCol());
907 void GridFrame::OnColSize( wxGridSizeEvent
& ev
)
909 wxLogMessage(_T("Resized col %d"), ev
.GetRowOrCol());
915 void GridFrame::OnShowSelection(wxCommandEvent
& WXUNUSED(event
))
917 // max number of elements to dump -- otherwise it can take too much time
918 static const size_t countMax
= 100;
922 switch ( grid
->GetSelectionMode() )
924 case wxGrid::wxGridSelectCells
:
926 const wxGridCellCoordsArray
cells(grid
->GetSelectedCells());
927 size_t count
= cells
.size();
928 wxLogMessage(_T("%lu cells selected:"), (unsigned long)count
);
929 if ( count
> countMax
)
931 wxLogMessage(_T("[too many selected cells, ")
932 _T("showing only the first %lu]"),
933 (unsigned long)countMax
);
937 for ( size_t n
= 0; n
< count
; n
++ )
939 const wxGridCellCoords
& c
= cells
[n
];
940 wxLogMessage(_T(" selected cell %lu: (%d, %d)"),
941 (unsigned long)n
, c
.GetCol(), c
.GetRow());
946 case wxGrid::wxGridSelectRows
:
950 case wxGrid::wxGridSelectColumns
:
952 const wxChar
*plural
, *single
;
960 plural
= _T("columns");
961 single
= _T("column");
964 const wxArrayInt
sels((const wxArrayInt
)(rows
? grid
->GetSelectedRows()
965 : grid
->GetSelectedCols()));
966 size_t count
= sels
.size();
967 wxLogMessage(_T("%lu %s selected:"),
968 (unsigned long)count
, plural
);
969 if ( count
> countMax
)
971 wxLogMessage(_T("[too many selected %s, ")
972 _T("showing only the first %lu]"),
973 plural
, (unsigned long)countMax
);
977 for ( size_t n
= 0; n
< count
; n
++ )
979 wxLogMessage(_T(" selected %s %lu: %d"),
980 single
, (unsigned long)n
, sels
[n
]);
986 wxFAIL_MSG( _T("unknown wxGrid selection mode") );
991 void GridFrame::OnSelectCell( wxGridEvent
& ev
)
994 if ( ev
.Selecting() )
995 logBuf
<< _T("Selected ");
997 logBuf
<< _T("Deselected ");
998 logBuf
<< _T("cell at row ") << ev
.GetRow()
999 << _T(" col ") << ev
.GetCol()
1000 << _T(" ( ControlDown: ")<< (ev
.ControlDown() ? 'T':'F')
1001 << _T(", ShiftDown: ")<< (ev
.ShiftDown() ? 'T':'F')
1002 << _T(", AltDown: ")<< (ev
.AltDown() ? 'T':'F')
1003 << _T(", MetaDown: ")<< (ev
.MetaDown() ? 'T':'F') << _T(" )");
1005 //Indicate whether this column was moved
1006 if ( ((wxGrid
*)ev
.GetEventObject())->GetColPos( ev
.GetCol() ) != ev
.GetCol() )
1007 logBuf
<< _T(" *** Column moved, current position: ") << ((wxGrid
*)ev
.GetEventObject())->GetColPos( ev
.GetCol() );
1009 wxLogMessage( wxT("%s"), logBuf
.c_str() );
1011 // you must call Skip() if you want the default processing
1012 // to occur in wxGrid
1016 void GridFrame::OnRangeSelected( wxGridRangeSelectEvent
& ev
)
1019 if ( ev
.Selecting() )
1020 logBuf
<< _T("Selected ");
1022 logBuf
<< _T("Deselected ");
1023 logBuf
<< _T("cells from row ") << ev
.GetTopRow()
1024 << _T(" col ") << ev
.GetLeftCol()
1025 << _T(" to row ") << ev
.GetBottomRow()
1026 << _T(" col ") << ev
.GetRightCol()
1027 << _T(" ( ControlDown: ")<< (ev
.ControlDown() ? 'T':'F')
1028 << _T(", ShiftDown: ")<< (ev
.ShiftDown() ? 'T':'F')
1029 << _T(", AltDown: ")<< (ev
.AltDown() ? 'T':'F')
1030 << _T(", MetaDown: ")<< (ev
.MetaDown() ? 'T':'F') << _T(" )");
1031 wxLogMessage( wxT("%s"), logBuf
.c_str() );
1036 void GridFrame::OnCellValueChanged( wxGridEvent
& ev
)
1038 int row
= ev
.GetRow(),
1041 wxLogMessage(_T("Value changed for cell at row %d, col %d: now \"%s\""),
1042 row
, col
, grid
->GetCellValue(row
, col
).c_str());
1047 void GridFrame::OnCellBeginDrag( wxGridEvent
& ev
)
1049 wxLogMessage(_T("Got request to drag cell at row %d, col %d"),
1050 ev
.GetRow(), ev
.GetCol());
1055 void GridFrame::OnEditorShown( wxGridEvent
& ev
)
1058 if ( (ev
.GetCol() == 4) &&
1059 (ev
.GetRow() == 0) &&
1060 (wxMessageBox(_T("Are you sure you wish to edit this cell"),
1061 _T("Checking"),wxYES_NO
) == wxNO
) ) {
1067 wxLogMessage( wxT("Cell editor shown.") );
1072 void GridFrame::OnEditorHidden( wxGridEvent
& ev
)
1075 if ( (ev
.GetCol() == 4) &&
1076 (ev
.GetRow() == 0) &&
1077 (wxMessageBox(_T("Are you sure you wish to finish editing this cell"),
1078 _T("Checking"),wxYES_NO
) == wxNO
) ) {
1084 wxLogMessage( wxT("Cell editor hidden.") );
1089 void GridFrame::About( wxCommandEvent
& WXUNUSED(ev
) )
1091 (void)wxMessageBox( _T("\n\nwxGrid demo \n\n")
1092 _T("Michael Bedward, Julian Smart, Vadim Zeitlin"),
1098 void GridFrame::OnQuit( wxCommandEvent
& WXUNUSED(ev
) )
1103 void GridFrame::OnBugsTable(wxCommandEvent
& )
1105 BugsGridFrame
*frame
= new BugsGridFrame
;
1109 void GridFrame::OnSmallGrid(wxCommandEvent
& )
1111 wxFrame
* frame
= new wxFrame(NULL
, wxID_ANY
, _T("A Small Grid"),
1112 wxDefaultPosition
, wxSize(640, 480));
1113 wxPanel
* panel
= new wxPanel(frame
, wxID_ANY
);
1114 wxGrid
* grid
= new wxGrid(panel
, wxID_ANY
, wxPoint(10,10), wxSize(400,400),
1115 wxWANTS_CHARS
| wxSIMPLE_BORDER
);
1116 grid
->CreateGrid(3,3);
1120 void GridFrame::OnVTable(wxCommandEvent
& )
1122 static long s_sizeGrid
= 10000;
1125 // MB: wxGetNumberFromUser doesn't work properly for wxMotif
1128 s
= wxGetTextFromUser( _T("Size of the table to create"),
1132 s
.ToLong( &s_sizeGrid
);
1135 s_sizeGrid
= wxGetNumberFromUser(_T("Size of the table to create"),
1137 _T("wxGridDemo question"),
1142 if ( s_sizeGrid
!= -1 )
1144 BigGridFrame
* win
= new BigGridFrame(s_sizeGrid
);
1149 // ----------------------------------------------------------------------------
1150 // MyGridCellRenderer
1151 // ----------------------------------------------------------------------------
1153 // do something that the default renderer doesn't here just to show that it is
1154 // possible to alter the appearance of the cell beyond what the attributes
1156 void MyGridCellRenderer::Draw(wxGrid
& grid
,
1157 wxGridCellAttr
& attr
,
1163 wxGridCellStringRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
1165 dc
.SetPen(*wxGREEN_PEN
);
1166 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1167 dc
.DrawEllipse(rect
);
1170 // ----------------------------------------------------------------------------
1171 // MyGridCellAttrProvider
1172 // ----------------------------------------------------------------------------
1174 MyGridCellAttrProvider::MyGridCellAttrProvider()
1176 m_attrForOddRows
= new wxGridCellAttr
;
1177 m_attrForOddRows
->SetBackgroundColour(*wxLIGHT_GREY
);
1180 MyGridCellAttrProvider::~MyGridCellAttrProvider()
1182 m_attrForOddRows
->DecRef();
1185 wxGridCellAttr
*MyGridCellAttrProvider::GetAttr(int row
, int col
,
1186 wxGridCellAttr::wxAttrKind kind
/* = wxGridCellAttr::Any */) const
1188 wxGridCellAttr
*attr
= wxGridCellAttrProvider::GetAttr(row
, col
, kind
);
1194 attr
= m_attrForOddRows
;
1199 if ( !attr
->HasBackgroundColour() )
1201 wxGridCellAttr
*attrNew
= attr
->Clone();
1204 attr
->SetBackgroundColour(*wxLIGHT_GREY
);
1212 // ============================================================================
1213 // BigGridFrame and BigGridTable: Sample of a non-standard table
1214 // ============================================================================
1216 BigGridFrame::BigGridFrame(long sizeGrid
)
1217 : wxFrame(NULL
, wxID_ANY
, _T("Plugin Virtual Table"),
1218 wxDefaultPosition
, wxSize(500, 450))
1220 m_grid
= new wxGrid(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
);
1221 m_table
= new BigGridTable(sizeGrid
);
1223 // VZ: I don't understand why this slows down the display that much,
1224 // must profile it...
1225 //m_table->SetAttrProvider(new MyGridCellAttrProvider);
1227 m_grid
->SetTable(m_table
, true);
1229 #if defined __WXMOTIF__
1230 // MB: the grid isn't getting a sensible default size under wxMotif
1232 GetClientSize( &cw
, &ch
);
1233 m_grid
->SetSize( cw
, ch
);
1237 // ============================================================================
1238 // BugsGridFrame: a "realistic" table
1239 // ============================================================================
1241 // ----------------------------------------------------------------------------
1243 // ----------------------------------------------------------------------------
1266 static const wxString severities
[] =
1275 static struct BugsGridData
1281 wxChar platform
[12];
1283 } gs_dataBugsGrid
[] =
1285 { 18, _T("foo doesn't work"), Sev_Major
, 1, _T("wxMSW"), true },
1286 { 27, _T("bar crashes"), Sev_Critical
, 1, _T("all"), false },
1287 { 45, _T("printing is slow"), Sev_Minor
, 3, _T("wxMSW"), true },
1288 { 68, _T("Rectangle() fails"), Sev_Normal
, 1, _T("wxMSW"), false },
1291 static const wxChar
*headers
[Col_Max
] =
1301 // ----------------------------------------------------------------------------
1303 // ----------------------------------------------------------------------------
1305 wxString
BugsGridTable::GetTypeName(int WXUNUSED(row
), int col
)
1311 return wxGRID_VALUE_NUMBER
;;
1314 // fall thorugh (TODO should be a list)
1317 return wxString::Format(_T("%s:80"), wxGRID_VALUE_STRING
);
1320 return wxString::Format(_T("%s:all,MSW,GTK,other"), wxGRID_VALUE_CHOICE
);
1323 return wxGRID_VALUE_BOOL
;
1326 wxFAIL_MSG(_T("unknown column"));
1328 return wxEmptyString
;
1331 int BugsGridTable::GetNumberRows()
1333 return WXSIZEOF(gs_dataBugsGrid
);
1336 int BugsGridTable::GetNumberCols()
1341 bool BugsGridTable::IsEmptyCell( int WXUNUSED(row
), int WXUNUSED(col
) )
1346 wxString
BugsGridTable::GetValue( int row
, int col
)
1348 const BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1353 return wxString::Format(_T("%d"), gd
.id
);
1356 return wxString::Format(_T("%d"), gd
.prio
);
1359 return gd
.opened
? _T("1") : _T("0");
1362 return severities
[gd
.severity
];
1371 return wxEmptyString
;
1374 void BugsGridTable::SetValue( int row
, int col
, const wxString
& value
)
1376 BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1383 wxFAIL_MSG(_T("unexpected column"));
1389 for ( n
= 0; n
< WXSIZEOF(severities
); n
++ )
1391 if ( severities
[n
] == value
)
1393 gd
.severity
= (Severity
)n
;
1398 if ( n
== WXSIZEOF(severities
) )
1400 wxLogWarning(_T("Invalid severity value '%s'."),
1402 gd
.severity
= Sev_Normal
;
1408 wxStrncpy(gd
.summary
, value
, WXSIZEOF(gd
.summary
));
1412 wxStrncpy(gd
.platform
, value
, WXSIZEOF(gd
.platform
));
1418 BugsGridTable::CanGetValueAs(int WXUNUSED(row
),
1420 const wxString
& typeName
)
1422 if ( typeName
== wxGRID_VALUE_STRING
)
1426 else if ( typeName
== wxGRID_VALUE_BOOL
)
1428 return col
== Col_Opened
;
1430 else if ( typeName
== wxGRID_VALUE_NUMBER
)
1432 return col
== Col_Id
|| col
== Col_Priority
|| col
== Col_Severity
;
1440 bool BugsGridTable::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
1442 return CanGetValueAs(row
, col
, typeName
);
1445 long BugsGridTable::GetValueAsLong( int row
, int col
)
1447 const BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1461 wxFAIL_MSG(_T("unexpected column"));
1466 bool BugsGridTable::GetValueAsBool( int row
, int col
)
1468 if ( col
== Col_Opened
)
1470 return gs_dataBugsGrid
[row
].opened
;
1474 wxFAIL_MSG(_T("unexpected column"));
1480 void BugsGridTable::SetValueAsLong( int row
, int col
, long value
)
1482 BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1491 wxFAIL_MSG(_T("unexpected column"));
1495 void BugsGridTable::SetValueAsBool( int row
, int col
, bool value
)
1497 if ( col
== Col_Opened
)
1499 gs_dataBugsGrid
[row
].opened
= value
;
1503 wxFAIL_MSG(_T("unexpected column"));
1507 wxString
BugsGridTable::GetColLabelValue( int col
)
1509 return headers
[col
];
1512 // ----------------------------------------------------------------------------
1514 // ----------------------------------------------------------------------------
1516 BugsGridFrame::BugsGridFrame()
1517 : wxFrame(NULL
, wxID_ANY
, _T("Bugs table"))
1519 wxGrid
*grid
= new wxGrid(this, wxID_ANY
, wxDefaultPosition
);
1520 wxGridTableBase
*table
= new BugsGridTable();
1521 table
->SetAttrProvider(new MyGridCellAttrProvider
);
1522 grid
->SetTable(table
, true);
1524 wxGridCellAttr
*attrRO
= new wxGridCellAttr
,
1525 *attrRangeEditor
= new wxGridCellAttr
,
1526 *attrCombo
= new wxGridCellAttr
;
1528 attrRO
->SetReadOnly();
1529 attrRangeEditor
->SetEditor(new wxGridCellNumberEditor(1, 5));
1530 attrCombo
->SetEditor(new wxGridCellChoiceEditor(WXSIZEOF(severities
),
1533 grid
->SetColAttr(Col_Id
, attrRO
);
1534 grid
->SetColAttr(Col_Priority
, attrRangeEditor
);
1535 grid
->SetColAttr(Col_Severity
, attrCombo
);
1538 SetClientSize(grid
->GetSize());