1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: Grid control wxWidgets sample
4 // Author: Michael Bedward
6 // Copyright: (c) Michael Bedward, Julian Smart
7 // Licence: wxWindows licence
8 /////////////////////////////////////////////////////////////////////////////
16 class GridApp
: public wxApp
23 class GridFrame
: public wxFrame
28 wxLogTextCtrl
*logger
;
33 void ToggleRowLabels( wxCommandEvent
& );
34 void ToggleColLabels( wxCommandEvent
& );
35 void ToggleEditing( wxCommandEvent
& );
36 void ToggleRowSizing( wxCommandEvent
& );
37 void ToggleColSizing( wxCommandEvent
& );
38 void ToggleColMoving( wxCommandEvent
& );
39 void ToggleGridSizing( wxCommandEvent
& );
40 void ToggleGridDragCell ( wxCommandEvent
& );
41 void SetNativeColHeader ( wxCommandEvent
& );
42 void SetCustomColHeader( wxCommandEvent
& );
43 void SetDefaultColHeader( wxCommandEvent
& );
44 void SetTabBehaviour( wxCommandEvent
& );
45 void SetTabCustomHandler( wxCommandEvent
& );
46 void ToggleGridLines( wxCommandEvent
& );
47 void AutoSizeCols( wxCommandEvent
& );
48 void CellOverflow( wxCommandEvent
& );
49 void ResizeCell( wxCommandEvent
& );
50 void SetLabelColour( wxCommandEvent
& );
51 void SetLabelTextColour( wxCommandEvent
& );
52 void SetLabelFont(wxCommandEvent
&);
53 void SetRowLabelHorizAlignment( wxCommandEvent
& );
54 void SetRowLabelVertAlignment( wxCommandEvent
& );
55 void SetColLabelHorizAlignment( wxCommandEvent
& );
56 void SetColLabelVertAlignment( wxCommandEvent
& );
57 void SetGridLineColour( wxCommandEvent
& );
59 void SetCellFgColour(wxCommandEvent
&);
60 void SetCellBgColour(wxCommandEvent
&);
62 void InsertRow( wxCommandEvent
& );
63 void InsertCol( wxCommandEvent
& );
64 void DeleteSelectedRows( wxCommandEvent
& );
65 void DeleteSelectedCols( wxCommandEvent
& );
66 void ClearGrid( wxCommandEvent
& );
67 void SelectCells( wxCommandEvent
& );
68 void SelectRows( wxCommandEvent
& );
69 void SelectCols( wxCommandEvent
& );
70 void SelectRowsOrCols( wxCommandEvent
& );
72 void DeselectCell(wxCommandEvent
& event
);
73 void DeselectCol(wxCommandEvent
& event
);
74 void DeselectRow(wxCommandEvent
& event
);
75 void DeselectAll(wxCommandEvent
& event
);
76 void SelectCell(wxCommandEvent
& event
);
77 void SelectCol(wxCommandEvent
& event
);
78 void SelectRow(wxCommandEvent
& event
);
79 void SelectAll(wxCommandEvent
& event
);
80 void OnAddToSelectToggle(wxCommandEvent
& event
);
82 void AutoSizeRow(wxCommandEvent
& event
);
83 void AutoSizeCol(wxCommandEvent
& event
);
84 void AutoSizeRowLabel(wxCommandEvent
& event
);
85 void AutoSizeColLabel(wxCommandEvent
& event
);
86 void AutoSizeLabelsCol(wxCommandEvent
& event
);
87 void AutoSizeLabelsRow(wxCommandEvent
& event
);
88 void AutoSizeTable(wxCommandEvent
& event
);
90 void HideCol(wxCommandEvent
& event
);
91 void ShowCol(wxCommandEvent
& event
);
92 void HideRow(wxCommandEvent
& event
);
93 void ShowRow(wxCommandEvent
& event
);
96 void OnLabelLeftClick( wxGridEvent
& );
97 void OnCellLeftClick( wxGridEvent
& );
98 void OnRowSize( wxGridSizeEvent
& );
99 void OnColSize( wxGridSizeEvent
& );
100 void OnColAutoSize( wxGridSizeEvent
& );
101 void OnSelectCell( wxGridEvent
& );
102 void OnRangeSelected( wxGridRangeSelectEvent
& );
103 void OnCellValueChanging( wxGridEvent
& );
104 void OnCellValueChanged( wxGridEvent
& );
105 void OnCellBeginDrag( wxGridEvent
& );
107 void OnEditorShown(wxGridEvent
&);
108 void OnEditorHidden(wxGridEvent
&);
110 void OnSetHighlightWidth(wxCommandEvent
&);
111 void OnSetROHighlightWidth(wxCommandEvent
&);
113 void OnGridCustomTab(wxGridEvent
& event
);
119 void OnQuit( wxCommandEvent
& );
120 void About( wxCommandEvent
& );
121 void OnVTable( wxCommandEvent
& );
122 void OnBugsTable( wxCommandEvent
& );
123 void OnTabularTable( wxCommandEvent
& );
124 void OnGridRender( wxCommandEvent
& event
);
125 void OnRenderPaint( wxPaintEvent
& event
);
129 ID_TOGGLEROWLABELS
= 100,
136 ID_TOGGLEGRIDDRAGCELL
,
146 ID_SETLABELTEXTCOLOUR
,
149 ID_ROWLABELHORIZALIGN
,
150 ID_ROWLABELVERTALIGN
,
152 ID_COLLABELHORIZALIGN
,
153 ID_COLLABELVERTALIGN
,
172 ID_SET_CELL_FG_COLOUR
,
173 ID_SET_CELL_BG_COLOUR
,
194 ID_SET_HIGHLIGHT_WIDTH
,
195 ID_SET_RO_HIGHLIGHT_WIDTH
,
201 ID_RENDER_GRID_LINES
,
202 ID_RENDER_GRID_BORDER
,
203 ID_RENDER_SELECT_HLIGHT
,
208 ID_RENDER_DEFAULT_SIZE
,
215 // add the cells to selection when using commands from select menu?
218 wxBitmap m_gridBitmap
;
220 DECLARE_EVENT_TABLE()
223 class MyGridCellRenderer
: public wxGridCellStringRenderer
226 virtual void Draw(wxGrid
& grid
,
227 wxGridCellAttr
& attr
,
234 // ----------------------------------------------------------------------------
235 // demonstration of virtual table which doesn't store all of its data in
237 // ----------------------------------------------------------------------------
239 class BigGridTable
: public wxGridTableBase
242 BigGridTable(long sizeGrid
) { m_sizeGrid
= sizeGrid
; }
244 int GetNumberRows() { return m_sizeGrid
; }
245 int GetNumberCols() { return m_sizeGrid
; }
246 wxString
GetValue( int row
, int col
)
248 return wxString::Format(wxT("(%d, %d)"), row
, col
);
251 void SetValue( int , int , const wxString
& ) { /* ignore */ }
252 bool IsEmptyCell( int , int ) { return false; }
258 class BigGridFrame
: public wxFrame
261 BigGridFrame(long sizeGrid
);
265 BigGridTable
* m_table
;
268 // ----------------------------------------------------------------------------
269 // an example of custom attr provider: this one makes all odd rows appear grey
270 // ----------------------------------------------------------------------------
272 class MyGridCellAttrProvider
: public wxGridCellAttrProvider
275 MyGridCellAttrProvider();
276 virtual ~MyGridCellAttrProvider();
278 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
279 wxGridCellAttr::wxAttrKind kind
) const;
282 wxGridCellAttr
*m_attrForOddRows
;
285 // ----------------------------------------------------------------------------
286 // another, more realistic, grid example: shows typed columns and more
287 // ----------------------------------------------------------------------------
289 class BugsGridTable
: public wxGridTableBase
294 virtual int GetNumberRows();
295 virtual int GetNumberCols();
296 virtual bool IsEmptyCell( int row
, int col
);
297 virtual wxString
GetValue( int row
, int col
);
298 virtual void SetValue( int row
, int col
, const wxString
& value
);
300 virtual wxString
GetColLabelValue( int col
);
302 virtual wxString
GetTypeName( int row
, int col
);
303 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
304 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
306 virtual long GetValueAsLong( int row
, int col
);
307 virtual bool GetValueAsBool( int row
, int col
);
309 virtual void SetValueAsLong( int row
, int col
, long value
);
310 virtual void SetValueAsBool( int row
, int col
, bool value
);
313 class BugsGridFrame
: public wxFrame