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 #include "wx/odcombo.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 // Implement dynamic class for type value.
86 IMPLEMENT_DYNAMIC_CLASS(wxColourPropertyValue
, wxObject
)
88 bool operator == (const wxColourPropertyValue
& a
, const wxColourPropertyValue
& b
)
90 return ( ( a
.m_colour
== b
.m_colour
) && (a
.m_type
== b
.m_type
) );
93 bool operator == (const wxArrayInt
& array1
, const wxArrayInt
& array2
)
95 if ( array1
.size() != array2
.size() )
98 for ( i
=0; i
<array1
.size(); i
++ )
100 if ( array1
[i
] != array2
[i
] )
106 // -----------------------------------------------------------------------
107 // wxSpinCtrl-based property editor
108 // -----------------------------------------------------------------------
114 #define IS_MOTION_SPIN_SUPPORTED 1
116 #define IS_MOTION_SPIN_SUPPORTED 0
119 #if IS_MOTION_SPIN_SUPPORTED
122 // This class implements ability to rapidly change "spin" value
123 // by moving mouse when one of the spin buttons is depressed.
124 class wxPGSpinButton
: public wxSpinButton
127 wxPGSpinButton() : wxSpinButton()
130 m_hasCapture
= false;
133 Connect( wxEVT_LEFT_DOWN
,
134 wxMouseEventHandler(wxPGSpinButton::OnMouseEvent
) );
135 Connect( wxEVT_LEFT_UP
,
136 wxMouseEventHandler(wxPGSpinButton::OnMouseEvent
) );
137 Connect( wxEVT_MOTION
,
138 wxMouseEventHandler(wxPGSpinButton::OnMouseEvent
) );
139 Connect( wxEVT_MOUSE_CAPTURE_LOST
,
140 wxMouseCaptureLostEventHandler(wxPGSpinButton::OnMouseCaptureLost
) );
149 wxPoint m_ptPosition
;
151 // Having a separate spins variable allows us to handle validation etc. for
152 // multiple spin events at once (with quick mouse movements there could be
153 // hundreds of 'spins' being done at once). Technically things like this
154 // should be stored in event (wxSpinEvent in this case), but there probably
155 // isn't anything there that can be reliably reused.
160 // SpinButton seems to be a special for mouse capture, so we may need track
161 // privately whether mouse is actually captured.
172 SetCursor(wxCURSOR_SIZENS
);
181 m_hasCapture
= false;
184 wxWindow
*parent
= GetParent();
186 SetCursor(parent
->GetCursor());
188 SetCursor(wxNullCursor
);
191 void OnMouseEvent(wxMouseEvent
& event
)
193 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
196 m_ptPosition
= event
.GetPosition();
198 else if ( event
.GetEventType() == wxEVT_LEFT_UP
)
203 else if ( event
.GetEventType() == wxEVT_MOTION
)
207 int dy
= m_ptPosition
.y
- event
.GetPosition().y
;
211 m_ptPosition
= event
.GetPosition();
213 wxSpinEvent
evtscroll( (dy
>= 0) ? wxEVT_SCROLL_LINEUP
:
214 wxEVT_SCROLL_LINEDOWN
,
216 evtscroll
.SetEventObject(this);
218 wxASSERT( m_spins
== 1 );
221 GetEventHandler()->ProcessEvent(evtscroll
);
229 void OnMouseCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
235 #endif // IS_MOTION_SPIN_SUPPORTED
238 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(SpinCtrl
,
243 // Trivial destructor.
244 wxPGSpinCtrlEditor::~wxPGSpinCtrlEditor()
249 // Create controls and initialize event handling.
250 wxPGWindowList
wxPGSpinCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
251 const wxPoint
& pos
, const wxSize
& sz
) const
253 const int margin
= 1;
254 wxSize
butSz(18, sz
.y
);
255 wxSize
tcSz(sz
.x
- butSz
.x
- margin
, sz
.y
);
256 wxPoint
butPos(pos
.x
+ tcSz
.x
+ margin
, pos
.y
);
260 #if IS_MOTION_SPIN_SUPPORTED
261 if ( property
->GetAttributeAsLong(wxT("MotionSpin"), 0) )
263 wnd2
= new wxPGSpinButton();
268 wnd2
= new wxSpinButton();
274 wnd2
->Create( propgrid
->GetPanel(), wxPG_SUBID2
, butPos
, butSz
, wxSP_VERTICAL
);
276 wnd2
->SetRange( INT_MIN
, INT_MAX
);
279 // Let's add validator to make sure only numbers can be entered
280 wxTextValidator
validator(wxFILTER_NUMERIC
, &m_tempString
);
282 wxTextCtrl
* wnd1
= (wxTextCtrl
*) wxPGTextCtrlEditor::CreateControls( propgrid
, property
, pos
, tcSz
).m_primary
;
283 wnd1
->SetValidator(validator
);
285 return wxPGWindowList(wnd1
, wnd2
);
288 // Control's events are redirected here
289 bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
290 wxWindow
* wnd
, wxEvent
& event
) const
292 int evtType
= event
.GetEventType();
295 bool bigStep
= false;
297 if ( evtType
== wxEVT_KEY_DOWN
)
299 wxKeyEvent
& keyEvent
= (wxKeyEvent
&)event
;
300 keycode
= keyEvent
.GetKeyCode();
302 if ( keycode
== WXK_UP
)
303 evtType
= wxEVT_SCROLL_LINEUP
;
304 else if ( keycode
== WXK_DOWN
)
305 evtType
= wxEVT_SCROLL_LINEDOWN
;
306 else if ( keycode
== WXK_PAGEUP
)
308 evtType
= wxEVT_SCROLL_LINEUP
;
311 else if ( keycode
== WXK_PAGEDOWN
)
313 evtType
= wxEVT_SCROLL_LINEDOWN
;
318 if ( evtType
== wxEVT_SCROLL_LINEUP
|| evtType
== wxEVT_SCROLL_LINEDOWN
)
320 #if IS_MOTION_SPIN_SUPPORTED
321 if ( property
->GetAttributeAsLong(wxT("MotionSpin"), 0) )
323 wxPGSpinButton
* spinButton
=
324 (wxPGSpinButton
*) propgrid
->GetEditorControlSecondary();
327 spins
= spinButton
->GetSpins();
332 // Can't use wnd since it might be clipper window
333 wxTextCtrl
* tc
= wxDynamicCast(propgrid
->GetEditorControl(), wxTextCtrl
);
338 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
340 int mode
= wxPG_PROPERTY_VALIDATION_SATURATE
;
342 if ( property
->GetAttributeAsLong(wxT("Wrap"), 0) )
343 mode
= wxPG_PROPERTY_VALIDATION_WRAP
;
345 if ( property
->GetValueType() == wxT("double") )
348 double step
= property
->GetAttributeAsDouble(wxT("Step"), 1.0);
351 if ( s
.ToDouble(&v_d
) )
356 step
*= (double) spins
;
358 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_d
+= step
;
362 wxFloatProperty::DoValidation(property
, v_d
, NULL
, mode
);
364 wxPropertyGrid::DoubleToString(s
, v_d
, 6, true, NULL
);
374 wxLongLong_t step
= property
->GetAttributeAsLong(wxT("Step"), 1);
377 if ( s
.ToLongLong(&v_ll
, 10) )
384 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_ll
+= step
;
388 wxIntProperty::DoValidation(property
, v_ll
, NULL
, mode
);
390 s
= wxLongLong(v_ll
).ToString();
400 int ip
= tc
->GetInsertionPoint();
401 int lp
= tc
->GetLastPosition();
403 tc
->SetInsertionPoint(ip
+(tc
->GetLastPosition()-lp
));
409 return wxPGTextCtrlEditor::OnEvent(propgrid
,property
,wnd
,event
);
412 #endif // wxUSE_SPINBTN
415 // -----------------------------------------------------------------------
416 // wxDatePickerCtrl-based property editor
417 // -----------------------------------------------------------------------
419 #if wxUSE_DATEPICKCTRL
422 #include "wx/datectrl.h"
423 #include "wx/dateevt.h"
425 class wxPGDatePickerCtrlEditor
: public wxPGEditor
427 DECLARE_DYNAMIC_CLASS(wxPGDatePickerCtrlEditor
)
429 virtual ~wxPGDatePickerCtrlEditor();
431 wxString
GetName() const;
432 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
433 wxPGProperty
* property
,
435 const wxSize
& size
) const;
436 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const;
437 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
438 wxWindow
* wnd
, wxEvent
& event
) const;
439 virtual bool GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* wnd
) const;
440 virtual void SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const;
444 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(DatePickerCtrl
,
445 wxPGDatePickerCtrlEditor
,
449 wxPGDatePickerCtrlEditor::~wxPGDatePickerCtrlEditor()
453 wxPGWindowList
wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
,
454 wxPGProperty
* property
,
456 const wxSize
& sz
) const
458 wxCHECK_MSG( property
->IsKindOf(CLASSINFO(wxDateProperty
)),
460 wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
462 wxDateProperty
* prop
= wxDynamicCast(property
, wxDateProperty
);
464 // Use two stage creation to allow cleaner display on wxMSW
465 wxDatePickerCtrl
* ctrl
= new wxDatePickerCtrl();
468 wxSize useSz
= wxDefaultSize
;
474 wxDateTime
dateValue(wxInvalidDateTime
);
476 wxVariant value
= prop
->GetValue();
477 if ( value
.GetType() == wxT("datetime") )
478 dateValue
= value
.GetDateTime();
480 ctrl
->Create(propgrid
->GetPanel(),
485 prop
->GetDatePickerStyle() | wxNO_BORDER
);
494 // Copies value from property to control
495 void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty
* property
,
496 wxWindow
* wnd
) const
498 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
499 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
501 wxDateTime
dateValue(wxInvalidDateTime
);
502 wxVariant
v(property
->GetValue());
503 if ( v
.GetType() == wxT("datetime") )
504 dateValue
= v
.GetDateTime();
506 ctrl
->SetValue( dateValue
);
509 // Control's events are redirected here
510 bool wxPGDatePickerCtrlEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propgrid
),
511 wxPGProperty
* WXUNUSED(property
),
512 wxWindow
* WXUNUSED(wnd
),
513 wxEvent
& event
) const
515 if ( event
.GetEventType() == wxEVT_DATE_CHANGED
)
521 bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const
523 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
524 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
526 variant
= ctrl
->GetValue();
531 void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty
* property
,
532 wxWindow
* wnd
) const
534 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
535 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
537 wxDateProperty
* prop
= wxDynamicCast(property
, wxDateProperty
);
541 int datePickerStyle
= prop
->GetDatePickerStyle();
542 if ( datePickerStyle
& wxDP_ALLOWNONE
)
543 ctrl
->SetValue(wxInvalidDateTime
);
547 #endif // wxUSE_DATEPICKCTRL
550 // -----------------------------------------------------------------------
552 // -----------------------------------------------------------------------
554 #include "wx/fontdlg.h"
555 #include "wx/fontenum.h"
557 static const wxChar
* gs_fp_es_family_labels
[] = {
558 wxT("Default"), wxT("Decorative"),
559 wxT("Roman"), wxT("Script"),
560 wxT("Swiss"), wxT("Modern"),
564 static long gs_fp_es_family_values
[] = {
565 wxDEFAULT
, wxDECORATIVE
,
570 static const wxChar
* gs_fp_es_style_labels
[] = {
577 static long gs_fp_es_style_values
[] = {
583 static const wxChar
* gs_fp_es_weight_labels
[] = {
590 static long gs_fp_es_weight_values
[] = {
596 // Class body is in advprops.h
599 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty
,wxPGProperty
,
600 wxFont
,const wxFont
&,TextCtrlAndButton
)
603 wxFontProperty::wxFontProperty( const wxString
& label
, const wxString
& name
,
604 const wxFont
& value
)
605 : wxPGProperty(label
,name
)
607 SetValue(WXVARIANT(value
));
609 // Initialize font family choices list
610 if ( !wxPGGlobalVars
->m_fontFamilyChoices
)
612 wxArrayString faceNames
= wxFontEnumerator::GetFacenames();
616 wxPGGlobalVars
->m_fontFamilyChoices
= new wxPGChoices(faceNames
);
619 wxString
emptyString(wxEmptyString
);
624 AddPrivateChild( new wxIntProperty( _("Point Size"),
625 wxS("Point Size"),(long)font
.GetPointSize() ) );
627 AddPrivateChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
628 gs_fp_es_family_labels
,gs_fp_es_family_values
,
631 wxString faceName
= font
.GetFaceName();
632 // If font was not in there, add it now
633 if ( faceName
.length() &&
634 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
635 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
637 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"), wxS("Face Name"),
638 *wxPGGlobalVars
->m_fontFamilyChoices
);
640 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
642 AddPrivateChild( p
);
644 AddPrivateChild( new wxEnumProperty(_("Style"), wxS("Style"),
645 gs_fp_es_style_labels
,gs_fp_es_style_values
,
648 AddPrivateChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
649 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,
652 AddPrivateChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
653 font
.GetUnderlined()) );
656 wxFontProperty::~wxFontProperty() { }
658 void wxFontProperty::OnSetValue()
665 m_value
<< *wxNORMAL_FONT
;
669 wxString
wxFontProperty::ValueToString( wxVariant
& value
,
672 return wxPGProperty::ValueToString(value
, argFlags
);
675 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
678 if ( propgrid
->IsMainButtonEvent(event
) )
680 // Update value from last minute changes
681 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
686 data
.SetInitialFont( font
);
687 data
.SetColour(*wxBLACK
);
689 wxFontDialog
dlg(propgrid
, data
);
690 if ( dlg
.ShowModal() == wxID_OK
)
692 propgrid
->EditorsValueWasModified();
695 variant
<< dlg
.GetFontData().GetChosenFont();
696 SetValueInEvent( variant
);
703 void wxFontProperty::RefreshChildren()
705 if ( !GetChildCount() ) return;
708 Item(0)->SetValue( (long)font
.GetPointSize() );
709 Item(1)->SetValue( (long)font
.GetFamily() );
710 Item(2)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
711 Item(3)->SetValue( (long)font
.GetStyle() );
712 Item(4)->SetValue( (long)font
.GetWeight() );
713 Item(5)->SetValue( font
.GetUnderlined() );
716 wxVariant
wxFontProperty::ChildChanged( wxVariant
& thisValue
,
718 wxVariant
& childValue
) const
725 font
.SetPointSize( childValue
.GetLong() );
729 int fam
= childValue
.GetLong();
730 if ( fam
< wxDEFAULT
||
733 font
.SetFamily( fam
);
738 int faceIndex
= childValue
.GetLong();
740 if ( faceIndex
>= 0 )
741 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
743 font
.SetFaceName( faceName
);
747 int st
= childValue
.GetLong();
748 if ( st
!= wxFONTSTYLE_NORMAL
&&
749 st
!= wxFONTSTYLE_SLANT
&&
750 st
!= wxFONTSTYLE_ITALIC
)
751 st
= wxFONTWEIGHT_NORMAL
;
756 int wt
= childValue
.GetLong();
757 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
758 wt
!= wxFONTWEIGHT_LIGHT
&&
759 wt
!= wxFONTWEIGHT_BOLD
)
760 wt
= wxFONTWEIGHT_NORMAL
;
761 font
.SetWeight( wt
);
765 font
.SetUnderlined( childValue
.GetBool() );
768 wxVariant newVariant
;
774 wxSize wxFontProperty::OnMeasureImage() const
776 return wxSize(-1,-1);
779 void wxFontProperty::OnCustomPaint(wxDC& dc,
781 wxPGPaintData& paintData)
784 if ( paintData.m_choiceItem >= 0 )
785 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
787 drawFace = m_value_wxFont.GetFaceName();
789 if ( drawFace.length() )
791 // Draw the background
792 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
793 //dc.SetBrush( *wxWHITE_BRUSH );
794 //dc.SetPen( *wxMEDIUM_GREY_PEN );
795 dc.DrawRectangle( rect );
797 wxFont oldFont = dc.GetFont();
798 wxFont drawFont(oldFont.GetPointSize(),
799 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
800 dc.SetFont(drawFont);
802 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
803 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
809 // No file - just draw a white box
810 dc.SetBrush ( *wxWHITE_BRUSH );
811 dc.DrawRectangle ( rect );
817 // -----------------------------------------------------------------------
818 // wxSystemColourProperty
819 // -----------------------------------------------------------------------
821 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
822 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
824 #include "wx/colordlg.h"
826 //#define wx_cp_es_syscolours_len 25
827 static const wxChar
* gs_cp_es_syscolour_labels
[] = {
830 wxT("ActiveCaption"),
832 wxT("ButtonHighlight"),
841 wxT("HighlightText"),
842 wxT("InactiveBorder"),
843 wxT("InactiveCaption"),
844 wxT("InactiveCaptionText"),
856 static long gs_cp_es_syscolour_values
[] = {
857 wxSYS_COLOUR_APPWORKSPACE
,
858 wxSYS_COLOUR_ACTIVEBORDER
,
859 wxSYS_COLOUR_ACTIVECAPTION
,
860 wxSYS_COLOUR_BTNFACE
,
861 wxSYS_COLOUR_BTNHIGHLIGHT
,
862 wxSYS_COLOUR_BTNSHADOW
,
863 wxSYS_COLOUR_BTNTEXT
,
864 wxSYS_COLOUR_CAPTIONTEXT
,
865 wxSYS_COLOUR_3DDKSHADOW
,
866 wxSYS_COLOUR_3DLIGHT
,
867 wxSYS_COLOUR_BACKGROUND
,
868 wxSYS_COLOUR_GRAYTEXT
,
869 wxSYS_COLOUR_HIGHLIGHT
,
870 wxSYS_COLOUR_HIGHLIGHTTEXT
,
871 wxSYS_COLOUR_INACTIVEBORDER
,
872 wxSYS_COLOUR_INACTIVECAPTION
,
873 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
875 wxSYS_COLOUR_SCROLLBAR
,
877 wxSYS_COLOUR_INFOTEXT
,
879 wxSYS_COLOUR_WINDOWFRAME
,
880 wxSYS_COLOUR_WINDOWTEXT
,
885 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
888 // Class body is in advprops.h
890 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
891 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
894 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
896 wxColourPropertyValue cpv
;
899 cpv
.Init( type
, colour
);
901 cpv
.Init( type
, *wxWHITE
);
903 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
911 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
914 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
915 const wxColourPropertyValue
& value
)
916 : wxEnumProperty( label
,
918 gs_cp_es_syscolour_labels
,
919 gs_cp_es_syscolour_values
,
920 &gs_wxSystemColourProperty_choicesCache
)
923 Init( value
.m_type
, value
.m_colour
);
925 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
929 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
930 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
931 const wxColourPropertyValue
& value
)
932 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
935 Init( value
.m_type
, value
.m_colour
);
937 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
941 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
942 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
943 const wxColour
& value
)
944 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
947 Init( wxPG_COLOUR_CUSTOM
, value
);
949 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
953 wxSystemColourProperty::~wxSystemColourProperty() { }
956 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
961 if ( pVariant
->IsNull() )
962 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
964 if ( pVariant
->GetType() == wxS("wxColourPropertyValue") )
966 wxColourPropertyValue v
;
972 bool variantProcessed
= true;
974 if ( pVariant
->GetType() == wxS("wxColour*") )
976 wxColour
* pCol
= wxStaticCast(pVariant
->GetWxObjectPtr(), wxColour
);
979 else if ( pVariant
->GetType() == wxS("wxColour") )
983 else if ( pVariant
->GetType() == wxArrayInt_VariantType
)
985 // This code is mostly needed for wxPython bindings, which
986 // may offer tuple of integers as colour value.
990 if ( arr
.size() >= 3 )
998 if ( arr
.size() >= 4 )
1001 col
= wxColour(r
, g
, b
, a
);
1005 variantProcessed
= false;
1010 variantProcessed
= false;
1013 if ( !variantProcessed
)
1014 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
1016 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
1018 int colInd
= ColToInd(col
);
1019 if ( colInd
!= wxNOT_FOUND
)
1025 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1032 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
1035 size_t i_max
= m_choices
.GetCount();
1037 if ( !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1040 for ( i
=0; i
<i_max
; i
++ )
1042 int ind
= m_choices
[i
].GetValue();
1044 if ( colour
== GetColour(ind
) )
1046 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
1047 GetClassName(),GetLabel().c_str(),
1048 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
1049 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
1056 void wxSystemColourProperty::OnSetValue()
1058 // Convert from generic wxobject ptr to wxPGVariantDataColour
1059 if ( m_value
.GetType() == wxS("wxColour*") )
1061 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
1065 wxColourPropertyValue val
= GetVal(&m_value
);
1067 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
1075 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
1076 val
.m_colour
= GetColour( val
.m_type
);
1078 m_value
= TranslateVal(val
);
1081 int ind
= wxNOT_FOUND
;
1083 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
1085 wxColourPropertyValue cpv
;
1087 wxColour col
= cpv
.m_colour
;
1091 SetValueToUnspecified();
1092 SetIndex(wxNOT_FOUND
);
1096 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
||
1097 (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1099 ind
= GetIndexForValue(cpv
.m_type
);
1103 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
1104 ind
= GetCustomColourIndex();
1114 SetValueToUnspecified();
1115 SetIndex(wxNOT_FOUND
);
1119 ind
= ColToInd(col
);
1121 if ( ind
== wxNOT_FOUND
&&
1122 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1123 ind
= GetCustomColourIndex();
1130 wxColour
wxSystemColourProperty::GetColour( int index
) const
1132 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
1135 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
1137 if ( index
== wxNOT_FOUND
)
1138 return wxString::Format(wxT("(%i,%i,%i)"),
1143 return m_choices
.GetLabel(index
);
1146 wxString
wxSystemColourProperty::ValueToString( wxVariant
& value
,
1147 int argFlags
) const
1149 wxColourPropertyValue val
= GetVal(&value
);
1153 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1155 // GetIndex() only works reliably if wxPG_VALUE_IS_CURRENT flag is set,
1156 // but we should use it whenever possible.
1159 // If custom colour was selected, use invalid index, so that
1160 // ColourToString() will return properly formatted colour text.
1161 if ( index
== GetCustomColourIndex() &&
1162 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1163 index
= wxNOT_FOUND
;
1167 index
= m_choices
.Index(val
.m_type
);
1170 return ColourToString(val
.m_colour
, index
);
1174 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
1176 return wxPG_DEFAULT_IMAGE_SIZE
;
1180 int wxSystemColourProperty::GetCustomColourIndex() const
1182 return m_choices
.GetCount() - 1;
1186 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1188 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1191 wxPropertyGrid
* propgrid
= GetGrid();
1192 wxASSERT( propgrid
);
1194 // Must only occur when user triggers event
1195 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
) )
1198 wxColourPropertyValue val
= GetVal();
1200 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1203 data
.SetChooseFull(true);
1204 data
.SetColour(val
.m_colour
);
1206 for ( i
= 0; i
< 16; i
++)
1208 wxColour
colour(i
*16, i
*16, i
*16);
1209 data
.SetCustomColour(i
, colour
);
1212 wxColourDialog
dialog(propgrid
, &data
);
1213 if ( dialog
.ShowModal() == wxID_OK
)
1215 wxColourData retData
= dialog
.GetColourData();
1216 val
.m_colour
= retData
.GetColour();
1218 variant
= DoTranslateVal(val
);
1220 SetValueInEvent(variant
);
1229 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1232 int type
= m_choices
.GetValue(index
);
1234 if ( type
== wxPG_COLOUR_CUSTOM
)
1236 QueryColourFromUser(variant
);
1240 variant
= TranslateVal( type
, GetColour(type
) );
1246 // Need to do some extra event handling.
1247 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
,
1248 wxWindow
* WXUNUSED(primary
),
1251 bool askColour
= false;
1253 if ( propgrid
->IsMainButtonEvent(event
) )
1255 // We need to handle button click in case editor has been
1256 // switched to one that has wxButton as well.
1259 else if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
1261 // Must override index detection since at this point GetIndex()
1262 // will return old value.
1263 wxOwnerDrawnComboBox
* cb
=
1264 static_cast<wxOwnerDrawnComboBox
*>(propgrid
->GetEditorControl());
1268 int index
= cb
->GetSelection();
1270 if ( index
== GetCustomColourIndex() &&
1271 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1276 if ( askColour
&& !propgrid
->WasValueChangedInEvent() )
1279 if ( QueryColourFromUser(variant
) )
1285 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1288 virtual void Render( wxDC& dc, const wxRect& rect,
1289 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1290 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1292 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1293 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1295 dc.SetPen(*wxBLACK_PEN);
1297 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1301 const wxArrayInt& values = prop->GetValues();
1302 if ( values.GetChildCount() )
1303 colInd = values[item];
1306 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1308 else if ( !prop->IsValueUnspecified() )
1309 dc.SetBrush( prop->GetVal().m_colour );
1311 dc.SetBrush( *wxWHITE );
1313 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1314 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1315 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1316 imageRect.width, imageRect.height );
1320 text = property->GetValueAsString();
1322 text = property->GetChoiceString(item);
1323 DrawText( dc, rect, imageRect.width, text );
1328 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1330 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1333 return &g_wxPGColourPropertyRenderer;
1334 return wxEnumProperty::GetCellRenderer(column);
1337 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1338 wxPGPaintData
& paintdata
)
1342 if ( paintdata
.m_choiceItem
>= 0 &&
1343 paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1344 (paintdata
.m_choiceItem
!= GetCustomColourIndex() ||
1345 m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1347 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1348 col
= GetColour( colInd
);
1350 else if ( !IsValueUnspecified() )
1352 col
= GetVal().m_colour
;
1358 dc
.DrawRectangle(rect
);
1363 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1366 // Accept colour format "[Name] [(R,G,B)]"
1367 // Name takes precedence.
1369 wxString colourName
;
1372 int ppos
= text
.Find(wxT("("));
1374 if ( ppos
== wxNOT_FOUND
)
1380 colourName
= text
.substr(0, ppos
);
1381 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1384 // Strip spaces from extremities
1385 colourName
.Trim(true);
1386 colourName
.Trim(false);
1387 colourRGB
.Trim(true);
1389 // Validate colourRGB string - (1,1,1) is shortest allowed
1390 if ( colourRGB
.length() < 7 )
1393 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1394 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) &&
1395 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1397 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1399 // This really should not occurr...
1405 QueryColourFromUser(value
);
1409 wxColourPropertyValue val
;
1413 if ( colourName
.length() )
1415 // Try predefined colour first
1416 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1417 if ( res
&& GetIndex() >= 0 )
1419 val
.m_type
= GetIndex();
1420 if ( val
.m_type
< m_choices
.GetCount() )
1421 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1423 // Get proper colour for type.
1424 val
.m_colour
= GetColour(val
.m_type
);
1429 if ( colourRGB
.length() && !done
)
1431 // Then check custom colour.
1432 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1434 int r
= -1, g
= -1, b
= -1;
1435 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1437 if ( r
>= 0 && r
<= 255 &&
1438 g
>= 0 && g
<= 255 &&
1439 b
>= 0 && b
<= 255 )
1441 val
.m_colour
.Set(r
,g
,b
);
1453 value
= DoTranslateVal(val
);
1460 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1462 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1464 int ival
= value
.GetLong();
1466 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1468 // Show custom choice
1469 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1470 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1472 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1474 // Hide custom choice
1475 m_choices
.RemoveAt(GetCustomColourIndex());
1476 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1484 // -----------------------------------------------------------------------
1486 // -----------------------------------------------------------------------
1488 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1508 (const wxChar
*) NULL
1511 static unsigned long gs_cp_es_normcolour_colours
[] = {
1513 wxPG_COLOUR(128,0,0),
1514 wxPG_COLOUR(0,0,128),
1515 wxPG_COLOUR(128,0,128),
1516 wxPG_COLOUR(0,128,128),
1517 wxPG_COLOUR(128,128,128),
1518 wxPG_COLOUR(0,128,0),
1519 wxPG_COLOUR(128,128,0),
1520 wxPG_COLOUR(166,124,81),
1521 wxPG_COLOUR(0,0,255),
1522 wxPG_COLOUR(255,0,255),
1523 wxPG_COLOUR(255,0,0),
1524 wxPG_COLOUR(247,148,28),
1525 wxPG_COLOUR(192,192,192),
1526 wxPG_COLOUR(0,255,0),
1527 wxPG_COLOUR(0,255,255),
1528 wxPG_COLOUR(255,255,0),
1529 wxPG_COLOUR(255,255,255),
1533 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxColourProperty
, wxSystemColourProperty
,
1534 wxColour
, const wxColour
&, TextCtrlAndButton
)
1536 static wxPGChoices gs_wxColourProperty_choicesCache
;
1538 wxColourProperty::wxColourProperty( const wxString
& label
,
1539 const wxString
& name
,
1540 const wxColour
& value
)
1541 : wxSystemColourProperty(label
, name
, gs_cp_es_normcolour_labels
,
1543 &gs_wxColourProperty_choicesCache
, value
)
1547 m_flags
|= wxPG_PROP_TRANSLATE_CUSTOM
;
1550 wxColourProperty::~wxColourProperty()
1554 void wxColourProperty::Init( wxColour colour
)
1561 int ind
= ColToInd(colour
);
1563 ind
= m_choices
.GetCount() - 1;
1567 wxString
wxColourProperty::ValueToString( wxVariant
& value
,
1568 int argFlags
) const
1570 const wxPGEditor
* editor
= GetEditorClass();
1571 if ( editor
!= wxPGEditor_Choice
&&
1572 editor
!= wxPGEditor_ChoiceAndButton
&&
1573 editor
!= wxPGEditor_ComboBox
)
1574 argFlags
|= wxPG_PROPERTY_SPECIFIC
;
1576 return wxSystemColourProperty::ValueToString(value
, argFlags
);
1579 wxColour
wxColourProperty::GetColour( int index
) const
1581 return gs_cp_es_normcolour_colours
[m_choices
.GetValue(index
)];
1584 wxVariant
wxColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1587 variant
<< v
.m_colour
;
1591 // -----------------------------------------------------------------------
1593 // -----------------------------------------------------------------------
1595 #define wxPG_CURSOR_IMAGE_WIDTH 32
1597 #define NUM_CURSORS 28
1599 //#define wx_cp_es_syscursors_len 28
1600 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1612 wxT("Middle Button"),
1618 wxT("Question Arrow"),
1619 wxT("Right Button"),
1620 wxT("Sizing NE-SW"),
1622 wxT("Sizing NW-SE"),
1629 (const wxChar
*) NULL
1632 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1635 wxCURSOR_RIGHT_ARROW
,
1642 wxCURSOR_LEFT_BUTTON
,
1644 wxCURSOR_MIDDLE_BUTTON
,
1646 wxCURSOR_PAINT_BRUSH
,
1648 wxCURSOR_POINT_LEFT
,
1649 wxCURSOR_POINT_RIGHT
,
1650 wxCURSOR_QUESTION_ARROW
,
1651 wxCURSOR_RIGHT_BUTTON
,
1663 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1665 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1667 : wxEnumProperty( label
,
1669 gs_cp_es_syscursors_labels
,
1670 gs_cp_es_syscursors_values
,
1673 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1676 wxCursorProperty::~wxCursorProperty()
1680 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1682 #if wxPG_CAN_DRAW_CURSOR
1683 if ( item
!= -1 && item
< NUM_CURSORS
)
1684 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1691 #if wxPG_CAN_DRAW_CURSOR
1693 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1695 wxPGPaintData
& paintdata
)
1698 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1700 if ( paintdata
.m_choiceItem
>= 0 )
1702 dc
.DrawRectangle( rect
);
1704 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1706 wxStockCursor cursorIndex
=
1707 (wxStockCursor
) gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1710 if ( cursorIndex
== wxCURSOR_NONE
)
1711 cursorIndex
= wxCURSOR_ARROW
;
1713 wxCursor
cursor( cursorIndex
);
1716 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1720 (HICON
)cursor
.GetHandle(),
1725 #if !defined(__WXWINCE__)
1726 DI_COMPAT
| DI_DEFAULTSIZE
|
1737 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1738 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1740 return wxEnumProperty::GetCellRenderer(column);
1744 // -----------------------------------------------------------------------
1745 // wxImageFileProperty
1746 // -----------------------------------------------------------------------
1750 const wxString
& wxPGGetDefaultImageWildcard()
1752 // Form the wildcard, if not done yet
1753 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1758 // TODO: This section may require locking (using global).
1760 wxList
& handlers
= wxImage::GetHandlers();
1762 wxList::iterator node
;
1764 // Let's iterate over the image handler list.
1765 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1766 for ( node
= handlers
.begin(); node
!= handlers
.end(); ++node
)
1768 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1770 wxString ext_lo
= handler
->GetExtension();
1771 wxString ext_up
= ext_lo
.Upper();
1773 str
.append( ext_up
);
1774 str
.append( wxT(" files (*.") );
1775 str
.append( ext_up
);
1776 str
.append( wxT(")|*.") );
1777 str
.append( ext_lo
);
1778 str
.append( wxT("|") );
1781 str
.append ( wxT("All files (*.*)|*.*") );
1783 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1786 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1789 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1791 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1792 const wxString
& value
)
1793 : wxFileProperty(label
,name
,value
)
1795 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1801 wxImageFileProperty::~wxImageFileProperty()
1809 void wxImageFileProperty::OnSetValue()
1811 wxFileProperty::OnSetValue();
1825 wxFileName filename
= GetFileName();
1827 // Create the image thumbnail
1828 if ( filename
.FileExists() )
1830 m_pImage
= new wxImage( filename
.GetFullPath() );
1834 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1836 return wxPG_DEFAULT_IMAGE_SIZE
;
1839 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1843 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1845 // Draw the thumbnail
1847 // Create the bitmap here because required size is not known in OnSetValue().
1850 m_pImage
->Rescale( rect
.width
, rect
.height
);
1851 m_pBitmap
= new wxBitmap( *m_pImage
);
1856 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1860 // No file - just draw a white box
1861 dc
.SetBrush( *wxWHITE_BRUSH
);
1862 dc
.DrawRectangle ( rect
);
1866 #endif // wxUSE_IMAGE
1868 // -----------------------------------------------------------------------
1869 // wxMultiChoiceProperty
1870 // -----------------------------------------------------------------------
1874 #include "wx/choicdlg.h"
1876 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1877 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1879 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1880 const wxString
& name
,
1881 const wxPGChoices
& choices
,
1882 const wxArrayString
& value
)
1883 : wxPGProperty(label
,name
)
1885 m_choices
.Assign(choices
);
1889 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1890 const wxString
& name
,
1891 const wxArrayString
& strings
,
1892 const wxArrayString
& value
)
1893 : wxPGProperty(label
,name
)
1895 m_choices
.Set(strings
);
1899 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1900 const wxString
& name
,
1901 const wxArrayString
& value
)
1902 : wxPGProperty(label
,name
)
1904 wxArrayString strings
;
1905 m_choices
.Set(strings
);
1909 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1913 void wxMultiChoiceProperty::OnSetValue()
1915 GenerateValueAsString(m_value
, &m_display
);
1918 wxString
wxMultiChoiceProperty::ValueToString( wxVariant
& value
,
1919 int argFlags
) const
1921 // If possible, use cached string
1922 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1926 GenerateValueAsString(value
, &s
);
1930 void wxMultiChoiceProperty::GenerateValueAsString( wxVariant
& value
,
1931 wxString
* target
) const
1933 wxArrayString strings
;
1935 if ( value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1936 strings
= value
.GetArrayString();
1938 wxString
& tempStr
= *target
;
1940 unsigned int itemCount
= strings
.size();
1945 tempStr
.append( wxT("\"") );
1947 for ( i
= 0; i
< itemCount
; i
++ )
1949 tempStr
.append( strings
[i
] );
1950 tempStr
.append( wxT("\"") );
1951 if ( i
< (itemCount
-1) )
1952 tempStr
.append ( wxT(" \"") );
1956 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1958 wxVariant variant
= GetValue();
1959 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(variant
);
1962 // Translate values to string indices.
1963 wxArrayInt selections
;
1965 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1967 for ( i
=0; i
<valueArr
.size(); i
++ )
1972 for ( i
=0; i
<valueArr
.size(); i
++ )
1974 int sIndex
= m_choices
.Index(valueArr
[i
]);
1976 selections
.Add(sIndex
);
1983 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1984 wxWindow
* WXUNUSED(primary
),
1987 if ( propgrid
->IsMainButtonEvent(event
) )
1990 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
1992 wxArrayString labels
= m_choices
.GetLabels();
1993 unsigned int choiceCount
;
1995 if ( m_choices
.IsOk() )
1996 choiceCount
= m_choices
.GetCount();
2000 // launch editor dialog
2001 wxMultiChoiceDialog
dlg( propgrid
,
2002 _("Make a selection:"),
2005 choiceCount
?&labels
[0]:NULL
,
2006 wxCHOICEDLG_STYLE
);
2008 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
2010 wxArrayString strings
= useValue
.GetArrayString();
2011 wxArrayString extraStrings
;
2013 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
2015 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
2017 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
2019 wxArrayInt arrInt
= dlg
.GetSelections();
2023 // Strings that were not in list of choices
2024 wxArrayString value
;
2026 // Translate string indices to strings
2029 if ( userStringMode
== 1 )
2031 for (n
=0;n
<extraStrings
.size();n
++)
2032 value
.push_back(extraStrings
[n
]);
2036 for ( i
=0; i
<arrInt
.size(); i
++ )
2037 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
2039 if ( userStringMode
== 2 )
2041 for (n
=0;n
<extraStrings
.size();n
++)
2042 value
.push_back(extraStrings
[n
]);
2045 variant
= WXVARIANT(value
);
2047 SetValueInEvent(variant
);
2055 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
2059 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
2061 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
2062 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
2064 WX_PG_TOKENIZER2_END()
2066 wxVariant
v( WXVARIANT(arr
) );
2072 #endif // wxUSE_CHOICEDLG
2075 // -----------------------------------------------------------------------
2077 // -----------------------------------------------------------------------
2082 #if wxUSE_DATEPICKCTRL
2083 #define dtCtrl DatePickerCtrl
2085 #define dtCtrl TextCtrl
2088 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
2095 wxString
wxDateProperty::ms_defaultDateFormat
;
2098 wxDateProperty::wxDateProperty( const wxString
& label
,
2099 const wxString
& name
,
2100 const wxDateTime
& value
)
2101 : wxPGProperty(label
,name
)
2103 //wxPGRegisterDefaultValueType(wxDateTime)
2105 #if wxUSE_DATEPICKCTRL
2106 wxPGRegisterEditorClass(DatePickerCtrl
);
2108 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
2116 wxDateProperty::~wxDateProperty()
2120 void wxDateProperty::OnSetValue()
2123 // Convert invalid dates to unspecified value
2124 if ( m_value
.GetType() == wxT("datetime") )
2126 if ( !m_value
.GetDateTime().IsValid() )
2131 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
2132 int WXUNUSED(argFlags
) ) const
2136 // FIXME: do we really want to return true from here if only part of the
2137 // string was parsed?
2138 const char* c
= dt
.ParseFormat(text
);
2149 wxString
wxDateProperty::ValueToString( wxVariant
& value
,
2150 int argFlags
) const
2152 const wxChar
* format
= (const wxChar
*) NULL
;
2154 wxDateTime dateTime
= value
.GetDateTime();
2156 if ( !dateTime
.IsValid() )
2157 return wxT("Invalid");
2159 if ( !ms_defaultDateFormat
.length() )
2161 #if wxUSE_DATEPICKCTRL
2162 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
2164 bool showCentury
= true;
2166 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
2169 if ( m_format
.length() &&
2170 !(argFlags
& wxPG_FULL_VALUE
) )
2171 format
= m_format
.c_str();
2173 // Determine default from locale
2174 // NB: This is really simple stuff, but can't figure anything
2175 // better without proper support in wxLocale
2177 format
= ms_defaultDateFormat
.c_str();
2179 return dateTime
.Format(format
);
2182 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
2184 // This code is basicly copied from datectlg.cpp's SetFormat
2189 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
2190 wxString
str(dt
.Format(wxT("%x")));
2192 const wxChar
*p
= str
.c_str();
2196 if (n
== dt
.GetDay())
2198 format
.Append(wxT("%d"));
2201 else if (n
== (int)dt
.GetMonth()+1)
2203 format
.Append(wxT("%m"));
2206 else if (n
== dt
.GetYear())
2208 format
.Append(wxT("%Y"));
2211 else if (n
== (dt
.GetYear() % 100))
2214 format
.Append(wxT("%Y"));
2216 format
.Append(wxT("%y"));
2220 format
.Append(*p
++);
2226 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
2228 if ( name
== wxPG_DATE_FORMAT
)
2230 m_format
= value
.GetString();
2233 else if ( name
== wxPG_DATE_PICKER_STYLE
)
2235 m_dpStyle
= value
.GetLong();
2236 ms_defaultDateFormat
.clear(); // This may need recalculation
2242 #endif // wxUSE_DATETIME
2245 // -----------------------------------------------------------------------
2246 // wxPropertyGridInterface
2247 // -----------------------------------------------------------------------
2249 void wxPropertyGridInterface::InitAllTypeHandlers()
2253 // -----------------------------------------------------------------------
2255 void wxPropertyGridInterface::RegisterAdditionalEditors()
2257 // Register editor classes, if necessary.
2258 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
2259 wxPropertyGrid::RegisterDefaultEditors();
2262 wxPGRegisterEditorClass(SpinCtrl
);
2264 #if wxUSE_DATEPICKCTRL
2265 wxPGRegisterEditorClass(DatePickerCtrl
);
2269 // -----------------------------------------------------------------------
2271 #endif // wxPG_INCLUDE_ADVPROPS
2273 #endif // wxUSE_PROPGRID