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 SetNativeColHeader ( wxCommandEvent
& );
43 void SetCustomColHeader( wxCommandEvent
& );
44 void SetDefaultColHeader( wxCommandEvent
& );
45 void ToggleGridLines( wxCommandEvent
& );
46 void AutoSizeCols( wxCommandEvent
& );
47 void CellOverflow( wxCommandEvent
& );
48 void ResizeCell( wxCommandEvent
& );
49 void SetLabelColour( wxCommandEvent
& );
50 void SetLabelTextColour( wxCommandEvent
& );
51 void SetLabelFont(wxCommandEvent
&);
52 void SetRowLabelHorizAlignment( wxCommandEvent
& );
53 void SetRowLabelVertAlignment( wxCommandEvent
& );
54 void SetColLabelHorizAlignment( wxCommandEvent
& );
55 void SetColLabelVertAlignment( wxCommandEvent
& );
56 void SetGridLineColour( wxCommandEvent
& );
58 void SetCellFgColour(wxCommandEvent
&);
59 void SetCellBgColour(wxCommandEvent
&);
61 void InsertRow( wxCommandEvent
& );
62 void InsertCol( wxCommandEvent
& );
63 void DeleteSelectedRows( wxCommandEvent
& );
64 void DeleteSelectedCols( wxCommandEvent
& );
65 void ClearGrid( wxCommandEvent
& );
66 void SelectCells( wxCommandEvent
& );
67 void SelectRows( wxCommandEvent
& );
68 void SelectCols( wxCommandEvent
& );
69 void SelectRowsOrCols( wxCommandEvent
& );
71 void DeselectCell(wxCommandEvent
& event
);
72 void DeselectCol(wxCommandEvent
& event
);
73 void DeselectRow(wxCommandEvent
& event
);
74 void DeselectAll(wxCommandEvent
& event
);
75 void SelectCell(wxCommandEvent
& event
);
76 void SelectCol(wxCommandEvent
& event
);
77 void SelectRow(wxCommandEvent
& event
);
78 void SelectAll(wxCommandEvent
& event
);
79 void OnAddToSelectToggle(wxCommandEvent
& event
);
80 void OnShowSelection(wxCommandEvent
& event
);
82 void AutoSizeRow(wxCommandEvent
& event
);
83 void AutoSizeCol(wxCommandEvent
& event
);
84 void AutoSizeRowLabel(wxCommandEvent
& event
);
85 void AutoSizeColLabel(wxCommandEvent
& event
);
86 void AutoSizeLabelsCol(wxCommandEvent
& event
);
87 void AutoSizeLabelsRow(wxCommandEvent
& event
);
88 void AutoSizeTable(wxCommandEvent
& event
);
90 void OnLabelLeftClick( wxGridEvent
& );
91 void OnCellLeftClick( wxGridEvent
& );
92 void OnRowSize( wxGridSizeEvent
& );
93 void OnColSize( wxGridSizeEvent
& );
94 void OnSelectCell( wxGridEvent
& );
95 void OnRangeSelected( wxGridRangeSelectEvent
& );
96 void OnCellValueChanging( wxGridEvent
& );
97 void OnCellValueChanged( wxGridEvent
& );
98 void OnCellBeginDrag( wxGridEvent
& );
100 void OnEditorShown(wxGridEvent
&);
101 void OnEditorHidden(wxGridEvent
&);
103 void OnSetHighlightWidth(wxCommandEvent
&);
104 void OnSetROHighlightWidth(wxCommandEvent
&);
110 void OnQuit( wxCommandEvent
& );
111 void About( wxCommandEvent
& );
112 void OnVTable( wxCommandEvent
& );
113 void OnBugsTable( wxCommandEvent
& );
114 void OnTabularTable( wxCommandEvent
& );
118 ID_TOGGLEROWLABELS
= 100,
125 ID_TOGGLEGRIDDRAGCELL
,
131 ID_SETLABELTEXTCOLOUR
,
134 ID_ROWLABELHORIZALIGN
,
135 ID_ROWLABELVERTALIGN
,
137 ID_COLLABELHORIZALIGN
,
138 ID_COLLABELVERTALIGN
,
153 ID_SET_CELL_FG_COLOUR
,
154 ID_SET_CELL_BG_COLOUR
,
176 ID_SET_HIGHLIGHT_WIDTH
,
177 ID_SET_RO_HIGHLIGHT_WIDTH
,
186 // add the cells to selection when using commands from select menu?
189 DECLARE_EVENT_TABLE()
192 class MyGridCellRenderer
: public wxGridCellStringRenderer
195 virtual void Draw(wxGrid
& grid
,
196 wxGridCellAttr
& attr
,
203 // ----------------------------------------------------------------------------
204 // demonstration of virtual table which doesn't store all of its data in
206 // ----------------------------------------------------------------------------
208 class BigGridTable
: public wxGridTableBase
211 BigGridTable(long sizeGrid
) { m_sizeGrid
= sizeGrid
; }
213 int GetNumberRows() { return m_sizeGrid
; }
214 int GetNumberCols() { return m_sizeGrid
; }
215 wxString
GetValue( int row
, int col
)
217 return wxString::Format(wxT("(%d, %d)"), row
, col
);
220 void SetValue( int , int , const wxString
& ) { /* ignore */ }
221 bool IsEmptyCell( int , int ) { return false; }
227 class BigGridFrame
: public wxFrame
230 BigGridFrame(long sizeGrid
);
234 BigGridTable
* m_table
;
237 // ----------------------------------------------------------------------------
238 // an example of custom attr provider: this one makes all odd rows appear grey
239 // ----------------------------------------------------------------------------
241 class MyGridCellAttrProvider
: public wxGridCellAttrProvider
244 MyGridCellAttrProvider();
245 virtual ~MyGridCellAttrProvider();
247 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
248 wxGridCellAttr::wxAttrKind kind
) const;
251 wxGridCellAttr
*m_attrForOddRows
;
254 // ----------------------------------------------------------------------------
255 // another, more realistic, grid example: shows typed columns and more
256 // ----------------------------------------------------------------------------
258 class BugsGridTable
: public wxGridTableBase
263 virtual int GetNumberRows();
264 virtual int GetNumberCols();
265 virtual bool IsEmptyCell( int row
, int col
);
266 virtual wxString
GetValue( int row
, int col
);
267 virtual void SetValue( int row
, int col
, const wxString
& value
);
269 virtual wxString
GetColLabelValue( int col
);
271 virtual wxString
GetTypeName( int row
, int col
);
272 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
273 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
275 virtual long GetValueAsLong( int row
, int col
);
276 virtual bool GetValueAsBool( int row
, int col
);
278 virtual void SetValueAsLong( int row
, int col
, long value
);
279 virtual void SetValueAsBool( int row
, int col
, bool value
);
282 class BugsGridFrame
: public wxFrame