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()
91 virtual ~wxColourPropertyValue()
95 wxColourPropertyValue( const wxColourPropertyValue
& v
)
98 m_colour
= v
.m_colour
;
101 void Init( wxUint32 type
, const wxColour
& colour
)
107 wxColourPropertyValue( const wxColour
& colour
)
109 m_type
= wxPG_COLOUR_CUSTOM
;
113 wxColourPropertyValue( wxUint32 type
)
118 wxColourPropertyValue( wxUint32 type
, const wxColour
& colour
)
120 Init( type
, colour
);
124 void operator=(const wxColourPropertyValue
& cpv
)
126 Init( cpv
.m_type
, cpv
.m_colour
);
130 DECLARE_DYNAMIC_CLASS(wxColourPropertyValue
)
136 bool WXDLLIMPEXP_PROPGRID
137 operator==(const wxColourPropertyValue
&, const wxColourPropertyValue
&);
139 DECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
144 #define wxPG_EMPTY_CPV (*((wxColourPropertyValue*)NULL))
145 #define wxPG_NORMAL_FONT (*wxNORMAL_FONT)
147 #define wxPG_EMPTY_CPV wxCPV_wxPG_EMPTY
148 #define wxPG_NORMAL_FONT wxFONT_wxPG_NORMAL_FONT
152 // -----------------------------------------------------------------------
153 // Declare part of custom colour property macro pairs.
155 #if wxUSE_IMAGE || defined(SWIG)
156 #include "wx/image.h"
159 // -----------------------------------------------------------------------
161 // Exclude class from wxPython bindings
164 /** @class wxFontProperty
166 Property representing wxFont.
168 class WXDLLIMPEXP_PROPGRID wxFontProperty
: public wxPGProperty
170 WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty
)
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;
180 WX_PG_DECLARE_EVENT_METHODS()
181 WX_PG_DECLARE_PARENTAL_METHODS()
182 //WX_PG_DECLARE_CUSTOM_PAINT_METHODS()
189 // -----------------------------------------------------------------------
192 /** If set, then match from list is searched for a custom colour. */
193 #define wxPG_PROP_TRANSLATE_CUSTOM wxPG_PROP_CLASS_SPECIFIC_1
196 /** @class wxSystemColourProperty
198 Has dropdown list of wxWidgets system colours. Value used is
199 of wxColourPropertyValue type.
201 class WXDLLIMPEXP_PROPGRID wxSystemColourProperty
: public wxEnumProperty
203 WX_PG_DECLARE_PROPERTY_CLASS(wxSystemColourProperty
)
206 wxSystemColourProperty( const wxString
& label
= wxPG_LABEL
,
207 const wxString
& name
= wxPG_LABEL
,
208 const wxColourPropertyValue
&
209 value
= wxColourPropertyValue() );
210 virtual ~wxSystemColourProperty();
212 virtual void OnSetValue();
213 virtual bool IntToValue(wxVariant
& variant
,
215 int argFlags
= 0) const;
218 Override in derived class to customize how colours are printed as
221 virtual wxString
ColourToString( const wxColour
& col
, int index
) const;
223 /** Returns index of entry that triggers colour picker dialog
226 virtual int GetCustomColourIndex() const;
228 WX_PG_DECLARE_BASIC_TYPE_METHODS()
229 WX_PG_DECLARE_EVENT_METHODS()
230 WX_PG_DECLARE_ATTRIBUTE_METHODS()
232 WX_PG_DECLARE_CUSTOM_PAINT_METHODS()
233 //virtual wxSize GetImageSize( int item ) const;
234 //virtual wxPGCellRenderer* GetCellRenderer( int column ) const;
236 // Helper function to show the colour dialog
237 bool QueryColourFromUser( wxVariant
& variant
) const;
239 /** Default is to use wxSystemSettings::GetColour(index). Override to use
240 custom colour tables etc.
242 virtual wxColour
GetColour( int index
) const;
244 wxColourPropertyValue
GetVal( const wxVariant
* pVariant
= NULL
) const;
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
);
256 void Init( int type
, const wxColour
& colour
);
258 // Utility functions for internal use
259 virtual wxVariant
DoTranslateVal( wxColourPropertyValue
& v
) const;
260 wxVariant
TranslateVal( wxColourPropertyValue
& v
) const
262 return DoTranslateVal( v
);
264 wxVariant
TranslateVal( int type
, const wxColour
& colour
) const
266 wxColourPropertyValue
v(type
, colour
);
267 return DoTranslateVal( v
);
270 // Translates colour to a int value, return wxNOT_FOUND if no match.
271 int ColToInd( const wxColour
& colour
) const;
274 // -----------------------------------------------------------------------
276 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(
277 wxColourProperty
, class WXDLLIMPEXP_PROPGRID
)
279 // Exclude classes from wxPython bindings
282 // -----------------------------------------------------------------------
284 /** @class wxCursorProperty
286 Property representing wxCursor.
288 class WXDLLIMPEXP_PROPGRID wxCursorProperty
: public wxEnumProperty
290 DECLARE_DYNAMIC_CLASS(wxCursorProperty
)
292 wxCursorProperty( const wxString
& label
= wxPG_LABEL
,
293 const wxString
& name
= wxPG_LABEL
,
295 virtual ~wxCursorProperty();
297 WX_PG_DECLARE_CUSTOM_PAINT_METHODS()
298 //virtual wxSize GetImageSize( int item ) const;
299 //virtual wxPGCellRenderer* GetCellRenderer( int column ) const;
302 // -----------------------------------------------------------------------
306 WXDLLIMPEXP_PROPGRID
const wxString
& wxPGGetDefaultImageWildcard();
308 /** @class wxImageFileProperty
310 Property representing image file(name).
312 class WXDLLIMPEXP_PROPGRID wxImageFileProperty
: public wxFileProperty
314 DECLARE_DYNAMIC_CLASS(wxImageFileProperty
)
317 wxImageFileProperty( const wxString
& label
= wxPG_LABEL
,
318 const wxString
& name
= wxPG_LABEL
,
319 const wxString
& value
= wxEmptyString
);
320 virtual ~wxImageFileProperty();
322 virtual void OnSetValue();
324 WX_PG_DECLARE_CUSTOM_PAINT_METHODS()
327 wxBitmap
* m_pBitmap
; // final thumbnail area
328 wxImage
* m_pImage
; // intermediate thumbnail area
333 #if wxUSE_CHOICEDLG || defined(SWIG)
335 /** @class wxMultiChoiceProperty
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().
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.
347 class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty
: public wxPGProperty
349 WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty
)
352 wxMultiChoiceProperty( const wxString
& label
,
353 const wxString
& name
,
354 const wxArrayString
& strings
,
355 const wxArrayString
& value
);
357 wxMultiChoiceProperty( const wxString
& label
,
358 const wxString
& name
,
359 const wxPGChoices
& choices
,
360 const wxArrayString
& value
= wxArrayString() );
362 wxMultiChoiceProperty( const wxString
& label
= wxPG_LABEL
,
363 const wxString
& name
= wxPG_LABEL
,
364 const wxArrayString
& value
= wxArrayString() );
366 virtual ~wxMultiChoiceProperty();
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()
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 // Cache displayed text since generating it is relatively complicated.
393 #endif // wxUSE_CHOICEDLG
395 // -----------------------------------------------------------------------
399 /** @class wxDateProperty
401 Property representing wxDateTime.
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.
408 class WXDLLIMPEXP_PROPGRID wxDateProperty
: public wxPGProperty
410 WX_PG_DECLARE_PROPERTY_CLASS(wxDateProperty
)
413 wxDateProperty( const wxString
& label
= wxPG_LABEL
,
414 const wxString
& name
= wxPG_LABEL
,
415 const wxDateTime
& value
= wxDateTime() );
416 virtual ~wxDateProperty();
418 virtual wxString
GetValueAsString( int flags
= 0 ) const;
419 virtual bool StringToValue(wxVariant
& variant
,
420 const wxString
& text
,
421 int argFlags
= 0) const;
423 WX_PG_DECLARE_ATTRIBUTE_METHODS()
425 void SetFormat( const wxString
& format
)
430 const wxString
& GetFormat() const
435 void SetDateValue( const wxDateTime
& dt
)
437 //m_valueDateTime = dt;
441 wxDateTime
GetDateValue() const
443 //return m_valueDateTime;
447 long GetDatePickerStyle() const
454 long m_dpStyle
; // DatePicker style
456 static wxString ms_defaultDateFormat
;
457 static wxString
DetermineDefaultDateFormat( bool showCentury
);
460 #endif // wxUSE_DATETIME
464 // -----------------------------------------------------------------------
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).
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.
481 #include "wx/spinbutt.h"
482 #include "wx/propgrid/editors.h"
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
490 WX_PG_DECLARE_EDITOR_CLASS(wxPGSpinCtrlEditor
)
492 virtual ~wxPGSpinCtrlEditor();
494 // See below for short explanations of what these are suppposed to do.
495 wxPG_DECLARE_CREATECONTROLS
497 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
498 wxWindow
* wnd
, wxEvent
& event
) const;
501 mutable wxString m_tempString
;
504 #endif // wxUSE_SPINBTN
506 // -----------------------------------------------------------------------
508 #endif // wxUSE_PROPGRID
510 #endif // _WX_PROPGRID_ADVPROPS_H_