Explicitly call wxObject ctor in wxColourPropertyValue ctors
[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 : wxObject()
88 {
89 m_type = 0;
90 }
91
92 virtual ~wxColourPropertyValue()
93 {
94 }
95
96 wxColourPropertyValue( const wxColourPropertyValue& v )
97 : wxObject()
98 {
99 m_type = v.m_type;
100 m_colour = v.m_colour;
101 }
102
103 void Init( wxUint32 type, const wxColour& colour )
104 {
105 m_type = type;
106 m_colour = colour;
107 }
108
109 wxColourPropertyValue( const wxColour& colour )
110 : wxObject()
111 {
112 m_type = wxPG_COLOUR_CUSTOM;
113 m_colour = colour;
114 }
115
116 wxColourPropertyValue( wxUint32 type )
117 : wxObject()
118 {
119 m_type = type;
120 }
121
122 wxColourPropertyValue( wxUint32 type, const wxColour& colour )
123 : wxObject()
124 {
125 Init( type, colour );
126 }
127
128 #ifndef SWIG
129 void operator=(const wxColourPropertyValue& cpv)
130 {
131 Init( cpv.m_type, cpv.m_colour );
132 }
133
134 private:
135 DECLARE_DYNAMIC_CLASS(wxColourPropertyValue)
136 #endif
137 };
138
139
140 #ifndef SWIG
141 bool WXDLLIMPEXP_PROPGRID
142 operator==(const wxColourPropertyValue&, const wxColourPropertyValue&);
143
144 DECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue, WXDLLIMPEXP_PROPGRID)
145
146 #endif
147
148 #ifndef SWIG
149 #define wxPG_EMPTY_CPV (*((wxColourPropertyValue*)NULL))
150 #define wxPG_NORMAL_FONT (*wxNORMAL_FONT)
151 #else
152 #define wxPG_EMPTY_CPV wxCPV_wxPG_EMPTY
153 #define wxPG_NORMAL_FONT wxFONT_wxPG_NORMAL_FONT
154 #endif
155
156
157 // -----------------------------------------------------------------------
158 // Declare part of custom colour property macro pairs.
159
160 #if wxUSE_IMAGE || defined(SWIG)
161 #include "wx/image.h"
162 #endif
163
164 // -----------------------------------------------------------------------
165
166 // Exclude class from wxPython bindings
167 #ifndef SWIG
168
169 /** @class wxFontProperty
170 @ingroup classes
171 Property representing wxFont.
172 */
173 class WXDLLIMPEXP_PROPGRID wxFontProperty : public wxPGProperty
174 {
175 WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty)
176 public:
177
178 wxFontProperty(const wxString& label = wxPG_LABEL,
179 const wxString& name = wxPG_LABEL,
180 const wxFont& value = wxFont());
181 virtual ~wxFontProperty();
182 virtual void OnSetValue();
183 virtual wxString GetValueAsString( int argFlags = 0 ) const;
184 virtual bool OnEvent( wxPropertyGrid* propgrid,
185 wxWindow* primary, wxEvent& event );
186 virtual void ChildChanged( wxVariant& thisValue,
187 int childIndex, wxVariant& childValue ) const;
188 virtual void RefreshChildren();
189
190 protected:
191 };
192
193 #endif // !SWIG
194
195 // -----------------------------------------------------------------------
196
197
198 /** If set, then match from list is searched for a custom colour. */
199 #define wxPG_PROP_TRANSLATE_CUSTOM wxPG_PROP_CLASS_SPECIFIC_1
200
201
202 /** @class wxSystemColourProperty
203 @ingroup classes
204 Has dropdown list of wxWidgets system colours. Value used is
205 of wxColourPropertyValue type.
206 */
207 class WXDLLIMPEXP_PROPGRID wxSystemColourProperty : public wxEnumProperty
208 {
209 WX_PG_DECLARE_PROPERTY_CLASS(wxSystemColourProperty)
210 public:
211
212 wxSystemColourProperty( const wxString& label = wxPG_LABEL,
213 const wxString& name = wxPG_LABEL,
214 const wxColourPropertyValue&
215 value = wxColourPropertyValue() );
216 virtual ~wxSystemColourProperty();
217
218 virtual void OnSetValue();
219 virtual bool IntToValue(wxVariant& variant,
220 int number,
221 int argFlags = 0) const;
222
223 /**
224 Override in derived class to customize how colours are printed as
225 strings.
226 */
227 virtual wxString ColourToString( const wxColour& col, int index ) const;
228
229 /** Returns index of entry that triggers colour picker dialog
230 (default is last).
231 */
232 virtual int GetCustomColourIndex() const;
233
234 virtual wxString GetValueAsString( int argFlags = 0 ) const;
235 virtual bool StringToValue( wxVariant& variant,
236 const wxString& text,
237 int argFlags = 0 ) const;
238 virtual bool OnEvent( wxPropertyGrid* propgrid,
239 wxWindow* primary, wxEvent& event );
240 virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
241 virtual wxSize OnMeasureImage( int item ) const;
242 virtual void OnCustomPaint( wxDC& dc,
243 const wxRect& rect, wxPGPaintData& paintdata );
244
245 // Helper function to show the colour dialog
246 bool QueryColourFromUser( wxVariant& variant ) const;
247
248 /** Default is to use wxSystemSettings::GetColour(index). Override to use
249 custom colour tables etc.
250 */
251 virtual wxColour GetColour( int index ) const;
252
253 wxColourPropertyValue GetVal( const wxVariant* pVariant = NULL ) const;
254
255 protected:
256
257 // Special constructors to be used by derived classes.
258 wxSystemColourProperty( const wxString& label, const wxString& name,
259 const wxChar** labels, const long* values, wxPGChoices* choicesCache,
260 const wxColourPropertyValue& value );
261 wxSystemColourProperty( const wxString& label, const wxString& name,
262 const wxChar** labels, const long* values, wxPGChoices* choicesCache,
263 const wxColour& value );
264
265 void Init( int type, const wxColour& colour );
266
267 // Utility functions for internal use
268 virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const;
269 wxVariant TranslateVal( wxColourPropertyValue& v ) const
270 {
271 return DoTranslateVal( v );
272 }
273 wxVariant TranslateVal( int type, const wxColour& colour ) const
274 {
275 wxColourPropertyValue v(type, colour);
276 return DoTranslateVal( v );
277 }
278
279 // Translates colour to a int value, return wxNOT_FOUND if no match.
280 int ColToInd( const wxColour& colour ) const;
281 };
282
283 // -----------------------------------------------------------------------
284
285 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(
286 wxColourProperty, class WXDLLIMPEXP_PROPGRID)
287
288 // Exclude classes from wxPython bindings
289 #ifndef SWIG
290
291 // -----------------------------------------------------------------------
292
293 /** @class wxCursorProperty
294 @ingroup classes
295 Property representing wxCursor.
296 */
297 class WXDLLIMPEXP_PROPGRID wxCursorProperty : public wxEnumProperty
298 {
299 DECLARE_DYNAMIC_CLASS(wxCursorProperty)
300
301 wxCursorProperty( const wxString& label= wxPG_LABEL,
302 const wxString& name= wxPG_LABEL,
303 int value = 0 );
304 virtual ~wxCursorProperty();
305
306 virtual wxSize OnMeasureImage( int item ) const;
307 virtual void OnCustomPaint( wxDC& dc,
308 const wxRect& rect, wxPGPaintData& paintdata );
309 };
310
311 // -----------------------------------------------------------------------
312
313 #if wxUSE_IMAGE
314
315 WXDLLIMPEXP_PROPGRID const wxString& wxPGGetDefaultImageWildcard();
316
317 /** @class wxImageFileProperty
318 @ingroup classes
319 Property representing image file(name).
320 */
321 class WXDLLIMPEXP_PROPGRID wxImageFileProperty : public wxFileProperty
322 {
323 DECLARE_DYNAMIC_CLASS(wxImageFileProperty)
324 public:
325
326 wxImageFileProperty( const wxString& label= wxPG_LABEL,
327 const wxString& name = wxPG_LABEL,
328 const wxString& value = wxEmptyString);
329 virtual ~wxImageFileProperty();
330
331 virtual void OnSetValue();
332
333 virtual wxSize OnMeasureImage( int item ) const;
334 virtual void OnCustomPaint( wxDC& dc,
335 const wxRect& rect, wxPGPaintData& paintdata );
336
337 protected:
338 wxBitmap* m_pBitmap; // final thumbnail area
339 wxImage* m_pImage; // intermediate thumbnail area
340 };
341
342 #endif
343
344 #if wxUSE_CHOICEDLG || defined(SWIG)
345
346 /** @class wxMultiChoiceProperty
347 @ingroup classes
348 Property that manages a value resulting from wxMultiChoiceDialog. Value is
349 array of strings. You can get value as array of choice values/indices by
350 calling wxMultiChoiceProperty::GetValueAsArrayInt().
351
352 <b>Supported special attributes:</b>
353 - "UserStringMode": If > 0, allow user to manually enter strings that are
354 not in the list of choices. If this value is 1, user strings are
355 preferably placed in front of valid choices. If value is 2, then those
356 strings will placed behind valid choices.
357 */
358 class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty : public wxPGProperty
359 {
360 WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty)
361 public:
362
363 wxMultiChoiceProperty( const wxString& label,
364 const wxString& name,
365 const wxArrayString& strings,
366 const wxArrayString& value );
367 #ifndef SWIG
368 wxMultiChoiceProperty( const wxString& label,
369 const wxString& name,
370 const wxPGChoices& choices,
371 const wxArrayString& value = wxArrayString() );
372
373 wxMultiChoiceProperty( const wxString& label = wxPG_LABEL,
374 const wxString& name = wxPG_LABEL,
375 const wxArrayString& value = wxArrayString() );
376 #endif
377 virtual ~wxMultiChoiceProperty();
378
379 virtual void OnSetValue();
380 virtual wxString GetValueAsString( int flags = 0 ) const;
381 virtual bool StringToValue(wxVariant& variant,
382 const wxString& text,
383 int argFlags = 0) const;
384 virtual bool OnEvent( wxPropertyGrid* propgrid,
385 wxWindow* primary, wxEvent& event );
386
387 wxArrayInt GetValueAsArrayInt() const
388 {
389 return m_choices.GetValuesForStrings(m_value.GetArrayString());
390 }
391
392 protected:
393
394 void GenerateValueAsString();
395
396 // Returns translation of values into string indices.
397 wxArrayInt GetValueAsIndices() const;
398
399 wxArrayString m_valueAsStrings; // Value as array of strings
400
401 // Cache displayed text since generating it is relatively complicated.
402 wxString m_display;
403 };
404
405 #endif // wxUSE_CHOICEDLG
406
407 // -----------------------------------------------------------------------
408
409 #if wxUSE_DATETIME
410
411 /** @class wxDateProperty
412 @ingroup classes
413 Property representing wxDateTime.
414
415 <b>Supported special attributes:</b>
416 - "DateFormat": Determines displayed date format.
417 - "PickerStyle": Determines window style used with wxDatePickerCtrl.
418 Default is wxDP_DEFAULT | wxDP_SHOWCENTURY.
419 */
420 class WXDLLIMPEXP_PROPGRID wxDateProperty : public wxPGProperty
421 {
422 WX_PG_DECLARE_PROPERTY_CLASS(wxDateProperty)
423 public:
424
425 wxDateProperty( const wxString& label = wxPG_LABEL,
426 const wxString& name = wxPG_LABEL,
427 const wxDateTime& value = wxDateTime() );
428 virtual ~wxDateProperty();
429
430 virtual wxString GetValueAsString( int flags = 0 ) const;
431 virtual bool StringToValue(wxVariant& variant,
432 const wxString& text,
433 int argFlags = 0) const;
434
435 virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
436
437 void SetFormat( const wxString& format )
438 {
439 m_format = format;
440 }
441
442 const wxString& GetFormat() const
443 {
444 return m_format;
445 }
446
447 void SetDateValue( const wxDateTime& dt )
448 {
449 //m_valueDateTime = dt;
450 m_value = dt;
451 }
452
453 wxDateTime GetDateValue() const
454 {
455 //return m_valueDateTime;
456 return m_value;
457 }
458
459 long GetDatePickerStyle() const
460 {
461 return m_dpStyle;
462 }
463
464 protected:
465 wxString m_format;
466 long m_dpStyle; // DatePicker style
467
468 static wxString ms_defaultDateFormat;
469 static wxString DetermineDefaultDateFormat( bool showCentury );
470 };
471
472 #endif // wxUSE_DATETIME
473
474 #endif // !SWIG
475
476 // -----------------------------------------------------------------------
477
478 #if wxUSE_SPINBTN
479
480 //
481 // Implement an editor control that allows using wxSpinCtrl (actually, a
482 // combination of wxTextCtrl and wxSpinButton) to edit value of wxIntProperty
483 // and wxFloatProperty (and similar).
484 //
485 // Note that new editor classes needs to be registered before use. This can be
486 // accomplished using wxPGRegisterEditorClass macro, which is used for SpinCtrl
487 // in wxPropertyGridInterface::RegisterAdditionalEditors (see below).
488 // Registration can also be performed in a constructor of a property that is
489 // likely to require the editor in question.
490 //
491
492
493 #include "wx/spinbutt.h"
494 #include "wx/propgrid/editors.h"
495
496
497 // NOTE: Regardless that this class inherits from a working editor, it has
498 // all necessary methods to work independently. wxTextCtrl stuff is only
499 // used for event handling here.
500 class WXDLLIMPEXP_PROPGRID wxPGSpinCtrlEditor : public wxPGTextCtrlEditor
501 {
502 WX_PG_DECLARE_EDITOR_CLASS(wxPGSpinCtrlEditor)
503 public:
504 virtual ~wxPGSpinCtrlEditor();
505
506 // See below for short explanations of what these are suppposed to do.
507 wxPG_DECLARE_CREATECONTROLS
508
509 virtual bool OnEvent( wxPropertyGrid* propgrid, wxPGProperty* property,
510 wxWindow* wnd, wxEvent& event ) const;
511
512 private:
513 mutable wxString m_tempString;
514 };
515
516 #endif // wxUSE_SPINBTN
517
518 // -----------------------------------------------------------------------
519
520 #endif // wxUSE_PROPGRID
521
522 #endif // _WX_PROPGRID_ADVPROPS_H_