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 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
),
149 wnd2
->Connect( id
, wxEVT_SCROLL_LINEDOWN
,
150 wxCommandEventHandler(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 wxCommandEventHandler(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 wxCommandEventHandler(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 AddChild( new wxIntProperty( _("Point Size"), wxS("Point Size"),(long)font
.GetPointSize() ) );
482 AddChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
483 gs_fp_es_family_labels
,gs_fp_es_family_values
,
486 wxString faceName
= font
.GetFaceName();
487 // If font was not in there, add it now
488 if ( faceName
.length() &&
489 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
490 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
492 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"), wxS("Face Name"),
493 *wxPGGlobalVars
->m_fontFamilyChoices
);
495 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
499 AddChild( new wxEnumProperty(_("Style"), wxS("Style"),
500 gs_fp_es_style_labels
,gs_fp_es_style_values
,font
.GetStyle()) );
502 AddChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
503 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,font
.GetWeight()) );
505 AddChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
506 font
.GetUnderlined()) );
509 wxFontProperty::~wxFontProperty() { }
511 void wxFontProperty::OnSetValue()
518 font
= wxFont(10,wxSWISS
,wxNORMAL
,wxNORMAL
);
523 wxString
wxFontProperty::GetValueAsString( int argFlags
) const
525 return wxPGProperty::GetValueAsString(argFlags
);
528 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
531 if ( propgrid
->IsMainButtonEvent(event
) )
533 // Update value from last minute changes
534 PrepareValueForDialogEditing(propgrid
);
539 data
.SetInitialFont( font
);
540 data
.SetColour(*wxBLACK
);
542 wxFontDialog
dlg(propgrid
, data
);
543 if ( dlg
.ShowModal() == wxID_OK
)
545 propgrid
->EditorsValueWasModified();
548 variant
<< dlg
.GetFontData().GetChosenFont();
549 SetValueInEvent( variant
);
556 void wxFontProperty::RefreshChildren()
558 if ( !GetChildCount() ) return;
561 Item(0)->SetValue( (long)font
.GetPointSize() );
562 Item(1)->SetValue( (long)font
.GetFamily() );
563 Item(2)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
564 Item(3)->SetValue( (long)font
.GetStyle() );
565 Item(4)->SetValue( (long)font
.GetWeight() );
566 Item(5)->SetValue( font
.GetUnderlined() );
569 void wxFontProperty::ChildChanged( wxVariant
& thisValue
, int ind
, wxVariant
& childValue
) const
576 font
.SetPointSize( wxPGVariantToInt(childValue
) );
580 int fam
= childValue
.GetLong();
581 if ( fam
< wxDEFAULT
||
584 font
.SetFamily( fam
);
589 int faceIndex
= childValue
.GetLong();
591 if ( faceIndex
>= 0 )
592 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
594 font
.SetFaceName( faceName
);
598 int st
= childValue
.GetLong();
599 if ( st
!= wxFONTSTYLE_NORMAL
&&
600 st
!= wxFONTSTYLE_SLANT
&&
601 st
!= wxFONTSTYLE_ITALIC
)
602 st
= wxFONTWEIGHT_NORMAL
;
607 int wt
= childValue
.GetLong();
608 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
609 wt
!= wxFONTWEIGHT_LIGHT
&&
610 wt
!= wxFONTWEIGHT_BOLD
)
611 wt
= wxFONTWEIGHT_NORMAL
;
612 font
.SetWeight( wt
);
616 font
.SetUnderlined( childValue
.GetBool() );
623 wxSize wxFontProperty::OnMeasureImage() const
625 return wxSize(-1,-1);
628 void wxFontProperty::OnCustomPaint(wxDC& dc,
630 wxPGPaintData& paintData)
633 if ( paintData.m_choiceItem >= 0 )
634 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
636 drawFace = m_value_wxFont.GetFaceName();
638 if ( drawFace.length() )
640 // Draw the background
641 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
642 //dc.SetBrush( *wxWHITE_BRUSH );
643 //dc.SetPen( *wxMEDIUM_GREY_PEN );
644 dc.DrawRectangle( rect );
646 wxFont oldFont = dc.GetFont();
647 wxFont drawFont(oldFont.GetPointSize(),
648 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
649 dc.SetFont(drawFont);
651 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
652 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
658 // No file - just draw a white box
659 dc.SetBrush ( *wxWHITE_BRUSH );
660 dc.DrawRectangle ( rect );
666 // -----------------------------------------------------------------------
667 // wxSystemColourProperty
668 // -----------------------------------------------------------------------
670 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
671 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
673 #include "wx/colordlg.h"
675 //#define wx_cp_es_syscolours_len 25
676 static const wxChar
* gs_cp_es_syscolour_labels
[] = {
679 wxT("ActiveCaption"),
681 wxT("ButtonHighlight"),
690 wxT("HighlightText"),
691 wxT("InactiveBorder"),
692 wxT("InactiveCaption"),
693 wxT("InactiveCaptionText"),
705 static long gs_cp_es_syscolour_values
[] = {
706 wxSYS_COLOUR_APPWORKSPACE
,
707 wxSYS_COLOUR_ACTIVEBORDER
,
708 wxSYS_COLOUR_ACTIVECAPTION
,
709 wxSYS_COLOUR_BTNFACE
,
710 wxSYS_COLOUR_BTNHIGHLIGHT
,
711 wxSYS_COLOUR_BTNSHADOW
,
712 wxSYS_COLOUR_BTNTEXT
,
713 wxSYS_COLOUR_CAPTIONTEXT
,
714 wxSYS_COLOUR_3DDKSHADOW
,
715 wxSYS_COLOUR_3DLIGHT
,
716 wxSYS_COLOUR_BACKGROUND
,
717 wxSYS_COLOUR_GRAYTEXT
,
718 wxSYS_COLOUR_HIGHLIGHT
,
719 wxSYS_COLOUR_HIGHLIGHTTEXT
,
720 wxSYS_COLOUR_INACTIVEBORDER
,
721 wxSYS_COLOUR_INACTIVECAPTION
,
722 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
724 wxSYS_COLOUR_SCROLLBAR
,
726 wxSYS_COLOUR_INFOTEXT
,
728 wxSYS_COLOUR_WINDOWFRAME
,
729 wxSYS_COLOUR_WINDOWTEXT
,
734 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
737 // Class body is in advprops.h
739 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
740 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
743 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
745 wxColourPropertyValue cpv
;
748 cpv
.Init( type
, colour
);
750 cpv
.Init( type
, *wxWHITE
);
752 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
760 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
763 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
764 const wxColourPropertyValue
& value
)
765 : wxEnumProperty( label
,
767 gs_cp_es_syscolour_labels
,
768 gs_cp_es_syscolour_values
,
769 &gs_wxSystemColourProperty_choicesCache
)
772 Init( value
.m_type
, value
.m_colour
);
774 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
778 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
779 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
780 const wxColourPropertyValue
& value
)
781 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
784 Init( value
.m_type
, value
.m_colour
);
786 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
790 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
791 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
792 const wxColour
& value
)
793 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
796 Init( wxPG_COLOUR_CUSTOM
, value
);
798 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
802 wxSystemColourProperty::~wxSystemColourProperty() { }
805 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
810 if ( pVariant
->IsNull() )
811 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
813 if ( pVariant
->GetType() == wxS("wxColourPropertyValue") )
815 wxColourPropertyValue v
;
821 bool variantProcessed
= true;
823 if ( pVariant
->GetType() == wxS("wxColour*") )
825 wxColour
* pCol
= wxStaticCast(pVariant
->GetWxObjectPtr(), wxColour
);
828 else if ( pVariant
->GetType() == wxS("wxColour") )
832 else if ( pVariant
->GetType() == wxArrayInt_VariantType
)
834 // This code is mostly needed for wxPython bindings, which
835 // may offer tuple of integers as colour value.
839 if ( arr
.size() >= 3 )
847 if ( arr
.size() >= 4 )
850 col
= wxColour(r
, g
, b
, a
);
854 variantProcessed
= false;
859 variantProcessed
= false;
862 if ( !variantProcessed
)
863 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
865 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
867 int colInd
= ColToInd(col
);
868 if ( colInd
!= wxNOT_FOUND
)
874 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
881 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
884 size_t i_max
= m_choices
.GetCount() - 1;
886 for ( i
=0; i
<i_max
; i
++ )
888 int ind
= m_choices
[i
].GetValue();
890 if ( colour
== GetColour(ind
) )
892 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
893 GetClassName(),GetLabel().c_str(),
894 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
895 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
903 static inline wxColour
wxColourFromPGLong( long col
)
905 return wxColour((col
&0xFF),((col
>>8)&0xFF),((col
>>16)&0xFF));
909 void wxSystemColourProperty::OnSetValue()
911 // Convert from generic wxobject ptr to wxPGVariantDataColour
912 if ( m_value
.GetType() == wxS("wxColour*") )
914 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
918 wxColourPropertyValue val
= GetVal(&m_value
);
920 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
928 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
929 val
.m_colour
= GetColour( val
.m_type
);
931 m_value
= TranslateVal(val
);
936 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
938 wxColourPropertyValue cpv
;
940 wxColour col
= cpv
.m_colour
;
944 SetValueToUnspecified();
945 SetIndex(wxNOT_FOUND
);
949 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
)
951 if ( m_choices
.HasValues() )
952 ind
= GetIndexForValue(cpv
.m_type
);
958 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
959 ind
= GetCustomColourIndex();
969 SetValueToUnspecified();
970 SetIndex(wxNOT_FOUND
);
976 if ( ind
== wxNOT_FOUND
)
977 ind
= GetCustomColourIndex();
984 wxColour
wxSystemColourProperty::GetColour( int index
) const
986 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
989 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
991 if ( index
== wxNOT_FOUND
)
992 return wxString::Format(wxT("(%i,%i,%i)"),
997 return m_choices
.GetLabel(index
);
1000 wxString
wxSystemColourProperty::GetValueAsString( int argFlags
) const
1002 wxColourPropertyValue val
= GetVal();
1004 int ind
= GetIndex();
1006 // Always show custom colour for textctrl-editor
1007 if ( val
.m_type
== wxPG_COLOUR_CUSTOM
||
1008 ind
== GetCustomColourIndex() ||
1009 (argFlags
& wxPG_PROPERTY_SPECIFIC
) )
1011 return ColourToString(val
.m_colour
, wxNOT_FOUND
);
1015 return wxEmptyString
;
1017 return ColourToString(val
.m_colour
, ind
);
1021 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
1023 return wxPG_DEFAULT_IMAGE_SIZE
;
1027 int wxSystemColourProperty::GetCustomColourIndex() const
1029 return m_choices
.GetCount() - 1;
1033 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1035 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1038 wxPropertyGrid
* propgrid
= GetGrid();
1039 wxASSERT( propgrid
);
1041 // Must only occur when user triggers event
1042 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_ONCUSTOMEDITOREVENT
) )
1045 wxColourPropertyValue val
= GetVal();
1047 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1050 data
.SetChooseFull(true);
1051 data
.SetColour(val
.m_colour
);
1053 for ( i
= 0; i
< 16; i
++)
1055 wxColour
colour(i
*16, i
*16, i
*16);
1056 data
.SetCustomColour(i
, colour
);
1059 wxColourDialog
dialog(propgrid
, &data
);
1060 if ( dialog
.ShowModal() == wxID_OK
)
1062 wxColourData retData
= dialog
.GetColourData();
1063 val
.m_colour
= retData
.GetColour();
1065 variant
= DoTranslateVal(val
);
1067 SetValueInEvent(variant
);
1076 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1079 int type
= GetValueForIndex(index
);
1080 bool hasValue
= m_choices
[index
].HasValue();
1082 if ( ( hasValue
&& type
== wxPG_COLOUR_CUSTOM
) ||
1083 ( !hasValue
&& (index
== (int)GetCustomColourIndex() &&
1084 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
))
1088 QueryColourFromUser(variant
);
1092 variant
= TranslateVal( type
, GetColour(type
) );
1098 // Need to do some extra event handling.
1099 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
), wxEvent
& event
)
1101 if ( propgrid
->IsMainButtonEvent(event
) )
1103 // We need to handle button click in case editor has been
1104 // switched to one that has wxButton as well.
1106 if ( QueryColourFromUser(variant
) )
1112 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1115 virtual void Render( wxDC& dc, const wxRect& rect,
1116 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1117 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1119 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1120 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1122 dc.SetPen(*wxBLACK_PEN);
1124 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1128 const wxArrayInt& values = prop->GetValues();
1129 if ( values.GetChildCount() )
1130 colInd = values[item];
1133 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1135 else if ( !prop->IsValueUnspecified() )
1136 dc.SetBrush( prop->GetVal().m_colour );
1138 dc.SetBrush( *wxWHITE );
1140 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1141 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1142 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1143 imageRect.width, imageRect.height );
1147 text = property->GetValueAsString();
1149 text = property->GetChoiceString(item);
1150 DrawText( dc, rect, imageRect.width, text );
1155 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1157 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1160 return &g_wxPGColourPropertyRenderer;
1161 return wxEnumProperty::GetCellRenderer(column);
1164 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1165 wxPGPaintData
& paintdata
)
1169 if ( paintdata
.m_choiceItem
>= 0 && paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1170 paintdata
.m_choiceItem
!= GetCustomColourIndex() )
1172 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1173 col
= GetColour( colInd
);
1175 else if ( !IsValueUnspecified() )
1177 col
= GetVal().m_colour
;
1183 dc
.DrawRectangle(rect
);
1188 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1191 // Accept colour format "[Name] [(R,G,B)]"
1192 // Name takes precedence.
1194 wxString colourName
;
1197 int ppos
= text
.Find(wxT("("));
1199 if ( ppos
== wxNOT_FOUND
)
1205 colourName
= text
.substr(0, ppos
);
1206 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1209 // Strip spaces from extremities
1210 colourName
.Trim(true);
1211 colourName
.Trim(false);
1212 colourRGB
.Trim(true);
1214 // Validate colourRGB string - (1,1,1) is shortest allowed
1215 if ( colourRGB
.length() < 7 )
1218 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1219 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1221 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1223 // This really should not occurr...
1229 QueryColourFromUser(value
);
1233 wxColourPropertyValue val
;
1237 if ( colourName
.length() )
1239 // Try predefined colour first
1240 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1241 if ( res
&& GetIndex() >= 0 )
1243 val
.m_type
= GetIndex();
1244 if ( val
.m_type
>= 0 && val
.m_type
< m_choices
.GetCount() && m_choices
[val
.m_type
].HasValue() )
1245 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1247 // Get proper colour for type.
1248 val
.m_colour
= GetColour(val
.m_type
);
1253 if ( colourRGB
.length() && !done
)
1255 // Then check custom colour.
1256 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1258 int r
= -1, g
= -1, b
= -1;
1259 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1261 if ( r
>= 0 && r
<= 255 &&
1262 g
>= 0 && g
<= 255 &&
1263 b
>= 0 && b
<= 255 )
1265 val
.m_colour
.Set(r
,g
,b
);
1277 value
= DoTranslateVal(val
);
1284 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1286 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1288 int ival
= wxPGVariantToInt(value
);
1290 SetChoicesExclusive(); // Make sure we don't corrupt colour lists of other properties
1292 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1294 // Show custom choice
1295 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1296 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1298 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1300 // Hide custom choice
1301 m_choices
.RemoveAt(GetCustomColourIndex());
1302 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1310 // -----------------------------------------------------------------------
1312 // -----------------------------------------------------------------------
1314 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1334 (const wxChar
*) NULL
1337 static unsigned long gs_cp_es_normcolour_colours
[] = {
1339 wxPG_COLOUR(128,0,0),
1340 wxPG_COLOUR(0,0,128),
1341 wxPG_COLOUR(128,0,128),
1342 wxPG_COLOUR(0,128,128),
1343 wxPG_COLOUR(128,128,128),
1344 wxPG_COLOUR(0,128,0),
1345 wxPG_COLOUR(128,128,0),
1346 wxPG_COLOUR(166,124,81),
1347 wxPG_COLOUR(0,0,255),
1348 wxPG_COLOUR(255,0,255),
1349 wxPG_COLOUR(255,0,0),
1350 wxPG_COLOUR(247,148,28),
1351 wxPG_COLOUR(192,192,192),
1352 wxPG_COLOUR(0,255,0),
1353 wxPG_COLOUR(0,255,255),
1354 wxPG_COLOUR(255,255,0),
1355 wxPG_COLOUR(255,255,255),
1359 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxColourProperty
, wxSystemColourProperty
,
1360 wxColour
, const wxColour
&, TextCtrlAndButton
)
1362 static wxPGChoices gs_wxColourProperty_choicesCache
;
1364 wxColourProperty::wxColourProperty( const wxString
& label
,
1365 const wxString
& name
,
1366 const wxColour
& value
)
1367 : wxSystemColourProperty(label
, name
, gs_cp_es_normcolour_labels
,
1369 &gs_wxColourProperty_choicesCache
, value
)
1373 m_flags
|= wxPG_PROP_TRANSLATE_CUSTOM
;
1376 wxColourProperty::~wxColourProperty()
1380 void wxColourProperty::Init( wxColour colour
)
1387 int ind
= ColToInd(colour
);
1389 ind
= m_choices
.GetCount() - 1;
1393 wxString
wxColourProperty::GetValueAsString( int argFlags
) const
1395 const wxPGEditor
* editor
= GetEditorClass();
1396 if ( editor
!= wxPGEditor_Choice
&&
1397 editor
!= wxPGEditor_ChoiceAndButton
&&
1398 editor
!= wxPGEditor_ComboBox
)
1399 argFlags
|= wxPG_PROPERTY_SPECIFIC
;
1401 return wxSystemColourProperty::GetValueAsString(argFlags
);
1404 wxColour
wxColourProperty::GetColour( int index
) const
1406 if ( !m_choices
.HasValue(index
) )
1408 wxASSERT( index
< (int)GetItemCount() );
1409 return gs_cp_es_normcolour_colours
[index
];
1411 return gs_cp_es_normcolour_colours
[m_choices
.GetValue(index
)];
1414 wxVariant
wxColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1417 variant
<< v
.m_colour
;
1421 // -----------------------------------------------------------------------
1423 // -----------------------------------------------------------------------
1425 #define wxPG_CURSOR_IMAGE_WIDTH 32
1427 #define NUM_CURSORS 28
1429 //#define wx_cp_es_syscursors_len 28
1430 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1442 wxT("Middle Button"),
1448 wxT("Question Arrow"),
1449 wxT("Right Button"),
1450 wxT("Sizing NE-SW"),
1452 wxT("Sizing NW-SE"),
1459 (const wxChar
*) NULL
1462 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1465 wxCURSOR_RIGHT_ARROW
,
1472 wxCURSOR_LEFT_BUTTON
,
1474 wxCURSOR_MIDDLE_BUTTON
,
1476 wxCURSOR_PAINT_BRUSH
,
1478 wxCURSOR_POINT_LEFT
,
1479 wxCURSOR_POINT_RIGHT
,
1480 wxCURSOR_QUESTION_ARROW
,
1481 wxCURSOR_RIGHT_BUTTON
,
1493 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1495 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1497 : wxEnumProperty( label
,
1499 gs_cp_es_syscursors_labels
,
1500 gs_cp_es_syscursors_values
,
1503 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1506 wxCursorProperty::~wxCursorProperty()
1510 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1512 #if wxPG_CAN_DRAW_CURSOR
1513 if ( item
!= -1 && item
< NUM_CURSORS
)
1514 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1521 #if wxPG_CAN_DRAW_CURSOR
1523 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1525 wxPGPaintData
& paintdata
)
1528 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1530 if ( paintdata
.m_choiceItem
>= 0 )
1532 dc
.DrawRectangle( rect
);
1534 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1536 wxStockCursor cursorIndex
=
1537 (wxStockCursor
) gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1540 if ( cursorIndex
== wxCURSOR_NONE
)
1541 cursorIndex
= wxCURSOR_ARROW
;
1543 wxCursor
cursor( cursorIndex
);
1546 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1550 (HICON
)cursor
.GetHandle(),
1555 DI_COMPAT
| DI_DEFAULTSIZE
| DI_NORMAL
1564 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1565 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1567 return wxEnumProperty::GetCellRenderer(column);
1571 // -----------------------------------------------------------------------
1572 // wxImageFileProperty
1573 // -----------------------------------------------------------------------
1577 const wxString
& wxPGGetDefaultImageWildcard()
1579 // Form the wildcard, if not done yet
1580 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1585 // TODO: This section may require locking (using global).
1587 wxList
& handlers
= wxImage::GetHandlers();
1589 wxList::iterator node
;
1591 // Let's iterate over the image handler list.
1592 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1593 for ( node
= handlers
.begin(); node
!= handlers
.end(); node
++ )
1595 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1597 wxString ext_lo
= handler
->GetExtension();
1598 wxString ext_up
= ext_lo
.Upper();
1600 str
.append( ext_up
);
1601 str
.append( wxT(" files (*.") );
1602 str
.append( ext_up
);
1603 str
.append( wxT(")|*.") );
1604 str
.append( ext_lo
);
1605 str
.append( wxT("|") );
1608 str
.append ( wxT("All files (*.*)|*.*") );
1610 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1613 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1616 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1618 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1619 const wxString
& value
)
1620 : wxFileProperty(label
,name
,value
)
1622 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1624 m_pImage
= (wxImage
*) NULL
;
1625 m_pBitmap
= (wxBitmap
*) NULL
;
1628 wxImageFileProperty::~wxImageFileProperty()
1636 void wxImageFileProperty::OnSetValue()
1638 wxFileProperty::OnSetValue();
1652 // Create the image thumbnail
1653 if ( m_filename
.FileExists() )
1655 m_pImage
= new wxImage( m_filename
.GetFullPath() );
1659 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1661 return wxPG_DEFAULT_IMAGE_SIZE
;
1664 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1668 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1670 // Draw the thumbnail
1672 // Create the bitmap here because required size is not known in OnSetValue().
1675 m_pImage
->Rescale( rect
.width
, rect
.height
);
1676 m_pBitmap
= new wxBitmap( *m_pImage
);
1681 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1685 // No file - just draw a white box
1686 dc
.SetBrush( *wxWHITE_BRUSH
);
1687 dc
.DrawRectangle ( rect
);
1691 #endif // wxUSE_IMAGE
1693 // -----------------------------------------------------------------------
1694 // wxMultiChoiceProperty
1695 // -----------------------------------------------------------------------
1699 #include "wx/choicdlg.h"
1701 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1702 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1704 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1705 const wxString
& name
,
1706 const wxPGChoices
& choices
,
1707 const wxArrayString
& value
)
1708 : wxPGProperty(label
,name
)
1710 m_choices
.Assign(choices
);
1714 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1715 const wxString
& name
,
1716 const wxArrayString
& strings
,
1717 const wxArrayString
& value
)
1718 : wxPGProperty(label
,name
)
1720 m_choices
.Set(strings
);
1724 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1725 const wxString
& name
,
1726 const wxArrayString
& value
)
1727 : wxPGProperty(label
,name
)
1729 wxArrayString strings
;
1730 m_choices
.Set(strings
);
1734 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1738 void wxMultiChoiceProperty::OnSetValue()
1740 GenerateValueAsString();
1743 wxString
wxMultiChoiceProperty::GetValueAsString( int ) const
1748 void wxMultiChoiceProperty::GenerateValueAsString()
1750 wxArrayString strings
;
1752 if ( m_value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1753 strings
= m_value
.GetArrayString();
1755 wxString
& tempStr
= m_display
;
1757 unsigned int itemCount
= strings
.size();
1762 tempStr
.append( wxT("\"") );
1764 for ( i
= 0; i
< itemCount
; i
++ )
1766 tempStr
.append( strings
[i
] );
1767 tempStr
.append( wxT("\"") );
1768 if ( i
< (itemCount
-1) )
1769 tempStr
.append ( wxT(" \"") );
1773 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1775 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(GetValue());
1778 // Translate values to string indices.
1779 wxArrayInt selections
;
1781 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1783 for ( i
=0; i
<valueArr
.size(); i
++ )
1788 for ( i
=0; i
<valueArr
.size(); i
++ )
1790 int sIndex
= m_choices
.Index(valueArr
[i
]);
1792 selections
.Add(sIndex
);
1799 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1800 wxWindow
* WXUNUSED(primary
),
1803 if ( propgrid
->IsMainButtonEvent(event
) )
1806 PrepareValueForDialogEditing(propgrid
);
1808 wxArrayString labels
= m_choices
.GetLabels();
1809 unsigned int choiceCount
;
1811 if ( m_choices
.IsOk() )
1812 choiceCount
= m_choices
.GetCount();
1816 // launch editor dialog
1817 wxMultiChoiceDialog
dlg( propgrid
,
1818 _("Make a selection:"),
1821 choiceCount
?&labels
[0]:NULL
,
1822 wxCHOICEDLG_STYLE
);
1824 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
1826 wxArrayString strings
= m_value
.GetArrayString();
1827 wxArrayString extraStrings
;
1829 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
1831 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
1833 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1835 wxArrayInt arrInt
= dlg
.GetSelections();
1839 // Strings that were not in list of choices
1840 wxArrayString value
;
1842 // Translate string indices to strings
1845 if ( userStringMode
== 1 )
1847 for (n
=0;n
<extraStrings
.size();n
++)
1848 value
.push_back(extraStrings
[n
]);
1852 for ( i
=0; i
<arrInt
.size(); i
++ )
1853 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
1855 if ( userStringMode
== 2 )
1857 for (n
=0;n
<extraStrings
.size();n
++)
1858 value
.push_back(extraStrings
[n
]);
1861 variant
= WXVARIANT(value
);
1863 SetValueInEvent(variant
);
1871 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1875 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1877 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
1878 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
1880 WX_PG_TOKENIZER2_END()
1882 wxVariant
v( WXVARIANT(arr
) );
1888 #endif // wxUSE_CHOICEDLG
1891 // -----------------------------------------------------------------------
1893 // -----------------------------------------------------------------------
1898 #if wxUSE_DATEPICKCTRL
1899 #define dtCtrl DatePickerCtrl
1901 #define dtCtrl TextCtrl
1904 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
1911 wxString
wxDateProperty::ms_defaultDateFormat
;
1914 wxDateProperty::wxDateProperty( const wxString
& label
,
1915 const wxString
& name
,
1916 const wxDateTime
& value
)
1917 : wxPGProperty(label
,name
)
1919 //wxPGRegisterDefaultValueType(wxDateTime)
1921 #if wxUSE_DATEPICKCTRL
1922 wxPGRegisterEditorClass(DatePickerCtrl
);
1924 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
1932 wxDateProperty::~wxDateProperty()
1936 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
1937 int WXUNUSED(argFlags
) ) const
1941 const char* c
= dt
.ParseFormat(text
, wxString(wxDefaultDateTimeFormat
), wxDefaultDateTime
, NULL
);
1952 wxString
wxDateProperty::GetValueAsString( int argFlags
) const
1954 const wxChar
* format
= (const wxChar
*) NULL
;
1956 wxDateTime dateTime
= m_value
.GetDateTime();
1958 if ( !dateTime
.IsValid() )
1959 return wxT("Invalid");
1961 if ( !ms_defaultDateFormat
.length() )
1963 #if wxUSE_DATEPICKCTRL
1964 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
1966 bool showCentury
= true;
1968 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
1971 if ( m_format
.length() &&
1972 !(argFlags
& wxPG_FULL_VALUE
) )
1973 format
= m_format
.c_str();
1975 // Determine default from locale
1976 // NB: This is really simple stuff, but can't figure anything
1977 // better without proper support in wxLocale
1979 format
= ms_defaultDateFormat
.c_str();
1981 return dateTime
.Format(format
);
1984 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
1986 // This code is basicly copied from datectlg.cpp's SetFormat
1991 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
1992 wxString
str(dt
.Format(wxT("%x")));
1994 const wxChar
*p
= str
.c_str();
1998 if (n
== dt
.GetDay())
2000 format
.Append(wxT("%d"));
2003 else if (n
== (int)dt
.GetMonth()+1)
2005 format
.Append(wxT("%m"));
2008 else if (n
== dt
.GetYear())
2010 format
.Append(wxT("%Y"));
2013 else if (n
== (dt
.GetYear() % 100))
2016 format
.Append(wxT("%Y"));
2018 format
.Append(wxT("%y"));
2022 format
.Append(*p
++);
2028 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
2030 if ( name
== wxPG_DATE_FORMAT
)
2032 m_format
= value
.GetString();
2035 else if ( name
== wxPG_DATE_PICKER_STYLE
)
2037 m_dpStyle
= value
.GetLong();
2038 ms_defaultDateFormat
.clear(); // This may need recalculation
2044 #endif // wxUSE_DATETIME
2047 // -----------------------------------------------------------------------
2048 // wxPropertyGridInterface
2049 // -----------------------------------------------------------------------
2051 void wxPropertyGridInterface::InitAllTypeHandlers()
2055 // -----------------------------------------------------------------------
2057 void wxPropertyGridInterface::RegisterAdditionalEditors()
2059 // Register editor classes, if necessary.
2060 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
2061 wxPropertyGrid::RegisterDefaultEditors();
2064 wxPGRegisterEditorClass(SpinCtrl
);
2066 #if wxUSE_DATEPICKCTRL
2067 wxPGRegisterEditorClass(DatePickerCtrl
);
2071 // -----------------------------------------------------------------------
2073 #endif // wxPG_INCLUDE_ADVPROPS
2075 #endif // wxUSE_PROPGRID