]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/gridctrl.h
CanSetTransparent needs to be virtual
[wxWidgets.git] / include / wx / generic / gridctrl.h
1 ///////////////////////////////////////////////////////////////////////////
2 // Name: generic/gridctrl.h
3 // Purpose: wxGrid controls
4 // Author: Paul Gammans, Roger Gammans
5 // Modified by:
6 // Created: 11/04/2001
7 // RCS-ID: $Id$
8 // Copyright: (c) The Computer Surgery (paul@compsurg.co.uk)
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_GENERIC_GRIDCTRL_H_
13 #define _WX_GENERIC_GRIDCTRL_H_
14
15 #include "wx/grid.h"
16
17 #if wxUSE_GRID
18
19 #define wxGRID_VALUE_CHOICEINT wxT("choiceint")
20 #define wxGRID_VALUE_DATETIME wxT("datetime")
21
22
23 // the default renderer for the cells containing string data
24 class WXDLLIMPEXP_ADV wxGridCellStringRenderer : public wxGridCellRenderer
25 {
26 public:
27 // draw the string
28 virtual void Draw(wxGrid& grid,
29 wxGridCellAttr& attr,
30 wxDC& dc,
31 const wxRect& rect,
32 int row, int col,
33 bool isSelected);
34
35 // return the string extent
36 virtual wxSize GetBestSize(wxGrid& grid,
37 wxGridCellAttr& attr,
38 wxDC& dc,
39 int row, int col);
40
41 virtual wxGridCellRenderer *Clone() const
42 { return new wxGridCellStringRenderer; }
43
44 protected:
45 // set the text colours before drawing
46 void SetTextColoursAndFont(const wxGrid& grid,
47 const wxGridCellAttr& attr,
48 wxDC& dc,
49 bool isSelected);
50
51 // calc the string extent for given string/font
52 wxSize DoGetBestSize(const wxGridCellAttr& attr,
53 wxDC& dc,
54 const wxString& text);
55 };
56
57 // the default renderer for the cells containing numeric (long) data
58 class WXDLLIMPEXP_ADV wxGridCellNumberRenderer : public wxGridCellStringRenderer
59 {
60 public:
61 // draw the string right aligned
62 virtual void Draw(wxGrid& grid,
63 wxGridCellAttr& attr,
64 wxDC& dc,
65 const wxRect& rect,
66 int row, int col,
67 bool isSelected);
68
69 virtual wxSize GetBestSize(wxGrid& grid,
70 wxGridCellAttr& attr,
71 wxDC& dc,
72 int row, int col);
73
74 virtual wxGridCellRenderer *Clone() const
75 { return new wxGridCellNumberRenderer; }
76
77 protected:
78 wxString GetString(const wxGrid& grid, int row, int col);
79 };
80
81 class WXDLLIMPEXP_ADV wxGridCellFloatRenderer : public wxGridCellStringRenderer
82 {
83 public:
84 wxGridCellFloatRenderer(int width = -1, int precision = -1);
85
86 // get/change formatting parameters
87 int GetWidth() const { return m_width; }
88 void SetWidth(int width) { m_width = width; m_format.clear(); }
89 int GetPrecision() const { return m_precision; }
90 void SetPrecision(int precision) { m_precision = precision; m_format.clear(); }
91
92 // draw the string right aligned with given width/precision
93 virtual void Draw(wxGrid& grid,
94 wxGridCellAttr& attr,
95 wxDC& dc,
96 const wxRect& rect,
97 int row, int col,
98 bool isSelected);
99
100 virtual wxSize GetBestSize(wxGrid& grid,
101 wxGridCellAttr& attr,
102 wxDC& dc,
103 int row, int col);
104
105 // parameters string format is "width[,precision]"
106 virtual void SetParameters(const wxString& params);
107
108 virtual wxGridCellRenderer *Clone() const;
109
110 protected:
111 wxString GetString(const wxGrid& grid, int row, int col);
112
113 private:
114 // formatting parameters
115 int m_width,
116 m_precision;
117
118 wxString m_format;
119 };
120
121 // renderer for boolean fields
122 class WXDLLIMPEXP_ADV wxGridCellBoolRenderer : public wxGridCellRenderer
123 {
124 public:
125 // draw a check mark or nothing
126 virtual void Draw(wxGrid& grid,
127 wxGridCellAttr& attr,
128 wxDC& dc,
129 const wxRect& rect,
130 int row, int col,
131 bool isSelected);
132
133 // return the checkmark size
134 virtual wxSize GetBestSize(wxGrid& grid,
135 wxGridCellAttr& attr,
136 wxDC& dc,
137 int row, int col);
138
139 virtual wxGridCellRenderer *Clone() const
140 { return new wxGridCellBoolRenderer; }
141
142 private:
143 static wxSize ms_sizeCheckMark;
144 };
145
146
147 #if wxUSE_DATETIME
148
149 #include "wx/datetime.h"
150
151 // the default renderer for the cells containing times and dates
152 class WXDLLIMPEXP_ADV wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
153 {
154 public:
155 wxGridCellDateTimeRenderer(const wxString& outformat = wxDefaultDateTimeFormat,
156 const wxString& informat = wxDefaultDateTimeFormat);
157
158 // draw the string right aligned
159 virtual void Draw(wxGrid& grid,
160 wxGridCellAttr& attr,
161 wxDC& dc,
162 const wxRect& rect,
163 int row, int col,
164 bool isSelected);
165
166 virtual wxSize GetBestSize(wxGrid& grid,
167 wxGridCellAttr& attr,
168 wxDC& dc,
169 int row, int col);
170
171 virtual wxGridCellRenderer *Clone() const;
172
173 // output strptime()-like format string
174 virtual void SetParameters(const wxString& params);
175
176 protected:
177 wxString GetString(const wxGrid& grid, int row, int col);
178
179 wxString m_iformat;
180 wxString m_oformat;
181 wxDateTime m_dateDef;
182 wxDateTime::TimeZone m_tz;
183 };
184
185 #endif // wxUSE_DATETIME
186
187 // renders a number using the corresponding text string
188 class WXDLLIMPEXP_ADV wxGridCellEnumRenderer : public wxGridCellStringRenderer
189 {
190 public:
191 wxGridCellEnumRenderer( const wxString& choices = wxEmptyString );
192
193 // draw the string right aligned
194 virtual void Draw(wxGrid& grid,
195 wxGridCellAttr& attr,
196 wxDC& dc,
197 const wxRect& rect,
198 int row, int col,
199 bool isSelected);
200
201 virtual wxSize GetBestSize(wxGrid& grid,
202 wxGridCellAttr& attr,
203 wxDC& dc,
204 int row, int col);
205
206 virtual wxGridCellRenderer *Clone() const;
207
208 // parameters string format is "item1[,item2[...,itemN]]" where itemN will
209 // be used if the cell value is N-1
210 virtual void SetParameters(const wxString& params);
211
212 protected:
213 wxString GetString(const wxGrid& grid, int row, int col);
214
215 wxArrayString m_choices;
216 };
217
218
219 class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
220 {
221 public:
222 wxGridCellAutoWrapStringRenderer() : wxGridCellStringRenderer() { }
223
224 virtual void Draw(wxGrid& grid,
225 wxGridCellAttr& attr,
226 wxDC& dc,
227 const wxRect& rect,
228 int row, int col,
229 bool isSelected);
230
231 virtual wxSize GetBestSize(wxGrid& grid,
232 wxGridCellAttr& attr,
233 wxDC& dc,
234 int row, int col);
235
236 virtual wxGridCellRenderer *Clone() const
237 { return new wxGridCellAutoWrapStringRenderer; }
238
239 private:
240 wxArrayString GetTextLines( wxGrid& grid,
241 wxDC& dc,
242 const wxGridCellAttr& attr,
243 const wxRect& rect,
244 int row, int col);
245
246 };
247
248 #endif // wxUSE_GRID
249 #endif // _WX_GENERIC_GRIDCTRL_H_