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