Moved wxPGChoices m_choices member from various property classes to base wxPGProperty...
[wxWidgets.git] / include / wx / propgrid / advprops.h
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/advprops.h
3 // Purpose: wxPropertyGrid Advanced Properties (font, colour, etc.)
4 // Author: Jaakko Salli
5 // Modified by:
6 // Created: 2004-09-25
7 // RCS-ID: $Id:
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifndef _WX_PROPGRID_ADVPROPS_H_
13 #define _WX_PROPGRID_ADVPROPS_H_
14
15 #if wxUSE_PROPGRID
16
17 #include "wx/propgrid/props.h"
18
19 // -----------------------------------------------------------------------
20
21
22 //
23 // Additional Value Type Handlers
24 //
25 #ifndef SWIG
26 bool WXDLLIMPEXP_PROPGRID operator==(const wxFont&, const wxFont&);
27
28 bool WXDLLIMPEXP_PROPGRID
29 operator==(const wxArrayInt& array1, const wxArrayInt& array2);
30 #endif
31
32
33 //
34 // Additional Property Editors
35 //
36 #if wxUSE_SPINBTN
37 WX_PG_DECLARE_EDITOR_WITH_DECL(SpinCtrl,WXDLLIMPEXP_PROPGRID)
38 #endif
39
40 #if wxUSE_DATEPICKCTRL
41 WX_PG_DECLARE_EDITOR_WITH_DECL(DatePickerCtrl,WXDLLIMPEXP_PROPGRID)
42 #endif
43
44 // -----------------------------------------------------------------------
45
46
47 // Web colour is currently unsupported
48 #define wxPG_COLOUR_WEB_BASE 0x10000
49 //#define wxPG_TO_WEB_COLOUR(A) ((wxUint32)(A+wxPG_COLOUR_WEB_BASE))
50
51
52 #define wxPG_COLOUR_CUSTOM 0xFFFFFF
53 #define wxPG_COLOUR_UNSPECIFIED (wxPG_COLOUR_CUSTOM+1)
54
55 /** @class wxColourPropertyValue
56
57 Because text, background and other colours tend to differ between
58 platforms, wxSystemColourProperty must be able to select between system
59 colour and, when necessary, to pick a custom one. wxSystemColourProperty
60 value makes this possible.
61 */
62 class WXDLLIMPEXP_PROPGRID wxColourPropertyValue : public wxObject
63 {
64 public:
65 /** An integer value relating to the colour, and which exact
66 meaning depends on the property with which it is used.
67
68 For wxSystemColourProperty:
69
70 Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
71 macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
72
73 For custom colour properties without values array specified:
74
75 index or wxPG_COLOUR_CUSTOM
76
77 For custom colour properties <b>with</b> values array specified:
78
79 m_arrValues[index] or wxPG_COLOUR_CUSTOM
80 */
81 wxUint32 m_type;
82
83 /** Resulting colour. Should be correct regardless of type. */
84 wxColour m_colour;
85
86 wxColourPropertyValue()
87 {
88 m_type = 0;
89 }
90
91 virtual ~wxColourPropertyValue()
92 {
93 }
94
95 wxColourPropertyValue( const wxColourPropertyValue& v )
96 {
97 m_type = v.m_type;
98 m_colour = v.m_colour;
99 }
100
101 void Init( wxUint32 type, const wxColour& colour )
102 {
103 m_type = type;
104 m_colour = colour;
105 }
106
107 wxColourPropertyValue( const wxColour& colour )
108 {
109 m_type = wxPG_COLOUR_CUSTOM;
110 m_colour = colour;
111 }
112
113 wxColourPropertyValue( wxUint32 type )
114 {
115 m_type = type;
116 }
117
118 wxColourPropertyValue( wxUint32 type, const wxColour& colour )
119 {
120 Init( type, colour );
121 }
122
123 #ifndef SWIG
124 void operator=(const wxColourPropertyValue& cpv)
125 {
126 Init( cpv.m_type, cpv.m_colour );
127 }
128
129 private:
130 DECLARE_DYNAMIC_CLASS(wxColourPropertyValue)
131 #endif
132 };
133
134
135 #ifndef SWIG
136 bool WXDLLIMPEXP_PROPGRID
137 operator==(const wxColourPropertyValue&, const wxColourPropertyValue&);
138
139 DECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue, WXDLLIMPEXP_PROPGRID)
140
141 #endif
142
143 #ifndef SWIG
144 #define wxPG_EMPTY_CPV (*((wxColourPropertyValue*)NULL))
145 #define wxPG_NORMAL_FONT (*wxNORMAL_FONT)
146 #else
147 #define wxPG_EMPTY_CPV wxCPV_wxPG_EMPTY
148 #define wxPG_NORMAL_FONT wxFONT_wxPG_NORMAL_FONT
149 #endif
150
151
152 // -----------------------------------------------------------------------
153 // Declare part of custom colour property macro pairs.
154
155 #if wxUSE_IMAGE || defined(SWIG)
156 #include "wx/image.h"
157 #endif
158
159 // -----------------------------------------------------------------------
160
161 // Exclude class from wxPython bindings
162 #ifndef SWIG
163
164 /** @class wxFontProperty
165 @ingroup classes
166 Property representing wxFont.
167 */
168 class WXDLLIMPEXP_PROPGRID wxFontProperty : public wxPGProperty
169 {
170 WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty)
171 public:
172
173 wxFontProperty(const wxString& label = wxPG_LABEL,
174 const wxString& name = wxPG_LABEL,
175 const wxFont& value = wxFont());
176 virtual ~wxFontProperty();
177 virtual void OnSetValue();
178 virtual wxString GetValueAsString( int argFlags = 0 ) const;
179
180 WX_PG_DECLARE_EVENT_METHODS()
181 WX_PG_DECLARE_PARENTAL_METHODS()
182 //WX_PG_DECLARE_CUSTOM_PAINT_METHODS()
183
184 protected:
185 };
186
187 #endif // !SWIG
188
189 // -----------------------------------------------------------------------
190
191
192 /** If set, then match from list is searched for a custom colour. */
193 #define wxPG_PROP_TRANSLATE_CUSTOM wxPG_PROP_CLASS_SPECIFIC_1
194
195
196 /** @class wxSystemColourProperty
197 @ingroup classes
198 Has dropdown list of wxWidgets system colours. Value used is
199 of wxColourPropertyValue type.
200 */
201 class WXDLLIMPEXP_PROPGRID wxSystemColourProperty : public wxEnumProperty
202 {
203 WX_PG_DECLARE_PROPERTY_CLASS(wxSystemColourProperty)
204 public:
205
206 wxSystemColourProperty( const wxString& label = wxPG_LABEL,
207 const wxString& name = wxPG_LABEL,
208 const wxColourPropertyValue&
209 value = wxColourPropertyValue() );
210 virtual ~wxSystemColourProperty();
211
212 virtual void OnSetValue();
213 virtual bool IntToValue(wxVariant& variant,
214 int number,
215 int argFlags = 0) const;
216
217 /**
218 Override in derived class to customize how colours are printed as
219 strings.
220 */
221 virtual wxString ColourToString( const wxColour& col, int index ) const;
222
223 /** Returns index of entry that triggers colour picker dialog
224 (default is last).
225 */
226 virtual int GetCustomColourIndex() const;
227
228 WX_PG_DECLARE_BASIC_TYPE_METHODS()
229 WX_PG_DECLARE_EVENT_METHODS()
230 WX_PG_DECLARE_ATTRIBUTE_METHODS()
231
232 WX_PG_DECLARE_CUSTOM_PAINT_METHODS()
233 //virtual wxSize GetImageSize( int item ) const;
234 //virtual wxPGCellRenderer* GetCellRenderer( int column ) const;
235
236 // Helper function to show the colour dialog
237 bool QueryColourFromUser( wxVariant& variant ) const;
238
239 /** Default is to use wxSystemSettings::GetColour(index). Override to use
240 custom colour tables etc.
241 */
242 virtual wxColour GetColour( int index ) const;
243
244 wxColourPropertyValue GetVal( const wxVariant* pVariant = NULL ) const;
245
246 protected:
247
248 // Special constructors to be used by derived classes.
249 wxSystemColourProperty( const wxString& label, const wxString& name,
250 const wxChar** labels, const long* values, wxPGChoices* choicesCache,
251 const wxColourPropertyValue& value );
252 wxSystemColourProperty( const wxString& label, const wxString& name,
253 const wxChar** labels, const long* values, wxPGChoices* choicesCache,
254 const wxColour& value );
255
256 void Init( int type, const wxColour& colour );
257
258 // Utility functions for internal use
259 virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const;
260 wxVariant TranslateVal( wxColourPropertyValue& v ) const
261 {
262 return DoTranslateVal( v );
263 }
264 wxVariant TranslateVal( int type, const wxColour& colour ) const
265 {
266 wxColourPropertyValue v(type, colour);
267 return DoTranslateVal( v );
268 }
269
270 // Translates colour to a int value, return wxNOT_FOUND if no match.
271 int ColToInd( const wxColour& colour ) const;
272 };
273
274 // -----------------------------------------------------------------------
275
276 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(
277 wxColourProperty, class WXDLLIMPEXP_PROPGRID)
278
279 // Exclude classes from wxPython bindings
280 #ifndef SWIG
281
282 // -----------------------------------------------------------------------
283
284 /** @class wxCursorProperty
285 @ingroup classes
286 Property representing wxCursor.
287 */
288 class WXDLLIMPEXP_PROPGRID wxCursorProperty : public wxEnumProperty
289 {
290 DECLARE_DYNAMIC_CLASS(wxCursorProperty)
291
292 wxCursorProperty( const wxString& label= wxPG_LABEL,
293 const wxString& name= wxPG_LABEL,
294 int value = 0 );
295 virtual ~wxCursorProperty();
296
297 WX_PG_DECLARE_CUSTOM_PAINT_METHODS()
298 //virtual wxSize GetImageSize( int item ) const;
299 //virtual wxPGCellRenderer* GetCellRenderer( int column ) const;
300 };
301
302 // -----------------------------------------------------------------------
303
304 #if wxUSE_IMAGE
305
306 WXDLLIMPEXP_PROPGRID const wxString& wxPGGetDefaultImageWildcard();
307
308 /** @class wxImageFileProperty
309 @ingroup classes
310 Property representing image file(name).
311 */
312 class WXDLLIMPEXP_PROPGRID wxImageFileProperty : public wxFileProperty
313 {
314 DECLARE_DYNAMIC_CLASS(wxImageFileProperty)
315 public:
316
317 wxImageFileProperty( const wxString& label= wxPG_LABEL,
318 const wxString& name = wxPG_LABEL,
319 const wxString& value = wxEmptyString);
320 virtual ~wxImageFileProperty();
321
322 virtual void OnSetValue();
323
324 WX_PG_DECLARE_CUSTOM_PAINT_METHODS()
325
326 protected:
327 wxBitmap* m_pBitmap; // final thumbnail area
328 wxImage* m_pImage; // intermediate thumbnail area
329 };
330
331 #endif
332
333 #if wxUSE_CHOICEDLG || defined(SWIG)
334
335 /** @class wxMultiChoiceProperty
336 @ingroup classes
337 Property that manages a value resulting from wxMultiChoiceDialog. Value is
338 array of strings. You can get value as array of choice values/indices by
339 calling wxMultiChoiceProperty::GetValueAsArrayInt().
340
341 <b>Supported special attributes:</b>
342 - "UserStringMode": If > 0, allow user to manually enter strings that are
343 not in the list of choices. If this value is 1, user strings are
344 preferably placed in front of valid choices. If value is 2, then those
345 strings will placed behind valid choices.
346 */
347 class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty : public wxPGProperty
348 {
349 WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty)
350 public:
351
352 wxMultiChoiceProperty( const wxString& label,
353 const wxString& name,
354 const wxArrayString& strings,
355 const wxArrayString& value );
356 #ifndef SWIG
357 wxMultiChoiceProperty( const wxString& label,
358 const wxString& name,
359 const wxPGChoices& choices,
360 const wxArrayString& value = wxArrayString() );
361
362 wxMultiChoiceProperty( const wxString& label = wxPG_LABEL,
363 const wxString& name = wxPG_LABEL,
364 const wxArrayString& value = wxArrayString() );
365 #endif
366 virtual ~wxMultiChoiceProperty();
367
368 virtual void OnSetValue();
369 virtual wxString GetValueAsString( int flags = 0 ) const;
370 virtual bool StringToValue(wxVariant& variant,
371 const wxString& text,
372 int argFlags = 0) const;
373 WX_PG_DECLARE_EVENT_METHODS()
374
375 wxArrayInt GetValueAsArrayInt() const
376 {
377 return m_choices.GetValuesForStrings(m_value.GetArrayString());
378 }
379
380 protected:
381
382 void GenerateValueAsString();
383
384 // Returns translation of values into string indices.
385 wxArrayInt GetValueAsIndices() const;
386
387 wxArrayString m_valueAsStrings; // Value as array of strings
388
389 // Cache displayed text since generating it is relatively complicated.
390 wxString m_display;
391 };
392
393 #endif // wxUSE_CHOICEDLG
394
395 // -----------------------------------------------------------------------
396
397 #if wxUSE_DATETIME
398
399 /** @class wxDateProperty
400 @ingroup classes
401 Property representing wxDateTime.
402
403 <b>Supported special attributes:</b>
404 - "DateFormat": Determines displayed date format.
405 - "PickerStyle": Determines window style used with wxDatePickerCtrl.
406 Default is wxDP_DEFAULT | wxDP_SHOWCENTURY.
407 */
408 class WXDLLIMPEXP_PROPGRID wxDateProperty : public wxPGProperty
409 {
410 WX_PG_DECLARE_PROPERTY_CLASS(wxDateProperty)
411 public:
412
413 wxDateProperty( const wxString& label = wxPG_LABEL,
414 const wxString& name = wxPG_LABEL,
415 const wxDateTime& value = wxDateTime() );
416 virtual ~wxDateProperty();
417
418 virtual wxString GetValueAsString( int flags = 0 ) const;
419 virtual bool StringToValue(wxVariant& variant,
420 const wxString& text,
421 int argFlags = 0) const;
422
423 WX_PG_DECLARE_ATTRIBUTE_METHODS()
424
425 void SetFormat( const wxString& format )
426 {
427 m_format = format;
428 }
429
430 const wxString& GetFormat() const
431 {
432 return m_format;
433 }
434
435 void SetDateValue( const wxDateTime& dt )
436 {
437 //m_valueDateTime = dt;
438 m_value = dt;
439 }
440
441 wxDateTime GetDateValue() const
442 {
443 //return m_valueDateTime;
444 return m_value;
445 }
446
447 long GetDatePickerStyle() const
448 {
449 return m_dpStyle;
450 }
451
452 protected:
453 wxString m_format;
454 long m_dpStyle; // DatePicker style
455
456 static wxString ms_defaultDateFormat;
457 static wxString DetermineDefaultDateFormat( bool showCentury );
458 };
459
460 #endif // wxUSE_DATETIME
461
462 #endif // !SWIG
463
464 // -----------------------------------------------------------------------
465
466 #if wxUSE_SPINBTN
467
468 //
469 // Implement an editor control that allows using wxSpinCtrl (actually, a
470 // combination of wxTextCtrl and wxSpinButton) to edit value of wxIntProperty
471 // and wxFloatProperty (and similar).
472 //
473 // Note that new editor classes needs to be registered before use. This can be
474 // accomplished using wxPGRegisterEditorClass macro, which is used for SpinCtrl
475 // in wxPropertyGridInterface::RegisterAdditionalEditors (see below).
476 // Registration can also be performed in a constructor of a property that is
477 // likely to require the editor in question.
478 //
479
480
481 #include "wx/spinbutt.h"
482 #include "wx/propgrid/editors.h"
483
484
485 // NOTE: Regardless that this class inherits from a working editor, it has
486 // all necessary methods to work independently. wxTextCtrl stuff is only
487 // used for event handling here.
488 class WXDLLIMPEXP_PROPGRID wxPGSpinCtrlEditor : public wxPGTextCtrlEditor
489 {
490 WX_PG_DECLARE_EDITOR_CLASS(wxPGSpinCtrlEditor)
491 public:
492 virtual ~wxPGSpinCtrlEditor();
493
494 // See below for short explanations of what these are suppposed to do.
495 wxPG_DECLARE_CREATECONTROLS
496
497 virtual bool OnEvent( wxPropertyGrid* propgrid, wxPGProperty* property,
498 wxWindow* wnd, wxEvent& event ) const;
499
500 private:
501 mutable wxString m_tempString;
502 };
503
504 #endif // wxUSE_SPINBTN
505
506 // -----------------------------------------------------------------------
507
508 #endif // wxUSE_PROPGRID
509
510 #endif // _WX_PROPGRID_ADVPROPS_H_