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