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_
15 #include "wx/propgrid/props.h"
17 // -----------------------------------------------------------------------
21 // Additional Value Type Handlers
24 bool WXDLLIMPEXP_PROPGRID
operator==(const wxFont
&, const wxFont
&);
26 bool WXDLLIMPEXP_PROPGRID
27 operator==(const wxArrayInt
& array1
, const wxArrayInt
& array2
);
32 // Additional Property Editors
35 WX_PG_DECLARE_EDITOR_WITH_DECL(SpinCtrl
,WXDLLIMPEXP_PROPGRID
)
38 #if wxUSE_DATEPICKCTRL
39 WX_PG_DECLARE_EDITOR_WITH_DECL(DatePickerCtrl
,WXDLLIMPEXP_PROPGRID
)
42 // -----------------------------------------------------------------------
45 // Web colour is currently unsupported
46 #define wxPG_COLOUR_WEB_BASE 0x10000
47 //#define wxPG_TO_WEB_COLOUR(A) ((wxUint32)(A+wxPG_COLOUR_WEB_BASE))
50 #define wxPG_COLOUR_CUSTOM 0xFFFFFF
51 #define wxPG_COLOUR_UNSPECIFIED (wxPG_COLOUR_CUSTOM+1)
53 /** @class wxColourPropertyValue
55 Because text, background and other colours tend to differ between
56 platforms, wxSystemColourProperty must be able to select between system
57 colour and, when necessary, to pick a custom one. wxSystemColourProperty
58 value makes this possible.
60 class WXDLLIMPEXP_PROPGRID wxColourPropertyValue
: public wxObject
63 /** An integer value relating to the colour, and which exact
64 meaning depends on the property with which it is used.
66 For wxSystemColourProperty:
68 Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
69 macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
71 For custom colour properties without values array specified:
73 index or wxPG_COLOUR_CUSTOM
75 For custom colour properties <b>with</b> values array specified:
77 m_arrValues[index] or wxPG_COLOUR_CUSTOM
81 /** Resulting colour. Should be correct regardless of type. */
84 wxColourPropertyValue()
89 virtual ~wxColourPropertyValue()
93 wxColourPropertyValue( const wxColourPropertyValue
& v
)
96 m_colour
= v
.m_colour
;
99 void Init( wxUint32 type
, const wxColour
& colour
)
105 wxColourPropertyValue( const wxColour
& colour
)
107 m_type
= wxPG_COLOUR_CUSTOM
;
111 wxColourPropertyValue( wxUint32 type
)
116 wxColourPropertyValue( wxUint32 type
, const wxColour
& colour
)
118 Init( type
, colour
);
122 void operator=(const wxColourPropertyValue
& cpv
)
124 Init( cpv
.m_type
, cpv
.m_colour
);
128 DECLARE_DYNAMIC_CLASS(wxColourPropertyValue
)
134 bool WXDLLIMPEXP_PROPGRID
135 operator==(const wxColourPropertyValue
&, const wxColourPropertyValue
&);
137 WX_PG_DECLARE_WXOBJECT_VARIANT_DATA(wxPGVariantDataColourPropertyValue
,
138 wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
142 #define wxPG_EMPTY_CPV (*((wxColourPropertyValue*)NULL))
143 #define wxPG_NORMAL_FONT (*wxNORMAL_FONT)
145 #define wxPG_EMPTY_CPV wxCPV_wxPG_EMPTY
146 #define wxPG_NORMAL_FONT wxFONT_wxPG_NORMAL_FONT
150 // -----------------------------------------------------------------------
151 // Declare part of custom colour property macro pairs.
153 #if wxUSE_IMAGE || defined(SWIG)
154 #include "wx/image.h"
157 // -----------------------------------------------------------------------
159 // Exclude class from wxPython bindings
162 /** @class wxFontProperty
164 Property representing wxFont.
166 class WXDLLIMPEXP_PROPGRID wxFontProperty
: public wxPGProperty
168 WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty
)
171 wxFontProperty(const wxString
& label
= wxPG_LABEL
,
172 const wxString
& name
= wxPG_LABEL
,
173 const wxFont
& value
= wxFont());
174 virtual ~wxFontProperty();
175 virtual void OnSetValue();
176 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
178 WX_PG_DECLARE_EVENT_METHODS()
179 WX_PG_DECLARE_PARENTAL_METHODS()
180 //WX_PG_DECLARE_CUSTOM_PAINT_METHODS()
187 // -----------------------------------------------------------------------
190 /** If set, then match from list is searched for a custom colour. */
191 #define wxPG_PROP_TRANSLATE_CUSTOM wxPG_PROP_CLASS_SPECIFIC_1
194 /** @class wxSystemColourProperty
196 Has dropdown list of wxWidgets system colours. Value used is
197 of wxColourPropertyValue type.
199 class WXDLLIMPEXP_PROPGRID wxSystemColourProperty
: public wxEnumProperty
201 WX_PG_DECLARE_PROPERTY_CLASS(wxSystemColourProperty
)
204 wxSystemColourProperty( const wxString
& label
= wxPG_LABEL
,
205 const wxString
& name
= wxPG_LABEL
,
206 const wxColourPropertyValue
&
207 value
= wxColourPropertyValue() );
208 virtual ~wxSystemColourProperty();
210 virtual void OnSetValue();
211 virtual bool IntToValue(wxVariant
& variant
,
213 int argFlags
= 0) const;
216 Override in derived class to customize how colours are printed as
219 virtual wxString
ColourToString( const wxColour
& col
, int index
) const;
221 /** Returns index of entry that triggers colour picker dialog
224 virtual int GetCustomColourIndex() const;
226 WX_PG_DECLARE_BASIC_TYPE_METHODS()
227 WX_PG_DECLARE_EVENT_METHODS()
228 WX_PG_DECLARE_ATTRIBUTE_METHODS()
230 WX_PG_DECLARE_CUSTOM_PAINT_METHODS()
231 //virtual wxSize GetImageSize( int item ) const;
232 //virtual wxPGCellRenderer* GetCellRenderer( int column ) const;
234 // Helper function to show the colour dialog
235 bool QueryColourFromUser( wxVariant
& variant
) const;
237 /** Default is to use wxSystemSettings::GetColour(index). Override to use
238 custom colour tables etc.
240 virtual wxColour
GetColour( int index
) const;
242 wxColourPropertyValue
GetVal( const wxVariant
* pVariant
= NULL
) const;
246 // Special constructors to be used by derived classes.
247 wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
248 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
249 const wxColourPropertyValue
& value
);
250 wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
251 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
252 const wxColour
& value
);
254 void Init( int type
, const wxColour
& colour
);
256 // Utility functions for internal use
257 virtual wxVariant
DoTranslateVal( wxColourPropertyValue
& v
) const;
258 wxVariant
TranslateVal( wxColourPropertyValue
& v
) const
260 return DoTranslateVal( v
);
262 wxVariant
TranslateVal( int type
, const wxColour
& colour
) const
264 wxColourPropertyValue
v(type
, colour
);
265 return DoTranslateVal( v
);
268 // Translates colour to a int value, return wxNOT_FOUND if no match.
269 int ColToInd( const wxColour
& colour
) const;
272 // -----------------------------------------------------------------------
274 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(
275 wxColourProperty
, class WXDLLIMPEXP_PROPGRID
)
277 // Exclude classes from wxPython bindings
280 // -----------------------------------------------------------------------
282 /** @class wxCursorProperty
284 Property representing wxCursor.
286 class WXDLLIMPEXP_PROPGRID wxCursorProperty
: public wxEnumProperty
288 DECLARE_DYNAMIC_CLASS(wxCursorProperty
)
290 wxCursorProperty( const wxString
& label
= wxPG_LABEL
,
291 const wxString
& name
= wxPG_LABEL
,
293 virtual ~wxCursorProperty();
295 WX_PG_DECLARE_CUSTOM_PAINT_METHODS()
296 //virtual wxSize GetImageSize( int item ) const;
297 //virtual wxPGCellRenderer* GetCellRenderer( int column ) const;
300 // -----------------------------------------------------------------------
304 WXDLLIMPEXP_PROPGRID
const wxString
& wxPGGetDefaultImageWildcard();
306 /** @class wxImageFileProperty
308 Property representing image file(name).
310 class WXDLLIMPEXP_PROPGRID wxImageFileProperty
: public wxFileProperty
312 DECLARE_DYNAMIC_CLASS(wxImageFileProperty
)
315 wxImageFileProperty( const wxString
& label
= wxPG_LABEL
,
316 const wxString
& name
= wxPG_LABEL
,
317 const wxString
& value
= wxEmptyString
);
318 virtual ~wxImageFileProperty();
320 virtual void OnSetValue();
322 WX_PG_DECLARE_CUSTOM_PAINT_METHODS()
325 wxBitmap
* m_pBitmap
; // final thumbnail area
326 wxImage
* m_pImage
; // intermediate thumbnail area
331 #if wxUSE_CHOICEDLG || defined(SWIG)
333 /** @class wxMultiChoiceProperty
335 Property that manages a value resulting from wxMultiChoiceDialog. Value is
336 array of strings. You can get value as array of choice values/indices by
337 calling wxMultiChoiceProperty::GetValueAsArrayInt().
339 <b>Supported special attributes:</b>
340 - "UserStringMode": If > 0, allow user to manually enter strings that are
341 not in the list of choices. If this value is 1, user strings are
342 preferably placed in front of valid choices. If value is 2, then those
343 strings will placed behind valid choices.
345 class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty
: public wxPGProperty
347 WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty
)
350 wxMultiChoiceProperty( const wxString
& label
,
351 const wxString
& name
,
352 const wxArrayString
& strings
,
353 const wxArrayString
& value
);
355 wxMultiChoiceProperty( const wxString
& label
,
356 const wxString
& name
,
357 const wxPGChoices
& choices
,
358 const wxArrayString
& value
= wxArrayString() );
360 wxMultiChoiceProperty( const wxString
& label
= wxPG_LABEL
,
361 const wxString
& name
= wxPG_LABEL
,
362 const wxArrayString
& value
= wxArrayString() );
364 virtual ~wxMultiChoiceProperty();
366 virtual void OnSetValue();
367 virtual wxString
GetValueAsString( int flags
= 0 ) const;
368 virtual bool StringToValue(wxVariant
& variant
,
369 const wxString
& text
,
370 int argFlags
= 0) const;
371 WX_PG_DECLARE_EVENT_METHODS()
373 virtual int GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
);
375 wxArrayInt
GetValueAsArrayInt() const
377 return m_choices
.GetValuesForStrings(m_value
.GetArrayString());
382 void GenerateValueAsString();
384 // Returns translation of values into string indices.
385 wxArrayInt
GetValueAsIndices() const;
387 wxArrayString m_valueAsStrings
; // Value as array of strings
389 wxPGChoices m_choices
;
391 // Cache displayed text since generating it is relatively complicated.
395 #endif // wxUSE_CHOICEDLG
397 // -----------------------------------------------------------------------
401 /** @class wxDateProperty
403 Property representing wxDateTime.
405 <b>Supported special attributes:</b>
406 - "DateFormat": Determines displayed date format.
407 - "PickerStyle": Determines window style used with wxDatePickerCtrl.
408 Default is wxDP_DEFAULT | wxDP_SHOWCENTURY.
410 class WXDLLIMPEXP_PROPGRID wxDateProperty
: public wxPGProperty
412 WX_PG_DECLARE_PROPERTY_CLASS(wxDateProperty
)
415 wxDateProperty( const wxString
& label
= wxPG_LABEL
,
416 const wxString
& name
= wxPG_LABEL
,
417 const wxDateTime
& value
= wxDateTime() );
418 virtual ~wxDateProperty();
420 virtual wxString
GetValueAsString( int flags
= 0 ) const;
421 virtual bool StringToValue(wxVariant
& variant
,
422 const wxString
& text
,
423 int argFlags
= 0) const;
425 WX_PG_DECLARE_ATTRIBUTE_METHODS()
427 void SetFormat( const wxString
& format
)
432 const wxString
& GetFormat() const
437 void SetDateValue( const wxDateTime
& dt
)
439 //m_valueDateTime = dt;
443 wxDateTime
GetDateValue() const
445 //return m_valueDateTime;
449 long GetDatePickerStyle() const
456 long m_dpStyle
; // DatePicker style
458 static wxString ms_defaultDateFormat
;
459 static wxString
DetermineDefaultDateFormat( bool showCentury
);
462 #endif // wxUSE_DATETIME
466 // -----------------------------------------------------------------------
471 // Implement an editor control that allows using wxSpinCtrl (actually, a
472 // combination of wxTextCtrl and wxSpinButton) to edit value of wxIntProperty
473 // and wxFloatProperty (and similar).
475 // Note that new editor classes needs to be registered before use. This can be
476 // accomplished using wxPGRegisterEditorClass macro, which is used for SpinCtrl
477 // in wxPropertyGridInterface::RegisterAdditionalEditors (see below).
478 // Registration can also be performed in a constructor of a property that is
479 // likely to require the editor in question.
483 #include "wx/spinbutt.h"
484 #include "wx/propgrid/editors.h"
487 // NOTE: Regardless that this class inherits from a working editor, it has
488 // all necessary methods to work independently. wxTextCtrl stuff is only
489 // used for event handling here.
490 class WXDLLIMPEXP_PROPGRID wxPGSpinCtrlEditor
: public wxPGTextCtrlEditor
492 WX_PG_DECLARE_EDITOR_CLASS(wxPGSpinCtrlEditor
)
494 virtual ~wxPGSpinCtrlEditor();
496 // See below for short explanations of what these are suppposed to do.
497 wxPG_DECLARE_CREATECONTROLS
499 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
500 wxWindow
* wnd
, wxEvent
& event
) const;
503 mutable wxString m_tempString
;
506 #endif // wxUSE_SPINBTN
508 // -----------------------------------------------------------------------
510 #endif // _WX_PROPGRID_ADVPROPS_H_