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
)
95 EVT_MENU( ID_SELROWSORCOLS
, GridFrame::SelectRowsOrCols
)
97 EVT_MENU( ID_SET_CELL_FG_COLOUR
, GridFrame::SetCellFgColour
)
98 EVT_MENU( ID_SET_CELL_BG_COLOUR
, GridFrame::SetCellBgColour
)
100 EVT_MENU( wxID_ABOUT
, GridFrame::About
)
101 EVT_MENU( wxID_EXIT
, GridFrame::OnQuit
)
102 EVT_MENU( ID_VTABLE
, GridFrame::OnVTable
)
103 EVT_MENU( ID_BUGS_TABLE
, GridFrame::OnBugsTable
)
104 EVT_MENU( ID_SMALL_GRID
, GridFrame::OnSmallGrid
)
105 EVT_MENU( ID_TABULAR_GRID
, GridFrame::OnTabularGrid
)
107 EVT_MENU( ID_DESELECT_CELL
, GridFrame::DeselectCell
)
108 EVT_MENU( ID_DESELECT_COL
, GridFrame::DeselectCol
)
109 EVT_MENU( ID_DESELECT_ROW
, GridFrame::DeselectRow
)
110 EVT_MENU( ID_DESELECT_ALL
, GridFrame::DeselectAll
)
111 EVT_MENU( ID_SELECT_CELL
, GridFrame::SelectCell
)
112 EVT_MENU( ID_SELECT_COL
, GridFrame::SelectCol
)
113 EVT_MENU( ID_SELECT_ROW
, GridFrame::SelectRow
)
114 EVT_MENU( ID_SELECT_ALL
, GridFrame::SelectAll
)
115 EVT_MENU( ID_SELECT_UNSELECT
, GridFrame::OnAddToSelectToggle
)
116 EVT_MENU( ID_SHOW_SELECTION
, GridFrame::OnShowSelection
)
118 EVT_MENU( ID_SIZE_ROW
, GridFrame::AutoSizeRow
)
119 EVT_MENU( ID_SIZE_COL
, GridFrame::AutoSizeCol
)
120 EVT_MENU( ID_SIZE_ROW_LABEL
, GridFrame::AutoSizeRowLabel
)
121 EVT_MENU( ID_SIZE_COL_LABEL
, GridFrame::AutoSizeColLabel
)
122 EVT_MENU( ID_SIZE_LABELS_COL
, GridFrame::AutoSizeLabelsCol
)
123 EVT_MENU( ID_SIZE_LABELS_ROW
, GridFrame::AutoSizeLabelsRow
)
124 EVT_MENU( ID_SIZE_GRID
, GridFrame::AutoSizeTable
)
126 EVT_MENU( ID_SET_HIGHLIGHT_WIDTH
, GridFrame::OnSetHighlightWidth
)
127 EVT_MENU( ID_SET_RO_HIGHLIGHT_WIDTH
, GridFrame::OnSetROHighlightWidth
)
129 EVT_GRID_LABEL_LEFT_CLICK( GridFrame::OnLabelLeftClick
)
130 EVT_GRID_CELL_LEFT_CLICK( GridFrame::OnCellLeftClick
)
131 EVT_GRID_ROW_SIZE( GridFrame::OnRowSize
)
132 EVT_GRID_COL_SIZE( GridFrame::OnColSize
)
133 EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell
)
134 EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected
)
135 EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged
)
136 EVT_GRID_CELL_BEGIN_DRAG( GridFrame::OnCellBeginDrag
)
138 EVT_GRID_EDITOR_SHOWN( GridFrame::OnEditorShown
)
139 EVT_GRID_EDITOR_HIDDEN( GridFrame::OnEditorHidden
)
143 GridFrame::GridFrame()
144 : wxFrame( (wxFrame
*)NULL
, wxID_ANY
, _T("wxWidgets grid class demo"),
148 wxMenu
*fileMenu
= new wxMenu
;
149 fileMenu
->Append( ID_VTABLE
, _T("&Virtual table test\tCtrl-V"));
150 fileMenu
->Append( ID_BUGS_TABLE
, _T("&Bugs table test\tCtrl-B"));
151 fileMenu
->Append( ID_SMALL_GRID
, _T("&Small Grid test\tCtrl-S"));
152 fileMenu
->Append( ID_TABULAR_GRID
, _T("&Tabular Grid test\tCtrl-T"));
153 fileMenu
->AppendSeparator();
154 fileMenu
->Append( wxID_EXIT
, _T("E&xit\tAlt-X") );
156 wxMenu
*viewMenu
= new wxMenu
;
157 viewMenu
->AppendCheckItem(ID_TOGGLEROWLABELS
, "&Row labels");
158 viewMenu
->AppendCheckItem(ID_TOGGLECOLLABELS
, "&Col labels");
159 viewMenu
->AppendCheckItem(ID_TOGGLEEDIT
,"&Editable");
160 viewMenu
->AppendCheckItem(ID_TOGGLEROWSIZING
, "Ro&w drag-resize");
161 viewMenu
->AppendCheckItem(ID_TOGGLECOLSIZING
, "C&ol drag-resize");
162 viewMenu
->AppendCheckItem(ID_TOGGLECOLMOVING
, "Col drag-&move");
163 viewMenu
->AppendCheckItem(ID_TOGGLEGRIDSIZING
, "&Grid drag-resize");
164 viewMenu
->AppendCheckItem(ID_TOGGLEGRIDDRAGCELL
, "&Grid drag-cell");
165 viewMenu
->AppendCheckItem(ID_TOGGLENATIVEHEADER
, "&Native column headers");
166 viewMenu
->AppendCheckItem(ID_TOGGLEGRIDLINES
, "&Grid Lines");
167 viewMenu
->AppendCheckItem(ID_SET_HIGHLIGHT_WIDTH
, "&Set Cell Highlight Width...");
168 viewMenu
->AppendCheckItem(ID_SET_RO_HIGHLIGHT_WIDTH
, "&Set Cell RO Highlight Width...");
169 viewMenu
->AppendCheckItem(ID_AUTOSIZECOLS
, "&Auto-size cols");
170 viewMenu
->AppendCheckItem(ID_CELLOVERFLOW
, "&Overflow cells");
171 viewMenu
->AppendCheckItem(ID_RESIZECELL
, "&Resize cell (7,1)");
173 wxMenu
*rowLabelMenu
= new wxMenu
;
175 viewMenu
->Append( ID_ROWLABELALIGN
, _T("R&ow label alignment"),
177 _T("Change alignment of row labels") );
179 rowLabelMenu
->Append( ID_ROWLABELHORIZALIGN
, _T("&Horizontal") );
180 rowLabelMenu
->Append( ID_ROWLABELVERTALIGN
, _T("&Vertical") );
182 wxMenu
*colLabelMenu
= new wxMenu
;
184 viewMenu
->Append( ID_COLLABELALIGN
, _T("Col l&abel alignment"),
186 _T("Change alignment of col labels") );
188 colLabelMenu
->Append( ID_COLLABELHORIZALIGN
, _T("&Horizontal") );
189 colLabelMenu
->Append( ID_COLLABELVERTALIGN
, _T("&Vertical") );
191 wxMenu
*colMenu
= new wxMenu
;
192 colMenu
->Append( ID_SETLABELCOLOUR
, _T("Set &label colour...") );
193 colMenu
->Append( ID_SETLABELTEXTCOLOUR
, _T("Set label &text colour...") );
194 colMenu
->Append( ID_SETLABEL_FONT
, _T("Set label fo&nt...") );
195 colMenu
->Append( ID_GRIDLINECOLOUR
, _T("&Grid line colour...") );
196 colMenu
->Append( ID_SET_CELL_FG_COLOUR
, _T("Set cell &foreground colour...") );
197 colMenu
->Append( ID_SET_CELL_BG_COLOUR
, _T("Set cell &background colour...") );
199 wxMenu
*editMenu
= new wxMenu
;
200 editMenu
->Append( ID_INSERTROW
, _T("Insert &row") );
201 editMenu
->Append( ID_INSERTCOL
, _T("Insert &column") );
202 editMenu
->Append( ID_DELETEROW
, _T("Delete selected ro&ws") );
203 editMenu
->Append( ID_DELETECOL
, _T("Delete selected co&ls") );
204 editMenu
->Append( ID_CLEARGRID
, _T("Cl&ear grid cell contents") );
206 wxMenu
*selectMenu
= new wxMenu
;
207 selectMenu
->Append( ID_SELECT_UNSELECT
, _T("Add new cells to the selection"),
208 _T("When off, old selection is deselected before ")
209 _T("selecting the new cells"), wxITEM_CHECK
);
210 selectMenu
->Append( ID_SHOW_SELECTION
,
211 _T("&Show current selection\tCtrl-Alt-S"));
212 selectMenu
->AppendSeparator();
213 selectMenu
->Append( ID_SELECT_ALL
, _T("Select all"));
214 selectMenu
->Append( ID_SELECT_ROW
, _T("Select row 2"));
215 selectMenu
->Append( ID_SELECT_COL
, _T("Select col 2"));
216 selectMenu
->Append( ID_SELECT_CELL
, _T("Select cell (3, 1)"));
217 selectMenu
->AppendSeparator();
218 selectMenu
->Append( ID_DESELECT_ALL
, _T("Deselect all"));
219 selectMenu
->Append( ID_DESELECT_ROW
, _T("Deselect row 2"));
220 selectMenu
->Append( ID_DESELECT_COL
, _T("Deselect col 2"));
221 selectMenu
->Append( ID_DESELECT_CELL
, _T("Deselect cell (3, 1)"));
222 wxMenu
*selectionMenu
= new wxMenu
;
223 selectMenu
->Append( ID_CHANGESEL
, _T("Change &selection mode"),
225 _T("Change selection mode") );
227 selectionMenu
->Append( ID_SELCELLS
, _T("Select &cells") );
228 selectionMenu
->Append( ID_SELROWS
, _T("Select &rows") );
229 selectionMenu
->Append( ID_SELCOLS
, _T("Select col&umns") );
230 selectionMenu
->Append( ID_SELROWSORCOLS
, _T("Select rows &or columns") );
232 wxMenu
*autosizeMenu
= new wxMenu
;
233 autosizeMenu
->Append( ID_SIZE_ROW
, _T("Selected &row data") );
234 autosizeMenu
->Append( ID_SIZE_COL
, _T("Selected &column data") );
235 autosizeMenu
->Append( ID_SIZE_ROW_LABEL
, _T("Selected row la&bel") );
236 autosizeMenu
->Append( ID_SIZE_COL_LABEL
, _T("Selected column &label") );
237 autosizeMenu
->Append( ID_SIZE_LABELS_COL
, _T("Column la&bels") );
238 autosizeMenu
->Append( ID_SIZE_LABELS_ROW
, _T("Row label&s") );
239 autosizeMenu
->Append( ID_SIZE_GRID
, _T("Entire &grid") );
241 wxMenu
*helpMenu
= new wxMenu
;
242 helpMenu
->Append( wxID_ABOUT
, _T("&About wxGrid demo") );
244 wxMenuBar
*menuBar
= new wxMenuBar
;
245 menuBar
->Append( fileMenu
, _T("&File") );
246 menuBar
->Append( viewMenu
, _T("&Grid") );
247 menuBar
->Append( colMenu
, _T("&Colours") );
248 menuBar
->Append( editMenu
, _T("&Edit") );
249 menuBar
->Append( selectMenu
, _T("&Select") );
250 menuBar
->Append( autosizeMenu
, _T("&Autosize") );
251 menuBar
->Append( helpMenu
, _T("&Help") );
253 SetMenuBar( menuBar
);
257 grid
= new wxGrid( this,
260 wxSize( 400, 300 ) );
263 int gridW
= 600, gridH
= 300;
264 int logW
= gridW
, logH
= 100;
266 logWin
= new wxTextCtrl( this,
269 wxPoint( 0, gridH
+ 20 ),
270 wxSize( logW
, logH
),
273 logger
= new wxLogTextCtrl( logWin
);
274 m_logOld
= wxLog::SetActiveTarget( logger
);
275 wxLog::DisableTimestamp();
278 // this will create a grid and, by default, an associated grid
280 grid
->CreateGrid( 0, 0 );
281 grid
->AppendRows(100);
282 grid
->AppendCols(100);
284 int ir
= grid
->GetNumberRows();
285 grid
->DeleteRows(0, ir
);
286 grid
->AppendRows(ir
);
288 grid
->SetRowSize( 0, 60 );
289 grid
->SetCellValue( 0, 0, _T("Ctrl+Home\nwill go to\nthis cell") );
291 grid
->SetCellValue( 0, 1, _T("A long piece of text to demonstrate wrapping.") );
292 grid
->SetCellRenderer(0 , 1, new wxGridCellAutoWrapStringRenderer
);
293 grid
->SetCellEditor( 0, 1 , new wxGridCellAutoWrapStringEditor
);
295 grid
->SetCellValue( 0, 2, _T("Blah") );
296 grid
->SetCellValue( 0, 3, _T("Read only") );
297 grid
->SetReadOnly( 0, 3 );
299 grid
->SetCellValue( 0, 4, _T("Can veto edit this cell") );
301 grid
->SetCellValue( 0, 5, _T("Press\nCtrl+arrow\nto skip over\ncells") );
303 grid
->SetRowSize( 99, 60 );
304 grid
->SetCellValue( 99, 99, _T("Ctrl+End\nwill go to\nthis cell") );
305 grid
->SetCellValue( 1, 0, _T("This default cell will overflow into neighboring cells, but not if you turn overflow off."));
307 grid
->SetCellTextColour(1, 2, *wxRED
);
308 grid
->SetCellBackgroundColour(1, 2, *wxGREEN
);
310 grid
->SetCellValue( 1, 4, _T("I'm in the middle"));
312 grid
->SetCellValue(2, 2, _T("red"));
314 grid
->SetCellTextColour(2, 2, *wxRED
);
315 grid
->SetCellValue(3, 3, _T("green on grey"));
316 grid
->SetCellTextColour(3, 3, *wxGREEN
);
317 grid
->SetCellBackgroundColour(3, 3, *wxLIGHT_GREY
);
319 grid
->SetCellValue(4, 4, _T("a weird looking cell"));
320 grid
->SetCellAlignment(4, 4, wxALIGN_CENTRE
, wxALIGN_CENTRE
);
321 grid
->SetCellRenderer(4, 4, new MyGridCellRenderer
);
323 grid
->SetCellRenderer(3, 0, new wxGridCellBoolRenderer
);
324 grid
->SetCellEditor(3, 0, new wxGridCellBoolEditor
);
326 wxGridCellAttr
*attr
;
327 attr
= new wxGridCellAttr
;
328 attr
->SetTextColour(*wxBLUE
);
329 grid
->SetColAttr(5, attr
);
330 attr
= new wxGridCellAttr
;
331 attr
->SetBackgroundColour(*wxRED
);
332 grid
->SetRowAttr(5, attr
);
334 grid
->SetCellValue(2, 4, _T("a wider column"));
335 grid
->SetColSize(4, 120);
336 grid
->SetColMinimalWidth(4, 120);
338 grid
->SetCellTextColour(5, 8, *wxGREEN
);
339 grid
->SetCellValue(5, 8, _T("Bg from row attr\nText col from cell attr"));
340 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"));
342 grid
->SetColFormatFloat(6);
343 grid
->SetCellValue(0, 6, wxString::Format(wxT("%g"), 3.1415));
344 grid
->SetCellValue(1, 6, wxString::Format(wxT("%g"), 1415.0));
345 grid
->SetCellValue(2, 6, wxString::Format(wxT("%g"), 12345.67890));
347 grid
->SetColFormatFloat(7, 6, 2);
348 grid
->SetCellValue(0, 7, wxString::Format(wxT("%g"), 3.1415));
349 grid
->SetCellValue(1, 7, wxString::Format(wxT("%g"), 1415.0));
350 grid
->SetCellValue(2, 7, wxString::Format(wxT("%g"), 12345.67890));
352 grid
->SetColFormatNumber(8);
353 grid
->SetCellValue(0, 8, "17");
354 grid
->SetCellValue(1, 8, "0");
355 grid
->SetCellValue(2, 8, "-666");
357 const wxString choices
[] =
359 _T("Please select a choice"),
360 _T("This takes two cells"),
361 _T("Another choice"),
363 grid
->SetCellEditor(4, 0, new wxGridCellChoiceEditor(WXSIZEOF(choices
), choices
));
364 grid
->SetCellSize(4, 0, 1, 2);
365 grid
->SetCellValue(4, 0, choices
[0]);
366 grid
->SetCellOverflow(4, 0, false);
368 grid
->SetCellSize(7, 1, 3, 4);
369 grid
->SetCellAlignment(7, 1, wxALIGN_CENTRE
, wxALIGN_CENTRE
);
370 grid
->SetCellValue(7, 1, _T("Big box!"));
372 // this does exactly nothing except testing that SetAttr() handles NULL
373 // attributes and does reference counting correctly
374 grid
->SetAttr(11, 11, NULL
);
375 grid
->SetAttr(11, 11, new wxGridCellAttr
);
376 grid
->SetAttr(11, 11, NULL
);
378 wxBoxSizer
*topSizer
= new wxBoxSizer( wxVERTICAL
);
384 topSizer
->Add( logWin
,
389 SetSizerAndFit( topSizer
);
396 GridFrame::~GridFrame()
399 delete wxLog::SetActiveTarget(m_logOld
);
404 void GridFrame::SetDefaults()
406 GetMenuBar()->Check( ID_TOGGLEROWLABELS
, true );
407 GetMenuBar()->Check( ID_TOGGLECOLLABELS
, true );
408 GetMenuBar()->Check( ID_TOGGLEEDIT
, true );
409 GetMenuBar()->Check( ID_TOGGLEROWSIZING
, true );
410 GetMenuBar()->Check( ID_TOGGLECOLSIZING
, true );
411 GetMenuBar()->Check( ID_TOGGLECOLMOVING
, false );
412 GetMenuBar()->Check( ID_TOGGLEGRIDSIZING
, true );
413 GetMenuBar()->Check( ID_TOGGLEGRIDDRAGCELL
, false );
414 GetMenuBar()->Check( ID_TOGGLENATIVEHEADER
, false );
415 GetMenuBar()->Check( ID_TOGGLEGRIDLINES
, true );
416 GetMenuBar()->Check( ID_CELLOVERFLOW
, true );
420 void GridFrame::ToggleRowLabels( wxCommandEvent
& WXUNUSED(ev
) )
422 if ( GetMenuBar()->IsChecked( ID_TOGGLEROWLABELS
) )
424 grid
->SetRowLabelSize( grid
->GetDefaultRowLabelSize() );
428 grid
->SetRowLabelSize( 0 );
433 void GridFrame::ToggleColLabels( wxCommandEvent
& WXUNUSED(ev
) )
435 if ( GetMenuBar()->IsChecked( ID_TOGGLECOLLABELS
) )
437 grid
->SetColLabelSize( grid
->GetDefaultColLabelSize() );
441 grid
->SetColLabelSize( 0 );
446 void GridFrame::ToggleEditing( wxCommandEvent
& WXUNUSED(ev
) )
449 GetMenuBar()->IsChecked( ID_TOGGLEEDIT
) );
453 void GridFrame::ToggleRowSizing( wxCommandEvent
& WXUNUSED(ev
) )
455 grid
->EnableDragRowSize(
456 GetMenuBar()->IsChecked( ID_TOGGLEROWSIZING
) );
460 void GridFrame::ToggleColSizing( wxCommandEvent
& WXUNUSED(ev
) )
462 grid
->EnableDragColSize(
463 GetMenuBar()->IsChecked( ID_TOGGLECOLSIZING
) );
466 void GridFrame::ToggleColMoving( wxCommandEvent
& WXUNUSED(ev
) )
468 grid
->EnableDragColMove(
469 GetMenuBar()->IsChecked( ID_TOGGLECOLMOVING
) );
472 void GridFrame::ToggleGridSizing( wxCommandEvent
& WXUNUSED(ev
) )
474 grid
->EnableDragGridSize(
475 GetMenuBar()->IsChecked( ID_TOGGLEGRIDSIZING
) );
478 void GridFrame::ToggleGridDragCell( wxCommandEvent
& WXUNUSED(ev
) )
480 grid
->EnableDragCell(
481 GetMenuBar()->IsChecked( ID_TOGGLEGRIDDRAGCELL
) );
484 void GridFrame::ToggleNativeHeader( wxCommandEvent
& WXUNUSED(ev
) )
486 grid
->SetUseNativeColLabels(
487 GetMenuBar()->IsChecked( ID_TOGGLENATIVEHEADER
) );
490 void GridFrame::ToggleGridLines( wxCommandEvent
& WXUNUSED(ev
) )
492 grid
->EnableGridLines(
493 GetMenuBar()->IsChecked( ID_TOGGLEGRIDLINES
) );
496 void GridFrame::OnSetHighlightWidth( wxCommandEvent
& WXUNUSED(ev
) )
498 wxString choices
[] = { _T("0"), _T("1"), _T("2"), _T("3"), _T("4"), _T("5"), _T("6"), _T("7"), _T("8"), _T("9"), _T("10")};
500 wxSingleChoiceDialog
dlg(this, _T("Choose the thickness of the highlight pen:"),
501 _T("Pen Width"), 11, choices
);
503 int current
= grid
->GetCellHighlightPenWidth();
504 dlg
.SetSelection(current
);
505 if (dlg
.ShowModal() == wxID_OK
) {
506 grid
->SetCellHighlightPenWidth(dlg
.GetSelection());
510 void GridFrame::OnSetROHighlightWidth( wxCommandEvent
& WXUNUSED(ev
) )
512 wxString choices
[] = { _T("0"), _T("1"), _T("2"), _T("3"), _T("4"), _T("5"), _T("6"), _T("7"), _T("8"), _T("9"), _T("10")};
514 wxSingleChoiceDialog
dlg(this, _T("Choose the thickness of the highlight pen:"),
515 _T("Pen Width"), 11, choices
);
517 int current
= grid
->GetCellHighlightROPenWidth();
518 dlg
.SetSelection(current
);
519 if (dlg
.ShowModal() == wxID_OK
) {
520 grid
->SetCellHighlightROPenWidth(dlg
.GetSelection());
526 void GridFrame::AutoSizeCols( wxCommandEvent
& WXUNUSED(ev
) )
528 grid
->AutoSizeColumns();
532 void GridFrame::CellOverflow( wxCommandEvent
& ev
)
534 grid
->SetDefaultCellOverflow(ev
.IsChecked());
538 void GridFrame::ResizeCell( wxCommandEvent
& ev
)
541 grid
->SetCellSize( 7, 1, 5, 5 );
543 grid
->SetCellSize( 7, 1, 1, 5 );
547 void GridFrame::SetLabelColour( wxCommandEvent
& WXUNUSED(ev
) )
549 wxColourDialog
dlg( NULL
);
550 if ( dlg
.ShowModal() == wxID_OK
)
552 wxColourData retData
;
553 retData
= dlg
.GetColourData();
554 wxColour colour
= retData
.GetColour();
556 grid
->SetLabelBackgroundColour( colour
);
561 void GridFrame::SetLabelTextColour( wxCommandEvent
& WXUNUSED(ev
) )
563 wxColourDialog
dlg( NULL
);
564 if ( dlg
.ShowModal() == wxID_OK
)
566 wxColourData retData
;
567 retData
= dlg
.GetColourData();
568 wxColour colour
= retData
.GetColour();
570 grid
->SetLabelTextColour( colour
);
574 void GridFrame::SetLabelFont( wxCommandEvent
& WXUNUSED(ev
) )
576 wxFont font
= wxGetFontFromUser(this);
579 grid
->SetLabelFont(font
);
583 void GridFrame::SetRowLabelHorizAlignment( wxCommandEvent
& WXUNUSED(ev
) )
586 grid
->GetRowLabelAlignment( &horiz
, &vert
);
591 horiz
= wxALIGN_CENTRE
;
595 horiz
= wxALIGN_RIGHT
;
599 horiz
= wxALIGN_LEFT
;
603 grid
->SetRowLabelAlignment( horiz
, vert
);
606 void GridFrame::SetRowLabelVertAlignment( wxCommandEvent
& WXUNUSED(ev
) )
609 grid
->GetRowLabelAlignment( &horiz
, &vert
);
614 vert
= wxALIGN_CENTRE
;
618 vert
= wxALIGN_BOTTOM
;
626 grid
->SetRowLabelAlignment( horiz
, vert
);
630 void GridFrame::SetColLabelHorizAlignment( wxCommandEvent
& WXUNUSED(ev
) )
633 grid
->GetColLabelAlignment( &horiz
, &vert
);
638 horiz
= wxALIGN_CENTRE
;
642 horiz
= wxALIGN_RIGHT
;
646 horiz
= wxALIGN_LEFT
;
650 grid
->SetColLabelAlignment( horiz
, vert
);
654 void GridFrame::SetColLabelVertAlignment( wxCommandEvent
& WXUNUSED(ev
) )
657 grid
->GetColLabelAlignment( &horiz
, &vert
);
662 vert
= wxALIGN_CENTRE
;
666 vert
= wxALIGN_BOTTOM
;
674 grid
->SetColLabelAlignment( horiz
, vert
);
678 void GridFrame::SetGridLineColour( wxCommandEvent
& WXUNUSED(ev
) )
680 wxColourDialog
dlg( NULL
);
681 if ( dlg
.ShowModal() == wxID_OK
)
683 wxColourData retData
;
684 retData
= dlg
.GetColourData();
685 wxColour colour
= retData
.GetColour();
687 grid
->SetGridLineColour( colour
);
692 void GridFrame::InsertRow( wxCommandEvent
& WXUNUSED(ev
) )
694 grid
->InsertRows( grid
->GetGridCursorRow(), 1 );
698 void GridFrame::InsertCol( wxCommandEvent
& WXUNUSED(ev
) )
700 grid
->InsertCols( grid
->GetGridCursorCol(), 1 );
704 void GridFrame::DeleteSelectedRows( wxCommandEvent
& WXUNUSED(ev
) )
706 if ( grid
->IsSelection() )
708 wxGridUpdateLocker
locker(grid
);
709 for ( int n
= 0; n
< grid
->GetNumberRows(); )
711 if ( grid
->IsInSelection( n
, 0 ) )
712 grid
->DeleteRows( n
, 1 );
720 void GridFrame::AutoSizeRow(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
->AutoSizeRow( sels
[n
], false );
730 void GridFrame::AutoSizeCol(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
->AutoSizeColumn( sels
[n
], false );
740 void GridFrame::AutoSizeRowLabel(wxCommandEvent
& WXUNUSED(event
))
742 wxGridUpdateLocker
locker(grid
);
743 const wxArrayInt sels
= grid
->GetSelectedRows();
744 for ( size_t n
= 0, count
= sels
.size(); n
< count
; n
++ )
746 grid
->AutoSizeRowLabelSize( sels
[n
] );
750 void GridFrame::AutoSizeColLabel(wxCommandEvent
& WXUNUSED(event
))
752 wxGridUpdateLocker
locker(grid
);
753 const wxArrayInt sels
= grid
->GetSelectedCols();
754 for ( size_t n
= 0, count
= sels
.size(); n
< count
; n
++ )
756 grid
->AutoSizeColLabelSize( sels
[n
] );
760 void GridFrame::AutoSizeLabelsCol(wxCommandEvent
& WXUNUSED(event
))
762 grid
->SetColLabelSize( wxGRID_AUTOSIZE
);
765 void GridFrame::AutoSizeLabelsRow(wxCommandEvent
& WXUNUSED(event
))
767 grid
->SetRowLabelSize( wxGRID_AUTOSIZE
);
770 void GridFrame::AutoSizeTable(wxCommandEvent
& WXUNUSED(event
))
776 void GridFrame::DeleteSelectedCols( wxCommandEvent
& WXUNUSED(ev
) )
778 if ( grid
->IsSelection() )
780 wxGridUpdateLocker
locker(grid
);
781 for ( int n
= 0; n
< grid
->GetNumberCols(); )
783 if ( grid
->IsInSelection( 0 , n
) )
784 grid
->DeleteCols( n
, 1 );
792 void GridFrame::ClearGrid( wxCommandEvent
& WXUNUSED(ev
) )
797 void GridFrame::SelectCells( wxCommandEvent
& WXUNUSED(ev
) )
799 grid
->SetSelectionMode( wxGrid::wxGridSelectCells
);
802 void GridFrame::SelectRows( wxCommandEvent
& WXUNUSED(ev
) )
804 grid
->SetSelectionMode( wxGrid::wxGridSelectRows
);
807 void GridFrame::SelectCols( wxCommandEvent
& WXUNUSED(ev
) )
809 grid
->SetSelectionMode( wxGrid::wxGridSelectColumns
);
812 void GridFrame::SelectRowsOrCols( wxCommandEvent
& WXUNUSED(ev
) )
814 grid
->SetSelectionMode( wxGrid::wxGridSelectRowsOrColumns
);
817 void GridFrame::SetCellFgColour( wxCommandEvent
& WXUNUSED(ev
) )
819 wxColour col
= wxGetColourFromUser(this);
822 grid
->SetDefaultCellTextColour(col
);
827 void GridFrame::SetCellBgColour( wxCommandEvent
& WXUNUSED(ev
) )
829 wxColour col
= wxGetColourFromUser(this);
832 // Check the new Refresh function by passing it a rectangle
833 // which exactly fits the grid.
835 wxRect
r(pt
, grid
->GetSize());
836 grid
->SetDefaultCellBackgroundColour(col
);
837 grid
->Refresh(true, &r
);
841 void GridFrame::DeselectCell(wxCommandEvent
& WXUNUSED(event
))
843 grid
->DeselectCell(3, 1);
846 void GridFrame::DeselectCol(wxCommandEvent
& WXUNUSED(event
))
848 grid
->DeselectCol(2);
851 void GridFrame::DeselectRow(wxCommandEvent
& WXUNUSED(event
))
853 grid
->DeselectRow(2);
856 void GridFrame::DeselectAll(wxCommandEvent
& WXUNUSED(event
))
858 grid
->ClearSelection();
861 void GridFrame::SelectCell(wxCommandEvent
& WXUNUSED(event
))
863 grid
->SelectBlock(3, 1, 3, 1, m_addToSel
);
866 void GridFrame::SelectCol(wxCommandEvent
& WXUNUSED(event
))
868 grid
->SelectCol(2, m_addToSel
);
871 void GridFrame::SelectRow(wxCommandEvent
& WXUNUSED(event
))
873 grid
->SelectRow(2, m_addToSel
);
876 void GridFrame::SelectAll(wxCommandEvent
& WXUNUSED(event
))
881 void GridFrame::OnAddToSelectToggle(wxCommandEvent
& event
)
883 m_addToSel
= event
.IsChecked();
886 void GridFrame::OnLabelLeftClick( wxGridEvent
& ev
)
889 if ( ev
.GetRow() != -1 )
891 logBuf
<< _T("Left click on row label ") << ev
.GetRow();
893 else if ( ev
.GetCol() != -1 )
895 logBuf
<< _T("Left click on col label ") << ev
.GetCol();
899 logBuf
<< _T("Left click on corner label");
902 if ( ev
.ShiftDown() )
903 logBuf
<< _T(" (shift down)");
904 if ( ev
.ControlDown() )
905 logBuf
<< _T(" (control down)");
906 wxLogMessage( wxT("%s"), logBuf
.c_str() );
908 // you must call event skip if you want default grid processing
914 void GridFrame::OnCellLeftClick( wxGridEvent
& ev
)
916 wxLogMessage(_T("Left click at row %d, col %d"), ev
.GetRow(), ev
.GetCol());
918 // you must call event skip if you want default grid processing
919 // (cell highlighting etc.)
925 void GridFrame::OnRowSize( wxGridSizeEvent
& ev
)
927 wxLogMessage(_T("Resized row %d"), ev
.GetRowOrCol());
933 void GridFrame::OnColSize( wxGridSizeEvent
& ev
)
935 wxLogMessage(_T("Resized col %d"), ev
.GetRowOrCol());
941 void GridFrame::OnShowSelection(wxCommandEvent
& WXUNUSED(event
))
943 // max number of elements to dump -- otherwise it can take too much time
944 static const size_t countMax
= 100;
948 switch ( grid
->GetSelectionMode() )
950 case wxGrid::wxGridSelectCells
:
952 const wxGridCellCoordsArray
cells(grid
->GetSelectedCells());
953 size_t count
= cells
.size();
954 wxLogMessage(_T("%lu cells selected:"), (unsigned long)count
);
955 if ( count
> countMax
)
957 wxLogMessage(_T("[too many selected cells, ")
958 _T("showing only the first %lu]"),
959 (unsigned long)countMax
);
963 for ( size_t n
= 0; n
< count
; n
++ )
965 const wxGridCellCoords
& c
= cells
[n
];
966 wxLogMessage(_T(" selected cell %lu: (%d, %d)"),
967 (unsigned long)n
, c
.GetCol(), c
.GetRow());
972 case wxGrid::wxGridSelectRows
:
976 case wxGrid::wxGridSelectColumns
:
978 const wxChar
*plural
, *single
;
986 plural
= _T("columns");
987 single
= _T("column");
990 const wxArrayInt
sels((const wxArrayInt
)(rows
? grid
->GetSelectedRows()
991 : grid
->GetSelectedCols()));
992 size_t count
= sels
.size();
993 wxLogMessage(_T("%lu %s selected:"),
994 (unsigned long)count
, plural
);
995 if ( count
> countMax
)
997 wxLogMessage(_T("[too many selected %s, ")
998 _T("showing only the first %lu]"),
999 plural
, (unsigned long)countMax
);
1003 for ( size_t n
= 0; n
< count
; n
++ )
1005 wxLogMessage(_T(" selected %s %lu: %d"),
1006 single
, (unsigned long)n
, sels
[n
]);
1012 wxFAIL_MSG( _T("unknown wxGrid selection mode") );
1017 void GridFrame::OnSelectCell( wxGridEvent
& ev
)
1020 if ( ev
.Selecting() )
1021 logBuf
<< _T("Selected ");
1023 logBuf
<< _T("Deselected ");
1024 logBuf
<< _T("cell at row ") << ev
.GetRow()
1025 << _T(" col ") << ev
.GetCol()
1026 << _T(" ( ControlDown: ")<< (ev
.ControlDown() ? 'T':'F')
1027 << _T(", ShiftDown: ")<< (ev
.ShiftDown() ? 'T':'F')
1028 << _T(", AltDown: ")<< (ev
.AltDown() ? 'T':'F')
1029 << _T(", MetaDown: ")<< (ev
.MetaDown() ? 'T':'F') << _T(" )");
1031 //Indicate whether this column was moved
1032 if ( ((wxGrid
*)ev
.GetEventObject())->GetColPos( ev
.GetCol() ) != ev
.GetCol() )
1033 logBuf
<< _T(" *** Column moved, current position: ") << ((wxGrid
*)ev
.GetEventObject())->GetColPos( ev
.GetCol() );
1035 wxLogMessage( wxT("%s"), logBuf
.c_str() );
1037 // you must call Skip() if you want the default processing
1038 // to occur in wxGrid
1042 void GridFrame::OnRangeSelected( wxGridRangeSelectEvent
& ev
)
1045 if ( ev
.Selecting() )
1046 logBuf
<< _T("Selected ");
1048 logBuf
<< _T("Deselected ");
1049 logBuf
<< _T("cells from row ") << ev
.GetTopRow()
1050 << _T(" col ") << ev
.GetLeftCol()
1051 << _T(" to row ") << ev
.GetBottomRow()
1052 << _T(" col ") << ev
.GetRightCol()
1053 << _T(" ( ControlDown: ")<< (ev
.ControlDown() ? 'T':'F')
1054 << _T(", ShiftDown: ")<< (ev
.ShiftDown() ? 'T':'F')
1055 << _T(", AltDown: ")<< (ev
.AltDown() ? 'T':'F')
1056 << _T(", MetaDown: ")<< (ev
.MetaDown() ? 'T':'F') << _T(" )");
1057 wxLogMessage( wxT("%s"), logBuf
.c_str() );
1062 void GridFrame::OnCellValueChanged( wxGridEvent
& ev
)
1064 int row
= ev
.GetRow(),
1067 wxLogMessage(_T("Value changed for cell at row %d, col %d: now \"%s\""),
1068 row
, col
, grid
->GetCellValue(row
, col
).c_str());
1073 void GridFrame::OnCellBeginDrag( wxGridEvent
& ev
)
1075 wxLogMessage(_T("Got request to drag cell at row %d, col %d"),
1076 ev
.GetRow(), ev
.GetCol());
1081 void GridFrame::OnEditorShown( wxGridEvent
& ev
)
1084 if ( (ev
.GetCol() == 4) &&
1085 (ev
.GetRow() == 0) &&
1086 (wxMessageBox(_T("Are you sure you wish to edit this cell"),
1087 _T("Checking"),wxYES_NO
) == wxNO
) ) {
1093 wxLogMessage( wxT("Cell editor shown.") );
1098 void GridFrame::OnEditorHidden( wxGridEvent
& ev
)
1101 if ( (ev
.GetCol() == 4) &&
1102 (ev
.GetRow() == 0) &&
1103 (wxMessageBox(_T("Are you sure you wish to finish editing this cell"),
1104 _T("Checking"),wxYES_NO
) == wxNO
) ) {
1110 wxLogMessage( wxT("Cell editor hidden.") );
1115 void GridFrame::About( wxCommandEvent
& WXUNUSED(ev
) )
1117 (void)wxMessageBox( _T("\n\nwxGrid demo \n\n")
1118 _T("Michael Bedward, Julian Smart, Vadim Zeitlin"),
1124 void GridFrame::OnQuit( wxCommandEvent
& WXUNUSED(ev
) )
1129 void GridFrame::OnBugsTable(wxCommandEvent
& )
1131 BugsGridFrame
*frame
= new BugsGridFrame
;
1135 void GridFrame::OnSmallGrid(wxCommandEvent
& )
1137 wxFrame
* frame
= new wxFrame(NULL
, wxID_ANY
, _T("A Small Grid"),
1138 wxDefaultPosition
, wxSize(640, 480));
1139 wxPanel
* panel
= new wxPanel(frame
, wxID_ANY
);
1140 wxGrid
* grid
= new wxGrid(panel
, wxID_ANY
, wxPoint(10,10), wxSize(400,400),
1141 wxWANTS_CHARS
| wxSIMPLE_BORDER
);
1142 grid
->CreateGrid(3,3);
1146 // ----------------------------------------------------------------------------
1147 // MyGridCellAttrProvider
1148 // ----------------------------------------------------------------------------
1150 MyGridCellAttrProvider::MyGridCellAttrProvider()
1152 m_attrForOddRows
= new wxGridCellAttr
;
1153 m_attrForOddRows
->SetBackgroundColour(*wxLIGHT_GREY
);
1156 MyGridCellAttrProvider::~MyGridCellAttrProvider()
1158 m_attrForOddRows
->DecRef();
1161 wxGridCellAttr
*MyGridCellAttrProvider::GetAttr(int row
, int col
,
1162 wxGridCellAttr::wxAttrKind kind
/* = wxGridCellAttr::Any */) const
1164 wxGridCellAttr
*attr
= wxGridCellAttrProvider::GetAttr(row
, col
, kind
);
1170 attr
= m_attrForOddRows
;
1175 if ( !attr
->HasBackgroundColour() )
1177 wxGridCellAttr
*attrNew
= attr
->Clone();
1180 attr
->SetBackgroundColour(*wxLIGHT_GREY
);
1188 // ----------------------------------------------------------------------------
1190 void GridFrame::OnTabularGrid(wxCommandEvent
& )
1192 wxFrame
* frame
= new wxFrame(NULL
, wxID_ANY
, _T("A small tabular Grid"),
1193 wxDefaultPosition
, wxSize(640, 480));
1194 wxGrid
* grid
= new wxGrid(frame
, wxID_ANY
, wxPoint(10,10), wxSize(40,40),
1195 wxWANTS_CHARS
| wxBORDER_SUNKEN
);
1196 grid
->SetRowLabelSize( 0 );
1197 grid
->DisableDragRowSize();
1198 grid
->SetUseNativeColLabels();
1199 grid
->CreateGrid(10,10);
1200 grid
->SetSelectionMode( wxGrid::wxGridSelectRows
);
1205 void GridFrame::OnVTable(wxCommandEvent
& )
1207 static long s_sizeGrid
= 10000;
1210 // MB: wxGetNumberFromUser doesn't work properly for wxMotif
1213 s
= wxGetTextFromUser( _T("Size of the table to create"),
1217 s
.ToLong( &s_sizeGrid
);
1220 s_sizeGrid
= wxGetNumberFromUser(_T("Size of the table to create"),
1222 _T("wxGridDemo question"),
1227 if ( s_sizeGrid
!= -1 )
1229 BigGridFrame
* win
= new BigGridFrame(s_sizeGrid
);
1234 // ----------------------------------------------------------------------------
1235 // MyGridCellRenderer
1236 // ----------------------------------------------------------------------------
1238 // do something that the default renderer doesn't here just to show that it is
1239 // possible to alter the appearance of the cell beyond what the attributes
1241 void MyGridCellRenderer::Draw(wxGrid
& grid
,
1242 wxGridCellAttr
& attr
,
1248 wxGridCellStringRenderer::Draw(grid
, attr
, dc
, rect
, row
, col
, isSelected
);
1250 dc
.SetPen(*wxGREEN_PEN
);
1251 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1252 dc
.DrawEllipse(rect
);
1255 // ============================================================================
1256 // BigGridFrame and BigGridTable: Sample of a non-standard table
1257 // ============================================================================
1259 BigGridFrame::BigGridFrame(long sizeGrid
)
1260 : wxFrame(NULL
, wxID_ANY
, _T("Plugin Virtual Table"),
1261 wxDefaultPosition
, wxSize(500, 450))
1263 m_grid
= new wxGrid(this, wxID_ANY
, wxDefaultPosition
, wxDefaultSize
);
1264 m_table
= new BigGridTable(sizeGrid
);
1266 // VZ: I don't understand why this slows down the display that much,
1267 // must profile it...
1268 //m_table->SetAttrProvider(new MyGridCellAttrProvider);
1270 m_grid
->SetTable(m_table
, true);
1272 #if defined __WXMOTIF__
1273 // MB: the grid isn't getting a sensible default size under wxMotif
1275 GetClientSize( &cw
, &ch
);
1276 m_grid
->SetSize( cw
, ch
);
1280 // ============================================================================
1281 // BugsGridFrame: a "realistic" table
1282 // ============================================================================
1284 // ----------------------------------------------------------------------------
1286 // ----------------------------------------------------------------------------
1309 static const wxString severities
[] =
1318 static struct BugsGridData
1324 wxChar platform
[12];
1326 } gs_dataBugsGrid
[] =
1328 { 18, _T("foo doesn't work"), Sev_Major
, 1, _T("wxMSW"), true },
1329 { 27, _T("bar crashes"), Sev_Critical
, 1, _T("all"), false },
1330 { 45, _T("printing is slow"), Sev_Minor
, 3, _T("wxMSW"), true },
1331 { 68, _T("Rectangle() fails"), Sev_Normal
, 1, _T("wxMSW"), false },
1334 static const wxChar
*headers
[Col_Max
] =
1344 // ----------------------------------------------------------------------------
1346 // ----------------------------------------------------------------------------
1348 wxString
BugsGridTable::GetTypeName(int WXUNUSED(row
), int col
)
1354 return wxGRID_VALUE_NUMBER
;;
1357 // fall thorugh (TODO should be a list)
1360 return wxString::Format(_T("%s:80"), wxGRID_VALUE_STRING
);
1363 return wxString::Format(_T("%s:all,MSW,GTK,other"), wxGRID_VALUE_CHOICE
);
1366 return wxGRID_VALUE_BOOL
;
1369 wxFAIL_MSG(_T("unknown column"));
1371 return wxEmptyString
;
1374 int BugsGridTable::GetNumberRows()
1376 return WXSIZEOF(gs_dataBugsGrid
);
1379 int BugsGridTable::GetNumberCols()
1384 bool BugsGridTable::IsEmptyCell( int WXUNUSED(row
), int WXUNUSED(col
) )
1389 wxString
BugsGridTable::GetValue( int row
, int col
)
1391 const BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1396 return wxString::Format(_T("%d"), gd
.id
);
1399 return wxString::Format(_T("%d"), gd
.prio
);
1402 return gd
.opened
? _T("1") : _T("0");
1405 return severities
[gd
.severity
];
1414 return wxEmptyString
;
1417 void BugsGridTable::SetValue( int row
, int col
, const wxString
& value
)
1419 BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1426 wxFAIL_MSG(_T("unexpected column"));
1432 for ( n
= 0; n
< WXSIZEOF(severities
); n
++ )
1434 if ( severities
[n
] == value
)
1436 gd
.severity
= (Severity
)n
;
1441 if ( n
== WXSIZEOF(severities
) )
1443 wxLogWarning(_T("Invalid severity value '%s'."),
1445 gd
.severity
= Sev_Normal
;
1451 wxStrncpy(gd
.summary
, value
, WXSIZEOF(gd
.summary
));
1455 wxStrncpy(gd
.platform
, value
, WXSIZEOF(gd
.platform
));
1461 BugsGridTable::CanGetValueAs(int WXUNUSED(row
),
1463 const wxString
& typeName
)
1465 if ( typeName
== wxGRID_VALUE_STRING
)
1469 else if ( typeName
== wxGRID_VALUE_BOOL
)
1471 return col
== Col_Opened
;
1473 else if ( typeName
== wxGRID_VALUE_NUMBER
)
1475 return col
== Col_Id
|| col
== Col_Priority
|| col
== Col_Severity
;
1483 bool BugsGridTable::CanSetValueAs( int row
, int col
, const wxString
& typeName
)
1485 return CanGetValueAs(row
, col
, typeName
);
1488 long BugsGridTable::GetValueAsLong( int row
, int col
)
1490 const BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1504 wxFAIL_MSG(_T("unexpected column"));
1509 bool BugsGridTable::GetValueAsBool( int row
, int col
)
1511 if ( col
== Col_Opened
)
1513 return gs_dataBugsGrid
[row
].opened
;
1517 wxFAIL_MSG(_T("unexpected column"));
1523 void BugsGridTable::SetValueAsLong( int row
, int col
, long value
)
1525 BugsGridData
& gd
= gs_dataBugsGrid
[row
];
1534 wxFAIL_MSG(_T("unexpected column"));
1538 void BugsGridTable::SetValueAsBool( int row
, int col
, bool value
)
1540 if ( col
== Col_Opened
)
1542 gs_dataBugsGrid
[row
].opened
= value
;
1546 wxFAIL_MSG(_T("unexpected column"));
1550 wxString
BugsGridTable::GetColLabelValue( int col
)
1552 return headers
[col
];
1555 // ----------------------------------------------------------------------------
1557 // ----------------------------------------------------------------------------
1559 BugsGridFrame::BugsGridFrame()
1560 : wxFrame(NULL
, wxID_ANY
, _T("Bugs table"))
1562 wxGrid
*grid
= new wxGrid(this, wxID_ANY
, wxDefaultPosition
);
1563 wxGridTableBase
*table
= new BugsGridTable();
1564 table
->SetAttrProvider(new MyGridCellAttrProvider
);
1565 grid
->SetTable(table
, true);
1567 wxGridCellAttr
*attrRO
= new wxGridCellAttr
,
1568 *attrRangeEditor
= new wxGridCellAttr
,
1569 *attrCombo
= new wxGridCellAttr
;
1571 attrRO
->SetReadOnly();
1572 attrRangeEditor
->SetEditor(new wxGridCellNumberEditor(1, 5));
1573 attrCombo
->SetEditor(new wxGridCellChoiceEditor(WXSIZEOF(severities
),
1576 grid
->SetColAttr(Col_Id
, attrRO
);
1577 grid
->SetColAttr(Col_Priority
, attrRangeEditor
);
1578 grid
->SetColAttr(Col_Severity
, attrCombo
);
1581 SetClientSize(grid
->GetSize());