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