1 /////////////////////////////////////////////////////////////////////////////
2 // Name:        wx/propgrid/props.h
3 // Purpose:     wxPropertyGrid Property Classes
4 // Author:      Jaakko Salli
5 // Modified by:
6 // Created:     2007-03-28
7 // Copyright:   (c) Jaakko Salli
8 // Licence:     wxWindows licence
9 /////////////////////////////////////////////////////////////////////////////
10 
11 #ifndef _WX_PROPGRID_PROPS_H_
12 #define _WX_PROPGRID_PROPS_H_
13 
14 #include "wx/defs.h"
15 
16 #if wxUSE_PROPGRID
17 
18 // -----------------------------------------------------------------------
19 
20 class wxPGArrayEditorDialog;
21 
22 #include "wx/propgrid/editors.h"
23 
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"
30 
31 // -----------------------------------------------------------------------
32 
33 //
34 // Property class implementation helper macros.
35 //
36 
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)
40 
41 // -----------------------------------------------------------------------
42 
43 //
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;
48 
49 // Common function exit
50 #define WX_PG_DOGETVALIDATOR_EXIT(VALIDATOR) \
51     s_ptr = VALIDATOR; \
52     wxPGGlobalVars->m_arrValidators.push_back( VALIDATOR ); \
53     return VALIDATOR;
54 
55 // -----------------------------------------------------------------------
56 
57 /** @class wxPGInDialogValidator
58     @ingroup classes
59     Creates and manages a temporary wxTextCtrl for validation purposes.
60     Uses wxPropertyGrid's current editor, if available.
61 */
62 class WXDLLIMPEXP_PROPGRID wxPGInDialogValidator
63 {
64 public:
wxPGInDialogValidator()65     wxPGInDialogValidator()
66     {
67         m_textCtrl = NULL;
68     }
69 
~wxPGInDialogValidator()70     ~wxPGInDialogValidator()
71     {
72         if ( m_textCtrl )
73             m_textCtrl->Destroy();
74     }
75 
76     bool DoValidate( wxPropertyGrid* propGrid,
77                      wxValidator* validator,
78                      const wxString& value );
79 
80 private:
81     wxTextCtrl*         m_textCtrl;
82 };
83 
84 
85 // -----------------------------------------------------------------------
86 // Property classes
87 // -----------------------------------------------------------------------
88 
89 #define wxPG_PROP_PASSWORD  wxPG_PROP_CLASS_SPECIFIC_2
90 
91 /** @class wxStringProperty
92     @ingroup classes
93     Basic property with string value.
94 
95     <b>Supported special attributes:</b>
96     - "Password": set to 1 in order to enable wxTE_PASSWORD on the editor.
97 
98     @remarks
99     - If value "<composed>" is set, then actual value is formed (or composed)
100       from values of child properties.
101 */
102 class WXDLLIMPEXP_PROPGRID wxStringProperty : public wxPGProperty
103 {
104     WX_PG_DECLARE_PROPERTY_CLASS(wxStringProperty)
105 public:
106     wxStringProperty( const wxString& label = wxPG_LABEL,
107                       const wxString& name = wxPG_LABEL,
108                       const wxString& value = wxEmptyString );
109     virtual ~wxStringProperty();
110 
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;
115 
116     virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
117 
118     /** This is updated so "<composed>" special value can be handled.
119     */
120     virtual void OnSetValue();
121 
122 protected:
123 };
124 
125 // -----------------------------------------------------------------------
126 
127 /** Constants used with NumericValidation<>().
128 */
129 enum wxPGNumericValidationConstants
130 {
131     /** Instead of modifying the value, show an error message.
132     */
133     wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE      = 0,
134 
135     /** Modify value, but stick with the limitations.
136     */
137     wxPG_PROPERTY_VALIDATION_SATURATE           = 1,
138 
139     /** Modify value, wrap around on overflow.
140     */
141     wxPG_PROPERTY_VALIDATION_WRAP               = 2
142 };
143 
144 // -----------------------------------------------------------------------
145 
146 #if wxUSE_VALIDATORS
147 
148 /**
149     A more comprehensive numeric validator class.
150 */
151 class WXDLLIMPEXP_PROPGRID wxNumericPropertyValidator : public wxTextValidator
152 {
153 public:
154     enum NumericType
155     {
156         Signed = 0,
157         Unsigned,
158         Float
159     };
160 
161     wxNumericPropertyValidator( NumericType numericType, int base = 10 );
~wxNumericPropertyValidator()162     virtual ~wxNumericPropertyValidator() { }
163     virtual bool Validate(wxWindow* parent);
164 };
165 
166 #endif // wxUSE_VALIDATORS
167 
168 
169 /** @class wxIntProperty
170     @ingroup classes
171     Basic property with integer value.
172 
173     Seamlessly supports 64-bit integer (wxLongLong) on overflow.
174 
175     <b>Example how to use seamless 64-bit integer support</b>
176 
177       Getting value:
178 
179       @code
180           wxLongLong_t value = pg->GetPropertyValueAsLongLong();
181       @endcode
182 
183          or
184 
185       @code
186           wxLongLong_t value;
187           wxVariant variant = property->GetValue();
188           if ( variant.GetType() == "wxLongLong" )
189               value = wxLongLongFromVariant(variant);
190           else
191               value = variant.GetLong();
192       @endcode
193 
194       Setting value:
195 
196        @code
197           pg->SetPropertyValue(longLongVal);
198       @endcode
199 
200          or
201 
202       @code
203           property->SetValue(WXVARIANT(longLongVal));
204       @endcode
205 
206 
207     <b>Supported special attributes:</b>
208     - "Min", "Max": Specify acceptable value range.
209 */
210 class WXDLLIMPEXP_PROPGRID wxIntProperty : public wxPGProperty
211 {
212     WX_PG_DECLARE_PROPERTY_CLASS(wxIntProperty)
213 public:
214     wxIntProperty( const wxString& label = wxPG_LABEL,
215                    const wxString& name = wxPG_LABEL,
216                    long value = 0 );
217     virtual ~wxIntProperty();
218 
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,
229                              int number,
230                              int argFlags = 0 ) const;
231     static wxValidator* GetClassValidator();
232     virtual wxValidator* DoGetValidator() const;
233 
234     /** Validation helper.
235     */
236     static bool DoValidation( const wxPGProperty* property,
237                               wxLongLong_t& value,
238                               wxPGValidationInfo* pValidationInfo,
239                               int mode =
240                                 wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE );
241 
242 protected:
243 };
244 
245 // -----------------------------------------------------------------------
246 
247 /** @class wxUIntProperty
248     @ingroup classes
249     Basic property with unsigned integer value.
250     Seamlessly supports 64-bit integer (wxULongLong) on overflow.
251 
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
259     numbers.
260 
261     @remarks
262     - For example how to use seamless 64-bit integer support, see wxIntProperty
263     documentation (just use wxULongLong instead of wxLongLong).
264 */
265 class WXDLLIMPEXP_PROPGRID wxUIntProperty : public wxPGProperty
266 {
267     WX_PG_DECLARE_PROPERTY_CLASS(wxUIntProperty)
268 public:
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,
285                              int number,
286                              int argFlags = 0 ) const;
287 protected:
288     wxByte      m_base;
289     wxByte      m_realBase; // translated to 8,16,etc.
290     wxByte      m_prefix;
291 private:
292     void Init();
293 };
294 
295 // -----------------------------------------------------------------------
296 
297 /** @class wxFloatProperty
298     @ingroup classes
299     Basic property with double-precision floating point value.
300 
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.
304 */
305 class WXDLLIMPEXP_PROPGRID wxFloatProperty : public wxPGProperty
306 {
307     WX_PG_DECLARE_PROPERTY_CLASS(wxFloatProperty)
308 public:
309     wxFloatProperty( const wxString& label = wxPG_LABEL,
310                      const wxString& name = wxPG_LABEL,
311                      double value = 0.0 );
312     virtual ~wxFloatProperty();
313 
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 #if wxABI_VERSION >= 30003
320     virtual wxVariant DoGetAttribute( const wxString& name ) const;
321 #endif
322     virtual bool ValidateValue( wxVariant& value,
323                                 wxPGValidationInfo& validationInfo ) const;
324 
325     /** Validation helper.
326     */
327     static bool DoValidation( const wxPGProperty* property,
328                               double& value,
329                               wxPGValidationInfo* pValidationInfo,
330                               int mode =
331                                  wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE );
332     static wxValidator* GetClassValidator();
333     virtual wxValidator* DoGetValidator () const;
334 
335 protected:
336     int m_precision;
337 };
338 
339 // -----------------------------------------------------------------------
340 
341 /** @class wxBoolProperty
342     @ingroup classes
343     Basic property with boolean value.
344 
345     <b>Supported special attributes:</b>
346     - "UseCheckbox": Set to 1 to use check box editor instead of combo box.
347     - "UseDClickCycling": Set to 1 to cycle combo box instead showing the list.
348 */
349 class WXDLLIMPEXP_PROPGRID wxBoolProperty : public wxPGProperty
350 {
351     WX_PG_DECLARE_PROPERTY_CLASS(wxBoolProperty)
352 public:
353     wxBoolProperty( const wxString& label = wxPG_LABEL,
354                     const wxString& name = wxPG_LABEL,
355                     bool value = false );
356     virtual ~wxBoolProperty();
357 
358     virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
359     virtual bool StringToValue( wxVariant& variant,
360                                 const wxString& text,
361                                 int argFlags = 0 ) const;
362     virtual bool IntToValue( wxVariant& variant,
363                              int number, int argFlags = 0 ) const;
364     virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
365 };
366 
367 // -----------------------------------------------------------------------
368 
369 // If set, then selection of choices is static and should not be
370 // changed (i.e. returns NULL in GetPropertyChoices).
371 #define wxPG_PROP_STATIC_CHOICES    wxPG_PROP_CLASS_SPECIFIC_1
372 
373 /** @class wxEnumProperty
374     @ingroup classes
375     You can derive custom properties with choices from this class. See
376     wxBaseEnumProperty for remarks.
377 
378     @remarks
379     - Updating private index is important. You can do this either by calling
380     SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue
381     be called (by not implementing it, or by calling super class function in
382     it) -OR- you can just call SetIndex in OnSetValue.
383 */
384 class WXDLLIMPEXP_PROPGRID wxEnumProperty : public wxPGProperty
385 {
386     WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty)
387 public:
388 
389 #ifndef SWIG
390     wxEnumProperty( const wxString& label = wxPG_LABEL,
391                     const wxString& name = wxPG_LABEL,
392                     const wxChar* const* labels = NULL,
393                     const long* values = NULL,
394                     int value = 0 );
395     wxEnumProperty( const wxString& label,
396                     const wxString& name,
397                     wxPGChoices& choices,
398                     int value = 0 );
399 
400     // Special constructor for caching choices (used by derived class)
401     wxEnumProperty( const wxString& label,
402                     const wxString& name,
403                     const wxChar* const* labels,
404                     const long* values,
405                     wxPGChoices* choicesCache,
406                     int value = 0 );
407 
408     wxEnumProperty( const wxString& label,
409                     const wxString& name,
410                     const wxArrayString& labels,
411                     const wxArrayInt& values = wxArrayInt(),
412                     int value = 0 );
413 #else
414     wxEnumProperty( const wxString& label = wxPG_LABEL,
415                     const wxString& name = wxPG_LABEL,
416                     const wxArrayString& labels = wxArrayString(),
417                     const wxArrayInt& values = wxArrayInt(),
418                     int value = 0 );
419 #endif
420 
421     virtual ~wxEnumProperty();
422 
GetItemCount()423     size_t GetItemCount() const { return m_choices.GetCount(); }
424 
425     virtual void OnSetValue();
426     virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
427     virtual bool StringToValue( wxVariant& variant,
428                                 const wxString& text,
429                                 int argFlags = 0 ) const;
430     virtual bool ValidateValue( wxVariant& value,
431                                 wxPGValidationInfo& validationInfo ) const;
432 
433     // If wxPG_FULL_VALUE is not set in flags, then the value is interpreted
434     // as index to choices list. Otherwise, it is actual value.
435     virtual bool IntToValue( wxVariant& variant,
436                              int number,
437                              int argFlags = 0 ) const;
438 
439     //
440     // Additional virtuals
441 
442     // This must be overridden to have non-index based value
443     virtual int GetIndexForValue( int value ) const;
444 
445     // GetChoiceSelection needs to overridden since m_index is
446     // the true index, and various property classes derived from
447     // this take advantage of it.
GetChoiceSelection()448     virtual int GetChoiceSelection() const { return m_index; }
449 
450     virtual void OnValidationFailure( wxVariant& pendingValue );
451 
452 protected:
453 
454     int GetIndex() const;
455     void SetIndex( int index );
456 
457     bool ValueFromString_( wxVariant& value,
458                            const wxString& text,
459                            int argFlags ) const;
460     bool ValueFromInt_( wxVariant& value, int intVal, int argFlags ) const;
461 
ResetNextIndex()462     static void ResetNextIndex() { ms_nextIndex = -2; }
463 
464 private:
465     // This is private so that classes are guaranteed to use GetIndex
466     // for up-to-date index value.
467     int                     m_index;
468 
469     // Relies on ValidateValue being called always before OnSetValue
470     static int              ms_nextIndex;
471 };
472 
473 // -----------------------------------------------------------------------
474 
475 /** @class wxEditEnumProperty
476     @ingroup classes
477     wxEnumProperty with wxString value and writable combo box editor.
478 
479     @remarks
480     Uses int value, similar to wxEnumProperty, unless text entered by user is
481     is not in choices (in which case string value is used).
482 */
483 class WXDLLIMPEXP_PROPGRID wxEditEnumProperty : public wxEnumProperty
484 {
485     WX_PG_DECLARE_PROPERTY_CLASS(wxEditEnumProperty)
486 public:
487 
488     wxEditEnumProperty( const wxString& label,
489                         const wxString& name,
490                         const wxChar* const* labels,
491                         const long* values,
492                         const wxString& value );
493     wxEditEnumProperty( const wxString& label = wxPG_LABEL,
494                         const wxString& name = wxPG_LABEL,
495                         const wxArrayString& labels = wxArrayString(),
496                         const wxArrayInt& values = wxArrayInt(),
497                         const wxString& value = wxEmptyString );
498     wxEditEnumProperty( const wxString& label,
499                         const wxString& name,
500                         wxPGChoices& choices,
501                         const wxString& value = wxEmptyString );
502 
503     // Special constructor for caching choices (used by derived class)
504     wxEditEnumProperty( const wxString& label,
505                         const wxString& name,
506                         const wxChar* const* labels,
507                         const long* values,
508                         wxPGChoices* choicesCache,
509                         const wxString& value );
510 
511     virtual ~wxEditEnumProperty();
512 
513 protected:
514 };
515 
516 // -----------------------------------------------------------------------
517 
518 /** @class wxFlagsProperty
519     @ingroup classes
520     Represents a bit set that fits in a long integer. wxBoolProperty
521     sub-properties are created for editing individual bits. Textctrl is created
522     to manually edit the flags as a text; a continuous sequence of spaces,
523     commas and semicolons is considered as a flag id separator.
524     <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
525     you will need to use SetPropertyChoices - otherwise they will not get
526     updated properly.
527 */
528 class WXDLLIMPEXP_PROPGRID wxFlagsProperty : public wxPGProperty
529 {
530     WX_PG_DECLARE_PROPERTY_CLASS(wxFlagsProperty)
531 public:
532 
533 #ifndef SWIG
534     wxFlagsProperty( const wxString& label,
535                      const wxString& name,
536                      const wxChar* const* labels,
537                      const long* values = NULL,
538                      long value = 0 );
539     wxFlagsProperty( const wxString& label,
540                      const wxString& name,
541                      wxPGChoices& choices,
542                      long value = 0 );
543 #endif
544     wxFlagsProperty( const wxString& label = wxPG_LABEL,
545                      const wxString& name = wxPG_LABEL,
546                      const wxArrayString& labels = wxArrayString(),
547                      const wxArrayInt& values = wxArrayInt(),
548                      int value = 0 );
549     virtual ~wxFlagsProperty ();
550 
551     virtual void OnSetValue();
552     virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
553     virtual bool StringToValue( wxVariant& variant,
554                                 const wxString& text,
555                                 int flags ) const;
556     virtual wxVariant ChildChanged( wxVariant& thisValue,
557                                     int childIndex,
558                                     wxVariant& childValue ) const;
559     virtual void RefreshChildren();
560     virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
561 
562     // GetChoiceSelection needs to overridden since m_choices is
563     // used and value is integer, but it is not index.
GetChoiceSelection()564     virtual int GetChoiceSelection() const { return wxNOT_FOUND; }
565 
566     // helpers
GetItemCount()567     size_t GetItemCount() const { return m_choices.GetCount(); }
GetLabel(size_t ind)568     const wxString& GetLabel( size_t ind ) const
569         { return m_choices.GetLabel(static_cast<int>(ind)); }
570 
571 protected:
572     // Used to detect if choices have been changed
573     wxPGChoicesData*        m_oldChoicesData;
574 
575     // Needed to properly mark changed sub-properties
576     long                    m_oldValue;
577 
578     // Converts string id to a relevant bit.
579     long IdToBit( const wxString& id ) const;
580 
581     // Creates children and sets value.
582     void Init();
583 };
584 
585 // -----------------------------------------------------------------------
586 
587 /** @class wxPGFileDialogAdapter
588     @ingroup classes
589 */
590 class WXDLLIMPEXP_PROPGRID
591     wxPGFileDialogAdapter : public wxPGEditorDialogAdapter
592 {
593 public:
594     virtual bool DoShowDialog( wxPropertyGrid* propGrid,
595                                wxPGProperty* property );
596 };
597 
598 // -----------------------------------------------------------------------
599 
600 // Indicates first bit useable by derived properties.
601 #define wxPG_PROP_SHOW_FULL_FILENAME  wxPG_PROP_CLASS_SPECIFIC_1
602 
603 /** @class wxFileProperty
604     @ingroup classes
605     Like wxLongStringProperty, but the button triggers file selector instead.
606 
607     <b>Supported special attributes:</b>
608     - "Wildcard": Sets wildcard (see wxFileDialog for format details), "All
609     files..." is default.
610     - "ShowFullPath": Default 1. When 0, only the file name is shown (i.e. drive
611       and directory are hidden).
612     - "ShowRelativePath": If set, then the filename is shown relative to the
613     given path string.
614     - "InitialPath": Sets the initial path of where to look for files.
615     - "DialogTitle": Sets a specific title for the dir dialog.
616 */
617 class WXDLLIMPEXP_PROPGRID wxFileProperty : public wxPGProperty
618 {
619     friend class wxPGFileDialogAdapter;
620     WX_PG_DECLARE_PROPERTY_CLASS(wxFileProperty)
621 public:
622 
623     wxFileProperty( const wxString& label = wxPG_LABEL,
624                     const wxString& name = wxPG_LABEL,
625                     const wxString& value = wxEmptyString );
626     virtual ~wxFileProperty ();
627 
628     virtual void OnSetValue();
629     virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
630     virtual bool StringToValue( wxVariant& variant,
631                                 const wxString& text,
632                                 int argFlags = 0 ) const;
633     virtual wxPGEditorDialogAdapter* GetEditorDialog() const;
634     virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
635 
636     static wxValidator* GetClassValidator();
637     virtual wxValidator* DoGetValidator() const;
638 
639     /**
640         Returns filename to file represented by current value.
641     */
642     wxFileName GetFileName() const;
643 
644 protected:
645     wxString    m_wildcard;
646     wxString    m_basePath; // If set, then show path relative to it
647     wxString    m_initialPath; // If set, start the file dialog here
648     wxString    m_dlgTitle; // If set, used as title for file dialog
649     int         m_indFilter; // index to the selected filter
650 };
651 
652 // -----------------------------------------------------------------------
653 
654 #define wxPG_PROP_NO_ESCAPE     wxPG_PROP_CLASS_SPECIFIC_1
655 
656 
657 /** @class wxPGLongStringDialogAdapter
658     @ingroup classes
659 */
660 class WXDLLIMPEXP_PROPGRID
661     wxPGLongStringDialogAdapter : public wxPGEditorDialogAdapter
662 {
663 public:
664     virtual bool DoShowDialog( wxPropertyGrid* propGrid,
665                                wxPGProperty* property );
666 };
667 
668 
669 /** @class wxLongStringProperty
670     @ingroup classes
671     Like wxStringProperty, but has a button that triggers a small text
672     editor dialog.
673 */
674 class WXDLLIMPEXP_PROPGRID wxLongStringProperty : public wxPGProperty
675 {
676     WX_PG_DECLARE_PROPERTY_CLASS(wxLongStringProperty)
677 public:
678 
679     wxLongStringProperty( const wxString& label = wxPG_LABEL,
680                           const wxString& name = wxPG_LABEL,
681                           const wxString& value = wxEmptyString );
682     virtual ~wxLongStringProperty();
683 
684     virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
685     virtual bool StringToValue( wxVariant& variant,
686                                 const wxString& text,
687                                 int argFlags = 0 ) const;
688     virtual bool OnEvent( wxPropertyGrid* propgrid,
689                           wxWindow* primary, wxEvent& event );
690 
691     // Shows string editor dialog. Value to be edited should be read from
692     // value, and if dialog is not cancelled, it should be stored back and true
693     // should be returned if that was the case.
694     virtual bool OnButtonClick( wxPropertyGrid* propgrid, wxString& value );
695 
696     static bool DisplayEditorDialog( wxPGProperty* prop,
697                                      wxPropertyGrid* propGrid,
698                                      wxString& value );
699 
700 protected:
701 };
702 
703 // -----------------------------------------------------------------------
704 
705 
706 /** @class wxDirProperty
707     @ingroup classes
708     Like wxLongStringProperty, but the button triggers dir selector instead.
709 
710     <b>Supported special attributes:</b>
711     - "DialogMessage": Sets specific message in the dir selector.
712 */
713 class WXDLLIMPEXP_PROPGRID wxDirProperty : public wxLongStringProperty
714 {
715     DECLARE_DYNAMIC_CLASS(wxDirProperty)
716 public:
717     wxDirProperty( const wxString& name = wxPG_LABEL,
718                    const wxString& label = wxPG_LABEL,
719                    const wxString& value = wxEmptyString );
720     virtual ~wxDirProperty();
721 
722     virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
723     virtual wxValidator* DoGetValidator() const;
724 
725     virtual bool OnButtonClick ( wxPropertyGrid* propGrid, wxString& value );
726 
727 protected:
728     wxString    m_dlgMessage;
729 };
730 
731 // -----------------------------------------------------------------------
732 
733 // wxBoolProperty specific flags
734 #define wxPG_PROP_USE_CHECKBOX      wxPG_PROP_CLASS_SPECIFIC_1
735 // DCC = Double Click Cycles
736 #define wxPG_PROP_USE_DCC           wxPG_PROP_CLASS_SPECIFIC_2
737 
738 
739 // -----------------------------------------------------------------------
740 
741 /** @class wxArrayStringProperty
742     @ingroup classes
743     Property that manages a list of strings.
744 */
745 class WXDLLIMPEXP_PROPGRID wxArrayStringProperty : public wxPGProperty
746 {
747     WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty)
748 public:
749     wxArrayStringProperty( const wxString& label = wxPG_LABEL,
750                            const wxString& name = wxPG_LABEL,
751                            const wxArrayString& value = wxArrayString() );
752     virtual ~wxArrayStringProperty();
753 
754     virtual void OnSetValue();
755     virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
756     virtual bool StringToValue( wxVariant& variant,
757                                 const wxString& text,
758                                 int argFlags = 0 ) const;
759     virtual bool OnEvent( wxPropertyGrid* propgrid,
760                           wxWindow* primary, wxEvent& event );
761     virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
762 
763     // Implement in derived class for custom array-to-string conversion.
764     virtual void ConvertArrayToString(const wxArrayString& arr,
765                                       wxString* pString,
766                                       const wxUniChar& delimiter) const;
767 
768     // Shows string editor dialog. Value to be edited should be read from
769     // value, and if dialog is not cancelled, it should be stored back and true
770     // should be returned if that was the case.
771     virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value );
772 
773     // Helper.
774     virtual bool OnButtonClick( wxPropertyGrid* propgrid,
775                                 wxWindow* primary,
776                                 const wxChar* cbt );
777 
778     // Creates wxPGArrayEditorDialog for string editing. Called in OnButtonClick.
779     virtual wxPGArrayEditorDialog* CreateEditorDialog();
780 
781     enum ConversionFlags
782     {
783         Escape          = 0x01,
784         QuoteStrings    = 0x02
785     };
786 
787     /**
788         Generates contents for string dst based on the contents of
789         wxArrayString src.
790     */
791     static void ArrayStringToString( wxString& dst, const wxArrayString& src,
792                                      wxUniChar delimiter, int flags );
793 
794 protected:
795     // Previously this was to be implemented in derived class for array-to-
796     // string conversion. Now you should implement ConvertValueToString()
797     // instead.
798     virtual void GenerateValueAsString();
799 
800     wxString        m_display; // Cache for displayed text.
801     wxUniChar       m_delimiter;
802 };
803 
804 // -----------------------------------------------------------------------
805 
806 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, \
807                                                                     DECL) \
808 DECL PROPNAME : public wxArrayStringProperty \
809 { \
810     WX_PG_DECLARE_PROPERTY_CLASS(PROPNAME) \
811 public: \
812     PROPNAME( const wxString& label = wxPG_LABEL, \
813               const wxString& name = wxPG_LABEL, \
814               const wxArrayString& value = wxArrayString() ); \
815     ~PROPNAME(); \
816     virtual bool OnEvent( wxPropertyGrid* propgrid, \
817                           wxWindow* primary, wxEvent& event ); \
818     virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \
819     virtual wxValidator* DoGetValidator() const; \
820 };
821 
822 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM) \
823 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM, class)
824 
825 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
826                                                             DELIMCHAR, \
827                                                             CUSTBUTTXT) \
828 WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME, wxArrayStringProperty, \
829                                wxArrayString, const wxArrayString&, \
830                                TextCtrlAndButton) \
831 PROPNAME::PROPNAME( const wxString& label, \
832                     const wxString& name, \
833                     const wxArrayString& value ) \
834     : wxArrayStringProperty(label,name,value) \
835 { \
836     PROPNAME::GenerateValueAsString(); \
837     m_delimiter = DELIMCHAR; \
838 } \
839 PROPNAME::~PROPNAME() { } \
840 bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
841                         wxWindow* primary, wxEvent& event ) \
842 { \
843     if ( event.GetEventType() == wxEVT_BUTTON ) \
844         return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \
845     return false; \
846 }
847 
848 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \
849 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME)
850 
851 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_DECL(PROPNAME, DECL) \
852 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, DECL)
853 
854 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \
855 WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
856                                                     DELIMCHAR, \
857                                                     CUSTBUTTXT) \
858 wxValidator* PROPNAME::DoGetValidator () const \
859 { return NULL; }
860 
861 
862 // -----------------------------------------------------------------------
863 // wxPGArrayEditorDialog
864 // -----------------------------------------------------------------------
865 
866 #if wxUSE_EDITABLELISTBOX
867 
868 class WXDLLIMPEXP_FWD_ADV wxEditableListBox;
869 class WXDLLIMPEXP_FWD_CORE wxListEvent;
870 
871 #define wxAEDIALOG_STYLE \
872     (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
873 
874 class WXDLLIMPEXP_PROPGRID wxPGArrayEditorDialog : public wxDialog
875 {
876 public:
877     wxPGArrayEditorDialog();
~wxPGArrayEditorDialog()878     virtual ~wxPGArrayEditorDialog() { }
879 
880     void Init();
881 
882     wxPGArrayEditorDialog( wxWindow *parent,
883                          const wxString& message,
884                          const wxString& caption,
885                          long style = wxAEDIALOG_STYLE,
886                          const wxPoint& pos = wxDefaultPosition,
887                          const wxSize& sz = wxDefaultSize );
888 
889     bool Create( wxWindow *parent,
890                  const wxString& message,
891                  const wxString& caption,
892                  long style = wxAEDIALOG_STYLE,
893                  const wxPoint& pos = wxDefaultPosition,
894                  const wxSize& sz = wxDefaultSize );
895 
EnableCustomNewAction()896     void EnableCustomNewAction()
897     {
898         m_hasCustomNewAction = true;
899     }
900 
901     /** Set value modified by dialog.
902     */
SetDialogValue(const wxVariant & WXUNUSED (value))903     virtual void SetDialogValue( const wxVariant& WXUNUSED(value) )
904     {
905         wxFAIL_MSG(wxT("re-implement this member function in derived class"));
906     }
907 
908     /** Return value modified by dialog.
909     */
GetDialogValue()910     virtual wxVariant GetDialogValue() const
911     {
912         wxFAIL_MSG(wxT("re-implement this member function in derived class"));
913         return wxVariant();
914     }
915 
916     /** Override to return wxValidator to be used with the wxTextCtrl
917         in dialog. Note that the validator is used in the standard
918         wx way, ie. it immediately prevents user from entering invalid
919         input.
920 
921         @remarks
922         Dialog frees the validator.
923     */
GetTextCtrlValidator()924     virtual wxValidator* GetTextCtrlValidator() const
925     {
926         return NULL;
927     }
928 
929     // Returns true if array was actually modified
IsModified()930     bool IsModified() const { return m_modified; }
931 
932     // wxEditableListBox utilities
933     int GetSelection() const;
934 
935     // implementation from now on
936     void OnAddClick(wxCommandEvent& event);
937     void OnDeleteClick(wxCommandEvent& event);
938     void OnUpClick(wxCommandEvent& event);
939     void OnDownClick(wxCommandEvent& event);
940     void OnEndLabelEdit(wxListEvent& event);
941     void OnIdle(wxIdleEvent& event);
942 
943 protected:
944     wxEditableListBox*  m_elb;
945 
946     // These are used for focus repair
947     wxWindow*           m_elbSubPanel;
948     wxWindow*           m_lastFocused;
949 
950     // A new item, edited by user, is pending at this index.
951     // It will be committed once list ctrl item editing is done.
952     int             m_itemPendingAtIndex;
953 
954     bool            m_modified;
955     bool            m_hasCustomNewAction;
956 
957     // These must be overridden - must return true on success.
958     virtual wxString ArrayGet( size_t index ) = 0;
959     virtual size_t ArrayGetCount() = 0;
960     virtual bool ArrayInsert( const wxString& str, int index ) = 0;
961     virtual bool ArraySet( size_t index, const wxString& str ) = 0;
962     virtual void ArrayRemoveAt( int index ) = 0;
963     virtual void ArraySwap( size_t first, size_t second ) = 0;
OnCustomNewAction(wxString * WXUNUSED (resString))964     virtual bool OnCustomNewAction(wxString* WXUNUSED(resString))
965     {
966         return false;
967     }
968 
969 private:
970     DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayEditorDialog)
971     DECLARE_EVENT_TABLE()
972 };
973 
974 #endif // wxUSE_EDITABLELISTBOX
975 
976 // -----------------------------------------------------------------------
977 // wxPGArrayStringEditorDialog
978 // -----------------------------------------------------------------------
979 
980 class WXDLLIMPEXP_PROPGRID
981     wxPGArrayStringEditorDialog : public wxPGArrayEditorDialog
982 {
983 public:
984     wxPGArrayStringEditorDialog();
~wxPGArrayStringEditorDialog()985     virtual ~wxPGArrayStringEditorDialog() { }
986 
987     void Init();
988 
SetDialogValue(const wxVariant & value)989     virtual void SetDialogValue( const wxVariant& value )
990     {
991         m_array = value.GetArrayString();
992     }
993 
GetDialogValue()994     virtual wxVariant GetDialogValue() const
995     {
996         return m_array;
997     }
998 
SetCustomButton(const wxString & custBtText,wxArrayStringProperty * pcc)999     void SetCustomButton( const wxString& custBtText,
1000                           wxArrayStringProperty* pcc )
1001     {
1002         if ( !custBtText.empty() )
1003         {
1004             EnableCustomNewAction();
1005             m_pCallingClass = pcc;
1006         }
1007     }
1008 
1009     virtual bool OnCustomNewAction(wxString* resString);
1010 
1011 protected:
1012     wxArrayString   m_array;
1013 
1014     wxArrayStringProperty*     m_pCallingClass;
1015 
1016     virtual wxString ArrayGet( size_t index );
1017     virtual size_t ArrayGetCount();
1018     virtual bool ArrayInsert( const wxString& str, int index );
1019     virtual bool ArraySet( size_t index, const wxString& str );
1020     virtual void ArrayRemoveAt( int index );
1021     virtual void ArraySwap( size_t first, size_t second );
1022 
1023 private:
1024     DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog)
1025     DECLARE_EVENT_TABLE()
1026 };
1027 
1028 // -----------------------------------------------------------------------
1029 
1030 #endif // wxUSE_PROPGRID
1031 
1032 #endif // _WX_PROPGRID_PROPS_H_
1033