Remove all lines containing cvs/svn "$Id$" keyword.
[wxWidgets.git] / include / wx / generic / grideditors.h
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 // Copyright: (c) Michael Bedward
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10
11 #ifndef _WX_GENERIC_GRID_EDITORS_H_
12 #define _WX_GENERIC_GRID_EDITORS_H_
13
14 #include "wx/defs.h"
15
16 #if wxUSE_GRID
17
18 class wxGridCellEditorEvtHandler : public wxEvtHandler
19 {
20 public:
21 wxGridCellEditorEvtHandler(wxGrid* grid, wxGridCellEditor* editor)
22 : m_grid(grid),
23 m_editor(editor),
24 m_inSetFocus(false)
25 {
26 }
27
28 void OnKillFocus(wxFocusEvent& event);
29 void OnKeyDown(wxKeyEvent& event);
30 void OnChar(wxKeyEvent& event);
31
32 void SetInSetFocus(bool inSetFocus) { m_inSetFocus = inSetFocus; }
33
34 private:
35 wxGrid *m_grid;
36 wxGridCellEditor *m_editor;
37
38 // Work around the fact that a focus kill event can be sent to
39 // a combobox within a set focus event.
40 bool m_inSetFocus;
41
42 DECLARE_EVENT_TABLE()
43 DECLARE_DYNAMIC_CLASS(wxGridCellEditorEvtHandler)
44 wxDECLARE_NO_COPY_CLASS(wxGridCellEditorEvtHandler);
45 };
46
47
48 #if wxUSE_TEXTCTRL
49
50 // the editor for string/text data
51 class WXDLLIMPEXP_ADV wxGridCellTextEditor : public wxGridCellEditor
52 {
53 public:
54 wxEXPLICIT wxGridCellTextEditor(size_t maxChars = 0);
55
56 virtual void Create(wxWindow* parent,
57 wxWindowID id,
58 wxEvtHandler* evtHandler);
59 virtual void SetSize(const wxRect& rect);
60
61 virtual void PaintBackground(wxDC& dc,
62 const wxRect& rectCell,
63 const wxGridCellAttr& attr);
64
65 virtual bool IsAcceptedKey(wxKeyEvent& event);
66 virtual void BeginEdit(int row, int col, wxGrid* grid);
67 virtual bool EndEdit(int row, int col, const wxGrid* grid,
68 const wxString& oldval, wxString *newval);
69 virtual void ApplyEdit(int row, int col, wxGrid* grid);
70
71 virtual void Reset();
72 virtual void StartingKey(wxKeyEvent& event);
73 virtual void HandleReturn(wxKeyEvent& event);
74
75 // parameters string format is "max_width"
76 virtual void SetParameters(const wxString& params);
77 virtual void SetValidator(const wxValidator& validator);
78
79 virtual wxGridCellEditor *Clone() const;
80
81 // added GetValue so we can get the value which is in the control
82 virtual wxString GetValue() const;
83
84 protected:
85 wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
86
87 // parts of our virtual functions reused by the derived classes
88 void DoCreate(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler,
89 long style = 0);
90 void DoBeginEdit(const wxString& startValue);
91 void DoReset(const wxString& startValue);
92
93 private:
94 size_t m_maxChars; // max number of chars allowed
95 wxScopedPtr<wxValidator> m_validator;
96 wxString m_value;
97
98 wxDECLARE_NO_COPY_CLASS(wxGridCellTextEditor);
99 };
100
101 // the editor for numeric (long) data
102 class WXDLLIMPEXP_ADV wxGridCellNumberEditor : public wxGridCellTextEditor
103 {
104 public:
105 // allows to specify the range - if min == max == -1, no range checking is
106 // done
107 wxGridCellNumberEditor(int min = -1, int max = -1);
108
109 virtual void Create(wxWindow* parent,
110 wxWindowID id,
111 wxEvtHandler* evtHandler);
112
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);
118
119 virtual void Reset();
120 virtual void StartingKey(wxKeyEvent& event);
121
122 // parameters string format is "min,max"
123 virtual void SetParameters(const wxString& params);
124
125 virtual wxGridCellEditor *Clone() const
126 { return new wxGridCellNumberEditor(m_min, m_max); }
127
128 // added GetValue so we can get the value which is in the control
129 virtual wxString GetValue() const;
130
131 protected:
132 #if wxUSE_SPINCTRL
133 wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; }
134 #endif
135
136 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
137 bool HasRange() const
138 {
139 #if wxUSE_SPINCTRL
140 return m_min != m_max;
141 #else
142 return false;
143 #endif
144 }
145
146 // string representation of our value
147 wxString GetString() const
148 { return wxString::Format(wxT("%ld"), m_value); }
149
150 private:
151 int m_min,
152 m_max;
153
154 long m_value;
155
156 wxDECLARE_NO_COPY_CLASS(wxGridCellNumberEditor);
157 };
158
159
160 enum wxGridCellFloatFormat
161 {
162 // Decimal floating point (%f)
163 wxGRID_FLOAT_FORMAT_FIXED = 0x0010,
164
165 // Scientific notation (mantise/exponent) using e character (%e)
166 wxGRID_FLOAT_FORMAT_SCIENTIFIC = 0x0020,
167
168 // Use the shorter of %e or %f (%g)
169 wxGRID_FLOAT_FORMAT_COMPACT = 0x0040,
170
171 // To use in combination with one of the above formats (%F/%E/%G)
172 wxGRID_FLOAT_FORMAT_UPPER = 0x0080,
173
174 // Format used by default.
175 wxGRID_FLOAT_FORMAT_DEFAULT = wxGRID_FLOAT_FORMAT_FIXED,
176
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
182 };
183
184 // the editor for floating point numbers (double) data
185 class WXDLLIMPEXP_ADV wxGridCellFloatEditor : public wxGridCellTextEditor
186 {
187 public:
188 wxGridCellFloatEditor(int width = -1,
189 int precision = -1,
190 int format = wxGRID_FLOAT_FORMAT_DEFAULT);
191
192 virtual void Create(wxWindow* parent,
193 wxWindowID id,
194 wxEvtHandler* evtHandler);
195
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);
201
202 virtual void Reset();
203 virtual void StartingKey(wxKeyEvent& event);
204
205 virtual wxGridCellEditor *Clone() const
206 { return new wxGridCellFloatEditor(m_width, m_precision); }
207
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);
211
212 protected:
213 // string representation of our value
214 wxString GetString();
215
216 private:
217 int m_width,
218 m_precision;
219 double m_value;
220
221 int m_style;
222 wxString m_format;
223
224 wxDECLARE_NO_COPY_CLASS(wxGridCellFloatEditor);
225 };
226
227 #endif // wxUSE_TEXTCTRL
228
229 #if wxUSE_CHECKBOX
230
231 // the editor for boolean data
232 class WXDLLIMPEXP_ADV wxGridCellBoolEditor : public wxGridCellEditor
233 {
234 public:
235 wxGridCellBoolEditor() { }
236
237 virtual void Create(wxWindow* parent,
238 wxWindowID id,
239 wxEvtHandler* evtHandler);
240
241 virtual void SetSize(const wxRect& rect);
242 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
243
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);
249
250 virtual void Reset();
251 virtual void StartingClick();
252 virtual void StartingKey(wxKeyEvent& event);
253
254 virtual wxGridCellEditor *Clone() const
255 { return new wxGridCellBoolEditor; }
256
257 // added GetValue so we can get the value which is in the control, see
258 // also UseStringValues()
259 virtual wxString GetValue() const;
260
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);
265
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);
269
270 protected:
271 wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
272
273 private:
274 bool m_value;
275
276 static wxString ms_stringValues[2];
277
278 wxDECLARE_NO_COPY_CLASS(wxGridCellBoolEditor);
279 };
280
281 #endif // wxUSE_CHECKBOX
282
283 #if wxUSE_COMBOBOX
284
285 // the editor for string data allowing to choose from the list of strings
286 class WXDLLIMPEXP_ADV wxGridCellChoiceEditor : public wxGridCellEditor
287 {
288 public:
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);
295
296 virtual void Create(wxWindow* parent,
297 wxWindowID id,
298 wxEvtHandler* evtHandler);
299
300 virtual void SetSize(const wxRect& rect);
301
302 virtual void PaintBackground(wxDC& dc,
303 const wxRect& rectCell,
304 const wxGridCellAttr& attr);
305
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);
310
311 virtual void Reset();
312
313 // parameters string format is "item1[,item2[...,itemN]]"
314 virtual void SetParameters(const wxString& params);
315
316 virtual wxGridCellEditor *Clone() const;
317
318 // added GetValue so we can get the value which is in the control
319 virtual wxString GetValue() const;
320
321 protected:
322 wxComboBox *Combo() const { return (wxComboBox *)m_control; }
323
324 wxString m_value;
325 wxArrayString m_choices;
326 bool m_allowOthers;
327
328 wxDECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor);
329 };
330
331 #endif // wxUSE_COMBOBOX
332
333 #if wxUSE_COMBOBOX
334
335 class WXDLLIMPEXP_ADV wxGridCellEnumEditor : public wxGridCellChoiceEditor
336 {
337 public:
338 wxGridCellEnumEditor( const wxString& choices = wxEmptyString );
339 virtual ~wxGridCellEnumEditor() {}
340
341 virtual wxGridCellEditor* Clone() const;
342
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);
347
348 private:
349 long m_index;
350
351 wxDECLARE_NO_COPY_CLASS(wxGridCellEnumEditor);
352 };
353
354 #endif // wxUSE_COMBOBOX
355
356 class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
357 {
358 public:
359 wxGridCellAutoWrapStringEditor() : wxGridCellTextEditor() { }
360 virtual void Create(wxWindow* parent,
361 wxWindowID id,
362 wxEvtHandler* evtHandler);
363
364 virtual wxGridCellEditor *Clone() const
365 { return new wxGridCellAutoWrapStringEditor; }
366
367 wxDECLARE_NO_COPY_CLASS(wxGridCellAutoWrapStringEditor);
368 };
369
370 #endif // wxUSE_GRID
371
372 #endif // _WX_GENERIC_GRID_EDITORS_H_