]> git.saurik.com Git - wxWidgets.git/blob - include/wx/propgrid/props.h
Reworked wxPGCell. It is now reference counted, and therefore much more user friendly...
[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 ValueToString( wxVariant& value, 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 ValueToString( wxVariant& value, 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 ValueToString( wxVariant& value, 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 ValueToString( wxVariant& value, 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 ValueToString( wxVariant& value, 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 // If set, then selection of choices is static and should not be
347 // changed (i.e. returns NULL in GetPropertyChoices).
348 #define wxPG_PROP_STATIC_CHOICES wxPG_PROP_CLASS_SPECIFIC_1
349
350 /** @class wxEnumProperty
351 @ingroup classes
352 You can derive custom properties with choices from this class. See
353 wxBaseEnumProperty for remarks.
354
355 @remarks
356 - Updating private index is important. You can do this either by calling
357 SetIndex() in IntToValue, and then letting wxBaseEnumProperty::OnSetValue
358 be called (by not implementing it, or by calling super class function in
359 it) -OR- you can just call SetIndex in OnSetValue.
360 */
361 class WXDLLIMPEXP_PROPGRID wxEnumProperty : public wxPGProperty
362 {
363 WX_PG_DECLARE_PROPERTY_CLASS(wxEnumProperty)
364 public:
365
366 #ifndef SWIG
367 wxEnumProperty( const wxString& label = wxPG_LABEL,
368 const wxString& name = wxPG_LABEL,
369 const wxChar** labels = NULL,
370 const long* values = NULL,
371 int value = 0 );
372 wxEnumProperty( const wxString& label,
373 const wxString& name,
374 wxPGChoices& choices,
375 int value = 0 );
376
377 // Special constructor for caching choices (used by derived class)
378 wxEnumProperty( const wxString& label,
379 const wxString& name,
380 const wxChar** labels,
381 const long* values,
382 wxPGChoices* choicesCache,
383 int value = 0 );
384
385 wxEnumProperty( const wxString& label,
386 const wxString& name,
387 const wxArrayString& labels,
388 const wxArrayInt& values = wxArrayInt(),
389 int value = 0 );
390 #else
391 wxEnumProperty( const wxString& label = wxPG_LABEL,
392 const wxString& name = wxPG_LABEL,
393 const wxArrayString& labels = wxArrayString(),
394 const wxArrayInt& values = wxArrayInt(),
395 int value = 0 );
396 #endif
397
398 virtual ~wxEnumProperty();
399
400 size_t GetItemCount() const { return m_choices.GetCount(); }
401
402 virtual void OnSetValue();
403 virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
404 virtual bool StringToValue( wxVariant& variant,
405 const wxString& text,
406 int argFlags = 0 ) const;
407 virtual bool ValidateValue( wxVariant& value,
408 wxPGValidationInfo& validationInfo ) const;
409
410 // If wxPG_FULL_VALUE is not set in flags, then the value is interpreted
411 // as index to choices list. Otherwise, it is actual value.
412 virtual bool IntToValue( wxVariant& variant,
413 int number,
414 int argFlags = 0 ) const;
415
416 //
417 // Additional virtuals
418
419 // This must be overridden to have non-index based value
420 virtual int GetIndexForValue( int value ) const;
421
422 // GetChoiceSelection needs to overridden since m_index is
423 // the true index, and various property classes derived from
424 // this take advantage of it.
425 virtual int GetChoiceSelection() const { return m_index; }
426
427 protected:
428
429 int GetIndex() const;
430 void SetIndex( int index );
431
432 bool ValueFromString_( wxVariant& value,
433 const wxString& text,
434 int argFlags ) const;
435 bool ValueFromInt_( wxVariant& value, int intVal, int argFlags ) const;
436
437 static void ResetNextIndex() { ms_nextIndex = -2; }
438
439 private:
440 // This is private so that classes are guaranteed to use GetIndex
441 // for up-to-date index value.
442 int m_index;
443
444 // Relies on ValidateValue being called always before OnSetValue
445 static int ms_nextIndex;
446 };
447
448 // -----------------------------------------------------------------------
449
450 /** @class wxEditEnumProperty
451 @ingroup classes
452 wxEnumProperty with wxString value and writable combo box editor.
453
454 @remarks
455 Uses int value, similar to wxEnumProperty, unless text entered by user is
456 is not in choices (in which case string value is used).
457 */
458 class WXDLLIMPEXP_PROPGRID wxEditEnumProperty : public wxEnumProperty
459 {
460 WX_PG_DECLARE_PROPERTY_CLASS(wxEditEnumProperty)
461 public:
462
463 wxEditEnumProperty( const wxString& label,
464 const wxString& name,
465 const wxChar** labels,
466 const long* values,
467 const wxString& value );
468 wxEditEnumProperty( const wxString& label = wxPG_LABEL,
469 const wxString& name = wxPG_LABEL,
470 const wxArrayString& labels = wxArrayString(),
471 const wxArrayInt& values = wxArrayInt(),
472 const wxString& value = wxEmptyString );
473 wxEditEnumProperty( const wxString& label,
474 const wxString& name,
475 wxPGChoices& choices,
476 const wxString& value = wxEmptyString );
477
478 // Special constructor for caching choices (used by derived class)
479 wxEditEnumProperty( const wxString& label,
480 const wxString& name,
481 const wxChar** labels,
482 const long* values,
483 wxPGChoices* choicesCache,
484 const wxString& value );
485
486 virtual ~wxEditEnumProperty();
487
488 protected:
489 };
490
491 // -----------------------------------------------------------------------
492
493 /** @class wxFlagsProperty
494 @ingroup classes
495 Represents a bit set that fits in a long integer. wxBoolProperty
496 sub-properties are created for editing individual bits. Textctrl is created
497 to manually edit the flags as a text; a continous sequence of spaces,
498 commas and semicolons is considered as a flag id separator.
499 <b>Note:</b> When changing "choices" (ie. flag labels) of wxFlagsProperty,
500 you will need to use SetPropertyChoices - otherwise they will not get
501 updated properly.
502 */
503 class WXDLLIMPEXP_PROPGRID wxFlagsProperty : public wxPGProperty
504 {
505 WX_PG_DECLARE_PROPERTY_CLASS(wxFlagsProperty)
506 public:
507
508 #ifndef SWIG
509 wxFlagsProperty( const wxString& label,
510 const wxString& name,
511 const wxChar** labels,
512 const long* values = NULL,
513 long value = 0 );
514 wxFlagsProperty( const wxString& label,
515 const wxString& name,
516 wxPGChoices& choices,
517 long value = 0 );
518 #endif
519 wxFlagsProperty( const wxString& label = wxPG_LABEL,
520 const wxString& name = wxPG_LABEL,
521 const wxArrayString& labels = wxArrayString(),
522 const wxArrayInt& values = wxArrayInt(),
523 int value = 0 );
524 virtual ~wxFlagsProperty ();
525
526 virtual void OnSetValue();
527 virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
528 virtual bool StringToValue( wxVariant& variant,
529 const wxString& text,
530 int flags ) const;
531 virtual void ChildChanged( wxVariant& thisValue,
532 int childIndex,
533 wxVariant& childValue ) const;
534 virtual void RefreshChildren();
535
536 // GetChoiceSelection needs to overridden since m_choices is
537 // used and value is integer, but it is not index.
538 virtual int GetChoiceSelection() const { return wxNOT_FOUND; }
539
540 // helpers
541 size_t GetItemCount() const { return m_choices.GetCount(); }
542 const wxString& GetLabel( size_t ind ) const
543 { return m_choices.GetLabel(ind); }
544
545 protected:
546 // Used to detect if choices have been changed
547 wxPGChoicesData* m_oldChoicesData;
548
549 // Needed to properly mark changed sub-properties
550 long m_oldValue;
551
552 // Converts string id to a relevant bit.
553 long IdToBit( const wxString& id ) const;
554
555 // Creates children and sets value.
556 void Init();
557 };
558
559 // -----------------------------------------------------------------------
560
561 /** @class wxPGFileDialogAdapter
562 @ingroup classes
563 */
564 class WXDLLIMPEXP_PROPGRID
565 wxPGFileDialogAdapter : public wxPGEditorDialogAdapter
566 {
567 public:
568 virtual bool DoShowDialog( wxPropertyGrid* propGrid,
569 wxPGProperty* property );
570 };
571
572 // -----------------------------------------------------------------------
573
574 #include "wx/filename.h"
575
576 // Indicates first bit useable by derived properties.
577 #define wxPG_PROP_SHOW_FULL_FILENAME wxPG_PROP_CLASS_SPECIFIC_1
578
579 /** @class wxFileProperty
580 @ingroup classes
581 Like wxLongStringProperty, but the button triggers file selector instead.
582
583 <b>Supported special attributes:</b>
584 - "Wildcard": Sets wildcard (see wxFileDialog for format details), "All
585 files..." is default.
586 - "ShowFullPath": Default 1. When 0, only the file name is shown (i.e. drive
587 and directory are hidden).
588 - "ShowRelativePath": If set, then the filename is shown relative to the
589 given path string.
590 - "InitialPath": Sets the initial path of where to look for files.
591 - "DialogTitle": Sets a specific title for the dir dialog.
592 */
593 class WXDLLIMPEXP_PROPGRID wxFileProperty : public wxPGProperty
594 {
595 friend class wxPGFileDialogAdapter;
596 WX_PG_DECLARE_PROPERTY_CLASS(wxFileProperty)
597 public:
598
599 wxFileProperty( const wxString& label = wxPG_LABEL,
600 const wxString& name = wxPG_LABEL,
601 const wxString& value = wxEmptyString );
602 virtual ~wxFileProperty ();
603
604 virtual void OnSetValue();
605 virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
606 virtual bool StringToValue( wxVariant& variant,
607 const wxString& text,
608 int argFlags = 0 ) const;
609 virtual wxPGEditorDialogAdapter* GetEditorDialog() const;
610 virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
611
612 static wxValidator* GetClassValidator();
613 virtual wxValidator* DoGetValidator() const;
614
615 /**
616 Returns filename to file represented by current value.
617 */
618 wxFileName GetFileName() const;
619
620 protected:
621 wxString m_wildcard;
622 wxString m_basePath; // If set, then show path relative to it
623 wxString m_initialPath; // If set, start the file dialog here
624 wxString m_dlgTitle; // If set, used as title for file dialog
625 int m_indFilter; // index to the selected filter
626 };
627
628 // -----------------------------------------------------------------------
629
630 #define wxPG_PROP_NO_ESCAPE wxPG_PROP_CLASS_SPECIFIC_1
631
632
633 /** @class wxPGLongStringDialogAdapter
634 @ingroup classes
635 */
636 class WXDLLIMPEXP_PROPGRID
637 wxPGLongStringDialogAdapter : public wxPGEditorDialogAdapter
638 {
639 public:
640 virtual bool DoShowDialog( wxPropertyGrid* propGrid,
641 wxPGProperty* property );
642 };
643
644
645 /** @class wxLongStringProperty
646 @ingroup classes
647 Like wxStringProperty, but has a button that triggers a small text
648 editor dialog.
649 */
650 class WXDLLIMPEXP_PROPGRID wxLongStringProperty : public wxPGProperty
651 {
652 WX_PG_DECLARE_PROPERTY_CLASS(wxLongStringProperty)
653 public:
654
655 wxLongStringProperty( const wxString& label = wxPG_LABEL,
656 const wxString& name = wxPG_LABEL,
657 const wxString& value = wxEmptyString );
658 virtual ~wxLongStringProperty();
659
660 virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
661 virtual bool StringToValue( wxVariant& variant,
662 const wxString& text,
663 int argFlags = 0 ) const;
664 virtual bool OnEvent( wxPropertyGrid* propgrid,
665 wxWindow* primary, wxEvent& event );
666
667 // Shows string editor dialog. Value to be edited should be read from
668 // value, and if dialog is not cancelled, it should be stored back and true
669 // should be returned if that was the case.
670 virtual bool OnButtonClick( wxPropertyGrid* propgrid, wxString& value );
671
672 static bool DisplayEditorDialog( wxPGProperty* prop,
673 wxPropertyGrid* propGrid,
674 wxString& value );
675
676 protected:
677 };
678
679 // -----------------------------------------------------------------------
680
681
682 // Exclude class from wxPython bindings
683 #ifndef SWIG
684
685 /** @class wxDirProperty
686 @ingroup classes
687 Like wxLongStringProperty, but the button triggers dir selector instead.
688
689 <b>Supported special attributes:</b>
690 - "DialogMessage": Sets specific message in the dir selector.
691 */
692 class WXDLLIMPEXP_PROPGRID wxDirProperty : public wxLongStringProperty
693 {
694 #ifndef SWIG
695 DECLARE_DYNAMIC_CLASS(wxDirProperty)
696 #endif
697 public:
698 wxDirProperty( const wxString& name = wxPG_LABEL,
699 const wxString& label = wxPG_LABEL,
700 const wxString& value = wxEmptyString );
701 virtual ~wxDirProperty();
702
703 virtual bool DoSetAttribute( const wxString& name, wxVariant& value );
704 virtual wxValidator* DoGetValidator() const;
705
706 virtual bool OnButtonClick ( wxPropertyGrid* propGrid, wxString& value );
707
708 protected:
709 wxString m_dlgMessage;
710 };
711
712 #endif // !SWIG
713
714 // -----------------------------------------------------------------------
715
716 // wxBoolProperty specific flags
717 #define wxPG_PROP_USE_CHECKBOX wxPG_PROP_CLASS_SPECIFIC_1
718 // DCC = Double Click Cycles
719 #define wxPG_PROP_USE_DCC wxPG_PROP_CLASS_SPECIFIC_2
720
721
722 // -----------------------------------------------------------------------
723
724 /** @class wxArrayStringProperty
725 @ingroup classes
726 Property that manages a list of strings.
727 */
728 class WXDLLIMPEXP_PROPGRID wxArrayStringProperty : public wxPGProperty
729 {
730 WX_PG_DECLARE_PROPERTY_CLASS(wxArrayStringProperty)
731 public:
732
733 wxArrayStringProperty( const wxString& label = wxPG_LABEL,
734 const wxString& name = wxPG_LABEL,
735 const wxArrayString& value = wxArrayString() );
736 virtual ~wxArrayStringProperty();
737
738 virtual void OnSetValue();
739 virtual wxString ValueToString( wxVariant& value, int argFlags = 0 ) const;
740 virtual bool StringToValue( wxVariant& variant,
741 const wxString& text,
742 int argFlags = 0 ) const;
743 virtual bool OnEvent( wxPropertyGrid* propgrid,
744 wxWindow* primary, wxEvent& event );
745
746 virtual void GenerateValueAsString();
747
748 // Shows string editor dialog. Value to be edited should be read from
749 // value, and if dialog is not cancelled, it should be stored back and true
750 // should be returned if that was the case.
751 virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value );
752
753 // Helper.
754 virtual bool OnButtonClick( wxPropertyGrid* propgrid,
755 wxWindow* primary,
756 const wxChar* cbt );
757
758 #ifndef SWIG
759 // Creates wxArrayEditorDialog for string editing. Called in OnButtonClick.
760 virtual wxArrayEditorDialog* CreateEditorDialog();
761 #endif
762
763 protected:
764 wxString m_display; // Cache for displayed text.
765 };
766
767 // -----------------------------------------------------------------------
768
769 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, \
770 DECL) \
771 DECL PROPNAME : public wxArrayStringProperty \
772 { \
773 WX_PG_DECLARE_PROPERTY_CLASS(PROPNAME) \
774 public: \
775 PROPNAME( const wxString& label = wxPG_LABEL, \
776 const wxString& name = wxPG_LABEL, \
777 const wxArrayString& value = wxArrayString() ); \
778 ~PROPNAME(); \
779 virtual void GenerateValueAsString(); \
780 virtual bool StringToValue( wxVariant& value, \
781 const wxString& text, int = 0 ) const; \
782 virtual bool OnEvent( wxPropertyGrid* propgrid, \
783 wxWindow* primary, wxEvent& event ); \
784 virtual bool OnCustomStringEdit( wxWindow* parent, wxString& value ); \
785 virtual wxValidator* DoGetValidator() const; \
786 };
787
788 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM) \
789 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAM, class)
790
791 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
792 DELIMCHAR, \
793 CUSTBUTTXT) \
794 WX_PG_IMPLEMENT_PROPERTY_CLASS(PROPNAME, wxArrayStringProperty, \
795 wxArrayString, const wxArrayString&, \
796 TextCtrlAndButton) \
797 PROPNAME::PROPNAME( const wxString& label, \
798 const wxString& name, \
799 const wxArrayString& value ) \
800 : wxArrayStringProperty(label,name,value) \
801 { \
802 PROPNAME::GenerateValueAsString(); \
803 } \
804 PROPNAME::~PROPNAME() { } \
805 void PROPNAME::GenerateValueAsString() \
806 { \
807 wxChar delimChar = DELIMCHAR; \
808 if ( delimChar == wxS('"') ) \
809 wxArrayStringProperty::GenerateValueAsString(); \
810 else \
811 wxPropertyGrid::ArrayStringToString(m_display, \
812 m_value.GetArrayString(), \
813 0,DELIMCHAR,0); \
814 } \
815 bool PROPNAME::StringToValue( wxVariant& variant, \
816 const wxString& text, int ) const \
817 { \
818 wxChar delimChar = DELIMCHAR; \
819 if ( delimChar == wxS('"') ) \
820 return wxArrayStringProperty::StringToValue(variant, text, 0); \
821 \
822 wxArrayString arr; \
823 WX_PG_TOKENIZER1_BEGIN(text,DELIMCHAR) \
824 arr.Add( token ); \
825 WX_PG_TOKENIZER1_END() \
826 variant = arr; \
827 return true; \
828 } \
829 bool PROPNAME::OnEvent( wxPropertyGrid* propgrid, \
830 wxWindow* primary, wxEvent& event ) \
831 { \
832 if ( event.GetEventType() == wxEVT_COMMAND_BUTTON_CLICKED ) \
833 return OnButtonClick(propgrid,primary,(const wxChar*) CUSTBUTTXT); \
834 return false; \
835 }
836
837 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY(PROPNAME) \
838 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME)
839
840 #define WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_DECL(PROPNAME, DECL) \
841 WX_PG_DECLARE_ARRAYSTRING_PROPERTY_WITH_VALIDATOR_WITH_DECL(PROPNAME, DECL)
842
843 #define WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY(PROPNAME,DELIMCHAR,CUSTBUTTXT) \
844 WX_PG_IMPLEMENT_ARRAYSTRING_PROPERTY_WITH_VALIDATOR(PROPNAME, \
845 DELIMCHAR, \
846 CUSTBUTTXT) \
847 wxValidator* PROPNAME::DoGetValidator () const \
848 { return (wxValidator*) NULL; }
849
850
851 // -----------------------------------------------------------------------
852 // wxArrayEditorDialog
853 // -----------------------------------------------------------------------
854
855 #include "wx/button.h"
856 #include "wx/dialog.h"
857 #include "wx/listbox.h"
858
859 #define wxAEDIALOG_STYLE \
860 (wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxOK | wxCANCEL | wxCENTRE)
861
862 class WXDLLIMPEXP_PROPGRID wxArrayEditorDialog : public wxDialog
863 {
864 public:
865 wxArrayEditorDialog();
866 virtual ~wxArrayEditorDialog() { }
867
868 void Init();
869
870 wxArrayEditorDialog( wxWindow *parent,
871 const wxString& message,
872 const wxString& caption,
873 long style = wxAEDIALOG_STYLE,
874 const wxPoint& pos = wxDefaultPosition,
875 const wxSize& sz = wxDefaultSize );
876
877 bool Create( wxWindow *parent,
878 const wxString& message,
879 const wxString& caption,
880 long style = wxAEDIALOG_STYLE,
881 const wxPoint& pos = wxDefaultPosition,
882 const wxSize& sz = wxDefaultSize );
883
884 /** Set value modified by dialog.
885 */
886 virtual void SetDialogValue( const wxVariant& WXUNUSED(value) )
887 {
888 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
889 }
890
891 /** Return value modified by dialog.
892 */
893 virtual wxVariant GetDialogValue() const
894 {
895 wxFAIL_MSG(wxT("re-implement this member function in derived class"));
896 return wxVariant();
897 }
898
899 /** Override to return wxValidator to be used with the wxTextCtrl
900 in dialog. Note that the validator is used in the standard
901 wx way, ie. it immediately prevents user from entering invalid
902 input.
903
904 @remarks
905 Dialog frees the validator.
906 */
907 virtual wxValidator* GetTextCtrlValidator() const
908 {
909 return (wxValidator*) NULL;
910 }
911
912 // Returns true if array was actually modified
913 bool IsModified() const { return m_modified; }
914
915 //const wxArrayString& GetStrings() const { return m_array; }
916
917 // implementation from now on
918 void OnUpdateClick(wxCommandEvent& event);
919 void OnAddClick(wxCommandEvent& event);
920 void OnDeleteClick(wxCommandEvent& event);
921 void OnListBoxClick(wxCommandEvent& event);
922 void OnUpClick(wxCommandEvent& event);
923 void OnDownClick(wxCommandEvent& event);
924 //void OnCustomEditClick(wxCommandEvent& event);
925 void OnIdle(wxIdleEvent& event);
926
927 protected:
928 wxTextCtrl* m_edValue;
929 wxListBox* m_lbStrings;
930
931 wxButton* m_butAdd; // Button pointers
932 wxButton* m_butCustom; // required for disabling/enabling changing.
933 wxButton* m_butUpdate;
934 wxButton* m_butRemove;
935 wxButton* m_butUp;
936 wxButton* m_butDown;
937
938 //wxArrayString m_array;
939
940 const wxChar* m_custBtText;
941 //wxArrayStringPropertyClass* m_pCallingClass;
942
943 bool m_modified;
944
945 unsigned char m_curFocus;
946
947 // These must be overridden - must return true on success.
948 virtual wxString ArrayGet( size_t index ) = 0;
949 virtual size_t ArrayGetCount() = 0;
950 virtual bool ArrayInsert( const wxString& str, int index ) = 0;
951 virtual bool ArraySet( size_t index, const wxString& str ) = 0;
952 virtual void ArrayRemoveAt( int index ) = 0;
953 virtual void ArraySwap( size_t first, size_t second ) = 0;
954
955 private:
956 #ifndef SWIG
957 DECLARE_DYNAMIC_CLASS_NO_COPY(wxArrayEditorDialog)
958 DECLARE_EVENT_TABLE()
959 #endif
960 };
961
962 // -----------------------------------------------------------------------
963 // wxPGArrayStringEditorDialog
964 // -----------------------------------------------------------------------
965
966 class WXDLLIMPEXP_PROPGRID
967 wxPGArrayStringEditorDialog : public wxArrayEditorDialog
968 {
969 public:
970 wxPGArrayStringEditorDialog();
971 virtual ~wxPGArrayStringEditorDialog() { }
972
973 void Init();
974
975 virtual void SetDialogValue( const wxVariant& value )
976 {
977 m_array = value.GetArrayString();
978 }
979
980 virtual wxVariant GetDialogValue() const
981 {
982 return m_array;
983 }
984
985 void SetCustomButton( const wxChar* custBtText, wxArrayStringProperty* pcc )
986 {
987 m_custBtText = custBtText;
988 m_pCallingClass = pcc;
989 }
990
991 void OnCustomEditClick(wxCommandEvent& event);
992
993 protected:
994 wxArrayString m_array;
995
996 wxArrayStringProperty* m_pCallingClass;
997
998 virtual wxString ArrayGet( size_t index );
999 virtual size_t ArrayGetCount();
1000 virtual bool ArrayInsert( const wxString& str, int index );
1001 virtual bool ArraySet( size_t index, const wxString& str );
1002 virtual void ArrayRemoveAt( int index );
1003 virtual void ArraySwap( size_t first, size_t second );
1004
1005 private:
1006 #ifndef SWIG
1007 DECLARE_DYNAMIC_CLASS_NO_COPY(wxPGArrayStringEditorDialog)
1008 DECLARE_EVENT_TABLE()
1009 #endif
1010 };
1011
1012 // -----------------------------------------------------------------------
1013
1014 #endif // wxUSE_PROPGRID
1015
1016 #endif // _WX_PROPGRID_PROPS_H_