]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/gridctrl.h
activating DrawRectangle optimization
[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 // 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,
85 int precision = -1,
86 int format = wxGRID_FLOAT_FORMAT_DEFAULT);
87
88 // get/change formatting parameters
89 int GetWidth() const { return m_width; }
90 void SetWidth(int width) { m_width = width; m_format.clear(); }
91 int GetPrecision() const { return m_precision; }
92 void SetPrecision(int precision) { m_precision = precision; m_format.clear(); }
93 int GetFormat() const { return m_style; }
94 void SetFormat(int format) { m_style = format; m_format.clear(); }
95
96 // draw the string right aligned with given width/precision
97 virtual void Draw(wxGrid& grid,
98 wxGridCellAttr& attr,
99 wxDC& dc,
100 const wxRect& rect,
101 int row, int col,
102 bool isSelected);
103
104 virtual wxSize GetBestSize(wxGrid& grid,
105 wxGridCellAttr& attr,
106 wxDC& dc,
107 int row, int col);
108
109 // parameters string format is "width[,precision[,format]]"
110 // with format being one of f|e|g|E|F|G
111 virtual void SetParameters(const wxString& params);
112
113 virtual wxGridCellRenderer *Clone() const;
114
115 protected:
116 wxString GetString(const wxGrid& grid, int row, int col);
117
118 private:
119 // formatting parameters
120 int m_width,
121 m_precision;
122
123 int m_style;
124 wxString m_format;
125 };
126
127 // renderer for boolean fields
128 class WXDLLIMPEXP_ADV wxGridCellBoolRenderer : public wxGridCellRenderer
129 {
130 public:
131 // draw a check mark or nothing
132 virtual void Draw(wxGrid& grid,
133 wxGridCellAttr& attr,
134 wxDC& dc,
135 const wxRect& rect,
136 int row, int col,
137 bool isSelected);
138
139 // return the checkmark size
140 virtual wxSize GetBestSize(wxGrid& grid,
141 wxGridCellAttr& attr,
142 wxDC& dc,
143 int row, int col);
144
145 virtual wxGridCellRenderer *Clone() const
146 { return new wxGridCellBoolRenderer; }
147
148 private:
149 static wxSize ms_sizeCheckMark;
150 };
151
152
153 #if wxUSE_DATETIME
154
155 #include "wx/datetime.h"
156
157 // the default renderer for the cells containing times and dates
158 class WXDLLIMPEXP_ADV wxGridCellDateTimeRenderer : public wxGridCellStringRenderer
159 {
160 public:
161 wxGridCellDateTimeRenderer(const wxString& outformat = wxDefaultDateTimeFormat,
162 const wxString& informat = wxDefaultDateTimeFormat);
163
164 // draw the string right aligned
165 virtual void Draw(wxGrid& grid,
166 wxGridCellAttr& attr,
167 wxDC& dc,
168 const wxRect& rect,
169 int row, int col,
170 bool isSelected);
171
172 virtual wxSize GetBestSize(wxGrid& grid,
173 wxGridCellAttr& attr,
174 wxDC& dc,
175 int row, int col);
176
177 virtual wxGridCellRenderer *Clone() const;
178
179 // output strptime()-like format string
180 virtual void SetParameters(const wxString& params);
181
182 protected:
183 wxString GetString(const wxGrid& grid, int row, int col);
184
185 wxString m_iformat;
186 wxString m_oformat;
187 wxDateTime m_dateDef;
188 wxDateTime::TimeZone m_tz;
189 };
190
191 #endif // wxUSE_DATETIME
192
193 // renders a number using the corresponding text string
194 class WXDLLIMPEXP_ADV wxGridCellEnumRenderer : public wxGridCellStringRenderer
195 {
196 public:
197 wxGridCellEnumRenderer( const wxString& choices = wxEmptyString );
198
199 // draw the string right aligned
200 virtual void Draw(wxGrid& grid,
201 wxGridCellAttr& attr,
202 wxDC& dc,
203 const wxRect& rect,
204 int row, int col,
205 bool isSelected);
206
207 virtual wxSize GetBestSize(wxGrid& grid,
208 wxGridCellAttr& attr,
209 wxDC& dc,
210 int row, int col);
211
212 virtual wxGridCellRenderer *Clone() const;
213
214 // parameters string format is "item1[,item2[...,itemN]]" where itemN will
215 // be used if the cell value is N-1
216 virtual void SetParameters(const wxString& params);
217
218 protected:
219 wxString GetString(const wxGrid& grid, int row, int col);
220
221 wxArrayString m_choices;
222 };
223
224
225 class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer
226 {
227 public:
228 wxGridCellAutoWrapStringRenderer() : wxGridCellStringRenderer() { }
229
230 virtual void Draw(wxGrid& grid,
231 wxGridCellAttr& attr,
232 wxDC& dc,
233 const wxRect& rect,
234 int row, int col,
235 bool isSelected);
236
237 virtual wxSize GetBestSize(wxGrid& grid,
238 wxGridCellAttr& attr,
239 wxDC& dc,
240 int row, int col);
241
242 virtual wxGridCellRenderer *Clone() const
243 { return new wxGridCellAutoWrapStringRenderer; }
244
245 private:
246 wxArrayString GetTextLines( wxGrid& grid,
247 wxDC& dc,
248 const wxGridCellAttr& attr,
249 const wxRect& rect,
250 int row, int col);
251
252 };
253
254 #endif // wxUSE_GRID
255 #endif // _WX_GENERIC_GRIDCTRL_H_