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 // Let's add validator to make sure only numbers can be entered
141 wxTextValidator
validator(wxFILTER_NUMERIC
, &m_tempString
);
143 wxTextCtrl
* wnd1
= (wxTextCtrl
*) wxPGTextCtrlEditor::CreateControls( propgrid
, property
, pos
, tcSz
).m_primary
;
144 wnd1
->SetValidator(validator
);
146 return wxPGWindowList(wnd1
, wnd2
);
149 // Control's events are redirected here
150 bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
151 wxWindow
* wnd
, wxEvent
& event
) const
153 int evtType
= event
.GetEventType();
155 bool bigStep
= false;
157 if ( evtType
== wxEVT_KEY_DOWN
)
159 wxKeyEvent
& keyEvent
= (wxKeyEvent
&)event
;
160 keycode
= keyEvent
.GetKeyCode();
162 if ( keycode
== WXK_UP
)
163 evtType
= wxEVT_SCROLL_LINEUP
;
164 else if ( keycode
== WXK_DOWN
)
165 evtType
= wxEVT_SCROLL_LINEDOWN
;
166 else if ( keycode
== WXK_PAGEUP
)
168 evtType
= wxEVT_SCROLL_LINEUP
;
171 else if ( keycode
== WXK_PAGEDOWN
)
173 evtType
= wxEVT_SCROLL_LINEDOWN
;
178 if ( evtType
== wxEVT_SCROLL_LINEUP
|| evtType
== wxEVT_SCROLL_LINEDOWN
)
181 // Can't use wnd since it might be clipper window
182 wxTextCtrl
* tc
= wxDynamicCast(propgrid
->GetEditorControl(), wxTextCtrl
);
187 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
189 int mode
= wxPG_PROPERTY_VALIDATION_SATURATE
;
191 if ( property
->GetAttributeAsLong(wxT("Wrap"), 0) )
192 mode
= wxPG_PROPERTY_VALIDATION_WRAP
;
194 if ( property
->GetValueType() == wxT("double") )
197 double step
= property
->GetAttributeAsDouble(wxT("Step"), 1.0);
200 if ( s
.ToDouble(&v_d
) )
205 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_d
+= step
;
209 wxFloatProperty::DoValidation(property
, v_d
, NULL
, mode
);
211 wxPropertyGrid::DoubleToString(s
, v_d
, 6, true, NULL
);
221 wxLongLong_t step
= property
->GetAttributeAsLong(wxT("Step"), 1);
224 if ( s
.ToLongLong(&v_ll
, 10) )
229 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_ll
+= step
;
233 wxIntProperty::DoValidation(property
, v_ll
, NULL
, mode
);
235 s
= wxLongLong(v_ll
).ToString();
245 int ip
= tc
->GetInsertionPoint();
246 int lp
= tc
->GetLastPosition();
248 tc
->SetInsertionPoint(ip
+(tc
->GetLastPosition()-lp
));
254 return wxPGTextCtrlEditor::OnEvent(propgrid
,property
,wnd
,event
);
257 #endif // wxUSE_SPINBTN
260 // -----------------------------------------------------------------------
261 // wxDatePickerCtrl-based property editor
262 // -----------------------------------------------------------------------
264 #if wxUSE_DATEPICKCTRL
267 #include "wx/datectrl.h"
268 #include "wx/dateevt.h"
270 class wxPGDatePickerCtrlEditor
: public wxPGEditor
272 DECLARE_DYNAMIC_CLASS(wxPGDatePickerCtrlEditor
)
274 virtual ~wxPGDatePickerCtrlEditor();
276 wxString
GetName() const;
277 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
278 wxPGProperty
* property
,
280 const wxSize
& size
) const;
281 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const;
282 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
283 wxWindow
* wnd
, wxEvent
& event
) const;
284 virtual bool GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* wnd
) const;
285 virtual void SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const;
289 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(DatePickerCtrl
,
290 wxPGDatePickerCtrlEditor
,
294 wxPGDatePickerCtrlEditor::~wxPGDatePickerCtrlEditor()
298 wxPGWindowList
wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
,
299 wxPGProperty
* property
,
301 const wxSize
& sz
) const
303 wxCHECK_MSG( property
->IsKindOf(CLASSINFO(wxDateProperty
)),
305 wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
307 wxDateProperty
* prop
= (wxDateProperty
*) property
;
309 // Use two stage creation to allow cleaner display on wxMSW
310 wxDatePickerCtrl
* ctrl
= new wxDatePickerCtrl();
313 wxSize useSz
= wxDefaultSize
;
318 ctrl
->Create(propgrid
->GetPanel(),
320 prop
->GetDateValue(),
323 prop
->GetDatePickerStyle() | wxNO_BORDER
);
332 // Copies value from property to control
333 void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const
335 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
336 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
338 // We assume that property's data type is 'int' (or something similar),
339 // thus allowing us to get raw, unchecked value via DoGetValue.
340 ctrl
->SetValue( property
->GetValue().GetDateTime() );
343 // Control's events are redirected here
344 bool wxPGDatePickerCtrlEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propgrid
),
345 wxPGProperty
* WXUNUSED(property
),
346 wxWindow
* WXUNUSED(wnd
),
347 wxEvent
& event
) const
349 if ( event
.GetEventType() == wxEVT_DATE_CHANGED
)
355 bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const
357 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
358 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
360 variant
= ctrl
->GetValue();
365 void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* WXUNUSED(wnd
) ) const
368 //wxDateProperty* prop = (wxDateProperty*) property;
372 #endif // wxUSE_DATEPICKCTRL
375 // -----------------------------------------------------------------------
377 // -----------------------------------------------------------------------
379 #include "wx/fontdlg.h"
380 #include "wx/fontenum.h"
382 static const wxChar
* gs_fp_es_family_labels
[] = {
383 wxT("Default"), wxT("Decorative"),
384 wxT("Roman"), wxT("Script"),
385 wxT("Swiss"), wxT("Modern"),
389 static long gs_fp_es_family_values
[] = {
390 wxDEFAULT
, wxDECORATIVE
,
395 static const wxChar
* gs_fp_es_style_labels
[] = {
402 static long gs_fp_es_style_values
[] = {
408 static const wxChar
* gs_fp_es_weight_labels
[] = {
415 static long gs_fp_es_weight_values
[] = {
421 // Class body is in advprops.h
424 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty
,wxPGProperty
,
425 wxFont
,const wxFont
&,TextCtrlAndButton
)
428 wxFontProperty::wxFontProperty( const wxString
& label
, const wxString
& name
,
429 const wxFont
& value
)
430 : wxPGProperty(label
,name
)
432 SetValue(WXVARIANT(value
));
434 // Initialize font family choices list
435 if ( !wxPGGlobalVars
->m_fontFamilyChoices
)
437 wxArrayString faceNames
= wxFontEnumerator::GetFacenames();
441 wxPGGlobalVars
->m_fontFamilyChoices
= new wxPGChoices(faceNames
);
444 wxString
emptyString(wxEmptyString
);
449 SetParentalType(wxPG_PROP_AGGREGATE
);
451 AddChild( new wxIntProperty( _("Point Size"), wxS("Point Size"),(long)font
.GetPointSize() ) );
453 AddChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
454 gs_fp_es_family_labels
,gs_fp_es_family_values
,
457 wxString faceName
= font
.GetFaceName();
458 // If font was not in there, add it now
459 if ( faceName
.length() &&
460 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
461 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
463 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"), wxS("Face Name"),
464 *wxPGGlobalVars
->m_fontFamilyChoices
);
466 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
470 AddChild( new wxEnumProperty(_("Style"), wxS("Style"),
471 gs_fp_es_style_labels
,gs_fp_es_style_values
,font
.GetStyle()) );
473 AddChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
474 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,font
.GetWeight()) );
476 AddChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
477 font
.GetUnderlined()) );
480 wxFontProperty::~wxFontProperty() { }
482 void wxFontProperty::OnSetValue()
489 font
= wxFont(10,wxSWISS
,wxNORMAL
,wxNORMAL
);
494 wxString
wxFontProperty::ValueToString( wxVariant
& value
,
497 return wxPGProperty::ValueToString(value
, argFlags
);
500 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
503 if ( propgrid
->IsMainButtonEvent(event
) )
505 // Update value from last minute changes
506 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
511 data
.SetInitialFont( font
);
512 data
.SetColour(*wxBLACK
);
514 wxFontDialog
dlg(propgrid
, data
);
515 if ( dlg
.ShowModal() == wxID_OK
)
517 propgrid
->EditorsValueWasModified();
520 variant
<< dlg
.GetFontData().GetChosenFont();
521 SetValueInEvent( variant
);
528 void wxFontProperty::RefreshChildren()
530 if ( !GetChildCount() ) return;
533 Item(0)->SetValue( (long)font
.GetPointSize() );
534 Item(1)->SetValue( (long)font
.GetFamily() );
535 Item(2)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
536 Item(3)->SetValue( (long)font
.GetStyle() );
537 Item(4)->SetValue( (long)font
.GetWeight() );
538 Item(5)->SetValue( font
.GetUnderlined() );
541 void wxFontProperty::ChildChanged( wxVariant
& thisValue
, int ind
, wxVariant
& childValue
) const
548 font
.SetPointSize( wxPGVariantToInt(childValue
) );
552 int fam
= childValue
.GetLong();
553 if ( fam
< wxDEFAULT
||
556 font
.SetFamily( fam
);
561 int faceIndex
= childValue
.GetLong();
563 if ( faceIndex
>= 0 )
564 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
566 font
.SetFaceName( faceName
);
570 int st
= childValue
.GetLong();
571 if ( st
!= wxFONTSTYLE_NORMAL
&&
572 st
!= wxFONTSTYLE_SLANT
&&
573 st
!= wxFONTSTYLE_ITALIC
)
574 st
= wxFONTWEIGHT_NORMAL
;
579 int wt
= childValue
.GetLong();
580 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
581 wt
!= wxFONTWEIGHT_LIGHT
&&
582 wt
!= wxFONTWEIGHT_BOLD
)
583 wt
= wxFONTWEIGHT_NORMAL
;
584 font
.SetWeight( wt
);
588 font
.SetUnderlined( childValue
.GetBool() );
595 wxSize wxFontProperty::OnMeasureImage() const
597 return wxSize(-1,-1);
600 void wxFontProperty::OnCustomPaint(wxDC& dc,
602 wxPGPaintData& paintData)
605 if ( paintData.m_choiceItem >= 0 )
606 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
608 drawFace = m_value_wxFont.GetFaceName();
610 if ( drawFace.length() )
612 // Draw the background
613 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
614 //dc.SetBrush( *wxWHITE_BRUSH );
615 //dc.SetPen( *wxMEDIUM_GREY_PEN );
616 dc.DrawRectangle( rect );
618 wxFont oldFont = dc.GetFont();
619 wxFont drawFont(oldFont.GetPointSize(),
620 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
621 dc.SetFont(drawFont);
623 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
624 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
630 // No file - just draw a white box
631 dc.SetBrush ( *wxWHITE_BRUSH );
632 dc.DrawRectangle ( rect );
638 // -----------------------------------------------------------------------
639 // wxSystemColourProperty
640 // -----------------------------------------------------------------------
642 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
643 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
645 #include "wx/colordlg.h"
647 //#define wx_cp_es_syscolours_len 25
648 static const wxChar
* gs_cp_es_syscolour_labels
[] = {
651 wxT("ActiveCaption"),
653 wxT("ButtonHighlight"),
662 wxT("HighlightText"),
663 wxT("InactiveBorder"),
664 wxT("InactiveCaption"),
665 wxT("InactiveCaptionText"),
677 static long gs_cp_es_syscolour_values
[] = {
678 wxSYS_COLOUR_APPWORKSPACE
,
679 wxSYS_COLOUR_ACTIVEBORDER
,
680 wxSYS_COLOUR_ACTIVECAPTION
,
681 wxSYS_COLOUR_BTNFACE
,
682 wxSYS_COLOUR_BTNHIGHLIGHT
,
683 wxSYS_COLOUR_BTNSHADOW
,
684 wxSYS_COLOUR_BTNTEXT
,
685 wxSYS_COLOUR_CAPTIONTEXT
,
686 wxSYS_COLOUR_3DDKSHADOW
,
687 wxSYS_COLOUR_3DLIGHT
,
688 wxSYS_COLOUR_BACKGROUND
,
689 wxSYS_COLOUR_GRAYTEXT
,
690 wxSYS_COLOUR_HIGHLIGHT
,
691 wxSYS_COLOUR_HIGHLIGHTTEXT
,
692 wxSYS_COLOUR_INACTIVEBORDER
,
693 wxSYS_COLOUR_INACTIVECAPTION
,
694 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
696 wxSYS_COLOUR_SCROLLBAR
,
698 wxSYS_COLOUR_INFOTEXT
,
700 wxSYS_COLOUR_WINDOWFRAME
,
701 wxSYS_COLOUR_WINDOWTEXT
,
706 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
709 // Class body is in advprops.h
711 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
712 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
715 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
717 wxColourPropertyValue cpv
;
720 cpv
.Init( type
, colour
);
722 cpv
.Init( type
, *wxWHITE
);
724 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
732 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
735 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
736 const wxColourPropertyValue
& value
)
737 : wxEnumProperty( label
,
739 gs_cp_es_syscolour_labels
,
740 gs_cp_es_syscolour_values
,
741 &gs_wxSystemColourProperty_choicesCache
)
744 Init( value
.m_type
, value
.m_colour
);
746 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
750 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
751 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
752 const wxColourPropertyValue
& value
)
753 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
756 Init( value
.m_type
, value
.m_colour
);
758 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
762 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
763 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
764 const wxColour
& value
)
765 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
768 Init( wxPG_COLOUR_CUSTOM
, value
);
770 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
774 wxSystemColourProperty::~wxSystemColourProperty() { }
777 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
782 if ( pVariant
->IsNull() )
783 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
785 if ( pVariant
->GetType() == wxS("wxColourPropertyValue") )
787 wxColourPropertyValue v
;
793 bool variantProcessed
= true;
795 if ( pVariant
->GetType() == wxS("wxColour*") )
797 wxColour
* pCol
= wxStaticCast(pVariant
->GetWxObjectPtr(), wxColour
);
800 else if ( pVariant
->GetType() == wxS("wxColour") )
804 else if ( pVariant
->GetType() == wxArrayInt_VariantType
)
806 // This code is mostly needed for wxPython bindings, which
807 // may offer tuple of integers as colour value.
811 if ( arr
.size() >= 3 )
819 if ( arr
.size() >= 4 )
822 col
= wxColour(r
, g
, b
, a
);
826 variantProcessed
= false;
831 variantProcessed
= false;
834 if ( !variantProcessed
)
835 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
837 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
839 int colInd
= ColToInd(col
);
840 if ( colInd
!= wxNOT_FOUND
)
846 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
853 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
856 size_t i_max
= m_choices
.GetCount() - 1;
858 for ( i
=0; i
<i_max
; i
++ )
860 int ind
= m_choices
[i
].GetValue();
862 if ( colour
== GetColour(ind
) )
864 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
865 GetClassName(),GetLabel().c_str(),
866 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
867 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
874 void wxSystemColourProperty::OnSetValue()
876 // Convert from generic wxobject ptr to wxPGVariantDataColour
877 if ( m_value
.GetType() == wxS("wxColour*") )
879 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
883 wxColourPropertyValue val
= GetVal(&m_value
);
885 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
893 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
894 val
.m_colour
= GetColour( val
.m_type
);
896 m_value
= TranslateVal(val
);
899 int ind
= wxNOT_FOUND
;
901 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
903 wxColourPropertyValue cpv
;
905 wxColour col
= cpv
.m_colour
;
909 SetValueToUnspecified();
910 SetIndex(wxNOT_FOUND
);
914 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
)
916 ind
= GetIndexForValue(cpv
.m_type
);
920 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
921 ind
= GetCustomColourIndex();
931 SetValueToUnspecified();
932 SetIndex(wxNOT_FOUND
);
938 if ( ind
== wxNOT_FOUND
)
939 ind
= GetCustomColourIndex();
946 wxColour
wxSystemColourProperty::GetColour( int index
) const
948 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
951 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
953 if ( index
== wxNOT_FOUND
)
954 return wxString::Format(wxT("(%i,%i,%i)"),
959 return m_choices
.GetLabel(index
);
962 wxString
wxSystemColourProperty::ValueToString( wxVariant
& value
,
965 wxColourPropertyValue val
= GetVal(&value
);
969 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
971 // GetIndex() only works reliably if wxPG_VALUE_IS_CURRENT flag is set,
972 // but we should use it whenever possible.
975 // If custom colour was selected, use invalid index, so that
976 // ColourToString() will return properly formatted colour text.
977 if ( index
== GetCustomColourIndex() )
982 index
= m_choices
.Index(val
.m_type
);
985 return ColourToString(val
.m_colour
, index
);
989 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
991 return wxPG_DEFAULT_IMAGE_SIZE
;
995 int wxSystemColourProperty::GetCustomColourIndex() const
997 return m_choices
.GetCount() - 1;
1001 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1003 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1006 wxPropertyGrid
* propgrid
= GetGrid();
1007 wxASSERT( propgrid
);
1009 // Must only occur when user triggers event
1010 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
) )
1013 wxColourPropertyValue val
= GetVal();
1015 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1018 data
.SetChooseFull(true);
1019 data
.SetColour(val
.m_colour
);
1021 for ( i
= 0; i
< 16; i
++)
1023 wxColour
colour(i
*16, i
*16, i
*16);
1024 data
.SetCustomColour(i
, colour
);
1027 wxColourDialog
dialog(propgrid
, &data
);
1028 if ( dialog
.ShowModal() == wxID_OK
)
1030 wxColourData retData
= dialog
.GetColourData();
1031 val
.m_colour
= retData
.GetColour();
1033 variant
= DoTranslateVal(val
);
1035 SetValueInEvent(variant
);
1044 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1047 int type
= m_choices
.GetValue(index
);
1049 if ( type
== wxPG_COLOUR_CUSTOM
)
1051 QueryColourFromUser(variant
);
1055 variant
= TranslateVal( type
, GetColour(type
) );
1061 // Need to do some extra event handling.
1062 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
), wxEvent
& event
)
1064 if ( propgrid
->IsMainButtonEvent(event
) )
1066 // We need to handle button click in case editor has been
1067 // switched to one that has wxButton as well.
1069 if ( QueryColourFromUser(variant
) )
1075 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1078 virtual void Render( wxDC& dc, const wxRect& rect,
1079 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1080 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1082 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1083 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1085 dc.SetPen(*wxBLACK_PEN);
1087 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1091 const wxArrayInt& values = prop->GetValues();
1092 if ( values.GetChildCount() )
1093 colInd = values[item];
1096 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1098 else if ( !prop->IsValueUnspecified() )
1099 dc.SetBrush( prop->GetVal().m_colour );
1101 dc.SetBrush( *wxWHITE );
1103 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1104 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1105 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1106 imageRect.width, imageRect.height );
1110 text = property->GetValueAsString();
1112 text = property->GetChoiceString(item);
1113 DrawText( dc, rect, imageRect.width, text );
1118 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1120 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1123 return &g_wxPGColourPropertyRenderer;
1124 return wxEnumProperty::GetCellRenderer(column);
1127 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1128 wxPGPaintData
& paintdata
)
1132 if ( paintdata
.m_choiceItem
>= 0 && paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1133 paintdata
.m_choiceItem
!= GetCustomColourIndex() )
1135 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1136 col
= GetColour( colInd
);
1138 else if ( !IsValueUnspecified() )
1140 col
= GetVal().m_colour
;
1146 dc
.DrawRectangle(rect
);
1151 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1154 // Accept colour format "[Name] [(R,G,B)]"
1155 // Name takes precedence.
1157 wxString colourName
;
1160 int ppos
= text
.Find(wxT("("));
1162 if ( ppos
== wxNOT_FOUND
)
1168 colourName
= text
.substr(0, ppos
);
1169 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1172 // Strip spaces from extremities
1173 colourName
.Trim(true);
1174 colourName
.Trim(false);
1175 colourRGB
.Trim(true);
1177 // Validate colourRGB string - (1,1,1) is shortest allowed
1178 if ( colourRGB
.length() < 7 )
1181 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1182 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1184 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1186 // This really should not occurr...
1192 QueryColourFromUser(value
);
1196 wxColourPropertyValue val
;
1200 if ( colourName
.length() )
1202 // Try predefined colour first
1203 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1204 if ( res
&& GetIndex() >= 0 )
1206 val
.m_type
= GetIndex();
1207 if ( val
.m_type
< m_choices
.GetCount() )
1208 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1210 // Get proper colour for type.
1211 val
.m_colour
= GetColour(val
.m_type
);
1216 if ( colourRGB
.length() && !done
)
1218 // Then check custom colour.
1219 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1221 int r
= -1, g
= -1, b
= -1;
1222 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1224 if ( r
>= 0 && r
<= 255 &&
1225 g
>= 0 && g
<= 255 &&
1226 b
>= 0 && b
<= 255 )
1228 val
.m_colour
.Set(r
,g
,b
);
1240 value
= DoTranslateVal(val
);
1247 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1249 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1251 int ival
= wxPGVariantToInt(value
);
1253 SetChoicesExclusive(); // Make sure we don't corrupt colour lists of other properties
1255 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1257 // Show custom choice
1258 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1259 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1261 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1263 // Hide custom choice
1264 m_choices
.RemoveAt(GetCustomColourIndex());
1265 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1273 // -----------------------------------------------------------------------
1275 // -----------------------------------------------------------------------
1277 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1297 (const wxChar
*) NULL
1300 static unsigned long gs_cp_es_normcolour_colours
[] = {
1302 wxPG_COLOUR(128,0,0),
1303 wxPG_COLOUR(0,0,128),
1304 wxPG_COLOUR(128,0,128),
1305 wxPG_COLOUR(0,128,128),
1306 wxPG_COLOUR(128,128,128),
1307 wxPG_COLOUR(0,128,0),
1308 wxPG_COLOUR(128,128,0),
1309 wxPG_COLOUR(166,124,81),
1310 wxPG_COLOUR(0,0,255),
1311 wxPG_COLOUR(255,0,255),
1312 wxPG_COLOUR(255,0,0),
1313 wxPG_COLOUR(247,148,28),
1314 wxPG_COLOUR(192,192,192),
1315 wxPG_COLOUR(0,255,0),
1316 wxPG_COLOUR(0,255,255),
1317 wxPG_COLOUR(255,255,0),
1318 wxPG_COLOUR(255,255,255),
1322 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxColourProperty
, wxSystemColourProperty
,
1323 wxColour
, const wxColour
&, TextCtrlAndButton
)
1325 static wxPGChoices gs_wxColourProperty_choicesCache
;
1327 wxColourProperty::wxColourProperty( const wxString
& label
,
1328 const wxString
& name
,
1329 const wxColour
& value
)
1330 : wxSystemColourProperty(label
, name
, gs_cp_es_normcolour_labels
,
1332 &gs_wxColourProperty_choicesCache
, value
)
1336 m_flags
|= wxPG_PROP_TRANSLATE_CUSTOM
;
1339 wxColourProperty::~wxColourProperty()
1343 void wxColourProperty::Init( wxColour colour
)
1350 int ind
= ColToInd(colour
);
1352 ind
= m_choices
.GetCount() - 1;
1356 wxString
wxColourProperty::ValueToString( wxVariant
& value
,
1357 int argFlags
) const
1359 const wxPGEditor
* editor
= GetEditorClass();
1360 if ( editor
!= wxPGEditor_Choice
&&
1361 editor
!= wxPGEditor_ChoiceAndButton
&&
1362 editor
!= wxPGEditor_ComboBox
)
1363 argFlags
|= wxPG_PROPERTY_SPECIFIC
;
1365 return wxSystemColourProperty::ValueToString(value
, argFlags
);
1368 wxColour
wxColourProperty::GetColour( int index
) const
1370 return gs_cp_es_normcolour_colours
[m_choices
.GetValue(index
)];
1373 wxVariant
wxColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1376 variant
<< v
.m_colour
;
1380 // -----------------------------------------------------------------------
1382 // -----------------------------------------------------------------------
1384 #define wxPG_CURSOR_IMAGE_WIDTH 32
1386 #define NUM_CURSORS 28
1388 //#define wx_cp_es_syscursors_len 28
1389 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1401 wxT("Middle Button"),
1407 wxT("Question Arrow"),
1408 wxT("Right Button"),
1409 wxT("Sizing NE-SW"),
1411 wxT("Sizing NW-SE"),
1418 (const wxChar
*) NULL
1421 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1424 wxCURSOR_RIGHT_ARROW
,
1431 wxCURSOR_LEFT_BUTTON
,
1433 wxCURSOR_MIDDLE_BUTTON
,
1435 wxCURSOR_PAINT_BRUSH
,
1437 wxCURSOR_POINT_LEFT
,
1438 wxCURSOR_POINT_RIGHT
,
1439 wxCURSOR_QUESTION_ARROW
,
1440 wxCURSOR_RIGHT_BUTTON
,
1452 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1454 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1456 : wxEnumProperty( label
,
1458 gs_cp_es_syscursors_labels
,
1459 gs_cp_es_syscursors_values
,
1462 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1465 wxCursorProperty::~wxCursorProperty()
1469 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1471 #if wxPG_CAN_DRAW_CURSOR
1472 if ( item
!= -1 && item
< NUM_CURSORS
)
1473 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1480 #if wxPG_CAN_DRAW_CURSOR
1482 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1484 wxPGPaintData
& paintdata
)
1487 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1489 if ( paintdata
.m_choiceItem
>= 0 )
1491 dc
.DrawRectangle( rect
);
1493 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1495 wxStockCursor cursorIndex
=
1496 (wxStockCursor
) gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1499 if ( cursorIndex
== wxCURSOR_NONE
)
1500 cursorIndex
= wxCURSOR_ARROW
;
1502 wxCursor
cursor( cursorIndex
);
1505 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1509 (HICON
)cursor
.GetHandle(),
1514 #if !defined(__WXWINCE__)
1515 DI_COMPAT
| DI_DEFAULTSIZE
|
1526 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1527 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1529 return wxEnumProperty::GetCellRenderer(column);
1533 // -----------------------------------------------------------------------
1534 // wxImageFileProperty
1535 // -----------------------------------------------------------------------
1539 const wxString
& wxPGGetDefaultImageWildcard()
1541 // Form the wildcard, if not done yet
1542 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1547 // TODO: This section may require locking (using global).
1549 wxList
& handlers
= wxImage::GetHandlers();
1551 wxList::iterator node
;
1553 // Let's iterate over the image handler list.
1554 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1555 for ( node
= handlers
.begin(); node
!= handlers
.end(); ++node
)
1557 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1559 wxString ext_lo
= handler
->GetExtension();
1560 wxString ext_up
= ext_lo
.Upper();
1562 str
.append( ext_up
);
1563 str
.append( wxT(" files (*.") );
1564 str
.append( ext_up
);
1565 str
.append( wxT(")|*.") );
1566 str
.append( ext_lo
);
1567 str
.append( wxT("|") );
1570 str
.append ( wxT("All files (*.*)|*.*") );
1572 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1575 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1578 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1580 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1581 const wxString
& value
)
1582 : wxFileProperty(label
,name
,value
)
1584 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1586 m_pImage
= (wxImage
*) NULL
;
1587 m_pBitmap
= (wxBitmap
*) NULL
;
1590 wxImageFileProperty::~wxImageFileProperty()
1598 void wxImageFileProperty::OnSetValue()
1600 wxFileProperty::OnSetValue();
1614 wxFileName filename
= GetFileName();
1616 // Create the image thumbnail
1617 if ( filename
.FileExists() )
1619 m_pImage
= new wxImage( filename
.GetFullPath() );
1623 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1625 return wxPG_DEFAULT_IMAGE_SIZE
;
1628 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1632 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1634 // Draw the thumbnail
1636 // Create the bitmap here because required size is not known in OnSetValue().
1639 m_pImage
->Rescale( rect
.width
, rect
.height
);
1640 m_pBitmap
= new wxBitmap( *m_pImage
);
1645 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1649 // No file - just draw a white box
1650 dc
.SetBrush( *wxWHITE_BRUSH
);
1651 dc
.DrawRectangle ( rect
);
1655 #endif // wxUSE_IMAGE
1657 // -----------------------------------------------------------------------
1658 // wxMultiChoiceProperty
1659 // -----------------------------------------------------------------------
1663 #include "wx/choicdlg.h"
1665 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1666 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1668 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1669 const wxString
& name
,
1670 const wxPGChoices
& choices
,
1671 const wxArrayString
& value
)
1672 : wxPGProperty(label
,name
)
1674 m_choices
.Assign(choices
);
1678 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1679 const wxString
& name
,
1680 const wxArrayString
& strings
,
1681 const wxArrayString
& value
)
1682 : wxPGProperty(label
,name
)
1684 m_choices
.Set(strings
);
1688 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1689 const wxString
& name
,
1690 const wxArrayString
& value
)
1691 : wxPGProperty(label
,name
)
1693 wxArrayString strings
;
1694 m_choices
.Set(strings
);
1698 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1702 void wxMultiChoiceProperty::OnSetValue()
1704 GenerateValueAsString(m_value
, &m_display
);
1707 wxString
wxMultiChoiceProperty::ValueToString( wxVariant
& value
,
1708 int argFlags
) const
1710 // If possible, use cached string
1711 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1715 GenerateValueAsString(value
, &s
);
1719 void wxMultiChoiceProperty::GenerateValueAsString( wxVariant
& value
,
1720 wxString
* target
) const
1722 wxArrayString strings
;
1724 if ( value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1725 strings
= value
.GetArrayString();
1727 wxString
& tempStr
= *target
;
1729 unsigned int itemCount
= strings
.size();
1734 tempStr
.append( wxT("\"") );
1736 for ( i
= 0; i
< itemCount
; i
++ )
1738 tempStr
.append( strings
[i
] );
1739 tempStr
.append( wxT("\"") );
1740 if ( i
< (itemCount
-1) )
1741 tempStr
.append ( wxT(" \"") );
1745 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1747 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(GetValue());
1750 // Translate values to string indices.
1751 wxArrayInt selections
;
1753 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1755 for ( i
=0; i
<valueArr
.size(); i
++ )
1760 for ( i
=0; i
<valueArr
.size(); i
++ )
1762 int sIndex
= m_choices
.Index(valueArr
[i
]);
1764 selections
.Add(sIndex
);
1771 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1772 wxWindow
* WXUNUSED(primary
),
1775 if ( propgrid
->IsMainButtonEvent(event
) )
1778 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
1780 wxArrayString labels
= m_choices
.GetLabels();
1781 unsigned int choiceCount
;
1783 if ( m_choices
.IsOk() )
1784 choiceCount
= m_choices
.GetCount();
1788 // launch editor dialog
1789 wxMultiChoiceDialog
dlg( propgrid
,
1790 _("Make a selection:"),
1793 choiceCount
?&labels
[0]:NULL
,
1794 wxCHOICEDLG_STYLE
);
1796 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
1798 wxArrayString strings
= useValue
.GetArrayString();
1799 wxArrayString extraStrings
;
1801 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
1803 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
1805 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1807 wxArrayInt arrInt
= dlg
.GetSelections();
1811 // Strings that were not in list of choices
1812 wxArrayString value
;
1814 // Translate string indices to strings
1817 if ( userStringMode
== 1 )
1819 for (n
=0;n
<extraStrings
.size();n
++)
1820 value
.push_back(extraStrings
[n
]);
1824 for ( i
=0; i
<arrInt
.size(); i
++ )
1825 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
1827 if ( userStringMode
== 2 )
1829 for (n
=0;n
<extraStrings
.size();n
++)
1830 value
.push_back(extraStrings
[n
]);
1833 variant
= WXVARIANT(value
);
1835 SetValueInEvent(variant
);
1843 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1847 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1849 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
1850 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
1852 WX_PG_TOKENIZER2_END()
1854 wxVariant
v( WXVARIANT(arr
) );
1860 #endif // wxUSE_CHOICEDLG
1863 // -----------------------------------------------------------------------
1865 // -----------------------------------------------------------------------
1870 #if wxUSE_DATEPICKCTRL
1871 #define dtCtrl DatePickerCtrl
1873 #define dtCtrl TextCtrl
1876 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
1883 wxString
wxDateProperty::ms_defaultDateFormat
;
1886 wxDateProperty::wxDateProperty( const wxString
& label
,
1887 const wxString
& name
,
1888 const wxDateTime
& value
)
1889 : wxPGProperty(label
,name
)
1891 //wxPGRegisterDefaultValueType(wxDateTime)
1893 #if wxUSE_DATEPICKCTRL
1894 wxPGRegisterEditorClass(DatePickerCtrl
);
1896 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
1904 wxDateProperty::~wxDateProperty()
1908 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
1909 int WXUNUSED(argFlags
) ) const
1913 const char* c
= dt
.ParseFormat(text
, wxString(wxDefaultDateTimeFormat
), wxDefaultDateTime
, NULL
);
1924 wxString
wxDateProperty::ValueToString( wxVariant
& value
,
1925 int argFlags
) const
1927 const wxChar
* format
= (const wxChar
*) NULL
;
1929 wxDateTime dateTime
= value
.GetDateTime();
1931 if ( !dateTime
.IsValid() )
1932 return wxT("Invalid");
1934 if ( !ms_defaultDateFormat
.length() )
1936 #if wxUSE_DATEPICKCTRL
1937 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
1939 bool showCentury
= true;
1941 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
1944 if ( m_format
.length() &&
1945 !(argFlags
& wxPG_FULL_VALUE
) )
1946 format
= m_format
.c_str();
1948 // Determine default from locale
1949 // NB: This is really simple stuff, but can't figure anything
1950 // better without proper support in wxLocale
1952 format
= ms_defaultDateFormat
.c_str();
1954 return dateTime
.Format(format
);
1957 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
1959 // This code is basicly copied from datectlg.cpp's SetFormat
1964 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
1965 wxString
str(dt
.Format(wxT("%x")));
1967 const wxChar
*p
= str
.c_str();
1971 if (n
== dt
.GetDay())
1973 format
.Append(wxT("%d"));
1976 else if (n
== (int)dt
.GetMonth()+1)
1978 format
.Append(wxT("%m"));
1981 else if (n
== dt
.GetYear())
1983 format
.Append(wxT("%Y"));
1986 else if (n
== (dt
.GetYear() % 100))
1989 format
.Append(wxT("%Y"));
1991 format
.Append(wxT("%y"));
1995 format
.Append(*p
++);
2001 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
2003 if ( name
== wxPG_DATE_FORMAT
)
2005 m_format
= value
.GetString();
2008 else if ( name
== wxPG_DATE_PICKER_STYLE
)
2010 m_dpStyle
= value
.GetLong();
2011 ms_defaultDateFormat
.clear(); // This may need recalculation
2017 #endif // wxUSE_DATETIME
2020 // -----------------------------------------------------------------------
2021 // wxPropertyGridInterface
2022 // -----------------------------------------------------------------------
2024 void wxPropertyGridInterface::InitAllTypeHandlers()
2028 // -----------------------------------------------------------------------
2030 void wxPropertyGridInterface::RegisterAdditionalEditors()
2032 // Register editor classes, if necessary.
2033 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
2034 wxPropertyGrid::RegisterDefaultEditors();
2037 wxPGRegisterEditorClass(SpinCtrl
);
2039 #if wxUSE_DATEPICKCTRL
2040 wxPGRegisterEditorClass(DatePickerCtrl
);
2044 // -----------------------------------------------------------------------
2046 #endif // wxPG_INCLUDE_ADVPROPS
2048 #endif // wxUSE_PROPGRID