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.push_back( VALIDATOR ); \
219 // -----------------------------------------------------------------------
223 #include "wx/textctrl.h"
225 /** @class wxPGInDialogValidator
227 Creates and manages a temporary wxTextCtrl for validation purposes.
228 Uses wxPropertyGrid's current editor, if available.
230 class WXDLLIMPEXP_PROPGRID wxPGInDialogValidator
233 wxPGInDialogValidator()
238 ~wxPGInDialogValidator()
241 m_textCtrl
->Destroy();
244 bool DoValidate( wxPropertyGrid
* propGrid
,
245 wxValidator
* validator
,
246 const wxString
& value
);
249 wxTextCtrl
* m_textCtrl
;
255 // -----------------------------------------------------------------------
257 // -----------------------------------------------------------------------
259 #define wxPG_PROP_PASSWORD wxPG_PROP_CLASS_SPECIFIC_2
261 /** @class wxStringProperty
263 Basic property with string value.
265 <b>Supported special attributes:</b>
266 - "Password": set to 1 inorder to enable wxTE_PASSWORD on the editor.
269 - If value "<composed>" is set, then actual value is formed (or composed)
270 from values of child properties.
272 class WXDLLIMPEXP_PROPGRID wxStringProperty
: public wxPGProperty
274 WX_PG_DECLARE_PROPERTY_CLASS(wxStringProperty
)
276 wxStringProperty( const wxString
& label
= wxPG_LABEL
,
277 const wxString
& name
= wxPG_LABEL
,
278 const wxString
& value
= wxEmptyString
);
279 virtual ~wxStringProperty();
281 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
282 virtual bool StringToValue( wxVariant
& variant
,
283 const wxString
& text
,
284 int argFlags
= 0 ) const;
286 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
288 /** This is updated so "<composed>" special value can be handled.
290 virtual void OnSetValue();
295 // -----------------------------------------------------------------------
298 /** Constants used with DoValidation() methods.
302 /** Instead of modifying the value, show an error message.
304 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
= 0,
306 /** Modify value, but stick with the limitations.
308 wxPG_PROPERTY_VALIDATION_SATURATE
= 1,
310 /** Modify value, wrap around on overflow.
312 wxPG_PROPERTY_VALIDATION_WRAP
= 2
316 // -----------------------------------------------------------------------
318 /** @class wxIntProperty
320 Basic property with integer value.
322 Seamlessly supports 64-bit integer (wxLongLong) on overflow.
324 <b>Example how to use seamless 64-bit integer support</b>
329 wxLongLong_t value = pg->GetPropertyValueAsLongLong();
336 wxVariant variant = property->GetValue();
337 if ( variant.GetType() == "wxLongLong" )
338 value = wxLongLongFromVariant(variant);
340 value = variant.GetLong();
346 pg->SetPropertyValue(longLongVal);
352 property->SetValue(WXVARIANT(longLongVal));
356 <b>Supported special attributes:</b>
357 - "Min", "Max": Specify acceptable value range.
359 class WXDLLIMPEXP_PROPGRID wxIntProperty
: public wxPGProperty
361 WX_PG_DECLARE_PROPERTY_CLASS(wxIntProperty
)
363 wxIntProperty( const wxString
& label
= wxPG_LABEL
,
364 const wxString
& name
= wxPG_LABEL
,
366 virtual ~wxIntProperty();
368 wxIntProperty( const wxString
& label
,
369 const wxString
& name
,
370 const wxLongLong
& value
);
371 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
372 virtual bool StringToValue( wxVariant
& variant
,
373 const wxString
& text
,
374 int argFlags
= 0 ) const;
375 virtual bool ValidateValue( wxVariant
& value
,
376 wxPGValidationInfo
& validationInfo
) const;
377 virtual bool IntToValue( wxVariant
& variant
,
379 int argFlags
= 0 ) const;
380 static wxValidator
* GetClassValidator();
381 virtual wxValidator
* DoGetValidator() const;
383 /** Validation helper.
385 static bool DoValidation( const wxPGProperty
* property
,
387 wxPGValidationInfo
* pValidationInfo
,
389 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
394 // -----------------------------------------------------------------------
396 /** @class wxUIntProperty
398 Basic property with unsigned integer value.
399 Seamlessly supports 64-bit integer (wxULongLong) on overflow.
401 <b>Supported special attributes:</b>
402 - "Min", "Max": Specify acceptable value range.
403 - "Base": Define base. Valid constants are wxPG_BASE_OCT, wxPG_BASE_DEC,
404 wxPG_BASE_HEX and wxPG_BASE_HEXL (lowercase characters). Arbitrary bases
405 are <b>not</b> supported.
406 - "Prefix": Possible values are wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and
407 wxPG_PREFIX_DOLLAR_SIGN. Only wxPG_PREFIX_NONE works with Decimal and Octal
411 - For example how to use seamless 64-bit integer support, see wxIntProperty
412 documentation (just use wxULongLong instead of wxLongLong).
414 class WXDLLIMPEXP_PROPGRID wxUIntProperty
: public wxPGProperty
416 WX_PG_DECLARE_PROPERTY_CLASS(wxUIntProperty
)
418 wxUIntProperty( const wxString
& label
= wxPG_LABEL
,
419 const wxString
& name
= wxPG_LABEL
,
420 unsigned long value
= 0 );
421 virtual ~wxUIntProperty();
422 wxUIntProperty( const wxString
& label
,
423 const wxString
& name
,
424 const wxULongLong
& value
);
425 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
426 virtual bool StringToValue( wxVariant
& variant
,
427 const wxString
& text
,
428 int argFlags
= 0 ) const;
429 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
430 virtual bool ValidateValue( wxVariant
& value
,
431 wxPGValidationInfo
& validationInfo
) const;
432 virtual bool IntToValue( wxVariant
& variant
,
434 int argFlags
= 0 ) const;
437 wxByte m_realBase
; // translated to 8,16,etc.
443 // -----------------------------------------------------------------------
445 /** @class wxFloatProperty
447 Basic property with double-precision floating point value.
449 <b>Supported special attributes:</b>
450 - "Precision": Sets the (max) precision used when floating point value is
451 rendered as text. The default -1 means infinite precision.
453 class WXDLLIMPEXP_PROPGRID wxFloatProperty
: public wxPGProperty
455 WX_PG_DECLARE_PROPERTY_CLASS(wxFloatProperty
)
457 wxFloatProperty( const wxString
& label
= wxPG_LABEL
,
458 const wxString
& name
= wxPG_LABEL
,
459 double value
= 0.0 );
460 virtual ~wxFloatProperty();
462 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
463 virtual bool StringToValue( wxVariant
& variant
,
464 const wxString
& text
,
465 int argFlags
= 0 ) const;
466 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
467 virtual bool ValidateValue( wxVariant
& value
,
468 wxPGValidationInfo
& validationInfo
) const;
470 /** Validation helper.
472 static bool DoValidation( const wxPGProperty
* property
,
474 wxPGValidationInfo
* pValidationInfo
,
476 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
480 virtual wxValidator
* DoGetValidator () const;
483 // -----------------------------------------------------------------------
485 // Exclude class from wxPython bindings
488 /** @class wxBoolProperty
490 Basic property with boolean value.
492 <b>Supported special attributes:</b>
493 - "UseCheckbox": Set to 1 to use check box editor instead of combo box.
494 - "UseDClickCycling": Set to 1 to cycle combo box instead showing the list.
496 class WXDLLIMPEXP_PROPGRID wxBoolProperty
: public wxPGProperty
498 WX_PG_DECLARE_PROPERTY_CLASS(wxBoolProperty
)
500 wxBoolProperty( const wxString
& label
= wxPG_LABEL
,
501 const wxString
& name
= wxPG_LABEL
,
502 bool value
= false );
503 virtual ~wxBoolProperty();
505 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
506 virtual bool StringToValue( wxVariant
& variant
,
507 const wxString
& text
,
508 int argFlags
= 0 ) const;
509 virtual bool IntToValue( wxVariant
& variant
,
510 int number
, int argFlags
= 0 ) const;
511 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
516 // -----------------------------------------------------------------------
518 /** @class wxBaseEnumProperty
520 Derive dynamic custom properties with choices from this class.
523 - Updating private index is important. You can do this either by calling
524 SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue
525 be called (by not implementing it, or by calling super class function in
526 it) -OR- you can just call SetIndex in OnSetValue.
528 class WXDLLIMPEXP_PROPGRID wxBaseEnumProperty
: public wxPGProperty
531 wxBaseEnumProperty( const wxString
& label
= wxPG_LABEL
,
532 const wxString
& name
= wxPG_LABEL
);
534 virtual void OnSetValue();
535 virtual wxString
GetValueAsString( int argFlags
) const;
536 virtual bool StringToValue( wxVariant
& variant
,
537 const wxString
& text
,
538 int argFlags
= 0 ) const;
539 virtual bool ValidateValue( wxVariant
& value
,
540 wxPGValidationInfo
& validationInfo
) const;
542 // If wxPG_FULL_VALUE is not set in flags, then the value is interpreted
543 // as index to choices list. Otherwise, it is actual value.
544 virtual bool IntToValue( wxVariant
& variant
,
546 int argFlags
= 0 ) const;
549 // Additional virtuals
551 // This must be overridden to have non-index based value
552 virtual int GetIndexForValue( int value
) const;
554 // This returns string and value for index
555 // Returns NULL if beyond last item
556 // pvalue is never NULL - always set it.
557 virtual const wxString
* GetEntry( size_t index
, int* pvalue
) const = 0;
559 // GetChoiceSelection needs to overridden since m_index is
560 // the true index, and various property classes derived from
561 // this take advantage of it.
562 virtual int GetChoiceSelection() const { return m_index
; }
564 int GetValueForIndex( size_t index
) const
567 GetEntry( index
, &v
);
573 int GetIndex() const;
574 void SetIndex( int index
);
576 bool ValueFromString_( wxVariant
& value
,
577 const wxString
& text
,
578 int argFlags
) const;
579 bool ValueFromInt_( wxVariant
& value
, int intVal
, int argFlags
) const;
581 static void ResetNextIndex() { ms_nextIndex
= -2; }
584 // This is private so that classes are guaranteed to use GetIndex
585 // for up-to-date index value.
588 // Relies on ValidateValue being called always before OnSetValue
589 static int ms_nextIndex
;
592 // -----------------------------------------------------------------------
594 // If set, then selection of choices is static and should not be
595 // changed (i.e. returns NULL in GetPropertyChoices).
596 #define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1
598 /** @class wxEnumProperty
600 You can derive custom properties with choices from this class. See
601 wxBaseEnumProperty for remarks.
603 class WXDLLIMPEXP_PROPGRID wxEnumProperty
: public wxBaseEnumProperty
605 WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty
)
609 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
610 const wxString
& name
= wxPG_LABEL
,
611 const wxChar
** labels
= NULL
,
612 const long* values
= NULL
,
614 wxEnumProperty( const wxString
& label
,
615 const wxString
& name
,
616 wxPGChoices
& choices
,
619 // Special constructor for caching choices (used by derived class)
620 wxEnumProperty( const wxString
& label
,
621 const wxString
& name
,
622 const wxChar
** labels
,
624 wxPGChoices
* choicesCache
,
627 wxEnumProperty( const wxString
& label
,
628 const wxString
& name
,
629 const wxArrayString
& labels
,
630 const wxArrayInt
& values
= wxArrayInt(),
633 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
634 const wxString
& name
= wxPG_LABEL
,
635 const wxArrayString
& labels
= wxArrayString(),
636 const wxArrayInt
& values
= wxArrayInt(),
640 virtual ~wxEnumProperty();
642 virtual int GetIndexForValue( int value
) const;
643 virtual const wxString
* GetEntry( size_t index
, int* pvalue
) const;
645 size_t GetItemCount() const { return m_choices
.GetCount(); }
646 const wxPGChoices
& GetChoices() const { return m_choices
; }
649 // -----------------------------------------------------------------------
651 /** @class wxEditEnumProperty
653 wxEnumProperty with wxString value and writable combo box editor.
656 Uses int value, similar to wxEnumProperty, unless text entered by user is
657 is not in choices (in which case string value is used).
659 class WXDLLIMPEXP_PROPGRID wxEditEnumProperty
: public wxEnumProperty
661 WX_PG_DECLARE_PROPERTY_CLASS(wxEditEnumProperty
)
664 wxEditEnumProperty( const wxString
& label
,
665 const wxString
& name
,
666 const wxChar
** labels
,
668 const wxString
& value
);
669 wxEditEnumProperty( const wxString
& label
= wxPG_LABEL
,
670 const wxString
& name
= wxPG_LABEL
,
671 const wxArrayString
& labels
= wxArrayString(),
672 const wxArrayInt
& values
= wxArrayInt(),
673 const wxString
& value
= wxEmptyString
);
674 wxEditEnumProperty( const wxString
& label
,
675 const wxString
& name
,
676 wxPGChoices
& choices
,
677 const wxString
& value
= wxEmptyString
);
679 // Special constructor for caching choices (used by derived class)
680 wxEditEnumProperty( const wxString
& label
,
681 const wxString
& name
,
682 const wxChar
** labels
,
684 wxPGChoices
* choicesCache
,
685 const wxString
& value
);
687 virtual ~wxEditEnumProperty();
692 // -----------------------------------------------------------------------
694 /** @class wxFlagsProperty
696 Represents a bit set that fits in a long integer. wxBoolProperty
697 sub-properties are created for editing individual bits. Textctrl is created
698 to manually edit the flags as a text; a continous sequence of spaces,
699 commas and semicolons is considered as a flag id separator.
700 <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
701 you will need to use SetPropertyChoices - otherwise they will not get
704 class WXDLLIMPEXP_PROPGRID wxFlagsProperty
: public wxPGProperty
706 WX_PG_DECLARE_PROPERTY_CLASS(wxFlagsProperty
)
710 wxFlagsProperty( const wxString
& label
,
711 const wxString
& name
,
712 const wxChar
** labels
,
713 const long* values
= NULL
,
715 wxFlagsProperty( const wxString
& label
,
716 const wxString
& name
,
717 wxPGChoices
& choices
,
720 wxFlagsProperty( const wxString
& label
= wxPG_LABEL
,
721 const wxString
& name
= wxPG_LABEL
,
722 const wxArrayString
& labels
= wxArrayString(),
723 const wxArrayInt
& values
= wxArrayInt(),
725 virtual ~wxFlagsProperty ();
727 virtual void OnSetValue();
728 virtual wxString
GetValueAsString( int argFlags
) const;
729 virtual bool StringToValue( wxVariant
& variant
,
730 const wxString
& text
,
732 virtual void ChildChanged( wxVariant
& thisValue
,
734 wxVariant
& childValue
) const;
735 virtual void RefreshChildren();
737 // GetChoiceSelection needs to overridden since m_choices is
738 // used and value is integer, but it is not index.
739 virtual int GetChoiceSelection() const { return wxNOT_FOUND
; }
742 size_t GetItemCount() const { return m_choices
.GetCount(); }
743 const wxString
& GetLabel( size_t ind
) const
744 { return m_choices
.GetLabel(ind
); }
747 // Used to detect if choices have been changed
748 wxPGChoicesData
* m_oldChoicesData
;
750 // Needed to properly mark changed sub-properties
753 // Converts string id to a relevant bit.
754 long IdToBit( const wxString
& id
) const;
756 // Creates children and sets value.
760 // -----------------------------------------------------------------------
762 /** @class wxPGFileDialogAdapter
765 class WXDLLIMPEXP_PROPGRID
766 wxPGFileDialogAdapter
: public wxPGEditorDialogAdapter
769 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
770 wxPGProperty
* property
);
773 // -----------------------------------------------------------------------
775 #include "wx/filename.h"
777 // Indicates first bit useable by derived properties.
778 #define wxPG_PROP_SHOW_FULL_FILENAME wxPG_PROP_CLASS_SPECIFIC_1
780 /** @class wxFileProperty
782 Like wxLongStringProperty, but the button triggers file selector instead.
784 <b>Supported special attributes:</b>
785 - "Wildcard": Sets wildcard (see wxFileDialog for format details), "All
786 files..." is default.
787 - "ShowFullPath": Default 1. When 0, only the file name is shown (i.e. drive
788 and directory are hidden).
789 - "ShowRelativePath": If set, then the filename is shown relative to the
791 - "InitialPath": Sets the initial path of where to look for files.
792 - "DialogTitle": Sets a specific title for the dir dialog.
794 class WXDLLIMPEXP_PROPGRID wxFileProperty
: public wxPGProperty
796 friend class wxPGFileDialogAdapter
;
797 WX_PG_DECLARE_PROPERTY_CLASS(wxFileProperty
)
800 wxFileProperty( const wxString
& label
= wxPG_LABEL
,
801 const wxString
& name
= wxPG_LABEL
,
802 const wxString
& value
= wxEmptyString
);
803 virtual ~wxFileProperty ();
805 virtual void OnSetValue();
806 virtual wxString
GetValueAsString( int argFlags
) const;
807 virtual bool StringToValue( wxVariant
& variant
,
808 const wxString
& text
,
809 int argFlags
= 0 ) const;
810 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
811 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
813 static wxValidator
* GetClassValidator();
814 virtual wxValidator
* DoGetValidator() const;
818 wxString m_basePath
; // If set, then show path relative to it
819 wxString m_initialPath
; // If set, start the file dialog here
820 wxString m_dlgTitle
; // If set, used as title for file dialog
821 wxFileName m_filename
; // used as primary storage
822 int m_indFilter
; // index to the selected filter
825 // -----------------------------------------------------------------------
827 #define wxPG_PROP_NO_ESCAPE wxPG_PROP_CLASS_SPECIFIC_1
830 /** @class wxPGLongStringDialogAdapter
833 class WXDLLIMPEXP_PROPGRID
834 wxPGLongStringDialogAdapter
: public wxPGEditorDialogAdapter
837 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
838 wxPGProperty
* property
);
842 /** @class wxLongStringProperty
844 Like wxStringProperty, but has a button that triggers a small text
847 class WXDLLIMPEXP_PROPGRID wxLongStringProperty
: public wxPGProperty
849 WX_PG_DECLARE_PROPERTY_CLASS(wxLongStringProperty
)
852 wxLongStringProperty( const wxString
& label
= wxPG_LABEL
,
853 const wxString
& name
= wxPG_LABEL
,
854 const wxString
& value
= wxEmptyString
);
855 virtual ~wxLongStringProperty();
857 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
858 virtual bool StringToValue( wxVariant
& variant
,
859 const wxString
& text
,
860 int argFlags
= 0 ) const;
861 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
862 wxWindow
* primary
, wxEvent
& event
);
864 // Shows string editor dialog. Value to be edited should be read from
865 // value, and if dialog is not cancelled, it should be stored back and true
866 // should be returned if that was the case.
867 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
, wxString
& value
);
869 static bool DisplayEditorDialog( wxPGProperty
* prop
,
870 wxPropertyGrid
* propGrid
,
876 // -----------------------------------------------------------------------
879 // Exclude class from wxPython bindings
882 /** @class wxDirProperty
884 Like wxLongStringProperty, but the button triggers dir selector instead.
886 <b>Supported special attributes:</b>
887 - "DialogMessage": Sets specific message in the dir selector.
889 class WXDLLIMPEXP_PROPGRID wxDirProperty
: public wxLongStringProperty
892 DECLARE_DYNAMIC_CLASS(wxDirProperty
)
895 wxDirProperty( const wxString
& name
= wxPG_LABEL
,
896 const wxString
& label
= wxPG_LABEL
,
897 const wxString
& value
= wxEmptyString
);
898 virtual ~wxDirProperty();
900 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
901 virtual wxValidator
* DoGetValidator() const;
903 virtual bool OnButtonClick ( wxPropertyGrid
* propGrid
, wxString
& value
);
906 wxString m_dlgMessage
;
911 // -----------------------------------------------------------------------
913 // wxBoolProperty specific flags
914 #define wxPG_PROP_USE_CHECKBOX wxPG_PROP_CLASS_SPECIFIC_1
915 // DCC = Double Click Cycles
916 #define wxPG_PROP_USE_DCC wxPG_PROP_CLASS_SPECIFIC_2
919 // -----------------------------------------------------------------------
921 /** @class wxArrayStringProperty
923 Property that manages a list of strings.
925 class WXDLLIMPEXP_PROPGRID wxArrayStringProperty
: public wxPGProperty
927 WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty
)
930 wxArrayStringProperty( const wxString
& label
= wxPG_LABEL
,
931 const wxString
& name
= wxPG_LABEL
,
932 const wxArrayString
& value
= wxArrayString() );
933 virtual ~wxArrayStringProperty();
935 virtual void OnSetValue();
936 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
937 virtual bool StringToValue( wxVariant
& variant
,
938 const wxString
& text
,
939 int argFlags
= 0 ) const;
940 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
941 wxWindow
* primary
, wxEvent
& event
);
943 virtual void GenerateValueAsString();
945 // Shows string editor dialog. Value to be edited should be read from
946 // value, and if dialog is not cancelled, it should be stored back and true
947 // should be returned if that was the case.
948 virtual bool OnCustomStringEdit( wxWindow
* parent
, wxString
& value
);
951 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
,
956 // Creates wxArrayEditorDialog for string editing. Called in OnButtonClick.
957 virtual wxArrayEditorDialog
* CreateEditorDialog();
961 wxString m_display
; // Cache for displayed text.
964 // -----------------------------------------------------------------------
966 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, \
968 DECL PROPNAME : public wxArrayStringProperty \
970 WX_PG_DECLARE_PROPERTY_CLASS(PROPNAME) \
972 PROPNAME( const wxString& label = wxPG_LABEL, \
973 const wxString& name = wxPG_LABEL, \
974 const wxArrayString& value = wxArrayString() ); \
976 virtual void GenerateValueAsString(); \
977 virtual bool StringToValue( wxVariant& value, \
978 const wxString& text, int = 0 ) const; \
979 virtual bool OnEvent( wxPropertyGrid* propgrid, \
980 wxWindow* primary, wxEvent& event ); \
981 virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \
982 virtual wxValidator* DoGetValidator() const; \
985 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM) \
986 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM, class)
988 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
991 WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME, wxArrayStringProperty, \
992 wxArrayString, const wxArrayString&, \
994 PROPNAME::PROPNAME( const wxString& label, \
995 const wxString& name, \
996 const wxArrayString& value ) \
997 : wxArrayStringProperty(label,name,value) \
999 PROPNAME::GenerateValueAsString(); \
1001 PROPNAME::~PROPNAME() { } \
1002 void PROPNAME::GenerateValueAsString() \
1004 wxChar delimChar = DELIMCHAR; \
1005 if ( delimChar == wxS('"') ) \
1006 wxArrayStringProperty::GenerateValueAsString(); \
1008 wxPropertyGrid::ArrayStringToString(m_display, \
1009 m_value.GetArrayString(), \
1012 bool PROPNAME::StringToValue( wxVariant& variant, \
1013 const wxString& text, int ) const \
1015 wxChar delimChar = DELIMCHAR; \
1016 if ( delimChar == wxS('"') ) \
1017 return wxArrayStringProperty::StringToValue(variant, text, 0); \
1019 wxArrayString arr; \
1020 WX_PG_TOKENIZER1_BEGIN(text,DELIMCHAR) \
1022 WX_PG_TOKENIZER1_END() \
1026 bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
1027 wxWindow* primary, wxEvent& event ) \
1029 if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) \
1030 return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \
1034 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \
1035 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME)
1037 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_DECL(PROPNAME, DECL) \
1038 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, DECL)
1040 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \
1041 WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
1044 wxValidator* PROPNAME::DoGetValidator () const \
1045 { return (wxValidator*) NULL; }
1048 // -----------------------------------------------------------------------
1049 // wxArrayEditorDialog
1050 // -----------------------------------------------------------------------
1052 #include "wx/button.h"
1053 #include "wx/dialog.h"
1054 #include "wx/listbox.h"
1056 #define wxAEDIALOG_STYLE \
1057 (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
1059 class WXDLLIMPEXP_PROPGRID wxArrayEditorDialog
: public wxDialog
1062 wxArrayEditorDialog();
1063 virtual ~wxArrayEditorDialog() { }
1067 wxArrayEditorDialog( wxWindow
*parent
,
1068 const wxString
& message
,
1069 const wxString
& caption
,
1070 long style
= wxAEDIALOG_STYLE
,
1071 const wxPoint
& pos
= wxDefaultPosition
,
1072 const wxSize
& sz
= wxDefaultSize
);
1074 bool Create( wxWindow
*parent
,
1075 const wxString
& message
,
1076 const wxString
& caption
,
1077 long style
= wxAEDIALOG_STYLE
,
1078 const wxPoint
& pos
= wxDefaultPosition
,
1079 const wxSize
& sz
= wxDefaultSize
);
1081 /** Set value modified by dialog.
1083 virtual void SetDialogValue( const wxVariant
& WXUNUSED(value
) )
1085 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
1088 /** Return value modified by dialog.
1090 virtual wxVariant
GetDialogValue() const
1092 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
1096 /** Override to return wxValidator to be used with the wxTextCtrl
1097 in dialog. Note that the validator is used in the standard
1098 wx way, ie. it immediately prevents user from entering invalid
1102 Dialog frees the validator.
1104 virtual wxValidator
* GetTextCtrlValidator() const
1106 return (wxValidator
*) NULL
;
1109 // Returns true if array was actually modified
1110 bool IsModified() const { return m_modified
; }
1112 //const wxArrayString& GetStrings() const { return m_array; }
1114 // implementation from now on
1115 void OnUpdateClick(wxCommandEvent
& event
);
1116 void OnAddClick(wxCommandEvent
& event
);
1117 void OnDeleteClick(wxCommandEvent
& event
);
1118 void OnListBoxClick(wxCommandEvent
& event
);
1119 void OnUpClick(wxCommandEvent
& event
);
1120 void OnDownClick(wxCommandEvent
& event
);
1121 //void OnCustomEditClick(wxCommandEvent& event);
1122 void OnIdle(wxIdleEvent
& event
);
1125 wxTextCtrl
* m_edValue
;
1126 wxListBox
* m_lbStrings
;
1128 wxButton
* m_butAdd
; // Button pointers
1129 wxButton
* m_butCustom
; // required for disabling/enabling changing.
1130 wxButton
* m_butUpdate
;
1131 wxButton
* m_butRemove
;
1133 wxButton
* m_butDown
;
1135 //wxArrayString m_array;
1137 const wxChar
* m_custBtText
;
1138 //wxArrayStringPropertyClass* m_pCallingClass;
1142 unsigned char m_curFocus
;
1144 // These must be overridden - must return true on success.
1145 virtual wxString
ArrayGet( size_t index
) = 0;
1146 virtual size_t ArrayGetCount() = 0;
1147 virtual bool ArrayInsert( const wxString
& str
, int index
) = 0;
1148 virtual bool ArraySet( size_t index
, const wxString
& str
) = 0;
1149 virtual void ArrayRemoveAt( int index
) = 0;
1150 virtual void ArraySwap( size_t first
, size_t second
) = 0;
1154 DECLARE_DYNAMIC_CLASS_NO_COPY(wxArrayEditorDialog
)
1155 DECLARE_EVENT_TABLE()
1159 // -----------------------------------------------------------------------
1160 // wxPGArrayStringEditorDialog
1161 // -----------------------------------------------------------------------
1163 class WXDLLIMPEXP_PROPGRID
1164 wxPGArrayStringEditorDialog
: public wxArrayEditorDialog
1167 wxPGArrayStringEditorDialog();
1168 virtual ~wxPGArrayStringEditorDialog() { }
1172 virtual void SetDialogValue( const wxVariant
& value
)
1174 m_array
= value
.GetArrayString();
1177 virtual wxVariant
GetDialogValue() const
1182 void SetCustomButton( const wxChar
* custBtText
, wxArrayStringProperty
* pcc
)
1184 m_custBtText
= custBtText
;
1185 m_pCallingClass
= pcc
;
1188 void OnCustomEditClick(wxCommandEvent
& event
);
1191 wxArrayString m_array
;
1193 wxArrayStringProperty
* m_pCallingClass
;
1195 virtual wxString
ArrayGet( size_t index
);
1196 virtual size_t ArrayGetCount();
1197 virtual bool ArrayInsert( const wxString
& str
, int index
);
1198 virtual bool ArraySet( size_t index
, const wxString
& str
);
1199 virtual void ArrayRemoveAt( int index
);
1200 virtual void ArraySwap( size_t first
, size_t second
);
1204 DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog
)
1205 DECLARE_EVENT_TABLE()
1209 // -----------------------------------------------------------------------
1211 #endif // wxUSE_PROPGRID
1213 #endif // _WX_PROPGRID_PROPS_H_