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