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"
558 static const wxChar
* gs_fp_es_family_labels
[] = {
559 wxT("Default"), wxT("Decorative"),
560 wxT("Roman"), wxT("Script"),
561 wxT("Swiss"), wxT("Modern"),
565 static long gs_fp_es_family_values
[] = {
566 wxDEFAULT
, wxDECORATIVE
,
571 static const wxChar
* gs_fp_es_style_labels
[] = {
578 static long gs_fp_es_style_values
[] = {
584 static const wxChar
* gs_fp_es_weight_labels
[] = {
591 static long gs_fp_es_weight_values
[] = {
597 // Class body is in advprops.h
600 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty
,wxPGProperty
,
601 wxFont
,const wxFont
&,TextCtrlAndButton
)
604 wxFontProperty::wxFontProperty( const wxString
& label
, const wxString
& name
,
605 const wxFont
& value
)
606 : wxPGProperty(label
,name
)
608 SetValue(WXVARIANT(value
));
610 // Initialize font family choices list
611 if ( !wxPGGlobalVars
->m_fontFamilyChoices
)
613 wxArrayString faceNames
= wxFontEnumerator::GetFacenames();
617 wxPGGlobalVars
->m_fontFamilyChoices
= new wxPGChoices(faceNames
);
620 wxString
emptyString(wxEmptyString
);
625 AddPrivateChild( new wxIntProperty( _("Point Size"),
626 wxS("Point Size"),(long)font
.GetPointSize() ) );
628 AddPrivateChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
629 gs_fp_es_family_labels
,gs_fp_es_family_values
,
632 wxString faceName
= font
.GetFaceName();
633 // If font was not in there, add it now
634 if ( faceName
.length() &&
635 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
636 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
638 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"), wxS("Face Name"),
639 *wxPGGlobalVars
->m_fontFamilyChoices
);
641 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
643 AddPrivateChild( p
);
645 AddPrivateChild( new wxEnumProperty(_("Style"), wxS("Style"),
646 gs_fp_es_style_labels
,gs_fp_es_style_values
,
649 AddPrivateChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
650 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,
653 AddPrivateChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
654 font
.GetUnderlined()) );
657 wxFontProperty::~wxFontProperty() { }
659 void wxFontProperty::OnSetValue()
666 m_value
<< *wxNORMAL_FONT
;
670 wxString
wxFontProperty::ValueToString( wxVariant
& value
,
673 return wxPGProperty::ValueToString(value
, argFlags
);
676 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
679 if ( propgrid
->IsMainButtonEvent(event
) )
681 // Update value from last minute changes
682 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
687 data
.SetInitialFont( font
);
688 data
.SetColour(*wxBLACK
);
690 wxFontDialog
dlg(propgrid
, data
);
691 if ( dlg
.ShowModal() == wxID_OK
)
693 propgrid
->EditorsValueWasModified();
696 variant
<< dlg
.GetFontData().GetChosenFont();
697 SetValueInEvent( variant
);
704 void wxFontProperty::RefreshChildren()
706 if ( !GetChildCount() ) return;
709 Item(0)->SetValue( (long)font
.GetPointSize() );
710 Item(1)->SetValue( (long)font
.GetFamily() );
711 Item(2)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
712 Item(3)->SetValue( (long)font
.GetStyle() );
713 Item(4)->SetValue( (long)font
.GetWeight() );
714 Item(5)->SetValue( font
.GetUnderlined() );
717 wxVariant
wxFontProperty::ChildChanged( wxVariant
& thisValue
,
719 wxVariant
& childValue
) const
726 font
.SetPointSize( childValue
.GetLong() );
730 int fam
= childValue
.GetLong();
731 if ( fam
< wxDEFAULT
||
734 font
.SetFamily( fam
);
739 int faceIndex
= childValue
.GetLong();
741 if ( faceIndex
>= 0 )
742 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
744 font
.SetFaceName( faceName
);
748 int st
= childValue
.GetLong();
749 if ( st
!= wxFONTSTYLE_NORMAL
&&
750 st
!= wxFONTSTYLE_SLANT
&&
751 st
!= wxFONTSTYLE_ITALIC
)
752 st
= wxFONTWEIGHT_NORMAL
;
757 int wt
= childValue
.GetLong();
758 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
759 wt
!= wxFONTWEIGHT_LIGHT
&&
760 wt
!= wxFONTWEIGHT_BOLD
)
761 wt
= wxFONTWEIGHT_NORMAL
;
762 font
.SetWeight( wt
);
766 font
.SetUnderlined( childValue
.GetBool() );
769 wxVariant newVariant
;
775 wxSize wxFontProperty::OnMeasureImage() const
777 return wxSize(-1,-1);
780 void wxFontProperty::OnCustomPaint(wxDC& dc,
782 wxPGPaintData& paintData)
785 if ( paintData.m_choiceItem >= 0 )
786 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
788 drawFace = m_value_wxFont.GetFaceName();
790 if ( drawFace.length() )
792 // Draw the background
793 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
794 //dc.SetBrush( *wxWHITE_BRUSH );
795 //dc.SetPen( *wxMEDIUM_GREY_PEN );
796 dc.DrawRectangle( rect );
798 wxFont oldFont = dc.GetFont();
799 wxFont drawFont(oldFont.GetPointSize(),
800 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
801 dc.SetFont(drawFont);
803 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
804 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
810 // No file - just draw a white box
811 dc.SetBrush ( *wxWHITE_BRUSH );
812 dc.DrawRectangle ( rect );
818 // -----------------------------------------------------------------------
819 // wxSystemColourProperty
820 // -----------------------------------------------------------------------
822 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
823 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
825 #include "wx/colordlg.h"
827 //#define wx_cp_es_syscolours_len 25
828 static const wxChar
* gs_cp_es_syscolour_labels
[] = {
831 wxT("ActiveCaption"),
833 wxT("ButtonHighlight"),
842 wxT("HighlightText"),
843 wxT("InactiveBorder"),
844 wxT("InactiveCaption"),
845 wxT("InactiveCaptionText"),
857 static long gs_cp_es_syscolour_values
[] = {
858 wxSYS_COLOUR_APPWORKSPACE
,
859 wxSYS_COLOUR_ACTIVEBORDER
,
860 wxSYS_COLOUR_ACTIVECAPTION
,
861 wxSYS_COLOUR_BTNFACE
,
862 wxSYS_COLOUR_BTNHIGHLIGHT
,
863 wxSYS_COLOUR_BTNSHADOW
,
864 wxSYS_COLOUR_BTNTEXT
,
865 wxSYS_COLOUR_CAPTIONTEXT
,
866 wxSYS_COLOUR_3DDKSHADOW
,
867 wxSYS_COLOUR_3DLIGHT
,
868 wxSYS_COLOUR_BACKGROUND
,
869 wxSYS_COLOUR_GRAYTEXT
,
870 wxSYS_COLOUR_HIGHLIGHT
,
871 wxSYS_COLOUR_HIGHLIGHTTEXT
,
872 wxSYS_COLOUR_INACTIVEBORDER
,
873 wxSYS_COLOUR_INACTIVECAPTION
,
874 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
876 wxSYS_COLOUR_SCROLLBAR
,
878 wxSYS_COLOUR_INFOTEXT
,
880 wxSYS_COLOUR_WINDOWFRAME
,
881 wxSYS_COLOUR_WINDOWTEXT
,
886 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
889 // Class body is in advprops.h
891 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
892 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
895 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
897 wxColourPropertyValue cpv
;
900 cpv
.Init( type
, colour
);
902 cpv
.Init( type
, *wxWHITE
);
904 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
912 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
915 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
916 const wxColourPropertyValue
& value
)
917 : wxEnumProperty( label
,
919 gs_cp_es_syscolour_labels
,
920 gs_cp_es_syscolour_values
,
921 &gs_wxSystemColourProperty_choicesCache
)
924 Init( value
.m_type
, value
.m_colour
);
926 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
930 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
931 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
932 const wxColourPropertyValue
& value
)
933 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
936 Init( value
.m_type
, value
.m_colour
);
938 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
942 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
943 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
944 const wxColour
& value
)
945 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
948 Init( wxPG_COLOUR_CUSTOM
, value
);
950 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
954 wxSystemColourProperty::~wxSystemColourProperty() { }
957 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
962 if ( pVariant
->IsNull() )
963 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
965 if ( pVariant
->GetType() == wxS("wxColourPropertyValue") )
967 wxColourPropertyValue v
;
973 bool variantProcessed
= true;
975 if ( pVariant
->GetType() == wxS("wxColour*") )
977 wxColour
* pCol
= wxStaticCast(pVariant
->GetWxObjectPtr(), wxColour
);
980 else if ( pVariant
->GetType() == wxS("wxColour") )
984 else if ( pVariant
->GetType() == wxArrayInt_VariantType
)
986 // This code is mostly needed for wxPython bindings, which
987 // may offer tuple of integers as colour value.
991 if ( arr
.size() >= 3 )
999 if ( arr
.size() >= 4 )
1002 col
= wxColour(r
, g
, b
, a
);
1006 variantProcessed
= false;
1011 variantProcessed
= false;
1014 if ( !variantProcessed
)
1015 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
1017 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
1019 int colInd
= ColToInd(col
);
1020 if ( colInd
!= wxNOT_FOUND
)
1026 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1033 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
1036 size_t i_max
= m_choices
.GetCount();
1038 if ( !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1041 for ( i
=0; i
<i_max
; i
++ )
1043 int ind
= m_choices
[i
].GetValue();
1045 if ( colour
== GetColour(ind
) )
1047 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
1048 GetClassName(),GetLabel().c_str(),
1049 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
1050 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
1057 void wxSystemColourProperty::OnSetValue()
1059 // Convert from generic wxobject ptr to wxPGVariantDataColour
1060 if ( m_value
.GetType() == wxS("wxColour*") )
1062 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
1066 wxColourPropertyValue val
= GetVal(&m_value
);
1068 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
1076 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
1077 val
.m_colour
= GetColour( val
.m_type
);
1079 m_value
= TranslateVal(val
);
1082 int ind
= wxNOT_FOUND
;
1084 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
1086 wxColourPropertyValue cpv
;
1088 wxColour col
= cpv
.m_colour
;
1092 SetValueToUnspecified();
1093 SetIndex(wxNOT_FOUND
);
1097 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
||
1098 (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1100 ind
= GetIndexForValue(cpv
.m_type
);
1104 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
1105 ind
= GetCustomColourIndex();
1115 SetValueToUnspecified();
1116 SetIndex(wxNOT_FOUND
);
1120 ind
= ColToInd(col
);
1122 if ( ind
== wxNOT_FOUND
&&
1123 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1124 ind
= GetCustomColourIndex();
1131 wxColour
wxSystemColourProperty::GetColour( int index
) const
1133 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
1136 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
1138 if ( index
== wxNOT_FOUND
)
1139 return wxString::Format(wxT("(%i,%i,%i)"),
1144 return m_choices
.GetLabel(index
);
1147 wxString
wxSystemColourProperty::ValueToString( wxVariant
& value
,
1148 int argFlags
) const
1150 wxColourPropertyValue val
= GetVal(&value
);
1154 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1156 // GetIndex() only works reliably if wxPG_VALUE_IS_CURRENT flag is set,
1157 // but we should use it whenever possible.
1160 // If custom colour was selected, use invalid index, so that
1161 // ColourToString() will return properly formatted colour text.
1162 if ( index
== GetCustomColourIndex() &&
1163 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1164 index
= wxNOT_FOUND
;
1168 index
= m_choices
.Index(val
.m_type
);
1171 return ColourToString(val
.m_colour
, index
);
1175 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
1177 return wxPG_DEFAULT_IMAGE_SIZE
;
1181 int wxSystemColourProperty::GetCustomColourIndex() const
1183 return m_choices
.GetCount() - 1;
1187 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1189 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1192 wxPropertyGrid
* propgrid
= GetGrid();
1193 wxASSERT( propgrid
);
1195 // Must only occur when user triggers event
1196 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
) )
1199 wxColourPropertyValue val
= GetVal();
1201 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1204 data
.SetChooseFull(true);
1205 data
.SetColour(val
.m_colour
);
1207 for ( i
= 0; i
< 16; i
++)
1209 wxColour
colour(i
*16, i
*16, i
*16);
1210 data
.SetCustomColour(i
, colour
);
1213 wxColourDialog
dialog(propgrid
, &data
);
1214 if ( dialog
.ShowModal() == wxID_OK
)
1216 wxColourData retData
= dialog
.GetColourData();
1217 val
.m_colour
= retData
.GetColour();
1219 variant
= DoTranslateVal(val
);
1221 SetValueInEvent(variant
);
1230 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1233 int type
= m_choices
.GetValue(index
);
1235 if ( type
== wxPG_COLOUR_CUSTOM
)
1237 QueryColourFromUser(variant
);
1241 variant
= TranslateVal( type
, GetColour(type
) );
1247 // Need to do some extra event handling.
1248 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
,
1249 wxWindow
* WXUNUSED(primary
),
1252 bool askColour
= false;
1254 if ( propgrid
->IsMainButtonEvent(event
) )
1256 // We need to handle button click in case editor has been
1257 // switched to one that has wxButton as well.
1260 else if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
1262 // Must override index detection since at this point GetIndex()
1263 // will return old value.
1264 wxOwnerDrawnComboBox
* cb
=
1265 static_cast<wxOwnerDrawnComboBox
*>(propgrid
->GetEditorControl());
1269 int index
= cb
->GetSelection();
1271 if ( index
== GetCustomColourIndex() &&
1272 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1277 if ( askColour
&& !propgrid
->WasValueChangedInEvent() )
1280 if ( QueryColourFromUser(variant
) )
1286 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1289 virtual void Render( wxDC& dc, const wxRect& rect,
1290 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1291 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1293 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1294 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1296 dc.SetPen(*wxBLACK_PEN);
1298 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1302 const wxArrayInt& values = prop->GetValues();
1303 if ( values.GetChildCount() )
1304 colInd = values[item];
1307 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1309 else if ( !prop->IsValueUnspecified() )
1310 dc.SetBrush( prop->GetVal().m_colour );
1312 dc.SetBrush( *wxWHITE );
1314 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1315 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1316 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1317 imageRect.width, imageRect.height );
1321 text = property->GetValueAsString();
1323 text = property->GetChoiceString(item);
1324 DrawText( dc, rect, imageRect.width, text );
1329 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1331 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1334 return &g_wxPGColourPropertyRenderer;
1335 return wxEnumProperty::GetCellRenderer(column);
1338 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1339 wxPGPaintData
& paintdata
)
1343 if ( paintdata
.m_choiceItem
>= 0 &&
1344 paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1345 (paintdata
.m_choiceItem
!= GetCustomColourIndex() ||
1346 m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1348 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1349 col
= GetColour( colInd
);
1351 else if ( !IsValueUnspecified() )
1353 col
= GetVal().m_colour
;
1359 dc
.DrawRectangle(rect
);
1364 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1367 // Accept colour format "[Name] [(R,G,B)]"
1368 // Name takes precedence.
1370 wxString colourName
;
1373 int ppos
= text
.Find(wxT("("));
1375 if ( ppos
== wxNOT_FOUND
)
1381 colourName
= text
.substr(0, ppos
);
1382 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1385 // Strip spaces from extremities
1386 colourName
.Trim(true);
1387 colourName
.Trim(false);
1388 colourRGB
.Trim(true);
1390 // Validate colourRGB string - (1,1,1) is shortest allowed
1391 if ( colourRGB
.length() < 7 )
1394 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1395 !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) &&
1396 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1398 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1400 // This really should not occurr...
1406 QueryColourFromUser(value
);
1410 wxColourPropertyValue val
;
1414 if ( colourName
.length() )
1416 // Try predefined colour first
1417 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1418 if ( res
&& GetIndex() >= 0 )
1420 val
.m_type
= GetIndex();
1421 if ( val
.m_type
< m_choices
.GetCount() )
1422 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1424 // Get proper colour for type.
1425 val
.m_colour
= GetColour(val
.m_type
);
1430 if ( colourRGB
.length() && !done
)
1432 // Then check custom colour.
1433 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1435 int r
= -1, g
= -1, b
= -1;
1436 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1438 if ( r
>= 0 && r
<= 255 &&
1439 g
>= 0 && g
<= 255 &&
1440 b
>= 0 && b
<= 255 )
1442 val
.m_colour
.Set(r
,g
,b
);
1454 value
= DoTranslateVal(val
);
1461 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1463 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1465 int ival
= value
.GetLong();
1467 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1469 // Show custom choice
1470 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1471 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1473 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1475 // Hide custom choice
1476 m_choices
.RemoveAt(GetCustomColourIndex());
1477 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1485 // -----------------------------------------------------------------------
1487 // -----------------------------------------------------------------------
1489 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1509 (const wxChar
*) NULL
1512 static unsigned long gs_cp_es_normcolour_colours
[] = {
1514 wxPG_COLOUR(128,0,0),
1515 wxPG_COLOUR(0,0,128),
1516 wxPG_COLOUR(128,0,128),
1517 wxPG_COLOUR(0,128,128),
1518 wxPG_COLOUR(128,128,128),
1519 wxPG_COLOUR(0,128,0),
1520 wxPG_COLOUR(128,128,0),
1521 wxPG_COLOUR(166,124,81),
1522 wxPG_COLOUR(0,0,255),
1523 wxPG_COLOUR(255,0,255),
1524 wxPG_COLOUR(255,0,0),
1525 wxPG_COLOUR(247,148,28),
1526 wxPG_COLOUR(192,192,192),
1527 wxPG_COLOUR(0,255,0),
1528 wxPG_COLOUR(0,255,255),
1529 wxPG_COLOUR(255,255,0),
1530 wxPG_COLOUR(255,255,255),
1534 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxColourProperty
, wxSystemColourProperty
,
1535 wxColour
, const wxColour
&, TextCtrlAndButton
)
1537 static wxPGChoices gs_wxColourProperty_choicesCache
;
1539 wxColourProperty::wxColourProperty( const wxString
& label
,
1540 const wxString
& name
,
1541 const wxColour
& value
)
1542 : wxSystemColourProperty(label
, name
, gs_cp_es_normcolour_labels
,
1544 &gs_wxColourProperty_choicesCache
, value
)
1548 m_flags
|= wxPG_PROP_TRANSLATE_CUSTOM
;
1551 wxColourProperty::~wxColourProperty()
1555 void wxColourProperty::Init( wxColour colour
)
1562 int ind
= ColToInd(colour
);
1564 ind
= m_choices
.GetCount() - 1;
1568 wxString
wxColourProperty::ValueToString( wxVariant
& value
,
1569 int argFlags
) const
1571 const wxPGEditor
* editor
= GetEditorClass();
1572 if ( editor
!= wxPGEditor_Choice
&&
1573 editor
!= wxPGEditor_ChoiceAndButton
&&
1574 editor
!= wxPGEditor_ComboBox
)
1575 argFlags
|= wxPG_PROPERTY_SPECIFIC
;
1577 return wxSystemColourProperty::ValueToString(value
, argFlags
);
1580 wxColour
wxColourProperty::GetColour( int index
) const
1582 return gs_cp_es_normcolour_colours
[m_choices
.GetValue(index
)];
1585 wxVariant
wxColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1588 variant
<< v
.m_colour
;
1592 // -----------------------------------------------------------------------
1594 // -----------------------------------------------------------------------
1596 #define wxPG_CURSOR_IMAGE_WIDTH 32
1598 #define NUM_CURSORS 28
1600 //#define wx_cp_es_syscursors_len 28
1601 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1613 wxT("Middle Button"),
1619 wxT("Question Arrow"),
1620 wxT("Right Button"),
1621 wxT("Sizing NE-SW"),
1623 wxT("Sizing NW-SE"),
1630 (const wxChar
*) NULL
1633 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1636 wxCURSOR_RIGHT_ARROW
,
1643 wxCURSOR_LEFT_BUTTON
,
1645 wxCURSOR_MIDDLE_BUTTON
,
1647 wxCURSOR_PAINT_BRUSH
,
1649 wxCURSOR_POINT_LEFT
,
1650 wxCURSOR_POINT_RIGHT
,
1651 wxCURSOR_QUESTION_ARROW
,
1652 wxCURSOR_RIGHT_BUTTON
,
1664 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1666 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1668 : wxEnumProperty( label
,
1670 gs_cp_es_syscursors_labels
,
1671 gs_cp_es_syscursors_values
,
1674 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1677 wxCursorProperty::~wxCursorProperty()
1681 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1683 #if wxPG_CAN_DRAW_CURSOR
1684 if ( item
!= -1 && item
< NUM_CURSORS
)
1685 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1692 #if wxPG_CAN_DRAW_CURSOR
1694 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1696 wxPGPaintData
& paintdata
)
1699 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1701 if ( paintdata
.m_choiceItem
>= 0 )
1703 dc
.DrawRectangle( rect
);
1705 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1707 wxStockCursor cursorIndex
=
1708 (wxStockCursor
) gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1711 if ( cursorIndex
== wxCURSOR_NONE
)
1712 cursorIndex
= wxCURSOR_ARROW
;
1714 wxCursor
cursor( cursorIndex
);
1717 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1721 (HICON
)cursor
.GetHandle(),
1726 #if !defined(__WXWINCE__)
1727 DI_COMPAT
| DI_DEFAULTSIZE
|
1738 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1739 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1741 return wxEnumProperty::GetCellRenderer(column);
1745 // -----------------------------------------------------------------------
1746 // wxImageFileProperty
1747 // -----------------------------------------------------------------------
1751 const wxString
& wxPGGetDefaultImageWildcard()
1753 // Form the wildcard, if not done yet
1754 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1759 // TODO: This section may require locking (using global).
1761 wxList
& handlers
= wxImage::GetHandlers();
1763 wxList::iterator node
;
1765 // Let's iterate over the image handler list.
1766 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1767 for ( node
= handlers
.begin(); node
!= handlers
.end(); ++node
)
1769 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1771 wxString ext_lo
= handler
->GetExtension();
1772 wxString ext_up
= ext_lo
.Upper();
1774 str
.append( ext_up
);
1775 str
.append( wxT(" files (*.") );
1776 str
.append( ext_up
);
1777 str
.append( wxT(")|*.") );
1778 str
.append( ext_lo
);
1779 str
.append( wxT("|") );
1782 str
.append ( wxT("All files (*.*)|*.*") );
1784 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1787 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1790 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1792 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1793 const wxString
& value
)
1794 : wxFileProperty(label
,name
,value
)
1796 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1802 wxImageFileProperty::~wxImageFileProperty()
1810 void wxImageFileProperty::OnSetValue()
1812 wxFileProperty::OnSetValue();
1826 wxFileName filename
= GetFileName();
1828 // Create the image thumbnail
1829 if ( filename
.FileExists() )
1831 m_pImage
= new wxImage( filename
.GetFullPath() );
1835 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1837 return wxPG_DEFAULT_IMAGE_SIZE
;
1840 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1844 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1846 // Draw the thumbnail
1848 // Create the bitmap here because required size is not known in OnSetValue().
1851 m_pImage
->Rescale( rect
.width
, rect
.height
);
1852 m_pBitmap
= new wxBitmap( *m_pImage
);
1857 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1861 // No file - just draw a white box
1862 dc
.SetBrush( *wxWHITE_BRUSH
);
1863 dc
.DrawRectangle ( rect
);
1867 #endif // wxUSE_IMAGE
1869 // -----------------------------------------------------------------------
1870 // wxMultiChoiceProperty
1871 // -----------------------------------------------------------------------
1875 #include "wx/choicdlg.h"
1877 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1878 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1880 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1881 const wxString
& name
,
1882 const wxPGChoices
& choices
,
1883 const wxArrayString
& value
)
1884 : wxPGProperty(label
,name
)
1886 m_choices
.Assign(choices
);
1890 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1891 const wxString
& name
,
1892 const wxArrayString
& strings
,
1893 const wxArrayString
& value
)
1894 : wxPGProperty(label
,name
)
1896 m_choices
.Set(strings
);
1900 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1901 const wxString
& name
,
1902 const wxArrayString
& value
)
1903 : wxPGProperty(label
,name
)
1905 wxArrayString strings
;
1906 m_choices
.Set(strings
);
1910 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1914 void wxMultiChoiceProperty::OnSetValue()
1916 GenerateValueAsString(m_value
, &m_display
);
1919 wxString
wxMultiChoiceProperty::ValueToString( wxVariant
& value
,
1920 int argFlags
) const
1922 // If possible, use cached string
1923 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1927 GenerateValueAsString(value
, &s
);
1931 void wxMultiChoiceProperty::GenerateValueAsString( wxVariant
& value
,
1932 wxString
* target
) const
1934 wxArrayString strings
;
1936 if ( value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1937 strings
= value
.GetArrayString();
1939 wxString
& tempStr
= *target
;
1941 unsigned int itemCount
= strings
.size();
1946 tempStr
.append( wxT("\"") );
1948 for ( i
= 0; i
< itemCount
; i
++ )
1950 tempStr
.append( strings
[i
] );
1951 tempStr
.append( wxT("\"") );
1952 if ( i
< (itemCount
-1) )
1953 tempStr
.append ( wxT(" \"") );
1957 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1959 wxVariant variant
= GetValue();
1960 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(variant
);
1963 // Translate values to string indices.
1964 wxArrayInt selections
;
1966 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1968 for ( i
=0; i
<valueArr
.size(); i
++ )
1973 for ( i
=0; i
<valueArr
.size(); i
++ )
1975 int sIndex
= m_choices
.Index(valueArr
[i
]);
1977 selections
.Add(sIndex
);
1984 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1985 wxWindow
* WXUNUSED(primary
),
1988 if ( propgrid
->IsMainButtonEvent(event
) )
1991 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
1993 wxArrayString labels
= m_choices
.GetLabels();
1994 unsigned int choiceCount
;
1996 if ( m_choices
.IsOk() )
1997 choiceCount
= m_choices
.GetCount();
2001 // launch editor dialog
2002 wxMultiChoiceDialog
dlg( propgrid
,
2003 _("Make a selection:"),
2006 choiceCount
?&labels
[0]:NULL
,
2007 wxCHOICEDLG_STYLE
);
2009 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
2011 wxArrayString strings
= useValue
.GetArrayString();
2012 wxArrayString extraStrings
;
2014 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
2016 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
2018 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
2020 wxArrayInt arrInt
= dlg
.GetSelections();
2024 // Strings that were not in list of choices
2025 wxArrayString value
;
2027 // Translate string indices to strings
2030 if ( userStringMode
== 1 )
2032 for (n
=0;n
<extraStrings
.size();n
++)
2033 value
.push_back(extraStrings
[n
]);
2037 for ( i
=0; i
<arrInt
.size(); i
++ )
2038 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
2040 if ( userStringMode
== 2 )
2042 for (n
=0;n
<extraStrings
.size();n
++)
2043 value
.push_back(extraStrings
[n
]);
2046 variant
= WXVARIANT(value
);
2048 SetValueInEvent(variant
);
2056 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
2060 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
2062 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
2063 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
2065 WX_PG_TOKENIZER2_END()
2067 wxVariant
v( WXVARIANT(arr
) );
2073 #endif // wxUSE_CHOICEDLG
2076 // -----------------------------------------------------------------------
2078 // -----------------------------------------------------------------------
2083 #if wxUSE_DATEPICKCTRL
2084 #define dtCtrl DatePickerCtrl
2086 #define dtCtrl TextCtrl
2089 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
2096 wxString
wxDateProperty::ms_defaultDateFormat
;
2099 wxDateProperty::wxDateProperty( const wxString
& label
,
2100 const wxString
& name
,
2101 const wxDateTime
& value
)
2102 : wxPGProperty(label
,name
)
2104 //wxPGRegisterDefaultValueType(wxDateTime)
2106 #if wxUSE_DATEPICKCTRL
2107 wxPGRegisterEditorClass(DatePickerCtrl
);
2109 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
2117 wxDateProperty::~wxDateProperty()
2121 void wxDateProperty::OnSetValue()
2124 // Convert invalid dates to unspecified value
2125 if ( m_value
.GetType() == wxT("datetime") )
2127 if ( !m_value
.GetDateTime().IsValid() )
2132 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
2133 int WXUNUSED(argFlags
) ) const
2137 // FIXME: do we really want to return true from here if only part of the
2138 // string was parsed?
2139 const char* c
= dt
.ParseFormat(text
);
2150 wxString
wxDateProperty::ValueToString( wxVariant
& value
,
2151 int argFlags
) const
2153 const wxChar
* format
= (const wxChar
*) NULL
;
2155 wxDateTime dateTime
= value
.GetDateTime();
2157 if ( !dateTime
.IsValid() )
2158 return wxT("Invalid");
2160 if ( !ms_defaultDateFormat
.length() )
2162 #if wxUSE_DATEPICKCTRL
2163 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
2165 bool showCentury
= true;
2167 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
2170 if ( m_format
.length() &&
2171 !(argFlags
& wxPG_FULL_VALUE
) )
2172 format
= m_format
.c_str();
2174 // Determine default from locale
2175 // NB: This is really simple stuff, but can't figure anything
2176 // better without proper support in wxLocale
2178 format
= ms_defaultDateFormat
.c_str();
2180 return dateTime
.Format(format
);
2183 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
2185 // This code is basicly copied from datectlg.cpp's SetFormat
2190 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
2191 wxString
str(dt
.Format(wxT("%x")));
2193 const wxChar
*p
= str
.c_str();
2197 if (n
== dt
.GetDay())
2199 format
.Append(wxT("%d"));
2202 else if (n
== (int)dt
.GetMonth()+1)
2204 format
.Append(wxT("%m"));
2207 else if (n
== dt
.GetYear())
2209 format
.Append(wxT("%Y"));
2212 else if (n
== (dt
.GetYear() % 100))
2215 format
.Append(wxT("%Y"));
2217 format
.Append(wxT("%y"));
2221 format
.Append(*p
++);
2227 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
2229 if ( name
== wxPG_DATE_FORMAT
)
2231 m_format
= value
.GetString();
2234 else if ( name
== wxPG_DATE_PICKER_STYLE
)
2236 m_dpStyle
= value
.GetLong();
2237 ms_defaultDateFormat
.clear(); // This may need recalculation
2243 #endif // wxUSE_DATETIME
2246 // -----------------------------------------------------------------------
2247 // wxPropertyGridInterface
2248 // -----------------------------------------------------------------------
2250 void wxPropertyGridInterface::InitAllTypeHandlers()
2254 // -----------------------------------------------------------------------
2256 void wxPropertyGridInterface::RegisterAdditionalEditors()
2258 // Register editor classes, if necessary.
2259 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
2260 wxPropertyGrid::RegisterDefaultEditors();
2263 wxPGRegisterEditorClass(SpinCtrl
);
2265 #if wxUSE_DATEPICKCTRL
2266 wxPGRegisterEditorClass(DatePickerCtrl
);
2270 // -----------------------------------------------------------------------
2272 #endif // wxPG_INCLUDE_ADVPROPS
2274 #endif // wxUSE_PROPGRID