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"
45 #include "wx/layout.h"
47 #include "wx/textdlg.h"
48 #include "wx/filedlg.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>
67 // -----------------------------------------------------------------------
69 #if defined(__WXMSW__)
70 #define wxPG_CAN_DRAW_CURSOR 1
71 #elif defined(__WXGTK__)
72 #define wxPG_CAN_DRAW_CURSOR 0
73 #elif defined(__WXMAC__)
74 #define wxPG_CAN_DRAW_CURSOR 0
76 #define wxPG_CAN_DRAW_CURSOR 0
80 // -----------------------------------------------------------------------
82 // -----------------------------------------------------------------------
85 bool operator == (const wxFont
&, const wxFont
&)
90 // Implement dynamic class for type value.
91 IMPLEMENT_DYNAMIC_CLASS(wxColourPropertyValue
, wxObject
)
93 bool operator == (const wxColourPropertyValue
& a
, const wxColourPropertyValue
& b
)
95 return ( ( a
.m_colour
== b
.m_colour
) && (a
.m_type
== b
.m_type
) );
98 bool operator == (const wxArrayInt
& array1
, const wxArrayInt
& array2
)
100 if ( array1
.size() != array2
.size() )
103 for ( i
=0; i
<array1
.size(); i
++ )
105 if ( array1
[i
] != array2
[i
] )
111 // -----------------------------------------------------------------------
112 // wxSpinCtrl-based property editor
113 // -----------------------------------------------------------------------
118 // This macro also defines global wxPGEditor_SpinCtrl for storing
119 // the singleton class instance.
120 WX_PG_IMPLEMENT_EDITOR_CLASS(SpinCtrl
,wxPGSpinCtrlEditor
,wxPGEditor
)
123 // Trivial destructor.
124 wxPGSpinCtrlEditor::~wxPGSpinCtrlEditor()
129 // Create controls and initialize event handling.
130 wxPGWindowList
wxPGSpinCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
131 const wxPoint
& pos
, const wxSize
& sz
) const
133 const int margin
= 1;
134 wxSize
butSz(18, sz
.y
);
135 wxSize
tcSz(sz
.x
- butSz
.x
- margin
, sz
.y
);
136 wxPoint
butPos(pos
.x
+ tcSz
.x
+ margin
, pos
.y
);
138 wxSpinButton
* wnd2
= new wxSpinButton();
142 wnd2
->Create( propgrid
->GetPanel(), wxPG_SUBID2
, butPos
, butSz
, wxSP_VERTICAL
);
144 wnd2
->SetRange( INT_MIN
, INT_MAX
);
147 propgrid
->Connect( wxPG_SUBID2
, wxEVT_SCROLL_LINEUP
,
148 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
149 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propgrid
);
150 propgrid
->Connect( wxPG_SUBID2
, wxEVT_SCROLL_LINEDOWN
,
151 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
152 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propgrid
);
153 propgrid
->Connect( wxPG_SUBID1
, wxEVT_KEY_DOWN
,
154 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
155 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propgrid
);
157 // Let's add validator to make sure only numbers can be entered
158 wxTextValidator
validator(wxFILTER_NUMERIC
, &m_tempString
);
160 wxTextCtrl
* wnd1
= (wxTextCtrl
*) wxPGTextCtrlEditor::CreateControls( propgrid
, property
, pos
, tcSz
).m_primary
;
161 wnd1
->SetValidator(validator
);
163 return wxPGWindowList(wnd1
, wnd2
);
166 // Control's events are redirected here
167 bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
168 wxWindow
* wnd
, wxEvent
& event
) const
170 int evtType
= event
.GetEventType();
172 bool bigStep
= false;
174 if ( evtType
== wxEVT_KEY_DOWN
)
176 wxKeyEvent
& keyEvent
= (wxKeyEvent
&)event
;
177 keycode
= keyEvent
.GetKeyCode();
179 if ( keycode
== WXK_UP
)
180 evtType
= wxEVT_SCROLL_LINEUP
;
181 else if ( keycode
== WXK_DOWN
)
182 evtType
= wxEVT_SCROLL_LINEDOWN
;
183 else if ( keycode
== WXK_PAGEUP
)
185 evtType
= wxEVT_SCROLL_LINEUP
;
188 else if ( keycode
== WXK_PAGEDOWN
)
190 evtType
= wxEVT_SCROLL_LINEDOWN
;
195 if ( evtType
== wxEVT_SCROLL_LINEUP
|| evtType
== wxEVT_SCROLL_LINEDOWN
)
198 // Can't use wnd since it might be clipper window
199 wxTextCtrl
* tc
= wxDynamicCast(propgrid
->GetEditorControl(), wxTextCtrl
);
204 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
206 int mode
= wxPG_PROPERTY_VALIDATION_SATURATE
;
208 if ( property
->GetAttributeAsLong(wxT("Wrap"), 0) )
209 mode
= wxPG_PROPERTY_VALIDATION_WRAP
;
211 if ( property
->GetValueType() == wxT("double") )
214 double step
= property
->GetAttributeAsDouble(wxT("Step"), 1.0);
217 if ( s
.ToDouble(&v_d
) )
222 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_d
+= step
;
226 wxFloatProperty::DoValidation(property
, v_d
, NULL
, mode
);
228 wxPropertyGrid::DoubleToString(s
, v_d
, 6, true, NULL
);
238 wxLongLong_t step
= property
->GetAttributeAsLong(wxT("Step"), 1);
241 if ( s
.ToLongLong(&v_ll
, 10) )
246 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_ll
+= step
;
250 wxIntProperty::DoValidation(property
, v_ll
, NULL
, mode
);
252 s
= wxLongLong(v_ll
).ToString();
262 int ip
= tc
->GetInsertionPoint();
263 int lp
= tc
->GetLastPosition();
265 tc
->SetInsertionPoint(ip
+(tc
->GetLastPosition()-lp
));
271 return wxPGTextCtrlEditor::OnEvent(propgrid
,property
,wnd
,event
);
274 #endif // wxUSE_SPINBTN
277 // -----------------------------------------------------------------------
278 // wxDatePickerCtrl-based property editor
279 // -----------------------------------------------------------------------
281 #if wxUSE_DATEPICKCTRL
284 #include <wx/datectrl.h>
285 #include <wx/dateevt.h>
287 class wxPGDatePickerCtrlEditor
: public wxPGEditor
289 WX_PG_DECLARE_EDITOR_CLASS(wxPGDatePickerCtrlEditor
)
291 virtual ~wxPGDatePickerCtrlEditor();
293 wxPG_DECLARE_CREATECONTROLS
295 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const;
296 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
297 wxWindow
* wnd
, wxEvent
& event
) const;
298 virtual bool GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* wnd
) const;
299 virtual void SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const;
303 WX_PG_IMPLEMENT_EDITOR_CLASS(DatePickerCtrl
,wxPGDatePickerCtrlEditor
,wxPGEditor
)
306 wxPGDatePickerCtrlEditor::~wxPGDatePickerCtrlEditor()
310 wxPGWindowList
wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
,
311 wxPGProperty
* property
,
313 const wxSize
& sz
) const
315 wxCHECK_MSG( property
->IsKindOf(CLASSINFO(wxDateProperty
)),
317 wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
319 wxDateProperty
* prop
= (wxDateProperty
*) property
;
321 // Use two stage creation to allow cleaner display on wxMSW
322 wxDatePickerCtrl
* ctrl
= new wxDatePickerCtrl();
325 wxSize useSz
= wxDefaultSize
;
330 ctrl
->Create(propgrid
->GetPanel(),
332 prop
->GetDateValue(),
335 prop
->GetDatePickerStyle() | wxNO_BORDER
);
337 // Connect all required events to grid's OnCustomEditorEvent
338 // (all relevenat wxTextCtrl, wxComboBox and wxButton events are
339 // already connected)
340 propgrid
->Connect( wxPG_SUBID1
, wxEVT_DATE_CHANGED
,
341 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
342 &wxPropertyGrid::OnCustomEditorEvent
);
351 // Copies value from property to control
352 void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const
354 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
355 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
357 // We assume that property's data type is 'int' (or something similar),
358 // thus allowing us to get raw, unchecked value via DoGetValue.
359 ctrl
->SetValue( property
->GetValue().GetDateTime() );
362 // Control's events are redirected here
363 bool wxPGDatePickerCtrlEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propgrid
),
364 wxPGProperty
* WXUNUSED(property
),
365 wxWindow
* WXUNUSED(wnd
),
366 wxEvent
& event
) const
368 if ( event
.GetEventType() == wxEVT_DATE_CHANGED
)
374 bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const
376 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
377 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
379 variant
= ctrl
->GetValue();
384 void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* WXUNUSED(wnd
) ) const
387 //wxDateProperty* prop = (wxDateProperty*) property;
391 #endif // wxUSE_DATEPICKCTRL
394 // -----------------------------------------------------------------------
396 // -----------------------------------------------------------------------
398 #include <wx/fontdlg.h>
399 #include <wx/fontenum.h>
401 static const wxChar
* gs_fp_es_family_labels
[] = {
402 wxT("Default"), wxT("Decorative"),
403 wxT("Roman"), wxT("Script"),
404 wxT("Swiss"), wxT("Modern"),
408 static long gs_fp_es_family_values
[] = {
409 wxDEFAULT
, wxDECORATIVE
,
414 static const wxChar
* gs_fp_es_style_labels
[] = {
421 static long gs_fp_es_style_values
[] = {
427 static const wxChar
* gs_fp_es_weight_labels
[] = {
434 static long gs_fp_es_weight_values
[] = {
440 // Class body is in advprops.h
443 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty
,wxPGProperty
,
444 wxFont
,const wxFont
&,TextCtrlAndButton
)
447 wxFontProperty::wxFontProperty( const wxString
& label
, const wxString
& name
,
448 const wxFont
& value
)
449 : wxPGProperty(label
,name
)
451 SetValue(WXVARIANT(value
));
453 // Initialize font family choices list
454 if ( !wxPGGlobalVars
->m_fontFamilyChoices
)
456 wxFontEnumerator enumerator
;
457 enumerator
.EnumerateFacenames();
459 #if wxMINOR_VERSION > 6
460 wxArrayString faceNames
= enumerator
.GetFacenames();
462 wxArrayString
& faceNames
= *enumerator
.GetFacenames();
467 wxPGGlobalVars
->m_fontFamilyChoices
= new wxPGChoices(faceNames
);
470 wxString
emptyString(wxEmptyString
);
475 AddChild( new wxIntProperty( _("Point Size"), wxS("Point Size"),(long)font
.GetPointSize() ) );
477 AddChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
478 gs_fp_es_family_labels
,gs_fp_es_family_values
,
481 wxString faceName
= font
.GetFaceName();
482 // If font was not in there, add it now
483 if ( faceName
.length() &&
484 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
485 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
487 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"), wxS("Face Name"),
488 *wxPGGlobalVars
->m_fontFamilyChoices
);
490 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
494 AddChild( new wxEnumProperty(_("Style"), wxS("Style"),
495 gs_fp_es_style_labels
,gs_fp_es_style_values
,font
.GetStyle()) );
497 AddChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
498 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,font
.GetWeight()) );
500 AddChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
501 font
.GetUnderlined()) );
504 wxFontProperty::~wxFontProperty() { }
506 void wxFontProperty::OnSetValue()
513 font
= wxFont(10,wxSWISS
,wxNORMAL
,wxNORMAL
);
518 wxString
wxFontProperty::GetValueAsString( int argFlags
) const
520 return wxPGProperty::GetValueAsString(argFlags
);
523 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
526 if ( propgrid
->IsMainButtonEvent(event
) )
528 // Update value from last minute changes
529 PrepareValueForDialogEditing(propgrid
);
534 data
.SetInitialFont( font
);
535 data
.SetColour(*wxBLACK
);
537 wxFontDialog
dlg(propgrid
, data
);
538 if ( dlg
.ShowModal() == wxID_OK
)
540 propgrid
->EditorsValueWasModified();
543 variant
<< dlg
.GetFontData().GetChosenFont();
544 SetValueInEvent( variant
);
551 void wxFontProperty::RefreshChildren()
553 if ( !GetChildCount() ) return;
556 Item(0)->SetValue( (long)font
.GetPointSize() );
557 Item(1)->SetValue( (long)font
.GetFamily() );
558 Item(2)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
559 Item(3)->SetValue( (long)font
.GetStyle() );
560 Item(4)->SetValue( (long)font
.GetWeight() );
561 Item(5)->SetValue( font
.GetUnderlined() );
564 void wxFontProperty::ChildChanged( wxVariant
& thisValue
, int ind
, wxVariant
& childValue
) const
571 font
.SetPointSize( wxPGVariantToInt(childValue
) );
575 int fam
= childValue
.GetLong();
576 if ( fam
< wxDEFAULT
||
579 font
.SetFamily( fam
);
584 int faceIndex
= childValue
.GetLong();
586 if ( faceIndex
>= 0 )
587 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
589 font
.SetFaceName( faceName
);
593 int st
= childValue
.GetLong();
594 if ( st
!= wxFONTSTYLE_NORMAL
&&
595 st
!= wxFONTSTYLE_SLANT
&&
596 st
!= wxFONTSTYLE_ITALIC
)
597 st
= wxFONTWEIGHT_NORMAL
;
602 int wt
= childValue
.GetLong();
603 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
604 wt
!= wxFONTWEIGHT_LIGHT
&&
605 wt
!= wxFONTWEIGHT_BOLD
)
606 wt
= wxFONTWEIGHT_NORMAL
;
607 font
.SetWeight( wt
);
611 font
.SetUnderlined( childValue
.GetBool() );
618 wxSize wxFontProperty::OnMeasureImage() const
620 return wxSize(-1,-1);
623 void wxFontProperty::OnCustomPaint(wxDC& dc,
625 wxPGPaintData& paintData)
628 if ( paintData.m_choiceItem >= 0 )
629 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
631 drawFace = m_value_wxFont.GetFaceName();
633 if ( drawFace.length() )
635 // Draw the background
636 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
637 //dc.SetBrush( *wxWHITE_BRUSH );
638 //dc.SetPen( *wxMEDIUM_GREY_PEN );
639 dc.DrawRectangle( rect );
641 wxFont oldFont = dc.GetFont();
642 wxFont drawFont(oldFont.GetPointSize(),
643 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
644 dc.SetFont(drawFont);
646 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
647 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
653 // No file - just draw a white box
654 dc.SetBrush ( *wxWHITE_BRUSH );
655 dc.DrawRectangle ( rect );
661 // -----------------------------------------------------------------------
662 // wxSystemColourProperty
663 // -----------------------------------------------------------------------
665 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
666 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
668 #include <wx/colordlg.h>
670 //#define wx_cp_es_syscolours_len 25
671 static const wxChar
* gs_cp_es_syscolour_labels
[] = {
674 wxT("ActiveCaption"),
676 wxT("ButtonHighlight"),
685 wxT("HighlightText"),
686 wxT("InactiveBorder"),
687 wxT("InactiveCaption"),
688 wxT("InactiveCaptionText"),
700 static long gs_cp_es_syscolour_values
[] = {
701 wxSYS_COLOUR_APPWORKSPACE
,
702 wxSYS_COLOUR_ACTIVEBORDER
,
703 wxSYS_COLOUR_ACTIVECAPTION
,
704 wxSYS_COLOUR_BTNFACE
,
705 wxSYS_COLOUR_BTNHIGHLIGHT
,
706 wxSYS_COLOUR_BTNSHADOW
,
707 wxSYS_COLOUR_BTNTEXT
,
708 wxSYS_COLOUR_CAPTIONTEXT
,
709 wxSYS_COLOUR_3DDKSHADOW
,
710 wxSYS_COLOUR_3DLIGHT
,
711 wxSYS_COLOUR_BACKGROUND
,
712 wxSYS_COLOUR_GRAYTEXT
,
713 wxSYS_COLOUR_HIGHLIGHT
,
714 wxSYS_COLOUR_HIGHLIGHTTEXT
,
715 wxSYS_COLOUR_INACTIVEBORDER
,
716 wxSYS_COLOUR_INACTIVECAPTION
,
717 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
719 wxSYS_COLOUR_SCROLLBAR
,
721 wxSYS_COLOUR_INFOTEXT
,
723 wxSYS_COLOUR_WINDOWFRAME
,
724 wxSYS_COLOUR_WINDOWTEXT
,
729 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
732 // Class body is in advprops.h
734 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
735 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
738 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
740 wxColourPropertyValue cpv
;
743 cpv
.Init( type
, colour
);
745 cpv
.Init( type
, *wxWHITE
);
747 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
755 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
758 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
759 const wxColourPropertyValue
& value
)
760 : wxEnumProperty( label
,
762 gs_cp_es_syscolour_labels
,
763 gs_cp_es_syscolour_values
,
764 &gs_wxSystemColourProperty_choicesCache
)
767 Init( value
.m_type
, value
.m_colour
);
769 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
773 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
774 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
775 const wxColourPropertyValue
& value
)
776 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
779 Init( value
.m_type
, value
.m_colour
);
781 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
785 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
786 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
787 const wxColour
& value
)
788 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
791 Init( wxPG_COLOUR_CUSTOM
, value
);
793 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
797 wxSystemColourProperty::~wxSystemColourProperty() { }
800 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
805 if ( pVariant
->IsNull() )
806 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
808 if ( pVariant
->GetType() == wxS("wxColourPropertyValue") )
810 wxColourPropertyValue v
;
816 bool variantProcessed
= true;
818 if ( pVariant
->GetType() == wxS("wxColour*") )
820 wxColour
* pCol
= wxStaticCast(pVariant
->GetWxObjectPtr(), wxColour
);
823 else if ( pVariant
->GetType() == wxS("wxColour") )
827 else if ( pVariant
->GetType() == wxArrayInt_VariantType
)
829 // This code is mostly needed for wxPython bindings, which
830 // may offer tuple of integers as colour value.
834 if ( arr
.size() >= 3 )
842 if ( arr
.size() >= 4 )
845 col
= wxColour(r
, g
, b
, a
);
849 variantProcessed
= false;
854 variantProcessed
= false;
857 if ( !variantProcessed
)
858 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
860 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
862 int colInd
= ColToInd(col
);
863 if ( colInd
!= wxNOT_FOUND
)
869 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
876 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
879 size_t i_max
= m_choices
.GetCount() - 1;
881 for ( i
=0; i
<i_max
; i
++ )
883 int ind
= m_choices
[i
].GetValue();
885 if ( colour
== GetColour(ind
) )
887 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
888 GetClassName(),GetLabel().c_str(),
889 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
890 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
898 static inline wxColour
wxColourFromPGLong( long col
)
900 return wxColour((col
&0xFF),((col
>>8)&0xFF),((col
>>16)&0xFF));
904 void wxSystemColourProperty::OnSetValue()
906 // Convert from generic wxobject ptr to wxPGVariantDataColour
907 if ( m_value
.GetType() == wxS("wxColour*") )
909 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
913 wxColourPropertyValue val
= GetVal(&m_value
);
915 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
923 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
924 val
.m_colour
= GetColour( val
.m_type
);
926 m_value
= TranslateVal(val
);
931 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
933 wxColourPropertyValue cpv
;
935 wxColour col
= cpv
.m_colour
;
939 SetValueToUnspecified();
940 SetIndex(wxNOT_FOUND
);
944 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
)
946 if ( m_choices
.HasValues() )
947 ind
= GetIndexForValue(cpv
.m_type
);
953 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
954 ind
= GetCustomColourIndex();
964 SetValueToUnspecified();
965 SetIndex(wxNOT_FOUND
);
971 if ( ind
== wxNOT_FOUND
)
972 ind
= GetCustomColourIndex();
979 wxColour
wxSystemColourProperty::GetColour( int index
) const
981 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
984 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
986 if ( index
== wxNOT_FOUND
)
987 return wxString::Format(wxT("(%i,%i,%i)"),
992 return m_choices
.GetLabel(index
);
995 wxString
wxSystemColourProperty::GetValueAsString( int argFlags
) const
997 wxColourPropertyValue val
= GetVal();
999 int ind
= GetIndex();
1001 // Always show custom colour for textctrl-editor
1002 if ( val
.m_type
== wxPG_COLOUR_CUSTOM
||
1003 ind
== GetCustomColourIndex() ||
1004 (argFlags
& wxPG_PROPERTY_SPECIFIC
) )
1006 return ColourToString(val
.m_colour
, wxNOT_FOUND
);
1010 return wxEmptyString
;
1012 return ColourToString(val
.m_colour
, ind
);
1016 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
1018 return wxPG_DEFAULT_IMAGE_SIZE
;
1022 int wxSystemColourProperty::GetCustomColourIndex() const
1024 return m_choices
.GetCount() - 1;
1028 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1030 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1033 wxPropertyGrid
* propgrid
= GetGrid();
1034 wxASSERT( propgrid
);
1036 // Must only occur when user triggers event
1037 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_ONCUSTOMEDITOREVENT
) )
1040 wxColourPropertyValue val
= GetVal();
1042 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1045 data
.SetChooseFull(true);
1046 data
.SetColour(val
.m_colour
);
1048 for ( i
= 0; i
< 16; i
++)
1050 wxColour
colour(i
*16, i
*16, i
*16);
1051 data
.SetCustomColour(i
, colour
);
1054 wxColourDialog
dialog(propgrid
, &data
);
1055 if ( dialog
.ShowModal() == wxID_OK
)
1057 wxColourData retData
= dialog
.GetColourData();
1058 val
.m_colour
= retData
.GetColour();
1060 variant
= DoTranslateVal(val
);
1062 SetValueInEvent(variant
);
1071 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1074 int type
= GetValueForIndex(index
);
1075 bool hasValue
= m_choices
[index
].HasValue();
1077 if ( ( hasValue
&& type
== wxPG_COLOUR_CUSTOM
) ||
1078 ( !hasValue
&& (index
== (int)GetCustomColourIndex() &&
1079 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
))
1083 QueryColourFromUser(variant
);
1087 variant
= TranslateVal( type
, GetColour(type
) );
1093 // Need to do some extra event handling.
1094 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
), wxEvent
& event
)
1096 if ( propgrid
->IsMainButtonEvent(event
) )
1098 // We need to handle button click in case editor has been
1099 // switched to one that has wxButton as well.
1101 if ( QueryColourFromUser(variant
) )
1107 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1110 virtual void Render( wxDC& dc, const wxRect& rect,
1111 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1112 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1114 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1115 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1117 dc.SetPen(*wxBLACK_PEN);
1119 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1123 const wxArrayInt& values = prop->GetValues();
1124 if ( values.GetChildCount() )
1125 colInd = values[item];
1128 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1130 else if ( !prop->IsValueUnspecified() )
1131 dc.SetBrush( prop->GetVal().m_colour );
1133 dc.SetBrush( *wxWHITE );
1135 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1136 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1137 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1138 imageRect.width, imageRect.height );
1142 text = property->GetValueAsString();
1144 text = property->GetChoiceString(item);
1145 DrawText( dc, rect, imageRect.width, text );
1150 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1152 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1155 return &g_wxPGColourPropertyRenderer;
1156 return wxEnumProperty::GetCellRenderer(column);
1159 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1160 wxPGPaintData
& paintdata
)
1164 if ( paintdata
.m_choiceItem
>= 0 && paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1165 paintdata
.m_choiceItem
!= GetCustomColourIndex() )
1167 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1168 col
= GetColour( colInd
);
1170 else if ( !IsValueUnspecified() )
1172 col
= GetVal().m_colour
;
1178 dc
.DrawRectangle(rect
);
1183 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1186 // Accept colour format "[Name] [(R,G,B)]"
1187 // Name takes precedence.
1189 wxString colourName
;
1192 int ppos
= text
.Find(wxT("("));
1194 if ( ppos
== wxNOT_FOUND
)
1200 colourName
= text
.substr(0, ppos
);
1201 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1204 // Strip spaces from extremities
1205 colourName
.Trim(true);
1206 colourName
.Trim(false);
1207 colourRGB
.Trim(true);
1209 // Validate colourRGB string - (1,1,1) is shortest allowed
1210 if ( colourRGB
.length() < 7 )
1213 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1214 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1216 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1218 // This really should not occurr...
1224 QueryColourFromUser(value
);
1228 wxColourPropertyValue val
;
1232 if ( colourName
.length() )
1234 // Try predefined colour first
1235 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1236 if ( res
&& GetIndex() >= 0 )
1238 val
.m_type
= GetIndex();
1239 if ( val
.m_type
>= 0 && val
.m_type
< m_choices
.GetCount() && m_choices
[val
.m_type
].HasValue() )
1240 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1242 // Get proper colour for type.
1243 val
.m_colour
= GetColour(val
.m_type
);
1248 if ( colourRGB
.length() && !done
)
1250 // Then check custom colour.
1251 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1253 int r
= -1, g
= -1, b
= -1;
1254 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1256 if ( r
>= 0 && r
<= 255 &&
1257 g
>= 0 && g
<= 255 &&
1258 b
>= 0 && b
<= 255 )
1260 val
.m_colour
.Set(r
,g
,b
);
1272 value
= DoTranslateVal(val
);
1279 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1281 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1283 int ival
= wxPGVariantToInt(value
);
1285 SetChoicesExclusive(); // Make sure we don't corrupt colour lists of other properties
1287 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1289 // Show custom choice
1290 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1291 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1293 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1295 // Hide custom choice
1296 m_choices
.RemoveAt(GetCustomColourIndex());
1297 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1305 // -----------------------------------------------------------------------
1307 // -----------------------------------------------------------------------
1309 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1329 (const wxChar
*) NULL
1332 static unsigned long gs_cp_es_normcolour_colours
[] = {
1334 wxPG_COLOUR(128,0,0),
1335 wxPG_COLOUR(0,0,128),
1336 wxPG_COLOUR(128,0,128),
1337 wxPG_COLOUR(0,128,128),
1338 wxPG_COLOUR(128,128,128),
1339 wxPG_COLOUR(0,128,0),
1340 wxPG_COLOUR(128,128,0),
1341 wxPG_COLOUR(166,124,81),
1342 wxPG_COLOUR(0,0,255),
1343 wxPG_COLOUR(255,0,255),
1344 wxPG_COLOUR(255,0,0),
1345 wxPG_COLOUR(247,148,28),
1346 wxPG_COLOUR(192,192,192),
1347 wxPG_COLOUR(0,255,0),
1348 wxPG_COLOUR(0,255,255),
1349 wxPG_COLOUR(255,255,0),
1350 wxPG_COLOUR(255,255,255),
1354 WX_PG_IMPLEMENT_CUSTOM_COLOUR_PROPERTY_USES_WXCOLOUR2(wxColourProperty
,
1355 gs_cp_es_normcolour_labels
,
1357 gs_cp_es_normcolour_colours
,
1360 // -----------------------------------------------------------------------
1362 // -----------------------------------------------------------------------
1364 #define wxPG_CURSOR_IMAGE_WIDTH 32
1366 #define NUM_CURSORS 28
1368 //#define wx_cp_es_syscursors_len 28
1369 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1381 wxT("Middle Button"),
1387 wxT("Question Arrow"),
1388 wxT("Right Button"),
1389 wxT("Sizing NE-SW"),
1391 wxT("Sizing NW-SE"),
1398 (const wxChar
*) NULL
1401 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1404 wxCURSOR_RIGHT_ARROW
,
1411 wxCURSOR_LEFT_BUTTON
,
1413 wxCURSOR_MIDDLE_BUTTON
,
1415 wxCURSOR_PAINT_BRUSH
,
1417 wxCURSOR_POINT_LEFT
,
1418 wxCURSOR_POINT_RIGHT
,
1419 wxCURSOR_QUESTION_ARROW
,
1420 wxCURSOR_RIGHT_BUTTON
,
1432 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1434 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1436 : wxEnumProperty( label
,
1438 gs_cp_es_syscursors_labels
,
1439 gs_cp_es_syscursors_values
,
1442 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1445 wxCursorProperty::~wxCursorProperty()
1449 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1451 #if wxPG_CAN_DRAW_CURSOR
1452 if ( item
!= -1 && item
< NUM_CURSORS
)
1453 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1460 #if wxPG_CAN_DRAW_CURSOR
1462 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1464 wxPGPaintData
& paintdata
)
1467 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1469 if ( paintdata
.m_choiceItem
>= 0 )
1471 dc
.DrawRectangle( rect
);
1473 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1475 int cursorindex
= gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1478 if ( cursorindex
== wxCURSOR_NONE
)
1479 cursorindex
= wxCURSOR_ARROW
;
1481 wxCursor
cursor( cursorindex
);
1484 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1488 (HICON
)cursor
.GetHandle(),
1493 DI_COMPAT
| DI_DEFAULTSIZE
| DI_NORMAL
1502 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1503 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1505 return wxEnumProperty::GetCellRenderer(column);
1509 // -----------------------------------------------------------------------
1510 // wxImageFileProperty
1511 // -----------------------------------------------------------------------
1515 const wxString
& wxPGGetDefaultImageWildcard()
1517 // Form the wildcard, if not done yet
1518 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1523 // TODO: This section may require locking (using global).
1525 wxList
& handlers
= wxImage::GetHandlers();
1527 wxList::iterator node
;
1529 // Let's iterate over the image handler list.
1530 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1531 for ( node
= handlers
.begin(); node
!= handlers
.end(); node
++ )
1533 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1535 wxString ext_lo
= handler
->GetExtension();
1536 wxString ext_up
= ext_lo
.Upper();
1538 str
.append( ext_up
);
1539 str
.append( wxT(" files (*.") );
1540 str
.append( ext_up
);
1541 str
.append( wxT(")|*.") );
1542 str
.append( ext_lo
);
1543 str
.append( wxT("|") );
1546 str
.append ( wxT("All files (*.*)|*.*") );
1548 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1551 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1554 WX_PG_IMPLEMENT_DERIVED_PROPERTY_CLASS(wxImageFileProperty
,
1558 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1559 const wxString
& value
)
1560 : wxFileProperty(label
,name
,value
)
1562 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1564 m_pImage
= (wxImage
*) NULL
;
1565 m_pBitmap
= (wxBitmap
*) NULL
;
1568 wxImageFileProperty::~wxImageFileProperty()
1576 void wxImageFileProperty::OnSetValue()
1578 wxFileProperty::OnSetValue();
1592 // Create the image thumbnail
1593 if ( m_filename
.FileExists() )
1595 m_pImage
= new wxImage( m_filename
.GetFullPath() );
1599 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1601 return wxPG_DEFAULT_IMAGE_SIZE
;
1604 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1608 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1610 // Draw the thumbnail
1612 // Create the bitmap here because required size is not known in OnSetValue().
1615 m_pImage
->Rescale( rect
.width
, rect
.height
);
1616 m_pBitmap
= new wxBitmap( *m_pImage
);
1621 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1625 // No file - just draw a white box
1626 dc
.SetBrush( *wxWHITE_BRUSH
);
1627 dc
.DrawRectangle ( rect
);
1631 #endif // wxUSE_IMAGE
1633 // -----------------------------------------------------------------------
1634 // wxMultiChoiceProperty
1635 // -----------------------------------------------------------------------
1639 #include <wx/choicdlg.h>
1641 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1642 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1644 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1645 const wxString
& name
,
1646 const wxPGChoices
& choices
,
1647 const wxArrayString
& value
)
1648 : wxPGProperty(label
,name
)
1650 m_choices
.Assign(choices
);
1654 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1655 const wxString
& name
,
1656 const wxArrayString
& strings
,
1657 const wxArrayString
& value
)
1658 : wxPGProperty(label
,name
)
1660 m_choices
.Set(strings
);
1664 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1665 const wxString
& name
,
1666 const wxArrayString
& value
)
1667 : wxPGProperty(label
,name
)
1669 wxArrayString strings
;
1670 m_choices
.Set(strings
);
1674 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1678 void wxMultiChoiceProperty::OnSetValue()
1680 GenerateValueAsString();
1683 wxString
wxMultiChoiceProperty::GetValueAsString( int ) const
1688 void wxMultiChoiceProperty::GenerateValueAsString()
1690 wxArrayString strings
;
1692 if ( m_value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1693 strings
= m_value
.GetArrayString();
1695 wxString
& tempStr
= m_display
;
1697 unsigned int itemCount
= strings
.size();
1702 tempStr
.append( wxT("\"") );
1704 for ( i
= 0; i
< itemCount
; i
++ )
1706 tempStr
.append( strings
[i
] );
1707 tempStr
.append( wxT("\"") );
1708 if ( i
< (itemCount
-1) )
1709 tempStr
.append ( wxT(" \"") );
1713 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1715 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(GetValue());
1718 // Translate values to string indices.
1719 wxArrayInt selections
;
1721 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1723 for ( i
=0; i
<valueArr
.size(); i
++ )
1728 for ( i
=0; i
<valueArr
.size(); i
++ )
1730 int sIndex
= m_choices
.Index(valueArr
[i
]);
1732 selections
.Add(sIndex
);
1739 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1740 wxWindow
* WXUNUSED(primary
),
1743 if ( propgrid
->IsMainButtonEvent(event
) )
1746 PrepareValueForDialogEditing(propgrid
);
1748 wxArrayString labels
= m_choices
.GetLabels();
1749 unsigned int choiceCount
;
1751 if ( m_choices
.IsOk() )
1752 choiceCount
= m_choices
.GetCount();
1756 // launch editor dialog
1757 wxMultiChoiceDialog
dlg( propgrid
,
1758 _("Make a selection:"),
1761 choiceCount
?&labels
[0]:NULL
,
1762 wxCHOICEDLG_STYLE
);
1764 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
1766 wxArrayString strings
= m_value
.GetArrayString();
1767 wxArrayString extraStrings
;
1769 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
1771 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
1773 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1775 wxArrayInt arrInt
= dlg
.GetSelections();
1779 // Strings that were not in list of choices
1780 wxArrayString value
;
1782 // Translate string indices to strings
1785 if ( userStringMode
== 1 )
1787 for (n
=0;n
<extraStrings
.size();n
++)
1788 value
.push_back(extraStrings
[n
]);
1792 for ( i
=0; i
<arrInt
.size(); i
++ )
1793 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
1795 if ( userStringMode
== 2 )
1797 for (n
=0;n
<extraStrings
.size();n
++)
1798 value
.push_back(extraStrings
[n
]);
1801 variant
= WXVARIANT(value
);
1803 SetValueInEvent(variant
);
1811 int wxMultiChoiceProperty::GetChoiceInfo( wxPGChoiceInfo
* choiceinfo
)
1814 choiceinfo
->m_choices
= &m_choices
;
1818 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1822 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1824 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
1825 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
1827 WX_PG_TOKENIZER2_END()
1829 wxVariant
v( WXVARIANT(arr
) );
1835 #endif // wxUSE_CHOICEDLG
1838 // -----------------------------------------------------------------------
1840 // -----------------------------------------------------------------------
1845 #if wxUSE_DATEPICKCTRL
1846 #define dtCtrl DatePickerCtrl
1848 #define dtCtrl TextCtrl
1851 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
1858 wxString
wxDateProperty::ms_defaultDateFormat
;
1861 wxDateProperty::wxDateProperty( const wxString
& label
,
1862 const wxString
& name
,
1863 const wxDateTime
& value
)
1864 : wxPGProperty(label
,name
)
1866 //wxPGRegisterDefaultValueType(wxDateTime)
1868 #if wxUSE_DATEPICKCTRL
1869 wxPGRegisterEditorClass(DatePickerCtrl
);
1871 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
1879 wxDateProperty::~wxDateProperty()
1883 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
1884 int WXUNUSED(argFlags
) ) const
1888 const char* c
= dt
.ParseFormat(text
, wxString(wxDefaultDateTimeFormat
), wxDefaultDateTime
, NULL
);
1899 wxString
wxDateProperty::GetValueAsString( int argFlags
) const
1901 const wxChar
* format
= (const wxChar
*) NULL
;
1903 wxDateTime dateTime
= m_value
.GetDateTime();
1905 if ( !dateTime
.IsValid() )
1906 return wxT("Invalid");
1908 if ( !ms_defaultDateFormat
.length() )
1910 #if wxUSE_DATEPICKCTRL
1911 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
1913 bool showCentury
= true;
1915 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
1918 if ( m_format
.length() &&
1919 !(argFlags
& wxPG_FULL_VALUE
) )
1920 format
= m_format
.c_str();
1922 // Determine default from locale
1923 // NB: This is really simple stuff, but can't figure anything
1924 // better without proper support in wxLocale
1926 format
= ms_defaultDateFormat
.c_str();
1928 return dateTime
.Format(format
);
1931 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
1933 // This code is basicly copied from datectlg.cpp's SetFormat
1938 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
1939 wxString
str(dt
.Format(wxT("%x")));
1941 const wxChar
*p
= str
.c_str();
1945 if (n
== dt
.GetDay())
1947 format
.Append(wxT("%d"));
1950 else if (n
== (int)dt
.GetMonth()+1)
1952 format
.Append(wxT("%m"));
1955 else if (n
== dt
.GetYear())
1957 format
.Append(wxT("%Y"));
1960 else if (n
== (dt
.GetYear() % 100))
1963 format
.Append(wxT("%Y"));
1965 format
.Append(wxT("%y"));
1969 format
.Append(*p
++);
1975 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1977 if ( name
== wxPG_DATE_FORMAT
)
1979 m_format
= value
.GetString();
1982 else if ( name
== wxPG_DATE_PICKER_STYLE
)
1984 m_dpStyle
= value
.GetLong();
1985 ms_defaultDateFormat
.clear(); // This may need recalculation
1991 #endif // wxUSE_DATETIME
1994 // -----------------------------------------------------------------------
1995 // wxPropertyGridInterface
1996 // -----------------------------------------------------------------------
1998 void wxPropertyGridInterface::InitAllTypeHandlers()
2002 // -----------------------------------------------------------------------
2004 void wxPropertyGridInterface::RegisterAdditionalEditors()
2007 wxPGRegisterEditorClass(SpinCtrl
);
2009 #if wxUSE_DATEPICKCTRL
2010 wxPGRegisterEditorClass(DatePickerCtrl
);
2014 // -----------------------------------------------------------------------
2016 #endif // wxPG_INCLUDE_ADVPROPS
2018 #endif // wxUSE_PROPGRID