]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/grideditors.h
Applied rowspan patch #15276 (dghart)
[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 virtual void SetValidator(const wxValidator& validator);
79
80 virtual wxGridCellEditor *Clone() const;
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 wxScopedPtr<wxValidator> m_validator;
97 wxString m_value;
98
99 wxDECLARE_NO_COPY_CLASS(wxGridCellTextEditor);
100 };
101
102 // the editor for numeric (long) data
103 class WXDLLIMPEXP_ADV wxGridCellNumberEditor : public wxGridCellTextEditor
104 {
105 public:
106 // allows to specify the range - if min == max == -1, no range checking is
107 // done
108 wxGridCellNumberEditor(int min = -1, int max = -1);
109
110 virtual void Create(wxWindow* parent,
111 wxWindowID id,
112 wxEvtHandler* evtHandler);
113
114 virtual bool IsAcceptedKey(wxKeyEvent& event);
115 virtual void BeginEdit(int row, int col, wxGrid* grid);
116 virtual bool EndEdit(int row, int col, const wxGrid* grid,
117 const wxString& oldval, wxString *newval);
118 virtual void ApplyEdit(int row, int col, wxGrid* grid);
119
120 virtual void Reset();
121 virtual void StartingKey(wxKeyEvent& event);
122
123 // parameters string format is "min,max"
124 virtual void SetParameters(const wxString& params);
125
126 virtual wxGridCellEditor *Clone() const
127 { return new wxGridCellNumberEditor(m_min, m_max); }
128
129 // added GetValue so we can get the value which is in the control
130 virtual wxString GetValue() const;
131
132 protected:
133 #if wxUSE_SPINCTRL
134 wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; }
135 #endif
136
137 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
138 bool HasRange() const
139 {
140 #if wxUSE_SPINCTRL
141 return m_min != m_max;
142 #else
143 return false;
144 #endif
145 }
146
147 // string representation of our value
148 wxString GetString() const
149 { return wxString::Format(wxT("%ld"), m_value); }
150
151 private:
152 int m_min,
153 m_max;
154
155 long m_value;
156
157 wxDECLARE_NO_COPY_CLASS(wxGridCellNumberEditor);
158 };
159
160
161 enum wxGridCellFloatFormat
162 {
163 // Decimal floating point (%f)
164 wxGRID_FLOAT_FORMAT_FIXED = 0x0010,
165
166 // Scientific notation (mantise/exponent) using e character (%e)
167 wxGRID_FLOAT_FORMAT_SCIENTIFIC = 0x0020,
168
169 // Use the shorter of %e or %f (%g)
170 wxGRID_FLOAT_FORMAT_COMPACT = 0x0040,
171
172 // To use in combination with one of the above formats (%F/%E/%G)
173 wxGRID_FLOAT_FORMAT_UPPER = 0x0080,
174
175 // Format used by default.
176 wxGRID_FLOAT_FORMAT_DEFAULT = wxGRID_FLOAT_FORMAT_FIXED,
177
178 // A mask to extract format from the combination of flags.
179 wxGRID_FLOAT_FORMAT_MASK = wxGRID_FLOAT_FORMAT_FIXED |
180 wxGRID_FLOAT_FORMAT_SCIENTIFIC |
181 wxGRID_FLOAT_FORMAT_COMPACT |
182 wxGRID_FLOAT_FORMAT_UPPER
183 };
184
185 // the editor for floating point numbers (double) data
186 class WXDLLIMPEXP_ADV wxGridCellFloatEditor : public wxGridCellTextEditor
187 {
188 public:
189 wxGridCellFloatEditor(int width = -1,
190 int precision = -1,
191 int format = wxGRID_FLOAT_FORMAT_DEFAULT);
192
193 virtual void Create(wxWindow* parent,
194 wxWindowID id,
195 wxEvtHandler* evtHandler);
196
197 virtual bool IsAcceptedKey(wxKeyEvent& event);
198 virtual void BeginEdit(int row, int col, wxGrid* grid);
199 virtual bool EndEdit(int row, int col, const wxGrid* grid,
200 const wxString& oldval, wxString *newval);
201 virtual void ApplyEdit(int row, int col, wxGrid* grid);
202
203 virtual void Reset();
204 virtual void StartingKey(wxKeyEvent& event);
205
206 virtual wxGridCellEditor *Clone() const
207 { return new wxGridCellFloatEditor(m_width, m_precision); }
208
209 // parameters string format is "width[,precision[,format]]"
210 // format to choose beween f|e|g|E|G (f is used by default)
211 virtual void SetParameters(const wxString& params);
212
213 protected:
214 // string representation of our value
215 wxString GetString();
216
217 private:
218 int m_width,
219 m_precision;
220 double m_value;
221
222 int m_style;
223 wxString m_format;
224
225 wxDECLARE_NO_COPY_CLASS(wxGridCellFloatEditor);
226 };
227
228 #endif // wxUSE_TEXTCTRL
229
230 #if wxUSE_CHECKBOX
231
232 // the editor for boolean data
233 class WXDLLIMPEXP_ADV wxGridCellBoolEditor : public wxGridCellEditor
234 {
235 public:
236 wxGridCellBoolEditor() { }
237
238 virtual void Create(wxWindow* parent,
239 wxWindowID id,
240 wxEvtHandler* evtHandler);
241
242 virtual void SetSize(const wxRect& rect);
243 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
244
245 virtual bool IsAcceptedKey(wxKeyEvent& event);
246 virtual void BeginEdit(int row, int col, wxGrid* grid);
247 virtual bool EndEdit(int row, int col, const wxGrid* grid,
248 const wxString& oldval, wxString *newval);
249 virtual void ApplyEdit(int row, int col, wxGrid* grid);
250
251 virtual void Reset();
252 virtual void StartingClick();
253 virtual void StartingKey(wxKeyEvent& event);
254
255 virtual wxGridCellEditor *Clone() const
256 { return new wxGridCellBoolEditor; }
257
258 // added GetValue so we can get the value which is in the control, see
259 // also UseStringValues()
260 virtual wxString GetValue() const;
261
262 // set the string values returned by GetValue() for the true and false
263 // states, respectively
264 static void UseStringValues(const wxString& valueTrue = wxT("1"),
265 const wxString& valueFalse = wxEmptyString);
266
267 // return true if the given string is equal to the string representation of
268 // true value which we currently use
269 static bool IsTrueValue(const wxString& value);
270
271 protected:
272 wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
273
274 private:
275 bool m_value;
276
277 static wxString ms_stringValues[2];
278
279 wxDECLARE_NO_COPY_CLASS(wxGridCellBoolEditor);
280 };
281
282 #endif // wxUSE_CHECKBOX
283
284 #if wxUSE_COMBOBOX
285
286 // the editor for string data allowing to choose from the list of strings
287 class WXDLLIMPEXP_ADV wxGridCellChoiceEditor : public wxGridCellEditor
288 {
289 public:
290 // if !allowOthers, user can't type a string not in choices array
291 wxGridCellChoiceEditor(size_t count = 0,
292 const wxString choices[] = NULL,
293 bool allowOthers = false);
294 wxGridCellChoiceEditor(const wxArrayString& choices,
295 bool allowOthers = false);
296
297 virtual void Create(wxWindow* parent,
298 wxWindowID id,
299 wxEvtHandler* evtHandler);
300
301 virtual void SetSize(const wxRect& rect);
302
303 virtual void PaintBackground(wxDC& dc,
304 const wxRect& rectCell,
305 const wxGridCellAttr& attr);
306
307 virtual void BeginEdit(int row, int col, wxGrid* grid);
308 virtual bool EndEdit(int row, int col, const wxGrid* grid,
309 const wxString& oldval, wxString *newval);
310 virtual void ApplyEdit(int row, int col, wxGrid* grid);
311
312 virtual void Reset();
313
314 // parameters string format is "item1[,item2[...,itemN]]"
315 virtual void SetParameters(const wxString& params);
316
317 virtual wxGridCellEditor *Clone() const;
318
319 // added GetValue so we can get the value which is in the control
320 virtual wxString GetValue() const;
321
322 protected:
323 wxComboBox *Combo() const { return (wxComboBox *)m_control; }
324
325 wxString m_value;
326 wxArrayString m_choices;
327 bool m_allowOthers;
328
329 wxDECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor);
330 };
331
332 #endif // wxUSE_COMBOBOX
333
334 #if wxUSE_COMBOBOX
335
336 class WXDLLIMPEXP_ADV wxGridCellEnumEditor : public wxGridCellChoiceEditor
337 {
338 public:
339 wxGridCellEnumEditor( const wxString& choices = wxEmptyString );
340 virtual ~wxGridCellEnumEditor() {}
341
342 virtual wxGridCellEditor* Clone() const;
343
344 virtual void BeginEdit(int row, int col, wxGrid* grid);
345 virtual bool EndEdit(int row, int col, const wxGrid* grid,
346 const wxString& oldval, wxString *newval);
347 virtual void ApplyEdit(int row, int col, wxGrid* grid);
348
349 private:
350 long m_index;
351
352 wxDECLARE_NO_COPY_CLASS(wxGridCellEnumEditor);
353 };
354
355 #endif // wxUSE_COMBOBOX
356
357 class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
358 {
359 public:
360 wxGridCellAutoWrapStringEditor() : wxGridCellTextEditor() { }
361 virtual void Create(wxWindow* parent,
362 wxWindowID id,
363 wxEvtHandler* evtHandler);
364
365 virtual wxGridCellEditor *Clone() const
366 { return new wxGridCellAutoWrapStringEditor; }
367
368 wxDECLARE_NO_COPY_CLASS(wxGridCellAutoWrapStringEditor);
369 };
370
371 #endif // wxUSE_GRID
372
373 #endif // _WX_GENERIC_GRID_EDITORS_H_