1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/advprops.cpp
3 // Purpose: wxPropertyGrid Advanced Properties (font, colour, etc.)
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/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/textctrl.h"
42 #include "wx/scrolwin.h"
43 #include "wx/dirdlg.h"
44 #include "wx/combobox.h"
46 #include "wx/textdlg.h"
47 #include "wx/filedlg.h"
49 #include "wx/wxcrtvararg.h"
52 #define __wxPG_SOURCE_FILE__
54 #include "wx/propgrid/propgrid.h"
56 #if wxPG_INCLUDE_ADVPROPS
58 #include "wx/propgrid/advprops.h"
61 #include "wx/msw/private.h"
62 #include "wx/msw/dc.h"
65 // -----------------------------------------------------------------------
67 #if defined(__WXMSW__)
68 #define wxPG_CAN_DRAW_CURSOR 1
69 #elif defined(__WXGTK__)
70 #define wxPG_CAN_DRAW_CURSOR 0
71 #elif defined(__WXMAC__)
72 #define wxPG_CAN_DRAW_CURSOR 0
74 #define wxPG_CAN_DRAW_CURSOR 0
78 // -----------------------------------------------------------------------
80 // -----------------------------------------------------------------------
83 // Implement dynamic class for type value.
84 IMPLEMENT_DYNAMIC_CLASS(wxColourPropertyValue
, wxObject
)
86 bool operator == (const wxColourPropertyValue
& a
, const wxColourPropertyValue
& b
)
88 return ( ( a
.m_colour
== b
.m_colour
) && (a
.m_type
== b
.m_type
) );
91 bool operator == (const wxArrayInt
& array1
, const wxArrayInt
& array2
)
93 if ( array1
.size() != array2
.size() )
96 for ( i
=0; i
<array1
.size(); i
++ )
98 if ( array1
[i
] != array2
[i
] )
104 // -----------------------------------------------------------------------
105 // wxSpinCtrl-based property editor
106 // -----------------------------------------------------------------------
111 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(SpinCtrl
,
116 // Trivial destructor.
117 wxPGSpinCtrlEditor::~wxPGSpinCtrlEditor()
122 // Create controls and initialize event handling.
123 wxPGWindowList
wxPGSpinCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
124 const wxPoint
& pos
, const wxSize
& sz
) const
126 const int margin
= 1;
127 wxSize
butSz(18, sz
.y
);
128 wxSize
tcSz(sz
.x
- butSz
.x
- margin
, sz
.y
);
129 wxPoint
butPos(pos
.x
+ tcSz
.x
+ margin
, pos
.y
);
131 wxSpinButton
* wnd2
= new wxSpinButton();
135 wnd2
->Create( propgrid
->GetPanel(), wxPG_SUBID2
, butPos
, butSz
, wxSP_VERTICAL
);
137 wnd2
->SetRange( INT_MIN
, INT_MAX
);
140 wxWindowID id
= wnd2
->GetId();
141 wnd2
->Connect( id
, wxEVT_SCROLL_LINEUP
,
142 wxEventHandler(wxPropertyGrid::OnCustomEditorEvent
),
144 wnd2
->Connect( id
, wxEVT_SCROLL_LINEDOWN
,
145 wxEventHandler(wxPropertyGrid::OnCustomEditorEvent
),
148 // Let's add validator to make sure only numbers can be entered
149 wxTextValidator
validator(wxFILTER_NUMERIC
, &m_tempString
);
151 wxTextCtrl
* wnd1
= (wxTextCtrl
*) wxPGTextCtrlEditor::CreateControls( propgrid
, property
, pos
, tcSz
).m_primary
;
152 wnd1
->SetValidator(validator
);
154 wnd1
->Connect( wnd1
->GetId(), wxEVT_KEY_DOWN
,
155 wxEventHandler(wxPropertyGrid::OnCustomEditorEvent
),
158 return wxPGWindowList(wnd1
, wnd2
);
161 // Control's events are redirected here
162 bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
163 wxWindow
* wnd
, wxEvent
& event
) const
165 int evtType
= event
.GetEventType();
167 bool bigStep
= false;
169 if ( evtType
== wxEVT_KEY_DOWN
)
171 wxKeyEvent
& keyEvent
= (wxKeyEvent
&)event
;
172 keycode
= keyEvent
.GetKeyCode();
174 if ( keycode
== WXK_UP
)
175 evtType
= wxEVT_SCROLL_LINEUP
;
176 else if ( keycode
== WXK_DOWN
)
177 evtType
= wxEVT_SCROLL_LINEDOWN
;
178 else if ( keycode
== WXK_PAGEUP
)
180 evtType
= wxEVT_SCROLL_LINEUP
;
183 else if ( keycode
== WXK_PAGEDOWN
)
185 evtType
= wxEVT_SCROLL_LINEDOWN
;
190 if ( evtType
== wxEVT_SCROLL_LINEUP
|| evtType
== wxEVT_SCROLL_LINEDOWN
)
193 // Can't use wnd since it might be clipper window
194 wxTextCtrl
* tc
= wxDynamicCast(propgrid
->GetEditorControl(), wxTextCtrl
);
199 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
201 int mode
= wxPG_PROPERTY_VALIDATION_SATURATE
;
203 if ( property
->GetAttributeAsLong(wxT("Wrap"), 0) )
204 mode
= wxPG_PROPERTY_VALIDATION_WRAP
;
206 if ( property
->GetValueType() == wxT("double") )
209 double step
= property
->GetAttributeAsDouble(wxT("Step"), 1.0);
212 if ( s
.ToDouble(&v_d
) )
217 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_d
+= step
;
221 wxFloatProperty::DoValidation(property
, v_d
, NULL
, mode
);
223 wxPropertyGrid::DoubleToString(s
, v_d
, 6, true, NULL
);
233 wxLongLong_t step
= property
->GetAttributeAsLong(wxT("Step"), 1);
236 if ( s
.ToLongLong(&v_ll
, 10) )
241 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_ll
+= step
;
245 wxIntProperty::DoValidation(property
, v_ll
, NULL
, mode
);
247 s
= wxLongLong(v_ll
).ToString();
257 int ip
= tc
->GetInsertionPoint();
258 int lp
= tc
->GetLastPosition();
260 tc
->SetInsertionPoint(ip
+(tc
->GetLastPosition()-lp
));
266 return wxPGTextCtrlEditor::OnEvent(propgrid
,property
,wnd
,event
);
269 #endif // wxUSE_SPINBTN
272 // -----------------------------------------------------------------------
273 // wxDatePickerCtrl-based property editor
274 // -----------------------------------------------------------------------
276 #if wxUSE_DATEPICKCTRL
279 #include "wx/datectrl.h"
280 #include "wx/dateevt.h"
282 class wxPGDatePickerCtrlEditor
: public wxPGEditor
284 DECLARE_DYNAMIC_CLASS(wxPGDatePickerCtrlEditor
)
286 virtual ~wxPGDatePickerCtrlEditor();
288 wxString
GetName() const;
289 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
290 wxPGProperty
* property
,
292 const wxSize
& size
) const;
293 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const;
294 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
295 wxWindow
* wnd
, wxEvent
& event
) const;
296 virtual bool GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* wnd
) const;
297 virtual void SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const;
301 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(DatePickerCtrl
,
302 wxPGDatePickerCtrlEditor
,
306 wxPGDatePickerCtrlEditor::~wxPGDatePickerCtrlEditor()
310 wxPGWindowList
wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
,
311 wxPGProperty
* property
,
313 const wxSize
& sz
) const
315 wxCHECK_MSG( property
->IsKindOf(CLASSINFO(wxDateProperty
)),
317 wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
319 wxDateProperty
* prop
= (wxDateProperty
*) property
;
321 // Use two stage creation to allow cleaner display on wxMSW
322 wxDatePickerCtrl
* ctrl
= new wxDatePickerCtrl();
325 wxSize useSz
= wxDefaultSize
;
330 ctrl
->Create(propgrid
->GetPanel(),
332 prop
->GetDateValue(),
335 prop
->GetDatePickerStyle() | wxNO_BORDER
);
337 // Connect all required events to grid's OnCustomEditorEvent
338 // (all relevenat wxTextCtrl, wxComboBox and wxButton events are
339 // already connected)
340 ctrl
->Connect( wxPG_SUBID1
, wxEVT_DATE_CHANGED
,
341 wxEventHandler(wxPropertyGrid::OnCustomEditorEvent
),
351 // Copies value from property to control
352 void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const
354 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
355 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
357 // We assume that property's data type is 'int' (or something similar),
358 // thus allowing us to get raw, unchecked value via DoGetValue.
359 ctrl
->SetValue( property
->GetValue().GetDateTime() );
362 // Control's events are redirected here
363 bool wxPGDatePickerCtrlEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propgrid
),
364 wxPGProperty
* WXUNUSED(property
),
365 wxWindow
* WXUNUSED(wnd
),
366 wxEvent
& event
) const
368 if ( event
.GetEventType() == wxEVT_DATE_CHANGED
)
374 bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const
376 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
377 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
379 variant
= ctrl
->GetValue();
384 void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* WXUNUSED(wnd
) ) const
387 //wxDateProperty* prop = (wxDateProperty*) property;
391 #endif // wxUSE_DATEPICKCTRL
394 // -----------------------------------------------------------------------
396 // -----------------------------------------------------------------------
398 #include "wx/fontdlg.h"
399 #include "wx/fontenum.h"
401 static const wxChar
* gs_fp_es_family_labels
[] = {
402 wxT("Default"), wxT("Decorative"),
403 wxT("Roman"), wxT("Script"),
404 wxT("Swiss"), wxT("Modern"),
408 static long gs_fp_es_family_values
[] = {
409 wxDEFAULT
, wxDECORATIVE
,
414 static const wxChar
* gs_fp_es_style_labels
[] = {
421 static long gs_fp_es_style_values
[] = {
427 static const wxChar
* gs_fp_es_weight_labels
[] = {
434 static long gs_fp_es_weight_values
[] = {
440 // Class body is in advprops.h
443 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty
,wxPGProperty
,
444 wxFont
,const wxFont
&,TextCtrlAndButton
)
447 wxFontProperty::wxFontProperty( const wxString
& label
, const wxString
& name
,
448 const wxFont
& value
)
449 : wxPGProperty(label
,name
)
451 SetValue(WXVARIANT(value
));
453 // Initialize font family choices list
454 if ( !wxPGGlobalVars
->m_fontFamilyChoices
)
456 wxArrayString faceNames
= wxFontEnumerator::GetFacenames();
460 wxPGGlobalVars
->m_fontFamilyChoices
= new wxPGChoices(faceNames
);
463 wxString
emptyString(wxEmptyString
);
468 SetParentalType(wxPG_PROP_AGGREGATE
);
470 AddChild( new wxIntProperty( _("Point Size"), wxS("Point Size"),(long)font
.GetPointSize() ) );
472 AddChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
473 gs_fp_es_family_labels
,gs_fp_es_family_values
,
476 wxString faceName
= font
.GetFaceName();
477 // If font was not in there, add it now
478 if ( faceName
.length() &&
479 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
480 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
482 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"), wxS("Face Name"),
483 *wxPGGlobalVars
->m_fontFamilyChoices
);
485 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
489 AddChild( new wxEnumProperty(_("Style"), wxS("Style"),
490 gs_fp_es_style_labels
,gs_fp_es_style_values
,font
.GetStyle()) );
492 AddChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
493 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,font
.GetWeight()) );
495 AddChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
496 font
.GetUnderlined()) );
499 wxFontProperty::~wxFontProperty() { }
501 void wxFontProperty::OnSetValue()
508 font
= wxFont(10,wxSWISS
,wxNORMAL
,wxNORMAL
);
513 wxString
wxFontProperty::ValueToString( wxVariant
& value
,
516 return wxPGProperty::ValueToString(value
, argFlags
);
519 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
522 if ( propgrid
->IsMainButtonEvent(event
) )
524 // Update value from last minute changes
525 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
530 data
.SetInitialFont( font
);
531 data
.SetColour(*wxBLACK
);
533 wxFontDialog
dlg(propgrid
, data
);
534 if ( dlg
.ShowModal() == wxID_OK
)
536 propgrid
->EditorsValueWasModified();
539 variant
<< dlg
.GetFontData().GetChosenFont();
540 SetValueInEvent( variant
);
547 void wxFontProperty::RefreshChildren()
549 if ( !GetChildCount() ) return;
552 Item(0)->SetValue( (long)font
.GetPointSize() );
553 Item(1)->SetValue( (long)font
.GetFamily() );
554 Item(2)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
555 Item(3)->SetValue( (long)font
.GetStyle() );
556 Item(4)->SetValue( (long)font
.GetWeight() );
557 Item(5)->SetValue( font
.GetUnderlined() );
560 void wxFontProperty::ChildChanged( wxVariant
& thisValue
, int ind
, wxVariant
& childValue
) const
567 font
.SetPointSize( wxPGVariantToInt(childValue
) );
571 int fam
= childValue
.GetLong();
572 if ( fam
< wxDEFAULT
||
575 font
.SetFamily( fam
);
580 int faceIndex
= childValue
.GetLong();
582 if ( faceIndex
>= 0 )
583 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
585 font
.SetFaceName( faceName
);
589 int st
= childValue
.GetLong();
590 if ( st
!= wxFONTSTYLE_NORMAL
&&
591 st
!= wxFONTSTYLE_SLANT
&&
592 st
!= wxFONTSTYLE_ITALIC
)
593 st
= wxFONTWEIGHT_NORMAL
;
598 int wt
= childValue
.GetLong();
599 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
600 wt
!= wxFONTWEIGHT_LIGHT
&&
601 wt
!= wxFONTWEIGHT_BOLD
)
602 wt
= wxFONTWEIGHT_NORMAL
;
603 font
.SetWeight( wt
);
607 font
.SetUnderlined( childValue
.GetBool() );
614 wxSize wxFontProperty::OnMeasureImage() const
616 return wxSize(-1,-1);
619 void wxFontProperty::OnCustomPaint(wxDC& dc,
621 wxPGPaintData& paintData)
624 if ( paintData.m_choiceItem >= 0 )
625 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
627 drawFace = m_value_wxFont.GetFaceName();
629 if ( drawFace.length() )
631 // Draw the background
632 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
633 //dc.SetBrush( *wxWHITE_BRUSH );
634 //dc.SetPen( *wxMEDIUM_GREY_PEN );
635 dc.DrawRectangle( rect );
637 wxFont oldFont = dc.GetFont();
638 wxFont drawFont(oldFont.GetPointSize(),
639 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
640 dc.SetFont(drawFont);
642 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
643 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
649 // No file - just draw a white box
650 dc.SetBrush ( *wxWHITE_BRUSH );
651 dc.DrawRectangle ( rect );
657 // -----------------------------------------------------------------------
658 // wxSystemColourProperty
659 // -----------------------------------------------------------------------
661 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
662 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
664 #include "wx/colordlg.h"
666 //#define wx_cp_es_syscolours_len 25
667 static const wxChar
* gs_cp_es_syscolour_labels
[] = {
670 wxT("ActiveCaption"),
672 wxT("ButtonHighlight"),
681 wxT("HighlightText"),
682 wxT("InactiveBorder"),
683 wxT("InactiveCaption"),
684 wxT("InactiveCaptionText"),
696 static long gs_cp_es_syscolour_values
[] = {
697 wxSYS_COLOUR_APPWORKSPACE
,
698 wxSYS_COLOUR_ACTIVEBORDER
,
699 wxSYS_COLOUR_ACTIVECAPTION
,
700 wxSYS_COLOUR_BTNFACE
,
701 wxSYS_COLOUR_BTNHIGHLIGHT
,
702 wxSYS_COLOUR_BTNSHADOW
,
703 wxSYS_COLOUR_BTNTEXT
,
704 wxSYS_COLOUR_CAPTIONTEXT
,
705 wxSYS_COLOUR_3DDKSHADOW
,
706 wxSYS_COLOUR_3DLIGHT
,
707 wxSYS_COLOUR_BACKGROUND
,
708 wxSYS_COLOUR_GRAYTEXT
,
709 wxSYS_COLOUR_HIGHLIGHT
,
710 wxSYS_COLOUR_HIGHLIGHTTEXT
,
711 wxSYS_COLOUR_INACTIVEBORDER
,
712 wxSYS_COLOUR_INACTIVECAPTION
,
713 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
715 wxSYS_COLOUR_SCROLLBAR
,
717 wxSYS_COLOUR_INFOTEXT
,
719 wxSYS_COLOUR_WINDOWFRAME
,
720 wxSYS_COLOUR_WINDOWTEXT
,
725 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
728 // Class body is in advprops.h
730 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
731 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
734 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
736 wxColourPropertyValue cpv
;
739 cpv
.Init( type
, colour
);
741 cpv
.Init( type
, *wxWHITE
);
743 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
751 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
754 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
755 const wxColourPropertyValue
& value
)
756 : wxEnumProperty( label
,
758 gs_cp_es_syscolour_labels
,
759 gs_cp_es_syscolour_values
,
760 &gs_wxSystemColourProperty_choicesCache
)
763 Init( value
.m_type
, value
.m_colour
);
765 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
769 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
770 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
771 const wxColourPropertyValue
& value
)
772 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
775 Init( value
.m_type
, value
.m_colour
);
777 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
781 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
782 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
783 const wxColour
& value
)
784 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
787 Init( wxPG_COLOUR_CUSTOM
, value
);
789 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
793 wxSystemColourProperty::~wxSystemColourProperty() { }
796 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
801 if ( pVariant
->IsNull() )
802 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
804 if ( pVariant
->GetType() == wxS("wxColourPropertyValue") )
806 wxColourPropertyValue v
;
812 bool variantProcessed
= true;
814 if ( pVariant
->GetType() == wxS("wxColour*") )
816 wxColour
* pCol
= wxStaticCast(pVariant
->GetWxObjectPtr(), wxColour
);
819 else if ( pVariant
->GetType() == wxS("wxColour") )
823 else if ( pVariant
->GetType() == wxArrayInt_VariantType
)
825 // This code is mostly needed for wxPython bindings, which
826 // may offer tuple of integers as colour value.
830 if ( arr
.size() >= 3 )
838 if ( arr
.size() >= 4 )
841 col
= wxColour(r
, g
, b
, a
);
845 variantProcessed
= false;
850 variantProcessed
= false;
853 if ( !variantProcessed
)
854 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
856 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
858 int colInd
= ColToInd(col
);
859 if ( colInd
!= wxNOT_FOUND
)
865 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
872 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
875 size_t i_max
= m_choices
.GetCount() - 1;
877 for ( i
=0; i
<i_max
; i
++ )
879 int ind
= m_choices
[i
].GetValue();
881 if ( colour
== GetColour(ind
) )
883 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
884 GetClassName(),GetLabel().c_str(),
885 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
886 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
893 void wxSystemColourProperty::OnSetValue()
895 // Convert from generic wxobject ptr to wxPGVariantDataColour
896 if ( m_value
.GetType() == wxS("wxColour*") )
898 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
902 wxColourPropertyValue val
= GetVal(&m_value
);
904 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
912 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
913 val
.m_colour
= GetColour( val
.m_type
);
915 m_value
= TranslateVal(val
);
918 int ind
= wxNOT_FOUND
;
920 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
922 wxColourPropertyValue cpv
;
924 wxColour col
= cpv
.m_colour
;
928 SetValueToUnspecified();
929 SetIndex(wxNOT_FOUND
);
933 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
)
935 ind
= GetIndexForValue(cpv
.m_type
);
939 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
940 ind
= GetCustomColourIndex();
950 SetValueToUnspecified();
951 SetIndex(wxNOT_FOUND
);
957 if ( ind
== wxNOT_FOUND
)
958 ind
= GetCustomColourIndex();
965 wxColour
wxSystemColourProperty::GetColour( int index
) const
967 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
970 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
972 if ( index
== wxNOT_FOUND
)
973 return wxString::Format(wxT("(%i,%i,%i)"),
978 return m_choices
.GetLabel(index
);
981 wxString
wxSystemColourProperty::ValueToString( wxVariant
& value
,
984 wxColourPropertyValue val
= GetVal(&value
);
988 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
990 // GetIndex() only works reliably if wxPG_VALUE_IS_CURRENT flag is set,
991 // but we should use it whenever possible.
994 // If custom colour was selected, use invalid index, so that
995 // ColourToString() will return properly formatted colour text.
996 if ( index
== GetCustomColourIndex() )
1001 index
= m_choices
.Index(val
.m_type
);
1004 return ColourToString(val
.m_colour
, index
);
1008 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
1010 return wxPG_DEFAULT_IMAGE_SIZE
;
1014 int wxSystemColourProperty::GetCustomColourIndex() const
1016 return m_choices
.GetCount() - 1;
1020 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1022 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1025 wxPropertyGrid
* propgrid
= GetGrid();
1026 wxASSERT( propgrid
);
1028 // Must only occur when user triggers event
1029 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_ONCUSTOMEDITOREVENT
) )
1032 wxColourPropertyValue val
= GetVal();
1034 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1037 data
.SetChooseFull(true);
1038 data
.SetColour(val
.m_colour
);
1040 for ( i
= 0; i
< 16; i
++)
1042 wxColour
colour(i
*16, i
*16, i
*16);
1043 data
.SetCustomColour(i
, colour
);
1046 wxColourDialog
dialog(propgrid
, &data
);
1047 if ( dialog
.ShowModal() == wxID_OK
)
1049 wxColourData retData
= dialog
.GetColourData();
1050 val
.m_colour
= retData
.GetColour();
1052 variant
= DoTranslateVal(val
);
1054 SetValueInEvent(variant
);
1063 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1066 int type
= m_choices
.GetValue(index
);
1068 if ( type
== wxPG_COLOUR_CUSTOM
)
1070 QueryColourFromUser(variant
);
1074 variant
= TranslateVal( type
, GetColour(type
) );
1080 // Need to do some extra event handling.
1081 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
), wxEvent
& event
)
1083 if ( propgrid
->IsMainButtonEvent(event
) )
1085 // We need to handle button click in case editor has been
1086 // switched to one that has wxButton as well.
1088 if ( QueryColourFromUser(variant
) )
1094 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1097 virtual void Render( wxDC& dc, const wxRect& rect,
1098 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1099 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1101 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1102 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1104 dc.SetPen(*wxBLACK_PEN);
1106 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1110 const wxArrayInt& values = prop->GetValues();
1111 if ( values.GetChildCount() )
1112 colInd = values[item];
1115 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1117 else if ( !prop->IsValueUnspecified() )
1118 dc.SetBrush( prop->GetVal().m_colour );
1120 dc.SetBrush( *wxWHITE );
1122 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1123 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1124 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1125 imageRect.width, imageRect.height );
1129 text = property->GetValueAsString();
1131 text = property->GetChoiceString(item);
1132 DrawText( dc, rect, imageRect.width, text );
1137 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1139 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1142 return &g_wxPGColourPropertyRenderer;
1143 return wxEnumProperty::GetCellRenderer(column);
1146 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1147 wxPGPaintData
& paintdata
)
1151 if ( paintdata
.m_choiceItem
>= 0 && paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1152 paintdata
.m_choiceItem
!= GetCustomColourIndex() )
1154 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1155 col
= GetColour( colInd
);
1157 else if ( !IsValueUnspecified() )
1159 col
= GetVal().m_colour
;
1165 dc
.DrawRectangle(rect
);
1170 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1173 // Accept colour format "[Name] [(R,G,B)]"
1174 // Name takes precedence.
1176 wxString colourName
;
1179 int ppos
= text
.Find(wxT("("));
1181 if ( ppos
== wxNOT_FOUND
)
1187 colourName
= text
.substr(0, ppos
);
1188 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1191 // Strip spaces from extremities
1192 colourName
.Trim(true);
1193 colourName
.Trim(false);
1194 colourRGB
.Trim(true);
1196 // Validate colourRGB string - (1,1,1) is shortest allowed
1197 if ( colourRGB
.length() < 7 )
1200 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1201 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1203 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1205 // This really should not occurr...
1211 QueryColourFromUser(value
);
1215 wxColourPropertyValue val
;
1219 if ( colourName
.length() )
1221 // Try predefined colour first
1222 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1223 if ( res
&& GetIndex() >= 0 )
1225 val
.m_type
= GetIndex();
1226 if ( val
.m_type
< m_choices
.GetCount() )
1227 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1229 // Get proper colour for type.
1230 val
.m_colour
= GetColour(val
.m_type
);
1235 if ( colourRGB
.length() && !done
)
1237 // Then check custom colour.
1238 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1240 int r
= -1, g
= -1, b
= -1;
1241 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1243 if ( r
>= 0 && r
<= 255 &&
1244 g
>= 0 && g
<= 255 &&
1245 b
>= 0 && b
<= 255 )
1247 val
.m_colour
.Set(r
,g
,b
);
1259 value
= DoTranslateVal(val
);
1266 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1268 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1270 int ival
= wxPGVariantToInt(value
);
1272 SetChoicesExclusive(); // Make sure we don't corrupt colour lists of other properties
1274 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1276 // Show custom choice
1277 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1278 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1280 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1282 // Hide custom choice
1283 m_choices
.RemoveAt(GetCustomColourIndex());
1284 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1292 // -----------------------------------------------------------------------
1294 // -----------------------------------------------------------------------
1296 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1316 (const wxChar
*) NULL
1319 static unsigned long gs_cp_es_normcolour_colours
[] = {
1321 wxPG_COLOUR(128,0,0),
1322 wxPG_COLOUR(0,0,128),
1323 wxPG_COLOUR(128,0,128),
1324 wxPG_COLOUR(0,128,128),
1325 wxPG_COLOUR(128,128,128),
1326 wxPG_COLOUR(0,128,0),
1327 wxPG_COLOUR(128,128,0),
1328 wxPG_COLOUR(166,124,81),
1329 wxPG_COLOUR(0,0,255),
1330 wxPG_COLOUR(255,0,255),
1331 wxPG_COLOUR(255,0,0),
1332 wxPG_COLOUR(247,148,28),
1333 wxPG_COLOUR(192,192,192),
1334 wxPG_COLOUR(0,255,0),
1335 wxPG_COLOUR(0,255,255),
1336 wxPG_COLOUR(255,255,0),
1337 wxPG_COLOUR(255,255,255),
1341 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxColourProperty
, wxSystemColourProperty
,
1342 wxColour
, const wxColour
&, TextCtrlAndButton
)
1344 static wxPGChoices gs_wxColourProperty_choicesCache
;
1346 wxColourProperty::wxColourProperty( const wxString
& label
,
1347 const wxString
& name
,
1348 const wxColour
& value
)
1349 : wxSystemColourProperty(label
, name
, gs_cp_es_normcolour_labels
,
1351 &gs_wxColourProperty_choicesCache
, value
)
1355 m_flags
|= wxPG_PROP_TRANSLATE_CUSTOM
;
1358 wxColourProperty::~wxColourProperty()
1362 void wxColourProperty::Init( wxColour colour
)
1369 int ind
= ColToInd(colour
);
1371 ind
= m_choices
.GetCount() - 1;
1375 wxString
wxColourProperty::ValueToString( wxVariant
& value
,
1376 int argFlags
) const
1378 const wxPGEditor
* editor
= GetEditorClass();
1379 if ( editor
!= wxPGEditor_Choice
&&
1380 editor
!= wxPGEditor_ChoiceAndButton
&&
1381 editor
!= wxPGEditor_ComboBox
)
1382 argFlags
|= wxPG_PROPERTY_SPECIFIC
;
1384 return wxSystemColourProperty::ValueToString(value
, argFlags
);
1387 wxColour
wxColourProperty::GetColour( int index
) const
1389 return gs_cp_es_normcolour_colours
[m_choices
.GetValue(index
)];
1392 wxVariant
wxColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1395 variant
<< v
.m_colour
;
1399 // -----------------------------------------------------------------------
1401 // -----------------------------------------------------------------------
1403 #define wxPG_CURSOR_IMAGE_WIDTH 32
1405 #define NUM_CURSORS 28
1407 //#define wx_cp_es_syscursors_len 28
1408 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1420 wxT("Middle Button"),
1426 wxT("Question Arrow"),
1427 wxT("Right Button"),
1428 wxT("Sizing NE-SW"),
1430 wxT("Sizing NW-SE"),
1437 (const wxChar
*) NULL
1440 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1443 wxCURSOR_RIGHT_ARROW
,
1450 wxCURSOR_LEFT_BUTTON
,
1452 wxCURSOR_MIDDLE_BUTTON
,
1454 wxCURSOR_PAINT_BRUSH
,
1456 wxCURSOR_POINT_LEFT
,
1457 wxCURSOR_POINT_RIGHT
,
1458 wxCURSOR_QUESTION_ARROW
,
1459 wxCURSOR_RIGHT_BUTTON
,
1471 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1473 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1475 : wxEnumProperty( label
,
1477 gs_cp_es_syscursors_labels
,
1478 gs_cp_es_syscursors_values
,
1481 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1484 wxCursorProperty::~wxCursorProperty()
1488 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1490 #if wxPG_CAN_DRAW_CURSOR
1491 if ( item
!= -1 && item
< NUM_CURSORS
)
1492 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1499 #if wxPG_CAN_DRAW_CURSOR
1501 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1503 wxPGPaintData
& paintdata
)
1506 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1508 if ( paintdata
.m_choiceItem
>= 0 )
1510 dc
.DrawRectangle( rect
);
1512 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1514 wxStockCursor cursorIndex
=
1515 (wxStockCursor
) gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1518 if ( cursorIndex
== wxCURSOR_NONE
)
1519 cursorIndex
= wxCURSOR_ARROW
;
1521 wxCursor
cursor( cursorIndex
);
1524 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1528 (HICON
)cursor
.GetHandle(),
1533 #if !defined(__WXWINCE__)
1534 DI_COMPAT
| DI_DEFAULTSIZE
|
1545 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1546 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1548 return wxEnumProperty::GetCellRenderer(column);
1552 // -----------------------------------------------------------------------
1553 // wxImageFileProperty
1554 // -----------------------------------------------------------------------
1558 const wxString
& wxPGGetDefaultImageWildcard()
1560 // Form the wildcard, if not done yet
1561 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1566 // TODO: This section may require locking (using global).
1568 wxList
& handlers
= wxImage::GetHandlers();
1570 wxList::iterator node
;
1572 // Let's iterate over the image handler list.
1573 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1574 for ( node
= handlers
.begin(); node
!= handlers
.end(); ++node
)
1576 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1578 wxString ext_lo
= handler
->GetExtension();
1579 wxString ext_up
= ext_lo
.Upper();
1581 str
.append( ext_up
);
1582 str
.append( wxT(" files (*.") );
1583 str
.append( ext_up
);
1584 str
.append( wxT(")|*.") );
1585 str
.append( ext_lo
);
1586 str
.append( wxT("|") );
1589 str
.append ( wxT("All files (*.*)|*.*") );
1591 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1594 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1597 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1599 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1600 const wxString
& value
)
1601 : wxFileProperty(label
,name
,value
)
1603 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1605 m_pImage
= (wxImage
*) NULL
;
1606 m_pBitmap
= (wxBitmap
*) NULL
;
1609 wxImageFileProperty::~wxImageFileProperty()
1617 void wxImageFileProperty::OnSetValue()
1619 wxFileProperty::OnSetValue();
1633 wxFileName filename
= GetFileName();
1635 // Create the image thumbnail
1636 if ( filename
.FileExists() )
1638 m_pImage
= new wxImage( filename
.GetFullPath() );
1642 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1644 return wxPG_DEFAULT_IMAGE_SIZE
;
1647 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1651 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1653 // Draw the thumbnail
1655 // Create the bitmap here because required size is not known in OnSetValue().
1658 m_pImage
->Rescale( rect
.width
, rect
.height
);
1659 m_pBitmap
= new wxBitmap( *m_pImage
);
1664 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1668 // No file - just draw a white box
1669 dc
.SetBrush( *wxWHITE_BRUSH
);
1670 dc
.DrawRectangle ( rect
);
1674 #endif // wxUSE_IMAGE
1676 // -----------------------------------------------------------------------
1677 // wxMultiChoiceProperty
1678 // -----------------------------------------------------------------------
1682 #include "wx/choicdlg.h"
1684 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1685 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1687 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1688 const wxString
& name
,
1689 const wxPGChoices
& choices
,
1690 const wxArrayString
& value
)
1691 : wxPGProperty(label
,name
)
1693 m_choices
.Assign(choices
);
1697 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1698 const wxString
& name
,
1699 const wxArrayString
& strings
,
1700 const wxArrayString
& value
)
1701 : wxPGProperty(label
,name
)
1703 m_choices
.Set(strings
);
1707 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1708 const wxString
& name
,
1709 const wxArrayString
& value
)
1710 : wxPGProperty(label
,name
)
1712 wxArrayString strings
;
1713 m_choices
.Set(strings
);
1717 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1721 void wxMultiChoiceProperty::OnSetValue()
1723 GenerateValueAsString(m_value
, &m_display
);
1726 wxString
wxMultiChoiceProperty::ValueToString( wxVariant
& value
,
1727 int argFlags
) const
1729 // If possible, use cached string
1730 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1734 GenerateValueAsString(value
, &s
);
1738 void wxMultiChoiceProperty::GenerateValueAsString( wxVariant
& value
,
1739 wxString
* target
) const
1741 wxArrayString strings
;
1743 if ( value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1744 strings
= value
.GetArrayString();
1746 wxString
& tempStr
= *target
;
1748 unsigned int itemCount
= strings
.size();
1753 tempStr
.append( wxT("\"") );
1755 for ( i
= 0; i
< itemCount
; i
++ )
1757 tempStr
.append( strings
[i
] );
1758 tempStr
.append( wxT("\"") );
1759 if ( i
< (itemCount
-1) )
1760 tempStr
.append ( wxT(" \"") );
1764 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1766 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(GetValue());
1769 // Translate values to string indices.
1770 wxArrayInt selections
;
1772 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1774 for ( i
=0; i
<valueArr
.size(); i
++ )
1779 for ( i
=0; i
<valueArr
.size(); i
++ )
1781 int sIndex
= m_choices
.Index(valueArr
[i
]);
1783 selections
.Add(sIndex
);
1790 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1791 wxWindow
* WXUNUSED(primary
),
1794 if ( propgrid
->IsMainButtonEvent(event
) )
1797 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
1799 wxArrayString labels
= m_choices
.GetLabels();
1800 unsigned int choiceCount
;
1802 if ( m_choices
.IsOk() )
1803 choiceCount
= m_choices
.GetCount();
1807 // launch editor dialog
1808 wxMultiChoiceDialog
dlg( propgrid
,
1809 _("Make a selection:"),
1812 choiceCount
?&labels
[0]:NULL
,
1813 wxCHOICEDLG_STYLE
);
1815 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
1817 wxArrayString strings
= useValue
.GetArrayString();
1818 wxArrayString extraStrings
;
1820 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
1822 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
1824 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1826 wxArrayInt arrInt
= dlg
.GetSelections();
1830 // Strings that were not in list of choices
1831 wxArrayString value
;
1833 // Translate string indices to strings
1836 if ( userStringMode
== 1 )
1838 for (n
=0;n
<extraStrings
.size();n
++)
1839 value
.push_back(extraStrings
[n
]);
1843 for ( i
=0; i
<arrInt
.size(); i
++ )
1844 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
1846 if ( userStringMode
== 2 )
1848 for (n
=0;n
<extraStrings
.size();n
++)
1849 value
.push_back(extraStrings
[n
]);
1852 variant
= WXVARIANT(value
);
1854 SetValueInEvent(variant
);
1862 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1866 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1868 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
1869 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
1871 WX_PG_TOKENIZER2_END()
1873 wxVariant
v( WXVARIANT(arr
) );
1879 #endif // wxUSE_CHOICEDLG
1882 // -----------------------------------------------------------------------
1884 // -----------------------------------------------------------------------
1889 #if wxUSE_DATEPICKCTRL
1890 #define dtCtrl DatePickerCtrl
1892 #define dtCtrl TextCtrl
1895 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
1902 wxString
wxDateProperty::ms_defaultDateFormat
;
1905 wxDateProperty::wxDateProperty( const wxString
& label
,
1906 const wxString
& name
,
1907 const wxDateTime
& value
)
1908 : wxPGProperty(label
,name
)
1910 //wxPGRegisterDefaultValueType(wxDateTime)
1912 #if wxUSE_DATEPICKCTRL
1913 wxPGRegisterEditorClass(DatePickerCtrl
);
1915 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
1923 wxDateProperty::~wxDateProperty()
1927 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
1928 int WXUNUSED(argFlags
) ) const
1932 const char* c
= dt
.ParseFormat(text
, wxString(wxDefaultDateTimeFormat
), wxDefaultDateTime
, NULL
);
1943 wxString
wxDateProperty::ValueToString( wxVariant
& value
,
1944 int argFlags
) const
1946 const wxChar
* format
= (const wxChar
*) NULL
;
1948 wxDateTime dateTime
= value
.GetDateTime();
1950 if ( !dateTime
.IsValid() )
1951 return wxT("Invalid");
1953 if ( !ms_defaultDateFormat
.length() )
1955 #if wxUSE_DATEPICKCTRL
1956 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
1958 bool showCentury
= true;
1960 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
1963 if ( m_format
.length() &&
1964 !(argFlags
& wxPG_FULL_VALUE
) )
1965 format
= m_format
.c_str();
1967 // Determine default from locale
1968 // NB: This is really simple stuff, but can't figure anything
1969 // better without proper support in wxLocale
1971 format
= ms_defaultDateFormat
.c_str();
1973 return dateTime
.Format(format
);
1976 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
1978 // This code is basicly copied from datectlg.cpp's SetFormat
1983 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
1984 wxString
str(dt
.Format(wxT("%x")));
1986 const wxChar
*p
= str
.c_str();
1990 if (n
== dt
.GetDay())
1992 format
.Append(wxT("%d"));
1995 else if (n
== (int)dt
.GetMonth()+1)
1997 format
.Append(wxT("%m"));
2000 else if (n
== dt
.GetYear())
2002 format
.Append(wxT("%Y"));
2005 else if (n
== (dt
.GetYear() % 100))
2008 format
.Append(wxT("%Y"));
2010 format
.Append(wxT("%y"));
2014 format
.Append(*p
++);
2020 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
2022 if ( name
== wxPG_DATE_FORMAT
)
2024 m_format
= value
.GetString();
2027 else if ( name
== wxPG_DATE_PICKER_STYLE
)
2029 m_dpStyle
= value
.GetLong();
2030 ms_defaultDateFormat
.clear(); // This may need recalculation
2036 #endif // wxUSE_DATETIME
2039 // -----------------------------------------------------------------------
2040 // wxPropertyGridInterface
2041 // -----------------------------------------------------------------------
2043 void wxPropertyGridInterface::InitAllTypeHandlers()
2047 // -----------------------------------------------------------------------
2049 void wxPropertyGridInterface::RegisterAdditionalEditors()
2051 // Register editor classes, if necessary.
2052 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
2053 wxPropertyGrid::RegisterDefaultEditors();
2056 wxPGRegisterEditorClass(SpinCtrl
);
2058 #if wxUSE_DATEPICKCTRL
2059 wxPGRegisterEditorClass(DatePickerCtrl
);
2063 // -----------------------------------------------------------------------
2065 #endif // wxPG_INCLUDE_ADVPROPS
2067 #endif // wxUSE_PROPGRID