1 /////////////////////////////////////////////////////////////////////////////
2 // Name: wx/propgrid/props.h
3 // Purpose: wxPropertyGrid Property Classes
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
12 #ifndef _WX_PROPGRID_PROPS_H_
13 #define _WX_PROPGRID_PROPS_H_
19 // -----------------------------------------------------------------------
21 class wxPGArrayEditorDialog
;
23 #include "wx/propgrid/editors.h"
25 #include "wx/filename.h"
26 #include "wx/dialog.h"
27 #include "wx/textctrl.h"
28 #include "wx/button.h"
29 #include "wx/listbox.h"
30 #include "wx/valtext.h"
32 // -----------------------------------------------------------------------
35 // Property class implementation helper macros.
38 #define WX_PG_IMPLEMENT_PROPERTY_CLASS(NAME, UPCLASS, T, T_AS_ARG, EDITOR) \
39 IMPLEMENT_DYNAMIC_CLASS(NAME, UPCLASS) \
40 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(NAME, T, EDITOR)
42 // -----------------------------------------------------------------------
45 // These macros help creating DoGetValidator
46 #define WX_PG_DOGETVALIDATOR_ENTRY() \
47 static wxValidator* s_ptr = NULL; \
48 if ( s_ptr ) return s_ptr;
50 // Common function exit
51 #define WX_PG_DOGETVALIDATOR_EXIT(VALIDATOR) \
53 wxPGGlobalVars->m_arrValidators.push_back( VALIDATOR ); \
56 // -----------------------------------------------------------------------
58 /** @class wxPGInDialogValidator
60 Creates and manages a temporary wxTextCtrl for validation purposes.
61 Uses wxPropertyGrid's current editor, if available.
63 class WXDLLIMPEXP_PROPGRID wxPGInDialogValidator
66 wxPGInDialogValidator()
71 ~wxPGInDialogValidator()
74 m_textCtrl
->Destroy();
77 bool DoValidate( wxPropertyGrid
* propGrid
,
78 wxValidator
* validator
,
79 const wxString
& value
);
82 wxTextCtrl
* m_textCtrl
;
86 // -----------------------------------------------------------------------
88 // -----------------------------------------------------------------------
90 #define wxPG_PROP_PASSWORD wxPG_PROP_CLASS_SPECIFIC_2
92 /** @class wxStringProperty
94 Basic property with string value.
96 <b>Supported special attributes:</b>
97 - "Password": set to 1 inorder to enable wxTE_PASSWORD on the editor.
100 - If value "<composed>" is set, then actual value is formed (or composed)
101 from values of child properties.
103 class WXDLLIMPEXP_PROPGRID wxStringProperty
: public wxPGProperty
105 WX_PG_DECLARE_PROPERTY_CLASS(wxStringProperty
)
107 wxStringProperty( const wxString
& label
= wxPG_LABEL
,
108 const wxString
& name
= wxPG_LABEL
,
109 const wxString
& value
= wxEmptyString
);
110 virtual ~wxStringProperty();
112 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
113 virtual bool StringToValue( wxVariant
& variant
,
114 const wxString
& text
,
115 int argFlags
= 0 ) const;
117 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
119 /** This is updated so "<composed>" special value can be handled.
121 virtual void OnSetValue();
126 // -----------------------------------------------------------------------
128 /** Constants used with NumericValidation<>().
130 enum wxPGNumericValidationConstants
132 /** Instead of modifying the value, show an error message.
134 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
= 0,
136 /** Modify value, but stick with the limitations.
138 wxPG_PROPERTY_VALIDATION_SATURATE
= 1,
140 /** Modify value, wrap around on overflow.
142 wxPG_PROPERTY_VALIDATION_WRAP
= 2
145 // -----------------------------------------------------------------------
150 A more comprehensive numeric validator class.
152 class WXDLLIMPEXP_PROPGRID wxNumericPropertyValidator
: public wxTextValidator
162 wxNumericPropertyValidator( NumericType numericType
, int base
= 10 );
163 virtual ~wxNumericPropertyValidator() { }
164 virtual bool Validate(wxWindow
* parent
);
167 #endif // wxUSE_VALIDATORS
170 /** @class wxIntProperty
172 Basic property with integer value.
174 Seamlessly supports 64-bit integer (wxLongLong) on overflow.
176 <b>Example how to use seamless 64-bit integer support</b>
181 wxLongLong_t value = pg->GetPropertyValueAsLongLong();
188 wxVariant variant = property->GetValue();
189 if ( variant.GetType() == "wxLongLong" )
190 value = wxLongLongFromVariant(variant);
192 value = variant.GetLong();
198 pg->SetPropertyValue(longLongVal);
204 property->SetValue(WXVARIANT(longLongVal));
208 <b>Supported special attributes:</b>
209 - "Min", "Max": Specify acceptable value range.
211 class WXDLLIMPEXP_PROPGRID wxIntProperty
: public wxPGProperty
213 WX_PG_DECLARE_PROPERTY_CLASS(wxIntProperty
)
215 wxIntProperty( const wxString
& label
= wxPG_LABEL
,
216 const wxString
& name
= wxPG_LABEL
,
218 virtual ~wxIntProperty();
220 wxIntProperty( const wxString
& label
,
221 const wxString
& name
,
222 const wxLongLong
& value
);
223 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
224 virtual bool StringToValue( wxVariant
& variant
,
225 const wxString
& text
,
226 int argFlags
= 0 ) const;
227 virtual bool ValidateValue( wxVariant
& value
,
228 wxPGValidationInfo
& validationInfo
) const;
229 virtual bool IntToValue( wxVariant
& variant
,
231 int argFlags
= 0 ) const;
232 static wxValidator
* GetClassValidator();
233 virtual wxValidator
* DoGetValidator() const;
235 /** Validation helper.
237 static bool DoValidation( const wxPGProperty
* property
,
239 wxPGValidationInfo
* pValidationInfo
,
241 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
246 // -----------------------------------------------------------------------
248 /** @class wxUIntProperty
250 Basic property with unsigned integer value.
251 Seamlessly supports 64-bit integer (wxULongLong) on overflow.
253 <b>Supported special attributes:</b>
254 - "Min", "Max": Specify acceptable value range.
255 - "Base": Define base. Valid constants are wxPG_BASE_OCT, wxPG_BASE_DEC,
256 wxPG_BASE_HEX and wxPG_BASE_HEXL (lowercase characters). Arbitrary bases
257 are <b>not</b> supported.
258 - "Prefix": Possible values are wxPG_PREFIX_NONE, wxPG_PREFIX_0x, and
259 wxPG_PREFIX_DOLLAR_SIGN. Only wxPG_PREFIX_NONE works with Decimal and Octal
263 - For example how to use seamless 64-bit integer support, see wxIntProperty
264 documentation (just use wxULongLong instead of wxLongLong).
266 class WXDLLIMPEXP_PROPGRID wxUIntProperty
: public wxPGProperty
268 WX_PG_DECLARE_PROPERTY_CLASS(wxUIntProperty
)
270 wxUIntProperty( const wxString
& label
= wxPG_LABEL
,
271 const wxString
& name
= wxPG_LABEL
,
272 unsigned long value
= 0 );
273 virtual ~wxUIntProperty();
274 wxUIntProperty( const wxString
& label
,
275 const wxString
& name
,
276 const wxULongLong
& value
);
277 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
278 virtual bool StringToValue( wxVariant
& variant
,
279 const wxString
& text
,
280 int argFlags
= 0 ) const;
281 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
282 virtual bool ValidateValue( wxVariant
& value
,
283 wxPGValidationInfo
& validationInfo
) const;
284 virtual wxValidator
* DoGetValidator () const;
285 virtual bool IntToValue( wxVariant
& variant
,
287 int argFlags
= 0 ) const;
290 wxByte m_realBase
; // translated to 8,16,etc.
296 // -----------------------------------------------------------------------
298 /** @class wxFloatProperty
300 Basic property with double-precision floating point value.
302 <b>Supported special attributes:</b>
303 - "Precision": Sets the (max) precision used when floating point value is
304 rendered as text. The default -1 means infinite precision.
306 class WXDLLIMPEXP_PROPGRID wxFloatProperty
: public wxPGProperty
308 WX_PG_DECLARE_PROPERTY_CLASS(wxFloatProperty
)
310 wxFloatProperty( const wxString
& label
= wxPG_LABEL
,
311 const wxString
& name
= wxPG_LABEL
,
312 double value
= 0.0 );
313 virtual ~wxFloatProperty();
315 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
316 virtual bool StringToValue( wxVariant
& variant
,
317 const wxString
& text
,
318 int argFlags
= 0 ) const;
319 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
320 virtual bool ValidateValue( wxVariant
& value
,
321 wxPGValidationInfo
& validationInfo
) const;
323 /** Validation helper.
325 static bool DoValidation( const wxPGProperty
* property
,
327 wxPGValidationInfo
* pValidationInfo
,
329 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
330 static wxValidator
* GetClassValidator();
331 virtual wxValidator
* DoGetValidator () const;
337 // -----------------------------------------------------------------------
339 /** @class wxBoolProperty
341 Basic property with boolean value.
343 <b>Supported special attributes:</b>
344 - "UseCheckbox": Set to 1 to use check box editor instead of combo box.
345 - "UseDClickCycling": Set to 1 to cycle combo box instead showing the list.
347 class WXDLLIMPEXP_PROPGRID wxBoolProperty
: public wxPGProperty
349 WX_PG_DECLARE_PROPERTY_CLASS(wxBoolProperty
)
351 wxBoolProperty( const wxString
& label
= wxPG_LABEL
,
352 const wxString
& name
= wxPG_LABEL
,
353 bool value
= false );
354 virtual ~wxBoolProperty();
356 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
357 virtual bool StringToValue( wxVariant
& variant
,
358 const wxString
& text
,
359 int argFlags
= 0 ) const;
360 virtual bool IntToValue( wxVariant
& variant
,
361 int number
, int argFlags
= 0 ) const;
362 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
365 // -----------------------------------------------------------------------
367 // If set, then selection of choices is static and should not be
368 // changed (i.e. returns NULL in GetPropertyChoices).
369 #define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1
371 /** @class wxEnumProperty
373 You can derive custom properties with choices from this class. See
374 wxBaseEnumProperty for remarks.
377 - Updating private index is important. You can do this either by calling
378 SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue
379 be called (by not implementing it, or by calling super class function in
380 it) -OR- you can just call SetIndex in OnSetValue.
382 class WXDLLIMPEXP_PROPGRID wxEnumProperty
: public wxPGProperty
384 WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty
)
388 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
389 const wxString
& name
= wxPG_LABEL
,
390 const wxChar
* const* labels
= NULL
,
391 const long* values
= NULL
,
393 wxEnumProperty( const wxString
& label
,
394 const wxString
& name
,
395 wxPGChoices
& choices
,
398 // Special constructor for caching choices (used by derived class)
399 wxEnumProperty( const wxString
& label
,
400 const wxString
& name
,
401 const wxChar
* const* labels
,
403 wxPGChoices
* choicesCache
,
406 wxEnumProperty( const wxString
& label
,
407 const wxString
& name
,
408 const wxArrayString
& labels
,
409 const wxArrayInt
& values
= wxArrayInt(),
412 wxEnumProperty( const wxString
& label
= wxPG_LABEL
,
413 const wxString
& name
= wxPG_LABEL
,
414 const wxArrayString
& labels
= wxArrayString(),
415 const wxArrayInt
& values
= wxArrayInt(),
419 virtual ~wxEnumProperty();
421 size_t GetItemCount() const { return m_choices
.GetCount(); }
423 virtual void OnSetValue();
424 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
425 virtual bool StringToValue( wxVariant
& variant
,
426 const wxString
& text
,
427 int argFlags
= 0 ) const;
428 virtual bool ValidateValue( wxVariant
& value
,
429 wxPGValidationInfo
& validationInfo
) const;
431 // If wxPG_FULL_VALUE is not set in flags, then the value is interpreted
432 // as index to choices list. Otherwise, it is actual value.
433 virtual bool IntToValue( wxVariant
& variant
,
435 int argFlags
= 0 ) const;
438 // Additional virtuals
440 // This must be overridden to have non-index based value
441 virtual int GetIndexForValue( int value
) const;
443 // GetChoiceSelection needs to overridden since m_index is
444 // the true index, and various property classes derived from
445 // this take advantage of it.
446 virtual int GetChoiceSelection() const { return m_index
; }
448 virtual void OnValidationFailure( wxVariant
& pendingValue
);
452 int GetIndex() const;
453 void SetIndex( int index
);
455 bool ValueFromString_( wxVariant
& value
,
456 const wxString
& text
,
457 int argFlags
) const;
458 bool ValueFromInt_( wxVariant
& value
, int intVal
, int argFlags
) const;
460 static void ResetNextIndex() { ms_nextIndex
= -2; }
463 // This is private so that classes are guaranteed to use GetIndex
464 // for up-to-date index value.
467 // Relies on ValidateValue being called always before OnSetValue
468 static int ms_nextIndex
;
471 // -----------------------------------------------------------------------
473 /** @class wxEditEnumProperty
475 wxEnumProperty with wxString value and writable combo box editor.
478 Uses int value, similar to wxEnumProperty, unless text entered by user is
479 is not in choices (in which case string value is used).
481 class WXDLLIMPEXP_PROPGRID wxEditEnumProperty
: public wxEnumProperty
483 WX_PG_DECLARE_PROPERTY_CLASS(wxEditEnumProperty
)
486 wxEditEnumProperty( const wxString
& label
,
487 const wxString
& name
,
488 const wxChar
* const* labels
,
490 const wxString
& value
);
491 wxEditEnumProperty( const wxString
& label
= wxPG_LABEL
,
492 const wxString
& name
= wxPG_LABEL
,
493 const wxArrayString
& labels
= wxArrayString(),
494 const wxArrayInt
& values
= wxArrayInt(),
495 const wxString
& value
= wxEmptyString
);
496 wxEditEnumProperty( const wxString
& label
,
497 const wxString
& name
,
498 wxPGChoices
& choices
,
499 const wxString
& value
= wxEmptyString
);
501 // Special constructor for caching choices (used by derived class)
502 wxEditEnumProperty( const wxString
& label
,
503 const wxString
& name
,
504 const wxChar
* const* labels
,
506 wxPGChoices
* choicesCache
,
507 const wxString
& value
);
509 virtual ~wxEditEnumProperty();
514 // -----------------------------------------------------------------------
516 /** @class wxFlagsProperty
518 Represents a bit set that fits in a long integer. wxBoolProperty
519 sub-properties are created for editing individual bits. Textctrl is created
520 to manually edit the flags as a text; a continous sequence of spaces,
521 commas and semicolons is considered as a flag id separator.
522 <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
523 you will need to use SetPropertyChoices - otherwise they will not get
526 class WXDLLIMPEXP_PROPGRID wxFlagsProperty
: public wxPGProperty
528 WX_PG_DECLARE_PROPERTY_CLASS(wxFlagsProperty
)
532 wxFlagsProperty( const wxString
& label
,
533 const wxString
& name
,
534 const wxChar
* const* labels
,
535 const long* values
= NULL
,
537 wxFlagsProperty( const wxString
& label
,
538 const wxString
& name
,
539 wxPGChoices
& choices
,
542 wxFlagsProperty( const wxString
& label
= wxPG_LABEL
,
543 const wxString
& name
= wxPG_LABEL
,
544 const wxArrayString
& labels
= wxArrayString(),
545 const wxArrayInt
& values
= wxArrayInt(),
547 virtual ~wxFlagsProperty ();
549 virtual void OnSetValue();
550 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
551 virtual bool StringToValue( wxVariant
& variant
,
552 const wxString
& text
,
554 virtual wxVariant
ChildChanged( wxVariant
& thisValue
,
556 wxVariant
& childValue
) const;
557 virtual void RefreshChildren();
558 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
560 // GetChoiceSelection needs to overridden since m_choices is
561 // used and value is integer, but it is not index.
562 virtual int GetChoiceSelection() const { return wxNOT_FOUND
; }
565 size_t GetItemCount() const { return m_choices
.GetCount(); }
566 const wxString
& GetLabel( size_t ind
) const
567 { return m_choices
.GetLabel(ind
); }
570 // Used to detect if choices have been changed
571 wxPGChoicesData
* m_oldChoicesData
;
573 // Needed to properly mark changed sub-properties
576 // Converts string id to a relevant bit.
577 long IdToBit( const wxString
& id
) const;
579 // Creates children and sets value.
583 // -----------------------------------------------------------------------
585 /** @class wxPGFileDialogAdapter
588 class WXDLLIMPEXP_PROPGRID
589 wxPGFileDialogAdapter
: public wxPGEditorDialogAdapter
592 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
593 wxPGProperty
* property
);
596 // -----------------------------------------------------------------------
598 // Indicates first bit useable by derived properties.
599 #define wxPG_PROP_SHOW_FULL_FILENAME wxPG_PROP_CLASS_SPECIFIC_1
601 /** @class wxFileProperty
603 Like wxLongStringProperty, but the button triggers file selector instead.
605 <b>Supported special attributes:</b>
606 - "Wildcard": Sets wildcard (see wxFileDialog for format details), "All
607 files..." is default.
608 - "ShowFullPath": Default 1. When 0, only the file name is shown (i.e. drive
609 and directory are hidden).
610 - "ShowRelativePath": If set, then the filename is shown relative to the
612 - "InitialPath": Sets the initial path of where to look for files.
613 - "DialogTitle": Sets a specific title for the dir dialog.
615 class WXDLLIMPEXP_PROPGRID wxFileProperty
: public wxPGProperty
617 friend class wxPGFileDialogAdapter
;
618 WX_PG_DECLARE_PROPERTY_CLASS(wxFileProperty
)
621 wxFileProperty( const wxString
& label
= wxPG_LABEL
,
622 const wxString
& name
= wxPG_LABEL
,
623 const wxString
& value
= wxEmptyString
);
624 virtual ~wxFileProperty ();
626 virtual void OnSetValue();
627 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
628 virtual bool StringToValue( wxVariant
& variant
,
629 const wxString
& text
,
630 int argFlags
= 0 ) const;
631 virtual wxPGEditorDialogAdapter
* GetEditorDialog() const;
632 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
634 static wxValidator
* GetClassValidator();
635 virtual wxValidator
* DoGetValidator() const;
638 Returns filename to file represented by current value.
640 wxFileName
GetFileName() const;
644 wxString m_basePath
; // If set, then show path relative to it
645 wxString m_initialPath
; // If set, start the file dialog here
646 wxString m_dlgTitle
; // If set, used as title for file dialog
647 int m_indFilter
; // index to the selected filter
650 // -----------------------------------------------------------------------
652 #define wxPG_PROP_NO_ESCAPE wxPG_PROP_CLASS_SPECIFIC_1
655 /** @class wxPGLongStringDialogAdapter
658 class WXDLLIMPEXP_PROPGRID
659 wxPGLongStringDialogAdapter
: public wxPGEditorDialogAdapter
662 virtual bool DoShowDialog( wxPropertyGrid
* propGrid
,
663 wxPGProperty
* property
);
667 /** @class wxLongStringProperty
669 Like wxStringProperty, but has a button that triggers a small text
672 class WXDLLIMPEXP_PROPGRID wxLongStringProperty
: public wxPGProperty
674 WX_PG_DECLARE_PROPERTY_CLASS(wxLongStringProperty
)
677 wxLongStringProperty( const wxString
& label
= wxPG_LABEL
,
678 const wxString
& name
= wxPG_LABEL
,
679 const wxString
& value
= wxEmptyString
);
680 virtual ~wxLongStringProperty();
682 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
683 virtual bool StringToValue( wxVariant
& variant
,
684 const wxString
& text
,
685 int argFlags
= 0 ) const;
686 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
687 wxWindow
* primary
, wxEvent
& event
);
689 // Shows string editor dialog. Value to be edited should be read from
690 // value, and if dialog is not cancelled, it should be stored back and true
691 // should be returned if that was the case.
692 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
, wxString
& value
);
694 static bool DisplayEditorDialog( wxPGProperty
* prop
,
695 wxPropertyGrid
* propGrid
,
701 // -----------------------------------------------------------------------
704 /** @class wxDirProperty
706 Like wxLongStringProperty, but the button triggers dir selector instead.
708 <b>Supported special attributes:</b>
709 - "DialogMessage": Sets specific message in the dir selector.
711 class WXDLLIMPEXP_PROPGRID wxDirProperty
: public wxLongStringProperty
713 DECLARE_DYNAMIC_CLASS(wxDirProperty
)
715 wxDirProperty( const wxString
& name
= wxPG_LABEL
,
716 const wxString
& label
= wxPG_LABEL
,
717 const wxString
& value
= wxEmptyString
);
718 virtual ~wxDirProperty();
720 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
721 virtual wxValidator
* DoGetValidator() const;
723 virtual bool OnButtonClick ( wxPropertyGrid
* propGrid
, wxString
& value
);
726 wxString m_dlgMessage
;
729 // -----------------------------------------------------------------------
731 // wxBoolProperty specific flags
732 #define wxPG_PROP_USE_CHECKBOX wxPG_PROP_CLASS_SPECIFIC_1
733 // DCC = Double Click Cycles
734 #define wxPG_PROP_USE_DCC wxPG_PROP_CLASS_SPECIFIC_2
737 // -----------------------------------------------------------------------
739 /** @class wxArrayStringProperty
741 Property that manages a list of strings.
743 class WXDLLIMPEXP_PROPGRID wxArrayStringProperty
: public wxPGProperty
745 WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty
)
747 wxArrayStringProperty( const wxString
& label
= wxPG_LABEL
,
748 const wxString
& name
= wxPG_LABEL
,
749 const wxArrayString
& value
= wxArrayString() );
750 virtual ~wxArrayStringProperty();
752 virtual void OnSetValue();
753 virtual wxString
ValueToString( wxVariant
& value
, int argFlags
= 0 ) const;
754 virtual bool StringToValue( wxVariant
& variant
,
755 const wxString
& text
,
756 int argFlags
= 0 ) const;
757 virtual bool OnEvent( wxPropertyGrid
* propgrid
,
758 wxWindow
* primary
, wxEvent
& event
);
759 virtual bool DoSetAttribute( const wxString
& name
, wxVariant
& value
);
761 // Implement in derived class for custom array-to-string conversion.
762 virtual void ConvertArrayToString(const wxArrayString
& arr
,
764 const wxUniChar
& delimiter
) const;
766 // Shows string editor dialog. Value to be edited should be read from
767 // value, and if dialog is not cancelled, it should be stored back and true
768 // should be returned if that was the case.
769 virtual bool OnCustomStringEdit( wxWindow
* parent
, wxString
& value
);
772 virtual bool OnButtonClick( wxPropertyGrid
* propgrid
,
776 // Creates wxPGArrayEditorDialog for string editing. Called in OnButtonClick.
777 virtual wxPGArrayEditorDialog
* CreateEditorDialog();
786 Generates contents for string dst based on the contents of
789 static void ArrayStringToString( wxString
& dst
, const wxArrayString
& src
,
790 wxUniChar delimiter
, int flags
);
793 // Previously this was to be implemented in derived class for array-to-
794 // string conversion. Now you should implement ConvertValueToString()
796 virtual void GenerateValueAsString();
798 wxString m_display
; // Cache for displayed text.
799 wxUniChar m_delimiter
;
802 // -----------------------------------------------------------------------
804 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, \
806 DECL PROPNAME : public wxArrayStringProperty \
808 WX_PG_DECLARE_PROPERTY_CLASS(PROPNAME) \
810 PROPNAME( const wxString& label = wxPG_LABEL, \
811 const wxString& name = wxPG_LABEL, \
812 const wxArrayString& value = wxArrayString() ); \
814 virtual bool OnEvent( wxPropertyGrid* propgrid, \
815 wxWindow* primary, wxEvent& event ); \
816 virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \
817 virtual wxValidator* DoGetValidator() const; \
820 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM) \
821 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM, class)
823 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
826 WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME, wxArrayStringProperty, \
827 wxArrayString, const wxArrayString&, \
829 PROPNAME::PROPNAME( const wxString& label, \
830 const wxString& name, \
831 const wxArrayString& value ) \
832 : wxArrayStringProperty(label,name,value) \
834 PROPNAME::GenerateValueAsString(); \
835 m_delimiter = DELIMCHAR; \
837 PROPNAME::~PROPNAME() { } \
838 bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
839 wxWindow* primary, wxEvent& event ) \
841 if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) \
842 return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \
846 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \
847 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME)
849 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_DECL(PROPNAME, DECL) \
850 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, DECL)
852 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \
853 WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
856 wxValidator* PROPNAME::DoGetValidator () const \
860 // -----------------------------------------------------------------------
861 // wxPGArrayEditorDialog
862 // -----------------------------------------------------------------------
864 #if wxUSE_EDITABLELISTBOX
866 class WXDLLIMPEXP_FWD_ADV wxEditableListBox
;
867 class WXDLLIMPEXP_FWD_CORE wxListEvent
;
869 #define wxAEDIALOG_STYLE \
870 (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
872 class WXDLLIMPEXP_PROPGRID wxPGArrayEditorDialog
: public wxDialog
875 wxPGArrayEditorDialog();
876 virtual ~wxPGArrayEditorDialog() { }
880 wxPGArrayEditorDialog( wxWindow
*parent
,
881 const wxString
& message
,
882 const wxString
& caption
,
883 long style
= wxAEDIALOG_STYLE
,
884 const wxPoint
& pos
= wxDefaultPosition
,
885 const wxSize
& sz
= wxDefaultSize
);
887 bool Create( wxWindow
*parent
,
888 const wxString
& message
,
889 const wxString
& caption
,
890 long style
= wxAEDIALOG_STYLE
,
891 const wxPoint
& pos
= wxDefaultPosition
,
892 const wxSize
& sz
= wxDefaultSize
);
894 void EnableCustomNewAction()
896 m_hasCustomNewAction
= true;
899 /** Set value modified by dialog.
901 virtual void SetDialogValue( const wxVariant
& WXUNUSED(value
) )
903 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
906 /** Return value modified by dialog.
908 virtual wxVariant
GetDialogValue() const
910 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
914 /** Override to return wxValidator to be used with the wxTextCtrl
915 in dialog. Note that the validator is used in the standard
916 wx way, ie. it immediately prevents user from entering invalid
920 Dialog frees the validator.
922 virtual wxValidator
* GetTextCtrlValidator() const
927 // Returns true if array was actually modified
928 bool IsModified() const { return m_modified
; }
930 // wxEditableListBox utilities
931 int GetSelection() const;
933 // implementation from now on
934 void OnAddClick(wxCommandEvent
& event
);
935 void OnDeleteClick(wxCommandEvent
& event
);
936 void OnUpClick(wxCommandEvent
& event
);
937 void OnDownClick(wxCommandEvent
& event
);
938 void OnEndLabelEdit(wxListEvent
& event
);
939 void OnIdle(wxIdleEvent
& event
);
942 wxEditableListBox
* m_elb
;
944 // These are used for focus repair
945 wxWindow
* m_elbSubPanel
;
946 wxWindow
* m_lastFocused
;
948 // A new item, edited by user, is pending at this index.
949 // It will be committed once list ctrl item editing is done.
950 int m_itemPendingAtIndex
;
953 bool m_hasCustomNewAction
;
955 // These must be overridden - must return true on success.
956 virtual wxString
ArrayGet( size_t index
) = 0;
957 virtual size_t ArrayGetCount() = 0;
958 virtual bool ArrayInsert( const wxString
& str
, int index
) = 0;
959 virtual bool ArraySet( size_t index
, const wxString
& str
) = 0;
960 virtual void ArrayRemoveAt( int index
) = 0;
961 virtual void ArraySwap( size_t first
, size_t second
) = 0;
962 virtual bool OnCustomNewAction(wxString
* WXUNUSED(resString
))
968 DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayEditorDialog
)
969 DECLARE_EVENT_TABLE()
972 #endif // wxUSE_EDITABLELISTBOX
974 // -----------------------------------------------------------------------
975 // wxPGArrayStringEditorDialog
976 // -----------------------------------------------------------------------
978 class WXDLLIMPEXP_PROPGRID
979 wxPGArrayStringEditorDialog
: public wxPGArrayEditorDialog
982 wxPGArrayStringEditorDialog();
983 virtual ~wxPGArrayStringEditorDialog() { }
987 virtual void SetDialogValue( const wxVariant
& value
)
989 m_array
= value
.GetArrayString();
992 virtual wxVariant
GetDialogValue() const
997 void SetCustomButton( const wxString
& custBtText
,
998 wxArrayStringProperty
* pcc
)
1000 if ( !custBtText
.empty() )
1002 EnableCustomNewAction();
1003 m_pCallingClass
= pcc
;
1007 virtual bool OnCustomNewAction(wxString
* resString
);
1010 wxArrayString m_array
;
1012 wxArrayStringProperty
* m_pCallingClass
;
1014 virtual wxString
ArrayGet( size_t index
);
1015 virtual size_t ArrayGetCount();
1016 virtual bool ArrayInsert( const wxString
& str
, int index
);
1017 virtual bool ArraySet( size_t index
, const wxString
& str
);
1018 virtual void ArrayRemoveAt( int index
);
1019 virtual void ArraySwap( size_t first
, size_t second
);
1022 DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog
)
1023 DECLARE_EVENT_TABLE()
1026 // -----------------------------------------------------------------------
1028 #endif // wxUSE_PROPGRID
1030 #endif // _WX_PROPGRID_PROPS_H_