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 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()
454 wxPGWindowList
wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
,
455 wxPGProperty
* property
,
457 const wxSize
& sz
) const
459 wxCHECK_MSG( property
->IsKindOf(CLASSINFO(wxDateProperty
)),
461 wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
463 wxDateProperty
* prop
= wxDynamicCast(property
, wxDateProperty
);
465 // Use two stage creation to allow cleaner display on wxMSW
466 wxDatePickerCtrl
* ctrl
= new wxDatePickerCtrl();
469 wxSize useSz
= wxDefaultSize
;
475 wxDateTime
dateValue(wxInvalidDateTime
);
477 wxVariant value
= prop
->GetValue();
478 if ( value
.GetType() == wxT("datetime") )
479 dateValue
= value
.GetDateTime();
481 ctrl
->Create(propgrid
->GetPanel(),
486 prop
->GetDatePickerStyle() | wxNO_BORDER
);
495 // Copies value from property to control
496 void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty
* property
,
497 wxWindow
* wnd
) const
499 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
500 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
502 wxDateTime
dateValue(wxInvalidDateTime
);
503 wxVariant
v(property
->GetValue());
504 if ( v
.GetType() == wxT("datetime") )
505 dateValue
= v
.GetDateTime();
507 ctrl
->SetValue( dateValue
);
510 // Control's events are redirected here
511 bool wxPGDatePickerCtrlEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propgrid
),
512 wxPGProperty
* WXUNUSED(property
),
513 wxWindow
* WXUNUSED(wnd
),
514 wxEvent
& event
) const
516 if ( event
.GetEventType() == wxEVT_DATE_CHANGED
)
522 bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const
524 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
525 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
527 variant
= ctrl
->GetValue();
532 void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty
* property
,
533 wxWindow
* wnd
) const
535 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
536 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
538 wxDateProperty
* prop
= wxDynamicCast(property
, wxDateProperty
);
542 int datePickerStyle
= prop
->GetDatePickerStyle();
543 if ( datePickerStyle
& wxDP_ALLOWNONE
)
544 ctrl
->SetValue(wxInvalidDateTime
);
548 #endif // wxUSE_DATEPICKCTRL
551 // -----------------------------------------------------------------------
553 // -----------------------------------------------------------------------
555 #include "wx/fontdlg.h"
556 #include "wx/fontenum.h"
559 // NB: Do not use wxS here since unlike wxT it doesn't translate to wxChar*
562 static const wxChar
* gs_fp_es_family_labels
[] = {
563 wxT("Default"), wxT("Decorative"),
564 wxT("Roman"), wxT("Script"),
565 wxT("Swiss"), wxT("Modern"),
566 wxT("Teletype"), wxT("Unknown"),
570 static long gs_fp_es_family_values
[] = {
571 wxFONTFAMILY_DEFAULT
, wxFONTFAMILY_DECORATIVE
,
572 wxFONTFAMILY_ROMAN
, wxFONTFAMILY_SCRIPT
,
573 wxFONTFAMILY_SWISS
, wxFONTFAMILY_MODERN
,
574 wxFONTFAMILY_TELETYPE
, wxFONTFAMILY_UNKNOWN
577 static const wxChar
* gs_fp_es_style_labels
[] = {
584 static long gs_fp_es_style_values
[] = {
590 static const wxChar
* gs_fp_es_weight_labels
[] = {
597 static long gs_fp_es_weight_values
[] = {
603 // Class body is in advprops.h
606 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty
,wxPGProperty
,
607 wxFont
,const wxFont
&,TextCtrlAndButton
)
610 wxFontProperty::wxFontProperty( const wxString
& label
, const wxString
& name
,
611 const wxFont
& value
)
612 : wxPGProperty(label
,name
)
614 SetValue(WXVARIANT(value
));
616 // Initialize font family choices list
617 if ( !wxPGGlobalVars
->m_fontFamilyChoices
)
619 wxArrayString faceNames
= wxFontEnumerator::GetFacenames();
623 wxPGGlobalVars
->m_fontFamilyChoices
= new wxPGChoices(faceNames
);
626 wxString
emptyString(wxEmptyString
);
631 AddPrivateChild( new wxIntProperty( _("Point Size"),
632 wxS("Point Size"),(long)font
.GetPointSize() ) );
634 wxString faceName
= font
.GetFaceName();
635 // If font was not in there, add it now
636 if ( faceName
.length() &&
637 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
638 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
640 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"), wxS("Face Name"),
641 *wxPGGlobalVars
->m_fontFamilyChoices
);
643 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
645 AddPrivateChild( p
);
647 AddPrivateChild( new wxEnumProperty(_("Style"), wxS("Style"),
648 gs_fp_es_style_labels
,gs_fp_es_style_values
,
651 AddPrivateChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
652 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,
655 AddPrivateChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
656 font
.GetUnderlined()) );
658 AddPrivateChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
659 gs_fp_es_family_labels
,gs_fp_es_family_values
,
663 wxFontProperty::~wxFontProperty() { }
665 void wxFontProperty::OnSetValue()
672 m_value
<< *wxNORMAL_FONT
;
676 wxString
wxFontProperty::ValueToString( wxVariant
& value
,
679 return wxPGProperty::ValueToString(value
, argFlags
);
682 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
685 if ( propgrid
->IsMainButtonEvent(event
) )
687 // Update value from last minute changes
688 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
693 data
.SetInitialFont( font
);
694 data
.SetColour(*wxBLACK
);
696 wxFontDialog
dlg(propgrid
, data
);
697 if ( dlg
.ShowModal() == wxID_OK
)
699 propgrid
->EditorsValueWasModified();
702 variant
<< dlg
.GetFontData().GetChosenFont();
703 SetValueInEvent( variant
);
710 void wxFontProperty::RefreshChildren()
712 if ( !GetChildCount() ) return;
715 Item(0)->SetValue( (long)font
.GetPointSize() );
716 Item(1)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
717 Item(2)->SetValue( (long)font
.GetStyle() );
718 Item(3)->SetValue( (long)font
.GetWeight() );
719 Item(4)->SetValue( font
.GetUnderlined() );
720 Item(5)->SetValue( (long)font
.GetFamily() );
723 wxVariant
wxFontProperty::ChildChanged( wxVariant
& thisValue
,
725 wxVariant
& childValue
) const
732 font
.SetPointSize( childValue
.GetLong() );
737 int faceIndex
= childValue
.GetLong();
739 if ( faceIndex
>= 0 )
740 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
742 font
.SetFaceName( faceName
);
746 int st
= childValue
.GetLong();
747 if ( st
!= wxFONTSTYLE_NORMAL
&&
748 st
!= wxFONTSTYLE_SLANT
&&
749 st
!= wxFONTSTYLE_ITALIC
)
750 st
= wxFONTWEIGHT_NORMAL
;
755 int wt
= childValue
.GetLong();
756 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
757 wt
!= wxFONTWEIGHT_LIGHT
&&
758 wt
!= wxFONTWEIGHT_BOLD
)
759 wt
= wxFONTWEIGHT_NORMAL
;
760 font
.SetWeight( wt
);
764 font
.SetUnderlined( childValue
.GetBool() );
768 int fam
= childValue
.GetLong();
769 if ( fam
< wxDEFAULT
||
772 font
.SetFamily( fam
);
775 wxVariant newVariant
;
781 wxSize wxFontProperty::OnMeasureImage() const
783 return wxSize(-1,-1);
786 void wxFontProperty::OnCustomPaint(wxDC& dc,
788 wxPGPaintData& paintData)
791 if ( paintData.m_choiceItem >= 0 )
792 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
794 drawFace = m_value_wxFont.GetFaceName();
796 if ( drawFace.length() )
798 // Draw the background
799 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
800 //dc.SetBrush( *wxWHITE_BRUSH );
801 //dc.SetPen( *wxMEDIUM_GREY_PEN );
802 dc.DrawRectangle( rect );
804 wxFont oldFont = dc.GetFont();
805 wxFont drawFont(oldFont.GetPointSize(),
806 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
807 dc.SetFont(drawFont);
809 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
810 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
816 // No file - just draw a white box
817 dc.SetBrush ( *wxWHITE_BRUSH );
818 dc.DrawRectangle ( rect );
824 // -----------------------------------------------------------------------
825 // wxSystemColourProperty
826 // -----------------------------------------------------------------------
828 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
829 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
831 #include "wx/colordlg.h"
833 //#define wx_cp_es_syscolours_len 25
834 static const wxChar
* gs_cp_es_syscolour_labels
[] = {
837 wxT("ActiveCaption"),
839 wxT("ButtonHighlight"),
848 wxT("HighlightText"),
849 wxT("InactiveBorder"),
850 wxT("InactiveCaption"),
851 wxT("InactiveCaptionText"),
863 static long gs_cp_es_syscolour_values
[] = {
864 wxSYS_COLOUR_APPWORKSPACE
,
865 wxSYS_COLOUR_ACTIVEBORDER
,
866 wxSYS_COLOUR_ACTIVECAPTION
,
867 wxSYS_COLOUR_BTNFACE
,
868 wxSYS_COLOUR_BTNHIGHLIGHT
,
869 wxSYS_COLOUR_BTNSHADOW
,
870 wxSYS_COLOUR_BTNTEXT
,
871 wxSYS_COLOUR_CAPTIONTEXT
,
872 wxSYS_COLOUR_3DDKSHADOW
,
873 wxSYS_COLOUR_3DLIGHT
,
874 wxSYS_COLOUR_BACKGROUND
,
875 wxSYS_COLOUR_GRAYTEXT
,
876 wxSYS_COLOUR_HIGHLIGHT
,
877 wxSYS_COLOUR_HIGHLIGHTTEXT
,
878 wxSYS_COLOUR_INACTIVEBORDER
,
879 wxSYS_COLOUR_INACTIVECAPTION
,
880 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
882 wxSYS_COLOUR_SCROLLBAR
,
884 wxSYS_COLOUR_INFOTEXT
,
886 wxSYS_COLOUR_WINDOWFRAME
,
887 wxSYS_COLOUR_WINDOWTEXT
,
892 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
895 // Class body is in advprops.h
897 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
898 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
901 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
903 wxColourPropertyValue cpv
;
906 cpv
.Init( type
, colour
);
908 cpv
.Init( type
, *wxWHITE
);
910 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
918 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
921 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
922 const wxColourPropertyValue
& value
)
923 : wxEnumProperty( label
,
925 gs_cp_es_syscolour_labels
,
926 gs_cp_es_syscolour_values
,
927 &gs_wxSystemColourProperty_choicesCache
)
930 Init( value
.m_type
, value
.m_colour
);
932 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
936 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
937 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
938 const wxColourPropertyValue
& value
)
939 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
942 Init( value
.m_type
, value
.m_colour
);
944 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
948 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
949 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
950 const wxColour
& value
)
951 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
954 Init( wxPG_COLOUR_CUSTOM
, value
);
956 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
960 wxSystemColourProperty::~wxSystemColourProperty() { }
963 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
968 if ( pVariant
->IsNull() )
969 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
971 if ( pVariant
->GetType() == wxS("wxColourPropertyValue") )
973 wxColourPropertyValue v
;
979 bool variantProcessed
= true;
981 if ( pVariant
->GetType() == wxS("wxColour*") )
983 wxColour
* pCol
= wxStaticCast(pVariant
->GetWxObjectPtr(), wxColour
);
986 else if ( pVariant
->GetType() == wxS("wxColour") )
990 else if ( pVariant
->GetType() == wxArrayInt_VariantType
)
992 // This code is mostly needed for wxPython bindings, which
993 // may offer tuple of integers as colour value.
997 if ( arr
.size() >= 3 )
1005 if ( arr
.size() >= 4 )
1008 col
= wxColour(r
, g
, b
, a
);
1012 variantProcessed
= false;
1017 variantProcessed
= false;
1020 if ( !variantProcessed
)
1021 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
1023 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
1025 int colInd
= ColToInd(col
);
1026 if ( colInd
!= wxNOT_FOUND
)
1032 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1039 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
1042 size_t i_max
= m_choices
.GetCount();
1044 if ( !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1047 for ( i
=0; i
<i_max
; i
++ )
1049 int ind
= m_choices
[i
].GetValue();
1051 if ( colour
== GetColour(ind
) )
1053 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
1054 GetClassName(),GetLabel().c_str(),
1055 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
1056 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
1063 void wxSystemColourProperty::OnSetValue()
1065 // Convert from generic wxobject ptr to wxPGVariantDataColour
1066 if ( m_value
.GetType() == wxS("wxColour*") )
1068 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
1072 wxColourPropertyValue val
= GetVal(&m_value
);
1074 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
1082 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
1083 val
.m_colour
= GetColour( val
.m_type
);
1085 m_value
= TranslateVal(val
);
1088 int ind
= wxNOT_FOUND
;
1090 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
1092 wxColourPropertyValue cpv
;
1094 wxColour col
= cpv
.m_colour
;
1098 SetValueToUnspecified();
1099 SetIndex(wxNOT_FOUND
);
1103 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
||
1104 (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1106 ind
= GetIndexForValue(cpv
.m_type
);
1110 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
1111 ind
= GetCustomColourIndex();
1121 SetValueToUnspecified();
1122 SetIndex(wxNOT_FOUND
);
1126 ind
= ColToInd(col
);
1128 if ( ind
== wxNOT_FOUND
&&
1129 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1130 ind
= GetCustomColourIndex();
1137 wxColour
wxSystemColourProperty::GetColour( int index
) const
1139 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
1142 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
1144 if ( index
== wxNOT_FOUND
)
1145 return wxString::Format(wxT("(%i,%i,%i)"),
1150 return m_choices
.GetLabel(index
);
1153 wxString
wxSystemColourProperty::ValueToString( wxVariant
& value
,
1154 int argFlags
) const
1156 wxColourPropertyValue val
= GetVal(&value
);
1160 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1162 // GetIndex() only works reliably if wxPG_VALUE_IS_CURRENT flag is set,
1163 // but we should use it whenever possible.
1166 // If custom colour was selected, use invalid index, so that
1167 // ColourToString() will return properly formatted colour text.
1168 if ( index
== GetCustomColourIndex() &&
1169 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1170 index
= wxNOT_FOUND
;
1174 index
= m_choices
.Index(val
.m_type
);
1177 return ColourToString(val
.m_colour
, index
);
1181 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
1183 return wxPG_DEFAULT_IMAGE_SIZE
;
1187 int wxSystemColourProperty::GetCustomColourIndex() const
1189 return m_choices
.GetCount() - 1;
1193 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1195 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1198 wxPropertyGrid
* propgrid
= GetGrid();
1199 wxASSERT( propgrid
);
1201 // Must only occur when user triggers event
1202 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
) )
1205 wxColourPropertyValue val
= GetVal();
1207 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1210 data
.SetChooseFull(true);
1211 data
.SetColour(val
.m_colour
);
1213 for ( i
= 0; i
< 16; i
++)
1215 wxColour
colour(i
*16, i
*16, i
*16);
1216 data
.SetCustomColour(i
, colour
);
1219 wxColourDialog
dialog(propgrid
, &data
);
1220 if ( dialog
.ShowModal() == wxID_OK
)
1222 wxColourData retData
= dialog
.GetColourData();
1223 val
.m_colour
= retData
.GetColour();
1225 variant
= DoTranslateVal(val
);
1227 SetValueInEvent(variant
);
1236 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1239 int type
= m_choices
.GetValue(index
);
1241 if ( type
== wxPG_COLOUR_CUSTOM
)
1243 QueryColourFromUser(variant
);
1247 variant
= TranslateVal( type
, GetColour(type
) );
1253 // Need to do some extra event handling.
1254 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
,
1255 wxWindow
* WXUNUSED(primary
),
1258 bool askColour
= false;
1260 if ( propgrid
->IsMainButtonEvent(event
) )
1262 // We need to handle button click in case editor has been
1263 // switched to one that has wxButton as well.
1266 else if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
1268 // Must override index detection since at this point GetIndex()
1269 // will return old value.
1270 wxOwnerDrawnComboBox
* cb
=
1271 static_cast<wxOwnerDrawnComboBox
*>(propgrid
->GetEditorControl());
1275 int index
= cb
->GetSelection();
1277 if ( index
== GetCustomColourIndex() &&
1278 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1283 if ( askColour
&& !propgrid
->WasValueChangedInEvent() )
1286 if ( QueryColourFromUser(variant
) )
1292 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1295 virtual void Render( wxDC& dc, const wxRect& rect,
1296 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1297 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1299 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1300 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1302 dc.SetPen(*wxBLACK_PEN);
1304 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1308 const wxArrayInt& values = prop->GetValues();
1309 if ( values.GetChildCount() )
1310 colInd = values[item];
1313 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1315 else if ( !prop->IsValueUnspecified() )
1316 dc.SetBrush( prop->GetVal().m_colour );
1318 dc.SetBrush( *wxWHITE );
1320 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1321 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1322 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1323 imageRect.width, imageRect.height );
1327 text = property->GetValueAsString();
1329 text = property->GetChoiceString(item);
1330 DrawText( dc, rect, imageRect.width, text );
1335 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1337 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1340 return &g_wxPGColourPropertyRenderer;
1341 return wxEnumProperty::GetCellRenderer(column);
1344 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1345 wxPGPaintData
& paintdata
)
1349 if ( paintdata
.m_choiceItem
>= 0 &&
1350 paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1351 (paintdata
.m_choiceItem
!= GetCustomColourIndex() ||
1352 m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1354 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1355 col
= GetColour( colInd
);
1357 else if ( !IsValueUnspecified() )
1359 col
= GetVal().m_colour
;
1365 dc
.DrawRectangle(rect
);
1370 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1373 // Accept colour format "[Name] [(R,G,B)]"
1374 // Name takes precedence.
1376 wxString colourName
;
1379 int ppos
= text
.Find(wxT("("));
1381 if ( ppos
== wxNOT_FOUND
)
1387 colourName
= text
.substr(0, ppos
);
1388 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1391 // Strip spaces from extremities
1392 colourName
.Trim(true);
1393 colourName
.Trim(false);
1394 colourRGB
.Trim(true);
1396 // Validate colourRGB string - (1,1,1) is shortest allowed
1397 if ( colourRGB
.length() < 7 )
1400 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1401 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) &&
1402 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1404 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1406 // This really should not occurr...
1412 QueryColourFromUser(value
);
1416 wxColourPropertyValue val
;
1420 if ( colourName
.length() )
1422 // Try predefined colour first
1423 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1424 if ( res
&& GetIndex() >= 0 )
1426 val
.m_type
= GetIndex();
1427 if ( val
.m_type
< m_choices
.GetCount() )
1428 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1430 // Get proper colour for type.
1431 val
.m_colour
= GetColour(val
.m_type
);
1436 if ( colourRGB
.length() && !done
)
1438 // Then check custom colour.
1439 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1441 int r
= -1, g
= -1, b
= -1;
1442 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1444 if ( r
>= 0 && r
<= 255 &&
1445 g
>= 0 && g
<= 255 &&
1446 b
>= 0 && b
<= 255 )
1448 val
.m_colour
.Set(r
,g
,b
);
1460 value
= DoTranslateVal(val
);
1467 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1469 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1471 int ival
= value
.GetLong();
1473 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1475 // Show custom choice
1476 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1477 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1479 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1481 // Hide custom choice
1482 m_choices
.RemoveAt(GetCustomColourIndex());
1483 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1491 // -----------------------------------------------------------------------
1493 // -----------------------------------------------------------------------
1495 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1515 (const wxChar
*) NULL
1518 static unsigned long gs_cp_es_normcolour_colours
[] = {
1520 wxPG_COLOUR(128,0,0),
1521 wxPG_COLOUR(0,0,128),
1522 wxPG_COLOUR(128,0,128),
1523 wxPG_COLOUR(0,128,128),
1524 wxPG_COLOUR(128,128,128),
1525 wxPG_COLOUR(0,128,0),
1526 wxPG_COLOUR(128,128,0),
1527 wxPG_COLOUR(166,124,81),
1528 wxPG_COLOUR(0,0,255),
1529 wxPG_COLOUR(255,0,255),
1530 wxPG_COLOUR(255,0,0),
1531 wxPG_COLOUR(247,148,28),
1532 wxPG_COLOUR(192,192,192),
1533 wxPG_COLOUR(0,255,0),
1534 wxPG_COLOUR(0,255,255),
1535 wxPG_COLOUR(255,255,0),
1536 wxPG_COLOUR(255,255,255),
1540 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxColourProperty
, wxSystemColourProperty
,
1541 wxColour
, const wxColour
&, TextCtrlAndButton
)
1543 static wxPGChoices gs_wxColourProperty_choicesCache
;
1545 wxColourProperty::wxColourProperty( const wxString
& label
,
1546 const wxString
& name
,
1547 const wxColour
& value
)
1548 : wxSystemColourProperty(label
, name
, gs_cp_es_normcolour_labels
,
1550 &gs_wxColourProperty_choicesCache
, value
)
1554 m_flags
|= wxPG_PROP_TRANSLATE_CUSTOM
;
1557 wxColourProperty::~wxColourProperty()
1561 void wxColourProperty::Init( wxColour colour
)
1568 int ind
= ColToInd(colour
);
1570 ind
= m_choices
.GetCount() - 1;
1574 wxString
wxColourProperty::ValueToString( wxVariant
& value
,
1575 int argFlags
) const
1577 const wxPGEditor
* editor
= GetEditorClass();
1578 if ( editor
!= wxPGEditor_Choice
&&
1579 editor
!= wxPGEditor_ChoiceAndButton
&&
1580 editor
!= wxPGEditor_ComboBox
)
1581 argFlags
|= wxPG_PROPERTY_SPECIFIC
;
1583 return wxSystemColourProperty::ValueToString(value
, argFlags
);
1586 wxColour
wxColourProperty::GetColour( int index
) const
1588 return gs_cp_es_normcolour_colours
[m_choices
.GetValue(index
)];
1591 wxVariant
wxColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1594 variant
<< v
.m_colour
;
1598 // -----------------------------------------------------------------------
1600 // -----------------------------------------------------------------------
1602 #define wxPG_CURSOR_IMAGE_WIDTH 32
1604 #define NUM_CURSORS 28
1606 //#define wx_cp_es_syscursors_len 28
1607 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1619 wxT("Middle Button"),
1625 wxT("Question Arrow"),
1626 wxT("Right Button"),
1627 wxT("Sizing NE-SW"),
1629 wxT("Sizing NW-SE"),
1636 (const wxChar
*) NULL
1639 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1642 wxCURSOR_RIGHT_ARROW
,
1649 wxCURSOR_LEFT_BUTTON
,
1651 wxCURSOR_MIDDLE_BUTTON
,
1653 wxCURSOR_PAINT_BRUSH
,
1655 wxCURSOR_POINT_LEFT
,
1656 wxCURSOR_POINT_RIGHT
,
1657 wxCURSOR_QUESTION_ARROW
,
1658 wxCURSOR_RIGHT_BUTTON
,
1670 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1672 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1674 : wxEnumProperty( label
,
1676 gs_cp_es_syscursors_labels
,
1677 gs_cp_es_syscursors_values
,
1680 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1683 wxCursorProperty::~wxCursorProperty()
1687 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1689 #if wxPG_CAN_DRAW_CURSOR
1690 if ( item
!= -1 && item
< NUM_CURSORS
)
1691 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1698 #if wxPG_CAN_DRAW_CURSOR
1700 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1702 wxPGPaintData
& paintdata
)
1705 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1707 if ( paintdata
.m_choiceItem
>= 0 )
1709 dc
.DrawRectangle( rect
);
1711 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1713 wxStockCursor cursorIndex
=
1714 (wxStockCursor
) gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1717 if ( cursorIndex
== wxCURSOR_NONE
)
1718 cursorIndex
= wxCURSOR_ARROW
;
1720 wxCursor
cursor( cursorIndex
);
1723 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1727 (HICON
)cursor
.GetHandle(),
1732 #if !defined(__WXWINCE__)
1733 DI_COMPAT
| DI_DEFAULTSIZE
|
1744 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1745 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1747 return wxEnumProperty::GetCellRenderer(column);
1751 // -----------------------------------------------------------------------
1752 // wxImageFileProperty
1753 // -----------------------------------------------------------------------
1757 const wxString
& wxPGGetDefaultImageWildcard()
1759 // Form the wildcard, if not done yet
1760 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1765 // TODO: This section may require locking (using global).
1767 wxList
& handlers
= wxImage::GetHandlers();
1769 wxList::iterator node
;
1771 // Let's iterate over the image handler list.
1772 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1773 for ( node
= handlers
.begin(); node
!= handlers
.end(); ++node
)
1775 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1777 wxString ext_lo
= handler
->GetExtension();
1778 wxString ext_up
= ext_lo
.Upper();
1780 str
.append( ext_up
);
1781 str
.append( wxT(" files (*.") );
1782 str
.append( ext_up
);
1783 str
.append( wxT(")|*.") );
1784 str
.append( ext_lo
);
1785 str
.append( wxT("|") );
1788 str
.append ( wxT("All files (*.*)|*.*") );
1790 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1793 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1796 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1798 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1799 const wxString
& value
)
1800 : wxFileProperty(label
,name
,value
)
1802 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1808 wxImageFileProperty::~wxImageFileProperty()
1816 void wxImageFileProperty::OnSetValue()
1818 wxFileProperty::OnSetValue();
1832 wxFileName filename
= GetFileName();
1834 // Create the image thumbnail
1835 if ( filename
.FileExists() )
1837 m_pImage
= new wxImage( filename
.GetFullPath() );
1841 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1843 return wxPG_DEFAULT_IMAGE_SIZE
;
1846 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1850 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1852 // Draw the thumbnail
1854 // Create the bitmap here because required size is not known in OnSetValue().
1857 m_pImage
->Rescale( rect
.width
, rect
.height
);
1858 m_pBitmap
= new wxBitmap( *m_pImage
);
1863 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1867 // No file - just draw a white box
1868 dc
.SetBrush( *wxWHITE_BRUSH
);
1869 dc
.DrawRectangle ( rect
);
1873 #endif // wxUSE_IMAGE
1875 // -----------------------------------------------------------------------
1876 // wxMultiChoiceProperty
1877 // -----------------------------------------------------------------------
1881 #include "wx/choicdlg.h"
1883 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1884 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1886 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1887 const wxString
& name
,
1888 const wxPGChoices
& choices
,
1889 const wxArrayString
& value
)
1890 : wxPGProperty(label
,name
)
1892 m_choices
.Assign(choices
);
1896 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1897 const wxString
& name
,
1898 const wxArrayString
& strings
,
1899 const wxArrayString
& value
)
1900 : wxPGProperty(label
,name
)
1902 m_choices
.Set(strings
);
1906 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1907 const wxString
& name
,
1908 const wxArrayString
& value
)
1909 : wxPGProperty(label
,name
)
1911 wxArrayString strings
;
1912 m_choices
.Set(strings
);
1916 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1920 void wxMultiChoiceProperty::OnSetValue()
1922 GenerateValueAsString(m_value
, &m_display
);
1925 wxString
wxMultiChoiceProperty::ValueToString( wxVariant
& value
,
1926 int argFlags
) const
1928 // If possible, use cached string
1929 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1933 GenerateValueAsString(value
, &s
);
1937 void wxMultiChoiceProperty::GenerateValueAsString( wxVariant
& value
,
1938 wxString
* target
) const
1940 wxArrayString strings
;
1942 if ( value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1943 strings
= value
.GetArrayString();
1945 wxString
& tempStr
= *target
;
1947 unsigned int itemCount
= strings
.size();
1952 tempStr
.append( wxT("\"") );
1954 for ( i
= 0; i
< itemCount
; i
++ )
1956 tempStr
.append( strings
[i
] );
1957 tempStr
.append( wxT("\"") );
1958 if ( i
< (itemCount
-1) )
1959 tempStr
.append ( wxT(" \"") );
1963 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1965 wxVariant variant
= GetValue();
1966 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(variant
);
1969 // Translate values to string indices.
1970 wxArrayInt selections
;
1972 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1974 for ( i
=0; i
<valueArr
.size(); i
++ )
1979 for ( i
=0; i
<valueArr
.size(); i
++ )
1981 int sIndex
= m_choices
.Index(valueArr
[i
]);
1983 selections
.Add(sIndex
);
1990 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1991 wxWindow
* WXUNUSED(primary
),
1994 if ( propgrid
->IsMainButtonEvent(event
) )
1997 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
1999 wxArrayString labels
= m_choices
.GetLabels();
2000 unsigned int choiceCount
;
2002 if ( m_choices
.IsOk() )
2003 choiceCount
= m_choices
.GetCount();
2007 // launch editor dialog
2008 wxMultiChoiceDialog
dlg( propgrid
,
2009 _("Make a selection:"),
2012 choiceCount
?&labels
[0]:NULL
,
2013 wxCHOICEDLG_STYLE
);
2015 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
2017 wxArrayString strings
= useValue
.GetArrayString();
2018 wxArrayString extraStrings
;
2020 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
2022 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
2024 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
2026 wxArrayInt arrInt
= dlg
.GetSelections();
2030 // Strings that were not in list of choices
2031 wxArrayString value
;
2033 // Translate string indices to strings
2036 if ( userStringMode
== 1 )
2038 for (n
=0;n
<extraStrings
.size();n
++)
2039 value
.push_back(extraStrings
[n
]);
2043 for ( i
=0; i
<arrInt
.size(); i
++ )
2044 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
2046 if ( userStringMode
== 2 )
2048 for (n
=0;n
<extraStrings
.size();n
++)
2049 value
.push_back(extraStrings
[n
]);
2052 variant
= WXVARIANT(value
);
2054 SetValueInEvent(variant
);
2062 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
2066 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
2068 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
2069 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
2071 WX_PG_TOKENIZER2_END()
2073 wxVariant
v( WXVARIANT(arr
) );
2079 #endif // wxUSE_CHOICEDLG
2082 // -----------------------------------------------------------------------
2084 // -----------------------------------------------------------------------
2089 #if wxUSE_DATEPICKCTRL
2090 #define dtCtrl DatePickerCtrl
2092 #define dtCtrl TextCtrl
2095 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
2102 wxString
wxDateProperty::ms_defaultDateFormat
;
2105 wxDateProperty::wxDateProperty( const wxString
& label
,
2106 const wxString
& name
,
2107 const wxDateTime
& value
)
2108 : wxPGProperty(label
,name
)
2110 //wxPGRegisterDefaultValueType(wxDateTime)
2112 #if wxUSE_DATEPICKCTRL
2113 wxPGRegisterEditorClass(DatePickerCtrl
);
2115 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
2123 wxDateProperty::~wxDateProperty()
2127 void wxDateProperty::OnSetValue()
2130 // Convert invalid dates to unspecified value
2131 if ( m_value
.GetType() == wxT("datetime") )
2133 if ( !m_value
.GetDateTime().IsValid() )
2138 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
2139 int WXUNUSED(argFlags
) ) const
2143 // FIXME: do we really want to return true from here if only part of the
2144 // string was parsed?
2145 const char* c
= dt
.ParseFormat(text
);
2156 wxString
wxDateProperty::ValueToString( wxVariant
& value
,
2157 int argFlags
) const
2159 const wxChar
* format
= (const wxChar
*) NULL
;
2161 wxDateTime dateTime
= value
.GetDateTime();
2163 if ( !dateTime
.IsValid() )
2164 return wxT("Invalid");
2166 if ( !ms_defaultDateFormat
.length() )
2168 #if wxUSE_DATEPICKCTRL
2169 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
2171 bool showCentury
= true;
2173 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
2176 if ( m_format
.length() &&
2177 !(argFlags
& wxPG_FULL_VALUE
) )
2178 format
= m_format
.c_str();
2180 // Determine default from locale
2181 // NB: This is really simple stuff, but can't figure anything
2182 // better without proper support in wxLocale
2184 format
= ms_defaultDateFormat
.c_str();
2186 return dateTime
.Format(format
);
2189 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
2191 // This code is basicly copied from datectlg.cpp's SetFormat
2196 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
2197 wxString
str(dt
.Format(wxT("%x")));
2199 const wxChar
*p
= str
.c_str();
2203 if (n
== dt
.GetDay())
2205 format
.Append(wxT("%d"));
2208 else if (n
== (int)dt
.GetMonth()+1)
2210 format
.Append(wxT("%m"));
2213 else if (n
== dt
.GetYear())
2215 format
.Append(wxT("%Y"));
2218 else if (n
== (dt
.GetYear() % 100))
2221 format
.Append(wxT("%Y"));
2223 format
.Append(wxT("%y"));
2227 format
.Append(*p
++);
2233 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
2235 if ( name
== wxPG_DATE_FORMAT
)
2237 m_format
= value
.GetString();
2240 else if ( name
== wxPG_DATE_PICKER_STYLE
)
2242 m_dpStyle
= value
.GetLong();
2243 ms_defaultDateFormat
.clear(); // This may need recalculation
2249 #endif // wxUSE_DATETIME
2252 // -----------------------------------------------------------------------
2253 // wxPropertyGridInterface
2254 // -----------------------------------------------------------------------
2256 void wxPropertyGridInterface::InitAllTypeHandlers()
2260 // -----------------------------------------------------------------------
2262 void wxPropertyGridInterface::RegisterAdditionalEditors()
2264 // Register editor classes, if necessary.
2265 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
2266 wxPropertyGrid::RegisterDefaultEditors();
2269 wxPGRegisterEditorClass(SpinCtrl
);
2271 #if wxUSE_DATEPICKCTRL
2272 wxPGRegisterEditorClass(DatePickerCtrl
);
2276 // -----------------------------------------------------------------------
2278 #endif // wxPG_INCLUDE_ADVPROPS
2280 #endif // wxUSE_PROPGRID