]>
git.saurik.com Git - wxWidgets.git/blob - samples/newgrid/griddemo.h
b450ef6e00d8e445cab60d5e7f15fc952ac5071c
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
);
74 void OnLabelLeftClick( wxGridEvent
& );
75 void OnCellLeftClick( wxGridEvent
& );
76 void OnRowSize( wxGridSizeEvent
& );
77 void OnColSize( wxGridSizeEvent
& );
78 void OnSelectCell( wxGridEvent
& );
79 void OnRangeSelected( wxGridRangeSelectEvent
& );
80 void OnCellValueChanged( wxGridEvent
& );
82 void OnEditorShown(wxGridEvent
&);
83 void OnEditorHidden(wxGridEvent
&);
89 void OnQuit( wxCommandEvent
& );
90 void About( wxCommandEvent
& );
91 void OnVTable( wxCommandEvent
& );
92 void OnBugsTable( wxCommandEvent
& );
96 ID_TOGGLEROWLABELS
= 100,
105 ID_SETLABELTEXTCOLOUR
,
107 ID_ROWLABELHORIZALIGN
,
108 ID_ROWLABELVERTALIGN
,
110 ID_COLLABELHORIZALIGN
,
111 ID_COLLABELVERTALIGN
,
122 ID_SET_CELL_FG_COLOUR
,
123 ID_SET_CELL_BG_COLOUR
,
141 DECLARE_EVENT_TABLE()
144 class MyGridCellRenderer
: public wxGridCellStringRenderer
147 virtual void Draw(wxGrid
& grid
,
148 wxGridCellAttr
& attr
,
155 // ----------------------------------------------------------------------------
156 // demonstration of virtual table which doesn't store all of its data in
158 // ----------------------------------------------------------------------------
160 class BigGridTable
: public wxGridTableBase
163 BigGridTable(long sizeGrid
) { m_sizeGrid
= sizeGrid
; }
165 int GetNumberRows() { return m_sizeGrid
; }
166 int GetNumberCols() { return m_sizeGrid
; }
167 wxString
GetValue( int row
, int col
)
169 return wxString::Format("(%d, %d)", row
, col
);
172 void SetValue( int , int , const wxString
& ) { /* ignore */ }
173 bool IsEmptyCell( int , int ) { return FALSE
; }
179 class BigGridFrame
: public wxFrame
182 BigGridFrame(long sizeGrid
);
186 BigGridTable
* m_table
;
189 // ----------------------------------------------------------------------------
190 // an example of custom attr provider: this one makes all odd rows appear grey
191 // ----------------------------------------------------------------------------
193 class MyGridCellAttrProvider
: public wxGridCellAttrProvider
196 MyGridCellAttrProvider();
197 virtual ~MyGridCellAttrProvider();
199 virtual wxGridCellAttr
*GetAttr(int row
, int col
) const;
202 wxGridCellAttr
*m_attrForOddRows
;
205 // ----------------------------------------------------------------------------
206 // another, more realistic, grid example: shows typed columns and more
207 // ----------------------------------------------------------------------------
209 class BugsGridTable
: public wxGridTableBase
214 virtual int GetNumberRows();
215 virtual int GetNumberCols();
216 virtual bool IsEmptyCell( int row
, int col
);
217 virtual wxString
GetValue( int row
, int col
);
218 virtual void SetValue( int row
, int col
, const wxString
& value
);
220 virtual wxString
GetColLabelValue( int col
);
222 virtual wxString
GetTypeName( int row
, int col
);
223 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
224 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
226 virtual long GetValueAsLong( int row
, int col
);
227 virtual bool GetValueAsBool( int row
, int col
);
229 virtual void SetValueAsLong( int row
, int col
, long value
);
230 virtual void SetValueAsBool( int row
, int col
, bool value
);
233 class BugsGridFrame
: public wxFrame