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 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
);
77 void OnLabelLeftClick( wxGridEvent
& );
78 void OnCellLeftClick( wxGridEvent
& );
79 void OnRowSize( wxGridSizeEvent
& );
80 void OnColSize( wxGridSizeEvent
& );
81 void OnSelectCell( wxGridEvent
& );
82 void OnRangeSelected( wxGridRangeSelectEvent
& );
83 void OnCellValueChanged( wxGridEvent
& );
84 void OnCellBeginDrag( wxGridEvent
& );
86 void OnEditorShown(wxGridEvent
&);
87 void OnEditorHidden(wxGridEvent
&);
89 void OnSetHighlightWidth(wxCommandEvent
&);
90 void OnSetROHighlightWidth(wxCommandEvent
&);
96 void OnQuit( wxCommandEvent
& );
97 void About( wxCommandEvent
& );
98 void OnVTable( wxCommandEvent
& );
99 void OnBugsTable( wxCommandEvent
& );
100 void OnSmallGrid( wxCommandEvent
& );
104 ID_TOGGLEROWLABELS
= 100,
110 ID_TOGGLEGRIDDRAGCELL
,
116 ID_SETLABELTEXTCOLOUR
,
119 ID_ROWLABELHORIZALIGN
,
120 ID_ROWLABELVERTALIGN
,
122 ID_COLLABELHORIZALIGN
,
123 ID_COLLABELVERTALIGN
,
134 ID_SET_CELL_FG_COLOUR
,
135 ID_SET_CELL_BG_COLOUR
,
149 ID_SET_HIGHLIGHT_WIDTH
,
150 ID_SET_RO_HIGHLIGHT_WIDTH
,
159 // add the cells to selection when using commands from select menu?
162 DECLARE_EVENT_TABLE()
165 class MyGridCellRenderer
: public wxGridCellStringRenderer
168 virtual void Draw(wxGrid
& grid
,
169 wxGridCellAttr
& attr
,
176 // ----------------------------------------------------------------------------
177 // demonstration of virtual table which doesn't store all of its data in
179 // ----------------------------------------------------------------------------
181 class BigGridTable
: public wxGridTableBase
184 BigGridTable(long sizeGrid
) { m_sizeGrid
= sizeGrid
; }
186 int GetNumberRows() { return m_sizeGrid
; }
187 int GetNumberCols() { return m_sizeGrid
; }
188 wxString
GetValue( int row
, int col
)
190 return wxString::Format(wxT("(%d, %d)"), row
, col
);
193 void SetValue( int , int , const wxString
& ) { /* ignore */ }
194 bool IsEmptyCell( int , int ) { return false; }
200 class BigGridFrame
: public wxFrame
203 BigGridFrame(long sizeGrid
);
207 BigGridTable
* m_table
;
210 // ----------------------------------------------------------------------------
211 // an example of custom attr provider: this one makes all odd rows appear grey
212 // ----------------------------------------------------------------------------
214 class MyGridCellAttrProvider
: public wxGridCellAttrProvider
217 MyGridCellAttrProvider();
218 virtual ~MyGridCellAttrProvider();
220 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
221 wxGridCellAttr::wxAttrKind kind
) const;
224 wxGridCellAttr
*m_attrForOddRows
;
227 // ----------------------------------------------------------------------------
228 // another, more realistic, grid example: shows typed columns and more
229 // ----------------------------------------------------------------------------
231 class BugsGridTable
: public wxGridTableBase
236 virtual int GetNumberRows();
237 virtual int GetNumberCols();
238 virtual bool IsEmptyCell( int row
, int col
);
239 virtual wxString
GetValue( int row
, int col
);
240 virtual void SetValue( int row
, int col
, const wxString
& value
);
242 virtual wxString
GetColLabelValue( int col
);
244 virtual wxString
GetTypeName( int row
, int col
);
245 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
246 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
248 virtual long GetValueAsLong( int row
, int col
);
249 virtual bool GetValueAsBool( int row
, int col
);
251 virtual void SetValueAsLong( int row
, int col
, long value
);
252 virtual void SetValueAsBool( int row
, int col
, bool value
);
255 class BugsGridFrame
: public wxFrame