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 // -----------------------------------------------------------------------
22 // Additional Value Type Handlers
24 bool WXDLLIMPEXP_PROPGRID
25 operator==(const wxArrayInt
& array1
, const wxArrayInt
& array2
);
28 // Additional Property Editors
31 WX_PG_DECLARE_EDITOR_WITH_DECL(SpinCtrl
,WXDLLIMPEXP_PROPGRID
)
34 #if wxUSE_DATEPICKCTRL
35 WX_PG_DECLARE_EDITOR_WITH_DECL(DatePickerCtrl
,WXDLLIMPEXP_PROPGRID
)
38 // -----------------------------------------------------------------------
41 // Web colour is currently unsupported
42 #define wxPG_COLOUR_WEB_BASE 0x10000
43 //#define wxPG_TO_WEB_COLOUR(A) ((wxUint32)(A+wxPG_COLOUR_WEB_BASE))
46 #define wxPG_COLOUR_CUSTOM 0xFFFFFF
47 #define wxPG_COLOUR_UNSPECIFIED (wxPG_COLOUR_CUSTOM+1)
49 /** @class wxColourPropertyValue
51 Because text, background and other colours tend to differ between
52 platforms, wxSystemColourProperty must be able to select between system
53 colour and, when necessary, to pick a custom one. wxSystemColourProperty
54 value makes this possible.
56 class WXDLLIMPEXP_PROPGRID wxColourPropertyValue
: public wxObject
59 /** An integer value relating to the colour, and which exact
60 meaning depends on the property with which it is used.
62 For wxSystemColourProperty:
64 Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
65 macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
67 For custom colour properties without values array specified:
69 index or wxPG_COLOUR_CUSTOM
71 For custom colour properties <b>with</b> values array specified:
73 m_arrValues[index] or wxPG_COLOUR_CUSTOM
77 /** Resulting colour. Should be correct regardless of type. */
80 wxColourPropertyValue()
86 virtual ~wxColourPropertyValue()
90 wxColourPropertyValue( const wxColourPropertyValue
& v
)
94 m_colour
= v
.m_colour
;
97 void Init( wxUint32 type
, const wxColour
& colour
)
103 wxColourPropertyValue( const wxColour
& colour
)
106 m_type
= wxPG_COLOUR_CUSTOM
;
110 wxColourPropertyValue( wxUint32 type
)
116 wxColourPropertyValue( wxUint32 type
, const wxColour
& colour
)
119 Init( type
, colour
);
122 void operator=(const wxColourPropertyValue
& cpv
)
125 Init( cpv
.m_type
, cpv
.m_colour
);
129 DECLARE_DYNAMIC_CLASS(wxColourPropertyValue
)
133 bool WXDLLIMPEXP_PROPGRID
134 operator==(const wxColourPropertyValue
&, const wxColourPropertyValue
&);
136 DECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
138 // -----------------------------------------------------------------------
139 // Declare part of custom colour property macro pairs.
142 #include "wx/image.h"
145 // -----------------------------------------------------------------------
147 /** @class wxFontProperty
149 Property representing wxFont.
151 class WXDLLIMPEXP_PROPGRID wxFontProperty
: public wxPGProperty
153 WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty
)
156 wxFontProperty(const wxString
& label
= wxPG_LABEL
,
157 const wxString
& name
= wxPG_LABEL
,
158 const wxFont
& value
= wxFont());
159 virtual ~wxFontProperty();
160 virtual void OnSetValue();
161 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
162 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
163 wxWindow
* primary
, wxEvent
& event
);
164 virtual wxVariant
ChildChanged( wxVariant
& thisValue
,
166 wxVariant
& childValue
) const;
167 virtual void RefreshChildren();
172 // -----------------------------------------------------------------------
175 /** If set, then match from list is searched for a custom colour. */
176 #define wxPG_PROP_TRANSLATE_CUSTOM wxPG_PROP_CLASS_SPECIFIC_1
179 /** @class wxSystemColourProperty
181 Has dropdown list of wxWidgets system colours. Value used is
182 of wxColourPropertyValue type.
184 class WXDLLIMPEXP_PROPGRID wxSystemColourProperty
: public wxEnumProperty
186 WX_PG_DECLARE_PROPERTY_CLASS(wxSystemColourProperty
)
189 wxSystemColourProperty( const wxString
& label
= wxPG_LABEL
,
190 const wxString
& name
= wxPG_LABEL
,
191 const wxColourPropertyValue
&
192 value
= wxColourPropertyValue() );
193 virtual ~wxSystemColourProperty();
195 virtual void OnSetValue();
196 virtual bool IntToValue(wxVariant
& variant
,
198 int argFlags
= 0) const;
201 Override in derived class to customize how colours are printed as
204 virtual wxString
ColourToString( const wxColour
& col
, int index
) const;
206 /** Returns index of entry that triggers colour picker dialog
209 virtual int GetCustomColourIndex() const;
211 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
212 virtual bool StringToValue( wxVariant
& variant
,
213 const wxString
& text
,
214 int argFlags
= 0 ) const;
215 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
216 wxWindow
* primary
, wxEvent
& event
);
217 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
218 virtual wxSize
OnMeasureImage( int item
) const;
219 virtual void OnCustomPaint( wxDC
& dc
,
220 const wxRect
& rect
, wxPGPaintData
& paintdata
);
222 // Helper function to show the colour dialog
223 bool QueryColourFromUser( wxVariant
& variant
) const;
225 /** Default is to use wxSystemSettings::GetColour(index). Override to use
226 custom colour tables etc.
228 virtual wxColour
GetColour( int index
) const;
230 wxColourPropertyValue
GetVal( const wxVariant
* pVariant
= NULL
) const;
234 // Special constructors to be used by derived classes.
235 wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
236 const wxChar
* const* labels
, const long* values
, wxPGChoices
* choicesCache
,
237 const wxColourPropertyValue
& value
);
238 wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
239 const wxChar
* const* labels
, const long* values
, wxPGChoices
* choicesCache
,
240 const wxColour
& value
);
242 void Init( int type
, const wxColour
& colour
);
244 // Utility functions for internal use
245 virtual wxVariant
DoTranslateVal( wxColourPropertyValue
& v
) const;
246 wxVariant
TranslateVal( wxColourPropertyValue
& v
) const
248 return DoTranslateVal( v
);
250 wxVariant
TranslateVal( int type
, const wxColour
& colour
) const
252 wxColourPropertyValue
v(type
, colour
);
253 return DoTranslateVal( v
);
256 // Translates colour to a int value, return wxNOT_FOUND if no match.
257 int ColToInd( const wxColour
& colour
) const;
260 // -----------------------------------------------------------------------
262 class WXDLLIMPEXP_PROPGRID wxColourProperty
: public wxSystemColourProperty
264 WX_PG_DECLARE_PROPERTY_CLASS(wxColourProperty
)
266 wxColourProperty( const wxString
& label
= wxPG_LABEL
,
267 const wxString
& name
= wxPG_LABEL
,
268 const wxColour
& value
= *wxWHITE
);
269 virtual ~wxColourProperty();
271 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
272 virtual wxColour
GetColour( int index
) const;
275 virtual wxVariant
DoTranslateVal( wxColourPropertyValue
& v
) const;
278 void Init( wxColour colour
);
281 // -----------------------------------------------------------------------
283 /** @class wxCursorProperty
285 Property representing wxCursor.
287 class WXDLLIMPEXP_PROPGRID wxCursorProperty
: public wxEnumProperty
289 DECLARE_DYNAMIC_CLASS(wxCursorProperty
)
291 wxCursorProperty( const wxString
& label
= wxPG_LABEL
,
292 const wxString
& name
= wxPG_LABEL
,
294 virtual ~wxCursorProperty();
296 virtual wxSize
OnMeasureImage( int item
) const;
297 virtual void OnCustomPaint( wxDC
& dc
,
298 const wxRect
& rect
, wxPGPaintData
& paintdata
);
301 // -----------------------------------------------------------------------
305 WXDLLIMPEXP_PROPGRID
const wxString
& wxPGGetDefaultImageWildcard();
307 /** @class wxImageFileProperty
309 Property representing image file(name).
311 class WXDLLIMPEXP_PROPGRID wxImageFileProperty
: public wxFileProperty
313 DECLARE_DYNAMIC_CLASS(wxImageFileProperty
)
316 wxImageFileProperty( const wxString
& label
= wxPG_LABEL
,
317 const wxString
& name
= wxPG_LABEL
,
318 const wxString
& value
= wxEmptyString
);
319 virtual ~wxImageFileProperty();
321 virtual void OnSetValue();
323 virtual wxSize
OnMeasureImage( int item
) const;
324 virtual void OnCustomPaint( wxDC
& dc
,
325 const wxRect
& rect
, wxPGPaintData
& paintdata
);
328 wxBitmap
* m_pBitmap
; // final thumbnail area
329 wxImage
* m_pImage
; // intermediate thumbnail area
336 /** @class wxMultiChoiceProperty
338 Property that manages a value resulting from wxMultiChoiceDialog. Value is
339 array of strings. You can get value as array of choice values/indices by
340 calling wxMultiChoiceProperty::GetValueAsArrayInt().
342 <b>Supported special attributes:</b>
343 - "UserStringMode": If > 0, allow user to manually enter strings that are
344 not in the list of choices. If this value is 1, user strings are
345 preferably placed in front of valid choices. If value is 2, then those
346 strings will placed behind valid choices.
348 class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty
: public wxPGProperty
350 WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty
)
353 wxMultiChoiceProperty( const wxString
& label
,
354 const wxString
& name
,
355 const wxArrayString
& strings
,
356 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
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
370 virtual bool StringToValue(wxVariant
& variant
,
371 const wxString
& text
,
372 int argFlags
= 0) const;
373 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
374 wxWindow
* primary
, wxEvent
& event
);
376 wxArrayInt
GetValueAsArrayInt() const
378 return m_choices
.GetValuesForStrings(m_value
.GetArrayString());
383 void GenerateValueAsString( wxVariant
& value
, wxString
* target
) const;
385 // Returns translation of values into string indices.
386 wxArrayInt
GetValueAsIndices() const;
388 wxArrayString m_valueAsStrings
; // Value as array of strings
390 // Cache displayed text since generating it is relatively complicated.
394 #endif // wxUSE_CHOICEDLG
396 // -----------------------------------------------------------------------
400 /** @class wxDateProperty
402 Property representing wxDateTime.
404 <b>Supported special attributes:</b>
405 - "DateFormat": Determines displayed date format.
406 - "PickerStyle": Determines window style used with wxDatePickerCtrl.
407 Default is wxDP_DEFAULT | wxDP_SHOWCENTURY. Using wxDP_ALLOWNONE
408 enables additional support for unspecified property value.
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 void OnSetValue();
421 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
422 virtual bool StringToValue(wxVariant
& variant
,
423 const wxString
& text
,
424 int argFlags
= 0) const;
426 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
428 void SetFormat( const wxString
& format
)
433 const wxString
& GetFormat() const
438 void SetDateValue( const wxDateTime
& dt
)
440 //m_valueDateTime = dt;
444 wxDateTime
GetDateValue() const
446 //return m_valueDateTime;
450 long GetDatePickerStyle() const
457 long m_dpStyle
; // DatePicker style
459 static wxString ms_defaultDateFormat
;
460 static wxString
DetermineDefaultDateFormat( bool showCentury
);
463 #endif // wxUSE_DATETIME
465 // -----------------------------------------------------------------------
470 // Implement an editor control that allows using wxSpinCtrl (actually, a
471 // combination of wxTextCtrl and wxSpinButton) to edit value of wxIntProperty
472 // and wxFloatProperty (and similar).
474 // Note that new editor classes needs to be registered before use. This can be
475 // accomplished using wxPGRegisterEditorClass macro, which is used for SpinCtrl
476 // in wxPropertyGridInterface::RegisterAdditionalEditors (see below).
477 // Registration can also be performed in a constructor of a property that is
478 // likely to require the editor in question.
482 #include "wx/spinbutt.h"
483 #include "wx/propgrid/editors.h"
486 // NOTE: Regardless that this class inherits from a working editor, it has
487 // all necessary methods to work independently. wxTextCtrl stuff is only
488 // used for event handling here.
489 class WXDLLIMPEXP_PROPGRID wxPGSpinCtrlEditor
: public wxPGTextCtrlEditor
491 DECLARE_DYNAMIC_CLASS(wxPGSpinCtrlEditor
)
493 virtual ~wxPGSpinCtrlEditor();
495 wxString
GetName() const;
496 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
497 wxPGProperty
* property
,
499 const wxSize
& size
) const;
500 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
501 wxWindow
* wnd
, wxEvent
& event
) const;
504 mutable wxString m_tempString
;
507 #endif // wxUSE_SPINBTN
509 // -----------------------------------------------------------------------
511 #endif // wxUSE_PROPGRID
513 #endif // _WX_PROPGRID_ADVPROPS_H_