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 bool operator == (const wxFont
&, const wxFont
&)
88 // Implement dynamic class for type value.
89 IMPLEMENT_DYNAMIC_CLASS(wxColourPropertyValue
, wxObject
)
91 bool operator == (const wxColourPropertyValue
& a
, const wxColourPropertyValue
& b
)
93 return ( ( a
.m_colour
== b
.m_colour
) && (a
.m_type
== b
.m_type
) );
96 bool operator == (const wxArrayInt
& array1
, const wxArrayInt
& array2
)
98 if ( array1
.size() != array2
.size() )
101 for ( i
=0; i
<array1
.size(); i
++ )
103 if ( array1
[i
] != array2
[i
] )
109 // -----------------------------------------------------------------------
110 // wxSpinCtrl-based property editor
111 // -----------------------------------------------------------------------
116 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(SpinCtrl
,
121 // Trivial destructor.
122 wxPGSpinCtrlEditor::~wxPGSpinCtrlEditor()
127 // Create controls and initialize event handling.
128 wxPGWindowList
wxPGSpinCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
129 const wxPoint
& pos
, const wxSize
& sz
) const
131 const int margin
= 1;
132 wxSize
butSz(18, sz
.y
);
133 wxSize
tcSz(sz
.x
- butSz
.x
- margin
, sz
.y
);
134 wxPoint
butPos(pos
.x
+ tcSz
.x
+ margin
, pos
.y
);
136 wxSpinButton
* wnd2
= new wxSpinButton();
140 wnd2
->Create( propgrid
->GetPanel(), wxPG_SUBID2
, butPos
, butSz
, wxSP_VERTICAL
);
142 wnd2
->SetRange( INT_MIN
, INT_MAX
);
145 wxWindowID id
= wnd2
->GetId();
146 wnd2
->Connect( id
, wxEVT_SCROLL_LINEUP
,
147 wxEventHandler(wxPropertyGrid::OnCustomEditorEvent
),
149 wnd2
->Connect( id
, wxEVT_SCROLL_LINEDOWN
,
150 wxEventHandler(wxPropertyGrid::OnCustomEditorEvent
),
153 // Let's add validator to make sure only numbers can be entered
154 wxTextValidator
validator(wxFILTER_NUMERIC
, &m_tempString
);
156 wxTextCtrl
* wnd1
= (wxTextCtrl
*) wxPGTextCtrlEditor::CreateControls( propgrid
, property
, pos
, tcSz
).m_primary
;
157 wnd1
->SetValidator(validator
);
159 wnd1
->Connect( wnd1
->GetId(), wxEVT_KEY_DOWN
,
160 wxEventHandler(wxPropertyGrid::OnCustomEditorEvent
),
163 return wxPGWindowList(wnd1
, wnd2
);
166 // Control's events are redirected here
167 bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
168 wxWindow
* wnd
, wxEvent
& event
) const
170 int evtType
= event
.GetEventType();
172 bool bigStep
= false;
174 if ( evtType
== wxEVT_KEY_DOWN
)
176 wxKeyEvent
& keyEvent
= (wxKeyEvent
&)event
;
177 keycode
= keyEvent
.GetKeyCode();
179 if ( keycode
== WXK_UP
)
180 evtType
= wxEVT_SCROLL_LINEUP
;
181 else if ( keycode
== WXK_DOWN
)
182 evtType
= wxEVT_SCROLL_LINEDOWN
;
183 else if ( keycode
== WXK_PAGEUP
)
185 evtType
= wxEVT_SCROLL_LINEUP
;
188 else if ( keycode
== WXK_PAGEDOWN
)
190 evtType
= wxEVT_SCROLL_LINEDOWN
;
195 if ( evtType
== wxEVT_SCROLL_LINEUP
|| evtType
== wxEVT_SCROLL_LINEDOWN
)
198 // Can't use wnd since it might be clipper window
199 wxTextCtrl
* tc
= wxDynamicCast(propgrid
->GetEditorControl(), wxTextCtrl
);
204 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
206 int mode
= wxPG_PROPERTY_VALIDATION_SATURATE
;
208 if ( property
->GetAttributeAsLong(wxT("Wrap"), 0) )
209 mode
= wxPG_PROPERTY_VALIDATION_WRAP
;
211 if ( property
->GetValueType() == wxT("double") )
214 double step
= property
->GetAttributeAsDouble(wxT("Step"), 1.0);
217 if ( s
.ToDouble(&v_d
) )
222 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_d
+= step
;
226 wxFloatProperty::DoValidation(property
, v_d
, NULL
, mode
);
228 wxPropertyGrid::DoubleToString(s
, v_d
, 6, true, NULL
);
238 wxLongLong_t step
= property
->GetAttributeAsLong(wxT("Step"), 1);
241 if ( s
.ToLongLong(&v_ll
, 10) )
246 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_ll
+= step
;
250 wxIntProperty::DoValidation(property
, v_ll
, NULL
, mode
);
252 s
= wxLongLong(v_ll
).ToString();
262 int ip
= tc
->GetInsertionPoint();
263 int lp
= tc
->GetLastPosition();
265 tc
->SetInsertionPoint(ip
+(tc
->GetLastPosition()-lp
));
271 return wxPGTextCtrlEditor::OnEvent(propgrid
,property
,wnd
,event
);
274 #endif // wxUSE_SPINBTN
277 // -----------------------------------------------------------------------
278 // wxDatePickerCtrl-based property editor
279 // -----------------------------------------------------------------------
281 #if wxUSE_DATEPICKCTRL
284 #include "wx/datectrl.h"
285 #include "wx/dateevt.h"
287 class wxPGDatePickerCtrlEditor
: public wxPGEditor
289 DECLARE_DYNAMIC_CLASS(wxPGDatePickerCtrlEditor
)
291 virtual ~wxPGDatePickerCtrlEditor();
293 wxString
GetName() const;
294 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
295 wxPGProperty
* property
,
297 const wxSize
& size
) const;
298 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const;
299 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
300 wxWindow
* wnd
, wxEvent
& event
) const;
301 virtual bool GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* wnd
) const;
302 virtual void SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const;
306 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(DatePickerCtrl
,
307 wxPGDatePickerCtrlEditor
,
311 wxPGDatePickerCtrlEditor::~wxPGDatePickerCtrlEditor()
315 wxPGWindowList
wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
,
316 wxPGProperty
* property
,
318 const wxSize
& sz
) const
320 wxCHECK_MSG( property
->IsKindOf(CLASSINFO(wxDateProperty
)),
322 wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
324 wxDateProperty
* prop
= (wxDateProperty
*) property
;
326 // Use two stage creation to allow cleaner display on wxMSW
327 wxDatePickerCtrl
* ctrl
= new wxDatePickerCtrl();
330 wxSize useSz
= wxDefaultSize
;
335 ctrl
->Create(propgrid
->GetPanel(),
337 prop
->GetDateValue(),
340 prop
->GetDatePickerStyle() | wxNO_BORDER
);
342 // Connect all required events to grid's OnCustomEditorEvent
343 // (all relevenat wxTextCtrl, wxComboBox and wxButton events are
344 // already connected)
345 ctrl
->Connect( wxPG_SUBID1
, wxEVT_DATE_CHANGED
,
346 wxEventHandler(wxPropertyGrid::OnCustomEditorEvent
),
356 // Copies value from property to control
357 void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const
359 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
360 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
362 // We assume that property's data type is 'int' (or something similar),
363 // thus allowing us to get raw, unchecked value via DoGetValue.
364 ctrl
->SetValue( property
->GetValue().GetDateTime() );
367 // Control's events are redirected here
368 bool wxPGDatePickerCtrlEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propgrid
),
369 wxPGProperty
* WXUNUSED(property
),
370 wxWindow
* WXUNUSED(wnd
),
371 wxEvent
& event
) const
373 if ( event
.GetEventType() == wxEVT_DATE_CHANGED
)
379 bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const
381 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
382 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
384 variant
= ctrl
->GetValue();
389 void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* WXUNUSED(wnd
) ) const
392 //wxDateProperty* prop = (wxDateProperty*) property;
396 #endif // wxUSE_DATEPICKCTRL
399 // -----------------------------------------------------------------------
401 // -----------------------------------------------------------------------
403 #include "wx/fontdlg.h"
404 #include "wx/fontenum.h"
406 static const wxChar
* gs_fp_es_family_labels
[] = {
407 wxT("Default"), wxT("Decorative"),
408 wxT("Roman"), wxT("Script"),
409 wxT("Swiss"), wxT("Modern"),
413 static long gs_fp_es_family_values
[] = {
414 wxDEFAULT
, wxDECORATIVE
,
419 static const wxChar
* gs_fp_es_style_labels
[] = {
426 static long gs_fp_es_style_values
[] = {
432 static const wxChar
* gs_fp_es_weight_labels
[] = {
439 static long gs_fp_es_weight_values
[] = {
445 // Class body is in advprops.h
448 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty
,wxPGProperty
,
449 wxFont
,const wxFont
&,TextCtrlAndButton
)
452 wxFontProperty::wxFontProperty( const wxString
& label
, const wxString
& name
,
453 const wxFont
& value
)
454 : wxPGProperty(label
,name
)
456 SetValue(WXVARIANT(value
));
458 // Initialize font family choices list
459 if ( !wxPGGlobalVars
->m_fontFamilyChoices
)
461 wxFontEnumerator enumerator
;
462 enumerator
.EnumerateFacenames();
464 #if wxMINOR_VERSION > 6
465 wxArrayString faceNames
= enumerator
.GetFacenames();
467 wxArrayString
& faceNames
= *enumerator
.GetFacenames();
472 wxPGGlobalVars
->m_fontFamilyChoices
= new wxPGChoices(faceNames
);
475 wxString
emptyString(wxEmptyString
);
480 SetParentalType(wxPG_PROP_AGGREGATE
);
482 AddChild( new wxIntProperty( _("Point Size"), wxS("Point Size"),(long)font
.GetPointSize() ) );
484 AddChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
485 gs_fp_es_family_labels
,gs_fp_es_family_values
,
488 wxString faceName
= font
.GetFaceName();
489 // If font was not in there, add it now
490 if ( faceName
.length() &&
491 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
492 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
494 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"), wxS("Face Name"),
495 *wxPGGlobalVars
->m_fontFamilyChoices
);
497 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
501 AddChild( new wxEnumProperty(_("Style"), wxS("Style"),
502 gs_fp_es_style_labels
,gs_fp_es_style_values
,font
.GetStyle()) );
504 AddChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
505 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,font
.GetWeight()) );
507 AddChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
508 font
.GetUnderlined()) );
511 wxFontProperty::~wxFontProperty() { }
513 void wxFontProperty::OnSetValue()
520 font
= wxFont(10,wxSWISS
,wxNORMAL
,wxNORMAL
);
525 wxString
wxFontProperty::ValueToString( wxVariant
& value
,
528 return wxPGProperty::ValueToString(value
, argFlags
);
531 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
534 if ( propgrid
->IsMainButtonEvent(event
) )
536 // Update value from last minute changes
537 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
542 data
.SetInitialFont( font
);
543 data
.SetColour(*wxBLACK
);
545 wxFontDialog
dlg(propgrid
, data
);
546 if ( dlg
.ShowModal() == wxID_OK
)
548 propgrid
->EditorsValueWasModified();
551 variant
<< dlg
.GetFontData().GetChosenFont();
552 SetValueInEvent( variant
);
559 void wxFontProperty::RefreshChildren()
561 if ( !GetChildCount() ) return;
564 Item(0)->SetValue( (long)font
.GetPointSize() );
565 Item(1)->SetValue( (long)font
.GetFamily() );
566 Item(2)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
567 Item(3)->SetValue( (long)font
.GetStyle() );
568 Item(4)->SetValue( (long)font
.GetWeight() );
569 Item(5)->SetValue( font
.GetUnderlined() );
572 void wxFontProperty::ChildChanged( wxVariant
& thisValue
, int ind
, wxVariant
& childValue
) const
579 font
.SetPointSize( wxPGVariantToInt(childValue
) );
583 int fam
= childValue
.GetLong();
584 if ( fam
< wxDEFAULT
||
587 font
.SetFamily( fam
);
592 int faceIndex
= childValue
.GetLong();
594 if ( faceIndex
>= 0 )
595 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
597 font
.SetFaceName( faceName
);
601 int st
= childValue
.GetLong();
602 if ( st
!= wxFONTSTYLE_NORMAL
&&
603 st
!= wxFONTSTYLE_SLANT
&&
604 st
!= wxFONTSTYLE_ITALIC
)
605 st
= wxFONTWEIGHT_NORMAL
;
610 int wt
= childValue
.GetLong();
611 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
612 wt
!= wxFONTWEIGHT_LIGHT
&&
613 wt
!= wxFONTWEIGHT_BOLD
)
614 wt
= wxFONTWEIGHT_NORMAL
;
615 font
.SetWeight( wt
);
619 font
.SetUnderlined( childValue
.GetBool() );
626 wxSize wxFontProperty::OnMeasureImage() const
628 return wxSize(-1,-1);
631 void wxFontProperty::OnCustomPaint(wxDC& dc,
633 wxPGPaintData& paintData)
636 if ( paintData.m_choiceItem >= 0 )
637 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
639 drawFace = m_value_wxFont.GetFaceName();
641 if ( drawFace.length() )
643 // Draw the background
644 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
645 //dc.SetBrush( *wxWHITE_BRUSH );
646 //dc.SetPen( *wxMEDIUM_GREY_PEN );
647 dc.DrawRectangle( rect );
649 wxFont oldFont = dc.GetFont();
650 wxFont drawFont(oldFont.GetPointSize(),
651 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
652 dc.SetFont(drawFont);
654 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
655 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
661 // No file - just draw a white box
662 dc.SetBrush ( *wxWHITE_BRUSH );
663 dc.DrawRectangle ( rect );
669 // -----------------------------------------------------------------------
670 // wxSystemColourProperty
671 // -----------------------------------------------------------------------
673 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
674 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
676 #include "wx/colordlg.h"
678 //#define wx_cp_es_syscolours_len 25
679 static const wxChar
* gs_cp_es_syscolour_labels
[] = {
682 wxT("ActiveCaption"),
684 wxT("ButtonHighlight"),
693 wxT("HighlightText"),
694 wxT("InactiveBorder"),
695 wxT("InactiveCaption"),
696 wxT("InactiveCaptionText"),
708 static long gs_cp_es_syscolour_values
[] = {
709 wxSYS_COLOUR_APPWORKSPACE
,
710 wxSYS_COLOUR_ACTIVEBORDER
,
711 wxSYS_COLOUR_ACTIVECAPTION
,
712 wxSYS_COLOUR_BTNFACE
,
713 wxSYS_COLOUR_BTNHIGHLIGHT
,
714 wxSYS_COLOUR_BTNSHADOW
,
715 wxSYS_COLOUR_BTNTEXT
,
716 wxSYS_COLOUR_CAPTIONTEXT
,
717 wxSYS_COLOUR_3DDKSHADOW
,
718 wxSYS_COLOUR_3DLIGHT
,
719 wxSYS_COLOUR_BACKGROUND
,
720 wxSYS_COLOUR_GRAYTEXT
,
721 wxSYS_COLOUR_HIGHLIGHT
,
722 wxSYS_COLOUR_HIGHLIGHTTEXT
,
723 wxSYS_COLOUR_INACTIVEBORDER
,
724 wxSYS_COLOUR_INACTIVECAPTION
,
725 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
727 wxSYS_COLOUR_SCROLLBAR
,
729 wxSYS_COLOUR_INFOTEXT
,
731 wxSYS_COLOUR_WINDOWFRAME
,
732 wxSYS_COLOUR_WINDOWTEXT
,
737 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
740 // Class body is in advprops.h
742 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
743 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
746 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
748 wxColourPropertyValue cpv
;
751 cpv
.Init( type
, colour
);
753 cpv
.Init( type
, *wxWHITE
);
755 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
763 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
766 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
767 const wxColourPropertyValue
& value
)
768 : wxEnumProperty( label
,
770 gs_cp_es_syscolour_labels
,
771 gs_cp_es_syscolour_values
,
772 &gs_wxSystemColourProperty_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 wxColourPropertyValue
& value
)
784 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
787 Init( value
.m_type
, value
.m_colour
);
789 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
793 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
794 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
795 const wxColour
& value
)
796 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
799 Init( wxPG_COLOUR_CUSTOM
, value
);
801 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
805 wxSystemColourProperty::~wxSystemColourProperty() { }
808 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
813 if ( pVariant
->IsNull() )
814 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
816 if ( pVariant
->GetType() == wxS("wxColourPropertyValue") )
818 wxColourPropertyValue v
;
824 bool variantProcessed
= true;
826 if ( pVariant
->GetType() == wxS("wxColour*") )
828 wxColour
* pCol
= wxStaticCast(pVariant
->GetWxObjectPtr(), wxColour
);
831 else if ( pVariant
->GetType() == wxS("wxColour") )
835 else if ( pVariant
->GetType() == wxArrayInt_VariantType
)
837 // This code is mostly needed for wxPython bindings, which
838 // may offer tuple of integers as colour value.
842 if ( arr
.size() >= 3 )
850 if ( arr
.size() >= 4 )
853 col
= wxColour(r
, g
, b
, a
);
857 variantProcessed
= false;
862 variantProcessed
= false;
865 if ( !variantProcessed
)
866 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
868 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
870 int colInd
= ColToInd(col
);
871 if ( colInd
!= wxNOT_FOUND
)
877 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
884 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
887 size_t i_max
= m_choices
.GetCount() - 1;
889 for ( i
=0; i
<i_max
; i
++ )
891 int ind
= m_choices
[i
].GetValue();
893 if ( colour
== GetColour(ind
) )
895 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
896 GetClassName(),GetLabel().c_str(),
897 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
898 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
906 static inline wxColour
wxColourFromPGLong( long col
)
908 return wxColour((col
&0xFF),((col
>>8)&0xFF),((col
>>16)&0xFF));
912 void wxSystemColourProperty::OnSetValue()
914 // Convert from generic wxobject ptr to wxPGVariantDataColour
915 if ( m_value
.GetType() == wxS("wxColour*") )
917 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
921 wxColourPropertyValue val
= GetVal(&m_value
);
923 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
931 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
932 val
.m_colour
= GetColour( val
.m_type
);
934 m_value
= TranslateVal(val
);
939 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
941 wxColourPropertyValue cpv
;
943 wxColour col
= cpv
.m_colour
;
947 SetValueToUnspecified();
948 SetIndex(wxNOT_FOUND
);
952 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
)
954 if ( m_choices
.HasValues() )
955 ind
= GetIndexForValue(cpv
.m_type
);
961 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
962 ind
= GetCustomColourIndex();
972 SetValueToUnspecified();
973 SetIndex(wxNOT_FOUND
);
979 if ( ind
== wxNOT_FOUND
)
980 ind
= GetCustomColourIndex();
987 wxColour
wxSystemColourProperty::GetColour( int index
) const
989 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
992 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
994 if ( index
== wxNOT_FOUND
)
995 return wxString::Format(wxT("(%i,%i,%i)"),
1000 return m_choices
.GetLabel(index
);
1003 wxString
wxSystemColourProperty::ValueToString( wxVariant
& value
,
1004 int argFlags
) const
1006 wxColourPropertyValue val
= GetVal(&value
);
1010 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1012 // GetIndex() only works reliably if wxPG_VALUE_IS_CURRENT flag is set,
1013 // but we should use it whenever possible.
1016 // If custom colour was selected, use invalid index, so that
1017 // ColourToString() will return properly formatted colour text.
1018 if ( index
== GetCustomColourIndex() )
1019 index
= wxNOT_FOUND
;
1023 index
= m_choices
.Index(val
.m_type
);
1026 return ColourToString(val
.m_colour
, index
);
1030 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
1032 return wxPG_DEFAULT_IMAGE_SIZE
;
1036 int wxSystemColourProperty::GetCustomColourIndex() const
1038 return m_choices
.GetCount() - 1;
1042 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1044 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1047 wxPropertyGrid
* propgrid
= GetGrid();
1048 wxASSERT( propgrid
);
1050 // Must only occur when user triggers event
1051 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_ONCUSTOMEDITOREVENT
) )
1054 wxColourPropertyValue val
= GetVal();
1056 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1059 data
.SetChooseFull(true);
1060 data
.SetColour(val
.m_colour
);
1062 for ( i
= 0; i
< 16; i
++)
1064 wxColour
colour(i
*16, i
*16, i
*16);
1065 data
.SetCustomColour(i
, colour
);
1068 wxColourDialog
dialog(propgrid
, &data
);
1069 if ( dialog
.ShowModal() == wxID_OK
)
1071 wxColourData retData
= dialog
.GetColourData();
1072 val
.m_colour
= retData
.GetColour();
1074 variant
= DoTranslateVal(val
);
1076 SetValueInEvent(variant
);
1085 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1088 int type
= GetValueForIndex(index
);
1089 bool hasValue
= m_choices
[index
].HasValue();
1091 if ( ( hasValue
&& type
== wxPG_COLOUR_CUSTOM
) ||
1092 ( !hasValue
&& (index
== (int)GetCustomColourIndex() &&
1093 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
))
1097 QueryColourFromUser(variant
);
1101 variant
= TranslateVal( type
, GetColour(type
) );
1107 // Need to do some extra event handling.
1108 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
), wxEvent
& event
)
1110 if ( propgrid
->IsMainButtonEvent(event
) )
1112 // We need to handle button click in case editor has been
1113 // switched to one that has wxButton as well.
1115 if ( QueryColourFromUser(variant
) )
1121 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1124 virtual void Render( wxDC& dc, const wxRect& rect,
1125 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1126 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1128 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1129 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1131 dc.SetPen(*wxBLACK_PEN);
1133 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1137 const wxArrayInt& values = prop->GetValues();
1138 if ( values.GetChildCount() )
1139 colInd = values[item];
1142 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1144 else if ( !prop->IsValueUnspecified() )
1145 dc.SetBrush( prop->GetVal().m_colour );
1147 dc.SetBrush( *wxWHITE );
1149 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1150 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1151 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1152 imageRect.width, imageRect.height );
1156 text = property->GetValueAsString();
1158 text = property->GetChoiceString(item);
1159 DrawText( dc, rect, imageRect.width, text );
1164 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1166 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1169 return &g_wxPGColourPropertyRenderer;
1170 return wxEnumProperty::GetCellRenderer(column);
1173 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1174 wxPGPaintData
& paintdata
)
1178 if ( paintdata
.m_choiceItem
>= 0 && paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1179 paintdata
.m_choiceItem
!= GetCustomColourIndex() )
1181 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1182 col
= GetColour( colInd
);
1184 else if ( !IsValueUnspecified() )
1186 col
= GetVal().m_colour
;
1192 dc
.DrawRectangle(rect
);
1197 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1200 // Accept colour format "[Name] [(R,G,B)]"
1201 // Name takes precedence.
1203 wxString colourName
;
1206 int ppos
= text
.Find(wxT("("));
1208 if ( ppos
== wxNOT_FOUND
)
1214 colourName
= text
.substr(0, ppos
);
1215 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1218 // Strip spaces from extremities
1219 colourName
.Trim(true);
1220 colourName
.Trim(false);
1221 colourRGB
.Trim(true);
1223 // Validate colourRGB string - (1,1,1) is shortest allowed
1224 if ( colourRGB
.length() < 7 )
1227 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1228 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1230 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1232 // This really should not occurr...
1238 QueryColourFromUser(value
);
1242 wxColourPropertyValue val
;
1246 if ( colourName
.length() )
1248 // Try predefined colour first
1249 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1250 if ( res
&& GetIndex() >= 0 )
1252 val
.m_type
= GetIndex();
1253 if ( val
.m_type
>= 0 && val
.m_type
< m_choices
.GetCount() && m_choices
[val
.m_type
].HasValue() )
1254 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1256 // Get proper colour for type.
1257 val
.m_colour
= GetColour(val
.m_type
);
1262 if ( colourRGB
.length() && !done
)
1264 // Then check custom colour.
1265 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1267 int r
= -1, g
= -1, b
= -1;
1268 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1270 if ( r
>= 0 && r
<= 255 &&
1271 g
>= 0 && g
<= 255 &&
1272 b
>= 0 && b
<= 255 )
1274 val
.m_colour
.Set(r
,g
,b
);
1286 value
= DoTranslateVal(val
);
1293 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1295 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1297 int ival
= wxPGVariantToInt(value
);
1299 SetChoicesExclusive(); // Make sure we don't corrupt colour lists of other properties
1301 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1303 // Show custom choice
1304 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1305 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1307 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1309 // Hide custom choice
1310 m_choices
.RemoveAt(GetCustomColourIndex());
1311 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1319 // -----------------------------------------------------------------------
1321 // -----------------------------------------------------------------------
1323 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1343 (const wxChar
*) NULL
1346 static unsigned long gs_cp_es_normcolour_colours
[] = {
1348 wxPG_COLOUR(128,0,0),
1349 wxPG_COLOUR(0,0,128),
1350 wxPG_COLOUR(128,0,128),
1351 wxPG_COLOUR(0,128,128),
1352 wxPG_COLOUR(128,128,128),
1353 wxPG_COLOUR(0,128,0),
1354 wxPG_COLOUR(128,128,0),
1355 wxPG_COLOUR(166,124,81),
1356 wxPG_COLOUR(0,0,255),
1357 wxPG_COLOUR(255,0,255),
1358 wxPG_COLOUR(255,0,0),
1359 wxPG_COLOUR(247,148,28),
1360 wxPG_COLOUR(192,192,192),
1361 wxPG_COLOUR(0,255,0),
1362 wxPG_COLOUR(0,255,255),
1363 wxPG_COLOUR(255,255,0),
1364 wxPG_COLOUR(255,255,255),
1368 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxColourProperty
, wxSystemColourProperty
,
1369 wxColour
, const wxColour
&, TextCtrlAndButton
)
1371 static wxPGChoices gs_wxColourProperty_choicesCache
;
1373 wxColourProperty::wxColourProperty( const wxString
& label
,
1374 const wxString
& name
,
1375 const wxColour
& value
)
1376 : wxSystemColourProperty(label
, name
, gs_cp_es_normcolour_labels
,
1378 &gs_wxColourProperty_choicesCache
, value
)
1382 m_flags
|= wxPG_PROP_TRANSLATE_CUSTOM
;
1385 wxColourProperty::~wxColourProperty()
1389 void wxColourProperty::Init( wxColour colour
)
1396 int ind
= ColToInd(colour
);
1398 ind
= m_choices
.GetCount() - 1;
1402 wxString
wxColourProperty::ValueToString( wxVariant
& value
,
1403 int argFlags
) const
1405 const wxPGEditor
* editor
= GetEditorClass();
1406 if ( editor
!= wxPGEditor_Choice
&&
1407 editor
!= wxPGEditor_ChoiceAndButton
&&
1408 editor
!= wxPGEditor_ComboBox
)
1409 argFlags
|= wxPG_PROPERTY_SPECIFIC
;
1411 return wxSystemColourProperty::ValueToString(value
, argFlags
);
1414 wxColour
wxColourProperty::GetColour( int index
) const
1416 if ( !m_choices
.HasValue(index
) )
1418 wxASSERT( index
< (int)GetItemCount() );
1419 return gs_cp_es_normcolour_colours
[index
];
1421 return gs_cp_es_normcolour_colours
[m_choices
.GetValue(index
)];
1424 wxVariant
wxColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1427 variant
<< v
.m_colour
;
1431 // -----------------------------------------------------------------------
1433 // -----------------------------------------------------------------------
1435 #define wxPG_CURSOR_IMAGE_WIDTH 32
1437 #define NUM_CURSORS 28
1439 //#define wx_cp_es_syscursors_len 28
1440 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1452 wxT("Middle Button"),
1458 wxT("Question Arrow"),
1459 wxT("Right Button"),
1460 wxT("Sizing NE-SW"),
1462 wxT("Sizing NW-SE"),
1469 (const wxChar
*) NULL
1472 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1475 wxCURSOR_RIGHT_ARROW
,
1482 wxCURSOR_LEFT_BUTTON
,
1484 wxCURSOR_MIDDLE_BUTTON
,
1486 wxCURSOR_PAINT_BRUSH
,
1488 wxCURSOR_POINT_LEFT
,
1489 wxCURSOR_POINT_RIGHT
,
1490 wxCURSOR_QUESTION_ARROW
,
1491 wxCURSOR_RIGHT_BUTTON
,
1503 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1505 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1507 : wxEnumProperty( label
,
1509 gs_cp_es_syscursors_labels
,
1510 gs_cp_es_syscursors_values
,
1513 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1516 wxCursorProperty::~wxCursorProperty()
1520 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1522 #if wxPG_CAN_DRAW_CURSOR
1523 if ( item
!= -1 && item
< NUM_CURSORS
)
1524 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1531 #if wxPG_CAN_DRAW_CURSOR
1533 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1535 wxPGPaintData
& paintdata
)
1538 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1540 if ( paintdata
.m_choiceItem
>= 0 )
1542 dc
.DrawRectangle( rect
);
1544 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1546 wxStockCursor cursorIndex
=
1547 (wxStockCursor
) gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1550 if ( cursorIndex
== wxCURSOR_NONE
)
1551 cursorIndex
= wxCURSOR_ARROW
;
1553 wxCursor
cursor( cursorIndex
);
1556 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1560 (HICON
)cursor
.GetHandle(),
1565 DI_COMPAT
| DI_DEFAULTSIZE
| DI_NORMAL
1574 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1575 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1577 return wxEnumProperty::GetCellRenderer(column);
1581 // -----------------------------------------------------------------------
1582 // wxImageFileProperty
1583 // -----------------------------------------------------------------------
1587 const wxString
& wxPGGetDefaultImageWildcard()
1589 // Form the wildcard, if not done yet
1590 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1595 // TODO: This section may require locking (using global).
1597 wxList
& handlers
= wxImage::GetHandlers();
1599 wxList::iterator node
;
1601 // Let's iterate over the image handler list.
1602 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1603 for ( node
= handlers
.begin(); node
!= handlers
.end(); node
++ )
1605 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1607 wxString ext_lo
= handler
->GetExtension();
1608 wxString ext_up
= ext_lo
.Upper();
1610 str
.append( ext_up
);
1611 str
.append( wxT(" files (*.") );
1612 str
.append( ext_up
);
1613 str
.append( wxT(")|*.") );
1614 str
.append( ext_lo
);
1615 str
.append( wxT("|") );
1618 str
.append ( wxT("All files (*.*)|*.*") );
1620 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1623 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1626 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1628 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1629 const wxString
& value
)
1630 : wxFileProperty(label
,name
,value
)
1632 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1634 m_pImage
= (wxImage
*) NULL
;
1635 m_pBitmap
= (wxBitmap
*) NULL
;
1638 wxImageFileProperty::~wxImageFileProperty()
1646 void wxImageFileProperty::OnSetValue()
1648 wxFileProperty::OnSetValue();
1662 wxFileName filename
= GetFileName();
1664 // Create the image thumbnail
1665 if ( filename
.FileExists() )
1667 m_pImage
= new wxImage( filename
.GetFullPath() );
1671 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1673 return wxPG_DEFAULT_IMAGE_SIZE
;
1676 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1680 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1682 // Draw the thumbnail
1684 // Create the bitmap here because required size is not known in OnSetValue().
1687 m_pImage
->Rescale( rect
.width
, rect
.height
);
1688 m_pBitmap
= new wxBitmap( *m_pImage
);
1693 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1697 // No file - just draw a white box
1698 dc
.SetBrush( *wxWHITE_BRUSH
);
1699 dc
.DrawRectangle ( rect
);
1703 #endif // wxUSE_IMAGE
1705 // -----------------------------------------------------------------------
1706 // wxMultiChoiceProperty
1707 // -----------------------------------------------------------------------
1711 #include "wx/choicdlg.h"
1713 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1714 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1716 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1717 const wxString
& name
,
1718 const wxPGChoices
& choices
,
1719 const wxArrayString
& value
)
1720 : wxPGProperty(label
,name
)
1722 m_choices
.Assign(choices
);
1726 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1727 const wxString
& name
,
1728 const wxArrayString
& strings
,
1729 const wxArrayString
& value
)
1730 : wxPGProperty(label
,name
)
1732 m_choices
.Set(strings
);
1736 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1737 const wxString
& name
,
1738 const wxArrayString
& value
)
1739 : wxPGProperty(label
,name
)
1741 wxArrayString strings
;
1742 m_choices
.Set(strings
);
1746 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1750 void wxMultiChoiceProperty::OnSetValue()
1752 GenerateValueAsString(m_value
, &m_display
);
1755 wxString
wxMultiChoiceProperty::ValueToString( wxVariant
& value
,
1756 int argFlags
) const
1758 // If possible, use cached string
1759 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1763 GenerateValueAsString(value
, &s
);
1767 void wxMultiChoiceProperty::GenerateValueAsString( wxVariant
& value
,
1768 wxString
* target
) const
1770 wxArrayString strings
;
1772 if ( value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1773 strings
= value
.GetArrayString();
1775 wxString
& tempStr
= *target
;
1777 unsigned int itemCount
= strings
.size();
1782 tempStr
.append( wxT("\"") );
1784 for ( i
= 0; i
< itemCount
; i
++ )
1786 tempStr
.append( strings
[i
] );
1787 tempStr
.append( wxT("\"") );
1788 if ( i
< (itemCount
-1) )
1789 tempStr
.append ( wxT(" \"") );
1793 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1795 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(GetValue());
1798 // Translate values to string indices.
1799 wxArrayInt selections
;
1801 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1803 for ( i
=0; i
<valueArr
.size(); i
++ )
1808 for ( i
=0; i
<valueArr
.size(); i
++ )
1810 int sIndex
= m_choices
.Index(valueArr
[i
]);
1812 selections
.Add(sIndex
);
1819 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1820 wxWindow
* WXUNUSED(primary
),
1823 if ( propgrid
->IsMainButtonEvent(event
) )
1826 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
1828 wxArrayString labels
= m_choices
.GetLabels();
1829 unsigned int choiceCount
;
1831 if ( m_choices
.IsOk() )
1832 choiceCount
= m_choices
.GetCount();
1836 // launch editor dialog
1837 wxMultiChoiceDialog
dlg( propgrid
,
1838 _("Make a selection:"),
1841 choiceCount
?&labels
[0]:NULL
,
1842 wxCHOICEDLG_STYLE
);
1844 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
1846 wxArrayString strings
= useValue
.GetArrayString();
1847 wxArrayString extraStrings
;
1849 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
1851 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
1853 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1855 wxArrayInt arrInt
= dlg
.GetSelections();
1859 // Strings that were not in list of choices
1860 wxArrayString value
;
1862 // Translate string indices to strings
1865 if ( userStringMode
== 1 )
1867 for (n
=0;n
<extraStrings
.size();n
++)
1868 value
.push_back(extraStrings
[n
]);
1872 for ( i
=0; i
<arrInt
.size(); i
++ )
1873 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
1875 if ( userStringMode
== 2 )
1877 for (n
=0;n
<extraStrings
.size();n
++)
1878 value
.push_back(extraStrings
[n
]);
1881 variant
= WXVARIANT(value
);
1883 SetValueInEvent(variant
);
1891 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1895 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1897 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
1898 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
1900 WX_PG_TOKENIZER2_END()
1902 wxVariant
v( WXVARIANT(arr
) );
1908 #endif // wxUSE_CHOICEDLG
1911 // -----------------------------------------------------------------------
1913 // -----------------------------------------------------------------------
1918 #if wxUSE_DATEPICKCTRL
1919 #define dtCtrl DatePickerCtrl
1921 #define dtCtrl TextCtrl
1924 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
1931 wxString
wxDateProperty::ms_defaultDateFormat
;
1934 wxDateProperty::wxDateProperty( const wxString
& label
,
1935 const wxString
& name
,
1936 const wxDateTime
& value
)
1937 : wxPGProperty(label
,name
)
1939 //wxPGRegisterDefaultValueType(wxDateTime)
1941 #if wxUSE_DATEPICKCTRL
1942 wxPGRegisterEditorClass(DatePickerCtrl
);
1944 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
1952 wxDateProperty::~wxDateProperty()
1956 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
1957 int WXUNUSED(argFlags
) ) const
1961 const char* c
= dt
.ParseFormat(text
, wxString(wxDefaultDateTimeFormat
), wxDefaultDateTime
, NULL
);
1972 wxString
wxDateProperty::ValueToString( wxVariant
& value
,
1973 int argFlags
) const
1975 const wxChar
* format
= (const wxChar
*) NULL
;
1977 wxDateTime dateTime
= value
.GetDateTime();
1979 if ( !dateTime
.IsValid() )
1980 return wxT("Invalid");
1982 if ( !ms_defaultDateFormat
.length() )
1984 #if wxUSE_DATEPICKCTRL
1985 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
1987 bool showCentury
= true;
1989 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
1992 if ( m_format
.length() &&
1993 !(argFlags
& wxPG_FULL_VALUE
) )
1994 format
= m_format
.c_str();
1996 // Determine default from locale
1997 // NB: This is really simple stuff, but can't figure anything
1998 // better without proper support in wxLocale
2000 format
= ms_defaultDateFormat
.c_str();
2002 return dateTime
.Format(format
);
2005 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
2007 // This code is basicly copied from datectlg.cpp's SetFormat
2012 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
2013 wxString
str(dt
.Format(wxT("%x")));
2015 const wxChar
*p
= str
.c_str();
2019 if (n
== dt
.GetDay())
2021 format
.Append(wxT("%d"));
2024 else if (n
== (int)dt
.GetMonth()+1)
2026 format
.Append(wxT("%m"));
2029 else if (n
== dt
.GetYear())
2031 format
.Append(wxT("%Y"));
2034 else if (n
== (dt
.GetYear() % 100))
2037 format
.Append(wxT("%Y"));
2039 format
.Append(wxT("%y"));
2043 format
.Append(*p
++);
2049 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
2051 if ( name
== wxPG_DATE_FORMAT
)
2053 m_format
= value
.GetString();
2056 else if ( name
== wxPG_DATE_PICKER_STYLE
)
2058 m_dpStyle
= value
.GetLong();
2059 ms_defaultDateFormat
.clear(); // This may need recalculation
2065 #endif // wxUSE_DATETIME
2068 // -----------------------------------------------------------------------
2069 // wxPropertyGridInterface
2070 // -----------------------------------------------------------------------
2072 void wxPropertyGridInterface::InitAllTypeHandlers()
2076 // -----------------------------------------------------------------------
2078 void wxPropertyGridInterface::RegisterAdditionalEditors()
2080 // Register editor classes, if necessary.
2081 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
2082 wxPropertyGrid::RegisterDefaultEditors();
2085 wxPGRegisterEditorClass(SpinCtrl
);
2087 #if wxUSE_DATEPICKCTRL
2088 wxPGRegisterEditorClass(DatePickerCtrl
);
2092 // -----------------------------------------------------------------------
2094 #endif // wxPG_INCLUDE_ADVPROPS
2096 #endif // wxUSE_PROPGRID