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