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
)
198 int dy
= m_ptPosition
.y
- event
.GetPosition().y
;
199 m_ptPosition
= event
.GetPosition();
201 wxSpinEvent
evtscroll( (dy
>= 0) ? wxEVT_SCROLL_LINEUP
:
202 wxEVT_SCROLL_LINEDOWN
,
204 evtscroll
.SetEventObject(this);
207 GetEventHandler()->ProcessEvent(evtscroll
);
214 void OnMouseCaptureLost(wxMouseCaptureLostEvent
& WXUNUSED(event
))
221 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(SpinCtrl
,
226 // Trivial destructor.
227 wxPGSpinCtrlEditor::~wxPGSpinCtrlEditor()
232 // Create controls and initialize event handling.
233 wxPGWindowList
wxPGSpinCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
234 const wxPoint
& pos
, const wxSize
& sz
) const
236 const int margin
= 1;
237 wxSize
butSz(18, sz
.y
);
238 wxSize
tcSz(sz
.x
- butSz
.x
- margin
, sz
.y
);
239 wxPoint
butPos(pos
.x
+ tcSz
.x
+ margin
, pos
.y
);
243 wnd2
= new wxPGSpinButton();
248 wnd2
->Create( propgrid
->GetPanel(), wxPG_SUBID2
, butPos
, butSz
, wxSP_VERTICAL
);
250 wnd2
->SetRange( INT_MIN
, INT_MAX
);
253 // Let's add validator to make sure only numbers can be entered
254 wxTextValidator
validator(wxFILTER_NUMERIC
, &m_tempString
);
256 wxTextCtrl
* wnd1
= (wxTextCtrl
*) wxPGTextCtrlEditor::CreateControls( propgrid
, property
, pos
, tcSz
).m_primary
;
257 wnd1
->SetValidator(validator
);
259 return wxPGWindowList(wnd1
, wnd2
);
262 // Control's events are redirected here
263 bool wxPGSpinCtrlEditor::OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
264 wxWindow
* wnd
, wxEvent
& event
) const
266 int evtType
= event
.GetEventType();
269 bool bigStep
= false;
271 if ( evtType
== wxEVT_KEY_DOWN
)
273 wxKeyEvent
& keyEvent
= (wxKeyEvent
&)event
;
274 keycode
= keyEvent
.GetKeyCode();
276 if ( keycode
== WXK_UP
)
277 evtType
= wxEVT_SCROLL_LINEUP
;
278 else if ( keycode
== WXK_DOWN
)
279 evtType
= wxEVT_SCROLL_LINEDOWN
;
280 else if ( keycode
== WXK_PAGEUP
)
282 evtType
= wxEVT_SCROLL_LINEUP
;
285 else if ( keycode
== WXK_PAGEDOWN
)
287 evtType
= wxEVT_SCROLL_LINEDOWN
;
292 if ( evtType
== wxEVT_SCROLL_LINEUP
|| evtType
== wxEVT_SCROLL_LINEDOWN
)
294 wxPGSpinButton
* spinButton
=
295 (wxPGSpinButton
*) propgrid
->GetEditorControlSecondary();
298 spins
= spinButton
->GetSpins();
301 // Can't use wnd since it might be clipper window
302 wxTextCtrl
* tc
= wxDynamicCast(propgrid
->GetEditorControl(), wxTextCtrl
);
307 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
309 int mode
= wxPG_PROPERTY_VALIDATION_SATURATE
;
311 if ( property
->GetAttributeAsLong(wxT("Wrap"), 0) )
312 mode
= wxPG_PROPERTY_VALIDATION_WRAP
;
314 if ( property
->GetValueType() == wxT("double") )
317 double step
= property
->GetAttributeAsDouble(wxT("Step"), 1.0);
320 if ( s
.ToDouble(&v_d
) )
325 step
*= (double) spins
;
327 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_d
+= step
;
331 wxFloatProperty::DoValidation(property
, v_d
, NULL
, mode
);
333 wxPropertyGrid::DoubleToString(s
, v_d
, 6, true, NULL
);
343 wxLongLong_t step
= property
->GetAttributeAsLong(wxT("Step"), 1);
346 if ( s
.ToLongLong(&v_ll
, 10) )
353 if ( evtType
== wxEVT_SCROLL_LINEUP
) v_ll
+= step
;
357 wxIntProperty::DoValidation(property
, v_ll
, NULL
, mode
);
359 s
= wxLongLong(v_ll
).ToString();
369 int ip
= tc
->GetInsertionPoint();
370 int lp
= tc
->GetLastPosition();
372 tc
->SetInsertionPoint(ip
+(tc
->GetLastPosition()-lp
));
378 return wxPGTextCtrlEditor::OnEvent(propgrid
,property
,wnd
,event
);
381 #endif // wxUSE_SPINBTN
384 // -----------------------------------------------------------------------
385 // wxDatePickerCtrl-based property editor
386 // -----------------------------------------------------------------------
388 #if wxUSE_DATEPICKCTRL
391 #include "wx/datectrl.h"
392 #include "wx/dateevt.h"
394 class wxPGDatePickerCtrlEditor
: public wxPGEditor
396 DECLARE_DYNAMIC_CLASS(wxPGDatePickerCtrlEditor
)
398 virtual ~wxPGDatePickerCtrlEditor();
400 wxString
GetName() const;
401 virtual wxPGWindowList
CreateControls(wxPropertyGrid
* propgrid
,
402 wxPGProperty
* property
,
404 const wxSize
& size
) const;
405 virtual void UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const;
406 virtual bool OnEvent( wxPropertyGrid
* propgrid
, wxPGProperty
* property
,
407 wxWindow
* wnd
, wxEvent
& event
) const;
408 virtual bool GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* wnd
) const;
409 virtual void SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const;
413 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(DatePickerCtrl
,
414 wxPGDatePickerCtrlEditor
,
418 wxPGDatePickerCtrlEditor::~wxPGDatePickerCtrlEditor()
422 wxPGWindowList
wxPGDatePickerCtrlEditor::CreateControls( wxPropertyGrid
* propgrid
,
423 wxPGProperty
* property
,
425 const wxSize
& sz
) const
427 wxCHECK_MSG( property
->IsKindOf(CLASSINFO(wxDateProperty
)),
429 wxT("DatePickerCtrl editor can only be used with wxDateProperty or derivative.") );
431 wxDateProperty
* prop
= (wxDateProperty
*) property
;
433 // Use two stage creation to allow cleaner display on wxMSW
434 wxDatePickerCtrl
* ctrl
= new wxDatePickerCtrl();
437 wxSize useSz
= wxDefaultSize
;
443 wxDateTime
dateValue(wxInvalidDateTime
);
445 wxVariant value
= prop
->GetValue();
446 if ( value
.GetType() == wxT("datetime") )
447 dateValue
= value
.GetDateTime();
449 ctrl
->Create(propgrid
->GetPanel(),
454 prop
->GetDatePickerStyle() | wxNO_BORDER
);
463 // Copies value from property to control
464 void wxPGDatePickerCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* wnd
) const
466 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
467 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
469 // We assume that property's data type is 'int' (or something similar),
470 // thus allowing us to get raw, unchecked value via DoGetValue.
471 ctrl
->SetValue( property
->GetValue().GetDateTime() );
474 // Control's events are redirected here
475 bool wxPGDatePickerCtrlEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propgrid
),
476 wxPGProperty
* WXUNUSED(property
),
477 wxWindow
* WXUNUSED(wnd
),
478 wxEvent
& event
) const
480 if ( event
.GetEventType() == wxEVT_DATE_CHANGED
)
486 bool wxPGDatePickerCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* WXUNUSED(property
), wxWindow
* wnd
) const
488 wxDatePickerCtrl
* ctrl
= (wxDatePickerCtrl
*) wnd
;
489 wxASSERT( ctrl
&& ctrl
->IsKindOf(CLASSINFO(wxDatePickerCtrl
)) );
491 variant
= ctrl
->GetValue();
496 void wxPGDatePickerCtrlEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* WXUNUSED(wnd
) ) const
499 //wxDateProperty* prop = (wxDateProperty*) property;
503 #endif // wxUSE_DATEPICKCTRL
506 // -----------------------------------------------------------------------
508 // -----------------------------------------------------------------------
510 #include "wx/fontdlg.h"
511 #include "wx/fontenum.h"
513 static const wxChar
* gs_fp_es_family_labels
[] = {
514 wxT("Default"), wxT("Decorative"),
515 wxT("Roman"), wxT("Script"),
516 wxT("Swiss"), wxT("Modern"),
520 static long gs_fp_es_family_values
[] = {
521 wxDEFAULT
, wxDECORATIVE
,
526 static const wxChar
* gs_fp_es_style_labels
[] = {
533 static long gs_fp_es_style_values
[] = {
539 static const wxChar
* gs_fp_es_weight_labels
[] = {
546 static long gs_fp_es_weight_values
[] = {
552 // Class body is in advprops.h
555 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxFontProperty
,wxPGProperty
,
556 wxFont
,const wxFont
&,TextCtrlAndButton
)
559 wxFontProperty::wxFontProperty( const wxString
& label
, const wxString
& name
,
560 const wxFont
& value
)
561 : wxPGProperty(label
,name
)
563 SetValue(WXVARIANT(value
));
565 // Initialize font family choices list
566 if ( !wxPGGlobalVars
->m_fontFamilyChoices
)
568 wxArrayString faceNames
= wxFontEnumerator::GetFacenames();
572 wxPGGlobalVars
->m_fontFamilyChoices
= new wxPGChoices(faceNames
);
575 wxString
emptyString(wxEmptyString
);
580 SetParentalType(wxPG_PROP_AGGREGATE
);
582 AddChild( new wxIntProperty( _("Point Size"), wxS("Point Size"),(long)font
.GetPointSize() ) );
584 AddChild( new wxEnumProperty(_("Family"), wxS("PointSize"),
585 gs_fp_es_family_labels
,gs_fp_es_family_values
,
588 wxString faceName
= font
.GetFaceName();
589 // If font was not in there, add it now
590 if ( faceName
.length() &&
591 wxPGGlobalVars
->m_fontFamilyChoices
->Index(faceName
) == wxNOT_FOUND
)
592 wxPGGlobalVars
->m_fontFamilyChoices
->AddAsSorted(faceName
);
594 wxPGProperty
* p
= new wxEnumProperty(_("Face Name"), wxS("Face Name"),
595 *wxPGGlobalVars
->m_fontFamilyChoices
);
597 p
->SetValueFromString(faceName
, wxPG_FULL_VALUE
);
601 AddChild( new wxEnumProperty(_("Style"), wxS("Style"),
602 gs_fp_es_style_labels
,gs_fp_es_style_values
,font
.GetStyle()) );
604 AddChild( new wxEnumProperty(_("Weight"), wxS("Weight"),
605 gs_fp_es_weight_labels
,gs_fp_es_weight_values
,font
.GetWeight()) );
607 AddChild( new wxBoolProperty(_("Underlined"), wxS("Underlined"),
608 font
.GetUnderlined()) );
611 wxFontProperty::~wxFontProperty() { }
613 void wxFontProperty::OnSetValue()
620 font
= wxFont(10,wxSWISS
,wxNORMAL
,wxNORMAL
);
625 wxString
wxFontProperty::ValueToString( wxVariant
& value
,
628 return wxPGProperty::ValueToString(value
, argFlags
);
631 bool wxFontProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
),
634 if ( propgrid
->IsMainButtonEvent(event
) )
636 // Update value from last minute changes
637 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
642 data
.SetInitialFont( font
);
643 data
.SetColour(*wxBLACK
);
645 wxFontDialog
dlg(propgrid
, data
);
646 if ( dlg
.ShowModal() == wxID_OK
)
648 propgrid
->EditorsValueWasModified();
651 variant
<< dlg
.GetFontData().GetChosenFont();
652 SetValueInEvent( variant
);
659 void wxFontProperty::RefreshChildren()
661 if ( !GetChildCount() ) return;
664 Item(0)->SetValue( (long)font
.GetPointSize() );
665 Item(1)->SetValue( (long)font
.GetFamily() );
666 Item(2)->SetValueFromString( font
.GetFaceName(), wxPG_FULL_VALUE
);
667 Item(3)->SetValue( (long)font
.GetStyle() );
668 Item(4)->SetValue( (long)font
.GetWeight() );
669 Item(5)->SetValue( font
.GetUnderlined() );
672 void wxFontProperty::ChildChanged( wxVariant
& thisValue
, int ind
, wxVariant
& childValue
) const
679 font
.SetPointSize( wxPGVariantToInt(childValue
) );
683 int fam
= childValue
.GetLong();
684 if ( fam
< wxDEFAULT
||
687 font
.SetFamily( fam
);
692 int faceIndex
= childValue
.GetLong();
694 if ( faceIndex
>= 0 )
695 faceName
= wxPGGlobalVars
->m_fontFamilyChoices
->GetLabel(faceIndex
);
697 font
.SetFaceName( faceName
);
701 int st
= childValue
.GetLong();
702 if ( st
!= wxFONTSTYLE_NORMAL
&&
703 st
!= wxFONTSTYLE_SLANT
&&
704 st
!= wxFONTSTYLE_ITALIC
)
705 st
= wxFONTWEIGHT_NORMAL
;
710 int wt
= childValue
.GetLong();
711 if ( wt
!= wxFONTWEIGHT_NORMAL
&&
712 wt
!= wxFONTWEIGHT_LIGHT
&&
713 wt
!= wxFONTWEIGHT_BOLD
)
714 wt
= wxFONTWEIGHT_NORMAL
;
715 font
.SetWeight( wt
);
719 font
.SetUnderlined( childValue
.GetBool() );
726 wxSize wxFontProperty::OnMeasureImage() const
728 return wxSize(-1,-1);
731 void wxFontProperty::OnCustomPaint(wxDC& dc,
733 wxPGPaintData& paintData)
736 if ( paintData.m_choiceItem >= 0 )
737 drawFace = wxPGGlobalVars->m_fontFamilyChoices->GetLabel(paintData.m_choiceItem);
739 drawFace = m_value_wxFont.GetFaceName();
741 if ( drawFace.length() )
743 // Draw the background
744 dc.SetBrush( wxColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE)) );
745 //dc.SetBrush( *wxWHITE_BRUSH );
746 //dc.SetPen( *wxMEDIUM_GREY_PEN );
747 dc.DrawRectangle( rect );
749 wxFont oldFont = dc.GetFont();
750 wxFont drawFont(oldFont.GetPointSize(),
751 wxDEFAULT,wxNORMAL,wxBOLD,false,drawFace);
752 dc.SetFont(drawFont);
754 dc.SetTextForeground( wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT) );
755 dc.DrawText( wxT("Aa"), rect.x+2, rect.y+1 );
761 // No file - just draw a white box
762 dc.SetBrush ( *wxWHITE_BRUSH );
763 dc.DrawRectangle ( rect );
769 // -----------------------------------------------------------------------
770 // wxSystemColourProperty
771 // -----------------------------------------------------------------------
773 // wxEnumProperty based classes cannot use wxPG_PROP_CLASS_SPECIFIC_1
774 #define wxPG_PROP_HIDE_CUSTOM_COLOUR wxPG_PROP_CLASS_SPECIFIC_2
776 #include "wx/colordlg.h"
778 //#define wx_cp_es_syscolours_len 25
779 static const wxChar
* gs_cp_es_syscolour_labels
[] = {
782 wxT("ActiveCaption"),
784 wxT("ButtonHighlight"),
793 wxT("HighlightText"),
794 wxT("InactiveBorder"),
795 wxT("InactiveCaption"),
796 wxT("InactiveCaptionText"),
808 static long gs_cp_es_syscolour_values
[] = {
809 wxSYS_COLOUR_APPWORKSPACE
,
810 wxSYS_COLOUR_ACTIVEBORDER
,
811 wxSYS_COLOUR_ACTIVECAPTION
,
812 wxSYS_COLOUR_BTNFACE
,
813 wxSYS_COLOUR_BTNHIGHLIGHT
,
814 wxSYS_COLOUR_BTNSHADOW
,
815 wxSYS_COLOUR_BTNTEXT
,
816 wxSYS_COLOUR_CAPTIONTEXT
,
817 wxSYS_COLOUR_3DDKSHADOW
,
818 wxSYS_COLOUR_3DLIGHT
,
819 wxSYS_COLOUR_BACKGROUND
,
820 wxSYS_COLOUR_GRAYTEXT
,
821 wxSYS_COLOUR_HIGHLIGHT
,
822 wxSYS_COLOUR_HIGHLIGHTTEXT
,
823 wxSYS_COLOUR_INACTIVEBORDER
,
824 wxSYS_COLOUR_INACTIVECAPTION
,
825 wxSYS_COLOUR_INACTIVECAPTIONTEXT
,
827 wxSYS_COLOUR_SCROLLBAR
,
829 wxSYS_COLOUR_INFOTEXT
,
831 wxSYS_COLOUR_WINDOWFRAME
,
832 wxSYS_COLOUR_WINDOWTEXT
,
837 IMPLEMENT_VARIANT_OBJECT_EXPORTED_SHALLOWCMP(wxColourPropertyValue
, WXDLLIMPEXP_PROPGRID
)
840 // Class body is in advprops.h
842 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxSystemColourProperty
,wxEnumProperty
,
843 wxColourPropertyValue
,const wxColourPropertyValue
&,Choice
)
846 void wxSystemColourProperty::Init( int type
, const wxColour
& colour
)
848 wxColourPropertyValue cpv
;
851 cpv
.Init( type
, colour
);
853 cpv
.Init( type
, *wxWHITE
);
855 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Colour selection cannot be changed.
863 static wxPGChoices gs_wxSystemColourProperty_choicesCache
;
866 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
867 const wxColourPropertyValue
& value
)
868 : wxEnumProperty( label
,
870 gs_cp_es_syscolour_labels
,
871 gs_cp_es_syscolour_values
,
872 &gs_wxSystemColourProperty_choicesCache
)
875 Init( value
.m_type
, value
.m_colour
);
877 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
881 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
882 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
883 const wxColourPropertyValue
& value
)
884 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
887 Init( value
.m_type
, value
.m_colour
);
889 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
893 wxSystemColourProperty::wxSystemColourProperty( const wxString
& label
, const wxString
& name
,
894 const wxChar
** labels
, const long* values
, wxPGChoices
* choicesCache
,
895 const wxColour
& value
)
896 : wxEnumProperty( label
, name
, labels
, values
, choicesCache
)
899 Init( wxPG_COLOUR_CUSTOM
, value
);
901 Init( wxPG_COLOUR_CUSTOM
, *wxWHITE
);
905 wxSystemColourProperty::~wxSystemColourProperty() { }
908 wxColourPropertyValue
wxSystemColourProperty::GetVal( const wxVariant
* pVariant
) const
913 if ( pVariant
->IsNull() )
914 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
916 if ( pVariant
->GetType() == wxS("wxColourPropertyValue") )
918 wxColourPropertyValue v
;
924 bool variantProcessed
= true;
926 if ( pVariant
->GetType() == wxS("wxColour*") )
928 wxColour
* pCol
= wxStaticCast(pVariant
->GetWxObjectPtr(), wxColour
);
931 else if ( pVariant
->GetType() == wxS("wxColour") )
935 else if ( pVariant
->GetType() == wxArrayInt_VariantType
)
937 // This code is mostly needed for wxPython bindings, which
938 // may offer tuple of integers as colour value.
942 if ( arr
.size() >= 3 )
950 if ( arr
.size() >= 4 )
953 col
= wxColour(r
, g
, b
, a
);
957 variantProcessed
= false;
962 variantProcessed
= false;
965 if ( !variantProcessed
)
966 return wxColourPropertyValue(wxPG_COLOUR_UNSPECIFIED
, wxColour());
968 wxColourPropertyValue
v2( wxPG_COLOUR_CUSTOM
, col
);
970 int colInd
= ColToInd(col
);
971 if ( colInd
!= wxNOT_FOUND
)
977 wxVariant
wxSystemColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
984 int wxSystemColourProperty::ColToInd( const wxColour
& colour
) const
987 size_t i_max
= m_choices
.GetCount() - 1;
989 for ( i
=0; i
<i_max
; i
++ )
991 int ind
= m_choices
[i
].GetValue();
993 if ( colour
== GetColour(ind
) )
995 /*wxLogDebug(wxT("%s(%s): Index %i for ( getcolour(%i,%i,%i), colour(%i,%i,%i))"),
996 GetClassName(),GetLabel().c_str(),
997 (int)i,(int)GetColour(ind).Red(),(int)GetColour(ind).Green(),(int)GetColour(ind).Blue(),
998 (int)colour.Red(),(int)colour.Green(),(int)colour.Blue());*/
1005 void wxSystemColourProperty::OnSetValue()
1007 // Convert from generic wxobject ptr to wxPGVariantDataColour
1008 if ( m_value
.GetType() == wxS("wxColour*") )
1010 wxColour
* pCol
= wxStaticCast(m_value
.GetWxObjectPtr(), wxColour
);
1014 wxColourPropertyValue val
= GetVal(&m_value
);
1016 if ( val
.m_type
== wxPG_COLOUR_UNSPECIFIED
)
1024 if ( val
.m_type
< wxPG_COLOUR_WEB_BASE
)
1025 val
.m_colour
= GetColour( val
.m_type
);
1027 m_value
= TranslateVal(val
);
1030 int ind
= wxNOT_FOUND
;
1032 if ( m_value
.GetType() == wxS("wxColourPropertyValue") )
1034 wxColourPropertyValue cpv
;
1036 wxColour col
= cpv
.m_colour
;
1040 SetValueToUnspecified();
1041 SetIndex(wxNOT_FOUND
);
1045 if ( cpv
.m_type
< wxPG_COLOUR_WEB_BASE
)
1047 ind
= GetIndexForValue(cpv
.m_type
);
1051 cpv
.m_type
= wxPG_COLOUR_CUSTOM
;
1052 ind
= GetCustomColourIndex();
1062 SetValueToUnspecified();
1063 SetIndex(wxNOT_FOUND
);
1067 ind
= ColToInd(col
);
1069 if ( ind
== wxNOT_FOUND
)
1070 ind
= GetCustomColourIndex();
1077 wxColour
wxSystemColourProperty::GetColour( int index
) const
1079 return wxSystemSettings::GetColour( (wxSystemColour
)index
);
1082 wxString
wxSystemColourProperty::ColourToString( const wxColour
& col
, int index
) const
1084 if ( index
== wxNOT_FOUND
)
1085 return wxString::Format(wxT("(%i,%i,%i)"),
1090 return m_choices
.GetLabel(index
);
1093 wxString
wxSystemColourProperty::ValueToString( wxVariant
& value
,
1094 int argFlags
) const
1096 wxColourPropertyValue val
= GetVal(&value
);
1100 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1102 // GetIndex() only works reliably if wxPG_VALUE_IS_CURRENT flag is set,
1103 // but we should use it whenever possible.
1106 // If custom colour was selected, use invalid index, so that
1107 // ColourToString() will return properly formatted colour text.
1108 if ( index
== GetCustomColourIndex() )
1109 index
= wxNOT_FOUND
;
1113 index
= m_choices
.Index(val
.m_type
);
1116 return ColourToString(val
.m_colour
, index
);
1120 wxSize
wxSystemColourProperty::OnMeasureImage( int ) const
1122 return wxPG_DEFAULT_IMAGE_SIZE
;
1126 int wxSystemColourProperty::GetCustomColourIndex() const
1128 return m_choices
.GetCount() - 1;
1132 bool wxSystemColourProperty::QueryColourFromUser( wxVariant
& variant
) const
1134 wxASSERT( m_value
.GetType() != wxPG_VARIANT_TYPE_STRING
);
1137 wxPropertyGrid
* propgrid
= GetGrid();
1138 wxASSERT( propgrid
);
1140 // Must only occur when user triggers event
1141 if ( !(propgrid
->GetInternalFlags() & wxPG_FL_IN_HANDLECUSTOMEDITOREVENT
) )
1144 wxColourPropertyValue val
= GetVal();
1146 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1149 data
.SetChooseFull(true);
1150 data
.SetColour(val
.m_colour
);
1152 for ( i
= 0; i
< 16; i
++)
1154 wxColour
colour(i
*16, i
*16, i
*16);
1155 data
.SetCustomColour(i
, colour
);
1158 wxColourDialog
dialog(propgrid
, &data
);
1159 if ( dialog
.ShowModal() == wxID_OK
)
1161 wxColourData retData
= dialog
.GetColourData();
1162 val
.m_colour
= retData
.GetColour();
1164 variant
= DoTranslateVal(val
);
1166 SetValueInEvent(variant
);
1175 bool wxSystemColourProperty::IntToValue( wxVariant
& variant
, int number
, int WXUNUSED(argFlags
) ) const
1178 int type
= m_choices
.GetValue(index
);
1180 if ( type
== wxPG_COLOUR_CUSTOM
)
1182 QueryColourFromUser(variant
);
1186 variant
= TranslateVal( type
, GetColour(type
) );
1192 // Need to do some extra event handling.
1193 bool wxSystemColourProperty::OnEvent( wxPropertyGrid
* propgrid
, wxWindow
* WXUNUSED(primary
), wxEvent
& event
)
1195 if ( propgrid
->IsMainButtonEvent(event
) )
1197 // We need to handle button click in case editor has been
1198 // switched to one that has wxButton as well.
1200 if ( QueryColourFromUser(variant
) )
1206 /*class wxPGColourPropertyRenderer : public wxPGDefaultRenderer
1209 virtual void Render( wxDC& dc, const wxRect& rect,
1210 const wxPropertyGrid* propertyGrid, wxPGProperty* property,
1211 int WXUNUSED(column), int item, int WXUNUSED(flags) ) const
1213 wxASSERT( property->IsKindOf(CLASSINFO(wxSystemColourProperty)) );
1214 wxSystemColourProperty* prop = wxStaticCast(property, wxSystemColourProperty);
1216 dc.SetPen(*wxBLACK_PEN);
1218 ( item < (int)(GetCustomColourIndex) || (prop->HasFlag(wxPG_PROP_HIDE_CUSTOM_COLOUR)))
1222 const wxArrayInt& values = prop->GetValues();
1223 if ( values.GetChildCount() )
1224 colInd = values[item];
1227 dc.SetBrush( wxColour( prop->GetColour( colInd ) ) );
1229 else if ( !prop->IsValueUnspecified() )
1230 dc.SetBrush( prop->GetVal().m_colour );
1232 dc.SetBrush( *wxWHITE );
1234 wxRect imageRect = propertyGrid->GetImageRect(property, item);
1235 wxLogDebug(wxT("%i, %i"),imageRect.x,imageRect.y);
1236 dc.DrawRectangle( rect.x+imageRect.x, rect.y+imageRect.y,
1237 imageRect.width, imageRect.height );
1241 text = property->GetValueAsString();
1243 text = property->GetChoiceString(item);
1244 DrawText( dc, rect, imageRect.width, text );
1249 wxPGColourPropertyRenderer g_wxPGColourPropertyRenderer;
1251 wxPGCellRenderer* wxSystemColourProperty::GetCellRenderer( int column ) const
1254 return &g_wxPGColourPropertyRenderer;
1255 return wxEnumProperty::GetCellRenderer(column);
1258 void wxSystemColourProperty::OnCustomPaint( wxDC
& dc
, const wxRect
& rect
,
1259 wxPGPaintData
& paintdata
)
1263 if ( paintdata
.m_choiceItem
>= 0 && paintdata
.m_choiceItem
< (int)m_choices
.GetCount() &&
1264 paintdata
.m_choiceItem
!= GetCustomColourIndex() )
1266 int colInd
= m_choices
[paintdata
.m_choiceItem
].GetValue();
1267 col
= GetColour( colInd
);
1269 else if ( !IsValueUnspecified() )
1271 col
= GetVal().m_colour
;
1277 dc
.DrawRectangle(rect
);
1282 bool wxSystemColourProperty::StringToValue( wxVariant
& value
, const wxString
& text
, int argFlags
) const
1285 // Accept colour format "[Name] [(R,G,B)]"
1286 // Name takes precedence.
1288 wxString colourName
;
1291 int ppos
= text
.Find(wxT("("));
1293 if ( ppos
== wxNOT_FOUND
)
1299 colourName
= text
.substr(0, ppos
);
1300 colourRGB
= text
.substr(ppos
, text
.length()-ppos
);
1303 // Strip spaces from extremities
1304 colourName
.Trim(true);
1305 colourName
.Trim(false);
1306 colourRGB
.Trim(true);
1308 // Validate colourRGB string - (1,1,1) is shortest allowed
1309 if ( colourRGB
.length() < 7 )
1312 if ( colourRGB
.length() == 0 && m_choices
.GetCount() &&
1313 colourName
== m_choices
.GetLabel(GetCustomColourIndex()) )
1315 if ( !(argFlags
& wxPG_EDITABLE_VALUE
))
1317 // This really should not occurr...
1323 QueryColourFromUser(value
);
1327 wxColourPropertyValue val
;
1331 if ( colourName
.length() )
1333 // Try predefined colour first
1334 bool res
= wxEnumProperty::StringToValue(value
, colourName
, argFlags
);
1335 if ( res
&& GetIndex() >= 0 )
1337 val
.m_type
= GetIndex();
1338 if ( val
.m_type
< m_choices
.GetCount() )
1339 val
.m_type
= m_choices
[val
.m_type
].GetValue();
1341 // Get proper colour for type.
1342 val
.m_colour
= GetColour(val
.m_type
);
1347 if ( colourRGB
.length() && !done
)
1349 // Then check custom colour.
1350 val
.m_type
= wxPG_COLOUR_CUSTOM
;
1352 int r
= -1, g
= -1, b
= -1;
1353 wxSscanf(colourRGB
.c_str(),wxT("(%i,%i,%i)"),&r
,&g
,&b
);
1355 if ( r
>= 0 && r
<= 255 &&
1356 g
>= 0 && g
<= 255 &&
1357 b
>= 0 && b
<= 255 )
1359 val
.m_colour
.Set(r
,g
,b
);
1371 value
= DoTranslateVal(val
);
1378 bool wxSystemColourProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
1380 if ( name
== wxPG_COLOUR_ALLOW_CUSTOM
)
1382 int ival
= wxPGVariantToInt(value
);
1384 SetChoicesExclusive(); // Make sure we don't corrupt colour lists of other properties
1386 if ( ival
&& (m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1388 // Show custom choice
1389 m_choices
.Insert(wxT("Custom"), GetCustomColourIndex(), wxPG_COLOUR_CUSTOM
);
1390 m_flags
&= ~(wxPG_PROP_HIDE_CUSTOM_COLOUR
);
1392 else if ( !ival
&& !(m_flags
& wxPG_PROP_HIDE_CUSTOM_COLOUR
) )
1394 // Hide custom choice
1395 m_choices
.RemoveAt(GetCustomColourIndex());
1396 m_flags
|= wxPG_PROP_HIDE_CUSTOM_COLOUR
;
1404 // -----------------------------------------------------------------------
1406 // -----------------------------------------------------------------------
1408 static const wxChar
* gs_cp_es_normcolour_labels
[] = {
1428 (const wxChar
*) NULL
1431 static unsigned long gs_cp_es_normcolour_colours
[] = {
1433 wxPG_COLOUR(128,0,0),
1434 wxPG_COLOUR(0,0,128),
1435 wxPG_COLOUR(128,0,128),
1436 wxPG_COLOUR(0,128,128),
1437 wxPG_COLOUR(128,128,128),
1438 wxPG_COLOUR(0,128,0),
1439 wxPG_COLOUR(128,128,0),
1440 wxPG_COLOUR(166,124,81),
1441 wxPG_COLOUR(0,0,255),
1442 wxPG_COLOUR(255,0,255),
1443 wxPG_COLOUR(255,0,0),
1444 wxPG_COLOUR(247,148,28),
1445 wxPG_COLOUR(192,192,192),
1446 wxPG_COLOUR(0,255,0),
1447 wxPG_COLOUR(0,255,255),
1448 wxPG_COLOUR(255,255,0),
1449 wxPG_COLOUR(255,255,255),
1453 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxColourProperty
, wxSystemColourProperty
,
1454 wxColour
, const wxColour
&, TextCtrlAndButton
)
1456 static wxPGChoices gs_wxColourProperty_choicesCache
;
1458 wxColourProperty::wxColourProperty( const wxString
& label
,
1459 const wxString
& name
,
1460 const wxColour
& value
)
1461 : wxSystemColourProperty(label
, name
, gs_cp_es_normcolour_labels
,
1463 &gs_wxColourProperty_choicesCache
, value
)
1467 m_flags
|= wxPG_PROP_TRANSLATE_CUSTOM
;
1470 wxColourProperty::~wxColourProperty()
1474 void wxColourProperty::Init( wxColour colour
)
1481 int ind
= ColToInd(colour
);
1483 ind
= m_choices
.GetCount() - 1;
1487 wxString
wxColourProperty::ValueToString( wxVariant
& value
,
1488 int argFlags
) const
1490 const wxPGEditor
* editor
= GetEditorClass();
1491 if ( editor
!= wxPGEditor_Choice
&&
1492 editor
!= wxPGEditor_ChoiceAndButton
&&
1493 editor
!= wxPGEditor_ComboBox
)
1494 argFlags
|= wxPG_PROPERTY_SPECIFIC
;
1496 return wxSystemColourProperty::ValueToString(value
, argFlags
);
1499 wxColour
wxColourProperty::GetColour( int index
) const
1501 return gs_cp_es_normcolour_colours
[m_choices
.GetValue(index
)];
1504 wxVariant
wxColourProperty::DoTranslateVal( wxColourPropertyValue
& v
) const
1507 variant
<< v
.m_colour
;
1511 // -----------------------------------------------------------------------
1513 // -----------------------------------------------------------------------
1515 #define wxPG_CURSOR_IMAGE_WIDTH 32
1517 #define NUM_CURSORS 28
1519 //#define wx_cp_es_syscursors_len 28
1520 static const wxChar
* gs_cp_es_syscursors_labels
[NUM_CURSORS
+1] = {
1532 wxT("Middle Button"),
1538 wxT("Question Arrow"),
1539 wxT("Right Button"),
1540 wxT("Sizing NE-SW"),
1542 wxT("Sizing NW-SE"),
1549 (const wxChar
*) NULL
1552 static long gs_cp_es_syscursors_values
[NUM_CURSORS
] = {
1555 wxCURSOR_RIGHT_ARROW
,
1562 wxCURSOR_LEFT_BUTTON
,
1564 wxCURSOR_MIDDLE_BUTTON
,
1566 wxCURSOR_PAINT_BRUSH
,
1568 wxCURSOR_POINT_LEFT
,
1569 wxCURSOR_POINT_RIGHT
,
1570 wxCURSOR_QUESTION_ARROW
,
1571 wxCURSOR_RIGHT_BUTTON
,
1583 IMPLEMENT_DYNAMIC_CLASS(wxCursorProperty
, wxEnumProperty
)
1585 wxCursorProperty::wxCursorProperty( const wxString
& label
, const wxString
& name
,
1587 : wxEnumProperty( label
,
1589 gs_cp_es_syscursors_labels
,
1590 gs_cp_es_syscursors_values
,
1593 m_flags
|= wxPG_PROP_STATIC_CHOICES
; // Cursor selection cannot be changed.
1596 wxCursorProperty::~wxCursorProperty()
1600 wxSize
wxCursorProperty::OnMeasureImage( int item
) const
1602 #if wxPG_CAN_DRAW_CURSOR
1603 if ( item
!= -1 && item
< NUM_CURSORS
)
1604 return wxSize(wxPG_CURSOR_IMAGE_WIDTH
,wxPG_CURSOR_IMAGE_WIDTH
);
1611 #if wxPG_CAN_DRAW_CURSOR
1613 void wxCursorProperty::OnCustomPaint( wxDC
& dc
,
1615 wxPGPaintData
& paintdata
)
1618 dc
.SetBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BTNFACE
) );
1620 if ( paintdata
.m_choiceItem
>= 0 )
1622 dc
.DrawRectangle( rect
);
1624 if ( paintdata
.m_choiceItem
< NUM_CURSORS
)
1626 wxStockCursor cursorIndex
=
1627 (wxStockCursor
) gs_cp_es_syscursors_values
[paintdata
.m_choiceItem
];
1630 if ( cursorIndex
== wxCURSOR_NONE
)
1631 cursorIndex
= wxCURSOR_ARROW
;
1633 wxCursor
cursor( cursorIndex
);
1636 HDC hDc
= (HDC
)((const wxMSWDCImpl
*)dc
.GetImpl())->GetHDC();
1640 (HICON
)cursor
.GetHandle(),
1645 #if !defined(__WXWINCE__)
1646 DI_COMPAT
| DI_DEFAULTSIZE
|
1657 void wxCursorProperty::OnCustomPaint( wxDC
&, const wxRect
&, wxPGPaintData
& ) { }
1658 /*wxPGCellRenderer* wxCursorProperty::GetCellRenderer( int column ) const
1660 return wxEnumProperty::GetCellRenderer(column);
1664 // -----------------------------------------------------------------------
1665 // wxImageFileProperty
1666 // -----------------------------------------------------------------------
1670 const wxString
& wxPGGetDefaultImageWildcard()
1672 // Form the wildcard, if not done yet
1673 if ( !wxPGGlobalVars
->m_pDefaultImageWildcard
.length() )
1678 // TODO: This section may require locking (using global).
1680 wxList
& handlers
= wxImage::GetHandlers();
1682 wxList::iterator node
;
1684 // Let's iterate over the image handler list.
1685 //for ( wxList::Node *node = handlers.GetFirst(); node; node = node->GetNext() )
1686 for ( node
= handlers
.begin(); node
!= handlers
.end(); ++node
)
1688 wxImageHandler
*handler
= (wxImageHandler
*)*node
;
1690 wxString ext_lo
= handler
->GetExtension();
1691 wxString ext_up
= ext_lo
.Upper();
1693 str
.append( ext_up
);
1694 str
.append( wxT(" files (*.") );
1695 str
.append( ext_up
);
1696 str
.append( wxT(")|*.") );
1697 str
.append( ext_lo
);
1698 str
.append( wxT("|") );
1701 str
.append ( wxT("All files (*.*)|*.*") );
1703 wxPGGlobalVars
->m_pDefaultImageWildcard
= str
;
1706 return wxPGGlobalVars
->m_pDefaultImageWildcard
;
1709 IMPLEMENT_DYNAMIC_CLASS(wxImageFileProperty
, wxFileProperty
)
1711 wxImageFileProperty::wxImageFileProperty( const wxString
& label
, const wxString
& name
,
1712 const wxString
& value
)
1713 : wxFileProperty(label
,name
,value
)
1715 SetAttribute( wxPG_FILE_WILDCARD
, wxPGGetDefaultImageWildcard() );
1717 m_pImage
= (wxImage
*) NULL
;
1718 m_pBitmap
= (wxBitmap
*) NULL
;
1721 wxImageFileProperty::~wxImageFileProperty()
1729 void wxImageFileProperty::OnSetValue()
1731 wxFileProperty::OnSetValue();
1745 wxFileName filename
= GetFileName();
1747 // Create the image thumbnail
1748 if ( filename
.FileExists() )
1750 m_pImage
= new wxImage( filename
.GetFullPath() );
1754 wxSize
wxImageFileProperty::OnMeasureImage( int ) const
1756 return wxPG_DEFAULT_IMAGE_SIZE
;
1759 void wxImageFileProperty::OnCustomPaint( wxDC
& dc
,
1763 if ( m_pBitmap
|| (m_pImage
&& m_pImage
->Ok() ) )
1765 // Draw the thumbnail
1767 // Create the bitmap here because required size is not known in OnSetValue().
1770 m_pImage
->Rescale( rect
.width
, rect
.height
);
1771 m_pBitmap
= new wxBitmap( *m_pImage
);
1776 dc
.DrawBitmap( *m_pBitmap
, rect
.x
, rect
.y
, false );
1780 // No file - just draw a white box
1781 dc
.SetBrush( *wxWHITE_BRUSH
);
1782 dc
.DrawRectangle ( rect
);
1786 #endif // wxUSE_IMAGE
1788 // -----------------------------------------------------------------------
1789 // wxMultiChoiceProperty
1790 // -----------------------------------------------------------------------
1794 #include "wx/choicdlg.h"
1796 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxMultiChoiceProperty
,wxPGProperty
,
1797 wxArrayInt
,const wxArrayInt
&,TextCtrlAndButton
)
1799 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1800 const wxString
& name
,
1801 const wxPGChoices
& choices
,
1802 const wxArrayString
& value
)
1803 : wxPGProperty(label
,name
)
1805 m_choices
.Assign(choices
);
1809 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1810 const wxString
& name
,
1811 const wxArrayString
& strings
,
1812 const wxArrayString
& value
)
1813 : wxPGProperty(label
,name
)
1815 m_choices
.Set(strings
);
1819 wxMultiChoiceProperty::wxMultiChoiceProperty( const wxString
& label
,
1820 const wxString
& name
,
1821 const wxArrayString
& value
)
1822 : wxPGProperty(label
,name
)
1824 wxArrayString strings
;
1825 m_choices
.Set(strings
);
1829 wxMultiChoiceProperty::~wxMultiChoiceProperty()
1833 void wxMultiChoiceProperty::OnSetValue()
1835 GenerateValueAsString(m_value
, &m_display
);
1838 wxString
wxMultiChoiceProperty::ValueToString( wxVariant
& value
,
1839 int argFlags
) const
1841 // If possible, use cached string
1842 if ( argFlags
& wxPG_VALUE_IS_CURRENT
)
1846 GenerateValueAsString(value
, &s
);
1850 void wxMultiChoiceProperty::GenerateValueAsString( wxVariant
& value
,
1851 wxString
* target
) const
1853 wxArrayString strings
;
1855 if ( value
.GetType() == wxPG_VARIANT_TYPE_ARRSTRING
)
1856 strings
= value
.GetArrayString();
1858 wxString
& tempStr
= *target
;
1860 unsigned int itemCount
= strings
.size();
1865 tempStr
.append( wxT("\"") );
1867 for ( i
= 0; i
< itemCount
; i
++ )
1869 tempStr
.append( strings
[i
] );
1870 tempStr
.append( wxT("\"") );
1871 if ( i
< (itemCount
-1) )
1872 tempStr
.append ( wxT(" \"") );
1876 wxArrayInt
wxMultiChoiceProperty::GetValueAsIndices() const
1878 const wxArrayInt
& valueArr
= wxArrayIntRefFromVariant(GetValue());
1881 // Translate values to string indices.
1882 wxArrayInt selections
;
1884 if ( !m_choices
.IsOk() || !m_choices
.GetCount() || !(&valueArr
) )
1886 for ( i
=0; i
<valueArr
.size(); i
++ )
1891 for ( i
=0; i
<valueArr
.size(); i
++ )
1893 int sIndex
= m_choices
.Index(valueArr
[i
]);
1895 selections
.Add(sIndex
);
1902 bool wxMultiChoiceProperty::OnEvent( wxPropertyGrid
* propgrid
,
1903 wxWindow
* WXUNUSED(primary
),
1906 if ( propgrid
->IsMainButtonEvent(event
) )
1909 wxVariant useValue
= propgrid
->GetUncommittedPropertyValue();
1911 wxArrayString labels
= m_choices
.GetLabels();
1912 unsigned int choiceCount
;
1914 if ( m_choices
.IsOk() )
1915 choiceCount
= m_choices
.GetCount();
1919 // launch editor dialog
1920 wxMultiChoiceDialog
dlg( propgrid
,
1921 _("Make a selection:"),
1924 choiceCount
?&labels
[0]:NULL
,
1925 wxCHOICEDLG_STYLE
);
1927 dlg
.Move( propgrid
->GetGoodEditorDialogPosition(this,dlg
.GetSize()) );
1929 wxArrayString strings
= useValue
.GetArrayString();
1930 wxArrayString extraStrings
;
1932 dlg
.SetSelections(m_choices
.GetIndicesForStrings(strings
, &extraStrings
));
1934 if ( dlg
.ShowModal() == wxID_OK
&& choiceCount
)
1936 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1938 wxArrayInt arrInt
= dlg
.GetSelections();
1942 // Strings that were not in list of choices
1943 wxArrayString value
;
1945 // Translate string indices to strings
1948 if ( userStringMode
== 1 )
1950 for (n
=0;n
<extraStrings
.size();n
++)
1951 value
.push_back(extraStrings
[n
]);
1955 for ( i
=0; i
<arrInt
.size(); i
++ )
1956 value
.Add(m_choices
.GetLabel(arrInt
.Item(i
)));
1958 if ( userStringMode
== 2 )
1960 for (n
=0;n
<extraStrings
.size();n
++)
1961 value
.push_back(extraStrings
[n
]);
1964 variant
= WXVARIANT(value
);
1966 SetValueInEvent(variant
);
1974 bool wxMultiChoiceProperty::StringToValue( wxVariant
& variant
, const wxString
& text
, int ) const
1978 int userStringMode
= GetAttributeAsLong(wxT("UserStringMode"), 0);
1980 WX_PG_TOKENIZER2_BEGIN(text
,wxT('"'))
1981 if ( userStringMode
> 0 || (m_choices
.IsOk() && m_choices
.Index( token
) != wxNOT_FOUND
) )
1983 WX_PG_TOKENIZER2_END()
1985 wxVariant
v( WXVARIANT(arr
) );
1991 #endif // wxUSE_CHOICEDLG
1994 // -----------------------------------------------------------------------
1996 // -----------------------------------------------------------------------
2001 #if wxUSE_DATEPICKCTRL
2002 #define dtCtrl DatePickerCtrl
2004 #define dtCtrl TextCtrl
2007 WX_PG_IMPLEMENT_PROPERTY_CLASS(wxDateProperty
,
2014 wxString
wxDateProperty::ms_defaultDateFormat
;
2017 wxDateProperty::wxDateProperty( const wxString
& label
,
2018 const wxString
& name
,
2019 const wxDateTime
& value
)
2020 : wxPGProperty(label
,name
)
2022 //wxPGRegisterDefaultValueType(wxDateTime)
2024 #if wxUSE_DATEPICKCTRL
2025 wxPGRegisterEditorClass(DatePickerCtrl
);
2027 m_dpStyle
= wxDP_DEFAULT
| wxDP_SHOWCENTURY
;
2035 wxDateProperty::~wxDateProperty()
2039 bool wxDateProperty::StringToValue( wxVariant
& variant
, const wxString
& text
,
2040 int WXUNUSED(argFlags
) ) const
2044 const char* c
= dt
.ParseFormat(text
, wxString(wxDefaultDateTimeFormat
), wxDefaultDateTime
, NULL
);
2055 wxString
wxDateProperty::ValueToString( wxVariant
& value
,
2056 int argFlags
) const
2058 const wxChar
* format
= (const wxChar
*) NULL
;
2060 wxDateTime dateTime
= value
.GetDateTime();
2062 if ( !dateTime
.IsValid() )
2063 return wxT("Invalid");
2065 if ( !ms_defaultDateFormat
.length() )
2067 #if wxUSE_DATEPICKCTRL
2068 bool showCentury
= m_dpStyle
& wxDP_SHOWCENTURY
? true : false;
2070 bool showCentury
= true;
2072 ms_defaultDateFormat
= DetermineDefaultDateFormat( showCentury
);
2075 if ( m_format
.length() &&
2076 !(argFlags
& wxPG_FULL_VALUE
) )
2077 format
= m_format
.c_str();
2079 // Determine default from locale
2080 // NB: This is really simple stuff, but can't figure anything
2081 // better without proper support in wxLocale
2083 format
= ms_defaultDateFormat
.c_str();
2085 return dateTime
.Format(format
);
2088 wxString
wxDateProperty::DetermineDefaultDateFormat( bool showCentury
)
2090 // This code is basicly copied from datectlg.cpp's SetFormat
2095 dt
.ParseFormat(wxT("2003-10-13"), wxT("%Y-%m-%d"));
2096 wxString
str(dt
.Format(wxT("%x")));
2098 const wxChar
*p
= str
.c_str();
2102 if (n
== dt
.GetDay())
2104 format
.Append(wxT("%d"));
2107 else if (n
== (int)dt
.GetMonth()+1)
2109 format
.Append(wxT("%m"));
2112 else if (n
== dt
.GetYear())
2114 format
.Append(wxT("%Y"));
2117 else if (n
== (dt
.GetYear() % 100))
2120 format
.Append(wxT("%Y"));
2122 format
.Append(wxT("%y"));
2126 format
.Append(*p
++);
2132 bool wxDateProperty::DoSetAttribute( const wxString
& name
, wxVariant
& value
)
2134 if ( name
== wxPG_DATE_FORMAT
)
2136 m_format
= value
.GetString();
2139 else if ( name
== wxPG_DATE_PICKER_STYLE
)
2141 m_dpStyle
= value
.GetLong();
2142 ms_defaultDateFormat
.clear(); // This may need recalculation
2148 #endif // wxUSE_DATETIME
2151 // -----------------------------------------------------------------------
2152 // wxPropertyGridInterface
2153 // -----------------------------------------------------------------------
2155 void wxPropertyGridInterface::InitAllTypeHandlers()
2159 // -----------------------------------------------------------------------
2161 void wxPropertyGridInterface::RegisterAdditionalEditors()
2163 // Register editor classes, if necessary.
2164 if ( wxPGGlobalVars
->m_mapEditorClasses
.empty() )
2165 wxPropertyGrid::RegisterDefaultEditors();
2168 wxPGRegisterEditorClass(SpinCtrl
);
2170 #if wxUSE_DATEPICKCTRL
2171 wxPGRegisterEditorClass(DatePickerCtrl
);
2175 // -----------------------------------------------------------------------
2177 #endif // wxPG_INCLUDE_ADVPROPS
2179 #endif // wxUSE_PROPGRID