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
);
79 virtual wxGridCellEditor
*Clone() const
80 { return new wxGridCellTextEditor(m_maxChars
); }
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
98 wxDECLARE_NO_COPY_CLASS(wxGridCellTextEditor
);
101 // the editor for numeric (long) data
102 class WXDLLIMPEXP_ADV wxGridCellNumberEditor
: public wxGridCellTextEditor
105 // allows to specify the range - if min == max == -1, no range checking is
107 wxGridCellNumberEditor(int min
= -1, int max
= -1);
109 virtual void Create(wxWindow
* parent
,
111 wxEvtHandler
* evtHandler
);
113 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
114 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
115 virtual bool EndEdit(int row
, int col
, const wxGrid
* grid
,
116 const wxString
& oldval
, wxString
*newval
);
117 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
119 virtual void Reset();
120 virtual void StartingKey(wxKeyEvent
& event
);
122 // parameters string format is "min,max"
123 virtual void SetParameters(const wxString
& params
);
125 virtual wxGridCellEditor
*Clone() const
126 { return new wxGridCellNumberEditor(m_min
, m_max
); }
128 // added GetValue so we can get the value which is in the control
129 virtual wxString
GetValue() const;
133 wxSpinCtrl
*Spin() const { return (wxSpinCtrl
*)m_control
; }
136 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
137 bool HasRange() const
140 return m_min
!= m_max
;
146 // string representation of our value
147 wxString
GetString() const
148 { return wxString::Format(wxT("%ld"), m_value
); }
156 wxDECLARE_NO_COPY_CLASS(wxGridCellNumberEditor
);
160 enum wxGridCellFloatFormat
162 // Decimal floating point (%f)
163 wxGRID_FLOAT_FORMAT_FIXED
= 0x0010,
165 // Scientific notation (mantise/exponent) using e character (%e)
166 wxGRID_FLOAT_FORMAT_SCIENTIFIC
= 0x0020,
168 // Use the shorter of %e or %f (%g)
169 wxGRID_FLOAT_FORMAT_COMPACT
= 0x0040,
171 // To use in combination with one of the above formats (%F/%E/%G)
172 wxGRID_FLOAT_FORMAT_UPPER
= 0x0080,
174 // Format used by default.
175 wxGRID_FLOAT_FORMAT_DEFAULT
= wxGRID_FLOAT_FORMAT_FIXED
,
177 // A mask to extract format from the combination of flags.
178 wxGRID_FLOAT_FORMAT_MASK
= wxGRID_FLOAT_FORMAT_FIXED
|
179 wxGRID_FLOAT_FORMAT_SCIENTIFIC
|
180 wxGRID_FLOAT_FORMAT_COMPACT
|
181 wxGRID_FLOAT_FORMAT_UPPER
184 // the editor for floating point numbers (double) data
185 class WXDLLIMPEXP_ADV wxGridCellFloatEditor
: public wxGridCellTextEditor
188 wxGridCellFloatEditor(int width
= -1,
190 int format
= wxGRID_FLOAT_FORMAT_DEFAULT
);
192 virtual void Create(wxWindow
* parent
,
194 wxEvtHandler
* evtHandler
);
196 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
197 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
198 virtual bool EndEdit(int row
, int col
, const wxGrid
* grid
,
199 const wxString
& oldval
, wxString
*newval
);
200 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
202 virtual void Reset();
203 virtual void StartingKey(wxKeyEvent
& event
);
205 virtual wxGridCellEditor
*Clone() const
206 { return new wxGridCellFloatEditor(m_width
, m_precision
); }
208 // parameters string format is "width[,precision[,format]]"
209 // format to choose beween f|e|g|E|G (f is used by default)
210 virtual void SetParameters(const wxString
& params
);
213 // string representation of our value
214 wxString
GetString();
224 wxDECLARE_NO_COPY_CLASS(wxGridCellFloatEditor
);
227 #endif // wxUSE_TEXTCTRL
231 // the editor for boolean data
232 class WXDLLIMPEXP_ADV wxGridCellBoolEditor
: public wxGridCellEditor
235 wxGridCellBoolEditor() { }
237 virtual void Create(wxWindow
* parent
,
239 wxEvtHandler
* evtHandler
);
241 virtual void SetSize(const wxRect
& rect
);
242 virtual void Show(bool show
, wxGridCellAttr
*attr
= NULL
);
244 virtual bool IsAcceptedKey(wxKeyEvent
& event
);
245 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
246 virtual bool EndEdit(int row
, int col
, const wxGrid
* grid
,
247 const wxString
& oldval
, wxString
*newval
);
248 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
250 virtual void Reset();
251 virtual void StartingClick();
252 virtual void StartingKey(wxKeyEvent
& event
);
254 virtual wxGridCellEditor
*Clone() const
255 { return new wxGridCellBoolEditor
; }
257 // added GetValue so we can get the value which is in the control, see
258 // also UseStringValues()
259 virtual wxString
GetValue() const;
261 // set the string values returned by GetValue() for the true and false
262 // states, respectively
263 static void UseStringValues(const wxString
& valueTrue
= wxT("1"),
264 const wxString
& valueFalse
= wxEmptyString
);
266 // return true if the given string is equal to the string representation of
267 // true value which we currently use
268 static bool IsTrueValue(const wxString
& value
);
271 wxCheckBox
*CBox() const { return (wxCheckBox
*)m_control
; }
276 static wxString ms_stringValues
[2];
278 wxDECLARE_NO_COPY_CLASS(wxGridCellBoolEditor
);
281 #endif // wxUSE_CHECKBOX
285 // the editor for string data allowing to choose from the list of strings
286 class WXDLLIMPEXP_ADV wxGridCellChoiceEditor
: public wxGridCellEditor
289 // if !allowOthers, user can't type a string not in choices array
290 wxGridCellChoiceEditor(size_t count
= 0,
291 const wxString choices
[] = NULL
,
292 bool allowOthers
= false);
293 wxGridCellChoiceEditor(const wxArrayString
& choices
,
294 bool allowOthers
= false);
296 virtual void Create(wxWindow
* parent
,
298 wxEvtHandler
* evtHandler
);
300 virtual void SetSize(const wxRect
& rect
);
302 virtual void PaintBackground(wxDC
& dc
,
303 const wxRect
& rectCell
,
304 const wxGridCellAttr
& attr
);
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
);
311 virtual void Reset();
313 // parameters string format is "item1[,item2[...,itemN]]"
314 virtual void SetParameters(const wxString
& params
);
316 virtual wxGridCellEditor
*Clone() const;
318 // added GetValue so we can get the value which is in the control
319 virtual wxString
GetValue() const;
322 wxComboBox
*Combo() const { return (wxComboBox
*)m_control
; }
325 wxArrayString m_choices
;
328 wxDECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor
);
331 #endif // wxUSE_COMBOBOX
335 class WXDLLIMPEXP_ADV wxGridCellEnumEditor
: public wxGridCellChoiceEditor
338 wxGridCellEnumEditor( const wxString
& choices
= wxEmptyString
);
339 virtual ~wxGridCellEnumEditor() {}
341 virtual wxGridCellEditor
* Clone() const;
343 virtual void BeginEdit(int row
, int col
, wxGrid
* grid
);
344 virtual bool EndEdit(int row
, int col
, const wxGrid
* grid
,
345 const wxString
& oldval
, wxString
*newval
);
346 virtual void ApplyEdit(int row
, int col
, wxGrid
* grid
);
351 wxDECLARE_NO_COPY_CLASS(wxGridCellEnumEditor
);
354 #endif // wxUSE_COMBOBOX
356 class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringEditor
: public wxGridCellTextEditor
359 wxGridCellAutoWrapStringEditor() : wxGridCellTextEditor() { }
360 virtual void Create(wxWindow
* parent
,
362 wxEvtHandler
* evtHandler
);
364 virtual wxGridCellEditor
*Clone() const
365 { return new wxGridCellAutoWrapStringEditor
; }
367 wxDECLARE_NO_COPY_CLASS(wxGridCellAutoWrapStringEditor
);
372 #endif // _WX_GENERIC_GRID_EDITORS_H_