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 wxEXPLICIT
wxGridCellTextEditor(size_t maxChars
= 0);
57 virtual void Create(wxWindow
* parent
,
59 wxEvtHandler
* evtHandler
);
60 virtual void SetSize(const wxRect
& rect
);
62 virtual void PaintBackground(wxDC
& dc
,
63 const wxRect
& rectCell
,
64 const wxGridCellAttr
& attr
);
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
);
73 virtual void StartingKey(wxKeyEvent
& event
);
74 virtual void HandleReturn(wxKeyEvent
& event
);
76 // parameters string format is "max_width"
77 virtual void SetParameters(const wxString
& params
);
78 virtual void SetValidator(const wxValidator
& validator
);
80 virtual wxGridCellEditor
*Clone() const;
82 // added GetValue so we can get the value which is in the control
83 virtual wxString
GetValue() const;
86 wxTextCtrl
*Text() const { return (wxTextCtrl
*)m_control
; }
88 // parts of our virtual functions reused by the derived classes
89 void DoCreate(wxWindow
* parent
, wxWindowID id
, wxEvtHandler
* evtHandler
,
91 void DoBeginEdit(const wxString
& startValue
);
92 void DoReset(const wxString
& startValue
);
95 size_t m_maxChars
; // max number of chars allowed
96 wxScopedPtr
<wxValidator
> m_validator
;
99 wxDECLARE_NO_COPY_CLASS(wxGridCellTextEditor
);
102 // the editor for numeric (long) data
103 class WXDLLIMPEXP_ADV wxGridCellNumberEditor
: public wxGridCellTextEditor
106 // allows to specify the range - if min == max == -1, no range checking is
108 wxGridCellNumberEditor(int min
= -1, int max
= -1);
110 virtual void Create(wxWindow
* parent
,
112 wxEvtHandler
* evtHandler
);
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
);
120 virtual void Reset();
121 virtual void StartingKey(wxKeyEvent
& event
);
123 // parameters string format is "min,max"
124 virtual void SetParameters(const wxString
& params
);
126 virtual wxGridCellEditor
*Clone() const
127 { return new wxGridCellNumberEditor(m_min
, m_max
); }
129 // added GetValue so we can get the value which is in the control
130 virtual wxString
GetValue() const;
134 wxSpinCtrl
*Spin() const { return (wxSpinCtrl
*)m_control
; }
137 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
138 bool HasRange() const
141 return m_min
!= m_max
;
147 // string representation of our value
148 wxString
GetString() const
149 { return wxString::Format(wxT("%ld"), m_value
); }
157 wxDECLARE_NO_COPY_CLASS(wxGridCellNumberEditor
);
161 enum wxGridCellFloatFormat
163 // Decimal floating point (%f)
164 wxGRID_FLOAT_FORMAT_FIXED
= 0x0010,
166 // Scientific notation (mantise/exponent) using e character (%e)
167 wxGRID_FLOAT_FORMAT_SCIENTIFIC
= 0x0020,
169 // Use the shorter of %e or %f (%g)
170 wxGRID_FLOAT_FORMAT_COMPACT
= 0x0040,
172 // To use in combination with one of the above formats (%F/%E/%G)
173 wxGRID_FLOAT_FORMAT_UPPER
= 0x0080,
175 // Format used by default.
176 wxGRID_FLOAT_FORMAT_DEFAULT
= wxGRID_FLOAT_FORMAT_FIXED
,
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
185 // the editor for floating point numbers (double) data
186 class WXDLLIMPEXP_ADV wxGridCellFloatEditor
: public wxGridCellTextEditor
189 wxGridCellFloatEditor(int width
= -1,
191 int format
= wxGRID_FLOAT_FORMAT_DEFAULT
);
193 virtual void Create(wxWindow
* parent
,
195 wxEvtHandler
* evtHandler
);
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
);
203 virtual void Reset();
204 virtual void StartingKey(wxKeyEvent
& event
);
206 virtual wxGridCellEditor
*Clone() const
207 { return new wxGridCellFloatEditor(m_width
, m_precision
); }
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
);
214 // string representation of our value
215 wxString
GetString();
225 wxDECLARE_NO_COPY_CLASS(wxGridCellFloatEditor
);
228 #endif // wxUSE_TEXTCTRL
232 // the editor for boolean data
233 class WXDLLIMPEXP_ADV wxGridCellBoolEditor
: public wxGridCellEditor
236 wxGridCellBoolEditor() { }
238 virtual void Create(wxWindow
* parent
,
240 wxEvtHandler
* evtHandler
);
242 virtual void SetSize(const wxRect
& rect
);
243 virtual void Show(bool show
, wxGridCellAttr
*attr
= NULL
);
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
);
251 virtual void Reset();
252 virtual void StartingClick();
253 virtual void StartingKey(wxKeyEvent
& event
);
255 virtual wxGridCellEditor
*Clone() const
256 { return new wxGridCellBoolEditor
; }
258 // added GetValue so we can get the value which is in the control, see
259 // also UseStringValues()
260 virtual wxString
GetValue() const;
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
);
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
);
272 wxCheckBox
*CBox() const { return (wxCheckBox
*)m_control
; }
277 static wxString ms_stringValues
[2];
279 wxDECLARE_NO_COPY_CLASS(wxGridCellBoolEditor
);
282 #endif // wxUSE_CHECKBOX
286 // the editor for string data allowing to choose from the list of strings
287 class WXDLLIMPEXP_ADV wxGridCellChoiceEditor
: public wxGridCellEditor
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);
297 virtual void Create(wxWindow
* parent
,
299 wxEvtHandler
* evtHandler
);
301 virtual void SetSize(const wxRect
& rect
);
303 virtual void PaintBackground(wxDC
& dc
,
304 const wxRect
& rectCell
,
305 const wxGridCellAttr
& attr
);
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
);
312 virtual void Reset();
314 // parameters string format is "item1[,item2[...,itemN]]"
315 virtual void SetParameters(const wxString
& params
);
317 virtual wxGridCellEditor
*Clone() const;
319 // added GetValue so we can get the value which is in the control
320 virtual wxString
GetValue() const;
323 wxComboBox
*Combo() const { return (wxComboBox
*)m_control
; }
326 wxArrayString m_choices
;
329 wxDECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor
);
332 #endif // wxUSE_COMBOBOX
336 class WXDLLIMPEXP_ADV wxGridCellEnumEditor
: public wxGridCellChoiceEditor
339 wxGridCellEnumEditor( const wxString
& choices
= wxEmptyString
);
340 virtual ~wxGridCellEnumEditor() {}
342 virtual wxGridCellEditor
* Clone() const;
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
);
352 wxDECLARE_NO_COPY_CLASS(wxGridCellEnumEditor
);
355 #endif // wxUSE_COMBOBOX
357 class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringEditor
: public wxGridCellTextEditor
360 wxGridCellAutoWrapStringEditor() : wxGridCellTextEditor() { }
361 virtual void Create(wxWindow
* parent
,
363 wxEvtHandler
* evtHandler
);
365 virtual wxGridCellEditor
*Clone() const
366 { return new wxGridCellAutoWrapStringEditor
; }
368 wxDECLARE_NO_COPY_CLASS(wxGridCellAutoWrapStringEditor
);
373 #endif // _WX_GENERIC_GRID_EDITORS_H_