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_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, DECL) \
79 DECL CLASSNAME : public wxSystemColourProperty \
81 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
83 CLASSNAME( const wxString& label = wxPG_LABEL, \
84 const wxString& name = wxPG_LABEL, \
85 const wxColourPropertyValue& value = wxColourPropertyValue() ); \
86 virtual ~CLASSNAME(); \
87 virtual wxColour GetColour( int index ) const; \
90 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY(CLASSNAME) \
91 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, class)
93 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY(CLASSNAME,\
94 LABELS,VALUES,COLOURS) \
95 static wxPGChoices gs_##CLASSNAME##_choicesCache; \
96 IMPLEMENT_DYNAMIC_CLASS(CLASSNAME, wxSystemColourProperty) \
97 CLASSNAME::CLASSNAME( const wxString& label, const wxString& name, \
98 const wxColourPropertyValue& value ) \
99 : wxSystemColourProperty(label, name, LABELS, VALUES, \
100 &gs_##CLASSNAME##_choicesCache, value ) \
102 m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \
104 CLASSNAME::~CLASSNAME () { } \
105 wxColour CLASSNAME::GetColour ( int index ) const \
107 if ( !m_choices.HasValue(index) ) \
109 wxASSERT( index < (int)m_choices.GetCount() ); \
110 return COLOURS[index]; \
112 return COLOURS[m_choices.GetValue(index)]; \
115 // -----------------------------------------------------------------------
117 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME,\
119 DECL CLASSNAME : public wxSystemColourProperty \
121 WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
123 CLASSNAME( const wxString& label = wxPG_LABEL, \
124 const wxString& name = wxPG_LABEL, \
125 const wxColour& value = wxColour() ); \
126 virtual ~CLASSNAME(); \
127 virtual wxString GetValueAsString( int argFlags ) const; \
128 virtual wxColour GetColour( int index ) const; \
129 virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const; \
130 void Init( wxColour colour ); \
133 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME) \
134 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME, class)
136 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \
141 static wxPGChoices gs_##CLASSNAME##_choicesCache; \
142 WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME, wxSystemColourProperty, \
143 wxColour, const wxColour&,EDITOR) \
144 CLASSNAME::CLASSNAME( const wxString& label, \
145 const wxString& name, \
146 const wxColour& value ) \
147 : wxSystemColourProperty(label, name, LABELS, VALUES, \
148 &gs_##CLASSNAME##_choicesCache, value ) \
154 m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \
156 CLASSNAME::~CLASSNAME() { } \
157 void CLASSNAME::Init( wxColour colour ) \
159 if ( !colour.Ok() ) \
164 int ind = ColToInd(colour); \
166 ind = m_choices.GetCount() - 1; \
169 wxString CLASSNAME::GetValueAsString( int argFlags ) const \
171 const wxPGEditor* editor = GetEditorClass(); \
172 if ( editor != wxPG_EDITOR(Choice) && \
173 editor != wxPG_EDITOR(ChoiceAndButton) && \
174 editor != wxPG_EDITOR(ComboBox) ) \
175 argFlags |= wxPG_PROPERTY_SPECIFIC; \
176 return wxSystemColourProperty::GetValueAsString(argFlags); \
178 wxColour CLASSNAME::GetColour( int index ) const \
180 if ( !m_choices.HasValue(index) ) \
182 wxASSERT( index < (int)GetItemCount() ); \
183 return COLOURS[index]; \
185 return COLOURS[m_choices.GetValue(index)]; \
187 wxVariant CLASSNAME::DoTranslateVal( wxColourPropertyValue& v ) const \
190 variant << v.m_colour; \
195 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME, \
199 WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \
205 // -----------------------------------------------------------------------
208 // These macros help creating DoGetValidator
209 #define WX_PG_DOGETVALIDATOR_ENTRY() \
210 static wxValidator* s_ptr = (wxValidator*) NULL; \
211 if ( s_ptr ) return s_ptr;
213 // Common function exit
214 #define WX_PG_DOGETVALIDATOR_EXIT(VALIDATOR) \
216 wxPGGlobalVars->m_arrValidators.Add( (void*) VALIDATOR ); \
219 // -----------------------------------------------------------------------
223 /** @class wxPGInDialogValidator
225 Creates and manages a temporary wxTextCtrl for validation purposes.
226 Uses wxPropertyGrid's current editor, if available.
228 class WXDLLIMPEXP_PROPGRID wxPGInDialogValidator
231 wxPGInDialogValidator()
236 ~wxPGInDialogValidator()
239 m_textCtrl
->Destroy();
242 bool DoValidate( wxPropertyGrid
* propGrid
,
243 wxValidator
* validator
,
244 const wxString
& value
);
247 wxTextCtrl
* m_textCtrl
;
253 // -----------------------------------------------------------------------
255 // -----------------------------------------------------------------------
257 #define wxPG_PROP_PASSWORD wxPG_PROP_CLASS_SPECIFIC_2
259 /** @class wxStringProperty
261 Basic property with string value.
263 <b>Supported special attributes:</b>
264 - "Password": set to 1 inorder to enable wxTE_PASSWORD on the editor.
267 - If value "<composed>" is set, then actual value is formed (or composed)
268 from values of child properties.
270 class WXDLLIMPEXP_PROPGRID wxStringProperty
: public wxPGProperty
272 WX_PG_DECLARE_PROPERTY_CLASS(wxStringProperty
)
274 wxStringProperty( const wxString
& label
= wxPG_LABEL
,
275 const wxString
& name
= wxPG_LABEL
,
276 const wxString
& value
= wxEmptyString
);
277 virtual ~wxStringProperty();
279 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
280 virtual bool StringToValue( wxVariant
& variant
,
281 const wxString
& text
,
282 int argFlags
= 0 ) const;
284 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
286 /** This is updated so "<composed>" special value can be handled.
288 virtual void OnSetValue();
293 // -----------------------------------------------------------------------
296 /** Constants used with DoValidation() methods.
300 /** Instead of modifying the value, show an error message.
302 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
= 0,
304 /** Modify value, but stick with the limitations.
306 wxPG_PROPERTY_VALIDATION_SATURATE
= 1,
308 /** Modify value, wrap around on overflow.
310 wxPG_PROPERTY_VALIDATION_WRAP
= 2
314 // -----------------------------------------------------------------------
316 /** @class wxIntProperty
318 Basic property with integer value.
320 Seamlessly supports 64-bit integer (wxLongLong) on overflow.
322 <b>Example how to use seamless 64-bit integer support</b>
327 wxLongLong_t value = pg->GetPropertyValueAsLongLong();
334 wxVariant variant = property->GetValue();
335 if ( variant.GetType() == "wxLongLong" )
336 value = wxLongLongFromVariant(variant);
338 value = variant.GetLong();
344 pg->SetPropertyValue(longLongVal);
350 property->SetValue(WXVARIANT(longLongVal));
354 <b>Supported special attributes:</b>
355 - "Min", "Max": Specify acceptable value range.
357 class WXDLLIMPEXP_PROPGRID wxIntProperty
: public wxPGProperty
359 WX_PG_DECLARE_PROPERTY_CLASS(wxIntProperty
)
361 wxIntProperty( const wxString
& label
= wxPG_LABEL
,
362 const wxString
& name
= wxPG_LABEL
,
364 virtual ~wxIntProperty();
366 wxIntProperty( const wxString
& label
,
367 const wxString
& name
,
368 const wxLongLong
& value
);
369 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
370 virtual bool StringToValue( wxVariant
& variant
,
371 const wxString
& text
,
372 int argFlags
= 0 ) const;
373 virtual bool ValidateValue( wxVariant
& value
,
374 wxPGValidationInfo
& validationInfo
) const;
375 virtual bool IntToValue( wxVariant
& variant
,
377 int argFlags
= 0 ) const;
378 static wxValidator
* GetClassValidator();
379 virtual wxValidator
* DoGetValidator() const;
381 /** Validation helper.
383 static bool DoValidation( const wxPGProperty
* property
,
385 wxPGValidationInfo
* pValidationInfo
,
387 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
392 // -----------------------------------------------------------------------
394 /** @class wxUIntProperty
396 Basic property with unsigned integer value.
397 Seamlessly supports 64-bit integer (wxULongLong) on overflow.
399 <b>Supported special attributes:</b>
400 - "Min", "Max": Specify acceptable value range.
401 - "Base": Define base. Valid constants are wxPG_BASE_OCT, wxPG_BASE_DEC,
402 wxPG_BASE_HEX and wxPG_BASE_HEXL (lowercase characters). Arbitrary bases
403 are <b>not</b> supported.
404 - "Prefix": Possible values are wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and
405 wxPG_PREFIX_DOLLAR_SIGN. Only wxPG_PREFIX_NONE works with Decimal and Octal
409 - For example how to use seamless 64-bit integer support, see wxIntProperty
410 documentation (just use wxULongLong instead of wxLongLong).
412 class WXDLLIMPEXP_PROPGRID wxUIntProperty
: public wxPGProperty
414 WX_PG_DECLARE_PROPERTY_CLASS(wxUIntProperty
)
416 wxUIntProperty( const wxString
& label
= wxPG_LABEL
,
417 const wxString
& name
= wxPG_LABEL
,
418 unsigned long value
= 0 );
419 virtual ~wxUIntProperty();
420 wxUIntProperty( const wxString
& label
,
421 const wxString
& name
,
422 const wxULongLong
& value
);
423 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
424 virtual bool StringToValue( wxVariant
& variant
,
425 const wxString
& text
,
426 int argFlags
= 0 ) const;
427 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
428 virtual bool ValidateValue( wxVariant
& value
,
429 wxPGValidationInfo
& validationInfo
) const;
430 virtual bool IntToValue( wxVariant
& variant
,
432 int argFlags
= 0 ) const;
435 wxByte m_realBase
; // translated to 8,16,etc.
441 // -----------------------------------------------------------------------
443 /** @class wxFloatProperty
445 Basic property with double-precision floating point value.
447 <b>Supported special attributes:</b>
448 - "Precision": Sets the (max) precision used when floating point value is
449 rendered as text. The default -1 means infinite precision.
451 class WXDLLIMPEXP_PROPGRID wxFloatProperty
: public wxPGProperty
453 WX_PG_DECLARE_PROPERTY_CLASS(wxFloatProperty
)
455 wxFloatProperty( const wxString
& label
= wxPG_LABEL
,
456 const wxString
& name
= wxPG_LABEL
,
457 double value
= 0.0 );
458 virtual ~wxFloatProperty();
460 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
461 virtual bool StringToValue( wxVariant
& variant
,
462 const wxString
& text
,
463 int argFlags
= 0 ) const;
464 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
465 virtual bool ValidateValue( wxVariant
& value
,
466 wxPGValidationInfo
& validationInfo
) const;
468 /** Validation helper.
470 static bool DoValidation( const wxPGProperty
* property
,
472 wxPGValidationInfo
* pValidationInfo
,
474 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
478 virtual wxValidator
* DoGetValidator () const;
481 // -----------------------------------------------------------------------
483 // Exclude class from wxPython bindings
486 /** @class wxBoolProperty
488 Basic property with boolean value.
490 <b>Supported special attributes:</b>
491 - "UseCheckbox": Set to 1 to use check box editor instead of combo box.
492 - "UseDClickCycling": Set to 1 to cycle combo box instead showing the list.
494 class WXDLLIMPEXP_PROPGRID wxBoolProperty
: public wxPGProperty
496 WX_PG_DECLARE_PROPERTY_CLASS(wxBoolProperty
)
498 wxBoolProperty( const wxString
& label
= wxPG_LABEL
,
499 const wxString
& name
= wxPG_LABEL
,
500 bool value
= false );
501 virtual ~wxBoolProperty();
503 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
504 virtual bool StringToValue( wxVariant
& variant
,
505 const wxString
& text
,
506 int argFlags
= 0 ) const;
507 virtual bool IntToValue( wxVariant
& variant
,
508 int number
, int argFlags
= 0 ) const;
509 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
514 // -----------------------------------------------------------------------
516 /** @class wxBaseEnumProperty
518 Derive dynamic custom properties with choices from this class.
521 - Updating private index is important. You can do this either by calling
522 SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue
523 be called (by not implementing it, or by calling super class function in
524 it) -OR- you can just call SetIndex in OnSetValue.
526 class WXDLLIMPEXP_PROPGRID wxBaseEnumProperty
: public wxPGProperty
529 wxBaseEnumProperty( const wxString
& label
= wxPG_LABEL
,
530 const wxString
& name
= wxPG_LABEL
);
532 virtual void OnSetValue();
533 virtual wxString
GetValueAsString( int argFlags
) const;
534 virtual bool StringToValue( wxVariant
& variant
,
535 const wxString
& text
,
536 int argFlags
= 0 ) const;
537 virtual bool ValidateValue( wxVariant
& value
,
538 wxPGValidationInfo
& validationInfo
) const;
540 // If wxPG_FULL_VALUE is not set in flags, then the value is interpreted
541 // as index to choices list. Otherwise, it is actual value.
542 virtual bool IntToValue( wxVariant
& variant
,
544 int argFlags
= 0 ) const;
547 // Additional virtuals
549 // This must be overridden to have non-index based value
550 virtual int GetIndexForValue( int value
) const;
552 // This returns string and value for index
553 // Returns NULL if beyond last item
554 // pvalue is never NULL - always set it.
555 virtual const wxString
* GetEntry( size_t index
, int* pvalue
) const = 0;
557 // GetChoiceSelection needs to overridden since m_index is
558 // the true index, and various property classes derived from
559 // this take advantage of it.
560 virtual int GetChoiceSelection() const { return m_index
; }
562 int GetValueForIndex( size_t index
) const
565 GetEntry( index
, &v
);
571 int GetIndex() const;
572 void SetIndex( int index
);
574 bool ValueFromString_( wxVariant
& value
,
575 const wxString
& text
,
576 int argFlags
) const;
577 bool ValueFromInt_( wxVariant
& value
, int intVal
, int argFlags
) const;
579 static void ResetNextIndex() { ms_nextIndex
= -2; }
582 // This is private so that classes are guaranteed to use GetIndex
583 // for up-to-date index value.
586 // Relies on ValidateValue being called always before OnSetValue
587 static int ms_nextIndex
;
590 // -----------------------------------------------------------------------
592 // If set, then selection of choices is static and should not be
593 // changed (i.e. returns NULL in GetPropertyChoices).
594 #define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1
596 /** @class wxEnumProperty
598 You can derive custom properties with choices from this class. See
599 wxBaseEnumProperty for remarks.
601 class WXDLLIMPEXP_PROPGRID wxEnumProperty
: public wxBaseEnumProperty
603 WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty
)
607 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
608 const wxString
& name
= wxPG_LABEL
,
609 const wxChar
** labels
= NULL
,
610 const long* values
= NULL
,
612 wxEnumProperty( const wxString
& label
,
613 const wxString
& name
,
614 wxPGChoices
& choices
,
617 // Special constructor for caching choices (used by derived class)
618 wxEnumProperty( const wxString
& label
,
619 const wxString
& name
,
620 const wxChar
** labels
,
622 wxPGChoices
* choicesCache
,
625 wxEnumProperty( const wxString
& label
,
626 const wxString
& name
,
627 const wxArrayString
& labels
,
628 const wxArrayInt
& values
= wxArrayInt(),
631 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
632 const wxString
& name
= wxPG_LABEL
,
633 const wxArrayString
& labels
= wxArrayString(),
634 const wxArrayInt
& values
= wxArrayInt(),
638 virtual ~wxEnumProperty();
640 virtual int GetIndexForValue( int value
) const;
641 virtual const wxString
* GetEntry( size_t index
, int* pvalue
) const;
643 size_t GetItemCount() const { return m_choices
.GetCount(); }
644 const wxPGChoices
& GetChoices() const { return m_choices
; }
647 // -----------------------------------------------------------------------
649 /** @class wxEditEnumProperty
651 wxEnumProperty with wxString value and writable combo box editor.
654 Uses int value, similar to wxEnumProperty, unless text entered by user is
655 is not in choices (in which case string value is used).
657 class WXDLLIMPEXP_PROPGRID wxEditEnumProperty
: public wxEnumProperty
659 WX_PG_DECLARE_PROPERTY_CLASS(wxEditEnumProperty
)
662 wxEditEnumProperty( const wxString
& label
,
663 const wxString
& name
,
664 const wxChar
** labels
,
666 const wxString
& value
);
667 wxEditEnumProperty( const wxString
& label
= wxPG_LABEL
,
668 const wxString
& name
= wxPG_LABEL
,
669 const wxArrayString
& labels
= wxArrayString(),
670 const wxArrayInt
& values
= wxArrayInt(),
671 const wxString
& value
= wxEmptyString
);
672 wxEditEnumProperty( const wxString
& label
,
673 const wxString
& name
,
674 wxPGChoices
& choices
,
675 const wxString
& value
= wxEmptyString
);
677 // Special constructor for caching choices (used by derived class)
678 wxEditEnumProperty( const wxString
& label
,
679 const wxString
& name
,
680 const wxChar
** labels
,
682 wxPGChoices
* choicesCache
,
683 const wxString
& value
);
685 virtual ~wxEditEnumProperty();
690 // -----------------------------------------------------------------------
692 /** @class wxFlagsProperty
694 Represents a bit set that fits in a long integer. wxBoolProperty
695 sub-properties are created for editing individual bits. Textctrl is created
696 to manually edit the flags as a text; a continous sequence of spaces,
697 commas and semicolons is considered as a flag id separator.
698 <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
699 you will need to use SetPropertyChoices - otherwise they will not get
702 class WXDLLIMPEXP_PROPGRID wxFlagsProperty
: public wxPGProperty
704 WX_PG_DECLARE_PROPERTY_CLASS(wxFlagsProperty
)
708 wxFlagsProperty( const wxString
& label
,
709 const wxString
& name
,
710 const wxChar
** labels
,
711 const long* values
= NULL
,
713 wxFlagsProperty( const wxString
& label
,
714 const wxString
& name
,
715 wxPGChoices
& choices
,
718 wxFlagsProperty( const wxString
& label
= wxPG_LABEL
,
719 const wxString
& name
= wxPG_LABEL
,
720 const wxArrayString
& labels
= wxArrayString(),
721 const wxArrayInt
& values
= wxArrayInt(),
723 virtual ~wxFlagsProperty ();
725 virtual void OnSetValue();
726 virtual wxString
GetValueAsString( int argFlags
) const;
727 virtual bool StringToValue( wxVariant
& variant
,
728 const wxString
& text
,
730 virtual void ChildChanged( wxVariant
& thisValue
,
732 wxVariant
& childValue
) const;
733 virtual void RefreshChildren();
735 // GetChoiceSelection needs to overridden since m_choices is
736 // used and value is integer, but it is not index.
737 virtual int GetChoiceSelection() const { return wxNOT_FOUND
; }
740 size_t GetItemCount() const { return m_choices
.GetCount(); }
741 const wxString
& GetLabel( size_t ind
) const
742 { return m_choices
.GetLabel(ind
); }
745 // Used to detect if choices have been changed
746 wxPGChoicesData
* m_oldChoicesData
;
748 // Needed to properly mark changed sub-properties
751 // Converts string id to a relevant bit.
752 long IdToBit( const wxString
& id
) const;
754 // Creates children and sets value.
758 // -----------------------------------------------------------------------
760 /** @class wxPGFileDialogAdapter
763 class WXDLLIMPEXP_PROPGRID
764 wxPGFileDialogAdapter
: public wxPGEditorDialogAdapter
767 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
768 wxPGProperty
* property
);
771 // -----------------------------------------------------------------------
773 #include "wx/filename.h"
775 // Indicates first bit useable by derived properties.
776 #define wxPG_PROP_SHOW_FULL_FILENAME wxPG_PROP_CLASS_SPECIFIC_1
778 /** @class wxFileProperty
780 Like wxLongStringProperty, but the button triggers file selector instead.
782 <b>Supported special attributes:</b>
783 - "Wildcard": Sets wildcard (see wxFileDialog for format details), "All
784 files..." is default.
785 - "ShowFullPath": Default 1. When 0, only the file name is shown (i.e. drive
786 and directory are hidden).
787 - "ShowRelativePath": If set, then the filename is shown relative to the
789 - "InitialPath": Sets the initial path of where to look for files.
790 - "DialogTitle": Sets a specific title for the dir dialog.
792 class WXDLLIMPEXP_PROPGRID wxFileProperty
: public wxPGProperty
794 friend class wxPGFileDialogAdapter
;
795 WX_PG_DECLARE_PROPERTY_CLASS(wxFileProperty
)
798 wxFileProperty( const wxString
& label
= wxPG_LABEL
,
799 const wxString
& name
= wxPG_LABEL
,
800 const wxString
& value
= wxEmptyString
);
801 virtual ~wxFileProperty ();
803 virtual void OnSetValue();
804 virtual wxString
GetValueAsString( int argFlags
) const;
805 virtual bool StringToValue( wxVariant
& variant
,
806 const wxString
& text
,
807 int argFlags
= 0 ) const;
808 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
809 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
811 static wxValidator
* GetClassValidator();
812 virtual wxValidator
* DoGetValidator() const;
816 wxString m_basePath
; // If set, then show path relative to it
817 wxString m_initialPath
; // If set, start the file dialog here
818 wxString m_dlgTitle
; // If set, used as title for file dialog
819 wxFileName m_filename
; // used as primary storage
820 int m_indFilter
; // index to the selected filter
823 // -----------------------------------------------------------------------
825 #define wxPG_PROP_NO_ESCAPE wxPG_PROP_CLASS_SPECIFIC_1
828 /** @class wxPGLongStringDialogAdapter
831 class WXDLLIMPEXP_PROPGRID
832 wxPGLongStringDialogAdapter
: public wxPGEditorDialogAdapter
835 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
836 wxPGProperty
* property
);
840 /** @class wxLongStringProperty
842 Like wxStringProperty, but has a button that triggers a small text
845 class WXDLLIMPEXP_PROPGRID wxLongStringProperty
: public wxPGProperty
847 WX_PG_DECLARE_PROPERTY_CLASS(wxLongStringProperty
)
850 wxLongStringProperty( const wxString
& label
= wxPG_LABEL
,
851 const wxString
& name
= wxPG_LABEL
,
852 const wxString
& value
= wxEmptyString
);
853 virtual ~wxLongStringProperty();
855 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
856 virtual bool StringToValue( wxVariant
& variant
,
857 const wxString
& text
,
858 int argFlags
= 0 ) const;
859 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
860 wxWindow
* primary
, wxEvent
& event
);
862 // Shows string editor dialog. Value to be edited should be read from
863 // value, and if dialog is not cancelled, it should be stored back and true
864 // should be returned if that was the case.
865 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
, wxString
& value
);
867 static bool DisplayEditorDialog( wxPGProperty
* prop
,
868 wxPropertyGrid
* propGrid
,
874 // -----------------------------------------------------------------------
877 // Exclude class from wxPython bindings
880 /** @class wxDirProperty
882 Like wxLongStringProperty, but the button triggers dir selector instead.
884 <b>Supported special attributes:</b>
885 - "DialogMessage": Sets specific message in the dir selector.
887 class WXDLLIMPEXP_PROPGRID wxDirProperty
: public wxLongStringProperty
890 DECLARE_DYNAMIC_CLASS(wxDirProperty
)
893 wxDirProperty( const wxString
& name
= wxPG_LABEL
,
894 const wxString
& label
= wxPG_LABEL
,
895 const wxString
& value
= wxEmptyString
);
896 virtual ~wxDirProperty();
898 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
899 virtual wxValidator
* DoGetValidator() const;
901 virtual bool OnButtonClick ( wxPropertyGrid
* propGrid
, wxString
& value
);
904 wxString m_dlgMessage
;
909 // -----------------------------------------------------------------------
911 // wxBoolProperty specific flags
912 #define wxPG_PROP_USE_CHECKBOX wxPG_PROP_CLASS_SPECIFIC_1
913 // DCC = Double Click Cycles
914 #define wxPG_PROP_USE_DCC wxPG_PROP_CLASS_SPECIFIC_2
917 // -----------------------------------------------------------------------
919 /** @class wxArrayStringProperty
921 Property that manages a list of strings.
923 class WXDLLIMPEXP_PROPGRID wxArrayStringProperty
: public wxPGProperty
925 WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty
)
928 wxArrayStringProperty( const wxString
& label
= wxPG_LABEL
,
929 const wxString
& name
= wxPG_LABEL
,
930 const wxArrayString
& value
= wxArrayString() );
931 virtual ~wxArrayStringProperty();
933 virtual void OnSetValue();
934 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
935 virtual bool StringToValue( wxVariant
& variant
,
936 const wxString
& text
,
937 int argFlags
= 0 ) const;
938 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
939 wxWindow
* primary
, wxEvent
& event
);
941 virtual void GenerateValueAsString();
943 // Shows string editor dialog. Value to be edited should be read from
944 // value, and if dialog is not cancelled, it should be stored back and true
945 // should be returned if that was the case.
946 virtual bool OnCustomStringEdit( wxWindow
* parent
, wxString
& value
);
949 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
,
954 // Creates wxArrayEditorDialog for string editing. Called in OnButtonClick.
955 virtual wxArrayEditorDialog
* CreateEditorDialog();
959 wxString m_display
; // Cache for displayed text.
962 // -----------------------------------------------------------------------
964 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, \
966 DECL PROPNAME : public wxArrayStringProperty \
968 WX_PG_DECLARE_PROPERTY_CLASS(PROPNAME) \
970 PROPNAME( const wxString& label = wxPG_LABEL, \
971 const wxString& name = wxPG_LABEL, \
972 const wxArrayString& value = wxArrayString() ); \
974 virtual void GenerateValueAsString(); \
975 virtual bool StringToValue( wxVariant& value, \
976 const wxString& text, int = 0 ) const; \
977 virtual bool OnEvent( wxPropertyGrid* propgrid, \
978 wxWindow* primary, wxEvent& event ); \
979 virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \
980 virtual wxValidator* DoGetValidator() const; \
983 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM) \
984 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM, class)
986 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
989 WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME, wxArrayStringProperty, \
990 wxArrayString, const wxArrayString&, \
992 PROPNAME::PROPNAME( const wxString& label, \
993 const wxString& name, \
994 const wxArrayString& value ) \
995 : wxArrayStringProperty(label,name,value) \
997 PROPNAME::GenerateValueAsString(); \
999 PROPNAME::~PROPNAME() { } \
1000 void PROPNAME::GenerateValueAsString() \
1002 wxChar delimChar = DELIMCHAR; \
1003 if ( delimChar == wxS('"') ) \
1004 wxArrayStringProperty::GenerateValueAsString(); \
1006 wxPropertyGrid::ArrayStringToString(m_display, \
1007 m_value.GetArrayString(), \
1010 bool PROPNAME::StringToValue( wxVariant& variant, \
1011 const wxString& text, int ) const \
1013 wxChar delimChar = DELIMCHAR; \
1014 if ( delimChar == wxS('"') ) \
1015 return wxArrayStringProperty::StringToValue(variant, text, 0); \
1017 wxArrayString arr; \
1018 WX_PG_TOKENIZER1_BEGIN(text,DELIMCHAR) \
1020 WX_PG_TOKENIZER1_END() \
1024 bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
1025 wxWindow* primary, wxEvent& event ) \
1027 if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) \
1028 return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \
1032 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \
1033 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME)
1035 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_DECL(PROPNAME, DECL) \
1036 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, DECL)
1038 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \
1039 WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
1042 wxValidator* PROPNAME::DoGetValidator () const \
1043 { return (wxValidator*) NULL; }
1046 // -----------------------------------------------------------------------
1047 // wxArrayEditorDialog
1048 // -----------------------------------------------------------------------
1050 #include "wx/textctrl.h"
1051 #include "wx/button.h"
1052 #include "wx/listbox.h"
1054 #define wxAEDIALOG_STYLE \
1055 (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
1057 class WXDLLIMPEXP_PROPGRID wxArrayEditorDialog
: public wxDialog
1060 wxArrayEditorDialog();
1061 virtual ~wxArrayEditorDialog() { }
1065 wxArrayEditorDialog( wxWindow
*parent
,
1066 const wxString
& message
,
1067 const wxString
& caption
,
1068 long style
= wxAEDIALOG_STYLE
,
1069 const wxPoint
& pos
= wxDefaultPosition
,
1070 const wxSize
& sz
= wxDefaultSize
);
1072 bool Create( wxWindow
*parent
,
1073 const wxString
& message
,
1074 const wxString
& caption
,
1075 long style
= wxAEDIALOG_STYLE
,
1076 const wxPoint
& pos
= wxDefaultPosition
,
1077 const wxSize
& sz
= wxDefaultSize
);
1079 /** Set value modified by dialog.
1081 virtual void SetDialogValue( const wxVariant
& WXUNUSED(value
) )
1083 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
1086 /** Return value modified by dialog.
1088 virtual wxVariant
GetDialogValue() const
1090 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
1094 /** Override to return wxValidator to be used with the wxTextCtrl
1095 in dialog. Note that the validator is used in the standard
1096 wx way, ie. it immediately prevents user from entering invalid
1100 Dialog frees the validator.
1102 virtual wxValidator
* GetTextCtrlValidator() const
1104 return (wxValidator
*) NULL
;
1107 // Returns true if array was actually modified
1108 bool IsModified() const { return m_modified
; }
1110 //const wxArrayString& GetStrings() const { return m_array; }
1112 // implementation from now on
1113 void OnUpdateClick(wxCommandEvent
& event
);
1114 void OnAddClick(wxCommandEvent
& event
);
1115 void OnDeleteClick(wxCommandEvent
& event
);
1116 void OnListBoxClick(wxCommandEvent
& event
);
1117 void OnUpClick(wxCommandEvent
& event
);
1118 void OnDownClick(wxCommandEvent
& event
);
1119 //void OnCustomEditClick(wxCommandEvent& event);
1120 void OnIdle(wxIdleEvent
& event
);
1123 wxTextCtrl
* m_edValue
;
1124 wxListBox
* m_lbStrings
;
1126 wxButton
* m_butAdd
; // Button pointers
1127 wxButton
* m_butCustom
; // required for disabling/enabling changing.
1128 wxButton
* m_butUpdate
;
1129 wxButton
* m_butRemove
;
1131 wxButton
* m_butDown
;
1133 //wxArrayString m_array;
1135 const wxChar
* m_custBtText
;
1136 //wxArrayStringPropertyClass* m_pCallingClass;
1140 unsigned char m_curFocus
;
1142 // These must be overridden - must return true on success.
1143 virtual wxString
ArrayGet( size_t index
) = 0;
1144 virtual size_t ArrayGetCount() = 0;
1145 virtual bool ArrayInsert( const wxString
& str
, int index
) = 0;
1146 virtual bool ArraySet( size_t index
, const wxString
& str
) = 0;
1147 virtual void ArrayRemoveAt( int index
) = 0;
1148 virtual void ArraySwap( size_t first
, size_t second
) = 0;
1152 DECLARE_DYNAMIC_CLASS_NO_COPY(wxArrayEditorDialog
)
1153 DECLARE_EVENT_TABLE()
1157 // -----------------------------------------------------------------------
1158 // wxPGArrayStringEditorDialog
1159 // -----------------------------------------------------------------------
1161 class WXDLLIMPEXP_PROPGRID
1162 wxPGArrayStringEditorDialog
: public wxArrayEditorDialog
1165 wxPGArrayStringEditorDialog();
1166 virtual ~wxPGArrayStringEditorDialog() { }
1170 virtual void SetDialogValue( const wxVariant
& value
)
1172 m_array
= value
.GetArrayString();
1175 virtual wxVariant
GetDialogValue() const
1180 void SetCustomButton( const wxChar
* custBtText
, wxArrayStringProperty
* pcc
)
1182 m_custBtText
= custBtText
;
1183 m_pCallingClass
= pcc
;
1186 void OnCustomEditClick(wxCommandEvent
& event
);
1189 wxArrayString m_array
;
1191 wxArrayStringProperty
* m_pCallingClass
;
1193 virtual wxString
ArrayGet( size_t index
);
1194 virtual size_t ArrayGetCount();
1195 virtual bool ArrayInsert( const wxString
& str
, int index
);
1196 virtual bool ArraySet( size_t index
, const wxString
& str
);
1197 virtual void ArrayRemoveAt( int index
);
1198 virtual void ArraySwap( size_t first
, size_t second
);
1202 DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog
)
1203 DECLARE_EVENT_TABLE()
1207 // -----------------------------------------------------------------------
1209 #endif // wxUSE_PROPGRID
1211 #endif // _WX_PROPGRID_PROPS_H_