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_
15 // -----------------------------------------------------------------------
17 class wxArrayEditorDialog
;
19 #include "wx/propgrid/editors.h"
21 // -----------------------------------------------------------------------
24 // Additional property class declaration helper macros
28 // Property class implementation helper macros.
31 #define WX_PG_DECLARE_BASIC_TYPE_METHODS() \
32 virtual wxString GetValueAsString( int argFlags = 0 ) const; \
33 virtual bool StringToValue( wxVariant& variant, \
34 const wxString& text, \
35 int argFlags = 0 ) const;
37 #define WX_PG_DECLARE_CHOICE_METHODS() \
38 virtual bool IntToValue( wxVariant& variant, \
39 int number, int argFlags = 0 ) const; \
40 virtual int GetChoiceInfo( wxPGChoiceInfo* choiceinfo );
42 #define WX_PG_DECLARE_EVENT_METHODS() \
43 virtual bool OnEvent( wxPropertyGrid* propgrid, \
44 wxWindow* primary, wxEvent& event );
46 #define WX_PG_DECLARE_PARENTAL_METHODS() \
47 virtual void ChildChanged( wxVariant& thisValue, \
48 int childIndex, wxVariant& childValue ) const; \
49 virtual void RefreshChildren();
51 #define WX_PG_DECLARE_CUSTOM_PAINT_METHODS() \
52 virtual wxSize OnMeasureImage( int item ) const; \
53 virtual void OnCustomPaint( wxDC& dc, \
54 const wxRect& rect, wxPGPaintData& paintdata );
56 #define WX_PG_DECLARE_ATTRIBUTE_METHODS() \
57 virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
59 #define WX_PG_DECLARE_VALIDATOR_METHODS() \
60 virtual wxValidator* DoGetValidator() const;
62 // Adds constructor function as well.
63 #define WX_PG_IMPLEMENT_PROPERTY_CLASS2(NAME,CLASSNAME,\
64 UPCLASS,T,T_AS_ARG,EDITOR) \
65 IMPLEMENT_DYNAMIC_CLASS(NAME, UPCLASS) \
66 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(NAME,T,EDITOR)
69 #define WX_PG_IMPLEMENT_PROPERTY_CLASS(NAME,UPNAME,T,T_AS_ARG,EDITOR) \
70 WX_PG_IMPLEMENT_PROPERTY_CLASS2(NAME,NAME,UPNAME,T,T_AS_ARG,EDITOR)
72 #define WX_PG_DECLARE_DERIVED_PROPERTY_CLASS(CLASSNAME) \
73 DECLARE_DYNAMIC_CLASS(CLASSNAME)
75 // Derived property class is one that inherits from an existing working property
76 // class, but assumes same value and editor type.
77 #define WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(NAME,UPNAME,T_AS_ARG) \
78 IMPLEMENT_DYNAMIC_CLASS(NAME, UPNAME)
80 // -----------------------------------------------------------------------
82 #define wxPG_NO_ESCAPE wxPG_PROP_NO_ESCAPE // No escape sequences
83 #define wxPG_ESCAPE 0 // Escape sequences
85 #define WX_PG_DECLARE_STRING_PROPERTY_WITH_DECL(NAME, DECL) \
86 DECL NAME : public wxLongStringProperty \
88 WX_PG_DECLARE_DERIVED_PROPERTY_CLASS(NAME) \
90 NAME( const wxString& name = wxPG_LABEL, \
91 const wxString& label = wxPG_LABEL, \
92 const wxString& value = wxEmptyString); \
94 virtual bool OnButtonClick( wxPropertyGrid* propgrid, wxString& value ); \
95 WX_PG_DECLARE_VALIDATOR_METHODS() \
98 #define WX_PG_DECLARE_STRING_PROPERTY(NAME) \
99 WX_PG_DECLARE_STRING_PROPERTY_WITH_DECL(NAME, class) \
101 #define WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(NAME, FLAGS) \
102 WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(NAME,wxLongStringProperty,\
104 NAME::NAME( const wxString& name, \
105 const wxString& label, \
106 const wxString& value ) \
107 : wxLongStringProperty(name,label,value) \
113 #define WX_PG_IMPLEMENT_STRING_PROPERTY(NAME, FLAGS) \
114 WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(NAME,FLAGS) \
115 wxValidator* NAME::DoGetValidator () const \
116 { return (wxValidator*) NULL; }
118 // -----------------------------------------------------------------------
120 #define WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY_WITH_DECL(CLASSNAME,DECL) \
121 DECL CLASSNAME : public wxFlagsProperty \
123 WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
125 CLASSNAME( const wxString& label = wxPG_LABEL, \
126 const wxString& name = wxPG_LABEL, \
128 virtual ~CLASSNAME(); \
131 #define WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY(CLASSNAME) \
132 WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY_WITH_DECL(CLASSNAME, class)
134 // This will create interface for wxFlagsProperty derived class
136 #define WX_PG_IMPLEMENT_CUSTOM_FLAGS_PROPERTY(CLASSNAME,LABELS,VALUES,DEFVAL) \
137 WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME,wxFlagsProperty,long_##CLASSNAME,\
139 CLASSNAME::CLASSNAME( const wxString& label, \
140 const wxString& name, \
142 : wxFlagsProperty(label,name,LABELS,VALUES,value!=-1?value:DEFVAL) \
144 m_flags |= wxPG_PROP_STATIC_CHOICES; \
146 CLASSNAME::~CLASSNAME() { }
149 // -----------------------------------------------------------------------
151 #define WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY_WITH_DECL(CLASSNAME, DECL) \
152 class CLASSNAME : public wxEnumProperty \
154 WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
156 CLASSNAME( const wxString& label = wxPG_LABEL, \
157 const wxString& name = wxPG_LABEL, \
159 virtual ~CLASSNAME(); \
162 #define WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY(CLASSNAME) \
163 WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY_WITH_DECL(CLASSNAME, class)
165 #define WX_PG_IMPLEMENT_CUSTOM_ENUM_PROPERTY(CLASSNAME,LABELS,VALUES,DEFVAL) \
166 WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME, wxEnumProperty, long_##CLASSNAME, \
168 CLASSNAME::CLASSNAME( const wxString& label, const wxString& name, int value ) \
169 : wxEnumProperty(label,name,LABELS,VALUES,value!=-1?value:DEFVAL) \
171 m_flags |= wxPG_PROP_STATIC_CHOICES; \
173 CLASSNAME::~CLASSNAME() { }
176 // -----------------------------------------------------------------------
178 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, DECL) \
179 DECL CLASSNAME : public wxSystemColourProperty \
181 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
183 CLASSNAME( const wxString& label = wxPG_LABEL, \
184 const wxString& name = wxPG_LABEL, \
185 const wxColourPropertyValue& value = wxColourPropertyValue() ); \
186 virtual ~CLASSNAME(); \
187 virtual wxColour GetColour( int index ) const; \
190 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY(CLASSNAME) \
191 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, class)
193 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY(CLASSNAME,\
194 LABELS,VALUES,COLOURS) \
195 static wxPGChoices gs_##CLASSNAME##_choicesCache; \
196 WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(CLASSNAME, wxSystemColourProperty, \
197 const wxColourPropertyValue&) \
198 CLASSNAME::CLASSNAME( const wxString& label, const wxString& name, \
199 const wxColourPropertyValue& value ) \
200 : wxSystemColourProperty(label, name, LABELS, VALUES, \
201 &gs_##CLASSNAME##_choicesCache, value ) \
203 m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \
205 CLASSNAME::~CLASSNAME () { } \
206 wxColour CLASSNAME::GetColour ( int index ) const \
208 if ( !m_choices.HasValue(index) ) \
210 wxASSERT( index < (int)m_choices.GetCount() ); \
211 return COLOURS[index]; \
213 return COLOURS[m_choices.GetValue(index)]; \
216 // -----------------------------------------------------------------------
218 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME,\
220 DECL CLASSNAME : public wxSystemColourProperty \
222 WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
224 CLASSNAME( const wxString& label = wxPG_LABEL, \
225 const wxString& name = wxPG_LABEL, \
226 const wxColour& value = wxColour() ); \
227 virtual ~CLASSNAME(); \
228 virtual wxString GetValueAsString( int argFlags ) const; \
229 virtual wxColour GetColour( int index ) const; \
230 virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const; \
231 void Init( wxColour colour ); \
234 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME) \
235 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME, class)
237 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \
242 static wxPGChoices gs_##CLASSNAME##_choicesCache; \
243 WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME, wxSystemColourProperty, \
244 wxColour, const wxColour&,EDITOR) \
245 CLASSNAME::CLASSNAME( const wxString& label, \
246 const wxString& name, \
247 const wxColour& value ) \
248 : wxSystemColourProperty(label, name, LABELS, VALUES, \
249 &gs_##CLASSNAME##_choicesCache, value ) \
255 m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \
257 CLASSNAME::~CLASSNAME() { } \
258 void CLASSNAME::Init( wxColour colour ) \
260 if ( !colour.Ok() ) \
265 int ind = ColToInd(colour); \
267 ind = m_choices.GetCount() - 1; \
270 wxString CLASSNAME::GetValueAsString( int argFlags ) const \
272 const wxPGEditor* editor = GetEditorClass(); \
273 if ( editor != wxPG_EDITOR(Choice) && \
274 editor != wxPG_EDITOR(ChoiceAndButton) && \
275 editor != wxPG_EDITOR(ComboBox) ) \
276 argFlags |= wxPG_PROPERTY_SPECIFIC; \
277 return wxSystemColourProperty::GetValueAsString(argFlags); \
279 wxColour CLASSNAME::GetColour( int index ) const \
281 if ( !m_choices.HasValue(index) ) \
283 wxASSERT( index < (int)GetItemCount() ); \
284 return COLOURS[index]; \
286 return COLOURS[m_choices.GetValue(index)]; \
288 wxVariant CLASSNAME::DoTranslateVal( wxColourPropertyValue& v ) const \
291 variant << v.m_colour; \
296 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME, \
300 WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \
306 // -----------------------------------------------------------------------
309 // These macros help creating DoGetValidator
310 #define WX_PG_DOGETVALIDATOR_ENTRY() \
311 static wxValidator* s_ptr = (wxValidator*) NULL; \
312 if ( s_ptr ) return s_ptr;
314 // Common function exit
315 #define WX_PG_DOGETVALIDATOR_EXIT(VALIDATOR) \
317 wxPGGlobalVars->m_arrValidators.Add( (void*) VALIDATOR ); \
320 // -----------------------------------------------------------------------
324 /** @class wxPGInDialogValidator
326 Creates and manages a temporary wxTextCtrl for validation purposes.
327 Uses wxPropertyGrid's current editor, if available.
329 class WXDLLIMPEXP_PROPGRID wxPGInDialogValidator
332 wxPGInDialogValidator()
337 ~wxPGInDialogValidator()
340 m_textCtrl
->Destroy();
343 bool DoValidate( wxPropertyGrid
* propGrid
,
344 wxValidator
* validator
,
345 const wxString
& value
);
348 wxTextCtrl
* m_textCtrl
;
354 // -----------------------------------------------------------------------
356 // -----------------------------------------------------------------------
358 #define wxPG_PROP_PASSWORD wxPG_PROP_CLASS_SPECIFIC_2
360 /** @class wxStringProperty
362 Basic property with string value.
364 <b>Supported special attributes:</b>
365 - "Password": set to 1 inorder to enable wxTE_PASSWORD on the editor.
368 - If value "<composed>" is set, then actual value is formed (or composed)
369 from values of child properties.
371 class WXDLLIMPEXP_PROPGRID wxStringProperty
: public wxPGProperty
373 WX_PG_DECLARE_PROPERTY_CLASS(wxStringProperty
)
375 wxStringProperty( const wxString
& label
= wxPG_LABEL
,
376 const wxString
& name
= wxPG_LABEL
,
377 const wxString
& value
= wxEmptyString
);
378 virtual ~wxStringProperty();
380 WX_PG_DECLARE_BASIC_TYPE_METHODS()
381 WX_PG_DECLARE_ATTRIBUTE_METHODS()
383 /** This is updated so "<composed>" special value can be handled.
385 virtual void OnSetValue();
390 // -----------------------------------------------------------------------
393 /** Constants used with DoValidation() methods.
397 /** Instead of modifying the value, show an error message.
399 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
= 0,
401 /** Modify value, but stick with the limitations.
403 wxPG_PROPERTY_VALIDATION_SATURATE
= 1,
405 /** Modify value, wrap around on overflow.
407 wxPG_PROPERTY_VALIDATION_WRAP
= 2
411 // -----------------------------------------------------------------------
413 /** @class wxIntProperty
415 Basic property with integer value.
417 Seamlessly supports 64-bit integer (wxLongLong) on overflow.
419 <b>Example how to use seamless 64-bit integer support</b>
424 wxLongLong_t value = pg->GetPropertyValueAsLongLong();
431 wxVariant variant = property->GetValue();
432 if ( variant.GetType() == "wxLongLong" )
433 value = wxLongLongFromVariant(variant);
435 value = variant.GetLong();
441 pg->SetPropertyValue(longLongVal);
447 property->SetValue(WXVARIANT(longLongVal));
451 <b>Supported special attributes:</b>
452 - "Min", "Max": Specify acceptable value range.
454 class WXDLLIMPEXP_PROPGRID wxIntProperty
: public wxPGProperty
456 WX_PG_DECLARE_PROPERTY_CLASS(wxIntProperty
)
458 wxIntProperty( const wxString
& label
= wxPG_LABEL
,
459 const wxString
& name
= wxPG_LABEL
,
461 virtual ~wxIntProperty();
463 wxIntProperty( const wxString
& label
,
464 const wxString
& name
,
465 const wxLongLong
& value
);
466 WX_PG_DECLARE_BASIC_TYPE_METHODS()
467 virtual bool ValidateValue( wxVariant
& value
,
468 wxPGValidationInfo
& validationInfo
) const;
469 virtual bool IntToValue( wxVariant
& variant
,
471 int argFlags
= 0 ) const;
472 static wxValidator
* GetClassValidator();
473 virtual wxValidator
* DoGetValidator() const;
475 /** Validation helper.
477 static bool DoValidation( const wxPGProperty
* property
,
479 wxPGValidationInfo
* pValidationInfo
,
481 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
486 // -----------------------------------------------------------------------
488 /** @class wxUIntProperty
490 Basic property with unsigned integer value.
491 Seamlessly supports 64-bit integer (wxULongLong) on overflow.
493 <b>Supported special attributes:</b>
494 - "Min", "Max": Specify acceptable value range.
495 - "Base": Define base. Valid constants are wxPG_BASE_OCT, wxPG_BASE_DEC,
496 wxPG_BASE_HEX and wxPG_BASE_HEXL (lowercase characters). Arbitrary bases
497 are <b>not</b> supported.
498 - "Prefix": Possible values are wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and
499 wxPG_PREFIX_DOLLAR_SIGN. Only wxPG_PREFIX_NONE works with Decimal and Octal
503 - For example how to use seamless 64-bit integer support, see wxIntProperty
504 documentation (just use wxULongLong instead of wxLongLong).
506 class WXDLLIMPEXP_PROPGRID wxUIntProperty
: public wxPGProperty
508 WX_PG_DECLARE_PROPERTY_CLASS(wxUIntProperty
)
510 wxUIntProperty( const wxString
& label
= wxPG_LABEL
,
511 const wxString
& name
= wxPG_LABEL
,
512 unsigned long value
= 0 );
513 virtual ~wxUIntProperty();
514 wxUIntProperty( const wxString
& label
,
515 const wxString
& name
,
516 const wxULongLong
& value
);
517 WX_PG_DECLARE_BASIC_TYPE_METHODS()
518 WX_PG_DECLARE_ATTRIBUTE_METHODS()
519 virtual bool ValidateValue( wxVariant
& value
,
520 wxPGValidationInfo
& validationInfo
) const;
521 virtual bool IntToValue( wxVariant
& variant
,
523 int argFlags
= 0 ) const;
526 wxByte m_realBase
; // translated to 8,16,etc.
532 // -----------------------------------------------------------------------
534 /** @class wxFloatProperty
536 Basic property with double-precision floating point value.
538 <b>Supported special attributes:</b>
539 - "Precision": Sets the (max) precision used when floating point value is
540 rendered as text. The default -1 means infinite precision.
542 class WXDLLIMPEXP_PROPGRID wxFloatProperty
: public wxPGProperty
544 WX_PG_DECLARE_PROPERTY_CLASS(wxFloatProperty
)
546 wxFloatProperty( const wxString
& label
= wxPG_LABEL
,
547 const wxString
& name
= wxPG_LABEL
,
548 double value
= 0.0 );
549 virtual ~wxFloatProperty();
551 WX_PG_DECLARE_BASIC_TYPE_METHODS()
552 WX_PG_DECLARE_ATTRIBUTE_METHODS()
553 virtual bool ValidateValue( wxVariant
& value
,
554 wxPGValidationInfo
& validationInfo
) const;
556 /** Validation helper.
558 static bool DoValidation( const wxPGProperty
* property
,
560 wxPGValidationInfo
* pValidationInfo
,
562 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
566 virtual wxValidator
* DoGetValidator () const;
569 // -----------------------------------------------------------------------
571 // Exclude class from wxPython bindings
574 /** @class wxBoolProperty
576 Basic property with boolean value.
578 <b>Supported special attributes:</b>
579 - "UseCheckbox": Set to 1 to use check box editor instead of combo box.
580 - "UseDClickCycling": Set to 1 to cycle combo box instead showing the list.
582 class WXDLLIMPEXP_PROPGRID wxBoolProperty
: public wxPGProperty
584 WX_PG_DECLARE_PROPERTY_CLASS(wxBoolProperty
)
586 wxBoolProperty( const wxString
& label
= wxPG_LABEL
,
587 const wxString
& name
= wxPG_LABEL
,
588 bool value
= false );
589 virtual ~wxBoolProperty();
591 WX_PG_DECLARE_BASIC_TYPE_METHODS()
592 WX_PG_DECLARE_CHOICE_METHODS()
593 WX_PG_DECLARE_ATTRIBUTE_METHODS()
598 // -----------------------------------------------------------------------
600 /** @class wxBaseEnumProperty
602 Derive dynamic custom properties with choices from this class.
605 - Updating private index is important. You can do this either by calling
606 SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue
607 be called (by not implementing it, or by calling super class function in
608 it) -OR- you can just call SetIndex in OnSetValue.
610 class WXDLLIMPEXP_PROPGRID wxBaseEnumProperty
: public wxPGProperty
613 wxBaseEnumProperty( const wxString
& label
= wxPG_LABEL
,
614 const wxString
& name
= wxPG_LABEL
);
616 virtual void OnSetValue();
617 virtual wxString
GetValueAsString( int argFlags
) const;
618 virtual bool StringToValue( wxVariant
& variant
,
619 const wxString
& text
,
620 int argFlags
= 0 ) const;
621 virtual bool ValidateValue( wxVariant
& value
,
622 wxPGValidationInfo
& validationInfo
) const;
624 // If wxPG_FULL_VALUE is not set in flags, then the value is interpreted
625 // as index to choices list. Otherwise, it is actual value.
626 virtual bool IntToValue( wxVariant
& variant
,
628 int argFlags
= 0 ) const;
631 // Additional virtuals
633 // This must be overridden to have non-index based value
634 virtual int GetIndexForValue( int value
) const;
636 // This returns string and value for index
637 // Returns NULL if beyond last item
638 // pvalue is never NULL - always set it.
639 virtual const wxString
* GetEntry( size_t index
, int* pvalue
) const = 0;
641 int GetValueForIndex( size_t index
) const
644 GetEntry( index
, &v
);
650 int GetIndex() const;
651 void SetIndex( int index
);
653 bool ValueFromString_( wxVariant
& value
,
654 const wxString
& text
,
655 int argFlags
) const;
656 bool ValueFromInt_( wxVariant
& value
, int intVal
, int argFlags
) const;
658 static void ResetNextIndex() { ms_nextIndex
= -2; }
661 // This is private so that classes are guaranteed to use GetIndex
662 // for up-to-date index value.
665 // Relies on ValidateValue being called always before OnSetValue
666 static int ms_nextIndex
;
669 // -----------------------------------------------------------------------
671 // If set, then selection of choices is static and should not be
672 // changed (i.e. returns NULL in GetPropertyChoices).
673 #define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1
675 /** @class wxEnumProperty
677 You can derive custom properties with choices from this class. See
678 wxBaseEnumProperty for remarks.
680 class WXDLLIMPEXP_PROPGRID wxEnumProperty
: public wxBaseEnumProperty
682 WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty
)
686 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
687 const wxString
& name
= wxPG_LABEL
,
688 const wxChar
** labels
= NULL
,
689 const long* values
= NULL
,
691 wxEnumProperty( const wxString
& label
,
692 const wxString
& name
,
693 wxPGChoices
& choices
,
696 // Special constructor for caching choices (used by derived class)
697 wxEnumProperty( const wxString
& label
,
698 const wxString
& name
,
699 const wxChar
** labels
,
701 wxPGChoices
* choicesCache
,
704 wxEnumProperty( const wxString
& label
,
705 const wxString
& name
,
706 const wxArrayString
& labels
,
707 const wxArrayInt
& values
= wxArrayInt(),
710 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
711 const wxString
& name
= wxPG_LABEL
,
712 const wxArrayString
& labels
= wxArrayString(),
713 const wxArrayInt
& values
= wxArrayInt(),
717 virtual ~wxEnumProperty();
719 virtual int GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
);
720 virtual int GetIndexForValue( int value
) const;
721 virtual const wxString
* GetEntry( size_t index
, int* pvalue
) const;
723 size_t GetItemCount() const { return m_choices
.GetCount(); }
724 const wxPGChoices
& GetChoices() const { return m_choices
; }
727 wxPGChoices m_choices
;
730 // -----------------------------------------------------------------------
732 /** @class wxEditEnumProperty
734 wxEnumProperty with wxString value and writable combo box editor.
737 Uses int value, similar to wxEnumProperty, unless text entered by user is
738 is not in choices (in which case string value is used).
740 class WXDLLIMPEXP_PROPGRID wxEditEnumProperty
: public wxEnumProperty
742 WX_PG_DECLARE_PROPERTY_CLASS(wxEditEnumProperty
)
745 wxEditEnumProperty( const wxString
& label
,
746 const wxString
& name
,
747 const wxChar
** labels
,
749 const wxString
& value
);
750 wxEditEnumProperty( const wxString
& label
= wxPG_LABEL
,
751 const wxString
& name
= wxPG_LABEL
,
752 const wxArrayString
& labels
= wxArrayString(),
753 const wxArrayInt
& values
= wxArrayInt(),
754 const wxString
& value
= wxEmptyString
);
755 wxEditEnumProperty( const wxString
& label
,
756 const wxString
& name
,
757 wxPGChoices
& choices
,
758 const wxString
& value
= wxEmptyString
);
760 // Special constructor for caching choices (used by derived class)
761 wxEditEnumProperty( const wxString
& label
,
762 const wxString
& name
,
763 const wxChar
** labels
,
765 wxPGChoices
* choicesCache
,
766 const wxString
& value
);
768 virtual ~wxEditEnumProperty();
773 // -----------------------------------------------------------------------
775 /** @class wxFlagsProperty
777 Represents a bit set that fits in a long integer. wxBoolProperty
778 sub-properties are created for editing individual bits. Textctrl is created
779 to manually edit the flags as a text; a continous sequence of spaces,
780 commas and semicolons is considered as a flag id separator.
781 <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
782 you will need to use SetPropertyChoices - otherwise they will not get
785 class WXDLLIMPEXP_PROPGRID wxFlagsProperty
: public wxPGProperty
787 WX_PG_DECLARE_PROPERTY_CLASS(wxFlagsProperty
)
791 wxFlagsProperty( const wxString
& label
,
792 const wxString
& name
,
793 const wxChar
** labels
,
794 const long* values
= NULL
,
796 wxFlagsProperty( const wxString
& label
,
797 const wxString
& name
,
798 wxPGChoices
& choices
,
801 wxFlagsProperty( const wxString
& label
= wxPG_LABEL
,
802 const wxString
& name
= wxPG_LABEL
,
803 const wxArrayString
& labels
= wxArrayString(),
804 const wxArrayInt
& values
= wxArrayInt(),
806 virtual ~wxFlagsProperty ();
808 virtual void OnSetValue();
809 virtual wxString
GetValueAsString( int argFlags
) const;
810 virtual bool StringToValue( wxVariant
& variant
,
811 const wxString
& text
,
813 virtual void ChildChanged( wxVariant
& thisValue
,
815 wxVariant
& childValue
) const;
816 virtual void RefreshChildren();
818 // this is necessary for conveying m_choices
819 virtual int GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
);
822 size_t GetItemCount() const { return m_choices
.GetCount(); }
823 const wxString
& GetLabel( size_t ind
) const
824 { return m_choices
.GetLabel(ind
); }
827 wxPGChoices m_choices
;
829 // Used to detect if choices have been changed
830 wxPGChoicesData
* m_oldChoicesData
;
832 // Needed to properly mark changed sub-properties
835 // Converts string id to a relevant bit.
836 long IdToBit( const wxString
& id
) const;
838 // Creates children and sets value.
842 // -----------------------------------------------------------------------
844 /** @class wxPGFileDialogAdapter
847 class WXDLLIMPEXP_PROPGRID
848 wxPGFileDialogAdapter
: public wxPGEditorDialogAdapter
851 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
852 wxPGProperty
* property
);
855 // -----------------------------------------------------------------------
857 #include "wx/filename.h"
859 // Indicates first bit useable by derived properties.
860 #define wxPG_PROP_SHOW_FULL_FILENAME wxPG_PROP_CLASS_SPECIFIC_1
862 /** @class wxFileProperty
864 Like wxLongStringProperty, but the button triggers file selector instead.
866 <b>Supported special attributes:</b>
867 - "Wildcard": Sets wildcard (see wxFileDialog for format details), "All
868 files..." is default.
869 - "ShowFullPath": Default 1. When 0, only the file name is shown (i.e. drive
870 and directory are hidden).
871 - "ShowRelativePath": If set, then the filename is shown relative to the
873 - "InitialPath": Sets the initial path of where to look for files.
874 - "DialogTitle": Sets a specific title for the dir dialog.
876 class WXDLLIMPEXP_PROPGRID wxFileProperty
: public wxPGProperty
878 friend class wxPGFileDialogAdapter
;
879 WX_PG_DECLARE_PROPERTY_CLASS(wxFileProperty
)
882 wxFileProperty( const wxString
& label
= wxPG_LABEL
,
883 const wxString
& name
= wxPG_LABEL
,
884 const wxString
& value
= wxEmptyString
);
885 virtual ~wxFileProperty ();
887 virtual void OnSetValue();
888 virtual wxString
GetValueAsString( int argFlags
) const;
889 virtual bool StringToValue( wxVariant
& variant
,
890 const wxString
& text
,
891 int argFlags
= 0 ) const;
892 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
894 WX_PG_DECLARE_ATTRIBUTE_METHODS()
896 static wxValidator
* GetClassValidator();
897 virtual wxValidator
* DoGetValidator() const;
901 wxString m_basePath
; // If set, then show path relative to it
902 wxString m_initialPath
; // If set, start the file dialog here
903 wxString m_dlgTitle
; // If set, used as title for file dialog
904 wxFileName m_filename
; // used as primary storage
905 int m_indFilter
; // index to the selected filter
908 // -----------------------------------------------------------------------
910 #define wxPG_PROP_NO_ESCAPE wxPG_PROP_CLASS_SPECIFIC_1
913 /** @class wxPGLongStringDialogAdapter
916 class WXDLLIMPEXP_PROPGRID
917 wxPGLongStringDialogAdapter
: public wxPGEditorDialogAdapter
920 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
921 wxPGProperty
* property
);
925 /** @class wxLongStringProperty
927 Like wxStringProperty, but has a button that triggers a small text
930 class WXDLLIMPEXP_PROPGRID wxLongStringProperty
: public wxPGProperty
932 WX_PG_DECLARE_PROPERTY_CLASS(wxLongStringProperty
)
935 wxLongStringProperty( const wxString
& label
= wxPG_LABEL
,
936 const wxString
& name
= wxPG_LABEL
,
937 const wxString
& value
= wxEmptyString
);
938 virtual ~wxLongStringProperty();
940 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
941 virtual bool StringToValue( wxVariant
& variant
,
942 const wxString
& text
,
943 int argFlags
= 0 ) const;
945 WX_PG_DECLARE_EVENT_METHODS()
947 // Shows string editor dialog. Value to be edited should be read from
948 // value, and if dialog is not cancelled, it should be stored back and true
949 // should be returned if that was the case.
950 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
, wxString
& value
);
952 static bool DisplayEditorDialog( wxPGProperty
* prop
,
953 wxPropertyGrid
* propGrid
,
959 // -----------------------------------------------------------------------
962 // Exclude class from wxPython bindings
965 /** @class wxDirProperty
967 Like wxLongStringProperty, but the button triggers dir selector instead.
969 <b>Supported special attributes:</b>
970 - "DialogMessage": Sets specific message in the dir selector.
972 class WXDLLIMPEXP_PROPGRID wxDirProperty
: public wxLongStringProperty
975 DECLARE_DYNAMIC_CLASS(wxDirProperty
)
978 wxDirProperty( const wxString
& name
= wxPG_LABEL
,
979 const wxString
& label
= wxPG_LABEL
,
980 const wxString
& value
= wxEmptyString
);
981 virtual ~wxDirProperty();
983 WX_PG_DECLARE_ATTRIBUTE_METHODS()
984 WX_PG_DECLARE_VALIDATOR_METHODS()
986 virtual bool OnButtonClick ( wxPropertyGrid
* propGrid
, wxString
& value
);
989 wxString m_dlgMessage
;
994 // -----------------------------------------------------------------------
996 // wxBoolProperty specific flags
997 #define wxPG_PROP_USE_CHECKBOX wxPG_PROP_CLASS_SPECIFIC_1
998 // DCC = Double Click Cycles
999 #define wxPG_PROP_USE_DCC wxPG_PROP_CLASS_SPECIFIC_2
1002 // -----------------------------------------------------------------------
1004 /** @class wxArrayStringProperty
1006 Property that manages a list of strings.
1008 class WXDLLIMPEXP_PROPGRID wxArrayStringProperty
: public wxPGProperty
1010 WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty
)
1013 wxArrayStringProperty( const wxString
& label
= wxPG_LABEL
,
1014 const wxString
& name
= wxPG_LABEL
,
1015 const wxArrayString
& value
= wxArrayString() );
1016 virtual ~wxArrayStringProperty();
1018 virtual void OnSetValue();
1019 WX_PG_DECLARE_BASIC_TYPE_METHODS()
1020 WX_PG_DECLARE_EVENT_METHODS()
1022 virtual void GenerateValueAsString();
1024 // Shows string editor dialog. Value to be edited should be read from
1025 // value, and if dialog is not cancelled, it should be stored back and true
1026 // should be returned if that was the case.
1027 virtual bool OnCustomStringEdit( wxWindow
* parent
, wxString
& value
);
1030 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
,
1032 const wxChar
* cbt
);
1035 // Creates wxArrayEditorDialog for string editing. Called in OnButtonClick.
1036 virtual wxArrayEditorDialog
* CreateEditorDialog();
1040 wxString m_display
; // Cache for displayed text.
1043 // -----------------------------------------------------------------------
1045 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, \
1047 DECL PROPNAME : public wxArrayStringProperty \
1049 WX_PG_DECLARE_PROPERTY_CLASS(PROPNAME) \
1051 PROPNAME( const wxString& label = wxPG_LABEL, \
1052 const wxString& name = wxPG_LABEL, \
1053 const wxArrayString& value = wxArrayString() ); \
1055 virtual void GenerateValueAsString(); \
1056 virtual bool StringToValue( wxVariant& value, \
1057 const wxString& text, int = 0 ) const; \
1058 virtual bool OnEvent( wxPropertyGrid* propgrid, \
1059 wxWindow* primary, wxEvent& event ); \
1060 virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \
1061 WX_PG_DECLARE_VALIDATOR_METHODS() \
1064 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM) \
1065 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM, class)
1067 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
1070 WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME, wxArrayStringProperty, \
1071 wxArrayString, const wxArrayString&, \
1072 TextCtrlAndButton) \
1073 PROPNAME::PROPNAME( const wxString& label, \
1074 const wxString& name, \
1075 const wxArrayString& value ) \
1076 : wxArrayStringProperty(label,name,value) \
1078 PROPNAME::GenerateValueAsString(); \
1080 PROPNAME::~PROPNAME() { } \
1081 void PROPNAME::GenerateValueAsString() \
1083 wxChar delimChar = DELIMCHAR; \
1084 if ( delimChar == wxS('"') ) \
1085 wxArrayStringProperty::GenerateValueAsString(); \
1087 wxPropertyGrid::ArrayStringToString(m_display, \
1088 m_value.GetArrayString(), \
1091 bool PROPNAME::StringToValue( wxVariant& variant, \
1092 const wxString& text, int ) const \
1094 wxChar delimChar = DELIMCHAR; \
1095 if ( delimChar == wxS('"') ) \
1096 return wxArrayStringProperty::StringToValue(variant, text, 0); \
1098 wxArrayString arr; \
1099 WX_PG_TOKENIZER1_BEGIN(text,DELIMCHAR) \
1101 WX_PG_TOKENIZER1_END() \
1105 bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
1106 wxWindow* primary, wxEvent& event ) \
1108 if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) \
1109 return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \
1113 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \
1114 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME)
1116 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_DECL(PROPNAME, DECL) \
1117 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, DECL)
1119 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \
1120 WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
1123 wxValidator* PROPNAME::DoGetValidator () const \
1124 { return (wxValidator*) NULL; }
1127 // -----------------------------------------------------------------------
1128 // wxArrayEditorDialog
1129 // -----------------------------------------------------------------------
1131 #include "wx/textctrl.h"
1132 #include "wx/button.h"
1133 #include "wx/listbox.h"
1135 #define wxAEDIALOG_STYLE \
1136 (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
1138 class WXDLLIMPEXP_PROPGRID wxArrayEditorDialog
: public wxDialog
1141 wxArrayEditorDialog();
1142 virtual ~wxArrayEditorDialog() { }
1146 wxArrayEditorDialog( wxWindow
*parent
,
1147 const wxString
& message
,
1148 const wxString
& caption
,
1149 long style
= wxAEDIALOG_STYLE
,
1150 const wxPoint
& pos
= wxDefaultPosition
,
1151 const wxSize
& sz
= wxDefaultSize
);
1153 bool Create( wxWindow
*parent
,
1154 const wxString
& message
,
1155 const wxString
& caption
,
1156 long style
= wxAEDIALOG_STYLE
,
1157 const wxPoint
& pos
= wxDefaultPosition
,
1158 const wxSize
& sz
= wxDefaultSize
);
1160 /** Set value modified by dialog.
1162 virtual void SetDialogValue( const wxVariant
& WXUNUSED(value
) )
1164 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
1167 /** Return value modified by dialog.
1169 virtual wxVariant
GetDialogValue() const
1171 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
1175 /** Override to return wxValidator to be used with the wxTextCtrl
1176 in dialog. Note that the validator is used in the standard
1177 wx way, ie. it immediately prevents user from entering invalid
1181 Dialog frees the validator.
1183 virtual wxValidator
* GetTextCtrlValidator() const
1185 return (wxValidator
*) NULL
;
1188 // Returns true if array was actually modified
1189 bool IsModified() const { return m_modified
; }
1191 //const wxArrayString& GetStrings() const { return m_array; }
1193 // implementation from now on
1194 void OnUpdateClick(wxCommandEvent
& event
);
1195 void OnAddClick(wxCommandEvent
& event
);
1196 void OnDeleteClick(wxCommandEvent
& event
);
1197 void OnListBoxClick(wxCommandEvent
& event
);
1198 void OnUpClick(wxCommandEvent
& event
);
1199 void OnDownClick(wxCommandEvent
& event
);
1200 //void OnCustomEditClick(wxCommandEvent& event);
1201 void OnIdle(wxIdleEvent
& event
);
1204 wxTextCtrl
* m_edValue
;
1205 wxListBox
* m_lbStrings
;
1207 wxButton
* m_butAdd
; // Button pointers
1208 wxButton
* m_butCustom
; // required for disabling/enabling changing.
1209 wxButton
* m_butUpdate
;
1210 wxButton
* m_butRemove
;
1212 wxButton
* m_butDown
;
1214 //wxArrayString m_array;
1216 const wxChar
* m_custBtText
;
1217 //wxArrayStringPropertyClass* m_pCallingClass;
1221 unsigned char m_curFocus
;
1223 // These must be overridden - must return true on success.
1224 virtual wxString
ArrayGet( size_t index
) = 0;
1225 virtual size_t ArrayGetCount() = 0;
1226 virtual bool ArrayInsert( const wxString
& str
, int index
) = 0;
1227 virtual bool ArraySet( size_t index
, const wxString
& str
) = 0;
1228 virtual void ArrayRemoveAt( int index
) = 0;
1229 virtual void ArraySwap( size_t first
, size_t second
) = 0;
1233 DECLARE_DYNAMIC_CLASS_NO_COPY(wxArrayEditorDialog
)
1234 DECLARE_EVENT_TABLE()
1238 // -----------------------------------------------------------------------
1239 // wxPGArrayStringEditorDialog
1240 // -----------------------------------------------------------------------
1242 class WXDLLIMPEXP_PROPGRID
1243 wxPGArrayStringEditorDialog
: public wxArrayEditorDialog
1246 wxPGArrayStringEditorDialog();
1247 virtual ~wxPGArrayStringEditorDialog() { }
1251 virtual void SetDialogValue( const wxVariant
& value
)
1253 m_array
= value
.GetArrayString();
1256 virtual wxVariant
GetDialogValue() const
1261 void SetCustomButton( const wxChar
* custBtText
, wxArrayStringProperty
* pcc
)
1263 m_custBtText
= custBtText
;
1264 m_pCallingClass
= pcc
;
1267 void OnCustomEditClick(wxCommandEvent
& event
);
1270 wxArrayString m_array
;
1272 wxArrayStringProperty
* m_pCallingClass
;
1274 virtual wxString
ArrayGet( size_t index
);
1275 virtual size_t ArrayGetCount();
1276 virtual bool ArrayInsert( const wxString
& str
, int index
);
1277 virtual bool ArraySet( size_t index
, const wxString
& str
);
1278 virtual void ArrayRemoveAt( int index
);
1279 virtual void ArraySwap( size_t first
, size_t second
);
1283 DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog
)
1284 DECLARE_EVENT_TABLE()
1288 // -----------------------------------------------------------------------
1290 #endif // _WX_PROPGRID_PROPS_H_