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_TOGGLENATIVEHEADER
, GridFrame::ToggleNativeHeader
)
75 EVT_MENU( ID_TOGGLEGRIDLINES
, GridFrame::ToggleGridLines
)
76 EVT_MENU( ID_AUTOSIZECOLS
, GridFrame::AutoSizeCols
)
77 EVT_MENU( ID_CELLOVERFLOW
, GridFrame::CellOverflow
)
78 EVT_MENU( ID_RESIZECELL
, GridFrame::ResizeCell
)
79 EVT_MENU( ID_SETLABELCOLOUR
, GridFrame::SetLabelColour
)
80 EVT_MENU( ID_SETLABELTEXTCOLOUR
, GridFrame::SetLabelTextColour
)
81 EVT_MENU( ID_SETLABEL_FONT
, GridFrame::SetLabelFont
)
82 EVT_MENU( ID_ROWLABELHORIZALIGN
, GridFrame::SetRowLabelHorizAlignment
)
83 EVT_MENU( ID_ROWLABELVERTALIGN
, GridFrame::SetRowLabelVertAlignment
)
84 EVT_MENU( ID_COLLABELHORIZALIGN
, GridFrame::SetColLabelHorizAlignment
)
85 EVT_MENU( ID_COLLABELVERTALIGN
, GridFrame::SetColLabelVertAlignment
)
86 EVT_MENU( ID_GRIDLINECOLOUR
, GridFrame::SetGridLineColour
)
87 EVT_MENU( ID_INSERTROW
, GridFrame::InsertRow
)
88 EVT_MENU( ID_INSERTCOL
, GridFrame::InsertCol
)
89 EVT_MENU( ID_DELETEROW
, GridFrame::DeleteSelectedRows
)
90 EVT_MENU( ID_DELETECOL
, GridFrame::DeleteSelectedCols
)
91 EVT_MENU( ID_CLEARGRID
, GridFrame::ClearGrid
)
92 EVT_MENU( ID_SELCELLS
, GridFrame::SelectCells
)
93 EVT_MENU( ID_SELROWS
, GridFrame::SelectRows
)
94 EVT_MENU( ID_SELCOLS
, GridFrame::SelectCols
)
96 EVT_MENU( ID_SET_CELL_FG_COLOUR
, GridFrame::SetCellFgColour
)
97 EVT_MENU( ID_SET_CELL_BG_COLOUR
, GridFrame::SetCellBgColour
)
99 EVT_MENU( wxID_ABOUT
, GridFrame::About
)
100 EVT_MENU( wxID_EXIT
, GridFrame::OnQuit
)
101 EVT_MENU( ID_VTABLE
, GridFrame::OnVTable
)
102 EVT_MENU( ID_BUGS_TABLE
, GridFrame::OnBugsTable
)
103 EVT_MENU( ID_SMALL_GRID
, GridFrame::OnSmallGrid
)
104 EVT_MENU( ID_TABULAR_GRID
, GridFrame::OnTabularGrid
)
106 EVT_MENU( ID_DESELECT_CELL
, GridFrame::DeselectCell
)
107 EVT_MENU( ID_DESELECT_COL
, GridFrame::DeselectCol
)
108 EVT_MENU( ID_DESELECT_ROW
, GridFrame::DeselectRow
)
109 EVT_MENU( ID_DESELECT_ALL
, GridFrame::DeselectAll
)
110 EVT_MENU( ID_SELECT_CELL
, GridFrame::SelectCell
)
111 EVT_MENU( ID_SELECT_COL
, GridFrame::SelectCol
)
112 EVT_MENU( ID_SELECT_ROW
, GridFrame::SelectRow
)
113 EVT_MENU( ID_SELECT_ALL
, GridFrame::SelectAll
)
114 EVT_MENU( ID_SELECT_UNSELECT
, GridFrame::OnAddToSelectToggle
)
115 EVT_MENU( ID_SHOW_SELECTION
, GridFrame::OnShowSelection
)
117 EVT_MENU( ID_SIZE_ROW
, GridFrame::AutoSizeRow
)
118 EVT_MENU( ID_SIZE_COL
, GridFrame::AutoSizeCol
)
119 EVT_MENU( ID_SIZE_ROW_LABEL
, GridFrame::AutoSizeRowLabel
)
120 EVT_MENU( ID_SIZE_COL_LABEL
, GridFrame::AutoSizeColLabel
)
121 EVT_MENU( ID_SIZE_LABELS_COL
, GridFrame::AutoSizeLabelsCol
)
122 EVT_MENU( ID_SIZE_LABELS_ROW
, GridFrame::AutoSizeLabelsRow
)
123 EVT_MENU( ID_SIZE_GRID
, GridFrame::AutoSizeTable
)
125 EVT_MENU( ID_SET_HIGHLIGHT_WIDTH
, GridFrame::OnSetHighlightWidth
)
126 EVT_MENU( ID_SET_RO_HIGHLIGHT_WIDTH
, GridFrame::OnSetROHighlightWidth
)
128 EVT_GRID_LABEL_LEFT_CLICK( GridFrame::OnLabelLeftClick
)
129 EVT_GRID_CELL_LEFT_CLICK( GridFrame::OnCellLeftClick
)
130 EVT_GRID_ROW_SIZE( GridFrame::OnRowSize
)
131 EVT_GRID_COL_SIZE( GridFrame::OnColSize
)
132 EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell
)
133 EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected
)
134 EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged
)
135 EVT_GRID_CELL_BEGIN_DRAG( GridFrame::OnCellBeginDrag
)
137 EVT_GRID_EDITOR_SHOWN( GridFrame::OnEditorShown
)
138 EVT_GRID_EDITOR_HIDDEN( GridFrame::OnEditorHidden
)
142 GridFrame::GridFrame()
143 : wxFrame( (wxFrame
*)NULL
, wxID_ANY
, _T("wxWidgets grid class demo"),
147 wxMenu
*fileMenu
= new wxMenu
;
148 fileMenu
->Append( ID_VTABLE
, _T("&Virtual table test\tCtrl-V"));
149 fileMenu
->Append( ID_BUGS_TABLE
, _T("&Bugs table test\tCtrl-B"));
150 fileMenu
->Append( ID_SMALL_GRID
, _T("&Small Grid test\tCtrl-S"));
151 fileMenu
->Append( ID_TABULAR_GRID
, _T("&Tabular Grid test\tCtrl-T"));
152 fileMenu
->AppendSeparator();
153 fileMenu
->Append( wxID_EXIT
, _T("E&xit\tAlt-X") );
155 wxMenu
*viewMenu
= new wxMenu
;
156 viewMenu
->AppendCheckItem(ID_TOGGLEROWLABELS
, "&Row labels");
157 viewMenu
->AppendCheckItem(ID_TOGGLECOLLABELS
, "&Col labels");
158 viewMenu
->AppendCheckItem(ID_TOGGLEEDIT
,"&Editable");
159 viewMenu
->AppendCheckItem(ID_TOGGLEROWSIZING
, "Ro&w drag-resize");
160 viewMenu
->AppendCheckItem(ID_TOGGLECOLSIZING
, "C&ol drag-resize");
161 viewMenu
->AppendCheckItem(ID_TOGGLECOLMOVING
, "Col drag-&move");
162 viewMenu
->AppendCheckItem(ID_TOGGLEGRIDSIZING
, "&Grid drag-resize");
163 viewMenu
->AppendCheckItem(ID_TOGGLEGRIDDRAGCELL
, "&Grid drag-cell");
164 viewMenu
->AppendCheckItem(ID_TOGGLENATIVEHEADER
, "&Native column headers");
165 viewMenu
->AppendCheckItem(ID_TOGGLEGRIDLINES
, "&Grid Lines");
166 viewMenu
->AppendCheckItem(ID_SET_HIGHLIGHT_WIDTH
, "&Set Cell Highlight Width...");
167 viewMenu
->AppendCheckItem(ID_SET_RO_HIGHLIGHT_WIDTH
, "&Set Cell RO Highlight Width...");
168 viewMenu
->AppendCheckItem(ID_AUTOSIZECOLS
, "&Auto-size cols");
169 viewMenu
->AppendCheckItem(ID_CELLOVERFLOW
, "&Overflow cells");
170 viewMenu
->AppendCheckItem(ID_RESIZECELL
, "&Resize cell (7,1)");
172 wxMenu
*rowLabelMenu
= new wxMenu
;
174 viewMenu
->Append( ID_ROWLABELALIGN
, _T("R&ow label alignment"),
176 _T("Change alignment of row labels") );
178 rowLabelMenu
->Append( ID_ROWLABELHORIZALIGN
, _T("&Horizontal") );
179 rowLabelMenu
->Append( ID_ROWLABELVERTALIGN
, _T("&Vertical") );
181 wxMenu
*colLabelMenu
= new wxMenu
;
183 viewMenu
->Append( ID_COLLABELALIGN
, _T("Col l&abel alignment"),
185 _T("Change alignment of col labels") );
187 colLabelMenu
->Append( ID_COLLABELHORIZALIGN
, _T("&Horizontal") );
188 colLabelMenu
->Append( ID_COLLABELVERTALIGN
, _T("&Vertical") );
190 wxMenu
*colMenu
= new wxMenu
;
191 colMenu
->Append( ID_SETLABELCOLOUR
, _T("Set &label colour...") );
192 colMenu
->Append( ID_SETLABELTEXTCOLOUR
, _T("Set label &text colour...") );
193 colMenu
->Append( ID_SETLABEL_FONT
, _T("Set label fo&nt...") );
194 colMenu
->Append( ID_GRIDLINECOLOUR
, _T("&Grid line colour...") );
195 colMenu
->Append( ID_SET_CELL_FG_COLOUR
, _T("Set cell &foreground colour...") );
196 colMenu
->Append( ID_SET_CELL_BG_COLOUR
, _T("Set cell &background colour...") );
198 wxMenu
*editMenu
= new wxMenu
;
199 editMenu
->Append( ID_INSERTROW
, _T("Insert &row") );
200 editMenu
->Append( ID_INSERTCOL
, _T("Insert &column") );
201 editMenu
->Append( ID_DELETEROW
, _T("Delete selected ro&ws") );
202 editMenu
->Append( ID_DELETECOL
, _T("Delete selected co&ls") );
203 editMenu
->Append( ID_CLEARGRID
, _T("Cl&ear grid cell contents") );
205 wxMenu
*selectMenu
= new wxMenu
;
206 selectMenu
->Append( ID_SELECT_UNSELECT
, _T("Add new cells to the selection"),
207 _T("When off, old selection is deselected before ")
208 _T("selecting the new cells"), wxITEM_CHECK
);
209 selectMenu
->Append( ID_SHOW_SELECTION
,
210 _T("&Show current selection\tCtrl-Alt-S"));
211 selectMenu
->AppendSeparator();
212 selectMenu
->Append( ID_SELECT_ALL
, _T("Select all"));
213 selectMenu
->Append( ID_SELECT_ROW
, _T("Select row 2"));
214 selectMenu
->Append( ID_SELECT_COL
, _T("Select col 2"));
215 selectMenu
->Append( ID_SELECT_CELL
, _T("Select cell (3, 1)"));
216 selectMenu
->AppendSeparator();
217 selectMenu
->Append( ID_DESELECT_ALL
, _T("Deselect all"));
218 selectMenu
->Append( ID_DESELECT_ROW
, _T("Deselect row 2"));
219 selectMenu
->Append( ID_DESELECT_COL
, _T("Deselect col 2"));
220 selectMenu
->Append( ID_DESELECT_CELL
, _T("Deselect cell (3, 1)"));
221 wxMenu
*selectionMenu
= new wxMenu
;
222 selectMenu
->Append( ID_CHANGESEL
, _T("Change &selection mode"),
224 _T("Change selection mode") );
226 selectionMenu
->Append( ID_SELCELLS
, _T("Select &Cells") );
227 selectionMenu
->Append( ID_SELROWS
, _T("Select &Rows") );
228 selectionMenu
->Append( ID_SELCOLS
, _T("Select C&ols") );
230 wxMenu
*autosizeMenu
= new wxMenu
;
231 autosizeMenu
->Append( ID_SIZE_ROW
, _T("Selected &row data") );
232 autosizeMenu
->Append( ID_SIZE_COL
, _T("Selected &column data") );
233 autosizeMenu
->Append( ID_SIZE_ROW_LABEL
, _T("Selected row la&bel") );
234 autosizeMenu
->Append( ID_SIZE_COL_LABEL
, _T("Selected column &label") );
235 autosizeMenu
->Append( ID_SIZE_LABELS_COL
, _T("Column la&bels") );
236 autosizeMenu
->Append( ID_SIZE_LABELS_ROW
, _T("Row label&s") );
237 autosizeMenu
->Append( ID_SIZE_GRID
, _T("Entire &grid") );
239 wxMenu
*helpMenu
= new wxMenu
;
240 helpMenu
->Append( wxID_ABOUT
, _T("&About wxGrid demo") );
242 wxMenuBar
*menuBar
= new wxMenuBar
;
243 menuBar
->Append( fileMenu
, _T("&File") );
244 menuBar
->Append( viewMenu
, _T("&Grid") );
245 menuBar
->Append( colMenu
, _T("&Colours") );
246 menuBar
->Append( editMenu
, _T("&Edit") );
247 menuBar
->Append( selectMenu
, _T("&Select") );
248 menuBar
->Append( autosizeMenu
, _T("&Autosize") );
249 menuBar
->Append( helpMenu
, _T("&Help") );
251 SetMenuBar( menuBar
);
255 grid
= new wxGrid( this,
258 wxSize( 400, 300 ) );
261 int gridW
= 600, gridH
= 300;
262 int logW
= gridW
, logH
= 100;
264 logWin
= new wxTextCtrl( this,
267 wxPoint( 0, gridH
+ 20 ),
268 wxSize( logW
, logH
),
271 logger
= new wxLogTextCtrl( logWin
);
272 m_logOld
= wxLog::SetActiveTarget( logger
);
273 wxLog::DisableTimestamp();
276 // this will create a grid and, by default, an associated grid
278 grid
->CreateGrid( 0, 0 );
279 grid
->AppendRows(100);
280 grid
->AppendCols(100);
282 int ir
= grid
->GetNumberRows();
283 grid
->DeleteRows(0, ir
);
284 grid
->AppendRows(ir
);
286 grid
->SetRowSize( 0, 60 );
287 grid
->SetCellValue( 0, 0, _T("Ctrl+Home\nwill go to\nthis cell") );
289 grid
->SetCellValue( 0, 1, _T("A long piece of text to demonstrate wrapping.") );
290 grid
->SetCellRenderer(0 , 1, new wxGridCellAutoWrapStringRenderer
);
291 grid
->SetCellEditor( 0, 1 , new wxGridCellAutoWrapStringEditor
);
293 grid
->SetCellValue( 0, 2, _T("Blah") );
294 grid
->SetCellValue( 0, 3, _T("Read only") );
295 grid
->SetReadOnly( 0, 3 );
297 grid
->SetCellValue( 0, 4, _T("Can veto edit this cell") );
299 grid
->SetCellValue( 0, 5, _T("Press\nCtrl+arrow\nto skip over\ncells") );
301 grid
->SetRowSize( 99, 60 );
302 grid
->SetCellValue( 99, 99, _T("Ctrl+End\nwill go to\nthis cell") );
303 grid
->SetCellValue( 1, 0, _T("This default cell will overflow into neighboring cells, but not if you turn overflow off."));
305 grid
->SetCellTextColour(1, 2, *wxRED
);
306 grid
->SetCellBackgroundColour(1, 2, *wxGREEN
);
308 grid
->SetCellValue( 1, 4, _T("I'm in the middle"));
310 grid
->SetCellValue(2, 2, _T("red"));
312 grid
->SetCellTextColour(2, 2, *wxRED
);
313 grid
->SetCellValue(3, 3, _T("green on grey"));
314 grid
->SetCellTextColour(3, 3, *wxGREEN
);
315 grid
->SetCellBackgroundColour(3, 3, *wxLIGHT_GREY
);
317 grid
->SetCellValue(4, 4, _T("a weird looking cell"));
318 grid
->SetCellAlignment(4, 4, wxALIGN_CENTRE
, wxALIGN_CENTRE
);
319 grid
->SetCellRenderer(4, 4, new MyGridCellRenderer
);
321 grid
->SetCellRenderer(3, 0, new wxGridCellBoolRenderer
);
322 grid
->SetCellEditor(3, 0, new wxGridCellBoolEditor
);
324 wxGridCellAttr
*attr
;
325 attr
= new wxGridCellAttr
;
326 attr
->SetTextColour(*wxBLUE
);
327 grid
->SetColAttr(5, attr
);
328 attr
= new wxGridCellAttr
;
329 attr
->SetBackgroundColour(*wxRED
);
330 grid
->SetRowAttr(5, attr
);
332 grid
->SetCellValue(2, 4, _T("a wider column"));
333 grid
->SetColSize(4, 120);
334 grid
->SetColMinimalWidth(4, 120);
336 grid
->SetCellTextColour(5, 8, *wxGREEN
);
337 grid
->SetCellValue(5, 8, _T("Bg from row attr\nText col from cell attr"));
338 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"));
340 grid
->SetColFormatFloat(6);
341 grid
->SetCellValue(0, 6, wxString::Format(wxT("%g"), 3.1415));
342 grid
->SetCellValue(1, 6, wxString::Format(wxT("%g"), 1415.0));
343 grid
->SetCellValue(2, 6, wxString::Format(wxT("%g"), 12345.67890));
345 grid
->SetColFormatFloat(7, 6, 2);
346 grid
->SetCellValue(0, 7, wxString::Format(wxT("%g"), 3.1415));
347 grid
->SetCellValue(1, 7, wxString::Format(wxT("%g"), 1415.0));
348 grid
->SetCellValue(2, 7, wxString::Format(wxT("%g"), 12345.67890));
350 grid
->SetColFormatNumber(8);
351 grid
->SetCellValue(0, 8, "17");
352 grid
->SetCellValue(1, 8, "0");
353 grid
->SetCellValue(2, 8, "-666");
355 const wxString choices
[] =
357 _T("Please select a choice"),
358 _T("This takes two cells"),
359 _T("Another choice"),
361 grid
->SetCellEditor(4, 0, new wxGridCellChoiceEditor(WXSIZEOF(choices
), choices
));
362 grid
->SetCellSize(4, 0, 1, 2);
363 grid
->SetCellValue(4, 0, choices
[0]);
364 grid
->SetCellOverflow(4, 0, false);
366 grid
->SetCellSize(7, 1, 3, 4);
367 grid
->SetCellAlignment(7, 1, wxALIGN_CENTRE
, wxALIGN_CENTRE
);
368 grid
->SetCellValue(7, 1, _T("Big box!"));
370 // this does exactly nothing except testing that SetAttr() handles NULL
371 // attributes and does reference counting correctly
372 grid
->SetAttr(11, 11, NULL
);
373 grid
->SetAttr(11, 11, new wxGridCellAttr
);
374 grid
->SetAttr(11, 11, NULL
);
376 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
382 topSizer
->Add( logWin
,
387 SetSizerAndFit( topSizer
);
394 GridFrame::~GridFrame()
397 delete wxLog::SetActiveTarget(m_logOld
);
402 void GridFrame::SetDefaults()
404 GetMenuBar()->Check( ID_TOGGLEROWLABELS
, true );
405 GetMenuBar()->Check( ID_TOGGLECOLLABELS
, true );
406 GetMenuBar()->Check( ID_TOGGLEEDIT
, true );
407 GetMenuBar()->Check( ID_TOGGLEROWSIZING
, true );
408 GetMenuBar()->Check( ID_TOGGLECOLSIZING
, true );
409 GetMenuBar()->Check( ID_TOGGLECOLMOVING
, false );
410 GetMenuBar()->Check( ID_TOGGLEGRIDSIZING
, true );
411 GetMenuBar()->Check( ID_TOGGLEGRIDDRAGCELL
, false );
412 GetMenuBar()->Check( ID_TOGGLENATIVEHEADER
, false );
413 GetMenuBar()->Check( ID_TOGGLEGRIDLINES
, true );
414 GetMenuBar()->Check( ID_CELLOVERFLOW
, true );
418 void GridFrame::ToggleRowLabels( wxCommandEvent
& WXUNUSED(ev
) )
420 if ( GetMenuBar()->IsChecked( ID_TOGGLEROWLABELS
) )
422 grid
->SetRowLabelSize( grid
->GetDefaultRowLabelSize() );
426 grid
->SetRowLabelSize( 0 );
431 void GridFrame::ToggleColLabels( wxCommandEvent
& WXUNUSED(ev
) )
433 if ( GetMenuBar()->IsChecked( ID_TOGGLECOLLABELS
) )
435 grid
->SetColLabelSize( grid
->GetDefaultColLabelSize() );
439 grid
->SetColLabelSize( 0 );
444 void GridFrame::ToggleEditing( wxCommandEvent
& WXUNUSED(ev
) )
447 GetMenuBar()->IsChecked( ID_TOGGLEEDIT
) );
451 void GridFrame::ToggleRowSizing( wxCommandEvent
& WXUNUSED(ev
) )
453 grid
->EnableDragRowSize(
454 GetMenuBar()->IsChecked( ID_TOGGLEROWSIZING
) );
458 void GridFrame::ToggleColSizing( wxCommandEvent
& WXUNUSED(ev
) )
460 grid
->EnableDragColSize(
461 GetMenuBar()->IsChecked( ID_TOGGLECOLSIZING
) );
464 void GridFrame::ToggleColMoving( wxCommandEvent
& WXUNUSED(ev
) )
466 grid
->EnableDragColMove(
467 GetMenuBar()->IsChecked( ID_TOGGLECOLMOVING
) );
470 void GridFrame::ToggleGridSizing( wxCommandEvent
& WXUNUSED(ev
) )
472 grid
->EnableDragGridSize(
473 GetMenuBar()->IsChecked( ID_TOGGLEGRIDSIZING
) );
476 void GridFrame::ToggleGridDragCell( wxCommandEvent
& WXUNUSED(ev
) )
478 grid
->EnableDragCell(
479 GetMenuBar()->IsChecked( ID_TOGGLEGRIDDRAGCELL
) );
482 void GridFrame::ToggleNativeHeader( wxCommandEvent
& WXUNUSED(ev
) )
484 grid
->SetUseNativeColLabels(
485 GetMenuBar()->IsChecked( ID_TOGGLENATIVEHEADER
) );
488 void GridFrame::ToggleGridLines( wxCommandEvent
& WXUNUSED(ev
) )
490 grid
->EnableGridLines(
491 GetMenuBar()->IsChecked( ID_TOGGLEGRIDLINES
) );
494 void GridFrame::OnSetHighlightWidth( wxCommandEvent
& WXUNUSED(ev
) )
496 wxString choices
[] = { _T("0"), _T("1"), _T("2"), _T("3"), _T("4"), _T("5"), _T("6"), _T("7"), _T("8"), _T("9"), _T("10")};
498 wxSingleChoiceDialog
dlg(this, _T("Choose the thickness of the highlight pen:"),
499 _T("Pen Width"), 11, choices
);
501 int current
= grid
->GetCellHighlightPenWidth();
502 dlg
.SetSelection(current
);
503 if (dlg
.ShowModal() == wxID_OK
) {
504 grid
->SetCellHighlightPenWidth(dlg
.GetSelection());
508 void GridFrame::OnSetROHighlightWidth( wxCommandEvent
& WXUNUSED(ev
) )
510 wxString choices
[] = { _T("0"), _T("1"), _T("2"), _T("3"), _T("4"), _T("5"), _T("6"), _T("7"), _T("8"), _T("9"), _T("10")};
512 wxSingleChoiceDialog
dlg(this, _T("Choose the thickness of the highlight pen:"),
513 _T("Pen Width"), 11, choices
);
515 int current
= grid
->GetCellHighlightROPenWidth();
516 dlg
.SetSelection(current
);
517 if (dlg
.ShowModal() == wxID_OK
) {
518 grid
->SetCellHighlightROPenWidth(dlg
.GetSelection());
524 void GridFrame::AutoSizeCols( wxCommandEvent
& WXUNUSED(ev
) )
526 grid
->AutoSizeColumns();
530 void GridFrame::CellOverflow( wxCommandEvent
& ev
)
532 grid
->SetDefaultCellOverflow(ev
.IsChecked());
536 void GridFrame::ResizeCell( wxCommandEvent
& ev
)
539 grid
->SetCellSize( 7, 1, 5, 5 );
541 grid
->SetCellSize( 7, 1, 1, 5 );
545 void GridFrame::SetLabelColour( wxCommandEvent
& WXUNUSED(ev
) )
547 wxColourDialog
dlg( NULL
);
548 if ( dlg
.ShowModal() == wxID_OK
)
550 wxColourData retData
;
551 retData
= dlg
.GetColourData();
552 wxColour colour
= retData
.GetColour();
554 grid
->SetLabelBackgroundColour( colour
);
559 void GridFrame::SetLabelTextColour( wxCommandEvent
& WXUNUSED(ev
) )
561 wxColourDialog
dlg( NULL
);
562 if ( dlg
.ShowModal() == wxID_OK
)
564 wxColourData retData
;
565 retData
= dlg
.GetColourData();
566 wxColour colour
= retData
.GetColour();
568 grid
->SetLabelTextColour( colour
);
572 void GridFrame::SetLabelFont( wxCommandEvent
& WXUNUSED(ev
) )
574 wxFont font
= wxGetFontFromUser(this);
577 grid
->SetLabelFont(font
);
581 void GridFrame::SetRowLabelHorizAlignment( wxCommandEvent
& WXUNUSED(ev
) )
584 grid
->GetRowLabelAlignment( &horiz
, &vert
);
589 horiz
= wxALIGN_CENTRE
;
593 horiz
= wxALIGN_RIGHT
;
597 horiz
= wxALIGN_LEFT
;
601 grid
->SetRowLabelAlignment( horiz
, vert
);
604 void GridFrame::SetRowLabelVertAlignment( wxCommandEvent
& WXUNUSED(ev
) )
607 grid
->GetRowLabelAlignment( &horiz
, &vert
);
612 vert
= wxALIGN_CENTRE
;
616 vert
= wxALIGN_BOTTOM
;
624 grid
->SetRowLabelAlignment( horiz
, vert
);
628 void GridFrame::SetColLabelHorizAlignment( wxCommandEvent
& WXUNUSED(ev
) )
631 grid
->GetColLabelAlignment( &horiz
, &vert
);
636 horiz
= wxALIGN_CENTRE
;
640 horiz
= wxALIGN_RIGHT
;
644 horiz
= wxALIGN_LEFT
;
648 grid
->SetColLabelAlignment( horiz
, vert
);
652 void GridFrame::SetColLabelVertAlignment( wxCommandEvent
& WXUNUSED(ev
) )
655 grid
->GetColLabelAlignment( &horiz
, &vert
);
660 vert
= wxALIGN_CENTRE
;
664 vert
= wxALIGN_BOTTOM
;
672 grid
->SetColLabelAlignment( horiz
, vert
);
676 void GridFrame::SetGridLineColour( wxCommandEvent
& WXUNUSED(ev
) )
678 wxColourDialog
dlg( NULL
);
679 if ( dlg
.ShowModal() == wxID_OK
)
681 wxColourData retData
;
682 retData
= dlg
.GetColourData();
683 wxColour colour
= retData
.GetColour();
685 grid
->SetGridLineColour( colour
);
690 void GridFrame::InsertRow( wxCommandEvent
& WXUNUSED(ev
) )
692 grid
->InsertRows( grid
->GetGridCursorRow(), 1 );
696 void GridFrame::InsertCol( wxCommandEvent
& WXUNUSED(ev
) )
698 grid
->InsertCols( grid
->GetGridCursorCol(), 1 );
702 void GridFrame::DeleteSelectedRows( wxCommandEvent
& WXUNUSED(ev
) )
704 if ( grid
->IsSelection() )
706 wxGridUpdateLocker
locker(grid
);
707 for ( int n
= 0; n
< grid
->GetNumberRows(); )
709 if ( grid
->IsInSelection( n
, 0 ) )
710 grid
->DeleteRows( n
, 1 );
718 void GridFrame::AutoSizeRow(wxCommandEvent
& WXUNUSED(event
))
720 wxGridUpdateLocker
locker(grid
);
721 const wxArrayInt sels
= grid
->GetSelectedRows();
722 for ( size_t n
= 0, count
= sels
.size(); n
< count
; n
++ )
724 grid
->AutoSizeRow( sels
[n
], false );
728 void GridFrame::AutoSizeCol(wxCommandEvent
& WXUNUSED(event
))
730 wxGridUpdateLocker
locker(grid
);
731 const wxArrayInt sels
= grid
->GetSelectedCols();
732 for ( size_t n
= 0, count
= sels
.size(); n
< count
; n
++ )
734 grid
->AutoSizeColumn( sels
[n
], false );
738 void GridFrame::AutoSizeRowLabel(wxCommandEvent
& WXUNUSED(event
))
740 wxGridUpdateLocker
locker(grid
);
741 const wxArrayInt sels
= grid
->GetSelectedRows();
742 for ( size_t n
= 0, count
= sels
.size(); n
< count
; n
++ )
744 grid
->AutoSizeRowLabelSize( sels
[n
] );
748 void GridFrame::AutoSizeColLabel(wxCommandEvent
& WXUNUSED(event
))
750 wxGridUpdateLocker
locker(grid
);
751 const wxArrayInt sels
= grid
->GetSelectedCols();
752 for ( size_t n
= 0, count
= sels
.size(); n
< count
; n
++ )
754 grid
->AutoSizeColLabelSize( sels
[n
] );
758 void GridFrame::AutoSizeLabelsCol(wxCommandEvent
& WXUNUSED(event
))
760 grid
->SetColLabelSize( wxGRID_AUTOSIZE
);
763 void GridFrame::AutoSizeLabelsRow(wxCommandEvent
& WXUNUSED(event
))
765 grid
->SetRowLabelSize( wxGRID_AUTOSIZE
);
768 void GridFrame::AutoSizeTable(wxCommandEvent
& WXUNUSED(event
))
774 void GridFrame::DeleteSelectedCols( wxCommandEvent
& WXUNUSED(ev
) )
776 if ( grid
->IsSelection() )
778 wxGridUpdateLocker
locker(grid
);
779 for ( int n
= 0; n
< grid
->GetNumberCols(); )
781 if ( grid
->IsInSelection( 0 , n
) )
782 grid
->DeleteCols( n
, 1 );
790 void GridFrame::ClearGrid( wxCommandEvent
& WXUNUSED(ev
) )
795 void GridFrame::SelectCells( wxCommandEvent
& WXUNUSED(ev
) )
797 grid
->SetSelectionMode( wxGrid::wxGridSelectCells
);
800 void GridFrame::SelectRows( wxCommandEvent
& WXUNUSED(ev
) )
802 grid
->SetSelectionMode( wxGrid::wxGridSelectRows
);
805 void GridFrame::SelectCols( wxCommandEvent
& WXUNUSED(ev
) )
807 grid
->SetSelectionMode( wxGrid::wxGridSelectColumns
);
810 void GridFrame::SetCellFgColour( wxCommandEvent
& WXUNUSED(ev
) )
812 wxColour col
= wxGetColourFromUser(this);
815 grid
->SetDefaultCellTextColour(col
);
820 void GridFrame::SetCellBgColour( wxCommandEvent
& WXUNUSED(ev
) )
822 wxColour col
= wxGetColourFromUser(this);
825 // Check the new Refresh function by passing it a rectangle
826 // which exactly fits the grid.
828 wxRect
r(pt
, grid
->GetSize());
829 grid
->SetDefaultCellBackgroundColour(col
);
830 grid
->Refresh(true, &r
);
834 void GridFrame::DeselectCell(wxCommandEvent
& WXUNUSED(event
))
836 grid
->DeselectCell(3, 1);
839 void GridFrame::DeselectCol(wxCommandEvent
& WXUNUSED(event
))
841 grid
->DeselectCol(2);
844 void GridFrame::DeselectRow(wxCommandEvent
& WXUNUSED(event
))
846 grid
->DeselectRow(2);
849 void GridFrame::DeselectAll(wxCommandEvent
& WXUNUSED(event
))
851 grid
->ClearSelection();
854 void GridFrame::SelectCell(wxCommandEvent
& WXUNUSED(event
))
856 grid
->SelectBlock(3, 1, 3, 1, m_addToSel
);
859 void GridFrame::SelectCol(wxCommandEvent
& WXUNUSED(event
))
861 grid
->SelectCol(2, m_addToSel
);
864 void GridFrame::SelectRow(wxCommandEvent
& WXUNUSED(event
))
866 grid
->SelectRow(2, m_addToSel
);
869 void GridFrame::SelectAll(wxCommandEvent
& WXUNUSED(event
))
874 void GridFrame::OnAddToSelectToggle(wxCommandEvent
& event
)
876 m_addToSel
= event
.IsChecked();
879 void GridFrame::OnLabelLeftClick( wxGridEvent
& ev
)
882 if ( ev
.GetRow() != -1 )
884 logBuf
<< _T("Left click on row label ") << ev
.GetRow();
886 else if ( ev
.GetCol() != -1 )
888 logBuf
<< _T("Left click on col label ") << ev
.GetCol();
892 logBuf
<< _T("Left click on corner label");
895 if ( ev
.ShiftDown() )
896 logBuf
<< _T(" (shift down)");
897 if ( ev
.ControlDown() )
898 logBuf
<< _T(" (control down)");
899 wxLogMessage( wxT("%s"), logBuf
.c_str() );
901 // you must call event skip if you want default grid processing
907 void GridFrame::OnCellLeftClick( wxGridEvent
& ev
)
909 wxLogMessage(_T("Left click at row %d, col %d"), ev
.GetRow(), ev
.GetCol());
911 // you must call event skip if you want default grid processing
912 // (cell highlighting etc.)
918 void GridFrame::OnRowSize( wxGridSizeEvent
& ev
)
920 wxLogMessage(_T("Resized row %d"), ev
.GetRowOrCol());
926 void GridFrame::OnColSize( wxGridSizeEvent
& ev
)
928 wxLogMessage(_T("Resized col %d"), ev
.GetRowOrCol());
934 void GridFrame::OnShowSelection(wxCommandEvent
& WXUNUSED(event
))
936 // max number of elements to dump -- otherwise it can take too much time
937 static const size_t countMax
= 100;
941 switch ( grid
->GetSelectionMode() )
943 case wxGrid::wxGridSelectCells
:
945 const wxGridCellCoordsArray
cells(grid
->GetSelectedCells());
946 size_t count
= cells
.size();
947 wxLogMessage(_T("%lu cells selected:"), (unsigned long)count
);
948 if ( count
> countMax
)
950 wxLogMessage(_T("[too many selected cells, ")
951 _T("showing only the first %lu]"),
952 (unsigned long)countMax
);
956 for ( size_t n
= 0; n
< count
; n
++ )
958 const wxGridCellCoords
& c
= cells
[n
];
959 wxLogMessage(_T(" selected cell %lu: (%d, %d)"),
960 (unsigned long)n
, c
.GetCol(), c
.GetRow());
965 case wxGrid::wxGridSelectRows
:
969 case wxGrid::wxGridSelectColumns
:
971 const wxChar
*plural
, *single
;
979 plural
= _T("columns");
980 single
= _T("column");
983 const wxArrayInt
sels((const wxArrayInt
)(rows
? grid
->GetSelectedRows()
984 : grid
->GetSelectedCols()));
985 size_t count
= sels
.size();
986 wxLogMessage(_T("%lu %s selected:"),
987 (unsigned long)count
, plural
);
988 if ( count
> countMax
)
990 wxLogMessage(_T("[too many selected %s, ")
991 _T("showing only the first %lu]"),
992 plural
, (unsigned long)countMax
);
996 for ( size_t n
= 0; n
< count
; n
++ )
998 wxLogMessage(_T(" selected %s %lu: %d"),
999 single
, (unsigned long)n
, sels
[n
]);
1005 wxFAIL_MSG( _T("unknown wxGrid selection mode") );
1010 void GridFrame::OnSelectCell( wxGridEvent
& ev
)
1013 if ( ev
.Selecting() )
1014 logBuf
<< _T("Selected ");
1016 logBuf
<< _T("Deselected ");
1017 logBuf
<< _T("cell at row ") << ev
.GetRow()
1018 << _T(" col ") << ev
.GetCol()
1019 << _T(" ( ControlDown: ")<< (ev
.ControlDown() ? 'T':'F')
1020 << _T(", ShiftDown: ")<< (ev
.ShiftDown() ? 'T':'F')
1021 << _T(", AltDown: ")<< (ev
.AltDown() ? 'T':'F')
1022 << _T(", MetaDown: ")<< (ev
.MetaDown() ? 'T':'F') << _T(" )");
1024 //Indicate whether this column was moved
1025 if ( ((wxGrid
*)ev
.GetEventObject())->GetColPos( ev
.GetCol() ) != ev
.GetCol() )
1026 logBuf
<< _T(" *** Column moved, current position: ") << ((wxGrid
*)ev
.GetEventObject())->GetColPos( ev
.GetCol() );
1028 wxLogMessage( wxT("%s"), logBuf
.c_str() );
1030 // you must call Skip() if you want the default processing
1031 // to occur in wxGrid
1035 void GridFrame::OnRangeSelected( wxGridRangeSelectEvent
& ev
)
1038 if ( ev
.Selecting() )
1039 logBuf
<< _T("Selected ");
1041 logBuf
<< _T("Deselected ");
1042 logBuf
<< _T("cells from row ") << ev
.GetTopRow()
1043 << _T(" col ") << ev
.GetLeftCol()
1044 << _T(" to row ") << ev
.GetBottomRow()
1045 << _T(" col ") << ev
.GetRightCol()
1046 << _T(" ( ControlDown: ")<< (ev
.ControlDown() ? 'T':'F')
1047 << _T(", ShiftDown: ")<< (ev
.ShiftDown() ? 'T':'F')
1048 << _T(", AltDown: ")<< (ev
.AltDown() ? 'T':'F')
1049 << _T(", MetaDown: ")<< (ev
.MetaDown() ? 'T':'F') << _T(" )");
1050 wxLogMessage( wxT("%s"), logBuf
.c_str() );
1055 void GridFrame::OnCellValueChanged( wxGridEvent
& ev
)
1057 int row
= ev
.GetRow(),
1060 wxLogMessage(_T("Value changed for cell at row %d, col %d: now \"%s\""),
1061 row
, col
, grid
->GetCellValue(row
, col
).c_str());
1066 void GridFrame::OnCellBeginDrag( wxGridEvent
& ev
)
1068 wxLogMessage(_T("Got request to drag cell at row %d, col %d"),
1069 ev
.GetRow(), ev
.GetCol());
1074 void GridFrame::OnEditorShown( wxGridEvent
& ev
)
1077 if ( (ev
.GetCol() == 4) &&
1078 (ev
.GetRow() == 0) &&
1079 (wxMessageBox(_T("Are you sure you wish to edit this cell"),
1080 _T("Checking"),wxYES_NO
) == wxNO
) ) {
1086 wxLogMessage( wxT("Cell editor shown.") );
1091 void GridFrame::OnEditorHidden( wxGridEvent
& ev
)
1094 if ( (ev
.GetCol() == 4) &&
1095 (ev
.GetRow() == 0) &&
1096 (wxMessageBox(_T("Are you sure you wish to finish editing this cell"),
1097 _T("Checking"),wxYES_NO
) == wxNO
) ) {
1103 wxLogMessage( wxT("Cell editor hidden.") );
1108 void GridFrame::About( wxCommandEvent
& WXUNUSED(ev
) )
1110 (void)wxMessageBox( _T("\n\nwxGrid demo \n\n")
1111 _T("Michael Bedward, Julian Smart, Vadim Zeitlin"),
1117 void GridFrame::OnQuit( wxCommandEvent
& WXUNUSED(ev
) )
1122 void GridFrame::OnBugsTable(wxCommandEvent
& )
1124 BugsGridFrame
*frame
= new BugsGridFrame
;
1128 void GridFrame::OnSmallGrid(wxCommandEvent
& )
1130 wxFrame
* frame
= new wxFrame(NULL
, wxID_ANY
, _T("A Small Grid"),
1131 wxDefaultPosition
, wxSize(640, 480));
1132 wxPanel
* panel
= new wxPanel(frame
, wxID_ANY
);
1133 wxGrid
* grid
= new wxGrid(panel
, wxID_ANY
, wxPoint(10,10), wxSize(400,400),
1134 wxWANTS_CHARS
| wxSIMPLE_BORDER
);
1135 grid
->CreateGrid(3,3);
1139 // ----------------------------------------------------------------------------
1140 // MyGridCellAttrProvider
1141 // ----------------------------------------------------------------------------
1143 MyGridCellAttrProvider::MyGridCellAttrProvider()
1145 m_attrForOddRows
= new wxGridCellAttr
;
1146 m_attrForOddRows
->SetBackgroundColour(*wxLIGHT_GREY
);
1149 MyGridCellAttrProvider::~MyGridCellAttrProvider()
1151 m_attrForOddRows
->DecRef();
1154 wxGridCellAttr
*MyGridCellAttrProvider::GetAttr(int row
, int col
,
1155 wxGridCellAttr::wxAttrKind kind
/* = wxGridCellAttr::Any */) const
1157 wxGridCellAttr
*attr
= wxGridCellAttrProvider::GetAttr(row
, col
, kind
);
1163 attr
= m_attrForOddRows
;
1168 if ( !attr
->HasBackgroundColour() )
1170 wxGridCellAttr
*attrNew
= attr
->Clone();
1173 attr
->SetBackgroundColour(*wxLIGHT_GREY
);
1181 // ----------------------------------------------------------------------------
1183 void GridFrame::OnTabularGrid(wxCommandEvent
& )
1185 wxFrame
* frame
= new wxFrame(NULL
, wxID_ANY
, _T("A small tabular Grid"),
1186 wxDefaultPosition
, wxSize(640, 480));
1187 wxGrid
* grid
= new wxGrid(frame
, wxID_ANY
, wxPoint(10,10), wxSize(40,40),
1188 wxWANTS_CHARS
| wxBORDER_SUNKEN
);
1189 grid
->SetRowLabelSize( 0 );
1190 grid
->DisableDragRowSize();
1191 grid
->SetUseNativeColLabels();
1192 grid
->CreateGrid(10,10);
1193 grid
->SetSelectionMode( wxGrid::wxGridSelectRows
);
1198 void GridFrame::OnVTable(wxCommandEvent
& )
1200 static long s_sizeGrid
= 10000;
1203 // MB: wxGetNumberFromUser doesn't work properly for wxMotif
1206 s
= wxGetTextFromUser( _T("Size of the table to create"),
1210 s
.ToLong( &s_sizeGrid
);
1213 s_sizeGrid
= wxGetNumberFromUser(_T("Size of the table to create"),
1215 _T("wxGridDemo question"),
1220 if ( s_sizeGrid
!= -1 )
1222 BigGridFrame
* win
= new BigGridFrame(s_sizeGrid
);
1227 // ----------------------------------------------------------------------------
1228 // MyGridCellRenderer
1229 // ----------------------------------------------------------------------------
1231 // do something that the default renderer doesn't here just to show that it is
1232 // possible to alter the appearance of the cell beyond what the attributes
1234 void MyGridCellRenderer::Draw(wxGrid
& grid
,
1235 wxGridCellAttr
& attr
,
1241 wxGridCellStringRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
1243 dc
.SetPen(*wxGREEN_PEN
);
1244 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1245 dc
.DrawEllipse(rect
);
1248 // ============================================================================
1249 // BigGridFrame and BigGridTable: Sample of a non-standard table
1250 // ============================================================================
1252 BigGridFrame::BigGridFrame(long sizeGrid
)
1253 : wxFrame(NULL
, wxID_ANY
, _T("Plugin Virtual Table"),
1254 wxDefaultPosition
, wxSize(500, 450))
1256 m_grid
= new wxGrid(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
);
1257 m_table
= new BigGridTable(sizeGrid
);
1259 // VZ: I don't understand why this slows down the display that much,
1260 // must profile it...
1261 //m_table->SetAttrProvider(new MyGridCellAttrProvider);
1263 m_grid
->SetTable(m_table
, true);
1265 #if defined __WXMOTIF__
1266 // MB: the grid isn't getting a sensible default size under wxMotif
1268 GetClientSize( &cw
, &ch
);
1269 m_grid
->SetSize( cw
, ch
);
1273 // ============================================================================
1274 // BugsGridFrame: a "realistic" table
1275 // ============================================================================
1277 // ----------------------------------------------------------------------------
1279 // ----------------------------------------------------------------------------
1302 static const wxString severities
[] =
1311 static struct BugsGridData
1317 wxChar platform
[12];
1319 } gs_dataBugsGrid
[] =
1321 { 18, _T("foo doesn't work"), Sev_Major
, 1, _T("wxMSW"), true },
1322 { 27, _T("bar crashes"), Sev_Critical
, 1, _T("all"), false },
1323 { 45, _T("printing is slow"), Sev_Minor
, 3, _T("wxMSW"), true },
1324 { 68, _T("Rectangle() fails"), Sev_Normal
, 1, _T("wxMSW"), false },
1327 static const wxChar
*headers
[Col_Max
] =
1337 // ----------------------------------------------------------------------------
1339 // ----------------------------------------------------------------------------
1341 wxString
BugsGridTable::GetTypeName(int WXUNUSED(row
), int col
)
1347 return wxGRID_VALUE_NUMBER
;;
1350 // fall thorugh (TODO should be a list)
1353 return wxString::Format(_T("%s:80"), wxGRID_VALUE_STRING
);
1356 return wxString::Format(_T("%s:all,MSW,GTK,other"), wxGRID_VALUE_CHOICE
);
1359 return wxGRID_VALUE_BOOL
;
1362 wxFAIL_MSG(_T("unknown column"));
1364 return wxEmptyString
;
1367 int BugsGridTable::GetNumberRows()
1369 return WXSIZEOF(gs_dataBugsGrid
);
1372 int BugsGridTable::GetNumberCols()
1377 bool BugsGridTable::IsEmptyCell( int WXUNUSED(row
), int WXUNUSED(col
) )
1382 wxString
BugsGridTable::GetValue( int row
, int col
)
1384 const BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1389 return wxString::Format(_T("%d"), gd
.id
);
1392 return wxString::Format(_T("%d"), gd
.prio
);
1395 return gd
.opened
? _T("1") : _T("0");
1398 return severities
[gd
.severity
];
1407 return wxEmptyString
;
1410 void BugsGridTable::SetValue( int row
, int col
, const wxString
& value
)
1412 BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1419 wxFAIL_MSG(_T("unexpected column"));
1425 for ( n
= 0; n
< WXSIZEOF(severities
); n
++ )
1427 if ( severities
[n
] == value
)
1429 gd
.severity
= (Severity
)n
;
1434 if ( n
== WXSIZEOF(severities
) )
1436 wxLogWarning(_T("Invalid severity value '%s'."),
1438 gd
.severity
= Sev_Normal
;
1444 wxStrncpy(gd
.summary
, value
, WXSIZEOF(gd
.summary
));
1448 wxStrncpy(gd
.platform
, value
, WXSIZEOF(gd
.platform
));
1454 BugsGridTable::CanGetValueAs(int WXUNUSED(row
),
1456 const wxString
& typeName
)
1458 if ( typeName
== wxGRID_VALUE_STRING
)
1462 else if ( typeName
== wxGRID_VALUE_BOOL
)
1464 return col
== Col_Opened
;
1466 else if ( typeName
== wxGRID_VALUE_NUMBER
)
1468 return col
== Col_Id
|| col
== Col_Priority
|| col
== Col_Severity
;
1476 bool BugsGridTable::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
1478 return CanGetValueAs(row
, col
, typeName
);
1481 long BugsGridTable::GetValueAsLong( int row
, int col
)
1483 const BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1497 wxFAIL_MSG(_T("unexpected column"));
1502 bool BugsGridTable::GetValueAsBool( int row
, int col
)
1504 if ( col
== Col_Opened
)
1506 return gs_dataBugsGrid
[row
].opened
;
1510 wxFAIL_MSG(_T("unexpected column"));
1516 void BugsGridTable::SetValueAsLong( int row
, int col
, long value
)
1518 BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1527 wxFAIL_MSG(_T("unexpected column"));
1531 void BugsGridTable::SetValueAsBool( int row
, int col
, bool value
)
1533 if ( col
== Col_Opened
)
1535 gs_dataBugsGrid
[row
].opened
= value
;
1539 wxFAIL_MSG(_T("unexpected column"));
1543 wxString
BugsGridTable::GetColLabelValue( int col
)
1545 return headers
[col
];
1548 // ----------------------------------------------------------------------------
1550 // ----------------------------------------------------------------------------
1552 BugsGridFrame::BugsGridFrame()
1553 : wxFrame(NULL
, wxID_ANY
, _T("Bugs table"))
1555 wxGrid
*grid
= new wxGrid(this, wxID_ANY
, wxDefaultPosition
);
1556 wxGridTableBase
*table
= new BugsGridTable();
1557 table
->SetAttrProvider(new MyGridCellAttrProvider
);
1558 grid
->SetTable(table
, true);
1560 wxGridCellAttr
*attrRO
= new wxGridCellAttr
,
1561 *attrRangeEditor
= new wxGridCellAttr
,
1562 *attrCombo
= new wxGridCellAttr
;
1564 attrRO
->SetReadOnly();
1565 attrRangeEditor
->SetEditor(new wxGridCellNumberEditor(1, 5));
1566 attrCombo
->SetEditor(new wxGridCellChoiceEditor(WXSIZEOF(severities
),
1569 grid
->SetColAttr(Col_Id
, attrRO
);
1570 grid
->SetColAttr(Col_Priority
, attrRangeEditor
);
1571 grid
->SetColAttr(Col_Severity
, attrCombo
);
1574 SetClientSize(grid
->GetSize());