add a possibility to disable individual grid rows/columns resizing
[wxWidgets.git] / samples / grid / griddemo.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: griddemo.cpp
3 // Purpose: Grid control wxWidgets sample
4 // Author: Michael Bedward
5 // Modified by: Santiago Palacios
6 // RCS-ID: $Id$
7 // Copyright: (c) Michael Bedward, Julian Smart, Vadim Zeitlin
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
10
11 // ============================================================================
12 // declarations
13 // ============================================================================
14
15 // ----------------------------------------------------------------------------
16 // headers
17 // ----------------------------------------------------------------------------
18
19 // For compilers that support precompilation, includes "wx/wx.h".
20 #include "wx/wxprec.h"
21
22 #ifdef __BORLANDC__
23 #pragma hdrstop
24 #endif
25
26 #ifndef WX_PRECOMP
27 #include "wx/wx.h"
28 #endif
29
30 #include "wx/colordlg.h"
31 #include "wx/fontdlg.h"
32 #include "wx/numdlg.h"
33 #include "wx/aboutdlg.h"
34
35 #include "wx/grid.h"
36 #include "wx/headerctrl.h"
37 #include "wx/generic/gridctrl.h"
38 #include "wx/generic/grideditors.h"
39
40 #include "griddemo.h"
41
42 #ifndef __WXMSW__
43 #include "../sample.xpm"
44 #endif
45
46 // ----------------------------------------------------------------------------
47 // wxWin macros
48 // ----------------------------------------------------------------------------
49
50 IMPLEMENT_APP( GridApp )
51
52 // ============================================================================
53 // implementation
54 // ============================================================================
55
56 // ----------------------------------------------------------------------------
57 // GridApp
58 // ----------------------------------------------------------------------------
59
60 bool GridApp::OnInit()
61 {
62 GridFrame *frame = new GridFrame;
63 frame->Show(true);
64
65 return true;
66 }
67
68 // ----------------------------------------------------------------------------
69 // GridFrame
70 // ----------------------------------------------------------------------------
71
72 BEGIN_EVENT_TABLE( GridFrame, wxFrame )
73 EVT_MENU( ID_TOGGLEROWLABELS, GridFrame::ToggleRowLabels )
74 EVT_MENU( ID_TOGGLECOLLABELS, GridFrame::ToggleColLabels )
75 EVT_MENU( ID_TOGGLEEDIT, GridFrame::ToggleEditing )
76 EVT_MENU( ID_TOGGLEROWSIZING, GridFrame::ToggleRowSizing )
77 EVT_MENU( ID_TOGGLECOLSIZING, GridFrame::ToggleColSizing )
78 EVT_MENU( ID_TOGGLECOLMOVING, GridFrame::ToggleColMoving )
79 EVT_MENU( ID_TOGGLEGRIDSIZING, GridFrame::ToggleGridSizing )
80 EVT_MENU( ID_TOGGLEGRIDDRAGCELL, GridFrame::ToggleGridDragCell )
81 EVT_MENU( ID_TOGGLENATIVEHEADER, GridFrame::ToggleNativeHeader )
82 EVT_MENU( ID_TOGGLEGRIDLINES, GridFrame::ToggleGridLines )
83 EVT_MENU( ID_AUTOSIZECOLS, GridFrame::AutoSizeCols )
84 EVT_MENU( ID_CELLOVERFLOW, GridFrame::CellOverflow )
85 EVT_MENU( ID_RESIZECELL, GridFrame::ResizeCell )
86 EVT_MENU( ID_SETLABELCOLOUR, GridFrame::SetLabelColour )
87 EVT_MENU( ID_SETLABELTEXTCOLOUR, GridFrame::SetLabelTextColour )
88 EVT_MENU( ID_SETLABEL_FONT, GridFrame::SetLabelFont )
89 EVT_MENU( ID_ROWLABELHORIZALIGN, GridFrame::SetRowLabelHorizAlignment )
90 EVT_MENU( ID_ROWLABELVERTALIGN, GridFrame::SetRowLabelVertAlignment )
91 EVT_MENU( ID_COLLABELHORIZALIGN, GridFrame::SetColLabelHorizAlignment )
92 EVT_MENU( ID_COLLABELVERTALIGN, GridFrame::SetColLabelVertAlignment )
93 EVT_MENU( ID_GRIDLINECOLOUR, GridFrame::SetGridLineColour )
94 EVT_MENU( ID_INSERTROW, GridFrame::InsertRow )
95 EVT_MENU( ID_INSERTCOL, GridFrame::InsertCol )
96 EVT_MENU( ID_DELETEROW, GridFrame::DeleteSelectedRows )
97 EVT_MENU( ID_DELETECOL, GridFrame::DeleteSelectedCols )
98 EVT_MENU( ID_CLEARGRID, GridFrame::ClearGrid )
99 EVT_MENU( ID_SELCELLS, GridFrame::SelectCells )
100 EVT_MENU( ID_SELROWS, GridFrame::SelectRows )
101 EVT_MENU( ID_SELCOLS, GridFrame::SelectCols )
102 EVT_MENU( ID_SELROWSORCOLS, GridFrame::SelectRowsOrCols )
103
104 EVT_MENU( ID_SET_CELL_FG_COLOUR, GridFrame::SetCellFgColour )
105 EVT_MENU( ID_SET_CELL_BG_COLOUR, GridFrame::SetCellBgColour )
106
107 EVT_MENU( wxID_ABOUT, GridFrame::About )
108 EVT_MENU( wxID_EXIT, GridFrame::OnQuit )
109 EVT_MENU( ID_VTABLE, GridFrame::OnVTable)
110 EVT_MENU( ID_BUGS_TABLE, GridFrame::OnBugsTable)
111 EVT_MENU( ID_TABULAR_TABLE, GridFrame::OnTabularTable)
112
113 EVT_MENU( ID_DESELECT_CELL, GridFrame::DeselectCell)
114 EVT_MENU( ID_DESELECT_COL, GridFrame::DeselectCol)
115 EVT_MENU( ID_DESELECT_ROW, GridFrame::DeselectRow)
116 EVT_MENU( ID_DESELECT_ALL, GridFrame::DeselectAll)
117 EVT_MENU( ID_SELECT_CELL, GridFrame::SelectCell)
118 EVT_MENU( ID_SELECT_COL, GridFrame::SelectCol)
119 EVT_MENU( ID_SELECT_ROW, GridFrame::SelectRow)
120 EVT_MENU( ID_SELECT_ALL, GridFrame::SelectAll)
121 EVT_MENU( ID_SELECT_UNSELECT, GridFrame::OnAddToSelectToggle)
122 EVT_MENU( ID_SHOW_SELECTION, GridFrame::OnShowSelection)
123
124 EVT_MENU( ID_SIZE_ROW, GridFrame::AutoSizeRow )
125 EVT_MENU( ID_SIZE_COL, GridFrame::AutoSizeCol )
126 EVT_MENU( ID_SIZE_ROW_LABEL, GridFrame::AutoSizeRowLabel )
127 EVT_MENU( ID_SIZE_COL_LABEL, GridFrame::AutoSizeColLabel )
128 EVT_MENU( ID_SIZE_LABELS_COL, GridFrame::AutoSizeLabelsCol )
129 EVT_MENU( ID_SIZE_LABELS_ROW, GridFrame::AutoSizeLabelsRow )
130 EVT_MENU( ID_SIZE_GRID, GridFrame::AutoSizeTable )
131
132 EVT_MENU( ID_SET_HIGHLIGHT_WIDTH, GridFrame::OnSetHighlightWidth)
133 EVT_MENU( ID_SET_RO_HIGHLIGHT_WIDTH, GridFrame::OnSetROHighlightWidth)
134
135 EVT_GRID_LABEL_LEFT_CLICK( GridFrame::OnLabelLeftClick )
136 EVT_GRID_CELL_LEFT_CLICK( GridFrame::OnCellLeftClick )
137 EVT_GRID_ROW_SIZE( GridFrame::OnRowSize )
138 EVT_GRID_COL_SIZE( GridFrame::OnColSize )
139 EVT_GRID_SELECT_CELL( GridFrame::OnSelectCell )
140 EVT_GRID_RANGE_SELECT( GridFrame::OnRangeSelected )
141 EVT_GRID_CELL_CHANGING( GridFrame::OnCellValueChanging )
142 EVT_GRID_CELL_CHANGE( GridFrame::OnCellValueChanged )
143 EVT_GRID_CELL_BEGIN_DRAG( GridFrame::OnCellBeginDrag )
144
145 EVT_GRID_EDITOR_SHOWN( GridFrame::OnEditorShown )
146 EVT_GRID_EDITOR_HIDDEN( GridFrame::OnEditorHidden )
147 END_EVENT_TABLE()
148
149
150 GridFrame::GridFrame()
151 : wxFrame( (wxFrame *)NULL, wxID_ANY, _T("wxWidgets grid class demo"),
152 wxDefaultPosition,
153 wxDefaultSize )
154 {
155 SetIcon(wxICON(sample));
156
157 wxMenu *fileMenu = new wxMenu;
158 fileMenu->Append( ID_VTABLE, _T("&Virtual table test\tCtrl-V"));
159 fileMenu->Append( ID_BUGS_TABLE, _T("&Bugs table test\tCtrl-B"));
160 fileMenu->Append( ID_TABULAR_TABLE, _T("&Tabular table test\tCtrl-T"));
161 fileMenu->AppendSeparator();
162 fileMenu->Append( wxID_EXIT, _T("E&xit\tAlt-X") );
163
164 wxMenu *viewMenu = new wxMenu;
165 viewMenu->AppendCheckItem(ID_TOGGLEROWLABELS, "&Row labels");
166 viewMenu->AppendCheckItem(ID_TOGGLECOLLABELS, "&Col labels");
167 viewMenu->AppendCheckItem(ID_TOGGLEEDIT,"&Editable");
168 viewMenu->AppendCheckItem(ID_TOGGLEROWSIZING, "Ro&w drag-resize");
169 viewMenu->AppendCheckItem(ID_TOGGLECOLSIZING, "C&ol drag-resize");
170 viewMenu->AppendCheckItem(ID_TOGGLECOLMOVING, "Col drag-&move");
171 viewMenu->AppendCheckItem(ID_TOGGLEGRIDSIZING, "&Grid drag-resize");
172 viewMenu->AppendCheckItem(ID_TOGGLEGRIDDRAGCELL, "&Grid drag-cell");
173 viewMenu->AppendCheckItem(ID_TOGGLENATIVEHEADER, "&Native column headers");
174 viewMenu->AppendCheckItem(ID_TOGGLEGRIDLINES, "&Grid Lines");
175 viewMenu->AppendCheckItem(ID_SET_HIGHLIGHT_WIDTH, "&Set Cell Highlight Width...");
176 viewMenu->AppendCheckItem(ID_SET_RO_HIGHLIGHT_WIDTH, "&Set Cell RO Highlight Width...");
177 viewMenu->AppendCheckItem(ID_AUTOSIZECOLS, "&Auto-size cols");
178 viewMenu->AppendCheckItem(ID_CELLOVERFLOW, "&Overflow cells");
179 viewMenu->AppendCheckItem(ID_RESIZECELL, "&Resize cell (7,1)");
180
181 wxMenu *rowLabelMenu = new wxMenu;
182
183 viewMenu->Append( ID_ROWLABELALIGN, _T("R&ow label alignment"),
184 rowLabelMenu,
185 _T("Change alignment of row labels") );
186
187 rowLabelMenu->Append( ID_ROWLABELHORIZALIGN, _T("&Horizontal") );
188 rowLabelMenu->Append( ID_ROWLABELVERTALIGN, _T("&Vertical") );
189
190 wxMenu *colLabelMenu = new wxMenu;
191
192 viewMenu->Append( ID_COLLABELALIGN, _T("Col l&abel alignment"),
193 colLabelMenu,
194 _T("Change alignment of col labels") );
195
196 colLabelMenu->Append( ID_COLLABELHORIZALIGN, _T("&Horizontal") );
197 colLabelMenu->Append( ID_COLLABELVERTALIGN, _T("&Vertical") );
198
199 wxMenu *colMenu = new wxMenu;
200 colMenu->Append( ID_SETLABELCOLOUR, _T("Set &label colour...") );
201 colMenu->Append( ID_SETLABELTEXTCOLOUR, _T("Set label &text colour...") );
202 colMenu->Append( ID_SETLABEL_FONT, _T("Set label fo&nt...") );
203 colMenu->Append( ID_GRIDLINECOLOUR, _T("&Grid line colour...") );
204 colMenu->Append( ID_SET_CELL_FG_COLOUR, _T("Set cell &foreground colour...") );
205 colMenu->Append( ID_SET_CELL_BG_COLOUR, _T("Set cell &background colour...") );
206
207 wxMenu *editMenu = new wxMenu;
208 editMenu->Append( ID_INSERTROW, _T("Insert &row") );
209 editMenu->Append( ID_INSERTCOL, _T("Insert &column") );
210 editMenu->Append( ID_DELETEROW, _T("Delete selected ro&ws") );
211 editMenu->Append( ID_DELETECOL, _T("Delete selected co&ls") );
212 editMenu->Append( ID_CLEARGRID, _T("Cl&ear grid cell contents") );
213
214 wxMenu *selectMenu = new wxMenu;
215 selectMenu->Append( ID_SELECT_UNSELECT, _T("Add new cells to the selection"),
216 _T("When off, old selection is deselected before ")
217 _T("selecting the new cells"), wxITEM_CHECK );
218 selectMenu->Append( ID_SHOW_SELECTION,
219 _T("&Show current selection\tCtrl-Alt-S"));
220 selectMenu->AppendSeparator();
221 selectMenu->Append( ID_SELECT_ALL, _T("Select all"));
222 selectMenu->Append( ID_SELECT_ROW, _T("Select row 2"));
223 selectMenu->Append( ID_SELECT_COL, _T("Select col 2"));
224 selectMenu->Append( ID_SELECT_CELL, _T("Select cell (3, 1)"));
225 selectMenu->AppendSeparator();
226 selectMenu->Append( ID_DESELECT_ALL, _T("Deselect all"));
227 selectMenu->Append( ID_DESELECT_ROW, _T("Deselect row 2"));
228 selectMenu->Append( ID_DESELECT_COL, _T("Deselect col 2"));
229 selectMenu->Append( ID_DESELECT_CELL, _T("Deselect cell (3, 1)"));
230 wxMenu *selectionMenu = new wxMenu;
231 selectMenu->Append( ID_CHANGESEL, _T("Change &selection mode"),
232 selectionMenu,
233 _T("Change selection mode") );
234
235 selectionMenu->Append( ID_SELCELLS, _T("Select &cells") );
236 selectionMenu->Append( ID_SELROWS, _T("Select &rows") );
237 selectionMenu->Append( ID_SELCOLS, _T("Select col&umns") );
238 selectionMenu->Append( ID_SELROWSORCOLS, _T("Select rows &or columns") );
239
240 wxMenu *autosizeMenu = new wxMenu;
241 autosizeMenu->Append( ID_SIZE_ROW, _T("Selected &row data") );
242 autosizeMenu->Append( ID_SIZE_COL, _T("Selected &column data") );
243 autosizeMenu->Append( ID_SIZE_ROW_LABEL, _T("Selected row la&bel") );
244 autosizeMenu->Append( ID_SIZE_COL_LABEL, _T("Selected column &label") );
245 autosizeMenu->Append( ID_SIZE_LABELS_COL, _T("Column la&bels") );
246 autosizeMenu->Append( ID_SIZE_LABELS_ROW, _T("Row label&s") );
247 autosizeMenu->Append( ID_SIZE_GRID, _T("Entire &grid") );
248
249 wxMenu *helpMenu = new wxMenu;
250 helpMenu->Append( wxID_ABOUT, _T("&About wxGrid demo") );
251
252 wxMenuBar *menuBar = new wxMenuBar;
253 menuBar->Append( fileMenu, _T("&File") );
254 menuBar->Append( viewMenu, _T("&Grid") );
255 menuBar->Append( colMenu, _T("&Colours") );
256 menuBar->Append( editMenu, _T("&Edit") );
257 menuBar->Append( selectMenu, _T("&Select") );
258 menuBar->Append( autosizeMenu, _T("&Autosize") );
259 menuBar->Append( helpMenu, _T("&Help") );
260
261 SetMenuBar( menuBar );
262
263 m_addToSel = false;
264
265 grid = new wxGrid( this,
266 wxID_ANY,
267 wxPoint( 0, 0 ),
268 wxSize( 400, 300 ) );
269
270 #if wxUSE_LOG
271 int gridW = 600, gridH = 300;
272 int logW = gridW, logH = 100;
273
274 logWin = new wxTextCtrl( this,
275 wxID_ANY,
276 wxEmptyString,
277 wxPoint( 0, gridH + 20 ),
278 wxSize( logW, logH ),
279 wxTE_MULTILINE );
280
281 logger = new wxLogTextCtrl( logWin );
282 m_logOld = wxLog::SetActiveTarget( logger );
283 wxLog::DisableTimestamp();
284 #endif // wxUSE_LOG
285
286 // this will create a grid and, by default, an associated grid
287 // table for strings
288 grid->CreateGrid( 0, 0 );
289 grid->AppendRows(100);
290 grid->AppendCols(100);
291
292 int ir = grid->GetNumberRows();
293 grid->DeleteRows(0, ir);
294 grid->AppendRows(ir);
295
296 grid->SetRowSize( 0, 60 );
297 grid->SetCellValue( 0, 0, _T("Ctrl+Home\nwill go to\nthis cell") );
298
299 grid->SetCellValue( 0, 1, _T("A long piece of text to demonstrate wrapping.") );
300 grid->SetCellRenderer(0 , 1, new wxGridCellAutoWrapStringRenderer);
301 grid->SetCellEditor( 0, 1 , new wxGridCellAutoWrapStringEditor);
302
303 grid->SetCellValue( 0, 2, _T("Blah") );
304 grid->SetCellValue( 0, 3, _T("Read only") );
305 grid->SetReadOnly( 0, 3 );
306
307 grid->SetCellValue( 0, 4, _T("Can veto edit this cell") );
308
309 grid->SetCellValue( 0, 5, _T("Press\nCtrl+arrow\nto skip over\ncells") );
310
311 grid->SetRowSize( 99, 60 );
312 grid->SetCellValue( 99, 99, _T("Ctrl+End\nwill go to\nthis cell") );
313 grid->SetCellValue( 1, 0, _T("This default cell will overflow into neighboring cells, but not if you turn overflow off."));
314
315 grid->SetCellTextColour(1, 2, *wxRED);
316 grid->SetCellBackgroundColour(1, 2, *wxGREEN);
317
318 grid->SetCellValue( 1, 4, _T("I'm in the middle"));
319
320 grid->SetCellValue(2, 2, _T("red"));
321
322 grid->SetCellTextColour(2, 2, *wxRED);
323 grid->SetCellValue(3, 3, _T("green on grey"));
324 grid->SetCellTextColour(3, 3, *wxGREEN);
325 grid->SetCellBackgroundColour(3, 3, *wxLIGHT_GREY);
326
327 grid->SetCellValue(4, 4, _T("a weird looking cell"));
328 grid->SetCellAlignment(4, 4, wxALIGN_CENTRE, wxALIGN_CENTRE);
329 grid->SetCellRenderer(4, 4, new MyGridCellRenderer);
330
331 grid->SetCellRenderer(3, 0, new wxGridCellBoolRenderer);
332 grid->SetCellEditor(3, 0, new wxGridCellBoolEditor);
333
334 wxGridCellAttr *attr;
335 attr = new wxGridCellAttr;
336 attr->SetTextColour(*wxBLUE);
337 grid->SetColAttr(5, attr);
338 attr = new wxGridCellAttr;
339 attr->SetBackgroundColour(*wxRED);
340 grid->SetRowAttr(5, attr);
341
342 grid->SetCellValue(2, 4, _T("a wider column"));
343 grid->SetColSize(4, 120);
344 grid->SetColMinimalWidth(4, 120);
345
346 grid->SetCellTextColour(5, 8, *wxGREEN);
347 grid->SetCellValue(5, 8, _T("Bg from row attr\nText col from cell attr"));
348 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"));
349
350 grid->SetColFormatFloat(6);
351 grid->SetCellValue(0, 6, wxString::Format(wxT("%g"), 3.1415));
352 grid->SetCellValue(1, 6, wxString::Format(wxT("%g"), 1415.0));
353 grid->SetCellValue(2, 6, wxString::Format(wxT("%g"), 12345.67890));
354
355 grid->SetColFormatFloat(7, 6, 2);
356 grid->SetCellValue(0, 7, wxString::Format(wxT("%g"), 3.1415));
357 grid->SetCellValue(1, 7, wxString::Format(wxT("%g"), 1415.0));
358 grid->SetCellValue(2, 7, wxString::Format(wxT("%g"), 12345.67890));
359
360 grid->SetColFormatNumber(8);
361 grid->SetCellValue(0, 8, "17");
362 grid->SetCellValue(1, 8, "0");
363 grid->SetCellValue(2, 8, "-666");
364
365 const wxString choices[] =
366 {
367 _T("Please select a choice"),
368 _T("This takes two cells"),
369 _T("Another choice"),
370 };
371 grid->SetCellEditor(4, 0, new wxGridCellChoiceEditor(WXSIZEOF(choices), choices));
372 grid->SetCellSize(4, 0, 1, 2);
373 grid->SetCellValue(4, 0, choices[0]);
374 grid->SetCellOverflow(4, 0, false);
375
376 grid->SetCellSize(7, 1, 3, 4);
377 grid->SetCellAlignment(7, 1, wxALIGN_CENTRE, wxALIGN_CENTRE);
378 grid->SetCellValue(7, 1, _T("Big box!"));
379
380 // create a separator-like row: it's grey and it's non-resizeable
381 grid->DisableRowResize(10);
382 grid->SetRowSize(10, 30);
383 attr = new wxGridCellAttr;
384 attr->SetBackgroundColour(*wxLIGHT_GREY);
385 grid->SetRowAttr(10, attr);
386 grid->SetCellValue(10, 0, "You can't resize this row interactively -- try it");
387
388 // this does exactly nothing except testing that SetAttr() handles NULL
389 // attributes and does reference counting correctly
390 grid->SetAttr(11, 11, NULL);
391 grid->SetAttr(11, 11, new wxGridCellAttr);
392 grid->SetAttr(11, 11, NULL);
393
394 wxBoxSizer *topSizer = new wxBoxSizer( wxVERTICAL );
395 topSizer->Add( grid,
396 1,
397 wxEXPAND );
398
399 #if wxUSE_LOG
400 topSizer->Add( logWin,
401 0,
402 wxEXPAND );
403 #endif // wxUSE_LOG
404
405 SetSizerAndFit( topSizer );
406
407 Centre();
408 SetDefaults();
409 }
410
411
412 GridFrame::~GridFrame()
413 {
414 #if wxUSE_LOG
415 delete wxLog::SetActiveTarget(m_logOld);
416 #endif // wxUSE_LOG
417 }
418
419
420 void GridFrame::SetDefaults()
421 {
422 GetMenuBar()->Check( ID_TOGGLEROWLABELS, true );
423 GetMenuBar()->Check( ID_TOGGLECOLLABELS, true );
424 GetMenuBar()->Check( ID_TOGGLEEDIT, true );
425 GetMenuBar()->Check( ID_TOGGLEROWSIZING, true );
426 GetMenuBar()->Check( ID_TOGGLECOLSIZING, true );
427 GetMenuBar()->Check( ID_TOGGLECOLMOVING, false );
428 GetMenuBar()->Check( ID_TOGGLEGRIDSIZING, true );
429 GetMenuBar()->Check( ID_TOGGLEGRIDDRAGCELL, false );
430 GetMenuBar()->Check( ID_TOGGLENATIVEHEADER, false );
431 GetMenuBar()->Check( ID_TOGGLEGRIDLINES, true );
432 GetMenuBar()->Check( ID_CELLOVERFLOW, true );
433 }
434
435
436 void GridFrame::ToggleRowLabels( wxCommandEvent& WXUNUSED(ev) )
437 {
438 if ( GetMenuBar()->IsChecked( ID_TOGGLEROWLABELS ) )
439 {
440 grid->SetRowLabelSize( grid->GetDefaultRowLabelSize() );
441 }
442 else
443 {
444 grid->SetRowLabelSize( 0 );
445 }
446 }
447
448
449 void GridFrame::ToggleColLabels( wxCommandEvent& WXUNUSED(ev) )
450 {
451 if ( GetMenuBar()->IsChecked( ID_TOGGLECOLLABELS ) )
452 {
453 grid->SetColLabelSize( grid->GetDefaultColLabelSize() );
454 }
455 else
456 {
457 grid->SetColLabelSize( 0 );
458 }
459 }
460
461
462 void GridFrame::ToggleEditing( wxCommandEvent& WXUNUSED(ev) )
463 {
464 grid->EnableEditing(
465 GetMenuBar()->IsChecked( ID_TOGGLEEDIT ) );
466 }
467
468
469 void GridFrame::ToggleRowSizing( wxCommandEvent& WXUNUSED(ev) )
470 {
471 grid->EnableDragRowSize(
472 GetMenuBar()->IsChecked( ID_TOGGLEROWSIZING ) );
473 }
474
475
476 void GridFrame::ToggleColSizing( wxCommandEvent& WXUNUSED(ev) )
477 {
478 grid->EnableDragColSize(
479 GetMenuBar()->IsChecked( ID_TOGGLECOLSIZING ) );
480 }
481
482 void GridFrame::ToggleColMoving( wxCommandEvent& WXUNUSED(ev) )
483 {
484 grid->EnableDragColMove(
485 GetMenuBar()->IsChecked( ID_TOGGLECOLMOVING ) );
486 }
487
488 void GridFrame::ToggleGridSizing( wxCommandEvent& WXUNUSED(ev) )
489 {
490 grid->EnableDragGridSize(
491 GetMenuBar()->IsChecked( ID_TOGGLEGRIDSIZING ) );
492 }
493
494 void GridFrame::ToggleGridDragCell( wxCommandEvent& WXUNUSED(ev) )
495 {
496 grid->EnableDragCell(
497 GetMenuBar()->IsChecked( ID_TOGGLEGRIDDRAGCELL ) );
498 }
499
500 void GridFrame::ToggleNativeHeader( wxCommandEvent& WXUNUSED(ev) )
501 {
502 grid->SetUseNativeColLabels(
503 GetMenuBar()->IsChecked( ID_TOGGLENATIVEHEADER ) );
504 }
505
506 void GridFrame::ToggleGridLines( wxCommandEvent& WXUNUSED(ev) )
507 {
508 grid->EnableGridLines(
509 GetMenuBar()->IsChecked( ID_TOGGLEGRIDLINES ) );
510 }
511
512 void GridFrame::OnSetHighlightWidth( wxCommandEvent& WXUNUSED(ev) )
513 {
514 wxString choices[] = { _T("0"), _T("1"), _T("2"), _T("3"), _T("4"), _T("5"), _T("6"), _T("7"), _T("8"), _T("9"), _T("10")};
515
516 wxSingleChoiceDialog dlg(this, _T("Choose the thickness of the highlight pen:"),
517 _T("Pen Width"), 11, choices);
518
519 int current = grid->GetCellHighlightPenWidth();
520 dlg.SetSelection(current);
521 if (dlg.ShowModal() == wxID_OK) {
522 grid->SetCellHighlightPenWidth(dlg.GetSelection());
523 }
524 }
525
526 void GridFrame::OnSetROHighlightWidth( wxCommandEvent& WXUNUSED(ev) )
527 {
528 wxString choices[] = { _T("0"), _T("1"), _T("2"), _T("3"), _T("4"), _T("5"), _T("6"), _T("7"), _T("8"), _T("9"), _T("10")};
529
530 wxSingleChoiceDialog dlg(this, _T("Choose the thickness of the highlight pen:"),
531 _T("Pen Width"), 11, choices);
532
533 int current = grid->GetCellHighlightROPenWidth();
534 dlg.SetSelection(current);
535 if (dlg.ShowModal() == wxID_OK) {
536 grid->SetCellHighlightROPenWidth(dlg.GetSelection());
537 }
538 }
539
540
541
542 void GridFrame::AutoSizeCols( wxCommandEvent& WXUNUSED(ev) )
543 {
544 grid->AutoSizeColumns();
545 grid->Refresh();
546 }
547
548 void GridFrame::CellOverflow( wxCommandEvent& ev )
549 {
550 grid->SetDefaultCellOverflow(ev.IsChecked());
551 grid->Refresh();
552 }
553
554 void GridFrame::ResizeCell( wxCommandEvent& ev )
555 {
556 if (ev.IsChecked())
557 grid->SetCellSize( 7, 1, 5, 5 );
558 else
559 grid->SetCellSize( 7, 1, 1, 5 );
560 grid->Refresh();
561 }
562
563 void GridFrame::SetLabelColour( wxCommandEvent& WXUNUSED(ev) )
564 {
565 wxColourDialog dlg( NULL );
566 if ( dlg.ShowModal() == wxID_OK )
567 {
568 wxColourData retData;
569 retData = dlg.GetColourData();
570 wxColour colour = retData.GetColour();
571
572 grid->SetLabelBackgroundColour( colour );
573 }
574 }
575
576
577 void GridFrame::SetLabelTextColour( wxCommandEvent& WXUNUSED(ev) )
578 {
579 wxColourDialog dlg( NULL );
580 if ( dlg.ShowModal() == wxID_OK )
581 {
582 wxColourData retData;
583 retData = dlg.GetColourData();
584 wxColour colour = retData.GetColour();
585
586 grid->SetLabelTextColour( colour );
587 }
588 }
589
590 void GridFrame::SetLabelFont( wxCommandEvent& WXUNUSED(ev) )
591 {
592 wxFont font = wxGetFontFromUser(this);
593 if ( font.Ok() )
594 {
595 grid->SetLabelFont(font);
596 }
597 }
598
599 void GridFrame::SetRowLabelHorizAlignment( wxCommandEvent& WXUNUSED(ev) )
600 {
601 int horiz, vert;
602 grid->GetRowLabelAlignment( &horiz, &vert );
603
604 switch ( horiz )
605 {
606 case wxALIGN_LEFT:
607 horiz = wxALIGN_CENTRE;
608 break;
609
610 case wxALIGN_CENTRE:
611 horiz = wxALIGN_RIGHT;
612 break;
613
614 case wxALIGN_RIGHT:
615 horiz = wxALIGN_LEFT;
616 break;
617 }
618
619 grid->SetRowLabelAlignment( horiz, vert );
620 }
621
622 void GridFrame::SetRowLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) )
623 {
624 int horiz, vert;
625 grid->GetRowLabelAlignment( &horiz, &vert );
626
627 switch ( vert )
628 {
629 case wxALIGN_TOP:
630 vert = wxALIGN_CENTRE;
631 break;
632
633 case wxALIGN_CENTRE:
634 vert = wxALIGN_BOTTOM;
635 break;
636
637 case wxALIGN_BOTTOM:
638 vert = wxALIGN_TOP;
639 break;
640 }
641
642 grid->SetRowLabelAlignment( horiz, vert );
643 }
644
645
646 void GridFrame::SetColLabelHorizAlignment( wxCommandEvent& WXUNUSED(ev) )
647 {
648 int horiz, vert;
649 grid->GetColLabelAlignment( &horiz, &vert );
650
651 switch ( horiz )
652 {
653 case wxALIGN_LEFT:
654 horiz = wxALIGN_CENTRE;
655 break;
656
657 case wxALIGN_CENTRE:
658 horiz = wxALIGN_RIGHT;
659 break;
660
661 case wxALIGN_RIGHT:
662 horiz = wxALIGN_LEFT;
663 break;
664 }
665
666 grid->SetColLabelAlignment( horiz, vert );
667 }
668
669
670 void GridFrame::SetColLabelVertAlignment( wxCommandEvent& WXUNUSED(ev) )
671 {
672 int horiz, vert;
673 grid->GetColLabelAlignment( &horiz, &vert );
674
675 switch ( vert )
676 {
677 case wxALIGN_TOP:
678 vert = wxALIGN_CENTRE;
679 break;
680
681 case wxALIGN_CENTRE:
682 vert = wxALIGN_BOTTOM;
683 break;
684
685 case wxALIGN_BOTTOM:
686 vert = wxALIGN_TOP;
687 break;
688 }
689
690 grid->SetColLabelAlignment( horiz, vert );
691 }
692
693
694 void GridFrame::SetGridLineColour( wxCommandEvent& WXUNUSED(ev) )
695 {
696 wxColourDialog dlg( NULL );
697 if ( dlg.ShowModal() == wxID_OK )
698 {
699 wxColourData retData;
700 retData = dlg.GetColourData();
701 wxColour colour = retData.GetColour();
702
703 grid->SetGridLineColour( colour );
704 }
705 }
706
707
708 void GridFrame::InsertRow( wxCommandEvent& WXUNUSED(ev) )
709 {
710 grid->InsertRows( grid->GetGridCursorRow(), 1 );
711 }
712
713
714 void GridFrame::InsertCol( wxCommandEvent& WXUNUSED(ev) )
715 {
716 grid->InsertCols( grid->GetGridCursorCol(), 1 );
717 }
718
719
720 void GridFrame::DeleteSelectedRows( wxCommandEvent& WXUNUSED(ev) )
721 {
722 if ( grid->IsSelection() )
723 {
724 wxGridUpdateLocker locker(grid);
725 for ( int n = 0; n < grid->GetNumberRows(); )
726 {
727 if ( grid->IsInSelection( n , 0 ) )
728 grid->DeleteRows( n, 1 );
729 else
730 n++;
731 }
732 }
733 }
734
735
736 void GridFrame::AutoSizeRow(wxCommandEvent& WXUNUSED(event))
737 {
738 wxGridUpdateLocker locker(grid);
739 const wxArrayInt sels = grid->GetSelectedRows();
740 for ( size_t n = 0, count = sels.size(); n < count; n++ )
741 {
742 grid->AutoSizeRow( sels[n], false );
743 }
744 }
745
746 void GridFrame::AutoSizeCol(wxCommandEvent& WXUNUSED(event))
747 {
748 wxGridUpdateLocker locker(grid);
749 const wxArrayInt sels = grid->GetSelectedCols();
750 for ( size_t n = 0, count = sels.size(); n < count; n++ )
751 {
752 grid->AutoSizeColumn( sels[n], false );
753 }
754 }
755
756 void GridFrame::AutoSizeRowLabel(wxCommandEvent& WXUNUSED(event))
757 {
758 wxGridUpdateLocker locker(grid);
759 const wxArrayInt sels = grid->GetSelectedRows();
760 for ( size_t n = 0, count = sels.size(); n < count; n++ )
761 {
762 grid->AutoSizeRowLabelSize( sels[n] );
763 }
764 }
765
766 void GridFrame::AutoSizeColLabel(wxCommandEvent& WXUNUSED(event))
767 {
768 wxGridUpdateLocker locker(grid);
769 const wxArrayInt sels = grid->GetSelectedCols();
770 for ( size_t n = 0, count = sels.size(); n < count; n++ )
771 {
772 grid->AutoSizeColLabelSize( sels[n] );
773 }
774 }
775
776 void GridFrame::AutoSizeLabelsCol(wxCommandEvent& WXUNUSED(event))
777 {
778 grid->SetColLabelSize( wxGRID_AUTOSIZE );
779 }
780
781 void GridFrame::AutoSizeLabelsRow(wxCommandEvent& WXUNUSED(event))
782 {
783 grid->SetRowLabelSize( wxGRID_AUTOSIZE );
784 }
785
786 void GridFrame::AutoSizeTable(wxCommandEvent& WXUNUSED(event))
787 {
788 grid->AutoSize();
789 }
790
791
792 void GridFrame::DeleteSelectedCols( wxCommandEvent& WXUNUSED(ev) )
793 {
794 if ( grid->IsSelection() )
795 {
796 wxGridUpdateLocker locker(grid);
797 for ( int n = 0; n < grid->GetNumberCols(); )
798 {
799 if ( grid->IsInSelection( 0 , n ) )
800 grid->DeleteCols( n, 1 );
801 else
802 n++;
803 }
804 }
805 }
806
807
808 void GridFrame::ClearGrid( wxCommandEvent& WXUNUSED(ev) )
809 {
810 grid->ClearGrid();
811 }
812
813 void GridFrame::SelectCells( wxCommandEvent& WXUNUSED(ev) )
814 {
815 grid->SetSelectionMode( wxGrid::wxGridSelectCells );
816 }
817
818 void GridFrame::SelectRows( wxCommandEvent& WXUNUSED(ev) )
819 {
820 grid->SetSelectionMode( wxGrid::wxGridSelectRows );
821 }
822
823 void GridFrame::SelectCols( wxCommandEvent& WXUNUSED(ev) )
824 {
825 grid->SetSelectionMode( wxGrid::wxGridSelectColumns );
826 }
827
828 void GridFrame::SelectRowsOrCols( wxCommandEvent& WXUNUSED(ev) )
829 {
830 grid->SetSelectionMode( wxGrid::wxGridSelectRowsOrColumns );
831 }
832
833 void GridFrame::SetCellFgColour( wxCommandEvent& WXUNUSED(ev) )
834 {
835 wxColour col = wxGetColourFromUser(this);
836 if ( col.Ok() )
837 {
838 grid->SetDefaultCellTextColour(col);
839 grid->Refresh();
840 }
841 }
842
843 void GridFrame::SetCellBgColour( wxCommandEvent& WXUNUSED(ev) )
844 {
845 wxColour col = wxGetColourFromUser(this);
846 if ( col.Ok() )
847 {
848 // Check the new Refresh function by passing it a rectangle
849 // which exactly fits the grid.
850 wxPoint pt(0, 0);
851 wxRect r(pt, grid->GetSize());
852 grid->SetDefaultCellBackgroundColour(col);
853 grid->Refresh(true, &r);
854 }
855 }
856
857 void GridFrame::DeselectCell(wxCommandEvent& WXUNUSED(event))
858 {
859 grid->DeselectCell(3, 1);
860 }
861
862 void GridFrame::DeselectCol(wxCommandEvent& WXUNUSED(event))
863 {
864 grid->DeselectCol(2);
865 }
866
867 void GridFrame::DeselectRow(wxCommandEvent& WXUNUSED(event))
868 {
869 grid->DeselectRow(2);
870 }
871
872 void GridFrame::DeselectAll(wxCommandEvent& WXUNUSED(event))
873 {
874 grid->ClearSelection();
875 }
876
877 void GridFrame::SelectCell(wxCommandEvent& WXUNUSED(event))
878 {
879 grid->SelectBlock(3, 1, 3, 1, m_addToSel);
880 }
881
882 void GridFrame::SelectCol(wxCommandEvent& WXUNUSED(event))
883 {
884 grid->SelectCol(2, m_addToSel);
885 }
886
887 void GridFrame::SelectRow(wxCommandEvent& WXUNUSED(event))
888 {
889 grid->SelectRow(2, m_addToSel);
890 }
891
892 void GridFrame::SelectAll(wxCommandEvent& WXUNUSED(event))
893 {
894 grid->SelectAll();
895 }
896
897 void GridFrame::OnAddToSelectToggle(wxCommandEvent& event)
898 {
899 m_addToSel = event.IsChecked();
900 }
901
902 void GridFrame::OnLabelLeftClick( wxGridEvent& ev )
903 {
904 wxString logBuf;
905 if ( ev.GetRow() != -1 )
906 {
907 logBuf << _T("Left click on row label ") << ev.GetRow();
908 }
909 else if ( ev.GetCol() != -1 )
910 {
911 logBuf << _T("Left click on col label ") << ev.GetCol();
912 }
913 else
914 {
915 logBuf << _T("Left click on corner label");
916 }
917
918 if ( ev.ShiftDown() )
919 logBuf << _T(" (shift down)");
920 if ( ev.ControlDown() )
921 logBuf << _T(" (control down)");
922 wxLogMessage( wxT("%s"), logBuf.c_str() );
923
924 // you must call event skip if you want default grid processing
925 //
926 ev.Skip();
927 }
928
929
930 void GridFrame::OnCellLeftClick( wxGridEvent& ev )
931 {
932 wxLogMessage(_T("Left click at row %d, col %d"), ev.GetRow(), ev.GetCol());
933
934 // you must call event skip if you want default grid processing
935 // (cell highlighting etc.)
936 //
937 ev.Skip();
938 }
939
940
941 void GridFrame::OnRowSize( wxGridSizeEvent& ev )
942 {
943 wxLogMessage(_T("Resized row %d"), ev.GetRowOrCol());
944
945 ev.Skip();
946 }
947
948
949 void GridFrame::OnColSize( wxGridSizeEvent& ev )
950 {
951 wxLogMessage(_T("Resized col %d"), ev.GetRowOrCol());
952
953 ev.Skip();
954 }
955
956
957 void GridFrame::OnShowSelection(wxCommandEvent& WXUNUSED(event))
958 {
959 // max number of elements to dump -- otherwise it can take too much time
960 static const size_t countMax = 100;
961
962 bool rows = false;
963
964 switch ( grid->GetSelectionMode() )
965 {
966 case wxGrid::wxGridSelectCells:
967 {
968 const wxGridCellCoordsArray cells(grid->GetSelectedCells());
969 size_t count = cells.size();
970 wxLogMessage(_T("%lu cells selected:"), (unsigned long)count);
971 if ( count > countMax )
972 {
973 wxLogMessage(_T("[too many selected cells, ")
974 _T("showing only the first %lu]"),
975 (unsigned long)countMax);
976 count = countMax;
977 }
978
979 for ( size_t n = 0; n < count; n++ )
980 {
981 const wxGridCellCoords& c = cells[n];
982 wxLogMessage(_T(" selected cell %lu: (%d, %d)"),
983 (unsigned long)n, c.GetCol(), c.GetRow());
984 }
985 }
986 break;
987
988 case wxGrid::wxGridSelectRows:
989 rows = true;
990 // fall through
991
992 case wxGrid::wxGridSelectColumns:
993 {
994 const wxChar *plural, *single;
995 if ( rows )
996 {
997 plural = _T("rows");
998 single = _T("row");
999 }
1000 else // columns
1001 {
1002 plural = _T("columns");
1003 single = _T("column");
1004 }
1005
1006 const wxArrayInt sels((const wxArrayInt)(rows ? grid->GetSelectedRows()
1007 : grid->GetSelectedCols()));
1008 size_t count = sels.size();
1009 wxLogMessage(_T("%lu %s selected:"),
1010 (unsigned long)count, plural);
1011 if ( count > countMax )
1012 {
1013 wxLogMessage(_T("[too many selected %s, ")
1014 _T("showing only the first %lu]"),
1015 plural, (unsigned long)countMax);
1016 count = countMax;
1017 }
1018
1019 for ( size_t n = 0; n < count; n++ )
1020 {
1021 wxLogMessage(_T(" selected %s %lu: %d"),
1022 single, (unsigned long)n, sels[n]);
1023 }
1024 }
1025 break;
1026
1027 default:
1028 wxFAIL_MSG( _T("unknown wxGrid selection mode") );
1029 break;
1030 }
1031 }
1032
1033 void GridFrame::OnSelectCell( wxGridEvent& ev )
1034 {
1035 wxString logBuf;
1036 if ( ev.Selecting() )
1037 logBuf << _T("Selected ");
1038 else
1039 logBuf << _T("Deselected ");
1040 logBuf << _T("cell at row ") << ev.GetRow()
1041 << _T(" col ") << ev.GetCol()
1042 << _T(" ( ControlDown: ")<< (ev.ControlDown() ? 'T':'F')
1043 << _T(", ShiftDown: ")<< (ev.ShiftDown() ? 'T':'F')
1044 << _T(", AltDown: ")<< (ev.AltDown() ? 'T':'F')
1045 << _T(", MetaDown: ")<< (ev.MetaDown() ? 'T':'F') << _T(" )");
1046
1047 //Indicate whether this column was moved
1048 if ( ((wxGrid *)ev.GetEventObject())->GetColPos( ev.GetCol() ) != ev.GetCol() )
1049 logBuf << _T(" *** Column moved, current position: ") << ((wxGrid *)ev.GetEventObject())->GetColPos( ev.GetCol() );
1050
1051 wxLogMessage( wxT("%s"), logBuf.c_str() );
1052
1053 // you must call Skip() if you want the default processing
1054 // to occur in wxGrid
1055 ev.Skip();
1056 }
1057
1058 void GridFrame::OnRangeSelected( wxGridRangeSelectEvent& ev )
1059 {
1060 wxString logBuf;
1061 if ( ev.Selecting() )
1062 logBuf << _T("Selected ");
1063 else
1064 logBuf << _T("Deselected ");
1065 logBuf << _T("cells from row ") << ev.GetTopRow()
1066 << _T(" col ") << ev.GetLeftCol()
1067 << _T(" to row ") << ev.GetBottomRow()
1068 << _T(" col ") << ev.GetRightCol()
1069 << _T(" ( ControlDown: ")<< (ev.ControlDown() ? 'T':'F')
1070 << _T(", ShiftDown: ")<< (ev.ShiftDown() ? 'T':'F')
1071 << _T(", AltDown: ")<< (ev.AltDown() ? 'T':'F')
1072 << _T(", MetaDown: ")<< (ev.MetaDown() ? 'T':'F') << _T(" )");
1073 wxLogMessage( wxT("%s"), logBuf.c_str() );
1074
1075 ev.Skip();
1076 }
1077
1078 void GridFrame::OnCellValueChanging( wxGridEvent& ev )
1079 {
1080 int row = ev.GetRow(),
1081 col = ev.GetCol();
1082
1083 wxLogMessage("Value of cell at (%d, %d): about to change "
1084 "from \"%s\" to \"%s\"",
1085 row, col,
1086 grid->GetCellValue(row, col), ev.GetString());
1087
1088 // test how vetoing works
1089 if ( ev.GetString() == "42" )
1090 {
1091 wxLogMessage("Vetoing the change.");
1092 ev.Veto();
1093 return;
1094 }
1095
1096 ev.Skip();
1097 }
1098
1099 void GridFrame::OnCellValueChanged( wxGridEvent& ev )
1100 {
1101 int row = ev.GetRow(),
1102 col = ev.GetCol();
1103
1104 wxLogMessage("Value of cell at (%d, %d) changed and is now \"%s\" "
1105 "(was \"%s\")",
1106 row, col,
1107 grid->GetCellValue(row, col), ev.GetString());
1108
1109 ev.Skip();
1110 }
1111
1112 void GridFrame::OnCellBeginDrag( wxGridEvent& ev )
1113 {
1114 wxLogMessage(_T("Got request to drag cell at row %d, col %d"),
1115 ev.GetRow(), ev.GetCol());
1116
1117 ev.Skip();
1118 }
1119
1120 void GridFrame::OnEditorShown( wxGridEvent& ev )
1121 {
1122
1123 if ( (ev.GetCol() == 4) &&
1124 (ev.GetRow() == 0) &&
1125 (wxMessageBox(_T("Are you sure you wish to edit this cell"),
1126 _T("Checking"),wxYES_NO) == wxNO ) ) {
1127
1128 ev.Veto();
1129 return;
1130 }
1131
1132 wxLogMessage( wxT("Cell editor shown.") );
1133
1134 ev.Skip();
1135 }
1136
1137 void GridFrame::OnEditorHidden( wxGridEvent& ev )
1138 {
1139
1140 if ( (ev.GetCol() == 4) &&
1141 (ev.GetRow() == 0) &&
1142 (wxMessageBox(_T("Are you sure you wish to finish editing this cell"),
1143 _T("Checking"),wxYES_NO) == wxNO ) ) {
1144
1145 ev.Veto();
1146 return;
1147 }
1148
1149 wxLogMessage( wxT("Cell editor hidden.") );
1150
1151 ev.Skip();
1152 }
1153
1154 void GridFrame::About( wxCommandEvent& WXUNUSED(ev) )
1155 {
1156 wxAboutDialogInfo aboutInfo;
1157 aboutInfo.SetName(wxT("wxGrid demo"));
1158 aboutInfo.SetDescription(_("wxGrid sample program"));
1159 aboutInfo.AddDeveloper(wxT("Michael Bedward"));
1160 aboutInfo.AddDeveloper(wxT("Julian Smart"));
1161 aboutInfo.AddDeveloper(wxT("Vadim Zeitlin"));
1162
1163 // this is just to force the generic version of the about
1164 // dialog under wxMSW so that it's easy to test if the grid
1165 // repaints correctly when it has lost focus and a dialog
1166 // (different from the Windows standard message box -- it doesn't
1167 // work with it for some reason) is moved over it.
1168 aboutInfo.SetWebSite(wxT("http://www.wxwidgets.org"));
1169
1170 wxAboutBox(aboutInfo);
1171 }
1172
1173
1174 void GridFrame::OnQuit( wxCommandEvent& WXUNUSED(ev) )
1175 {
1176 Close( true );
1177 }
1178
1179 void GridFrame::OnBugsTable(wxCommandEvent& )
1180 {
1181 BugsGridFrame *frame = new BugsGridFrame;
1182 frame->Show(true);
1183 }
1184
1185 // ----------------------------------------------------------------------------
1186 // MyGridCellAttrProvider
1187 // ----------------------------------------------------------------------------
1188
1189 MyGridCellAttrProvider::MyGridCellAttrProvider()
1190 {
1191 m_attrForOddRows = new wxGridCellAttr;
1192 m_attrForOddRows->SetBackgroundColour(*wxLIGHT_GREY);
1193 }
1194
1195 MyGridCellAttrProvider::~MyGridCellAttrProvider()
1196 {
1197 m_attrForOddRows->DecRef();
1198 }
1199
1200 wxGridCellAttr *MyGridCellAttrProvider::GetAttr(int row, int col,
1201 wxGridCellAttr::wxAttrKind kind /* = wxGridCellAttr::Any */) const
1202 {
1203 wxGridCellAttr *attr = wxGridCellAttrProvider::GetAttr(row, col, kind);
1204
1205 if ( row % 2 )
1206 {
1207 if ( !attr )
1208 {
1209 attr = m_attrForOddRows;
1210 attr->IncRef();
1211 }
1212 else
1213 {
1214 if ( !attr->HasBackgroundColour() )
1215 {
1216 wxGridCellAttr *attrNew = attr->Clone();
1217 attr->DecRef();
1218 attr = attrNew;
1219 attr->SetBackgroundColour(*wxLIGHT_GREY);
1220 }
1221 }
1222 }
1223
1224 return attr;
1225 }
1226
1227 void GridFrame::OnVTable(wxCommandEvent& )
1228 {
1229 static long s_sizeGrid = 10000;
1230
1231 s_sizeGrid = wxGetNumberFromUser(_T("Size of the table to create"),
1232 _T("Size: "),
1233 _T("wxGridDemo question"),
1234 s_sizeGrid,
1235 0, 32000, this);
1236
1237 if ( s_sizeGrid != -1 )
1238 {
1239 BigGridFrame* win = new BigGridFrame(s_sizeGrid);
1240 win->Show(true);
1241 }
1242 }
1243
1244 // ----------------------------------------------------------------------------
1245 // MyGridCellRenderer
1246 // ----------------------------------------------------------------------------
1247
1248 // do something that the default renderer doesn't here just to show that it is
1249 // possible to alter the appearance of the cell beyond what the attributes
1250 // allow
1251 void MyGridCellRenderer::Draw(wxGrid& grid,
1252 wxGridCellAttr& attr,
1253 wxDC& dc,
1254 const wxRect& rect,
1255 int row, int col,
1256 bool isSelected)
1257 {
1258 wxGridCellStringRenderer::Draw(grid, attr, dc, rect, row, col, isSelected);
1259
1260 dc.SetPen(*wxGREEN_PEN);
1261 dc.SetBrush(*wxTRANSPARENT_BRUSH);
1262 dc.DrawEllipse(rect);
1263 }
1264
1265 // ============================================================================
1266 // BigGridFrame and BigGridTable: Sample of a non-standard table
1267 // ============================================================================
1268
1269 BigGridFrame::BigGridFrame(long sizeGrid)
1270 : wxFrame(NULL, wxID_ANY, _T("Plugin Virtual Table"),
1271 wxDefaultPosition, wxSize(500, 450))
1272 {
1273 m_grid = new wxGrid(this, wxID_ANY, wxDefaultPosition, wxDefaultSize);
1274 m_table = new BigGridTable(sizeGrid);
1275
1276 // VZ: I don't understand why this slows down the display that much,
1277 // must profile it...
1278 //m_table->SetAttrProvider(new MyGridCellAttrProvider);
1279
1280 m_grid->SetTable(m_table, true);
1281
1282 #if defined __WXMOTIF__
1283 // MB: the grid isn't getting a sensible default size under wxMotif
1284 int cw, ch;
1285 GetClientSize( &cw, &ch );
1286 m_grid->SetSize( cw, ch );
1287 #endif
1288 }
1289
1290 // ============================================================================
1291 // BugsGridFrame: a "realistic" table
1292 // ============================================================================
1293
1294 // ----------------------------------------------------------------------------
1295 // bugs table data
1296 // ----------------------------------------------------------------------------
1297
1298 enum Columns
1299 {
1300 Col_Id,
1301 Col_Summary,
1302 Col_Severity,
1303 Col_Priority,
1304 Col_Platform,
1305 Col_Opened,
1306 Col_Max
1307 };
1308
1309 enum Severity
1310 {
1311 Sev_Wish,
1312 Sev_Minor,
1313 Sev_Normal,
1314 Sev_Major,
1315 Sev_Critical,
1316 Sev_Max
1317 };
1318
1319 static const wxString severities[] =
1320 {
1321 _T("wishlist"),
1322 _T("minor"),
1323 _T("normal"),
1324 _T("major"),
1325 _T("critical"),
1326 };
1327
1328 static struct BugsGridData
1329 {
1330 int id;
1331 wxChar summary[80];
1332 Severity severity;
1333 int prio;
1334 wxChar platform[12];
1335 bool opened;
1336 } gs_dataBugsGrid [] =
1337 {
1338 { 18, _T("foo doesn't work"), Sev_Major, 1, _T("wxMSW"), true },
1339 { 27, _T("bar crashes"), Sev_Critical, 1, _T("all"), false },
1340 { 45, _T("printing is slow"), Sev_Minor, 3, _T("wxMSW"), true },
1341 { 68, _T("Rectangle() fails"), Sev_Normal, 1, _T("wxMSW"), false },
1342 };
1343
1344 static const wxChar *headers[Col_Max] =
1345 {
1346 _T("Id"),
1347 _T("Summary"),
1348 _T("Severity"),
1349 _T("Priority"),
1350 _T("Platform"),
1351 _T("Opened?"),
1352 };
1353
1354 // ----------------------------------------------------------------------------
1355 // BugsGridTable
1356 // ----------------------------------------------------------------------------
1357
1358 wxString BugsGridTable::GetTypeName(int WXUNUSED(row), int col)
1359 {
1360 switch ( col )
1361 {
1362 case Col_Id:
1363 case Col_Priority:
1364 return wxGRID_VALUE_NUMBER;;
1365
1366 case Col_Severity:
1367 // fall thorugh (TODO should be a list)
1368
1369 case Col_Summary:
1370 return wxString::Format(_T("%s:80"), wxGRID_VALUE_STRING);
1371
1372 case Col_Platform:
1373 return wxString::Format(_T("%s:all,MSW,GTK,other"), wxGRID_VALUE_CHOICE);
1374
1375 case Col_Opened:
1376 return wxGRID_VALUE_BOOL;
1377 }
1378
1379 wxFAIL_MSG(_T("unknown column"));
1380
1381 return wxEmptyString;
1382 }
1383
1384 int BugsGridTable::GetNumberRows()
1385 {
1386 return WXSIZEOF(gs_dataBugsGrid);
1387 }
1388
1389 int BugsGridTable::GetNumberCols()
1390 {
1391 return Col_Max;
1392 }
1393
1394 bool BugsGridTable::IsEmptyCell( int WXUNUSED(row), int WXUNUSED(col) )
1395 {
1396 return false;
1397 }
1398
1399 wxString BugsGridTable::GetValue( int row, int col )
1400 {
1401 const BugsGridData& gd = gs_dataBugsGrid[row];
1402
1403 switch ( col )
1404 {
1405 case Col_Id:
1406 return wxString::Format(_T("%d"), gd.id);
1407
1408 case Col_Priority:
1409 return wxString::Format(_T("%d"), gd.prio);
1410
1411 case Col_Opened:
1412 return gd.opened ? _T("1") : _T("0");
1413
1414 case Col_Severity:
1415 return severities[gd.severity];
1416
1417 case Col_Summary:
1418 return gd.summary;
1419
1420 case Col_Platform:
1421 return gd.platform;
1422 }
1423
1424 return wxEmptyString;
1425 }
1426
1427 void BugsGridTable::SetValue( int row, int col, const wxString& value )
1428 {
1429 BugsGridData& gd = gs_dataBugsGrid[row];
1430
1431 switch ( col )
1432 {
1433 case Col_Id:
1434 case Col_Priority:
1435 case Col_Opened:
1436 wxFAIL_MSG(_T("unexpected column"));
1437 break;
1438
1439 case Col_Severity:
1440 {
1441 size_t n;
1442 for ( n = 0; n < WXSIZEOF(severities); n++ )
1443 {
1444 if ( severities[n] == value )
1445 {
1446 gd.severity = (Severity)n;
1447 break;
1448 }
1449 }
1450
1451 if ( n == WXSIZEOF(severities) )
1452 {
1453 wxLogWarning(_T("Invalid severity value '%s'."),
1454 value.c_str());
1455 gd.severity = Sev_Normal;
1456 }
1457 }
1458 break;
1459
1460 case Col_Summary:
1461 wxStrncpy(gd.summary, value, WXSIZEOF(gd.summary));
1462 break;
1463
1464 case Col_Platform:
1465 wxStrncpy(gd.platform, value, WXSIZEOF(gd.platform));
1466 break;
1467 }
1468 }
1469
1470 bool
1471 BugsGridTable::CanGetValueAs(int WXUNUSED(row),
1472 int col,
1473 const wxString& typeName)
1474 {
1475 if ( typeName == wxGRID_VALUE_STRING )
1476 {
1477 return true;
1478 }
1479 else if ( typeName == wxGRID_VALUE_BOOL )
1480 {
1481 return col == Col_Opened;
1482 }
1483 else if ( typeName == wxGRID_VALUE_NUMBER )
1484 {
1485 return col == Col_Id || col == Col_Priority || col == Col_Severity;
1486 }
1487 else
1488 {
1489 return false;
1490 }
1491 }
1492
1493 bool BugsGridTable::CanSetValueAs( int row, int col, const wxString& typeName )
1494 {
1495 return CanGetValueAs(row, col, typeName);
1496 }
1497
1498 long BugsGridTable::GetValueAsLong( int row, int col )
1499 {
1500 const BugsGridData& gd = gs_dataBugsGrid[row];
1501
1502 switch ( col )
1503 {
1504 case Col_Id:
1505 return gd.id;
1506
1507 case Col_Priority:
1508 return gd.prio;
1509
1510 case Col_Severity:
1511 return gd.severity;
1512
1513 default:
1514 wxFAIL_MSG(_T("unexpected column"));
1515 return -1;
1516 }
1517 }
1518
1519 bool BugsGridTable::GetValueAsBool( int row, int col )
1520 {
1521 if ( col == Col_Opened )
1522 {
1523 return gs_dataBugsGrid[row].opened;
1524 }
1525 else
1526 {
1527 wxFAIL_MSG(_T("unexpected column"));
1528
1529 return false;
1530 }
1531 }
1532
1533 void BugsGridTable::SetValueAsLong( int row, int col, long value )
1534 {
1535 BugsGridData& gd = gs_dataBugsGrid[row];
1536
1537 switch ( col )
1538 {
1539 case Col_Priority:
1540 gd.prio = value;
1541 break;
1542
1543 default:
1544 wxFAIL_MSG(_T("unexpected column"));
1545 }
1546 }
1547
1548 void BugsGridTable::SetValueAsBool( int row, int col, bool value )
1549 {
1550 if ( col == Col_Opened )
1551 {
1552 gs_dataBugsGrid[row].opened = value;
1553 }
1554 else
1555 {
1556 wxFAIL_MSG(_T("unexpected column"));
1557 }
1558 }
1559
1560 wxString BugsGridTable::GetColLabelValue( int col )
1561 {
1562 return headers[col];
1563 }
1564
1565 // ----------------------------------------------------------------------------
1566 // BugsGridFrame
1567 // ----------------------------------------------------------------------------
1568
1569 BugsGridFrame::BugsGridFrame()
1570 : wxFrame(NULL, wxID_ANY, _T("Bugs table"))
1571 {
1572 wxGrid *grid = new wxGrid(this, wxID_ANY);
1573 wxGridTableBase *table = new BugsGridTable();
1574 table->SetAttrProvider(new MyGridCellAttrProvider);
1575 grid->SetTable(table, true);
1576
1577 wxGridCellAttr *attrRO = new wxGridCellAttr,
1578 *attrRangeEditor = new wxGridCellAttr,
1579 *attrCombo = new wxGridCellAttr;
1580
1581 attrRO->SetReadOnly();
1582 attrRangeEditor->SetEditor(new wxGridCellNumberEditor(1, 5));
1583 attrCombo->SetEditor(new wxGridCellChoiceEditor(WXSIZEOF(severities),
1584 severities));
1585
1586 grid->SetColAttr(Col_Id, attrRO);
1587 grid->SetColAttr(Col_Priority, attrRangeEditor);
1588 grid->SetColAttr(Col_Severity, attrCombo);
1589
1590 grid->Fit();
1591 SetClientSize(grid->GetSize());
1592 }
1593
1594 // ============================================================================
1595 // TabularGrid: grid used for display of tabular data
1596 // ============================================================================
1597
1598 class TabularGridTable : public wxGridTableBase
1599 {
1600 public:
1601 enum
1602 {
1603 COL_NAME,
1604 COL_EXT,
1605 COL_SIZE,
1606 COL_DATE,
1607 COL_MAX
1608 };
1609
1610 enum
1611 {
1612 ROW_MAX = 3
1613 };
1614
1615 TabularGridTable() { m_sortOrder = NULL; }
1616
1617 virtual int GetNumberRows() { return ROW_MAX; }
1618 virtual int GetNumberCols() { return COL_MAX; }
1619
1620 virtual wxString GetValue(int row, int col)
1621 {
1622 if ( m_sortOrder )
1623 row = m_sortOrder[row];
1624
1625 switch ( col )
1626 {
1627 case COL_NAME:
1628 case COL_EXT:
1629 return GetNameOrExt(row, col);
1630
1631 case COL_SIZE:
1632 return wxString::Format("%lu", GetSize(row));
1633
1634 case COL_DATE:
1635 return GetDate(row).FormatDate();
1636
1637 case COL_MAX:
1638 default:
1639 wxFAIL_MSG( "unknown column" );
1640 }
1641
1642 return wxString();
1643 }
1644
1645 virtual void SetValue(int, int, const wxString&)
1646 {
1647 wxFAIL_MSG( "shouldn't be called" );
1648 }
1649
1650 virtual wxString GetColLabelValue(int col)
1651 {
1652 // notice that column parameter here always refers to the internal
1653 // column index, independently of its position on the screen
1654 static const char *labels[] = { "Name", "Extension", "Size", "Date" };
1655 wxCOMPILE_TIME_ASSERT( WXSIZEOF(labels) == COL_MAX, LabelsMismatch );
1656
1657 return labels[col];
1658 }
1659
1660 virtual void SetColLabelValue(int, const wxString&)
1661 {
1662 wxFAIL_MSG( "shouldn't be called" );
1663 }
1664
1665 void Sort(int col, bool ascending)
1666 {
1667 // we hardcode all sorting orders for simplicity here
1668 static int sortOrders[COL_MAX][2][ROW_MAX] =
1669 {
1670 // descending ascending
1671 { { 2, 1, 0 }, { 0, 1, 2 } },
1672 { { 2, 1, 0 }, { 0, 1, 2 } },
1673 { { 2, 1, 0 }, { 0, 1, 2 } },
1674 { { 1, 0, 2 }, { 2, 0, 1 } },
1675 };
1676
1677 m_sortOrder = col == wxNOT_FOUND ? NULL : sortOrders[col][ascending];
1678 }
1679
1680 private:
1681 wxString GetNameOrExt(int row, int col) const
1682 {
1683 static const char *
1684 names[] = { "autoexec.bat", "boot.ini", "io.sys" };
1685 wxCOMPILE_TIME_ASSERT( WXSIZEOF(names) == ROW_MAX, NamesMismatch );
1686
1687 const wxString s(names[row]);
1688 return col == COL_NAME ? s.BeforeFirst('.') : s.AfterLast('.');
1689 }
1690
1691 unsigned long GetSize(int row) const
1692 {
1693 static const unsigned long
1694 sizes[] = { 412, 604, 40774 };
1695 wxCOMPILE_TIME_ASSERT( WXSIZEOF(sizes) == ROW_MAX, SizesMismatch );
1696
1697 return sizes[row];
1698 }
1699
1700 wxDateTime GetDate(int row) const
1701 {
1702 static const char *
1703 dates[] = { "2004-04-17", "2006-05-27", "1994-05-31" };
1704 wxCOMPILE_TIME_ASSERT( WXSIZEOF(dates) == ROW_MAX, DatesMismatch );
1705
1706 wxDateTime dt;
1707 dt.ParseISODate(dates[row]);
1708 return dt;
1709 }
1710
1711 int *m_sortOrder;
1712 };
1713
1714 // specialized text control for column indexes entry
1715 class ColIndexEntry : public wxTextCtrl
1716 {
1717 public:
1718 ColIndexEntry(wxWindow *parent)
1719 : wxTextCtrl(parent, wxID_ANY, "")
1720 {
1721 SetValidator(wxTextValidator(wxFILTER_NUMERIC));
1722 }
1723
1724 int GetCol()
1725 {
1726 unsigned long col;
1727 if ( !GetValue().ToULong(&col) || col > TabularGridTable::COL_MAX )
1728 {
1729 SetFocus();
1730 return -1;
1731 }
1732
1733 return col;
1734 }
1735
1736 protected:
1737 virtual wxSize DoGetBestSize() const
1738 {
1739 wxSize size = wxTextCtrl::DoGetBestSize();
1740 size.x = 3*GetCharWidth();
1741 return size;
1742 }
1743 };
1744
1745 class TabularGridFrame : public wxFrame
1746 {
1747 public:
1748 TabularGridFrame();
1749
1750 private:
1751 enum // control ids
1752 {
1753 Id_Check_UseNativeHeader,
1754 Id_Check_DrawNativeLabels,
1755 Id_Check_ShowRowLabels,
1756 Id_Check_EnableColMove
1757 };
1758
1759 // event handlers
1760
1761 void OnToggleUseNativeHeader(wxCommandEvent&)
1762 {
1763 m_grid->UseNativeColHeader(m_chkUseNative->IsChecked());
1764 }
1765
1766 void OnUpdateDrawNativeLabelsUI(wxUpdateUIEvent& event)
1767 {
1768 // we don't draw labels at all, native or otherwise, if we use the
1769 // native header control
1770 event.Enable( !m_chkUseNative->GetValue() );
1771 }
1772
1773 void OnToggleDrawNativeLabels(wxCommandEvent&)
1774 {
1775 m_grid->SetUseNativeColLabels(m_chkDrawNative->IsChecked());
1776 }
1777
1778 void OnToggleShowRowLabels(wxCommandEvent&)
1779 {
1780 m_grid->SetRowLabelSize(m_chkShowRowLabels->IsChecked()
1781 ? wxGRID_AUTOSIZE
1782 : 0);
1783 }
1784
1785 void OnToggleColMove(wxCommandEvent&)
1786 {
1787 m_grid->EnableDragColMove(m_chkEnableColMove->IsChecked());
1788 }
1789
1790 void OnShowHideColumn(wxCommandEvent& event)
1791 {
1792 int col = m_txtColShowHide->GetCol();
1793 if ( col != -1 )
1794 {
1795 m_grid->SetColSize(col,
1796 event.GetId() == wxID_ADD ? wxGRID_AUTOSIZE : 0);
1797
1798 UpdateOrderAndVisibility();
1799 }
1800 }
1801
1802 void OnMoveColumn(wxCommandEvent&)
1803 {
1804 int col = m_txtColIndex->GetCol();
1805 int pos = m_txtColPos->GetCol();
1806 if ( col == -1 || pos == -1 )
1807 return;
1808
1809 m_grid->SetColPos(col, pos);
1810
1811 UpdateOrderAndVisibility();
1812 }
1813
1814 void OnResetColumnOrder(wxCommandEvent&)
1815 {
1816 m_grid->ResetColPos();
1817
1818 UpdateOrderAndVisibility();
1819 }
1820
1821 void OnGridColSort(wxGridEvent& event)
1822 {
1823 const int col = event.GetCol();
1824 m_table->Sort(col, !(m_grid->IsSortingBy(col) &&
1825 m_grid->IsSortOrderAscending()));
1826 }
1827
1828 void OnGridColMove(wxGridEvent& event)
1829 {
1830 // can't update it yet as the order hasn't been changed, so do it a bit
1831 // later
1832 m_shouldUpdateOrder = true;
1833
1834 event.Skip();
1835 }
1836
1837 void OnGridColSize(wxGridSizeEvent& event)
1838 {
1839 // we only catch this event to react to the user showing or hiding this
1840 // column using the header control menu and not because we're
1841 // interested in column resizing
1842 UpdateOrderAndVisibility();
1843
1844 event.Skip();
1845 }
1846
1847 void OnIdle(wxIdleEvent& event)
1848 {
1849 if ( m_shouldUpdateOrder )
1850 {
1851 m_shouldUpdateOrder = false;
1852 UpdateOrderAndVisibility();
1853 }
1854
1855 event.Skip();
1856 }
1857
1858 void UpdateOrderAndVisibility()
1859 {
1860 wxString s;
1861 for ( int pos = 0; pos < TabularGridTable::COL_MAX; pos++ )
1862 {
1863 const int col = m_grid->GetColAt(pos);
1864 const bool isHidden = m_grid->GetColSize(col) == 0;
1865
1866 if ( isHidden )
1867 s << '[';
1868 s << col;
1869 if ( isHidden )
1870 s << ']';
1871
1872 s << ' ';
1873 }
1874
1875 m_statOrder->SetLabel(s);
1876 }
1877
1878 // controls
1879 wxGrid *m_grid;
1880 TabularGridTable *m_table;
1881 wxCheckBox *m_chkUseNative,
1882 *m_chkDrawNative,
1883 *m_chkShowRowLabels,
1884 *m_chkEnableColMove;
1885
1886 ColIndexEntry *m_txtColIndex,
1887 *m_txtColPos,
1888 *m_txtColShowHide;
1889
1890 wxStaticText *m_statOrder;
1891
1892 // fla for EVT_IDLE handler
1893 bool m_shouldUpdateOrder;
1894
1895 wxDECLARE_NO_COPY_CLASS(TabularGridFrame);
1896 DECLARE_EVENT_TABLE()
1897 };
1898
1899 BEGIN_EVENT_TABLE(TabularGridFrame, wxFrame)
1900 EVT_CHECKBOX(Id_Check_UseNativeHeader,
1901 TabularGridFrame::OnToggleUseNativeHeader)
1902 EVT_CHECKBOX(Id_Check_DrawNativeLabels,
1903 TabularGridFrame::OnToggleDrawNativeLabels)
1904 EVT_CHECKBOX(Id_Check_ShowRowLabels,
1905 TabularGridFrame::OnToggleShowRowLabels)
1906 EVT_CHECKBOX(Id_Check_EnableColMove,
1907 TabularGridFrame::OnToggleColMove)
1908
1909 EVT_UPDATE_UI(Id_Check_DrawNativeLabels,
1910 TabularGridFrame::OnUpdateDrawNativeLabelsUI)
1911
1912 EVT_BUTTON(wxID_APPLY, TabularGridFrame::OnMoveColumn)
1913 EVT_BUTTON(wxID_RESET, TabularGridFrame::OnResetColumnOrder)
1914 EVT_BUTTON(wxID_ADD, TabularGridFrame::OnShowHideColumn)
1915 EVT_BUTTON(wxID_DELETE, TabularGridFrame::OnShowHideColumn)
1916
1917 EVT_GRID_COL_SORT(TabularGridFrame::OnGridColSort)
1918 EVT_GRID_COL_MOVE(TabularGridFrame::OnGridColMove)
1919 EVT_GRID_COL_SIZE(TabularGridFrame::OnGridColSize)
1920
1921 EVT_IDLE(TabularGridFrame::OnIdle)
1922 END_EVENT_TABLE()
1923
1924 TabularGridFrame::TabularGridFrame()
1925 : wxFrame(NULL, wxID_ANY, "Tabular table")
1926 {
1927 m_shouldUpdateOrder = false;
1928
1929 wxPanel * const panel = new wxPanel(this);
1930
1931 // create and initialize the grid with the specified data
1932 m_table = new TabularGridTable;
1933 m_grid = new wxGrid(panel, wxID_ANY,
1934 wxDefaultPosition, wxDefaultSize,
1935 wxBORDER_STATIC | wxWANTS_CHARS);
1936 m_grid->SetTable(m_table, true, wxGrid::wxGridSelectRows);
1937
1938 m_grid->EnableDragColMove();
1939 m_grid->UseNativeColHeader();
1940 m_grid->HideRowLabels();
1941
1942 // add it and the other controls to the frame
1943 wxSizer * const sizerTop = new wxBoxSizer(wxVERTICAL);
1944 sizerTop->Add(m_grid, wxSizerFlags(1).Expand().Border());
1945
1946 wxSizer * const sizerControls = new wxBoxSizer(wxHORIZONTAL);
1947
1948 wxSizer * const sizerStyles = new wxBoxSizer(wxVERTICAL);
1949 m_chkUseNative = new wxCheckBox(panel, Id_Check_UseNativeHeader,
1950 "&Use native header");
1951 m_chkUseNative->SetValue(true);
1952 sizerStyles->Add(m_chkUseNative, wxSizerFlags().Border());
1953
1954 m_chkDrawNative = new wxCheckBox(panel, Id_Check_DrawNativeLabels,
1955 "&Draw native column labels");
1956 sizerStyles->Add(m_chkDrawNative, wxSizerFlags().Border());
1957
1958 m_chkShowRowLabels = new wxCheckBox(panel, Id_Check_ShowRowLabels,
1959 "Show &row labels");
1960 sizerStyles->Add(m_chkShowRowLabels, wxSizerFlags().Border());
1961
1962 m_chkEnableColMove = new wxCheckBox(panel, Id_Check_EnableColMove,
1963 "Allow column re&ordering");
1964 m_chkEnableColMove->SetValue(true);
1965 sizerStyles->Add(m_chkEnableColMove, wxSizerFlags().Border());
1966 sizerControls->Add(sizerStyles);
1967
1968 sizerControls->AddSpacer(10);
1969
1970 wxSizer * const sizerColumns = new wxBoxSizer(wxVERTICAL);
1971 wxSizer * const sizerMoveCols = new wxBoxSizer(wxHORIZONTAL);
1972 const wxSizerFlags
1973 flagsHorz(wxSizerFlags().Border(wxLEFT | wxRIGHT).Centre());
1974 sizerMoveCols->Add(new wxStaticText(panel, wxID_ANY, "&Move column"),
1975 flagsHorz);
1976 m_txtColIndex = new ColIndexEntry(panel);
1977 sizerMoveCols->Add(m_txtColIndex, flagsHorz);
1978 sizerMoveCols->Add(new wxStaticText(panel, wxID_ANY, "&to"), flagsHorz);
1979 m_txtColPos = new ColIndexEntry(panel);
1980 sizerMoveCols->Add(m_txtColPos, flagsHorz);
1981 sizerMoveCols->Add(new wxButton(panel, wxID_APPLY), flagsHorz);
1982
1983 sizerColumns->Add(sizerMoveCols, wxSizerFlags().Expand().Border(wxBOTTOM));
1984
1985 wxSizer * const sizerShowCols = new wxBoxSizer(wxHORIZONTAL);
1986 sizerShowCols->Add(new wxStaticText(panel, wxID_ANY, "Current order:"),
1987 flagsHorz);
1988 m_statOrder = new wxStaticText(panel, wxID_ANY, "<<< default >>>");
1989 sizerShowCols->Add(m_statOrder, flagsHorz);
1990 sizerShowCols->Add(new wxButton(panel, wxID_RESET, "&Reset order"));
1991 sizerColumns->Add(sizerShowCols, wxSizerFlags().Expand().Border(wxTOP));
1992
1993 wxSizer * const sizerShowHide = new wxBoxSizer(wxHORIZONTAL);
1994 sizerShowHide->Add(new wxStaticText(panel, wxID_ANY, "Show/hide column:"),
1995 flagsHorz);
1996 m_txtColShowHide = new ColIndexEntry(panel);
1997 sizerShowHide->Add(m_txtColShowHide, flagsHorz);
1998 sizerShowHide->Add(new wxButton(panel, wxID_ADD, "&Show"), flagsHorz);
1999 sizerShowHide->Add(new wxButton(panel, wxID_DELETE, "&Hide"), flagsHorz);
2000 sizerColumns->Add(sizerShowHide, wxSizerFlags().Expand().Border(wxTOP));
2001
2002 sizerControls->Add(sizerColumns, wxSizerFlags(1).Expand().Border());
2003
2004 sizerTop->Add(sizerControls, wxSizerFlags().Expand().Border());
2005
2006 panel->SetSizer(sizerTop);
2007
2008 SetClientSize(panel->GetBestSize());
2009 SetSizeHints(GetSize());
2010
2011 Show();
2012 }
2013
2014 void GridFrame::OnTabularTable(wxCommandEvent&)
2015 {
2016 new TabularGridFrame;
2017 }