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"
52 #include "wx/filename.h"
54 #include "wx/propgrid/propgrid.h"
56 #define wxPG_CUSTOM_IMAGE_WIDTH 20 // for wxColourProperty etc.
59 // -----------------------------------------------------------------------
61 // -----------------------------------------------------------------------
63 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxStringProperty
,wxPGProperty
,
64 wxString
,const wxString
&,TextCtrl
)
66 wxStringProperty::wxStringProperty( const wxString
& label
,
68 const wxString
& value
)
69 : wxPGProperty(label
,name
)
74 void wxStringProperty::OnSetValue()
76 if ( !m_value
.IsNull() && m_value
.GetString() == wxS("<composed>") )
77 SetFlag(wxPG_PROP_COMPOSED_VALUE
);
79 if ( HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
82 DoGenerateComposedValue(s
);
87 wxStringProperty::~wxStringProperty() { }
89 wxString
wxStringProperty::ValueToString( wxVariant
& value
,
92 wxString s
= value
.GetString();
94 if ( GetChildCount() && HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
96 // Value stored in m_value is non-editable, non-full value
97 if ( (argFlags
& wxPG_FULL_VALUE
) || (argFlags
& wxPG_EDITABLE_VALUE
) )
99 // Calling this under incorrect conditions will fail
100 wxASSERT_MSG( argFlags
& wxPG_VALUE_IS_CURRENT
,
101 "Sorry, currently default wxPGProperty::ValueToString() "
102 "implementation only works if value is m_value." );
104 DoGenerateComposedValue(s
, argFlags
);
110 // If string is password and value is for visual purposes,
111 // then return asterisks instead the actual string.
112 if ( (m_flags
& wxPG_PROP_PASSWORD
) && !(argFlags
& (wxPG_FULL_VALUE
|wxPG_EDITABLE_VALUE
)) )
113 return wxString(wxChar('*'), s
.Length());
118 bool wxStringProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
120 if ( GetChildCount() && HasFlag(wxPG_PROP_COMPOSED_VALUE
) )
121 return wxPGProperty::StringToValue(variant
, text
, argFlags
);
123 if ( variant
!= text
)
132 bool wxStringProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
134 if ( name
== wxPG_STRING_PASSWORD
)
136 m_flags
&= ~(wxPG_PROP_PASSWORD
);
137 if ( wxPGVariantToInt(value
) ) m_flags
|= wxPG_PROP_PASSWORD
;
144 // -----------------------------------------------------------------------
146 // -----------------------------------------------------------------------
148 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxIntProperty
,wxPGProperty
,
151 wxIntProperty::wxIntProperty( const wxString
& label
, const wxString
& name
,
152 long value
) : wxPGProperty(label
,name
)
157 wxIntProperty::wxIntProperty( const wxString
& label
, const wxString
& name
,
158 const wxLongLong
& value
) : wxPGProperty(label
,name
)
160 SetValue(WXVARIANT(value
));
163 wxIntProperty::~wxIntProperty() { }
165 wxString
wxIntProperty::ValueToString( wxVariant
& value
,
166 int WXUNUSED(argFlags
) ) const
168 if ( value
.GetType() == wxPG_VARIANT_TYPE_LONG
)
170 return wxString::Format(wxS("%li"),value
.GetLong());
172 else if ( value
.GetType() == wxLongLong_VariantType
)
176 return ll
.ToString();
179 return wxEmptyString
;
182 bool wxIntProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
187 if ( text
.length() == 0 )
193 // We know it is a number, but let's still check
195 if ( text
.IsNumber() )
197 // Remove leading zeroes, so that the number is not interpreted as octal
198 wxString::const_iterator i
= text
.begin();
199 wxString::const_iterator iMax
= text
.end() - 1; // Let's allow one, last zero though
201 int firstNonZeroPos
= 0;
203 for ( ; i
!= iMax
; ++i
)
206 if ( c
!= wxS('0') && c
!= wxS(' ') )
211 wxString useText
= text
.substr(firstNonZeroPos
, text
.length() - firstNonZeroPos
);
213 wxString variantType
= variant
.GetType();
214 bool isPrevLong
= variantType
== wxPG_VARIANT_TYPE_LONG
;
216 wxLongLong_t value64
= 0;
218 if ( useText
.ToLongLong(&value64
, 10) &&
219 ( value64
>= INT_MAX
|| value64
<= INT_MIN
)
222 bool doChangeValue
= isPrevLong
;
224 if ( !isPrevLong
&& variantType
== wxLongLong_VariantType
)
228 if ( oldValue
.GetValue() != value64
)
229 doChangeValue
= true;
234 wxLongLong
ll(value64
);
240 if ( useText
.ToLong( &value32
, 0 ) )
242 if ( !isPrevLong
|| variant
!= value32
)
249 else if ( argFlags
& wxPG_REPORT_ERROR
)
255 bool wxIntProperty::IntToValue( wxVariant
& variant
, int value
, int WXUNUSED(argFlags
) ) const
257 if ( variant
.GetType() != wxPG_VARIANT_TYPE_LONG
|| variant
!= (long)value
)
259 variant
= (long)value
;
265 bool wxIntProperty::DoValidation( const wxPGProperty
* property
, wxLongLong_t
& value
, wxPGValidationInfo
* pValidationInfo
, int mode
)
268 wxLongLong_t min
= wxINT64_MIN
;
269 wxLongLong_t max
= wxINT64_MAX
;
274 variant
= property
->GetAttribute(wxPGGlobalVars
->m_strMin
);
275 if ( !variant
.IsNull() )
277 wxPGVariantToLongLong(variant
, &min
);
281 variant
= property
->GetAttribute(wxPGGlobalVars
->m_strMax
);
282 if ( !variant
.IsNull() )
284 wxPGVariantToLongLong(variant
, &max
);
292 if ( mode
== wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
)
293 pValidationInfo
->SetFailureMessage(
294 wxString::Format(_("Value must be %lld or higher"),min
)
296 else if ( mode
== wxPG_PROPERTY_VALIDATION_SATURATE
)
299 value
= max
- (min
- value
);
308 if ( mode
== wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
)
309 pValidationInfo
->SetFailureMessage(
310 wxString::Format(_("Value must be %lld or higher"),min
)
312 else if ( mode
== wxPG_PROPERTY_VALIDATION_SATURATE
)
315 value
= min
+ (value
- max
);
322 bool wxIntProperty::ValidateValue( wxVariant
& value
, wxPGValidationInfo
& validationInfo
) const
325 if ( wxPGVariantToLongLong(value
, &ll
) )
326 return DoValidation(this, ll
, &validationInfo
, wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
330 wxValidator
* wxIntProperty::GetClassValidator()
333 WX_PG_DOGETVALIDATOR_ENTRY()
335 // Atleast wxPython 2.6.2.1 required that the string argument is given
337 wxTextValidator
* validator
= new wxTextValidator(wxFILTER_NUMERIC
,&v
);
339 WX_PG_DOGETVALIDATOR_EXIT(validator
)
345 wxValidator
* wxIntProperty::DoGetValidator() const
347 return GetClassValidator();
350 // -----------------------------------------------------------------------
352 // -----------------------------------------------------------------------
355 #define wxPG_UINT_TEMPLATE_MAX 8
357 static const wxChar
* gs_uintTemplates32
[wxPG_UINT_TEMPLATE_MAX
] = {
358 wxT("%x"),wxT("0x%x"),wxT("$%x"),
359 wxT("%X"),wxT("0x%X"),wxT("$%X"),
363 static const wxChar
* gs_uintTemplates64
[wxPG_UINT_TEMPLATE_MAX
] = {
364 wxT("%") wxLongLongFmtSpec
wxT("x"),
365 wxT("0x%") wxLongLongFmtSpec
wxT("x"),
366 wxT("$%") wxLongLongFmtSpec
wxT("x"),
367 wxT("%") wxLongLongFmtSpec
wxT("X"),
368 wxT("0x%") wxLongLongFmtSpec
wxT("X"),
369 wxT("$%") wxLongLongFmtSpec
wxT("X"),
370 wxT("%") wxLongLongFmtSpec
wxT("u"),
371 wxT("%") wxLongLongFmtSpec
wxT("o")
374 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxUIntProperty
,wxPGProperty
,
375 long,unsigned long,TextCtrl
)
377 void wxUIntProperty::Init()
379 m_base
= 6; // This is magic number for dec base (must be same as in setattribute)
381 m_prefix
= wxPG_PREFIX_NONE
;
384 wxUIntProperty::wxUIntProperty( const wxString
& label
, const wxString
& name
,
385 unsigned long value
) : wxPGProperty(label
,name
)
388 SetValue((long)value
);
391 wxUIntProperty::wxUIntProperty( const wxString
& label
, const wxString
& name
,
392 const wxULongLong
& value
) : wxPGProperty(label
,name
)
395 SetValue(WXVARIANT(value
));
398 wxUIntProperty::~wxUIntProperty() { }
400 wxString
wxUIntProperty::ValueToString( wxVariant
& value
,
401 int WXUNUSED(argFlags
) ) const
403 size_t index
= m_base
+ m_prefix
;
404 if ( index
>= wxPG_UINT_TEMPLATE_MAX
)
405 index
= wxPG_BASE_DEC
;
407 if ( value
.GetType() == wxPG_VARIANT_TYPE_LONG
)
409 return wxString::Format(gs_uintTemplates32
[index
], (unsigned long)value
.GetLong());
415 return wxString::Format(gs_uintTemplates64
[index
], ull
.GetValue());
418 bool wxUIntProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int WXUNUSED(argFlags
) ) const
420 wxString variantType
= variant
.GetType();
421 bool isPrevLong
= variantType
== wxPG_VARIANT_TYPE_LONG
;
423 if ( text
.length() == 0 )
430 if ( text
[0] == wxS('$') )
433 wxULongLong_t value64
= 0;
434 wxString s
= text
.substr(start
, text
.length() - start
);
436 if ( s
.ToULongLong(&value64
, (unsigned int)m_realBase
) )
438 if ( value64
>= LONG_MAX
)
440 bool doChangeValue
= isPrevLong
;
442 if ( !isPrevLong
&& variantType
== wxULongLong_VariantType
)
444 wxULongLong oldValue
;
446 if ( oldValue
.GetValue() != value64
)
447 doChangeValue
= true;
452 wxULongLong
ull(value64
);
459 unsigned long value32
= wxLongLong(value64
).GetLo();
460 if ( !isPrevLong
|| m_value
!= (long)value32
)
462 variant
= (long)value32
;
471 bool wxUIntProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
473 if ( variant
!= (long)number
)
475 variant
= (long)number
;
481 bool wxUIntProperty::ValidateValue( wxVariant
& value
, wxPGValidationInfo
& validationInfo
) const
485 if ( wxPGVariantToULongLong(value
, &ll
) )
487 wxULongLong_t min
= 0;
488 wxULongLong_t max
= wxUINT64_MAX
;
491 variant
= GetAttribute(wxPGGlobalVars
->m_strMin
);
492 if ( !variant
.IsNull() )
494 wxPGVariantToULongLong(variant
, &min
);
497 validationInfo
.SetFailureMessage(
498 wxString::Format(_("Value must be %llu or higher"),min
)
503 variant
= GetAttribute(wxPGGlobalVars
->m_strMax
);
504 if ( !variant
.IsNull() )
506 wxPGVariantToULongLong(variant
, &max
);
509 validationInfo
.SetFailureMessage(
510 wxString::Format(_("Value must be %llu or less"),max
)
519 bool wxUIntProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
521 if ( name
== wxPG_UINT_BASE
)
523 int val
= value
.GetLong();
525 m_realBase
= (wxByte
) val
;
526 if ( m_realBase
> 16 )
530 // Translate logical base to a template array index
532 if ( val
== wxPG_BASE_HEX
)
534 else if ( val
== wxPG_BASE_DEC
)
536 else if ( val
== wxPG_BASE_HEXL
)
540 else if ( name
== wxPG_UINT_PREFIX
)
542 m_prefix
= (wxByte
) value
.GetLong();
548 // -----------------------------------------------------------------------
550 // -----------------------------------------------------------------------
552 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFloatProperty
,wxPGProperty
,
553 double,double,TextCtrl
)
555 wxFloatProperty::wxFloatProperty( const wxString
& label
,
556 const wxString
& name
,
558 : wxPGProperty(label
,name
)
564 wxFloatProperty::~wxFloatProperty() { }
566 // This helper method provides standard way for floating point-using
567 // properties to convert values to string.
568 void wxPropertyGrid::DoubleToString(wxString
& target
,
572 wxString
* precTemplate
)
574 if ( precision
>= 0 )
578 precTemplate
= &text1
;
580 if ( !precTemplate
->length() )
582 *precTemplate
= wxS("%.");
583 *precTemplate
<< wxString::Format( wxS("%i"), precision
);
584 *precTemplate
<< wxS('f');
587 target
.Printf( precTemplate
->c_str(), value
);
591 target
.Printf( wxS("%f"), value
);
594 if ( removeZeroes
&& precision
!= 0 && target
.length() )
596 // Remove excess zeroes (do not remove this code just yet,
597 // since sprintf can't do the same consistently across platforms).
598 wxString::const_iterator i
= target
.end() - 1;
599 size_t new_len
= target
.length() - 1;
601 for ( ; i
!= target
.begin(); --i
)
603 if ( *i
!= wxS('0') )
608 wxChar cur_char
= *i
;
609 if ( cur_char
!= wxS('.') && cur_char
!= wxS(',') )
612 if ( new_len
!= target
.length() )
613 target
.resize(new_len
);
617 wxString
wxFloatProperty::ValueToString( wxVariant
& value
,
621 if ( !value
.IsNull() )
623 wxPropertyGrid::DoubleToString(text
,
626 !(argFlags
& wxPG_FULL_VALUE
),
632 bool wxFloatProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
637 if ( text
.length() == 0 )
643 bool res
= text
.ToDouble(&value
);
646 if ( variant
!= value
)
652 else if ( argFlags
& wxPG_REPORT_ERROR
)
658 bool wxFloatProperty::DoValidation( const wxPGProperty
* property
, double& value
, wxPGValidationInfo
* pValidationInfo
, int mode
)
661 double min
= (double)wxINT64_MIN
;
662 double max
= (double)wxINT64_MAX
;
667 variant
= property
->GetAttribute(wxPGGlobalVars
->m_strMin
);
668 if ( !variant
.IsNull() )
670 wxPGVariantToDouble(variant
, &min
);
674 variant
= property
->GetAttribute(wxPGGlobalVars
->m_strMax
);
675 if ( !variant
.IsNull() )
677 wxPGVariantToDouble(variant
, &max
);
685 if ( mode
== wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
)
686 pValidationInfo
->SetFailureMessage(
687 wxString::Format(_("Value must be %f or higher"),min
)
689 else if ( mode
== wxPG_PROPERTY_VALIDATION_SATURATE
)
692 value
= max
- (min
- value
);
699 wxPGVariantToDouble(variant
, &max
);
702 if ( mode
== wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
)
703 pValidationInfo
->SetFailureMessage(
704 wxString::Format(_("Value must be %f or less"),max
)
706 else if ( mode
== wxPG_PROPERTY_VALIDATION_SATURATE
)
709 value
= min
+ (value
- max
);
716 bool wxFloatProperty::ValidateValue( wxVariant
& value
, wxPGValidationInfo
& validationInfo
) const
719 if ( wxPGVariantToDouble(value
, &fpv
) )
720 return DoValidation(this, fpv
, &validationInfo
, wxPG_PROPERTY_VALIDATION_ERROR_MESSAGE
);
724 bool wxFloatProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
726 if ( name
== wxPG_FLOAT_PRECISION
)
728 m_precision
= value
.GetLong();
734 wxValidator
* wxFloatProperty::DoGetValidator() const
736 return wxIntProperty::GetClassValidator();
739 // -----------------------------------------------------------------------
741 // -----------------------------------------------------------------------
743 // We cannot use standard WX_PG_IMPLEMENT_PROPERTY_CLASS macro, since
744 // there is a custom GetEditorClass.
746 IMPLEMENT_DYNAMIC_CLASS(wxBoolProperty
, wxPGProperty
)
748 const wxPGEditor
* wxBoolProperty::DoGetEditorClass() const
750 // Select correct editor control.
751 #if wxPG_INCLUDE_CHECKBOX
752 if ( !(m_flags
& wxPG_PROP_USE_CHECKBOX
) )
753 return wxPGEditor_Choice
;
754 return wxPGEditor_CheckBox
;
756 return wxPGEditor_Choice
;
760 wxBoolProperty::wxBoolProperty( const wxString
& label
, const wxString
& name
, bool value
) :
761 wxPGProperty(label
,name
)
763 m_choices
.Assign(wxPGGlobalVars
->m_boolChoices
);
765 SetValue(wxPGVariant_Bool(value
));
767 m_flags
|= wxPG_PROP_USE_DCC
;
770 wxBoolProperty::~wxBoolProperty() { }
772 wxString
wxBoolProperty::ValueToString( wxVariant
& value
,
775 bool boolValue
= value
.GetBool();
777 // As a fragment of composite string value,
778 // make it a little more readable.
779 if ( argFlags
& wxPG_COMPOSITE_FRAGMENT
)
787 if ( argFlags
& wxPG_UNEDITABLE_COMPOSITE_FRAGMENT
)
788 return wxEmptyString
;
791 if ( wxPGGlobalVars
->m_autoGetTranslation
)
792 notFmt
= _("Not %s");
794 notFmt
= wxS("Not %s");
796 return wxString::Format(notFmt
.c_str(), m_label
.c_str());
800 if ( !(argFlags
& wxPG_FULL_VALUE
) )
802 return wxPGGlobalVars
->m_boolChoices
[boolValue
?1:0].GetText();
807 if ( boolValue
) text
= wxS("true");
808 else text
= wxS("false");
813 bool wxBoolProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int WXUNUSED(argFlags
) ) const
815 bool boolValue
= false;
816 if ( text
.CmpNoCase(wxPGGlobalVars
->m_boolChoices
[1].GetText()) == 0 ||
817 text
.CmpNoCase(wxS("true")) == 0 ||
818 text
.CmpNoCase(m_label
) == 0 )
821 if ( text
.length() == 0 )
827 if ( variant
!= boolValue
)
829 variant
= wxPGVariant_Bool(boolValue
);
835 bool wxBoolProperty::IntToValue( wxVariant
& variant
, int value
, int ) const
837 bool boolValue
= value
? true : false;
839 if ( variant
!= boolValue
)
841 variant
= wxPGVariant_Bool(boolValue
);
847 bool wxBoolProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
849 #if wxPG_INCLUDE_CHECKBOX
850 if ( name
== wxPG_BOOL_USE_CHECKBOX
)
852 int ival
= wxPGVariantToInt(value
);
854 m_flags
|= wxPG_PROP_USE_CHECKBOX
;
856 m_flags
&= ~(wxPG_PROP_USE_CHECKBOX
);
860 if ( name
== wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING
)
862 int ival
= wxPGVariantToInt(value
);
864 m_flags
|= wxPG_PROP_USE_DCC
;
866 m_flags
&= ~(wxPG_PROP_USE_DCC
);
872 // -----------------------------------------------------------------------
874 // -----------------------------------------------------------------------
876 IMPLEMENT_DYNAMIC_CLASS(wxEnumProperty
, wxPGProperty
)
878 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxEnumProperty
,long,Choice
)
880 wxEnumProperty::wxEnumProperty( const wxString
& label
, const wxString
& name
, const wxChar
** labels
,
881 const long* values
, int value
) : wxPGProperty(label
,name
)
887 m_choices
.Add(labels
,values
);
889 if ( GetItemCount() )
890 SetValue( (long)value
);
894 wxEnumProperty::wxEnumProperty( const wxString
& label
, const wxString
& name
, const wxChar
** labels
,
895 const long* values
, wxPGChoices
* choicesCache
, int value
)
896 : wxPGProperty(label
,name
)
900 wxASSERT( choicesCache
);
902 if ( choicesCache
->IsOk() )
904 m_choices
.Assign( *choicesCache
);
905 m_value
= wxPGVariant_Zero
;
909 m_choices
.Add(labels
,values
);
911 if ( GetItemCount() )
912 SetValue( (long)value
);
916 wxEnumProperty::wxEnumProperty( const wxString
& label
, const wxString
& name
,
917 const wxArrayString
& labels
, const wxArrayInt
& values
, int value
)
918 : wxPGProperty(label
,name
)
922 if ( &labels
&& labels
.size() )
924 m_choices
.Set(labels
, values
);
926 if ( GetItemCount() )
927 SetValue( (long)value
);
931 wxEnumProperty::wxEnumProperty( const wxString
& label
, const wxString
& name
,
932 wxPGChoices
& choices
, int value
)
933 : wxPGProperty(label
,name
)
935 m_choices
.Assign( choices
);
937 if ( GetItemCount() )
938 SetValue( (long)value
);
941 int wxEnumProperty::GetIndexForValue( int value
) const
943 if ( !m_choices
.IsOk() )
946 int intVal
= m_choices
.Index(value
);
953 wxEnumProperty::~wxEnumProperty ()
957 int wxEnumProperty::ms_nextIndex
= -2;
959 void wxEnumProperty::OnSetValue()
961 wxString variantType
= m_value
.GetType();
963 if ( variantType
== wxPG_VARIANT_TYPE_LONG
)
964 ValueFromInt_( m_value
, m_value
.GetLong(), wxPG_FULL_VALUE
);
965 else if ( variantType
== wxPG_VARIANT_TYPE_STRING
)
966 ValueFromString_( m_value
, m_value
.GetString(), 0 );
970 if ( ms_nextIndex
!= -2 )
972 m_index
= ms_nextIndex
;
977 bool wxEnumProperty::ValidateValue( wxVariant
& value
, wxPGValidationInfo
& WXUNUSED(validationInfo
) ) const
979 // Make sure string value is in the list,
980 // unless property has string as preferred value type
981 // To reduce code size, use conversion here as well
982 if ( value
.GetType() == wxPG_VARIANT_TYPE_STRING
&&
983 !this->IsKindOf(CLASSINFO(wxEditEnumProperty
)) )
984 return ValueFromString_( value
, value
.GetString(), wxPG_PROPERTY_SPECIFIC
);
989 wxString
wxEnumProperty::ValueToString( wxVariant
& value
,
990 int WXUNUSED(argFlags
) ) const
992 if ( value
.GetType() == wxPG_VARIANT_TYPE_STRING
)
993 return value
.GetString();
995 int index
= m_choices
.Index(value
.GetLong());
997 return wxEmptyString
;
999 return m_choices
.GetLabel(index
);
1002 bool wxEnumProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
1004 return ValueFromString_( variant
, text
, argFlags
);
1007 bool wxEnumProperty::IntToValue( wxVariant
& variant
, int intVal
, int argFlags
) const
1009 return ValueFromInt_( variant
, intVal
, argFlags
);
1012 bool wxEnumProperty::ValueFromString_( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1017 for ( unsigned int i
=0; i
<m_choices
.GetCount(); i
++ )
1019 const wxString
& entryLabel
= m_choices
.GetLabel(i
);
1020 if ( text
.CmpNoCase(entryLabel
) == 0 )
1023 useValue
= m_choices
.GetValue(i
);
1028 bool asText
= false;
1030 bool isEdit
= this->IsKindOf(CLASSINFO(wxEditEnumProperty
));
1032 // If text not any of the choices, store as text instead
1033 // (but only if we are wxEditEnumProperty)
1034 if ( useIndex
== -1 &&
1035 (value
.GetType() != wxPG_VARIANT_TYPE_STRING
|| (m_value
.GetString() != text
)) &&
1041 int setAsNextIndex
= -2;
1045 setAsNextIndex
= -1;
1048 else if ( useIndex
!= GetIndex() )
1050 if ( useIndex
!= -1 )
1052 setAsNextIndex
= useIndex
;
1053 value
= (long)useValue
;
1057 setAsNextIndex
= -1;
1058 value
= wxPGVariant_MinusOne
;
1062 if ( setAsNextIndex
!= -2 )
1064 // If wxPG_PROPERTY_SPECIFIC is set, then this is done for
1065 // validation purposes only, and index must not be changed
1066 if ( !(argFlags
& wxPG_PROPERTY_SPECIFIC
) )
1067 ms_nextIndex
= setAsNextIndex
;
1069 if ( isEdit
|| setAsNextIndex
!= -1 )
1077 bool wxEnumProperty::ValueFromInt_( wxVariant
& variant
, int intVal
, int argFlags
) const
1079 // If wxPG_FULL_VALUE is *not* in argFlags, then intVal is index from combo box.
1083 if ( argFlags
& wxPG_FULL_VALUE
)
1085 ms_nextIndex
= GetIndexForValue( intVal
);
1089 if ( intVal
!= GetIndex() )
1091 ms_nextIndex
= intVal
;
1095 if ( ms_nextIndex
!= -2 )
1097 if ( !(argFlags
& wxPG_FULL_VALUE
) )
1098 intVal
= m_choices
.GetValue(intVal
);
1100 variant
= (long)intVal
;
1109 wxEnumProperty::OnValidationFailure( wxVariant
& WXUNUSED(pendingValue
) )
1115 void wxEnumProperty::SetIndex( int index
)
1121 int wxEnumProperty::GetIndex() const
1123 if ( m_value
.IsNull() )
1126 if ( ms_nextIndex
!= -2 )
1127 return ms_nextIndex
;
1132 // -----------------------------------------------------------------------
1133 // wxEditEnumProperty
1134 // -----------------------------------------------------------------------
1136 IMPLEMENT_DYNAMIC_CLASS(wxEditEnumProperty
, wxPGProperty
)
1138 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxEditEnumProperty
,wxString
,ComboBox
)
1140 wxEditEnumProperty::wxEditEnumProperty( const wxString
& label
, const wxString
& name
, const wxChar
** labels
,
1141 const long* values
, const wxString
& value
)
1142 : wxEnumProperty(label
,name
,labels
,values
,0)
1147 wxEditEnumProperty::wxEditEnumProperty( const wxString
& label
, const wxString
& name
, const wxChar
** labels
,
1148 const long* values
, wxPGChoices
* choicesCache
, const wxString
& value
)
1149 : wxEnumProperty(label
,name
,labels
,values
,choicesCache
,0)
1154 wxEditEnumProperty::wxEditEnumProperty( const wxString
& label
, const wxString
& name
,
1155 const wxArrayString
& labels
, const wxArrayInt
& values
, const wxString
& value
)
1156 : wxEnumProperty(label
,name
,labels
,values
,0)
1161 wxEditEnumProperty::wxEditEnumProperty( const wxString
& label
, const wxString
& name
,
1162 wxPGChoices
& choices
, const wxString
& value
)
1163 : wxEnumProperty(label
,name
,choices
,0)
1168 wxEditEnumProperty::~wxEditEnumProperty()
1172 // -----------------------------------------------------------------------
1174 // -----------------------------------------------------------------------
1176 IMPLEMENT_DYNAMIC_CLASS(wxFlagsProperty
,wxPGProperty
)
1178 WX_PG_IMPLEMENT_PROPERTY_CLASS_PLAIN(wxFlagsProperty
,long,TextCtrl
)
1180 void wxFlagsProperty::Init()
1182 long value
= m_value
;
1185 // Generate children
1189 unsigned int prevChildCount
= m_children
.size();
1192 if ( prevChildCount
)
1194 wxPropertyGridPageState
* state
= GetParentState();
1196 // State safety check (it may be NULL in immediate parent)
1201 wxPGProperty
* selected
= state
->GetSelection();
1204 if ( selected
->GetParent() == this )
1205 oldSel
= selected
->GetIndexInParent();
1206 else if ( selected
== this )
1210 state
->DoClearSelection();
1213 // Delete old children
1214 for ( i
=0; i
<prevChildCount
; i
++ )
1215 delete m_children
[i
];
1219 // Relay wxPG_BOOL_USE_CHECKBOX and wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING
1220 // to child bool property controls.
1221 long attrUseCheckBox
= GetAttributeAsLong(wxPG_BOOL_USE_CHECKBOX
, 0);
1222 long attrUseDCC
= GetAttributeAsLong(wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING
,
1225 if ( m_choices
.IsOk() )
1227 const wxPGChoices
& choices
= m_choices
;
1229 for ( i
=0; i
<GetItemCount(); i
++ )
1232 child_val
= ( value
& choices
.GetValue(i
) )?true:false;
1234 wxPGProperty
* boolProp
;
1235 wxString label
= GetLabel(i
);
1238 if ( wxPGGlobalVars
->m_autoGetTranslation
)
1240 boolProp
= new wxBoolProperty( ::wxGetTranslation(label
), label
, child_val
);
1245 boolProp
= new wxBoolProperty( label
, label
, child_val
);
1247 if ( attrUseCheckBox
)
1248 boolProp
->SetAttribute(wxPG_BOOL_USE_CHECKBOX
,
1251 boolProp
->SetAttribute(wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING
,
1253 AddPrivateChild(boolProp
);
1256 m_oldChoicesData
= m_choices
.GetDataPtr();
1259 m_oldValue
= m_value
;
1261 if ( prevChildCount
)
1262 SubPropsChanged(oldSel
);
1265 wxFlagsProperty::wxFlagsProperty( const wxString
& label
, const wxString
& name
,
1266 const wxChar
** labels
, const long* values
, long value
) : wxPGProperty(label
,name
)
1268 m_oldChoicesData
= NULL
;
1272 m_choices
.Set(labels
,values
);
1274 wxASSERT( GetItemCount() );
1280 m_value
= wxPGVariant_Zero
;
1284 wxFlagsProperty::wxFlagsProperty( const wxString
& label
, const wxString
& name
,
1285 const wxArrayString
& labels
, const wxArrayInt
& values
, int value
)
1286 : wxPGProperty(label
,name
)
1288 m_oldChoicesData
= NULL
;
1290 if ( &labels
&& labels
.size() )
1292 m_choices
.Set(labels
,values
);
1294 wxASSERT( GetItemCount() );
1296 SetValue( (long)value
);
1300 m_value
= wxPGVariant_Zero
;
1304 wxFlagsProperty::wxFlagsProperty( const wxString
& label
, const wxString
& name
,
1305 wxPGChoices
& choices
, long value
)
1306 : wxPGProperty(label
,name
)
1308 m_oldChoicesData
= NULL
;
1310 if ( choices
.IsOk() )
1312 m_choices
.Assign(choices
);
1314 wxASSERT( GetItemCount() );
1320 m_value
= wxPGVariant_Zero
;
1324 wxFlagsProperty::~wxFlagsProperty()
1328 void wxFlagsProperty::OnSetValue()
1330 if ( !m_choices
.IsOk() || !GetItemCount() )
1332 m_value
= wxPGVariant_Zero
;
1336 long val
= m_value
.GetLong();
1340 // normalize the value (i.e. remove extra flags)
1342 const wxPGChoices
& choices
= m_choices
;
1343 for ( i
= 0; i
< GetItemCount(); i
++ )
1345 fullFlags
|= choices
.GetValue(i
);
1352 // Need to (re)init now?
1353 if ( GetChildCount() != GetItemCount() ||
1354 m_choices
.GetDataPtr() != m_oldChoicesData
)
1360 long newFlags
= m_value
;
1362 if ( newFlags
!= m_oldValue
)
1364 // Set child modified states
1366 const wxPGChoices
& choices
= m_choices
;
1367 for ( i
= 0; i
<GetItemCount(); i
++ )
1371 flag
= choices
.GetValue(i
);
1373 if ( (newFlags
& flag
) != (m_oldValue
& flag
) )
1374 Item(i
)->SetFlag( wxPG_PROP_MODIFIED
);
1377 m_oldValue
= newFlags
;
1381 wxString
wxFlagsProperty::ValueToString( wxVariant
& value
,
1382 int WXUNUSED(argFlags
) ) const
1386 if ( !m_choices
.IsOk() )
1391 const wxPGChoices
& choices
= m_choices
;
1393 for ( i
= 0; i
< GetItemCount(); i
++ )
1396 doAdd
= ( flags
& choices
.GetValue(i
) );
1400 text
+= choices
.GetLabel(i
);
1405 // remove last comma
1406 if ( text
.Len() > 1 )
1407 text
.Truncate ( text
.Len() - 2 );
1412 // Translate string into flag tokens
1413 bool wxFlagsProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1415 if ( !m_choices
.IsOk() )
1420 // semicolons are no longer valid delimeters
1421 WX_PG_TOKENIZER1_BEGIN(text
,wxS(','))
1423 if ( token
.length() )
1425 // Determine which one it is
1426 long bit
= IdToBit( token
);
1439 WX_PG_TOKENIZER1_END()
1441 if ( variant
!= (long)newFlags
)
1443 variant
= (long)newFlags
;
1450 // Converts string id to a relevant bit.
1451 long wxFlagsProperty::IdToBit( const wxString
& id
) const
1454 for ( i
= 0; i
< GetItemCount(); i
++ )
1456 if ( id
== GetLabel(i
) )
1458 return m_choices
.GetValue(i
);
1464 void wxFlagsProperty::RefreshChildren()
1466 if ( !m_choices
.IsOk() || !GetChildCount() ) return;
1468 int flags
= m_value
.GetLong();
1470 const wxPGChoices
& choices
= m_choices
;
1472 for ( i
= 0; i
< GetItemCount(); i
++ )
1476 flag
= choices
.GetValue(i
);
1478 long subVal
= flags
& flag
;
1479 wxPGProperty
* p
= Item(i
);
1481 if ( subVal
!= (m_oldValue
& flag
) )
1482 p
->SetFlag( wxPG_PROP_MODIFIED
);
1484 p
->SetValue( subVal
?true:false );
1490 wxVariant
wxFlagsProperty::ChildChanged( wxVariant
& thisValue
,
1492 wxVariant
& childValue
) const
1494 long oldValue
= thisValue
.GetLong();
1495 long val
= childValue
.GetLong();
1496 unsigned long vi
= m_choices
.GetValue(childIndex
);
1499 return (long) (oldValue
| vi
);
1501 return (long) (oldValue
& ~(vi
));
1504 bool wxFlagsProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1506 if ( name
== wxPG_BOOL_USE_CHECKBOX
||
1507 name
== wxPG_BOOL_USE_DOUBLE_CLICK_CYCLING
)
1509 for ( size_t i
=0; i
<GetChildCount(); i
++ )
1511 Item(i
)->SetAttribute(name
, value
);
1513 // Must return false so that the attribute is stored in
1514 // flag property's actual property storage
1520 // -----------------------------------------------------------------------
1522 // -----------------------------------------------------------------------
1524 IMPLEMENT_DYNAMIC_CLASS(wxDirProperty
, wxLongStringProperty
)
1526 wxDirProperty::wxDirProperty( const wxString
& name
, const wxString
& label
, const wxString
& value
)
1527 : wxLongStringProperty(name
,label
,value
)
1529 m_flags
|= wxPG_PROP_NO_ESCAPE
;
1532 wxDirProperty::~wxDirProperty() { }
1534 wxValidator
* wxDirProperty::DoGetValidator() const
1536 return wxFileProperty::GetClassValidator();
1539 bool wxDirProperty::OnButtonClick( wxPropertyGrid
* propGrid
, wxString
& value
)
1541 // Update property value from editor, if necessary
1542 wxSize
dlg_sz(300,400);
1544 wxString
dlgMessage(m_dlgMessage
);
1545 if ( dlgMessage
.empty() )
1546 dlgMessage
= _("Choose a directory:");
1547 wxDirDialog
dlg( propGrid
,
1551 #if !wxPG_SMALL_SCREEN
1552 propGrid
->GetGoodEditorDialogPosition(this,dlg_sz
),
1560 if ( dlg
.ShowModal() == wxID_OK
)
1562 value
= dlg
.GetPath();
1568 bool wxDirProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1570 if ( name
== wxPG_DIR_DIALOG_MESSAGE
)
1572 m_dlgMessage
= value
.GetString();
1578 // -----------------------------------------------------------------------
1579 // wxPGFileDialogAdapter
1580 // -----------------------------------------------------------------------
1582 bool wxPGFileDialogAdapter::DoShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
1584 wxFileProperty
* fileProp
= NULL
;
1588 if ( property
->IsKindOf(CLASSINFO(wxFileProperty
)) )
1590 fileProp
= ((wxFileProperty
*)property
);
1591 wxFileName filename
= fileProp
->GetValue().GetString();
1592 path
= filename
.GetPath();
1593 indFilter
= fileProp
->m_indFilter
;
1595 if ( !path
.length() && fileProp
->m_basePath
.length() )
1596 path
= fileProp
->m_basePath
;
1600 wxFileName
fn(property
->GetValue().GetString());
1601 path
= fn
.GetPath();
1604 wxFileDialog
dlg( propGrid
->GetPanel(),
1605 property
->GetAttribute(wxS("DialogTitle"), _("Choose a file")),
1606 property
->GetAttribute(wxS("InitialPath"), path
),
1608 property
->GetAttribute(wxPG_FILE_WILDCARD
, _("All files (*.*)|*.*")),
1610 wxDefaultPosition
);
1612 if ( indFilter
>= 0 )
1613 dlg
.SetFilterIndex( indFilter
);
1615 if ( dlg
.ShowModal() == wxID_OK
)
1618 fileProp
->m_indFilter
= dlg
.GetFilterIndex();
1619 SetValue( dlg
.GetPath() );
1625 // -----------------------------------------------------------------------
1627 // -----------------------------------------------------------------------
1629 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFileProperty
,wxPGProperty
,
1630 wxString
,const wxString
&,TextCtrlAndButton
)
1632 wxFileProperty::wxFileProperty( const wxString
& label
, const wxString
& name
,
1633 const wxString
& value
) : wxPGProperty(label
,name
)
1635 m_flags
|= wxPG_PROP_SHOW_FULL_FILENAME
;
1637 SetAttribute( wxPG_FILE_WILDCARD
, _("All files (*.*)|*.*") );
1642 wxFileProperty::~wxFileProperty() {}
1644 #if wxUSE_VALIDATORS
1646 wxValidator
* wxFileProperty::GetClassValidator()
1648 WX_PG_DOGETVALIDATOR_ENTRY()
1650 // Atleast wxPython 2.6.2.1 required that the string argument is given
1652 wxTextValidator
* validator
= new wxTextValidator(wxFILTER_EXCLUDE_CHAR_LIST
,&v
);
1654 wxArrayString exChars
;
1655 exChars
.Add(wxS("?"));
1656 exChars
.Add(wxS("*"));
1657 exChars
.Add(wxS("|"));
1658 exChars
.Add(wxS("<"));
1659 exChars
.Add(wxS(">"));
1660 exChars
.Add(wxS("\""));
1662 validator
->SetExcludes(exChars
);
1664 WX_PG_DOGETVALIDATOR_EXIT(validator
)
1667 wxValidator
* wxFileProperty::DoGetValidator() const
1669 return GetClassValidator();
1674 void wxFileProperty::OnSetValue()
1676 const wxString
& fnstr
= m_value
.GetString();
1678 wxFileName filename
= fnstr
;
1680 if ( !filename
.HasName() )
1682 m_value
= wxPGVariant_EmptyString
;
1685 // Find index for extension.
1686 if ( m_indFilter
< 0 && fnstr
.length() )
1688 wxString ext
= filename
.GetExt();
1691 size_t len
= m_wildcard
.length();
1693 pos
= m_wildcard
.find(wxS("|"), pos
);
1694 while ( pos
!= wxString::npos
&& pos
< (len
-3) )
1696 size_t ext_begin
= pos
+ 3;
1698 pos
= m_wildcard
.find(wxS("|"), ext_begin
);
1699 if ( pos
== wxString::npos
)
1701 wxString found_ext
= m_wildcard
.substr(ext_begin
, pos
-ext_begin
);
1703 if ( found_ext
.length() > 0 )
1705 if ( found_ext
[0] == wxS('*') )
1707 m_indFilter
= curind
;
1710 if ( ext
.CmpNoCase(found_ext
) == 0 )
1712 m_indFilter
= curind
;
1718 pos
= m_wildcard
.find(wxS("|"), pos
+1);
1725 wxFileName
wxFileProperty::GetFileName() const
1727 wxFileName filename
;
1729 if ( !m_value
.IsNull() )
1730 filename
= m_value
.GetString();
1735 wxString
wxFileProperty::ValueToString( wxVariant
& value
,
1736 int argFlags
) const
1738 wxFileName filename
= value
.GetString();
1740 if ( !filename
.HasName() )
1741 return wxEmptyString
;
1743 wxString fullName
= filename
.GetFullName();
1744 if ( !fullName
.length() )
1745 return wxEmptyString
;
1747 if ( argFlags
& wxPG_FULL_VALUE
)
1749 return filename
.GetFullPath();
1751 else if ( m_flags
& wxPG_PROP_SHOW_FULL_FILENAME
)
1753 if ( m_basePath
.Length() )
1755 wxFileName
fn2(filename
);
1756 fn2
.MakeRelativeTo(m_basePath
);
1757 return fn2
.GetFullPath();
1759 return filename
.GetFullPath();
1762 return filename
.GetFullName();
1765 wxPGEditorDialogAdapter
* wxFileProperty::GetEditorDialog() const
1767 return new wxPGFileDialogAdapter();
1770 bool wxFileProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int argFlags
) const
1772 wxFileName filename
= variant
.GetString();
1774 if ( (m_flags
& wxPG_PROP_SHOW_FULL_FILENAME
) || (argFlags
& wxPG_FULL_VALUE
) )
1776 if ( filename
!= text
)
1784 if ( filename
.GetFullName() != text
)
1786 wxFileName fn
= filename
;
1787 fn
.SetFullName(text
);
1788 variant
= fn
.GetFullPath();
1796 bool wxFileProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1798 // Return false on some occasions to make sure those attribs will get
1799 // stored in m_attributes.
1800 if ( name
== wxPG_FILE_SHOW_FULL_PATH
)
1802 if ( wxPGVariantToInt(value
) )
1803 m_flags
|= wxPG_PROP_SHOW_FULL_FILENAME
;
1805 m_flags
&= ~(wxPG_PROP_SHOW_FULL_FILENAME
);
1808 else if ( name
== wxPG_FILE_WILDCARD
)
1810 m_wildcard
= value
.GetString();
1812 else if ( name
== wxPG_FILE_SHOW_RELATIVE_PATH
)
1814 m_basePath
= value
.GetString();
1816 // Make sure wxPG_FILE_SHOW_FULL_PATH is also set
1817 m_flags
|= wxPG_PROP_SHOW_FULL_FILENAME
;
1819 else if ( name
== wxPG_FILE_INITIAL_PATH
)
1821 m_initialPath
= value
.GetString();
1824 else if ( name
== wxPG_FILE_DIALOG_TITLE
)
1826 m_dlgTitle
= value
.GetString();
1832 // -----------------------------------------------------------------------
1833 // wxPGLongStringDialogAdapter
1834 // -----------------------------------------------------------------------
1836 bool wxPGLongStringDialogAdapter::DoShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
1838 wxString val1
= property
->GetValueAsString(0);
1839 wxString val_orig
= val1
;
1842 if ( !property
->HasFlag(wxPG_PROP_NO_ESCAPE
) )
1843 wxPropertyGrid::ExpandEscapeSequences(value
, val1
);
1845 value
= wxString(val1
);
1847 // Run editor dialog.
1848 if ( wxLongStringProperty::DisplayEditorDialog(property
, propGrid
, value
) )
1850 if ( !property
->HasFlag(wxPG_PROP_NO_ESCAPE
) )
1851 wxPropertyGrid::CreateEscapeSequences(val1
,value
);
1855 if ( val1
!= val_orig
)
1864 // -----------------------------------------------------------------------
1865 // wxLongStringProperty
1866 // -----------------------------------------------------------------------
1868 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxLongStringProperty
,wxPGProperty
,
1869 wxString
,const wxString
&,TextCtrlAndButton
)
1871 wxLongStringProperty::wxLongStringProperty( const wxString
& label
, const wxString
& name
,
1872 const wxString
& value
) : wxPGProperty(label
,name
)
1877 wxLongStringProperty::~wxLongStringProperty() {}
1879 wxString
wxLongStringProperty::ValueToString( wxVariant
& value
,
1880 int WXUNUSED(argFlags
) ) const
1885 bool wxLongStringProperty::OnEvent( wxPropertyGrid
* propGrid
, wxWindow
* WXUNUSED(primary
),
1888 if ( propGrid
->IsMainButtonEvent(event
) )
1891 wxVariant useValue
= propGrid
->GetUncommittedPropertyValue();
1893 wxString val1
= useValue
.GetString();
1894 wxString val_orig
= val1
;
1897 if ( !(m_flags
& wxPG_PROP_NO_ESCAPE
) )
1898 wxPropertyGrid::ExpandEscapeSequences(value
,val1
);
1900 value
= wxString(val1
);
1902 // Run editor dialog.
1903 if ( OnButtonClick(propGrid
,value
) )
1905 if ( !(m_flags
& wxPG_PROP_NO_ESCAPE
) )
1906 wxPropertyGrid::CreateEscapeSequences(val1
,value
);
1910 if ( val1
!= val_orig
)
1912 SetValueInEvent( val1
);
1920 bool wxLongStringProperty::OnButtonClick( wxPropertyGrid
* propGrid
, wxString
& value
)
1922 return DisplayEditorDialog(this, propGrid
, value
);
1925 bool wxLongStringProperty::DisplayEditorDialog( wxPGProperty
* prop
, wxPropertyGrid
* propGrid
, wxString
& value
)
1928 // launch editor dialog
1929 wxDialog
* dlg
= new wxDialog(propGrid
,-1,prop
->GetLabel(),wxDefaultPosition
,wxDefaultSize
,
1930 wxDEFAULT_DIALOG_STYLE
|wxRESIZE_BORDER
|wxCLIP_CHILDREN
);
1932 dlg
->SetFont(propGrid
->GetFont()); // To allow entering chars of the same set as the propGrid
1934 // Multi-line text editor dialog.
1935 #if !wxPG_SMALL_SCREEN
1936 const int spacing
= 8;
1938 const int spacing
= 4;
1940 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
1941 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
1942 wxTextCtrl
* ed
= new wxTextCtrl(dlg
,11,value
,
1943 wxDefaultPosition
,wxDefaultSize
,wxTE_MULTILINE
);
1945 rowsizer
->Add( ed
, 1, wxEXPAND
|wxALL
, spacing
);
1946 topsizer
->Add( rowsizer
, 1, wxEXPAND
, 0 );
1948 wxStdDialogButtonSizer
* buttonSizer
= new wxStdDialogButtonSizer();
1949 buttonSizer
->AddButton(new wxButton(dlg
, wxID_OK
));
1950 buttonSizer
->AddButton(new wxButton(dlg
, wxID_CANCEL
));
1951 buttonSizer
->Realize();
1952 topsizer
->Add( buttonSizer
, 0,
1953 wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
|wxBOTTOM
|wxRIGHT
,
1956 dlg
->SetSizer( topsizer
);
1957 topsizer
->SetSizeHints( dlg
);
1959 #if !wxPG_SMALL_SCREEN
1960 dlg
->SetSize(400,300);
1962 dlg
->Move( propGrid
->GetGoodEditorDialogPosition(prop
,dlg
->GetSize()) );
1965 int res
= dlg
->ShowModal();
1967 if ( res
== wxID_OK
)
1969 value
= ed
->GetValue();
1977 bool wxLongStringProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1979 if ( variant
!= text
)
1987 // -----------------------------------------------------------------------
1988 // wxArrayEditorDialog
1989 // -----------------------------------------------------------------------
1991 BEGIN_EVENT_TABLE(wxArrayEditorDialog
, wxDialog
)
1992 EVT_IDLE(wxArrayEditorDialog::OnIdle
)
1993 EVT_LISTBOX(24, wxArrayEditorDialog::OnListBoxClick
)
1994 EVT_TEXT_ENTER(21, wxArrayEditorDialog::OnAddClick
)
1995 EVT_BUTTON(22, wxArrayEditorDialog::OnAddClick
)
1996 EVT_BUTTON(23, wxArrayEditorDialog::OnDeleteClick
)
1997 EVT_BUTTON(25, wxArrayEditorDialog::OnUpClick
)
1998 EVT_BUTTON(26, wxArrayEditorDialog::OnDownClick
)
1999 EVT_BUTTON(27, wxArrayEditorDialog::OnUpdateClick
)
2000 //EVT_BUTTON(28, wxArrayEditorDialog::OnCustomEditClick)
2003 IMPLEMENT_ABSTRACT_CLASS(wxArrayEditorDialog
, wxDialog
)
2005 #include "wx/statline.h"
2007 // -----------------------------------------------------------------------
2009 void wxArrayEditorDialog::OnIdle(wxIdleEvent
& event
)
2012 // Do control focus detection here.
2015 wxWindow
* focused
= FindFocus();
2017 // This strange focus thing is a workaround for wxGTK wxListBox focus
2019 if ( m_curFocus
== 0 && focused
!= m_edValue
&&
2020 focused
!= m_butAdd
&& focused
!= m_butUpdate
&&
2021 m_lbStrings
->GetSelection() >= 0 )
2023 // ListBox was just focused.
2024 m_butAdd
->Enable(false);
2025 m_butUpdate
->Enable(false);
2026 m_butRemove
->Enable(true);
2027 m_butUp
->Enable(true);
2028 m_butDown
->Enable(true);
2031 else if ( (m_curFocus
== 1 && focused
== m_edValue
) /*|| m_curFocus == 2*/ )
2033 // TextCtrl was just focused.
2034 m_butAdd
->Enable(true);
2035 bool upd_enable
= false;
2036 if ( m_lbStrings
->GetCount() && m_lbStrings
->GetSelection() >= 0 )
2038 m_butUpdate
->Enable(upd_enable
);
2039 m_butRemove
->Enable(false);
2040 m_butUp
->Enable(false);
2041 m_butDown
->Enable(false);
2048 // -----------------------------------------------------------------------
2050 wxArrayEditorDialog::wxArrayEditorDialog()
2056 // -----------------------------------------------------------------------
2058 void wxArrayEditorDialog::Init()
2060 m_custBtText
= (const wxChar
*) NULL
;
2063 // -----------------------------------------------------------------------
2065 wxArrayEditorDialog::wxArrayEditorDialog( wxWindow
*parent
,
2066 const wxString
& message
,
2067 const wxString
& caption
,
2074 Create(parent
,message
,caption
,style
,pos
,sz
);
2077 // -----------------------------------------------------------------------
2079 bool wxArrayEditorDialog::Create( wxWindow
*parent
,
2080 const wxString
& message
,
2081 const wxString
& caption
,
2086 // On wxMAC the dialog shows incorrectly if style is not exactly wxCAPTION
2087 // FIXME: This should be only a temporary fix.
2090 int useStyle
= wxCAPTION
;
2092 int useStyle
= style
;
2095 bool res
= wxDialog::Create(parent
, wxID_ANY
, caption
, pos
, sz
, useStyle
);
2097 SetFont(parent
->GetFont()); // To allow entering chars of the same set as the propGrid
2099 #if !wxPG_SMALL_SCREEN
2100 const int spacing
= 4;
2102 const int spacing
= 3;
2109 wxBoxSizer
* topsizer
= new wxBoxSizer( wxVERTICAL
);
2112 if ( message
.length() )
2113 topsizer
->Add( new wxStaticText(this,-1,message
),
2114 0, wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
|wxALL
, spacing
);
2117 wxBoxSizer
* rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
2118 m_edValue
= new wxTextCtrl(this,21,wxEmptyString
,
2119 wxDefaultPosition
,wxDefaultSize
,wxTE_PROCESS_ENTER
);
2120 wxValidator
* validator
= GetTextCtrlValidator();
2123 m_edValue
->SetValidator( *validator
);
2126 rowsizer
->Add( m_edValue
,
2127 1, wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
|wxALL
, spacing
);
2130 m_butAdd
= new wxButton(this,22,_("Add"));
2131 rowsizer
->Add( m_butAdd
,
2132 0, wxALIGN_LEFT
|wxALIGN_CENTRE_VERTICAL
|wxTOP
|wxBOTTOM
|wxRIGHT
, spacing
);
2133 topsizer
->Add( rowsizer
, 0, wxEXPAND
, spacing
);
2136 topsizer
->Add( new wxStaticLine(this,-1),
2137 0, wxEXPAND
|wxBOTTOM
|wxLEFT
|wxRIGHT
, spacing
);
2139 rowsizer
= new wxBoxSizer( wxHORIZONTAL
);
2142 m_lbStrings
= new wxListBox(this, 24, wxDefaultPosition
, wxDefaultSize
);
2144 for ( i
=0; i
<ArrayGetCount(); i
++ )
2145 m_lbStrings
->Append( ArrayGet(i
) );
2146 rowsizer
->Add( m_lbStrings
, 1, wxEXPAND
|wxRIGHT
, spacing
);
2148 // Manipulator buttons
2149 wxBoxSizer
* colsizer
= new wxBoxSizer( wxVERTICAL
);
2153 m_butCustom
= new wxButton(this,28,::wxGetTranslation(m_custBtText
));
2154 colsizer
->Add( m_butCustom
,
2155 0, wxALIGN_CENTER
|wxTOP
/*wxALIGN_LEFT|wxALIGN_CENTRE_VERTICAL|wxTOP|wxBOTTOM|wxRIGHT*/,
2158 m_butUpdate
= new wxButton(this,27,_("Update"));
2159 colsizer
->Add( m_butUpdate
,
2160 0, wxALIGN_CENTER
|wxTOP
, spacing
);
2161 m_butRemove
= new wxButton(this,23,_("Remove"));
2162 colsizer
->Add( m_butRemove
,
2163 0, wxALIGN_CENTER
|wxTOP
, spacing
);
2164 m_butUp
= new wxButton(this,25,_("Up"));
2165 colsizer
->Add( m_butUp
,
2166 0, wxALIGN_CENTER
|wxTOP
, spacing
);
2167 m_butDown
= new wxButton(this,26,_("Down"));
2168 colsizer
->Add( m_butDown
,
2169 0, wxALIGN_CENTER
|wxTOP
, spacing
);
2170 rowsizer
->Add( colsizer
, 0, 0, spacing
);
2172 topsizer
->Add( rowsizer
, 1, wxLEFT
|wxRIGHT
|wxEXPAND
, spacing
);
2175 topsizer
->Add( new wxStaticLine(this,-1),
2176 0, wxEXPAND
|wxTOP
|wxLEFT
|wxRIGHT
, spacing
);
2178 // Standard dialog buttons
2179 wxStdDialogButtonSizer
* buttonSizer
= new wxStdDialogButtonSizer();
2180 buttonSizer
->AddButton(new wxButton(this, wxID_OK
));
2181 buttonSizer
->AddButton(new wxButton(this, wxID_CANCEL
));
2182 buttonSizer
->Realize();
2183 topsizer
->Add( buttonSizer
, 0,
2184 wxALIGN_RIGHT
|wxALIGN_CENTRE_VERTICAL
|wxALL
,
2187 m_edValue
->SetFocus();
2189 SetSizer( topsizer
);
2190 topsizer
->SetSizeHints( this );
2192 #if !wxPG_SMALL_SCREEN
2193 if ( sz
.x
== wxDefaultSize
.x
&&
2194 sz
.y
== wxDefaultSize
.y
)
2195 SetSize( wxSize(275,360) );
2203 // -----------------------------------------------------------------------
2205 void wxArrayEditorDialog::OnAddClick(wxCommandEvent
& )
2207 wxString text
= m_edValue
->GetValue();
2208 if ( text
.length() )
2210 if ( ArrayInsert( text
, -1 ) )
2212 m_lbStrings
->Append( text
);
2219 // -----------------------------------------------------------------------
2221 void wxArrayEditorDialog::OnDeleteClick(wxCommandEvent
& )
2223 int index
= m_lbStrings
->GetSelection();
2226 ArrayRemoveAt( index
);
2227 m_lbStrings
->Delete ( index
);
2232 // -----------------------------------------------------------------------
2234 void wxArrayEditorDialog::OnUpClick(wxCommandEvent
& )
2236 int index
= m_lbStrings
->GetSelection();
2239 ArraySwap(index
-1,index
);
2240 /*wxString old_str = m_array[index-1];
2241 wxString new_str = m_array[index];
2242 m_array[index-1] = new_str;
2243 m_array[index] = old_str;*/
2244 m_lbStrings
->SetString ( index
-1, ArrayGet(index
-1) );
2245 m_lbStrings
->SetString ( index
, ArrayGet(index
) );
2246 m_lbStrings
->SetSelection ( index
-1 );
2251 // -----------------------------------------------------------------------
2253 void wxArrayEditorDialog::OnDownClick(wxCommandEvent
& )
2255 int index
= m_lbStrings
->GetSelection();
2256 int lastStringIndex
= ((int) m_lbStrings
->GetCount()) - 1;
2257 if ( index
>= 0 && index
< lastStringIndex
)
2259 ArraySwap(index
,index
+1);
2260 /*wxString old_str = m_array[index+1];
2261 wxString new_str = m_array[index];
2262 m_array[index+1] = new_str;
2263 m_array[index] = old_str;*/
2264 m_lbStrings
->SetString ( index
+1, ArrayGet(index
+1) );
2265 m_lbStrings
->SetString ( index
, ArrayGet(index
) );
2266 m_lbStrings
->SetSelection ( index
+1 );
2271 // -----------------------------------------------------------------------
2273 void wxArrayEditorDialog::OnUpdateClick(wxCommandEvent
& )
2275 int index
= m_lbStrings
->GetSelection();
2278 wxString str
= m_edValue
->GetValue();
2279 if ( ArraySet(index
,str
) )
2281 m_lbStrings
->SetString ( index
, str
);
2282 //m_array[index] = str;
2288 // -----------------------------------------------------------------------
2290 void wxArrayEditorDialog::OnListBoxClick(wxCommandEvent
& )
2292 int index
= m_lbStrings
->GetSelection();
2295 m_edValue
->SetValue( m_lbStrings
->GetString(index
) );
2299 // -----------------------------------------------------------------------
2300 // wxPGArrayStringEditorDialog
2301 // -----------------------------------------------------------------------
2303 IMPLEMENT_DYNAMIC_CLASS(wxPGArrayStringEditorDialog
, wxArrayEditorDialog
)
2305 BEGIN_EVENT_TABLE(wxPGArrayStringEditorDialog
, wxArrayEditorDialog
)
2306 EVT_BUTTON(28, wxPGArrayStringEditorDialog::OnCustomEditClick
)
2309 // -----------------------------------------------------------------------
2311 wxString
wxPGArrayStringEditorDialog::ArrayGet( size_t index
)
2313 return m_array
[index
];
2316 size_t wxPGArrayStringEditorDialog::ArrayGetCount()
2318 return m_array
.size();
2321 bool wxPGArrayStringEditorDialog::ArrayInsert( const wxString
& str
, int index
)
2326 m_array
.Insert(str
,index
);
2330 bool wxPGArrayStringEditorDialog::ArraySet( size_t index
, const wxString
& str
)
2332 m_array
[index
] = str
;
2336 void wxPGArrayStringEditorDialog::ArrayRemoveAt( int index
)
2338 m_array
.RemoveAt(index
);
2341 void wxPGArrayStringEditorDialog::ArraySwap( size_t first
, size_t second
)
2343 wxString old_str
= m_array
[first
];
2344 wxString new_str
= m_array
[second
];
2345 m_array
[first
] = new_str
;
2346 m_array
[second
] = old_str
;
2349 wxPGArrayStringEditorDialog::wxPGArrayStringEditorDialog()
2350 : wxArrayEditorDialog()
2355 void wxPGArrayStringEditorDialog::Init()
2357 m_pCallingClass
= NULL
;
2360 void wxPGArrayStringEditorDialog::OnCustomEditClick(wxCommandEvent
& )
2362 wxASSERT( m_pCallingClass
);
2363 wxString str
= m_edValue
->GetValue();
2364 if ( m_pCallingClass
->OnCustomStringEdit(m_parent
,str
) )
2366 //m_edValue->SetValue ( str );
2367 m_lbStrings
->Append ( str
);
2368 m_array
.Add ( str
);
2373 // -----------------------------------------------------------------------
2374 // wxArrayStringProperty
2375 // -----------------------------------------------------------------------
2377 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxArrayStringProperty
, // Property name
2378 wxPGProperty
, // Property we inherit from
2379 wxArrayString
, // Value type name
2380 const wxArrayString
&, // Value type, as given in constructor
2381 TextCtrlAndButton
) // Initial editor
2383 wxArrayStringProperty::wxArrayStringProperty( const wxString
& label
,
2384 const wxString
& name
,
2385 const wxArrayString
& array
)
2386 : wxPGProperty(label
,name
)
2391 wxArrayStringProperty::~wxArrayStringProperty() { }
2393 void wxArrayStringProperty::OnSetValue()
2395 GenerateValueAsString();
2398 #define ARRSTRPROP_ARRAY_TO_STRING(STRING,ARRAY) \
2399 wxPropertyGrid::ArrayStringToString(STRING,ARRAY,wxS('"'),wxS('"'),1)
2401 wxString
wxArrayStringProperty::ValueToString( wxVariant
& WXUNUSED(value
),
2402 int argFlags
) const
2405 // If this is called from GetValueAsString(), return cached string
2406 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
2411 wxArrayString arr
= m_value
.GetArrayString();
2413 ARRSTRPROP_ARRAY_TO_STRING(s
, arr
);
2417 // Converts wxArrayString to a string separated by delimeters and spaces.
2418 // preDelim is useful for "str1" "str2" style. Set flags to 1 to do slash
2420 void wxPropertyGrid::ArrayStringToString( wxString
& dst
, const wxArrayString
& src
,
2421 wxChar preDelim
, wxChar postDelim
,
2427 unsigned int itemCount
= src
.size();
2429 wxChar preas
[2] = { 0, 0 };
2435 preas
[0] = preDelim
;
2441 dst
.append( preas
);
2443 wxASSERT( postDelim
);
2444 wxString
postDelimStr(postDelim
);
2445 //wxString preDelimStr(preDelim);
2447 for ( i
= 0; i
< itemCount
; i
++ )
2449 wxString
str( src
.Item(i
) );
2451 // Do some character conversion.
2452 // Convertes \ to \\ and <preDelim> to \<preDelim>
2453 // Useful when preDelim and postDelim are "\"".
2456 str
.Replace( wxS("\\"), wxS("\\\\"), true );
2458 str
.Replace( preas
, pdr
, true );
2463 if ( i
< (itemCount
-1) )
2465 dst
.append( postDelimStr
);
2466 dst
.append( wxS(" ") );
2467 dst
.append( preas
);
2469 else if ( preDelim
)
2470 dst
.append( postDelimStr
);
2474 void wxArrayStringProperty::GenerateValueAsString()
2476 wxArrayString arr
= m_value
.GetArrayString();
2477 ARRSTRPROP_ARRAY_TO_STRING(m_display
, arr
);
2480 // Default implementation doesn't do anything.
2481 bool wxArrayStringProperty::OnCustomStringEdit( wxWindow
*, wxString
& )
2486 wxArrayEditorDialog
* wxArrayStringProperty::CreateEditorDialog()
2488 return new wxPGArrayStringEditorDialog();
2491 bool wxArrayStringProperty::OnButtonClick( wxPropertyGrid
* propGrid
,
2492 wxWindow
* WXUNUSED(primaryCtrl
),
2496 wxVariant useValue
= propGrid
->GetUncommittedPropertyValue();
2498 if ( !propGrid
->EditorValidate() )
2501 // Create editor dialog.
2502 wxArrayEditorDialog
* dlg
= CreateEditorDialog();
2503 #if wxUSE_VALIDATORS
2504 wxValidator
* validator
= GetValidator();
2505 wxPGInDialogValidator dialogValidator
;
2508 wxPGArrayStringEditorDialog
* strEdDlg
= wxDynamicCast(dlg
, wxPGArrayStringEditorDialog
);
2511 strEdDlg
->SetCustomButton(cbt
, this);
2513 dlg
->SetDialogValue( useValue
);
2514 dlg
->Create(propGrid
, wxEmptyString
, m_label
);
2516 #if !wxPG_SMALL_SCREEN
2517 dlg
->Move( propGrid
->GetGoodEditorDialogPosition(this,dlg
->GetSize()) );
2526 int res
= dlg
->ShowModal();
2528 if ( res
== wxID_OK
&& dlg
->IsModified() )
2530 wxVariant value
= dlg
->GetDialogValue();
2531 if ( !value
.IsNull() )
2533 wxArrayString actualValue
= value
.GetArrayString();
2535 ARRSTRPROP_ARRAY_TO_STRING(tempStr
, actualValue
);
2536 #if wxUSE_VALIDATORS
2537 if ( dialogValidator
.DoValidate( propGrid
, validator
, tempStr
) )
2540 SetValueInEvent( actualValue
);
2557 bool wxArrayStringProperty::OnEvent( wxPropertyGrid
* propGrid
,
2561 if ( propGrid
->IsMainButtonEvent(event
) )
2562 return OnButtonClick(propGrid
,primary
,(const wxChar
*) NULL
);
2566 bool wxArrayStringProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
2570 WX_PG_TOKENIZER2_BEGIN(text
,wxS('"'))
2572 // Need to replace backslashes with empty characters
2573 // (opposite what is done in GenerateValueString).
2574 token
.Replace ( wxS("\\"), wxEmptyString
, true );
2578 WX_PG_TOKENIZER2_END()
2585 // -----------------------------------------------------------------------
2586 // wxPGInDialogValidator
2587 // -----------------------------------------------------------------------
2589 #if wxUSE_VALIDATORS
2590 bool wxPGInDialogValidator::DoValidate( wxPropertyGrid
* propGrid
,
2591 wxValidator
* validator
,
2592 const wxString
& value
)
2597 wxTextCtrl
* tc
= m_textCtrl
;
2602 tc
= new wxTextCtrl( propGrid
, wxPG_SUBID_TEMP1
, wxEmptyString
,
2603 wxPoint(30000,30000));
2610 tc
->SetValue(value
);
2612 validator
->SetWindow(tc
);
2613 bool res
= validator
->Validate(propGrid
);
2618 bool wxPGInDialogValidator::DoValidate( wxPropertyGrid
* WXUNUSED(propGrid
),
2619 wxValidator
* WXUNUSED(validator
),
2620 const wxString
& WXUNUSED(value
) )
2626 // -----------------------------------------------------------------------
2628 #endif // wxUSE_PROPGRID