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