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