]>
Commit | Line | Data |
---|---|---|
d10f4bf9 VZ |
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) | |
65571936 | 9 | // Licence: wxWindows licence |
d10f4bf9 VZ |
10 | ///////////////////////////////////////////////////////////////////////////// |
11 | ||
12 | #ifndef _WX_GENERIC_GRIDCTRL_H_ | |
13 | #define _WX_GENERIC_GRIDCTRL_H_ | |
14 | ||
d10f4bf9 | 15 | #include "wx/grid.h" |
df9fac6d PC |
16 | |
17 | #if wxUSE_GRID | |
d10f4bf9 VZ |
18 | |
19 | #define wxGRID_VALUE_CHOICEINT _T("choiceint") | |
20 | #define wxGRID_VALUE_DATETIME _T("datetime") | |
21 | ||
29efc6e4 FM |
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 | ||
e2b87f38 | 147 | #if wxUSE_DATETIME |
6d7aee4f VZ |
148 | |
149 | #include "wx/datetime.h" | |
e2b87f38 | 150 | |
d10f4bf9 | 151 | // the default renderer for the cells containing Time and dates.. |
12f190b0 | 152 | class WXDLLIMPEXP_ADV wxGridCellDateTimeRenderer : public wxGridCellStringRenderer |
d10f4bf9 VZ |
153 | { |
154 | public: | |
fbfb8bcc VZ |
155 | wxGridCellDateTimeRenderer(const wxString& outformat = wxDefaultDateTimeFormat, |
156 | const wxString& informat = wxDefaultDateTimeFormat); | |
d10f4bf9 VZ |
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 | // parameters string format is "width[,precision]" | |
174 | virtual void SetParameters(const wxString& params); | |
175 | ||
176 | protected: | |
fbfb8bcc | 177 | wxString GetString(const wxGrid& grid, int row, int col); |
d10f4bf9 VZ |
178 | |
179 | wxString m_iformat; | |
180 | wxString m_oformat; | |
181 | wxDateTime m_dateDef; | |
182 | wxDateTime::TimeZone m_tz; | |
183 | }; | |
184 | ||
e2b87f38 | 185 | #endif // wxUSE_DATETIME |
d10f4bf9 VZ |
186 | |
187 | // the default renderer for the cells containing Time and dates.. | |
12f190b0 | 188 | class WXDLLIMPEXP_ADV wxGridCellEnumRenderer : public wxGridCellStringRenderer |
d10f4bf9 VZ |
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]]" | |
209 | virtual void SetParameters(const wxString& params); | |
210 | ||
211 | protected: | |
fbfb8bcc | 212 | wxString GetString(const wxGrid& grid, int row, int col); |
d10f4bf9 VZ |
213 | |
214 | wxArrayString m_choices; | |
215 | }; | |
216 | ||
d10f4bf9 | 217 | |
12f190b0 | 218 | class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringRenderer : public wxGridCellStringRenderer |
d10f4bf9 VZ |
219 | { |
220 | public: | |
221 | wxGridCellAutoWrapStringRenderer() : wxGridCellStringRenderer() { } | |
222 | ||
223 | virtual void Draw(wxGrid& grid, | |
224 | wxGridCellAttr& attr, | |
225 | wxDC& dc, | |
226 | const wxRect& rect, | |
227 | int row, int col, | |
228 | bool isSelected); | |
229 | ||
230 | virtual wxSize GetBestSize(wxGrid& grid, | |
231 | wxGridCellAttr& attr, | |
232 | wxDC& dc, | |
233 | int row, int col); | |
234 | ||
235 | virtual wxGridCellRenderer *Clone() const | |
236 | { return new wxGridCellAutoWrapStringRenderer; } | |
237 | ||
238 | private: | |
239 | wxArrayString GetTextLines( wxGrid& grid, | |
240 | wxDC& dc, | |
fbfb8bcc | 241 | const wxGridCellAttr& attr, |
d10f4bf9 VZ |
242 | const wxRect& rect, |
243 | int row, int col); | |
244 | ||
245 | }; | |
246 | ||
df9fac6d PC |
247 | #endif // wxUSE_GRID |
248 | #endif // _WX_GENERIC_GRIDCTRL_H_ |