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 // Property class implementation helper macros.
29 // Adds constructor function as well.
30 #define WX_PG_IMPLEMENT_PROPERTY_CLASS2(NAME,CLASSNAME,\
31 UPCLASS,T,T_AS_ARG,EDITOR) \
32 IMPLEMENT_DYNAMIC_CLASS(NAME, UPCLASS) \
33 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(NAME,T,EDITOR)
36 #define WX_PG_IMPLEMENT_PROPERTY_CLASS(NAME,UPNAME,T,T_AS_ARG,EDITOR) \
37 WX_PG_IMPLEMENT_PROPERTY_CLASS2(NAME,NAME,UPNAME,T,T_AS_ARG,EDITOR)
39 // -----------------------------------------------------------------------
41 #define wxPG_NO_ESCAPE wxPG_PROP_NO_ESCAPE // No escape sequences
42 #define wxPG_ESCAPE 0 // Escape sequences
44 #define WX_PG_DECLARE_STRING_PROPERTY_WITH_DECL(NAME, DECL) \
45 DECL NAME : public wxLongStringProperty \
47 DECLARE_DYNAMIC_CLASS(NAME) \
49 NAME( const wxString& name = wxPG_LABEL, \
50 const wxString& label = wxPG_LABEL, \
51 const wxString& value = wxEmptyString); \
53 virtual bool OnButtonClick( wxPropertyGrid* propgrid, wxString& value ); \
54 virtual wxValidator* DoGetValidator() const; \
57 #define WX_PG_DECLARE_STRING_PROPERTY(NAME) \
58 WX_PG_DECLARE_STRING_PROPERTY_WITH_DECL(NAME, class) \
60 #define WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(NAME, FLAGS) \
61 IMPLEMENT_DYNAMIC_CLASS(NAME,wxLongStringProperty) \
62 NAME::NAME( const wxString& name, \
63 const wxString& label, \
64 const wxString& value ) \
65 : wxLongStringProperty(name,label,value) \
71 #define WX_PG_IMPLEMENT_STRING_PROPERTY(NAME, FLAGS) \
72 WX_PG_IMPLEMENT_STRING_PROPERTY_WITH_VALIDATOR(NAME,FLAGS) \
73 wxValidator* NAME::DoGetValidator () const \
74 { return (wxValidator*) NULL; }
76 // -----------------------------------------------------------------------
78 #define WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY_WITH_DECL(CLASSNAME,DECL) \
79 DECL CLASSNAME : public wxFlagsProperty \
81 WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
83 CLASSNAME( const wxString& label = wxPG_LABEL, \
84 const wxString& name = wxPG_LABEL, \
86 virtual ~CLASSNAME(); \
89 #define WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY(CLASSNAME) \
90 WX_PG_DECLARE_CUSTOM_FLAGS_PROPERTY_WITH_DECL(CLASSNAME, class)
92 // This will create interface for wxFlagsProperty derived class
94 #define WX_PG_IMPLEMENT_CUSTOM_FLAGS_PROPERTY(CLASSNAME,LABELS,VALUES,DEFVAL) \
95 WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME,wxFlagsProperty,long_##CLASSNAME,\
97 CLASSNAME::CLASSNAME( const wxString& label, \
98 const wxString& name, \
100 : wxFlagsProperty(label,name,LABELS,VALUES,value!=-1?value:DEFVAL) \
102 m_flags |= wxPG_PROP_STATIC_CHOICES; \
104 CLASSNAME::~CLASSNAME() { }
107 // -----------------------------------------------------------------------
109 #define WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY_WITH_DECL(CLASSNAME, DECL) \
110 class CLASSNAME : public wxEnumProperty \
112 WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
114 CLASSNAME( const wxString& label = wxPG_LABEL, \
115 const wxString& name = wxPG_LABEL, \
117 virtual ~CLASSNAME(); \
120 #define WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY(CLASSNAME) \
121 WX_PG_DECLARE_CUSTOM_ENUM_PROPERTY_WITH_DECL(CLASSNAME, class)
123 #define WX_PG_IMPLEMENT_CUSTOM_ENUM_PROPERTY(CLASSNAME,LABELS,VALUES,DEFVAL) \
124 WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME, wxEnumProperty, long_##CLASSNAME, \
126 CLASSNAME::CLASSNAME( const wxString& label, const wxString& name, int value ) \
127 : wxEnumProperty(label,name,LABELS,VALUES,value!=-1?value:DEFVAL) \
129 m_flags |= wxPG_PROP_STATIC_CHOICES; \
131 CLASSNAME::~CLASSNAME() { }
134 // -----------------------------------------------------------------------
136 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, DECL) \
137 DECL CLASSNAME : public wxSystemColourProperty \
139 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
141 CLASSNAME( const wxString& label = wxPG_LABEL, \
142 const wxString& name = wxPG_LABEL, \
143 const wxColourPropertyValue& value = wxColourPropertyValue() ); \
144 virtual ~CLASSNAME(); \
145 virtual wxColour GetColour( int index ) const; \
148 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY(CLASSNAME) \
149 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, class)
151 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY(CLASSNAME,\
152 LABELS,VALUES,COLOURS) \
153 static wxPGChoices gs_##CLASSNAME##_choicesCache; \
154 IMPLEMENT_DYNAMIC_CLASS(CLASSNAME, wxSystemColourProperty) \
155 CLASSNAME::CLASSNAME( const wxString& label, const wxString& name, \
156 const wxColourPropertyValue& value ) \
157 : wxSystemColourProperty(label, name, LABELS, VALUES, \
158 &gs_##CLASSNAME##_choicesCache, value ) \
160 m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \
162 CLASSNAME::~CLASSNAME () { } \
163 wxColour CLASSNAME::GetColour ( int index ) const \
165 if ( !m_choices.HasValue(index) ) \
167 wxASSERT( index < (int)m_choices.GetCount() ); \
168 return COLOURS[index]; \
170 return COLOURS[m_choices.GetValue(index)]; \
173 // -----------------------------------------------------------------------
175 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME,\
177 DECL CLASSNAME : public wxSystemColourProperty \
179 WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
181 CLASSNAME( const wxString& label = wxPG_LABEL, \
182 const wxString& name = wxPG_LABEL, \
183 const wxColour& value = wxColour() ); \
184 virtual ~CLASSNAME(); \
185 virtual wxString GetValueAsString( int argFlags ) const; \
186 virtual wxColour GetColour( int index ) const; \
187 virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const; \
188 void Init( wxColour colour ); \
191 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME) \
192 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME, class)
194 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \
199 static wxPGChoices gs_##CLASSNAME##_choicesCache; \
200 WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME, wxSystemColourProperty, \
201 wxColour, const wxColour&,EDITOR) \
202 CLASSNAME::CLASSNAME( const wxString& label, \
203 const wxString& name, \
204 const wxColour& value ) \
205 : wxSystemColourProperty(label, name, LABELS, VALUES, \
206 &gs_##CLASSNAME##_choicesCache, value ) \
212 m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \
214 CLASSNAME::~CLASSNAME() { } \
215 void CLASSNAME::Init( wxColour colour ) \
217 if ( !colour.Ok() ) \
222 int ind = ColToInd(colour); \
224 ind = m_choices.GetCount() - 1; \
227 wxString CLASSNAME::GetValueAsString( int argFlags ) const \
229 const wxPGEditor* editor = GetEditorClass(); \
230 if ( editor != wxPG_EDITOR(Choice) && \
231 editor != wxPG_EDITOR(ChoiceAndButton) && \
232 editor != wxPG_EDITOR(ComboBox) ) \
233 argFlags |= wxPG_PROPERTY_SPECIFIC; \
234 return wxSystemColourProperty::GetValueAsString(argFlags); \
236 wxColour CLASSNAME::GetColour( int index ) const \
238 if ( !m_choices.HasValue(index) ) \
240 wxASSERT( index < (int)GetItemCount() ); \
241 return COLOURS[index]; \
243 return COLOURS[m_choices.GetValue(index)]; \
245 wxVariant CLASSNAME::DoTranslateVal( wxColourPropertyValue& v ) const \
248 variant << v.m_colour; \
253 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME, \
257 WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \
263 // -----------------------------------------------------------------------
266 // These macros help creating DoGetValidator
267 #define WX_PG_DOGETVALIDATOR_ENTRY() \
268 static wxValidator* s_ptr = (wxValidator*) NULL; \
269 if ( s_ptr ) return s_ptr;
271 // Common function exit
272 #define WX_PG_DOGETVALIDATOR_EXIT(VALIDATOR) \
274 wxPGGlobalVars->m_arrValidators.Add( (void*) VALIDATOR ); \
277 // -----------------------------------------------------------------------
281 /** @class wxPGInDialogValidator
283 Creates and manages a temporary wxTextCtrl for validation purposes.
284 Uses wxPropertyGrid's current editor, if available.
286 class WXDLLIMPEXP_PROPGRID wxPGInDialogValidator
289 wxPGInDialogValidator()
294 ~wxPGInDialogValidator()
297 m_textCtrl
->Destroy();
300 bool DoValidate( wxPropertyGrid
* propGrid
,
301 wxValidator
* validator
,
302 const wxString
& value
);
305 wxTextCtrl
* m_textCtrl
;
311 // -----------------------------------------------------------------------
313 // -----------------------------------------------------------------------
315 #define wxPG_PROP_PASSWORD wxPG_PROP_CLASS_SPECIFIC_2
317 /** @class wxStringProperty
319 Basic property with string value.
321 <b>Supported special attributes:</b>
322 - "Password": set to 1 inorder to enable wxTE_PASSWORD on the editor.
325 - If value "<composed>" is set, then actual value is formed (or composed)
326 from values of child properties.
328 class WXDLLIMPEXP_PROPGRID wxStringProperty
: public wxPGProperty
330 WX_PG_DECLARE_PROPERTY_CLASS(wxStringProperty
)
332 wxStringProperty( const wxString
& label
= wxPG_LABEL
,
333 const wxString
& name
= wxPG_LABEL
,
334 const wxString
& value
= wxEmptyString
);
335 virtual ~wxStringProperty();
337 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
338 virtual bool StringToValue( wxVariant
& variant
,
339 const wxString
& text
,
340 int argFlags
= 0 ) const;
342 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
344 /** This is updated so "<composed>" special value can be handled.
346 virtual void OnSetValue();
351 // -----------------------------------------------------------------------
354 /** Constants used with DoValidation() methods.
358 /** Instead of modifying the value, show an error message.
360 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
= 0,
362 /** Modify value, but stick with the limitations.
364 wxPG_PROPERTY_VALIDATION_SATURATE
= 1,
366 /** Modify value, wrap around on overflow.
368 wxPG_PROPERTY_VALIDATION_WRAP
= 2
372 // -----------------------------------------------------------------------
374 /** @class wxIntProperty
376 Basic property with integer value.
378 Seamlessly supports 64-bit integer (wxLongLong) on overflow.
380 <b>Example how to use seamless 64-bit integer support</b>
385 wxLongLong_t value = pg->GetPropertyValueAsLongLong();
392 wxVariant variant = property->GetValue();
393 if ( variant.GetType() == "wxLongLong" )
394 value = wxLongLongFromVariant(variant);
396 value = variant.GetLong();
402 pg->SetPropertyValue(longLongVal);
408 property->SetValue(WXVARIANT(longLongVal));
412 <b>Supported special attributes:</b>
413 - "Min", "Max": Specify acceptable value range.
415 class WXDLLIMPEXP_PROPGRID wxIntProperty
: public wxPGProperty
417 WX_PG_DECLARE_PROPERTY_CLASS(wxIntProperty
)
419 wxIntProperty( const wxString
& label
= wxPG_LABEL
,
420 const wxString
& name
= wxPG_LABEL
,
422 virtual ~wxIntProperty();
424 wxIntProperty( const wxString
& label
,
425 const wxString
& name
,
426 const wxLongLong
& value
);
427 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
428 virtual bool StringToValue( wxVariant
& variant
,
429 const wxString
& text
,
430 int argFlags
= 0 ) const;
431 virtual bool ValidateValue( wxVariant
& value
,
432 wxPGValidationInfo
& validationInfo
) const;
433 virtual bool IntToValue( wxVariant
& variant
,
435 int argFlags
= 0 ) const;
436 static wxValidator
* GetClassValidator();
437 virtual wxValidator
* DoGetValidator() const;
439 /** Validation helper.
441 static bool DoValidation( const wxPGProperty
* property
,
443 wxPGValidationInfo
* pValidationInfo
,
445 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
450 // -----------------------------------------------------------------------
452 /** @class wxUIntProperty
454 Basic property with unsigned integer value.
455 Seamlessly supports 64-bit integer (wxULongLong) on overflow.
457 <b>Supported special attributes:</b>
458 - "Min", "Max": Specify acceptable value range.
459 - "Base": Define base. Valid constants are wxPG_BASE_OCT, wxPG_BASE_DEC,
460 wxPG_BASE_HEX and wxPG_BASE_HEXL (lowercase characters). Arbitrary bases
461 are <b>not</b> supported.
462 - "Prefix": Possible values are wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and
463 wxPG_PREFIX_DOLLAR_SIGN. Only wxPG_PREFIX_NONE works with Decimal and Octal
467 - For example how to use seamless 64-bit integer support, see wxIntProperty
468 documentation (just use wxULongLong instead of wxLongLong).
470 class WXDLLIMPEXP_PROPGRID wxUIntProperty
: public wxPGProperty
472 WX_PG_DECLARE_PROPERTY_CLASS(wxUIntProperty
)
474 wxUIntProperty( const wxString
& label
= wxPG_LABEL
,
475 const wxString
& name
= wxPG_LABEL
,
476 unsigned long value
= 0 );
477 virtual ~wxUIntProperty();
478 wxUIntProperty( const wxString
& label
,
479 const wxString
& name
,
480 const wxULongLong
& value
);
481 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
482 virtual bool StringToValue( wxVariant
& variant
,
483 const wxString
& text
,
484 int argFlags
= 0 ) const;
485 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
486 virtual bool ValidateValue( wxVariant
& value
,
487 wxPGValidationInfo
& validationInfo
) const;
488 virtual bool IntToValue( wxVariant
& variant
,
490 int argFlags
= 0 ) const;
493 wxByte m_realBase
; // translated to 8,16,etc.
499 // -----------------------------------------------------------------------
501 /** @class wxFloatProperty
503 Basic property with double-precision floating point value.
505 <b>Supported special attributes:</b>
506 - "Precision": Sets the (max) precision used when floating point value is
507 rendered as text. The default -1 means infinite precision.
509 class WXDLLIMPEXP_PROPGRID wxFloatProperty
: public wxPGProperty
511 WX_PG_DECLARE_PROPERTY_CLASS(wxFloatProperty
)
513 wxFloatProperty( const wxString
& label
= wxPG_LABEL
,
514 const wxString
& name
= wxPG_LABEL
,
515 double value
= 0.0 );
516 virtual ~wxFloatProperty();
518 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
519 virtual bool StringToValue( wxVariant
& variant
,
520 const wxString
& text
,
521 int argFlags
= 0 ) const;
522 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
523 virtual bool ValidateValue( wxVariant
& value
,
524 wxPGValidationInfo
& validationInfo
) const;
526 /** Validation helper.
528 static bool DoValidation( const wxPGProperty
* property
,
530 wxPGValidationInfo
* pValidationInfo
,
532 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
536 virtual wxValidator
* DoGetValidator () const;
539 // -----------------------------------------------------------------------
541 // Exclude class from wxPython bindings
544 /** @class wxBoolProperty
546 Basic property with boolean value.
548 <b>Supported special attributes:</b>
549 - "UseCheckbox": Set to 1 to use check box editor instead of combo box.
550 - "UseDClickCycling": Set to 1 to cycle combo box instead showing the list.
552 class WXDLLIMPEXP_PROPGRID wxBoolProperty
: public wxPGProperty
554 WX_PG_DECLARE_PROPERTY_CLASS(wxBoolProperty
)
556 wxBoolProperty( const wxString
& label
= wxPG_LABEL
,
557 const wxString
& name
= wxPG_LABEL
,
558 bool value
= false );
559 virtual ~wxBoolProperty();
561 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
562 virtual bool StringToValue( wxVariant
& variant
,
563 const wxString
& text
,
564 int argFlags
= 0 ) const;
565 virtual bool IntToValue( wxVariant
& variant
,
566 int number
, int argFlags
= 0 ) const;
567 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
572 // -----------------------------------------------------------------------
574 /** @class wxBaseEnumProperty
576 Derive dynamic custom properties with choices from this class.
579 - Updating private index is important. You can do this either by calling
580 SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue
581 be called (by not implementing it, or by calling super class function in
582 it) -OR- you can just call SetIndex in OnSetValue.
584 class WXDLLIMPEXP_PROPGRID wxBaseEnumProperty
: public wxPGProperty
587 wxBaseEnumProperty( const wxString
& label
= wxPG_LABEL
,
588 const wxString
& name
= wxPG_LABEL
);
590 virtual void OnSetValue();
591 virtual wxString
GetValueAsString( int argFlags
) const;
592 virtual bool StringToValue( wxVariant
& variant
,
593 const wxString
& text
,
594 int argFlags
= 0 ) const;
595 virtual bool ValidateValue( wxVariant
& value
,
596 wxPGValidationInfo
& validationInfo
) const;
598 // If wxPG_FULL_VALUE is not set in flags, then the value is interpreted
599 // as index to choices list. Otherwise, it is actual value.
600 virtual bool IntToValue( wxVariant
& variant
,
602 int argFlags
= 0 ) const;
605 // Additional virtuals
607 // This must be overridden to have non-index based value
608 virtual int GetIndexForValue( int value
) const;
610 // This returns string and value for index
611 // Returns NULL if beyond last item
612 // pvalue is never NULL - always set it.
613 virtual const wxString
* GetEntry( size_t index
, int* pvalue
) const = 0;
615 // GetChoiceSelection needs to overridden since m_index is
616 // the true index, and various property classes derived from
617 // this take advantage of it.
618 virtual int GetChoiceSelection() const { return m_index
; }
620 int GetValueForIndex( size_t index
) const
623 GetEntry( index
, &v
);
629 int GetIndex() const;
630 void SetIndex( int index
);
632 bool ValueFromString_( wxVariant
& value
,
633 const wxString
& text
,
634 int argFlags
) const;
635 bool ValueFromInt_( wxVariant
& value
, int intVal
, int argFlags
) const;
637 static void ResetNextIndex() { ms_nextIndex
= -2; }
640 // This is private so that classes are guaranteed to use GetIndex
641 // for up-to-date index value.
644 // Relies on ValidateValue being called always before OnSetValue
645 static int ms_nextIndex
;
648 // -----------------------------------------------------------------------
650 // If set, then selection of choices is static and should not be
651 // changed (i.e. returns NULL in GetPropertyChoices).
652 #define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1
654 /** @class wxEnumProperty
656 You can derive custom properties with choices from this class. See
657 wxBaseEnumProperty for remarks.
659 class WXDLLIMPEXP_PROPGRID wxEnumProperty
: public wxBaseEnumProperty
661 WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty
)
665 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
666 const wxString
& name
= wxPG_LABEL
,
667 const wxChar
** labels
= NULL
,
668 const long* values
= NULL
,
670 wxEnumProperty( const wxString
& label
,
671 const wxString
& name
,
672 wxPGChoices
& choices
,
675 // Special constructor for caching choices (used by derived class)
676 wxEnumProperty( const wxString
& label
,
677 const wxString
& name
,
678 const wxChar
** labels
,
680 wxPGChoices
* choicesCache
,
683 wxEnumProperty( const wxString
& label
,
684 const wxString
& name
,
685 const wxArrayString
& labels
,
686 const wxArrayInt
& values
= wxArrayInt(),
689 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
690 const wxString
& name
= wxPG_LABEL
,
691 const wxArrayString
& labels
= wxArrayString(),
692 const wxArrayInt
& values
= wxArrayInt(),
696 virtual ~wxEnumProperty();
698 virtual int GetIndexForValue( int value
) const;
699 virtual const wxString
* GetEntry( size_t index
, int* pvalue
) const;
701 size_t GetItemCount() const { return m_choices
.GetCount(); }
702 const wxPGChoices
& GetChoices() const { return m_choices
; }
705 // -----------------------------------------------------------------------
707 /** @class wxEditEnumProperty
709 wxEnumProperty with wxString value and writable combo box editor.
712 Uses int value, similar to wxEnumProperty, unless text entered by user is
713 is not in choices (in which case string value is used).
715 class WXDLLIMPEXP_PROPGRID wxEditEnumProperty
: public wxEnumProperty
717 WX_PG_DECLARE_PROPERTY_CLASS(wxEditEnumProperty
)
720 wxEditEnumProperty( const wxString
& label
,
721 const wxString
& name
,
722 const wxChar
** labels
,
724 const wxString
& value
);
725 wxEditEnumProperty( const wxString
& label
= wxPG_LABEL
,
726 const wxString
& name
= wxPG_LABEL
,
727 const wxArrayString
& labels
= wxArrayString(),
728 const wxArrayInt
& values
= wxArrayInt(),
729 const wxString
& value
= wxEmptyString
);
730 wxEditEnumProperty( const wxString
& label
,
731 const wxString
& name
,
732 wxPGChoices
& choices
,
733 const wxString
& value
= wxEmptyString
);
735 // Special constructor for caching choices (used by derived class)
736 wxEditEnumProperty( const wxString
& label
,
737 const wxString
& name
,
738 const wxChar
** labels
,
740 wxPGChoices
* choicesCache
,
741 const wxString
& value
);
743 virtual ~wxEditEnumProperty();
748 // -----------------------------------------------------------------------
750 /** @class wxFlagsProperty
752 Represents a bit set that fits in a long integer. wxBoolProperty
753 sub-properties are created for editing individual bits. Textctrl is created
754 to manually edit the flags as a text; a continous sequence of spaces,
755 commas and semicolons is considered as a flag id separator.
756 <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
757 you will need to use SetPropertyChoices - otherwise they will not get
760 class WXDLLIMPEXP_PROPGRID wxFlagsProperty
: public wxPGProperty
762 WX_PG_DECLARE_PROPERTY_CLASS(wxFlagsProperty
)
766 wxFlagsProperty( const wxString
& label
,
767 const wxString
& name
,
768 const wxChar
** labels
,
769 const long* values
= NULL
,
771 wxFlagsProperty( const wxString
& label
,
772 const wxString
& name
,
773 wxPGChoices
& choices
,
776 wxFlagsProperty( const wxString
& label
= wxPG_LABEL
,
777 const wxString
& name
= wxPG_LABEL
,
778 const wxArrayString
& labels
= wxArrayString(),
779 const wxArrayInt
& values
= wxArrayInt(),
781 virtual ~wxFlagsProperty ();
783 virtual void OnSetValue();
784 virtual wxString
GetValueAsString( int argFlags
) const;
785 virtual bool StringToValue( wxVariant
& variant
,
786 const wxString
& text
,
788 virtual void ChildChanged( wxVariant
& thisValue
,
790 wxVariant
& childValue
) const;
791 virtual void RefreshChildren();
793 // GetChoiceSelection needs to overridden since m_choices is
794 // used and value is integer, but it is not index.
795 virtual int GetChoiceSelection() const { return wxNOT_FOUND
; }
798 size_t GetItemCount() const { return m_choices
.GetCount(); }
799 const wxString
& GetLabel( size_t ind
) const
800 { return m_choices
.GetLabel(ind
); }
803 // Used to detect if choices have been changed
804 wxPGChoicesData
* m_oldChoicesData
;
806 // Needed to properly mark changed sub-properties
809 // Converts string id to a relevant bit.
810 long IdToBit( const wxString
& id
) const;
812 // Creates children and sets value.
816 // -----------------------------------------------------------------------
818 /** @class wxPGFileDialogAdapter
821 class WXDLLIMPEXP_PROPGRID
822 wxPGFileDialogAdapter
: public wxPGEditorDialogAdapter
825 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
826 wxPGProperty
* property
);
829 // -----------------------------------------------------------------------
831 #include "wx/filename.h"
833 // Indicates first bit useable by derived properties.
834 #define wxPG_PROP_SHOW_FULL_FILENAME wxPG_PROP_CLASS_SPECIFIC_1
836 /** @class wxFileProperty
838 Like wxLongStringProperty, but the button triggers file selector instead.
840 <b>Supported special attributes:</b>
841 - "Wildcard": Sets wildcard (see wxFileDialog for format details), "All
842 files..." is default.
843 - "ShowFullPath": Default 1. When 0, only the file name is shown (i.e. drive
844 and directory are hidden).
845 - "ShowRelativePath": If set, then the filename is shown relative to the
847 - "InitialPath": Sets the initial path of where to look for files.
848 - "DialogTitle": Sets a specific title for the dir dialog.
850 class WXDLLIMPEXP_PROPGRID wxFileProperty
: public wxPGProperty
852 friend class wxPGFileDialogAdapter
;
853 WX_PG_DECLARE_PROPERTY_CLASS(wxFileProperty
)
856 wxFileProperty( const wxString
& label
= wxPG_LABEL
,
857 const wxString
& name
= wxPG_LABEL
,
858 const wxString
& value
= wxEmptyString
);
859 virtual ~wxFileProperty ();
861 virtual void OnSetValue();
862 virtual wxString
GetValueAsString( int argFlags
) const;
863 virtual bool StringToValue( wxVariant
& variant
,
864 const wxString
& text
,
865 int argFlags
= 0 ) const;
866 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
867 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
869 static wxValidator
* GetClassValidator();
870 virtual wxValidator
* DoGetValidator() const;
874 wxString m_basePath
; // If set, then show path relative to it
875 wxString m_initialPath
; // If set, start the file dialog here
876 wxString m_dlgTitle
; // If set, used as title for file dialog
877 wxFileName m_filename
; // used as primary storage
878 int m_indFilter
; // index to the selected filter
881 // -----------------------------------------------------------------------
883 #define wxPG_PROP_NO_ESCAPE wxPG_PROP_CLASS_SPECIFIC_1
886 /** @class wxPGLongStringDialogAdapter
889 class WXDLLIMPEXP_PROPGRID
890 wxPGLongStringDialogAdapter
: public wxPGEditorDialogAdapter
893 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
894 wxPGProperty
* property
);
898 /** @class wxLongStringProperty
900 Like wxStringProperty, but has a button that triggers a small text
903 class WXDLLIMPEXP_PROPGRID wxLongStringProperty
: public wxPGProperty
905 WX_PG_DECLARE_PROPERTY_CLASS(wxLongStringProperty
)
908 wxLongStringProperty( const wxString
& label
= wxPG_LABEL
,
909 const wxString
& name
= wxPG_LABEL
,
910 const wxString
& value
= wxEmptyString
);
911 virtual ~wxLongStringProperty();
913 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
914 virtual bool StringToValue( wxVariant
& variant
,
915 const wxString
& text
,
916 int argFlags
= 0 ) const;
917 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
918 wxWindow
* primary
, wxEvent
& event
);
920 // Shows string editor dialog. Value to be edited should be read from
921 // value, and if dialog is not cancelled, it should be stored back and true
922 // should be returned if that was the case.
923 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
, wxString
& value
);
925 static bool DisplayEditorDialog( wxPGProperty
* prop
,
926 wxPropertyGrid
* propGrid
,
932 // -----------------------------------------------------------------------
935 // Exclude class from wxPython bindings
938 /** @class wxDirProperty
940 Like wxLongStringProperty, but the button triggers dir selector instead.
942 <b>Supported special attributes:</b>
943 - "DialogMessage": Sets specific message in the dir selector.
945 class WXDLLIMPEXP_PROPGRID wxDirProperty
: public wxLongStringProperty
948 DECLARE_DYNAMIC_CLASS(wxDirProperty
)
951 wxDirProperty( const wxString
& name
= wxPG_LABEL
,
952 const wxString
& label
= wxPG_LABEL
,
953 const wxString
& value
= wxEmptyString
);
954 virtual ~wxDirProperty();
956 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
957 virtual wxValidator
* DoGetValidator() const;
959 virtual bool OnButtonClick ( wxPropertyGrid
* propGrid
, wxString
& value
);
962 wxString m_dlgMessage
;
967 // -----------------------------------------------------------------------
969 // wxBoolProperty specific flags
970 #define wxPG_PROP_USE_CHECKBOX wxPG_PROP_CLASS_SPECIFIC_1
971 // DCC = Double Click Cycles
972 #define wxPG_PROP_USE_DCC wxPG_PROP_CLASS_SPECIFIC_2
975 // -----------------------------------------------------------------------
977 /** @class wxArrayStringProperty
979 Property that manages a list of strings.
981 class WXDLLIMPEXP_PROPGRID wxArrayStringProperty
: public wxPGProperty
983 WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty
)
986 wxArrayStringProperty( const wxString
& label
= wxPG_LABEL
,
987 const wxString
& name
= wxPG_LABEL
,
988 const wxArrayString
& value
= wxArrayString() );
989 virtual ~wxArrayStringProperty();
991 virtual void OnSetValue();
992 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
993 virtual bool StringToValue( wxVariant
& variant
,
994 const wxString
& text
,
995 int argFlags
= 0 ) const;
996 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
997 wxWindow
* primary
, wxEvent
& event
);
999 virtual void GenerateValueAsString();
1001 // Shows string editor dialog. Value to be edited should be read from
1002 // value, and if dialog is not cancelled, it should be stored back and true
1003 // should be returned if that was the case.
1004 virtual bool OnCustomStringEdit( wxWindow
* parent
, wxString
& value
);
1007 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
,
1009 const wxChar
* cbt
);
1012 // Creates wxArrayEditorDialog for string editing. Called in OnButtonClick.
1013 virtual wxArrayEditorDialog
* CreateEditorDialog();
1017 wxString m_display
; // Cache for displayed text.
1020 // -----------------------------------------------------------------------
1022 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, \
1024 DECL PROPNAME : public wxArrayStringProperty \
1026 WX_PG_DECLARE_PROPERTY_CLASS(PROPNAME) \
1028 PROPNAME( const wxString& label = wxPG_LABEL, \
1029 const wxString& name = wxPG_LABEL, \
1030 const wxArrayString& value = wxArrayString() ); \
1032 virtual void GenerateValueAsString(); \
1033 virtual bool StringToValue( wxVariant& value, \
1034 const wxString& text, int = 0 ) const; \
1035 virtual bool OnEvent( wxPropertyGrid* propgrid, \
1036 wxWindow* primary, wxEvent& event ); \
1037 virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \
1038 virtual wxValidator* DoGetValidator() const; \
1041 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM) \
1042 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM, class)
1044 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
1047 WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME, wxArrayStringProperty, \
1048 wxArrayString, const wxArrayString&, \
1049 TextCtrlAndButton) \
1050 PROPNAME::PROPNAME( const wxString& label, \
1051 const wxString& name, \
1052 const wxArrayString& value ) \
1053 : wxArrayStringProperty(label,name,value) \
1055 PROPNAME::GenerateValueAsString(); \
1057 PROPNAME::~PROPNAME() { } \
1058 void PROPNAME::GenerateValueAsString() \
1060 wxChar delimChar = DELIMCHAR; \
1061 if ( delimChar == wxS('"') ) \
1062 wxArrayStringProperty::GenerateValueAsString(); \
1064 wxPropertyGrid::ArrayStringToString(m_display, \
1065 m_value.GetArrayString(), \
1068 bool PROPNAME::StringToValue( wxVariant& variant, \
1069 const wxString& text, int ) const \
1071 wxChar delimChar = DELIMCHAR; \
1072 if ( delimChar == wxS('"') ) \
1073 return wxArrayStringProperty::StringToValue(variant, text, 0); \
1075 wxArrayString arr; \
1076 WX_PG_TOKENIZER1_BEGIN(text,DELIMCHAR) \
1078 WX_PG_TOKENIZER1_END() \
1082 bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
1083 wxWindow* primary, wxEvent& event ) \
1085 if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) \
1086 return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \
1090 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \
1091 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME)
1093 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_DECL(PROPNAME, DECL) \
1094 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, DECL)
1096 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \
1097 WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
1100 wxValidator* PROPNAME::DoGetValidator () const \
1101 { return (wxValidator*) NULL; }
1104 // -----------------------------------------------------------------------
1105 // wxArrayEditorDialog
1106 // -----------------------------------------------------------------------
1108 #include "wx/textctrl.h"
1109 #include "wx/button.h"
1110 #include "wx/listbox.h"
1112 #define wxAEDIALOG_STYLE \
1113 (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
1115 class WXDLLIMPEXP_PROPGRID wxArrayEditorDialog
: public wxDialog
1118 wxArrayEditorDialog();
1119 virtual ~wxArrayEditorDialog() { }
1123 wxArrayEditorDialog( wxWindow
*parent
,
1124 const wxString
& message
,
1125 const wxString
& caption
,
1126 long style
= wxAEDIALOG_STYLE
,
1127 const wxPoint
& pos
= wxDefaultPosition
,
1128 const wxSize
& sz
= wxDefaultSize
);
1130 bool Create( wxWindow
*parent
,
1131 const wxString
& message
,
1132 const wxString
& caption
,
1133 long style
= wxAEDIALOG_STYLE
,
1134 const wxPoint
& pos
= wxDefaultPosition
,
1135 const wxSize
& sz
= wxDefaultSize
);
1137 /** Set value modified by dialog.
1139 virtual void SetDialogValue( const wxVariant
& WXUNUSED(value
) )
1141 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
1144 /** Return value modified by dialog.
1146 virtual wxVariant
GetDialogValue() const
1148 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
1152 /** Override to return wxValidator to be used with the wxTextCtrl
1153 in dialog. Note that the validator is used in the standard
1154 wx way, ie. it immediately prevents user from entering invalid
1158 Dialog frees the validator.
1160 virtual wxValidator
* GetTextCtrlValidator() const
1162 return (wxValidator
*) NULL
;
1165 // Returns true if array was actually modified
1166 bool IsModified() const { return m_modified
; }
1168 //const wxArrayString& GetStrings() const { return m_array; }
1170 // implementation from now on
1171 void OnUpdateClick(wxCommandEvent
& event
);
1172 void OnAddClick(wxCommandEvent
& event
);
1173 void OnDeleteClick(wxCommandEvent
& event
);
1174 void OnListBoxClick(wxCommandEvent
& event
);
1175 void OnUpClick(wxCommandEvent
& event
);
1176 void OnDownClick(wxCommandEvent
& event
);
1177 //void OnCustomEditClick(wxCommandEvent& event);
1178 void OnIdle(wxIdleEvent
& event
);
1181 wxTextCtrl
* m_edValue
;
1182 wxListBox
* m_lbStrings
;
1184 wxButton
* m_butAdd
; // Button pointers
1185 wxButton
* m_butCustom
; // required for disabling/enabling changing.
1186 wxButton
* m_butUpdate
;
1187 wxButton
* m_butRemove
;
1189 wxButton
* m_butDown
;
1191 //wxArrayString m_array;
1193 const wxChar
* m_custBtText
;
1194 //wxArrayStringPropertyClass* m_pCallingClass;
1198 unsigned char m_curFocus
;
1200 // These must be overridden - must return true on success.
1201 virtual wxString
ArrayGet( size_t index
) = 0;
1202 virtual size_t ArrayGetCount() = 0;
1203 virtual bool ArrayInsert( const wxString
& str
, int index
) = 0;
1204 virtual bool ArraySet( size_t index
, const wxString
& str
) = 0;
1205 virtual void ArrayRemoveAt( int index
) = 0;
1206 virtual void ArraySwap( size_t first
, size_t second
) = 0;
1210 DECLARE_DYNAMIC_CLASS_NO_COPY(wxArrayEditorDialog
)
1211 DECLARE_EVENT_TABLE()
1215 // -----------------------------------------------------------------------
1216 // wxPGArrayStringEditorDialog
1217 // -----------------------------------------------------------------------
1219 class WXDLLIMPEXP_PROPGRID
1220 wxPGArrayStringEditorDialog
: public wxArrayEditorDialog
1223 wxPGArrayStringEditorDialog();
1224 virtual ~wxPGArrayStringEditorDialog() { }
1228 virtual void SetDialogValue( const wxVariant
& value
)
1230 m_array
= value
.GetArrayString();
1233 virtual wxVariant
GetDialogValue() const
1238 void SetCustomButton( const wxChar
* custBtText
, wxArrayStringProperty
* pcc
)
1240 m_custBtText
= custBtText
;
1241 m_pCallingClass
= pcc
;
1244 void OnCustomEditClick(wxCommandEvent
& event
);
1247 wxArrayString m_array
;
1249 wxArrayStringProperty
* m_pCallingClass
;
1251 virtual wxString
ArrayGet( size_t index
);
1252 virtual size_t ArrayGetCount();
1253 virtual bool ArrayInsert( const wxString
& str
, int index
);
1254 virtual bool ArraySet( size_t index
, const wxString
& str
);
1255 virtual void ArrayRemoveAt( int index
);
1256 virtual void ArraySwap( size_t first
, size_t second
);
1260 DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog
)
1261 DECLARE_EVENT_TABLE()
1265 // -----------------------------------------------------------------------
1267 #endif // wxUSE_PROPGRID
1269 #endif // _WX_PROPGRID_PROPS_H_