1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/advprops.h
3 // Purpose: wxPropertyGrid Advanced Properties (font, colour, etc.)
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROPGRID_ADVPROPS_H_
13 #define _WX_PROPGRID_ADVPROPS_H_
17 #include "wx/propgrid/props.h"
19 // -----------------------------------------------------------------------
23 // Additional Value Type Handlers
26 bool WXDLLIMPEXP_PROPGRID
operator==(const wxFont
&, const wxFont
&);
28 bool WXDLLIMPEXP_PROPGRID
29 operator==(const wxArrayInt
& array1
, const wxArrayInt
& array2
);
34 // Additional Property Editors
37 WX_PG_DECLARE_EDITOR_WITH_DECL(SpinCtrl
,WXDLLIMPEXP_PROPGRID
)
40 #if wxUSE_DATEPICKCTRL
41 WX_PG_DECLARE_EDITOR_WITH_DECL(DatePickerCtrl
,WXDLLIMPEXP_PROPGRID
)
44 // -----------------------------------------------------------------------
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))
52 #define wxPG_COLOUR_CUSTOM 0xFFFFFF
53 #define wxPG_COLOUR_UNSPECIFIED (wxPG_COLOUR_CUSTOM+1)
55 /** @class wxColourPropertyValue
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.
62 class WXDLLIMPEXP_PROPGRID wxColourPropertyValue
: public wxObject
65 /** An integer value relating to the colour, and which exact
66 meaning depends on the property with which it is used.
68 For wxSystemColourProperty:
70 Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
71 macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
73 For custom colour properties without values array specified:
75 index or wxPG_COLOUR_CUSTOM
77 For custom colour properties <b>with</b> values array specified:
79 m_arrValues[index] or wxPG_COLOUR_CUSTOM
83 /** Resulting colour. Should be correct regardless of type. */
86 wxColourPropertyValue()
92 virtual ~wxColourPropertyValue()
96 wxColourPropertyValue( const wxColourPropertyValue
& v
)
100 m_colour
= v
.m_colour
;
103 void Init( wxUint32 type
, const wxColour
& colour
)
109 wxColourPropertyValue( const wxColour
& colour
)
112 m_type
= wxPG_COLOUR_CUSTOM
;
116 wxColourPropertyValue( wxUint32 type
)
122 wxColourPropertyValue( wxUint32 type
, const wxColour
& colour
)
125 Init( type
, colour
);
129 void operator=(const wxColourPropertyValue
& cpv
)
131 Init( cpv
.m_type
, cpv
.m_colour
);
135 DECLARE_DYNAMIC_CLASS(wxColourPropertyValue
)
141 bool WXDLLIMPEXP_PROPGRID
142 operator==(const wxColourPropertyValue
&, const wxColourPropertyValue
&);
144 DECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
149 #define wxPG_EMPTY_CPV (*((wxColourPropertyValue*)NULL))
150 #define wxPG_NORMAL_FONT (*wxNORMAL_FONT)
152 #define wxPG_EMPTY_CPV wxCPV_wxPG_EMPTY
153 #define wxPG_NORMAL_FONT wxFONT_wxPG_NORMAL_FONT
157 // -----------------------------------------------------------------------
158 // Declare part of custom colour property macro pairs.
160 #if wxUSE_IMAGE || defined(SWIG)
161 #include "wx/image.h"
164 // -----------------------------------------------------------------------
166 // Exclude class from wxPython bindings
169 /** @class wxFontProperty
171 Property representing wxFont.
173 class WXDLLIMPEXP_PROPGRID wxFontProperty
: public wxPGProperty
175 WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty
)
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();
195 // -----------------------------------------------------------------------
198 /** If set, then match from list is searched for a custom colour. */
199 #define wxPG_PROP_TRANSLATE_CUSTOM wxPG_PROP_CLASS_SPECIFIC_1
202 /** @class wxSystemColourProperty
204 Has dropdown list of wxWidgets system colours. Value used is
205 of wxColourPropertyValue type.
207 class WXDLLIMPEXP_PROPGRID wxSystemColourProperty
: public wxEnumProperty
209 WX_PG_DECLARE_PROPERTY_CLASS(wxSystemColourProperty
)
212 wxSystemColourProperty( const wxString
& label
= wxPG_LABEL
,
213 const wxString
& name
= wxPG_LABEL
,
214 const wxColourPropertyValue
&
215 value
= wxColourPropertyValue() );
216 virtual ~wxSystemColourProperty();
218 virtual void OnSetValue();
219 virtual bool IntToValue(wxVariant
& variant
,
221 int argFlags
= 0) const;
224 Override in derived class to customize how colours are printed as
227 virtual wxString
ColourToString( const wxColour
& col
, int index
) const;
229 /** Returns index of entry that triggers colour picker dialog
232 virtual int GetCustomColourIndex() const;
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
);
245 // Helper function to show the colour dialog
246 bool QueryColourFromUser( wxVariant
& variant
) const;
248 /** Default is to use wxSystemSettings::GetColour(index). Override to use
249 custom colour tables etc.
251 virtual wxColour
GetColour( int index
) const;
253 wxColourPropertyValue
GetVal( const wxVariant
* pVariant
= NULL
) const;
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
);
265 void Init( int type
, const wxColour
& colour
);
267 // Utility functions for internal use
268 virtual wxVariant
DoTranslateVal( wxColourPropertyValue
& v
) const;
269 wxVariant
TranslateVal( wxColourPropertyValue
& v
) const
271 return DoTranslateVal( v
);
273 wxVariant
TranslateVal( int type
, const wxColour
& colour
) const
275 wxColourPropertyValue
v(type
, colour
);
276 return DoTranslateVal( v
);
279 // Translates colour to a int value, return wxNOT_FOUND if no match.
280 int ColToInd( const wxColour
& colour
) const;
283 // -----------------------------------------------------------------------
285 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(
286 wxColourProperty
, class WXDLLIMPEXP_PROPGRID
)
288 // Exclude classes from wxPython bindings
291 // -----------------------------------------------------------------------
293 /** @class wxCursorProperty
295 Property representing wxCursor.
297 class WXDLLIMPEXP_PROPGRID wxCursorProperty
: public wxEnumProperty
299 DECLARE_DYNAMIC_CLASS(wxCursorProperty
)
301 wxCursorProperty( const wxString
& label
= wxPG_LABEL
,
302 const wxString
& name
= wxPG_LABEL
,
304 virtual ~wxCursorProperty();
306 virtual wxSize
OnMeasureImage( int item
) const;
307 virtual void OnCustomPaint( wxDC
& dc
,
308 const wxRect
& rect
, wxPGPaintData
& paintdata
);
311 // -----------------------------------------------------------------------
315 WXDLLIMPEXP_PROPGRID
const wxString
& wxPGGetDefaultImageWildcard();
317 /** @class wxImageFileProperty
319 Property representing image file(name).
321 class WXDLLIMPEXP_PROPGRID wxImageFileProperty
: public wxFileProperty
323 DECLARE_DYNAMIC_CLASS(wxImageFileProperty
)
326 wxImageFileProperty( const wxString
& label
= wxPG_LABEL
,
327 const wxString
& name
= wxPG_LABEL
,
328 const wxString
& value
= wxEmptyString
);
329 virtual ~wxImageFileProperty();
331 virtual void OnSetValue();
333 virtual wxSize
OnMeasureImage( int item
) const;
334 virtual void OnCustomPaint( wxDC
& dc
,
335 const wxRect
& rect
, wxPGPaintData
& paintdata
);
338 wxBitmap
* m_pBitmap
; // final thumbnail area
339 wxImage
* m_pImage
; // intermediate thumbnail area
344 #if wxUSE_CHOICEDLG || defined(SWIG)
346 /** @class wxMultiChoiceProperty
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().
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.
358 class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty
: public wxPGProperty
360 WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty
)
363 wxMultiChoiceProperty( const wxString
& label
,
364 const wxString
& name
,
365 const wxArrayString
& strings
,
366 const wxArrayString
& value
);
368 wxMultiChoiceProperty( const wxString
& label
,
369 const wxString
& name
,
370 const wxPGChoices
& choices
,
371 const wxArrayString
& value
= wxArrayString() );
373 wxMultiChoiceProperty( const wxString
& label
= wxPG_LABEL
,
374 const wxString
& name
= wxPG_LABEL
,
375 const wxArrayString
& value
= wxArrayString() );
377 virtual ~wxMultiChoiceProperty();
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
);
387 wxArrayInt
GetValueAsArrayInt() const
389 return m_choices
.GetValuesForStrings(m_value
.GetArrayString());
394 void GenerateValueAsString();
396 // Returns translation of values into string indices.
397 wxArrayInt
GetValueAsIndices() const;
399 wxArrayString m_valueAsStrings
; // Value as array of strings
401 // Cache displayed text since generating it is relatively complicated.
405 #endif // wxUSE_CHOICEDLG
407 // -----------------------------------------------------------------------
411 /** @class wxDateProperty
413 Property representing wxDateTime.
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.
420 class WXDLLIMPEXP_PROPGRID wxDateProperty
: public wxPGProperty
422 WX_PG_DECLARE_PROPERTY_CLASS(wxDateProperty
)
425 wxDateProperty( const wxString
& label
= wxPG_LABEL
,
426 const wxString
& name
= wxPG_LABEL
,
427 const wxDateTime
& value
= wxDateTime() );
428 virtual ~wxDateProperty();
430 virtual wxString
GetValueAsString( int flags
= 0 ) const;
431 virtual bool StringToValue(wxVariant
& variant
,
432 const wxString
& text
,
433 int argFlags
= 0) const;
435 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
437 void SetFormat( const wxString
& format
)
442 const wxString
& GetFormat() const
447 void SetDateValue( const wxDateTime
& dt
)
449 //m_valueDateTime = dt;
453 wxDateTime
GetDateValue() const
455 //return m_valueDateTime;
459 long GetDatePickerStyle() const
466 long m_dpStyle
; // DatePicker style
468 static wxString ms_defaultDateFormat
;
469 static wxString
DetermineDefaultDateFormat( bool showCentury
);
472 #endif // wxUSE_DATETIME
476 // -----------------------------------------------------------------------
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).
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.
493 #include "wx/spinbutt.h"
494 #include "wx/propgrid/editors.h"
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
502 WX_PG_DECLARE_EDITOR_CLASS(wxPGSpinCtrlEditor
)
504 virtual ~wxPGSpinCtrlEditor();
506 // See below for short explanations of what these are suppposed to do.
507 wxPG_DECLARE_CREATECONTROLS
509 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
510 wxWindow
* wnd
, wxEvent
& event
) const;
513 mutable wxString m_tempString
;
516 #endif // wxUSE_SPINBTN
518 // -----------------------------------------------------------------------
520 #endif // wxUSE_PROPGRID
522 #endif // _WX_PROPGRID_ADVPROPS_H_