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 ToggleColMoving( wxCommandEvent
& );
41 void ToggleGridSizing( wxCommandEvent
& );
42 void ToggleGridDragCell ( 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
& );
68 void DeselectCell(wxCommandEvent
& event
);
69 void DeselectCol(wxCommandEvent
& event
);
70 void DeselectRow(wxCommandEvent
& event
);
71 void DeselectAll(wxCommandEvent
& event
);
72 void SelectCell(wxCommandEvent
& event
);
73 void SelectCol(wxCommandEvent
& event
);
74 void SelectRow(wxCommandEvent
& event
);
75 void SelectAll(wxCommandEvent
& event
);
76 void OnAddToSelectToggle(wxCommandEvent
& event
);
77 void OnShowSelection(wxCommandEvent
& event
);
79 void OnLabelLeftClick( wxGridEvent
& );
80 void OnCellLeftClick( wxGridEvent
& );
81 void OnRowSize( wxGridSizeEvent
& );
82 void OnColSize( wxGridSizeEvent
& );
83 void OnSelectCell( wxGridEvent
& );
84 void OnRangeSelected( wxGridRangeSelectEvent
& );
85 void OnCellValueChanged( wxGridEvent
& );
86 void OnCellBeginDrag( wxGridEvent
& );
88 void OnEditorShown(wxGridEvent
&);
89 void OnEditorHidden(wxGridEvent
&);
91 void OnSetHighlightWidth(wxCommandEvent
&);
92 void OnSetROHighlightWidth(wxCommandEvent
&);
98 void OnQuit( wxCommandEvent
& );
99 void About( wxCommandEvent
& );
100 void OnVTable( wxCommandEvent
& );
101 void OnBugsTable( wxCommandEvent
& );
102 void OnSmallGrid( wxCommandEvent
& );
106 ID_TOGGLEROWLABELS
= 100,
113 ID_TOGGLEGRIDDRAGCELL
,
119 ID_SETLABELTEXTCOLOUR
,
122 ID_ROWLABELHORIZALIGN
,
123 ID_ROWLABELVERTALIGN
,
125 ID_COLLABELHORIZALIGN
,
126 ID_COLLABELVERTALIGN
,
137 ID_SET_CELL_FG_COLOUR
,
138 ID_SET_CELL_BG_COLOUR
,
153 ID_SET_HIGHLIGHT_WIDTH
,
154 ID_SET_RO_HIGHLIGHT_WIDTH
,
163 // add the cells to selection when using commands from select menu?
166 DECLARE_EVENT_TABLE()
169 class MyGridCellRenderer
: public wxGridCellStringRenderer
172 virtual void Draw(wxGrid
& grid
,
173 wxGridCellAttr
& attr
,
180 // ----------------------------------------------------------------------------
181 // demonstration of virtual table which doesn't store all of its data in
183 // ----------------------------------------------------------------------------
185 class BigGridTable
: public wxGridTableBase
188 BigGridTable(long sizeGrid
) { m_sizeGrid
= sizeGrid
; }
190 int GetNumberRows() { return m_sizeGrid
; }
191 int GetNumberCols() { return m_sizeGrid
; }
192 wxString
GetValue( int row
, int col
)
194 return wxString::Format(wxT("(%d, %d)"), row
, col
);
197 void SetValue( int , int , const wxString
& ) { /* ignore */ }
198 bool IsEmptyCell( int , int ) { return false; }
204 class BigGridFrame
: public wxFrame
207 BigGridFrame(long sizeGrid
);
211 BigGridTable
* m_table
;
214 // ----------------------------------------------------------------------------
215 // an example of custom attr provider: this one makes all odd rows appear grey
216 // ----------------------------------------------------------------------------
218 class MyGridCellAttrProvider
: public wxGridCellAttrProvider
221 MyGridCellAttrProvider();
222 virtual ~MyGridCellAttrProvider();
224 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
225 wxGridCellAttr::wxAttrKind kind
) const;
228 wxGridCellAttr
*m_attrForOddRows
;
231 // ----------------------------------------------------------------------------
232 // another, more realistic, grid example: shows typed columns and more
233 // ----------------------------------------------------------------------------
235 class BugsGridTable
: public wxGridTableBase
240 virtual int GetNumberRows();
241 virtual int GetNumberCols();
242 virtual bool IsEmptyCell( int row
, int col
);
243 virtual wxString
GetValue( int row
, int col
);
244 virtual void SetValue( int row
, int col
, const wxString
& value
);
246 virtual wxString
GetColLabelValue( int col
);
248 virtual wxString
GetTypeName( int row
, int col
);
249 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
250 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
252 virtual long GetValueAsLong( int row
, int col
);
253 virtual bool GetValueAsBool( int row
, int col
);
255 virtual void SetValueAsLong( int row
, int col
, long value
);
256 virtual void SetValueAsBool( int row
, int col
, bool value
);
259 class BugsGridFrame
: public wxFrame