1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Grid control wxWidgets sample
4 // Author: Michael Bedward
7 // Copyright: (c) Michael Bedward, Julian Smart
8 // Licence: wxWindows licence
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 SetNativeColHeader ( wxCommandEvent
& );
43 void SetCustomColHeader( wxCommandEvent
& );
44 void SetDefaultColHeader( wxCommandEvent
& );
45 void SetTabBehaviour( wxCommandEvent
& );
46 void SetTabCustomHandler( wxCommandEvent
& );
47 void ToggleGridLines( wxCommandEvent
& );
48 void AutoSizeCols( wxCommandEvent
& );
49 void CellOverflow( wxCommandEvent
& );
50 void ResizeCell( wxCommandEvent
& );
51 void SetLabelColour( wxCommandEvent
& );
52 void SetLabelTextColour( wxCommandEvent
& );
53 void SetLabelFont(wxCommandEvent
&);
54 void SetRowLabelHorizAlignment( wxCommandEvent
& );
55 void SetRowLabelVertAlignment( wxCommandEvent
& );
56 void SetColLabelHorizAlignment( wxCommandEvent
& );
57 void SetColLabelVertAlignment( wxCommandEvent
& );
58 void SetGridLineColour( wxCommandEvent
& );
60 void SetCellFgColour(wxCommandEvent
&);
61 void SetCellBgColour(wxCommandEvent
&);
63 void InsertRow( wxCommandEvent
& );
64 void InsertCol( wxCommandEvent
& );
65 void DeleteSelectedRows( wxCommandEvent
& );
66 void DeleteSelectedCols( wxCommandEvent
& );
67 void ClearGrid( wxCommandEvent
& );
68 void SelectCells( wxCommandEvent
& );
69 void SelectRows( wxCommandEvent
& );
70 void SelectCols( wxCommandEvent
& );
71 void SelectRowsOrCols( wxCommandEvent
& );
73 void DeselectCell(wxCommandEvent
& event
);
74 void DeselectCol(wxCommandEvent
& event
);
75 void DeselectRow(wxCommandEvent
& event
);
76 void DeselectAll(wxCommandEvent
& event
);
77 void SelectCell(wxCommandEvent
& event
);
78 void SelectCol(wxCommandEvent
& event
);
79 void SelectRow(wxCommandEvent
& event
);
80 void SelectAll(wxCommandEvent
& event
);
81 void OnAddToSelectToggle(wxCommandEvent
& event
);
83 void AutoSizeRow(wxCommandEvent
& event
);
84 void AutoSizeCol(wxCommandEvent
& event
);
85 void AutoSizeRowLabel(wxCommandEvent
& event
);
86 void AutoSizeColLabel(wxCommandEvent
& event
);
87 void AutoSizeLabelsCol(wxCommandEvent
& event
);
88 void AutoSizeLabelsRow(wxCommandEvent
& event
);
89 void AutoSizeTable(wxCommandEvent
& event
);
91 void HideCol(wxCommandEvent
& event
);
92 void ShowCol(wxCommandEvent
& event
);
93 void HideRow(wxCommandEvent
& event
);
94 void ShowRow(wxCommandEvent
& event
);
97 void OnLabelLeftClick( wxGridEvent
& );
98 void OnCellLeftClick( wxGridEvent
& );
99 void OnRowSize( wxGridSizeEvent
& );
100 void OnColSize( wxGridSizeEvent
& );
101 void OnColAutoSize( wxGridSizeEvent
& );
102 void OnSelectCell( wxGridEvent
& );
103 void OnRangeSelected( wxGridRangeSelectEvent
& );
104 void OnCellValueChanging( wxGridEvent
& );
105 void OnCellValueChanged( wxGridEvent
& );
106 void OnCellBeginDrag( wxGridEvent
& );
108 void OnEditorShown(wxGridEvent
&);
109 void OnEditorHidden(wxGridEvent
&);
111 void OnSetHighlightWidth(wxCommandEvent
&);
112 void OnSetROHighlightWidth(wxCommandEvent
&);
114 void OnGridCustomTab(wxGridEvent
& event
);
120 void OnQuit( wxCommandEvent
& );
121 void About( wxCommandEvent
& );
122 void OnVTable( wxCommandEvent
& );
123 void OnBugsTable( wxCommandEvent
& );
124 void OnTabularTable( wxCommandEvent
& );
125 void OnGridRender( wxCommandEvent
& event
);
126 void OnRenderPaint( wxPaintEvent
& event
);
130 ID_TOGGLEROWLABELS
= 100,
137 ID_TOGGLEGRIDDRAGCELL
,
147 ID_SETLABELTEXTCOLOUR
,
150 ID_ROWLABELHORIZALIGN
,
151 ID_ROWLABELVERTALIGN
,
153 ID_COLLABELHORIZALIGN
,
154 ID_COLLABELVERTALIGN
,
173 ID_SET_CELL_FG_COLOUR
,
174 ID_SET_CELL_BG_COLOUR
,
195 ID_SET_HIGHLIGHT_WIDTH
,
196 ID_SET_RO_HIGHLIGHT_WIDTH
,
202 ID_RENDER_GRID_LINES
,
203 ID_RENDER_GRID_BORDER
,
204 ID_RENDER_SELECT_HLIGHT
,
209 ID_RENDER_DEFAULT_SIZE
,
216 // add the cells to selection when using commands from select menu?
219 wxBitmap m_gridBitmap
;
221 DECLARE_EVENT_TABLE()
224 class MyGridCellRenderer
: public wxGridCellStringRenderer
227 virtual void Draw(wxGrid
& grid
,
228 wxGridCellAttr
& attr
,
235 // ----------------------------------------------------------------------------
236 // demonstration of virtual table which doesn't store all of its data in
238 // ----------------------------------------------------------------------------
240 class BigGridTable
: public wxGridTableBase
243 BigGridTable(long sizeGrid
) { m_sizeGrid
= sizeGrid
; }
245 int GetNumberRows() { return m_sizeGrid
; }
246 int GetNumberCols() { return m_sizeGrid
; }
247 wxString
GetValue( int row
, int col
)
249 return wxString::Format(wxT("(%d, %d)"), row
, col
);
252 void SetValue( int , int , const wxString
& ) { /* ignore */ }
253 bool IsEmptyCell( int , int ) { return false; }
259 class BigGridFrame
: public wxFrame
262 BigGridFrame(long sizeGrid
);
266 BigGridTable
* m_table
;
269 // ----------------------------------------------------------------------------
270 // an example of custom attr provider: this one makes all odd rows appear grey
271 // ----------------------------------------------------------------------------
273 class MyGridCellAttrProvider
: public wxGridCellAttrProvider
276 MyGridCellAttrProvider();
277 virtual ~MyGridCellAttrProvider();
279 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
280 wxGridCellAttr::wxAttrKind kind
) const;
283 wxGridCellAttr
*m_attrForOddRows
;
286 // ----------------------------------------------------------------------------
287 // another, more realistic, grid example: shows typed columns and more
288 // ----------------------------------------------------------------------------
290 class BugsGridTable
: public wxGridTableBase
295 virtual int GetNumberRows();
296 virtual int GetNumberCols();
297 virtual bool IsEmptyCell( int row
, int col
);
298 virtual wxString
GetValue( int row
, int col
);
299 virtual void SetValue( int row
, int col
, const wxString
& value
);
301 virtual wxString
GetColLabelValue( int col
);
303 virtual wxString
GetTypeName( int row
, int col
);
304 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
305 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
307 virtual long GetValueAsLong( int row
, int col
);
308 virtual bool GetValueAsBool( int row
, int col
);
310 virtual void SetValueAsLong( int row
, int col
, long value
);
311 virtual void SetValueAsBool( int row
, int col
, bool value
);
314 class BugsGridFrame
: public wxFrame