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 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, DECL) \
42 DECL CLASSNAME : public wxSystemColourProperty \
44 DECLARE_DYNAMIC_CLASS(CLASSNAME) \
46 CLASSNAME( const wxString& label = wxPG_LABEL, \
47 const wxString& name = wxPG_LABEL, \
48 const wxColourPropertyValue& value = wxColourPropertyValue() ); \
49 virtual ~CLASSNAME(); \
50 virtual wxColour GetColour( int index ) const; \
53 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY(CLASSNAME) \
54 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_WITH_DECL(CLASSNAME, class)
56 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY(CLASSNAME,\
57 LABELS,VALUES,COLOURS) \
58 static wxPGChoices gs_##CLASSNAME##_choicesCache; \
59 IMPLEMENT_DYNAMIC_CLASS(CLASSNAME, wxSystemColourProperty) \
60 CLASSNAME::CLASSNAME( const wxString& label, const wxString& name, \
61 const wxColourPropertyValue& value ) \
62 : wxSystemColourProperty(label, name, LABELS, VALUES, \
63 &gs_##CLASSNAME##_choicesCache, value ) \
65 m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \
67 CLASSNAME::~CLASSNAME () { } \
68 wxColour CLASSNAME::GetColour ( int index ) const \
70 if ( !m_choices.HasValue(index) ) \
72 wxASSERT( index < (int)m_choices.GetCount() ); \
73 return COLOURS[index]; \
75 return COLOURS[m_choices.GetValue(index)]; \
78 // -----------------------------------------------------------------------
80 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME,\
82 DECL CLASSNAME : public wxSystemColourProperty \
84 WX_PG_DECLARE_PROPERTY_CLASS(CLASSNAME) \
86 CLASSNAME( const wxString& label = wxPG_LABEL, \
87 const wxString& name = wxPG_LABEL, \
88 const wxColour& value = wxColour() ); \
89 virtual ~CLASSNAME(); \
90 virtual wxString GetValueAsString( int argFlags ) const; \
91 virtual wxColour GetColour( int index ) const; \
92 virtual wxVariant DoTranslateVal( wxColourPropertyValue& v ) const; \
93 void Init( wxColour colour ); \
96 #define WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME) \
97 WX_PG_DECLARE_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR_WITH_DECL(CLASSNAME, class)
99 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \
104 static wxPGChoices gs_##CLASSNAME##_choicesCache; \
105 WX_PG_IMPLEMENT_PROPERTY_CLASS(CLASSNAME, wxSystemColourProperty, \
106 wxColour, const wxColour&,EDITOR) \
107 CLASSNAME::CLASSNAME( const wxString& label, \
108 const wxString& name, \
109 const wxColour& value ) \
110 : wxSystemColourProperty(label, name, LABELS, VALUES, \
111 &gs_##CLASSNAME##_choicesCache, value ) \
117 m_flags |= wxPG_PROP_TRANSLATE_CUSTOM; \
119 CLASSNAME::~CLASSNAME() { } \
120 void CLASSNAME::Init( wxColour colour ) \
122 if ( !colour.Ok() ) \
127 int ind = ColToInd(colour); \
129 ind = m_choices.GetCount() - 1; \
132 wxString CLASSNAME::GetValueAsString( int argFlags ) const \
134 const wxPGEditor* editor = GetEditorClass(); \
135 if ( editor != wxPGEditor_Choice && \
136 editor != wxPGEditor_ChoiceAndButton && \
137 editor != wxPGEditor_ComboBox ) \
138 argFlags |= wxPG_PROPERTY_SPECIFIC; \
139 return wxSystemColourProperty::GetValueAsString(argFlags); \
141 wxColour CLASSNAME::GetColour( int index ) const \
143 if ( !m_choices.HasValue(index) ) \
145 wxASSERT( index < (int)GetItemCount() ); \
146 return COLOURS[index]; \
148 return COLOURS[m_choices.GetValue(index)]; \
150 wxVariant CLASSNAME::DoTranslateVal( wxColourPropertyValue& v ) const \
153 variant << v.m_colour; \
158 #define WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR(CLASSNAME, \
162 WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(CLASSNAME, \
168 // -----------------------------------------------------------------------
171 // These macros help creating DoGetValidator
172 #define WX_PG_DOGETVALIDATOR_ENTRY() \
173 static wxValidator* s_ptr = (wxValidator*) NULL; \
174 if ( s_ptr ) return s_ptr;
176 // Common function exit
177 #define WX_PG_DOGETVALIDATOR_EXIT(VALIDATOR) \
179 wxPGGlobalVars->m_arrValidators.push_back( VALIDATOR ); \
182 // -----------------------------------------------------------------------
186 #include "wx/textctrl.h"
188 /** @class wxPGInDialogValidator
190 Creates and manages a temporary wxTextCtrl for validation purposes.
191 Uses wxPropertyGrid's current editor, if available.
193 class WXDLLIMPEXP_PROPGRID wxPGInDialogValidator
196 wxPGInDialogValidator()
201 ~wxPGInDialogValidator()
204 m_textCtrl
->Destroy();
207 bool DoValidate( wxPropertyGrid
* propGrid
,
208 wxValidator
* validator
,
209 const wxString
& value
);
212 wxTextCtrl
* m_textCtrl
;
218 // -----------------------------------------------------------------------
220 // -----------------------------------------------------------------------
222 #define wxPG_PROP_PASSWORD wxPG_PROP_CLASS_SPECIFIC_2
224 /** @class wxStringProperty
226 Basic property with string value.
228 <b>Supported special attributes:</b>
229 - "Password": set to 1 inorder to enable wxTE_PASSWORD on the editor.
232 - If value "<composed>" is set, then actual value is formed (or composed)
233 from values of child properties.
235 class WXDLLIMPEXP_PROPGRID wxStringProperty
: public wxPGProperty
237 WX_PG_DECLARE_PROPERTY_CLASS(wxStringProperty
)
239 wxStringProperty( const wxString
& label
= wxPG_LABEL
,
240 const wxString
& name
= wxPG_LABEL
,
241 const wxString
& value
= wxEmptyString
);
242 virtual ~wxStringProperty();
244 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
245 virtual bool StringToValue( wxVariant
& variant
,
246 const wxString
& text
,
247 int argFlags
= 0 ) const;
249 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
251 /** This is updated so "<composed>" special value can be handled.
253 virtual void OnSetValue();
258 // -----------------------------------------------------------------------
261 /** Constants used with DoValidation() methods.
265 /** Instead of modifying the value, show an error message.
267 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
= 0,
269 /** Modify value, but stick with the limitations.
271 wxPG_PROPERTY_VALIDATION_SATURATE
= 1,
273 /** Modify value, wrap around on overflow.
275 wxPG_PROPERTY_VALIDATION_WRAP
= 2
279 // -----------------------------------------------------------------------
281 /** @class wxIntProperty
283 Basic property with integer value.
285 Seamlessly supports 64-bit integer (wxLongLong) on overflow.
287 <b>Example how to use seamless 64-bit integer support</b>
292 wxLongLong_t value = pg->GetPropertyValueAsLongLong();
299 wxVariant variant = property->GetValue();
300 if ( variant.GetType() == "wxLongLong" )
301 value = wxLongLongFromVariant(variant);
303 value = variant.GetLong();
309 pg->SetPropertyValue(longLongVal);
315 property->SetValue(WXVARIANT(longLongVal));
319 <b>Supported special attributes:</b>
320 - "Min", "Max": Specify acceptable value range.
322 class WXDLLIMPEXP_PROPGRID wxIntProperty
: public wxPGProperty
324 WX_PG_DECLARE_PROPERTY_CLASS(wxIntProperty
)
326 wxIntProperty( const wxString
& label
= wxPG_LABEL
,
327 const wxString
& name
= wxPG_LABEL
,
329 virtual ~wxIntProperty();
331 wxIntProperty( const wxString
& label
,
332 const wxString
& name
,
333 const wxLongLong
& value
);
334 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
335 virtual bool StringToValue( wxVariant
& variant
,
336 const wxString
& text
,
337 int argFlags
= 0 ) const;
338 virtual bool ValidateValue( wxVariant
& value
,
339 wxPGValidationInfo
& validationInfo
) const;
340 virtual bool IntToValue( wxVariant
& variant
,
342 int argFlags
= 0 ) const;
343 static wxValidator
* GetClassValidator();
344 virtual wxValidator
* DoGetValidator() const;
346 /** Validation helper.
348 static bool DoValidation( const wxPGProperty
* property
,
350 wxPGValidationInfo
* pValidationInfo
,
352 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
357 // -----------------------------------------------------------------------
359 /** @class wxUIntProperty
361 Basic property with unsigned integer value.
362 Seamlessly supports 64-bit integer (wxULongLong) on overflow.
364 <b>Supported special attributes:</b>
365 - "Min", "Max": Specify acceptable value range.
366 - "Base": Define base. Valid constants are wxPG_BASE_OCT, wxPG_BASE_DEC,
367 wxPG_BASE_HEX and wxPG_BASE_HEXL (lowercase characters). Arbitrary bases
368 are <b>not</b> supported.
369 - "Prefix": Possible values are wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and
370 wxPG_PREFIX_DOLLAR_SIGN. Only wxPG_PREFIX_NONE works with Decimal and Octal
374 - For example how to use seamless 64-bit integer support, see wxIntProperty
375 documentation (just use wxULongLong instead of wxLongLong).
377 class WXDLLIMPEXP_PROPGRID wxUIntProperty
: public wxPGProperty
379 WX_PG_DECLARE_PROPERTY_CLASS(wxUIntProperty
)
381 wxUIntProperty( const wxString
& label
= wxPG_LABEL
,
382 const wxString
& name
= wxPG_LABEL
,
383 unsigned long value
= 0 );
384 virtual ~wxUIntProperty();
385 wxUIntProperty( const wxString
& label
,
386 const wxString
& name
,
387 const wxULongLong
& value
);
388 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
389 virtual bool StringToValue( wxVariant
& variant
,
390 const wxString
& text
,
391 int argFlags
= 0 ) const;
392 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
393 virtual bool ValidateValue( wxVariant
& value
,
394 wxPGValidationInfo
& validationInfo
) const;
395 virtual bool IntToValue( wxVariant
& variant
,
397 int argFlags
= 0 ) const;
400 wxByte m_realBase
; // translated to 8,16,etc.
406 // -----------------------------------------------------------------------
408 /** @class wxFloatProperty
410 Basic property with double-precision floating point value.
412 <b>Supported special attributes:</b>
413 - "Precision": Sets the (max) precision used when floating point value is
414 rendered as text. The default -1 means infinite precision.
416 class WXDLLIMPEXP_PROPGRID wxFloatProperty
: public wxPGProperty
418 WX_PG_DECLARE_PROPERTY_CLASS(wxFloatProperty
)
420 wxFloatProperty( const wxString
& label
= wxPG_LABEL
,
421 const wxString
& name
= wxPG_LABEL
,
422 double value
= 0.0 );
423 virtual ~wxFloatProperty();
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;
433 /** Validation helper.
435 static bool DoValidation( const wxPGProperty
* property
,
437 wxPGValidationInfo
* pValidationInfo
,
439 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
443 virtual wxValidator
* DoGetValidator () const;
446 // -----------------------------------------------------------------------
448 // Exclude class from wxPython bindings
451 /** @class wxBoolProperty
453 Basic property with boolean value.
455 <b>Supported special attributes:</b>
456 - "UseCheckbox": Set to 1 to use check box editor instead of combo box.
457 - "UseDClickCycling": Set to 1 to cycle combo box instead showing the list.
459 class WXDLLIMPEXP_PROPGRID wxBoolProperty
: public wxPGProperty
461 WX_PG_DECLARE_PROPERTY_CLASS(wxBoolProperty
)
463 wxBoolProperty( const wxString
& label
= wxPG_LABEL
,
464 const wxString
& name
= wxPG_LABEL
,
465 bool value
= false );
466 virtual ~wxBoolProperty();
468 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
469 virtual bool StringToValue( wxVariant
& variant
,
470 const wxString
& text
,
471 int argFlags
= 0 ) const;
472 virtual bool IntToValue( wxVariant
& variant
,
473 int number
, int argFlags
= 0 ) const;
474 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
479 // -----------------------------------------------------------------------
481 /** @class wxBaseEnumProperty
483 Derive dynamic custom properties with choices from this class.
486 - Updating private index is important. You can do this either by calling
487 SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue
488 be called (by not implementing it, or by calling super class function in
489 it) -OR- you can just call SetIndex in OnSetValue.
491 class WXDLLIMPEXP_PROPGRID wxBaseEnumProperty
: public wxPGProperty
494 wxBaseEnumProperty( const wxString
& label
= wxPG_LABEL
,
495 const wxString
& name
= wxPG_LABEL
);
497 virtual void OnSetValue();
498 virtual wxString
GetValueAsString( int argFlags
) const;
499 virtual bool StringToValue( wxVariant
& variant
,
500 const wxString
& text
,
501 int argFlags
= 0 ) const;
502 virtual bool ValidateValue( wxVariant
& value
,
503 wxPGValidationInfo
& validationInfo
) const;
505 // If wxPG_FULL_VALUE is not set in flags, then the value is interpreted
506 // as index to choices list. Otherwise, it is actual value.
507 virtual bool IntToValue( wxVariant
& variant
,
509 int argFlags
= 0 ) const;
512 // Additional virtuals
514 // This must be overridden to have non-index based value
515 virtual int GetIndexForValue( int value
) const;
517 // This returns string and value for index
518 // Returns NULL if beyond last item
519 // pvalue is never NULL - always set it.
520 virtual const wxString
* GetEntry( size_t index
, int* pvalue
) const = 0;
522 // GetChoiceSelection needs to overridden since m_index is
523 // the true index, and various property classes derived from
524 // this take advantage of it.
525 virtual int GetChoiceSelection() const { return m_index
; }
527 int GetValueForIndex( size_t index
) const
530 GetEntry( index
, &v
);
536 int GetIndex() const;
537 void SetIndex( int index
);
539 bool ValueFromString_( wxVariant
& value
,
540 const wxString
& text
,
541 int argFlags
) const;
542 bool ValueFromInt_( wxVariant
& value
, int intVal
, int argFlags
) const;
544 static void ResetNextIndex() { ms_nextIndex
= -2; }
547 // This is private so that classes are guaranteed to use GetIndex
548 // for up-to-date index value.
551 // Relies on ValidateValue being called always before OnSetValue
552 static int ms_nextIndex
;
555 // -----------------------------------------------------------------------
557 // If set, then selection of choices is static and should not be
558 // changed (i.e. returns NULL in GetPropertyChoices).
559 #define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1
561 /** @class wxEnumProperty
563 You can derive custom properties with choices from this class. See
564 wxBaseEnumProperty for remarks.
566 class WXDLLIMPEXP_PROPGRID wxEnumProperty
: public wxBaseEnumProperty
568 WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty
)
572 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
573 const wxString
& name
= wxPG_LABEL
,
574 const wxChar
** labels
= NULL
,
575 const long* values
= NULL
,
577 wxEnumProperty( const wxString
& label
,
578 const wxString
& name
,
579 wxPGChoices
& choices
,
582 // Special constructor for caching choices (used by derived class)
583 wxEnumProperty( const wxString
& label
,
584 const wxString
& name
,
585 const wxChar
** labels
,
587 wxPGChoices
* choicesCache
,
590 wxEnumProperty( const wxString
& label
,
591 const wxString
& name
,
592 const wxArrayString
& labels
,
593 const wxArrayInt
& values
= wxArrayInt(),
596 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
597 const wxString
& name
= wxPG_LABEL
,
598 const wxArrayString
& labels
= wxArrayString(),
599 const wxArrayInt
& values
= wxArrayInt(),
603 virtual ~wxEnumProperty();
605 virtual int GetIndexForValue( int value
) const;
606 virtual const wxString
* GetEntry( size_t index
, int* pvalue
) const;
608 size_t GetItemCount() const { return m_choices
.GetCount(); }
609 const wxPGChoices
& GetChoices() const { return m_choices
; }
612 // -----------------------------------------------------------------------
614 /** @class wxEditEnumProperty
616 wxEnumProperty with wxString value and writable combo box editor.
619 Uses int value, similar to wxEnumProperty, unless text entered by user is
620 is not in choices (in which case string value is used).
622 class WXDLLIMPEXP_PROPGRID wxEditEnumProperty
: public wxEnumProperty
624 WX_PG_DECLARE_PROPERTY_CLASS(wxEditEnumProperty
)
627 wxEditEnumProperty( const wxString
& label
,
628 const wxString
& name
,
629 const wxChar
** labels
,
631 const wxString
& value
);
632 wxEditEnumProperty( const wxString
& label
= wxPG_LABEL
,
633 const wxString
& name
= wxPG_LABEL
,
634 const wxArrayString
& labels
= wxArrayString(),
635 const wxArrayInt
& values
= wxArrayInt(),
636 const wxString
& value
= wxEmptyString
);
637 wxEditEnumProperty( const wxString
& label
,
638 const wxString
& name
,
639 wxPGChoices
& choices
,
640 const wxString
& value
= wxEmptyString
);
642 // Special constructor for caching choices (used by derived class)
643 wxEditEnumProperty( const wxString
& label
,
644 const wxString
& name
,
645 const wxChar
** labels
,
647 wxPGChoices
* choicesCache
,
648 const wxString
& value
);
650 virtual ~wxEditEnumProperty();
655 // -----------------------------------------------------------------------
657 /** @class wxFlagsProperty
659 Represents a bit set that fits in a long integer. wxBoolProperty
660 sub-properties are created for editing individual bits. Textctrl is created
661 to manually edit the flags as a text; a continous sequence of spaces,
662 commas and semicolons is considered as a flag id separator.
663 <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
664 you will need to use SetPropertyChoices - otherwise they will not get
667 class WXDLLIMPEXP_PROPGRID wxFlagsProperty
: public wxPGProperty
669 WX_PG_DECLARE_PROPERTY_CLASS(wxFlagsProperty
)
673 wxFlagsProperty( const wxString
& label
,
674 const wxString
& name
,
675 const wxChar
** labels
,
676 const long* values
= NULL
,
678 wxFlagsProperty( const wxString
& label
,
679 const wxString
& name
,
680 wxPGChoices
& choices
,
683 wxFlagsProperty( const wxString
& label
= wxPG_LABEL
,
684 const wxString
& name
= wxPG_LABEL
,
685 const wxArrayString
& labels
= wxArrayString(),
686 const wxArrayInt
& values
= wxArrayInt(),
688 virtual ~wxFlagsProperty ();
690 virtual void OnSetValue();
691 virtual wxString
GetValueAsString( int argFlags
) const;
692 virtual bool StringToValue( wxVariant
& variant
,
693 const wxString
& text
,
695 virtual void ChildChanged( wxVariant
& thisValue
,
697 wxVariant
& childValue
) const;
698 virtual void RefreshChildren();
700 // GetChoiceSelection needs to overridden since m_choices is
701 // used and value is integer, but it is not index.
702 virtual int GetChoiceSelection() const { return wxNOT_FOUND
; }
705 size_t GetItemCount() const { return m_choices
.GetCount(); }
706 const wxString
& GetLabel( size_t ind
) const
707 { return m_choices
.GetLabel(ind
); }
710 // Used to detect if choices have been changed
711 wxPGChoicesData
* m_oldChoicesData
;
713 // Needed to properly mark changed sub-properties
716 // Converts string id to a relevant bit.
717 long IdToBit( const wxString
& id
) const;
719 // Creates children and sets value.
723 // -----------------------------------------------------------------------
725 /** @class wxPGFileDialogAdapter
728 class WXDLLIMPEXP_PROPGRID
729 wxPGFileDialogAdapter
: public wxPGEditorDialogAdapter
732 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
733 wxPGProperty
* property
);
736 // -----------------------------------------------------------------------
738 #include "wx/filename.h"
740 // Indicates first bit useable by derived properties.
741 #define wxPG_PROP_SHOW_FULL_FILENAME wxPG_PROP_CLASS_SPECIFIC_1
743 /** @class wxFileProperty
745 Like wxLongStringProperty, but the button triggers file selector instead.
747 <b>Supported special attributes:</b>
748 - "Wildcard": Sets wildcard (see wxFileDialog for format details), "All
749 files..." is default.
750 - "ShowFullPath": Default 1. When 0, only the file name is shown (i.e. drive
751 and directory are hidden).
752 - "ShowRelativePath": If set, then the filename is shown relative to the
754 - "InitialPath": Sets the initial path of where to look for files.
755 - "DialogTitle": Sets a specific title for the dir dialog.
757 class WXDLLIMPEXP_PROPGRID wxFileProperty
: public wxPGProperty
759 friend class wxPGFileDialogAdapter
;
760 WX_PG_DECLARE_PROPERTY_CLASS(wxFileProperty
)
763 wxFileProperty( const wxString
& label
= wxPG_LABEL
,
764 const wxString
& name
= wxPG_LABEL
,
765 const wxString
& value
= wxEmptyString
);
766 virtual ~wxFileProperty ();
768 virtual void OnSetValue();
769 virtual wxString
GetValueAsString( int argFlags
) const;
770 virtual bool StringToValue( wxVariant
& variant
,
771 const wxString
& text
,
772 int argFlags
= 0 ) const;
773 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
774 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
776 static wxValidator
* GetClassValidator();
777 virtual wxValidator
* DoGetValidator() const;
781 wxString m_basePath
; // If set, then show path relative to it
782 wxString m_initialPath
; // If set, start the file dialog here
783 wxString m_dlgTitle
; // If set, used as title for file dialog
784 wxFileName m_filename
; // used as primary storage
785 int m_indFilter
; // index to the selected filter
788 // -----------------------------------------------------------------------
790 #define wxPG_PROP_NO_ESCAPE wxPG_PROP_CLASS_SPECIFIC_1
793 /** @class wxPGLongStringDialogAdapter
796 class WXDLLIMPEXP_PROPGRID
797 wxPGLongStringDialogAdapter
: public wxPGEditorDialogAdapter
800 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
801 wxPGProperty
* property
);
805 /** @class wxLongStringProperty
807 Like wxStringProperty, but has a button that triggers a small text
810 class WXDLLIMPEXP_PROPGRID wxLongStringProperty
: public wxPGProperty
812 WX_PG_DECLARE_PROPERTY_CLASS(wxLongStringProperty
)
815 wxLongStringProperty( const wxString
& label
= wxPG_LABEL
,
816 const wxString
& name
= wxPG_LABEL
,
817 const wxString
& value
= wxEmptyString
);
818 virtual ~wxLongStringProperty();
820 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
821 virtual bool StringToValue( wxVariant
& variant
,
822 const wxString
& text
,
823 int argFlags
= 0 ) const;
824 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
825 wxWindow
* primary
, wxEvent
& event
);
827 // Shows string editor dialog. Value to be edited should be read from
828 // value, and if dialog is not cancelled, it should be stored back and true
829 // should be returned if that was the case.
830 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
, wxString
& value
);
832 static bool DisplayEditorDialog( wxPGProperty
* prop
,
833 wxPropertyGrid
* propGrid
,
839 // -----------------------------------------------------------------------
842 // Exclude class from wxPython bindings
845 /** @class wxDirProperty
847 Like wxLongStringProperty, but the button triggers dir selector instead.
849 <b>Supported special attributes:</b>
850 - "DialogMessage": Sets specific message in the dir selector.
852 class WXDLLIMPEXP_PROPGRID wxDirProperty
: public wxLongStringProperty
855 DECLARE_DYNAMIC_CLASS(wxDirProperty
)
858 wxDirProperty( const wxString
& name
= wxPG_LABEL
,
859 const wxString
& label
= wxPG_LABEL
,
860 const wxString
& value
= wxEmptyString
);
861 virtual ~wxDirProperty();
863 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
864 virtual wxValidator
* DoGetValidator() const;
866 virtual bool OnButtonClick ( wxPropertyGrid
* propGrid
, wxString
& value
);
869 wxString m_dlgMessage
;
874 // -----------------------------------------------------------------------
876 // wxBoolProperty specific flags
877 #define wxPG_PROP_USE_CHECKBOX wxPG_PROP_CLASS_SPECIFIC_1
878 // DCC = Double Click Cycles
879 #define wxPG_PROP_USE_DCC wxPG_PROP_CLASS_SPECIFIC_2
882 // -----------------------------------------------------------------------
884 /** @class wxArrayStringProperty
886 Property that manages a list of strings.
888 class WXDLLIMPEXP_PROPGRID wxArrayStringProperty
: public wxPGProperty
890 WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty
)
893 wxArrayStringProperty( const wxString
& label
= wxPG_LABEL
,
894 const wxString
& name
= wxPG_LABEL
,
895 const wxArrayString
& value
= wxArrayString() );
896 virtual ~wxArrayStringProperty();
898 virtual void OnSetValue();
899 virtual wxString
GetValueAsString( int argFlags
= 0 ) const;
900 virtual bool StringToValue( wxVariant
& variant
,
901 const wxString
& text
,
902 int argFlags
= 0 ) const;
903 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
904 wxWindow
* primary
, wxEvent
& event
);
906 virtual void GenerateValueAsString();
908 // Shows string editor dialog. Value to be edited should be read from
909 // value, and if dialog is not cancelled, it should be stored back and true
910 // should be returned if that was the case.
911 virtual bool OnCustomStringEdit( wxWindow
* parent
, wxString
& value
);
914 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
,
919 // Creates wxArrayEditorDialog for string editing. Called in OnButtonClick.
920 virtual wxArrayEditorDialog
* CreateEditorDialog();
924 wxString m_display
; // Cache for displayed text.
927 // -----------------------------------------------------------------------
929 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, \
931 DECL PROPNAME : public wxArrayStringProperty \
933 WX_PG_DECLARE_PROPERTY_CLASS(PROPNAME) \
935 PROPNAME( const wxString& label = wxPG_LABEL, \
936 const wxString& name = wxPG_LABEL, \
937 const wxArrayString& value = wxArrayString() ); \
939 virtual void GenerateValueAsString(); \
940 virtual bool StringToValue( wxVariant& value, \
941 const wxString& text, int = 0 ) const; \
942 virtual bool OnEvent( wxPropertyGrid* propgrid, \
943 wxWindow* primary, wxEvent& event ); \
944 virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \
945 virtual wxValidator* DoGetValidator() const; \
948 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM) \
949 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM, class)
951 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
954 WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME, wxArrayStringProperty, \
955 wxArrayString, const wxArrayString&, \
957 PROPNAME::PROPNAME( const wxString& label, \
958 const wxString& name, \
959 const wxArrayString& value ) \
960 : wxArrayStringProperty(label,name,value) \
962 PROPNAME::GenerateValueAsString(); \
964 PROPNAME::~PROPNAME() { } \
965 void PROPNAME::GenerateValueAsString() \
967 wxChar delimChar = DELIMCHAR; \
968 if ( delimChar == wxS('"') ) \
969 wxArrayStringProperty::GenerateValueAsString(); \
971 wxPropertyGrid::ArrayStringToString(m_display, \
972 m_value.GetArrayString(), \
975 bool PROPNAME::StringToValue( wxVariant& variant, \
976 const wxString& text, int ) const \
978 wxChar delimChar = DELIMCHAR; \
979 if ( delimChar == wxS('"') ) \
980 return wxArrayStringProperty::StringToValue(variant, text, 0); \
983 WX_PG_TOKENIZER1_BEGIN(text,DELIMCHAR) \
985 WX_PG_TOKENIZER1_END() \
989 bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
990 wxWindow* primary, wxEvent& event ) \
992 if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) \
993 return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \
997 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \
998 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME)
1000 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_DECL(PROPNAME, DECL) \
1001 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, DECL)
1003 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \
1004 WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
1007 wxValidator* PROPNAME::DoGetValidator () const \
1008 { return (wxValidator*) NULL; }
1011 // -----------------------------------------------------------------------
1012 // wxArrayEditorDialog
1013 // -----------------------------------------------------------------------
1015 #include "wx/button.h"
1016 #include "wx/dialog.h"
1017 #include "wx/listbox.h"
1019 #define wxAEDIALOG_STYLE \
1020 (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
1022 class WXDLLIMPEXP_PROPGRID wxArrayEditorDialog
: public wxDialog
1025 wxArrayEditorDialog();
1026 virtual ~wxArrayEditorDialog() { }
1030 wxArrayEditorDialog( wxWindow
*parent
,
1031 const wxString
& message
,
1032 const wxString
& caption
,
1033 long style
= wxAEDIALOG_STYLE
,
1034 const wxPoint
& pos
= wxDefaultPosition
,
1035 const wxSize
& sz
= wxDefaultSize
);
1037 bool Create( wxWindow
*parent
,
1038 const wxString
& message
,
1039 const wxString
& caption
,
1040 long style
= wxAEDIALOG_STYLE
,
1041 const wxPoint
& pos
= wxDefaultPosition
,
1042 const wxSize
& sz
= wxDefaultSize
);
1044 /** Set value modified by dialog.
1046 virtual void SetDialogValue( const wxVariant
& WXUNUSED(value
) )
1048 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
1051 /** Return value modified by dialog.
1053 virtual wxVariant
GetDialogValue() const
1055 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
1059 /** Override to return wxValidator to be used with the wxTextCtrl
1060 in dialog. Note that the validator is used in the standard
1061 wx way, ie. it immediately prevents user from entering invalid
1065 Dialog frees the validator.
1067 virtual wxValidator
* GetTextCtrlValidator() const
1069 return (wxValidator
*) NULL
;
1072 // Returns true if array was actually modified
1073 bool IsModified() const { return m_modified
; }
1075 //const wxArrayString& GetStrings() const { return m_array; }
1077 // implementation from now on
1078 void OnUpdateClick(wxCommandEvent
& event
);
1079 void OnAddClick(wxCommandEvent
& event
);
1080 void OnDeleteClick(wxCommandEvent
& event
);
1081 void OnListBoxClick(wxCommandEvent
& event
);
1082 void OnUpClick(wxCommandEvent
& event
);
1083 void OnDownClick(wxCommandEvent
& event
);
1084 //void OnCustomEditClick(wxCommandEvent& event);
1085 void OnIdle(wxIdleEvent
& event
);
1088 wxTextCtrl
* m_edValue
;
1089 wxListBox
* m_lbStrings
;
1091 wxButton
* m_butAdd
; // Button pointers
1092 wxButton
* m_butCustom
; // required for disabling/enabling changing.
1093 wxButton
* m_butUpdate
;
1094 wxButton
* m_butRemove
;
1096 wxButton
* m_butDown
;
1098 //wxArrayString m_array;
1100 const wxChar
* m_custBtText
;
1101 //wxArrayStringPropertyClass* m_pCallingClass;
1105 unsigned char m_curFocus
;
1107 // These must be overridden - must return true on success.
1108 virtual wxString
ArrayGet( size_t index
) = 0;
1109 virtual size_t ArrayGetCount() = 0;
1110 virtual bool ArrayInsert( const wxString
& str
, int index
) = 0;
1111 virtual bool ArraySet( size_t index
, const wxString
& str
) = 0;
1112 virtual void ArrayRemoveAt( int index
) = 0;
1113 virtual void ArraySwap( size_t first
, size_t second
) = 0;
1117 DECLARE_DYNAMIC_CLASS_NO_COPY(wxArrayEditorDialog
)
1118 DECLARE_EVENT_TABLE()
1122 // -----------------------------------------------------------------------
1123 // wxPGArrayStringEditorDialog
1124 // -----------------------------------------------------------------------
1126 class WXDLLIMPEXP_PROPGRID
1127 wxPGArrayStringEditorDialog
: public wxArrayEditorDialog
1130 wxPGArrayStringEditorDialog();
1131 virtual ~wxPGArrayStringEditorDialog() { }
1135 virtual void SetDialogValue( const wxVariant
& value
)
1137 m_array
= value
.GetArrayString();
1140 virtual wxVariant
GetDialogValue() const
1145 void SetCustomButton( const wxChar
* custBtText
, wxArrayStringProperty
* pcc
)
1147 m_custBtText
= custBtText
;
1148 m_pCallingClass
= pcc
;
1151 void OnCustomEditClick(wxCommandEvent
& event
);
1154 wxArrayString m_array
;
1156 wxArrayStringProperty
* m_pCallingClass
;
1158 virtual wxString
ArrayGet( size_t index
);
1159 virtual size_t ArrayGetCount();
1160 virtual bool ArrayInsert( const wxString
& str
, int index
);
1161 virtual bool ArraySet( size_t index
, const wxString
& str
);
1162 virtual void ArrayRemoveAt( int index
);
1163 virtual void ArraySwap( size_t first
, size_t second
);
1167 DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog
)
1168 DECLARE_EVENT_TABLE()
1172 // -----------------------------------------------------------------------
1174 #endif // wxUSE_PROPGRID
1176 #endif // _WX_PROPGRID_PROPS_H_