1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Grid control wxWindows sample
4 // Author: Michael Bedward
7 // Copyright: (c) Michael Bedward, Julian Smart
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
15 #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
16 #error "This sample requires the new wxGrid class."
21 class GridApp
: public wxApp
28 class GridFrame
: public wxFrame
32 wxLogTextCtrl
*logger
;
37 void ToggleRowLabels( wxCommandEvent
& );
38 void ToggleColLabels( wxCommandEvent
& );
39 void ToggleEditing( wxCommandEvent
& );
40 void ToggleRowSizing( wxCommandEvent
& );
41 void ToggleColSizing( wxCommandEvent
& );
42 void ToggleGridSizing( wxCommandEvent
& );
43 void ToggleGridLines( wxCommandEvent
& );
44 void AutoSizeCols( wxCommandEvent
& );
45 void SetLabelColour( wxCommandEvent
& );
46 void SetLabelTextColour( wxCommandEvent
& );
47 void SetLabelFont(wxCommandEvent
&);
48 void SetRowLabelHorizAlignment( wxCommandEvent
& );
49 void SetRowLabelVertAlignment( wxCommandEvent
& );
50 void SetColLabelHorizAlignment( wxCommandEvent
& );
51 void SetColLabelVertAlignment( wxCommandEvent
& );
52 void SetGridLineColour( wxCommandEvent
& );
54 void SetCellFgColour(wxCommandEvent
&);
55 void SetCellBgColour(wxCommandEvent
&);
57 void InsertRow( wxCommandEvent
& );
58 void InsertCol( wxCommandEvent
& );
59 void DeleteSelectedRows( wxCommandEvent
& );
60 void DeleteSelectedCols( wxCommandEvent
& );
61 void ClearGrid( wxCommandEvent
& );
62 void SelectCells( wxCommandEvent
& );
63 void SelectRows( wxCommandEvent
& );
64 void SelectCols( wxCommandEvent
& );
66 void DeselectCell(wxCommandEvent
& event
);
67 void DeselectCol(wxCommandEvent
& event
);
68 void DeselectRow(wxCommandEvent
& event
);
69 void DeselectAll(wxCommandEvent
& event
);
70 void SelectCell(wxCommandEvent
& event
);
71 void SelectCol(wxCommandEvent
& event
);
72 void SelectRow(wxCommandEvent
& event
);
73 void SelectAll(wxCommandEvent
& event
);
74 void OnAddToSelectToggle(wxCommandEvent
& event
);
76 void OnLabelLeftClick( wxGridEvent
& );
77 void OnCellLeftClick( wxGridEvent
& );
78 void OnRowSize( wxGridSizeEvent
& );
79 void OnColSize( wxGridSizeEvent
& );
80 void OnSelectCell( wxGridEvent
& );
81 void OnRangeSelected( wxGridRangeSelectEvent
& );
82 void OnCellValueChanged( wxGridEvent
& );
84 void OnEditorShown(wxGridEvent
&);
85 void OnEditorHidden(wxGridEvent
&);
87 void OnSetHighlightWidth(wxCommandEvent
&);
88 void OnSetROHighlightWidth(wxCommandEvent
&);
94 void OnQuit( wxCommandEvent
& );
95 void About( wxCommandEvent
& );
96 void OnVTable( wxCommandEvent
& );
97 void OnBugsTable( wxCommandEvent
& );
98 void OnSmallGrid( wxCommandEvent
& );
102 ID_TOGGLEROWLABELS
= 100,
111 ID_SETLABELTEXTCOLOUR
,
114 ID_ROWLABELHORIZALIGN
,
115 ID_ROWLABELVERTALIGN
,
117 ID_COLLABELHORIZALIGN
,
118 ID_COLLABELVERTALIGN
,
129 ID_SET_CELL_FG_COLOUR
,
130 ID_SET_CELL_BG_COLOUR
,
145 ID_SET_HIGHLIGHT_WIDTH
,
146 ID_SET_RO_HIGHLIGHT_WIDTH
,
153 // add the cells to selection when using commands from select menu?
156 DECLARE_EVENT_TABLE()
159 class MyGridCellRenderer
: public wxGridCellStringRenderer
162 virtual void Draw(wxGrid
& grid
,
163 wxGridCellAttr
& attr
,
170 // ----------------------------------------------------------------------------
171 // demonstration of virtual table which doesn't store all of its data in
173 // ----------------------------------------------------------------------------
175 class BigGridTable
: public wxGridTableBase
178 BigGridTable(long sizeGrid
) { m_sizeGrid
= sizeGrid
; }
180 int GetNumberRows() { return m_sizeGrid
; }
181 int GetNumberCols() { return m_sizeGrid
; }
182 wxString
GetValue( int row
, int col
)
184 return wxString::Format(wxT("(%d, %d)"), row
, col
);
187 void SetValue( int , int , const wxString
& ) { /* ignore */ }
188 bool IsEmptyCell( int , int ) { return FALSE
; }
194 class BigGridFrame
: public wxFrame
197 BigGridFrame(long sizeGrid
);
201 BigGridTable
* m_table
;
204 // ----------------------------------------------------------------------------
205 // an example of custom attr provider: this one makes all odd rows appear grey
206 // ----------------------------------------------------------------------------
208 class MyGridCellAttrProvider
: public wxGridCellAttrProvider
211 MyGridCellAttrProvider();
212 virtual ~MyGridCellAttrProvider();
214 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
215 wxGridCellAttr::wxAttrKind kind
) const;
218 wxGridCellAttr
*m_attrForOddRows
;
221 // ----------------------------------------------------------------------------
222 // another, more realistic, grid example: shows typed columns and more
223 // ----------------------------------------------------------------------------
225 class BugsGridTable
: public wxGridTableBase
230 virtual int GetNumberRows();
231 virtual int GetNumberCols();
232 virtual bool IsEmptyCell( int row
, int col
);
233 virtual wxString
GetValue( int row
, int col
);
234 virtual void SetValue( int row
, int col
, const wxString
& value
);
236 virtual wxString
GetColLabelValue( int col
);
238 virtual wxString
GetTypeName( int row
, int col
);
239 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
240 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
242 virtual long GetValueAsLong( int row
, int col
);
243 virtual bool GetValueAsBool( int row
, int col
);
245 virtual void SetValueAsLong( int row
, int col
, long value
);
246 virtual void SetValueAsBool( int row
, int col
, bool value
);
249 class BugsGridFrame
: public wxFrame