]> git.saurik.com Git - wxWidgets.git/blame - include/wx/generic/grideditors.h
Add wxToolBarToolBase, missing flags, etc.
[wxWidgets.git] / include / wx / generic / grideditors.h
CommitLineData
a3ef8eb5
VZ
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 wxDECLARE_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(int row, int col, const wxGrid* grid,
67 const wxString& oldval, wxString *newval);
68 virtual void ApplyEdit(int row, int col, wxGrid* grid);
69
70 virtual void Reset();
71 virtual void StartingKey(wxKeyEvent& event);
72 virtual void HandleReturn(wxKeyEvent& event);
73
74 // parameters string format is "max_width"
75 virtual void SetParameters(const wxString& params);
76
77 virtual wxGridCellEditor *Clone() const
78 { return new wxGridCellTextEditor; }
79
80 // added GetValue so we can get the value which is in the control
81 virtual wxString GetValue() const;
82
83protected:
84 wxTextCtrl *Text() const { return (wxTextCtrl *)m_control; }
85
86 // parts of our virtual functions reused by the derived classes
87 void DoCreate(wxWindow* parent, wxWindowID id, wxEvtHandler* evtHandler,
88 long style = 0);
89 void DoBeginEdit(const wxString& startValue);
90 void DoReset(const wxString& startValue);
91
92private:
93 size_t m_maxChars; // max number of chars allowed
94 wxString m_value;
95
96 wxDECLARE_NO_COPY_CLASS(wxGridCellTextEditor);
97};
98
99// the editor for numeric (long) data
100class WXDLLIMPEXP_ADV wxGridCellNumberEditor : public wxGridCellTextEditor
101{
102public:
103 // allows to specify the range - if min == max == -1, no range checking is
104 // done
105 wxGridCellNumberEditor(int min = -1, int max = -1);
106
107 virtual void Create(wxWindow* parent,
108 wxWindowID id,
109 wxEvtHandler* evtHandler);
110
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);
116
117 virtual void Reset();
118 virtual void StartingKey(wxKeyEvent& event);
119
120 // parameters string format is "min,max"
121 virtual void SetParameters(const wxString& params);
122
123 virtual wxGridCellEditor *Clone() const
124 { return new wxGridCellNumberEditor(m_min, m_max); }
125
126 // added GetValue so we can get the value which is in the control
127 virtual wxString GetValue() const;
128
129protected:
130#if wxUSE_SPINCTRL
131 wxSpinCtrl *Spin() const { return (wxSpinCtrl *)m_control; }
132#endif
133
134 // if HasRange(), we use wxSpinCtrl - otherwise wxTextCtrl
135 bool HasRange() const
136 {
137#if wxUSE_SPINCTRL
138 return m_min != m_max;
139#else
140 return false;
141#endif
142 }
143
144 // string representation of our value
145 wxString GetString() const
9a83f860 146 { return wxString::Format(wxT("%ld"), m_value); }
a3ef8eb5
VZ
147
148private:
149 int m_min,
150 m_max;
151
152 long m_value;
153
154 wxDECLARE_NO_COPY_CLASS(wxGridCellNumberEditor);
155};
156
1d8d3cc5
VZ
157
158enum wxGridCellFloatFormat
159{
160 // Decimal floating point (%f)
161 wxGRID_FLOAT_FORMAT_FIXED = 0x0010,
162
163 // Scientific notation (mantise/exponent) using e character (%e)
164 wxGRID_FLOAT_FORMAT_SCIENTIFIC = 0x0020,
165
166 // Use the shorter of %e or %f (%g)
167 wxGRID_FLOAT_FORMAT_COMPACT = 0x0040,
168
169 // To use in combination with one of the above formats (%F/%E/%G)
170 wxGRID_FLOAT_FORMAT_UPPER = 0x0080,
171
172 // Format used by default.
173 wxGRID_FLOAT_FORMAT_DEFAULT = wxGRID_FLOAT_FORMAT_FIXED,
174
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
180};
181
a3ef8eb5
VZ
182// the editor for floating point numbers (double) data
183class WXDLLIMPEXP_ADV wxGridCellFloatEditor : public wxGridCellTextEditor
184{
185public:
1d8d3cc5
VZ
186 wxGridCellFloatEditor(int width = -1,
187 int precision = -1,
188 int format = wxGRID_FLOAT_FORMAT_DEFAULT);
a3ef8eb5
VZ
189
190 virtual void Create(wxWindow* parent,
191 wxWindowID id,
192 wxEvtHandler* evtHandler);
193
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);
199
200 virtual void Reset();
201 virtual void StartingKey(wxKeyEvent& event);
202
203 virtual wxGridCellEditor *Clone() const
204 { return new wxGridCellFloatEditor(m_width, m_precision); }
205
1d8d3cc5
VZ
206 // parameters string format is "width[,precision[,format]]"
207 // format to choose beween f|e|g|E|G (f is used by default)
a3ef8eb5
VZ
208 virtual void SetParameters(const wxString& params);
209
210protected:
211 // string representation of our value
1d8d3cc5 212 wxString GetString();
a3ef8eb5
VZ
213
214private:
215 int m_width,
216 m_precision;
217 double m_value;
218
1d8d3cc5
VZ
219 int m_style;
220 wxString m_format;
221
a3ef8eb5
VZ
222 wxDECLARE_NO_COPY_CLASS(wxGridCellFloatEditor);
223};
224
225#endif // wxUSE_TEXTCTRL
226
227#if wxUSE_CHECKBOX
228
229// the editor for boolean data
230class WXDLLIMPEXP_ADV wxGridCellBoolEditor : public wxGridCellEditor
231{
232public:
233 wxGridCellBoolEditor() { }
234
235 virtual void Create(wxWindow* parent,
236 wxWindowID id,
237 wxEvtHandler* evtHandler);
238
239 virtual void SetSize(const wxRect& rect);
240 virtual void Show(bool show, wxGridCellAttr *attr = NULL);
241
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);
247
248 virtual void Reset();
249 virtual void StartingClick();
250 virtual void StartingKey(wxKeyEvent& event);
251
252 virtual wxGridCellEditor *Clone() const
253 { return new wxGridCellBoolEditor; }
254
255 // added GetValue so we can get the value which is in the control, see
256 // also UseStringValues()
257 virtual wxString GetValue() const;
258
259 // set the string values returned by GetValue() for the true and false
260 // states, respectively
9a83f860 261 static void UseStringValues(const wxString& valueTrue = wxT("1"),
a3ef8eb5
VZ
262 const wxString& valueFalse = wxEmptyString);
263
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);
267
268protected:
269 wxCheckBox *CBox() const { return (wxCheckBox *)m_control; }
270
271private:
272 bool m_value;
273
274 static wxString ms_stringValues[2];
275
276 wxDECLARE_NO_COPY_CLASS(wxGridCellBoolEditor);
277};
278
279#endif // wxUSE_CHECKBOX
280
281#if wxUSE_COMBOBOX
282
283// the editor for string data allowing to choose from the list of strings
284class WXDLLIMPEXP_ADV wxGridCellChoiceEditor : public wxGridCellEditor
285{
286public:
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);
293
294 virtual void Create(wxWindow* parent,
295 wxWindowID id,
296 wxEvtHandler* evtHandler);
297
e59e670c
VZ
298 virtual void SetSize(const wxRect& rect);
299
a3ef8eb5
VZ
300 virtual void PaintBackground(const wxRect& rectCell, wxGridCellAttr *attr);
301
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);
306
307 virtual void Reset();
308
309 // parameters string format is "item1[,item2[...,itemN]]"
310 virtual void SetParameters(const wxString& params);
311
312 virtual wxGridCellEditor *Clone() const;
313
314 // added GetValue so we can get the value which is in the control
315 virtual wxString GetValue() const;
316
317protected:
318 wxComboBox *Combo() const { return (wxComboBox *)m_control; }
319
320 wxString m_value;
321 wxArrayString m_choices;
322 bool m_allowOthers;
323
324 wxDECLARE_NO_COPY_CLASS(wxGridCellChoiceEditor);
325};
326
327#endif // wxUSE_COMBOBOX
328
329#if wxUSE_COMBOBOX
330
331class WXDLLIMPEXP_ADV wxGridCellEnumEditor : public wxGridCellChoiceEditor
332{
333public:
334 wxGridCellEnumEditor( const wxString& choices = wxEmptyString );
335 virtual ~wxGridCellEnumEditor() {}
336
337 virtual wxGridCellEditor* Clone() const;
338
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);
343
344private:
345 long m_index;
346
347 wxDECLARE_NO_COPY_CLASS(wxGridCellEnumEditor);
348};
349
350#endif // wxUSE_COMBOBOX
351
352class WXDLLIMPEXP_ADV wxGridCellAutoWrapStringEditor : public wxGridCellTextEditor
353{
354public:
355 wxGridCellAutoWrapStringEditor() : wxGridCellTextEditor() { }
356 virtual void Create(wxWindow* parent,
357 wxWindowID id,
358 wxEvtHandler* evtHandler);
359
360 virtual wxGridCellEditor *Clone() const
361 { return new wxGridCellAutoWrapStringEditor; }
362
363 wxDECLARE_NO_COPY_CLASS(wxGridCellAutoWrapStringEditor);
364};
365
366#endif // wxUSE_GRID
367
368#endif // _WX_GENERIC_GRID_EDITORS_H_