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; \
42 virtual int GetChoiceInfo( wxPGChoiceInfo* choiceinfo );
44 #define WX_PG_DECLARE_EVENT_METHODS() \
45 virtual bool OnEvent( wxPropertyGrid* propgrid, \
46 wxWindow* primary, wxEvent& event );
48 #define WX_PG_DECLARE_PARENTAL_METHODS() \
49 virtual void ChildChanged( wxVariant& thisValue, \
50 int childIndex, wxVariant& childValue ) const; \
51 virtual void RefreshChildren();
53 #define WX_PG_DECLARE_CUSTOM_PAINT_METHODS() \
54 virtual wxSize OnMeasureImage( int item ) const; \
55 virtual void OnCustomPaint( wxDC& dc, \
56 const wxRect& rect, wxPGPaintData& paintdata );
58 #define WX_PG_DECLARE_ATTRIBUTE_METHODS() \
59 virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
61 #define WX_PG_DECLARE_VALIDATOR_METHODS() \
62 virtual wxValidator* DoGetValidator() const;
64 // Adds constructor function as well.
65 #define WX_PG_IMPLEMENT_PROPERTY_CLASS2(NAME,CLASSNAME,\
66 UPCLASS,T,T_AS_ARG,EDITOR) \
67 IMPLEMENT_DYNAMIC_CLASS(NAME, UPCLASS) \
68 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(NAME,T,EDITOR)
71 #define WX_PG_IMPLEMENT_PROPERTY_CLASS(NAME,UPNAME,T,T_AS_ARG,EDITOR) \
72 WX_PG_IMPLEMENT_PROPERTY_CLASS2(NAME,NAME,UPNAME,T,T_AS_ARG,EDITOR)
74 #define WX_PG_DECLARE_DERIVED_PROPERTY_CLASS(CLASSNAME) \
75 DECLARE_DYNAMIC_CLASS(CLASSNAME)
77 // Derived property class is one that inherits from an existing working property
78 // class, but assumes same value and editor type.
79 #define WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(NAME,UPNAME,T_AS_ARG) \
80 IMPLEMENT_DYNAMIC_CLASS(NAME, UPNAME)
82 // -----------------------------------------------------------------------
84 #define wxPG_NO_ESCAPE wxPG_PROP_NO_ESCAPE // No escape sequences
85 #define wxPG_ESCAPE 0 // Escape sequences
87 #define WX_PG_DECLARE_STRING_PROPERTY_WITH_DECL(NAME, DECL) \
88 DECL NAME : public wxLongStringProperty \
90 WX_PG_DECLARE_DERIVED_PROPERTY_CLASS(NAME) \
92 NAME( const wxString& name = wxPG_LABEL, \
93 const wxString& label = wxPG_LABEL, \
94 const wxString& value = wxEmptyString); \
96 virtual bool OnButtonClick( wxPropertyGrid* propgrid, wxString& value ); \
97 WX_PG_DECLARE_VALIDATOR_METHODS() \
100 #define WX_PG_DECLARE_STRING_PROPERTY(NAME) \
101 WX_PG_DECLARE_STRING_PROPERTY_WITH_DECL(NAME, class) \
103 #define WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(NAME, FLAGS) \
104 WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(NAME,wxLongStringProperty,\
106 NAME::NAME( const wxString& name, \
107 const wxString& label, \
108 const wxString& value ) \
109 : wxLongStringProperty(name,label,value) \
115 #define WX_PG_IMPLEMENT_STRING_PROPERTY(NAME, FLAGS) \
116 WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(NAME,FLAGS) \
117 wxValidator* NAME::DoGetValidator () const \
118 { return (wxValidator*) NULL; }
120 // -----------------------------------------------------------------------
122 #define WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY_WITH_DECL(CLASSNAME,DECL) \
123 DECL CLASSNAME : public wxFlagsProperty \
125 WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
127 CLASSNAME( const wxString& label = wxPG_LABEL, \
128 const wxString& name = wxPG_LABEL, \
130 virtual ~CLASSNAME(); \
133 #define WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY(CLASSNAME) \
134 WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY_WITH_DECL(CLASSNAME, class)
136 // This will create interface for wxFlagsProperty derived class
138 #define WX_PG_IMPLEMENT_CUSTOM_FLAGS_PROPERTY(CLASSNAME,LABELS,VALUES,DEFVAL) \
139 WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME,wxFlagsProperty,long_##CLASSNAME,\
141 CLASSNAME::CLASSNAME( const wxString& label, \
142 const wxString& name, \
144 : wxFlagsProperty(label,name,LABELS,VALUES,value!=-1?value:DEFVAL) \
146 m_flags |= wxPG_PROP_STATIC_CHOICES; \
148 CLASSNAME::~CLASSNAME() { }
151 // -----------------------------------------------------------------------
153 #define WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY_WITH_DECL(CLASSNAME, DECL) \
154 class CLASSNAME : public wxEnumProperty \
156 WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
158 CLASSNAME( const wxString& label = wxPG_LABEL, \
159 const wxString& name = wxPG_LABEL, \
161 virtual ~CLASSNAME(); \
164 #define WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY(CLASSNAME) \
165 WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY_WITH_DECL(CLASSNAME, class)
167 #define WX_PG_IMPLEMENT_CUSTOM_ENUM_PROPERTY(CLASSNAME,LABELS,VALUES,DEFVAL) \
168 WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME, wxEnumProperty, long_##CLASSNAME, \
170 CLASSNAME::CLASSNAME( const wxString& label, const wxString& name, int value ) \
171 : wxEnumProperty(label,name,LABELS,VALUES,value!=-1?value:DEFVAL) \
173 m_flags |= wxPG_PROP_STATIC_CHOICES; \
175 CLASSNAME::~CLASSNAME() { }
178 // -----------------------------------------------------------------------
180 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, DECL) \
181 DECL CLASSNAME : public wxSystemColourProperty \
183 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
185 CLASSNAME( const wxString& label = wxPG_LABEL, \
186 const wxString& name = wxPG_LABEL, \
187 const wxColourPropertyValue& value = wxColourPropertyValue() ); \
188 virtual ~CLASSNAME(); \
189 virtual wxColour GetColour( int index ) const; \
192 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY(CLASSNAME) \
193 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, class)
195 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY(CLASSNAME,\
196 LABELS,VALUES,COLOURS) \
197 static wxPGChoices gs_##CLASSNAME##_choicesCache; \
198 WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(CLASSNAME, wxSystemColourProperty, \
199 const wxColourPropertyValue&) \
200 CLASSNAME::CLASSNAME( const wxString& label, const wxString& name, \
201 const wxColourPropertyValue& value ) \
202 : wxSystemColourProperty(label, name, LABELS, VALUES, \
203 &gs_##CLASSNAME##_choicesCache, value ) \
205 m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \
207 CLASSNAME::~CLASSNAME () { } \
208 wxColour CLASSNAME::GetColour ( int index ) const \
210 if ( !m_choices.HasValue(index) ) \
212 wxASSERT( index < (int)m_choices.GetCount() ); \
213 return COLOURS[index]; \
215 return COLOURS[m_choices.GetValue(index)]; \
218 // -----------------------------------------------------------------------
220 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME,\
222 DECL CLASSNAME : public wxSystemColourProperty \
224 WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
226 CLASSNAME( const wxString& label = wxPG_LABEL, \
227 const wxString& name = wxPG_LABEL, \
228 const wxColour& value = wxColour() ); \
229 virtual ~CLASSNAME(); \
230 virtual wxString GetValueAsString( int argFlags ) const; \
231 virtual wxColour GetColour( int index ) const; \
232 virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const; \
233 void Init( wxColour colour ); \
236 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME) \
237 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME, class)
239 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \
244 static wxPGChoices gs_##CLASSNAME##_choicesCache; \
245 WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME, wxSystemColourProperty, \
246 wxColour, const wxColour&,EDITOR) \
247 CLASSNAME::CLASSNAME( const wxString& label, \
248 const wxString& name, \
249 const wxColour& value ) \
250 : wxSystemColourProperty(label, name, LABELS, VALUES, \
251 &gs_##CLASSNAME##_choicesCache, value ) \
257 m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \
259 CLASSNAME::~CLASSNAME() { } \
260 void CLASSNAME::Init( wxColour colour ) \
262 if ( !colour.Ok() ) \
267 int ind = ColToInd(colour); \
269 ind = m_choices.GetCount() - 1; \
272 wxString CLASSNAME::GetValueAsString( int argFlags ) const \
274 const wxPGEditor* editor = GetEditorClass(); \
275 if ( editor != wxPG_EDITOR(Choice) && \
276 editor != wxPG_EDITOR(ChoiceAndButton) && \
277 editor != wxPG_EDITOR(ComboBox) ) \
278 argFlags |= wxPG_PROPERTY_SPECIFIC; \
279 return wxSystemColourProperty::GetValueAsString(argFlags); \
281 wxColour CLASSNAME::GetColour( int index ) const \
283 if ( !m_choices.HasValue(index) ) \
285 wxASSERT( index < (int)GetItemCount() ); \
286 return COLOURS[index]; \
288 return COLOURS[m_choices.GetValue(index)]; \
290 wxVariant CLASSNAME::DoTranslateVal( wxColourPropertyValue& v ) const \
293 variant << v.m_colour; \
298 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME, \
302 WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \
308 // -----------------------------------------------------------------------
311 // These macros help creating DoGetValidator
312 #define WX_PG_DOGETVALIDATOR_ENTRY() \
313 static wxValidator* s_ptr = (wxValidator*) NULL; \
314 if ( s_ptr ) return s_ptr;
316 // Common function exit
317 #define WX_PG_DOGETVALIDATOR_EXIT(VALIDATOR) \
319 wxPGGlobalVars->m_arrValidators.Add( (void*) VALIDATOR ); \
322 // -----------------------------------------------------------------------
326 /** @class wxPGInDialogValidator
328 Creates and manages a temporary wxTextCtrl for validation purposes.
329 Uses wxPropertyGrid's current editor, if available.
331 class WXDLLIMPEXP_PROPGRID wxPGInDialogValidator
334 wxPGInDialogValidator()
339 ~wxPGInDialogValidator()
342 m_textCtrl
->Destroy();
345 bool DoValidate( wxPropertyGrid
* propGrid
,
346 wxValidator
* validator
,
347 const wxString
& value
);
350 wxTextCtrl
* m_textCtrl
;
356 // -----------------------------------------------------------------------
358 // -----------------------------------------------------------------------
360 #define wxPG_PROP_PASSWORD wxPG_PROP_CLASS_SPECIFIC_2
362 /** @class wxStringProperty
364 Basic property with string value.
366 <b>Supported special attributes:</b>
367 - "Password": set to 1 inorder to enable wxTE_PASSWORD on the editor.
370 - If value "<composed>" is set, then actual value is formed (or composed)
371 from values of child properties.
373 class WXDLLIMPEXP_PROPGRID wxStringProperty
: public wxPGProperty
375 WX_PG_DECLARE_PROPERTY_CLASS(wxStringProperty
)
377 wxStringProperty( const wxString
& label
= wxPG_LABEL
,
378 const wxString
& name
= wxPG_LABEL
,
379 const wxString
& value
= wxEmptyString
);
380 virtual ~wxStringProperty();
382 WX_PG_DECLARE_BASIC_TYPE_METHODS()
383 WX_PG_DECLARE_ATTRIBUTE_METHODS()
385 /** This is updated so "<composed>" special value can be handled.
387 virtual void OnSetValue();
392 // -----------------------------------------------------------------------
395 /** Constants used with DoValidation() methods.
399 /** Instead of modifying the value, show an error message.
401 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
= 0,
403 /** Modify value, but stick with the limitations.
405 wxPG_PROPERTY_VALIDATION_SATURATE
= 1,
407 /** Modify value, wrap around on overflow.
409 wxPG_PROPERTY_VALIDATION_WRAP
= 2
413 // -----------------------------------------------------------------------
415 /** @class wxIntProperty
417 Basic property with integer value.
419 Seamlessly supports 64-bit integer (wxLongLong) on overflow.
421 <b>Example how to use seamless 64-bit integer support</b>
426 wxLongLong_t value = pg->GetPropertyValueAsLongLong();
433 wxVariant variant = property->GetValue();
434 if ( variant.GetType() == "wxLongLong" )
435 value = wxLongLongFromVariant(variant);
437 value = variant.GetLong();
443 pg->SetPropertyValue(longLongVal);
449 property->SetValue(WXVARIANT(longLongVal));
453 <b>Supported special attributes:</b>
454 - "Min", "Max": Specify acceptable value range.
456 class WXDLLIMPEXP_PROPGRID wxIntProperty
: public wxPGProperty
458 WX_PG_DECLARE_PROPERTY_CLASS(wxIntProperty
)
460 wxIntProperty( const wxString
& label
= wxPG_LABEL
,
461 const wxString
& name
= wxPG_LABEL
,
463 virtual ~wxIntProperty();
465 wxIntProperty( const wxString
& label
,
466 const wxString
& name
,
467 const wxLongLong
& value
);
468 WX_PG_DECLARE_BASIC_TYPE_METHODS()
469 virtual bool ValidateValue( wxVariant
& value
,
470 wxPGValidationInfo
& validationInfo
) const;
471 virtual bool IntToValue( wxVariant
& variant
,
473 int argFlags
= 0 ) const;
474 static wxValidator
* GetClassValidator();
475 virtual wxValidator
* DoGetValidator() const;
477 /** Validation helper.
479 static bool DoValidation( const wxPGProperty
* property
,
481 wxPGValidationInfo
* pValidationInfo
,
483 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
488 // -----------------------------------------------------------------------
490 /** @class wxUIntProperty
492 Basic property with unsigned integer value.
493 Seamlessly supports 64-bit integer (wxULongLong) on overflow.
495 <b>Supported special attributes:</b>
496 - "Min", "Max": Specify acceptable value range.
497 - "Base": Define base. Valid constants are wxPG_BASE_OCT, wxPG_BASE_DEC,
498 wxPG_BASE_HEX and wxPG_BASE_HEXL (lowercase characters). Arbitrary bases
499 are <b>not</b> supported.
500 - "Prefix": Possible values are wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and
501 wxPG_PREFIX_DOLLAR_SIGN. Only wxPG_PREFIX_NONE works with Decimal and Octal
505 - For example how to use seamless 64-bit integer support, see wxIntProperty
506 documentation (just use wxULongLong instead of wxLongLong).
508 class WXDLLIMPEXP_PROPGRID wxUIntProperty
: public wxPGProperty
510 WX_PG_DECLARE_PROPERTY_CLASS(wxUIntProperty
)
512 wxUIntProperty( const wxString
& label
= wxPG_LABEL
,
513 const wxString
& name
= wxPG_LABEL
,
514 unsigned long value
= 0 );
515 virtual ~wxUIntProperty();
516 wxUIntProperty( const wxString
& label
,
517 const wxString
& name
,
518 const wxULongLong
& value
);
519 WX_PG_DECLARE_BASIC_TYPE_METHODS()
520 WX_PG_DECLARE_ATTRIBUTE_METHODS()
521 virtual bool ValidateValue( wxVariant
& value
,
522 wxPGValidationInfo
& validationInfo
) const;
523 virtual bool IntToValue( wxVariant
& variant
,
525 int argFlags
= 0 ) const;
528 wxByte m_realBase
; // translated to 8,16,etc.
534 // -----------------------------------------------------------------------
536 /** @class wxFloatProperty
538 Basic property with double-precision floating point value.
540 <b>Supported special attributes:</b>
541 - "Precision": Sets the (max) precision used when floating point value is
542 rendered as text. The default -1 means infinite precision.
544 class WXDLLIMPEXP_PROPGRID wxFloatProperty
: public wxPGProperty
546 WX_PG_DECLARE_PROPERTY_CLASS(wxFloatProperty
)
548 wxFloatProperty( const wxString
& label
= wxPG_LABEL
,
549 const wxString
& name
= wxPG_LABEL
,
550 double value
= 0.0 );
551 virtual ~wxFloatProperty();
553 WX_PG_DECLARE_BASIC_TYPE_METHODS()
554 WX_PG_DECLARE_ATTRIBUTE_METHODS()
555 virtual bool ValidateValue( wxVariant
& value
,
556 wxPGValidationInfo
& validationInfo
) const;
558 /** Validation helper.
560 static bool DoValidation( const wxPGProperty
* property
,
562 wxPGValidationInfo
* pValidationInfo
,
564 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
568 virtual wxValidator
* DoGetValidator () const;
571 // -----------------------------------------------------------------------
573 // Exclude class from wxPython bindings
576 /** @class wxBoolProperty
578 Basic property with boolean value.
580 <b>Supported special attributes:</b>
581 - "UseCheckbox": Set to 1 to use check box editor instead of combo box.
582 - "UseDClickCycling": Set to 1 to cycle combo box instead showing the list.
584 class WXDLLIMPEXP_PROPGRID wxBoolProperty
: public wxPGProperty
586 WX_PG_DECLARE_PROPERTY_CLASS(wxBoolProperty
)
588 wxBoolProperty( const wxString
& label
= wxPG_LABEL
,
589 const wxString
& name
= wxPG_LABEL
,
590 bool value
= false );
591 virtual ~wxBoolProperty();
593 WX_PG_DECLARE_BASIC_TYPE_METHODS()
594 WX_PG_DECLARE_CHOICE_METHODS()
595 WX_PG_DECLARE_ATTRIBUTE_METHODS()
600 // -----------------------------------------------------------------------
602 /** @class wxBaseEnumProperty
604 Derive dynamic custom properties with choices from this class.
607 - Updating private index is important. You can do this either by calling
608 SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue
609 be called (by not implementing it, or by calling super class function in
610 it) -OR- you can just call SetIndex in OnSetValue.
612 class WXDLLIMPEXP_PROPGRID wxBaseEnumProperty
: public wxPGProperty
615 wxBaseEnumProperty( const wxString
& label
= wxPG_LABEL
,
616 const wxString
& name
= wxPG_LABEL
);
618 virtual void OnSetValue();
619 virtual wxString
GetValueAsString( int argFlags
) const;
620 virtual bool StringToValue( wxVariant
& variant
,
621 const wxString
& text
,
622 int argFlags
= 0 ) const;
623 virtual bool ValidateValue( wxVariant
& value
,
624 wxPGValidationInfo
& validationInfo
) const;
626 // If wxPG_FULL_VALUE is not set in flags, then the value is interpreted
627 // as index to choices list. Otherwise, it is actual value.
628 virtual bool IntToValue( wxVariant
& variant
,
630 int argFlags
= 0 ) const;
633 // Additional virtuals
635 // This must be overridden to have non-index based value
636 virtual int GetIndexForValue( int value
) const;
638 // This returns string and value for index
639 // Returns NULL if beyond last item
640 // pvalue is never NULL - always set it.
641 virtual const wxString
* GetEntry( size_t index
, int* pvalue
) const = 0;
643 int GetValueForIndex( size_t index
) const
646 GetEntry( index
, &v
);
652 int GetIndex() const;
653 void SetIndex( int index
);
655 bool ValueFromString_( wxVariant
& value
,
656 const wxString
& text
,
657 int argFlags
) const;
658 bool ValueFromInt_( wxVariant
& value
, int intVal
, int argFlags
) const;
660 static void ResetNextIndex() { ms_nextIndex
= -2; }
663 // This is private so that classes are guaranteed to use GetIndex
664 // for up-to-date index value.
667 // Relies on ValidateValue being called always before OnSetValue
668 static int ms_nextIndex
;
671 // -----------------------------------------------------------------------
673 // If set, then selection of choices is static and should not be
674 // changed (i.e. returns NULL in GetPropertyChoices).
675 #define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1
677 /** @class wxEnumProperty
679 You can derive custom properties with choices from this class. See
680 wxBaseEnumProperty for remarks.
682 class WXDLLIMPEXP_PROPGRID wxEnumProperty
: public wxBaseEnumProperty
684 WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty
)
688 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
689 const wxString
& name
= wxPG_LABEL
,
690 const wxChar
** labels
= NULL
,
691 const long* values
= NULL
,
693 wxEnumProperty( const wxString
& label
,
694 const wxString
& name
,
695 wxPGChoices
& choices
,
698 // Special constructor for caching choices (used by derived class)
699 wxEnumProperty( const wxString
& label
,
700 const wxString
& name
,
701 const wxChar
** labels
,
703 wxPGChoices
* choicesCache
,
706 wxEnumProperty( const wxString
& label
,
707 const wxString
& name
,
708 const wxArrayString
& labels
,
709 const wxArrayInt
& values
= wxArrayInt(),
712 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
713 const wxString
& name
= wxPG_LABEL
,
714 const wxArrayString
& labels
= wxArrayString(),
715 const wxArrayInt
& values
= wxArrayInt(),
719 virtual ~wxEnumProperty();
721 virtual int GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
);
722 virtual int GetIndexForValue( int value
) const;
723 virtual const wxString
* GetEntry( size_t index
, int* pvalue
) const;
725 size_t GetItemCount() const { return m_choices
.GetCount(); }
726 const wxPGChoices
& GetChoices() const { return m_choices
; }
729 wxPGChoices 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 // this is necessary for conveying m_choices
821 virtual int GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
);
824 size_t GetItemCount() const { return m_choices
.GetCount(); }
825 const wxString
& GetLabel( size_t ind
) const
826 { return m_choices
.GetLabel(ind
); }
829 wxPGChoices m_choices
;
831 // Used to detect if choices have been changed
832 wxPGChoicesData
* m_oldChoicesData
;
834 // Needed to properly mark changed sub-properties
837 // Converts string id to a relevant bit.
838 long IdToBit( const wxString
& id
) const;
840 // Creates children and sets value.
844 // -----------------------------------------------------------------------
846 /** @class wxPGFileDialogAdapter
849 class WXDLLIMPEXP_PROPGRID
850 wxPGFileDialogAdapter
: public wxPGEditorDialogAdapter
853 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
854 wxPGProperty
* property
);
857 // -----------------------------------------------------------------------
859 #include "wx/filename.h"
861 // Indicates first bit useable by derived properties.
862 #define wxPG_PROP_SHOW_FULL_FILENAME wxPG_PROP_CLASS_SPECIFIC_1
864 /** @class wxFileProperty
866 Like wxLongStringProperty, but the button triggers file selector instead.
868 <b>Supported special attributes:</b>
869 - "Wildcard": Sets wildcard (see wxFileDialog for format details), "All
870 files..." is default.
871 - "ShowFullPath": Default 1. When 0, only the file name is shown (i.e. drive
872 and directory are hidden).
873 - "ShowRelativePath": If set, then the filename is shown relative to the
875 - "InitialPath": Sets the initial path of where to look for files.
876 - "DialogTitle": Sets a specific title for the dir dialog.
878 class WXDLLIMPEXP_PROPGRID wxFileProperty
: public wxPGProperty
880 friend class wxPGFileDialogAdapter
;
881 WX_PG_DECLARE_PROPERTY_CLASS(wxFileProperty
)
884 wxFileProperty( const wxString
& label
= wxPG_LABEL
,
885 const wxString
& name
= wxPG_LABEL
,
886 const wxString
& value
= wxEmptyString
);
887 virtual ~wxFileProperty ();
889 virtual void OnSetValue();
890 virtual wxString
GetValueAsString( int argFlags
) const;
891 virtual bool StringToValue( wxVariant
& variant
,
892 const wxString
& text
,
893 int argFlags
= 0 ) const;
894 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
896 WX_PG_DECLARE_ATTRIBUTE_METHODS()
898 static wxValidator
* GetClassValidator();
899 virtual wxValidator
* DoGetValidator() const;
903 wxString m_basePath
; // If set, then show path relative to it
904 wxString m_initialPath
; // If set, start the file dialog here
905 wxString m_dlgTitle
; // If set, used as title for file dialog
906 wxFileName m_filename
; // used as primary storage
907 int m_indFilter
; // index to the selected filter
910 // -----------------------------------------------------------------------
912 #define wxPG_PROP_NO_ESCAPE wxPG_PROP_CLASS_SPECIFIC_1
915 /** @class wxPGLongStringDialogAdapter
918 class WXDLLIMPEXP_PROPGRID
919 wxPGLongStringDialogAdapter
: public wxPGEditorDialogAdapter
922 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
923 wxPGProperty
* property
);
927 /** @class wxLongStringProperty
929 Like wxStringProperty, but has a button that triggers a small text
932 class WXDLLIMPEXP_PROPGRID wxLongStringProperty
: public wxPGProperty
934 WX_PG_DECLARE_PROPERTY_CLASS(wxLongStringProperty
)
937 wxLongStringProperty( const wxString
& label
= wxPG_LABEL
,
938 const wxString
& name
= wxPG_LABEL
,
939 const wxString
& value
= wxEmptyString
);
940 virtual ~wxLongStringProperty();
942 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
943 virtual bool StringToValue( wxVariant
& variant
,
944 const wxString
& text
,
945 int argFlags
= 0 ) const;
947 WX_PG_DECLARE_EVENT_METHODS()
949 // Shows string editor dialog. Value to be edited should be read from
950 // value, and if dialog is not cancelled, it should be stored back and true
951 // should be returned if that was the case.
952 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
, wxString
& value
);
954 static bool DisplayEditorDialog( wxPGProperty
* prop
,
955 wxPropertyGrid
* propGrid
,
961 // -----------------------------------------------------------------------
964 // Exclude class from wxPython bindings
967 /** @class wxDirProperty
969 Like wxLongStringProperty, but the button triggers dir selector instead.
971 <b>Supported special attributes:</b>
972 - "DialogMessage": Sets specific message in the dir selector.
974 class WXDLLIMPEXP_PROPGRID wxDirProperty
: public wxLongStringProperty
977 DECLARE_DYNAMIC_CLASS(wxDirProperty
)
980 wxDirProperty( const wxString
& name
= wxPG_LABEL
,
981 const wxString
& label
= wxPG_LABEL
,
982 const wxString
& value
= wxEmptyString
);
983 virtual ~wxDirProperty();
985 WX_PG_DECLARE_ATTRIBUTE_METHODS()
986 WX_PG_DECLARE_VALIDATOR_METHODS()
988 virtual bool OnButtonClick ( wxPropertyGrid
* propGrid
, wxString
& value
);
991 wxString m_dlgMessage
;
996 // -----------------------------------------------------------------------
998 // wxBoolProperty specific flags
999 #define wxPG_PROP_USE_CHECKBOX wxPG_PROP_CLASS_SPECIFIC_1
1000 // DCC = Double Click Cycles
1001 #define wxPG_PROP_USE_DCC wxPG_PROP_CLASS_SPECIFIC_2
1004 // -----------------------------------------------------------------------
1006 /** @class wxArrayStringProperty
1008 Property that manages a list of strings.
1010 class WXDLLIMPEXP_PROPGRID wxArrayStringProperty
: public wxPGProperty
1012 WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty
)
1015 wxArrayStringProperty( const wxString
& label
= wxPG_LABEL
,
1016 const wxString
& name
= wxPG_LABEL
,
1017 const wxArrayString
& value
= wxArrayString() );
1018 virtual ~wxArrayStringProperty();
1020 virtual void OnSetValue();
1021 WX_PG_DECLARE_BASIC_TYPE_METHODS()
1022 WX_PG_DECLARE_EVENT_METHODS()
1024 virtual void GenerateValueAsString();
1026 // Shows string editor dialog. Value to be edited should be read from
1027 // value, and if dialog is not cancelled, it should be stored back and true
1028 // should be returned if that was the case.
1029 virtual bool OnCustomStringEdit( wxWindow
* parent
, wxString
& value
);
1032 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
,
1034 const wxChar
* cbt
);
1037 // Creates wxArrayEditorDialog for string editing. Called in OnButtonClick.
1038 virtual wxArrayEditorDialog
* CreateEditorDialog();
1042 wxString m_display
; // Cache for displayed text.
1045 // -----------------------------------------------------------------------
1047 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, \
1049 DECL PROPNAME : public wxArrayStringProperty \
1051 WX_PG_DECLARE_PROPERTY_CLASS(PROPNAME) \
1053 PROPNAME( const wxString& label = wxPG_LABEL, \
1054 const wxString& name = wxPG_LABEL, \
1055 const wxArrayString& value = wxArrayString() ); \
1057 virtual void GenerateValueAsString(); \
1058 virtual bool StringToValue( wxVariant& value, \
1059 const wxString& text, int = 0 ) const; \
1060 virtual bool OnEvent( wxPropertyGrid* propgrid, \
1061 wxWindow* primary, wxEvent& event ); \
1062 virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \
1063 WX_PG_DECLARE_VALIDATOR_METHODS() \
1066 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM) \
1067 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM, class)
1069 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
1072 WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME, wxArrayStringProperty, \
1073 wxArrayString, const wxArrayString&, \
1074 TextCtrlAndButton) \
1075 PROPNAME::PROPNAME( const wxString& label, \
1076 const wxString& name, \
1077 const wxArrayString& value ) \
1078 : wxArrayStringProperty(label,name,value) \
1080 PROPNAME::GenerateValueAsString(); \
1082 PROPNAME::~PROPNAME() { } \
1083 void PROPNAME::GenerateValueAsString() \
1085 wxChar delimChar = DELIMCHAR; \
1086 if ( delimChar == wxS('"') ) \
1087 wxArrayStringProperty::GenerateValueAsString(); \
1089 wxPropertyGrid::ArrayStringToString(m_display, \
1090 m_value.GetArrayString(), \
1093 bool PROPNAME::StringToValue( wxVariant& variant, \
1094 const wxString& text, int ) const \
1096 wxChar delimChar = DELIMCHAR; \
1097 if ( delimChar == wxS('"') ) \
1098 return wxArrayStringProperty::StringToValue(variant, text, 0); \
1100 wxArrayString arr; \
1101 WX_PG_TOKENIZER1_BEGIN(text,DELIMCHAR) \
1103 WX_PG_TOKENIZER1_END() \
1107 bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
1108 wxWindow* primary, wxEvent& event ) \
1110 if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) \
1111 return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \
1115 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \
1116 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME)
1118 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_DECL(PROPNAME, DECL) \
1119 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, DECL)
1121 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \
1122 WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
1125 wxValidator* PROPNAME::DoGetValidator () const \
1126 { return (wxValidator*) NULL; }
1129 // -----------------------------------------------------------------------
1130 // wxArrayEditorDialog
1131 // -----------------------------------------------------------------------
1133 #include "wx/textctrl.h"
1134 #include "wx/button.h"
1135 #include "wx/listbox.h"
1137 #define wxAEDIALOG_STYLE \
1138 (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
1140 class WXDLLIMPEXP_PROPGRID wxArrayEditorDialog
: public wxDialog
1143 wxArrayEditorDialog();
1144 virtual ~wxArrayEditorDialog() { }
1148 wxArrayEditorDialog( wxWindow
*parent
,
1149 const wxString
& message
,
1150 const wxString
& caption
,
1151 long style
= wxAEDIALOG_STYLE
,
1152 const wxPoint
& pos
= wxDefaultPosition
,
1153 const wxSize
& sz
= wxDefaultSize
);
1155 bool Create( wxWindow
*parent
,
1156 const wxString
& message
,
1157 const wxString
& caption
,
1158 long style
= wxAEDIALOG_STYLE
,
1159 const wxPoint
& pos
= wxDefaultPosition
,
1160 const wxSize
& sz
= wxDefaultSize
);
1162 /** Set value modified by dialog.
1164 virtual void SetDialogValue( const wxVariant
& WXUNUSED(value
) )
1166 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
1169 /** Return value modified by dialog.
1171 virtual wxVariant
GetDialogValue() const
1173 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
1177 /** Override to return wxValidator to be used with the wxTextCtrl
1178 in dialog. Note that the validator is used in the standard
1179 wx way, ie. it immediately prevents user from entering invalid
1183 Dialog frees the validator.
1185 virtual wxValidator
* GetTextCtrlValidator() const
1187 return (wxValidator
*) NULL
;
1190 // Returns true if array was actually modified
1191 bool IsModified() const { return m_modified
; }
1193 //const wxArrayString& GetStrings() const { return m_array; }
1195 // implementation from now on
1196 void OnUpdateClick(wxCommandEvent
& event
);
1197 void OnAddClick(wxCommandEvent
& event
);
1198 void OnDeleteClick(wxCommandEvent
& event
);
1199 void OnListBoxClick(wxCommandEvent
& event
);
1200 void OnUpClick(wxCommandEvent
& event
);
1201 void OnDownClick(wxCommandEvent
& event
);
1202 //void OnCustomEditClick(wxCommandEvent& event);
1203 void OnIdle(wxIdleEvent
& event
);
1206 wxTextCtrl
* m_edValue
;
1207 wxListBox
* m_lbStrings
;
1209 wxButton
* m_butAdd
; // Button pointers
1210 wxButton
* m_butCustom
; // required for disabling/enabling changing.
1211 wxButton
* m_butUpdate
;
1212 wxButton
* m_butRemove
;
1214 wxButton
* m_butDown
;
1216 //wxArrayString m_array;
1218 const wxChar
* m_custBtText
;
1219 //wxArrayStringPropertyClass* m_pCallingClass;
1223 unsigned char m_curFocus
;
1225 // These must be overridden - must return true on success.
1226 virtual wxString
ArrayGet( size_t index
) = 0;
1227 virtual size_t ArrayGetCount() = 0;
1228 virtual bool ArrayInsert( const wxString
& str
, int index
) = 0;
1229 virtual bool ArraySet( size_t index
, const wxString
& str
) = 0;
1230 virtual void ArrayRemoveAt( int index
) = 0;
1231 virtual void ArraySwap( size_t first
, size_t second
) = 0;
1235 DECLARE_DYNAMIC_CLASS_NO_COPY(wxArrayEditorDialog
)
1236 DECLARE_EVENT_TABLE()
1240 // -----------------------------------------------------------------------
1241 // wxPGArrayStringEditorDialog
1242 // -----------------------------------------------------------------------
1244 class WXDLLIMPEXP_PROPGRID
1245 wxPGArrayStringEditorDialog
: public wxArrayEditorDialog
1248 wxPGArrayStringEditorDialog();
1249 virtual ~wxPGArrayStringEditorDialog() { }
1253 virtual void SetDialogValue( const wxVariant
& value
)
1255 m_array
= value
.GetArrayString();
1258 virtual wxVariant
GetDialogValue() const
1263 void SetCustomButton( const wxChar
* custBtText
, wxArrayStringProperty
* pcc
)
1265 m_custBtText
= custBtText
;
1266 m_pCallingClass
= pcc
;
1269 void OnCustomEditClick(wxCommandEvent
& event
);
1272 wxArrayString m_array
;
1274 wxArrayStringProperty
* m_pCallingClass
;
1276 virtual wxString
ArrayGet( size_t index
);
1277 virtual size_t ArrayGetCount();
1278 virtual bool ArrayInsert( const wxString
& str
, int index
);
1279 virtual bool ArraySet( size_t index
, const wxString
& str
);
1280 virtual void ArrayRemoveAt( int index
);
1281 virtual void ArraySwap( size_t first
, size_t second
);
1285 DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog
)
1286 DECLARE_EVENT_TABLE()
1290 // -----------------------------------------------------------------------
1292 #endif // wxUSE_PROPGRID
1294 #endif // _WX_PROPGRID_PROPS_H_