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
8 // Copyright: (c) Michael Bedward
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_GENERIC_GRID_EDITORS_H_
13 #define _WX_GENERIC_GRID_EDITORS_H_
19 class wxGridCellEditorEvtHandler
: public wxEvtHandler
22 wxGridCellEditorEvtHandler(wxGrid
* grid
, wxGridCellEditor
* editor
)
29 void OnKillFocus(wxFocusEvent
& event
);
30 void OnKeyDown(wxKeyEvent
& event
);
31 void OnChar(wxKeyEvent
& event
);
33 void SetInSetFocus(bool inSetFocus
) { m_inSetFocus
= inSetFocus
; }
37 wxGridCellEditor
*m_editor
;
39 // Work around the fact that a focus kill event can be sent to
40 // a combobox within a set focus event.
44 DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler
)
45 wxDECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler
);
51 // the editor for string/text data
52 class WXDLLIMPEXP_ADV wxGridCellTextEditor
: public wxGridCellEditor
55 wxGridCellTextEditor();
57 virtual void Create(wxWindow
* parent
,
59 wxEvtHandler
* evtHandler
);
60 virtual void SetSize(const wxRect
& rect
);
62 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
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
);
71 virtual void StartingKey(wxKeyEvent
& event
);
72 virtual void HandleReturn(wxKeyEvent
& event
);
74 // parameters string format is "max_width"
75 virtual void SetParameters(const wxString
& params
);
77 virtual wxGridCellEditor
*Clone() const
78 { return new wxGridCellTextEditor
; }
80 // added GetValue so we can get the value which is in the control
81 virtual wxString
GetValue() const;
84 wxTextCtrl
*Text() const { return (wxTextCtrl
*)m_control
; }
86 // parts of our virtual functions reused by the derived classes
87 void DoCreate(wxWindow
* parent
, wxWindowID id
, wxEvtHandler
* evtHandler
,
89 void DoBeginEdit(const wxString
& startValue
);
90 void DoReset(const wxString
& startValue
);
93 size_t m_maxChars
; // max number of chars allowed
96 wxDECLARE_NO_COPY_CLASS(wxGridCellTextEditor
);
99 // the editor for numeric (long) data
100 class WXDLLIMPEXP_ADV wxGridCellNumberEditor
: public wxGridCellTextEditor
103 // allows to specify the range - if min == max == -1, no range checking is
105 wxGridCellNumberEditor(int min
= -1, int max
= -1);
107 virtual void Create(wxWindow
* parent
,
109 wxEvtHandler
* evtHandler
);
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
);
117 virtual void Reset();
118 virtual void StartingKey(wxKeyEvent
& event
);
120 // parameters string format is "min,max"
121 virtual void SetParameters(const wxString
& params
);
123 virtual wxGridCellEditor
*Clone() const
124 { return new wxGridCellNumberEditor(m_min
, m_max
); }
126 // added GetValue so we can get the value which is in the control
127 virtual wxString
GetValue() const;
131 wxSpinCtrl
*Spin() const { return (wxSpinCtrl
*)m_control
; }
134 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
135 bool HasRange() const
138 return m_min
!= m_max
;
144 // string representation of our value
145 wxString
GetString() const
146 { return wxString::Format(_T("%ld"), m_value
); }
154 wxDECLARE_NO_COPY_CLASS(wxGridCellNumberEditor
);
157 // the editor for floating point numbers (double) data
158 class WXDLLIMPEXP_ADV wxGridCellFloatEditor
: public wxGridCellTextEditor
161 wxGridCellFloatEditor(int width
= -1, int precision
= -1);
163 virtual void Create(wxWindow
* parent
,
165 wxEvtHandler
* evtHandler
);
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
);
173 virtual void Reset();
174 virtual void StartingKey(wxKeyEvent
& event
);
176 virtual wxGridCellEditor
*Clone() const
177 { return new wxGridCellFloatEditor(m_width
, m_precision
); }
179 // parameters string format is "width,precision"
180 virtual void SetParameters(const wxString
& params
);
183 // string representation of our value
184 wxString
GetString() const;
191 wxDECLARE_NO_COPY_CLASS(wxGridCellFloatEditor
);
194 #endif // wxUSE_TEXTCTRL
198 // the editor for boolean data
199 class WXDLLIMPEXP_ADV wxGridCellBoolEditor
: public wxGridCellEditor
202 wxGridCellBoolEditor() { }
204 virtual void Create(wxWindow
* parent
,
206 wxEvtHandler
* evtHandler
);
208 virtual void SetSize(const wxRect
& rect
);
209 virtual void Show(bool show
, wxGridCellAttr
*attr
= NULL
);
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
);
217 virtual void Reset();
218 virtual void StartingClick();
219 virtual void StartingKey(wxKeyEvent
& event
);
221 virtual wxGridCellEditor
*Clone() const
222 { return new wxGridCellBoolEditor
; }
224 // added GetValue so we can get the value which is in the control, see
225 // also UseStringValues()
226 virtual wxString
GetValue() const;
228 // set the string values returned by GetValue() for the true and false
229 // states, respectively
230 static void UseStringValues(const wxString
& valueTrue
= _T("1"),
231 const wxString
& valueFalse
= wxEmptyString
);
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
);
238 wxCheckBox
*CBox() const { return (wxCheckBox
*)m_control
; }
243 static wxString ms_stringValues
[2];
245 wxDECLARE_NO_COPY_CLASS(wxGridCellBoolEditor
);
248 #endif // wxUSE_CHECKBOX
252 // the editor for string data allowing to choose from the list of strings
253 class WXDLLIMPEXP_ADV wxGridCellChoiceEditor
: public wxGridCellEditor
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);
263 virtual void Create(wxWindow
* parent
,
265 wxEvtHandler
* evtHandler
);
267 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
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
);
274 virtual void Reset();
276 // parameters string format is "item1[,item2[...,itemN]]"
277 virtual void SetParameters(const wxString
& params
);
279 virtual wxGridCellEditor
*Clone() const;
281 // added GetValue so we can get the value which is in the control
282 virtual wxString
GetValue() const;
285 wxComboBox
*Combo() const { return (wxComboBox
*)m_control
; }
288 wxArrayString m_choices
;
291 wxDECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor
);
294 #endif // wxUSE_COMBOBOX
298 class WXDLLIMPEXP_ADV wxGridCellEnumEditor
: public wxGridCellChoiceEditor
301 wxGridCellEnumEditor( const wxString
& choices
= wxEmptyString
);
302 virtual ~wxGridCellEnumEditor() {}
304 virtual wxGridCellEditor
* Clone() const;
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
);
314 wxDECLARE_NO_COPY_CLASS(wxGridCellEnumEditor
);
317 #endif // wxUSE_COMBOBOX
319 class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringEditor
: public wxGridCellTextEditor
322 wxGridCellAutoWrapStringEditor() : wxGridCellTextEditor() { }
323 virtual void Create(wxWindow
* parent
,
325 wxEvtHandler
* evtHandler
);
327 virtual wxGridCellEditor
*Clone() const
328 { return new wxGridCellAutoWrapStringEditor
; }
330 wxDECLARE_NO_COPY_CLASS(wxGridCellAutoWrapStringEditor
);
335 #endif // _WX_GENERIC_GRID_EDITORS_H_