]> git.saurik.com Git - wxWidgets.git/blame - samples/newgrid/griddemo.h
grid autosize fixes/changes
[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& );
e442cc0d
MB
43 void SetLabelColour( wxCommandEvent& );
44 void SetLabelTextColour( wxCommandEvent& );
45 void SetRowLabelHorizAlignment( wxCommandEvent& );
46 void SetRowLabelVertAlignment( wxCommandEvent& );
47 void SetColLabelHorizAlignment( wxCommandEvent& );
48 void SetColLabelVertAlignment( wxCommandEvent& );
49 void SetGridLineColour( wxCommandEvent& );
0eee5283 50
ab79958a
VZ
51 void SetCellFgColour(wxCommandEvent &);
52 void SetCellBgColour(wxCommandEvent &);
53
b99be8fb
VZ
54 void InsertRow( wxCommandEvent& );
55 void InsertCol( wxCommandEvent& );
56 void DeleteSelectedRows( wxCommandEvent& );
57 void DeleteSelectedCols( wxCommandEvent& );
e442cc0d
MB
58 void ClearGrid( wxCommandEvent& );
59
e442cc0d
MB
60 void OnLabelLeftClick( wxGridEvent& );
61 void OnCellLeftClick( wxGridEvent& );
62 void OnRowSize( wxGridSizeEvent& );
63 void OnColSize( wxGridSizeEvent& );
c336585e 64 void OnSelectCell( wxGridEvent& );
e442cc0d
MB
65 void OnRangeSelected( wxGridRangeSelectEvent& );
66 void OnCellValueChanged( wxGridEvent& );
b99be8fb 67
b54ba671
VZ
68 void OnEditorShown(wxGridEvent&);
69 void OnEditorHidden(wxGridEvent&);
70
ab79958a 71public:
e442cc0d
MB
72 GridFrame();
73 ~GridFrame();
74
e442cc0d 75 void OnQuit( wxCommandEvent& );
f445b853 76 void About( wxCommandEvent& );
f97c9b5b 77 void OnVTable( wxCommandEvent& );
35f97e95 78 void OnBugsTable( wxCommandEvent& );
e442cc0d 79
ab79958a
VZ
80 enum
81 {
82 ID_TOGGLEROWLABELS = 100,
83 ID_TOGGLECOLLABELS,
84 ID_TOGGLEEDIT,
dd16fdae
MB
85 ID_TOGGLEROWSIZING,
86 ID_TOGGLECOLSIZING,
4cfa5de6 87 ID_TOGGLEGRIDSIZING,
ab79958a
VZ
88 ID_SETLABELCOLOUR,
89 ID_SETLABELTEXTCOLOUR,
90 ID_ROWLABELALIGN,
91 ID_ROWLABELHORIZALIGN,
92 ID_ROWLABELVERTALIGN,
93 ID_COLLABELALIGN,
94 ID_COLLABELHORIZALIGN,
95 ID_COLLABELVERTALIGN,
96 ID_GRIDLINECOLOUR,
97 ID_INSERTROW,
98 ID_INSERTCOL,
99 ID_DELETEROW,
100 ID_DELETECOL,
101 ID_CLEARGRID,
102 ID_SET_CELL_FG_COLOUR,
103 ID_SET_CELL_BG_COLOUR,
104 ID_ABOUT,
f97c9b5b 105 ID_VTABLE,
35f97e95 106 ID_BUGS_TABLE,
ab79958a
VZ
107
108 ID_TESTFUNC
109 };
b99be8fb 110
66b3609e
VZ
111 wxLog *m_logOld;
112
e442cc0d
MB
113 DECLARE_EVENT_TABLE()
114};
115
ab79958a
VZ
116class MyGridCellRenderer : public wxGridCellStringRenderer
117{
118public:
119 virtual void Draw(wxGrid& grid,
f97c9b5b 120 wxGridCellAttr& attr,
ab79958a
VZ
121 wxDC& dc,
122 const wxRect& rect,
123 int row, int col,
124 bool isSelected);
125};
e442cc0d 126
1618dca7
VZ
127// ----------------------------------------------------------------------------
128// demonstration of virtual table which doesn't store all of its data in
129// memory
130// ----------------------------------------------------------------------------
f97c9b5b 131
1618dca7
VZ
132class BigGridTable : public wxGridTableBase
133{
f97c9b5b 134public:
1618dca7
VZ
135 BigGridTable(long sizeGrid) { m_sizeGrid = sizeGrid; }
136
137 long GetNumberRows() { return m_sizeGrid; }
138 long GetNumberCols() { return m_sizeGrid; }
1618dca7
VZ
139 wxString GetValue( int row, int col )
140 {
141 return wxString::Format("(%d, %d)", row, col);
f97c9b5b
RD
142 }
143
1618dca7 144 void SetValue( int , int , const wxString& ) { /* ignore */ }
f97c9b5b 145 bool IsEmptyCell( int , int ) { return FALSE; }
1618dca7
VZ
146
147private:
148 long m_sizeGrid;
f97c9b5b
RD
149};
150
1618dca7
VZ
151class BigGridFrame : public wxFrame
152{
f97c9b5b 153public:
1618dca7 154 BigGridFrame(long sizeGrid);
f97c9b5b
RD
155
156private:
157 wxGrid* m_grid;
158 BigGridTable* m_table;
159};
160
35f97e95 161// ----------------------------------------------------------------------------
816be743 162// another, more realistic, grid example: shows typed columns and more
35f97e95
VZ
163// ----------------------------------------------------------------------------
164
816be743
VZ
165class BugsGridTable : public wxGridTableBase
166{
167public:
168 BugsGridTable();
169
170 virtual long GetNumberRows();
171 virtual long GetNumberCols();
172 virtual bool IsEmptyCell( int row, int col );
173 virtual wxString GetValue( int row, int col );
174 virtual void SetValue( int row, int col, const wxString& value );
175
176 virtual wxString GetColLabelValue( int col );
177
178 virtual wxString GetTypeName( int row, int col );
179 virtual bool CanGetValueAs( int row, int col, const wxString& typeName );
180 virtual bool CanSetValueAs( int row, int col, const wxString& typeName );
181
182 virtual long GetValueAsLong( int row, int col );
183 virtual bool GetValueAsBool( int row, int col );
184
185 virtual void SetValueAsLong( int row, int col, long value );
186 virtual void SetValueAsBool( int row, int col, bool value );
187};
188
35f97e95
VZ
189class BugsGridFrame : public wxFrame
190{
191public:
192 BugsGridFrame();
193};
f97c9b5b 194
1618dca7 195#endif // griddemo_h
e442cc0d 196