1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/props.h
3 // Purpose: wxPropertyGrid Property Classes
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROPGRID_PROPS_H_
13 #define _WX_PROPGRID_PROPS_H_
17 // -----------------------------------------------------------------------
19 class wxArrayEditorDialog
;
21 #include "wx/propgrid/editors.h"
23 // -----------------------------------------------------------------------
26 // Additional property class declaration helper macros
30 // Property class implementation helper macros.
33 #define WX_PG_DECLARE_BASIC_TYPE_METHODS() \
34 virtual wxString GetValueAsString( int argFlags = 0 ) const; \
35 virtual bool StringToValue( wxVariant& variant, \
36 const wxString& text, \
37 int argFlags = 0 ) const;
39 #define WX_PG_DECLARE_CHOICE_METHODS() \
40 virtual bool IntToValue( wxVariant& variant, \
41 int number, int argFlags = 0 ) const; \
43 #define WX_PG_DECLARE_EVENT_METHODS() \
44 virtual bool OnEvent( wxPropertyGrid* propgrid, \
45 wxWindow* primary, wxEvent& event );
47 #define WX_PG_DECLARE_PARENTAL_METHODS() \
48 virtual void ChildChanged( wxVariant& thisValue, \
49 int childIndex, wxVariant& childValue ) const; \
50 virtual void RefreshChildren();
52 #define WX_PG_DECLARE_CUSTOM_PAINT_METHODS() \
53 virtual wxSize OnMeasureImage( int item ) const; \
54 virtual void OnCustomPaint( wxDC& dc, \
55 const wxRect& rect, wxPGPaintData& paintdata );
57 #define WX_PG_DECLARE_ATTRIBUTE_METHODS() \
58 virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
60 #define WX_PG_DECLARE_VALIDATOR_METHODS() \
61 virtual wxValidator* DoGetValidator() const;
63 // Adds constructor function as well.
64 #define WX_PG_IMPLEMENT_PROPERTY_CLASS2(NAME,CLASSNAME,\
65 UPCLASS,T,T_AS_ARG,EDITOR) \
66 IMPLEMENT_DYNAMIC_CLASS(NAME, UPCLASS) \
67 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(NAME,T,EDITOR)
70 #define WX_PG_IMPLEMENT_PROPERTY_CLASS(NAME,UPNAME,T,T_AS_ARG,EDITOR) \
71 WX_PG_IMPLEMENT_PROPERTY_CLASS2(NAME,NAME,UPNAME,T,T_AS_ARG,EDITOR)
73 #define WX_PG_DECLARE_DERIVED_PROPERTY_CLASS(CLASSNAME) \
74 DECLARE_DYNAMIC_CLASS(CLASSNAME)
76 // Derived property class is one that inherits from an existing working property
77 // class, but assumes same value and editor type.
78 #define WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(NAME,UPNAME,T_AS_ARG) \
79 IMPLEMENT_DYNAMIC_CLASS(NAME, UPNAME)
81 // -----------------------------------------------------------------------
83 #define wxPG_NO_ESCAPE wxPG_PROP_NO_ESCAPE // No escape sequences
84 #define wxPG_ESCAPE 0 // Escape sequences
86 #define WX_PG_DECLARE_STRING_PROPERTY_WITH_DECL(NAME, DECL) \
87 DECL NAME : public wxLongStringProperty \
89 WX_PG_DECLARE_DERIVED_PROPERTY_CLASS(NAME) \
91 NAME( const wxString& name = wxPG_LABEL, \
92 const wxString& label = wxPG_LABEL, \
93 const wxString& value = wxEmptyString); \
95 virtual bool OnButtonClick( wxPropertyGrid* propgrid, wxString& value ); \
96 WX_PG_DECLARE_VALIDATOR_METHODS() \
99 #define WX_PG_DECLARE_STRING_PROPERTY(NAME) \
100 WX_PG_DECLARE_STRING_PROPERTY_WITH_DECL(NAME, class) \
102 #define WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(NAME, FLAGS) \
103 WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(NAME,wxLongStringProperty,\
105 NAME::NAME( const wxString& name, \
106 const wxString& label, \
107 const wxString& value ) \
108 : wxLongStringProperty(name,label,value) \
114 #define WX_PG_IMPLEMENT_STRING_PROPERTY(NAME, FLAGS) \
115 WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(NAME,FLAGS) \
116 wxValidator* NAME::DoGetValidator () const \
117 { return (wxValidator*) NULL; }
119 // -----------------------------------------------------------------------
121 #define WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY_WITH_DECL(CLASSNAME,DECL) \
122 DECL CLASSNAME : public wxFlagsProperty \
124 WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
126 CLASSNAME( const wxString& label = wxPG_LABEL, \
127 const wxString& name = wxPG_LABEL, \
129 virtual ~CLASSNAME(); \
132 #define WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY(CLASSNAME) \
133 WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY_WITH_DECL(CLASSNAME, class)
135 // This will create interface for wxFlagsProperty derived class
137 #define WX_PG_IMPLEMENT_CUSTOM_FLAGS_PROPERTY(CLASSNAME,LABELS,VALUES,DEFVAL) \
138 WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME,wxFlagsProperty,long_##CLASSNAME,\
140 CLASSNAME::CLASSNAME( const wxString& label, \
141 const wxString& name, \
143 : wxFlagsProperty(label,name,LABELS,VALUES,value!=-1?value:DEFVAL) \
145 m_flags |= wxPG_PROP_STATIC_CHOICES; \
147 CLASSNAME::~CLASSNAME() { }
150 // -----------------------------------------------------------------------
152 #define WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY_WITH_DECL(CLASSNAME, DECL) \
153 class CLASSNAME : public wxEnumProperty \
155 WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
157 CLASSNAME( const wxString& label = wxPG_LABEL, \
158 const wxString& name = wxPG_LABEL, \
160 virtual ~CLASSNAME(); \
163 #define WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY(CLASSNAME) \
164 WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY_WITH_DECL(CLASSNAME, class)
166 #define WX_PG_IMPLEMENT_CUSTOM_ENUM_PROPERTY(CLASSNAME,LABELS,VALUES,DEFVAL) \
167 WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME, wxEnumProperty, long_##CLASSNAME, \
169 CLASSNAME::CLASSNAME( const wxString& label, const wxString& name, int value ) \
170 : wxEnumProperty(label,name,LABELS,VALUES,value!=-1?value:DEFVAL) \
172 m_flags |= wxPG_PROP_STATIC_CHOICES; \
174 CLASSNAME::~CLASSNAME() { }
177 // -----------------------------------------------------------------------
179 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, DECL) \
180 DECL CLASSNAME : public wxSystemColourProperty \
182 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
184 CLASSNAME( const wxString& label = wxPG_LABEL, \
185 const wxString& name = wxPG_LABEL, \
186 const wxColourPropertyValue& value = wxColourPropertyValue() ); \
187 virtual ~CLASSNAME(); \
188 virtual wxColour GetColour( int index ) const; \
191 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY(CLASSNAME) \
192 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, class)
194 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY(CLASSNAME,\
195 LABELS,VALUES,COLOURS) \
196 static wxPGChoices gs_##CLASSNAME##_choicesCache; \
197 WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(CLASSNAME, wxSystemColourProperty, \
198 const wxColourPropertyValue&) \
199 CLASSNAME::CLASSNAME( const wxString& label, const wxString& name, \
200 const wxColourPropertyValue& value ) \
201 : wxSystemColourProperty(label, name, LABELS, VALUES, \
202 &gs_##CLASSNAME##_choicesCache, value ) \
204 m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \
206 CLASSNAME::~CLASSNAME () { } \
207 wxColour CLASSNAME::GetColour ( int index ) const \
209 if ( !m_choices.HasValue(index) ) \
211 wxASSERT( index < (int)m_choices.GetCount() ); \
212 return COLOURS[index]; \
214 return COLOURS[m_choices.GetValue(index)]; \
217 // -----------------------------------------------------------------------
219 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME,\
221 DECL CLASSNAME : public wxSystemColourProperty \
223 WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
225 CLASSNAME( const wxString& label = wxPG_LABEL, \
226 const wxString& name = wxPG_LABEL, \
227 const wxColour& value = wxColour() ); \
228 virtual ~CLASSNAME(); \
229 virtual wxString GetValueAsString( int argFlags ) const; \
230 virtual wxColour GetColour( int index ) const; \
231 virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const; \
232 void Init( wxColour colour ); \
235 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME) \
236 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME, class)
238 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \
243 static wxPGChoices gs_##CLASSNAME##_choicesCache; \
244 WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME, wxSystemColourProperty, \
245 wxColour, const wxColour&,EDITOR) \
246 CLASSNAME::CLASSNAME( const wxString& label, \
247 const wxString& name, \
248 const wxColour& value ) \
249 : wxSystemColourProperty(label, name, LABELS, VALUES, \
250 &gs_##CLASSNAME##_choicesCache, value ) \
256 m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \
258 CLASSNAME::~CLASSNAME() { } \
259 void CLASSNAME::Init( wxColour colour ) \
261 if ( !colour.Ok() ) \
266 int ind = ColToInd(colour); \
268 ind = m_choices.GetCount() - 1; \
271 wxString CLASSNAME::GetValueAsString( int argFlags ) const \
273 const wxPGEditor* editor = GetEditorClass(); \
274 if ( editor != wxPG_EDITOR(Choice) && \
275 editor != wxPG_EDITOR(ChoiceAndButton) && \
276 editor != wxPG_EDITOR(ComboBox) ) \
277 argFlags |= wxPG_PROPERTY_SPECIFIC; \
278 return wxSystemColourProperty::GetValueAsString(argFlags); \
280 wxColour CLASSNAME::GetColour( int index ) const \
282 if ( !m_choices.HasValue(index) ) \
284 wxASSERT( index < (int)GetItemCount() ); \
285 return COLOURS[index]; \
287 return COLOURS[m_choices.GetValue(index)]; \
289 wxVariant CLASSNAME::DoTranslateVal( wxColourPropertyValue& v ) const \
292 variant << v.m_colour; \
297 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME, \
301 WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \
307 // -----------------------------------------------------------------------
310 // These macros help creating DoGetValidator
311 #define WX_PG_DOGETVALIDATOR_ENTRY() \
312 static wxValidator* s_ptr = (wxValidator*) NULL; \
313 if ( s_ptr ) return s_ptr;
315 // Common function exit
316 #define WX_PG_DOGETVALIDATOR_EXIT(VALIDATOR) \
318 wxPGGlobalVars->m_arrValidators.Add( (void*) VALIDATOR ); \
321 // -----------------------------------------------------------------------
325 /** @class wxPGInDialogValidator
327 Creates and manages a temporary wxTextCtrl for validation purposes.
328 Uses wxPropertyGrid's current editor, if available.
330 class WXDLLIMPEXP_PROPGRID wxPGInDialogValidator
333 wxPGInDialogValidator()
338 ~wxPGInDialogValidator()
341 m_textCtrl
->Destroy();
344 bool DoValidate( wxPropertyGrid
* propGrid
,
345 wxValidator
* validator
,
346 const wxString
& value
);
349 wxTextCtrl
* m_textCtrl
;
355 // -----------------------------------------------------------------------
357 // -----------------------------------------------------------------------
359 #define wxPG_PROP_PASSWORD wxPG_PROP_CLASS_SPECIFIC_2
361 /** @class wxStringProperty
363 Basic property with string value.
365 <b>Supported special attributes:</b>
366 - "Password": set to 1 inorder to enable wxTE_PASSWORD on the editor.
369 - If value "<composed>" is set, then actual value is formed (or composed)
370 from values of child properties.
372 class WXDLLIMPEXP_PROPGRID wxStringProperty
: public wxPGProperty
374 WX_PG_DECLARE_PROPERTY_CLASS(wxStringProperty
)
376 wxStringProperty( const wxString
& label
= wxPG_LABEL
,
377 const wxString
& name
= wxPG_LABEL
,
378 const wxString
& value
= wxEmptyString
);
379 virtual ~wxStringProperty();
381 WX_PG_DECLARE_BASIC_TYPE_METHODS()
382 WX_PG_DECLARE_ATTRIBUTE_METHODS()
384 /** This is updated so "<composed>" special value can be handled.
386 virtual void OnSetValue();
391 // -----------------------------------------------------------------------
394 /** Constants used with DoValidation() methods.
398 /** Instead of modifying the value, show an error message.
400 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
= 0,
402 /** Modify value, but stick with the limitations.
404 wxPG_PROPERTY_VALIDATION_SATURATE
= 1,
406 /** Modify value, wrap around on overflow.
408 wxPG_PROPERTY_VALIDATION_WRAP
= 2
412 // -----------------------------------------------------------------------
414 /** @class wxIntProperty
416 Basic property with integer value.
418 Seamlessly supports 64-bit integer (wxLongLong) on overflow.
420 <b>Example how to use seamless 64-bit integer support</b>
425 wxLongLong_t value = pg->GetPropertyValueAsLongLong();
432 wxVariant variant = property->GetValue();
433 if ( variant.GetType() == "wxLongLong" )
434 value = wxLongLongFromVariant(variant);
436 value = variant.GetLong();
442 pg->SetPropertyValue(longLongVal);
448 property->SetValue(WXVARIANT(longLongVal));
452 <b>Supported special attributes:</b>
453 - "Min", "Max": Specify acceptable value range.
455 class WXDLLIMPEXP_PROPGRID wxIntProperty
: public wxPGProperty
457 WX_PG_DECLARE_PROPERTY_CLASS(wxIntProperty
)
459 wxIntProperty( const wxString
& label
= wxPG_LABEL
,
460 const wxString
& name
= wxPG_LABEL
,
462 virtual ~wxIntProperty();
464 wxIntProperty( const wxString
& label
,
465 const wxString
& name
,
466 const wxLongLong
& value
);
467 WX_PG_DECLARE_BASIC_TYPE_METHODS()
468 virtual bool ValidateValue( wxVariant
& value
,
469 wxPGValidationInfo
& validationInfo
) const;
470 virtual bool IntToValue( wxVariant
& variant
,
472 int argFlags
= 0 ) const;
473 static wxValidator
* GetClassValidator();
474 virtual wxValidator
* DoGetValidator() const;
476 /** Validation helper.
478 static bool DoValidation( const wxPGProperty
* property
,
480 wxPGValidationInfo
* pValidationInfo
,
482 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
487 // -----------------------------------------------------------------------
489 /** @class wxUIntProperty
491 Basic property with unsigned integer value.
492 Seamlessly supports 64-bit integer (wxULongLong) on overflow.
494 <b>Supported special attributes:</b>
495 - "Min", "Max": Specify acceptable value range.
496 - "Base": Define base. Valid constants are wxPG_BASE_OCT, wxPG_BASE_DEC,
497 wxPG_BASE_HEX and wxPG_BASE_HEXL (lowercase characters). Arbitrary bases
498 are <b>not</b> supported.
499 - "Prefix": Possible values are wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and
500 wxPG_PREFIX_DOLLAR_SIGN. Only wxPG_PREFIX_NONE works with Decimal and Octal
504 - For example how to use seamless 64-bit integer support, see wxIntProperty
505 documentation (just use wxULongLong instead of wxLongLong).
507 class WXDLLIMPEXP_PROPGRID wxUIntProperty
: public wxPGProperty
509 WX_PG_DECLARE_PROPERTY_CLASS(wxUIntProperty
)
511 wxUIntProperty( const wxString
& label
= wxPG_LABEL
,
512 const wxString
& name
= wxPG_LABEL
,
513 unsigned long value
= 0 );
514 virtual ~wxUIntProperty();
515 wxUIntProperty( const wxString
& label
,
516 const wxString
& name
,
517 const wxULongLong
& value
);
518 WX_PG_DECLARE_BASIC_TYPE_METHODS()
519 WX_PG_DECLARE_ATTRIBUTE_METHODS()
520 virtual bool ValidateValue( wxVariant
& value
,
521 wxPGValidationInfo
& validationInfo
) const;
522 virtual bool IntToValue( wxVariant
& variant
,
524 int argFlags
= 0 ) const;
527 wxByte m_realBase
; // translated to 8,16,etc.
533 // -----------------------------------------------------------------------
535 /** @class wxFloatProperty
537 Basic property with double-precision floating point value.
539 <b>Supported special attributes:</b>
540 - "Precision": Sets the (max) precision used when floating point value is
541 rendered as text. The default -1 means infinite precision.
543 class WXDLLIMPEXP_PROPGRID wxFloatProperty
: public wxPGProperty
545 WX_PG_DECLARE_PROPERTY_CLASS(wxFloatProperty
)
547 wxFloatProperty( const wxString
& label
= wxPG_LABEL
,
548 const wxString
& name
= wxPG_LABEL
,
549 double value
= 0.0 );
550 virtual ~wxFloatProperty();
552 WX_PG_DECLARE_BASIC_TYPE_METHODS()
553 WX_PG_DECLARE_ATTRIBUTE_METHODS()
554 virtual bool ValidateValue( wxVariant
& value
,
555 wxPGValidationInfo
& validationInfo
) const;
557 /** Validation helper.
559 static bool DoValidation( const wxPGProperty
* property
,
561 wxPGValidationInfo
* pValidationInfo
,
563 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
567 virtual wxValidator
* DoGetValidator () const;
570 // -----------------------------------------------------------------------
572 // Exclude class from wxPython bindings
575 /** @class wxBoolProperty
577 Basic property with boolean value.
579 <b>Supported special attributes:</b>
580 - "UseCheckbox": Set to 1 to use check box editor instead of combo box.
581 - "UseDClickCycling": Set to 1 to cycle combo box instead showing the list.
583 class WXDLLIMPEXP_PROPGRID wxBoolProperty
: public wxPGProperty
585 WX_PG_DECLARE_PROPERTY_CLASS(wxBoolProperty
)
587 wxBoolProperty( const wxString
& label
= wxPG_LABEL
,
588 const wxString
& name
= wxPG_LABEL
,
589 bool value
= false );
590 virtual ~wxBoolProperty();
592 WX_PG_DECLARE_BASIC_TYPE_METHODS()
593 WX_PG_DECLARE_CHOICE_METHODS()
594 WX_PG_DECLARE_ATTRIBUTE_METHODS()
599 // -----------------------------------------------------------------------
601 /** @class wxBaseEnumProperty
603 Derive dynamic custom properties with choices from this class.
606 - Updating private index is important. You can do this either by calling
607 SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue
608 be called (by not implementing it, or by calling super class function in
609 it) -OR- you can just call SetIndex in OnSetValue.
611 class WXDLLIMPEXP_PROPGRID wxBaseEnumProperty
: public wxPGProperty
614 wxBaseEnumProperty( const wxString
& label
= wxPG_LABEL
,
615 const wxString
& name
= wxPG_LABEL
);
617 virtual void OnSetValue();
618 virtual wxString
GetValueAsString( int argFlags
) const;
619 virtual bool StringToValue( wxVariant
& variant
,
620 const wxString
& text
,
621 int argFlags
= 0 ) const;
622 virtual bool ValidateValue( wxVariant
& value
,
623 wxPGValidationInfo
& validationInfo
) const;
625 // If wxPG_FULL_VALUE is not set in flags, then the value is interpreted
626 // as index to choices list. Otherwise, it is actual value.
627 virtual bool IntToValue( wxVariant
& variant
,
629 int argFlags
= 0 ) const;
632 // Additional virtuals
634 // This must be overridden to have non-index based value
635 virtual int GetIndexForValue( int value
) const;
637 // This returns string and value for index
638 // Returns NULL if beyond last item
639 // pvalue is never NULL - always set it.
640 virtual const wxString
* GetEntry( size_t index
, int* pvalue
) const = 0;
642 // GetChoiceSelection needs to overridden since m_index is
643 // the true index, and various property classes derived from
644 // this take advantage of it.
645 virtual int GetChoiceSelection() const { return m_index
; }
647 int GetValueForIndex( size_t index
) const
650 GetEntry( index
, &v
);
656 int GetIndex() const;
657 void SetIndex( int index
);
659 bool ValueFromString_( wxVariant
& value
,
660 const wxString
& text
,
661 int argFlags
) const;
662 bool ValueFromInt_( wxVariant
& value
, int intVal
, int argFlags
) const;
664 static void ResetNextIndex() { ms_nextIndex
= -2; }
667 // This is private so that classes are guaranteed to use GetIndex
668 // for up-to-date index value.
671 // Relies on ValidateValue being called always before OnSetValue
672 static int ms_nextIndex
;
675 // -----------------------------------------------------------------------
677 // If set, then selection of choices is static and should not be
678 // changed (i.e. returns NULL in GetPropertyChoices).
679 #define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1
681 /** @class wxEnumProperty
683 You can derive custom properties with choices from this class. See
684 wxBaseEnumProperty for remarks.
686 class WXDLLIMPEXP_PROPGRID wxEnumProperty
: public wxBaseEnumProperty
688 WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty
)
692 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
693 const wxString
& name
= wxPG_LABEL
,
694 const wxChar
** labels
= NULL
,
695 const long* values
= NULL
,
697 wxEnumProperty( const wxString
& label
,
698 const wxString
& name
,
699 wxPGChoices
& choices
,
702 // Special constructor for caching choices (used by derived class)
703 wxEnumProperty( const wxString
& label
,
704 const wxString
& name
,
705 const wxChar
** labels
,
707 wxPGChoices
* choicesCache
,
710 wxEnumProperty( const wxString
& label
,
711 const wxString
& name
,
712 const wxArrayString
& labels
,
713 const wxArrayInt
& values
= wxArrayInt(),
716 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
717 const wxString
& name
= wxPG_LABEL
,
718 const wxArrayString
& labels
= wxArrayString(),
719 const wxArrayInt
& values
= wxArrayInt(),
723 virtual ~wxEnumProperty();
725 virtual int GetIndexForValue( int value
) const;
726 virtual const wxString
* GetEntry( size_t index
, int* pvalue
) const;
728 size_t GetItemCount() const { return m_choices
.GetCount(); }
729 const wxPGChoices
& GetChoices() const { return m_choices
; }
732 // -----------------------------------------------------------------------
734 /** @class wxEditEnumProperty
736 wxEnumProperty with wxString value and writable combo box editor.
739 Uses int value, similar to wxEnumProperty, unless text entered by user is
740 is not in choices (in which case string value is used).
742 class WXDLLIMPEXP_PROPGRID wxEditEnumProperty
: public wxEnumProperty
744 WX_PG_DECLARE_PROPERTY_CLASS(wxEditEnumProperty
)
747 wxEditEnumProperty( const wxString
& label
,
748 const wxString
& name
,
749 const wxChar
** labels
,
751 const wxString
& value
);
752 wxEditEnumProperty( const wxString
& label
= wxPG_LABEL
,
753 const wxString
& name
= wxPG_LABEL
,
754 const wxArrayString
& labels
= wxArrayString(),
755 const wxArrayInt
& values
= wxArrayInt(),
756 const wxString
& value
= wxEmptyString
);
757 wxEditEnumProperty( const wxString
& label
,
758 const wxString
& name
,
759 wxPGChoices
& choices
,
760 const wxString
& value
= wxEmptyString
);
762 // Special constructor for caching choices (used by derived class)
763 wxEditEnumProperty( const wxString
& label
,
764 const wxString
& name
,
765 const wxChar
** labels
,
767 wxPGChoices
* choicesCache
,
768 const wxString
& value
);
770 virtual ~wxEditEnumProperty();
775 // -----------------------------------------------------------------------
777 /** @class wxFlagsProperty
779 Represents a bit set that fits in a long integer. wxBoolProperty
780 sub-properties are created for editing individual bits. Textctrl is created
781 to manually edit the flags as a text; a continous sequence of spaces,
782 commas and semicolons is considered as a flag id separator.
783 <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
784 you will need to use SetPropertyChoices - otherwise they will not get
787 class WXDLLIMPEXP_PROPGRID wxFlagsProperty
: public wxPGProperty
789 WX_PG_DECLARE_PROPERTY_CLASS(wxFlagsProperty
)
793 wxFlagsProperty( const wxString
& label
,
794 const wxString
& name
,
795 const wxChar
** labels
,
796 const long* values
= NULL
,
798 wxFlagsProperty( const wxString
& label
,
799 const wxString
& name
,
800 wxPGChoices
& choices
,
803 wxFlagsProperty( const wxString
& label
= wxPG_LABEL
,
804 const wxString
& name
= wxPG_LABEL
,
805 const wxArrayString
& labels
= wxArrayString(),
806 const wxArrayInt
& values
= wxArrayInt(),
808 virtual ~wxFlagsProperty ();
810 virtual void OnSetValue();
811 virtual wxString
GetValueAsString( int argFlags
) const;
812 virtual bool StringToValue( wxVariant
& variant
,
813 const wxString
& text
,
815 virtual void ChildChanged( wxVariant
& thisValue
,
817 wxVariant
& childValue
) const;
818 virtual void RefreshChildren();
820 // GetChoiceSelection needs to overridden since m_choices is
821 // used and value is integer, but it is not index.
822 virtual int GetChoiceSelection() const { return wxNOT_FOUND
; }
825 size_t GetItemCount() const { return m_choices
.GetCount(); }
826 const wxString
& GetLabel( size_t ind
) const
827 { return m_choices
.GetLabel(ind
); }
830 // Used to detect if choices have been changed
831 wxPGChoicesData
* m_oldChoicesData
;
833 // Needed to properly mark changed sub-properties
836 // Converts string id to a relevant bit.
837 long IdToBit( const wxString
& id
) const;
839 // Creates children and sets value.
843 // -----------------------------------------------------------------------
845 /** @class wxPGFileDialogAdapter
848 class WXDLLIMPEXP_PROPGRID
849 wxPGFileDialogAdapter
: public wxPGEditorDialogAdapter
852 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
853 wxPGProperty
* property
);
856 // -----------------------------------------------------------------------
858 #include "wx/filename.h"
860 // Indicates first bit useable by derived properties.
861 #define wxPG_PROP_SHOW_FULL_FILENAME wxPG_PROP_CLASS_SPECIFIC_1
863 /** @class wxFileProperty
865 Like wxLongStringProperty, but the button triggers file selector instead.
867 <b>Supported special attributes:</b>
868 - "Wildcard": Sets wildcard (see wxFileDialog for format details), "All
869 files..." is default.
870 - "ShowFullPath": Default 1. When 0, only the file name is shown (i.e. drive
871 and directory are hidden).
872 - "ShowRelativePath": If set, then the filename is shown relative to the
874 - "InitialPath": Sets the initial path of where to look for files.
875 - "DialogTitle": Sets a specific title for the dir dialog.
877 class WXDLLIMPEXP_PROPGRID wxFileProperty
: public wxPGProperty
879 friend class wxPGFileDialogAdapter
;
880 WX_PG_DECLARE_PROPERTY_CLASS(wxFileProperty
)
883 wxFileProperty( const wxString
& label
= wxPG_LABEL
,
884 const wxString
& name
= wxPG_LABEL
,
885 const wxString
& value
= wxEmptyString
);
886 virtual ~wxFileProperty ();
888 virtual void OnSetValue();
889 virtual wxString
GetValueAsString( int argFlags
) const;
890 virtual bool StringToValue( wxVariant
& variant
,
891 const wxString
& text
,
892 int argFlags
= 0 ) const;
893 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
895 WX_PG_DECLARE_ATTRIBUTE_METHODS()
897 static wxValidator
* GetClassValidator();
898 virtual wxValidator
* DoGetValidator() const;
902 wxString m_basePath
; // If set, then show path relative to it
903 wxString m_initialPath
; // If set, start the file dialog here
904 wxString m_dlgTitle
; // If set, used as title for file dialog
905 wxFileName m_filename
; // used as primary storage
906 int m_indFilter
; // index to the selected filter
909 // -----------------------------------------------------------------------
911 #define wxPG_PROP_NO_ESCAPE wxPG_PROP_CLASS_SPECIFIC_1
914 /** @class wxPGLongStringDialogAdapter
917 class WXDLLIMPEXP_PROPGRID
918 wxPGLongStringDialogAdapter
: public wxPGEditorDialogAdapter
921 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
922 wxPGProperty
* property
);
926 /** @class wxLongStringProperty
928 Like wxStringProperty, but has a button that triggers a small text
931 class WXDLLIMPEXP_PROPGRID wxLongStringProperty
: public wxPGProperty
933 WX_PG_DECLARE_PROPERTY_CLASS(wxLongStringProperty
)
936 wxLongStringProperty( const wxString
& label
= wxPG_LABEL
,
937 const wxString
& name
= wxPG_LABEL
,
938 const wxString
& value
= wxEmptyString
);
939 virtual ~wxLongStringProperty();
941 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
942 virtual bool StringToValue( wxVariant
& variant
,
943 const wxString
& text
,
944 int argFlags
= 0 ) const;
946 WX_PG_DECLARE_EVENT_METHODS()
948 // Shows string editor dialog. Value to be edited should be read from
949 // value, and if dialog is not cancelled, it should be stored back and true
950 // should be returned if that was the case.
951 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
, wxString
& value
);
953 static bool DisplayEditorDialog( wxPGProperty
* prop
,
954 wxPropertyGrid
* propGrid
,
960 // -----------------------------------------------------------------------
963 // Exclude class from wxPython bindings
966 /** @class wxDirProperty
968 Like wxLongStringProperty, but the button triggers dir selector instead.
970 <b>Supported special attributes:</b>
971 - "DialogMessage": Sets specific message in the dir selector.
973 class WXDLLIMPEXP_PROPGRID wxDirProperty
: public wxLongStringProperty
976 DECLARE_DYNAMIC_CLASS(wxDirProperty
)
979 wxDirProperty( const wxString
& name
= wxPG_LABEL
,
980 const wxString
& label
= wxPG_LABEL
,
981 const wxString
& value
= wxEmptyString
);
982 virtual ~wxDirProperty();
984 WX_PG_DECLARE_ATTRIBUTE_METHODS()
985 WX_PG_DECLARE_VALIDATOR_METHODS()
987 virtual bool OnButtonClick ( wxPropertyGrid
* propGrid
, wxString
& value
);
990 wxString m_dlgMessage
;
995 // -----------------------------------------------------------------------
997 // wxBoolProperty specific flags
998 #define wxPG_PROP_USE_CHECKBOX wxPG_PROP_CLASS_SPECIFIC_1
999 // DCC = Double Click Cycles
1000 #define wxPG_PROP_USE_DCC wxPG_PROP_CLASS_SPECIFIC_2
1003 // -----------------------------------------------------------------------
1005 /** @class wxArrayStringProperty
1007 Property that manages a list of strings.
1009 class WXDLLIMPEXP_PROPGRID wxArrayStringProperty
: public wxPGProperty
1011 WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty
)
1014 wxArrayStringProperty( const wxString
& label
= wxPG_LABEL
,
1015 const wxString
& name
= wxPG_LABEL
,
1016 const wxArrayString
& value
= wxArrayString() );
1017 virtual ~wxArrayStringProperty();
1019 virtual void OnSetValue();
1020 WX_PG_DECLARE_BASIC_TYPE_METHODS()
1021 WX_PG_DECLARE_EVENT_METHODS()
1023 virtual void GenerateValueAsString();
1025 // Shows string editor dialog. Value to be edited should be read from
1026 // value, and if dialog is not cancelled, it should be stored back and true
1027 // should be returned if that was the case.
1028 virtual bool OnCustomStringEdit( wxWindow
* parent
, wxString
& value
);
1031 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
,
1033 const wxChar
* cbt
);
1036 // Creates wxArrayEditorDialog for string editing. Called in OnButtonClick.
1037 virtual wxArrayEditorDialog
* CreateEditorDialog();
1041 wxString m_display
; // Cache for displayed text.
1044 // -----------------------------------------------------------------------
1046 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, \
1048 DECL PROPNAME : public wxArrayStringProperty \
1050 WX_PG_DECLARE_PROPERTY_CLASS(PROPNAME) \
1052 PROPNAME( const wxString& label = wxPG_LABEL, \
1053 const wxString& name = wxPG_LABEL, \
1054 const wxArrayString& value = wxArrayString() ); \
1056 virtual void GenerateValueAsString(); \
1057 virtual bool StringToValue( wxVariant& value, \
1058 const wxString& text, int = 0 ) const; \
1059 virtual bool OnEvent( wxPropertyGrid* propgrid, \
1060 wxWindow* primary, wxEvent& event ); \
1061 virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \
1062 WX_PG_DECLARE_VALIDATOR_METHODS() \
1065 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM) \
1066 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM, class)
1068 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
1071 WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME, wxArrayStringProperty, \
1072 wxArrayString, const wxArrayString&, \
1073 TextCtrlAndButton) \
1074 PROPNAME::PROPNAME( const wxString& label, \
1075 const wxString& name, \
1076 const wxArrayString& value ) \
1077 : wxArrayStringProperty(label,name,value) \
1079 PROPNAME::GenerateValueAsString(); \
1081 PROPNAME::~PROPNAME() { } \
1082 void PROPNAME::GenerateValueAsString() \
1084 wxChar delimChar = DELIMCHAR; \
1085 if ( delimChar == wxS('"') ) \
1086 wxArrayStringProperty::GenerateValueAsString(); \
1088 wxPropertyGrid::ArrayStringToString(m_display, \
1089 m_value.GetArrayString(), \
1092 bool PROPNAME::StringToValue( wxVariant& variant, \
1093 const wxString& text, int ) const \
1095 wxChar delimChar = DELIMCHAR; \
1096 if ( delimChar == wxS('"') ) \
1097 return wxArrayStringProperty::StringToValue(variant, text, 0); \
1099 wxArrayString arr; \
1100 WX_PG_TOKENIZER1_BEGIN(text,DELIMCHAR) \
1102 WX_PG_TOKENIZER1_END() \
1106 bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
1107 wxWindow* primary, wxEvent& event ) \
1109 if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) \
1110 return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \
1114 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \
1115 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME)
1117 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_DECL(PROPNAME, DECL) \
1118 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, DECL)
1120 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \
1121 WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
1124 wxValidator* PROPNAME::DoGetValidator () const \
1125 { return (wxValidator*) NULL; }
1128 // -----------------------------------------------------------------------
1129 // wxArrayEditorDialog
1130 // -----------------------------------------------------------------------
1132 #include "wx/textctrl.h"
1133 #include "wx/button.h"
1134 #include "wx/listbox.h"
1136 #define wxAEDIALOG_STYLE \
1137 (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
1139 class WXDLLIMPEXP_PROPGRID wxArrayEditorDialog
: public wxDialog
1142 wxArrayEditorDialog();
1143 virtual ~wxArrayEditorDialog() { }
1147 wxArrayEditorDialog( wxWindow
*parent
,
1148 const wxString
& message
,
1149 const wxString
& caption
,
1150 long style
= wxAEDIALOG_STYLE
,
1151 const wxPoint
& pos
= wxDefaultPosition
,
1152 const wxSize
& sz
= wxDefaultSize
);
1154 bool Create( wxWindow
*parent
,
1155 const wxString
& message
,
1156 const wxString
& caption
,
1157 long style
= wxAEDIALOG_STYLE
,
1158 const wxPoint
& pos
= wxDefaultPosition
,
1159 const wxSize
& sz
= wxDefaultSize
);
1161 /** Set value modified by dialog.
1163 virtual void SetDialogValue( const wxVariant
& WXUNUSED(value
) )
1165 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
1168 /** Return value modified by dialog.
1170 virtual wxVariant
GetDialogValue() const
1172 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
1176 /** Override to return wxValidator to be used with the wxTextCtrl
1177 in dialog. Note that the validator is used in the standard
1178 wx way, ie. it immediately prevents user from entering invalid
1182 Dialog frees the validator.
1184 virtual wxValidator
* GetTextCtrlValidator() const
1186 return (wxValidator
*) NULL
;
1189 // Returns true if array was actually modified
1190 bool IsModified() const { return m_modified
; }
1192 //const wxArrayString& GetStrings() const { return m_array; }
1194 // implementation from now on
1195 void OnUpdateClick(wxCommandEvent
& event
);
1196 void OnAddClick(wxCommandEvent
& event
);
1197 void OnDeleteClick(wxCommandEvent
& event
);
1198 void OnListBoxClick(wxCommandEvent
& event
);
1199 void OnUpClick(wxCommandEvent
& event
);
1200 void OnDownClick(wxCommandEvent
& event
);
1201 //void OnCustomEditClick(wxCommandEvent& event);
1202 void OnIdle(wxIdleEvent
& event
);
1205 wxTextCtrl
* m_edValue
;
1206 wxListBox
* m_lbStrings
;
1208 wxButton
* m_butAdd
; // Button pointers
1209 wxButton
* m_butCustom
; // required for disabling/enabling changing.
1210 wxButton
* m_butUpdate
;
1211 wxButton
* m_butRemove
;
1213 wxButton
* m_butDown
;
1215 //wxArrayString m_array;
1217 const wxChar
* m_custBtText
;
1218 //wxArrayStringPropertyClass* m_pCallingClass;
1222 unsigned char m_curFocus
;
1224 // These must be overridden - must return true on success.
1225 virtual wxString
ArrayGet( size_t index
) = 0;
1226 virtual size_t ArrayGetCount() = 0;
1227 virtual bool ArrayInsert( const wxString
& str
, int index
) = 0;
1228 virtual bool ArraySet( size_t index
, const wxString
& str
) = 0;
1229 virtual void ArrayRemoveAt( int index
) = 0;
1230 virtual void ArraySwap( size_t first
, size_t second
) = 0;
1234 DECLARE_DYNAMIC_CLASS_NO_COPY(wxArrayEditorDialog
)
1235 DECLARE_EVENT_TABLE()
1239 // -----------------------------------------------------------------------
1240 // wxPGArrayStringEditorDialog
1241 // -----------------------------------------------------------------------
1243 class WXDLLIMPEXP_PROPGRID
1244 wxPGArrayStringEditorDialog
: public wxArrayEditorDialog
1247 wxPGArrayStringEditorDialog();
1248 virtual ~wxPGArrayStringEditorDialog() { }
1252 virtual void SetDialogValue( const wxVariant
& value
)
1254 m_array
= value
.GetArrayString();
1257 virtual wxVariant
GetDialogValue() const
1262 void SetCustomButton( const wxChar
* custBtText
, wxArrayStringProperty
* pcc
)
1264 m_custBtText
= custBtText
;
1265 m_pCallingClass
= pcc
;
1268 void OnCustomEditClick(wxCommandEvent
& event
);
1271 wxArrayString m_array
;
1273 wxArrayStringProperty
* m_pCallingClass
;
1275 virtual wxString
ArrayGet( size_t index
);
1276 virtual size_t ArrayGetCount();
1277 virtual bool ArrayInsert( const wxString
& str
, int index
);
1278 virtual bool ArraySet( size_t index
, const wxString
& str
);
1279 virtual void ArrayRemoveAt( int index
);
1280 virtual void ArraySwap( size_t first
, size_t second
);
1284 DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog
)
1285 DECLARE_EVENT_TABLE()
1289 // -----------------------------------------------------------------------
1291 #endif // wxUSE_PROPGRID
1293 #endif // _WX_PROPGRID_PROPS_H_