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 licence
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 // Destructor. It is useful to reset the global pointer in it.
244 wxPGSpinCtrlEditor::~wxPGSpinCtrlEditor()
246 wxPG_EDITOR(SpinCtrl
) = NULL
;
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 wxWindow
* wnd1
= wxPGTextCtrlEditor::CreateControls(propgrid
, property
, pos
, tcSz
).m_primary
;
281 // Let's add validator to make sure only numbers can be entered
282 wxTextValidator
validator(wxFILTER_NUMERIC
, &m_tempString
);
283 wnd1
->SetValidator(validator
);
286 return wxPGWindowList(wnd1
, wnd2
);
289 // Control's events are redirected here
290 bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
291 wxWindow
* wnd
, wxEvent
& event
) const
293 int evtType
= event
.GetEventType();
296 bool bigStep
= false;
298 if ( evtType
== wxEVT_KEY_DOWN
)
300 wxKeyEvent
& keyEvent
= (wxKeyEvent
&)event
;
301 keycode
= keyEvent
.GetKeyCode();
303 if ( keycode
== WXK_UP
)
304 evtType
= wxEVT_SCROLL_LINEUP
;
305 else if ( keycode
== WXK_DOWN
)
306 evtType
= wxEVT_SCROLL_LINEDOWN
;
307 else if ( keycode
== WXK_PAGEUP
)
309 evtType
= wxEVT_SCROLL_LINEUP
;
312 else if ( keycode
== WXK_PAGEDOWN
)
314 evtType
= wxEVT_SCROLL_LINEDOWN
;
319 if ( evtType
== wxEVT_SCROLL_LINEUP
|| evtType
== wxEVT_SCROLL_LINEDOWN
)
321 #if IS_MOTION_SPIN_SUPPORTED
322 if ( property
->GetAttributeAsLong(wxT("MotionSpin"), 0) )
324 wxPGSpinButton
* spinButton
=
325 (wxPGSpinButton
*) propgrid
->GetEditorControlSecondary();
328 spins
= spinButton
->GetSpins();
333 // Can't use wnd since it might be clipper window
334 wxTextCtrl
* tc
= wxDynamicCast(propgrid
->GetEditorControl(), wxTextCtrl
);
339 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
341 int mode
= wxPG_PROPERTY_VALIDATION_SATURATE
;
343 if ( property
->GetAttributeAsLong(wxT("Wrap"), 0) )
344 mode
= wxPG_PROPERTY_VALIDATION_WRAP
;
346 if ( property
->GetValueType() == wxT("double") )
349 double step
= property
->GetAttributeAsDouble(wxT("Step"), 1.0);
352 if ( s
.ToDouble(&v_d
) )
357 step
*= (double) spins
;
359 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_d
+= step
;
363 wxFloatProperty::DoValidation(property
, v_d
, NULL
, mode
);
365 wxPropertyGrid::DoubleToString(s
, v_d
, 6, true, NULL
);
375 wxLongLong_t step
= property
->GetAttributeAsLong(wxT("Step"), 1);
378 if ( s
.ToLongLong(&v_ll
, 10) )
385 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_ll
+= step
;
389 wxIntProperty::DoValidation(property
, v_ll
, NULL
, mode
);
391 s
= wxLongLong(v_ll
).ToString();
401 int ip
= tc
->GetInsertionPoint();
402 int lp
= tc
->GetLastPosition();
404 tc
->SetInsertionPoint(ip
+(tc
->GetLastPosition()-lp
));
410 return wxPGTextCtrlEditor::OnEvent(propgrid
,property
,wnd
,event
);
413 #endif // wxUSE_SPINBTN
416 // -----------------------------------------------------------------------
417 // wxDatePickerCtrl-based property editor
418 // -----------------------------------------------------------------------
420 #if wxUSE_DATEPICKCTRL
423 #include "wx/datectrl.h"
424 #include "wx/dateevt.h"
426 class wxPGDatePickerCtrlEditor
: public wxPGEditor
428 DECLARE_DYNAMIC_CLASS(wxPGDatePickerCtrlEditor
)
430 virtual ~wxPGDatePickerCtrlEditor();
432 wxString
GetName() const;
433 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
434 wxPGProperty
* property
,
436 const wxSize
& size
) const;
437 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const;
438 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
439 wxWindow
* wnd
, wxEvent
& event
) const;
440 virtual bool GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* wnd
) const;
441 virtual void SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const;
445 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(DatePickerCtrl
,
446 wxPGDatePickerCtrlEditor
,
450 wxPGDatePickerCtrlEditor::~wxPGDatePickerCtrlEditor()
452 wxPG_EDITOR(DatePickerCtrl
) = NULL
;
455 wxPGWindowList
wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
,
456 wxPGProperty
* property
,
458 const wxSize
& sz
) const
460 wxCHECK_MSG( wxDynamicCast(property
, wxDateProperty
),
462 wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
464 wxDateProperty
* prop
= wxDynamicCast(property
, wxDateProperty
);
466 // Use two stage creation to allow cleaner display on wxMSW
467 wxDatePickerCtrl
* ctrl
= new wxDatePickerCtrl();
470 wxSize useSz
= wxDefaultSize
;
476 wxDateTime
dateValue(wxInvalidDateTime
);
478 wxVariant value
= prop
->GetValue();
479 if ( value
.GetType() == wxT("datetime") )
480 dateValue
= value
.GetDateTime();
482 ctrl
->Create(propgrid
->GetPanel(),
487 prop
->GetDatePickerStyle() | wxNO_BORDER
);
496 // Copies value from property to control
497 void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty
* property
,
498 wxWindow
* wnd
) const
500 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
501 wxASSERT( wxDynamicCast(ctrl
, wxDatePickerCtrl
) );
503 wxDateTime
dateValue(wxInvalidDateTime
);
504 wxVariant
v(property
->GetValue());
505 if ( v
.GetType() == wxT("datetime") )
506 dateValue
= v
.GetDateTime();
508 ctrl
->SetValue( dateValue
);
511 // Control's events are redirected here
512 bool wxPGDatePickerCtrlEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propgrid
),
513 wxPGProperty
* WXUNUSED(property
),
514 wxWindow
* WXUNUSED(wnd
),
515 wxEvent
& event
) const
517 if ( event
.GetEventType() == wxEVT_DATE_CHANGED
)
523 bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const
525 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
526 wxASSERT( wxDynamicCast(ctrl
, wxDatePickerCtrl
) );
528 variant
= ctrl
->GetValue();
533 void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty
* property
,
534 wxWindow
* wnd
) const
536 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
537 wxASSERT( wxDynamicCast(ctrl
, wxDatePickerCtrl
) );
539 wxDateProperty
* prop
= wxDynamicCast(property
, wxDateProperty
);
543 int datePickerStyle
= prop
->GetDatePickerStyle();
544 if ( datePickerStyle
& wxDP_ALLOWNONE
)
545 ctrl
->SetValue(wxInvalidDateTime
);
549 #endif // wxUSE_DATEPICKCTRL
552 // -----------------------------------------------------------------------
554 // -----------------------------------------------------------------------
556 #include "wx/fontdlg.h"
557 #include "wx/fontenum.h"
560 // NB: Do not use wxS here since unlike wxT it doesn't translate to wxChar*
563 static const wxChar
* const gs_fp_es_family_labels
[] = {
564 wxT("Default"), wxT("Decorative"),
565 wxT("Roman"), wxT("Script"),
566 wxT("Swiss"), wxT("Modern"),
567 wxT("Teletype"), wxT("Unknown"),
571 static const long gs_fp_es_family_values
[] = {
572 wxFONTFAMILY_DEFAULT
, wxFONTFAMILY_DECORATIVE
,
573 wxFONTFAMILY_ROMAN
, wxFONTFAMILY_SCRIPT
,
574 wxFONTFAMILY_SWISS
, wxFONTFAMILY_MODERN
,
575 wxFONTFAMILY_TELETYPE
, wxFONTFAMILY_UNKNOWN
578 static const wxChar
* const gs_fp_es_style_labels
[] = {
585 static const long gs_fp_es_style_values
[] = {
591 static const wxChar
* const gs_fp_es_weight_labels
[] = {
598 static const long gs_fp_es_weight_values
[] = {
604 // Class body is in advprops.h
607 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty
,wxPGProperty
,
608 wxFont
,const wxFont
&,TextCtrlAndButton
)
611 wxFontProperty::wxFontProperty( const wxString
& label
, const wxString
& name
,
612 const wxFont
& value
)
613 : wxPGProperty(label
,name
)
615 SetValue(WXVARIANT(value
));
617 // Initialize font family choices list
618 if ( !wxPGGlobalVars
->m_fontFamilyChoices
)
620 wxArrayString faceNames
= wxFontEnumerator::GetFacenames();
624 wxPGGlobalVars
->m_fontFamilyChoices
= new wxPGChoices(faceNames
);
627 wxString
emptyString(wxEmptyString
);
632 AddPrivateChild( new wxIntProperty( _("Point Size"),
633 wxS("Point Size"),(long)font
.GetPointSize() ) );
635 wxString faceName
= font
.GetFaceName();
636 // If font was not in there, add it now
637 if ( !faceName
.empty() &&
638 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
639 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
641 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"), wxS("Face Name"),
642 *wxPGGlobalVars
->m_fontFamilyChoices
);
644 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
646 AddPrivateChild( p
);
648 AddPrivateChild( new wxEnumProperty(_("Style"), wxS("Style"),
649 gs_fp_es_style_labels
,gs_fp_es_style_values
,
652 AddPrivateChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
653 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,
656 AddPrivateChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
657 font
.GetUnderlined()) );
659 AddPrivateChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
660 gs_fp_es_family_labels
,gs_fp_es_family_values
,
664 wxFontProperty::~wxFontProperty() { }
666 void wxFontProperty::OnSetValue()
673 m_value
<< *wxNORMAL_FONT
;
677 wxString
wxFontProperty::ValueToString( wxVariant
& value
,
680 return wxPGProperty::ValueToString(value
, argFlags
);
683 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
686 if ( propgrid
->IsMainButtonEvent(event
) )
688 // Update value from last minute changes
689 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
694 if ( useValue
.GetType() == wxS("wxFont") )
697 data
.SetInitialFont( font
);
698 data
.SetColour(*wxBLACK
);
700 wxFontDialog
dlg(propgrid
, data
);
701 if ( dlg
.ShowModal() == wxID_OK
)
703 propgrid
->EditorsValueWasModified();
706 variant
<< dlg
.GetFontData().GetChosenFont();
707 SetValueInEvent( variant
);
714 void wxFontProperty::RefreshChildren()
716 if ( !GetChildCount() ) return;
719 Item(0)->SetValue( (long)font
.GetPointSize() );
720 Item(1)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
721 Item(2)->SetValue( (long)font
.GetStyle() );
722 Item(3)->SetValue( (long)font
.GetWeight() );
723 Item(4)->SetValue( font
.GetUnderlined() );
724 Item(5)->SetValue( (long)font
.GetFamily() );
727 wxVariant
wxFontProperty::ChildChanged( wxVariant
& thisValue
,
729 wxVariant
& childValue
) const
736 font
.SetPointSize( childValue
.GetLong() );
741 int faceIndex
= childValue
.GetLong();
743 if ( faceIndex
>= 0 )
744 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
746 font
.SetFaceName( faceName
);
750 int st
= childValue
.GetLong();
751 if ( st
!= wxFONTSTYLE_NORMAL
&&
752 st
!= wxFONTSTYLE_SLANT
&&
753 st
!= wxFONTSTYLE_ITALIC
)
754 st
= wxFONTWEIGHT_NORMAL
;
759 int wt
= childValue
.GetLong();
760 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
761 wt
!= wxFONTWEIGHT_LIGHT
&&
762 wt
!= wxFONTWEIGHT_BOLD
)
763 wt
= wxFONTWEIGHT_NORMAL
;
764 font
.SetWeight( wt
);
768 font
.SetUnderlined( childValue
.GetBool() );
772 int fam
= childValue
.GetLong();
773 if ( fam
< wxDEFAULT
||
776 font
.SetFamily( fam
);
779 wxVariant newVariant
;
785 wxSize wxFontProperty::OnMeasureImage() const
787 return wxSize(-1,-1);
790 void wxFontProperty::OnCustomPaint(wxDC& dc,
792 wxPGPaintData& paintData)
795 if ( paintData.m_choiceItem >= 0 )
796 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
798 drawFace = m_value_wxFont.GetFaceName();
800 if ( !drawFace.empty() )
802 // Draw the background
803 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
804 //dc.SetBrush( *wxWHITE_BRUSH );
805 //dc.SetPen( *wxMEDIUM_GREY_PEN );
806 dc.DrawRectangle( rect );
808 wxFont oldFont = dc.GetFont();
809 wxFont drawFont(oldFont.GetPointSize(),
810 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
811 dc.SetFont(drawFont);
813 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
814 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
820 // No file - just draw a white box
821 dc.SetBrush ( *wxWHITE_BRUSH );
822 dc.DrawRectangle ( rect );
828 // -----------------------------------------------------------------------
829 // wxSystemColourProperty
830 // -----------------------------------------------------------------------
832 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
833 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
835 #include "wx/colordlg.h"
837 //#define wx_cp_es_syscolours_len 25
838 static const wxChar
* const gs_cp_es_syscolour_labels
[] = {
841 wxT("ActiveCaption"),
843 wxT("ButtonHighlight"),
852 wxT("HighlightText"),
853 wxT("InactiveBorder"),
854 wxT("InactiveCaption"),
855 wxT("InactiveCaptionText"),
867 static const long gs_cp_es_syscolour_values
[] = {
868 wxSYS_COLOUR_APPWORKSPACE
,
869 wxSYS_COLOUR_ACTIVEBORDER
,
870 wxSYS_COLOUR_ACTIVECAPTION
,
871 wxSYS_COLOUR_BTNFACE
,
872 wxSYS_COLOUR_BTNHIGHLIGHT
,
873 wxSYS_COLOUR_BTNSHADOW
,
874 wxSYS_COLOUR_BTNTEXT
,
875 wxSYS_COLOUR_CAPTIONTEXT
,
876 wxSYS_COLOUR_3DDKSHADOW
,
877 wxSYS_COLOUR_3DLIGHT
,
878 wxSYS_COLOUR_BACKGROUND
,
879 wxSYS_COLOUR_GRAYTEXT
,
880 wxSYS_COLOUR_HIGHLIGHT
,
881 wxSYS_COLOUR_HIGHLIGHTTEXT
,
882 wxSYS_COLOUR_INACTIVEBORDER
,
883 wxSYS_COLOUR_INACTIVECAPTION
,
884 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
886 wxSYS_COLOUR_SCROLLBAR
,
888 wxSYS_COLOUR_INFOTEXT
,
890 wxSYS_COLOUR_WINDOWFRAME
,
891 wxSYS_COLOUR_WINDOWTEXT
,
896 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
899 // Class body is in advprops.h
901 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
902 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
905 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
907 wxColourPropertyValue cpv
;
910 cpv
.Init( type
, colour
);
912 cpv
.Init( type
, *wxWHITE
);
914 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
922 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
925 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
926 const wxColourPropertyValue
& value
)
927 : wxEnumProperty( label
,
929 gs_cp_es_syscolour_labels
,
930 gs_cp_es_syscolour_values
,
931 &gs_wxSystemColourProperty_choicesCache
)
934 Init( value
.m_type
, value
.m_colour
);
936 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
940 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
941 const wxChar
* const* labels
, const long* values
, wxPGChoices
* choicesCache
,
942 const wxColourPropertyValue
& value
)
943 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
946 Init( value
.m_type
, value
.m_colour
);
948 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
952 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
953 const wxChar
* const* labels
, const long* values
, wxPGChoices
* choicesCache
,
954 const wxColour
& value
)
955 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
958 Init( wxPG_COLOUR_CUSTOM
, value
);
960 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
964 wxSystemColourProperty::~wxSystemColourProperty() { }
967 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
972 if ( pVariant
->IsNull() )
973 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
975 if ( pVariant
->GetType() == wxS("wxColourPropertyValue") )
977 wxColourPropertyValue v
;
983 bool variantProcessed
= true;
985 if ( pVariant
->GetType() == wxS("wxColour*") )
987 wxColour
* pCol
= wxStaticCast(pVariant
->GetWxObjectPtr(), wxColour
);
990 else if ( pVariant
->GetType() == wxS("wxColour") )
994 else if ( pVariant
->GetType() == wxArrayInt_VariantType
)
996 // This code is mostly needed for wxPython bindings, which
997 // may offer tuple of integers as colour value.
1001 if ( arr
.size() >= 3 )
1009 if ( arr
.size() >= 4 )
1012 col
= wxColour(r
, g
, b
, a
);
1016 variantProcessed
= false;
1021 variantProcessed
= false;
1024 if ( !variantProcessed
)
1025 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
1027 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
1029 int colInd
= ColToInd(col
);
1030 if ( colInd
!= wxNOT_FOUND
)
1036 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1043 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
1046 size_t i_max
= m_choices
.GetCount();
1048 if ( !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1051 for ( i
=0; i
<i_max
; i
++ )
1053 int ind
= m_choices
[i
].GetValue();
1055 if ( colour
== GetColour(ind
) )
1057 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
1058 GetClassName(),GetLabel().c_str(),
1059 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
1060 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
1067 void wxSystemColourProperty::OnSetValue()
1069 // Convert from generic wxobject ptr to wxPGVariantDataColour
1070 if ( m_value
.GetType() == wxS("wxColour*") )
1072 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
1076 wxColourPropertyValue val
= GetVal(&m_value
);
1078 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
1086 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
1087 val
.m_colour
= GetColour( val
.m_type
);
1089 m_value
= TranslateVal(val
);
1092 int ind
= wxNOT_FOUND
;
1094 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
1096 wxColourPropertyValue cpv
;
1098 wxColour col
= cpv
.m_colour
;
1102 SetValueToUnspecified();
1103 SetIndex(wxNOT_FOUND
);
1107 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
||
1108 (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1110 ind
= GetIndexForValue(cpv
.m_type
);
1114 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
1115 ind
= GetCustomColourIndex();
1125 SetValueToUnspecified();
1126 SetIndex(wxNOT_FOUND
);
1130 ind
= ColToInd(col
);
1132 if ( ind
== wxNOT_FOUND
&&
1133 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1134 ind
= GetCustomColourIndex();
1141 wxColour
wxSystemColourProperty::GetColour( int index
) const
1143 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
1146 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
,
1148 int argFlags
) const
1151 if ( index
== wxNOT_FOUND
)
1154 if ( (argFlags
& wxPG_FULL_VALUE
) ||
1155 GetAttributeAsLong(wxPG_COLOUR_HAS_ALPHA
, 0) )
1157 return wxString::Format(wxS("(%i,%i,%i,%i)"),
1165 return wxString::Format(wxS("(%i,%i,%i)"),
1173 return m_choices
.GetLabel(index
);
1177 wxString
wxSystemColourProperty::ValueToString( wxVariant
& value
,
1178 int argFlags
) const
1180 wxColourPropertyValue val
= GetVal(&value
);
1184 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1186 // GetIndex() only works reliably if wxPG_VALUE_IS_CURRENT flag is set,
1187 // but we should use it whenever possible.
1190 // If custom colour was selected, use invalid index, so that
1191 // ColourToString() will return properly formatted colour text.
1192 if ( index
== GetCustomColourIndex() &&
1193 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1194 index
= wxNOT_FOUND
;
1198 index
= m_choices
.Index(val
.m_type
);
1201 return ColourToString(val
.m_colour
, index
, argFlags
);
1205 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
1207 return wxPG_DEFAULT_IMAGE_SIZE
;
1211 int wxSystemColourProperty::GetCustomColourIndex() const
1213 return m_choices
.GetCount() - 1;
1217 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1219 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1222 wxPropertyGrid
* propgrid
= GetGrid();
1223 wxASSERT( propgrid
);
1225 // Must only occur when user triggers event
1226 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
) )
1229 wxColourPropertyValue val
= GetVal();
1231 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1234 data
.SetChooseFull(true);
1235 data
.SetColour(val
.m_colour
);
1237 for ( i
= 0; i
< 16; i
++)
1239 wxColour
colour(i
*16, i
*16, i
*16);
1240 data
.SetCustomColour(i
, colour
);
1243 wxColourDialog
dialog(propgrid
, &data
);
1244 if ( dialog
.ShowModal() == wxID_OK
)
1246 wxColourData retData
= dialog
.GetColourData();
1247 val
.m_colour
= retData
.GetColour();
1249 variant
= DoTranslateVal(val
);
1251 SetValueInEvent(variant
);
1260 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1263 int type
= m_choices
.GetValue(index
);
1265 if ( type
== wxPG_COLOUR_CUSTOM
)
1267 QueryColourFromUser(variant
);
1271 variant
= TranslateVal( type
, GetColour(type
) );
1277 // Need to do some extra event handling.
1278 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
,
1279 wxWindow
* WXUNUSED(primary
),
1282 bool askColour
= false;
1284 if ( propgrid
->IsMainButtonEvent(event
) )
1286 // We need to handle button click in case editor has been
1287 // switched to one that has wxButton as well.
1290 else if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
1292 // Must override index detection since at this point GetIndex()
1293 // will return old value.
1294 wxOwnerDrawnComboBox
* cb
=
1295 static_cast<wxOwnerDrawnComboBox
*>(propgrid
->GetEditorControl());
1299 int index
= cb
->GetSelection();
1301 if ( index
== GetCustomColourIndex() &&
1302 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1307 if ( askColour
&& !propgrid
->WasValueChangedInEvent() )
1310 if ( QueryColourFromUser(variant
) )
1316 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1319 virtual void Render( wxDC& dc, const wxRect& rect,
1320 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1321 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1323 wxASSERT( wxDynamicCast(property, wxSystemColourProperty) );
1324 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1326 dc.SetPen(*wxBLACK_PEN);
1328 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1332 const wxArrayInt& values = prop->GetValues();
1333 if ( values.GetChildCount() )
1334 colInd = values[item];
1337 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1339 else if ( !prop->IsValueUnspecified() )
1340 dc.SetBrush( prop->GetVal().m_colour );
1342 dc.SetBrush( *wxWHITE );
1344 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1345 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1346 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1347 imageRect.width, imageRect.height );
1351 text = property->GetValueAsString();
1353 text = property->GetChoiceString(item);
1354 DrawText( dc, rect, imageRect.width, text );
1359 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1361 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1364 return &g_wxPGColourPropertyRenderer;
1365 return wxEnumProperty::GetCellRenderer(column);
1368 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1369 wxPGPaintData
& paintdata
)
1373 if ( paintdata
.m_choiceItem
>= 0 &&
1374 paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1375 (paintdata
.m_choiceItem
!= GetCustomColourIndex() ||
1376 m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1378 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1379 col
= GetColour( colInd
);
1381 else if ( !IsValueUnspecified() )
1383 col
= GetVal().m_colour
;
1389 dc
.DrawRectangle(rect
);
1394 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1396 wxString
custColName(m_choices
.GetLabel(GetCustomColourIndex()));
1397 wxString
colStr(text
);
1401 wxColour customColour
;
1402 bool conversionSuccess
= false;
1404 if ( colStr
!= custColName
)
1406 if ( colStr
.Find(wxS("(")) == 0 )
1408 // Eliminate whitespace
1409 colStr
.Replace(wxS(" "), wxEmptyString
);
1411 int commaCount
= colStr
.Freq(wxS(','));
1412 if ( commaCount
== 2 )
1414 // Convert (R,G,B) to rgb(R,G,B)
1415 colStr
= wxS("rgb") + colStr
;
1417 else if ( commaCount
== 3 )
1419 // We have int alpha, CSS format that wxColour takes as
1420 // input processes float alpha. So, let's parse the colour
1421 // ourselves instead of trying to convert it to a format
1422 // that wxColour::FromString() understands.
1423 int r
= -1, g
= -1, b
= -1, a
= -1;
1424 wxSscanf(colStr
, wxS("(%i,%i,%i,%i)"), &r
, &g
, &b
, &a
);
1425 customColour
.Set(r
, g
, b
, a
);
1426 conversionSuccess
= customColour
.IsOk();
1430 if ( !conversionSuccess
)
1431 conversionSuccess
= customColour
.Set(colStr
);
1434 if ( !conversionSuccess
&& m_choices
.GetCount() &&
1435 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) &&
1436 colStr
== custColName
)
1438 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1440 // This really should not occurr...
1446 QueryColourFromUser(value
);
1450 wxColourPropertyValue val
;
1454 if ( !conversionSuccess
)
1456 // Try predefined colour first
1457 bool res
= wxEnumProperty::StringToValue(value
,
1460 if ( res
&& GetIndex() >= 0 )
1462 val
.m_type
= GetIndex();
1463 if ( val
.m_type
< m_choices
.GetCount() )
1464 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1466 // Get proper colour for type.
1467 val
.m_colour
= GetColour(val
.m_type
);
1474 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1475 val
.m_colour
= customColour
;
1485 value
= DoTranslateVal(val
);
1492 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1494 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1496 int ival
= value
.GetLong();
1498 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1500 // Show custom choice
1501 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1502 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1504 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1506 // Hide custom choice
1507 m_choices
.RemoveAt(GetCustomColourIndex());
1508 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1516 // -----------------------------------------------------------------------
1518 // -----------------------------------------------------------------------
1520 static const wxChar
* const gs_cp_es_normcolour_labels
[] = {
1540 (const wxChar
*) NULL
1543 static const unsigned long gs_cp_es_normcolour_colours
[] = {
1545 wxPG_COLOUR(128,0,0),
1546 wxPG_COLOUR(0,0,128),
1547 wxPG_COLOUR(128,0,128),
1548 wxPG_COLOUR(0,128,128),
1549 wxPG_COLOUR(128,128,128),
1550 wxPG_COLOUR(0,128,0),
1551 wxPG_COLOUR(128,128,0),
1552 wxPG_COLOUR(166,124,81),
1553 wxPG_COLOUR(0,0,255),
1554 wxPG_COLOUR(255,0,255),
1555 wxPG_COLOUR(255,0,0),
1556 wxPG_COLOUR(247,148,28),
1557 wxPG_COLOUR(192,192,192),
1558 wxPG_COLOUR(0,255,0),
1559 wxPG_COLOUR(0,255,255),
1560 wxPG_COLOUR(255,255,0),
1561 wxPG_COLOUR(255,255,255),
1565 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxColourProperty
, wxSystemColourProperty
,
1566 wxColour
, const wxColour
&, TextCtrlAndButton
)
1568 static wxPGChoices gs_wxColourProperty_choicesCache
;
1570 wxColourProperty::wxColourProperty( const wxString
& label
,
1571 const wxString
& name
,
1572 const wxColour
& value
)
1573 : wxSystemColourProperty(label
, name
, gs_cp_es_normcolour_labels
,
1575 &gs_wxColourProperty_choicesCache
, value
)
1579 m_flags
|= wxPG_PROP_TRANSLATE_CUSTOM
;
1582 wxColourProperty::~wxColourProperty()
1586 void wxColourProperty::Init( wxColour colour
)
1588 if ( !colour
.IsOk() )
1593 int ind
= ColToInd(colour
);
1595 ind
= m_choices
.GetCount() - 1;
1599 wxString
wxColourProperty::ValueToString( wxVariant
& value
,
1600 int argFlags
) const
1602 const wxPGEditor
* editor
= GetEditorClass();
1603 if ( editor
!= wxPGEditor_Choice
&&
1604 editor
!= wxPGEditor_ChoiceAndButton
&&
1605 editor
!= wxPGEditor_ComboBox
)
1606 argFlags
|= wxPG_PROPERTY_SPECIFIC
;
1608 return wxSystemColourProperty::ValueToString(value
, argFlags
);
1611 wxColour
wxColourProperty::GetColour( int index
) const
1613 return gs_cp_es_normcolour_colours
[m_choices
.GetValue(index
)];
1616 wxVariant
wxColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1619 variant
<< v
.m_colour
;
1623 // -----------------------------------------------------------------------
1625 // -----------------------------------------------------------------------
1627 #define wxPG_CURSOR_IMAGE_WIDTH 32
1629 #define NUM_CURSORS 28
1631 //#define wx_cp_es_syscursors_len 28
1632 static const wxChar
* const gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1644 wxT("Middle Button"),
1650 wxT("Question Arrow"),
1651 wxT("Right Button"),
1652 wxT("Sizing NE-SW"),
1654 wxT("Sizing NW-SE"),
1661 (const wxChar
*) NULL
1664 static const long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1667 wxCURSOR_RIGHT_ARROW
,
1674 wxCURSOR_LEFT_BUTTON
,
1676 wxCURSOR_MIDDLE_BUTTON
,
1678 wxCURSOR_PAINT_BRUSH
,
1680 wxCURSOR_POINT_LEFT
,
1681 wxCURSOR_POINT_RIGHT
,
1682 wxCURSOR_QUESTION_ARROW
,
1683 wxCURSOR_RIGHT_BUTTON
,
1695 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1697 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1699 : wxEnumProperty( label
,
1701 gs_cp_es_syscursors_labels
,
1702 gs_cp_es_syscursors_values
,
1705 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1708 wxCursorProperty::~wxCursorProperty()
1712 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1714 #if wxPG_CAN_DRAW_CURSOR
1715 if ( item
!= -1 && item
< NUM_CURSORS
)
1716 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1723 #if wxPG_CAN_DRAW_CURSOR
1725 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1727 wxPGPaintData
& paintdata
)
1730 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1732 if ( paintdata
.m_choiceItem
>= 0 )
1734 dc
.DrawRectangle( rect
);
1736 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1738 wxStockCursor cursorIndex
=
1739 (wxStockCursor
) gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1742 if ( cursorIndex
== wxCURSOR_NONE
)
1743 cursorIndex
= wxCURSOR_ARROW
;
1745 wxCursor
cursor( cursorIndex
);
1748 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1752 (HICON
)cursor
.GetHandle(),
1757 #if !defined(__WXWINCE__)
1758 DI_COMPAT
| DI_DEFAULTSIZE
|
1769 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1770 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1772 return wxEnumProperty::GetCellRenderer(column);
1776 // -----------------------------------------------------------------------
1777 // wxImageFileProperty
1778 // -----------------------------------------------------------------------
1782 const wxString
& wxPGGetDefaultImageWildcard()
1784 // Form the wildcard, if not done yet
1785 if ( wxPGGlobalVars
->m_pDefaultImageWildcard
.empty() )
1790 // TODO: This section may require locking (using global).
1792 wxList
& handlers
= wxImage::GetHandlers();
1794 wxList::iterator node
;
1796 // Let's iterate over the image handler list.
1797 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1798 for ( node
= handlers
.begin(); node
!= handlers
.end(); ++node
)
1800 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1802 wxString ext_lo
= handler
->GetExtension();
1803 wxString ext_up
= ext_lo
.Upper();
1805 str
.append( ext_up
);
1806 str
.append( wxT(" files (*.") );
1807 str
.append( ext_up
);
1808 str
.append( wxT(")|*.") );
1809 str
.append( ext_lo
);
1810 str
.append( wxT("|") );
1813 str
.append ( wxT("All files (*.*)|*.*") );
1815 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1818 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1821 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1823 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1824 const wxString
& value
)
1825 : wxFileProperty(label
,name
,value
)
1827 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1833 wxImageFileProperty::~wxImageFileProperty()
1841 void wxImageFileProperty::OnSetValue()
1843 wxFileProperty::OnSetValue();
1847 wxDELETE(m_pBitmap
);
1849 wxFileName filename
= GetFileName();
1851 // Create the image thumbnail
1852 if ( filename
.FileExists() )
1854 m_pImage
= new wxImage( filename
.GetFullPath() );
1858 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1860 return wxPG_DEFAULT_IMAGE_SIZE
;
1863 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1867 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->IsOk() ) )
1869 // Draw the thumbnail
1871 // Create the bitmap here because required size is not known in OnSetValue().
1874 m_pImage
->Rescale( rect
.width
, rect
.height
);
1875 m_pBitmap
= new wxBitmap( *m_pImage
);
1879 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1883 // No file - just draw a white box
1884 dc
.SetBrush( *wxWHITE_BRUSH
);
1885 dc
.DrawRectangle ( rect
);
1889 #endif // wxUSE_IMAGE
1891 // -----------------------------------------------------------------------
1892 // wxMultiChoiceProperty
1893 // -----------------------------------------------------------------------
1897 #include "wx/choicdlg.h"
1899 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1900 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1902 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1903 const wxString
& name
,
1904 const wxPGChoices
& choices
,
1905 const wxArrayString
& value
)
1906 : wxPGProperty(label
,name
)
1908 m_choices
.Assign(choices
);
1912 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1913 const wxString
& name
,
1914 const wxArrayString
& strings
,
1915 const wxArrayString
& value
)
1916 : wxPGProperty(label
,name
)
1918 m_choices
.Set(strings
);
1922 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1923 const wxString
& name
,
1924 const wxArrayString
& value
)
1925 : wxPGProperty(label
,name
)
1927 wxArrayString strings
;
1928 m_choices
.Set(strings
);
1932 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1936 void wxMultiChoiceProperty::OnSetValue()
1938 GenerateValueAsString(m_value
, &m_display
);
1941 wxString
wxMultiChoiceProperty::ValueToString( wxVariant
& value
,
1942 int argFlags
) const
1944 // If possible, use cached string
1945 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1949 GenerateValueAsString(value
, &s
);
1953 void wxMultiChoiceProperty::GenerateValueAsString( wxVariant
& value
,
1954 wxString
* target
) const
1956 wxArrayString strings
;
1958 if ( value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1959 strings
= value
.GetArrayString();
1961 wxString
& tempStr
= *target
;
1963 unsigned int itemCount
= strings
.size();
1968 tempStr
.append( wxT("\"") );
1970 for ( i
= 0; i
< itemCount
; i
++ )
1972 tempStr
.append( strings
[i
] );
1973 tempStr
.append( wxT("\"") );
1974 if ( i
< (itemCount
-1) )
1975 tempStr
.append ( wxT(" \"") );
1979 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1981 wxVariant variant
= GetValue();
1982 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(variant
);
1985 // Translate values to string indices.
1986 wxArrayInt selections
;
1988 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1990 for ( i
=0; i
<valueArr
.size(); i
++ )
1995 for ( i
=0; i
<valueArr
.size(); i
++ )
1997 int sIndex
= m_choices
.Index(valueArr
[i
]);
1999 selections
.Add(sIndex
);
2006 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
2007 wxWindow
* WXUNUSED(primary
),
2010 if ( propgrid
->IsMainButtonEvent(event
) )
2013 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
2015 wxArrayString labels
= m_choices
.GetLabels();
2016 unsigned int choiceCount
;
2018 if ( m_choices
.IsOk() )
2019 choiceCount
= m_choices
.GetCount();
2023 // launch editor dialog
2024 wxMultiChoiceDialog
dlg( propgrid
,
2025 _("Make a selection:"),
2028 choiceCount
?&labels
[0]:NULL
,
2029 wxCHOICEDLG_STYLE
);
2031 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
2033 wxArrayString strings
= useValue
.GetArrayString();
2034 wxArrayString extraStrings
;
2036 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
2038 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
2040 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
2042 wxArrayInt arrInt
= dlg
.GetSelections();
2046 // Strings that were not in list of choices
2047 wxArrayString value
;
2049 // Translate string indices to strings
2052 if ( userStringMode
== 1 )
2054 for (n
=0;n
<extraStrings
.size();n
++)
2055 value
.push_back(extraStrings
[n
]);
2059 for ( i
=0; i
<arrInt
.size(); i
++ )
2060 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
2062 if ( userStringMode
== 2 )
2064 for (n
=0;n
<extraStrings
.size();n
++)
2065 value
.push_back(extraStrings
[n
]);
2068 variant
= WXVARIANT(value
);
2070 SetValueInEvent(variant
);
2078 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
2082 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
2084 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
2085 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
2087 WX_PG_TOKENIZER2_END()
2089 wxVariant
v( WXVARIANT(arr
) );
2095 #endif // wxUSE_CHOICEDLG
2098 // -----------------------------------------------------------------------
2100 // -----------------------------------------------------------------------
2105 #if wxUSE_DATEPICKCTRL
2106 #define dtCtrl DatePickerCtrl
2108 #define dtCtrl TextCtrl
2111 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
2118 wxString
wxDateProperty::ms_defaultDateFormat
;
2121 wxDateProperty::wxDateProperty( const wxString
& label
,
2122 const wxString
& name
,
2123 const wxDateTime
& value
)
2124 : wxPGProperty(label
,name
)
2126 //wxPGRegisterDefaultValueType(wxDateTime)
2128 #if wxUSE_DATEPICKCTRL
2129 wxPGRegisterEditorClass(DatePickerCtrl
);
2131 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
2139 wxDateProperty::~wxDateProperty()
2143 void wxDateProperty::OnSetValue()
2146 // Convert invalid dates to unspecified value
2147 if ( m_value
.GetType() == wxT("datetime") )
2149 if ( !m_value
.GetDateTime().IsValid() )
2154 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
2155 int WXUNUSED(argFlags
) ) const
2159 // FIXME: do we really want to return true from here if only part of the
2160 // string was parsed?
2161 const char* c
= dt
.ParseFormat(text
);
2172 wxString
wxDateProperty::ValueToString( wxVariant
& value
,
2173 int argFlags
) const
2175 const wxChar
* format
= (const wxChar
*) NULL
;
2177 wxDateTime dateTime
= value
.GetDateTime();
2179 if ( !dateTime
.IsValid() )
2180 return wxT("Invalid");
2182 if ( ms_defaultDateFormat
.empty() )
2184 #if wxUSE_DATEPICKCTRL
2185 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
2187 bool showCentury
= true;
2189 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
2192 if ( !m_format
.empty() &&
2193 !(argFlags
& wxPG_FULL_VALUE
) )
2194 format
= m_format
.c_str();
2196 // Determine default from locale
2197 // NB: This is really simple stuff, but can't figure anything
2198 // better without proper support in wxLocale
2200 format
= ms_defaultDateFormat
.c_str();
2202 return dateTime
.Format(format
);
2205 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
2207 // This code is basicly copied from datectlg.cpp's SetFormat
2212 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
2213 wxString
str(dt
.Format(wxT("%x")));
2215 const wxChar
*p
= str
.c_str();
2219 if (n
== dt
.GetDay())
2221 format
.Append(wxT("%d"));
2224 else if (n
== (int)dt
.GetMonth()+1)
2226 format
.Append(wxT("%m"));
2229 else if (n
== dt
.GetYear())
2231 format
.Append(wxT("%Y"));
2234 else if (n
== (dt
.GetYear() % 100))
2237 format
.Append(wxT("%Y"));
2239 format
.Append(wxT("%y"));
2243 format
.Append(*p
++);
2249 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
2251 if ( name
== wxPG_DATE_FORMAT
)
2253 m_format
= value
.GetString();
2256 else if ( name
== wxPG_DATE_PICKER_STYLE
)
2258 m_dpStyle
= value
.GetLong();
2259 ms_defaultDateFormat
.clear(); // This may need recalculation
2265 #endif // wxUSE_DATETIME
2268 // -----------------------------------------------------------------------
2269 // wxPropertyGridInterface
2270 // -----------------------------------------------------------------------
2272 void wxPropertyGridInterface::InitAllTypeHandlers()
2276 // -----------------------------------------------------------------------
2278 void wxPropertyGridInterface::RegisterAdditionalEditors()
2280 // Register editor classes, if necessary.
2281 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
2282 wxPropertyGrid::RegisterDefaultEditors();
2285 wxPGRegisterEditorClass(SpinCtrl
);
2287 #if wxUSE_DATEPICKCTRL
2288 wxPGRegisterEditorClass(DatePickerCtrl
);
2292 // -----------------------------------------------------------------------
2294 #endif // wxPG_INCLUDE_ADVPROPS
2296 #endif // wxUSE_PROPGRID