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 wxFontEnumerator enumerator
;
457 enumerator
.EnumerateFacenames();
459 #if wxMINOR_VERSION > 6
460 wxArrayString faceNames
= enumerator
.GetFacenames();
462 wxArrayString
& faceNames
= *enumerator
.GetFacenames();
467 wxPGGlobalVars
->m_fontFamilyChoices
= new wxPGChoices(faceNames
);
470 wxString
emptyString(wxEmptyString
);
475 SetParentalType(wxPG_PROP_AGGREGATE
);
477 AddChild( new wxIntProperty( _("Point Size"), wxS("Point Size"),(long)font
.GetPointSize() ) );
479 AddChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
480 gs_fp_es_family_labels
,gs_fp_es_family_values
,
483 wxString faceName
= font
.GetFaceName();
484 // If font was not in there, add it now
485 if ( faceName
.length() &&
486 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
487 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
489 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"), wxS("Face Name"),
490 *wxPGGlobalVars
->m_fontFamilyChoices
);
492 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
496 AddChild( new wxEnumProperty(_("Style"), wxS("Style"),
497 gs_fp_es_style_labels
,gs_fp_es_style_values
,font
.GetStyle()) );
499 AddChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
500 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,font
.GetWeight()) );
502 AddChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
503 font
.GetUnderlined()) );
506 wxFontProperty::~wxFontProperty() { }
508 void wxFontProperty::OnSetValue()
515 font
= wxFont(10,wxSWISS
,wxNORMAL
,wxNORMAL
);
520 wxString
wxFontProperty::ValueToString( wxVariant
& value
,
523 return wxPGProperty::ValueToString(value
, argFlags
);
526 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
529 if ( propgrid
->IsMainButtonEvent(event
) )
531 // Update value from last minute changes
532 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
537 data
.SetInitialFont( font
);
538 data
.SetColour(*wxBLACK
);
540 wxFontDialog
dlg(propgrid
, data
);
541 if ( dlg
.ShowModal() == wxID_OK
)
543 propgrid
->EditorsValueWasModified();
546 variant
<< dlg
.GetFontData().GetChosenFont();
547 SetValueInEvent( variant
);
554 void wxFontProperty::RefreshChildren()
556 if ( !GetChildCount() ) return;
559 Item(0)->SetValue( (long)font
.GetPointSize() );
560 Item(1)->SetValue( (long)font
.GetFamily() );
561 Item(2)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
562 Item(3)->SetValue( (long)font
.GetStyle() );
563 Item(4)->SetValue( (long)font
.GetWeight() );
564 Item(5)->SetValue( font
.GetUnderlined() );
567 void wxFontProperty::ChildChanged( wxVariant
& thisValue
, int ind
, wxVariant
& childValue
) const
574 font
.SetPointSize( wxPGVariantToInt(childValue
) );
578 int fam
= childValue
.GetLong();
579 if ( fam
< wxDEFAULT
||
582 font
.SetFamily( fam
);
587 int faceIndex
= childValue
.GetLong();
589 if ( faceIndex
>= 0 )
590 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
592 font
.SetFaceName( faceName
);
596 int st
= childValue
.GetLong();
597 if ( st
!= wxFONTSTYLE_NORMAL
&&
598 st
!= wxFONTSTYLE_SLANT
&&
599 st
!= wxFONTSTYLE_ITALIC
)
600 st
= wxFONTWEIGHT_NORMAL
;
605 int wt
= childValue
.GetLong();
606 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
607 wt
!= wxFONTWEIGHT_LIGHT
&&
608 wt
!= wxFONTWEIGHT_BOLD
)
609 wt
= wxFONTWEIGHT_NORMAL
;
610 font
.SetWeight( wt
);
614 font
.SetUnderlined( childValue
.GetBool() );
621 wxSize wxFontProperty::OnMeasureImage() const
623 return wxSize(-1,-1);
626 void wxFontProperty::OnCustomPaint(wxDC& dc,
628 wxPGPaintData& paintData)
631 if ( paintData.m_choiceItem >= 0 )
632 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
634 drawFace = m_value_wxFont.GetFaceName();
636 if ( drawFace.length() )
638 // Draw the background
639 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
640 //dc.SetBrush( *wxWHITE_BRUSH );
641 //dc.SetPen( *wxMEDIUM_GREY_PEN );
642 dc.DrawRectangle( rect );
644 wxFont oldFont = dc.GetFont();
645 wxFont drawFont(oldFont.GetPointSize(),
646 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
647 dc.SetFont(drawFont);
649 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
650 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
656 // No file - just draw a white box
657 dc.SetBrush ( *wxWHITE_BRUSH );
658 dc.DrawRectangle ( rect );
664 // -----------------------------------------------------------------------
665 // wxSystemColourProperty
666 // -----------------------------------------------------------------------
668 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
669 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
671 #include "wx/colordlg.h"
673 //#define wx_cp_es_syscolours_len 25
674 static const wxChar
* gs_cp_es_syscolour_labels
[] = {
677 wxT("ActiveCaption"),
679 wxT("ButtonHighlight"),
688 wxT("HighlightText"),
689 wxT("InactiveBorder"),
690 wxT("InactiveCaption"),
691 wxT("InactiveCaptionText"),
703 static long gs_cp_es_syscolour_values
[] = {
704 wxSYS_COLOUR_APPWORKSPACE
,
705 wxSYS_COLOUR_ACTIVEBORDER
,
706 wxSYS_COLOUR_ACTIVECAPTION
,
707 wxSYS_COLOUR_BTNFACE
,
708 wxSYS_COLOUR_BTNHIGHLIGHT
,
709 wxSYS_COLOUR_BTNSHADOW
,
710 wxSYS_COLOUR_BTNTEXT
,
711 wxSYS_COLOUR_CAPTIONTEXT
,
712 wxSYS_COLOUR_3DDKSHADOW
,
713 wxSYS_COLOUR_3DLIGHT
,
714 wxSYS_COLOUR_BACKGROUND
,
715 wxSYS_COLOUR_GRAYTEXT
,
716 wxSYS_COLOUR_HIGHLIGHT
,
717 wxSYS_COLOUR_HIGHLIGHTTEXT
,
718 wxSYS_COLOUR_INACTIVEBORDER
,
719 wxSYS_COLOUR_INACTIVECAPTION
,
720 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
722 wxSYS_COLOUR_SCROLLBAR
,
724 wxSYS_COLOUR_INFOTEXT
,
726 wxSYS_COLOUR_WINDOWFRAME
,
727 wxSYS_COLOUR_WINDOWTEXT
,
732 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
735 // Class body is in advprops.h
737 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
738 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
741 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
743 wxColourPropertyValue cpv
;
746 cpv
.Init( type
, colour
);
748 cpv
.Init( type
, *wxWHITE
);
750 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
758 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
761 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
762 const wxColourPropertyValue
& value
)
763 : wxEnumProperty( label
,
765 gs_cp_es_syscolour_labels
,
766 gs_cp_es_syscolour_values
,
767 &gs_wxSystemColourProperty_choicesCache
)
770 Init( value
.m_type
, value
.m_colour
);
772 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
776 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
777 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
778 const wxColourPropertyValue
& value
)
779 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
782 Init( value
.m_type
, value
.m_colour
);
784 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
788 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
789 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
790 const wxColour
& value
)
791 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
794 Init( wxPG_COLOUR_CUSTOM
, value
);
796 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
800 wxSystemColourProperty::~wxSystemColourProperty() { }
803 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
808 if ( pVariant
->IsNull() )
809 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
811 if ( pVariant
->GetType() == wxS("wxColourPropertyValue") )
813 wxColourPropertyValue v
;
819 bool variantProcessed
= true;
821 if ( pVariant
->GetType() == wxS("wxColour*") )
823 wxColour
* pCol
= wxStaticCast(pVariant
->GetWxObjectPtr(), wxColour
);
826 else if ( pVariant
->GetType() == wxS("wxColour") )
830 else if ( pVariant
->GetType() == wxArrayInt_VariantType
)
832 // This code is mostly needed for wxPython bindings, which
833 // may offer tuple of integers as colour value.
837 if ( arr
.size() >= 3 )
845 if ( arr
.size() >= 4 )
848 col
= wxColour(r
, g
, b
, a
);
852 variantProcessed
= false;
857 variantProcessed
= false;
860 if ( !variantProcessed
)
861 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
863 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
865 int colInd
= ColToInd(col
);
866 if ( colInd
!= wxNOT_FOUND
)
872 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
879 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
882 size_t i_max
= m_choices
.GetCount() - 1;
884 for ( i
=0; i
<i_max
; i
++ )
886 int ind
= m_choices
[i
].GetValue();
888 if ( colour
== GetColour(ind
) )
890 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
891 GetClassName(),GetLabel().c_str(),
892 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
893 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
901 static inline wxColour
wxColourFromPGLong( long col
)
903 return wxColour((col
&0xFF),((col
>>8)&0xFF),((col
>>16)&0xFF));
907 void wxSystemColourProperty::OnSetValue()
909 // Convert from generic wxobject ptr to wxPGVariantDataColour
910 if ( m_value
.GetType() == wxS("wxColour*") )
912 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
916 wxColourPropertyValue val
= GetVal(&m_value
);
918 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
926 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
927 val
.m_colour
= GetColour( val
.m_type
);
929 m_value
= TranslateVal(val
);
932 int ind
= wxNOT_FOUND
;
934 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
936 wxColourPropertyValue cpv
;
938 wxColour col
= cpv
.m_colour
;
942 SetValueToUnspecified();
943 SetIndex(wxNOT_FOUND
);
947 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
)
949 ind
= GetIndexForValue(cpv
.m_type
);
953 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
954 ind
= GetCustomColourIndex();
964 SetValueToUnspecified();
965 SetIndex(wxNOT_FOUND
);
971 if ( ind
== wxNOT_FOUND
)
972 ind
= GetCustomColourIndex();
979 wxColour
wxSystemColourProperty::GetColour( int index
) const
981 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
984 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
986 if ( index
== wxNOT_FOUND
)
987 return wxString::Format(wxT("(%i,%i,%i)"),
992 return m_choices
.GetLabel(index
);
995 wxString
wxSystemColourProperty::ValueToString( wxVariant
& value
,
998 wxColourPropertyValue val
= GetVal(&value
);
1002 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1004 // GetIndex() only works reliably if wxPG_VALUE_IS_CURRENT flag is set,
1005 // but we should use it whenever possible.
1008 // If custom colour was selected, use invalid index, so that
1009 // ColourToString() will return properly formatted colour text.
1010 if ( index
== GetCustomColourIndex() )
1011 index
= wxNOT_FOUND
;
1015 index
= m_choices
.Index(val
.m_type
);
1018 return ColourToString(val
.m_colour
, index
);
1022 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
1024 return wxPG_DEFAULT_IMAGE_SIZE
;
1028 int wxSystemColourProperty::GetCustomColourIndex() const
1030 return m_choices
.GetCount() - 1;
1034 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1036 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1039 wxPropertyGrid
* propgrid
= GetGrid();
1040 wxASSERT( propgrid
);
1042 // Must only occur when user triggers event
1043 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_ONCUSTOMEDITOREVENT
) )
1046 wxColourPropertyValue val
= GetVal();
1048 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1051 data
.SetChooseFull(true);
1052 data
.SetColour(val
.m_colour
);
1054 for ( i
= 0; i
< 16; i
++)
1056 wxColour
colour(i
*16, i
*16, i
*16);
1057 data
.SetCustomColour(i
, colour
);
1060 wxColourDialog
dialog(propgrid
, &data
);
1061 if ( dialog
.ShowModal() == wxID_OK
)
1063 wxColourData retData
= dialog
.GetColourData();
1064 val
.m_colour
= retData
.GetColour();
1066 variant
= DoTranslateVal(val
);
1068 SetValueInEvent(variant
);
1077 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1080 int type
= m_choices
.GetValue(index
);
1082 if ( type
== wxPG_COLOUR_CUSTOM
)
1084 QueryColourFromUser(variant
);
1088 variant
= TranslateVal( type
, GetColour(type
) );
1094 // Need to do some extra event handling.
1095 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
), wxEvent
& event
)
1097 if ( propgrid
->IsMainButtonEvent(event
) )
1099 // We need to handle button click in case editor has been
1100 // switched to one that has wxButton as well.
1102 if ( QueryColourFromUser(variant
) )
1108 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1111 virtual void Render( wxDC& dc, const wxRect& rect,
1112 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1113 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1115 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1116 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1118 dc.SetPen(*wxBLACK_PEN);
1120 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1124 const wxArrayInt& values = prop->GetValues();
1125 if ( values.GetChildCount() )
1126 colInd = values[item];
1129 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1131 else if ( !prop->IsValueUnspecified() )
1132 dc.SetBrush( prop->GetVal().m_colour );
1134 dc.SetBrush( *wxWHITE );
1136 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1137 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1138 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1139 imageRect.width, imageRect.height );
1143 text = property->GetValueAsString();
1145 text = property->GetChoiceString(item);
1146 DrawText( dc, rect, imageRect.width, text );
1151 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1153 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1156 return &g_wxPGColourPropertyRenderer;
1157 return wxEnumProperty::GetCellRenderer(column);
1160 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1161 wxPGPaintData
& paintdata
)
1165 if ( paintdata
.m_choiceItem
>= 0 && paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1166 paintdata
.m_choiceItem
!= GetCustomColourIndex() )
1168 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1169 col
= GetColour( colInd
);
1171 else if ( !IsValueUnspecified() )
1173 col
= GetVal().m_colour
;
1179 dc
.DrawRectangle(rect
);
1184 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1187 // Accept colour format "[Name] [(R,G,B)]"
1188 // Name takes precedence.
1190 wxString colourName
;
1193 int ppos
= text
.Find(wxT("("));
1195 if ( ppos
== wxNOT_FOUND
)
1201 colourName
= text
.substr(0, ppos
);
1202 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1205 // Strip spaces from extremities
1206 colourName
.Trim(true);
1207 colourName
.Trim(false);
1208 colourRGB
.Trim(true);
1210 // Validate colourRGB string - (1,1,1) is shortest allowed
1211 if ( colourRGB
.length() < 7 )
1214 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1215 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1217 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1219 // This really should not occurr...
1225 QueryColourFromUser(value
);
1229 wxColourPropertyValue val
;
1233 if ( colourName
.length() )
1235 // Try predefined colour first
1236 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1237 if ( res
&& GetIndex() >= 0 )
1239 val
.m_type
= GetIndex();
1240 if ( val
.m_type
>= 0 && val
.m_type
< m_choices
.GetCount() )
1241 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1243 // Get proper colour for type.
1244 val
.m_colour
= GetColour(val
.m_type
);
1249 if ( colourRGB
.length() && !done
)
1251 // Then check custom colour.
1252 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1254 int r
= -1, g
= -1, b
= -1;
1255 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1257 if ( r
>= 0 && r
<= 255 &&
1258 g
>= 0 && g
<= 255 &&
1259 b
>= 0 && b
<= 255 )
1261 val
.m_colour
.Set(r
,g
,b
);
1273 value
= DoTranslateVal(val
);
1280 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1282 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1284 int ival
= wxPGVariantToInt(value
);
1286 SetChoicesExclusive(); // Make sure we don't corrupt colour lists of other properties
1288 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1290 // Show custom choice
1291 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1292 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1294 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1296 // Hide custom choice
1297 m_choices
.RemoveAt(GetCustomColourIndex());
1298 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1306 // -----------------------------------------------------------------------
1308 // -----------------------------------------------------------------------
1310 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1330 (const wxChar
*) NULL
1333 static unsigned long gs_cp_es_normcolour_colours
[] = {
1335 wxPG_COLOUR(128,0,0),
1336 wxPG_COLOUR(0,0,128),
1337 wxPG_COLOUR(128,0,128),
1338 wxPG_COLOUR(0,128,128),
1339 wxPG_COLOUR(128,128,128),
1340 wxPG_COLOUR(0,128,0),
1341 wxPG_COLOUR(128,128,0),
1342 wxPG_COLOUR(166,124,81),
1343 wxPG_COLOUR(0,0,255),
1344 wxPG_COLOUR(255,0,255),
1345 wxPG_COLOUR(255,0,0),
1346 wxPG_COLOUR(247,148,28),
1347 wxPG_COLOUR(192,192,192),
1348 wxPG_COLOUR(0,255,0),
1349 wxPG_COLOUR(0,255,255),
1350 wxPG_COLOUR(255,255,0),
1351 wxPG_COLOUR(255,255,255),
1355 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxColourProperty
, wxSystemColourProperty
,
1356 wxColour
, const wxColour
&, TextCtrlAndButton
)
1358 static wxPGChoices gs_wxColourProperty_choicesCache
;
1360 wxColourProperty::wxColourProperty( const wxString
& label
,
1361 const wxString
& name
,
1362 const wxColour
& value
)
1363 : wxSystemColourProperty(label
, name
, gs_cp_es_normcolour_labels
,
1365 &gs_wxColourProperty_choicesCache
, value
)
1369 m_flags
|= wxPG_PROP_TRANSLATE_CUSTOM
;
1372 wxColourProperty::~wxColourProperty()
1376 void wxColourProperty::Init( wxColour colour
)
1383 int ind
= ColToInd(colour
);
1385 ind
= m_choices
.GetCount() - 1;
1389 wxString
wxColourProperty::ValueToString( wxVariant
& value
,
1390 int argFlags
) const
1392 const wxPGEditor
* editor
= GetEditorClass();
1393 if ( editor
!= wxPGEditor_Choice
&&
1394 editor
!= wxPGEditor_ChoiceAndButton
&&
1395 editor
!= wxPGEditor_ComboBox
)
1396 argFlags
|= wxPG_PROPERTY_SPECIFIC
;
1398 return wxSystemColourProperty::ValueToString(value
, argFlags
);
1401 wxColour
wxColourProperty::GetColour( int index
) const
1403 return gs_cp_es_normcolour_colours
[m_choices
.GetValue(index
)];
1406 wxVariant
wxColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1409 variant
<< v
.m_colour
;
1413 // -----------------------------------------------------------------------
1415 // -----------------------------------------------------------------------
1417 #define wxPG_CURSOR_IMAGE_WIDTH 32
1419 #define NUM_CURSORS 28
1421 //#define wx_cp_es_syscursors_len 28
1422 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1434 wxT("Middle Button"),
1440 wxT("Question Arrow"),
1441 wxT("Right Button"),
1442 wxT("Sizing NE-SW"),
1444 wxT("Sizing NW-SE"),
1451 (const wxChar
*) NULL
1454 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1457 wxCURSOR_RIGHT_ARROW
,
1464 wxCURSOR_LEFT_BUTTON
,
1466 wxCURSOR_MIDDLE_BUTTON
,
1468 wxCURSOR_PAINT_BRUSH
,
1470 wxCURSOR_POINT_LEFT
,
1471 wxCURSOR_POINT_RIGHT
,
1472 wxCURSOR_QUESTION_ARROW
,
1473 wxCURSOR_RIGHT_BUTTON
,
1485 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1487 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1489 : wxEnumProperty( label
,
1491 gs_cp_es_syscursors_labels
,
1492 gs_cp_es_syscursors_values
,
1495 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1498 wxCursorProperty::~wxCursorProperty()
1502 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1504 #if wxPG_CAN_DRAW_CURSOR
1505 if ( item
!= -1 && item
< NUM_CURSORS
)
1506 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1513 #if wxPG_CAN_DRAW_CURSOR
1515 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1517 wxPGPaintData
& paintdata
)
1520 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1522 if ( paintdata
.m_choiceItem
>= 0 )
1524 dc
.DrawRectangle( rect
);
1526 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1528 wxStockCursor cursorIndex
=
1529 (wxStockCursor
) gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1532 if ( cursorIndex
== wxCURSOR_NONE
)
1533 cursorIndex
= wxCURSOR_ARROW
;
1535 wxCursor
cursor( cursorIndex
);
1538 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1542 (HICON
)cursor
.GetHandle(),
1547 DI_COMPAT
| DI_DEFAULTSIZE
| DI_NORMAL
1556 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1557 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1559 return wxEnumProperty::GetCellRenderer(column);
1563 // -----------------------------------------------------------------------
1564 // wxImageFileProperty
1565 // -----------------------------------------------------------------------
1569 const wxString
& wxPGGetDefaultImageWildcard()
1571 // Form the wildcard, if not done yet
1572 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1577 // TODO: This section may require locking (using global).
1579 wxList
& handlers
= wxImage::GetHandlers();
1581 wxList::iterator node
;
1583 // Let's iterate over the image handler list.
1584 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1585 for ( node
= handlers
.begin(); node
!= handlers
.end(); node
++ )
1587 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1589 wxString ext_lo
= handler
->GetExtension();
1590 wxString ext_up
= ext_lo
.Upper();
1592 str
.append( ext_up
);
1593 str
.append( wxT(" files (*.") );
1594 str
.append( ext_up
);
1595 str
.append( wxT(")|*.") );
1596 str
.append( ext_lo
);
1597 str
.append( wxT("|") );
1600 str
.append ( wxT("All files (*.*)|*.*") );
1602 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1605 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1608 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1610 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1611 const wxString
& value
)
1612 : wxFileProperty(label
,name
,value
)
1614 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1616 m_pImage
= (wxImage
*) NULL
;
1617 m_pBitmap
= (wxBitmap
*) NULL
;
1620 wxImageFileProperty::~wxImageFileProperty()
1628 void wxImageFileProperty::OnSetValue()
1630 wxFileProperty::OnSetValue();
1644 wxFileName filename
= GetFileName();
1646 // Create the image thumbnail
1647 if ( filename
.FileExists() )
1649 m_pImage
= new wxImage( filename
.GetFullPath() );
1653 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1655 return wxPG_DEFAULT_IMAGE_SIZE
;
1658 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1662 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1664 // Draw the thumbnail
1666 // Create the bitmap here because required size is not known in OnSetValue().
1669 m_pImage
->Rescale( rect
.width
, rect
.height
);
1670 m_pBitmap
= new wxBitmap( *m_pImage
);
1675 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1679 // No file - just draw a white box
1680 dc
.SetBrush( *wxWHITE_BRUSH
);
1681 dc
.DrawRectangle ( rect
);
1685 #endif // wxUSE_IMAGE
1687 // -----------------------------------------------------------------------
1688 // wxMultiChoiceProperty
1689 // -----------------------------------------------------------------------
1693 #include "wx/choicdlg.h"
1695 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1696 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1698 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1699 const wxString
& name
,
1700 const wxPGChoices
& choices
,
1701 const wxArrayString
& value
)
1702 : wxPGProperty(label
,name
)
1704 m_choices
.Assign(choices
);
1708 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1709 const wxString
& name
,
1710 const wxArrayString
& strings
,
1711 const wxArrayString
& value
)
1712 : wxPGProperty(label
,name
)
1714 m_choices
.Set(strings
);
1718 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1719 const wxString
& name
,
1720 const wxArrayString
& value
)
1721 : wxPGProperty(label
,name
)
1723 wxArrayString strings
;
1724 m_choices
.Set(strings
);
1728 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1732 void wxMultiChoiceProperty::OnSetValue()
1734 GenerateValueAsString(m_value
, &m_display
);
1737 wxString
wxMultiChoiceProperty::ValueToString( wxVariant
& value
,
1738 int argFlags
) const
1740 // If possible, use cached string
1741 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1745 GenerateValueAsString(value
, &s
);
1749 void wxMultiChoiceProperty::GenerateValueAsString( wxVariant
& value
,
1750 wxString
* target
) const
1752 wxArrayString strings
;
1754 if ( value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1755 strings
= value
.GetArrayString();
1757 wxString
& tempStr
= *target
;
1759 unsigned int itemCount
= strings
.size();
1764 tempStr
.append( wxT("\"") );
1766 for ( i
= 0; i
< itemCount
; i
++ )
1768 tempStr
.append( strings
[i
] );
1769 tempStr
.append( wxT("\"") );
1770 if ( i
< (itemCount
-1) )
1771 tempStr
.append ( wxT(" \"") );
1775 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1777 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(GetValue());
1780 // Translate values to string indices.
1781 wxArrayInt selections
;
1783 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1785 for ( i
=0; i
<valueArr
.size(); i
++ )
1790 for ( i
=0; i
<valueArr
.size(); i
++ )
1792 int sIndex
= m_choices
.Index(valueArr
[i
]);
1794 selections
.Add(sIndex
);
1801 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1802 wxWindow
* WXUNUSED(primary
),
1805 if ( propgrid
->IsMainButtonEvent(event
) )
1808 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
1810 wxArrayString labels
= m_choices
.GetLabels();
1811 unsigned int choiceCount
;
1813 if ( m_choices
.IsOk() )
1814 choiceCount
= m_choices
.GetCount();
1818 // launch editor dialog
1819 wxMultiChoiceDialog
dlg( propgrid
,
1820 _("Make a selection:"),
1823 choiceCount
?&labels
[0]:NULL
,
1824 wxCHOICEDLG_STYLE
);
1826 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
1828 wxArrayString strings
= useValue
.GetArrayString();
1829 wxArrayString extraStrings
;
1831 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
1833 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
1835 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1837 wxArrayInt arrInt
= dlg
.GetSelections();
1841 // Strings that were not in list of choices
1842 wxArrayString value
;
1844 // Translate string indices to strings
1847 if ( userStringMode
== 1 )
1849 for (n
=0;n
<extraStrings
.size();n
++)
1850 value
.push_back(extraStrings
[n
]);
1854 for ( i
=0; i
<arrInt
.size(); i
++ )
1855 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
1857 if ( userStringMode
== 2 )
1859 for (n
=0;n
<extraStrings
.size();n
++)
1860 value
.push_back(extraStrings
[n
]);
1863 variant
= WXVARIANT(value
);
1865 SetValueInEvent(variant
);
1873 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1877 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1879 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
1880 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
1882 WX_PG_TOKENIZER2_END()
1884 wxVariant
v( WXVARIANT(arr
) );
1890 #endif // wxUSE_CHOICEDLG
1893 // -----------------------------------------------------------------------
1895 // -----------------------------------------------------------------------
1900 #if wxUSE_DATEPICKCTRL
1901 #define dtCtrl DatePickerCtrl
1903 #define dtCtrl TextCtrl
1906 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
1913 wxString
wxDateProperty::ms_defaultDateFormat
;
1916 wxDateProperty::wxDateProperty( const wxString
& label
,
1917 const wxString
& name
,
1918 const wxDateTime
& value
)
1919 : wxPGProperty(label
,name
)
1921 //wxPGRegisterDefaultValueType(wxDateTime)
1923 #if wxUSE_DATEPICKCTRL
1924 wxPGRegisterEditorClass(DatePickerCtrl
);
1926 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
1934 wxDateProperty::~wxDateProperty()
1938 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
1939 int WXUNUSED(argFlags
) ) const
1943 const char* c
= dt
.ParseFormat(text
, wxString(wxDefaultDateTimeFormat
), wxDefaultDateTime
, NULL
);
1954 wxString
wxDateProperty::ValueToString( wxVariant
& value
,
1955 int argFlags
) const
1957 const wxChar
* format
= (const wxChar
*) NULL
;
1959 wxDateTime dateTime
= value
.GetDateTime();
1961 if ( !dateTime
.IsValid() )
1962 return wxT("Invalid");
1964 if ( !ms_defaultDateFormat
.length() )
1966 #if wxUSE_DATEPICKCTRL
1967 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
1969 bool showCentury
= true;
1971 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
1974 if ( m_format
.length() &&
1975 !(argFlags
& wxPG_FULL_VALUE
) )
1976 format
= m_format
.c_str();
1978 // Determine default from locale
1979 // NB: This is really simple stuff, but can't figure anything
1980 // better without proper support in wxLocale
1982 format
= ms_defaultDateFormat
.c_str();
1984 return dateTime
.Format(format
);
1987 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
1989 // This code is basicly copied from datectlg.cpp's SetFormat
1994 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
1995 wxString
str(dt
.Format(wxT("%x")));
1997 const wxChar
*p
= str
.c_str();
2001 if (n
== dt
.GetDay())
2003 format
.Append(wxT("%d"));
2006 else if (n
== (int)dt
.GetMonth()+1)
2008 format
.Append(wxT("%m"));
2011 else if (n
== dt
.GetYear())
2013 format
.Append(wxT("%Y"));
2016 else if (n
== (dt
.GetYear() % 100))
2019 format
.Append(wxT("%Y"));
2021 format
.Append(wxT("%y"));
2025 format
.Append(*p
++);
2031 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
2033 if ( name
== wxPG_DATE_FORMAT
)
2035 m_format
= value
.GetString();
2038 else if ( name
== wxPG_DATE_PICKER_STYLE
)
2040 m_dpStyle
= value
.GetLong();
2041 ms_defaultDateFormat
.clear(); // This may need recalculation
2047 #endif // wxUSE_DATETIME
2050 // -----------------------------------------------------------------------
2051 // wxPropertyGridInterface
2052 // -----------------------------------------------------------------------
2054 void wxPropertyGridInterface::InitAllTypeHandlers()
2058 // -----------------------------------------------------------------------
2060 void wxPropertyGridInterface::RegisterAdditionalEditors()
2062 // Register editor classes, if necessary.
2063 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
2064 wxPropertyGrid::RegisterDefaultEditors();
2067 wxPGRegisterEditorClass(SpinCtrl
);
2069 #if wxUSE_DATEPICKCTRL
2070 wxPGRegisterEditorClass(DatePickerCtrl
);
2074 // -----------------------------------------------------------------------
2076 #endif // wxPG_INCLUDE_ADVPROPS
2078 #endif // wxUSE_PROPGRID