]> git.saurik.com Git - wxWidgets.git/blob - include/wx/generic/grideditors.h
Fix activation handling in generic wxDataViewCtrl renderers.
[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 wxGridCellTextEditor();
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(const wxRect& rectCell, wxGridCellAttr *attr);
63
64 virtual bool IsAcceptedKey(wxKeyEvent& event);
65 virtual void BeginEdit(int row, int col, wxGrid* grid);
66 virtual bool EndEdit(int row, int col, const wxGrid* grid,
67 const wxString& oldval, wxString *newval);
68 virtual void ApplyEdit(int row, int col, wxGrid* grid);
69
70 virtual void Reset();
71 virtual void StartingKey(wxKeyEvent& event);
72 virtual void HandleReturn(wxKeyEvent& event);
73
74 // parameters string format is "max_width"
75 virtual void SetParameters(const wxString& params);
76
77 virtual wxGridCellEditor *Clone() const
78 { return new wxGridCellTextEditor; }
79
80 // added GetValue so we can get the value which is in the control
81 virtual wxString GetValue() const;
82
83 protected:
84 wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
85
86 // parts of our virtual functions reused by the derived classes
87 void DoCreate(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler,
88 long style = 0);
89 void DoBeginEdit(const wxString& startValue);
90 void DoReset(const wxString& startValue);
91
92 private:
93 size_t m_maxChars; // max number of chars allowed
94 wxString m_value;
95
96 wxDECLARE_NO_COPY_CLASS(wxGridCellTextEditor);
97 };
98
99 // the editor for numeric (long) data
100 class WXDLLIMPEXP_ADV wxGridCellNumberEditor : public wxGridCellTextEditor
101 {
102 public:
103 // allows to specify the range - if min == max == -1, no range checking is
104 // done
105 wxGridCellNumberEditor(int min = -1, int max = -1);
106
107 virtual void Create(wxWindow* parent,
108 wxWindowID id,
109 wxEvtHandler* evtHandler);
110
111 virtual bool IsAcceptedKey(wxKeyEvent& event);
112 virtual void BeginEdit(int row, int col, wxGrid* grid);
113 virtual bool EndEdit(int row, int col, const wxGrid* grid,
114 const wxString& oldval, wxString *newval);
115 virtual void ApplyEdit(int row, int col, wxGrid* grid);
116
117 virtual void Reset();
118 virtual void StartingKey(wxKeyEvent& event);
119
120 // parameters string format is "min,max"
121 virtual void SetParameters(const wxString& params);
122
123 virtual wxGridCellEditor *Clone() const
124 { return new wxGridCellNumberEditor(m_min, m_max); }
125
126 // added GetValue so we can get the value which is in the control
127 virtual wxString GetValue() const;
128
129 protected:
130 #if wxUSE_SPINCTRL
131 wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; }
132 #endif
133
134 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
135 bool HasRange() const
136 {
137 #if wxUSE_SPINCTRL
138 return m_min != m_max;
139 #else
140 return false;
141 #endif
142 }
143
144 // string representation of our value
145 wxString GetString() const
146 { return wxString::Format(wxT("%ld"), m_value); }
147
148 private:
149 int m_min,
150 m_max;
151
152 long m_value;
153
154 wxDECLARE_NO_COPY_CLASS(wxGridCellNumberEditor);
155 };
156
157 // the editor for floating point numbers (double) data
158 class WXDLLIMPEXP_ADV wxGridCellFloatEditor : public wxGridCellTextEditor
159 {
160 public:
161 wxGridCellFloatEditor(int width = -1, int precision = -1);
162
163 virtual void Create(wxWindow* parent,
164 wxWindowID id,
165 wxEvtHandler* evtHandler);
166
167 virtual bool IsAcceptedKey(wxKeyEvent& event);
168 virtual void BeginEdit(int row, int col, wxGrid* grid);
169 virtual bool EndEdit(int row, int col, const wxGrid* grid,
170 const wxString& oldval, wxString *newval);
171 virtual void ApplyEdit(int row, int col, wxGrid* grid);
172
173 virtual void Reset();
174 virtual void StartingKey(wxKeyEvent& event);
175
176 virtual wxGridCellEditor *Clone() const
177 { return new wxGridCellFloatEditor(m_width, m_precision); }
178
179 // parameters string format is "width,precision"
180 virtual void SetParameters(const wxString& params);
181
182 protected:
183 // string representation of our value
184 wxString GetString() const;
185
186 private:
187 int m_width,
188 m_precision;
189 double m_value;
190
191 wxDECLARE_NO_COPY_CLASS(wxGridCellFloatEditor);
192 };
193
194 #endif // wxUSE_TEXTCTRL
195
196 #if wxUSE_CHECKBOX
197
198 // the editor for boolean data
199 class WXDLLIMPEXP_ADV wxGridCellBoolEditor : public wxGridCellEditor
200 {
201 public:
202 wxGridCellBoolEditor() { }
203
204 virtual void Create(wxWindow* parent,
205 wxWindowID id,
206 wxEvtHandler* evtHandler);
207
208 virtual void SetSize(const wxRect& rect);
209 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
210
211 virtual bool IsAcceptedKey(wxKeyEvent& event);
212 virtual void BeginEdit(int row, int col, wxGrid* grid);
213 virtual bool EndEdit(int row, int col, const wxGrid* grid,
214 const wxString& oldval, wxString *newval);
215 virtual void ApplyEdit(int row, int col, wxGrid* grid);
216
217 virtual void Reset();
218 virtual void StartingClick();
219 virtual void StartingKey(wxKeyEvent& event);
220
221 virtual wxGridCellEditor *Clone() const
222 { return new wxGridCellBoolEditor; }
223
224 // added GetValue so we can get the value which is in the control, see
225 // also UseStringValues()
226 virtual wxString GetValue() const;
227
228 // set the string values returned by GetValue() for the true and false
229 // states, respectively
230 static void UseStringValues(const wxString& valueTrue = wxT("1"),
231 const wxString& valueFalse = wxEmptyString);
232
233 // return true if the given string is equal to the string representation of
234 // true value which we currently use
235 static bool IsTrueValue(const wxString& value);
236
237 protected:
238 wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
239
240 private:
241 bool m_value;
242
243 static wxString ms_stringValues[2];
244
245 wxDECLARE_NO_COPY_CLASS(wxGridCellBoolEditor);
246 };
247
248 #endif // wxUSE_CHECKBOX
249
250 #if wxUSE_COMBOBOX
251
252 // the editor for string data allowing to choose from the list of strings
253 class WXDLLIMPEXP_ADV wxGridCellChoiceEditor : public wxGridCellEditor
254 {
255 public:
256 // if !allowOthers, user can't type a string not in choices array
257 wxGridCellChoiceEditor(size_t count = 0,
258 const wxString choices[] = NULL,
259 bool allowOthers = false);
260 wxGridCellChoiceEditor(const wxArrayString& choices,
261 bool allowOthers = false);
262
263 virtual void Create(wxWindow* parent,
264 wxWindowID id,
265 wxEvtHandler* evtHandler);
266
267 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
268
269 virtual void BeginEdit(int row, int col, wxGrid* grid);
270 virtual bool EndEdit(int row, int col, const wxGrid* grid,
271 const wxString& oldval, wxString *newval);
272 virtual void ApplyEdit(int row, int col, wxGrid* grid);
273
274 virtual void Reset();
275
276 // parameters string format is "item1[,item2[...,itemN]]"
277 virtual void SetParameters(const wxString& params);
278
279 virtual wxGridCellEditor *Clone() const;
280
281 // added GetValue so we can get the value which is in the control
282 virtual wxString GetValue() const;
283
284 protected:
285 wxComboBox *Combo() const { return (wxComboBox *)m_control; }
286
287 wxString m_value;
288 wxArrayString m_choices;
289 bool m_allowOthers;
290
291 wxDECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor);
292 };
293
294 #endif // wxUSE_COMBOBOX
295
296 #if wxUSE_COMBOBOX
297
298 class WXDLLIMPEXP_ADV wxGridCellEnumEditor : public wxGridCellChoiceEditor
299 {
300 public:
301 wxGridCellEnumEditor( const wxString& choices = wxEmptyString );
302 virtual ~wxGridCellEnumEditor() {}
303
304 virtual wxGridCellEditor* Clone() const;
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 private:
312 long m_index;
313
314 wxDECLARE_NO_COPY_CLASS(wxGridCellEnumEditor);
315 };
316
317 #endif // wxUSE_COMBOBOX
318
319 class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
320 {
321 public:
322 wxGridCellAutoWrapStringEditor() : wxGridCellTextEditor() { }
323 virtual void Create(wxWindow* parent,
324 wxWindowID id,
325 wxEvtHandler* evtHandler);
326
327 virtual wxGridCellEditor *Clone() const
328 { return new wxGridCellAutoWrapStringEditor; }
329
330 wxDECLARE_NO_COPY_CLASS(wxGridCellAutoWrapStringEditor);
331 };
332
333 #endif // wxUSE_GRID
334
335 #endif // _WX_GENERIC_GRID_EDITORS_H_