1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Grid control wxWindows sample
4 // Author: Michael Bedward
7 // Copyright: (c) Michael Bedward, Julian Smart
8 // Licence: wxWindows license
9 /////////////////////////////////////////////////////////////////////////////
15 #if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
16 #error "This sample requires the new wxGrid class."
21 class GridApp
: public wxApp
28 class GridFrame
: public wxFrame
32 wxLogTextCtrl
*logger
;
37 void ToggleRowLabels( wxCommandEvent
& );
38 void ToggleColLabels( wxCommandEvent
& );
39 void ToggleEditing( wxCommandEvent
& );
40 void ToggleRowSizing( wxCommandEvent
& );
41 void ToggleColSizing( wxCommandEvent
& );
42 void ToggleGridSizing( wxCommandEvent
& );
43 void ToggleGridLines( wxCommandEvent
& );
44 void AutoSizeCols( wxCommandEvent
& );
45 void SetLabelColour( wxCommandEvent
& );
46 void SetLabelTextColour( wxCommandEvent
& );
47 void SetRowLabelHorizAlignment( wxCommandEvent
& );
48 void SetRowLabelVertAlignment( wxCommandEvent
& );
49 void SetColLabelHorizAlignment( wxCommandEvent
& );
50 void SetColLabelVertAlignment( wxCommandEvent
& );
51 void SetGridLineColour( wxCommandEvent
& );
53 void SetCellFgColour(wxCommandEvent
&);
54 void SetCellBgColour(wxCommandEvent
&);
56 void InsertRow( wxCommandEvent
& );
57 void InsertCol( wxCommandEvent
& );
58 void DeleteSelectedRows( wxCommandEvent
& );
59 void DeleteSelectedCols( wxCommandEvent
& );
60 void ClearGrid( wxCommandEvent
& );
61 void SelectCells( wxCommandEvent
& );
62 void SelectRows( wxCommandEvent
& );
63 void SelectCols( wxCommandEvent
& );
65 void DeselectCell(wxCommandEvent
& event
);
66 void DeselectCol(wxCommandEvent
& event
);
67 void DeselectRow(wxCommandEvent
& event
);
68 void DeselectAll(wxCommandEvent
& event
);
69 void SelectCell(wxCommandEvent
& event
);
70 void SelectCol(wxCommandEvent
& event
);
71 void SelectRow(wxCommandEvent
& event
);
72 void SelectAll(wxCommandEvent
& event
);
73 void OnAddToSelectToggle(wxCommandEvent
& event
);
75 void OnLabelLeftClick( wxGridEvent
& );
76 void OnCellLeftClick( wxGridEvent
& );
77 void OnRowSize( wxGridSizeEvent
& );
78 void OnColSize( wxGridSizeEvent
& );
79 void OnSelectCell( wxGridEvent
& );
80 void OnRangeSelected( wxGridRangeSelectEvent
& );
81 void OnCellValueChanged( wxGridEvent
& );
83 void OnEditorShown(wxGridEvent
&);
84 void OnEditorHidden(wxGridEvent
&);
86 void OnSetHighlightWidth(wxCommandEvent
&);
87 void OnSetROHighlightWidth(wxCommandEvent
&);
93 void OnQuit( wxCommandEvent
& );
94 void About( wxCommandEvent
& );
95 void OnVTable( wxCommandEvent
& );
96 void OnBugsTable( wxCommandEvent
& );
100 ID_TOGGLEROWLABELS
= 100,
109 ID_SETLABELTEXTCOLOUR
,
111 ID_ROWLABELHORIZALIGN
,
112 ID_ROWLABELVERTALIGN
,
114 ID_COLLABELHORIZALIGN
,
115 ID_COLLABELVERTALIGN
,
126 ID_SET_CELL_FG_COLOUR
,
127 ID_SET_CELL_BG_COLOUR
,
141 ID_SET_HIGHLIGHT_WIDTH
,
142 ID_SET_RO_HIGHLIGHT_WIDTH
,
149 // add the cells to selection when using commands from select menu?
152 DECLARE_EVENT_TABLE()
155 class MyGridCellRenderer
: public wxGridCellStringRenderer
158 virtual void Draw(wxGrid
& grid
,
159 wxGridCellAttr
& attr
,
166 // ----------------------------------------------------------------------------
167 // demonstration of virtual table which doesn't store all of its data in
169 // ----------------------------------------------------------------------------
171 class BigGridTable
: public wxGridTableBase
174 BigGridTable(long sizeGrid
) { m_sizeGrid
= sizeGrid
; }
176 int GetNumberRows() { return m_sizeGrid
; }
177 int GetNumberCols() { return m_sizeGrid
; }
178 wxString
GetValue( int row
, int col
)
180 return wxString::Format("(%d, %d)", row
, col
);
183 void SetValue( int , int , const wxString
& ) { /* ignore */ }
184 bool IsEmptyCell( int , int ) { return FALSE
; }
190 class BigGridFrame
: public wxFrame
193 BigGridFrame(long sizeGrid
);
197 BigGridTable
* m_table
;
200 // ----------------------------------------------------------------------------
201 // an example of custom attr provider: this one makes all odd rows appear grey
202 // ----------------------------------------------------------------------------
204 class MyGridCellAttrProvider
: public wxGridCellAttrProvider
207 MyGridCellAttrProvider();
208 virtual ~MyGridCellAttrProvider();
210 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
211 wxGridCellAttr::wxAttrKind kind
/* = wxGridCellAttr::Any */) const;
214 wxGridCellAttr
*m_attrForOddRows
;
217 // ----------------------------------------------------------------------------
218 // another, more realistic, grid example: shows typed columns and more
219 // ----------------------------------------------------------------------------
221 class BugsGridTable
: public wxGridTableBase
226 virtual int GetNumberRows();
227 virtual int GetNumberCols();
228 virtual bool IsEmptyCell( int row
, int col
);
229 virtual wxString
GetValue( int row
, int col
);
230 virtual void SetValue( int row
, int col
, const wxString
& value
);
232 virtual wxString
GetColLabelValue( int col
);
234 virtual wxString
GetTypeName( int row
, int col
);
235 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
236 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
238 virtual long GetValueAsLong( int row
, int col
);
239 virtual bool GetValueAsBool( int row
, int col
);
241 virtual void SetValueAsLong( int row
, int col
, long value
);
242 virtual void SetValueAsBool( int row
, int col
, bool value
);
245 class BugsGridFrame
: public wxFrame