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
& );
113 ID_TOGGLEROWLABELS
= 100,
120 ID_TOGGLEGRIDDRAGCELL
,
126 ID_SETLABELTEXTCOLOUR
,
129 ID_ROWLABELHORIZALIGN
,
130 ID_ROWLABELVERTALIGN
,
132 ID_COLLABELHORIZALIGN
,
133 ID_COLLABELVERTALIGN
,
144 ID_SET_CELL_FG_COLOUR
,
145 ID_SET_CELL_BG_COLOUR
,
167 ID_SET_HIGHLIGHT_WIDTH
,
168 ID_SET_RO_HIGHLIGHT_WIDTH
,
177 // add the cells to selection when using commands from select menu?
180 DECLARE_EVENT_TABLE()
183 class MyGridCellRenderer
: public wxGridCellStringRenderer
186 virtual void Draw(wxGrid
& grid
,
187 wxGridCellAttr
& attr
,
194 // ----------------------------------------------------------------------------
195 // demonstration of virtual table which doesn't store all of its data in
197 // ----------------------------------------------------------------------------
199 class BigGridTable
: public wxGridTableBase
202 BigGridTable(long sizeGrid
) { m_sizeGrid
= sizeGrid
; }
204 int GetNumberRows() { return m_sizeGrid
; }
205 int GetNumberCols() { return m_sizeGrid
; }
206 wxString
GetValue( int row
, int col
)
208 return wxString::Format(wxT("(%d, %d)"), row
, col
);
211 void SetValue( int , int , const wxString
& ) { /* ignore */ }
212 bool IsEmptyCell( int , int ) { return false; }
218 class BigGridFrame
: public wxFrame
221 BigGridFrame(long sizeGrid
);
225 BigGridTable
* m_table
;
228 // ----------------------------------------------------------------------------
229 // an example of custom attr provider: this one makes all odd rows appear grey
230 // ----------------------------------------------------------------------------
232 class MyGridCellAttrProvider
: public wxGridCellAttrProvider
235 MyGridCellAttrProvider();
236 virtual ~MyGridCellAttrProvider();
238 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
239 wxGridCellAttr::wxAttrKind kind
) const;
242 wxGridCellAttr
*m_attrForOddRows
;
245 // ----------------------------------------------------------------------------
246 // another, more realistic, grid example: shows typed columns and more
247 // ----------------------------------------------------------------------------
249 class BugsGridTable
: public wxGridTableBase
254 virtual int GetNumberRows();
255 virtual int GetNumberCols();
256 virtual bool IsEmptyCell( int row
, int col
);
257 virtual wxString
GetValue( int row
, int col
);
258 virtual void SetValue( int row
, int col
, const wxString
& value
);
260 virtual wxString
GetColLabelValue( int col
);
262 virtual wxString
GetTypeName( int row
, int col
);
263 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
264 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
266 virtual long GetValueAsLong( int row
, int col
);
267 virtual bool GetValueAsBool( int row
, int col
);
269 virtual void SetValueAsLong( int row
, int col
, long value
);
270 virtual void SetValueAsBool( int row
, int col
, bool value
);
273 class BugsGridFrame
: public wxFrame