]> git.saurik.com Git - wxWidgets.git/blame - samples/newgrid/griddemo.h
Disable putting selected text in the Primary Selection, since wxGTK is
[wxWidgets.git] / samples / newgrid / griddemo.h
CommitLineData
10434f3c
MB
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/////////////////////////////////////////////////////////////////////////////
e442cc0d
MB
10
11
12#ifndef griddemo_h
13#define griddemo_h
14
b99be8fb
VZ
15#if !defined(wxUSE_NEW_GRID) || !(wxUSE_NEW_GRID)
16 #error "This sample requires the new wxGrid class."
17#endif
e442cc0d
MB
18
19class wxGrid;
20
21class GridApp : public wxApp
22{
ab79958a 23public:
e442cc0d
MB
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();
f445b853 36
e442cc0d
MB
37 void ToggleRowLabels( wxCommandEvent& );
38 void ToggleColLabels( wxCommandEvent& );
f445b853 39 void ToggleEditing( wxCommandEvent& );
dd16fdae
MB
40 void ToggleRowSizing( wxCommandEvent& );
41 void ToggleColSizing( wxCommandEvent& );
4cfa5de6 42 void ToggleGridSizing( wxCommandEvent& );
f6bcfd97
BP
43 void ToggleGridLines( wxCommandEvent& );
44 void AutoSizeCols( wxCommandEvent& );
ecd69fb6
SN
45 void CellOverflow( wxCommandEvent& );
46 void ResizeCell( wxCommandEvent& );
e442cc0d
MB
47 void SetLabelColour( wxCommandEvent& );
48 void SetLabelTextColour( wxCommandEvent& );
bf9adb3a 49 void SetLabelFont(wxCommandEvent &);
e442cc0d
MB
50 void SetRowLabelHorizAlignment( wxCommandEvent& );
51 void SetRowLabelVertAlignment( wxCommandEvent& );
52 void SetColLabelHorizAlignment( wxCommandEvent& );
53 void SetColLabelVertAlignment( wxCommandEvent& );
54 void SetGridLineColour( wxCommandEvent& );
0eee5283 55
ab79958a
VZ
56 void SetCellFgColour(wxCommandEvent &);
57 void SetCellBgColour(wxCommandEvent &);
58
b99be8fb
VZ
59 void InsertRow( wxCommandEvent& );
60 void InsertCol( wxCommandEvent& );
61 void DeleteSelectedRows( wxCommandEvent& );
62 void DeleteSelectedCols( wxCommandEvent& );
e442cc0d 63 void ClearGrid( wxCommandEvent& );
043d16b2
SN
64 void SelectCells( wxCommandEvent& );
65 void SelectRows( wxCommandEvent& );
66 void SelectCols( wxCommandEvent& );
e442cc0d 67
14e5a313
VZ
68 void DeselectCell(wxCommandEvent& event);
69 void DeselectCol(wxCommandEvent& event);
70 void DeselectRow(wxCommandEvent& event);
71 void DeselectAll(wxCommandEvent& event);
72 void SelectCell(wxCommandEvent& event);
73 void SelectCol(wxCommandEvent& event);
74 void SelectRow(wxCommandEvent& event);
75 void SelectAll(wxCommandEvent& event);
93521c94 76 void OnAddToSelectToggle(wxCommandEvent& event);
14e5a313 77
e442cc0d
MB
78 void OnLabelLeftClick( wxGridEvent& );
79 void OnCellLeftClick( wxGridEvent& );
80 void OnRowSize( wxGridSizeEvent& );
81 void OnColSize( wxGridSizeEvent& );
c336585e 82 void OnSelectCell( wxGridEvent& );
e442cc0d
MB
83 void OnRangeSelected( wxGridRangeSelectEvent& );
84 void OnCellValueChanged( wxGridEvent& );
b99be8fb 85
b54ba671
VZ
86 void OnEditorShown(wxGridEvent&);
87 void OnEditorHidden(wxGridEvent&);
88
d2520c85
RD
89 void OnSetHighlightWidth(wxCommandEvent&);
90 void OnSetROHighlightWidth(wxCommandEvent&);
91
ab79958a 92public:
e442cc0d
MB
93 GridFrame();
94 ~GridFrame();
95
e442cc0d 96 void OnQuit( wxCommandEvent& );
f445b853 97 void About( wxCommandEvent& );
f97c9b5b 98 void OnVTable( wxCommandEvent& );
35f97e95 99 void OnBugsTable( wxCommandEvent& );
671bcff5 100 void OnSmallGrid( wxCommandEvent& );
e442cc0d 101
ab79958a
VZ
102 enum
103 {
104 ID_TOGGLEROWLABELS = 100,
105 ID_TOGGLECOLLABELS,
106 ID_TOGGLEEDIT,
dd16fdae
MB
107 ID_TOGGLEROWSIZING,
108 ID_TOGGLECOLSIZING,
4cfa5de6 109 ID_TOGGLEGRIDSIZING,
f6bcfd97
BP
110 ID_TOGGLEGRIDLINES,
111 ID_AUTOSIZECOLS,
ecd69fb6
SN
112 ID_CELLOVERFLOW,
113 ID_RESIZECELL,
ab79958a
VZ
114 ID_SETLABELCOLOUR,
115 ID_SETLABELTEXTCOLOUR,
bf9adb3a 116 ID_SETLABEL_FONT,
ab79958a
VZ
117 ID_ROWLABELALIGN,
118 ID_ROWLABELHORIZALIGN,
119 ID_ROWLABELVERTALIGN,
120 ID_COLLABELALIGN,
121 ID_COLLABELHORIZALIGN,
122 ID_COLLABELVERTALIGN,
123 ID_GRIDLINECOLOUR,
124 ID_INSERTROW,
125 ID_INSERTCOL,
126 ID_DELETEROW,
127 ID_DELETECOL,
128 ID_CLEARGRID,
93521c94
VZ
129 ID_CHANGESEL,
130 ID_SELCELLS,
131 ID_SELROWS,
132 ID_SELCOLS,
ab79958a
VZ
133 ID_SET_CELL_FG_COLOUR,
134 ID_SET_CELL_BG_COLOUR,
135 ID_ABOUT,
f97c9b5b 136 ID_VTABLE,
35f97e95 137 ID_BUGS_TABLE,
671bcff5 138 ID_SMALL_GRID,
93521c94 139 ID_SELECT_UNSELECT,
14e5a313
VZ
140 ID_SELECT_ALL,
141 ID_SELECT_ROW,
142 ID_SELECT_COL,
143 ID_SELECT_CELL,
144 ID_DESELECT_ALL,
145 ID_DESELECT_ROW,
146 ID_DESELECT_COL,
147 ID_DESELECT_CELL,
ab79958a 148
d2520c85
RD
149 ID_SET_HIGHLIGHT_WIDTH,
150 ID_SET_RO_HIGHLIGHT_WIDTH,
151
ab79958a
VZ
152 ID_TESTFUNC
153 };
b99be8fb 154
66b3609e
VZ
155 wxLog *m_logOld;
156
93521c94
VZ
157 // add the cells to selection when using commands from select menu?
158 bool m_addToSel;
159
e442cc0d
MB
160 DECLARE_EVENT_TABLE()
161};
162
ab79958a
VZ
163class MyGridCellRenderer : public wxGridCellStringRenderer
164{
165public:
166 virtual void Draw(wxGrid& grid,
f97c9b5b 167 wxGridCellAttr& attr,
ab79958a
VZ
168 wxDC& dc,
169 const wxRect& rect,
170 int row, int col,
171 bool isSelected);
172};
e442cc0d 173
1618dca7
VZ
174// ----------------------------------------------------------------------------
175// demonstration of virtual table which doesn't store all of its data in
176// memory
177// ----------------------------------------------------------------------------
f97c9b5b 178
1618dca7
VZ
179class BigGridTable : public wxGridTableBase
180{
f97c9b5b 181public:
1618dca7
VZ
182 BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; }
183
e32352cf
SN
184 int GetNumberRows() { return m_sizeGrid; }
185 int GetNumberCols() { return m_sizeGrid; }
1618dca7
VZ
186 wxString GetValue( int row, int col )
187 {
4693b20c 188 return wxString::Format(wxT("(%d, %d)"), row, col);
f97c9b5b
RD
189 }
190
1618dca7 191 void SetValue( int , int , const wxString& ) { /* ignore */ }
f97c9b5b 192 bool IsEmptyCell( int , int ) { return FALSE; }
1618dca7
VZ
193
194private:
195 long m_sizeGrid;
f97c9b5b
RD
196};
197
1618dca7
VZ
198class BigGridFrame : public wxFrame
199{
f97c9b5b 200public:
1618dca7 201 BigGridFrame(long sizeGrid);
f97c9b5b
RD
202
203private:
204 wxGrid* m_grid;
205 BigGridTable* m_table;
206};
207
a68c1246
VZ
208// ----------------------------------------------------------------------------
209// an example of custom attr provider: this one makes all odd rows appear grey
210// ----------------------------------------------------------------------------
211
212class MyGridCellAttrProvider : public wxGridCellAttrProvider
213{
214public:
215 MyGridCellAttrProvider();
216 virtual ~MyGridCellAttrProvider();
217
19d7140e 218 virtual wxGridCellAttr *GetAttr(int row, int col,
d10f4bf9 219 wxGridCellAttr::wxAttrKind kind) const;
a68c1246
VZ
220
221private:
222 wxGridCellAttr *m_attrForOddRows;
223};
224
35f97e95 225// ----------------------------------------------------------------------------
816be743 226// another, more realistic, grid example: shows typed columns and more
35f97e95
VZ
227// ----------------------------------------------------------------------------
228
816be743
VZ
229class BugsGridTable : public wxGridTableBase
230{
231public:
232 BugsGridTable();
233
e32352cf
SN
234 virtual int GetNumberRows();
235 virtual int GetNumberCols();
816be743
VZ
236 virtual bool IsEmptyCell( int row, int col );
237 virtual wxString GetValue( int row, int col );
238 virtual void SetValue( int row, int col, const wxString& value );
239
240 virtual wxString GetColLabelValue( int col );
241
242 virtual wxString GetTypeName( int row, int col );
243 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
244 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
245
246 virtual long GetValueAsLong( int row, int col );
247 virtual bool GetValueAsBool( int row, int col );
248
249 virtual void SetValueAsLong( int row, int col, long value );
250 virtual void SetValueAsBool( int row, int col, bool value );
251};
252
35f97e95
VZ
253class BugsGridFrame : public wxFrame
254{
255public:
256 BugsGridFrame();
257};
f97c9b5b 258
19d7140e 259
1618dca7 260#endif // griddemo_h
e442cc0d 261