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 ToggleNativeHeader ( 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
& );
67 void SelectRowsOrCols( wxCommandEvent
& );
69 void DeselectCell(wxCommandEvent
& event
);
70 void DeselectCol(wxCommandEvent
& event
);
71 void DeselectRow(wxCommandEvent
& event
);
72 void DeselectAll(wxCommandEvent
& event
);
73 void SelectCell(wxCommandEvent
& event
);
74 void SelectCol(wxCommandEvent
& event
);
75 void SelectRow(wxCommandEvent
& event
);
76 void SelectAll(wxCommandEvent
& event
);
77 void OnAddToSelectToggle(wxCommandEvent
& event
);
78 void OnShowSelection(wxCommandEvent
& event
);
80 void AutoSizeRow(wxCommandEvent
& event
);
81 void AutoSizeCol(wxCommandEvent
& event
);
82 void AutoSizeRowLabel(wxCommandEvent
& event
);
83 void AutoSizeColLabel(wxCommandEvent
& event
);
84 void AutoSizeLabelsCol(wxCommandEvent
& event
);
85 void AutoSizeLabelsRow(wxCommandEvent
& event
);
86 void AutoSizeTable(wxCommandEvent
& event
);
88 void OnLabelLeftClick( wxGridEvent
& );
89 void OnCellLeftClick( wxGridEvent
& );
90 void OnRowSize( wxGridSizeEvent
& );
91 void OnColSize( wxGridSizeEvent
& );
92 void OnSelectCell( wxGridEvent
& );
93 void OnRangeSelected( wxGridRangeSelectEvent
& );
94 void OnCellValueChanged( wxGridEvent
& );
95 void OnCellBeginDrag( wxGridEvent
& );
97 void OnEditorShown(wxGridEvent
&);
98 void OnEditorHidden(wxGridEvent
&);
100 void OnSetHighlightWidth(wxCommandEvent
&);
101 void OnSetROHighlightWidth(wxCommandEvent
&);
107 void OnQuit( wxCommandEvent
& );
108 void About( wxCommandEvent
& );
109 void OnVTable( wxCommandEvent
& );
110 void OnBugsTable( wxCommandEvent
& );
111 void OnTabularTable( wxCommandEvent
& );
115 ID_TOGGLEROWLABELS
= 100,
122 ID_TOGGLEGRIDDRAGCELL
,
123 ID_TOGGLENATIVEHEADER
,
129 ID_SETLABELTEXTCOLOUR
,
132 ID_ROWLABELHORIZALIGN
,
133 ID_ROWLABELVERTALIGN
,
135 ID_COLLABELHORIZALIGN
,
136 ID_COLLABELVERTALIGN
,
148 ID_SET_CELL_FG_COLOUR
,
149 ID_SET_CELL_BG_COLOUR
,
171 ID_SET_HIGHLIGHT_WIDTH
,
172 ID_SET_RO_HIGHLIGHT_WIDTH
,
181 // add the cells to selection when using commands from select menu?
184 DECLARE_EVENT_TABLE()
187 class MyGridCellRenderer
: public wxGridCellStringRenderer
190 virtual void Draw(wxGrid
& grid
,
191 wxGridCellAttr
& attr
,
198 // ----------------------------------------------------------------------------
199 // demonstration of virtual table which doesn't store all of its data in
201 // ----------------------------------------------------------------------------
203 class BigGridTable
: public wxGridTableBase
206 BigGridTable(long sizeGrid
) { m_sizeGrid
= sizeGrid
; }
208 int GetNumberRows() { return m_sizeGrid
; }
209 int GetNumberCols() { return m_sizeGrid
; }
210 wxString
GetValue( int row
, int col
)
212 return wxString::Format(wxT("(%d, %d)"), row
, col
);
215 void SetValue( int , int , const wxString
& ) { /* ignore */ }
216 bool IsEmptyCell( int , int ) { return false; }
222 class BigGridFrame
: public wxFrame
225 BigGridFrame(long sizeGrid
);
229 BigGridTable
* m_table
;
232 // ----------------------------------------------------------------------------
233 // an example of custom attr provider: this one makes all odd rows appear grey
234 // ----------------------------------------------------------------------------
236 class MyGridCellAttrProvider
: public wxGridCellAttrProvider
239 MyGridCellAttrProvider();
240 virtual ~MyGridCellAttrProvider();
242 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
243 wxGridCellAttr::wxAttrKind kind
) const;
246 wxGridCellAttr
*m_attrForOddRows
;
249 // ----------------------------------------------------------------------------
250 // another, more realistic, grid example: shows typed columns and more
251 // ----------------------------------------------------------------------------
253 class BugsGridTable
: public wxGridTableBase
258 virtual int GetNumberRows();
259 virtual int GetNumberCols();
260 virtual bool IsEmptyCell( int row
, int col
);
261 virtual wxString
GetValue( int row
, int col
);
262 virtual void SetValue( int row
, int col
, const wxString
& value
);
264 virtual wxString
GetColLabelValue( int col
);
266 virtual wxString
GetTypeName( int row
, int col
);
267 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
268 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
270 virtual long GetValueAsLong( int row
, int col
);
271 virtual bool GetValueAsBool( int row
, int col
);
273 virtual void SetValueAsLong( int row
, int col
, long value
);
274 virtual void SetValueAsBool( int row
, int col
, bool value
);
277 class BugsGridFrame
: public wxFrame