1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/props.h
3 // Purpose: wxPropertyGrid Property Classes
4 // Author: Jaakko Salli
7 // Copyright: (c) Jaakko Salli
8 // Licence: wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
11 #ifndef _WX_PROPGRID_PROPS_H_
12 #define _WX_PROPGRID_PROPS_H_
18 // -----------------------------------------------------------------------
20 class wxPGArrayEditorDialog
;
22 #include "wx/propgrid/editors.h"
24 #include "wx/filename.h"
25 #include "wx/dialog.h"
26 #include "wx/textctrl.h"
27 #include "wx/button.h"
28 #include "wx/listbox.h"
29 #include "wx/valtext.h"
31 // -----------------------------------------------------------------------
34 // Property class implementation helper macros.
37 #define WX_PG_IMPLEMENT_PROPERTY_CLASS(NAME, UPCLASS, T, T_AS_ARG, EDITOR) \
38 IMPLEMENT_DYNAMIC_CLASS(NAME, UPCLASS) \
39 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(NAME, T, EDITOR)
41 // -----------------------------------------------------------------------
44 // These macros help creating DoGetValidator
45 #define WX_PG_DOGETVALIDATOR_ENTRY() \
46 static wxValidator* s_ptr = NULL; \
47 if ( s_ptr ) return s_ptr;
49 // Common function exit
50 #define WX_PG_DOGETVALIDATOR_EXIT(VALIDATOR) \
52 wxPGGlobalVars->m_arrValidators.push_back( VALIDATOR ); \
55 // -----------------------------------------------------------------------
57 /** @class wxPGInDialogValidator
59 Creates and manages a temporary wxTextCtrl for validation purposes.
60 Uses wxPropertyGrid's current editor, if available.
62 class WXDLLIMPEXP_PROPGRID wxPGInDialogValidator
65 wxPGInDialogValidator()
70 ~wxPGInDialogValidator()
73 m_textCtrl
->Destroy();
76 bool DoValidate( wxPropertyGrid
* propGrid
,
77 wxValidator
* validator
,
78 const wxString
& value
);
81 wxTextCtrl
* m_textCtrl
;
85 // -----------------------------------------------------------------------
87 // -----------------------------------------------------------------------
89 #define wxPG_PROP_PASSWORD wxPG_PROP_CLASS_SPECIFIC_2
91 /** @class wxStringProperty
93 Basic property with string value.
95 <b>Supported special attributes:</b>
96 - "Password": set to 1 in order to enable wxTE_PASSWORD on the editor.
99 - If value "<composed>" is set, then actual value is formed (or composed)
100 from values of child properties.
102 class WXDLLIMPEXP_PROPGRID wxStringProperty
: public wxPGProperty
104 WX_PG_DECLARE_PROPERTY_CLASS(wxStringProperty
)
106 wxStringProperty( const wxString
& label
= wxPG_LABEL
,
107 const wxString
& name
= wxPG_LABEL
,
108 const wxString
& value
= wxEmptyString
);
109 virtual ~wxStringProperty();
111 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
112 virtual bool StringToValue( wxVariant
& variant
,
113 const wxString
& text
,
114 int argFlags
= 0 ) const;
116 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
118 /** This is updated so "<composed>" special value can be handled.
120 virtual void OnSetValue();
125 // -----------------------------------------------------------------------
127 /** Constants used with NumericValidation<>().
129 enum wxPGNumericValidationConstants
131 /** Instead of modifying the value, show an error message.
133 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
= 0,
135 /** Modify value, but stick with the limitations.
137 wxPG_PROPERTY_VALIDATION_SATURATE
= 1,
139 /** Modify value, wrap around on overflow.
141 wxPG_PROPERTY_VALIDATION_WRAP
= 2
144 // -----------------------------------------------------------------------
149 A more comprehensive numeric validator class.
151 class WXDLLIMPEXP_PROPGRID wxNumericPropertyValidator
: public wxTextValidator
161 wxNumericPropertyValidator( NumericType numericType
, int base
= 10 );
162 virtual ~wxNumericPropertyValidator() { }
163 virtual bool Validate(wxWindow
* parent
);
166 #endif // wxUSE_VALIDATORS
169 /** @class wxIntProperty
171 Basic property with integer value.
173 Seamlessly supports 64-bit integer (wxLongLong) on overflow.
175 <b>Example how to use seamless 64-bit integer support</b>
180 wxLongLong_t value = pg->GetPropertyValueAsLongLong();
187 wxVariant variant = property->GetValue();
188 if ( variant.GetType() == "wxLongLong" )
189 value = wxLongLongFromVariant(variant);
191 value = variant.GetLong();
197 pg->SetPropertyValue(longLongVal);
203 property->SetValue(WXVARIANT(longLongVal));
207 <b>Supported special attributes:</b>
208 - "Min", "Max": Specify acceptable value range.
210 class WXDLLIMPEXP_PROPGRID wxIntProperty
: public wxPGProperty
212 WX_PG_DECLARE_PROPERTY_CLASS(wxIntProperty
)
214 wxIntProperty( const wxString
& label
= wxPG_LABEL
,
215 const wxString
& name
= wxPG_LABEL
,
217 virtual ~wxIntProperty();
219 wxIntProperty( const wxString
& label
,
220 const wxString
& name
,
221 const wxLongLong
& value
);
222 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
223 virtual bool StringToValue( wxVariant
& variant
,
224 const wxString
& text
,
225 int argFlags
= 0 ) const;
226 virtual bool ValidateValue( wxVariant
& value
,
227 wxPGValidationInfo
& validationInfo
) const;
228 virtual bool IntToValue( wxVariant
& variant
,
230 int argFlags
= 0 ) const;
231 static wxValidator
* GetClassValidator();
232 virtual wxValidator
* DoGetValidator() const;
234 /** Validation helper.
236 static bool DoValidation( const wxPGProperty
* property
,
238 wxPGValidationInfo
* pValidationInfo
,
240 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
245 // -----------------------------------------------------------------------
247 /** @class wxUIntProperty
249 Basic property with unsigned integer value.
250 Seamlessly supports 64-bit integer (wxULongLong) on overflow.
252 <b>Supported special attributes:</b>
253 - "Min", "Max": Specify acceptable value range.
254 - "Base": Define base. Valid constants are wxPG_BASE_OCT, wxPG_BASE_DEC,
255 wxPG_BASE_HEX and wxPG_BASE_HEXL (lowercase characters). Arbitrary bases
256 are <b>not</b> supported.
257 - "Prefix": Possible values are wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and
258 wxPG_PREFIX_DOLLAR_SIGN. Only wxPG_PREFIX_NONE works with Decimal and Octal
262 - For example how to use seamless 64-bit integer support, see wxIntProperty
263 documentation (just use wxULongLong instead of wxLongLong).
265 class WXDLLIMPEXP_PROPGRID wxUIntProperty
: public wxPGProperty
267 WX_PG_DECLARE_PROPERTY_CLASS(wxUIntProperty
)
269 wxUIntProperty( const wxString
& label
= wxPG_LABEL
,
270 const wxString
& name
= wxPG_LABEL
,
271 unsigned long value
= 0 );
272 virtual ~wxUIntProperty();
273 wxUIntProperty( const wxString
& label
,
274 const wxString
& name
,
275 const wxULongLong
& value
);
276 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
277 virtual bool StringToValue( wxVariant
& variant
,
278 const wxString
& text
,
279 int argFlags
= 0 ) const;
280 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
281 virtual bool ValidateValue( wxVariant
& value
,
282 wxPGValidationInfo
& validationInfo
) const;
283 virtual wxValidator
* DoGetValidator () const;
284 virtual bool IntToValue( wxVariant
& variant
,
286 int argFlags
= 0 ) const;
289 wxByte m_realBase
; // translated to 8,16,etc.
295 // -----------------------------------------------------------------------
297 /** @class wxFloatProperty
299 Basic property with double-precision floating point value.
301 <b>Supported special attributes:</b>
302 - "Precision": Sets the (max) precision used when floating point value is
303 rendered as text. The default -1 means infinite precision.
305 class WXDLLIMPEXP_PROPGRID wxFloatProperty
: public wxPGProperty
307 WX_PG_DECLARE_PROPERTY_CLASS(wxFloatProperty
)
309 wxFloatProperty( const wxString
& label
= wxPG_LABEL
,
310 const wxString
& name
= wxPG_LABEL
,
311 double value
= 0.0 );
312 virtual ~wxFloatProperty();
314 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
315 virtual bool StringToValue( wxVariant
& variant
,
316 const wxString
& text
,
317 int argFlags
= 0 ) const;
318 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
319 virtual bool ValidateValue( wxVariant
& value
,
320 wxPGValidationInfo
& validationInfo
) const;
322 /** Validation helper.
324 static bool DoValidation( const wxPGProperty
* property
,
326 wxPGValidationInfo
* pValidationInfo
,
328 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
329 static wxValidator
* GetClassValidator();
330 virtual wxValidator
* DoGetValidator () const;
336 // -----------------------------------------------------------------------
338 /** @class wxBoolProperty
340 Basic property with boolean value.
342 <b>Supported special attributes:</b>
343 - "UseCheckbox": Set to 1 to use check box editor instead of combo box.
344 - "UseDClickCycling": Set to 1 to cycle combo box instead showing the list.
346 class WXDLLIMPEXP_PROPGRID wxBoolProperty
: public wxPGProperty
348 WX_PG_DECLARE_PROPERTY_CLASS(wxBoolProperty
)
350 wxBoolProperty( const wxString
& label
= wxPG_LABEL
,
351 const wxString
& name
= wxPG_LABEL
,
352 bool value
= false );
353 virtual ~wxBoolProperty();
355 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
356 virtual bool StringToValue( wxVariant
& variant
,
357 const wxString
& text
,
358 int argFlags
= 0 ) const;
359 virtual bool IntToValue( wxVariant
& variant
,
360 int number
, int argFlags
= 0 ) const;
361 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
364 // -----------------------------------------------------------------------
366 // If set, then selection of choices is static and should not be
367 // changed (i.e. returns NULL in GetPropertyChoices).
368 #define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1
370 /** @class wxEnumProperty
372 You can derive custom properties with choices from this class. See
373 wxBaseEnumProperty for remarks.
376 - Updating private index is important. You can do this either by calling
377 SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue
378 be called (by not implementing it, or by calling super class function in
379 it) -OR- you can just call SetIndex in OnSetValue.
381 class WXDLLIMPEXP_PROPGRID wxEnumProperty
: public wxPGProperty
383 WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty
)
387 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
388 const wxString
& name
= wxPG_LABEL
,
389 const wxChar
* const* labels
= NULL
,
390 const long* values
= NULL
,
392 wxEnumProperty( const wxString
& label
,
393 const wxString
& name
,
394 wxPGChoices
& choices
,
397 // Special constructor for caching choices (used by derived class)
398 wxEnumProperty( const wxString
& label
,
399 const wxString
& name
,
400 const wxChar
* const* labels
,
402 wxPGChoices
* choicesCache
,
405 wxEnumProperty( const wxString
& label
,
406 const wxString
& name
,
407 const wxArrayString
& labels
,
408 const wxArrayInt
& values
= wxArrayInt(),
411 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
412 const wxString
& name
= wxPG_LABEL
,
413 const wxArrayString
& labels
= wxArrayString(),
414 const wxArrayInt
& values
= wxArrayInt(),
418 virtual ~wxEnumProperty();
420 size_t GetItemCount() const { return m_choices
.GetCount(); }
422 virtual void OnSetValue();
423 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
424 virtual bool StringToValue( wxVariant
& variant
,
425 const wxString
& text
,
426 int argFlags
= 0 ) const;
427 virtual bool ValidateValue( wxVariant
& value
,
428 wxPGValidationInfo
& validationInfo
) const;
430 // If wxPG_FULL_VALUE is not set in flags, then the value is interpreted
431 // as index to choices list. Otherwise, it is actual value.
432 virtual bool IntToValue( wxVariant
& variant
,
434 int argFlags
= 0 ) const;
437 // Additional virtuals
439 // This must be overridden to have non-index based value
440 virtual int GetIndexForValue( int value
) const;
442 // GetChoiceSelection needs to overridden since m_index is
443 // the true index, and various property classes derived from
444 // this take advantage of it.
445 virtual int GetChoiceSelection() const { return m_index
; }
447 virtual void OnValidationFailure( wxVariant
& pendingValue
);
451 int GetIndex() const;
452 void SetIndex( int index
);
454 bool ValueFromString_( wxVariant
& value
,
455 const wxString
& text
,
456 int argFlags
) const;
457 bool ValueFromInt_( wxVariant
& value
, int intVal
, int argFlags
) const;
459 static void ResetNextIndex() { ms_nextIndex
= -2; }
462 // This is private so that classes are guaranteed to use GetIndex
463 // for up-to-date index value.
466 // Relies on ValidateValue being called always before OnSetValue
467 static int ms_nextIndex
;
470 // -----------------------------------------------------------------------
472 /** @class wxEditEnumProperty
474 wxEnumProperty with wxString value and writable combo box editor.
477 Uses int value, similar to wxEnumProperty, unless text entered by user is
478 is not in choices (in which case string value is used).
480 class WXDLLIMPEXP_PROPGRID wxEditEnumProperty
: public wxEnumProperty
482 WX_PG_DECLARE_PROPERTY_CLASS(wxEditEnumProperty
)
485 wxEditEnumProperty( const wxString
& label
,
486 const wxString
& name
,
487 const wxChar
* const* labels
,
489 const wxString
& value
);
490 wxEditEnumProperty( const wxString
& label
= wxPG_LABEL
,
491 const wxString
& name
= wxPG_LABEL
,
492 const wxArrayString
& labels
= wxArrayString(),
493 const wxArrayInt
& values
= wxArrayInt(),
494 const wxString
& value
= wxEmptyString
);
495 wxEditEnumProperty( const wxString
& label
,
496 const wxString
& name
,
497 wxPGChoices
& choices
,
498 const wxString
& value
= wxEmptyString
);
500 // Special constructor for caching choices (used by derived class)
501 wxEditEnumProperty( const wxString
& label
,
502 const wxString
& name
,
503 const wxChar
* const* labels
,
505 wxPGChoices
* choicesCache
,
506 const wxString
& value
);
508 virtual ~wxEditEnumProperty();
513 // -----------------------------------------------------------------------
515 /** @class wxFlagsProperty
517 Represents a bit set that fits in a long integer. wxBoolProperty
518 sub-properties are created for editing individual bits. Textctrl is created
519 to manually edit the flags as a text; a continuous sequence of spaces,
520 commas and semicolons is considered as a flag id separator.
521 <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
522 you will need to use SetPropertyChoices - otherwise they will not get
525 class WXDLLIMPEXP_PROPGRID wxFlagsProperty
: public wxPGProperty
527 WX_PG_DECLARE_PROPERTY_CLASS(wxFlagsProperty
)
531 wxFlagsProperty( const wxString
& label
,
532 const wxString
& name
,
533 const wxChar
* const* labels
,
534 const long* values
= NULL
,
536 wxFlagsProperty( const wxString
& label
,
537 const wxString
& name
,
538 wxPGChoices
& choices
,
541 wxFlagsProperty( const wxString
& label
= wxPG_LABEL
,
542 const wxString
& name
= wxPG_LABEL
,
543 const wxArrayString
& labels
= wxArrayString(),
544 const wxArrayInt
& values
= wxArrayInt(),
546 virtual ~wxFlagsProperty ();
548 virtual void OnSetValue();
549 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
550 virtual bool StringToValue( wxVariant
& variant
,
551 const wxString
& text
,
553 virtual wxVariant
ChildChanged( wxVariant
& thisValue
,
555 wxVariant
& childValue
) const;
556 virtual void RefreshChildren();
557 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
559 // GetChoiceSelection needs to overridden since m_choices is
560 // used and value is integer, but it is not index.
561 virtual int GetChoiceSelection() const { return wxNOT_FOUND
; }
564 size_t GetItemCount() const { return m_choices
.GetCount(); }
565 const wxString
& GetLabel( size_t ind
) const
566 { return m_choices
.GetLabel(static_cast<int>(ind
)); }
569 // Used to detect if choices have been changed
570 wxPGChoicesData
* m_oldChoicesData
;
572 // Needed to properly mark changed sub-properties
575 // Converts string id to a relevant bit.
576 long IdToBit( const wxString
& id
) const;
578 // Creates children and sets value.
582 // -----------------------------------------------------------------------
584 /** @class wxPGFileDialogAdapter
587 class WXDLLIMPEXP_PROPGRID
588 wxPGFileDialogAdapter
: public wxPGEditorDialogAdapter
591 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
592 wxPGProperty
* property
);
595 // -----------------------------------------------------------------------
597 // Indicates first bit useable by derived properties.
598 #define wxPG_PROP_SHOW_FULL_FILENAME wxPG_PROP_CLASS_SPECIFIC_1
600 /** @class wxFileProperty
602 Like wxLongStringProperty, but the button triggers file selector instead.
604 <b>Supported special attributes:</b>
605 - "Wildcard": Sets wildcard (see wxFileDialog for format details), "All
606 files..." is default.
607 - "ShowFullPath": Default 1. When 0, only the file name is shown (i.e. drive
608 and directory are hidden).
609 - "ShowRelativePath": If set, then the filename is shown relative to the
611 - "InitialPath": Sets the initial path of where to look for files.
612 - "DialogTitle": Sets a specific title for the dir dialog.
614 class WXDLLIMPEXP_PROPGRID wxFileProperty
: public wxPGProperty
616 friend class wxPGFileDialogAdapter
;
617 WX_PG_DECLARE_PROPERTY_CLASS(wxFileProperty
)
620 wxFileProperty( const wxString
& label
= wxPG_LABEL
,
621 const wxString
& name
= wxPG_LABEL
,
622 const wxString
& value
= wxEmptyString
);
623 virtual ~wxFileProperty ();
625 virtual void OnSetValue();
626 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
627 virtual bool StringToValue( wxVariant
& variant
,
628 const wxString
& text
,
629 int argFlags
= 0 ) const;
630 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
631 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
633 static wxValidator
* GetClassValidator();
634 virtual wxValidator
* DoGetValidator() const;
637 Returns filename to file represented by current value.
639 wxFileName
GetFileName() const;
643 wxString m_basePath
; // If set, then show path relative to it
644 wxString m_initialPath
; // If set, start the file dialog here
645 wxString m_dlgTitle
; // If set, used as title for file dialog
646 int m_indFilter
; // index to the selected filter
649 // -----------------------------------------------------------------------
651 #define wxPG_PROP_NO_ESCAPE wxPG_PROP_CLASS_SPECIFIC_1
654 /** @class wxPGLongStringDialogAdapter
657 class WXDLLIMPEXP_PROPGRID
658 wxPGLongStringDialogAdapter
: public wxPGEditorDialogAdapter
661 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
662 wxPGProperty
* property
);
666 /** @class wxLongStringProperty
668 Like wxStringProperty, but has a button that triggers a small text
671 class WXDLLIMPEXP_PROPGRID wxLongStringProperty
: public wxPGProperty
673 WX_PG_DECLARE_PROPERTY_CLASS(wxLongStringProperty
)
676 wxLongStringProperty( const wxString
& label
= wxPG_LABEL
,
677 const wxString
& name
= wxPG_LABEL
,
678 const wxString
& value
= wxEmptyString
);
679 virtual ~wxLongStringProperty();
681 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
682 virtual bool StringToValue( wxVariant
& variant
,
683 const wxString
& text
,
684 int argFlags
= 0 ) const;
685 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
686 wxWindow
* primary
, wxEvent
& event
);
688 // Shows string editor dialog. Value to be edited should be read from
689 // value, and if dialog is not cancelled, it should be stored back and true
690 // should be returned if that was the case.
691 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
, wxString
& value
);
693 static bool DisplayEditorDialog( wxPGProperty
* prop
,
694 wxPropertyGrid
* propGrid
,
700 // -----------------------------------------------------------------------
703 /** @class wxDirProperty
705 Like wxLongStringProperty, but the button triggers dir selector instead.
707 <b>Supported special attributes:</b>
708 - "DialogMessage": Sets specific message in the dir selector.
710 class WXDLLIMPEXP_PROPGRID wxDirProperty
: public wxLongStringProperty
712 DECLARE_DYNAMIC_CLASS(wxDirProperty
)
714 wxDirProperty( const wxString
& name
= wxPG_LABEL
,
715 const wxString
& label
= wxPG_LABEL
,
716 const wxString
& value
= wxEmptyString
);
717 virtual ~wxDirProperty();
719 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
720 virtual wxValidator
* DoGetValidator() const;
722 virtual bool OnButtonClick ( wxPropertyGrid
* propGrid
, wxString
& value
);
725 wxString m_dlgMessage
;
728 // -----------------------------------------------------------------------
730 // wxBoolProperty specific flags
731 #define wxPG_PROP_USE_CHECKBOX wxPG_PROP_CLASS_SPECIFIC_1
732 // DCC = Double Click Cycles
733 #define wxPG_PROP_USE_DCC wxPG_PROP_CLASS_SPECIFIC_2
736 // -----------------------------------------------------------------------
738 /** @class wxArrayStringProperty
740 Property that manages a list of strings.
742 class WXDLLIMPEXP_PROPGRID wxArrayStringProperty
: public wxPGProperty
744 WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty
)
746 wxArrayStringProperty( const wxString
& label
= wxPG_LABEL
,
747 const wxString
& name
= wxPG_LABEL
,
748 const wxArrayString
& value
= wxArrayString() );
749 virtual ~wxArrayStringProperty();
751 virtual void OnSetValue();
752 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
753 virtual bool StringToValue( wxVariant
& variant
,
754 const wxString
& text
,
755 int argFlags
= 0 ) const;
756 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
757 wxWindow
* primary
, wxEvent
& event
);
758 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
760 // Implement in derived class for custom array-to-string conversion.
761 virtual void ConvertArrayToString(const wxArrayString
& arr
,
763 const wxUniChar
& delimiter
) const;
765 // Shows string editor dialog. Value to be edited should be read from
766 // value, and if dialog is not cancelled, it should be stored back and true
767 // should be returned if that was the case.
768 virtual bool OnCustomStringEdit( wxWindow
* parent
, wxString
& value
);
771 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
,
775 // Creates wxPGArrayEditorDialog for string editing. Called in OnButtonClick.
776 virtual wxPGArrayEditorDialog
* CreateEditorDialog();
785 Generates contents for string dst based on the contents of
788 static void ArrayStringToString( wxString
& dst
, const wxArrayString
& src
,
789 wxUniChar delimiter
, int flags
);
792 // Previously this was to be implemented in derived class for array-to-
793 // string conversion. Now you should implement ConvertValueToString()
795 virtual void GenerateValueAsString();
797 wxString m_display
; // Cache for displayed text.
798 wxUniChar m_delimiter
;
801 // -----------------------------------------------------------------------
803 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, \
805 DECL PROPNAME : public wxArrayStringProperty \
807 WX_PG_DECLARE_PROPERTY_CLASS(PROPNAME) \
809 PROPNAME( const wxString& label = wxPG_LABEL, \
810 const wxString& name = wxPG_LABEL, \
811 const wxArrayString& value = wxArrayString() ); \
813 virtual bool OnEvent( wxPropertyGrid* propgrid, \
814 wxWindow* primary, wxEvent& event ); \
815 virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \
816 virtual wxValidator* DoGetValidator() const; \
819 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM) \
820 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM, class)
822 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
825 WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME, wxArrayStringProperty, \
826 wxArrayString, const wxArrayString&, \
828 PROPNAME::PROPNAME( const wxString& label, \
829 const wxString& name, \
830 const wxArrayString& value ) \
831 : wxArrayStringProperty(label,name,value) \
833 PROPNAME::GenerateValueAsString(); \
834 m_delimiter = DELIMCHAR; \
836 PROPNAME::~PROPNAME() { } \
837 bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
838 wxWindow* primary, wxEvent& event ) \
840 if ( event.GetEventType() == wxEVT_BUTTON ) \
841 return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \
845 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \
846 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME)
848 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_DECL(PROPNAME, DECL) \
849 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, DECL)
851 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \
852 WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
855 wxValidator* PROPNAME::DoGetValidator () const \
859 // -----------------------------------------------------------------------
860 // wxPGArrayEditorDialog
861 // -----------------------------------------------------------------------
863 #if wxUSE_EDITABLELISTBOX
865 class WXDLLIMPEXP_FWD_ADV wxEditableListBox
;
866 class WXDLLIMPEXP_FWD_CORE wxListEvent
;
868 #define wxAEDIALOG_STYLE \
869 (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
871 class WXDLLIMPEXP_PROPGRID wxPGArrayEditorDialog
: public wxDialog
874 wxPGArrayEditorDialog();
875 virtual ~wxPGArrayEditorDialog() { }
879 wxPGArrayEditorDialog( wxWindow
*parent
,
880 const wxString
& message
,
881 const wxString
& caption
,
882 long style
= wxAEDIALOG_STYLE
,
883 const wxPoint
& pos
= wxDefaultPosition
,
884 const wxSize
& sz
= wxDefaultSize
);
886 bool Create( wxWindow
*parent
,
887 const wxString
& message
,
888 const wxString
& caption
,
889 long style
= wxAEDIALOG_STYLE
,
890 const wxPoint
& pos
= wxDefaultPosition
,
891 const wxSize
& sz
= wxDefaultSize
);
893 void EnableCustomNewAction()
895 m_hasCustomNewAction
= true;
898 /** Set value modified by dialog.
900 virtual void SetDialogValue( const wxVariant
& WXUNUSED(value
) )
902 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
905 /** Return value modified by dialog.
907 virtual wxVariant
GetDialogValue() const
909 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
913 /** Override to return wxValidator to be used with the wxTextCtrl
914 in dialog. Note that the validator is used in the standard
915 wx way, ie. it immediately prevents user from entering invalid
919 Dialog frees the validator.
921 virtual wxValidator
* GetTextCtrlValidator() const
926 // Returns true if array was actually modified
927 bool IsModified() const { return m_modified
; }
929 // wxEditableListBox utilities
930 int GetSelection() const;
932 // implementation from now on
933 void OnAddClick(wxCommandEvent
& event
);
934 void OnDeleteClick(wxCommandEvent
& event
);
935 void OnUpClick(wxCommandEvent
& event
);
936 void OnDownClick(wxCommandEvent
& event
);
937 void OnEndLabelEdit(wxListEvent
& event
);
938 void OnIdle(wxIdleEvent
& event
);
941 wxEditableListBox
* m_elb
;
943 // These are used for focus repair
944 wxWindow
* m_elbSubPanel
;
945 wxWindow
* m_lastFocused
;
947 // A new item, edited by user, is pending at this index.
948 // It will be committed once list ctrl item editing is done.
949 int m_itemPendingAtIndex
;
952 bool m_hasCustomNewAction
;
954 // These must be overridden - must return true on success.
955 virtual wxString
ArrayGet( size_t index
) = 0;
956 virtual size_t ArrayGetCount() = 0;
957 virtual bool ArrayInsert( const wxString
& str
, int index
) = 0;
958 virtual bool ArraySet( size_t index
, const wxString
& str
) = 0;
959 virtual void ArrayRemoveAt( int index
) = 0;
960 virtual void ArraySwap( size_t first
, size_t second
) = 0;
961 virtual bool OnCustomNewAction(wxString
* WXUNUSED(resString
))
967 DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayEditorDialog
)
968 DECLARE_EVENT_TABLE()
971 #endif // wxUSE_EDITABLELISTBOX
973 // -----------------------------------------------------------------------
974 // wxPGArrayStringEditorDialog
975 // -----------------------------------------------------------------------
977 class WXDLLIMPEXP_PROPGRID
978 wxPGArrayStringEditorDialog
: public wxPGArrayEditorDialog
981 wxPGArrayStringEditorDialog();
982 virtual ~wxPGArrayStringEditorDialog() { }
986 virtual void SetDialogValue( const wxVariant
& value
)
988 m_array
= value
.GetArrayString();
991 virtual wxVariant
GetDialogValue() const
996 void SetCustomButton( const wxString
& custBtText
,
997 wxArrayStringProperty
* pcc
)
999 if ( !custBtText
.empty() )
1001 EnableCustomNewAction();
1002 m_pCallingClass
= pcc
;
1006 virtual bool OnCustomNewAction(wxString
* resString
);
1009 wxArrayString m_array
;
1011 wxArrayStringProperty
* m_pCallingClass
;
1013 virtual wxString
ArrayGet( size_t index
);
1014 virtual size_t ArrayGetCount();
1015 virtual bool ArrayInsert( const wxString
& str
, int index
);
1016 virtual bool ArraySet( size_t index
, const wxString
& str
);
1017 virtual void ArrayRemoveAt( int index
);
1018 virtual void ArraySwap( size_t first
, size_t second
);
1021 DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog
)
1022 DECLARE_EVENT_TABLE()
1025 // -----------------------------------------------------------------------
1027 #endif // wxUSE_PROPGRID
1029 #endif // _WX_PROPGRID_PROPS_H_