]>
Commit | Line | Data |
---|---|---|
78e78812 VZ |
1 | /////////////////////////////////////////////////////////////////////////////\r |
2 | // Name: wx/generic/grideditors.h\r | |
3 | // Purpose: wxGridCellEditorEvtHandler and wxGrid editors\r | |
4 | // Author: Michael Bedward (based on code by Julian Smart, Robin Dunn)\r | |
5 | // Modified by: Santiago Palacios\r | |
6 | // Created: 1/08/1999\r | |
7 | // RCS-ID: $Id$\r | |
8 | // Copyright: (c) Michael Bedward\r | |
9 | // Licence: wxWindows licence\r | |
10 | /////////////////////////////////////////////////////////////////////////////\r | |
11 | \r | |
12 | #ifndef _WX_GENERIC_GRID_EDITORS_H_\r | |
13 | #define _WX_GENERIC_GRID_EDITORS_H_\r | |
14 | \r | |
15 | #include "wx/defs.h"\r | |
16 | \r | |
17 | #if wxUSE_GRID\r | |
18 | \r | |
19 | class wxGridCellEditorEvtHandler : public wxEvtHandler\r | |
20 | {\r | |
21 | public:\r | |
22 | wxGridCellEditorEvtHandler(wxGrid* grid, wxGridCellEditor* editor)\r | |
23 | : m_grid(grid),\r | |
24 | m_editor(editor),\r | |
25 | m_inSetFocus(false)\r | |
26 | {\r | |
27 | }\r | |
28 | \r | |
29 | void OnKillFocus(wxFocusEvent& event);\r | |
30 | void OnKeyDown(wxKeyEvent& event);\r | |
31 | void OnChar(wxKeyEvent& event);\r | |
32 | \r | |
33 | void SetInSetFocus(bool inSetFocus) { m_inSetFocus = inSetFocus; }\r | |
34 | \r | |
35 | private:\r | |
36 | wxGrid *m_grid;\r | |
37 | wxGridCellEditor *m_editor;\r | |
38 | \r | |
39 | // Work around the fact that a focus kill event can be sent to\r | |
40 | // a combobox within a set focus event.\r | |
41 | bool m_inSetFocus;\r | |
42 | \r | |
43 | DECLARE_EVENT_TABLE()\r | |
44 | DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler)\r | |
45 | wxDECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler);\r | |
46 | };\r | |
47 | \r | |
48 | \r | |
49 | #if wxUSE_TEXTCTRL\r | |
50 | \r | |
51 | // the editor for string/text data\r | |
52 | class WXDLLIMPEXP_ADV wxGridCellTextEditor : public wxGridCellEditor\r | |
53 | {\r | |
54 | public:\r | |
55 | wxGridCellTextEditor();\r | |
56 | \r | |
57 | virtual void Create(wxWindow* parent,\r | |
58 | wxWindowID id,\r | |
59 | wxEvtHandler* evtHandler);\r | |
60 | virtual void SetSize(const wxRect& rect);\r | |
61 | \r | |
62 | virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);\r | |
63 | \r | |
64 | virtual bool IsAcceptedKey(wxKeyEvent& event);\r | |
65 | virtual void BeginEdit(int row, int col, wxGrid* grid);\r | |
66 | virtual bool EndEdit(int row, int col, const wxGrid* grid,\r | |
67 | const wxString& oldval, wxString *newval);\r | |
68 | virtual void ApplyEdit(int row, int col, wxGrid* grid);\r | |
69 | \r | |
70 | virtual void Reset();\r | |
71 | virtual void StartingKey(wxKeyEvent& event);\r | |
72 | virtual void HandleReturn(wxKeyEvent& event);\r | |
73 | \r | |
74 | // parameters string format is "max_width"\r | |
75 | virtual void SetParameters(const wxString& params);\r | |
76 | \r | |
77 | virtual wxGridCellEditor *Clone() const\r | |
78 | { return new wxGridCellTextEditor; }\r | |
79 | \r | |
80 | // added GetValue so we can get the value which is in the control\r | |
81 | virtual wxString GetValue() const;\r | |
82 | \r | |
83 | protected:\r | |
84 | wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }\r | |
85 | \r | |
86 | // parts of our virtual functions reused by the derived classes\r | |
87 | void DoCreate(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler,\r | |
88 | long style = 0);\r | |
89 | void DoBeginEdit(const wxString& startValue);\r | |
90 | void DoReset(const wxString& startValue);\r | |
91 | \r | |
92 | private:\r | |
93 | size_t m_maxChars; // max number of chars allowed\r | |
94 | wxString m_value;\r | |
95 | \r | |
96 | wxDECLARE_NO_COPY_CLASS(wxGridCellTextEditor);\r | |
97 | };\r | |
98 | \r | |
99 | // the editor for numeric (long) data\r | |
100 | class WXDLLIMPEXP_ADV wxGridCellNumberEditor : public wxGridCellTextEditor\r | |
101 | {\r | |
102 | public:\r | |
103 | // allows to specify the range - if min == max == -1, no range checking is\r | |
104 | // done\r | |
105 | wxGridCellNumberEditor(int min = -1, int max = -1);\r | |
106 | \r | |
107 | virtual void Create(wxWindow* parent,\r | |
108 | wxWindowID id,\r | |
109 | wxEvtHandler* evtHandler);\r | |
110 | \r | |
111 | virtual bool IsAcceptedKey(wxKeyEvent& event);\r | |
112 | virtual void BeginEdit(int row, int col, wxGrid* grid);\r | |
113 | virtual bool EndEdit(int row, int col, const wxGrid* grid,\r | |
114 | const wxString& oldval, wxString *newval);\r | |
115 | virtual void ApplyEdit(int row, int col, wxGrid* grid);\r | |
116 | \r | |
117 | virtual void Reset();\r | |
118 | virtual void StartingKey(wxKeyEvent& event);\r | |
119 | \r | |
120 | // parameters string format is "min,max"\r | |
121 | virtual void SetParameters(const wxString& params);\r | |
122 | \r | |
123 | virtual wxGridCellEditor *Clone() const\r | |
124 | { return new wxGridCellNumberEditor(m_min, m_max); }\r | |
125 | \r | |
126 | // added GetValue so we can get the value which is in the control\r | |
127 | virtual wxString GetValue() const;\r | |
128 | \r | |
129 | protected:\r | |
130 | #if wxUSE_SPINCTRL\r | |
131 | wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; }\r | |
132 | #endif\r | |
133 | \r | |
134 | // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl\r | |
135 | bool HasRange() const\r | |
136 | {\r | |
137 | #if wxUSE_SPINCTRL\r | |
138 | return m_min != m_max;\r | |
139 | #else\r | |
140 | return false;\r | |
141 | #endif\r | |
142 | }\r | |
143 | \r | |
144 | // string representation of our value\r | |
145 | wxString GetString() const\r | |
146 | { return wxString::Format(_T("%ld"), m_value); }\r | |
147 | \r | |
148 | private:\r | |
149 | int m_min,\r | |
150 | m_max;\r | |
151 | \r | |
152 | long m_value;\r | |
153 | \r | |
154 | wxDECLARE_NO_COPY_CLASS(wxGridCellNumberEditor);\r | |
155 | };\r | |
156 | \r | |
157 | // the editor for floating point numbers (double) data\r | |
158 | class WXDLLIMPEXP_ADV wxGridCellFloatEditor : public wxGridCellTextEditor\r | |
159 | {\r | |
160 | public:\r | |
161 | wxGridCellFloatEditor(int width = -1, int precision = -1);\r | |
162 | \r | |
163 | virtual void Create(wxWindow* parent,\r | |
164 | wxWindowID id,\r | |
165 | wxEvtHandler* evtHandler);\r | |
166 | \r | |
167 | virtual bool IsAcceptedKey(wxKeyEvent& event);\r | |
168 | virtual void BeginEdit(int row, int col, wxGrid* grid);\r | |
169 | virtual bool EndEdit(int row, int col, const wxGrid* grid,\r | |
170 | const wxString& oldval, wxString *newval);\r | |
171 | virtual void ApplyEdit(int row, int col, wxGrid* grid);\r | |
172 | \r | |
173 | virtual void Reset();\r | |
174 | virtual void StartingKey(wxKeyEvent& event);\r | |
175 | \r | |
176 | virtual wxGridCellEditor *Clone() const\r | |
177 | { return new wxGridCellFloatEditor(m_width, m_precision); }\r | |
178 | \r | |
179 | // parameters string format is "width,precision"\r | |
180 | virtual void SetParameters(const wxString& params);\r | |
181 | \r | |
182 | protected:\r | |
183 | // string representation of our value\r | |
184 | wxString GetString() const;\r | |
185 | \r | |
186 | private:\r | |
187 | int m_width,\r | |
188 | m_precision;\r | |
189 | double m_value;\r | |
190 | \r | |
191 | wxDECLARE_NO_COPY_CLASS(wxGridCellFloatEditor);\r | |
192 | };\r | |
193 | \r | |
194 | #endif // wxUSE_TEXTCTRL\r | |
195 | \r | |
196 | #if wxUSE_CHECKBOX\r | |
197 | \r | |
198 | // the editor for boolean data\r | |
199 | class WXDLLIMPEXP_ADV wxGridCellBoolEditor : public wxGridCellEditor\r | |
200 | {\r | |
201 | public:\r | |
202 | wxGridCellBoolEditor() { }\r | |
203 | \r | |
204 | virtual void Create(wxWindow* parent,\r | |
205 | wxWindowID id,\r | |
206 | wxEvtHandler* evtHandler);\r | |
207 | \r | |
208 | virtual void SetSize(const wxRect& rect);\r | |
209 | virtual void Show(bool show, wxGridCellAttr *attr = NULL);\r | |
210 | \r | |
211 | virtual bool IsAcceptedKey(wxKeyEvent& event);\r | |
212 | virtual void BeginEdit(int row, int col, wxGrid* grid);\r | |
213 | virtual bool EndEdit(int row, int col, const wxGrid* grid,\r | |
214 | const wxString& oldval, wxString *newval);\r | |
215 | virtual void ApplyEdit(int row, int col, wxGrid* grid);\r | |
216 | \r | |
217 | virtual void Reset();\r | |
218 | virtual void StartingClick();\r | |
219 | virtual void StartingKey(wxKeyEvent& event);\r | |
220 | \r | |
221 | virtual wxGridCellEditor *Clone() const\r | |
222 | { return new wxGridCellBoolEditor; }\r | |
223 | \r | |
224 | // added GetValue so we can get the value which is in the control, see\r | |
225 | // also UseStringValues()\r | |
226 | virtual wxString GetValue() const;\r | |
227 | \r | |
228 | // set the string values returned by GetValue() for the true and false\r | |
229 | // states, respectively\r | |
230 | static void UseStringValues(const wxString& valueTrue = _T("1"),\r | |
231 | const wxString& valueFalse = wxEmptyString);\r | |
232 | \r | |
233 | // return true if the given string is equal to the string representation of\r | |
234 | // true value which we currently use\r | |
235 | static bool IsTrueValue(const wxString& value);\r | |
236 | \r | |
237 | protected:\r | |
238 | wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }\r | |
239 | \r | |
240 | private:\r | |
241 | bool m_value;\r | |
242 | \r | |
243 | static wxString ms_stringValues[2];\r | |
244 | \r | |
245 | wxDECLARE_NO_COPY_CLASS(wxGridCellBoolEditor);\r | |
246 | };\r | |
247 | \r | |
248 | #endif // wxUSE_CHECKBOX\r | |
249 | \r | |
250 | #if wxUSE_COMBOBOX\r | |
251 | \r | |
252 | // the editor for string data allowing to choose from the list of strings\r | |
253 | class WXDLLIMPEXP_ADV wxGridCellChoiceEditor : public wxGridCellEditor\r | |
254 | {\r | |
255 | public:\r | |
256 | // if !allowOthers, user can't type a string not in choices array\r | |
257 | wxGridCellChoiceEditor(size_t count = 0,\r | |
258 | const wxString choices[] = NULL,\r | |
259 | bool allowOthers = false);\r | |
260 | wxGridCellChoiceEditor(const wxArrayString& choices,\r | |
261 | bool allowOthers = false);\r | |
262 | \r | |
263 | virtual void Create(wxWindow* parent,\r | |
264 | wxWindowID id,\r | |
265 | wxEvtHandler* evtHandler);\r | |
266 | \r | |
267 | virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);\r | |
268 | \r | |
269 | virtual void BeginEdit(int row, int col, wxGrid* grid);\r | |
270 | virtual bool EndEdit(int row, int col, const wxGrid* grid,\r | |
271 | const wxString& oldval, wxString *newval);\r | |
272 | virtual void ApplyEdit(int row, int col, wxGrid* grid);\r | |
273 | \r | |
274 | virtual void Reset();\r | |
275 | \r | |
276 | // parameters string format is "item1[,item2[...,itemN]]"\r | |
277 | virtual void SetParameters(const wxString& params);\r | |
278 | \r | |
279 | virtual wxGridCellEditor *Clone() const;\r | |
280 | \r | |
281 | // added GetValue so we can get the value which is in the control\r | |
282 | virtual wxString GetValue() const;\r | |
283 | \r | |
284 | protected:\r | |
285 | wxComboBox *Combo() const { return (wxComboBox *)m_control; }\r | |
286 | \r | |
287 | wxString m_value;\r | |
288 | wxArrayString m_choices;\r | |
289 | bool m_allowOthers;\r | |
290 | \r | |
291 | wxDECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor);\r | |
292 | };\r | |
293 | \r | |
294 | #endif // wxUSE_COMBOBOX\r | |
295 | \r | |
296 | #if wxUSE_COMBOBOX\r | |
297 | \r | |
298 | class WXDLLIMPEXP_ADV wxGridCellEnumEditor : public wxGridCellChoiceEditor\r | |
299 | {\r | |
300 | public:\r | |
301 | wxGridCellEnumEditor( const wxString& choices = wxEmptyString );\r | |
302 | virtual ~wxGridCellEnumEditor() {}\r | |
303 | \r | |
304 | virtual wxGridCellEditor* Clone() const;\r | |
305 | \r | |
306 | virtual void BeginEdit(int row, int col, wxGrid* grid);\r | |
307 | virtual bool EndEdit(int row, int col, const wxGrid* grid,\r | |
308 | const wxString& oldval, wxString *newval);\r | |
309 | virtual void ApplyEdit(int row, int col, wxGrid* grid);\r | |
310 | \r | |
311 | private:\r | |
312 | long m_index;\r | |
313 | \r | |
314 | wxDECLARE_NO_COPY_CLASS(wxGridCellEnumEditor);\r | |
315 | };\r | |
316 | \r | |
317 | #endif // wxUSE_COMBOBOX\r | |
318 | \r | |
319 | class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor\r | |
320 | {\r | |
321 | public:\r | |
322 | wxGridCellAutoWrapStringEditor() : wxGridCellTextEditor() { }\r | |
323 | virtual void Create(wxWindow* parent,\r | |
324 | wxWindowID id,\r | |
325 | wxEvtHandler* evtHandler);\r | |
326 | \r | |
327 | virtual wxGridCellEditor *Clone() const\r | |
328 | { return new wxGridCellAutoWrapStringEditor; }\r | |
329 | \r | |
330 | wxDECLARE_NO_COPY_CLASS(wxGridCellAutoWrapStringEditor);\r | |
331 | };\r | |
332 | \r | |
333 | #endif // wxUSE_GRID\r | |
334 | \r | |
335 | #endif // _WX_GENERIC_GRID_EDITORS_H_\r |