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 void wxSystemColourProperty::OnSetValue()
903 // Convert from generic wxobject ptr to wxPGVariantDataColour
904 if ( m_value
.GetType() == wxS("wxColour*") )
906 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
910 wxColourPropertyValue val
= GetVal(&m_value
);
912 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
920 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
921 val
.m_colour
= GetColour( val
.m_type
);
923 m_value
= TranslateVal(val
);
926 int ind
= wxNOT_FOUND
;
928 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
930 wxColourPropertyValue cpv
;
932 wxColour col
= cpv
.m_colour
;
936 SetValueToUnspecified();
937 SetIndex(wxNOT_FOUND
);
941 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
)
943 ind
= GetIndexForValue(cpv
.m_type
);
947 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
948 ind
= GetCustomColourIndex();
958 SetValueToUnspecified();
959 SetIndex(wxNOT_FOUND
);
965 if ( ind
== wxNOT_FOUND
)
966 ind
= GetCustomColourIndex();
973 wxColour
wxSystemColourProperty::GetColour( int index
) const
975 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
978 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
980 if ( index
== wxNOT_FOUND
)
981 return wxString::Format(wxT("(%i,%i,%i)"),
986 return m_choices
.GetLabel(index
);
989 wxString
wxSystemColourProperty::ValueToString( wxVariant
& value
,
992 wxColourPropertyValue val
= GetVal(&value
);
996 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
998 // GetIndex() only works reliably if wxPG_VALUE_IS_CURRENT flag is set,
999 // but we should use it whenever possible.
1002 // If custom colour was selected, use invalid index, so that
1003 // ColourToString() will return properly formatted colour text.
1004 if ( index
== GetCustomColourIndex() )
1005 index
= wxNOT_FOUND
;
1009 index
= m_choices
.Index(val
.m_type
);
1012 return ColourToString(val
.m_colour
, index
);
1016 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
1018 return wxPG_DEFAULT_IMAGE_SIZE
;
1022 int wxSystemColourProperty::GetCustomColourIndex() const
1024 return m_choices
.GetCount() - 1;
1028 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1030 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1033 wxPropertyGrid
* propgrid
= GetGrid();
1034 wxASSERT( propgrid
);
1036 // Must only occur when user triggers event
1037 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_ONCUSTOMEDITOREVENT
) )
1040 wxColourPropertyValue val
= GetVal();
1042 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1045 data
.SetChooseFull(true);
1046 data
.SetColour(val
.m_colour
);
1048 for ( i
= 0; i
< 16; i
++)
1050 wxColour
colour(i
*16, i
*16, i
*16);
1051 data
.SetCustomColour(i
, colour
);
1054 wxColourDialog
dialog(propgrid
, &data
);
1055 if ( dialog
.ShowModal() == wxID_OK
)
1057 wxColourData retData
= dialog
.GetColourData();
1058 val
.m_colour
= retData
.GetColour();
1060 variant
= DoTranslateVal(val
);
1062 SetValueInEvent(variant
);
1071 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1074 int type
= m_choices
.GetValue(index
);
1076 if ( type
== wxPG_COLOUR_CUSTOM
)
1078 QueryColourFromUser(variant
);
1082 variant
= TranslateVal( type
, GetColour(type
) );
1088 // Need to do some extra event handling.
1089 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
), wxEvent
& event
)
1091 if ( propgrid
->IsMainButtonEvent(event
) )
1093 // We need to handle button click in case editor has been
1094 // switched to one that has wxButton as well.
1096 if ( QueryColourFromUser(variant
) )
1102 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1105 virtual void Render( wxDC& dc, const wxRect& rect,
1106 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1107 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1109 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1110 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1112 dc.SetPen(*wxBLACK_PEN);
1114 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1118 const wxArrayInt& values = prop->GetValues();
1119 if ( values.GetChildCount() )
1120 colInd = values[item];
1123 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1125 else if ( !prop->IsValueUnspecified() )
1126 dc.SetBrush( prop->GetVal().m_colour );
1128 dc.SetBrush( *wxWHITE );
1130 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1131 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1132 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1133 imageRect.width, imageRect.height );
1137 text = property->GetValueAsString();
1139 text = property->GetChoiceString(item);
1140 DrawText( dc, rect, imageRect.width, text );
1145 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1147 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1150 return &g_wxPGColourPropertyRenderer;
1151 return wxEnumProperty::GetCellRenderer(column);
1154 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1155 wxPGPaintData
& paintdata
)
1159 if ( paintdata
.m_choiceItem
>= 0 && paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1160 paintdata
.m_choiceItem
!= GetCustomColourIndex() )
1162 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1163 col
= GetColour( colInd
);
1165 else if ( !IsValueUnspecified() )
1167 col
= GetVal().m_colour
;
1173 dc
.DrawRectangle(rect
);
1178 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1181 // Accept colour format "[Name] [(R,G,B)]"
1182 // Name takes precedence.
1184 wxString colourName
;
1187 int ppos
= text
.Find(wxT("("));
1189 if ( ppos
== wxNOT_FOUND
)
1195 colourName
= text
.substr(0, ppos
);
1196 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1199 // Strip spaces from extremities
1200 colourName
.Trim(true);
1201 colourName
.Trim(false);
1202 colourRGB
.Trim(true);
1204 // Validate colourRGB string - (1,1,1) is shortest allowed
1205 if ( colourRGB
.length() < 7 )
1208 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1209 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1211 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1213 // This really should not occurr...
1219 QueryColourFromUser(value
);
1223 wxColourPropertyValue val
;
1227 if ( colourName
.length() )
1229 // Try predefined colour first
1230 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1231 if ( res
&& GetIndex() >= 0 )
1233 val
.m_type
= GetIndex();
1234 if ( val
.m_type
< m_choices
.GetCount() )
1235 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1237 // Get proper colour for type.
1238 val
.m_colour
= GetColour(val
.m_type
);
1243 if ( colourRGB
.length() && !done
)
1245 // Then check custom colour.
1246 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1248 int r
= -1, g
= -1, b
= -1;
1249 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1251 if ( r
>= 0 && r
<= 255 &&
1252 g
>= 0 && g
<= 255 &&
1253 b
>= 0 && b
<= 255 )
1255 val
.m_colour
.Set(r
,g
,b
);
1267 value
= DoTranslateVal(val
);
1274 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1276 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1278 int ival
= wxPGVariantToInt(value
);
1280 SetChoicesExclusive(); // Make sure we don't corrupt colour lists of other properties
1282 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1284 // Show custom choice
1285 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1286 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1288 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1290 // Hide custom choice
1291 m_choices
.RemoveAt(GetCustomColourIndex());
1292 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1300 // -----------------------------------------------------------------------
1302 // -----------------------------------------------------------------------
1304 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1324 (const wxChar
*) NULL
1327 static unsigned long gs_cp_es_normcolour_colours
[] = {
1329 wxPG_COLOUR(128,0,0),
1330 wxPG_COLOUR(0,0,128),
1331 wxPG_COLOUR(128,0,128),
1332 wxPG_COLOUR(0,128,128),
1333 wxPG_COLOUR(128,128,128),
1334 wxPG_COLOUR(0,128,0),
1335 wxPG_COLOUR(128,128,0),
1336 wxPG_COLOUR(166,124,81),
1337 wxPG_COLOUR(0,0,255),
1338 wxPG_COLOUR(255,0,255),
1339 wxPG_COLOUR(255,0,0),
1340 wxPG_COLOUR(247,148,28),
1341 wxPG_COLOUR(192,192,192),
1342 wxPG_COLOUR(0,255,0),
1343 wxPG_COLOUR(0,255,255),
1344 wxPG_COLOUR(255,255,0),
1345 wxPG_COLOUR(255,255,255),
1349 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxColourProperty
, wxSystemColourProperty
,
1350 wxColour
, const wxColour
&, TextCtrlAndButton
)
1352 static wxPGChoices gs_wxColourProperty_choicesCache
;
1354 wxColourProperty::wxColourProperty( const wxString
& label
,
1355 const wxString
& name
,
1356 const wxColour
& value
)
1357 : wxSystemColourProperty(label
, name
, gs_cp_es_normcolour_labels
,
1359 &gs_wxColourProperty_choicesCache
, value
)
1363 m_flags
|= wxPG_PROP_TRANSLATE_CUSTOM
;
1366 wxColourProperty::~wxColourProperty()
1370 void wxColourProperty::Init( wxColour colour
)
1377 int ind
= ColToInd(colour
);
1379 ind
= m_choices
.GetCount() - 1;
1383 wxString
wxColourProperty::ValueToString( wxVariant
& value
,
1384 int argFlags
) const
1386 const wxPGEditor
* editor
= GetEditorClass();
1387 if ( editor
!= wxPGEditor_Choice
&&
1388 editor
!= wxPGEditor_ChoiceAndButton
&&
1389 editor
!= wxPGEditor_ComboBox
)
1390 argFlags
|= wxPG_PROPERTY_SPECIFIC
;
1392 return wxSystemColourProperty::ValueToString(value
, argFlags
);
1395 wxColour
wxColourProperty::GetColour( int index
) const
1397 return gs_cp_es_normcolour_colours
[m_choices
.GetValue(index
)];
1400 wxVariant
wxColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1403 variant
<< v
.m_colour
;
1407 // -----------------------------------------------------------------------
1409 // -----------------------------------------------------------------------
1411 #define wxPG_CURSOR_IMAGE_WIDTH 32
1413 #define NUM_CURSORS 28
1415 //#define wx_cp_es_syscursors_len 28
1416 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1428 wxT("Middle Button"),
1434 wxT("Question Arrow"),
1435 wxT("Right Button"),
1436 wxT("Sizing NE-SW"),
1438 wxT("Sizing NW-SE"),
1445 (const wxChar
*) NULL
1448 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1451 wxCURSOR_RIGHT_ARROW
,
1458 wxCURSOR_LEFT_BUTTON
,
1460 wxCURSOR_MIDDLE_BUTTON
,
1462 wxCURSOR_PAINT_BRUSH
,
1464 wxCURSOR_POINT_LEFT
,
1465 wxCURSOR_POINT_RIGHT
,
1466 wxCURSOR_QUESTION_ARROW
,
1467 wxCURSOR_RIGHT_BUTTON
,
1479 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1481 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1483 : wxEnumProperty( label
,
1485 gs_cp_es_syscursors_labels
,
1486 gs_cp_es_syscursors_values
,
1489 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1492 wxCursorProperty::~wxCursorProperty()
1496 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1498 #if wxPG_CAN_DRAW_CURSOR
1499 if ( item
!= -1 && item
< NUM_CURSORS
)
1500 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1507 #if wxPG_CAN_DRAW_CURSOR
1509 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1511 wxPGPaintData
& paintdata
)
1514 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1516 if ( paintdata
.m_choiceItem
>= 0 )
1518 dc
.DrawRectangle( rect
);
1520 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1522 wxStockCursor cursorIndex
=
1523 (wxStockCursor
) gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1526 if ( cursorIndex
== wxCURSOR_NONE
)
1527 cursorIndex
= wxCURSOR_ARROW
;
1529 wxCursor
cursor( cursorIndex
);
1532 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1536 (HICON
)cursor
.GetHandle(),
1541 DI_COMPAT
| DI_DEFAULTSIZE
| DI_NORMAL
1550 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1551 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1553 return wxEnumProperty::GetCellRenderer(column);
1557 // -----------------------------------------------------------------------
1558 // wxImageFileProperty
1559 // -----------------------------------------------------------------------
1563 const wxString
& wxPGGetDefaultImageWildcard()
1565 // Form the wildcard, if not done yet
1566 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1571 // TODO: This section may require locking (using global).
1573 wxList
& handlers
= wxImage::GetHandlers();
1575 wxList::iterator node
;
1577 // Let's iterate over the image handler list.
1578 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1579 for ( node
= handlers
.begin(); node
!= handlers
.end(); node
++ )
1581 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1583 wxString ext_lo
= handler
->GetExtension();
1584 wxString ext_up
= ext_lo
.Upper();
1586 str
.append( ext_up
);
1587 str
.append( wxT(" files (*.") );
1588 str
.append( ext_up
);
1589 str
.append( wxT(")|*.") );
1590 str
.append( ext_lo
);
1591 str
.append( wxT("|") );
1594 str
.append ( wxT("All files (*.*)|*.*") );
1596 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1599 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1602 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1604 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1605 const wxString
& value
)
1606 : wxFileProperty(label
,name
,value
)
1608 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1610 m_pImage
= (wxImage
*) NULL
;
1611 m_pBitmap
= (wxBitmap
*) NULL
;
1614 wxImageFileProperty::~wxImageFileProperty()
1622 void wxImageFileProperty::OnSetValue()
1624 wxFileProperty::OnSetValue();
1638 wxFileName filename
= GetFileName();
1640 // Create the image thumbnail
1641 if ( filename
.FileExists() )
1643 m_pImage
= new wxImage( filename
.GetFullPath() );
1647 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1649 return wxPG_DEFAULT_IMAGE_SIZE
;
1652 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1656 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1658 // Draw the thumbnail
1660 // Create the bitmap here because required size is not known in OnSetValue().
1663 m_pImage
->Rescale( rect
.width
, rect
.height
);
1664 m_pBitmap
= new wxBitmap( *m_pImage
);
1669 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1673 // No file - just draw a white box
1674 dc
.SetBrush( *wxWHITE_BRUSH
);
1675 dc
.DrawRectangle ( rect
);
1679 #endif // wxUSE_IMAGE
1681 // -----------------------------------------------------------------------
1682 // wxMultiChoiceProperty
1683 // -----------------------------------------------------------------------
1687 #include "wx/choicdlg.h"
1689 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1690 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1692 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1693 const wxString
& name
,
1694 const wxPGChoices
& choices
,
1695 const wxArrayString
& value
)
1696 : wxPGProperty(label
,name
)
1698 m_choices
.Assign(choices
);
1702 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1703 const wxString
& name
,
1704 const wxArrayString
& strings
,
1705 const wxArrayString
& value
)
1706 : wxPGProperty(label
,name
)
1708 m_choices
.Set(strings
);
1712 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1713 const wxString
& name
,
1714 const wxArrayString
& value
)
1715 : wxPGProperty(label
,name
)
1717 wxArrayString strings
;
1718 m_choices
.Set(strings
);
1722 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1726 void wxMultiChoiceProperty::OnSetValue()
1728 GenerateValueAsString(m_value
, &m_display
);
1731 wxString
wxMultiChoiceProperty::ValueToString( wxVariant
& value
,
1732 int argFlags
) const
1734 // If possible, use cached string
1735 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1739 GenerateValueAsString(value
, &s
);
1743 void wxMultiChoiceProperty::GenerateValueAsString( wxVariant
& value
,
1744 wxString
* target
) const
1746 wxArrayString strings
;
1748 if ( value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1749 strings
= value
.GetArrayString();
1751 wxString
& tempStr
= *target
;
1753 unsigned int itemCount
= strings
.size();
1758 tempStr
.append( wxT("\"") );
1760 for ( i
= 0; i
< itemCount
; i
++ )
1762 tempStr
.append( strings
[i
] );
1763 tempStr
.append( wxT("\"") );
1764 if ( i
< (itemCount
-1) )
1765 tempStr
.append ( wxT(" \"") );
1769 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1771 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(GetValue());
1774 // Translate values to string indices.
1775 wxArrayInt selections
;
1777 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1779 for ( i
=0; i
<valueArr
.size(); i
++ )
1784 for ( i
=0; i
<valueArr
.size(); i
++ )
1786 int sIndex
= m_choices
.Index(valueArr
[i
]);
1788 selections
.Add(sIndex
);
1795 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1796 wxWindow
* WXUNUSED(primary
),
1799 if ( propgrid
->IsMainButtonEvent(event
) )
1802 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
1804 wxArrayString labels
= m_choices
.GetLabels();
1805 unsigned int choiceCount
;
1807 if ( m_choices
.IsOk() )
1808 choiceCount
= m_choices
.GetCount();
1812 // launch editor dialog
1813 wxMultiChoiceDialog
dlg( propgrid
,
1814 _("Make a selection:"),
1817 choiceCount
?&labels
[0]:NULL
,
1818 wxCHOICEDLG_STYLE
);
1820 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
1822 wxArrayString strings
= useValue
.GetArrayString();
1823 wxArrayString extraStrings
;
1825 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
1827 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
1829 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1831 wxArrayInt arrInt
= dlg
.GetSelections();
1835 // Strings that were not in list of choices
1836 wxArrayString value
;
1838 // Translate string indices to strings
1841 if ( userStringMode
== 1 )
1843 for (n
=0;n
<extraStrings
.size();n
++)
1844 value
.push_back(extraStrings
[n
]);
1848 for ( i
=0; i
<arrInt
.size(); i
++ )
1849 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
1851 if ( userStringMode
== 2 )
1853 for (n
=0;n
<extraStrings
.size();n
++)
1854 value
.push_back(extraStrings
[n
]);
1857 variant
= WXVARIANT(value
);
1859 SetValueInEvent(variant
);
1867 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1871 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1873 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
1874 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
1876 WX_PG_TOKENIZER2_END()
1878 wxVariant
v( WXVARIANT(arr
) );
1884 #endif // wxUSE_CHOICEDLG
1887 // -----------------------------------------------------------------------
1889 // -----------------------------------------------------------------------
1894 #if wxUSE_DATEPICKCTRL
1895 #define dtCtrl DatePickerCtrl
1897 #define dtCtrl TextCtrl
1900 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
1907 wxString
wxDateProperty::ms_defaultDateFormat
;
1910 wxDateProperty::wxDateProperty( const wxString
& label
,
1911 const wxString
& name
,
1912 const wxDateTime
& value
)
1913 : wxPGProperty(label
,name
)
1915 //wxPGRegisterDefaultValueType(wxDateTime)
1917 #if wxUSE_DATEPICKCTRL
1918 wxPGRegisterEditorClass(DatePickerCtrl
);
1920 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
1928 wxDateProperty::~wxDateProperty()
1932 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
1933 int WXUNUSED(argFlags
) ) const
1937 const char* c
= dt
.ParseFormat(text
, wxString(wxDefaultDateTimeFormat
), wxDefaultDateTime
, NULL
);
1948 wxString
wxDateProperty::ValueToString( wxVariant
& value
,
1949 int argFlags
) const
1951 const wxChar
* format
= (const wxChar
*) NULL
;
1953 wxDateTime dateTime
= value
.GetDateTime();
1955 if ( !dateTime
.IsValid() )
1956 return wxT("Invalid");
1958 if ( !ms_defaultDateFormat
.length() )
1960 #if wxUSE_DATEPICKCTRL
1961 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
1963 bool showCentury
= true;
1965 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
1968 if ( m_format
.length() &&
1969 !(argFlags
& wxPG_FULL_VALUE
) )
1970 format
= m_format
.c_str();
1972 // Determine default from locale
1973 // NB: This is really simple stuff, but can't figure anything
1974 // better without proper support in wxLocale
1976 format
= ms_defaultDateFormat
.c_str();
1978 return dateTime
.Format(format
);
1981 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
1983 // This code is basicly copied from datectlg.cpp's SetFormat
1988 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
1989 wxString
str(dt
.Format(wxT("%x")));
1991 const wxChar
*p
= str
.c_str();
1995 if (n
== dt
.GetDay())
1997 format
.Append(wxT("%d"));
2000 else if (n
== (int)dt
.GetMonth()+1)
2002 format
.Append(wxT("%m"));
2005 else if (n
== dt
.GetYear())
2007 format
.Append(wxT("%Y"));
2010 else if (n
== (dt
.GetYear() % 100))
2013 format
.Append(wxT("%Y"));
2015 format
.Append(wxT("%y"));
2019 format
.Append(*p
++);
2025 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
2027 if ( name
== wxPG_DATE_FORMAT
)
2029 m_format
= value
.GetString();
2032 else if ( name
== wxPG_DATE_PICKER_STYLE
)
2034 m_dpStyle
= value
.GetLong();
2035 ms_defaultDateFormat
.clear(); // This may need recalculation
2041 #endif // wxUSE_DATETIME
2044 // -----------------------------------------------------------------------
2045 // wxPropertyGridInterface
2046 // -----------------------------------------------------------------------
2048 void wxPropertyGridInterface::InitAllTypeHandlers()
2052 // -----------------------------------------------------------------------
2054 void wxPropertyGridInterface::RegisterAdditionalEditors()
2056 // Register editor classes, if necessary.
2057 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
2058 wxPropertyGrid::RegisterDefaultEditors();
2061 wxPGRegisterEditorClass(SpinCtrl
);
2063 #if wxUSE_DATEPICKCTRL
2064 wxPGRegisterEditorClass(DatePickerCtrl
);
2068 // -----------------------------------------------------------------------
2070 #endif // wxPG_INCLUDE_ADVPROPS
2072 #endif // wxUSE_PROPGRID