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