1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/advprops.h
3 // Purpose: wxPropertyGrid Advanced Properties (font, colour, etc.)
4 // Author: Jaakko Salli
7 // Copyright: (c) Jaakko Salli
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_PROPGRID_ADVPROPS_H_
12 #define _WX_PROPGRID_ADVPROPS_H_
18 #include "wx/propgrid/props.h"
20 // -----------------------------------------------------------------------
23 // Additional Value Type Handlers
25 bool WXDLLIMPEXP_PROPGRID
26 operator==(const wxArrayInt
& array1
, const wxArrayInt
& array2
);
29 // Additional Property Editors
32 WX_PG_DECLARE_EDITOR_WITH_DECL(SpinCtrl
,WXDLLIMPEXP_PROPGRID
)
35 #if wxUSE_DATEPICKCTRL
36 WX_PG_DECLARE_EDITOR_WITH_DECL(DatePickerCtrl
,WXDLLIMPEXP_PROPGRID
)
39 // -----------------------------------------------------------------------
42 // Web colour is currently unsupported
43 #define wxPG_COLOUR_WEB_BASE 0x10000
44 //#define wxPG_TO_WEB_COLOUR(A) ((wxUint32)(A+wxPG_COLOUR_WEB_BASE))
47 #define wxPG_COLOUR_CUSTOM 0xFFFFFF
48 #define wxPG_COLOUR_UNSPECIFIED (wxPG_COLOUR_CUSTOM+1)
50 /** @class wxColourPropertyValue
52 Because text, background and other colours tend to differ between
53 platforms, wxSystemColourProperty must be able to select between system
54 colour and, when necessary, to pick a custom one. wxSystemColourProperty
55 value makes this possible.
57 class WXDLLIMPEXP_PROPGRID wxColourPropertyValue
: public wxObject
60 /** An integer value relating to the colour, and which exact
61 meaning depends on the property with which it is used.
63 For wxSystemColourProperty:
65 Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
66 macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
68 For custom colour properties without values array specified:
70 index or wxPG_COLOUR_CUSTOM
72 For custom colour properties <b>with</b> values array specified:
74 m_arrValues[index] or wxPG_COLOUR_CUSTOM
78 /** Resulting colour. Should be correct regardless of type. */
81 wxColourPropertyValue()
87 virtual ~wxColourPropertyValue()
91 wxColourPropertyValue( const wxColourPropertyValue
& v
)
95 m_colour
= v
.m_colour
;
98 void Init( wxUint32 type
, const wxColour
& colour
)
104 wxColourPropertyValue( const wxColour
& colour
)
107 m_type
= wxPG_COLOUR_CUSTOM
;
111 wxColourPropertyValue( wxUint32 type
)
117 wxColourPropertyValue( wxUint32 type
, const wxColour
& colour
)
120 Init( type
, colour
);
123 void operator=(const wxColourPropertyValue
& cpv
)
126 Init( cpv
.m_type
, cpv
.m_colour
);
130 DECLARE_DYNAMIC_CLASS(wxColourPropertyValue
)
134 bool WXDLLIMPEXP_PROPGRID
135 operator==(const wxColourPropertyValue
&, const wxColourPropertyValue
&);
137 DECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
139 // -----------------------------------------------------------------------
140 // Declare part of custom colour property macro pairs.
143 #include "wx/image.h"
146 // -----------------------------------------------------------------------
148 /** @class wxFontProperty
150 Property representing wxFont.
152 class WXDLLIMPEXP_PROPGRID wxFontProperty
: public wxPGProperty
154 WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty
)
157 wxFontProperty(const wxString
& label
= wxPG_LABEL
,
158 const wxString
& name
= wxPG_LABEL
,
159 const wxFont
& value
= wxFont());
160 virtual ~wxFontProperty();
161 virtual void OnSetValue();
162 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
163 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
164 wxWindow
* primary
, wxEvent
& event
);
165 virtual wxVariant
ChildChanged( wxVariant
& thisValue
,
167 wxVariant
& childValue
) const;
168 virtual void RefreshChildren();
173 // -----------------------------------------------------------------------
176 /** If set, then match from list is searched for a custom colour. */
177 #define wxPG_PROP_TRANSLATE_CUSTOM wxPG_PROP_CLASS_SPECIFIC_1
180 /** @class wxSystemColourProperty
182 Has dropdown list of wxWidgets system colours. Value used is
183 of wxColourPropertyValue type.
185 class WXDLLIMPEXP_PROPGRID wxSystemColourProperty
: public wxEnumProperty
187 WX_PG_DECLARE_PROPERTY_CLASS(wxSystemColourProperty
)
190 wxSystemColourProperty( const wxString
& label
= wxPG_LABEL
,
191 const wxString
& name
= wxPG_LABEL
,
192 const wxColourPropertyValue
&
193 value
= wxColourPropertyValue() );
194 virtual ~wxSystemColourProperty();
196 virtual void OnSetValue();
197 virtual bool IntToValue(wxVariant
& variant
,
199 int argFlags
= 0) const;
202 Override in derived class to customize how colours are printed as
205 virtual wxString
ColourToString( const wxColour
& col
, int index
,
206 int argFlags
= 0 ) const;
208 /** Returns index of entry that triggers colour picker dialog
211 virtual int GetCustomColourIndex() const;
213 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
214 virtual bool StringToValue( wxVariant
& variant
,
215 const wxString
& text
,
216 int argFlags
= 0 ) const;
217 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
218 wxWindow
* primary
, wxEvent
& event
);
219 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
220 virtual wxSize
OnMeasureImage( int item
) const;
221 virtual void OnCustomPaint( wxDC
& dc
,
222 const wxRect
& rect
, wxPGPaintData
& paintdata
);
224 // Helper function to show the colour dialog
225 bool QueryColourFromUser( wxVariant
& variant
) const;
227 /** Default is to use wxSystemSettings::GetColour(index). Override to use
228 custom colour tables etc.
230 virtual wxColour
GetColour( int index
) const;
232 wxColourPropertyValue
GetVal( const wxVariant
* pVariant
= NULL
) const;
236 // Special constructors to be used by derived classes.
237 wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
238 const wxChar
* const* labels
, const long* values
, wxPGChoices
* choicesCache
,
239 const wxColourPropertyValue
& value
);
240 wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
241 const wxChar
* const* labels
, const long* values
, wxPGChoices
* choicesCache
,
242 const wxColour
& value
);
244 void Init( int type
, const wxColour
& colour
);
246 // Utility functions for internal use
247 virtual wxVariant
DoTranslateVal( wxColourPropertyValue
& v
) const;
248 wxVariant
TranslateVal( wxColourPropertyValue
& v
) const
250 return DoTranslateVal( v
);
252 wxVariant
TranslateVal( int type
, const wxColour
& colour
) const
254 wxColourPropertyValue
v(type
, colour
);
255 return DoTranslateVal( v
);
258 // Translates colour to a int value, return wxNOT_FOUND if no match.
259 int ColToInd( const wxColour
& colour
) const;
262 // -----------------------------------------------------------------------
264 class WXDLLIMPEXP_PROPGRID wxColourProperty
: public wxSystemColourProperty
266 WX_PG_DECLARE_PROPERTY_CLASS(wxColourProperty
)
268 wxColourProperty( const wxString
& label
= wxPG_LABEL
,
269 const wxString
& name
= wxPG_LABEL
,
270 const wxColour
& value
= *wxWHITE
);
271 virtual ~wxColourProperty();
273 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
274 virtual wxColour
GetColour( int index
) const;
277 virtual wxVariant
DoTranslateVal( wxColourPropertyValue
& v
) const;
280 void Init( wxColour colour
);
283 // -----------------------------------------------------------------------
285 /** @class wxCursorProperty
287 Property representing wxCursor.
289 class WXDLLIMPEXP_PROPGRID wxCursorProperty
: public wxEnumProperty
291 DECLARE_DYNAMIC_CLASS(wxCursorProperty
)
293 wxCursorProperty( const wxString
& label
= wxPG_LABEL
,
294 const wxString
& name
= wxPG_LABEL
,
296 virtual ~wxCursorProperty();
298 virtual wxSize
OnMeasureImage( int item
) const;
299 virtual void OnCustomPaint( wxDC
& dc
,
300 const wxRect
& rect
, wxPGPaintData
& paintdata
);
303 // -----------------------------------------------------------------------
307 WXDLLIMPEXP_PROPGRID
const wxString
& wxPGGetDefaultImageWildcard();
309 /** @class wxImageFileProperty
311 Property representing image file(name).
313 class WXDLLIMPEXP_PROPGRID wxImageFileProperty
: public wxFileProperty
315 DECLARE_DYNAMIC_CLASS(wxImageFileProperty
)
318 wxImageFileProperty( const wxString
& label
= wxPG_LABEL
,
319 const wxString
& name
= wxPG_LABEL
,
320 const wxString
& value
= wxEmptyString
);
321 virtual ~wxImageFileProperty();
323 virtual void OnSetValue();
325 virtual wxSize
OnMeasureImage( int item
) const;
326 virtual void OnCustomPaint( wxDC
& dc
,
327 const wxRect
& rect
, wxPGPaintData
& paintdata
);
330 wxBitmap
* m_pBitmap
; // final thumbnail area
331 wxImage
* m_pImage
; // intermediate thumbnail area
334 // Initialize m_pImage using the current file name.
335 void LoadImageFromFile();
342 /** @class wxMultiChoiceProperty
344 Property that manages a value resulting from wxMultiChoiceDialog. Value is
345 array of strings. You can get value as array of choice values/indices by
346 calling wxMultiChoiceProperty::GetValueAsArrayInt().
348 <b>Supported special attributes:</b>
349 - "UserStringMode": If > 0, allow user to manually enter strings that are
350 not in the list of choices. If this value is 1, user strings are
351 preferably placed in front of valid choices. If value is 2, then those
352 strings will placed behind valid choices.
354 class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty
: public wxPGProperty
356 WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty
)
359 wxMultiChoiceProperty( const wxString
& label
,
360 const wxString
& name
,
361 const wxArrayString
& strings
,
362 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
ValueToString( wxVariant
& value
, int argFlags
= 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( wxVariant
& value
, wxString
* target
) const;
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. Using wxDP_ALLOWNONE
414 enables additional support for unspecified property value.
416 class WXDLLIMPEXP_PROPGRID wxDateProperty
: public wxPGProperty
418 WX_PG_DECLARE_PROPERTY_CLASS(wxDateProperty
)
421 wxDateProperty( const wxString
& label
= wxPG_LABEL
,
422 const wxString
& name
= wxPG_LABEL
,
423 const wxDateTime
& value
= wxDateTime() );
424 virtual ~wxDateProperty();
426 virtual void OnSetValue();
427 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
428 virtual bool StringToValue(wxVariant
& variant
,
429 const wxString
& text
,
430 int argFlags
= 0) const;
432 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
434 void SetFormat( const wxString
& format
)
439 const wxString
& GetFormat() const
444 void SetDateValue( const wxDateTime
& dt
)
446 //m_valueDateTime = dt;
450 wxDateTime
GetDateValue() const
452 //return m_valueDateTime;
456 long GetDatePickerStyle() const
463 long m_dpStyle
; // DatePicker style
465 static wxString ms_defaultDateFormat
;
466 static wxString
DetermineDefaultDateFormat( bool showCentury
);
469 #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 DECLARE_DYNAMIC_CLASS(wxPGSpinCtrlEditor
)
499 virtual ~wxPGSpinCtrlEditor();
501 wxString
GetName() const;
502 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
503 wxPGProperty
* property
,
505 const wxSize
& size
) const;
506 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
507 wxWindow
* wnd
, wxEvent
& event
) const;
510 mutable wxString m_tempString
;
513 #endif // wxUSE_SPINBTN
515 // -----------------------------------------------------------------------
517 #endif // wxUSE_PROPGRID
519 #endif // _WX_PROPGRID_ADVPROPS_H_