]>
git.saurik.com Git - wxWidgets.git/blob - samples/newgrid/griddemo.h
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
);
73 void OnAddToSelectToggle(wxCommandEvent
& event
);
75 void OnLabelLeftClick( wxGridEvent
& );
76 void OnCellLeftClick( wxGridEvent
& );
77 void OnRowSize( wxGridSizeEvent
& );
78 void OnColSize( wxGridSizeEvent
& );
79 void OnSelectCell( wxGridEvent
& );
80 void OnRangeSelected( wxGridRangeSelectEvent
& );
81 void OnCellValueChanged( wxGridEvent
& );
83 void OnEditorShown(wxGridEvent
&);
84 void OnEditorHidden(wxGridEvent
&);
90 void OnQuit( wxCommandEvent
& );
91 void About( wxCommandEvent
& );
92 void OnVTable( wxCommandEvent
& );
93 void OnBugsTable( wxCommandEvent
& );
97 ID_TOGGLEROWLABELS
= 100,
106 ID_SETLABELTEXTCOLOUR
,
108 ID_ROWLABELHORIZALIGN
,
109 ID_ROWLABELVERTALIGN
,
111 ID_COLLABELHORIZALIGN
,
112 ID_COLLABELVERTALIGN
,
123 ID_SET_CELL_FG_COLOUR
,
124 ID_SET_CELL_BG_COLOUR
,
143 // add the cells to selection when using commands from select menu?
146 DECLARE_EVENT_TABLE()
149 class MyGridCellRenderer
: public wxGridCellStringRenderer
152 virtual void Draw(wxGrid
& grid
,
153 wxGridCellAttr
& attr
,
160 // ----------------------------------------------------------------------------
161 // demonstration of virtual table which doesn't store all of its data in
163 // ----------------------------------------------------------------------------
165 class BigGridTable
: public wxGridTableBase
168 BigGridTable(long sizeGrid
) { m_sizeGrid
= sizeGrid
; }
170 int GetNumberRows() { return m_sizeGrid
; }
171 int GetNumberCols() { return m_sizeGrid
; }
172 wxString
GetValue( int row
, int col
)
174 return wxString::Format("(%d, %d)", row
, col
);
177 void SetValue( int , int , const wxString
& ) { /* ignore */ }
178 bool IsEmptyCell( int , int ) { return FALSE
; }
184 class BigGridFrame
: public wxFrame
187 BigGridFrame(long sizeGrid
);
191 BigGridTable
* m_table
;
194 // ----------------------------------------------------------------------------
195 // an example of custom attr provider: this one makes all odd rows appear grey
196 // ----------------------------------------------------------------------------
198 class MyGridCellAttrProvider
: public wxGridCellAttrProvider
201 MyGridCellAttrProvider();
202 virtual ~MyGridCellAttrProvider();
204 virtual wxGridCellAttr
*GetAttr(int row
, int col
) const;
207 wxGridCellAttr
*m_attrForOddRows
;
210 // ----------------------------------------------------------------------------
211 // another, more realistic, grid example: shows typed columns and more
212 // ----------------------------------------------------------------------------
214 class BugsGridTable
: public wxGridTableBase
219 virtual int GetNumberRows();
220 virtual int GetNumberCols();
221 virtual bool IsEmptyCell( int row
, int col
);
222 virtual wxString
GetValue( int row
, int col
);
223 virtual void SetValue( int row
, int col
, const wxString
& value
);
225 virtual wxString
GetColLabelValue( int col
);
227 virtual wxString
GetTypeName( int row
, int col
);
228 virtual bool CanGetValueAs( int row
, int col
, const wxString
& typeName
);
229 virtual bool CanSetValueAs( int row
, int col
, const wxString
& typeName
);
231 virtual long GetValueAsLong( int row
, int col
);
232 virtual bool GetValueAsBool( int row
, int col
);
234 virtual void SetValueAsLong( int row
, int col
, long value
);
235 virtual void SetValueAsBool( int row
, int col
, bool value
);
238 class BugsGridFrame
: public wxFrame