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
= wxDynamicCast(property
, wxDateProperty
);
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
,
494 wxWindow
* wnd
) const
496 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
497 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
499 wxDateTime
dateValue(wxInvalidDateTime
);
500 wxVariant
v(property
->GetValue());
501 if ( v
.GetType() == wxT("datetime") )
502 dateValue
= v
.GetDateTime();
504 ctrl
->SetValue( dateValue
);
507 // Control's events are redirected here
508 bool wxPGDatePickerCtrlEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propgrid
),
509 wxPGProperty
* WXUNUSED(property
),
510 wxWindow
* WXUNUSED(wnd
),
511 wxEvent
& event
) const
513 if ( event
.GetEventType() == wxEVT_DATE_CHANGED
)
519 bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const
521 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
522 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
524 variant
= ctrl
->GetValue();
529 void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty
* property
,
530 wxWindow
* wnd
) const
532 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
533 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
535 wxDateProperty
* prop
= wxDynamicCast(property
, wxDateProperty
);
539 int datePickerStyle
= prop
->GetDatePickerStyle();
540 if ( datePickerStyle
& wxDP_ALLOWNONE
)
541 ctrl
->SetValue(wxInvalidDateTime
);
545 #endif // wxUSE_DATEPICKCTRL
548 // -----------------------------------------------------------------------
550 // -----------------------------------------------------------------------
552 #include "wx/fontdlg.h"
553 #include "wx/fontenum.h"
555 static const wxChar
* gs_fp_es_family_labels
[] = {
556 wxT("Default"), wxT("Decorative"),
557 wxT("Roman"), wxT("Script"),
558 wxT("Swiss"), wxT("Modern"),
562 static long gs_fp_es_family_values
[] = {
563 wxDEFAULT
, wxDECORATIVE
,
568 static const wxChar
* gs_fp_es_style_labels
[] = {
575 static long gs_fp_es_style_values
[] = {
581 static const wxChar
* gs_fp_es_weight_labels
[] = {
588 static long gs_fp_es_weight_values
[] = {
594 // Class body is in advprops.h
597 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty
,wxPGProperty
,
598 wxFont
,const wxFont
&,TextCtrlAndButton
)
601 wxFontProperty::wxFontProperty( const wxString
& label
, const wxString
& name
,
602 const wxFont
& value
)
603 : wxPGProperty(label
,name
)
605 SetValue(WXVARIANT(value
));
607 // Initialize font family choices list
608 if ( !wxPGGlobalVars
->m_fontFamilyChoices
)
610 wxArrayString faceNames
= wxFontEnumerator::GetFacenames();
614 wxPGGlobalVars
->m_fontFamilyChoices
= new wxPGChoices(faceNames
);
617 wxString
emptyString(wxEmptyString
);
622 AddPrivateChild( new wxIntProperty( _("Point Size"),
623 wxS("Point Size"),(long)font
.GetPointSize() ) );
625 AddPrivateChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
626 gs_fp_es_family_labels
,gs_fp_es_family_values
,
629 wxString faceName
= font
.GetFaceName();
630 // If font was not in there, add it now
631 if ( faceName
.length() &&
632 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
633 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
635 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"), wxS("Face Name"),
636 *wxPGGlobalVars
->m_fontFamilyChoices
);
638 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
640 AddPrivateChild( p
);
642 AddPrivateChild( new wxEnumProperty(_("Style"), wxS("Style"),
643 gs_fp_es_style_labels
,gs_fp_es_style_values
,
646 AddPrivateChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
647 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,
650 AddPrivateChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
651 font
.GetUnderlined()) );
654 wxFontProperty::~wxFontProperty() { }
656 void wxFontProperty::OnSetValue()
663 m_value
<< *wxNORMAL_FONT
;
667 wxString
wxFontProperty::ValueToString( wxVariant
& value
,
670 return wxPGProperty::ValueToString(value
, argFlags
);
673 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
676 if ( propgrid
->IsMainButtonEvent(event
) )
678 // Update value from last minute changes
679 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
684 data
.SetInitialFont( font
);
685 data
.SetColour(*wxBLACK
);
687 wxFontDialog
dlg(propgrid
, data
);
688 if ( dlg
.ShowModal() == wxID_OK
)
690 propgrid
->EditorsValueWasModified();
693 variant
<< dlg
.GetFontData().GetChosenFont();
694 SetValueInEvent( variant
);
701 void wxFontProperty::RefreshChildren()
703 if ( !GetChildCount() ) return;
706 Item(0)->SetValue( (long)font
.GetPointSize() );
707 Item(1)->SetValue( (long)font
.GetFamily() );
708 Item(2)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
709 Item(3)->SetValue( (long)font
.GetStyle() );
710 Item(4)->SetValue( (long)font
.GetWeight() );
711 Item(5)->SetValue( font
.GetUnderlined() );
714 wxVariant
wxFontProperty::ChildChanged( wxVariant
& thisValue
,
716 wxVariant
& childValue
) const
723 font
.SetPointSize( childValue
.GetLong() );
727 int fam
= childValue
.GetLong();
728 if ( fam
< wxDEFAULT
||
731 font
.SetFamily( fam
);
736 int faceIndex
= childValue
.GetLong();
738 if ( faceIndex
>= 0 )
739 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
741 font
.SetFaceName( faceName
);
745 int st
= childValue
.GetLong();
746 if ( st
!= wxFONTSTYLE_NORMAL
&&
747 st
!= wxFONTSTYLE_SLANT
&&
748 st
!= wxFONTSTYLE_ITALIC
)
749 st
= wxFONTWEIGHT_NORMAL
;
754 int wt
= childValue
.GetLong();
755 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
756 wt
!= wxFONTWEIGHT_LIGHT
&&
757 wt
!= wxFONTWEIGHT_BOLD
)
758 wt
= wxFONTWEIGHT_NORMAL
;
759 font
.SetWeight( wt
);
763 font
.SetUnderlined( childValue
.GetBool() );
766 wxVariant newVariant
;
772 wxSize wxFontProperty::OnMeasureImage() const
774 return wxSize(-1,-1);
777 void wxFontProperty::OnCustomPaint(wxDC& dc,
779 wxPGPaintData& paintData)
782 if ( paintData.m_choiceItem >= 0 )
783 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
785 drawFace = m_value_wxFont.GetFaceName();
787 if ( drawFace.length() )
789 // Draw the background
790 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
791 //dc.SetBrush( *wxWHITE_BRUSH );
792 //dc.SetPen( *wxMEDIUM_GREY_PEN );
793 dc.DrawRectangle( rect );
795 wxFont oldFont = dc.GetFont();
796 wxFont drawFont(oldFont.GetPointSize(),
797 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
798 dc.SetFont(drawFont);
800 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
801 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
807 // No file - just draw a white box
808 dc.SetBrush ( *wxWHITE_BRUSH );
809 dc.DrawRectangle ( rect );
815 // -----------------------------------------------------------------------
816 // wxSystemColourProperty
817 // -----------------------------------------------------------------------
819 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
820 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
822 #include "wx/colordlg.h"
824 //#define wx_cp_es_syscolours_len 25
825 static const wxChar
* gs_cp_es_syscolour_labels
[] = {
828 wxT("ActiveCaption"),
830 wxT("ButtonHighlight"),
839 wxT("HighlightText"),
840 wxT("InactiveBorder"),
841 wxT("InactiveCaption"),
842 wxT("InactiveCaptionText"),
854 static long gs_cp_es_syscolour_values
[] = {
855 wxSYS_COLOUR_APPWORKSPACE
,
856 wxSYS_COLOUR_ACTIVEBORDER
,
857 wxSYS_COLOUR_ACTIVECAPTION
,
858 wxSYS_COLOUR_BTNFACE
,
859 wxSYS_COLOUR_BTNHIGHLIGHT
,
860 wxSYS_COLOUR_BTNSHADOW
,
861 wxSYS_COLOUR_BTNTEXT
,
862 wxSYS_COLOUR_CAPTIONTEXT
,
863 wxSYS_COLOUR_3DDKSHADOW
,
864 wxSYS_COLOUR_3DLIGHT
,
865 wxSYS_COLOUR_BACKGROUND
,
866 wxSYS_COLOUR_GRAYTEXT
,
867 wxSYS_COLOUR_HIGHLIGHT
,
868 wxSYS_COLOUR_HIGHLIGHTTEXT
,
869 wxSYS_COLOUR_INACTIVEBORDER
,
870 wxSYS_COLOUR_INACTIVECAPTION
,
871 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
873 wxSYS_COLOUR_SCROLLBAR
,
875 wxSYS_COLOUR_INFOTEXT
,
877 wxSYS_COLOUR_WINDOWFRAME
,
878 wxSYS_COLOUR_WINDOWTEXT
,
883 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
886 // Class body is in advprops.h
888 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
889 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
892 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
894 wxColourPropertyValue cpv
;
897 cpv
.Init( type
, colour
);
899 cpv
.Init( type
, *wxWHITE
);
901 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
909 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
912 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
913 const wxColourPropertyValue
& value
)
914 : wxEnumProperty( label
,
916 gs_cp_es_syscolour_labels
,
917 gs_cp_es_syscolour_values
,
918 &gs_wxSystemColourProperty_choicesCache
)
921 Init( value
.m_type
, value
.m_colour
);
923 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
927 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
928 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
929 const wxColourPropertyValue
& value
)
930 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
933 Init( value
.m_type
, value
.m_colour
);
935 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
939 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
940 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
941 const wxColour
& value
)
942 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
945 Init( wxPG_COLOUR_CUSTOM
, value
);
947 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
951 wxSystemColourProperty::~wxSystemColourProperty() { }
954 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
959 if ( pVariant
->IsNull() )
960 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
962 if ( pVariant
->GetType() == wxS("wxColourPropertyValue") )
964 wxColourPropertyValue v
;
970 bool variantProcessed
= true;
972 if ( pVariant
->GetType() == wxS("wxColour*") )
974 wxColour
* pCol
= wxStaticCast(pVariant
->GetWxObjectPtr(), wxColour
);
977 else if ( pVariant
->GetType() == wxS("wxColour") )
981 else if ( pVariant
->GetType() == wxArrayInt_VariantType
)
983 // This code is mostly needed for wxPython bindings, which
984 // may offer tuple of integers as colour value.
988 if ( arr
.size() >= 3 )
996 if ( arr
.size() >= 4 )
999 col
= wxColour(r
, g
, b
, a
);
1003 variantProcessed
= false;
1008 variantProcessed
= false;
1011 if ( !variantProcessed
)
1012 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
1014 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
1016 int colInd
= ColToInd(col
);
1017 if ( colInd
!= wxNOT_FOUND
)
1023 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1030 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
1033 size_t i_max
= m_choices
.GetCount();
1035 if ( !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1038 for ( i
=0; i
<i_max
; i
++ )
1040 int ind
= m_choices
[i
].GetValue();
1042 if ( colour
== GetColour(ind
) )
1044 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
1045 GetClassName(),GetLabel().c_str(),
1046 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
1047 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
1054 void wxSystemColourProperty::OnSetValue()
1056 // Convert from generic wxobject ptr to wxPGVariantDataColour
1057 if ( m_value
.GetType() == wxS("wxColour*") )
1059 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
1063 wxColourPropertyValue val
= GetVal(&m_value
);
1065 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
1073 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
1074 val
.m_colour
= GetColour( val
.m_type
);
1076 m_value
= TranslateVal(val
);
1079 int ind
= wxNOT_FOUND
;
1081 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
1083 wxColourPropertyValue cpv
;
1085 wxColour col
= cpv
.m_colour
;
1089 SetValueToUnspecified();
1090 SetIndex(wxNOT_FOUND
);
1094 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
||
1095 (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1097 ind
= GetIndexForValue(cpv
.m_type
);
1101 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
1102 ind
= GetCustomColourIndex();
1112 SetValueToUnspecified();
1113 SetIndex(wxNOT_FOUND
);
1117 ind
= ColToInd(col
);
1119 if ( ind
== wxNOT_FOUND
&&
1120 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1121 ind
= GetCustomColourIndex();
1128 wxColour
wxSystemColourProperty::GetColour( int index
) const
1130 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
1133 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
1135 if ( index
== wxNOT_FOUND
)
1136 return wxString::Format(wxT("(%i,%i,%i)"),
1141 return m_choices
.GetLabel(index
);
1144 wxString
wxSystemColourProperty::ValueToString( wxVariant
& value
,
1145 int argFlags
) const
1147 wxColourPropertyValue val
= GetVal(&value
);
1151 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1153 // GetIndex() only works reliably if wxPG_VALUE_IS_CURRENT flag is set,
1154 // but we should use it whenever possible.
1157 // If custom colour was selected, use invalid index, so that
1158 // ColourToString() will return properly formatted colour text.
1159 if ( index
== GetCustomColourIndex() &&
1160 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1161 index
= wxNOT_FOUND
;
1165 index
= m_choices
.Index(val
.m_type
);
1168 return ColourToString(val
.m_colour
, index
);
1172 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
1174 return wxPG_DEFAULT_IMAGE_SIZE
;
1178 int wxSystemColourProperty::GetCustomColourIndex() const
1180 return m_choices
.GetCount() - 1;
1184 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1186 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1189 wxPropertyGrid
* propgrid
= GetGrid();
1190 wxASSERT( propgrid
);
1192 // Must only occur when user triggers event
1193 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
) )
1196 wxColourPropertyValue val
= GetVal();
1198 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1201 data
.SetChooseFull(true);
1202 data
.SetColour(val
.m_colour
);
1204 for ( i
= 0; i
< 16; i
++)
1206 wxColour
colour(i
*16, i
*16, i
*16);
1207 data
.SetCustomColour(i
, colour
);
1210 wxColourDialog
dialog(propgrid
, &data
);
1211 if ( dialog
.ShowModal() == wxID_OK
)
1213 wxColourData retData
= dialog
.GetColourData();
1214 val
.m_colour
= retData
.GetColour();
1216 variant
= DoTranslateVal(val
);
1218 SetValueInEvent(variant
);
1227 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1230 int type
= m_choices
.GetValue(index
);
1232 if ( type
== wxPG_COLOUR_CUSTOM
)
1234 QueryColourFromUser(variant
);
1238 variant
= TranslateVal( type
, GetColour(type
) );
1244 // Need to do some extra event handling.
1245 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
,
1246 wxWindow
* WXUNUSED(primary
),
1249 bool askColour
= false;
1251 if ( propgrid
->IsMainButtonEvent(event
) )
1255 else if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
1257 if ( GetIndex() == GetCustomColourIndex() &&
1258 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1264 // We need to handle button click in case editor has been
1265 // switched to one that has wxButton as well.
1267 if ( QueryColourFromUser(variant
) )
1273 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1276 virtual void Render( wxDC& dc, const wxRect& rect,
1277 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1278 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1280 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1281 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1283 dc.SetPen(*wxBLACK_PEN);
1285 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1289 const wxArrayInt& values = prop->GetValues();
1290 if ( values.GetChildCount() )
1291 colInd = values[item];
1294 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1296 else if ( !prop->IsValueUnspecified() )
1297 dc.SetBrush( prop->GetVal().m_colour );
1299 dc.SetBrush( *wxWHITE );
1301 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1302 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1303 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1304 imageRect.width, imageRect.height );
1308 text = property->GetValueAsString();
1310 text = property->GetChoiceString(item);
1311 DrawText( dc, rect, imageRect.width, text );
1316 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1318 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1321 return &g_wxPGColourPropertyRenderer;
1322 return wxEnumProperty::GetCellRenderer(column);
1325 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1326 wxPGPaintData
& paintdata
)
1330 if ( paintdata
.m_choiceItem
>= 0 &&
1331 paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1332 (paintdata
.m_choiceItem
!= GetCustomColourIndex() ||
1333 m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1335 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1336 col
= GetColour( colInd
);
1338 else if ( !IsValueUnspecified() )
1340 col
= GetVal().m_colour
;
1346 dc
.DrawRectangle(rect
);
1351 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1354 // Accept colour format "[Name] [(R,G,B)]"
1355 // Name takes precedence.
1357 wxString colourName
;
1360 int ppos
= text
.Find(wxT("("));
1362 if ( ppos
== wxNOT_FOUND
)
1368 colourName
= text
.substr(0, ppos
);
1369 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1372 // Strip spaces from extremities
1373 colourName
.Trim(true);
1374 colourName
.Trim(false);
1375 colourRGB
.Trim(true);
1377 // Validate colourRGB string - (1,1,1) is shortest allowed
1378 if ( colourRGB
.length() < 7 )
1381 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1382 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) &&
1383 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1385 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1387 // This really should not occurr...
1393 QueryColourFromUser(value
);
1397 wxColourPropertyValue val
;
1401 if ( colourName
.length() )
1403 // Try predefined colour first
1404 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1405 if ( res
&& GetIndex() >= 0 )
1407 val
.m_type
= GetIndex();
1408 if ( val
.m_type
< m_choices
.GetCount() )
1409 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1411 // Get proper colour for type.
1412 val
.m_colour
= GetColour(val
.m_type
);
1417 if ( colourRGB
.length() && !done
)
1419 // Then check custom colour.
1420 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1422 int r
= -1, g
= -1, b
= -1;
1423 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1425 if ( r
>= 0 && r
<= 255 &&
1426 g
>= 0 && g
<= 255 &&
1427 b
>= 0 && b
<= 255 )
1429 val
.m_colour
.Set(r
,g
,b
);
1441 value
= DoTranslateVal(val
);
1448 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1450 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1452 int ival
= value
.GetLong();
1454 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1456 // Show custom choice
1457 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1458 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1460 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1462 // Hide custom choice
1463 m_choices
.RemoveAt(GetCustomColourIndex());
1464 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1472 // -----------------------------------------------------------------------
1474 // -----------------------------------------------------------------------
1476 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1496 (const wxChar
*) NULL
1499 static unsigned long gs_cp_es_normcolour_colours
[] = {
1501 wxPG_COLOUR(128,0,0),
1502 wxPG_COLOUR(0,0,128),
1503 wxPG_COLOUR(128,0,128),
1504 wxPG_COLOUR(0,128,128),
1505 wxPG_COLOUR(128,128,128),
1506 wxPG_COLOUR(0,128,0),
1507 wxPG_COLOUR(128,128,0),
1508 wxPG_COLOUR(166,124,81),
1509 wxPG_COLOUR(0,0,255),
1510 wxPG_COLOUR(255,0,255),
1511 wxPG_COLOUR(255,0,0),
1512 wxPG_COLOUR(247,148,28),
1513 wxPG_COLOUR(192,192,192),
1514 wxPG_COLOUR(0,255,0),
1515 wxPG_COLOUR(0,255,255),
1516 wxPG_COLOUR(255,255,0),
1517 wxPG_COLOUR(255,255,255),
1521 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxColourProperty
, wxSystemColourProperty
,
1522 wxColour
, const wxColour
&, TextCtrlAndButton
)
1524 static wxPGChoices gs_wxColourProperty_choicesCache
;
1526 wxColourProperty::wxColourProperty( const wxString
& label
,
1527 const wxString
& name
,
1528 const wxColour
& value
)
1529 : wxSystemColourProperty(label
, name
, gs_cp_es_normcolour_labels
,
1531 &gs_wxColourProperty_choicesCache
, value
)
1535 m_flags
|= wxPG_PROP_TRANSLATE_CUSTOM
;
1538 wxColourProperty::~wxColourProperty()
1542 void wxColourProperty::Init( wxColour colour
)
1549 int ind
= ColToInd(colour
);
1551 ind
= m_choices
.GetCount() - 1;
1555 wxString
wxColourProperty::ValueToString( wxVariant
& value
,
1556 int argFlags
) const
1558 const wxPGEditor
* editor
= GetEditorClass();
1559 if ( editor
!= wxPGEditor_Choice
&&
1560 editor
!= wxPGEditor_ChoiceAndButton
&&
1561 editor
!= wxPGEditor_ComboBox
)
1562 argFlags
|= wxPG_PROPERTY_SPECIFIC
;
1564 return wxSystemColourProperty::ValueToString(value
, argFlags
);
1567 wxColour
wxColourProperty::GetColour( int index
) const
1569 return gs_cp_es_normcolour_colours
[m_choices
.GetValue(index
)];
1572 wxVariant
wxColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1575 variant
<< v
.m_colour
;
1579 // -----------------------------------------------------------------------
1581 // -----------------------------------------------------------------------
1583 #define wxPG_CURSOR_IMAGE_WIDTH 32
1585 #define NUM_CURSORS 28
1587 //#define wx_cp_es_syscursors_len 28
1588 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1600 wxT("Middle Button"),
1606 wxT("Question Arrow"),
1607 wxT("Right Button"),
1608 wxT("Sizing NE-SW"),
1610 wxT("Sizing NW-SE"),
1617 (const wxChar
*) NULL
1620 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1623 wxCURSOR_RIGHT_ARROW
,
1630 wxCURSOR_LEFT_BUTTON
,
1632 wxCURSOR_MIDDLE_BUTTON
,
1634 wxCURSOR_PAINT_BRUSH
,
1636 wxCURSOR_POINT_LEFT
,
1637 wxCURSOR_POINT_RIGHT
,
1638 wxCURSOR_QUESTION_ARROW
,
1639 wxCURSOR_RIGHT_BUTTON
,
1651 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1653 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1655 : wxEnumProperty( label
,
1657 gs_cp_es_syscursors_labels
,
1658 gs_cp_es_syscursors_values
,
1661 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1664 wxCursorProperty::~wxCursorProperty()
1668 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1670 #if wxPG_CAN_DRAW_CURSOR
1671 if ( item
!= -1 && item
< NUM_CURSORS
)
1672 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1679 #if wxPG_CAN_DRAW_CURSOR
1681 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1683 wxPGPaintData
& paintdata
)
1686 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1688 if ( paintdata
.m_choiceItem
>= 0 )
1690 dc
.DrawRectangle( rect
);
1692 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1694 wxStockCursor cursorIndex
=
1695 (wxStockCursor
) gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1698 if ( cursorIndex
== wxCURSOR_NONE
)
1699 cursorIndex
= wxCURSOR_ARROW
;
1701 wxCursor
cursor( cursorIndex
);
1704 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1708 (HICON
)cursor
.GetHandle(),
1713 #if !defined(__WXWINCE__)
1714 DI_COMPAT
| DI_DEFAULTSIZE
|
1725 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1726 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1728 return wxEnumProperty::GetCellRenderer(column);
1732 // -----------------------------------------------------------------------
1733 // wxImageFileProperty
1734 // -----------------------------------------------------------------------
1738 const wxString
& wxPGGetDefaultImageWildcard()
1740 // Form the wildcard, if not done yet
1741 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1746 // TODO: This section may require locking (using global).
1748 wxList
& handlers
= wxImage::GetHandlers();
1750 wxList::iterator node
;
1752 // Let's iterate over the image handler list.
1753 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1754 for ( node
= handlers
.begin(); node
!= handlers
.end(); ++node
)
1756 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1758 wxString ext_lo
= handler
->GetExtension();
1759 wxString ext_up
= ext_lo
.Upper();
1761 str
.append( ext_up
);
1762 str
.append( wxT(" files (*.") );
1763 str
.append( ext_up
);
1764 str
.append( wxT(")|*.") );
1765 str
.append( ext_lo
);
1766 str
.append( wxT("|") );
1769 str
.append ( wxT("All files (*.*)|*.*") );
1771 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1774 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1777 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1779 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1780 const wxString
& value
)
1781 : wxFileProperty(label
,name
,value
)
1783 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1789 wxImageFileProperty::~wxImageFileProperty()
1797 void wxImageFileProperty::OnSetValue()
1799 wxFileProperty::OnSetValue();
1813 wxFileName filename
= GetFileName();
1815 // Create the image thumbnail
1816 if ( filename
.FileExists() )
1818 m_pImage
= new wxImage( filename
.GetFullPath() );
1822 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1824 return wxPG_DEFAULT_IMAGE_SIZE
;
1827 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1831 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1833 // Draw the thumbnail
1835 // Create the bitmap here because required size is not known in OnSetValue().
1838 m_pImage
->Rescale( rect
.width
, rect
.height
);
1839 m_pBitmap
= new wxBitmap( *m_pImage
);
1844 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1848 // No file - just draw a white box
1849 dc
.SetBrush( *wxWHITE_BRUSH
);
1850 dc
.DrawRectangle ( rect
);
1854 #endif // wxUSE_IMAGE
1856 // -----------------------------------------------------------------------
1857 // wxMultiChoiceProperty
1858 // -----------------------------------------------------------------------
1862 #include "wx/choicdlg.h"
1864 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1865 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1867 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1868 const wxString
& name
,
1869 const wxPGChoices
& choices
,
1870 const wxArrayString
& value
)
1871 : wxPGProperty(label
,name
)
1873 m_choices
.Assign(choices
);
1877 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1878 const wxString
& name
,
1879 const wxArrayString
& strings
,
1880 const wxArrayString
& value
)
1881 : wxPGProperty(label
,name
)
1883 m_choices
.Set(strings
);
1887 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1888 const wxString
& name
,
1889 const wxArrayString
& value
)
1890 : wxPGProperty(label
,name
)
1892 wxArrayString strings
;
1893 m_choices
.Set(strings
);
1897 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1901 void wxMultiChoiceProperty::OnSetValue()
1903 GenerateValueAsString(m_value
, &m_display
);
1906 wxString
wxMultiChoiceProperty::ValueToString( wxVariant
& value
,
1907 int argFlags
) const
1909 // If possible, use cached string
1910 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1914 GenerateValueAsString(value
, &s
);
1918 void wxMultiChoiceProperty::GenerateValueAsString( wxVariant
& value
,
1919 wxString
* target
) const
1921 wxArrayString strings
;
1923 if ( value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1924 strings
= value
.GetArrayString();
1926 wxString
& tempStr
= *target
;
1928 unsigned int itemCount
= strings
.size();
1933 tempStr
.append( wxT("\"") );
1935 for ( i
= 0; i
< itemCount
; i
++ )
1937 tempStr
.append( strings
[i
] );
1938 tempStr
.append( wxT("\"") );
1939 if ( i
< (itemCount
-1) )
1940 tempStr
.append ( wxT(" \"") );
1944 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1946 wxVariant variant
= GetValue();
1947 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(variant
);
1950 // Translate values to string indices.
1951 wxArrayInt selections
;
1953 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1955 for ( i
=0; i
<valueArr
.size(); i
++ )
1960 for ( i
=0; i
<valueArr
.size(); i
++ )
1962 int sIndex
= m_choices
.Index(valueArr
[i
]);
1964 selections
.Add(sIndex
);
1971 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1972 wxWindow
* WXUNUSED(primary
),
1975 if ( propgrid
->IsMainButtonEvent(event
) )
1978 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
1980 wxArrayString labels
= m_choices
.GetLabels();
1981 unsigned int choiceCount
;
1983 if ( m_choices
.IsOk() )
1984 choiceCount
= m_choices
.GetCount();
1988 // launch editor dialog
1989 wxMultiChoiceDialog
dlg( propgrid
,
1990 _("Make a selection:"),
1993 choiceCount
?&labels
[0]:NULL
,
1994 wxCHOICEDLG_STYLE
);
1996 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
1998 wxArrayString strings
= useValue
.GetArrayString();
1999 wxArrayString extraStrings
;
2001 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
2003 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
2005 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
2007 wxArrayInt arrInt
= dlg
.GetSelections();
2011 // Strings that were not in list of choices
2012 wxArrayString value
;
2014 // Translate string indices to strings
2017 if ( userStringMode
== 1 )
2019 for (n
=0;n
<extraStrings
.size();n
++)
2020 value
.push_back(extraStrings
[n
]);
2024 for ( i
=0; i
<arrInt
.size(); i
++ )
2025 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
2027 if ( userStringMode
== 2 )
2029 for (n
=0;n
<extraStrings
.size();n
++)
2030 value
.push_back(extraStrings
[n
]);
2033 variant
= WXVARIANT(value
);
2035 SetValueInEvent(variant
);
2043 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
2047 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
2049 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
2050 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
2052 WX_PG_TOKENIZER2_END()
2054 wxVariant
v( WXVARIANT(arr
) );
2060 #endif // wxUSE_CHOICEDLG
2063 // -----------------------------------------------------------------------
2065 // -----------------------------------------------------------------------
2070 #if wxUSE_DATEPICKCTRL
2071 #define dtCtrl DatePickerCtrl
2073 #define dtCtrl TextCtrl
2076 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
2083 wxString
wxDateProperty::ms_defaultDateFormat
;
2086 wxDateProperty::wxDateProperty( const wxString
& label
,
2087 const wxString
& name
,
2088 const wxDateTime
& value
)
2089 : wxPGProperty(label
,name
)
2091 //wxPGRegisterDefaultValueType(wxDateTime)
2093 #if wxUSE_DATEPICKCTRL
2094 wxPGRegisterEditorClass(DatePickerCtrl
);
2096 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
2104 wxDateProperty::~wxDateProperty()
2108 void wxDateProperty::OnSetValue()
2111 // Convert invalid dates to unspecified value
2112 if ( m_value
.GetType() == wxT("datetime") )
2114 if ( !m_value
.GetDateTime().IsValid() )
2119 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
2120 int WXUNUSED(argFlags
) ) const
2124 // FIXME: do we really want to return true from here if only part of the
2125 // string was parsed?
2126 const char* c
= dt
.ParseFormat(text
);
2137 wxString
wxDateProperty::ValueToString( wxVariant
& value
,
2138 int argFlags
) const
2140 const wxChar
* format
= (const wxChar
*) NULL
;
2142 wxDateTime dateTime
= value
.GetDateTime();
2144 if ( !dateTime
.IsValid() )
2145 return wxT("Invalid");
2147 if ( !ms_defaultDateFormat
.length() )
2149 #if wxUSE_DATEPICKCTRL
2150 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
2152 bool showCentury
= true;
2154 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
2157 if ( m_format
.length() &&
2158 !(argFlags
& wxPG_FULL_VALUE
) )
2159 format
= m_format
.c_str();
2161 // Determine default from locale
2162 // NB: This is really simple stuff, but can't figure anything
2163 // better without proper support in wxLocale
2165 format
= ms_defaultDateFormat
.c_str();
2167 return dateTime
.Format(format
);
2170 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
2172 // This code is basicly copied from datectlg.cpp's SetFormat
2177 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
2178 wxString
str(dt
.Format(wxT("%x")));
2180 const wxChar
*p
= str
.c_str();
2184 if (n
== dt
.GetDay())
2186 format
.Append(wxT("%d"));
2189 else if (n
== (int)dt
.GetMonth()+1)
2191 format
.Append(wxT("%m"));
2194 else if (n
== dt
.GetYear())
2196 format
.Append(wxT("%Y"));
2199 else if (n
== (dt
.GetYear() % 100))
2202 format
.Append(wxT("%Y"));
2204 format
.Append(wxT("%y"));
2208 format
.Append(*p
++);
2214 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
2216 if ( name
== wxPG_DATE_FORMAT
)
2218 m_format
= value
.GetString();
2221 else if ( name
== wxPG_DATE_PICKER_STYLE
)
2223 m_dpStyle
= value
.GetLong();
2224 ms_defaultDateFormat
.clear(); // This may need recalculation
2230 #endif // wxUSE_DATETIME
2233 // -----------------------------------------------------------------------
2234 // wxPropertyGridInterface
2235 // -----------------------------------------------------------------------
2237 void wxPropertyGridInterface::InitAllTypeHandlers()
2241 // -----------------------------------------------------------------------
2243 void wxPropertyGridInterface::RegisterAdditionalEditors()
2245 // Register editor classes, if necessary.
2246 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
2247 wxPropertyGrid::RegisterDefaultEditors();
2250 wxPGRegisterEditorClass(SpinCtrl
);
2252 #if wxUSE_DATEPICKCTRL
2253 wxPGRegisterEditorClass(DatePickerCtrl
);
2257 // -----------------------------------------------------------------------
2259 #endif // wxPG_INCLUDE_ADVPROPS
2261 #endif // wxUSE_PROPGRID