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 OnLabelLeftClick( wxGridEvent
& );
92 void OnCellLeftClick( wxGridEvent
& );
93 void OnRowSize( wxGridSizeEvent
& );
94 void OnColSize( wxGridSizeEvent
& );
95 void OnSelectCell( wxGridEvent
& );
96 void OnRangeSelected( wxGridRangeSelectEvent
& );
97 void OnCellValueChanging( wxGridEvent
& );
98 void OnCellValueChanged( wxGridEvent
& );
99 void OnCellBeginDrag( wxGridEvent
& );
101 void OnEditorShown(wxGridEvent
&);
102 void OnEditorHidden(wxGridEvent
&);
104 void OnSetHighlightWidth(wxCommandEvent
&);
105 void OnSetROHighlightWidth(wxCommandEvent
&);
107 void OnGridCustomTab(wxGridEvent
& event
);
113 void OnQuit( wxCommandEvent
& );
114 void About( wxCommandEvent
& );
115 void OnVTable( wxCommandEvent
& );
116 void OnBugsTable( wxCommandEvent
& );
117 void OnTabularTable( wxCommandEvent
& );
118 void OnGridRender( wxCommandEvent
& event
);
119 void OnRenderPaint( wxPaintEvent
& event
);
123 ID_TOGGLEROWLABELS
= 100,
130 ID_TOGGLEGRIDDRAGCELL
,
136 ID_SETLABELTEXTCOLOUR
,
139 ID_ROWLABELHORIZALIGN
,
140 ID_ROWLABELVERTALIGN
,
142 ID_COLLABELHORIZALIGN
,
143 ID_COLLABELVERTALIGN
,
162 ID_SET_CELL_FG_COLOUR
,
163 ID_SET_CELL_BG_COLOUR
,
184 ID_SET_HIGHLIGHT_WIDTH
,
185 ID_SET_RO_HIGHLIGHT_WIDTH
,
191 ID_RENDER_GRID_LINES
,
192 ID_RENDER_GRID_BORDER
,
193 ID_RENDER_SELECT_HLIGHT
,
198 ID_RENDER_DEFAULT_SIZE
,
205 // add the cells to selection when using commands from select menu?
208 wxBitmap m_gridBitmap
;
210 DECLARE_EVENT_TABLE()
213 class MyGridCellRenderer
: public wxGridCellStringRenderer
216 virtual void Draw(wxGrid
& grid
,
217 wxGridCellAttr
& attr
,
224 // ----------------------------------------------------------------------------
225 // demonstration of virtual table which doesn't store all of its data in
227 // ----------------------------------------------------------------------------
229 class BigGridTable
: public wxGridTableBase
232 BigGridTable(long sizeGrid
) { m_sizeGrid
= sizeGrid
; }
234 int GetNumberRows() { return m_sizeGrid
; }
235 int GetNumberCols() { return m_sizeGrid
; }
236 wxString
GetValue( int row
, int col
)
238 return wxString::Format(wxT("(%d, %d)"), row
, col
);
241 void SetValue( int , int , const wxString
& ) { /* ignore */ }
242 bool IsEmptyCell( int , int ) { return false; }
248 class BigGridFrame
: public wxFrame
251 BigGridFrame(long sizeGrid
);
255 BigGridTable
* m_table
;
258 // ----------------------------------------------------------------------------
259 // an example of custom attr provider: this one makes all odd rows appear grey
260 // ----------------------------------------------------------------------------
262 class MyGridCellAttrProvider
: public wxGridCellAttrProvider
265 MyGridCellAttrProvider();
266 virtual ~MyGridCellAttrProvider();
268 virtual wxGridCellAttr
*GetAttr(int row
, int col
,
269 wxGridCellAttr::wxAttrKind kind
) const;
272 wxGridCellAttr
*m_attrForOddRows
;
275 // ----------------------------------------------------------------------------
276 // another, more realistic, grid example: shows typed columns and more
277 // ----------------------------------------------------------------------------
279 class BugsGridTable
: public wxGridTableBase
284 virtual int GetNumberRows();
285 virtual int GetNumberCols();
286 virtual bool IsEmptyCell( int row
, int col
);
287 virtual wxString
GetValue( int row
, int col
);
288 virtual void SetValue( int row
, int col
, const wxString
& value
);
290 virtual wxString
GetColLabelValue( int col
);
292 virtual wxString
GetTypeName( int row
, int col
);
293 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
294 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
296 virtual long GetValueAsLong( int row
, int col
);
297 virtual bool GetValueAsBool( int row
, int col
);
299 virtual void SetValueAsLong( int row
, int col
, long value
);
300 virtual void SetValueAsBool( int row
, int col
, bool value
);
303 class BugsGridFrame
: public wxFrame