1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/props.cpp
3 // Purpose: Basic Property Classes
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcclient.h"
32 #include "wx/dcmemory.h"
33 #include "wx/button.h"
36 #include "wx/cursor.h"
37 #include "wx/dialog.h"
38 #include "wx/settings.h"
39 #include "wx/msgdlg.h"
40 #include "wx/choice.h"
41 #include "wx/stattext.h"
42 #include "wx/scrolwin.h"
43 #include "wx/dirdlg.h"
44 #include "wx/combobox.h"
45 #include "wx/layout.h"
47 #include "wx/textdlg.h"
48 #include "wx/filedlg.h"
49 #include "wx/statusbr.h"
53 #include <wx/filename.h>
55 #include <wx/propgrid/propgrid.h>
57 #define wxPG_CUSTOM_IMAGE_WIDTH 20 // for wxColourProperty etc.
62 // -----------------------------------------------------------------------
64 // -----------------------------------------------------------------------
66 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxStringProperty
,wxPGProperty
,
67 wxString
,const wxString
&,TextCtrl
)
69 wxStringProperty::wxStringProperty( const wxString
& label
,
71 const wxString
& value
)
72 : wxPGProperty(label
,name
)
77 void wxStringProperty::OnSetValue()
79 if ( !m_value
.IsNull() && m_value
.GetString() == wxS("<composed>") )
80 SetFlag(wxPG_PROP_COMPOSED_VALUE
);
82 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
85 GenerateComposedValue(s
, 0);
90 wxStringProperty::~wxStringProperty() { }
92 wxString
wxStringProperty::GetValueAsString( int argFlags
) const
94 wxString s
= m_value
.GetString();
96 if ( GetChildCount() && HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
98 // Value stored in m_value is non-editable, non-full value
99 if ( (argFlags
& wxPG_FULL_VALUE
) || (argFlags
& wxPG_EDITABLE_VALUE
) )
100 GenerateComposedValue(s
, argFlags
);
105 // If string is password and value is for visual purposes,
106 // then return asterisks instead the actual string.
107 if ( (m_flags
& wxPG_PROP_PASSWORD
) && !(argFlags
& (wxPG_FULL_VALUE
|wxPG_EDITABLE_VALUE
)) )
108 return wxString(wxChar('*'), s
.Length());
113 bool wxStringProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
115 if ( GetChildCount() && HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
116 return wxPGProperty::StringToValue(variant
, text
, argFlags
);
118 if ( m_value
.GetString() != text
)
127 bool wxStringProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
129 if ( name
== wxPG_STRING_PASSWORD
)
131 m_flags
&= ~(wxPG_PROP_PASSWORD
);
132 if ( wxPGVariantToInt(value
) ) m_flags
|= wxPG_PROP_PASSWORD
;
139 // -----------------------------------------------------------------------
141 // -----------------------------------------------------------------------
143 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxIntProperty
,wxPGProperty
,
146 wxIntProperty::wxIntProperty( const wxString
& label
, const wxString
& name
,
147 long value
) : wxPGProperty(label
,name
)
152 wxIntProperty::wxIntProperty( const wxString
& label
, const wxString
& name
,
153 const wxLongLong
& value
) : wxPGProperty(label
,name
)
155 SetValue(WXVARIANT(value
));
158 wxIntProperty::~wxIntProperty() { }
160 wxString
wxIntProperty::GetValueAsString( int ) const
162 if ( m_value
.GetType() == wxPG_VARIANT_TYPE_LONG
)
164 return wxString::Format(wxS("%li"),m_value
.GetLong());
166 else if ( m_value
.GetType() == wxLongLong_VariantType
)
170 return ll
.ToString();
173 return wxEmptyString
;
176 bool wxIntProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
181 if ( text
.length() == 0 )
187 // We know it is a number, but let's still check
189 if ( text
.IsNumber() )
191 // Remove leading zeroes, so that the number is not interpreted as octal
192 wxString::const_iterator i
= text
.begin();
193 wxString::const_iterator iMax
= text
.end() - 1; // Let's allow one, last zero though
195 int firstNonZeroPos
= 0;
197 for ( ; i
!= iMax
; i
++ )
200 if ( c
!= wxS('0') && c
!= wxS(' ') )
205 wxString useText
= text
.substr(firstNonZeroPos
, text
.length() - firstNonZeroPos
);
207 wxString variantType
= variant
.GetType();
208 bool isPrevLong
= variantType
== wxPG_VARIANT_TYPE_LONG
;
210 wxLongLong_t value64
= 0;
212 if ( useText
.ToLongLong(&value64
, 10) &&
213 ( value64
>= INT_MAX
|| value64
<= INT_MIN
)
216 bool doChangeValue
= isPrevLong
;
218 if ( !isPrevLong
&& variantType
== wxLongLong_VariantType
)
222 if ( oldValue
.GetValue() != value64
)
223 doChangeValue
= true;
228 wxLongLong
ll(value64
);
234 if ( useText
.ToLong( &value32
, 0 ) )
236 if ( !isPrevLong
|| m_value
.GetLong() != value32
)
243 else if ( argFlags
& wxPG_REPORT_ERROR
)
249 bool wxIntProperty::IntToValue( wxVariant
& variant
, int value
, int WXUNUSED(argFlags
) ) const
251 if ( variant
.GetType() != wxPG_VARIANT_TYPE_LONG
|| variant
.GetLong() != value
)
253 variant
= (long)value
;
259 bool wxIntProperty::DoValidation( const wxPGProperty
* property
, wxLongLong_t
& value
, wxPGValidationInfo
* pValidationInfo
, int mode
)
262 wxLongLong_t min
= wxINT64_MIN
;
263 wxLongLong_t max
= wxINT64_MAX
;
268 variant
= property
->GetAttribute(wxPGGlobalVars
->m_strMin
);
269 if ( !variant
.IsNull() )
271 wxPGVariantToLongLong(variant
, &min
);
275 variant
= property
->GetAttribute(wxPGGlobalVars
->m_strMax
);
276 if ( !variant
.IsNull() )
278 wxPGVariantToLongLong(variant
, &max
);
286 if ( mode
== wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
)
287 pValidationInfo
->m_failureMessage
= wxString::Format(_("Value must be %lld or higher"),min
);
288 else if ( mode
== wxPG_PROPERTY_VALIDATION_SATURATE
)
291 value
= max
- (min
- value
);
300 if ( mode
== wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
)
301 pValidationInfo
->m_failureMessage
= wxString::Format(_("Value must be %lld or higher"),min
);
302 else if ( mode
== wxPG_PROPERTY_VALIDATION_SATURATE
)
305 value
= min
+ (value
- max
);
312 bool wxIntProperty::ValidateValue( wxVariant
& value
, wxPGValidationInfo
& validationInfo
) const
315 if ( wxPGVariantToLongLong(value
, &ll
) )
316 return DoValidation(this, ll
, &validationInfo
, wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
320 wxValidator
* wxIntProperty::GetClassValidator()
323 WX_PG_DOGETVALIDATOR_ENTRY()
325 // Atleast wxPython 2.6.2.1 required that the string argument is given
327 wxTextValidator
* validator
= new wxTextValidator(wxFILTER_NUMERIC
,&v
);
329 WX_PG_DOGETVALIDATOR_EXIT(validator
)
335 wxValidator
* wxIntProperty::DoGetValidator() const
337 return GetClassValidator();
340 // -----------------------------------------------------------------------
342 // -----------------------------------------------------------------------
345 #define wxPG_UINT_TEMPLATE_MAX 8
347 static const wxChar
* gs_uintTemplates32
[wxPG_UINT_TEMPLATE_MAX
] = {
348 wxT("%x"),wxT("0x%x"),wxT("$%x"),
349 wxT("%X"),wxT("0x%X"),wxT("$%X"),
353 static const wxChar
* gs_uintTemplates64
[wxPG_UINT_TEMPLATE_MAX
] = {
354 wxT("%") wxLongLongFmtSpec
wxT("x"),
355 wxT("0x%") wxLongLongFmtSpec
wxT("x"),
356 wxT("$%") wxLongLongFmtSpec
wxT("x"),
357 wxT("%") wxLongLongFmtSpec
wxT("X"),
358 wxT("0x%") wxLongLongFmtSpec
wxT("X"),
359 wxT("$%") wxLongLongFmtSpec
wxT("X"),
360 wxT("%") wxLongLongFmtSpec
wxT("u"),
361 wxT("%") wxLongLongFmtSpec
wxT("o")
364 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxUIntProperty
,wxPGProperty
,
365 long,unsigned long,TextCtrl
)
367 void wxUIntProperty::Init()
369 m_base
= 6; // This is magic number for dec base (must be same as in setattribute)
371 m_prefix
= wxPG_PREFIX_NONE
;
374 wxUIntProperty::wxUIntProperty( const wxString
& label
, const wxString
& name
,
375 unsigned long value
) : wxPGProperty(label
,name
)
378 SetValue((long)value
);
381 wxUIntProperty::wxUIntProperty( const wxString
& label
, const wxString
& name
,
382 const wxULongLong
& value
) : wxPGProperty(label
,name
)
385 SetValue(WXVARIANT(value
));
388 wxUIntProperty::~wxUIntProperty() { }
390 wxString
wxUIntProperty::GetValueAsString( int ) const
392 size_t index
= m_base
+ m_prefix
;
393 if ( index
>= wxPG_UINT_TEMPLATE_MAX
)
394 index
= wxPG_BASE_DEC
;
396 if ( m_value
.GetType() == wxPG_VARIANT_TYPE_LONG
)
398 return wxString::Format(gs_uintTemplates32
[index
], (unsigned long)m_value
.GetLong());
404 return wxString::Format(gs_uintTemplates64
[index
], ull
.GetValue());
407 bool wxUIntProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int WXUNUSED(argFlags
) ) const
409 wxString variantType
= variant
.GetType();
410 bool isPrevLong
= variantType
== wxPG_VARIANT_TYPE_LONG
;
412 if ( text
.length() == 0 )
419 if ( text
[0] == wxS('$') )
422 wxULongLong_t value64
= 0;
423 wxString s
= text
.substr(start
, text
.length() - start
);
425 if ( s
.ToULongLong(&value64
, (unsigned int)m_realBase
) )
427 if ( value64
>= LONG_MAX
)
429 bool doChangeValue
= isPrevLong
;
431 if ( !isPrevLong
&& variantType
== wxULongLong_VariantType
)
433 wxULongLong oldValue
;
435 if ( oldValue
.GetValue() != value64
)
436 doChangeValue
= true;
441 wxULongLong
ull(value64
);
448 unsigned long value32
= wxLongLong(value64
).GetLo();
449 if ( !isPrevLong
|| m_value
.GetLong() != (long)value32
)
451 variant
= (long)value32
;
460 bool wxUIntProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
462 if ( m_value
!= (long)number
)
464 variant
= (long)number
;
471 #define wxUINT64_MAX ULLONG_MAX
472 #define wxUINT64_MIN wxULL(0)
474 #define wxUINT64_MAX wxULL(0xFFFFFFFFFFFFFFFF)
475 #define wxUINT64_MIN wxULL(0)
478 bool wxUIntProperty::ValidateValue( wxVariant
& value
, wxPGValidationInfo
& validationInfo
) const
482 if ( wxPGVariantToULongLong(value
, &ll
) )
484 wxULongLong_t min
= wxUINT64_MIN
;
485 wxULongLong_t max
= wxUINT64_MAX
;
488 variant
= GetAttribute(wxPGGlobalVars
->m_strMin
);
489 if ( !variant
.IsNull() )
491 wxPGVariantToULongLong(variant
, &min
);
494 validationInfo
.m_failureMessage
= wxString::Format(_("Value must be %llu or higher"),min
);
498 variant
= GetAttribute(wxPGGlobalVars
->m_strMax
);
499 if ( !variant
.IsNull() )
501 wxPGVariantToULongLong(variant
, &max
);
504 validationInfo
.m_failureMessage
= wxString::Format(_("Value must be %llu or less"),max
);
512 bool wxUIntProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
514 if ( name
== wxPG_UINT_BASE
)
516 int val
= value
.GetLong();
518 m_realBase
= (wxByte
) val
;
519 if ( m_realBase
> 16 )
523 // Translate logical base to a template array index
525 if ( val
== wxPG_BASE_HEX
)
527 else if ( val
== wxPG_BASE_DEC
)
529 else if ( val
== wxPG_BASE_HEXL
)
533 else if ( name
== wxPG_UINT_PREFIX
)
535 m_prefix
= (wxByte
) value
.GetLong();
541 // -----------------------------------------------------------------------
543 // -----------------------------------------------------------------------
545 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFloatProperty
,wxPGProperty
,
546 double,double,TextCtrl
)
548 wxFloatProperty::wxFloatProperty( const wxString
& label
,
549 const wxString
& name
,
551 : wxPGProperty(label
,name
)
557 wxFloatProperty::~wxFloatProperty() { }
559 // This helper method provides standard way for floating point-using
560 // properties to convert values to string.
561 void wxPropertyGrid::DoubleToString(wxString
& target
,
565 wxString
* precTemplate
)
567 if ( precision
>= 0 )
571 precTemplate
= &text1
;
573 if ( !precTemplate
->length() )
575 *precTemplate
= wxS("%.");
576 *precTemplate
<< wxString::Format( wxS("%i"), precision
);
577 *precTemplate
<< wxS('f');
580 target
.Printf( precTemplate
->c_str(), value
);
584 target
.Printf( wxS("%f"), value
);
587 if ( removeZeroes
&& precision
!= 0 && target
.length() )
589 // Remove excess zeroes (do not remove this code just yet,
590 // since sprintf can't do the same consistently across platforms).
591 wxString::const_iterator i
= target
.end() - 1;
592 size_t new_len
= target
.length() - 1;
594 for ( ; i
!= target
.begin(); i
-- )
596 if ( *i
!= wxS('0') )
601 wxChar cur_char
= *i
;
602 if ( cur_char
!= wxS('.') && cur_char
!= wxS(',') )
605 if ( new_len
!= target
.length() )
606 target
.resize(new_len
);
610 wxString
wxFloatProperty::GetValueAsString( int argFlags
) const
613 if ( !m_value
.IsNull() )
615 wxPropertyGrid::DoubleToString(text
,
618 !(argFlags
& wxPG_FULL_VALUE
),
624 bool wxFloatProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
629 if ( text
.length() == 0 )
635 bool res
= text
.ToDouble(&value
);
638 if ( m_value
!= value
)
644 else if ( argFlags
& wxPG_REPORT_ERROR
)
650 bool wxFloatProperty::DoValidation( const wxPGProperty
* property
, double& value
, wxPGValidationInfo
* pValidationInfo
, int mode
)
653 double min
= (double)wxINT64_MIN
;
654 double max
= (double)wxINT64_MAX
;
659 variant
= property
->GetAttribute(wxPGGlobalVars
->m_strMin
);
660 if ( !variant
.IsNull() )
662 wxPGVariantToDouble(variant
, &min
);
666 variant
= property
->GetAttribute(wxPGGlobalVars
->m_strMax
);
667 if ( !variant
.IsNull() )
669 wxPGVariantToDouble(variant
, &max
);
677 if ( mode
== wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
)
678 pValidationInfo
->m_failureMessage
= wxString::Format(_("Value must be %f or higher"),min
);
679 else if ( mode
== wxPG_PROPERTY_VALIDATION_SATURATE
)
682 value
= max
- (min
- value
);
689 wxPGVariantToDouble(variant
, &max
);
692 if ( mode
== wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
)
693 pValidationInfo
->m_failureMessage
= wxString::Format(_("Value must be %f or less"),max
);
694 else if ( mode
== wxPG_PROPERTY_VALIDATION_SATURATE
)
697 value
= min
+ (value
- max
);
704 bool wxFloatProperty::ValidateValue( wxVariant
& value
, wxPGValidationInfo
& validationInfo
) const
707 if ( wxPGVariantToDouble(value
, &fpv
) )
708 return DoValidation(this, fpv
, &validationInfo
, wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
712 bool wxFloatProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
714 if ( name
== wxPG_FLOAT_PRECISION
)
716 m_precision
= value
.GetLong();
722 wxValidator
* wxFloatProperty::DoGetValidator() const
724 return wxIntProperty::GetClassValidator();
727 // -----------------------------------------------------------------------
729 // -----------------------------------------------------------------------
731 // We cannot use standard WX_PG_IMPLEMENT_PROPERTY_CLASS macro, since
732 // there is a custom GetEditorClass.
734 IMPLEMENT_DYNAMIC_CLASS(wxBoolProperty
, wxPGProperty
)
736 const wxPGEditor
* wxBoolProperty::DoGetEditorClass() const
738 // Select correct editor control.
739 #if wxPG_INCLUDE_CHECKBOX
740 if ( !(m_flags
& wxPG_PROP_USE_CHECKBOX
) )
741 return wxPG_EDITOR(Choice
);
742 return wxPG_EDITOR(CheckBox
);
744 return wxPG_EDITOR(Choice
);
748 wxBoolProperty::wxBoolProperty( const wxString
& label
, const wxString
& name
, bool value
) :
749 wxPGProperty(label
,name
)
751 m_choices
.Assign(wxPGGlobalVars
->m_boolChoices
);
753 SetValue(wxPGVariant_Bool(value
));
755 m_flags
|= wxPG_PROP_USE_DCC
;
758 wxBoolProperty::~wxBoolProperty() { }
760 wxString
wxBoolProperty::GetValueAsString( int argFlags
) const
762 bool value
= m_value
.GetBool();
764 // As a fragment of composite string value,
765 // make it a little more readable.
766 if ( argFlags
& wxPG_COMPOSITE_FRAGMENT
)
774 if ( argFlags
& wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
)
775 return wxEmptyString
;
778 if ( wxPGGlobalVars
->m_autoGetTranslation
)
779 notFmt
= _("Not %s");
781 notFmt
= wxS("Not %s");
783 return wxString::Format(notFmt
.c_str(), m_label
.c_str());
787 if ( !(argFlags
& wxPG_FULL_VALUE
) )
789 return wxPGGlobalVars
->m_boolChoices
[value
?1:0].GetText();
794 if (value
) text
= wxS("true");
795 else text
= wxS("false");
800 bool wxBoolProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int WXUNUSED(argFlags
) ) const
803 if ( text
.CmpNoCase(wxPGGlobalVars
->m_boolChoices
[1].GetText()) == 0 ||
804 text
.CmpNoCase(wxS("true")) == 0 ||
805 text
.CmpNoCase(m_label
) == 0 )
808 if ( text
.length() == 0 )
814 bool oldValue
= m_value
.GetBool();
816 if ( (oldValue
&& !value
) || (!oldValue
&& value
) )
818 variant
= wxPGVariant_Bool(value
);
824 bool wxBoolProperty::IntToValue( wxVariant
& variant
, int value
, int ) const
826 bool boolValue
= value
? true : false;
827 bool oldValue
= m_value
.GetBool();
829 if ( oldValue
!= boolValue
)
831 variant
= wxPGVariant_Bool(boolValue
);
837 bool wxBoolProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
839 #if wxPG_INCLUDE_CHECKBOX
840 if ( name
== wxPG_BOOL_USE_CHECKBOX
)
842 int ival
= wxPGVariantToInt(value
);
844 m_flags
|= wxPG_PROP_USE_CHECKBOX
;
846 m_flags
&= ~(wxPG_PROP_USE_CHECKBOX
);
850 if ( name
== wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING
)
852 int ival
= wxPGVariantToInt(value
);
854 m_flags
|= wxPG_PROP_USE_DCC
;
856 m_flags
&= ~(wxPG_PROP_USE_DCC
);
862 // -----------------------------------------------------------------------
863 // wxBaseEnumProperty
864 // -----------------------------------------------------------------------
866 int wxBaseEnumProperty::ms_nextIndex
= -2;
868 wxBaseEnumProperty::wxBaseEnumProperty( const wxString
& label
, const wxString
& name
)
869 : wxPGProperty(label
,name
)
871 m_value
= wxPGVariant_Zero
;
874 /** If has values array, then returns number at index with value -
875 otherwise just returns the value.
877 int wxBaseEnumProperty::GetIndexForValue( int value
) const
882 void wxBaseEnumProperty::OnSetValue()
884 wxString variantType
= m_value
.GetType();
886 if ( variantType
== wxPG_VARIANT_TYPE_LONG
)
887 ValueFromInt_( m_value
, m_value
.GetLong(), wxPG_FULL_VALUE
);
888 else if ( variantType
== wxPG_VARIANT_TYPE_STRING
)
889 ValueFromString_( m_value
, m_value
.GetString(), 0 );
893 if ( ms_nextIndex
!= -2 )
895 m_index
= ms_nextIndex
;
900 bool wxBaseEnumProperty::ValidateValue( wxVariant
& value
, wxPGValidationInfo
& WXUNUSED(validationInfo
) ) const
902 // Make sure string value is in the list,
903 // unless property has string as preferred value type
904 // To reduce code size, use conversion here as well
905 if ( value
.GetType() == wxPG_VARIANT_TYPE_STRING
&&
906 !this->IsKindOf(CLASSINFO(wxEditEnumProperty
)) )
907 return ValueFromString_( value
, value
.GetString(), wxPG_PROPERTY_SPECIFIC
);
912 wxString
wxBaseEnumProperty::GetValueAsString( int ) const
914 if ( m_value
.GetType() == wxPG_VARIANT_TYPE_STRING
)
915 return m_value
.GetString();
920 const wxString
* pstr
= GetEntry( m_index
, &unusedVal
);
925 return wxEmptyString
;
928 bool wxBaseEnumProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
930 return ValueFromString_( variant
, text
, argFlags
);
933 bool wxBaseEnumProperty::IntToValue( wxVariant
& variant
, int intVal
, int argFlags
) const
935 return ValueFromInt_( variant
, intVal
, argFlags
);
938 bool wxBaseEnumProperty::ValueFromString_( wxVariant
& value
, const wxString
& text
, int argFlags
) const
941 const wxString
* entryLabel
;
946 entryLabel
= GetEntry(i
, &entryValue
);
949 if ( text
.CmpNoCase(*entryLabel
) == 0 )
952 useValue
= (long)entryValue
;
957 entryLabel
= GetEntry(i
, &entryValue
);
962 bool isEdit
= this->IsKindOf(CLASSINFO(wxEditEnumProperty
));
964 // If text not any of the choices, store as text instead
965 // (but only if we are wxEditEnumProperty)
966 if ( useIndex
== -1 &&
967 (value
.GetType() != wxPG_VARIANT_TYPE_STRING
|| (m_value
.GetString() != text
)) &&
973 int setAsNextIndex
= -2;
980 else if ( m_index
!= useIndex
)
982 if ( useIndex
!= -1 )
984 setAsNextIndex
= useIndex
;
985 value
= (long)useValue
;
990 value
= wxPGVariant_MinusOne
;
994 if ( setAsNextIndex
!= -2 )
996 // If wxPG_PROPERTY_SPECIFIC is set, then this is done for
997 // validation purposes only, and index must not be changed
998 if ( !(argFlags
& wxPG_PROPERTY_SPECIFIC
) )
999 ms_nextIndex
= setAsNextIndex
;
1001 if ( isEdit
|| setAsNextIndex
!= -1 )
1009 bool wxBaseEnumProperty::ValueFromInt_( wxVariant
& variant
, int intVal
, int argFlags
) const
1011 // If wxPG_FULL_VALUE is *not* in argFlags, then intVal is index from combo box.
1015 if ( argFlags
& wxPG_FULL_VALUE
)
1017 ms_nextIndex
= GetIndexForValue( intVal
);
1021 if ( m_index
!= intVal
)
1023 ms_nextIndex
= intVal
;
1027 if ( ms_nextIndex
!= -2 )
1029 if ( !(argFlags
& wxPG_FULL_VALUE
) )
1030 GetEntry(intVal
, &intVal
);
1032 variant
= (long)intVal
;
1040 void wxBaseEnumProperty::SetIndex( int index
)
1046 int wxBaseEnumProperty::GetIndex() const
1048 if ( ms_nextIndex
!= -2 )
1049 return ms_nextIndex
;
1053 // -----------------------------------------------------------------------
1055 // -----------------------------------------------------------------------
1057 IMPLEMENT_DYNAMIC_CLASS(wxEnumProperty
, wxPGProperty
)
1059 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxEnumProperty
,long,Choice
)
1061 wxEnumProperty::wxEnumProperty( const wxString
& label
, const wxString
& name
, const wxChar
** labels
,
1062 const long* values
, int value
) : wxBaseEnumProperty(label
,name
)
1068 m_choices
.Add(labels
,values
);
1070 if ( GetItemCount() )
1071 SetValue( (long)value
);
1075 wxEnumProperty::wxEnumProperty( const wxString
& label
, const wxString
& name
, const wxChar
** labels
,
1076 const long* values
, wxPGChoices
* choicesCache
, int value
)
1077 : wxBaseEnumProperty(label
,name
)
1081 wxASSERT( choicesCache
);
1083 if ( choicesCache
->IsOk() )
1085 m_choices
.Assign( *choicesCache
);
1086 m_value
= wxPGVariant_Zero
;
1090 m_choices
.Add(labels
,values
);
1092 if ( GetItemCount() )
1093 SetValue( (long)value
);
1097 wxEnumProperty::wxEnumProperty( const wxString
& label
, const wxString
& name
,
1098 const wxArrayString
& labels
, const wxArrayInt
& values
, int value
) : wxBaseEnumProperty(label
,name
)
1102 if ( &labels
&& labels
.size() )
1104 m_choices
.Set(labels
, values
);
1106 if ( GetItemCount() )
1107 SetValue( (long)value
);
1111 wxEnumProperty::wxEnumProperty( const wxString
& label
, const wxString
& name
,
1112 wxPGChoices
& choices
, int value
)
1113 : wxBaseEnumProperty(label
,name
)
1115 m_choices
.Assign( choices
);
1117 if ( GetItemCount() )
1118 SetValue( (long)value
);
1121 int wxEnumProperty::GetIndexForValue( int value
) const
1123 if ( !m_choices
.IsOk() )
1126 if ( m_choices
.HasValues() )
1128 int intVal
= m_choices
.Index(value
);
1136 wxEnumProperty::~wxEnumProperty ()
1140 const wxString
* wxEnumProperty::GetEntry( size_t index
, int* pvalue
) const
1142 if ( m_choices
.IsOk() && index
< m_choices
.GetCount() )
1144 int value
= (int)index
;
1145 if ( m_choices
.HasValue(index
) )
1146 value
= m_choices
.GetValue(index
);
1151 return &m_choices
.GetLabel(index
);
1153 return (const wxString
*) NULL
;
1156 // -----------------------------------------------------------------------
1157 // wxEditEnumProperty
1158 // -----------------------------------------------------------------------
1160 IMPLEMENT_DYNAMIC_CLASS(wxEditEnumProperty
, wxPGProperty
)
1162 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxEditEnumProperty
,wxString
,ComboBox
)
1164 wxEditEnumProperty::wxEditEnumProperty( const wxString
& label
, const wxString
& name
, const wxChar
** labels
,
1165 const long* values
, const wxString
& value
)
1166 : wxEnumProperty(label
,name
,labels
,values
,0)
1171 wxEditEnumProperty::wxEditEnumProperty( const wxString
& label
, const wxString
& name
, const wxChar
** labels
,
1172 const long* values
, wxPGChoices
* choicesCache
, const wxString
& value
)
1173 : wxEnumProperty(label
,name
,labels
,values
,choicesCache
,0)
1178 wxEditEnumProperty::wxEditEnumProperty( const wxString
& label
, const wxString
& name
,
1179 const wxArrayString
& labels
, const wxArrayInt
& values
, const wxString
& value
)
1180 : wxEnumProperty(label
,name
,labels
,values
,0)
1185 wxEditEnumProperty::wxEditEnumProperty( const wxString
& label
, const wxString
& name
,
1186 wxPGChoices
& choices
, const wxString
& value
)
1187 : wxEnumProperty(label
,name
,choices
,0)
1192 wxEditEnumProperty::~wxEditEnumProperty()
1196 // -----------------------------------------------------------------------
1198 // -----------------------------------------------------------------------
1200 IMPLEMENT_DYNAMIC_CLASS(wxFlagsProperty
,wxPGProperty
)
1202 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxFlagsProperty
,long,TextCtrl
)
1204 void wxFlagsProperty::Init()
1206 SetFlag(wxPG_PROP_AGGREGATE
); // This is must be done here to support flag props
1207 // with inital zero children.
1209 long value
= m_value
;
1212 // Generate children
1216 unsigned int prevChildCount
= m_children
.GetCount();
1219 if ( prevChildCount
)
1221 wxPropertyGridPageState
* state
= GetParentState();
1223 // State safety check (it may be NULL in immediate parent)
1228 wxPGProperty
* selected
= state
->GetSelection();
1231 if ( selected
->GetParent() == this )
1232 oldSel
= selected
->GetArrIndex();
1233 else if ( selected
== this )
1237 state
->DoClearSelection();
1240 // Delete old children
1241 for ( i
=0; i
<prevChildCount
; i
++ )
1242 delete ( (wxPGProperty
*) m_children
[i
] );
1246 if ( m_choices
.IsOk() )
1248 const wxPGChoices
& choices
= m_choices
;
1250 for ( i
=0; i
<GetItemCount(); i
++ )
1253 if ( choices
.HasValue(i
) )
1254 child_val
= ( value
& choices
.GetValue(i
) )?true:false;
1256 child_val
= ( value
& (1<<i
) )?true:false;
1258 wxPGProperty
* boolProp
;
1259 wxString label
= GetLabel(i
);
1262 if ( wxPGGlobalVars
->m_autoGetTranslation
)
1264 boolProp
= new wxBoolProperty( ::wxGetTranslation(label
), label
, child_val
);
1269 boolProp
= new wxBoolProperty( label
, label
, child_val
);
1274 m_oldChoicesData
= m_choices
.GetDataPtr();
1277 m_oldValue
= m_value
;
1279 if ( prevChildCount
)
1280 SubPropsChanged(oldSel
);
1283 wxFlagsProperty::wxFlagsProperty( const wxString
& label
, const wxString
& name
,
1284 const wxChar
** labels
, const long* values
, long value
) : wxPGProperty(label
,name
)
1286 m_oldChoicesData
= (wxPGChoicesData
*) NULL
;
1290 m_choices
.Set(labels
,values
);
1292 wxASSERT( GetItemCount() );
1298 m_value
= wxPGVariant_Zero
;
1302 wxFlagsProperty::wxFlagsProperty( const wxString
& label
, const wxString
& name
,
1303 const wxArrayString
& labels
, const wxArrayInt
& values
, int value
)
1304 : wxPGProperty(label
,name
)
1306 m_oldChoicesData
= (wxPGChoicesData
*) NULL
;
1308 if ( &labels
&& labels
.size() )
1310 m_choices
.Set(labels
,values
);
1312 wxASSERT( GetItemCount() );
1314 SetValue( (long)value
);
1318 m_value
= wxPGVariant_Zero
;
1322 wxFlagsProperty::wxFlagsProperty( const wxString
& label
, const wxString
& name
,
1323 wxPGChoices
& choices
, long value
)
1324 : wxPGProperty(label
,name
)
1326 m_oldChoicesData
= (wxPGChoicesData
*) NULL
;
1328 if ( choices
.IsOk() )
1330 m_choices
.Assign(choices
);
1332 wxASSERT( GetItemCount() );
1338 m_value
= wxPGVariant_Zero
;
1342 wxFlagsProperty::~wxFlagsProperty()
1346 void wxFlagsProperty::OnSetValue()
1348 if ( !m_choices
.IsOk() || !GetItemCount() )
1350 m_value
= wxPGVariant_Zero
;
1354 long val
= m_value
.GetLong();
1358 // normalize the value (i.e. remove extra flags)
1360 const wxPGChoices
& choices
= m_choices
;
1361 for ( i
= 0; i
< GetItemCount(); i
++ )
1363 if ( choices
.HasValue(i
) )
1364 fullFlags
|= choices
.GetValue(i
);
1366 fullFlags
|= (1<<i
);
1373 // Need to (re)init now?
1374 if ( GetChildCount() != GetItemCount() ||
1375 m_choices
.GetDataPtr() != m_oldChoicesData
)
1381 long newFlags
= m_value
;
1383 if ( newFlags
!= m_oldValue
)
1385 // Set child modified states
1387 const wxPGChoices
& choices
= m_choices
;
1388 for ( i
= 0; i
<GetItemCount(); i
++ )
1392 if ( choices
.HasValue(i
) )
1393 flag
= choices
.GetValue(i
);
1397 if ( (newFlags
& flag
) != (m_oldValue
& flag
) )
1398 Item(i
)->SetFlag( wxPG_PROP_MODIFIED
);
1401 m_oldValue
= newFlags
;
1405 wxString
wxFlagsProperty::GetValueAsString( int ) const
1409 if ( !m_choices
.IsOk() )
1412 long flags
= m_value
;
1414 const wxPGChoices
& choices
= m_choices
;
1416 for ( i
= 0; i
< GetItemCount(); i
++ )
1419 if ( choices
.HasValue(i
) )
1420 doAdd
= ( flags
& choices
.GetValue(i
) );
1422 doAdd
= ( flags
& (1<<i
) );
1426 text
+= choices
.GetLabel(i
);
1431 // remove last comma
1432 if ( text
.Len() > 1 )
1433 text
.Truncate ( text
.Len() - 2 );
1438 // Translate string into flag tokens
1439 bool wxFlagsProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1441 if ( !m_choices
.IsOk() )
1445 long oldValue
= m_value
;
1447 // semicolons are no longer valid delimeters
1448 WX_PG_TOKENIZER1_BEGIN(text
,wxS(','))
1450 if ( token
.length() )
1452 // Determine which one it is
1453 long bit
= IdToBit( token
);
1466 WX_PG_TOKENIZER1_END()
1470 if ( newFlags
!= oldValue
)
1476 // Converts string id to a relevant bit.
1477 long wxFlagsProperty::IdToBit( const wxString
& id
) const
1480 for ( i
= 0; i
< GetItemCount(); i
++ )
1482 if ( id
== GetLabel(i
) )
1484 if ( m_choices
.HasValue(i
) )
1485 return m_choices
.GetValue(i
);
1492 void wxFlagsProperty::RefreshChildren()
1494 if ( !m_choices
.IsOk() || !GetChildCount() ) return;
1496 int flags
= m_value
.GetLong();
1498 const wxPGChoices
& choices
= m_choices
;
1500 for ( i
= 0; i
< GetItemCount(); i
++ )
1504 if ( choices
.HasValue(i
) )
1505 flag
= choices
.GetValue(i
);
1509 long subVal
= flags
& flag
;
1510 wxPGProperty
* p
= Item(i
);
1512 if ( subVal
!= (m_oldValue
& flag
) )
1513 p
->SetFlag( wxPG_PROP_MODIFIED
);
1515 p
->SetValue( subVal
?true:false );
1521 void wxFlagsProperty::ChildChanged( wxVariant
& thisValue
, int childIndex
, wxVariant
& childValue
) const
1523 long oldValue
= thisValue
.GetLong();
1524 long val
= childValue
.GetLong();
1525 unsigned long vi
= (1<<childIndex
);
1526 if ( m_choices
.HasValue(childIndex
) ) vi
= m_choices
.GetValue(childIndex
);
1528 thisValue
= (long)(oldValue
| vi
);
1530 thisValue
= (long)(oldValue
& ~(vi
));
1533 // -----------------------------------------------------------------------
1535 // -----------------------------------------------------------------------
1537 IMPLEMENT_DYNAMIC_CLASS(wxDirProperty
, wxLongStringProperty
)
1539 wxDirProperty::wxDirProperty( const wxString
& name
, const wxString
& label
, const wxString
& value
)
1540 : wxLongStringProperty(name
,label
,value
)
1542 m_flags
|= wxPG_NO_ESCAPE
;
1544 wxDirProperty::~wxDirProperty() { }
1546 wxValidator
* wxDirProperty::DoGetValidator() const
1548 return wxFileProperty::GetClassValidator();
1551 bool wxDirProperty::OnButtonClick( wxPropertyGrid
* propGrid
, wxString
& value
)
1553 wxSize
dlg_sz(300,400);
1555 wxDirDialog
dlg( propGrid
,
1556 m_dlgMessage
.length() ? m_dlgMessage
: wxString(_("Choose a directory:")),
1559 #if !wxPG_SMALL_SCREEN
1560 propGrid
->GetGoodEditorDialogPosition(this,dlg_sz
),
1567 if ( dlg
.ShowModal() == wxID_OK
)
1569 value
= dlg
.GetPath();
1575 bool wxDirProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1577 if ( name
== wxPG_DIR_DIALOG_MESSAGE
)
1579 m_dlgMessage
= value
.GetString();
1585 // -----------------------------------------------------------------------
1586 // wxPGFileDialogAdapter
1587 // -----------------------------------------------------------------------
1589 bool wxPGFileDialogAdapter::DoShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
1591 wxFileProperty
* fileProp
= NULL
;
1595 if ( property
->IsKindOf(CLASSINFO(wxFileProperty
)) )
1597 fileProp
= ((wxFileProperty
*)property
);
1598 path
= fileProp
->m_filename
.GetPath();
1599 indFilter
= fileProp
->m_indFilter
;
1601 if ( !path
.length() && fileProp
->m_basePath
.length() )
1602 path
= fileProp
->m_basePath
;
1606 wxFileName
fn(property
->GetValue().GetString());
1607 path
= fn
.GetPath();
1610 wxFileDialog
dlg( propGrid
->GetPanel(),
1611 property
->GetAttribute(wxS("DialogTitle"), _("Choose a file")),
1612 property
->GetAttribute(wxS("InitialPath"), path
),
1614 property
->GetAttribute(wxPG_FILE_WILDCARD
, _("All files (*.*)|*.*")),
1616 wxDefaultPosition
);
1618 if ( indFilter
>= 0 )
1619 dlg
.SetFilterIndex( indFilter
);
1621 if ( dlg
.ShowModal() == wxID_OK
)
1624 fileProp
->m_indFilter
= dlg
.GetFilterIndex();
1625 SetValue( dlg
.GetPath() );
1631 // -----------------------------------------------------------------------
1633 // -----------------------------------------------------------------------
1635 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFileProperty
,wxPGProperty
,
1636 wxString
,const wxString
&,TextCtrlAndButton
)
1638 wxFileProperty::wxFileProperty( const wxString
& label
, const wxString
& name
,
1639 const wxString
& value
) : wxPGProperty(label
,name
)
1641 m_flags
|= wxPG_PROP_SHOW_FULL_FILENAME
;
1643 SetAttribute( wxPG_FILE_WILDCARD
, _("All files (*.*)|*.*") );
1648 wxFileProperty::~wxFileProperty() {}
1650 #if wxUSE_VALIDATORS
1652 wxValidator
* wxFileProperty::GetClassValidator()
1654 WX_PG_DOGETVALIDATOR_ENTRY()
1656 // Atleast wxPython 2.6.2.1 required that the string argument is given
1658 wxTextValidator
* validator
= new wxTextValidator(wxFILTER_EXCLUDE_CHAR_LIST
,&v
);
1660 wxArrayString exChars
;
1661 exChars
.Add(wxS("?"));
1662 exChars
.Add(wxS("*"));
1663 exChars
.Add(wxS("|"));
1664 exChars
.Add(wxS("<"));
1665 exChars
.Add(wxS(">"));
1666 exChars
.Add(wxS("\""));
1668 validator
->SetExcludes(exChars
);
1670 WX_PG_DOGETVALIDATOR_EXIT(validator
)
1673 wxValidator
* wxFileProperty::DoGetValidator() const
1675 return GetClassValidator();
1680 void wxFileProperty::OnSetValue()
1682 const wxString
& fnstr
= m_value
.GetString();
1686 if ( !m_filename
.HasName() )
1688 m_value
= wxPGVariant_EmptyString
;
1692 // Find index for extension.
1693 if ( m_indFilter
< 0 && fnstr
.length() )
1695 wxString ext
= m_filename
.GetExt();
1698 size_t len
= m_wildcard
.length();
1700 pos
= m_wildcard
.find(wxS("|"), pos
);
1701 while ( pos
!= wxString::npos
&& pos
< (len
-3) )
1703 size_t ext_begin
= pos
+ 3;
1705 pos
= m_wildcard
.find(wxS("|"), ext_begin
);
1706 if ( pos
== wxString::npos
)
1708 wxString found_ext
= m_wildcard
.substr(ext_begin
, pos
-ext_begin
);
1710 if ( found_ext
.length() > 0 )
1712 if ( found_ext
[0] == wxS('*') )
1714 m_indFilter
= curind
;
1717 if ( ext
.CmpNoCase(found_ext
) == 0 )
1719 m_indFilter
= curind
;
1725 pos
= m_wildcard
.find(wxS("|"), pos
+1);
1732 wxString
wxFileProperty::GetValueAsString( int argFlags
) const
1734 // Always return empty string when name component is empty
1735 wxString fullName
= m_filename
.GetFullName();
1736 if ( !fullName
.length() )
1739 if ( argFlags
& wxPG_FULL_VALUE
)
1741 return m_filename
.GetFullPath();
1743 else if ( m_flags
& wxPG_PROP_SHOW_FULL_FILENAME
)
1745 if ( m_basePath
.Length() )
1747 wxFileName
fn2(m_filename
);
1748 fn2
.MakeRelativeTo(m_basePath
);
1749 return fn2
.GetFullPath();
1751 return m_filename
.GetFullPath();
1754 return m_filename
.GetFullName();
1757 wxPGEditorDialogAdapter
* wxFileProperty::GetEditorDialog() const
1759 return new wxPGFileDialogAdapter();
1762 bool wxFileProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
1764 if ( (m_flags
& wxPG_PROP_SHOW_FULL_FILENAME
) || (argFlags
& wxPG_FULL_VALUE
) )
1766 if ( m_filename
!= text
)
1774 if ( m_filename
.GetFullName() != text
)
1776 wxFileName fn
= m_filename
;
1777 fn
.SetFullName(text
);
1778 variant
= fn
.GetFullPath();
1786 bool wxFileProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1788 // Return false on some occasions to make sure those attribs will get
1789 // stored in m_attributes.
1790 if ( name
== wxPG_FILE_SHOW_FULL_PATH
)
1792 if ( wxPGVariantToInt(value
) )
1793 m_flags
|= wxPG_PROP_SHOW_FULL_FILENAME
;
1795 m_flags
&= ~(wxPG_PROP_SHOW_FULL_FILENAME
);
1798 else if ( name
== wxPG_FILE_WILDCARD
)
1800 m_wildcard
= value
.GetString();
1802 else if ( name
== wxPG_FILE_SHOW_RELATIVE_PATH
)
1804 m_basePath
= value
.GetString();
1806 // Make sure wxPG_FILE_SHOW_FULL_PATH is also set
1807 m_flags
|= wxPG_PROP_SHOW_FULL_FILENAME
;
1809 else if ( name
== wxPG_FILE_INITIAL_PATH
)
1811 m_initialPath
= value
.GetString();
1814 else if ( name
== wxPG_FILE_DIALOG_TITLE
)
1816 m_dlgTitle
= value
.GetString();
1822 // -----------------------------------------------------------------------
1823 // wxPGLongStringDialogAdapter
1824 // -----------------------------------------------------------------------
1826 bool wxPGLongStringDialogAdapter::DoShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
1828 wxString val1
= property
->GetValueAsString(0);
1829 wxString val_orig
= val1
;
1832 if ( !property
->HasFlag(wxPG_PROP_NO_ESCAPE
) )
1833 wxPropertyGrid::ExpandEscapeSequences(value
, val1
);
1835 value
= wxString(val1
);
1837 // Run editor dialog.
1838 if ( wxLongStringProperty::DisplayEditorDialog(property
, propGrid
, value
) )
1840 if ( !property
->HasFlag(wxPG_PROP_NO_ESCAPE
) )
1841 wxPropertyGrid::CreateEscapeSequences(val1
,value
);
1845 if ( val1
!= val_orig
)
1854 // -----------------------------------------------------------------------
1855 // wxLongStringProperty
1856 // -----------------------------------------------------------------------
1858 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxLongStringProperty
,wxPGProperty
,
1859 wxString
,const wxString
&,TextCtrlAndButton
)
1861 wxLongStringProperty::wxLongStringProperty( const wxString
& label
, const wxString
& name
,
1862 const wxString
& value
) : wxPGProperty(label
,name
)
1867 wxLongStringProperty::~wxLongStringProperty() {}
1869 wxString
wxLongStringProperty::GetValueAsString( int ) const
1874 bool wxLongStringProperty::OnEvent( wxPropertyGrid
* propGrid
, wxWindow
* WXUNUSED(primary
),
1877 if ( propGrid
->IsMainButtonEvent(event
) )
1880 PrepareValueForDialogEditing(propGrid
);
1882 wxString val1
= GetValueAsString(0);
1883 wxString val_orig
= val1
;
1886 if ( !(m_flags
& wxPG_PROP_NO_ESCAPE
) )
1887 wxPropertyGrid::ExpandEscapeSequences(value
,val1
);
1889 value
= wxString(val1
);
1891 // Run editor dialog.
1892 if ( OnButtonClick(propGrid
,value
) )
1894 if ( !(m_flags
& wxPG_PROP_NO_ESCAPE
) )
1895 wxPropertyGrid::CreateEscapeSequences(val1
,value
);
1899 if ( val1
!= val_orig
)
1901 SetValueInEvent( val1
);
1909 bool wxLongStringProperty::OnButtonClick( wxPropertyGrid
* propGrid
, wxString
& value
)
1911 return DisplayEditorDialog(this, propGrid
, value
);
1914 bool wxLongStringProperty::DisplayEditorDialog( wxPGProperty
* prop
, wxPropertyGrid
* propGrid
, wxString
& value
)
1917 // launch editor dialog
1918 wxDialog
* dlg
= new wxDialog(propGrid
,-1,prop
->GetLabel(),wxDefaultPosition
,wxDefaultSize
,
1919 wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
|wxCLIP_CHILDREN
);
1921 dlg
->SetFont(propGrid
->GetFont()); // To allow entering chars of the same set as the propGrid
1923 // Multi-line text editor dialog.
1924 #if !wxPG_SMALL_SCREEN
1925 const int spacing
= 8;
1927 const int spacing
= 4;
1929 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
1930 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
1931 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,value
,
1932 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
);
1934 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
1935 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
1936 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
1937 const int but_sz_flags
=
1938 wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxLEFT
|wxRIGHT
;
1939 rowsizer
->Add( new wxButton(dlg
,wxID_OK
,_("Ok")),
1940 0, but_sz_flags
, spacing
);
1941 rowsizer
->Add( new wxButton(dlg
,wxID_CANCEL
,_("Cancel")),
1942 0, but_sz_flags
, spacing
);
1943 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
1945 dlg
->SetSizer( topsizer
);
1946 topsizer
->SetSizeHints( dlg
);
1948 #if !wxPG_SMALL_SCREEN
1949 dlg
->SetSize(400,300);
1951 dlg
->Move( propGrid
->GetGoodEditorDialogPosition(prop
,dlg
->GetSize()) );
1954 int res
= dlg
->ShowModal();
1956 if ( res
== wxID_OK
)
1958 value
= ed
->GetValue();
1966 bool wxLongStringProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1968 if ( m_value
!= text
)
1976 // -----------------------------------------------------------------------
1977 // wxArrayEditorDialog
1978 // -----------------------------------------------------------------------
1980 BEGIN_EVENT_TABLE(wxArrayEditorDialog
, wxDialog
)
1981 EVT_IDLE(wxArrayEditorDialog::OnIdle
)
1982 EVT_LISTBOX(24, wxArrayEditorDialog::OnListBoxClick
)
1983 EVT_TEXT_ENTER(21, wxArrayEditorDialog::OnAddClick
)
1984 EVT_BUTTON(22, wxArrayEditorDialog::OnAddClick
)
1985 EVT_BUTTON(23, wxArrayEditorDialog::OnDeleteClick
)
1986 EVT_BUTTON(25, wxArrayEditorDialog::OnUpClick
)
1987 EVT_BUTTON(26, wxArrayEditorDialog::OnDownClick
)
1988 EVT_BUTTON(27, wxArrayEditorDialog::OnUpdateClick
)
1989 //EVT_BUTTON(28, wxArrayEditorDialog::OnCustomEditClick)
1992 IMPLEMENT_ABSTRACT_CLASS(wxArrayEditorDialog
, wxDialog
)
1994 #include <wx/statline.h>
1996 // -----------------------------------------------------------------------
1998 void wxArrayEditorDialog::OnIdle(wxIdleEvent
& event
)
2001 // Do control focus detection here.
2004 wxWindow
* focused
= FindFocus();
2006 // This strange focus thing is a workaround for wxGTK wxListBox focus
2008 if ( m_curFocus
== 0 && focused
!= m_edValue
&&
2009 focused
!= m_butAdd
&& focused
!= m_butUpdate
&&
2010 m_lbStrings
->GetSelection() >= 0 )
2012 // ListBox was just focused.
2013 m_butAdd
->Enable(false);
2014 m_butUpdate
->Enable(false);
2015 m_butRemove
->Enable(true);
2016 m_butUp
->Enable(true);
2017 m_butDown
->Enable(true);
2020 else if ( (m_curFocus
== 1 && focused
== m_edValue
) /*|| m_curFocus == 2*/ )
2022 // TextCtrl was just focused.
2023 m_butAdd
->Enable(true);
2024 bool upd_enable
= false;
2025 if ( m_lbStrings
->GetCount() && m_lbStrings
->GetSelection() >= 0 )
2027 m_butUpdate
->Enable(upd_enable
);
2028 m_butRemove
->Enable(false);
2029 m_butUp
->Enable(false);
2030 m_butDown
->Enable(false);
2037 // -----------------------------------------------------------------------
2039 wxArrayEditorDialog::wxArrayEditorDialog()
2045 // -----------------------------------------------------------------------
2047 void wxArrayEditorDialog::Init()
2049 m_custBtText
= (const wxChar
*) NULL
;
2052 // -----------------------------------------------------------------------
2054 wxArrayEditorDialog::wxArrayEditorDialog( wxWindow
*parent
,
2055 const wxString
& message
,
2056 const wxString
& caption
,
2063 Create(parent
,message
,caption
,style
,pos
,sz
);
2066 // -----------------------------------------------------------------------
2068 bool wxArrayEditorDialog::Create( wxWindow
*parent
,
2069 const wxString
& message
,
2070 const wxString
& caption
,
2075 // On wxMAC the dialog shows incorrectly if style is not exactly wxCAPTION
2076 // FIXME: This should be only a temporary fix.
2078 int useStyle
= wxCAPTION
;
2080 int useStyle
= style
;
2083 bool res
= wxDialog::Create(parent
, wxID_ANY
, caption
, pos
, sz
, useStyle
);
2085 SetFont(parent
->GetFont()); // To allow entering chars of the same set as the propGrid
2087 #if !wxPG_SMALL_SCREEN
2088 const int spacing
= 4;
2090 const int spacing
= 3;
2097 const int but_sz_flags
=
2098 wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
|wxALL
; //wxBOTTOM|wxLEFT|wxRIGHT;
2100 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
2103 if ( message
.length() )
2104 topsizer
->Add( new wxStaticText(this,-1,message
),
2105 0, wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
|wxALL
, spacing
);
2108 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
2109 m_edValue
= new wxTextCtrl(this,21,wxEmptyString
,
2110 wxDefaultPosition
,wxDefaultSize
,wxTE_PROCESS_ENTER
);
2111 wxValidator
* validator
= GetTextCtrlValidator();
2114 m_edValue
->SetValidator( *validator
);
2117 rowsizer
->Add( m_edValue
,
2118 1, wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
|wxALL
, spacing
);
2121 m_butAdd
= new wxButton(this,22,_("Add"));
2122 rowsizer
->Add( m_butAdd
,
2123 0, wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
|wxTOP
|wxBOTTOM
|wxRIGHT
, spacing
);
2124 topsizer
->Add( rowsizer
, 0, wxEXPAND
, spacing
);
2127 topsizer
->Add( new wxStaticLine(this,-1),
2128 0, wxEXPAND
|wxBOTTOM
|wxLEFT
|wxRIGHT
, spacing
);
2130 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
2133 m_lbStrings
= new wxListBox(this, 24, wxDefaultPosition
, wxDefaultSize
);
2135 for ( i
=0; i
<ArrayGetCount(); i
++ )
2136 m_lbStrings
->Append( ArrayGet(i
) );
2137 rowsizer
->Add( m_lbStrings
, 1, wxEXPAND
|wxRIGHT
, spacing
);
2139 // Manipulator buttons
2140 wxBoxSizer
* colsizer
= new wxBoxSizer( wxVERTICAL
);
2141 m_butCustom
= (wxButton
*) NULL
;
2144 m_butCustom
= new wxButton(this,28,::wxGetTranslation(m_custBtText
));
2145 colsizer
->Add( m_butCustom
,
2146 0, wxALIGN_CENTER
|wxTOP
/*wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT*/,
2149 m_butUpdate
= new wxButton(this,27,_("Update"));
2150 colsizer
->Add( m_butUpdate
,
2151 0, wxALIGN_CENTER
|wxTOP
, spacing
);
2152 m_butRemove
= new wxButton(this,23,_("Remove"));
2153 colsizer
->Add( m_butRemove
,
2154 0, wxALIGN_CENTER
|wxTOP
, spacing
);
2155 m_butUp
= new wxButton(this,25,_("Up"));
2156 colsizer
->Add( m_butUp
,
2157 0, wxALIGN_CENTER
|wxTOP
, spacing
);
2158 m_butDown
= new wxButton(this,26,_("Down"));
2159 colsizer
->Add( m_butDown
,
2160 0, wxALIGN_CENTER
|wxTOP
, spacing
);
2161 rowsizer
->Add( colsizer
, 0, 0, spacing
);
2163 topsizer
->Add( rowsizer
, 1, wxLEFT
|wxRIGHT
|wxEXPAND
, spacing
);
2166 topsizer
->Add( new wxStaticLine(this,-1),
2167 0, wxEXPAND
|wxTOP
|wxLEFT
|wxRIGHT
, spacing
);
2170 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
2172 const int but_sz_flags =
2173 wxALIGN_RIGHT|wxALIGN_CENTRE_VERTICAL|wxBOTTOM|wxLEFT|wxRIGHT;
2175 rowsizer
->Add( new wxButton(this,wxID_OK
,_("Ok")),
2176 0, but_sz_flags
, spacing
);
2177 rowsizer
->Add( new wxButton(this,wxID_CANCEL
,_("Cancel")),
2178 0, but_sz_flags
, spacing
);
2179 topsizer
->Add( rowsizer
, 0, wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
, 0 );
2181 m_edValue
->SetFocus();
2183 SetSizer( topsizer
);
2184 topsizer
->SetSizeHints( this );
2186 #if !wxPG_SMALL_SCREEN
2187 if ( sz
.x
== wxDefaultSize
.x
&&
2188 sz
.y
== wxDefaultSize
.y
)
2189 SetSize( wxSize(275,360) );
2197 // -----------------------------------------------------------------------
2199 void wxArrayEditorDialog::OnAddClick(wxCommandEvent
& )
2201 wxString text
= m_edValue
->GetValue();
2202 if ( text
.length() )
2204 if ( ArrayInsert( text
, -1 ) )
2206 m_lbStrings
->Append( text
);
2213 // -----------------------------------------------------------------------
2215 void wxArrayEditorDialog::OnDeleteClick(wxCommandEvent
& )
2217 int index
= m_lbStrings
->GetSelection();
2220 ArrayRemoveAt( index
);
2221 m_lbStrings
->Delete ( index
);
2226 // -----------------------------------------------------------------------
2228 void wxArrayEditorDialog::OnUpClick(wxCommandEvent
& )
2230 int index
= m_lbStrings
->GetSelection();
2233 ArraySwap(index
-1,index
);
2234 /*wxString old_str = m_array[index-1];
2235 wxString new_str = m_array[index];
2236 m_array[index-1] = new_str;
2237 m_array[index] = old_str;*/
2238 m_lbStrings
->SetString ( index
-1, ArrayGet(index
-1) );
2239 m_lbStrings
->SetString ( index
, ArrayGet(index
) );
2240 m_lbStrings
->SetSelection ( index
-1 );
2245 // -----------------------------------------------------------------------
2247 void wxArrayEditorDialog::OnDownClick(wxCommandEvent
& )
2249 int index
= m_lbStrings
->GetSelection();
2250 int lastStringIndex
= ((int) m_lbStrings
->GetCount()) - 1;
2251 if ( index
>= 0 && index
< lastStringIndex
)
2253 ArraySwap(index
,index
+1);
2254 /*wxString old_str = m_array[index+1];
2255 wxString new_str = m_array[index];
2256 m_array[index+1] = new_str;
2257 m_array[index] = old_str;*/
2258 m_lbStrings
->SetString ( index
+1, ArrayGet(index
+1) );
2259 m_lbStrings
->SetString ( index
, ArrayGet(index
) );
2260 m_lbStrings
->SetSelection ( index
+1 );
2265 // -----------------------------------------------------------------------
2267 void wxArrayEditorDialog::OnUpdateClick(wxCommandEvent
& )
2269 int index
= m_lbStrings
->GetSelection();
2272 wxString str
= m_edValue
->GetValue();
2273 if ( ArraySet(index
,str
) )
2275 m_lbStrings
->SetString ( index
, str
);
2276 //m_array[index] = str;
2282 // -----------------------------------------------------------------------
2284 void wxArrayEditorDialog::OnListBoxClick(wxCommandEvent
& )
2286 int index
= m_lbStrings
->GetSelection();
2289 m_edValue
->SetValue( m_lbStrings
->GetString(index
) );
2293 // -----------------------------------------------------------------------
2294 // wxPGArrayStringEditorDialog
2295 // -----------------------------------------------------------------------
2297 IMPLEMENT_DYNAMIC_CLASS(wxPGArrayStringEditorDialog
, wxArrayEditorDialog
)
2299 BEGIN_EVENT_TABLE(wxPGArrayStringEditorDialog
, wxArrayEditorDialog
)
2300 EVT_BUTTON(28, wxPGArrayStringEditorDialog::OnCustomEditClick
)
2303 // -----------------------------------------------------------------------
2305 wxString
wxPGArrayStringEditorDialog::ArrayGet( size_t index
)
2307 return m_array
[index
];
2310 size_t wxPGArrayStringEditorDialog::ArrayGetCount()
2312 return m_array
.size();
2315 bool wxPGArrayStringEditorDialog::ArrayInsert( const wxString
& str
, int index
)
2320 m_array
.Insert(str
,index
);
2324 bool wxPGArrayStringEditorDialog::ArraySet( size_t index
, const wxString
& str
)
2326 m_array
[index
] = str
;
2330 void wxPGArrayStringEditorDialog::ArrayRemoveAt( int index
)
2332 m_array
.RemoveAt(index
);
2335 void wxPGArrayStringEditorDialog::ArraySwap( size_t first
, size_t second
)
2337 wxString old_str
= m_array
[first
];
2338 wxString new_str
= m_array
[second
];
2339 m_array
[first
] = new_str
;
2340 m_array
[second
] = old_str
;
2343 wxPGArrayStringEditorDialog::wxPGArrayStringEditorDialog()
2344 : wxArrayEditorDialog()
2349 void wxPGArrayStringEditorDialog::Init()
2351 m_pCallingClass
= (wxArrayStringProperty
*) NULL
;
2354 void wxPGArrayStringEditorDialog::OnCustomEditClick(wxCommandEvent
& )
2356 wxASSERT( m_pCallingClass
);
2357 wxString str
= m_edValue
->GetValue();
2358 if ( m_pCallingClass
->OnCustomStringEdit(m_parent
,str
) )
2360 //m_edValue->SetValue ( str );
2361 m_lbStrings
->Append ( str
);
2362 m_array
.Add ( str
);
2367 // -----------------------------------------------------------------------
2368 // wxArrayStringProperty
2369 // -----------------------------------------------------------------------
2371 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxArrayStringProperty
, // Property name
2372 wxPGProperty
, // Property we inherit from
2373 wxArrayString
, // Value type name
2374 const wxArrayString
&, // Value type, as given in constructor
2375 TextCtrlAndButton
) // Initial editor
2377 wxArrayStringProperty::wxArrayStringProperty( const wxString
& label
,
2378 const wxString
& name
,
2379 const wxArrayString
& array
)
2380 : wxPGProperty(label
,name
)
2385 wxArrayStringProperty::~wxArrayStringProperty() { }
2387 void wxArrayStringProperty::OnSetValue()
2389 GenerateValueAsString();
2392 wxString
wxArrayStringProperty::GetValueAsString( int WXUNUSED(argFlags
) ) const
2397 // Converts wxArrayString to a string separated by delimeters and spaces.
2398 // preDelim is useful for "str1" "str2" style. Set flags to 1 to do slash
2400 void wxPropertyGrid::ArrayStringToString( wxString
& dst
, const wxArrayString
& src
,
2401 wxChar preDelim
, wxChar postDelim
,
2407 unsigned int itemCount
= src
.size();
2415 else if ( (flags
& 1) )
2417 preas
[0] = preDelim
;
2424 dst
.append( preas
);
2426 wxASSERT( postDelim
);
2427 wxString
postDelimStr(postDelim
);
2428 //wxString preDelimStr(preDelim);
2430 for ( i
= 0; i
< itemCount
; i
++ )
2432 wxString
str( src
.Item(i
) );
2434 // Do some character conversion.
2435 // Convertes \ to \\ and <preDelim> to \<preDelim>
2436 // Useful when preDelim and postDelim are "\"".
2439 str
.Replace( wxS("\\"), wxS("\\\\"), true );
2441 str
.Replace( preas
, pdr
, true );
2446 if ( i
< (itemCount
-1) )
2448 dst
.append( postDelimStr
);
2449 dst
.append( wxS(" ") );
2450 dst
.append( preas
);
2452 else if ( preDelim
)
2453 dst
.append( postDelimStr
);
2457 #define ARRSTRPROP_ARRAY_TO_STRING(STRING,ARRAY) \
2458 wxPropertyGrid::ArrayStringToString(STRING,ARRAY,wxS('"'),wxS('"'),1);
2460 void wxArrayStringProperty::GenerateValueAsString()
2462 wxArrayString arr
= m_value
.GetArrayString();
2463 ARRSTRPROP_ARRAY_TO_STRING(m_display
, arr
)
2466 // Default implementation doesn't do anything.
2467 bool wxArrayStringProperty::OnCustomStringEdit( wxWindow
*, wxString
& )
2472 wxArrayEditorDialog
* wxArrayStringProperty::CreateEditorDialog()
2474 return new wxPGArrayStringEditorDialog();
2477 bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid
* propGrid
,
2478 wxWindow
* WXUNUSED(primaryCtrl
),
2482 PrepareValueForDialogEditing(propGrid
);
2484 if ( !propGrid
->EditorValidate() )
2487 // Create editor dialog.
2488 wxArrayEditorDialog
* dlg
= CreateEditorDialog();
2489 #if wxUSE_VALIDATORS
2490 wxValidator
* validator
= GetValidator();
2491 wxPGInDialogValidator dialogValidator
;
2494 wxPGArrayStringEditorDialog
* strEdDlg
= wxDynamicCast(dlg
, wxPGArrayStringEditorDialog
);
2497 strEdDlg
->SetCustomButton(cbt
, this);
2499 dlg
->SetDialogValue( wxVariant(m_value
) );
2500 dlg
->Create(propGrid
, wxEmptyString
, m_label
);
2502 #if !wxPG_SMALL_SCREEN
2503 dlg
->Move( propGrid
->GetGoodEditorDialogPosition(this,dlg
->GetSize()) );
2512 int res
= dlg
->ShowModal();
2514 if ( res
== wxID_OK
&& dlg
->IsModified() )
2516 wxVariant value
= dlg
->GetDialogValue();
2517 if ( !value
.IsNull() )
2519 wxArrayString actualValue
= value
.GetArrayString();
2521 ARRSTRPROP_ARRAY_TO_STRING(tempStr
, actualValue
)
2522 #if wxUSE_VALIDATORS
2523 if ( dialogValidator
.DoValidate( propGrid
, validator
, tempStr
) )
2526 SetValueInEvent( actualValue
);
2543 bool wxArrayStringProperty::OnEvent( wxPropertyGrid
* propGrid
,
2547 if ( propGrid
->IsMainButtonEvent(event
) )
2548 return OnButtonClick(propGrid
,primary
,(const wxChar
*) NULL
);
2552 bool wxArrayStringProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
2556 WX_PG_TOKENIZER2_BEGIN(text
,wxS('"'))
2558 // Need to replace backslashes with empty characters
2559 // (opposite what is done in GenerateValueString).
2560 token
.Replace ( wxS("\\"), wxEmptyString
, true );
2564 WX_PG_TOKENIZER2_END()
2571 // -----------------------------------------------------------------------
2572 // wxPGInDialogValidator
2573 // -----------------------------------------------------------------------
2575 #if wxUSE_VALIDATORS
2576 bool wxPGInDialogValidator::DoValidate( wxPropertyGrid
* propGrid
,
2577 wxValidator
* validator
,
2578 const wxString
& value
)
2583 wxTextCtrl
* tc
= m_textCtrl
;
2588 tc
= new wxTextCtrl( propGrid
, wxPG_SUBID_TEMP1
, wxEmptyString
,
2589 wxPoint(30000,30000));
2596 tc
->SetValue(value
);
2598 validator
->SetWindow(tc
);
2599 bool res
= validator
->Validate(propGrid
);
2604 bool wxPGInDialogValidator::DoValidate( wxPropertyGrid
* WXUNUSED(propGrid
),
2605 wxValidator
* WXUNUSED(validator
),
2606 const wxString
& WXUNUSED(value
) )
2612 // -----------------------------------------------------------------------
2614 #endif // wxUSE_PROPGRID