1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/advprops.cpp
3 // Purpose: wxPropertyGrid Advanced Properties (font, colour, etc.)
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcclient.h"
32 #include "wx/button.h"
35 #include "wx/cursor.h"
36 #include "wx/dialog.h"
37 #include "wx/settings.h"
38 #include "wx/msgdlg.h"
39 #include "wx/choice.h"
40 #include "wx/stattext.h"
41 #include "wx/textctrl.h"
42 #include "wx/scrolwin.h"
43 #include "wx/dirdlg.h"
44 #include "wx/combobox.h"
46 #include "wx/textdlg.h"
47 #include "wx/filedlg.h"
49 #include "wx/wxcrtvararg.h"
52 #define __wxPG_SOURCE_FILE__
54 #include "wx/propgrid/propgrid.h"
56 #if wxPG_INCLUDE_ADVPROPS
58 #include "wx/propgrid/advprops.h"
61 #include "wx/msw/private.h"
62 #include "wx/msw/dc.h"
65 // -----------------------------------------------------------------------
67 #if defined(__WXMSW__)
68 #define wxPG_CAN_DRAW_CURSOR 1
69 #elif defined(__WXGTK__)
70 #define wxPG_CAN_DRAW_CURSOR 0
71 #elif defined(__WXMAC__)
72 #define wxPG_CAN_DRAW_CURSOR 0
74 #define wxPG_CAN_DRAW_CURSOR 0
78 // -----------------------------------------------------------------------
80 // -----------------------------------------------------------------------
83 // Implement dynamic class for type value.
84 IMPLEMENT_DYNAMIC_CLASS(wxColourPropertyValue
, wxObject
)
86 bool operator == (const wxColourPropertyValue
& a
, const wxColourPropertyValue
& b
)
88 return ( ( a
.m_colour
== b
.m_colour
) && (a
.m_type
== b
.m_type
) );
91 bool operator == (const wxArrayInt
& array1
, const wxArrayInt
& array2
)
93 if ( array1
.size() != array2
.size() )
96 for ( i
=0; i
<array1
.size(); i
++ )
98 if ( array1
[i
] != array2
[i
] )
104 // -----------------------------------------------------------------------
105 // wxSpinCtrl-based property editor
106 // -----------------------------------------------------------------------
112 // This class implements ability to rapidly change "spin" value
113 // by moving mouse when one of the spin buttons is depressed.
114 class wxPGSpinButton
: public wxSpinButton
117 wxPGSpinButton() : wxSpinButton()
120 m_hasCapture
= false;
123 Connect( wxEVT_LEFT_DOWN
,
124 wxMouseEventHandler(wxPGSpinButton::OnMouseEvent
) );
125 Connect( wxEVT_LEFT_UP
,
126 wxMouseEventHandler(wxPGSpinButton::OnMouseEvent
) );
127 Connect( wxEVT_MOTION
,
128 wxMouseEventHandler(wxPGSpinButton::OnMouseEvent
) );
129 Connect( wxEVT_MOUSE_CAPTURE_LOST
,
130 wxMouseCaptureLostEventHandler(wxPGSpinButton::OnMouseCaptureLost
) );
139 wxPoint m_ptPosition
;
141 // Having a separate spins variable allows us to handle validation etc. for
142 // multiple spin events at once (with quick mouse movements there could be
143 // hundreds of 'spins' being done at once). Technically things like this
144 // should be stored in event (wxSpinEvent in this case), but there probably
145 // isn't anything there that can be reliably reused.
150 // SpinButton seems to be a special for mouse capture, so we may need track
151 // privately whether mouse is actually captured.
162 SetCursor(wxCURSOR_SIZENS
);
171 m_hasCapture
= false;
174 wxWindow
*parent
= GetParent();
176 SetCursor(parent
->GetCursor());
178 SetCursor(wxNullCursor
);
181 void OnMouseEvent(wxMouseEvent
& event
)
183 if ( event
.GetEventType() == wxEVT_LEFT_DOWN
)
186 m_ptPosition
= event
.GetPosition();
188 else if ( event
.GetEventType() == wxEVT_LEFT_UP
)
193 else if ( event
.GetEventType() == wxEVT_MOTION
)
197 int dy
= m_ptPosition
.y
- event
.GetPosition().y
;
201 m_ptPosition
= event
.GetPosition();
203 wxSpinEvent
evtscroll( (dy
>= 0) ? wxEVT_SCROLL_LINEUP
:
204 wxEVT_SCROLL_LINEDOWN
,
206 evtscroll
.SetEventObject(this);
208 wxASSERT( m_spins
== 1 );
211 GetEventHandler()->ProcessEvent(evtscroll
);
219 void OnMouseCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
226 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(SpinCtrl
,
231 // Trivial destructor.
232 wxPGSpinCtrlEditor::~wxPGSpinCtrlEditor()
237 // Create controls and initialize event handling.
238 wxPGWindowList
wxPGSpinCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
239 const wxPoint
& pos
, const wxSize
& sz
) const
241 const int margin
= 1;
242 wxSize
butSz(18, sz
.y
);
243 wxSize
tcSz(sz
.x
- butSz
.x
- margin
, sz
.y
);
244 wxPoint
butPos(pos
.x
+ tcSz
.x
+ margin
, pos
.y
);
248 wnd2
= new wxPGSpinButton();
253 wnd2
->Create( propgrid
->GetPanel(), wxPG_SUBID2
, butPos
, butSz
, wxSP_VERTICAL
);
255 wnd2
->SetRange( INT_MIN
, INT_MAX
);
258 // Let's add validator to make sure only numbers can be entered
259 wxTextValidator
validator(wxFILTER_NUMERIC
, &m_tempString
);
261 wxTextCtrl
* wnd1
= (wxTextCtrl
*) wxPGTextCtrlEditor::CreateControls( propgrid
, property
, pos
, tcSz
).m_primary
;
262 wnd1
->SetValidator(validator
);
264 return wxPGWindowList(wnd1
, wnd2
);
267 // Control's events are redirected here
268 bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
269 wxWindow
* wnd
, wxEvent
& event
) const
271 int evtType
= event
.GetEventType();
274 bool bigStep
= false;
276 if ( evtType
== wxEVT_KEY_DOWN
)
278 wxKeyEvent
& keyEvent
= (wxKeyEvent
&)event
;
279 keycode
= keyEvent
.GetKeyCode();
281 if ( keycode
== WXK_UP
)
282 evtType
= wxEVT_SCROLL_LINEUP
;
283 else if ( keycode
== WXK_DOWN
)
284 evtType
= wxEVT_SCROLL_LINEDOWN
;
285 else if ( keycode
== WXK_PAGEUP
)
287 evtType
= wxEVT_SCROLL_LINEUP
;
290 else if ( keycode
== WXK_PAGEDOWN
)
292 evtType
= wxEVT_SCROLL_LINEDOWN
;
297 if ( evtType
== wxEVT_SCROLL_LINEUP
|| evtType
== wxEVT_SCROLL_LINEDOWN
)
299 wxPGSpinButton
* spinButton
=
300 (wxPGSpinButton
*) propgrid
->GetEditorControlSecondary();
303 spins
= spinButton
->GetSpins();
306 // Can't use wnd since it might be clipper window
307 wxTextCtrl
* tc
= wxDynamicCast(propgrid
->GetEditorControl(), wxTextCtrl
);
312 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
314 int mode
= wxPG_PROPERTY_VALIDATION_SATURATE
;
316 if ( property
->GetAttributeAsLong(wxT("Wrap"), 0) )
317 mode
= wxPG_PROPERTY_VALIDATION_WRAP
;
319 if ( property
->GetValueType() == wxT("double") )
322 double step
= property
->GetAttributeAsDouble(wxT("Step"), 1.0);
325 if ( s
.ToDouble(&v_d
) )
330 step
*= (double) spins
;
332 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_d
+= step
;
336 wxFloatProperty::DoValidation(property
, v_d
, NULL
, mode
);
338 wxPropertyGrid::DoubleToString(s
, v_d
, 6, true, NULL
);
348 wxLongLong_t step
= property
->GetAttributeAsLong(wxT("Step"), 1);
351 if ( s
.ToLongLong(&v_ll
, 10) )
358 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_ll
+= step
;
362 wxIntProperty::DoValidation(property
, v_ll
, NULL
, mode
);
364 s
= wxLongLong(v_ll
).ToString();
374 int ip
= tc
->GetInsertionPoint();
375 int lp
= tc
->GetLastPosition();
377 tc
->SetInsertionPoint(ip
+(tc
->GetLastPosition()-lp
));
383 return wxPGTextCtrlEditor::OnEvent(propgrid
,property
,wnd
,event
);
386 #endif // wxUSE_SPINBTN
389 // -----------------------------------------------------------------------
390 // wxDatePickerCtrl-based property editor
391 // -----------------------------------------------------------------------
393 #if wxUSE_DATEPICKCTRL
396 #include "wx/datectrl.h"
397 #include "wx/dateevt.h"
399 class wxPGDatePickerCtrlEditor
: public wxPGEditor
401 DECLARE_DYNAMIC_CLASS(wxPGDatePickerCtrlEditor
)
403 virtual ~wxPGDatePickerCtrlEditor();
405 wxString
GetName() const;
406 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
407 wxPGProperty
* property
,
409 const wxSize
& size
) const;
410 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const;
411 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
412 wxWindow
* wnd
, wxEvent
& event
) const;
413 virtual bool GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* wnd
) const;
414 virtual void SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const;
418 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(DatePickerCtrl
,
419 wxPGDatePickerCtrlEditor
,
423 wxPGDatePickerCtrlEditor::~wxPGDatePickerCtrlEditor()
427 wxPGWindowList
wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
,
428 wxPGProperty
* property
,
430 const wxSize
& sz
) const
432 wxCHECK_MSG( property
->IsKindOf(CLASSINFO(wxDateProperty
)),
434 wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
436 wxDateProperty
* prop
= (wxDateProperty
*) property
;
438 // Use two stage creation to allow cleaner display on wxMSW
439 wxDatePickerCtrl
* ctrl
= new wxDatePickerCtrl();
442 wxSize useSz
= wxDefaultSize
;
448 wxDateTime
dateValue(wxInvalidDateTime
);
450 wxVariant value
= prop
->GetValue();
451 if ( value
.GetType() == wxT("datetime") )
452 dateValue
= value
.GetDateTime();
454 ctrl
->Create(propgrid
->GetPanel(),
459 prop
->GetDatePickerStyle() | wxNO_BORDER
);
468 // Copies value from property to control
469 void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const
471 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
472 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
474 // We assume that property's data type is 'int' (or something similar),
475 // thus allowing us to get raw, unchecked value via DoGetValue.
476 ctrl
->SetValue( property
->GetValue().GetDateTime() );
479 // Control's events are redirected here
480 bool wxPGDatePickerCtrlEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propgrid
),
481 wxPGProperty
* WXUNUSED(property
),
482 wxWindow
* WXUNUSED(wnd
),
483 wxEvent
& event
) const
485 if ( event
.GetEventType() == wxEVT_DATE_CHANGED
)
491 bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const
493 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
494 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
496 variant
= ctrl
->GetValue();
501 void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* WXUNUSED(wnd
) ) const
504 //wxDateProperty* prop = (wxDateProperty*) property;
508 #endif // wxUSE_DATEPICKCTRL
511 // -----------------------------------------------------------------------
513 // -----------------------------------------------------------------------
515 #include "wx/fontdlg.h"
516 #include "wx/fontenum.h"
518 static const wxChar
* gs_fp_es_family_labels
[] = {
519 wxT("Default"), wxT("Decorative"),
520 wxT("Roman"), wxT("Script"),
521 wxT("Swiss"), wxT("Modern"),
525 static long gs_fp_es_family_values
[] = {
526 wxDEFAULT
, wxDECORATIVE
,
531 static const wxChar
* gs_fp_es_style_labels
[] = {
538 static long gs_fp_es_style_values
[] = {
544 static const wxChar
* gs_fp_es_weight_labels
[] = {
551 static long gs_fp_es_weight_values
[] = {
557 // Class body is in advprops.h
560 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty
,wxPGProperty
,
561 wxFont
,const wxFont
&,TextCtrlAndButton
)
564 wxFontProperty::wxFontProperty( const wxString
& label
, const wxString
& name
,
565 const wxFont
& value
)
566 : wxPGProperty(label
,name
)
568 SetValue(WXVARIANT(value
));
570 // Initialize font family choices list
571 if ( !wxPGGlobalVars
->m_fontFamilyChoices
)
573 wxArrayString faceNames
= wxFontEnumerator::GetFacenames();
577 wxPGGlobalVars
->m_fontFamilyChoices
= new wxPGChoices(faceNames
);
580 wxString
emptyString(wxEmptyString
);
585 SetParentalType(wxPG_PROP_AGGREGATE
);
587 AddChild( new wxIntProperty( _("Point Size"), wxS("Point Size"),(long)font
.GetPointSize() ) );
589 AddChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
590 gs_fp_es_family_labels
,gs_fp_es_family_values
,
593 wxString faceName
= font
.GetFaceName();
594 // If font was not in there, add it now
595 if ( faceName
.length() &&
596 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
597 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
599 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"), wxS("Face Name"),
600 *wxPGGlobalVars
->m_fontFamilyChoices
);
602 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
606 AddChild( new wxEnumProperty(_("Style"), wxS("Style"),
607 gs_fp_es_style_labels
,gs_fp_es_style_values
,font
.GetStyle()) );
609 AddChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
610 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,font
.GetWeight()) );
612 AddChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
613 font
.GetUnderlined()) );
616 wxFontProperty::~wxFontProperty() { }
618 void wxFontProperty::OnSetValue()
625 font
= wxFont(10,wxSWISS
,wxNORMAL
,wxNORMAL
);
630 wxString
wxFontProperty::ValueToString( wxVariant
& value
,
633 return wxPGProperty::ValueToString(value
, argFlags
);
636 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
639 if ( propgrid
->IsMainButtonEvent(event
) )
641 // Update value from last minute changes
642 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
647 data
.SetInitialFont( font
);
648 data
.SetColour(*wxBLACK
);
650 wxFontDialog
dlg(propgrid
, data
);
651 if ( dlg
.ShowModal() == wxID_OK
)
653 propgrid
->EditorsValueWasModified();
656 variant
<< dlg
.GetFontData().GetChosenFont();
657 SetValueInEvent( variant
);
664 void wxFontProperty::RefreshChildren()
666 if ( !GetChildCount() ) return;
669 Item(0)->SetValue( (long)font
.GetPointSize() );
670 Item(1)->SetValue( (long)font
.GetFamily() );
671 Item(2)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
672 Item(3)->SetValue( (long)font
.GetStyle() );
673 Item(4)->SetValue( (long)font
.GetWeight() );
674 Item(5)->SetValue( font
.GetUnderlined() );
677 void wxFontProperty::ChildChanged( wxVariant
& thisValue
, int ind
, wxVariant
& childValue
) const
684 font
.SetPointSize( wxPGVariantToInt(childValue
) );
688 int fam
= childValue
.GetLong();
689 if ( fam
< wxDEFAULT
||
692 font
.SetFamily( fam
);
697 int faceIndex
= childValue
.GetLong();
699 if ( faceIndex
>= 0 )
700 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
702 font
.SetFaceName( faceName
);
706 int st
= childValue
.GetLong();
707 if ( st
!= wxFONTSTYLE_NORMAL
&&
708 st
!= wxFONTSTYLE_SLANT
&&
709 st
!= wxFONTSTYLE_ITALIC
)
710 st
= wxFONTWEIGHT_NORMAL
;
715 int wt
= childValue
.GetLong();
716 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
717 wt
!= wxFONTWEIGHT_LIGHT
&&
718 wt
!= wxFONTWEIGHT_BOLD
)
719 wt
= wxFONTWEIGHT_NORMAL
;
720 font
.SetWeight( wt
);
724 font
.SetUnderlined( childValue
.GetBool() );
731 wxSize wxFontProperty::OnMeasureImage() const
733 return wxSize(-1,-1);
736 void wxFontProperty::OnCustomPaint(wxDC& dc,
738 wxPGPaintData& paintData)
741 if ( paintData.m_choiceItem >= 0 )
742 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
744 drawFace = m_value_wxFont.GetFaceName();
746 if ( drawFace.length() )
748 // Draw the background
749 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
750 //dc.SetBrush( *wxWHITE_BRUSH );
751 //dc.SetPen( *wxMEDIUM_GREY_PEN );
752 dc.DrawRectangle( rect );
754 wxFont oldFont = dc.GetFont();
755 wxFont drawFont(oldFont.GetPointSize(),
756 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
757 dc.SetFont(drawFont);
759 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
760 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
766 // No file - just draw a white box
767 dc.SetBrush ( *wxWHITE_BRUSH );
768 dc.DrawRectangle ( rect );
774 // -----------------------------------------------------------------------
775 // wxSystemColourProperty
776 // -----------------------------------------------------------------------
778 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
779 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
781 #include "wx/colordlg.h"
783 //#define wx_cp_es_syscolours_len 25
784 static const wxChar
* gs_cp_es_syscolour_labels
[] = {
787 wxT("ActiveCaption"),
789 wxT("ButtonHighlight"),
798 wxT("HighlightText"),
799 wxT("InactiveBorder"),
800 wxT("InactiveCaption"),
801 wxT("InactiveCaptionText"),
813 static long gs_cp_es_syscolour_values
[] = {
814 wxSYS_COLOUR_APPWORKSPACE
,
815 wxSYS_COLOUR_ACTIVEBORDER
,
816 wxSYS_COLOUR_ACTIVECAPTION
,
817 wxSYS_COLOUR_BTNFACE
,
818 wxSYS_COLOUR_BTNHIGHLIGHT
,
819 wxSYS_COLOUR_BTNSHADOW
,
820 wxSYS_COLOUR_BTNTEXT
,
821 wxSYS_COLOUR_CAPTIONTEXT
,
822 wxSYS_COLOUR_3DDKSHADOW
,
823 wxSYS_COLOUR_3DLIGHT
,
824 wxSYS_COLOUR_BACKGROUND
,
825 wxSYS_COLOUR_GRAYTEXT
,
826 wxSYS_COLOUR_HIGHLIGHT
,
827 wxSYS_COLOUR_HIGHLIGHTTEXT
,
828 wxSYS_COLOUR_INACTIVEBORDER
,
829 wxSYS_COLOUR_INACTIVECAPTION
,
830 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
832 wxSYS_COLOUR_SCROLLBAR
,
834 wxSYS_COLOUR_INFOTEXT
,
836 wxSYS_COLOUR_WINDOWFRAME
,
837 wxSYS_COLOUR_WINDOWTEXT
,
842 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
845 // Class body is in advprops.h
847 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
848 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
851 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
853 wxColourPropertyValue cpv
;
856 cpv
.Init( type
, colour
);
858 cpv
.Init( type
, *wxWHITE
);
860 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
868 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
871 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
872 const wxColourPropertyValue
& value
)
873 : wxEnumProperty( label
,
875 gs_cp_es_syscolour_labels
,
876 gs_cp_es_syscolour_values
,
877 &gs_wxSystemColourProperty_choicesCache
)
880 Init( value
.m_type
, value
.m_colour
);
882 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
886 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
887 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
888 const wxColourPropertyValue
& value
)
889 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
892 Init( value
.m_type
, value
.m_colour
);
894 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
898 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
899 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
900 const wxColour
& value
)
901 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
904 Init( wxPG_COLOUR_CUSTOM
, value
);
906 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
910 wxSystemColourProperty::~wxSystemColourProperty() { }
913 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
918 if ( pVariant
->IsNull() )
919 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
921 if ( pVariant
->GetType() == wxS("wxColourPropertyValue") )
923 wxColourPropertyValue v
;
929 bool variantProcessed
= true;
931 if ( pVariant
->GetType() == wxS("wxColour*") )
933 wxColour
* pCol
= wxStaticCast(pVariant
->GetWxObjectPtr(), wxColour
);
936 else if ( pVariant
->GetType() == wxS("wxColour") )
940 else if ( pVariant
->GetType() == wxArrayInt_VariantType
)
942 // This code is mostly needed for wxPython bindings, which
943 // may offer tuple of integers as colour value.
947 if ( arr
.size() >= 3 )
955 if ( arr
.size() >= 4 )
958 col
= wxColour(r
, g
, b
, a
);
962 variantProcessed
= false;
967 variantProcessed
= false;
970 if ( !variantProcessed
)
971 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
973 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
975 int colInd
= ColToInd(col
);
976 if ( colInd
!= wxNOT_FOUND
)
982 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
989 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
992 size_t i_max
= m_choices
.GetCount() - 1;
994 for ( i
=0; i
<i_max
; i
++ )
996 int ind
= m_choices
[i
].GetValue();
998 if ( colour
== GetColour(ind
) )
1000 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
1001 GetClassName(),GetLabel().c_str(),
1002 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
1003 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
1010 void wxSystemColourProperty::OnSetValue()
1012 // Convert from generic wxobject ptr to wxPGVariantDataColour
1013 if ( m_value
.GetType() == wxS("wxColour*") )
1015 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
1019 wxColourPropertyValue val
= GetVal(&m_value
);
1021 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
1029 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
1030 val
.m_colour
= GetColour( val
.m_type
);
1032 m_value
= TranslateVal(val
);
1035 int ind
= wxNOT_FOUND
;
1037 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
1039 wxColourPropertyValue cpv
;
1041 wxColour col
= cpv
.m_colour
;
1045 SetValueToUnspecified();
1046 SetIndex(wxNOT_FOUND
);
1050 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
)
1052 ind
= GetIndexForValue(cpv
.m_type
);
1056 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
1057 ind
= GetCustomColourIndex();
1067 SetValueToUnspecified();
1068 SetIndex(wxNOT_FOUND
);
1072 ind
= ColToInd(col
);
1074 if ( ind
== wxNOT_FOUND
)
1075 ind
= GetCustomColourIndex();
1082 wxColour
wxSystemColourProperty::GetColour( int index
) const
1084 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
1087 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
1089 if ( index
== wxNOT_FOUND
)
1090 return wxString::Format(wxT("(%i,%i,%i)"),
1095 return m_choices
.GetLabel(index
);
1098 wxString
wxSystemColourProperty::ValueToString( wxVariant
& value
,
1099 int argFlags
) const
1101 wxColourPropertyValue val
= GetVal(&value
);
1105 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1107 // GetIndex() only works reliably if wxPG_VALUE_IS_CURRENT flag is set,
1108 // but we should use it whenever possible.
1111 // If custom colour was selected, use invalid index, so that
1112 // ColourToString() will return properly formatted colour text.
1113 if ( index
== GetCustomColourIndex() )
1114 index
= wxNOT_FOUND
;
1118 index
= m_choices
.Index(val
.m_type
);
1121 return ColourToString(val
.m_colour
, index
);
1125 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
1127 return wxPG_DEFAULT_IMAGE_SIZE
;
1131 int wxSystemColourProperty::GetCustomColourIndex() const
1133 return m_choices
.GetCount() - 1;
1137 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1139 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1142 wxPropertyGrid
* propgrid
= GetGrid();
1143 wxASSERT( propgrid
);
1145 // Must only occur when user triggers event
1146 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
) )
1149 wxColourPropertyValue val
= GetVal();
1151 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1154 data
.SetChooseFull(true);
1155 data
.SetColour(val
.m_colour
);
1157 for ( i
= 0; i
< 16; i
++)
1159 wxColour
colour(i
*16, i
*16, i
*16);
1160 data
.SetCustomColour(i
, colour
);
1163 wxColourDialog
dialog(propgrid
, &data
);
1164 if ( dialog
.ShowModal() == wxID_OK
)
1166 wxColourData retData
= dialog
.GetColourData();
1167 val
.m_colour
= retData
.GetColour();
1169 variant
= DoTranslateVal(val
);
1171 SetValueInEvent(variant
);
1180 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1183 int type
= m_choices
.GetValue(index
);
1185 if ( type
== wxPG_COLOUR_CUSTOM
)
1187 QueryColourFromUser(variant
);
1191 variant
= TranslateVal( type
, GetColour(type
) );
1197 // Need to do some extra event handling.
1198 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
), wxEvent
& event
)
1200 if ( propgrid
->IsMainButtonEvent(event
) )
1202 // We need to handle button click in case editor has been
1203 // switched to one that has wxButton as well.
1205 if ( QueryColourFromUser(variant
) )
1211 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1214 virtual void Render( wxDC& dc, const wxRect& rect,
1215 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1216 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1218 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1219 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1221 dc.SetPen(*wxBLACK_PEN);
1223 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1227 const wxArrayInt& values = prop->GetValues();
1228 if ( values.GetChildCount() )
1229 colInd = values[item];
1232 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1234 else if ( !prop->IsValueUnspecified() )
1235 dc.SetBrush( prop->GetVal().m_colour );
1237 dc.SetBrush( *wxWHITE );
1239 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1240 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1241 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1242 imageRect.width, imageRect.height );
1246 text = property->GetValueAsString();
1248 text = property->GetChoiceString(item);
1249 DrawText( dc, rect, imageRect.width, text );
1254 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1256 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1259 return &g_wxPGColourPropertyRenderer;
1260 return wxEnumProperty::GetCellRenderer(column);
1263 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1264 wxPGPaintData
& paintdata
)
1268 if ( paintdata
.m_choiceItem
>= 0 && paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1269 paintdata
.m_choiceItem
!= GetCustomColourIndex() )
1271 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1272 col
= GetColour( colInd
);
1274 else if ( !IsValueUnspecified() )
1276 col
= GetVal().m_colour
;
1282 dc
.DrawRectangle(rect
);
1287 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1290 // Accept colour format "[Name] [(R,G,B)]"
1291 // Name takes precedence.
1293 wxString colourName
;
1296 int ppos
= text
.Find(wxT("("));
1298 if ( ppos
== wxNOT_FOUND
)
1304 colourName
= text
.substr(0, ppos
);
1305 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1308 // Strip spaces from extremities
1309 colourName
.Trim(true);
1310 colourName
.Trim(false);
1311 colourRGB
.Trim(true);
1313 // Validate colourRGB string - (1,1,1) is shortest allowed
1314 if ( colourRGB
.length() < 7 )
1317 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1318 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1320 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1322 // This really should not occurr...
1328 QueryColourFromUser(value
);
1332 wxColourPropertyValue val
;
1336 if ( colourName
.length() )
1338 // Try predefined colour first
1339 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1340 if ( res
&& GetIndex() >= 0 )
1342 val
.m_type
= GetIndex();
1343 if ( val
.m_type
< m_choices
.GetCount() )
1344 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1346 // Get proper colour for type.
1347 val
.m_colour
= GetColour(val
.m_type
);
1352 if ( colourRGB
.length() && !done
)
1354 // Then check custom colour.
1355 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1357 int r
= -1, g
= -1, b
= -1;
1358 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1360 if ( r
>= 0 && r
<= 255 &&
1361 g
>= 0 && g
<= 255 &&
1362 b
>= 0 && b
<= 255 )
1364 val
.m_colour
.Set(r
,g
,b
);
1376 value
= DoTranslateVal(val
);
1383 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1385 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1387 int ival
= wxPGVariantToInt(value
);
1389 SetChoicesExclusive(); // Make sure we don't corrupt colour lists of other properties
1391 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1393 // Show custom choice
1394 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1395 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1397 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1399 // Hide custom choice
1400 m_choices
.RemoveAt(GetCustomColourIndex());
1401 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1409 // -----------------------------------------------------------------------
1411 // -----------------------------------------------------------------------
1413 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1433 (const wxChar
*) NULL
1436 static unsigned long gs_cp_es_normcolour_colours
[] = {
1438 wxPG_COLOUR(128,0,0),
1439 wxPG_COLOUR(0,0,128),
1440 wxPG_COLOUR(128,0,128),
1441 wxPG_COLOUR(0,128,128),
1442 wxPG_COLOUR(128,128,128),
1443 wxPG_COLOUR(0,128,0),
1444 wxPG_COLOUR(128,128,0),
1445 wxPG_COLOUR(166,124,81),
1446 wxPG_COLOUR(0,0,255),
1447 wxPG_COLOUR(255,0,255),
1448 wxPG_COLOUR(255,0,0),
1449 wxPG_COLOUR(247,148,28),
1450 wxPG_COLOUR(192,192,192),
1451 wxPG_COLOUR(0,255,0),
1452 wxPG_COLOUR(0,255,255),
1453 wxPG_COLOUR(255,255,0),
1454 wxPG_COLOUR(255,255,255),
1458 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxColourProperty
, wxSystemColourProperty
,
1459 wxColour
, const wxColour
&, TextCtrlAndButton
)
1461 static wxPGChoices gs_wxColourProperty_choicesCache
;
1463 wxColourProperty::wxColourProperty( const wxString
& label
,
1464 const wxString
& name
,
1465 const wxColour
& value
)
1466 : wxSystemColourProperty(label
, name
, gs_cp_es_normcolour_labels
,
1468 &gs_wxColourProperty_choicesCache
, value
)
1472 m_flags
|= wxPG_PROP_TRANSLATE_CUSTOM
;
1475 wxColourProperty::~wxColourProperty()
1479 void wxColourProperty::Init( wxColour colour
)
1486 int ind
= ColToInd(colour
);
1488 ind
= m_choices
.GetCount() - 1;
1492 wxString
wxColourProperty::ValueToString( wxVariant
& value
,
1493 int argFlags
) const
1495 const wxPGEditor
* editor
= GetEditorClass();
1496 if ( editor
!= wxPGEditor_Choice
&&
1497 editor
!= wxPGEditor_ChoiceAndButton
&&
1498 editor
!= wxPGEditor_ComboBox
)
1499 argFlags
|= wxPG_PROPERTY_SPECIFIC
;
1501 return wxSystemColourProperty::ValueToString(value
, argFlags
);
1504 wxColour
wxColourProperty::GetColour( int index
) const
1506 return gs_cp_es_normcolour_colours
[m_choices
.GetValue(index
)];
1509 wxVariant
wxColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1512 variant
<< v
.m_colour
;
1516 // -----------------------------------------------------------------------
1518 // -----------------------------------------------------------------------
1520 #define wxPG_CURSOR_IMAGE_WIDTH 32
1522 #define NUM_CURSORS 28
1524 //#define wx_cp_es_syscursors_len 28
1525 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1537 wxT("Middle Button"),
1543 wxT("Question Arrow"),
1544 wxT("Right Button"),
1545 wxT("Sizing NE-SW"),
1547 wxT("Sizing NW-SE"),
1554 (const wxChar
*) NULL
1557 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1560 wxCURSOR_RIGHT_ARROW
,
1567 wxCURSOR_LEFT_BUTTON
,
1569 wxCURSOR_MIDDLE_BUTTON
,
1571 wxCURSOR_PAINT_BRUSH
,
1573 wxCURSOR_POINT_LEFT
,
1574 wxCURSOR_POINT_RIGHT
,
1575 wxCURSOR_QUESTION_ARROW
,
1576 wxCURSOR_RIGHT_BUTTON
,
1588 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1590 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1592 : wxEnumProperty( label
,
1594 gs_cp_es_syscursors_labels
,
1595 gs_cp_es_syscursors_values
,
1598 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1601 wxCursorProperty::~wxCursorProperty()
1605 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1607 #if wxPG_CAN_DRAW_CURSOR
1608 if ( item
!= -1 && item
< NUM_CURSORS
)
1609 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1616 #if wxPG_CAN_DRAW_CURSOR
1618 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1620 wxPGPaintData
& paintdata
)
1623 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1625 if ( paintdata
.m_choiceItem
>= 0 )
1627 dc
.DrawRectangle( rect
);
1629 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1631 wxStockCursor cursorIndex
=
1632 (wxStockCursor
) gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1635 if ( cursorIndex
== wxCURSOR_NONE
)
1636 cursorIndex
= wxCURSOR_ARROW
;
1638 wxCursor
cursor( cursorIndex
);
1641 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1645 (HICON
)cursor
.GetHandle(),
1650 #if !defined(__WXWINCE__)
1651 DI_COMPAT
| DI_DEFAULTSIZE
|
1662 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1663 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1665 return wxEnumProperty::GetCellRenderer(column);
1669 // -----------------------------------------------------------------------
1670 // wxImageFileProperty
1671 // -----------------------------------------------------------------------
1675 const wxString
& wxPGGetDefaultImageWildcard()
1677 // Form the wildcard, if not done yet
1678 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1683 // TODO: This section may require locking (using global).
1685 wxList
& handlers
= wxImage::GetHandlers();
1687 wxList::iterator node
;
1689 // Let's iterate over the image handler list.
1690 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1691 for ( node
= handlers
.begin(); node
!= handlers
.end(); ++node
)
1693 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1695 wxString ext_lo
= handler
->GetExtension();
1696 wxString ext_up
= ext_lo
.Upper();
1698 str
.append( ext_up
);
1699 str
.append( wxT(" files (*.") );
1700 str
.append( ext_up
);
1701 str
.append( wxT(")|*.") );
1702 str
.append( ext_lo
);
1703 str
.append( wxT("|") );
1706 str
.append ( wxT("All files (*.*)|*.*") );
1708 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1711 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1714 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1716 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1717 const wxString
& value
)
1718 : wxFileProperty(label
,name
,value
)
1720 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1722 m_pImage
= (wxImage
*) NULL
;
1723 m_pBitmap
= (wxBitmap
*) NULL
;
1726 wxImageFileProperty::~wxImageFileProperty()
1734 void wxImageFileProperty::OnSetValue()
1736 wxFileProperty::OnSetValue();
1750 wxFileName filename
= GetFileName();
1752 // Create the image thumbnail
1753 if ( filename
.FileExists() )
1755 m_pImage
= new wxImage( filename
.GetFullPath() );
1759 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1761 return wxPG_DEFAULT_IMAGE_SIZE
;
1764 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1768 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1770 // Draw the thumbnail
1772 // Create the bitmap here because required size is not known in OnSetValue().
1775 m_pImage
->Rescale( rect
.width
, rect
.height
);
1776 m_pBitmap
= new wxBitmap( *m_pImage
);
1781 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1785 // No file - just draw a white box
1786 dc
.SetBrush( *wxWHITE_BRUSH
);
1787 dc
.DrawRectangle ( rect
);
1791 #endif // wxUSE_IMAGE
1793 // -----------------------------------------------------------------------
1794 // wxMultiChoiceProperty
1795 // -----------------------------------------------------------------------
1799 #include "wx/choicdlg.h"
1801 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1802 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1804 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1805 const wxString
& name
,
1806 const wxPGChoices
& choices
,
1807 const wxArrayString
& value
)
1808 : wxPGProperty(label
,name
)
1810 m_choices
.Assign(choices
);
1814 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1815 const wxString
& name
,
1816 const wxArrayString
& strings
,
1817 const wxArrayString
& value
)
1818 : wxPGProperty(label
,name
)
1820 m_choices
.Set(strings
);
1824 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1825 const wxString
& name
,
1826 const wxArrayString
& value
)
1827 : wxPGProperty(label
,name
)
1829 wxArrayString strings
;
1830 m_choices
.Set(strings
);
1834 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1838 void wxMultiChoiceProperty::OnSetValue()
1840 GenerateValueAsString(m_value
, &m_display
);
1843 wxString
wxMultiChoiceProperty::ValueToString( wxVariant
& value
,
1844 int argFlags
) const
1846 // If possible, use cached string
1847 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1851 GenerateValueAsString(value
, &s
);
1855 void wxMultiChoiceProperty::GenerateValueAsString( wxVariant
& value
,
1856 wxString
* target
) const
1858 wxArrayString strings
;
1860 if ( value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1861 strings
= value
.GetArrayString();
1863 wxString
& tempStr
= *target
;
1865 unsigned int itemCount
= strings
.size();
1870 tempStr
.append( wxT("\"") );
1872 for ( i
= 0; i
< itemCount
; i
++ )
1874 tempStr
.append( strings
[i
] );
1875 tempStr
.append( wxT("\"") );
1876 if ( i
< (itemCount
-1) )
1877 tempStr
.append ( wxT(" \"") );
1881 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1883 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(GetValue());
1886 // Translate values to string indices.
1887 wxArrayInt selections
;
1889 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1891 for ( i
=0; i
<valueArr
.size(); i
++ )
1896 for ( i
=0; i
<valueArr
.size(); i
++ )
1898 int sIndex
= m_choices
.Index(valueArr
[i
]);
1900 selections
.Add(sIndex
);
1907 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1908 wxWindow
* WXUNUSED(primary
),
1911 if ( propgrid
->IsMainButtonEvent(event
) )
1914 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
1916 wxArrayString labels
= m_choices
.GetLabels();
1917 unsigned int choiceCount
;
1919 if ( m_choices
.IsOk() )
1920 choiceCount
= m_choices
.GetCount();
1924 // launch editor dialog
1925 wxMultiChoiceDialog
dlg( propgrid
,
1926 _("Make a selection:"),
1929 choiceCount
?&labels
[0]:NULL
,
1930 wxCHOICEDLG_STYLE
);
1932 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
1934 wxArrayString strings
= useValue
.GetArrayString();
1935 wxArrayString extraStrings
;
1937 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
1939 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
1941 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1943 wxArrayInt arrInt
= dlg
.GetSelections();
1947 // Strings that were not in list of choices
1948 wxArrayString value
;
1950 // Translate string indices to strings
1953 if ( userStringMode
== 1 )
1955 for (n
=0;n
<extraStrings
.size();n
++)
1956 value
.push_back(extraStrings
[n
]);
1960 for ( i
=0; i
<arrInt
.size(); i
++ )
1961 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
1963 if ( userStringMode
== 2 )
1965 for (n
=0;n
<extraStrings
.size();n
++)
1966 value
.push_back(extraStrings
[n
]);
1969 variant
= WXVARIANT(value
);
1971 SetValueInEvent(variant
);
1979 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1983 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1985 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
1986 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
1988 WX_PG_TOKENIZER2_END()
1990 wxVariant
v( WXVARIANT(arr
) );
1996 #endif // wxUSE_CHOICEDLG
1999 // -----------------------------------------------------------------------
2001 // -----------------------------------------------------------------------
2006 #if wxUSE_DATEPICKCTRL
2007 #define dtCtrl DatePickerCtrl
2009 #define dtCtrl TextCtrl
2012 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
2019 wxString
wxDateProperty::ms_defaultDateFormat
;
2022 wxDateProperty::wxDateProperty( const wxString
& label
,
2023 const wxString
& name
,
2024 const wxDateTime
& value
)
2025 : wxPGProperty(label
,name
)
2027 //wxPGRegisterDefaultValueType(wxDateTime)
2029 #if wxUSE_DATEPICKCTRL
2030 wxPGRegisterEditorClass(DatePickerCtrl
);
2032 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
2040 wxDateProperty::~wxDateProperty()
2044 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
2045 int WXUNUSED(argFlags
) ) const
2049 const char* c
= dt
.ParseFormat(text
, wxString(wxDefaultDateTimeFormat
), wxDefaultDateTime
, NULL
);
2060 wxString
wxDateProperty::ValueToString( wxVariant
& value
,
2061 int argFlags
) const
2063 const wxChar
* format
= (const wxChar
*) NULL
;
2065 wxDateTime dateTime
= value
.GetDateTime();
2067 if ( !dateTime
.IsValid() )
2068 return wxT("Invalid");
2070 if ( !ms_defaultDateFormat
.length() )
2072 #if wxUSE_DATEPICKCTRL
2073 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
2075 bool showCentury
= true;
2077 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
2080 if ( m_format
.length() &&
2081 !(argFlags
& wxPG_FULL_VALUE
) )
2082 format
= m_format
.c_str();
2084 // Determine default from locale
2085 // NB: This is really simple stuff, but can't figure anything
2086 // better without proper support in wxLocale
2088 format
= ms_defaultDateFormat
.c_str();
2090 return dateTime
.Format(format
);
2093 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
2095 // This code is basicly copied from datectlg.cpp's SetFormat
2100 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
2101 wxString
str(dt
.Format(wxT("%x")));
2103 const wxChar
*p
= str
.c_str();
2107 if (n
== dt
.GetDay())
2109 format
.Append(wxT("%d"));
2112 else if (n
== (int)dt
.GetMonth()+1)
2114 format
.Append(wxT("%m"));
2117 else if (n
== dt
.GetYear())
2119 format
.Append(wxT("%Y"));
2122 else if (n
== (dt
.GetYear() % 100))
2125 format
.Append(wxT("%Y"));
2127 format
.Append(wxT("%y"));
2131 format
.Append(*p
++);
2137 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
2139 if ( name
== wxPG_DATE_FORMAT
)
2141 m_format
= value
.GetString();
2144 else if ( name
== wxPG_DATE_PICKER_STYLE
)
2146 m_dpStyle
= value
.GetLong();
2147 ms_defaultDateFormat
.clear(); // This may need recalculation
2153 #endif // wxUSE_DATETIME
2156 // -----------------------------------------------------------------------
2157 // wxPropertyGridInterface
2158 // -----------------------------------------------------------------------
2160 void wxPropertyGridInterface::InitAllTypeHandlers()
2164 // -----------------------------------------------------------------------
2166 void wxPropertyGridInterface::RegisterAdditionalEditors()
2168 // Register editor classes, if necessary.
2169 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
2170 wxPropertyGrid::RegisterDefaultEditors();
2173 wxPGRegisterEditorClass(SpinCtrl
);
2175 #if wxUSE_DATEPICKCTRL
2176 wxPGRegisterEditorClass(DatePickerCtrl
);
2180 // -----------------------------------------------------------------------
2182 #endif // wxPG_INCLUDE_ADVPROPS
2184 #endif // wxUSE_PROPGRID