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 licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROPGRID_ADVPROPS_H_
13 #define _WX_PROPGRID_ADVPROPS_H_
19 #include "wx/propgrid/props.h"
21 // -----------------------------------------------------------------------
24 // Additional Value Type Handlers
26 bool WXDLLIMPEXP_PROPGRID
27 operator==(const wxArrayInt
& array1
, const wxArrayInt
& array2
);
30 // Additional Property Editors
33 WX_PG_DECLARE_EDITOR_WITH_DECL(SpinCtrl
,WXDLLIMPEXP_PROPGRID
)
36 #if wxUSE_DATEPICKCTRL
37 WX_PG_DECLARE_EDITOR_WITH_DECL(DatePickerCtrl
,WXDLLIMPEXP_PROPGRID
)
40 // -----------------------------------------------------------------------
43 // Web colour is currently unsupported
44 #define wxPG_COLOUR_WEB_BASE 0x10000
45 //#define wxPG_TO_WEB_COLOUR(A) ((wxUint32)(A+wxPG_COLOUR_WEB_BASE))
48 #define wxPG_COLOUR_CUSTOM 0xFFFFFF
49 #define wxPG_COLOUR_UNSPECIFIED (wxPG_COLOUR_CUSTOM+1)
51 /** @class wxColourPropertyValue
53 Because text, background and other colours tend to differ between
54 platforms, wxSystemColourProperty must be able to select between system
55 colour and, when necessary, to pick a custom one. wxSystemColourProperty
56 value makes this possible.
58 class WXDLLIMPEXP_PROPGRID wxColourPropertyValue
: public wxObject
61 /** An integer value relating to the colour, and which exact
62 meaning depends on the property with which it is used.
64 For wxSystemColourProperty:
66 Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
67 macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
69 For custom colour properties without values array specified:
71 index or wxPG_COLOUR_CUSTOM
73 For custom colour properties <b>with</b> values array specified:
75 m_arrValues[index] or wxPG_COLOUR_CUSTOM
79 /** Resulting colour. Should be correct regardless of type. */
82 wxColourPropertyValue()
88 virtual ~wxColourPropertyValue()
92 wxColourPropertyValue( const wxColourPropertyValue
& v
)
96 m_colour
= v
.m_colour
;
99 void Init( wxUint32 type
, const wxColour
& colour
)
105 wxColourPropertyValue( const wxColour
& colour
)
108 m_type
= wxPG_COLOUR_CUSTOM
;
112 wxColourPropertyValue( wxUint32 type
)
118 wxColourPropertyValue( wxUint32 type
, const wxColour
& colour
)
121 Init( type
, colour
);
124 void operator=(const wxColourPropertyValue
& cpv
)
127 Init( cpv
.m_type
, cpv
.m_colour
);
131 DECLARE_DYNAMIC_CLASS(wxColourPropertyValue
)
135 bool WXDLLIMPEXP_PROPGRID
136 operator==(const wxColourPropertyValue
&, const wxColourPropertyValue
&);
138 DECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
140 // -----------------------------------------------------------------------
141 // Declare part of custom colour property macro pairs.
144 #include "wx/image.h"
147 // -----------------------------------------------------------------------
149 /** @class wxFontProperty
151 Property representing wxFont.
153 class WXDLLIMPEXP_PROPGRID wxFontProperty
: public wxPGProperty
155 WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty
)
158 wxFontProperty(const wxString
& label
= wxPG_LABEL
,
159 const wxString
& name
= wxPG_LABEL
,
160 const wxFont
& value
= wxFont());
161 virtual ~wxFontProperty();
162 virtual void OnSetValue();
163 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
164 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
165 wxWindow
* primary
, wxEvent
& event
);
166 virtual wxVariant
ChildChanged( wxVariant
& thisValue
,
168 wxVariant
& childValue
) const;
169 virtual void RefreshChildren();
174 // -----------------------------------------------------------------------
177 /** If set, then match from list is searched for a custom colour. */
178 #define wxPG_PROP_TRANSLATE_CUSTOM wxPG_PROP_CLASS_SPECIFIC_1
181 /** @class wxSystemColourProperty
183 Has dropdown list of wxWidgets system colours. Value used is
184 of wxColourPropertyValue type.
186 class WXDLLIMPEXP_PROPGRID wxSystemColourProperty
: public wxEnumProperty
188 WX_PG_DECLARE_PROPERTY_CLASS(wxSystemColourProperty
)
191 wxSystemColourProperty( const wxString
& label
= wxPG_LABEL
,
192 const wxString
& name
= wxPG_LABEL
,
193 const wxColourPropertyValue
&
194 value
= wxColourPropertyValue() );
195 virtual ~wxSystemColourProperty();
197 virtual void OnSetValue();
198 virtual bool IntToValue(wxVariant
& variant
,
200 int argFlags
= 0) const;
203 Override in derived class to customize how colours are printed as
206 virtual wxString
ColourToString( const wxColour
& col
, int index
,
207 int argFlags
= 0 ) const;
209 /** Returns index of entry that triggers colour picker dialog
212 virtual int GetCustomColourIndex() const;
214 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
215 virtual bool StringToValue( wxVariant
& variant
,
216 const wxString
& text
,
217 int argFlags
= 0 ) const;
218 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
219 wxWindow
* primary
, wxEvent
& event
);
220 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
221 virtual wxSize
OnMeasureImage( int item
) const;
222 virtual void OnCustomPaint( wxDC
& dc
,
223 const wxRect
& rect
, wxPGPaintData
& paintdata
);
225 // Helper function to show the colour dialog
226 bool QueryColourFromUser( wxVariant
& variant
) const;
228 /** Default is to use wxSystemSettings::GetColour(index). Override to use
229 custom colour tables etc.
231 virtual wxColour
GetColour( int index
) const;
233 wxColourPropertyValue
GetVal( const wxVariant
* pVariant
= NULL
) const;
237 // Special constructors to be used by derived classes.
238 wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
239 const wxChar
* const* labels
, const long* values
, wxPGChoices
* choicesCache
,
240 const wxColourPropertyValue
& value
);
241 wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
242 const wxChar
* const* labels
, const long* values
, wxPGChoices
* choicesCache
,
243 const wxColour
& value
);
245 void Init( int type
, const wxColour
& colour
);
247 // Utility functions for internal use
248 virtual wxVariant
DoTranslateVal( wxColourPropertyValue
& v
) const;
249 wxVariant
TranslateVal( wxColourPropertyValue
& v
) const
251 return DoTranslateVal( v
);
253 wxVariant
TranslateVal( int type
, const wxColour
& colour
) const
255 wxColourPropertyValue
v(type
, colour
);
256 return DoTranslateVal( v
);
259 // Translates colour to a int value, return wxNOT_FOUND if no match.
260 int ColToInd( const wxColour
& colour
) const;
263 // -----------------------------------------------------------------------
265 class WXDLLIMPEXP_PROPGRID wxColourProperty
: public wxSystemColourProperty
267 WX_PG_DECLARE_PROPERTY_CLASS(wxColourProperty
)
269 wxColourProperty( const wxString
& label
= wxPG_LABEL
,
270 const wxString
& name
= wxPG_LABEL
,
271 const wxColour
& value
= *wxWHITE
);
272 virtual ~wxColourProperty();
274 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
275 virtual wxColour
GetColour( int index
) const;
278 virtual wxVariant
DoTranslateVal( wxColourPropertyValue
& v
) const;
281 void Init( wxColour colour
);
284 // -----------------------------------------------------------------------
286 /** @class wxCursorProperty
288 Property representing wxCursor.
290 class WXDLLIMPEXP_PROPGRID wxCursorProperty
: public wxEnumProperty
292 DECLARE_DYNAMIC_CLASS(wxCursorProperty
)
294 wxCursorProperty( const wxString
& label
= wxPG_LABEL
,
295 const wxString
& name
= wxPG_LABEL
,
297 virtual ~wxCursorProperty();
299 virtual wxSize
OnMeasureImage( int item
) const;
300 virtual void OnCustomPaint( wxDC
& dc
,
301 const wxRect
& rect
, wxPGPaintData
& paintdata
);
304 // -----------------------------------------------------------------------
308 WXDLLIMPEXP_PROPGRID
const wxString
& wxPGGetDefaultImageWildcard();
310 /** @class wxImageFileProperty
312 Property representing image file(name).
314 class WXDLLIMPEXP_PROPGRID wxImageFileProperty
: public wxFileProperty
316 DECLARE_DYNAMIC_CLASS(wxImageFileProperty
)
319 wxImageFileProperty( const wxString
& label
= wxPG_LABEL
,
320 const wxString
& name
= wxPG_LABEL
,
321 const wxString
& value
= wxEmptyString
);
322 virtual ~wxImageFileProperty();
324 virtual void OnSetValue();
326 virtual wxSize
OnMeasureImage( int item
) const;
327 virtual void OnCustomPaint( wxDC
& dc
,
328 const wxRect
& rect
, wxPGPaintData
& paintdata
);
331 wxBitmap
* m_pBitmap
; // final thumbnail area
332 wxImage
* m_pImage
; // intermediate thumbnail area
339 /** @class wxMultiChoiceProperty
341 Property that manages a value resulting from wxMultiChoiceDialog. Value is
342 array of strings. You can get value as array of choice values/indices by
343 calling wxMultiChoiceProperty::GetValueAsArrayInt().
345 <b>Supported special attributes:</b>
346 - "UserStringMode": If > 0, allow user to manually enter strings that are
347 not in the list of choices. If this value is 1, user strings are
348 preferably placed in front of valid choices. If value is 2, then those
349 strings will placed behind valid choices.
351 class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty
: public wxPGProperty
353 WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty
)
356 wxMultiChoiceProperty( const wxString
& label
,
357 const wxString
& name
,
358 const wxArrayString
& strings
,
359 const wxArrayString
& value
);
360 wxMultiChoiceProperty( const wxString
& label
,
361 const wxString
& name
,
362 const wxPGChoices
& choices
,
363 const wxArrayString
& value
= wxArrayString() );
365 wxMultiChoiceProperty( const wxString
& label
= wxPG_LABEL
,
366 const wxString
& name
= wxPG_LABEL
,
367 const wxArrayString
& value
= wxArrayString() );
369 virtual ~wxMultiChoiceProperty();
371 virtual void OnSetValue();
372 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
373 virtual bool StringToValue(wxVariant
& variant
,
374 const wxString
& text
,
375 int argFlags
= 0) const;
376 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
377 wxWindow
* primary
, wxEvent
& event
);
379 wxArrayInt
GetValueAsArrayInt() const
381 return m_choices
.GetValuesForStrings(m_value
.GetArrayString());
386 void GenerateValueAsString( wxVariant
& value
, wxString
* target
) const;
388 // Returns translation of values into string indices.
389 wxArrayInt
GetValueAsIndices() const;
391 wxArrayString m_valueAsStrings
; // Value as array of strings
393 // Cache displayed text since generating it is relatively complicated.
397 #endif // wxUSE_CHOICEDLG
399 // -----------------------------------------------------------------------
403 /** @class wxDateProperty
405 Property representing wxDateTime.
407 <b>Supported special attributes:</b>
408 - "DateFormat": Determines displayed date format.
409 - "PickerStyle": Determines window style used with wxDatePickerCtrl.
410 Default is wxDP_DEFAULT | wxDP_SHOWCENTURY. Using wxDP_ALLOWNONE
411 enables additional support for unspecified property value.
413 class WXDLLIMPEXP_PROPGRID wxDateProperty
: public wxPGProperty
415 WX_PG_DECLARE_PROPERTY_CLASS(wxDateProperty
)
418 wxDateProperty( const wxString
& label
= wxPG_LABEL
,
419 const wxString
& name
= wxPG_LABEL
,
420 const wxDateTime
& value
= wxDateTime() );
421 virtual ~wxDateProperty();
423 virtual void OnSetValue();
424 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
425 virtual bool StringToValue(wxVariant
& variant
,
426 const wxString
& text
,
427 int argFlags
= 0) const;
429 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
431 void SetFormat( const wxString
& format
)
436 const wxString
& GetFormat() const
441 void SetDateValue( const wxDateTime
& dt
)
443 //m_valueDateTime = dt;
447 wxDateTime
GetDateValue() const
449 //return m_valueDateTime;
453 long GetDatePickerStyle() const
460 long m_dpStyle
; // DatePicker style
462 static wxString ms_defaultDateFormat
;
463 static wxString
DetermineDefaultDateFormat( bool showCentury
);
466 #endif // wxUSE_DATETIME
468 // -----------------------------------------------------------------------
473 // Implement an editor control that allows using wxSpinCtrl (actually, a
474 // combination of wxTextCtrl and wxSpinButton) to edit value of wxIntProperty
475 // and wxFloatProperty (and similar).
477 // Note that new editor classes needs to be registered before use. This can be
478 // accomplished using wxPGRegisterEditorClass macro, which is used for SpinCtrl
479 // in wxPropertyGridInterface::RegisterAdditionalEditors (see below).
480 // Registration can also be performed in a constructor of a property that is
481 // likely to require the editor in question.
485 #include "wx/spinbutt.h"
486 #include "wx/propgrid/editors.h"
489 // NOTE: Regardless that this class inherits from a working editor, it has
490 // all necessary methods to work independently. wxTextCtrl stuff is only
491 // used for event handling here.
492 class WXDLLIMPEXP_PROPGRID wxPGSpinCtrlEditor
: public wxPGTextCtrlEditor
494 DECLARE_DYNAMIC_CLASS(wxPGSpinCtrlEditor
)
496 virtual ~wxPGSpinCtrlEditor();
498 wxString
GetName() const;
499 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
500 wxPGProperty
* property
,
502 const wxSize
& size
) const;
503 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
504 wxWindow
* wnd
, wxEvent
& event
) const;
507 mutable wxString m_tempString
;
510 #endif // wxUSE_SPINBTN
512 // -----------------------------------------------------------------------
514 #endif // wxUSE_PROPGRID
516 #endif // _WX_PROPGRID_ADVPROPS_H_