1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Grid control wxWidgets sample
4 // Author: Michael Bedward
7 // Copyright: (c) Michael Bedward, Julian Smart
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
17 class GridApp
: public wxApp
24 class GridFrame
: public wxFrame
29 wxLogTextCtrl
*logger
;
35 void ToggleRowLabels( wxCommandEvent
& );
36 void ToggleColLabels( wxCommandEvent
& );
37 void ToggleEditing( wxCommandEvent
& );
38 void ToggleRowSizing( wxCommandEvent
& );
39 void ToggleColSizing( wxCommandEvent
& );
40 void ToggleGridSizing( wxCommandEvent
& );
41 void ToggleGridLines( wxCommandEvent
& );
42 void AutoSizeCols( wxCommandEvent
& );
43 void CellOverflow( wxCommandEvent
& );
44 void ResizeCell( 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,
113 ID_SETLABELTEXTCOLOUR
,
116 ID_ROWLABELHORIZALIGN
,
117 ID_ROWLABELVERTALIGN
,
119 ID_COLLABELHORIZALIGN
,
120 ID_COLLABELVERTALIGN
,
131 ID_SET_CELL_FG_COLOUR
,
132 ID_SET_CELL_BG_COLOUR
,
147 ID_SET_HIGHLIGHT_WIDTH
,
148 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