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 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