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 int cursorindex
= gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1476 if ( cursorindex
== wxCURSOR_NONE
)
1477 cursorindex
= wxCURSOR_ARROW
;
1479 wxCursor
cursor( cursorindex
);
1482 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1486 (HICON
)cursor
.GetHandle(),
1491 DI_COMPAT
| DI_DEFAULTSIZE
| DI_NORMAL
1500 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1501 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1503 return wxEnumProperty::GetCellRenderer(column);
1507 // -----------------------------------------------------------------------
1508 // wxImageFileProperty
1509 // -----------------------------------------------------------------------
1513 const wxString
& wxPGGetDefaultImageWildcard()
1515 // Form the wildcard, if not done yet
1516 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1521 // TODO: This section may require locking (using global).
1523 wxList
& handlers
= wxImage::GetHandlers();
1525 wxList::iterator node
;
1527 // Let's iterate over the image handler list.
1528 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1529 for ( node
= handlers
.begin(); node
!= handlers
.end(); node
++ )
1531 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1533 wxString ext_lo
= handler
->GetExtension();
1534 wxString ext_up
= ext_lo
.Upper();
1536 str
.append( ext_up
);
1537 str
.append( wxT(" files (*.") );
1538 str
.append( ext_up
);
1539 str
.append( wxT(")|*.") );
1540 str
.append( ext_lo
);
1541 str
.append( wxT("|") );
1544 str
.append ( wxT("All files (*.*)|*.*") );
1546 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1549 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1552 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1554 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1555 const wxString
& value
)
1556 : wxFileProperty(label
,name
,value
)
1558 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1560 m_pImage
= (wxImage
*) NULL
;
1561 m_pBitmap
= (wxBitmap
*) NULL
;
1564 wxImageFileProperty::~wxImageFileProperty()
1572 void wxImageFileProperty::OnSetValue()
1574 wxFileProperty::OnSetValue();
1588 // Create the image thumbnail
1589 if ( m_filename
.FileExists() )
1591 m_pImage
= new wxImage( m_filename
.GetFullPath() );
1595 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1597 return wxPG_DEFAULT_IMAGE_SIZE
;
1600 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1604 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1606 // Draw the thumbnail
1608 // Create the bitmap here because required size is not known in OnSetValue().
1611 m_pImage
->Rescale( rect
.width
, rect
.height
);
1612 m_pBitmap
= new wxBitmap( *m_pImage
);
1617 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1621 // No file - just draw a white box
1622 dc
.SetBrush( *wxWHITE_BRUSH
);
1623 dc
.DrawRectangle ( rect
);
1627 #endif // wxUSE_IMAGE
1629 // -----------------------------------------------------------------------
1630 // wxMultiChoiceProperty
1631 // -----------------------------------------------------------------------
1635 #include <wx/choicdlg.h>
1637 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1638 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1640 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1641 const wxString
& name
,
1642 const wxPGChoices
& choices
,
1643 const wxArrayString
& value
)
1644 : wxPGProperty(label
,name
)
1646 m_choices
.Assign(choices
);
1650 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1651 const wxString
& name
,
1652 const wxArrayString
& strings
,
1653 const wxArrayString
& value
)
1654 : wxPGProperty(label
,name
)
1656 m_choices
.Set(strings
);
1660 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1661 const wxString
& name
,
1662 const wxArrayString
& value
)
1663 : wxPGProperty(label
,name
)
1665 wxArrayString strings
;
1666 m_choices
.Set(strings
);
1670 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1674 void wxMultiChoiceProperty::OnSetValue()
1676 GenerateValueAsString();
1679 wxString
wxMultiChoiceProperty::GetValueAsString( int ) const
1684 void wxMultiChoiceProperty::GenerateValueAsString()
1686 wxArrayString strings
;
1688 if ( m_value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1689 strings
= m_value
.GetArrayString();
1691 wxString
& tempStr
= m_display
;
1693 unsigned int itemCount
= strings
.size();
1698 tempStr
.append( wxT("\"") );
1700 for ( i
= 0; i
< itemCount
; i
++ )
1702 tempStr
.append( strings
[i
] );
1703 tempStr
.append( wxT("\"") );
1704 if ( i
< (itemCount
-1) )
1705 tempStr
.append ( wxT(" \"") );
1709 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1711 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(GetValue());
1714 // Translate values to string indices.
1715 wxArrayInt selections
;
1717 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1719 for ( i
=0; i
<valueArr
.size(); i
++ )
1724 for ( i
=0; i
<valueArr
.size(); i
++ )
1726 int sIndex
= m_choices
.Index(valueArr
[i
]);
1728 selections
.Add(sIndex
);
1735 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1736 wxWindow
* WXUNUSED(primary
),
1739 if ( propgrid
->IsMainButtonEvent(event
) )
1742 PrepareValueForDialogEditing(propgrid
);
1744 wxArrayString labels
= m_choices
.GetLabels();
1745 unsigned int choiceCount
;
1747 if ( m_choices
.IsOk() )
1748 choiceCount
= m_choices
.GetCount();
1752 // launch editor dialog
1753 wxMultiChoiceDialog
dlg( propgrid
,
1754 _("Make a selection:"),
1757 choiceCount
?&labels
[0]:NULL
,
1758 wxCHOICEDLG_STYLE
);
1760 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
1762 wxArrayString strings
= m_value
.GetArrayString();
1763 wxArrayString extraStrings
;
1765 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
1767 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
1769 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1771 wxArrayInt arrInt
= dlg
.GetSelections();
1775 // Strings that were not in list of choices
1776 wxArrayString value
;
1778 // Translate string indices to strings
1781 if ( userStringMode
== 1 )
1783 for (n
=0;n
<extraStrings
.size();n
++)
1784 value
.push_back(extraStrings
[n
]);
1788 for ( i
=0; i
<arrInt
.size(); i
++ )
1789 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
1791 if ( userStringMode
== 2 )
1793 for (n
=0;n
<extraStrings
.size();n
++)
1794 value
.push_back(extraStrings
[n
]);
1797 variant
= WXVARIANT(value
);
1799 SetValueInEvent(variant
);
1807 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1811 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1813 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
1814 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
1816 WX_PG_TOKENIZER2_END()
1818 wxVariant
v( WXVARIANT(arr
) );
1824 #endif // wxUSE_CHOICEDLG
1827 // -----------------------------------------------------------------------
1829 // -----------------------------------------------------------------------
1834 #if wxUSE_DATEPICKCTRL
1835 #define dtCtrl DatePickerCtrl
1837 #define dtCtrl TextCtrl
1840 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
1847 wxString
wxDateProperty::ms_defaultDateFormat
;
1850 wxDateProperty::wxDateProperty( const wxString
& label
,
1851 const wxString
& name
,
1852 const wxDateTime
& value
)
1853 : wxPGProperty(label
,name
)
1855 //wxPGRegisterDefaultValueType(wxDateTime)
1857 #if wxUSE_DATEPICKCTRL
1858 wxPGRegisterEditorClass(DatePickerCtrl
);
1860 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
1868 wxDateProperty::~wxDateProperty()
1872 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
1873 int WXUNUSED(argFlags
) ) const
1877 const char* c
= dt
.ParseFormat(text
, wxString(wxDefaultDateTimeFormat
), wxDefaultDateTime
, NULL
);
1888 wxString
wxDateProperty::GetValueAsString( int argFlags
) const
1890 const wxChar
* format
= (const wxChar
*) NULL
;
1892 wxDateTime dateTime
= m_value
.GetDateTime();
1894 if ( !dateTime
.IsValid() )
1895 return wxT("Invalid");
1897 if ( !ms_defaultDateFormat
.length() )
1899 #if wxUSE_DATEPICKCTRL
1900 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
1902 bool showCentury
= true;
1904 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
1907 if ( m_format
.length() &&
1908 !(argFlags
& wxPG_FULL_VALUE
) )
1909 format
= m_format
.c_str();
1911 // Determine default from locale
1912 // NB: This is really simple stuff, but can't figure anything
1913 // better without proper support in wxLocale
1915 format
= ms_defaultDateFormat
.c_str();
1917 return dateTime
.Format(format
);
1920 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
1922 // This code is basicly copied from datectlg.cpp's SetFormat
1927 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
1928 wxString
str(dt
.Format(wxT("%x")));
1930 const wxChar
*p
= str
.c_str();
1934 if (n
== dt
.GetDay())
1936 format
.Append(wxT("%d"));
1939 else if (n
== (int)dt
.GetMonth()+1)
1941 format
.Append(wxT("%m"));
1944 else if (n
== dt
.GetYear())
1946 format
.Append(wxT("%Y"));
1949 else if (n
== (dt
.GetYear() % 100))
1952 format
.Append(wxT("%Y"));
1954 format
.Append(wxT("%y"));
1958 format
.Append(*p
++);
1964 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1966 if ( name
== wxPG_DATE_FORMAT
)
1968 m_format
= value
.GetString();
1971 else if ( name
== wxPG_DATE_PICKER_STYLE
)
1973 m_dpStyle
= value
.GetLong();
1974 ms_defaultDateFormat
.clear(); // This may need recalculation
1980 #endif // wxUSE_DATETIME
1983 // -----------------------------------------------------------------------
1984 // wxPropertyGridInterface
1985 // -----------------------------------------------------------------------
1987 void wxPropertyGridInterface::InitAllTypeHandlers()
1991 // -----------------------------------------------------------------------
1993 void wxPropertyGridInterface::RegisterAdditionalEditors()
1996 wxPGRegisterEditorClass(SpinCtrl
);
1998 #if wxUSE_DATEPICKCTRL
1999 wxPGRegisterEditorClass(DatePickerCtrl
);
2003 // -----------------------------------------------------------------------
2005 #endif // wxPG_INCLUDE_ADVPROPS
2007 #endif // wxUSE_PROPGRID