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"
21 #include "wx/object.h"
23 #include "wx/string.h"
26 #include "wx/window.h"
29 #include "wx/dcclient.h"
30 #include "wx/button.h"
33 #include "wx/cursor.h"
34 #include "wx/dialog.h"
35 #include "wx/settings.h"
36 #include "wx/msgdlg.h"
37 #include "wx/choice.h"
38 #include "wx/stattext.h"
39 #include "wx/textctrl.h"
40 #include "wx/scrolwin.h"
41 #include "wx/dirdlg.h"
42 #include "wx/combobox.h"
43 #include "wx/layout.h"
45 #include "wx/textdlg.h"
46 #include "wx/filedlg.h"
50 #define __wxPG_SOURCE_FILE__
52 #include <wx/propgrid/propgrid.h>
54 #if wxPG_INCLUDE_ADVPROPS
56 #include <wx/propgrid/advprops.h>
59 #include <wx/msw/private.h>
60 #include <wx/msw/dc.h>
63 // -----------------------------------------------------------------------
65 #if defined(__WXMSW__)
66 #define wxPG_CAN_DRAW_CURSOR 1
67 #elif defined(__WXGTK__)
68 #define wxPG_CAN_DRAW_CURSOR 0
69 #elif defined(__WXMAC__)
70 #define wxPG_CAN_DRAW_CURSOR 0
72 #define wxPG_CAN_DRAW_CURSOR 0
76 // -----------------------------------------------------------------------
78 // -----------------------------------------------------------------------
81 bool operator == (const wxFont
&, const wxFont
&)
86 // Implement dynamic class for type value.
87 IMPLEMENT_DYNAMIC_CLASS(wxColourPropertyValue
, wxObject
)
89 bool operator == (const wxColourPropertyValue
& a
, const wxColourPropertyValue
& b
)
91 return ( ( a
.m_colour
== b
.m_colour
) && (a
.m_type
== b
.m_type
) );
94 bool operator == (const wxArrayInt
& array1
, const wxArrayInt
& array2
)
96 if ( array1
.size() != array2
.size() )
99 for ( i
=0; i
<array1
.size(); i
++ )
101 if ( array1
[i
] != array2
[i
] )
107 // -----------------------------------------------------------------------
108 // wxSpinCtrl-based property editor
109 // -----------------------------------------------------------------------
114 // This macro also defines global wxPGEditor_SpinCtrl for storing
115 // the singleton class instance.
116 WX_PG_IMPLEMENT_EDITOR_CLASS(SpinCtrl
,wxPGSpinCtrlEditor
,wxPGEditor
)
119 // Trivial destructor.
120 wxPGSpinCtrlEditor::~wxPGSpinCtrlEditor()
125 // Create controls and initialize event handling.
126 wxPGWindowList
wxPGSpinCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
127 const wxPoint
& pos
, const wxSize
& sz
) const
129 const int margin
= 1;
130 wxSize
butSz(18, sz
.y
);
131 wxSize
tcSz(sz
.x
- butSz
.x
- margin
, sz
.y
);
132 wxPoint
butPos(pos
.x
+ tcSz
.x
+ margin
, pos
.y
);
134 wxSpinButton
* wnd2
= new wxSpinButton();
138 wnd2
->Create( propgrid
->GetPanel(), wxPG_SUBID2
, butPos
, butSz
, wxSP_VERTICAL
);
140 wnd2
->SetRange( INT_MIN
, INT_MAX
);
143 propgrid
->Connect( wxPG_SUBID2
, wxEVT_SCROLL_LINEUP
,
144 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
145 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propgrid
);
146 propgrid
->Connect( wxPG_SUBID2
, wxEVT_SCROLL_LINEDOWN
,
147 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
148 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propgrid
);
149 propgrid
->Connect( wxPG_SUBID1
, wxEVT_KEY_DOWN
,
150 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
151 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propgrid
);
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 return wxPGWindowList(wnd1
, wnd2
);
162 // Control's events are redirected here
163 bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
164 wxWindow
* wnd
, wxEvent
& event
) const
166 int evtType
= event
.GetEventType();
168 bool bigStep
= false;
170 if ( evtType
== wxEVT_KEY_DOWN
)
172 wxKeyEvent
& keyEvent
= (wxKeyEvent
&)event
;
173 keycode
= keyEvent
.GetKeyCode();
175 if ( keycode
== WXK_UP
)
176 evtType
= wxEVT_SCROLL_LINEUP
;
177 else if ( keycode
== WXK_DOWN
)
178 evtType
= wxEVT_SCROLL_LINEDOWN
;
179 else if ( keycode
== WXK_PAGEUP
)
181 evtType
= wxEVT_SCROLL_LINEUP
;
184 else if ( keycode
== WXK_PAGEDOWN
)
186 evtType
= wxEVT_SCROLL_LINEDOWN
;
191 if ( evtType
== wxEVT_SCROLL_LINEUP
|| evtType
== wxEVT_SCROLL_LINEDOWN
)
194 // Can't use wnd since it might be clipper window
195 wxTextCtrl
* tc
= wxDynamicCast(propgrid
->GetEditorControl(), wxTextCtrl
);
200 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
202 int mode
= wxPG_PROPERTY_VALIDATION_SATURATE
;
204 if ( property
->GetAttributeAsLong(wxT("Wrap"), 0) )
205 mode
= wxPG_PROPERTY_VALIDATION_WRAP
;
207 if ( property
->GetValueType() == wxT("double") )
210 double step
= property
->GetAttributeAsDouble(wxT("Step"), 1.0);
213 if ( s
.ToDouble(&v_d
) )
218 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_d
+= step
;
222 wxFloatProperty::DoValidation(property
, v_d
, NULL
, mode
);
224 wxPropertyGrid::DoubleToString(s
, v_d
, 6, true, NULL
);
234 wxLongLong_t step
= property
->GetAttributeAsLong(wxT("Step"), 1);
237 if ( s
.ToLongLong(&v_ll
, 10) )
242 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_ll
+= step
;
246 wxIntProperty::DoValidation(property
, v_ll
, NULL
, mode
);
248 s
= wxLongLong(v_ll
).ToString();
258 int ip
= tc
->GetInsertionPoint();
259 int lp
= tc
->GetLastPosition();
261 tc
->SetInsertionPoint(ip
+(tc
->GetLastPosition()-lp
));
267 return wxPGTextCtrlEditor::OnEvent(propgrid
,property
,wnd
,event
);
270 #endif // wxUSE_SPINBTN
273 // -----------------------------------------------------------------------
274 // wxDatePickerCtrl-based property editor
275 // -----------------------------------------------------------------------
277 #if wxUSE_DATEPICKCTRL
280 #include <wx/datectrl.h>
281 #include <wx/dateevt.h>
283 class wxPGDatePickerCtrlEditor
: public wxPGEditor
285 WX_PG_DECLARE_EDITOR_CLASS(wxPGDatePickerCtrlEditor
)
287 virtual ~wxPGDatePickerCtrlEditor();
289 wxPG_DECLARE_CREATECONTROLS
291 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const;
292 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
293 wxWindow
* wnd
, wxEvent
& event
) const;
294 virtual bool GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* wnd
) const;
295 virtual void SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const;
299 WX_PG_IMPLEMENT_EDITOR_CLASS(DatePickerCtrl
,wxPGDatePickerCtrlEditor
,wxPGEditor
)
302 wxPGDatePickerCtrlEditor::~wxPGDatePickerCtrlEditor()
306 wxPGWindowList
wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
,
307 wxPGProperty
* property
,
309 const wxSize
& sz
) const
311 wxCHECK_MSG( property
->IsKindOf(CLASSINFO(wxDateProperty
)),
313 wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
315 wxDateProperty
* prop
= (wxDateProperty
*) property
;
317 // Use two stage creation to allow cleaner display on wxMSW
318 wxDatePickerCtrl
* ctrl
= new wxDatePickerCtrl();
321 wxSize useSz
= wxDefaultSize
;
326 ctrl
->Create(propgrid
->GetPanel(),
328 prop
->GetDateValue(),
331 prop
->GetDatePickerStyle() | wxNO_BORDER
);
333 // Connect all required events to grid's OnCustomEditorEvent
334 // (all relevenat wxTextCtrl, wxComboBox and wxButton events are
335 // already connected)
336 propgrid
->Connect( wxPG_SUBID1
, wxEVT_DATE_CHANGED
,
337 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
338 &wxPropertyGrid::OnCustomEditorEvent
);
347 // Copies value from property to control
348 void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const
350 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
351 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
353 // We assume that property's data type is 'int' (or something similar),
354 // thus allowing us to get raw, unchecked value via DoGetValue.
355 ctrl
->SetValue( property
->GetValue().GetDateTime() );
358 // Control's events are redirected here
359 bool wxPGDatePickerCtrlEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propgrid
),
360 wxPGProperty
* WXUNUSED(property
),
361 wxWindow
* WXUNUSED(wnd
),
362 wxEvent
& event
) const
364 if ( event
.GetEventType() == wxEVT_DATE_CHANGED
)
370 bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const
372 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
373 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
375 variant
= ctrl
->GetValue();
380 void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* WXUNUSED(wnd
) ) const
383 //wxDateProperty* prop = (wxDateProperty*) property;
387 #endif // wxUSE_DATEPICKCTRL
390 // -----------------------------------------------------------------------
392 // -----------------------------------------------------------------------
394 #include <wx/fontdlg.h>
395 #include <wx/fontenum.h>
397 static const wxChar
* gs_fp_es_family_labels
[] = {
398 wxT("Default"), wxT("Decorative"),
399 wxT("Roman"), wxT("Script"),
400 wxT("Swiss"), wxT("Modern"),
404 static long gs_fp_es_family_values
[] = {
405 wxDEFAULT
, wxDECORATIVE
,
410 static const wxChar
* gs_fp_es_style_labels
[] = {
417 static long gs_fp_es_style_values
[] = {
423 static const wxChar
* gs_fp_es_weight_labels
[] = {
430 static long gs_fp_es_weight_values
[] = {
436 // Class body is in advprops.h
439 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty
,wxPGProperty
,
440 wxFont
,const wxFont
&,TextCtrlAndButton
)
443 wxFontProperty::wxFontProperty( const wxString
& label
, const wxString
& name
,
444 const wxFont
& value
)
445 : wxPGProperty(label
,name
)
447 SetValue( wxFontToVariant(value
) );
449 // Initialize font family choices list
450 if ( !wxPGGlobalVars
->m_fontFamilyChoices
)
452 wxFontEnumerator enumerator
;
453 enumerator
.EnumerateFacenames();
455 #if wxMINOR_VERSION > 6
456 wxArrayString faceNames
= enumerator
.GetFacenames();
458 wxArrayString
& faceNames
= *enumerator
.GetFacenames();
463 wxPGGlobalVars
->m_fontFamilyChoices
= new wxPGChoices(faceNames
);
466 wxString
emptyString(wxEmptyString
);
468 wxFont
& font
= wxFontFromVariant(m_value
);
470 AddChild( new wxIntProperty( _("Point Size"),emptyString
,(long)font
.GetPointSize() ) );
472 AddChild( new wxEnumProperty(_("Family"), emptyString
,
473 gs_fp_es_family_labels
,gs_fp_es_family_values
,
476 wxString faceName
= font
.GetFaceName();
477 // If font was not in there, add it now
478 if ( faceName
.length() &&
479 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
480 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
482 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"),emptyString
,
483 *wxPGGlobalVars
->m_fontFamilyChoices
);
485 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
489 AddChild( new wxEnumProperty(_("Style"),emptyString
,
490 gs_fp_es_style_labels
,gs_fp_es_style_values
,font
.GetStyle()) );
492 AddChild( new wxEnumProperty(_("Weight"),emptyString
,
493 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,font
.GetWeight()) );
495 AddChild( new wxBoolProperty(_("Underlined"),emptyString
,
496 font
.GetUnderlined()) );
499 wxFontProperty::~wxFontProperty() { }
501 void wxFontProperty::OnSetValue()
503 wxFont
& font
= wxFontFromVariant(m_value
);
508 font2
= wxFont(10,wxSWISS
,wxNORMAL
,wxNORMAL
);
512 m_value
= wxFontToVariant(font2
);
515 wxString
wxFontProperty::GetValueAsString( int argFlags
) const
517 return wxPGProperty::GetValueAsString(argFlags
);
520 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
523 if ( propgrid
->IsMainButtonEvent(event
) )
525 // Update value from last minute changes
526 PrepareValueForDialogEditing(propgrid
);
529 data
.SetInitialFont( wxFontFromVariant(m_value
) );
530 data
.SetColour(*wxBLACK
);
532 wxFontDialog
dlg(propgrid
, data
);
533 if ( dlg
.ShowModal() == wxID_OK
)
535 propgrid
->EditorsValueWasModified();
537 wxVariant variant
= wxFontToVariant(dlg
.GetFontData().GetChosenFont());
538 SetValueInEvent( variant
);
545 void wxFontProperty::RefreshChildren()
547 if ( !GetChildCount() ) return;
548 const wxFont
& font
= wxFontFromVariant(m_value
);
549 Item(0)->SetValue( (long)font
.GetPointSize() );
550 Item(1)->SetValue( (long)font
.GetFamily() );
551 Item(2)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
552 Item(3)->SetValue( (long)font
.GetStyle() );
553 Item(4)->SetValue( (long)font
.GetWeight() );
554 Item(5)->SetValue( font
.GetUnderlined() );
557 void wxFontProperty::ChildChanged( wxVariant
& thisValue
, int ind
, wxVariant
& childValue
) const
559 wxFont
& font
= wxFontFromVariant(thisValue
);
563 font
.SetPointSize( wxPGVariantToInt(childValue
) );
567 int fam
= childValue
.GetLong();
568 if ( fam
< wxDEFAULT
||
571 font
.SetFamily( fam
);
576 int faceIndex
= childValue
.GetLong();
578 if ( faceIndex
>= 0 )
579 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
581 font
.SetFaceName( faceName
);
585 int st
= childValue
.GetLong();
586 if ( st
!= wxFONTSTYLE_NORMAL
&&
587 st
!= wxFONTSTYLE_SLANT
&&
588 st
!= wxFONTSTYLE_ITALIC
)
589 st
= wxFONTWEIGHT_NORMAL
;
594 int wt
= childValue
.GetLong();
595 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
596 wt
!= wxFONTWEIGHT_LIGHT
&&
597 wt
!= wxFONTWEIGHT_BOLD
)
598 wt
= wxFONTWEIGHT_NORMAL
;
599 font
.SetWeight( wt
);
603 font
.SetUnderlined( childValue
.GetBool() );
608 wxSize wxFontProperty::OnMeasureImage() const
610 return wxSize(-1,-1);
613 void wxFontProperty::OnCustomPaint(wxDC& dc,
615 wxPGPaintData& paintData)
618 if ( paintData.m_choiceItem >= 0 )
619 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
621 drawFace = m_value_wxFont.GetFaceName();
623 if ( drawFace.length() )
625 // Draw the background
626 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
627 //dc.SetBrush( *wxWHITE_BRUSH );
628 //dc.SetPen( *wxMEDIUM_GREY_PEN );
629 dc.DrawRectangle( rect );
631 wxFont oldFont = dc.GetFont();
632 wxFont drawFont(oldFont.GetPointSize(),
633 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
634 dc.SetFont(drawFont);
636 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
637 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
643 // No file - just draw a white box
644 dc.SetBrush ( *wxWHITE_BRUSH );
645 dc.DrawRectangle ( rect );
651 // -----------------------------------------------------------------------
652 // wxSystemColourProperty
653 // -----------------------------------------------------------------------
655 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
656 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
658 #include <wx/colordlg.h>
660 //#define wx_cp_es_syscolours_len 25
661 static const wxChar
* gs_cp_es_syscolour_labels
[] = {
664 wxT("ActiveCaption"),
666 wxT("ButtonHighlight"),
675 wxT("HighlightText"),
676 wxT("InactiveBorder"),
677 wxT("InactiveCaption"),
678 wxT("InactiveCaptionText"),
690 static long gs_cp_es_syscolour_values
[] = {
691 wxSYS_COLOUR_APPWORKSPACE
,
692 wxSYS_COLOUR_ACTIVEBORDER
,
693 wxSYS_COLOUR_ACTIVECAPTION
,
694 wxSYS_COLOUR_BTNFACE
,
695 wxSYS_COLOUR_BTNHIGHLIGHT
,
696 wxSYS_COLOUR_BTNSHADOW
,
697 wxSYS_COLOUR_BTNTEXT
,
698 wxSYS_COLOUR_CAPTIONTEXT
,
699 wxSYS_COLOUR_3DDKSHADOW
,
700 wxSYS_COLOUR_3DLIGHT
,
701 wxSYS_COLOUR_BACKGROUND
,
702 wxSYS_COLOUR_GRAYTEXT
,
703 wxSYS_COLOUR_HIGHLIGHT
,
704 wxSYS_COLOUR_HIGHLIGHTTEXT
,
705 wxSYS_COLOUR_INACTIVEBORDER
,
706 wxSYS_COLOUR_INACTIVECAPTION
,
707 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
709 wxSYS_COLOUR_SCROLLBAR
,
711 wxSYS_COLOUR_INFOTEXT
,
713 wxSYS_COLOUR_WINDOWFRAME
,
714 wxSYS_COLOUR_WINDOWTEXT
,
719 WX_PG_IMPLEMENT_WXOBJECT_VARIANT_DATA(wxPGVariantDataColourPropertyValue
, wxColourPropertyValue
)
722 // Class body is in advprops.h
724 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
725 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
728 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
730 wxColourPropertyValue cpv
;
733 cpv
.Init( type
, colour
);
735 cpv
.Init( type
, *wxWHITE
);
737 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
739 m_value
= wxColourPropertyValueToVariant(cpv
);
745 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
748 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
749 const wxColourPropertyValue
& value
)
750 : wxEnumProperty( label
,
752 gs_cp_es_syscolour_labels
,
753 gs_cp_es_syscolour_values
,
754 &gs_wxSystemColourProperty_choicesCache
)
757 Init( value
.m_type
, value
.m_colour
);
759 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
763 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
764 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
765 const wxColourPropertyValue
& value
)
766 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
769 Init( value
.m_type
, value
.m_colour
);
771 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
775 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
776 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
777 const wxColour
& value
)
778 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
781 Init( wxPG_COLOUR_CUSTOM
, value
);
783 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
787 wxSystemColourProperty::~wxSystemColourProperty() { }
790 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
795 if ( pVariant
->IsNull() )
796 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
798 wxColourPropertyValue
* v1
= &wxColourPropertyValueFromVariant(*pVariant
);
802 wxColour
* pCol
= wxGetVariantCast(*pVariant
, wxColour
);
804 bool variantProcessed
= true;
810 else if ( pVariant
->GetType() == wxT("wxArrayInt") )
815 if ( arr
.size() >= 3 )
823 if ( arr
.size() >= 4 )
826 col
= wxColour(r
, g
, b
, a
);
830 variantProcessed
= false;
833 else if ( pVariant
->GetType() == wxT("wxColour") )
839 variantProcessed
= false;
842 if ( !variantProcessed
)
843 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
845 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
847 int colInd
= ColToInd(col
);
848 if ( colInd
!= wxNOT_FOUND
)
854 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
856 return wxColourPropertyValueToVariant(v
);
859 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
862 size_t i_max
= m_choices
.GetCount() - 1;
864 for ( i
=0; i
<i_max
; i
++ )
866 int ind
= m_choices
[i
].GetValue();
868 if ( colour
== GetColour(ind
) )
870 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
871 GetClassName(),GetLabel().c_str(),
872 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
873 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
881 static inline wxColour
wxColourFromPGLong( long col
)
883 return wxColour((col
&0xFF),((col
>>8)&0xFF),((col
>>16)&0xFF));
887 void wxSystemColourProperty::OnSetValue()
889 // Convert from generic wxobject ptr to wxPGVariantDataColour
890 if ( wxPGIsVariantType(m_value
, wxobject
) )
892 wxASSERT( m_value
.IsValueKindOf(CLASSINFO(wxColour
)) );
893 wxColour
* pCol
= (wxColour
*) m_value
.GetWxObjectPtr();
897 wxColourPropertyValue val
= GetVal(&m_value
);
899 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
907 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
908 val
.m_colour
= GetColour( val
.m_type
);
910 m_value
= TranslateVal(val
);
913 wxColourPropertyValue
* pCpv
= &wxColourPropertyValueFromVariant(m_value
);
916 col
= pCpv
->m_colour
;
922 SetValueToUnspecified();
923 SetIndex(wxNOT_FOUND
);
931 if ( pCpv
->m_type
< wxPG_COLOUR_WEB_BASE
)
933 if ( m_choices
.HasValues() )
934 ind
= GetIndexForValue(pCpv
->m_type
);
940 pCpv
->m_type
= wxPG_COLOUR_CUSTOM
;
941 ind
= GetCustomColourIndex();
948 if ( ind
== wxNOT_FOUND
)
949 ind
= GetCustomColourIndex();
956 wxColour
wxSystemColourProperty::GetColour( int index
) const
958 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
961 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
963 if ( index
== wxNOT_FOUND
)
964 return wxString::Format(wxT("(%i,%i,%i)"),
969 return m_choices
.GetLabel(index
);
972 wxString
wxSystemColourProperty::GetValueAsString( int argFlags
) const
974 wxColourPropertyValue val
= GetVal();
976 int ind
= GetIndex();
978 // Always show custom colour for textctrl-editor
979 if ( val
.m_type
== wxPG_COLOUR_CUSTOM
||
980 ind
== GetCustomColourIndex() ||
981 (argFlags
& wxPG_PROPERTY_SPECIFIC
) )
983 return ColourToString(val
.m_colour
, wxNOT_FOUND
);
987 return wxEmptyString
;
989 return ColourToString(val
.m_colour
, ind
);
993 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
995 return wxPG_DEFAULT_IMAGE_SIZE
;
999 int wxSystemColourProperty::GetCustomColourIndex() const
1001 return m_choices
.GetCount() - 1;
1005 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1007 wxASSERT( m_value
.GetType() != wxT("string") );
1010 wxPropertyGrid
* propgrid
= GetGrid();
1011 wxASSERT( propgrid
);
1013 // Must only occur when user triggers event
1014 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_ONCUSTOMEDITOREVENT
) )
1017 wxColourPropertyValue val
= GetVal();
1019 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1022 data
.SetChooseFull(true);
1023 data
.SetColour(val
.m_colour
);
1025 for ( i
= 0; i
< 16; i
++)
1027 wxColour
colour(i
*16, i
*16, i
*16);
1028 data
.SetCustomColour(i
, colour
);
1031 wxColourDialog
dialog(propgrid
, &data
);
1032 if ( dialog
.ShowModal() == wxID_OK
)
1034 wxColourData retData
= dialog
.GetColourData();
1035 val
.m_colour
= retData
.GetColour();
1037 variant
= DoTranslateVal(val
);
1039 SetValueInEvent(variant
);
1048 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1051 int type
= GetValueForIndex(index
);
1052 bool hasValue
= m_choices
[index
].HasValue();
1054 if ( ( hasValue
&& type
== wxPG_COLOUR_CUSTOM
) ||
1055 ( !hasValue
&& (index
== (int)GetCustomColourIndex() &&
1056 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
))
1060 QueryColourFromUser(variant
);
1064 variant
= TranslateVal( type
, GetColour(type
) );
1070 // Need to do some extra event handling.
1071 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
), wxEvent
& event
)
1073 if ( propgrid
->IsMainButtonEvent(event
) )
1075 // We need to handle button click in case editor has been
1076 // switched to one that has wxButton as well.
1078 if ( QueryColourFromUser(variant
) )
1084 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1087 virtual void Render( wxDC& dc, const wxRect& rect,
1088 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1089 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1091 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1092 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1094 dc.SetPen(*wxBLACK_PEN);
1096 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1100 const wxArrayInt& values = prop->GetValues();
1101 if ( values.GetChildCount() )
1102 colInd = values[item];
1105 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1107 else if ( !prop->IsValueUnspecified() )
1108 dc.SetBrush( prop->GetVal().m_colour );
1110 dc.SetBrush( *wxWHITE );
1112 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1113 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1114 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1115 imageRect.width, imageRect.height );
1119 text = property->GetValueAsString();
1121 text = property->GetChoiceString(item);
1122 DrawText( dc, rect, imageRect.width, text );
1127 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1129 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1132 return &g_wxPGColourPropertyRenderer;
1133 return wxEnumProperty::GetCellRenderer(column);
1136 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1137 wxPGPaintData
& paintdata
)
1141 if ( paintdata
.m_choiceItem
>= 0 && paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1142 paintdata
.m_choiceItem
!= GetCustomColourIndex() )
1144 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1145 col
= GetColour( colInd
);
1147 else if ( !IsValueUnspecified() )
1149 col
= GetVal().m_colour
;
1155 dc
.DrawRectangle(rect
);
1160 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1163 // Accept colour format "[Name] [(R,G,B)]"
1164 // Name takes precedence.
1166 wxString colourName
;
1169 int ppos
= text
.Find(wxT("("));
1171 if ( ppos
== wxNOT_FOUND
)
1177 colourName
= text
.substr(0, ppos
);
1178 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1181 // Strip spaces from extremities
1182 colourName
.Trim(true);
1183 colourName
.Trim(false);
1184 colourRGB
.Trim(true);
1186 // Validate colourRGB string - (1,1,1) is shortest allowed
1187 if ( colourRGB
.length() < 7 )
1190 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1191 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1193 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1195 // This really should not occurr...
1201 QueryColourFromUser(value
);
1205 wxColourPropertyValue val
;
1209 if ( colourName
.length() )
1211 // Try predefined colour first
1212 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1213 if ( res
&& GetIndex() >= 0 )
1215 val
.m_type
= GetIndex();
1216 if ( val
.m_type
>= 0 && val
.m_type
< m_choices
.GetCount() && m_choices
[val
.m_type
].HasValue() )
1217 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1219 // Get proper colour for type.
1220 val
.m_colour
= GetColour(val
.m_type
);
1225 if ( colourRGB
.length() && !done
)
1227 // Then check custom colour.
1228 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1230 int r
= -1, g
= -1, b
= -1;
1231 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1233 if ( r
>= 0 && r
<= 255 &&
1234 g
>= 0 && g
<= 255 &&
1235 b
>= 0 && b
<= 255 )
1237 val
.m_colour
.Set(r
,g
,b
);
1249 value
= DoTranslateVal(val
);
1256 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1258 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1260 int ival
= wxPGVariantToInt(value
);
1262 SetChoicesExclusive(); // Make sure we don't corrupt colour lists of other properties
1264 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1266 // Show custom choice
1267 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1268 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1270 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1272 // Hide custom choice
1273 m_choices
.RemoveAt(GetCustomColourIndex());
1274 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1282 // -----------------------------------------------------------------------
1284 // -----------------------------------------------------------------------
1286 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1306 (const wxChar
*) NULL
1309 static unsigned long gs_cp_es_normcolour_colours
[] = {
1311 wxPG_COLOUR(128,0,0),
1312 wxPG_COLOUR(0,0,128),
1313 wxPG_COLOUR(128,0,128),
1314 wxPG_COLOUR(0,128,128),
1315 wxPG_COLOUR(128,128,128),
1316 wxPG_COLOUR(0,128,0),
1317 wxPG_COLOUR(128,128,0),
1318 wxPG_COLOUR(166,124,81),
1319 wxPG_COLOUR(0,0,255),
1320 wxPG_COLOUR(255,0,255),
1321 wxPG_COLOUR(255,0,0),
1322 wxPG_COLOUR(247,148,28),
1323 wxPG_COLOUR(192,192,192),
1324 wxPG_COLOUR(0,255,0),
1325 wxPG_COLOUR(0,255,255),
1326 wxPG_COLOUR(255,255,0),
1327 wxPG_COLOUR(255,255,255),
1331 WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(wxColourProperty
,
1332 gs_cp_es_normcolour_labels
,
1334 gs_cp_es_normcolour_colours
,
1337 // -----------------------------------------------------------------------
1339 // -----------------------------------------------------------------------
1341 #define wxPG_CURSOR_IMAGE_WIDTH 32
1343 #define NUM_CURSORS 28
1345 //#define wx_cp_es_syscursors_len 28
1346 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1358 wxT("Middle Button"),
1364 wxT("Question Arrow"),
1365 wxT("Right Button"),
1366 wxT("Sizing NE-SW"),
1368 wxT("Sizing NW-SE"),
1375 (const wxChar
*) NULL
1378 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1381 wxCURSOR_RIGHT_ARROW
,
1388 wxCURSOR_LEFT_BUTTON
,
1390 wxCURSOR_MIDDLE_BUTTON
,
1392 wxCURSOR_PAINT_BRUSH
,
1394 wxCURSOR_POINT_LEFT
,
1395 wxCURSOR_POINT_RIGHT
,
1396 wxCURSOR_QUESTION_ARROW
,
1397 wxCURSOR_RIGHT_BUTTON
,
1409 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1411 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1413 : wxEnumProperty( label
,
1415 gs_cp_es_syscursors_labels
,
1416 gs_cp_es_syscursors_values
,
1419 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1422 wxCursorProperty::~wxCursorProperty()
1426 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1428 #if wxPG_CAN_DRAW_CURSOR
1429 if ( item
!= -1 && item
< NUM_CURSORS
)
1430 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1437 #if wxPG_CAN_DRAW_CURSOR
1439 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1441 wxPGPaintData
& paintdata
)
1444 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1446 if ( paintdata
.m_choiceItem
>= 0 )
1448 dc
.DrawRectangle( rect
);
1450 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1452 int cursorindex
= gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1455 if ( cursorindex
== wxCURSOR_NONE
)
1456 cursorindex
= wxCURSOR_ARROW
;
1458 wxCursor
cursor( cursorindex
);
1461 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1465 (HICON
)cursor
.GetHandle(),
1470 DI_COMPAT
| DI_DEFAULTSIZE
| DI_NORMAL
1479 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1480 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1482 return wxEnumProperty::GetCellRenderer(column);
1486 // -----------------------------------------------------------------------
1487 // wxImageFileProperty
1488 // -----------------------------------------------------------------------
1492 const wxString
& wxPGGetDefaultImageWildcard()
1494 // Form the wildcard, if not done yet
1495 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1500 // TODO: This section may require locking (using global).
1502 wxList
& handlers
= wxImage::GetHandlers();
1504 wxList::iterator node
;
1506 // Let's iterate over the image handler list.
1507 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1508 for ( node
= handlers
.begin(); node
!= handlers
.end(); node
++ )
1510 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1512 wxString ext_lo
= handler
->GetExtension();
1513 wxString ext_up
= ext_lo
.Upper();
1515 str
.append( ext_up
);
1516 str
.append( wxT(" files (*.") );
1517 str
.append( ext_up
);
1518 str
.append( wxT(")|*.") );
1519 str
.append( ext_lo
);
1520 str
.append( wxT("|") );
1523 str
.append ( wxT("All files (*.*)|*.*") );
1525 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1528 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1531 WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(wxImageFileProperty
,
1535 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1536 const wxString
& value
)
1537 : wxFileProperty(label
,name
,value
)
1539 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1541 m_pImage
= (wxImage
*) NULL
;
1542 m_pBitmap
= (wxBitmap
*) NULL
;
1545 wxImageFileProperty::~wxImageFileProperty()
1553 void wxImageFileProperty::OnSetValue()
1555 wxFileProperty::OnSetValue();
1569 // Create the image thumbnail
1570 if ( m_filename
.FileExists() )
1572 m_pImage
= new wxImage( m_filename
.GetFullPath() );
1576 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1578 return wxPG_DEFAULT_IMAGE_SIZE
;
1581 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1585 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1587 // Draw the thumbnail
1589 // Create the bitmap here because required size is not known in OnSetValue().
1592 m_pImage
->Rescale( rect
.width
, rect
.height
);
1593 m_pBitmap
= new wxBitmap( *m_pImage
);
1598 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1602 // No file - just draw a white box
1603 dc
.SetBrush( *wxWHITE_BRUSH
);
1604 dc
.DrawRectangle ( rect
);
1608 #endif // wxUSE_IMAGE
1610 // -----------------------------------------------------------------------
1611 // wxMultiChoiceProperty
1612 // -----------------------------------------------------------------------
1616 #include <wx/choicdlg.h>
1618 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1619 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1621 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1622 const wxString
& name
,
1623 const wxPGChoices
& choices
,
1624 const wxArrayString
& value
)
1625 : wxPGProperty(label
,name
)
1627 m_choices
.Assign(choices
);
1631 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1632 const wxString
& name
,
1633 const wxArrayString
& strings
,
1634 const wxArrayString
& value
)
1635 : wxPGProperty(label
,name
)
1637 m_choices
.Set(strings
);
1641 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1642 const wxString
& name
,
1643 const wxArrayString
& value
)
1644 : wxPGProperty(label
,name
)
1646 wxArrayString strings
;
1647 m_choices
.Set(strings
);
1651 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1655 void wxMultiChoiceProperty::OnSetValue()
1657 GenerateValueAsString();
1660 wxString
wxMultiChoiceProperty::GetValueAsString( int ) const
1665 void wxMultiChoiceProperty::GenerateValueAsString()
1667 wxArrayString strings
;
1669 if ( wxPGIsVariantType(m_value
, arrstring
) )
1670 strings
= m_value
.GetArrayString();
1672 wxString
& tempStr
= m_display
;
1674 unsigned int itemCount
= strings
.size();
1679 tempStr
.append( wxT("\"") );
1681 for ( i
= 0; i
< itemCount
; i
++ )
1683 tempStr
.append( strings
[i
] );
1684 tempStr
.append( wxT("\"") );
1685 if ( i
< (itemCount
-1) )
1686 tempStr
.append ( wxT(" \"") );
1690 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1692 const wxArrayInt
& valueArr
= wxArrayIntFromVariant(GetValue());
1695 // Translate values to string indices.
1696 wxArrayInt selections
;
1698 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1700 for ( i
=0; i
<valueArr
.size(); i
++ )
1705 for ( i
=0; i
<valueArr
.size(); i
++ )
1707 int sIndex
= m_choices
.Index(valueArr
[i
]);
1709 selections
.Add(sIndex
);
1716 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1717 wxWindow
* WXUNUSED(primary
),
1720 if ( propgrid
->IsMainButtonEvent(event
) )
1723 PrepareValueForDialogEditing(propgrid
);
1725 wxArrayString labels
= m_choices
.GetLabels();
1726 unsigned int choiceCount
;
1728 if ( m_choices
.IsOk() )
1729 choiceCount
= m_choices
.GetCount();
1733 // launch editor dialog
1734 wxMultiChoiceDialog
dlg( propgrid
,
1735 _("Make a selection:"),
1738 choiceCount
?&labels
[0]:NULL
,
1739 wxCHOICEDLG_STYLE
);
1741 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
1743 wxArrayString strings
= m_value
.GetArrayString();
1744 wxArrayString extraStrings
;
1746 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
1748 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
1750 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1752 wxArrayInt arrInt
= dlg
.GetSelections();
1756 // Strings that were not in list of choices
1757 wxArrayString value
;
1759 // Translate string indices to strings
1762 if ( userStringMode
== 1 )
1764 for (n
=0;n
<extraStrings
.size();n
++)
1765 value
.push_back(extraStrings
[n
]);
1769 for ( i
=0; i
<arrInt
.size(); i
++ )
1770 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
1772 if ( userStringMode
== 2 )
1774 for (n
=0;n
<extraStrings
.size();n
++)
1775 value
.push_back(extraStrings
[n
]);
1778 variant
= WXVARIANT(value
);
1780 SetValueInEvent(variant
);
1788 int wxMultiChoiceProperty::GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
)
1791 choiceinfo
->m_choices
= &m_choices
;
1795 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1799 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1801 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
1802 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
1804 WX_PG_TOKENIZER2_END()
1806 wxVariant
v( WXVARIANT(arr
) );
1812 #endif // wxUSE_CHOICEDLG
1815 // -----------------------------------------------------------------------
1817 // -----------------------------------------------------------------------
1822 #if wxUSE_DATEPICKCTRL
1823 #define dtCtrl DatePickerCtrl
1825 #define dtCtrl TextCtrl
1828 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
1835 wxString
wxDateProperty::ms_defaultDateFormat
;
1838 wxDateProperty::wxDateProperty( const wxString
& label
,
1839 const wxString
& name
,
1840 const wxDateTime
& value
)
1841 : wxPGProperty(label
,name
)
1843 //wxPGRegisterDefaultValueType(wxDateTime)
1845 #if wxUSE_DATEPICKCTRL
1846 wxPGRegisterEditorClass(DatePickerCtrl
);
1848 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
1856 wxDateProperty::~wxDateProperty()
1860 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
1861 int WXUNUSED(argFlags
) ) const
1865 const char* c
= dt
.ParseFormat(text
, wxString(wxDefaultDateTimeFormat
), wxDefaultDateTime
, NULL
);
1876 wxString
wxDateProperty::GetValueAsString( int argFlags
) const
1878 const wxChar
* format
= (const wxChar
*) NULL
;
1880 wxDateTime dateTime
= m_value
.GetDateTime();
1882 if ( !dateTime
.IsValid() )
1883 return wxT("Invalid");
1885 if ( !ms_defaultDateFormat
.length() )
1887 #if wxUSE_DATEPICKCTRL
1888 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
1890 bool showCentury
= true;
1892 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
1895 if ( m_format
.length() &&
1896 !(argFlags
& wxPG_FULL_VALUE
) )
1897 format
= m_format
.c_str();
1899 // Determine default from locale
1900 // NB: This is really simple stuff, but can't figure anything
1901 // better without proper support in wxLocale
1903 format
= ms_defaultDateFormat
.c_str();
1905 return dateTime
.Format(format
);
1908 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
1910 // This code is basicly copied from datectlg.cpp's SetFormat
1915 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
1916 wxString
str(dt
.Format(wxT("%x")));
1918 const wxChar
*p
= str
.c_str();
1922 if (n
== dt
.GetDay())
1924 format
.Append(wxT("%d"));
1927 else if (n
== (int)dt
.GetMonth()+1)
1929 format
.Append(wxT("%m"));
1932 else if (n
== dt
.GetYear())
1934 format
.Append(wxT("%Y"));
1937 else if (n
== (dt
.GetYear() % 100))
1940 format
.Append(wxT("%Y"));
1942 format
.Append(wxT("%y"));
1946 format
.Append(*p
++);
1952 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1954 if ( name
== wxPG_DATE_FORMAT
)
1956 m_format
= value
.GetString();
1959 else if ( name
== wxPG_DATE_PICKER_STYLE
)
1961 m_dpStyle
= value
.GetLong();
1962 ms_defaultDateFormat
.clear(); // This may need recalculation
1968 #endif // wxUSE_DATETIME
1971 // -----------------------------------------------------------------------
1972 // wxPropertyGridInterface
1973 // -----------------------------------------------------------------------
1975 void wxPropertyGridInterface::InitAllTypeHandlers()
1979 // -----------------------------------------------------------------------
1981 void wxPropertyGridInterface::RegisterAdditionalEditors()
1984 wxPGRegisterEditorClass(SpinCtrl
);
1986 #if wxUSE_DATEPICKCTRL
1987 wxPGRegisterEditorClass(DatePickerCtrl
);
1991 // -----------------------------------------------------------------------
1993 #endif // wxPG_INCLUDE_ADVPROPS