]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/grideditors.h
fix wxDEFINE_EVENT_REFERENCE in wxEVENTS_COMPATIBILITY_2_8 case
[wxWidgets.git] / include / wx / generic / grideditors.h
CommitLineData
29efc6e4
FM
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
6// Created: 1/08/1999
7// RCS-ID: $Id$
8// Copyright: (c) Michael Bedward
9// Licence: wxWindows licence
10/////////////////////////////////////////////////////////////////////////////
11
12#ifndef _WX_GENERIC_GRID_EDITORS_H_
13#define _WX_GENERIC_GRID_EDITORS_H_
14
15#include "wx/defs.h"
16
17#if wxUSE_GRID
18
19class wxGridCellEditorEvtHandler : public wxEvtHandler
20{
21public:
22 wxGridCellEditorEvtHandler(wxGrid* grid, wxGridCellEditor* editor)
23 : m_grid(grid),
24 m_editor(editor),
25 m_inSetFocus(false)
26 {
27 }
28
29 void OnKillFocus(wxFocusEvent& event);
30 void OnKeyDown(wxKeyEvent& event);
31 void OnChar(wxKeyEvent& event);
32
33 void SetInSetFocus(bool inSetFocus) { m_inSetFocus = inSetFocus; }
34
35private:
36 wxGrid *m_grid;
37 wxGridCellEditor *m_editor;
38
39 // Work around the fact that a focus kill event can be sent to
40 // a combobox within a set focus event.
41 bool m_inSetFocus;
42
43 DECLARE_EVENT_TABLE()
44 DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler)
45 DECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler)
46};
47
48
49#if wxUSE_TEXTCTRL
50
51// the editor for string/text data
52class WXDLLIMPEXP_ADV wxGridCellTextEditor : public wxGridCellEditor
53{
54public:
55 wxGridCellTextEditor();
56
57 virtual void Create(wxWindow* parent,
58 wxWindowID id,
59 wxEvtHandler* evtHandler);
60 virtual void SetSize(const wxRect& rect);
61
62 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
63
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);
68
69 virtual void Reset();
70 virtual void StartingKey(wxKeyEvent& event);
71 virtual void HandleReturn(wxKeyEvent& event);
72
73 // parameters string format is "max_width"
74 virtual void SetParameters(const wxString& params);
75
76 virtual wxGridCellEditor *Clone() const
77 { return new wxGridCellTextEditor; }
78
79 // added GetValue so we can get the value which is in the control
80 virtual wxString GetValue() const;
81
82protected:
83 wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
84
85 // parts of our virtual functions reused by the derived classes
86 void DoCreate(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler,
87 long style = 0);
88 void DoBeginEdit(const wxString& startValue);
89 void DoReset(const wxString& startValue);
90
91private:
92 size_t m_maxChars; // max number of chars allowed
93 wxString m_value;
94
95 DECLARE_NO_COPY_CLASS(wxGridCellTextEditor)
96};
97
98// the editor for numeric (long) data
99class WXDLLIMPEXP_ADV wxGridCellNumberEditor : public wxGridCellTextEditor
100{
101public:
102 // allows to specify the range - if min == max == -1, no range checking is
103 // done
104 wxGridCellNumberEditor(int min = -1, int max = -1);
105
106 virtual void Create(wxWindow* parent,
107 wxWindowID id,
108 wxEvtHandler* evtHandler);
109
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);
114
115 virtual void Reset();
116 virtual void StartingKey(wxKeyEvent& event);
117
118 // parameters string format is "min,max"
119 virtual void SetParameters(const wxString& params);
120
121 virtual wxGridCellEditor *Clone() const
122 { return new wxGridCellNumberEditor(m_min, m_max); }
123
124 // added GetValue so we can get the value which is in the control
125 virtual wxString GetValue() const;
126
127protected:
128#if wxUSE_SPINCTRL
129 wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; }
130#endif
131
132 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
133 bool HasRange() const
134 {
135#if wxUSE_SPINCTRL
136 return m_min != m_max;
137#else
138 return false;
139#endif
140 }
141
142 // string representation of our value
143 wxString GetString() const
144 { return wxString::Format(_T("%ld"), m_value); }
145
146private:
147 int m_min,
148 m_max;
149
150 long m_value;
151
152 DECLARE_NO_COPY_CLASS(wxGridCellNumberEditor)
153};
154
155// the editor for floating point numbers (double) data
156class WXDLLIMPEXP_ADV wxGridCellFloatEditor : public wxGridCellTextEditor
157{
158public:
159 wxGridCellFloatEditor(int width = -1, int precision = -1);
160
161 virtual void Create(wxWindow* parent,
162 wxWindowID id,
163 wxEvtHandler* evtHandler);
164
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);
169
170 virtual void Reset();
171 virtual void StartingKey(wxKeyEvent& event);
172
173 virtual wxGridCellEditor *Clone() const
174 { return new wxGridCellFloatEditor(m_width, m_precision); }
175
176 // parameters string format is "width,precision"
177 virtual void SetParameters(const wxString& params);
178
179protected:
180 // string representation of our value
181 wxString GetString() const;
182
183private:
184 int m_width,
185 m_precision;
186 double m_value;
187
188 DECLARE_NO_COPY_CLASS(wxGridCellFloatEditor)
189};
190
191#endif // wxUSE_TEXTCTRL
192
193#if wxUSE_CHECKBOX
194
195// the editor for boolean data
196class WXDLLIMPEXP_ADV wxGridCellBoolEditor : public wxGridCellEditor
197{
198public:
199 wxGridCellBoolEditor() { }
200
201 virtual void Create(wxWindow* parent,
202 wxWindowID id,
203 wxEvtHandler* evtHandler);
204
205 virtual void SetSize(const wxRect& rect);
206 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
207
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);
212
213 virtual void Reset();
214 virtual void StartingClick();
215 virtual void StartingKey(wxKeyEvent& event);
216
217 virtual wxGridCellEditor *Clone() const
218 { return new wxGridCellBoolEditor; }
219
220 // added GetValue so we can get the value which is in the control, see
221 // also UseStringValues()
222 virtual wxString GetValue() const;
223
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);
228
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);
232
233protected:
234 wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
235
236private:
237 bool m_value;
238
239 static wxString ms_stringValues[2];
240
241 DECLARE_NO_COPY_CLASS(wxGridCellBoolEditor)
242};
243
244#endif // wxUSE_CHECKBOX
245
246#if wxUSE_COMBOBOX
247
248// the editor for string data allowing to choose from the list of strings
249class WXDLLIMPEXP_ADV wxGridCellChoiceEditor : public wxGridCellEditor
250{
251public:
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);
258
259 virtual void Create(wxWindow* parent,
260 wxWindowID id,
261 wxEvtHandler* evtHandler);
262
263 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
264
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);
268
269 virtual void Reset();
270
271 // parameters string format is "item1[,item2[...,itemN]]"
272 virtual void SetParameters(const wxString& params);
273
274 virtual wxGridCellEditor *Clone() const;
275
276 // added GetValue so we can get the value which is in the control
277 virtual wxString GetValue() const;
278
279protected:
280 wxComboBox *Combo() const { return (wxComboBox *)m_control; }
281
282 wxString m_value;
283 wxArrayString m_choices;
284 bool m_allowOthers;
285
286 DECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor)
287};
288
289#endif // wxUSE_COMBOBOX
290
291#if wxUSE_COMBOBOX
292
293class WXDLLIMPEXP_ADV wxGridCellEnumEditor : public wxGridCellChoiceEditor
294{
295public:
296 wxGridCellEnumEditor( const wxString& choices = wxEmptyString );
297 virtual ~wxGridCellEnumEditor() {}
298
299 virtual wxGridCellEditor* Clone() const;
300
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);
304
305private:
306 long m_index;
307
308 DECLARE_NO_COPY_CLASS(wxGridCellEnumEditor)
309};
310
311#endif // wxUSE_COMBOBOX
312
313class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
314{
315public:
316 wxGridCellAutoWrapStringEditor() : wxGridCellTextEditor() { }
317 virtual void Create(wxWindow* parent,
318 wxWindowID id,
319 wxEvtHandler* evtHandler);
320
321 virtual wxGridCellEditor *Clone() const
322 { return new wxGridCellAutoWrapStringEditor; }
323
324 DECLARE_NO_COPY_CLASS(wxGridCellAutoWrapStringEditor)
325};
326
327#endif // wxUSE_GRID
328#endif // _WX_GENERIC_GRID_EDITORS_H_