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(const wxString
& oldval
, wxString
*newval
);
67 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
70 virtual void StartingKey(wxKeyEvent
& event
);
71 virtual void HandleReturn(wxKeyEvent
& event
);
73 // parameters string format is "max_width"
74 virtual void SetParameters(const wxString
& params
);
76 virtual wxGridCellEditor
*Clone() const
77 { return new wxGridCellTextEditor
; }
79 // added GetValue so we can get the value which is in the control
80 virtual wxString
GetValue() const;
83 wxTextCtrl
*Text() const { return (wxTextCtrl
*)m_control
; }
85 // parts of our virtual functions reused by the derived classes
86 void DoCreate(wxWindow
* parent
, wxWindowID id
, wxEvtHandler
* evtHandler
,
88 void DoBeginEdit(const wxString
& startValue
);
89 void DoReset(const wxString
& startValue
);
92 size_t m_maxChars
; // max number of chars allowed
95 wxDECLARE_NO_COPY_CLASS(wxGridCellTextEditor
);
98 // the editor for numeric (long) data
99 class WXDLLIMPEXP_ADV wxGridCellNumberEditor
: public wxGridCellTextEditor
102 // allows to specify the range - if min == max == -1, no range checking is
104 wxGridCellNumberEditor(int min
= -1, int max
= -1);
106 virtual void Create(wxWindow
* parent
,
108 wxEvtHandler
* evtHandler
);
110 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
111 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
112 virtual bool EndEdit(const wxString
& oldval
, wxString
*newval
);
113 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
115 virtual void Reset();
116 virtual void StartingKey(wxKeyEvent
& event
);
118 // parameters string format is "min,max"
119 virtual void SetParameters(const wxString
& params
);
121 virtual wxGridCellEditor
*Clone() const
122 { return new wxGridCellNumberEditor(m_min
, m_max
); }
124 // added GetValue so we can get the value which is in the control
125 virtual wxString
GetValue() const;
129 wxSpinCtrl
*Spin() const { return (wxSpinCtrl
*)m_control
; }
132 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
133 bool HasRange() const
136 return m_min
!= m_max
;
142 // string representation of our value
143 wxString
GetString() const
144 { return wxString::Format(_T("%ld"), m_value
); }
152 wxDECLARE_NO_COPY_CLASS(wxGridCellNumberEditor
);
155 // the editor for floating point numbers (double) data
156 class WXDLLIMPEXP_ADV wxGridCellFloatEditor
: public wxGridCellTextEditor
159 wxGridCellFloatEditor(int width
= -1, int precision
= -1);
161 virtual void Create(wxWindow
* parent
,
163 wxEvtHandler
* evtHandler
);
165 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
166 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
167 virtual bool EndEdit(const wxString
& oldval
, wxString
*newval
);
168 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
170 virtual void Reset();
171 virtual void StartingKey(wxKeyEvent
& event
);
173 virtual wxGridCellEditor
*Clone() const
174 { return new wxGridCellFloatEditor(m_width
, m_precision
); }
176 // parameters string format is "width,precision"
177 virtual void SetParameters(const wxString
& params
);
180 // string representation of our value
181 wxString
GetString() const;
188 wxDECLARE_NO_COPY_CLASS(wxGridCellFloatEditor
);
191 #endif // wxUSE_TEXTCTRL
195 // the editor for boolean data
196 class WXDLLIMPEXP_ADV wxGridCellBoolEditor
: public wxGridCellEditor
199 wxGridCellBoolEditor() { }
201 virtual void Create(wxWindow
* parent
,
203 wxEvtHandler
* evtHandler
);
205 virtual void SetSize(const wxRect
& rect
);
206 virtual void Show(bool show
, wxGridCellAttr
*attr
= NULL
);
208 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
209 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
210 virtual bool EndEdit(const wxString
& oldval
, wxString
*newval
);
211 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
213 virtual void Reset();
214 virtual void StartingClick();
215 virtual void StartingKey(wxKeyEvent
& event
);
217 virtual wxGridCellEditor
*Clone() const
218 { return new wxGridCellBoolEditor
; }
220 // added GetValue so we can get the value which is in the control, see
221 // also UseStringValues()
222 virtual wxString
GetValue() const;
224 // set the string values returned by GetValue() for the true and false
225 // states, respectively
226 static void UseStringValues(const wxString
& valueTrue
= _T("1"),
227 const wxString
& valueFalse
= wxEmptyString
);
229 // return true if the given string is equal to the string representation of
230 // true value which we currently use
231 static bool IsTrueValue(const wxString
& value
);
234 wxCheckBox
*CBox() const { return (wxCheckBox
*)m_control
; }
239 static wxString ms_stringValues
[2];
241 wxDECLARE_NO_COPY_CLASS(wxGridCellBoolEditor
);
244 #endif // wxUSE_CHECKBOX
248 // the editor for string data allowing to choose from the list of strings
249 class WXDLLIMPEXP_ADV wxGridCellChoiceEditor
: public wxGridCellEditor
252 // if !allowOthers, user can't type a string not in choices array
253 wxGridCellChoiceEditor(size_t count
= 0,
254 const wxString choices
[] = NULL
,
255 bool allowOthers
= false);
256 wxGridCellChoiceEditor(const wxArrayString
& choices
,
257 bool allowOthers
= false);
259 virtual void Create(wxWindow
* parent
,
261 wxEvtHandler
* evtHandler
);
263 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
265 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
266 virtual bool EndEdit(const wxString
& oldval
, wxString
*newval
);
267 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
269 virtual void Reset();
271 // parameters string format is "item1[,item2[...,itemN]]"
272 virtual void SetParameters(const wxString
& params
);
274 virtual wxGridCellEditor
*Clone() const;
276 // added GetValue so we can get the value which is in the control
277 virtual wxString
GetValue() const;
280 wxComboBox
*Combo() const { return (wxComboBox
*)m_control
; }
283 wxArrayString m_choices
;
286 wxDECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor
);
289 #endif // wxUSE_COMBOBOX
293 class WXDLLIMPEXP_ADV wxGridCellEnumEditor
: public wxGridCellChoiceEditor
296 wxGridCellEnumEditor( const wxString
& choices
= wxEmptyString
);
297 virtual ~wxGridCellEnumEditor() {}
299 virtual wxGridCellEditor
* Clone() const;
301 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
302 virtual bool EndEdit(const wxString
& oldval
, wxString
*newval
);
303 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
308 wxDECLARE_NO_COPY_CLASS(wxGridCellEnumEditor
);
311 #endif // wxUSE_COMBOBOX
313 class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringEditor
: public wxGridCellTextEditor
316 wxGridCellAutoWrapStringEditor() : wxGridCellTextEditor() { }
317 virtual void Create(wxWindow
* parent
,
319 wxEvtHandler
* evtHandler
);
321 virtual wxGridCellEditor
*Clone() const
322 { return new wxGridCellAutoWrapStringEditor
; }
324 wxDECLARE_NO_COPY_CLASS(wxGridCellAutoWrapStringEditor
);
328 #endif // _WX_GENERIC_GRID_EDITORS_H_