]>
Commit | Line | Data |
---|---|---|
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 | ||
19 | class wxGridCellEditorEvtHandler : public wxEvtHandler | |
20 | { | |
21 | public: | |
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 | ||
35 | private: | |
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) | |
c0c133e1 | 45 | wxDECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler); |
29efc6e4 FM |
46 | }; |
47 | ||
48 | ||
49 | #if wxUSE_TEXTCTRL | |
50 | ||
51 | // the editor for string/text data | |
52 | class WXDLLIMPEXP_ADV wxGridCellTextEditor : public wxGridCellEditor | |
53 | { | |
54 | public: | |
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 | ||
82 | protected: | |
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 | ||
91 | private: | |
92 | size_t m_maxChars; // max number of chars allowed | |
93 | wxString m_value; | |
94 | ||
c0c133e1 | 95 | wxDECLARE_NO_COPY_CLASS(wxGridCellTextEditor); |
29efc6e4 FM |
96 | }; |
97 | ||
98 | // the editor for numeric (long) data | |
99 | class WXDLLIMPEXP_ADV wxGridCellNumberEditor : public wxGridCellTextEditor | |
100 | { | |
101 | public: | |
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 | ||
127 | protected: | |
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 | ||
146 | private: | |
147 | int m_min, | |
148 | m_max; | |
149 | ||
150 | long m_value; | |
151 | ||
c0c133e1 | 152 | wxDECLARE_NO_COPY_CLASS(wxGridCellNumberEditor); |
29efc6e4 FM |
153 | }; |
154 | ||
155 | // the editor for floating point numbers (double) data | |
156 | class WXDLLIMPEXP_ADV wxGridCellFloatEditor : public wxGridCellTextEditor | |
157 | { | |
158 | public: | |
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 | ||
179 | protected: | |
180 | // string representation of our value | |
181 | wxString GetString() const; | |
182 | ||
183 | private: | |
184 | int m_width, | |
185 | m_precision; | |
186 | double m_value; | |
187 | ||
c0c133e1 | 188 | wxDECLARE_NO_COPY_CLASS(wxGridCellFloatEditor); |
29efc6e4 FM |
189 | }; |
190 | ||
191 | #endif // wxUSE_TEXTCTRL | |
192 | ||
193 | #if wxUSE_CHECKBOX | |
194 | ||
195 | // the editor for boolean data | |
196 | class WXDLLIMPEXP_ADV wxGridCellBoolEditor : public wxGridCellEditor | |
197 | { | |
198 | public: | |
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 | ||
233 | protected: | |
234 | wxCheckBox *CBox() const { return (wxCheckBox *)m_control; } | |
235 | ||
236 | private: | |
237 | bool m_value; | |
238 | ||
239 | static wxString ms_stringValues[2]; | |
240 | ||
c0c133e1 | 241 | wxDECLARE_NO_COPY_CLASS(wxGridCellBoolEditor); |
29efc6e4 FM |
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 | |
249 | class WXDLLIMPEXP_ADV wxGridCellChoiceEditor : public wxGridCellEditor | |
250 | { | |
251 | public: | |
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 | ||
279 | protected: | |
280 | wxComboBox *Combo() const { return (wxComboBox *)m_control; } | |
281 | ||
282 | wxString m_value; | |
283 | wxArrayString m_choices; | |
284 | bool m_allowOthers; | |
285 | ||
c0c133e1 | 286 | wxDECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor); |
29efc6e4 FM |
287 | }; |
288 | ||
289 | #endif // wxUSE_COMBOBOX | |
290 | ||
291 | #if wxUSE_COMBOBOX | |
292 | ||
293 | class WXDLLIMPEXP_ADV wxGridCellEnumEditor : public wxGridCellChoiceEditor | |
294 | { | |
295 | public: | |
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 | ||
305 | private: | |
306 | long m_index; | |
307 | ||
c0c133e1 | 308 | wxDECLARE_NO_COPY_CLASS(wxGridCellEnumEditor); |
29efc6e4 FM |
309 | }; |
310 | ||
311 | #endif // wxUSE_COMBOBOX | |
312 | ||
313 | class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor | |
314 | { | |
315 | public: | |
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 | ||
c0c133e1 | 324 | wxDECLARE_NO_COPY_CLASS(wxGridCellAutoWrapStringEditor); |
29efc6e4 FM |
325 | }; |
326 | ||
327 | #endif // wxUSE_GRID | |
328 | #endif // _WX_GENERIC_GRID_EDITORS_H_ |