]> git.saurik.com Git - wxWidgets.git/blame_incremental - samples/newgrid/griddemo.h
make contrib symlink relative to WXDIR
[wxWidgets.git] / samples / newgrid / griddemo.h
... / ...
CommitLineData
1/////////////////////////////////////////////////////////////////////////////
2// Name: griddemo.h
3// Purpose: Grid control wxWindows sample
4// Author: Michael Bedward
5// Modified by:
6// RCS-ID: $Id$
7// Copyright: (c) Michael Bedward, Julian Smart
8// Licence: wxWindows license
9/////////////////////////////////////////////////////////////////////////////
10
11
12#ifndef griddemo_h
13#define griddemo_h
14
15#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
16 #error "This sample requires the new wxGrid class."
17#endif
18
19class wxGrid;
20
21class GridApp : public wxApp
22{
23public:
24 bool OnInit();
25};
26
27
28class GridFrame : public wxFrame
29{
30 wxGrid *grid;
31 wxTextCtrl *logWin;
32 wxLogTextCtrl *logger;
33 wxString logBuf;
34
35 void SetDefaults();
36
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& );
52
53 void SetCellFgColour(wxCommandEvent &);
54 void SetCellBgColour(wxCommandEvent &);
55
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& );
64
65 void OnLabelLeftClick( wxGridEvent& );
66 void OnCellLeftClick( wxGridEvent& );
67 void OnRowSize( wxGridSizeEvent& );
68 void OnColSize( wxGridSizeEvent& );
69 void OnSelectCell( wxGridEvent& );
70 void OnRangeSelected( wxGridRangeSelectEvent& );
71 void OnCellValueChanged( wxGridEvent& );
72
73 void OnEditorShown(wxGridEvent&);
74 void OnEditorHidden(wxGridEvent&);
75
76public:
77 GridFrame();
78 ~GridFrame();
79
80 void OnQuit( wxCommandEvent& );
81 void About( wxCommandEvent& );
82 void OnVTable( wxCommandEvent& );
83 void OnBugsTable( wxCommandEvent& );
84
85 enum
86 {
87 ID_TOGGLEROWLABELS = 100,
88 ID_TOGGLECOLLABELS,
89 ID_TOGGLEEDIT,
90 ID_TOGGLEROWSIZING,
91 ID_TOGGLECOLSIZING,
92 ID_TOGGLEGRIDSIZING,
93 ID_TOGGLEGRIDLINES,
94 ID_AUTOSIZECOLS,
95 ID_SETLABELCOLOUR,
96 ID_SETLABELTEXTCOLOUR,
97 ID_ROWLABELALIGN,
98 ID_ROWLABELHORIZALIGN,
99 ID_ROWLABELVERTALIGN,
100 ID_COLLABELALIGN,
101 ID_COLLABELHORIZALIGN,
102 ID_COLLABELVERTALIGN,
103 ID_GRIDLINECOLOUR,
104 ID_INSERTROW,
105 ID_INSERTCOL,
106 ID_DELETEROW,
107 ID_DELETECOL,
108 ID_CLEARGRID,
109 ID_CHANGESEL,
110 ID_SELCELLS,
111 ID_SELROWS,
112 ID_SELCOLS,
113 ID_SET_CELL_FG_COLOUR,
114 ID_SET_CELL_BG_COLOUR,
115 ID_ABOUT,
116 ID_VTABLE,
117 ID_BUGS_TABLE,
118
119 ID_TESTFUNC
120 };
121
122 wxLog *m_logOld;
123
124 DECLARE_EVENT_TABLE()
125};
126
127class MyGridCellRenderer : public wxGridCellStringRenderer
128{
129public:
130 virtual void Draw(wxGrid& grid,
131 wxGridCellAttr& attr,
132 wxDC& dc,
133 const wxRect& rect,
134 int row, int col,
135 bool isSelected);
136};
137
138// ----------------------------------------------------------------------------
139// demonstration of virtual table which doesn't store all of its data in
140// memory
141// ----------------------------------------------------------------------------
142
143class BigGridTable : public wxGridTableBase
144{
145public:
146 BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; }
147
148 int GetNumberRows() { return m_sizeGrid; }
149 int GetNumberCols() { return m_sizeGrid; }
150 wxString GetValue( int row, int col )
151 {
152 return wxString::Format("(%d, %d)", row, col);
153 }
154
155 void SetValue( int , int , const wxString& ) { /* ignore */ }
156 bool IsEmptyCell( int , int ) { return FALSE; }
157
158private:
159 long m_sizeGrid;
160};
161
162class BigGridFrame : public wxFrame
163{
164public:
165 BigGridFrame(long sizeGrid);
166
167private:
168 wxGrid* m_grid;
169 BigGridTable* m_table;
170};
171
172// ----------------------------------------------------------------------------
173// an example of custom attr provider: this one makes all odd rows appear grey
174// ----------------------------------------------------------------------------
175
176class MyGridCellAttrProvider : public wxGridCellAttrProvider
177{
178public:
179 MyGridCellAttrProvider();
180 virtual ~MyGridCellAttrProvider();
181
182 virtual wxGridCellAttr *GetAttr(int row, int col) const;
183
184private:
185 wxGridCellAttr *m_attrForOddRows;
186};
187
188// ----------------------------------------------------------------------------
189// another, more realistic, grid example: shows typed columns and more
190// ----------------------------------------------------------------------------
191
192class BugsGridTable : public wxGridTableBase
193{
194public:
195 BugsGridTable();
196
197 virtual int GetNumberRows();
198 virtual int GetNumberCols();
199 virtual bool IsEmptyCell( int row, int col );
200 virtual wxString GetValue( int row, int col );
201 virtual void SetValue( int row, int col, const wxString& value );
202
203 virtual wxString GetColLabelValue( int col );
204
205 virtual wxString GetTypeName( int row, int col );
206 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
207 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
208
209 virtual long GetValueAsLong( int row, int col );
210 virtual bool GetValueAsBool( int row, int col );
211
212 virtual void SetValueAsLong( int row, int col, long value );
213 virtual void SetValueAsBool( int row, int col, bool value );
214};
215
216class BugsGridFrame : public wxFrame
217{
218public:
219 BugsGridFrame();
220};
221
222#endif // griddemo_h
223