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