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 // -----------------------------------------------------------------------
25 // Additional Value Type Handlers
27 bool WXDLLIMPEXP_PROPGRID
28 operator==(const wxArrayInt
& array1
, const wxArrayInt
& array2
);
31 // Additional Property Editors
34 WX_PG_DECLARE_EDITOR_WITH_DECL(SpinCtrl
,WXDLLIMPEXP_PROPGRID
)
37 #if wxUSE_DATEPICKCTRL
38 WX_PG_DECLARE_EDITOR_WITH_DECL(DatePickerCtrl
,WXDLLIMPEXP_PROPGRID
)
43 // -----------------------------------------------------------------------
46 // Web colour is currently unsupported
47 #define wxPG_COLOUR_WEB_BASE 0x10000
48 //#define wxPG_TO_WEB_COLOUR(A) ((wxUint32)(A+wxPG_COLOUR_WEB_BASE))
51 #define wxPG_COLOUR_CUSTOM 0xFFFFFF
52 #define wxPG_COLOUR_UNSPECIFIED (wxPG_COLOUR_CUSTOM+1)
54 /** @class wxColourPropertyValue
56 Because text, background and other colours tend to differ between
57 platforms, wxSystemColourProperty must be able to select between system
58 colour and, when necessary, to pick a custom one. wxSystemColourProperty
59 value makes this possible.
61 class WXDLLIMPEXP_PROPGRID wxColourPropertyValue
: public wxObject
64 /** An integer value relating to the colour, and which exact
65 meaning depends on the property with which it is used.
67 For wxSystemColourProperty:
69 Any of wxSYS_COLOUR_XXX, or any web-colour ( use wxPG_TO_WEB_COLOUR
70 macro - (currently unsupported) ), or wxPG_COLOUR_CUSTOM.
72 For custom colour properties without values array specified:
74 index or wxPG_COLOUR_CUSTOM
76 For custom colour properties <b>with</b> values array specified:
78 m_arrValues[index] or wxPG_COLOUR_CUSTOM
82 /** Resulting colour. Should be correct regardless of type. */
85 wxColourPropertyValue()
91 virtual ~wxColourPropertyValue()
95 wxColourPropertyValue( const wxColourPropertyValue
& v
)
99 m_colour
= v
.m_colour
;
102 void Init( wxUint32 type
, const wxColour
& colour
)
108 wxColourPropertyValue( const wxColour
& colour
)
111 m_type
= wxPG_COLOUR_CUSTOM
;
115 wxColourPropertyValue( wxUint32 type
)
121 wxColourPropertyValue( wxUint32 type
, const wxColour
& colour
)
124 Init( type
, colour
);
128 void operator=(const wxColourPropertyValue
& cpv
)
131 Init( cpv
.m_type
, cpv
.m_colour
);
135 DECLARE_DYNAMIC_CLASS(wxColourPropertyValue
)
141 bool WXDLLIMPEXP_PROPGRID
142 operator==(const wxColourPropertyValue
&, const wxColourPropertyValue
&);
144 DECLARE_VARIANT_OBJECT_EXPORTED(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
149 #define wxPG_EMPTY_CPV (*(NULL))
150 #define wxPG_NORMAL_FONT (*wxNORMAL_FONT)
152 #define wxPG_EMPTY_CPV wxCPV_wxPG_EMPTY
153 #define wxPG_NORMAL_FONT wxFONT_wxPG_NORMAL_FONT
157 // -----------------------------------------------------------------------
158 // Declare part of custom colour property macro pairs.
161 #include "wx/image.h"
164 // -----------------------------------------------------------------------
166 // Exclude class from wxPython bindings
169 /** @class wxFontProperty
171 Property representing wxFont.
173 class WXDLLIMPEXP_PROPGRID wxFontProperty
: public wxPGProperty
175 WX_PG_DECLARE_PROPERTY_CLASS(wxFontProperty
)
178 wxFontProperty(const wxString
& label
= wxPG_LABEL
,
179 const wxString
& name
= wxPG_LABEL
,
180 const wxFont
& value
= wxFont());
181 virtual ~wxFontProperty();
182 virtual void OnSetValue();
183 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
184 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
185 wxWindow
* primary
, wxEvent
& event
);
186 virtual wxVariant
ChildChanged( wxVariant
& thisValue
,
188 wxVariant
& childValue
) const;
189 virtual void RefreshChildren();
196 // -----------------------------------------------------------------------
199 /** If set, then match from list is searched for a custom colour. */
200 #define wxPG_PROP_TRANSLATE_CUSTOM wxPG_PROP_CLASS_SPECIFIC_1
203 /** @class wxSystemColourProperty
205 Has dropdown list of wxWidgets system colours. Value used is
206 of wxColourPropertyValue type.
208 class WXDLLIMPEXP_PROPGRID wxSystemColourProperty
: public wxEnumProperty
210 WX_PG_DECLARE_PROPERTY_CLASS(wxSystemColourProperty
)
213 wxSystemColourProperty( const wxString
& label
= wxPG_LABEL
,
214 const wxString
& name
= wxPG_LABEL
,
215 const wxColourPropertyValue
&
216 value
= wxColourPropertyValue() );
217 virtual ~wxSystemColourProperty();
219 virtual void OnSetValue();
220 virtual bool IntToValue(wxVariant
& variant
,
222 int argFlags
= 0) const;
225 Override in derived class to customize how colours are printed as
228 virtual wxString
ColourToString( const wxColour
& col
, int index
) const;
230 /** Returns index of entry that triggers colour picker dialog
233 virtual int GetCustomColourIndex() const;
235 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
236 virtual bool StringToValue( wxVariant
& variant
,
237 const wxString
& text
,
238 int argFlags
= 0 ) const;
239 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
240 wxWindow
* primary
, wxEvent
& event
);
241 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
242 virtual wxSize
OnMeasureImage( int item
) const;
243 virtual void OnCustomPaint( wxDC
& dc
,
244 const wxRect
& rect
, wxPGPaintData
& paintdata
);
246 // Helper function to show the colour dialog
247 bool QueryColourFromUser( wxVariant
& variant
) const;
249 /** Default is to use wxSystemSettings::GetColour(index). Override to use
250 custom colour tables etc.
252 virtual wxColour
GetColour( int index
) const;
254 wxColourPropertyValue
GetVal( const wxVariant
* pVariant
= NULL
) const;
258 // Special constructors to be used by derived classes.
259 wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
260 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
261 const wxColourPropertyValue
& value
);
262 wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
263 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
264 const wxColour
& value
);
266 void Init( int type
, const wxColour
& colour
);
268 // Utility functions for internal use
269 virtual wxVariant
DoTranslateVal( wxColourPropertyValue
& v
) const;
270 wxVariant
TranslateVal( wxColourPropertyValue
& v
) const
272 return DoTranslateVal( v
);
274 wxVariant
TranslateVal( int type
, const wxColour
& colour
) const
276 wxColourPropertyValue
v(type
, colour
);
277 return DoTranslateVal( v
);
280 // Translates colour to a int value, return wxNOT_FOUND if no match.
281 int ColToInd( const wxColour
& colour
) const;
284 // -----------------------------------------------------------------------
286 class WXDLLIMPEXP_PROPGRID wxColourProperty
: public wxSystemColourProperty
288 WX_PG_DECLARE_PROPERTY_CLASS(wxColourProperty
)
290 wxColourProperty( const wxString
& label
= wxPG_LABEL
,
291 const wxString
& name
= wxPG_LABEL
,
292 const wxColour
& value
= *wxWHITE
);
293 virtual ~wxColourProperty();
295 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
296 virtual wxColour
GetColour( int index
) const;
299 virtual wxVariant
DoTranslateVal( wxColourPropertyValue
& v
) const;
302 void Init( wxColour colour
);
305 // -----------------------------------------------------------------------
307 // Exclude classes from wxPython bindings
310 /** @class wxCursorProperty
312 Property representing wxCursor.
314 class WXDLLIMPEXP_PROPGRID wxCursorProperty
: public wxEnumProperty
316 DECLARE_DYNAMIC_CLASS(wxCursorProperty
)
318 wxCursorProperty( const wxString
& label
= wxPG_LABEL
,
319 const wxString
& name
= wxPG_LABEL
,
321 virtual ~wxCursorProperty();
323 virtual wxSize
OnMeasureImage( int item
) const;
324 virtual void OnCustomPaint( wxDC
& dc
,
325 const wxRect
& rect
, wxPGPaintData
& paintdata
);
328 // -----------------------------------------------------------------------
332 WXDLLIMPEXP_PROPGRID
const wxString
& wxPGGetDefaultImageWildcard();
334 /** @class wxImageFileProperty
336 Property representing image file(name).
338 class WXDLLIMPEXP_PROPGRID wxImageFileProperty
: public wxFileProperty
340 DECLARE_DYNAMIC_CLASS(wxImageFileProperty
)
343 wxImageFileProperty( const wxString
& label
= wxPG_LABEL
,
344 const wxString
& name
= wxPG_LABEL
,
345 const wxString
& value
= wxEmptyString
);
346 virtual ~wxImageFileProperty();
348 virtual void OnSetValue();
350 virtual wxSize
OnMeasureImage( int item
) const;
351 virtual void OnCustomPaint( wxDC
& dc
,
352 const wxRect
& rect
, wxPGPaintData
& paintdata
);
355 wxBitmap
* m_pBitmap
; // final thumbnail area
356 wxImage
* m_pImage
; // intermediate thumbnail area
363 /** @class wxMultiChoiceProperty
365 Property that manages a value resulting from wxMultiChoiceDialog. Value is
366 array of strings. You can get value as array of choice values/indices by
367 calling wxMultiChoiceProperty::GetValueAsArrayInt().
369 <b>Supported special attributes:</b>
370 - "UserStringMode": If > 0, allow user to manually enter strings that are
371 not in the list of choices. If this value is 1, user strings are
372 preferably placed in front of valid choices. If value is 2, then those
373 strings will placed behind valid choices.
375 class WXDLLIMPEXP_PROPGRID wxMultiChoiceProperty
: public wxPGProperty
377 WX_PG_DECLARE_PROPERTY_CLASS(wxMultiChoiceProperty
)
380 wxMultiChoiceProperty( const wxString
& label
,
381 const wxString
& name
,
382 const wxArrayString
& strings
,
383 const wxArrayString
& value
);
385 wxMultiChoiceProperty( const wxString
& label
,
386 const wxString
& name
,
387 const wxPGChoices
& choices
,
388 const wxArrayString
& value
= wxArrayString() );
390 wxMultiChoiceProperty( const wxString
& label
= wxPG_LABEL
,
391 const wxString
& name
= wxPG_LABEL
,
392 const wxArrayString
& value
= wxArrayString() );
394 virtual ~wxMultiChoiceProperty();
396 virtual void OnSetValue();
397 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
398 virtual bool StringToValue(wxVariant
& variant
,
399 const wxString
& text
,
400 int argFlags
= 0) const;
401 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
402 wxWindow
* primary
, wxEvent
& event
);
404 wxArrayInt
GetValueAsArrayInt() const
406 return m_choices
.GetValuesForStrings(m_value
.GetArrayString());
411 void GenerateValueAsString( wxVariant
& value
, wxString
* target
) const;
413 // Returns translation of values into string indices.
414 wxArrayInt
GetValueAsIndices() const;
416 wxArrayString m_valueAsStrings
; // Value as array of strings
418 // Cache displayed text since generating it is relatively complicated.
422 #endif // wxUSE_CHOICEDLG
424 // -----------------------------------------------------------------------
428 /** @class wxDateProperty
430 Property representing wxDateTime.
432 <b>Supported special attributes:</b>
433 - "DateFormat": Determines displayed date format.
434 - "PickerStyle": Determines window style used with wxDatePickerCtrl.
435 Default is wxDP_DEFAULT | wxDP_SHOWCENTURY. Using wxDP_ALLOWNONE
436 enables additional support for unspecified property value.
438 class WXDLLIMPEXP_PROPGRID wxDateProperty
: public wxPGProperty
440 WX_PG_DECLARE_PROPERTY_CLASS(wxDateProperty
)
443 wxDateProperty( const wxString
& label
= wxPG_LABEL
,
444 const wxString
& name
= wxPG_LABEL
,
445 const wxDateTime
& value
= wxDateTime() );
446 virtual ~wxDateProperty();
448 virtual void OnSetValue();
449 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
450 virtual bool StringToValue(wxVariant
& variant
,
451 const wxString
& text
,
452 int argFlags
= 0) const;
454 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
456 void SetFormat( const wxString
& format
)
461 const wxString
& GetFormat() const
466 void SetDateValue( const wxDateTime
& dt
)
468 //m_valueDateTime = dt;
472 wxDateTime
GetDateValue() const
474 //return m_valueDateTime;
478 long GetDatePickerStyle() const
485 long m_dpStyle
; // DatePicker style
487 static wxString ms_defaultDateFormat
;
488 static wxString
DetermineDefaultDateFormat( bool showCentury
);
491 #endif // wxUSE_DATETIME
495 // -----------------------------------------------------------------------
500 // Implement an editor control that allows using wxSpinCtrl (actually, a
501 // combination of wxTextCtrl and wxSpinButton) to edit value of wxIntProperty
502 // and wxFloatProperty (and similar).
504 // Note that new editor classes needs to be registered before use. This can be
505 // accomplished using wxPGRegisterEditorClass macro, which is used for SpinCtrl
506 // in wxPropertyGridInterface::RegisterAdditionalEditors (see below).
507 // Registration can also be performed in a constructor of a property that is
508 // likely to require the editor in question.
512 #include "wx/spinbutt.h"
513 #include "wx/propgrid/editors.h"
516 // NOTE: Regardless that this class inherits from a working editor, it has
517 // all necessary methods to work independently. wxTextCtrl stuff is only
518 // used for event handling here.
519 class WXDLLIMPEXP_PROPGRID wxPGSpinCtrlEditor
: public wxPGTextCtrlEditor
521 DECLARE_DYNAMIC_CLASS(wxPGSpinCtrlEditor
)
523 virtual ~wxPGSpinCtrlEditor();
525 wxString
GetName() const;
526 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
527 wxPGProperty
* property
,
529 const wxSize
& size
) const;
530 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
531 wxWindow
* wnd
, wxEvent
& event
) const;
534 mutable wxString m_tempString
;
537 #endif // wxUSE_SPINBTN
539 // -----------------------------------------------------------------------
541 #endif // wxUSE_PROPGRID
543 #endif // _WX_PROPGRID_ADVPROPS_H_