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
;
34 void ToggleRowLabels( wxCommandEvent
& );
35 void ToggleColLabels( wxCommandEvent
& );
36 void ToggleEditing( wxCommandEvent
& );
37 void ToggleRowSizing( wxCommandEvent
& );
38 void ToggleColSizing( wxCommandEvent
& );
39 void ToggleColMoving( wxCommandEvent
& );
40 void ToggleGridSizing( wxCommandEvent
& );
41 void ToggleGridDragCell ( wxCommandEvent
& );
42 void ToggleGridLines( wxCommandEvent
& );
43 void AutoSizeCols( wxCommandEvent
& );
44 void CellOverflow( wxCommandEvent
& );
45 void ResizeCell( wxCommandEvent
& );
46 void SetLabelColour( wxCommandEvent
& );
47 void SetLabelTextColour( wxCommandEvent
& );
48 void SetLabelFont(wxCommandEvent
&);
49 void SetRowLabelHorizAlignment( wxCommandEvent
& );
50 void SetRowLabelVertAlignment( wxCommandEvent
& );
51 void SetColLabelHorizAlignment( wxCommandEvent
& );
52 void SetColLabelVertAlignment( wxCommandEvent
& );
53 void SetGridLineColour( wxCommandEvent
& );
55 void SetCellFgColour(wxCommandEvent
&);
56 void SetCellBgColour(wxCommandEvent
&);
58 void InsertRow( wxCommandEvent
& );
59 void InsertCol( wxCommandEvent
& );
60 void DeleteSelectedRows( wxCommandEvent
& );
61 void DeleteSelectedCols( wxCommandEvent
& );
62 void ClearGrid( wxCommandEvent
& );
63 void SelectCells( wxCommandEvent
& );
64 void SelectRows( wxCommandEvent
& );
65 void SelectCols( wxCommandEvent
& );
67 void DeselectCell(wxCommandEvent
& event
);
68 void DeselectCol(wxCommandEvent
& event
);
69 void DeselectRow(wxCommandEvent
& event
);
70 void DeselectAll(wxCommandEvent
& event
);
71 void SelectCell(wxCommandEvent
& event
);
72 void SelectCol(wxCommandEvent
& event
);
73 void SelectRow(wxCommandEvent
& event
);
74 void SelectAll(wxCommandEvent
& event
);
75 void OnAddToSelectToggle(wxCommandEvent
& event
);
76 void OnShowSelection(wxCommandEvent
& event
);
78 void AutoSizeRow(wxCommandEvent
& event
);
79 void AutoSizeCol(wxCommandEvent
& event
);
80 void AutoSizeRowLabel(wxCommandEvent
& event
);
81 void AutoSizeColLabel(wxCommandEvent
& event
);
82 void AutoSizeLabelsCol(wxCommandEvent
& event
);
83 void AutoSizeLabelsRow(wxCommandEvent
& event
);
84 void AutoSizeTable(wxCommandEvent
& event
);
86 void OnLabelLeftClick( wxGridEvent
& );
87 void OnCellLeftClick( wxGridEvent
& );
88 void OnRowSize( wxGridSizeEvent
& );
89 void OnColSize( wxGridSizeEvent
& );
90 void OnSelectCell( wxGridEvent
& );
91 void OnRangeSelected( wxGridRangeSelectEvent
& );
92 void OnCellValueChanged( wxGridEvent
& );
93 void OnCellBeginDrag( wxGridEvent
& );
95 void OnEditorShown(wxGridEvent
&);
96 void OnEditorHidden(wxGridEvent
&);
98 void OnSetHighlightWidth(wxCommandEvent
&);
99 void OnSetROHighlightWidth(wxCommandEvent
&);
105 void OnQuit( wxCommandEvent
& );
106 void About( wxCommandEvent
& );
107 void OnVTable( wxCommandEvent
& );
108 void OnBugsTable( wxCommandEvent
& );
109 void OnSmallGrid( wxCommandEvent
& );
110 void OnTabularGrid( wxCommandEvent
& );
114 ID_TOGGLEROWLABELS
= 100,
121 ID_TOGGLEGRIDDRAGCELL
,
127 ID_SETLABELTEXTCOLOUR
,
130 ID_ROWLABELHORIZALIGN
,
131 ID_ROWLABELVERTALIGN
,
133 ID_COLLABELHORIZALIGN
,
134 ID_COLLABELVERTALIGN
,
145 ID_SET_CELL_FG_COLOUR
,
146 ID_SET_CELL_BG_COLOUR
,
169 ID_SET_HIGHLIGHT_WIDTH
,
170 ID_SET_RO_HIGHLIGHT_WIDTH
,
179 // add the cells to selection when using commands from select menu?
182 DECLARE_EVENT_TABLE()
185 class MyGridCellRenderer
: public wxGridCellStringRenderer
188 virtual void Draw(wxGrid
& grid
,
189 wxGridCellAttr
& attr
,
196 // ----------------------------------------------------------------------------
197 // demonstration of virtual table which doesn't store all of its data in
199 // ----------------------------------------------------------------------------
201 class BigGridTable
: public wxGridTableBase
204 BigGridTable(long sizeGrid
) { m_sizeGrid
= sizeGrid
; }
206 int GetNumberRows() { return m_sizeGrid
; }
207 int GetNumberCols() { return m_sizeGrid
; }
208 wxString
GetValue( int row
, int col
)
210 return wxString::Format(wxT("(%d, %d)"), row
, col
);
213 void SetValue( int , int , const wxString
& ) { /* ignore */ }
214 bool IsEmptyCell( int , int ) { return false; }
220 class BigGridFrame
: public wxFrame
223 BigGridFrame(long sizeGrid
);
227 BigGridTable
* m_table
;
230 // ----------------------------------------------------------------------------
231 // an example of custom attr provider: this one makes all odd rows appear grey
232 // ----------------------------------------------------------------------------
234 class MyGridCellAttrProvider
: public wxGridCellAttrProvider
237 MyGridCellAttrProvider();
238 virtual ~MyGridCellAttrProvider();
240 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
241 wxGridCellAttr::wxAttrKind kind
) const;
244 wxGridCellAttr
*m_attrForOddRows
;
247 // ----------------------------------------------------------------------------
248 // another, more realistic, grid example: shows typed columns and more
249 // ----------------------------------------------------------------------------
251 class BugsGridTable
: public wxGridTableBase
256 virtual int GetNumberRows();
257 virtual int GetNumberCols();
258 virtual bool IsEmptyCell( int row
, int col
);
259 virtual wxString
GetValue( int row
, int col
);
260 virtual void SetValue( int row
, int col
, const wxString
& value
);
262 virtual wxString
GetColLabelValue( int col
);
264 virtual wxString
GetTypeName( int row
, int col
);
265 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
266 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
268 virtual long GetValueAsLong( int row
, int col
);
269 virtual bool GetValueAsBool( int row
, int col
);
271 virtual void SetValueAsLong( int row
, int col
, long value
);
272 virtual void SetValueAsBool( int row
, int col
, bool value
);
275 class BugsGridFrame
: public wxFrame