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(wxT("%ld"), m_value
); }
154 wxDECLARE_NO_COPY_CLASS(wxGridCellNumberEditor
);
158 enum wxGridCellFloatFormat
160 // Decimal floating point (%f)
161 wxGRID_FLOAT_FORMAT_FIXED
= 0x0010,
163 // Scientific notation (mantise/exponent) using e character (%e)
164 wxGRID_FLOAT_FORMAT_SCIENTIFIC
= 0x0020,
166 // Use the shorter of %e or %f (%g)
167 wxGRID_FLOAT_FORMAT_COMPACT
= 0x0040,
169 // To use in combination with one of the above formats (%F/%E/%G)
170 wxGRID_FLOAT_FORMAT_UPPER
= 0x0080,
172 // Format used by default.
173 wxGRID_FLOAT_FORMAT_DEFAULT
= wxGRID_FLOAT_FORMAT_FIXED
,
175 // A mask to extract format from the combination of flags.
176 wxGRID_FLOAT_FORMAT_MASK
= wxGRID_FLOAT_FORMAT_FIXED
|
177 wxGRID_FLOAT_FORMAT_SCIENTIFIC
|
178 wxGRID_FLOAT_FORMAT_COMPACT
|
179 wxGRID_FLOAT_FORMAT_UPPER
182 // the editor for floating point numbers (double) data
183 class WXDLLIMPEXP_ADV wxGridCellFloatEditor
: public wxGridCellTextEditor
186 wxGridCellFloatEditor(int width
= -1,
188 int format
= wxGRID_FLOAT_FORMAT_DEFAULT
);
190 virtual void Create(wxWindow
* parent
,
192 wxEvtHandler
* evtHandler
);
194 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
195 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
196 virtual bool EndEdit(int row
, int col
, const wxGrid
* grid
,
197 const wxString
& oldval
, wxString
*newval
);
198 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
200 virtual void Reset();
201 virtual void StartingKey(wxKeyEvent
& event
);
203 virtual wxGridCellEditor
*Clone() const
204 { return new wxGridCellFloatEditor(m_width
, m_precision
); }
206 // parameters string format is "width[,precision[,format]]"
207 // format to choose beween f|e|g|E|G (f is used by default)
208 virtual void SetParameters(const wxString
& params
);
211 // string representation of our value
212 wxString
GetString();
222 wxDECLARE_NO_COPY_CLASS(wxGridCellFloatEditor
);
225 #endif // wxUSE_TEXTCTRL
229 // the editor for boolean data
230 class WXDLLIMPEXP_ADV wxGridCellBoolEditor
: public wxGridCellEditor
233 wxGridCellBoolEditor() { }
235 virtual void Create(wxWindow
* parent
,
237 wxEvtHandler
* evtHandler
);
239 virtual void SetSize(const wxRect
& rect
);
240 virtual void Show(bool show
, wxGridCellAttr
*attr
= NULL
);
242 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
243 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
244 virtual bool EndEdit(int row
, int col
, const wxGrid
* grid
,
245 const wxString
& oldval
, wxString
*newval
);
246 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
248 virtual void Reset();
249 virtual void StartingClick();
250 virtual void StartingKey(wxKeyEvent
& event
);
252 virtual wxGridCellEditor
*Clone() const
253 { return new wxGridCellBoolEditor
; }
255 // added GetValue so we can get the value which is in the control, see
256 // also UseStringValues()
257 virtual wxString
GetValue() const;
259 // set the string values returned by GetValue() for the true and false
260 // states, respectively
261 static void UseStringValues(const wxString
& valueTrue
= wxT("1"),
262 const wxString
& valueFalse
= wxEmptyString
);
264 // return true if the given string is equal to the string representation of
265 // true value which we currently use
266 static bool IsTrueValue(const wxString
& value
);
269 wxCheckBox
*CBox() const { return (wxCheckBox
*)m_control
; }
274 static wxString ms_stringValues
[2];
276 wxDECLARE_NO_COPY_CLASS(wxGridCellBoolEditor
);
279 #endif // wxUSE_CHECKBOX
283 // the editor for string data allowing to choose from the list of strings
284 class WXDLLIMPEXP_ADV wxGridCellChoiceEditor
: public wxGridCellEditor
287 // if !allowOthers, user can't type a string not in choices array
288 wxGridCellChoiceEditor(size_t count
= 0,
289 const wxString choices
[] = NULL
,
290 bool allowOthers
= false);
291 wxGridCellChoiceEditor(const wxArrayString
& choices
,
292 bool allowOthers
= false);
294 virtual void Create(wxWindow
* parent
,
296 wxEvtHandler
* evtHandler
);
298 virtual void SetSize(const wxRect
& rect
);
300 virtual void PaintBackground(const wxRect
& rectCell
, wxGridCellAttr
*attr
);
302 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
303 virtual bool EndEdit(int row
, int col
, const wxGrid
* grid
,
304 const wxString
& oldval
, wxString
*newval
);
305 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
307 virtual void Reset();
309 // parameters string format is "item1[,item2[...,itemN]]"
310 virtual void SetParameters(const wxString
& params
);
312 virtual wxGridCellEditor
*Clone() const;
314 // added GetValue so we can get the value which is in the control
315 virtual wxString
GetValue() const;
318 wxComboBox
*Combo() const { return (wxComboBox
*)m_control
; }
321 wxArrayString m_choices
;
324 wxDECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor
);
327 #endif // wxUSE_COMBOBOX
331 class WXDLLIMPEXP_ADV wxGridCellEnumEditor
: public wxGridCellChoiceEditor
334 wxGridCellEnumEditor( const wxString
& choices
= wxEmptyString
);
335 virtual ~wxGridCellEnumEditor() {}
337 virtual wxGridCellEditor
* Clone() const;
339 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
340 virtual bool EndEdit(int row
, int col
, const wxGrid
* grid
,
341 const wxString
& oldval
, wxString
*newval
);
342 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
347 wxDECLARE_NO_COPY_CLASS(wxGridCellEnumEditor
);
350 #endif // wxUSE_COMBOBOX
352 class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringEditor
: public wxGridCellTextEditor
355 wxGridCellAutoWrapStringEditor() : wxGridCellTextEditor() { }
356 virtual void Create(wxWindow
* parent
,
358 wxEvtHandler
* evtHandler
);
360 virtual wxGridCellEditor
*Clone() const
361 { return new wxGridCellAutoWrapStringEditor
; }
363 wxDECLARE_NO_COPY_CLASS(wxGridCellAutoWrapStringEditor
);
368 #endif // _WX_GENERIC_GRID_EDITORS_H_