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 OnLabelLeftClick( wxGridEvent
& );
79 void OnCellLeftClick( wxGridEvent
& );
80 void OnRowSize( wxGridSizeEvent
& );
81 void OnColSize( wxGridSizeEvent
& );
82 void OnSelectCell( wxGridEvent
& );
83 void OnRangeSelected( wxGridRangeSelectEvent
& );
84 void OnCellValueChanged( wxGridEvent
& );
85 void OnCellBeginDrag( wxGridEvent
& );
87 void OnEditorShown(wxGridEvent
&);
88 void OnEditorHidden(wxGridEvent
&);
90 void OnSetHighlightWidth(wxCommandEvent
&);
91 void OnSetROHighlightWidth(wxCommandEvent
&);
97 void OnQuit( wxCommandEvent
& );
98 void About( wxCommandEvent
& );
99 void OnVTable( wxCommandEvent
& );
100 void OnBugsTable( wxCommandEvent
& );
101 void OnSmallGrid( wxCommandEvent
& );
105 ID_TOGGLEROWLABELS
= 100,
112 ID_TOGGLEGRIDDRAGCELL
,
118 ID_SETLABELTEXTCOLOUR
,
121 ID_ROWLABELHORIZALIGN
,
122 ID_ROWLABELVERTALIGN
,
124 ID_COLLABELHORIZALIGN
,
125 ID_COLLABELVERTALIGN
,
136 ID_SET_CELL_FG_COLOUR
,
137 ID_SET_CELL_BG_COLOUR
,
152 ID_SET_HIGHLIGHT_WIDTH
,
153 ID_SET_RO_HIGHLIGHT_WIDTH
,
162 // add the cells to selection when using commands from select menu?
165 DECLARE_EVENT_TABLE()
168 class MyGridCellRenderer
: public wxGridCellStringRenderer
171 virtual void Draw(wxGrid
& grid
,
172 wxGridCellAttr
& attr
,
179 // ----------------------------------------------------------------------------
180 // demonstration of virtual table which doesn't store all of its data in
182 // ----------------------------------------------------------------------------
184 class BigGridTable
: public wxGridTableBase
187 BigGridTable(long sizeGrid
) { m_sizeGrid
= sizeGrid
; }
189 int GetNumberRows() { return m_sizeGrid
; }
190 int GetNumberCols() { return m_sizeGrid
; }
191 wxString
GetValue( int row
, int col
)
193 return wxString::Format(wxT("(%d, %d)"), row
, col
);
196 void SetValue( int , int , const wxString
& ) { /* ignore */ }
197 bool IsEmptyCell( int , int ) { return false; }
203 class BigGridFrame
: public wxFrame
206 BigGridFrame(long sizeGrid
);
210 BigGridTable
* m_table
;
213 // ----------------------------------------------------------------------------
214 // an example of custom attr provider: this one makes all odd rows appear grey
215 // ----------------------------------------------------------------------------
217 class MyGridCellAttrProvider
: public wxGridCellAttrProvider
220 MyGridCellAttrProvider();
221 virtual ~MyGridCellAttrProvider();
223 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
224 wxGridCellAttr::wxAttrKind kind
) const;
227 wxGridCellAttr
*m_attrForOddRows
;
230 // ----------------------------------------------------------------------------
231 // another, more realistic, grid example: shows typed columns and more
232 // ----------------------------------------------------------------------------
234 class BugsGridTable
: public wxGridTableBase
239 virtual int GetNumberRows();
240 virtual int GetNumberCols();
241 virtual bool IsEmptyCell( int row
, int col
);
242 virtual wxString
GetValue( int row
, int col
);
243 virtual void SetValue( int row
, int col
, const wxString
& value
);
245 virtual wxString
GetColLabelValue( int col
);
247 virtual wxString
GetTypeName( int row
, int col
);
248 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
249 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
251 virtual long GetValueAsLong( int row
, int col
);
252 virtual bool GetValueAsBool( int row
, int col
);
254 virtual void SetValueAsLong( int row
, int col
, long value
);
255 virtual void SetValueAsBool( int row
, int col
, bool value
);
258 class BugsGridFrame
: public wxFrame