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