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
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()
90 virtual ~wxColourPropertyValue()
94 wxColourPropertyValue( const wxColourPropertyValue
& v
)
98 m_colour
= v
.m_colour
;
101 void Init( wxUint32 type
, const wxColour
& colour
)
107 wxColourPropertyValue( const wxColour
& colour
)
110 m_type
= wxPG_COLOUR_CUSTOM
;
114 wxColourPropertyValue( wxUint32 type
)
120 wxColourPropertyValue( wxUint32 type
, const wxColour
& colour
)
123 Init( type
, colour
);
127 void operator=(const wxColourPropertyValue
& cpv
)
129 Init( cpv
.m_type
, cpv
.m_colour
);
133 DECLARE_DYNAMIC_CLASS(wxColourPropertyValue
)
139 bool WXDLLIMPEXP_PROPGRID
140 operator==(const wxColourPropertyValue
&, const wxColourPropertyValue
&);
142 DECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
147 #define wxPG_EMPTY_CPV (*((wxColourPropertyValue*)NULL))
148 #define wxPG_NORMAL_FONT (*wxNORMAL_FONT)
150 #define wxPG_EMPTY_CPV wxCPV_wxPG_EMPTY
151 #define wxPG_NORMAL_FONT wxFONT_wxPG_NORMAL_FONT
155 // -----------------------------------------------------------------------
156 // Declare part of custom colour property macro pairs.
158 #if wxUSE_IMAGE || defined(SWIG)
159 #include "wx/image.h"
162 // -----------------------------------------------------------------------
164 // Exclude class from wxPython bindings
167 /** @class wxFontProperty
169 Property representing wxFont.
171 class WXDLLIMPEXP_PROPGRID wxFontProperty
: public wxPGProperty
173 WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty
)
176 wxFontProperty(const wxString
& label
= wxPG_LABEL
,
177 const wxString
& name
= wxPG_LABEL
,
178 const wxFont
& value
= wxFont());
179 virtual ~wxFontProperty();
180 virtual void OnSetValue();
181 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
182 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
183 wxWindow
* primary
, wxEvent
& event
);
184 virtual void ChildChanged( wxVariant
& thisValue
,
185 int childIndex
, wxVariant
& childValue
) const;
186 virtual void RefreshChildren();
193 // -----------------------------------------------------------------------
196 /** If set, then match from list is searched for a custom colour. */
197 #define wxPG_PROP_TRANSLATE_CUSTOM wxPG_PROP_CLASS_SPECIFIC_1
200 /** @class wxSystemColourProperty
202 Has dropdown list of wxWidgets system colours. Value used is
203 of wxColourPropertyValue type.
205 class WXDLLIMPEXP_PROPGRID wxSystemColourProperty
: public wxEnumProperty
207 WX_PG_DECLARE_PROPERTY_CLASS(wxSystemColourProperty
)
210 wxSystemColourProperty( const wxString
& label
= wxPG_LABEL
,
211 const wxString
& name
= wxPG_LABEL
,
212 const wxColourPropertyValue
&
213 value
= wxColourPropertyValue() );
214 virtual ~wxSystemColourProperty();
216 virtual void OnSetValue();
217 virtual bool IntToValue(wxVariant
& variant
,
219 int argFlags
= 0) const;
222 Override in derived class to customize how colours are printed as
225 virtual wxString
ColourToString( const wxColour
& col
, int index
) const;
227 /** Returns index of entry that triggers colour picker dialog
230 virtual int GetCustomColourIndex() const;
232 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
233 virtual bool StringToValue( wxVariant
& variant
,
234 const wxString
& text
,
235 int argFlags
= 0 ) const;
236 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
237 wxWindow
* primary
, wxEvent
& event
);
238 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
239 virtual wxSize
OnMeasureImage( int item
) const;
240 virtual void OnCustomPaint( wxDC
& dc
,
241 const wxRect
& rect
, wxPGPaintData
& paintdata
);
243 // Helper function to show the colour dialog
244 bool QueryColourFromUser( wxVariant
& variant
) const;
246 /** Default is to use wxSystemSettings::GetColour(index). Override to use
247 custom colour tables etc.
249 virtual wxColour
GetColour( int index
) const;
251 wxColourPropertyValue
GetVal( const wxVariant
* pVariant
= NULL
) const;
255 // Special constructors to be used by derived classes.
256 wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
257 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
258 const wxColourPropertyValue
& value
);
259 wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
260 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
261 const wxColour
& value
);
263 void Init( int type
, const wxColour
& colour
);
265 // Utility functions for internal use
266 virtual wxVariant
DoTranslateVal( wxColourPropertyValue
& v
) const;
267 wxVariant
TranslateVal( wxColourPropertyValue
& v
) const
269 return DoTranslateVal( v
);
271 wxVariant
TranslateVal( int type
, const wxColour
& colour
) const
273 wxColourPropertyValue
v(type
, colour
);
274 return DoTranslateVal( v
);
277 // Translates colour to a int value, return wxNOT_FOUND if no match.
278 int ColToInd( const wxColour
& colour
) const;
281 // -----------------------------------------------------------------------
283 class WXDLLIMPEXP_PROPGRID wxColourProperty
: public wxSystemColourProperty
285 WX_PG_DECLARE_PROPERTY_CLASS(wxColourProperty
)
287 wxColourProperty( const wxString
& label
= wxPG_LABEL
,
288 const wxString
& name
= wxPG_LABEL
,
289 const wxColour
& value
= *wxWHITE
);
290 virtual ~wxColourProperty();
293 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
294 virtual wxColour
GetColour( int index
) const;
295 virtual wxVariant
DoTranslateVal( wxColourPropertyValue
& v
) const;
298 void Init( wxColour colour
);
301 // -----------------------------------------------------------------------
303 // Exclude classes from wxPython bindings
306 /** @class wxCursorProperty
308 Property representing wxCursor.
310 class WXDLLIMPEXP_PROPGRID wxCursorProperty
: public wxEnumProperty
312 DECLARE_DYNAMIC_CLASS(wxCursorProperty
)
314 wxCursorProperty( const wxString
& label
= wxPG_LABEL
,
315 const wxString
& name
= wxPG_LABEL
,
317 virtual ~wxCursorProperty();
319 virtual wxSize
OnMeasureImage( int item
) const;
320 virtual void OnCustomPaint( wxDC
& dc
,
321 const wxRect
& rect
, wxPGPaintData
& paintdata
);
324 // -----------------------------------------------------------------------
328 WXDLLIMPEXP_PROPGRID
const wxString
& wxPGGetDefaultImageWildcard();
330 /** @class wxImageFileProperty
332 Property representing image file(name).
334 class WXDLLIMPEXP_PROPGRID wxImageFileProperty
: public wxFileProperty
336 DECLARE_DYNAMIC_CLASS(wxImageFileProperty
)
339 wxImageFileProperty( const wxString
& label
= wxPG_LABEL
,
340 const wxString
& name
= wxPG_LABEL
,
341 const wxString
& value
= wxEmptyString
);
342 virtual ~wxImageFileProperty();
344 virtual void OnSetValue();
346 virtual wxSize
OnMeasureImage( int item
) const;
347 virtual void OnCustomPaint( wxDC
& dc
,
348 const wxRect
& rect
, wxPGPaintData
& paintdata
);
351 wxBitmap
* m_pBitmap
; // final thumbnail area
352 wxImage
* m_pImage
; // intermediate thumbnail area
357 #if wxUSE_CHOICEDLG || defined(SWIG)
359 /** @class wxMultiChoiceProperty
361 Property that manages a value resulting from wxMultiChoiceDialog. Value is
362 array of strings. You can get value as array of choice values/indices by
363 calling wxMultiChoiceProperty::GetValueAsArrayInt().
365 <b>Supported special attributes:</b>
366 - "UserStringMode": If > 0, allow user to manually enter strings that are
367 not in the list of choices. If this value is 1, user strings are
368 preferably placed in front of valid choices. If value is 2, then those
369 strings will placed behind valid choices.
371 class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty
: public wxPGProperty
373 WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty
)
376 wxMultiChoiceProperty( const wxString
& label
,
377 const wxString
& name
,
378 const wxArrayString
& strings
,
379 const wxArrayString
& value
);
381 wxMultiChoiceProperty( const wxString
& label
,
382 const wxString
& name
,
383 const wxPGChoices
& choices
,
384 const wxArrayString
& value
= wxArrayString() );
386 wxMultiChoiceProperty( const wxString
& label
= wxPG_LABEL
,
387 const wxString
& name
= wxPG_LABEL
,
388 const wxArrayString
& value
= wxArrayString() );
390 virtual ~wxMultiChoiceProperty();
392 virtual void OnSetValue();
393 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
394 virtual bool StringToValue(wxVariant
& variant
,
395 const wxString
& text
,
396 int argFlags
= 0) const;
397 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
398 wxWindow
* primary
, wxEvent
& event
);
400 wxArrayInt
GetValueAsArrayInt() const
402 return m_choices
.GetValuesForStrings(m_value
.GetArrayString());
407 void GenerateValueAsString( wxVariant
& value
, wxString
* target
) const;
409 // Returns translation of values into string indices.
410 wxArrayInt
GetValueAsIndices() const;
412 wxArrayString m_valueAsStrings
; // Value as array of strings
414 // Cache displayed text since generating it is relatively complicated.
418 #endif // wxUSE_CHOICEDLG
420 // -----------------------------------------------------------------------
424 /** @class wxDateProperty
426 Property representing wxDateTime.
428 <b>Supported special attributes:</b>
429 - "DateFormat": Determines displayed date format.
430 - "PickerStyle": Determines window style used with wxDatePickerCtrl.
431 Default is wxDP_DEFAULT | wxDP_SHOWCENTURY.
433 class WXDLLIMPEXP_PROPGRID wxDateProperty
: public wxPGProperty
435 WX_PG_DECLARE_PROPERTY_CLASS(wxDateProperty
)
438 wxDateProperty( const wxString
& label
= wxPG_LABEL
,
439 const wxString
& name
= wxPG_LABEL
,
440 const wxDateTime
& value
= wxDateTime() );
441 virtual ~wxDateProperty();
443 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
444 virtual bool StringToValue(wxVariant
& variant
,
445 const wxString
& text
,
446 int argFlags
= 0) const;
448 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
450 void SetFormat( const wxString
& format
)
455 const wxString
& GetFormat() const
460 void SetDateValue( const wxDateTime
& dt
)
462 //m_valueDateTime = dt;
466 wxDateTime
GetDateValue() const
468 //return m_valueDateTime;
472 long GetDatePickerStyle() const
479 long m_dpStyle
; // DatePicker style
481 static wxString ms_defaultDateFormat
;
482 static wxString
DetermineDefaultDateFormat( bool showCentury
);
485 #endif // wxUSE_DATETIME
489 // -----------------------------------------------------------------------
494 // Implement an editor control that allows using wxSpinCtrl (actually, a
495 // combination of wxTextCtrl and wxSpinButton) to edit value of wxIntProperty
496 // and wxFloatProperty (and similar).
498 // Note that new editor classes needs to be registered before use. This can be
499 // accomplished using wxPGRegisterEditorClass macro, which is used for SpinCtrl
500 // in wxPropertyGridInterface::RegisterAdditionalEditors (see below).
501 // Registration can also be performed in a constructor of a property that is
502 // likely to require the editor in question.
506 #include "wx/spinbutt.h"
507 #include "wx/propgrid/editors.h"
510 // NOTE: Regardless that this class inherits from a working editor, it has
511 // all necessary methods to work independently. wxTextCtrl stuff is only
512 // used for event handling here.
513 class WXDLLIMPEXP_PROPGRID wxPGSpinCtrlEditor
: public wxPGTextCtrlEditor
515 DECLARE_DYNAMIC_CLASS(wxPGSpinCtrlEditor
)
517 virtual ~wxPGSpinCtrlEditor();
519 wxString
GetName() const;
520 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
521 wxPGProperty
* property
,
523 const wxSize
& size
) const;
524 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
525 wxWindow
* wnd
, wxEvent
& event
) const;
528 mutable wxString m_tempString
;
531 #endif // wxUSE_SPINBTN
533 // -----------------------------------------------------------------------
535 #endif // wxUSE_PROPGRID
537 #endif // _WX_PROPGRID_ADVPROPS_H_