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 // Implement dynamic class for type value.
84 IMPLEMENT_DYNAMIC_CLASS(wxColourPropertyValue
, wxObject
)
86 bool operator == (const wxColourPropertyValue
& a
, const wxColourPropertyValue
& b
)
88 return ( ( a
.m_colour
== b
.m_colour
) && (a
.m_type
== b
.m_type
) );
91 bool operator == (const wxArrayInt
& array1
, const wxArrayInt
& array2
)
93 if ( array1
.size() != array2
.size() )
96 for ( i
=0; i
<array1
.size(); i
++ )
98 if ( array1
[i
] != array2
[i
] )
104 // -----------------------------------------------------------------------
105 // wxSpinCtrl-based property editor
106 // -----------------------------------------------------------------------
112 #define IS_MOTION_SPIN_SUPPORTED 1
114 #define IS_MOTION_SPIN_SUPPORTED 0
117 #if IS_MOTION_SPIN_SUPPORTED
120 // This class implements ability to rapidly change "spin" value
121 // by moving mouse when one of the spin buttons is depressed.
122 class wxPGSpinButton
: public wxSpinButton
125 wxPGSpinButton() : wxSpinButton()
128 m_hasCapture
= false;
131 Connect( wxEVT_LEFT_DOWN
,
132 wxMouseEventHandler(wxPGSpinButton::OnMouseEvent
) );
133 Connect( wxEVT_LEFT_UP
,
134 wxMouseEventHandler(wxPGSpinButton::OnMouseEvent
) );
135 Connect( wxEVT_MOTION
,
136 wxMouseEventHandler(wxPGSpinButton::OnMouseEvent
) );
137 Connect( wxEVT_MOUSE_CAPTURE_LOST
,
138 wxMouseCaptureLostEventHandler(wxPGSpinButton::OnMouseCaptureLost
) );
147 wxPoint m_ptPosition
;
149 // Having a separate spins variable allows us to handle validation etc. for
150 // multiple spin events at once (with quick mouse movements there could be
151 // hundreds of 'spins' being done at once). Technically things like this
152 // should be stored in event (wxSpinEvent in this case), but there probably
153 // isn't anything there that can be reliably reused.
158 // SpinButton seems to be a special for mouse capture, so we may need track
159 // privately whether mouse is actually captured.
170 SetCursor(wxCURSOR_SIZENS
);
179 m_hasCapture
= false;
182 wxWindow
*parent
= GetParent();
184 SetCursor(parent
->GetCursor());
186 SetCursor(wxNullCursor
);
189 void OnMouseEvent(wxMouseEvent
& event
)
191 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
194 m_ptPosition
= event
.GetPosition();
196 else if ( event
.GetEventType() == wxEVT_LEFT_UP
)
201 else if ( event
.GetEventType() == wxEVT_MOTION
)
205 int dy
= m_ptPosition
.y
- event
.GetPosition().y
;
209 m_ptPosition
= event
.GetPosition();
211 wxSpinEvent
evtscroll( (dy
>= 0) ? wxEVT_SCROLL_LINEUP
:
212 wxEVT_SCROLL_LINEDOWN
,
214 evtscroll
.SetEventObject(this);
216 wxASSERT( m_spins
== 1 );
219 GetEventHandler()->ProcessEvent(evtscroll
);
227 void OnMouseCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
233 #endif // IS_MOTION_SPIN_SUPPORTED
236 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(SpinCtrl
,
241 // Trivial destructor.
242 wxPGSpinCtrlEditor::~wxPGSpinCtrlEditor()
247 // Create controls and initialize event handling.
248 wxPGWindowList
wxPGSpinCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
249 const wxPoint
& pos
, const wxSize
& sz
) const
251 const int margin
= 1;
252 wxSize
butSz(18, sz
.y
);
253 wxSize
tcSz(sz
.x
- butSz
.x
- margin
, sz
.y
);
254 wxPoint
butPos(pos
.x
+ tcSz
.x
+ margin
, pos
.y
);
258 #if IS_MOTION_SPIN_SUPPORTED
259 if ( property
->GetAttributeAsLong(wxT("MotionSpin"), 0) )
261 wnd2
= new wxPGSpinButton();
266 wnd2
= new wxSpinButton();
272 wnd2
->Create( propgrid
->GetPanel(), wxPG_SUBID2
, butPos
, butSz
, wxSP_VERTICAL
);
274 wnd2
->SetRange( INT_MIN
, INT_MAX
);
277 // Let's add validator to make sure only numbers can be entered
278 wxTextValidator
validator(wxFILTER_NUMERIC
, &m_tempString
);
280 wxTextCtrl
* wnd1
= (wxTextCtrl
*) wxPGTextCtrlEditor::CreateControls( propgrid
, property
, pos
, tcSz
).m_primary
;
281 wnd1
->SetValidator(validator
);
283 return wxPGWindowList(wnd1
, wnd2
);
286 // Control's events are redirected here
287 bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
288 wxWindow
* wnd
, wxEvent
& event
) const
290 int evtType
= event
.GetEventType();
293 bool bigStep
= false;
295 if ( evtType
== wxEVT_KEY_DOWN
)
297 wxKeyEvent
& keyEvent
= (wxKeyEvent
&)event
;
298 keycode
= keyEvent
.GetKeyCode();
300 if ( keycode
== WXK_UP
)
301 evtType
= wxEVT_SCROLL_LINEUP
;
302 else if ( keycode
== WXK_DOWN
)
303 evtType
= wxEVT_SCROLL_LINEDOWN
;
304 else if ( keycode
== WXK_PAGEUP
)
306 evtType
= wxEVT_SCROLL_LINEUP
;
309 else if ( keycode
== WXK_PAGEDOWN
)
311 evtType
= wxEVT_SCROLL_LINEDOWN
;
316 if ( evtType
== wxEVT_SCROLL_LINEUP
|| evtType
== wxEVT_SCROLL_LINEDOWN
)
318 #if IS_MOTION_SPIN_SUPPORTED
319 if ( property
->GetAttributeAsLong(wxT("MotionSpin"), 0) )
321 wxPGSpinButton
* spinButton
=
322 (wxPGSpinButton
*) propgrid
->GetEditorControlSecondary();
325 spins
= spinButton
->GetSpins();
330 // Can't use wnd since it might be clipper window
331 wxTextCtrl
* tc
= wxDynamicCast(propgrid
->GetEditorControl(), wxTextCtrl
);
336 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
338 int mode
= wxPG_PROPERTY_VALIDATION_SATURATE
;
340 if ( property
->GetAttributeAsLong(wxT("Wrap"), 0) )
341 mode
= wxPG_PROPERTY_VALIDATION_WRAP
;
343 if ( property
->GetValueType() == wxT("double") )
346 double step
= property
->GetAttributeAsDouble(wxT("Step"), 1.0);
349 if ( s
.ToDouble(&v_d
) )
354 step
*= (double) spins
;
356 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_d
+= step
;
360 wxFloatProperty::DoValidation(property
, v_d
, NULL
, mode
);
362 wxPropertyGrid::DoubleToString(s
, v_d
, 6, true, NULL
);
372 wxLongLong_t step
= property
->GetAttributeAsLong(wxT("Step"), 1);
375 if ( s
.ToLongLong(&v_ll
, 10) )
382 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_ll
+= step
;
386 wxIntProperty::DoValidation(property
, v_ll
, NULL
, mode
);
388 s
= wxLongLong(v_ll
).ToString();
398 int ip
= tc
->GetInsertionPoint();
399 int lp
= tc
->GetLastPosition();
401 tc
->SetInsertionPoint(ip
+(tc
->GetLastPosition()-lp
));
407 return wxPGTextCtrlEditor::OnEvent(propgrid
,property
,wnd
,event
);
410 #endif // wxUSE_SPINBTN
413 // -----------------------------------------------------------------------
414 // wxDatePickerCtrl-based property editor
415 // -----------------------------------------------------------------------
417 #if wxUSE_DATEPICKCTRL
420 #include "wx/datectrl.h"
421 #include "wx/dateevt.h"
423 class wxPGDatePickerCtrlEditor
: public wxPGEditor
425 DECLARE_DYNAMIC_CLASS(wxPGDatePickerCtrlEditor
)
427 virtual ~wxPGDatePickerCtrlEditor();
429 wxString
GetName() const;
430 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
431 wxPGProperty
* property
,
433 const wxSize
& size
) const;
434 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const;
435 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
436 wxWindow
* wnd
, wxEvent
& event
) const;
437 virtual bool GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* wnd
) const;
438 virtual void SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const;
442 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(DatePickerCtrl
,
443 wxPGDatePickerCtrlEditor
,
447 wxPGDatePickerCtrlEditor::~wxPGDatePickerCtrlEditor()
451 wxPGWindowList
wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
,
452 wxPGProperty
* property
,
454 const wxSize
& sz
) const
456 wxCHECK_MSG( property
->IsKindOf(CLASSINFO(wxDateProperty
)),
458 wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
460 wxDateProperty
* prop
= (wxDateProperty
*) property
;
462 // Use two stage creation to allow cleaner display on wxMSW
463 wxDatePickerCtrl
* ctrl
= new wxDatePickerCtrl();
466 wxSize useSz
= wxDefaultSize
;
472 wxDateTime
dateValue(wxInvalidDateTime
);
474 wxVariant value
= prop
->GetValue();
475 if ( value
.GetType() == wxT("datetime") )
476 dateValue
= value
.GetDateTime();
478 ctrl
->Create(propgrid
->GetPanel(),
483 prop
->GetDatePickerStyle() | wxNO_BORDER
);
492 // Copies value from property to control
493 void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const
495 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
496 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
498 // We assume that property's data type is 'int' (or something similar),
499 // thus allowing us to get raw, unchecked value via DoGetValue.
500 ctrl
->SetValue( property
->GetValue().GetDateTime() );
503 // Control's events are redirected here
504 bool wxPGDatePickerCtrlEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propgrid
),
505 wxPGProperty
* WXUNUSED(property
),
506 wxWindow
* WXUNUSED(wnd
),
507 wxEvent
& event
) const
509 if ( event
.GetEventType() == wxEVT_DATE_CHANGED
)
515 bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const
517 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
518 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
520 variant
= ctrl
->GetValue();
525 void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* WXUNUSED(wnd
) ) const
528 //wxDateProperty* prop = (wxDateProperty*) property;
532 #endif // wxUSE_DATEPICKCTRL
535 // -----------------------------------------------------------------------
537 // -----------------------------------------------------------------------
539 #include "wx/fontdlg.h"
540 #include "wx/fontenum.h"
542 static const wxChar
* gs_fp_es_family_labels
[] = {
543 wxT("Default"), wxT("Decorative"),
544 wxT("Roman"), wxT("Script"),
545 wxT("Swiss"), wxT("Modern"),
549 static long gs_fp_es_family_values
[] = {
550 wxDEFAULT
, wxDECORATIVE
,
555 static const wxChar
* gs_fp_es_style_labels
[] = {
562 static long gs_fp_es_style_values
[] = {
568 static const wxChar
* gs_fp_es_weight_labels
[] = {
575 static long gs_fp_es_weight_values
[] = {
581 // Class body is in advprops.h
584 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty
,wxPGProperty
,
585 wxFont
,const wxFont
&,TextCtrlAndButton
)
588 wxFontProperty::wxFontProperty( const wxString
& label
, const wxString
& name
,
589 const wxFont
& value
)
590 : wxPGProperty(label
,name
)
592 SetValue(WXVARIANT(value
));
594 // Initialize font family choices list
595 if ( !wxPGGlobalVars
->m_fontFamilyChoices
)
597 wxArrayString faceNames
= wxFontEnumerator::GetFacenames();
601 wxPGGlobalVars
->m_fontFamilyChoices
= new wxPGChoices(faceNames
);
604 wxString
emptyString(wxEmptyString
);
609 SetParentalType(wxPG_PROP_AGGREGATE
);
611 AddChild( new wxIntProperty( _("Point Size"), wxS("Point Size"),(long)font
.GetPointSize() ) );
613 AddChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
614 gs_fp_es_family_labels
,gs_fp_es_family_values
,
617 wxString faceName
= font
.GetFaceName();
618 // If font was not in there, add it now
619 if ( faceName
.length() &&
620 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
621 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
623 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"), wxS("Face Name"),
624 *wxPGGlobalVars
->m_fontFamilyChoices
);
626 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
630 AddChild( new wxEnumProperty(_("Style"), wxS("Style"),
631 gs_fp_es_style_labels
,gs_fp_es_style_values
,font
.GetStyle()) );
633 AddChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
634 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,font
.GetWeight()) );
636 AddChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
637 font
.GetUnderlined()) );
640 wxFontProperty::~wxFontProperty() { }
642 void wxFontProperty::OnSetValue()
649 font
= wxFont(10,wxSWISS
,wxNORMAL
,wxNORMAL
);
654 wxString
wxFontProperty::ValueToString( wxVariant
& value
,
657 return wxPGProperty::ValueToString(value
, argFlags
);
660 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
663 if ( propgrid
->IsMainButtonEvent(event
) )
665 // Update value from last minute changes
666 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
671 data
.SetInitialFont( font
);
672 data
.SetColour(*wxBLACK
);
674 wxFontDialog
dlg(propgrid
, data
);
675 if ( dlg
.ShowModal() == wxID_OK
)
677 propgrid
->EditorsValueWasModified();
680 variant
<< dlg
.GetFontData().GetChosenFont();
681 SetValueInEvent( variant
);
688 void wxFontProperty::RefreshChildren()
690 if ( !GetChildCount() ) return;
693 Item(0)->SetValue( (long)font
.GetPointSize() );
694 Item(1)->SetValue( (long)font
.GetFamily() );
695 Item(2)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
696 Item(3)->SetValue( (long)font
.GetStyle() );
697 Item(4)->SetValue( (long)font
.GetWeight() );
698 Item(5)->SetValue( font
.GetUnderlined() );
701 void wxFontProperty::ChildChanged( wxVariant
& thisValue
, int ind
, wxVariant
& childValue
) const
708 font
.SetPointSize( wxPGVariantToInt(childValue
) );
712 int fam
= childValue
.GetLong();
713 if ( fam
< wxDEFAULT
||
716 font
.SetFamily( fam
);
721 int faceIndex
= childValue
.GetLong();
723 if ( faceIndex
>= 0 )
724 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
726 font
.SetFaceName( faceName
);
730 int st
= childValue
.GetLong();
731 if ( st
!= wxFONTSTYLE_NORMAL
&&
732 st
!= wxFONTSTYLE_SLANT
&&
733 st
!= wxFONTSTYLE_ITALIC
)
734 st
= wxFONTWEIGHT_NORMAL
;
739 int wt
= childValue
.GetLong();
740 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
741 wt
!= wxFONTWEIGHT_LIGHT
&&
742 wt
!= wxFONTWEIGHT_BOLD
)
743 wt
= wxFONTWEIGHT_NORMAL
;
744 font
.SetWeight( wt
);
748 font
.SetUnderlined( childValue
.GetBool() );
755 wxSize wxFontProperty::OnMeasureImage() const
757 return wxSize(-1,-1);
760 void wxFontProperty::OnCustomPaint(wxDC& dc,
762 wxPGPaintData& paintData)
765 if ( paintData.m_choiceItem >= 0 )
766 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
768 drawFace = m_value_wxFont.GetFaceName();
770 if ( drawFace.length() )
772 // Draw the background
773 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
774 //dc.SetBrush( *wxWHITE_BRUSH );
775 //dc.SetPen( *wxMEDIUM_GREY_PEN );
776 dc.DrawRectangle( rect );
778 wxFont oldFont = dc.GetFont();
779 wxFont drawFont(oldFont.GetPointSize(),
780 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
781 dc.SetFont(drawFont);
783 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
784 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
790 // No file - just draw a white box
791 dc.SetBrush ( *wxWHITE_BRUSH );
792 dc.DrawRectangle ( rect );
798 // -----------------------------------------------------------------------
799 // wxSystemColourProperty
800 // -----------------------------------------------------------------------
802 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
803 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
805 #include "wx/colordlg.h"
807 //#define wx_cp_es_syscolours_len 25
808 static const wxChar
* gs_cp_es_syscolour_labels
[] = {
811 wxT("ActiveCaption"),
813 wxT("ButtonHighlight"),
822 wxT("HighlightText"),
823 wxT("InactiveBorder"),
824 wxT("InactiveCaption"),
825 wxT("InactiveCaptionText"),
837 static long gs_cp_es_syscolour_values
[] = {
838 wxSYS_COLOUR_APPWORKSPACE
,
839 wxSYS_COLOUR_ACTIVEBORDER
,
840 wxSYS_COLOUR_ACTIVECAPTION
,
841 wxSYS_COLOUR_BTNFACE
,
842 wxSYS_COLOUR_BTNHIGHLIGHT
,
843 wxSYS_COLOUR_BTNSHADOW
,
844 wxSYS_COLOUR_BTNTEXT
,
845 wxSYS_COLOUR_CAPTIONTEXT
,
846 wxSYS_COLOUR_3DDKSHADOW
,
847 wxSYS_COLOUR_3DLIGHT
,
848 wxSYS_COLOUR_BACKGROUND
,
849 wxSYS_COLOUR_GRAYTEXT
,
850 wxSYS_COLOUR_HIGHLIGHT
,
851 wxSYS_COLOUR_HIGHLIGHTTEXT
,
852 wxSYS_COLOUR_INACTIVEBORDER
,
853 wxSYS_COLOUR_INACTIVECAPTION
,
854 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
856 wxSYS_COLOUR_SCROLLBAR
,
858 wxSYS_COLOUR_INFOTEXT
,
860 wxSYS_COLOUR_WINDOWFRAME
,
861 wxSYS_COLOUR_WINDOWTEXT
,
866 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
869 // Class body is in advprops.h
871 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
872 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
875 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
877 wxColourPropertyValue cpv
;
880 cpv
.Init( type
, colour
);
882 cpv
.Init( type
, *wxWHITE
);
884 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
892 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
895 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
896 const wxColourPropertyValue
& value
)
897 : wxEnumProperty( label
,
899 gs_cp_es_syscolour_labels
,
900 gs_cp_es_syscolour_values
,
901 &gs_wxSystemColourProperty_choicesCache
)
904 Init( value
.m_type
, value
.m_colour
);
906 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
910 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
911 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
912 const wxColourPropertyValue
& value
)
913 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
916 Init( value
.m_type
, value
.m_colour
);
918 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
922 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
923 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
924 const wxColour
& value
)
925 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
928 Init( wxPG_COLOUR_CUSTOM
, value
);
930 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
934 wxSystemColourProperty::~wxSystemColourProperty() { }
937 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
942 if ( pVariant
->IsNull() )
943 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
945 if ( pVariant
->GetType() == wxS("wxColourPropertyValue") )
947 wxColourPropertyValue v
;
953 bool variantProcessed
= true;
955 if ( pVariant
->GetType() == wxS("wxColour*") )
957 wxColour
* pCol
= wxStaticCast(pVariant
->GetWxObjectPtr(), wxColour
);
960 else if ( pVariant
->GetType() == wxS("wxColour") )
964 else if ( pVariant
->GetType() == wxArrayInt_VariantType
)
966 // This code is mostly needed for wxPython bindings, which
967 // may offer tuple of integers as colour value.
971 if ( arr
.size() >= 3 )
979 if ( arr
.size() >= 4 )
982 col
= wxColour(r
, g
, b
, a
);
986 variantProcessed
= false;
991 variantProcessed
= false;
994 if ( !variantProcessed
)
995 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
997 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
999 int colInd
= ColToInd(col
);
1000 if ( colInd
!= wxNOT_FOUND
)
1006 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1013 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
1016 size_t i_max
= m_choices
.GetCount() - 1;
1018 for ( i
=0; i
<i_max
; i
++ )
1020 int ind
= m_choices
[i
].GetValue();
1022 if ( colour
== GetColour(ind
) )
1024 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
1025 GetClassName(),GetLabel().c_str(),
1026 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
1027 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
1034 void wxSystemColourProperty::OnSetValue()
1036 // Convert from generic wxobject ptr to wxPGVariantDataColour
1037 if ( m_value
.GetType() == wxS("wxColour*") )
1039 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
1043 wxColourPropertyValue val
= GetVal(&m_value
);
1045 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
1053 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
1054 val
.m_colour
= GetColour( val
.m_type
);
1056 m_value
= TranslateVal(val
);
1059 int ind
= wxNOT_FOUND
;
1061 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
1063 wxColourPropertyValue cpv
;
1065 wxColour col
= cpv
.m_colour
;
1069 SetValueToUnspecified();
1070 SetIndex(wxNOT_FOUND
);
1074 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
)
1076 ind
= GetIndexForValue(cpv
.m_type
);
1080 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
1081 ind
= GetCustomColourIndex();
1091 SetValueToUnspecified();
1092 SetIndex(wxNOT_FOUND
);
1096 ind
= ColToInd(col
);
1098 if ( ind
== wxNOT_FOUND
)
1099 ind
= GetCustomColourIndex();
1106 wxColour
wxSystemColourProperty::GetColour( int index
) const
1108 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
1111 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
1113 if ( index
== wxNOT_FOUND
)
1114 return wxString::Format(wxT("(%i,%i,%i)"),
1119 return m_choices
.GetLabel(index
);
1122 wxString
wxSystemColourProperty::ValueToString( wxVariant
& value
,
1123 int argFlags
) const
1125 wxColourPropertyValue val
= GetVal(&value
);
1129 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1131 // GetIndex() only works reliably if wxPG_VALUE_IS_CURRENT flag is set,
1132 // but we should use it whenever possible.
1135 // If custom colour was selected, use invalid index, so that
1136 // ColourToString() will return properly formatted colour text.
1137 if ( index
== GetCustomColourIndex() )
1138 index
= wxNOT_FOUND
;
1142 index
= m_choices
.Index(val
.m_type
);
1145 return ColourToString(val
.m_colour
, index
);
1149 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
1151 return wxPG_DEFAULT_IMAGE_SIZE
;
1155 int wxSystemColourProperty::GetCustomColourIndex() const
1157 return m_choices
.GetCount() - 1;
1161 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1163 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1166 wxPropertyGrid
* propgrid
= GetGrid();
1167 wxASSERT( propgrid
);
1169 // Must only occur when user triggers event
1170 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
) )
1173 wxColourPropertyValue val
= GetVal();
1175 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1178 data
.SetChooseFull(true);
1179 data
.SetColour(val
.m_colour
);
1181 for ( i
= 0; i
< 16; i
++)
1183 wxColour
colour(i
*16, i
*16, i
*16);
1184 data
.SetCustomColour(i
, colour
);
1187 wxColourDialog
dialog(propgrid
, &data
);
1188 if ( dialog
.ShowModal() == wxID_OK
)
1190 wxColourData retData
= dialog
.GetColourData();
1191 val
.m_colour
= retData
.GetColour();
1193 variant
= DoTranslateVal(val
);
1195 SetValueInEvent(variant
);
1204 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1207 int type
= m_choices
.GetValue(index
);
1209 if ( type
== wxPG_COLOUR_CUSTOM
)
1211 QueryColourFromUser(variant
);
1215 variant
= TranslateVal( type
, GetColour(type
) );
1221 // Need to do some extra event handling.
1222 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
), wxEvent
& event
)
1224 if ( propgrid
->IsMainButtonEvent(event
) )
1226 // We need to handle button click in case editor has been
1227 // switched to one that has wxButton as well.
1229 if ( QueryColourFromUser(variant
) )
1235 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1238 virtual void Render( wxDC& dc, const wxRect& rect,
1239 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1240 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1242 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1243 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1245 dc.SetPen(*wxBLACK_PEN);
1247 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1251 const wxArrayInt& values = prop->GetValues();
1252 if ( values.GetChildCount() )
1253 colInd = values[item];
1256 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1258 else if ( !prop->IsValueUnspecified() )
1259 dc.SetBrush( prop->GetVal().m_colour );
1261 dc.SetBrush( *wxWHITE );
1263 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1264 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1265 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1266 imageRect.width, imageRect.height );
1270 text = property->GetValueAsString();
1272 text = property->GetChoiceString(item);
1273 DrawText( dc, rect, imageRect.width, text );
1278 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1280 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1283 return &g_wxPGColourPropertyRenderer;
1284 return wxEnumProperty::GetCellRenderer(column);
1287 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1288 wxPGPaintData
& paintdata
)
1292 if ( paintdata
.m_choiceItem
>= 0 && paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1293 paintdata
.m_choiceItem
!= GetCustomColourIndex() )
1295 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1296 col
= GetColour( colInd
);
1298 else if ( !IsValueUnspecified() )
1300 col
= GetVal().m_colour
;
1306 dc
.DrawRectangle(rect
);
1311 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1314 // Accept colour format "[Name] [(R,G,B)]"
1315 // Name takes precedence.
1317 wxString colourName
;
1320 int ppos
= text
.Find(wxT("("));
1322 if ( ppos
== wxNOT_FOUND
)
1328 colourName
= text
.substr(0, ppos
);
1329 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1332 // Strip spaces from extremities
1333 colourName
.Trim(true);
1334 colourName
.Trim(false);
1335 colourRGB
.Trim(true);
1337 // Validate colourRGB string - (1,1,1) is shortest allowed
1338 if ( colourRGB
.length() < 7 )
1341 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1342 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1344 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1346 // This really should not occurr...
1352 QueryColourFromUser(value
);
1356 wxColourPropertyValue val
;
1360 if ( colourName
.length() )
1362 // Try predefined colour first
1363 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1364 if ( res
&& GetIndex() >= 0 )
1366 val
.m_type
= GetIndex();
1367 if ( val
.m_type
< m_choices
.GetCount() )
1368 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1370 // Get proper colour for type.
1371 val
.m_colour
= GetColour(val
.m_type
);
1376 if ( colourRGB
.length() && !done
)
1378 // Then check custom colour.
1379 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1381 int r
= -1, g
= -1, b
= -1;
1382 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1384 if ( r
>= 0 && r
<= 255 &&
1385 g
>= 0 && g
<= 255 &&
1386 b
>= 0 && b
<= 255 )
1388 val
.m_colour
.Set(r
,g
,b
);
1400 value
= DoTranslateVal(val
);
1407 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1409 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1411 int ival
= wxPGVariantToInt(value
);
1413 SetChoicesExclusive(); // Make sure we don't corrupt colour lists of other properties
1415 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1417 // Show custom choice
1418 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1419 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1421 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1423 // Hide custom choice
1424 m_choices
.RemoveAt(GetCustomColourIndex());
1425 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1433 // -----------------------------------------------------------------------
1435 // -----------------------------------------------------------------------
1437 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1457 (const wxChar
*) NULL
1460 static unsigned long gs_cp_es_normcolour_colours
[] = {
1462 wxPG_COLOUR(128,0,0),
1463 wxPG_COLOUR(0,0,128),
1464 wxPG_COLOUR(128,0,128),
1465 wxPG_COLOUR(0,128,128),
1466 wxPG_COLOUR(128,128,128),
1467 wxPG_COLOUR(0,128,0),
1468 wxPG_COLOUR(128,128,0),
1469 wxPG_COLOUR(166,124,81),
1470 wxPG_COLOUR(0,0,255),
1471 wxPG_COLOUR(255,0,255),
1472 wxPG_COLOUR(255,0,0),
1473 wxPG_COLOUR(247,148,28),
1474 wxPG_COLOUR(192,192,192),
1475 wxPG_COLOUR(0,255,0),
1476 wxPG_COLOUR(0,255,255),
1477 wxPG_COLOUR(255,255,0),
1478 wxPG_COLOUR(255,255,255),
1482 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxColourProperty
, wxSystemColourProperty
,
1483 wxColour
, const wxColour
&, TextCtrlAndButton
)
1485 static wxPGChoices gs_wxColourProperty_choicesCache
;
1487 wxColourProperty::wxColourProperty( const wxString
& label
,
1488 const wxString
& name
,
1489 const wxColour
& value
)
1490 : wxSystemColourProperty(label
, name
, gs_cp_es_normcolour_labels
,
1492 &gs_wxColourProperty_choicesCache
, value
)
1496 m_flags
|= wxPG_PROP_TRANSLATE_CUSTOM
;
1499 wxColourProperty::~wxColourProperty()
1503 void wxColourProperty::Init( wxColour colour
)
1510 int ind
= ColToInd(colour
);
1512 ind
= m_choices
.GetCount() - 1;
1516 wxString
wxColourProperty::ValueToString( wxVariant
& value
,
1517 int argFlags
) const
1519 const wxPGEditor
* editor
= GetEditorClass();
1520 if ( editor
!= wxPGEditor_Choice
&&
1521 editor
!= wxPGEditor_ChoiceAndButton
&&
1522 editor
!= wxPGEditor_ComboBox
)
1523 argFlags
|= wxPG_PROPERTY_SPECIFIC
;
1525 return wxSystemColourProperty::ValueToString(value
, argFlags
);
1528 wxColour
wxColourProperty::GetColour( int index
) const
1530 return gs_cp_es_normcolour_colours
[m_choices
.GetValue(index
)];
1533 wxVariant
wxColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1536 variant
<< v
.m_colour
;
1540 // -----------------------------------------------------------------------
1542 // -----------------------------------------------------------------------
1544 #define wxPG_CURSOR_IMAGE_WIDTH 32
1546 #define NUM_CURSORS 28
1548 //#define wx_cp_es_syscursors_len 28
1549 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1561 wxT("Middle Button"),
1567 wxT("Question Arrow"),
1568 wxT("Right Button"),
1569 wxT("Sizing NE-SW"),
1571 wxT("Sizing NW-SE"),
1578 (const wxChar
*) NULL
1581 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1584 wxCURSOR_RIGHT_ARROW
,
1591 wxCURSOR_LEFT_BUTTON
,
1593 wxCURSOR_MIDDLE_BUTTON
,
1595 wxCURSOR_PAINT_BRUSH
,
1597 wxCURSOR_POINT_LEFT
,
1598 wxCURSOR_POINT_RIGHT
,
1599 wxCURSOR_QUESTION_ARROW
,
1600 wxCURSOR_RIGHT_BUTTON
,
1612 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1614 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1616 : wxEnumProperty( label
,
1618 gs_cp_es_syscursors_labels
,
1619 gs_cp_es_syscursors_values
,
1622 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1625 wxCursorProperty::~wxCursorProperty()
1629 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1631 #if wxPG_CAN_DRAW_CURSOR
1632 if ( item
!= -1 && item
< NUM_CURSORS
)
1633 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1640 #if wxPG_CAN_DRAW_CURSOR
1642 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1644 wxPGPaintData
& paintdata
)
1647 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1649 if ( paintdata
.m_choiceItem
>= 0 )
1651 dc
.DrawRectangle( rect
);
1653 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1655 wxStockCursor cursorIndex
=
1656 (wxStockCursor
) gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1659 if ( cursorIndex
== wxCURSOR_NONE
)
1660 cursorIndex
= wxCURSOR_ARROW
;
1662 wxCursor
cursor( cursorIndex
);
1665 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1669 (HICON
)cursor
.GetHandle(),
1674 #if !defined(__WXWINCE__)
1675 DI_COMPAT
| DI_DEFAULTSIZE
|
1686 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1687 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1689 return wxEnumProperty::GetCellRenderer(column);
1693 // -----------------------------------------------------------------------
1694 // wxImageFileProperty
1695 // -----------------------------------------------------------------------
1699 const wxString
& wxPGGetDefaultImageWildcard()
1701 // Form the wildcard, if not done yet
1702 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1707 // TODO: This section may require locking (using global).
1709 wxList
& handlers
= wxImage::GetHandlers();
1711 wxList::iterator node
;
1713 // Let's iterate over the image handler list.
1714 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1715 for ( node
= handlers
.begin(); node
!= handlers
.end(); ++node
)
1717 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1719 wxString ext_lo
= handler
->GetExtension();
1720 wxString ext_up
= ext_lo
.Upper();
1722 str
.append( ext_up
);
1723 str
.append( wxT(" files (*.") );
1724 str
.append( ext_up
);
1725 str
.append( wxT(")|*.") );
1726 str
.append( ext_lo
);
1727 str
.append( wxT("|") );
1730 str
.append ( wxT("All files (*.*)|*.*") );
1732 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1735 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1738 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1740 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1741 const wxString
& value
)
1742 : wxFileProperty(label
,name
,value
)
1744 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1746 m_pImage
= (wxImage
*) NULL
;
1747 m_pBitmap
= (wxBitmap
*) NULL
;
1750 wxImageFileProperty::~wxImageFileProperty()
1758 void wxImageFileProperty::OnSetValue()
1760 wxFileProperty::OnSetValue();
1774 wxFileName filename
= GetFileName();
1776 // Create the image thumbnail
1777 if ( filename
.FileExists() )
1779 m_pImage
= new wxImage( filename
.GetFullPath() );
1783 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1785 return wxPG_DEFAULT_IMAGE_SIZE
;
1788 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1792 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1794 // Draw the thumbnail
1796 // Create the bitmap here because required size is not known in OnSetValue().
1799 m_pImage
->Rescale( rect
.width
, rect
.height
);
1800 m_pBitmap
= new wxBitmap( *m_pImage
);
1805 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1809 // No file - just draw a white box
1810 dc
.SetBrush( *wxWHITE_BRUSH
);
1811 dc
.DrawRectangle ( rect
);
1815 #endif // wxUSE_IMAGE
1817 // -----------------------------------------------------------------------
1818 // wxMultiChoiceProperty
1819 // -----------------------------------------------------------------------
1823 #include "wx/choicdlg.h"
1825 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1826 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1828 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1829 const wxString
& name
,
1830 const wxPGChoices
& choices
,
1831 const wxArrayString
& value
)
1832 : wxPGProperty(label
,name
)
1834 m_choices
.Assign(choices
);
1838 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1839 const wxString
& name
,
1840 const wxArrayString
& strings
,
1841 const wxArrayString
& value
)
1842 : wxPGProperty(label
,name
)
1844 m_choices
.Set(strings
);
1848 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1849 const wxString
& name
,
1850 const wxArrayString
& value
)
1851 : wxPGProperty(label
,name
)
1853 wxArrayString strings
;
1854 m_choices
.Set(strings
);
1858 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1862 void wxMultiChoiceProperty::OnSetValue()
1864 GenerateValueAsString(m_value
, &m_display
);
1867 wxString
wxMultiChoiceProperty::ValueToString( wxVariant
& value
,
1868 int argFlags
) const
1870 // If possible, use cached string
1871 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1875 GenerateValueAsString(value
, &s
);
1879 void wxMultiChoiceProperty::GenerateValueAsString( wxVariant
& value
,
1880 wxString
* target
) const
1882 wxArrayString strings
;
1884 if ( value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1885 strings
= value
.GetArrayString();
1887 wxString
& tempStr
= *target
;
1889 unsigned int itemCount
= strings
.size();
1894 tempStr
.append( wxT("\"") );
1896 for ( i
= 0; i
< itemCount
; i
++ )
1898 tempStr
.append( strings
[i
] );
1899 tempStr
.append( wxT("\"") );
1900 if ( i
< (itemCount
-1) )
1901 tempStr
.append ( wxT(" \"") );
1905 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1907 wxVariant variant
= GetValue();
1908 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(variant
);
1911 // Translate values to string indices.
1912 wxArrayInt selections
;
1914 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1916 for ( i
=0; i
<valueArr
.size(); i
++ )
1921 for ( i
=0; i
<valueArr
.size(); i
++ )
1923 int sIndex
= m_choices
.Index(valueArr
[i
]);
1925 selections
.Add(sIndex
);
1932 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1933 wxWindow
* WXUNUSED(primary
),
1936 if ( propgrid
->IsMainButtonEvent(event
) )
1939 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
1941 wxArrayString labels
= m_choices
.GetLabels();
1942 unsigned int choiceCount
;
1944 if ( m_choices
.IsOk() )
1945 choiceCount
= m_choices
.GetCount();
1949 // launch editor dialog
1950 wxMultiChoiceDialog
dlg( propgrid
,
1951 _("Make a selection:"),
1954 choiceCount
?&labels
[0]:NULL
,
1955 wxCHOICEDLG_STYLE
);
1957 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
1959 wxArrayString strings
= useValue
.GetArrayString();
1960 wxArrayString extraStrings
;
1962 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
1964 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
1966 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1968 wxArrayInt arrInt
= dlg
.GetSelections();
1972 // Strings that were not in list of choices
1973 wxArrayString value
;
1975 // Translate string indices to strings
1978 if ( userStringMode
== 1 )
1980 for (n
=0;n
<extraStrings
.size();n
++)
1981 value
.push_back(extraStrings
[n
]);
1985 for ( i
=0; i
<arrInt
.size(); i
++ )
1986 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
1988 if ( userStringMode
== 2 )
1990 for (n
=0;n
<extraStrings
.size();n
++)
1991 value
.push_back(extraStrings
[n
]);
1994 variant
= WXVARIANT(value
);
1996 SetValueInEvent(variant
);
2004 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
2008 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
2010 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
2011 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
2013 WX_PG_TOKENIZER2_END()
2015 wxVariant
v( WXVARIANT(arr
) );
2021 #endif // wxUSE_CHOICEDLG
2024 // -----------------------------------------------------------------------
2026 // -----------------------------------------------------------------------
2031 #if wxUSE_DATEPICKCTRL
2032 #define dtCtrl DatePickerCtrl
2034 #define dtCtrl TextCtrl
2037 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
2044 wxString
wxDateProperty::ms_defaultDateFormat
;
2047 wxDateProperty::wxDateProperty( const wxString
& label
,
2048 const wxString
& name
,
2049 const wxDateTime
& value
)
2050 : wxPGProperty(label
,name
)
2052 //wxPGRegisterDefaultValueType(wxDateTime)
2054 #if wxUSE_DATEPICKCTRL
2055 wxPGRegisterEditorClass(DatePickerCtrl
);
2057 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
2065 wxDateProperty::~wxDateProperty()
2069 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
2070 int WXUNUSED(argFlags
) ) const
2074 const char* c
= dt
.ParseFormat(text
, wxString(wxDefaultDateTimeFormat
), wxDefaultDateTime
, NULL
);
2085 wxString
wxDateProperty::ValueToString( wxVariant
& value
,
2086 int argFlags
) const
2088 const wxChar
* format
= (const wxChar
*) NULL
;
2090 wxDateTime dateTime
= value
.GetDateTime();
2092 if ( !dateTime
.IsValid() )
2093 return wxT("Invalid");
2095 if ( !ms_defaultDateFormat
.length() )
2097 #if wxUSE_DATEPICKCTRL
2098 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
2100 bool showCentury
= true;
2102 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
2105 if ( m_format
.length() &&
2106 !(argFlags
& wxPG_FULL_VALUE
) )
2107 format
= m_format
.c_str();
2109 // Determine default from locale
2110 // NB: This is really simple stuff, but can't figure anything
2111 // better without proper support in wxLocale
2113 format
= ms_defaultDateFormat
.c_str();
2115 return dateTime
.Format(format
);
2118 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
2120 // This code is basicly copied from datectlg.cpp's SetFormat
2125 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
2126 wxString
str(dt
.Format(wxT("%x")));
2128 const wxChar
*p
= str
.c_str();
2132 if (n
== dt
.GetDay())
2134 format
.Append(wxT("%d"));
2137 else if (n
== (int)dt
.GetMonth()+1)
2139 format
.Append(wxT("%m"));
2142 else if (n
== dt
.GetYear())
2144 format
.Append(wxT("%Y"));
2147 else if (n
== (dt
.GetYear() % 100))
2150 format
.Append(wxT("%Y"));
2152 format
.Append(wxT("%y"));
2156 format
.Append(*p
++);
2162 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
2164 if ( name
== wxPG_DATE_FORMAT
)
2166 m_format
= value
.GetString();
2169 else if ( name
== wxPG_DATE_PICKER_STYLE
)
2171 m_dpStyle
= value
.GetLong();
2172 ms_defaultDateFormat
.clear(); // This may need recalculation
2178 #endif // wxUSE_DATETIME
2181 // -----------------------------------------------------------------------
2182 // wxPropertyGridInterface
2183 // -----------------------------------------------------------------------
2185 void wxPropertyGridInterface::InitAllTypeHandlers()
2189 // -----------------------------------------------------------------------
2191 void wxPropertyGridInterface::RegisterAdditionalEditors()
2193 // Register editor classes, if necessary.
2194 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
2195 wxPropertyGrid::RegisterDefaultEditors();
2198 wxPGRegisterEditorClass(SpinCtrl
);
2200 #if wxUSE_DATEPICKCTRL
2201 wxPGRegisterEditorClass(DatePickerCtrl
);
2205 // -----------------------------------------------------------------------
2207 #endif // wxPG_INCLUDE_ADVPROPS
2209 #endif // wxUSE_PROPGRID