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