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 CellOverflow( wxCommandEvent
& );
46 void ResizeCell( wxCommandEvent
& );
47 void SetLabelColour( wxCommandEvent
& );
48 void SetLabelTextColour( wxCommandEvent
& );
49 void SetLabelFont(wxCommandEvent
&);
50 void SetRowLabelHorizAlignment( wxCommandEvent
& );
51 void SetRowLabelVertAlignment( wxCommandEvent
& );
52 void SetColLabelHorizAlignment( wxCommandEvent
& );
53 void SetColLabelVertAlignment( wxCommandEvent
& );
54 void SetGridLineColour( wxCommandEvent
& );
56 void SetCellFgColour(wxCommandEvent
&);
57 void SetCellBgColour(wxCommandEvent
&);
59 void InsertRow( wxCommandEvent
& );
60 void InsertCol( wxCommandEvent
& );
61 void DeleteSelectedRows( wxCommandEvent
& );
62 void DeleteSelectedCols( wxCommandEvent
& );
63 void ClearGrid( wxCommandEvent
& );
64 void SelectCells( wxCommandEvent
& );
65 void SelectRows( wxCommandEvent
& );
66 void SelectCols( wxCommandEvent
& );
68 void DeselectCell(wxCommandEvent
& event
);
69 void DeselectCol(wxCommandEvent
& event
);
70 void DeselectRow(wxCommandEvent
& event
);
71 void DeselectAll(wxCommandEvent
& event
);
72 void SelectCell(wxCommandEvent
& event
);
73 void SelectCol(wxCommandEvent
& event
);
74 void SelectRow(wxCommandEvent
& event
);
75 void SelectAll(wxCommandEvent
& event
);
76 void OnAddToSelectToggle(wxCommandEvent
& event
);
78 void OnLabelLeftClick( wxGridEvent
& );
79 void OnCellLeftClick( wxGridEvent
& );
80 void OnRowSize( wxGridSizeEvent
& );
81 void OnColSize( wxGridSizeEvent
& );
82 void OnSelectCell( wxGridEvent
& );
83 void OnRangeSelected( wxGridRangeSelectEvent
& );
84 void OnCellValueChanged( wxGridEvent
& );
86 void OnEditorShown(wxGridEvent
&);
87 void OnEditorHidden(wxGridEvent
&);
89 void OnSetHighlightWidth(wxCommandEvent
&);
90 void OnSetROHighlightWidth(wxCommandEvent
&);
96 void OnQuit( wxCommandEvent
& );
97 void About( wxCommandEvent
& );
98 void OnVTable( wxCommandEvent
& );
99 void OnBugsTable( wxCommandEvent
& );
100 void OnSmallGrid( wxCommandEvent
& );
104 ID_TOGGLEROWLABELS
= 100,
115 ID_SETLABELTEXTCOLOUR
,
118 ID_ROWLABELHORIZALIGN
,
119 ID_ROWLABELVERTALIGN
,
121 ID_COLLABELHORIZALIGN
,
122 ID_COLLABELVERTALIGN
,
133 ID_SET_CELL_FG_COLOUR
,
134 ID_SET_CELL_BG_COLOUR
,
149 ID_SET_HIGHLIGHT_WIDTH
,
150 ID_SET_RO_HIGHLIGHT_WIDTH
,
157 // add the cells to selection when using commands from select menu?
160 DECLARE_EVENT_TABLE()
163 class MyGridCellRenderer
: public wxGridCellStringRenderer
166 virtual void Draw(wxGrid
& grid
,
167 wxGridCellAttr
& attr
,
174 // ----------------------------------------------------------------------------
175 // demonstration of virtual table which doesn't store all of its data in
177 // ----------------------------------------------------------------------------
179 class BigGridTable
: public wxGridTableBase
182 BigGridTable(long sizeGrid
) { m_sizeGrid
= sizeGrid
; }
184 int GetNumberRows() { return m_sizeGrid
; }
185 int GetNumberCols() { return m_sizeGrid
; }
186 wxString
GetValue( int row
, int col
)
188 return wxString::Format(wxT("(%d, %d)"), row
, col
);
191 void SetValue( int , int , const wxString
& ) { /* ignore */ }
192 bool IsEmptyCell( int , int ) { return FALSE
; }
198 class BigGridFrame
: public wxFrame
201 BigGridFrame(long sizeGrid
);
205 BigGridTable
* m_table
;
208 // ----------------------------------------------------------------------------
209 // an example of custom attr provider: this one makes all odd rows appear grey
210 // ----------------------------------------------------------------------------
212 class MyGridCellAttrProvider
: public wxGridCellAttrProvider
215 MyGridCellAttrProvider();
216 virtual ~MyGridCellAttrProvider();
218 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
219 wxGridCellAttr::wxAttrKind kind
) const;
222 wxGridCellAttr
*m_attrForOddRows
;
225 // ----------------------------------------------------------------------------
226 // another, more realistic, grid example: shows typed columns and more
227 // ----------------------------------------------------------------------------
229 class BugsGridTable
: public wxGridTableBase
234 virtual int GetNumberRows();
235 virtual int GetNumberCols();
236 virtual bool IsEmptyCell( int row
, int col
);
237 virtual wxString
GetValue( int row
, int col
);
238 virtual void SetValue( int row
, int col
, const wxString
& value
);
240 virtual wxString
GetColLabelValue( int col
);
242 virtual wxString
GetTypeName( int row
, int col
);
243 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
244 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
246 virtual long GetValueAsLong( int row
, int col
);
247 virtual bool GetValueAsBool( int row
, int col
);
249 virtual void SetValueAsLong( int row
, int col
, long value
);
250 virtual void SetValueAsBool( int row
, int col
, bool value
);
253 class BugsGridFrame
: public wxFrame