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 // This macro also defines global wxPGEditor_SpinCtrl for storing
117 // the singleton class instance.
118 WX_PG_IMPLEMENT_EDITOR_CLASS(SpinCtrl
,wxPGSpinCtrlEditor
,wxPGEditor
)
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 propgrid
->Connect( wxPG_SUBID2
, wxEVT_SCROLL_LINEUP
,
146 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
147 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propgrid
);
148 propgrid
->Connect( wxPG_SUBID2
, wxEVT_SCROLL_LINEDOWN
,
149 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
150 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propgrid
);
151 propgrid
->Connect( wxPG_SUBID1
, wxEVT_KEY_DOWN
,
152 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
153 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propgrid
);
155 // Let's add validator to make sure only numbers can be entered
156 wxTextValidator
validator(wxFILTER_NUMERIC
, &m_tempString
);
158 wxTextCtrl
* wnd1
= (wxTextCtrl
*) wxPGTextCtrlEditor::CreateControls( propgrid
, property
, pos
, tcSz
).m_primary
;
159 wnd1
->SetValidator(validator
);
161 return wxPGWindowList(wnd1
, wnd2
);
164 // Control's events are redirected here
165 bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
166 wxWindow
* wnd
, wxEvent
& event
) const
168 int evtType
= event
.GetEventType();
170 bool bigStep
= false;
172 if ( evtType
== wxEVT_KEY_DOWN
)
174 wxKeyEvent
& keyEvent
= (wxKeyEvent
&)event
;
175 keycode
= keyEvent
.GetKeyCode();
177 if ( keycode
== WXK_UP
)
178 evtType
= wxEVT_SCROLL_LINEUP
;
179 else if ( keycode
== WXK_DOWN
)
180 evtType
= wxEVT_SCROLL_LINEDOWN
;
181 else if ( keycode
== WXK_PAGEUP
)
183 evtType
= wxEVT_SCROLL_LINEUP
;
186 else if ( keycode
== WXK_PAGEDOWN
)
188 evtType
= wxEVT_SCROLL_LINEDOWN
;
193 if ( evtType
== wxEVT_SCROLL_LINEUP
|| evtType
== wxEVT_SCROLL_LINEDOWN
)
196 // Can't use wnd since it might be clipper window
197 wxTextCtrl
* tc
= wxDynamicCast(propgrid
->GetEditorControl(), wxTextCtrl
);
202 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
204 int mode
= wxPG_PROPERTY_VALIDATION_SATURATE
;
206 if ( property
->GetAttributeAsLong(wxT("Wrap"), 0) )
207 mode
= wxPG_PROPERTY_VALIDATION_WRAP
;
209 if ( property
->GetValueType() == wxT("double") )
212 double step
= property
->GetAttributeAsDouble(wxT("Step"), 1.0);
215 if ( s
.ToDouble(&v_d
) )
220 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_d
+= step
;
224 wxFloatProperty::DoValidation(property
, v_d
, NULL
, mode
);
226 wxPropertyGrid::DoubleToString(s
, v_d
, 6, true, NULL
);
236 wxLongLong_t step
= property
->GetAttributeAsLong(wxT("Step"), 1);
239 if ( s
.ToLongLong(&v_ll
, 10) )
244 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_ll
+= step
;
248 wxIntProperty::DoValidation(property
, v_ll
, NULL
, mode
);
250 s
= wxLongLong(v_ll
).ToString();
260 int ip
= tc
->GetInsertionPoint();
261 int lp
= tc
->GetLastPosition();
263 tc
->SetInsertionPoint(ip
+(tc
->GetLastPosition()-lp
));
269 return wxPGTextCtrlEditor::OnEvent(propgrid
,property
,wnd
,event
);
272 #endif // wxUSE_SPINBTN
275 // -----------------------------------------------------------------------
276 // wxDatePickerCtrl-based property editor
277 // -----------------------------------------------------------------------
279 #if wxUSE_DATEPICKCTRL
282 #include <wx/datectrl.h>
283 #include <wx/dateevt.h>
285 class wxPGDatePickerCtrlEditor
: public wxPGEditor
287 WX_PG_DECLARE_EDITOR_CLASS(wxPGDatePickerCtrlEditor
)
289 virtual ~wxPGDatePickerCtrlEditor();
291 wxPG_DECLARE_CREATECONTROLS
293 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const;
294 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
295 wxWindow
* wnd
, wxEvent
& event
) const;
296 virtual bool GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* wnd
) const;
297 virtual void SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const;
301 WX_PG_IMPLEMENT_EDITOR_CLASS(DatePickerCtrl
,wxPGDatePickerCtrlEditor
,wxPGEditor
)
304 wxPGDatePickerCtrlEditor::~wxPGDatePickerCtrlEditor()
308 wxPGWindowList
wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
,
309 wxPGProperty
* property
,
311 const wxSize
& sz
) const
313 wxCHECK_MSG( property
->IsKindOf(CLASSINFO(wxDateProperty
)),
315 wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
317 wxDateProperty
* prop
= (wxDateProperty
*) property
;
319 // Use two stage creation to allow cleaner display on wxMSW
320 wxDatePickerCtrl
* ctrl
= new wxDatePickerCtrl();
323 wxSize useSz
= wxDefaultSize
;
328 ctrl
->Create(propgrid
->GetPanel(),
330 prop
->GetDateValue(),
333 prop
->GetDatePickerStyle() | wxNO_BORDER
);
335 // Connect all required events to grid's OnCustomEditorEvent
336 // (all relevenat wxTextCtrl, wxComboBox and wxButton events are
337 // already connected)
338 propgrid
->Connect( wxPG_SUBID1
, wxEVT_DATE_CHANGED
,
339 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
340 &wxPropertyGrid::OnCustomEditorEvent
);
349 // Copies value from property to control
350 void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const
352 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
353 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
355 // We assume that property's data type is 'int' (or something similar),
356 // thus allowing us to get raw, unchecked value via DoGetValue.
357 ctrl
->SetValue( property
->GetValue().GetDateTime() );
360 // Control's events are redirected here
361 bool wxPGDatePickerCtrlEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propgrid
),
362 wxPGProperty
* WXUNUSED(property
),
363 wxWindow
* WXUNUSED(wnd
),
364 wxEvent
& event
) const
366 if ( event
.GetEventType() == wxEVT_DATE_CHANGED
)
372 bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const
374 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
375 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
377 variant
= ctrl
->GetValue();
382 void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* WXUNUSED(wnd
) ) const
385 //wxDateProperty* prop = (wxDateProperty*) property;
389 #endif // wxUSE_DATEPICKCTRL
392 // -----------------------------------------------------------------------
394 // -----------------------------------------------------------------------
396 #include <wx/fontdlg.h>
397 #include <wx/fontenum.h>
399 static const wxChar
* gs_fp_es_family_labels
[] = {
400 wxT("Default"), wxT("Decorative"),
401 wxT("Roman"), wxT("Script"),
402 wxT("Swiss"), wxT("Modern"),
406 static long gs_fp_es_family_values
[] = {
407 wxDEFAULT
, wxDECORATIVE
,
412 static const wxChar
* gs_fp_es_style_labels
[] = {
419 static long gs_fp_es_style_values
[] = {
425 static const wxChar
* gs_fp_es_weight_labels
[] = {
432 static long gs_fp_es_weight_values
[] = {
438 // Class body is in advprops.h
441 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty
,wxPGProperty
,
442 wxFont
,const wxFont
&,TextCtrlAndButton
)
445 wxFontProperty::wxFontProperty( const wxString
& label
, const wxString
& name
,
446 const wxFont
& value
)
447 : wxPGProperty(label
,name
)
449 SetValue(WXVARIANT(value
));
451 // Initialize font family choices list
452 if ( !wxPGGlobalVars
->m_fontFamilyChoices
)
454 wxFontEnumerator enumerator
;
455 enumerator
.EnumerateFacenames();
457 #if wxMINOR_VERSION > 6
458 wxArrayString faceNames
= enumerator
.GetFacenames();
460 wxArrayString
& faceNames
= *enumerator
.GetFacenames();
465 wxPGGlobalVars
->m_fontFamilyChoices
= new wxPGChoices(faceNames
);
468 wxString
emptyString(wxEmptyString
);
473 AddChild( new wxIntProperty( _("Point Size"), wxS("Point Size"),(long)font
.GetPointSize() ) );
475 AddChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
476 gs_fp_es_family_labels
,gs_fp_es_family_values
,
479 wxString faceName
= font
.GetFaceName();
480 // If font was not in there, add it now
481 if ( faceName
.length() &&
482 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
483 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
485 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"), wxS("Face Name"),
486 *wxPGGlobalVars
->m_fontFamilyChoices
);
488 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
492 AddChild( new wxEnumProperty(_("Style"), wxS("Style"),
493 gs_fp_es_style_labels
,gs_fp_es_style_values
,font
.GetStyle()) );
495 AddChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
496 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,font
.GetWeight()) );
498 AddChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
499 font
.GetUnderlined()) );
502 wxFontProperty::~wxFontProperty() { }
504 void wxFontProperty::OnSetValue()
511 font
= wxFont(10,wxSWISS
,wxNORMAL
,wxNORMAL
);
516 wxString
wxFontProperty::GetValueAsString( int argFlags
) const
518 return wxPGProperty::GetValueAsString(argFlags
);
521 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
524 if ( propgrid
->IsMainButtonEvent(event
) )
526 // Update value from last minute changes
527 PrepareValueForDialogEditing(propgrid
);
532 data
.SetInitialFont( font
);
533 data
.SetColour(*wxBLACK
);
535 wxFontDialog
dlg(propgrid
, data
);
536 if ( dlg
.ShowModal() == wxID_OK
)
538 propgrid
->EditorsValueWasModified();
541 variant
<< dlg
.GetFontData().GetChosenFont();
542 SetValueInEvent( variant
);
549 void wxFontProperty::RefreshChildren()
551 if ( !GetChildCount() ) return;
554 Item(0)->SetValue( (long)font
.GetPointSize() );
555 Item(1)->SetValue( (long)font
.GetFamily() );
556 Item(2)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
557 Item(3)->SetValue( (long)font
.GetStyle() );
558 Item(4)->SetValue( (long)font
.GetWeight() );
559 Item(5)->SetValue( font
.GetUnderlined() );
562 void wxFontProperty::ChildChanged( wxVariant
& thisValue
, int ind
, wxVariant
& childValue
) const
569 font
.SetPointSize( wxPGVariantToInt(childValue
) );
573 int fam
= childValue
.GetLong();
574 if ( fam
< wxDEFAULT
||
577 font
.SetFamily( fam
);
582 int faceIndex
= childValue
.GetLong();
584 if ( faceIndex
>= 0 )
585 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
587 font
.SetFaceName( faceName
);
591 int st
= childValue
.GetLong();
592 if ( st
!= wxFONTSTYLE_NORMAL
&&
593 st
!= wxFONTSTYLE_SLANT
&&
594 st
!= wxFONTSTYLE_ITALIC
)
595 st
= wxFONTWEIGHT_NORMAL
;
600 int wt
= childValue
.GetLong();
601 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
602 wt
!= wxFONTWEIGHT_LIGHT
&&
603 wt
!= wxFONTWEIGHT_BOLD
)
604 wt
= wxFONTWEIGHT_NORMAL
;
605 font
.SetWeight( wt
);
609 font
.SetUnderlined( childValue
.GetBool() );
616 wxSize wxFontProperty::OnMeasureImage() const
618 return wxSize(-1,-1);
621 void wxFontProperty::OnCustomPaint(wxDC& dc,
623 wxPGPaintData& paintData)
626 if ( paintData.m_choiceItem >= 0 )
627 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
629 drawFace = m_value_wxFont.GetFaceName();
631 if ( drawFace.length() )
633 // Draw the background
634 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
635 //dc.SetBrush( *wxWHITE_BRUSH );
636 //dc.SetPen( *wxMEDIUM_GREY_PEN );
637 dc.DrawRectangle( rect );
639 wxFont oldFont = dc.GetFont();
640 wxFont drawFont(oldFont.GetPointSize(),
641 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
642 dc.SetFont(drawFont);
644 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
645 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
651 // No file - just draw a white box
652 dc.SetBrush ( *wxWHITE_BRUSH );
653 dc.DrawRectangle ( rect );
659 // -----------------------------------------------------------------------
660 // wxSystemColourProperty
661 // -----------------------------------------------------------------------
663 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
664 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
666 #include <wx/colordlg.h>
668 //#define wx_cp_es_syscolours_len 25
669 static const wxChar
* gs_cp_es_syscolour_labels
[] = {
672 wxT("ActiveCaption"),
674 wxT("ButtonHighlight"),
683 wxT("HighlightText"),
684 wxT("InactiveBorder"),
685 wxT("InactiveCaption"),
686 wxT("InactiveCaptionText"),
698 static long gs_cp_es_syscolour_values
[] = {
699 wxSYS_COLOUR_APPWORKSPACE
,
700 wxSYS_COLOUR_ACTIVEBORDER
,
701 wxSYS_COLOUR_ACTIVECAPTION
,
702 wxSYS_COLOUR_BTNFACE
,
703 wxSYS_COLOUR_BTNHIGHLIGHT
,
704 wxSYS_COLOUR_BTNSHADOW
,
705 wxSYS_COLOUR_BTNTEXT
,
706 wxSYS_COLOUR_CAPTIONTEXT
,
707 wxSYS_COLOUR_3DDKSHADOW
,
708 wxSYS_COLOUR_3DLIGHT
,
709 wxSYS_COLOUR_BACKGROUND
,
710 wxSYS_COLOUR_GRAYTEXT
,
711 wxSYS_COLOUR_HIGHLIGHT
,
712 wxSYS_COLOUR_HIGHLIGHTTEXT
,
713 wxSYS_COLOUR_INACTIVEBORDER
,
714 wxSYS_COLOUR_INACTIVECAPTION
,
715 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
717 wxSYS_COLOUR_SCROLLBAR
,
719 wxSYS_COLOUR_INFOTEXT
,
721 wxSYS_COLOUR_WINDOWFRAME
,
722 wxSYS_COLOUR_WINDOWTEXT
,
727 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
730 // Class body is in advprops.h
732 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
733 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
736 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
738 wxColourPropertyValue cpv
;
741 cpv
.Init( type
, colour
);
743 cpv
.Init( type
, *wxWHITE
);
745 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
753 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
756 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
757 const wxColourPropertyValue
& value
)
758 : wxEnumProperty( label
,
760 gs_cp_es_syscolour_labels
,
761 gs_cp_es_syscolour_values
,
762 &gs_wxSystemColourProperty_choicesCache
)
765 Init( value
.m_type
, value
.m_colour
);
767 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
771 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
772 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
773 const wxColourPropertyValue
& value
)
774 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
777 Init( value
.m_type
, value
.m_colour
);
779 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
783 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
784 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
785 const wxColour
& value
)
786 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
789 Init( wxPG_COLOUR_CUSTOM
, value
);
791 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
795 wxSystemColourProperty::~wxSystemColourProperty() { }
798 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
803 if ( pVariant
->IsNull() )
804 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
806 if ( pVariant
->GetType() == wxS("wxColourPropertyValue") )
808 wxColourPropertyValue v
;
814 bool variantProcessed
= true;
816 if ( pVariant
->GetType() == wxS("wxColour*") )
818 wxColour
* pCol
= wxStaticCast(pVariant
->GetWxObjectPtr(), wxColour
);
821 else if ( pVariant
->GetType() == wxS("wxColour") )
825 else if ( pVariant
->GetType() == wxArrayInt_VariantType
)
827 // This code is mostly needed for wxPython bindings, which
828 // may offer tuple of integers as colour value.
832 if ( arr
.size() >= 3 )
840 if ( arr
.size() >= 4 )
843 col
= wxColour(r
, g
, b
, a
);
847 variantProcessed
= false;
852 variantProcessed
= false;
855 if ( !variantProcessed
)
856 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
858 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
860 int colInd
= ColToInd(col
);
861 if ( colInd
!= wxNOT_FOUND
)
867 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
874 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
877 size_t i_max
= m_choices
.GetCount() - 1;
879 for ( i
=0; i
<i_max
; i
++ )
881 int ind
= m_choices
[i
].GetValue();
883 if ( colour
== GetColour(ind
) )
885 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
886 GetClassName(),GetLabel().c_str(),
887 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
888 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
896 static inline wxColour
wxColourFromPGLong( long col
)
898 return wxColour((col
&0xFF),((col
>>8)&0xFF),((col
>>16)&0xFF));
902 void wxSystemColourProperty::OnSetValue()
904 // Convert from generic wxobject ptr to wxPGVariantDataColour
905 if ( m_value
.GetType() == wxS("wxColour*") )
907 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
911 wxColourPropertyValue val
= GetVal(&m_value
);
913 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
921 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
922 val
.m_colour
= GetColour( val
.m_type
);
924 m_value
= TranslateVal(val
);
929 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
931 wxColourPropertyValue cpv
;
933 wxColour col
= cpv
.m_colour
;
937 SetValueToUnspecified();
938 SetIndex(wxNOT_FOUND
);
942 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
)
944 if ( m_choices
.HasValues() )
945 ind
= GetIndexForValue(cpv
.m_type
);
951 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
952 ind
= GetCustomColourIndex();
962 SetValueToUnspecified();
963 SetIndex(wxNOT_FOUND
);
969 if ( ind
== wxNOT_FOUND
)
970 ind
= GetCustomColourIndex();
977 wxColour
wxSystemColourProperty::GetColour( int index
) const
979 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
982 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
984 if ( index
== wxNOT_FOUND
)
985 return wxString::Format(wxT("(%i,%i,%i)"),
990 return m_choices
.GetLabel(index
);
993 wxString
wxSystemColourProperty::GetValueAsString( int argFlags
) const
995 wxColourPropertyValue val
= GetVal();
997 int ind
= GetIndex();
999 // Always show custom colour for textctrl-editor
1000 if ( val
.m_type
== wxPG_COLOUR_CUSTOM
||
1001 ind
== GetCustomColourIndex() ||
1002 (argFlags
& wxPG_PROPERTY_SPECIFIC
) )
1004 return ColourToString(val
.m_colour
, wxNOT_FOUND
);
1008 return wxEmptyString
;
1010 return ColourToString(val
.m_colour
, ind
);
1014 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
1016 return wxPG_DEFAULT_IMAGE_SIZE
;
1020 int wxSystemColourProperty::GetCustomColourIndex() const
1022 return m_choices
.GetCount() - 1;
1026 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1028 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1031 wxPropertyGrid
* propgrid
= GetGrid();
1032 wxASSERT( propgrid
);
1034 // Must only occur when user triggers event
1035 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_ONCUSTOMEDITOREVENT
) )
1038 wxColourPropertyValue val
= GetVal();
1040 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1043 data
.SetChooseFull(true);
1044 data
.SetColour(val
.m_colour
);
1046 for ( i
= 0; i
< 16; i
++)
1048 wxColour
colour(i
*16, i
*16, i
*16);
1049 data
.SetCustomColour(i
, colour
);
1052 wxColourDialog
dialog(propgrid
, &data
);
1053 if ( dialog
.ShowModal() == wxID_OK
)
1055 wxColourData retData
= dialog
.GetColourData();
1056 val
.m_colour
= retData
.GetColour();
1058 variant
= DoTranslateVal(val
);
1060 SetValueInEvent(variant
);
1069 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1072 int type
= GetValueForIndex(index
);
1073 bool hasValue
= m_choices
[index
].HasValue();
1075 if ( ( hasValue
&& type
== wxPG_COLOUR_CUSTOM
) ||
1076 ( !hasValue
&& (index
== (int)GetCustomColourIndex() &&
1077 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
))
1081 QueryColourFromUser(variant
);
1085 variant
= TranslateVal( type
, GetColour(type
) );
1091 // Need to do some extra event handling.
1092 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
), wxEvent
& event
)
1094 if ( propgrid
->IsMainButtonEvent(event
) )
1096 // We need to handle button click in case editor has been
1097 // switched to one that has wxButton as well.
1099 if ( QueryColourFromUser(variant
) )
1105 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1108 virtual void Render( wxDC& dc, const wxRect& rect,
1109 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1110 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1112 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1113 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1115 dc.SetPen(*wxBLACK_PEN);
1117 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1121 const wxArrayInt& values = prop->GetValues();
1122 if ( values.GetChildCount() )
1123 colInd = values[item];
1126 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1128 else if ( !prop->IsValueUnspecified() )
1129 dc.SetBrush( prop->GetVal().m_colour );
1131 dc.SetBrush( *wxWHITE );
1133 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1134 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1135 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1136 imageRect.width, imageRect.height );
1140 text = property->GetValueAsString();
1142 text = property->GetChoiceString(item);
1143 DrawText( dc, rect, imageRect.width, text );
1148 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1150 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1153 return &g_wxPGColourPropertyRenderer;
1154 return wxEnumProperty::GetCellRenderer(column);
1157 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1158 wxPGPaintData
& paintdata
)
1162 if ( paintdata
.m_choiceItem
>= 0 && paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1163 paintdata
.m_choiceItem
!= GetCustomColourIndex() )
1165 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1166 col
= GetColour( colInd
);
1168 else if ( !IsValueUnspecified() )
1170 col
= GetVal().m_colour
;
1176 dc
.DrawRectangle(rect
);
1181 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1184 // Accept colour format "[Name] [(R,G,B)]"
1185 // Name takes precedence.
1187 wxString colourName
;
1190 int ppos
= text
.Find(wxT("("));
1192 if ( ppos
== wxNOT_FOUND
)
1198 colourName
= text
.substr(0, ppos
);
1199 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1202 // Strip spaces from extremities
1203 colourName
.Trim(true);
1204 colourName
.Trim(false);
1205 colourRGB
.Trim(true);
1207 // Validate colourRGB string - (1,1,1) is shortest allowed
1208 if ( colourRGB
.length() < 7 )
1211 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1212 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1214 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1216 // This really should not occurr...
1222 QueryColourFromUser(value
);
1226 wxColourPropertyValue val
;
1230 if ( colourName
.length() )
1232 // Try predefined colour first
1233 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1234 if ( res
&& GetIndex() >= 0 )
1236 val
.m_type
= GetIndex();
1237 if ( val
.m_type
>= 0 && val
.m_type
< m_choices
.GetCount() && m_choices
[val
.m_type
].HasValue() )
1238 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1240 // Get proper colour for type.
1241 val
.m_colour
= GetColour(val
.m_type
);
1246 if ( colourRGB
.length() && !done
)
1248 // Then check custom colour.
1249 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1251 int r
= -1, g
= -1, b
= -1;
1252 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1254 if ( r
>= 0 && r
<= 255 &&
1255 g
>= 0 && g
<= 255 &&
1256 b
>= 0 && b
<= 255 )
1258 val
.m_colour
.Set(r
,g
,b
);
1270 value
= DoTranslateVal(val
);
1277 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1279 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1281 int ival
= wxPGVariantToInt(value
);
1283 SetChoicesExclusive(); // Make sure we don't corrupt colour lists of other properties
1285 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1287 // Show custom choice
1288 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1289 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1291 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1293 // Hide custom choice
1294 m_choices
.RemoveAt(GetCustomColourIndex());
1295 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1303 // -----------------------------------------------------------------------
1305 // -----------------------------------------------------------------------
1307 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1327 (const wxChar
*) NULL
1330 static unsigned long gs_cp_es_normcolour_colours
[] = {
1332 wxPG_COLOUR(128,0,0),
1333 wxPG_COLOUR(0,0,128),
1334 wxPG_COLOUR(128,0,128),
1335 wxPG_COLOUR(0,128,128),
1336 wxPG_COLOUR(128,128,128),
1337 wxPG_COLOUR(0,128,0),
1338 wxPG_COLOUR(128,128,0),
1339 wxPG_COLOUR(166,124,81),
1340 wxPG_COLOUR(0,0,255),
1341 wxPG_COLOUR(255,0,255),
1342 wxPG_COLOUR(255,0,0),
1343 wxPG_COLOUR(247,148,28),
1344 wxPG_COLOUR(192,192,192),
1345 wxPG_COLOUR(0,255,0),
1346 wxPG_COLOUR(0,255,255),
1347 wxPG_COLOUR(255,255,0),
1348 wxPG_COLOUR(255,255,255),
1352 WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(wxColourProperty
,
1353 gs_cp_es_normcolour_labels
,
1355 gs_cp_es_normcolour_colours
,
1358 // -----------------------------------------------------------------------
1360 // -----------------------------------------------------------------------
1362 #define wxPG_CURSOR_IMAGE_WIDTH 32
1364 #define NUM_CURSORS 28
1366 //#define wx_cp_es_syscursors_len 28
1367 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1379 wxT("Middle Button"),
1385 wxT("Question Arrow"),
1386 wxT("Right Button"),
1387 wxT("Sizing NE-SW"),
1389 wxT("Sizing NW-SE"),
1396 (const wxChar
*) NULL
1399 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1402 wxCURSOR_RIGHT_ARROW
,
1409 wxCURSOR_LEFT_BUTTON
,
1411 wxCURSOR_MIDDLE_BUTTON
,
1413 wxCURSOR_PAINT_BRUSH
,
1415 wxCURSOR_POINT_LEFT
,
1416 wxCURSOR_POINT_RIGHT
,
1417 wxCURSOR_QUESTION_ARROW
,
1418 wxCURSOR_RIGHT_BUTTON
,
1430 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1432 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1434 : wxEnumProperty( label
,
1436 gs_cp_es_syscursors_labels
,
1437 gs_cp_es_syscursors_values
,
1440 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1443 wxCursorProperty::~wxCursorProperty()
1447 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1449 #if wxPG_CAN_DRAW_CURSOR
1450 if ( item
!= -1 && item
< NUM_CURSORS
)
1451 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1458 #if wxPG_CAN_DRAW_CURSOR
1460 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1462 wxPGPaintData
& paintdata
)
1465 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1467 if ( paintdata
.m_choiceItem
>= 0 )
1469 dc
.DrawRectangle( rect
);
1471 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1473 wxStockCursor cursorIndex
=
1474 (wxStockCursor
) gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1477 if ( cursorIndex
== wxCURSOR_NONE
)
1478 cursorIndex
= wxCURSOR_ARROW
;
1480 wxCursor
cursor( cursorIndex
);
1483 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1487 (HICON
)cursor
.GetHandle(),
1492 DI_COMPAT
| DI_DEFAULTSIZE
| DI_NORMAL
1501 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1502 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1504 return wxEnumProperty::GetCellRenderer(column);
1508 // -----------------------------------------------------------------------
1509 // wxImageFileProperty
1510 // -----------------------------------------------------------------------
1514 const wxString
& wxPGGetDefaultImageWildcard()
1516 // Form the wildcard, if not done yet
1517 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1522 // TODO: This section may require locking (using global).
1524 wxList
& handlers
= wxImage::GetHandlers();
1526 wxList::iterator node
;
1528 // Let's iterate over the image handler list.
1529 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1530 for ( node
= handlers
.begin(); node
!= handlers
.end(); node
++ )
1532 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1534 wxString ext_lo
= handler
->GetExtension();
1535 wxString ext_up
= ext_lo
.Upper();
1537 str
.append( ext_up
);
1538 str
.append( wxT(" files (*.") );
1539 str
.append( ext_up
);
1540 str
.append( wxT(")|*.") );
1541 str
.append( ext_lo
);
1542 str
.append( wxT("|") );
1545 str
.append ( wxT("All files (*.*)|*.*") );
1547 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1550 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1553 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1555 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1556 const wxString
& value
)
1557 : wxFileProperty(label
,name
,value
)
1559 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1561 m_pImage
= (wxImage
*) NULL
;
1562 m_pBitmap
= (wxBitmap
*) NULL
;
1565 wxImageFileProperty::~wxImageFileProperty()
1573 void wxImageFileProperty::OnSetValue()
1575 wxFileProperty::OnSetValue();
1589 // Create the image thumbnail
1590 if ( m_filename
.FileExists() )
1592 m_pImage
= new wxImage( m_filename
.GetFullPath() );
1596 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1598 return wxPG_DEFAULT_IMAGE_SIZE
;
1601 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1605 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1607 // Draw the thumbnail
1609 // Create the bitmap here because required size is not known in OnSetValue().
1612 m_pImage
->Rescale( rect
.width
, rect
.height
);
1613 m_pBitmap
= new wxBitmap( *m_pImage
);
1618 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1622 // No file - just draw a white box
1623 dc
.SetBrush( *wxWHITE_BRUSH
);
1624 dc
.DrawRectangle ( rect
);
1628 #endif // wxUSE_IMAGE
1630 // -----------------------------------------------------------------------
1631 // wxMultiChoiceProperty
1632 // -----------------------------------------------------------------------
1636 #include <wx/choicdlg.h>
1638 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1639 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1641 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1642 const wxString
& name
,
1643 const wxPGChoices
& choices
,
1644 const wxArrayString
& value
)
1645 : wxPGProperty(label
,name
)
1647 m_choices
.Assign(choices
);
1651 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1652 const wxString
& name
,
1653 const wxArrayString
& strings
,
1654 const wxArrayString
& value
)
1655 : wxPGProperty(label
,name
)
1657 m_choices
.Set(strings
);
1661 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1662 const wxString
& name
,
1663 const wxArrayString
& value
)
1664 : wxPGProperty(label
,name
)
1666 wxArrayString strings
;
1667 m_choices
.Set(strings
);
1671 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1675 void wxMultiChoiceProperty::OnSetValue()
1677 GenerateValueAsString();
1680 wxString
wxMultiChoiceProperty::GetValueAsString( int ) const
1685 void wxMultiChoiceProperty::GenerateValueAsString()
1687 wxArrayString strings
;
1689 if ( m_value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1690 strings
= m_value
.GetArrayString();
1692 wxString
& tempStr
= m_display
;
1694 unsigned int itemCount
= strings
.size();
1699 tempStr
.append( wxT("\"") );
1701 for ( i
= 0; i
< itemCount
; i
++ )
1703 tempStr
.append( strings
[i
] );
1704 tempStr
.append( wxT("\"") );
1705 if ( i
< (itemCount
-1) )
1706 tempStr
.append ( wxT(" \"") );
1710 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1712 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(GetValue());
1715 // Translate values to string indices.
1716 wxArrayInt selections
;
1718 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1720 for ( i
=0; i
<valueArr
.size(); i
++ )
1725 for ( i
=0; i
<valueArr
.size(); i
++ )
1727 int sIndex
= m_choices
.Index(valueArr
[i
]);
1729 selections
.Add(sIndex
);
1736 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1737 wxWindow
* WXUNUSED(primary
),
1740 if ( propgrid
->IsMainButtonEvent(event
) )
1743 PrepareValueForDialogEditing(propgrid
);
1745 wxArrayString labels
= m_choices
.GetLabels();
1746 unsigned int choiceCount
;
1748 if ( m_choices
.IsOk() )
1749 choiceCount
= m_choices
.GetCount();
1753 // launch editor dialog
1754 wxMultiChoiceDialog
dlg( propgrid
,
1755 _("Make a selection:"),
1758 choiceCount
?&labels
[0]:NULL
,
1759 wxCHOICEDLG_STYLE
);
1761 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
1763 wxArrayString strings
= m_value
.GetArrayString();
1764 wxArrayString extraStrings
;
1766 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
1768 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
1770 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1772 wxArrayInt arrInt
= dlg
.GetSelections();
1776 // Strings that were not in list of choices
1777 wxArrayString value
;
1779 // Translate string indices to strings
1782 if ( userStringMode
== 1 )
1784 for (n
=0;n
<extraStrings
.size();n
++)
1785 value
.push_back(extraStrings
[n
]);
1789 for ( i
=0; i
<arrInt
.size(); i
++ )
1790 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
1792 if ( userStringMode
== 2 )
1794 for (n
=0;n
<extraStrings
.size();n
++)
1795 value
.push_back(extraStrings
[n
]);
1798 variant
= WXVARIANT(value
);
1800 SetValueInEvent(variant
);
1808 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1812 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1814 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
1815 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
1817 WX_PG_TOKENIZER2_END()
1819 wxVariant
v( WXVARIANT(arr
) );
1825 #endif // wxUSE_CHOICEDLG
1828 // -----------------------------------------------------------------------
1830 // -----------------------------------------------------------------------
1835 #if wxUSE_DATEPICKCTRL
1836 #define dtCtrl DatePickerCtrl
1838 #define dtCtrl TextCtrl
1841 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
1848 wxString
wxDateProperty::ms_defaultDateFormat
;
1851 wxDateProperty::wxDateProperty( const wxString
& label
,
1852 const wxString
& name
,
1853 const wxDateTime
& value
)
1854 : wxPGProperty(label
,name
)
1856 //wxPGRegisterDefaultValueType(wxDateTime)
1858 #if wxUSE_DATEPICKCTRL
1859 wxPGRegisterEditorClass(DatePickerCtrl
);
1861 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
1869 wxDateProperty::~wxDateProperty()
1873 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
1874 int WXUNUSED(argFlags
) ) const
1878 const char* c
= dt
.ParseFormat(text
, wxString(wxDefaultDateTimeFormat
), wxDefaultDateTime
, NULL
);
1889 wxString
wxDateProperty::GetValueAsString( int argFlags
) const
1891 const wxChar
* format
= (const wxChar
*) NULL
;
1893 wxDateTime dateTime
= m_value
.GetDateTime();
1895 if ( !dateTime
.IsValid() )
1896 return wxT("Invalid");
1898 if ( !ms_defaultDateFormat
.length() )
1900 #if wxUSE_DATEPICKCTRL
1901 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
1903 bool showCentury
= true;
1905 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
1908 if ( m_format
.length() &&
1909 !(argFlags
& wxPG_FULL_VALUE
) )
1910 format
= m_format
.c_str();
1912 // Determine default from locale
1913 // NB: This is really simple stuff, but can't figure anything
1914 // better without proper support in wxLocale
1916 format
= ms_defaultDateFormat
.c_str();
1918 return dateTime
.Format(format
);
1921 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
1923 // This code is basicly copied from datectlg.cpp's SetFormat
1928 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
1929 wxString
str(dt
.Format(wxT("%x")));
1931 const wxChar
*p
= str
.c_str();
1935 if (n
== dt
.GetDay())
1937 format
.Append(wxT("%d"));
1940 else if (n
== (int)dt
.GetMonth()+1)
1942 format
.Append(wxT("%m"));
1945 else if (n
== dt
.GetYear())
1947 format
.Append(wxT("%Y"));
1950 else if (n
== (dt
.GetYear() % 100))
1953 format
.Append(wxT("%Y"));
1955 format
.Append(wxT("%y"));
1959 format
.Append(*p
++);
1965 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1967 if ( name
== wxPG_DATE_FORMAT
)
1969 m_format
= value
.GetString();
1972 else if ( name
== wxPG_DATE_PICKER_STYLE
)
1974 m_dpStyle
= value
.GetLong();
1975 ms_defaultDateFormat
.clear(); // This may need recalculation
1981 #endif // wxUSE_DATETIME
1984 // -----------------------------------------------------------------------
1985 // wxPropertyGridInterface
1986 // -----------------------------------------------------------------------
1988 void wxPropertyGridInterface::InitAllTypeHandlers()
1992 // -----------------------------------------------------------------------
1994 void wxPropertyGridInterface::RegisterAdditionalEditors()
1997 wxPGRegisterEditorClass(SpinCtrl
);
1999 #if wxUSE_DATEPICKCTRL
2000 wxPGRegisterEditorClass(DatePickerCtrl
);
2004 // -----------------------------------------------------------------------
2006 #endif // wxPG_INCLUDE_ADVPROPS
2008 #endif // wxUSE_PROPGRID