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