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;
179 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
180 wxWindow
* primary
, wxEvent
& event
);
181 virtual void ChildChanged( wxVariant
& thisValue
,
182 int childIndex
, wxVariant
& childValue
) const;
183 virtual void RefreshChildren();
190 // -----------------------------------------------------------------------
193 /** If set, then match from list is searched for a custom colour. */
194 #define wxPG_PROP_TRANSLATE_CUSTOM wxPG_PROP_CLASS_SPECIFIC_1
197 /** @class wxSystemColourProperty
199 Has dropdown list of wxWidgets system colours. Value used is
200 of wxColourPropertyValue type.
202 class WXDLLIMPEXP_PROPGRID wxSystemColourProperty
: public wxEnumProperty
204 WX_PG_DECLARE_PROPERTY_CLASS(wxSystemColourProperty
)
207 wxSystemColourProperty( const wxString
& label
= wxPG_LABEL
,
208 const wxString
& name
= wxPG_LABEL
,
209 const wxColourPropertyValue
&
210 value
= wxColourPropertyValue() );
211 virtual ~wxSystemColourProperty();
213 virtual void OnSetValue();
214 virtual bool IntToValue(wxVariant
& variant
,
216 int argFlags
= 0) const;
219 Override in derived class to customize how colours are printed as
222 virtual wxString
ColourToString( const wxColour
& col
, int index
) const;
224 /** Returns index of entry that triggers colour picker dialog
227 virtual int GetCustomColourIndex() const;
229 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
230 virtual bool StringToValue( wxVariant
& variant
,
231 const wxString
& text
,
232 int argFlags
= 0 ) const;
233 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
234 wxWindow
* primary
, wxEvent
& event
);
235 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
236 virtual wxSize
OnMeasureImage( int item
) const;
237 virtual void OnCustomPaint( wxDC
& dc
,
238 const wxRect
& rect
, wxPGPaintData
& paintdata
);
240 // Helper function to show the colour dialog
241 bool QueryColourFromUser( wxVariant
& variant
) const;
243 /** Default is to use wxSystemSettings::GetColour(index). Override to use
244 custom colour tables etc.
246 virtual wxColour
GetColour( int index
) const;
248 wxColourPropertyValue
GetVal( const wxVariant
* pVariant
= NULL
) const;
252 // Special constructors to be used by derived classes.
253 wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
254 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
255 const wxColourPropertyValue
& value
);
256 wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
257 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
258 const wxColour
& value
);
260 void Init( int type
, const wxColour
& colour
);
262 // Utility functions for internal use
263 virtual wxVariant
DoTranslateVal( wxColourPropertyValue
& v
) const;
264 wxVariant
TranslateVal( wxColourPropertyValue
& v
) const
266 return DoTranslateVal( v
);
268 wxVariant
TranslateVal( int type
, const wxColour
& colour
) const
270 wxColourPropertyValue
v(type
, colour
);
271 return DoTranslateVal( v
);
274 // Translates colour to a int value, return wxNOT_FOUND if no match.
275 int ColToInd( const wxColour
& colour
) const;
278 // -----------------------------------------------------------------------
280 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(
281 wxColourProperty
, class WXDLLIMPEXP_PROPGRID
)
283 // Exclude classes from wxPython bindings
286 // -----------------------------------------------------------------------
288 /** @class wxCursorProperty
290 Property representing wxCursor.
292 class WXDLLIMPEXP_PROPGRID wxCursorProperty
: public wxEnumProperty
294 DECLARE_DYNAMIC_CLASS(wxCursorProperty
)
296 wxCursorProperty( const wxString
& label
= wxPG_LABEL
,
297 const wxString
& name
= wxPG_LABEL
,
299 virtual ~wxCursorProperty();
301 virtual wxSize
OnMeasureImage( int item
) const;
302 virtual void OnCustomPaint( wxDC
& dc
,
303 const wxRect
& rect
, wxPGPaintData
& paintdata
);
306 // -----------------------------------------------------------------------
310 WXDLLIMPEXP_PROPGRID
const wxString
& wxPGGetDefaultImageWildcard();
312 /** @class wxImageFileProperty
314 Property representing image file(name).
316 class WXDLLIMPEXP_PROPGRID wxImageFileProperty
: public wxFileProperty
318 DECLARE_DYNAMIC_CLASS(wxImageFileProperty
)
321 wxImageFileProperty( const wxString
& label
= wxPG_LABEL
,
322 const wxString
& name
= wxPG_LABEL
,
323 const wxString
& value
= wxEmptyString
);
324 virtual ~wxImageFileProperty();
326 virtual void OnSetValue();
328 virtual wxSize
OnMeasureImage( int item
) const;
329 virtual void OnCustomPaint( wxDC
& dc
,
330 const wxRect
& rect
, wxPGPaintData
& paintdata
);
333 wxBitmap
* m_pBitmap
; // final thumbnail area
334 wxImage
* m_pImage
; // intermediate thumbnail area
339 #if wxUSE_CHOICEDLG || defined(SWIG)
341 /** @class wxMultiChoiceProperty
343 Property that manages a value resulting from wxMultiChoiceDialog. Value is
344 array of strings. You can get value as array of choice values/indices by
345 calling wxMultiChoiceProperty::GetValueAsArrayInt().
347 <b>Supported special attributes:</b>
348 - "UserStringMode": If > 0, allow user to manually enter strings that are
349 not in the list of choices. If this value is 1, user strings are
350 preferably placed in front of valid choices. If value is 2, then those
351 strings will placed behind valid choices.
353 class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty
: public wxPGProperty
355 WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty
)
358 wxMultiChoiceProperty( const wxString
& label
,
359 const wxString
& name
,
360 const wxArrayString
& strings
,
361 const wxArrayString
& value
);
363 wxMultiChoiceProperty( const wxString
& label
,
364 const wxString
& name
,
365 const wxPGChoices
& choices
,
366 const wxArrayString
& value
= wxArrayString() );
368 wxMultiChoiceProperty( const wxString
& label
= wxPG_LABEL
,
369 const wxString
& name
= wxPG_LABEL
,
370 const wxArrayString
& value
= wxArrayString() );
372 virtual ~wxMultiChoiceProperty();
374 virtual void OnSetValue();
375 virtual wxString
GetValueAsString( int flags
= 0 ) const;
376 virtual bool StringToValue(wxVariant
& variant
,
377 const wxString
& text
,
378 int argFlags
= 0) const;
379 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
380 wxWindow
* primary
, wxEvent
& event
);
382 wxArrayInt
GetValueAsArrayInt() const
384 return m_choices
.GetValuesForStrings(m_value
.GetArrayString());
389 void GenerateValueAsString();
391 // Returns translation of values into string indices.
392 wxArrayInt
GetValueAsIndices() const;
394 wxArrayString m_valueAsStrings
; // Value as array of strings
396 // Cache displayed text since generating it is relatively complicated.
400 #endif // wxUSE_CHOICEDLG
402 // -----------------------------------------------------------------------
406 /** @class wxDateProperty
408 Property representing wxDateTime.
410 <b>Supported special attributes:</b>
411 - "DateFormat": Determines displayed date format.
412 - "PickerStyle": Determines window style used with wxDatePickerCtrl.
413 Default is wxDP_DEFAULT | wxDP_SHOWCENTURY.
415 class WXDLLIMPEXP_PROPGRID wxDateProperty
: public wxPGProperty
417 WX_PG_DECLARE_PROPERTY_CLASS(wxDateProperty
)
420 wxDateProperty( const wxString
& label
= wxPG_LABEL
,
421 const wxString
& name
= wxPG_LABEL
,
422 const wxDateTime
& value
= wxDateTime() );
423 virtual ~wxDateProperty();
425 virtual wxString
GetValueAsString( int flags
= 0 ) const;
426 virtual bool StringToValue(wxVariant
& variant
,
427 const wxString
& text
,
428 int argFlags
= 0) const;
430 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
432 void SetFormat( const wxString
& format
)
437 const wxString
& GetFormat() const
442 void SetDateValue( const wxDateTime
& dt
)
444 //m_valueDateTime = dt;
448 wxDateTime
GetDateValue() const
450 //return m_valueDateTime;
454 long GetDatePickerStyle() const
461 long m_dpStyle
; // DatePicker style
463 static wxString ms_defaultDateFormat
;
464 static wxString
DetermineDefaultDateFormat( bool showCentury
);
467 #endif // wxUSE_DATETIME
471 // -----------------------------------------------------------------------
476 // Implement an editor control that allows using wxSpinCtrl (actually, a
477 // combination of wxTextCtrl and wxSpinButton) to edit value of wxIntProperty
478 // and wxFloatProperty (and similar).
480 // Note that new editor classes needs to be registered before use. This can be
481 // accomplished using wxPGRegisterEditorClass macro, which is used for SpinCtrl
482 // in wxPropertyGridInterface::RegisterAdditionalEditors (see below).
483 // Registration can also be performed in a constructor of a property that is
484 // likely to require the editor in question.
488 #include "wx/spinbutt.h"
489 #include "wx/propgrid/editors.h"
492 // NOTE: Regardless that this class inherits from a working editor, it has
493 // all necessary methods to work independently. wxTextCtrl stuff is only
494 // used for event handling here.
495 class WXDLLIMPEXP_PROPGRID wxPGSpinCtrlEditor
: public wxPGTextCtrlEditor
497 WX_PG_DECLARE_EDITOR_CLASS(wxPGSpinCtrlEditor
)
499 virtual ~wxPGSpinCtrlEditor();
501 // See below for short explanations of what these are suppposed to do.
502 wxPG_DECLARE_CREATECONTROLS
504 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
505 wxWindow
* wnd
, wxEvent
& event
) const;
508 mutable wxString m_tempString
;
511 #endif // wxUSE_SPINBTN
513 // -----------------------------------------------------------------------
515 #endif // wxUSE_PROPGRID
517 #endif // _WX_PROPGRID_ADVPROPS_H_