1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/editors.cpp
3 // Purpose: wxPropertyGrid editors
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/dcmemory.h"
33 #include "wx/button.h"
36 #include "wx/cursor.h"
37 #include "wx/dialog.h"
38 #include "wx/settings.h"
39 #include "wx/msgdlg.h"
40 #include "wx/choice.h"
41 #include "wx/stattext.h"
42 #include "wx/scrolwin.h"
43 #include "wx/dirdlg.h"
45 #include "wx/textdlg.h"
46 #include "wx/filedlg.h"
47 #include "wx/statusbr.h"
54 #include "wx/dcbuffer.h"
55 #include "wx/bmpbuttn.h"
58 // This define is necessary to prevent macro clearing
59 #define __wxPG_SOURCE_FILE__
61 #include "wx/propgrid/propgrid.h"
62 #include "wx/propgrid/editors.h"
63 #include "wx/propgrid/props.h"
65 #if wxPG_USE_RENDERER_NATIVE
66 #include "wx/renderer.h"
69 // How many pixels between textctrl and button
71 #define wxPG_TEXTCTRL_AND_BUTTON_SPACING 4
73 #define wxPG_TEXTCTRL_AND_BUTTON_SPACING 2
76 #define wxPG_BUTTON_SIZEDEC 0
78 #include "wx/odcombo.h"
80 // -----------------------------------------------------------------------
82 #if defined(__WXMSW__)
84 #define wxPG_NAT_BUTTON_BORDER_ANY 1
85 #define wxPG_NAT_BUTTON_BORDER_X 1
86 #define wxPG_NAT_BUTTON_BORDER_Y 1
88 #define wxPG_CHECKMARK_XADJ 1
89 #define wxPG_CHECKMARK_YADJ (-1)
90 #define wxPG_CHECKMARK_WADJ 0
91 #define wxPG_CHECKMARK_HADJ 0
92 #define wxPG_CHECKMARK_DEFLATE 0
94 #define wxPG_TEXTCTRLYADJUST (m_spacingy+0)
96 #elif defined(__WXGTK__)
98 #define wxPG_CHECKMARK_XADJ 0
99 #define wxPG_CHECKMARK_YADJ 0
100 #define wxPG_CHECKMARK_WADJ (-1)
101 #define wxPG_CHECKMARK_HADJ (-1)
102 #define wxPG_CHECKMARK_DEFLATE 3
104 #define wxPG_NAT_BUTTON_BORDER_ANY 1
105 #define wxPG_NAT_BUTTON_BORDER_X 1
106 #define wxPG_NAT_BUTTON_BORDER_Y 1
108 #define wxPG_TEXTCTRLYADJUST 0
110 #elif defined(__WXMAC__)
112 #define wxPG_CHECKMARK_XADJ 0
113 #define wxPG_CHECKMARK_YADJ 0
114 #define wxPG_CHECKMARK_WADJ 0
115 #define wxPG_CHECKMARK_HADJ 0
116 #define wxPG_CHECKMARK_DEFLATE 0
118 #define wxPG_NAT_BUTTON_BORDER_ANY 0
119 #define wxPG_NAT_BUTTON_BORDER_X 0
120 #define wxPG_NAT_BUTTON_BORDER_Y 0
122 #define wxPG_TEXTCTRLYADJUST 0
126 #define wxPG_CHECKMARK_XADJ 0
127 #define wxPG_CHECKMARK_YADJ 0
128 #define wxPG_CHECKMARK_WADJ 0
129 #define wxPG_CHECKMARK_HADJ 0
130 #define wxPG_CHECKMARK_DEFLATE 0
132 #define wxPG_NAT_BUTTON_BORDER_ANY 0
133 #define wxPG_NAT_BUTTON_BORDER_X 0
134 #define wxPG_NAT_BUTTON_BORDER_Y 0
136 #define wxPG_TEXTCTRLYADJUST 0
142 #define wxPG_CHOICEXADJUST -3 // required because wxComboCtrl reserves 3pixels for wxTextCtrl's focus ring
143 #define wxPG_CHOICEYADJUST -3
145 #define wxPG_CHOICEXADJUST 0
146 #define wxPG_CHOICEYADJUST 0
149 // Number added to image width for SetCustomPaintWidth
150 #define ODCB_CUST_PAINT_MARGIN 6
152 // Milliseconds to wait for two mouse-ups after focus inorder
153 // to trigger a double-click.
154 #define DOUBLE_CLICK_CONVERSION_TRESHOLD 500
156 // -----------------------------------------------------------------------
158 // -----------------------------------------------------------------------
160 IMPLEMENT_ABSTRACT_CLASS(wxPGEditor
, wxObject
)
163 wxPGEditor
::~wxPGEditor()
167 wxString wxPGEditor
::GetName() const
169 return GetClassInfo()->GetClassName();
172 void wxPGEditor
::DrawValue( wxDC
& dc
, const wxRect
& rect
,
173 wxPGProperty
* WXUNUSED(property
),
174 const wxString
& text
) const
176 dc
.DrawText( text
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
179 bool wxPGEditor
::GetValueFromControl( wxVariant
&, wxPGProperty
*, wxWindow
* ) const
184 void wxPGEditor
::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, const wxString
& ) const
189 void wxPGEditor
::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, int ) const
194 int wxPGEditor
::InsertItem( wxWindow
*, const wxString
&, int ) const
200 void wxPGEditor
::DeleteItem( wxWindow
*, int ) const
206 void wxPGEditor
::OnFocus( wxPGProperty
*, wxWindow
* ) const
210 void wxPGEditor
::SetControlAppearance( wxPropertyGrid
* pg
,
211 wxPGProperty
* property
,
213 const wxPGCell
& cell
,
214 const wxPGCell
& oCell
,
215 bool WXUNUSED(unspecified
) ) const
217 // Get old editor appearance
218 wxTextCtrl
* tc
= NULL
;
219 wxComboCtrl
* cb
= NULL
;
220 if ( ctrl
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
222 tc
= (wxTextCtrl
*) ctrl
;
226 if ( ctrl
->IsKindOf(CLASSINFO(wxComboCtrl
)) )
228 cb
= (wxComboCtrl
*) ctrl
;
229 tc
= cb
->GetTextCtrl();
236 bool changeText
= false;
238 if ( cell
.HasText() && !pg
->IsEditorFocused() )
240 tcText
= cell
.GetText();
243 else if ( oCell
.HasText() )
245 tcText
= property
->GetValueAsString(
246 property
->HasFlag(wxPG_PROP_READONLY
)?
0:wxPG_EDITABLE_VALUE
);
252 // This prevents value from being modified
255 pg
->SetupTextCtrlValue(tcText
);
256 tc
->SetValue(tcText
);
265 wxVisualAttributes vattrs
= ctrl
->GetDefaultAttributes();
268 const wxColour
& fgCol
= cell
.GetFgCol();
271 ctrl
->SetForegroundColour(fgCol
);
273 else if ( oCell
.GetFgCol().IsOk() )
275 ctrl
->SetForegroundColour(vattrs
.colFg
);
279 const wxColour
& bgCol
= cell
.GetBgCol();
282 ctrl
->SetBackgroundColour(bgCol
);
284 else if ( oCell
.GetBgCol().IsOk() )
286 ctrl
->SetBackgroundColour(vattrs
.colBg
);
290 const wxFont
& font
= cell
.GetFont();
295 else if ( oCell
.GetFont().IsOk() )
297 ctrl
->SetFont(vattrs
.font
);
300 // Also call the old SetValueToUnspecified()
301 SetValueToUnspecified(property
, ctrl
);
304 void wxPGEditor
::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
),
305 wxWindow
* WXUNUSED(ctrl
) ) const
309 bool wxPGEditor
::CanContainCustomImage() const
314 // -----------------------------------------------------------------------
315 // wxPGTextCtrlEditor
316 // -----------------------------------------------------------------------
318 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrl
,wxPGTextCtrlEditor
,wxPGEditor
)
321 wxPGWindowList wxPGTextCtrlEditor
::CreateControls( wxPropertyGrid
* propGrid
,
322 wxPGProperty
* property
,
324 const wxSize
& sz
) const
329 // If has children, and limited editing is specified, then don't create.
330 if ( (property
->GetFlags() & wxPG_PROP_NOEDITOR
) &&
331 property
->GetChildCount() )
335 if ( !property
->HasFlag(wxPG_PROP_READONLY
) &&
336 !property
->IsValueUnspecified() )
337 argFlags
|= wxPG_EDITABLE_VALUE
;
338 text
= property
->GetValueAsString(argFlags
);
341 if ( (property
->GetFlags() & wxPG_PROP_PASSWORD
) &&
342 property
->IsKindOf(CLASSINFO(wxStringProperty
)) )
343 flags
|= wxTE_PASSWORD
;
345 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrl(pos
,sz
,text
,NULL
,flags
,
346 property
->GetMaxLength());
352 void wxPGTextCtrlEditor
::DrawValue( wxDC
& dc
, wxPGProperty
* property
, const wxRect
& rect
) const
354 if ( !property
->IsValueUnspecified() )
356 wxString drawStr
= property
->GetDisplayedString();
358 // Code below should no longer be needed, as the obfuscation
359 // is now done in GetValueAsString.
360 /*if ( (property->GetFlags() & wxPG_PROP_PASSWORD) &&
361 property->IsKindOf(WX_PG_CLASSINFO(wxStringProperty)) )
363 size_t a = drawStr.length();
365 drawStr.Append(wxS('*'),a);
367 dc
.DrawText( drawStr
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
372 void wxPGTextCtrlEditor
::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
374 wxTextCtrl
* tc
= wxDynamicCast(ctrl
, wxTextCtrl
);
379 if ( tc
->HasFlag(wxTE_PASSWORD
) )
380 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
382 s
= property
->GetDisplayedString();
384 wxPropertyGrid
* pg
= property
->GetGrid();
386 pg
->SetupTextCtrlValue(s
);
390 // Fix indentation, just in case (change in font boldness is one good
395 // Provided so that, for example, ComboBox editor can use the same code
396 // (multiple inheritance would get way too messy).
397 bool wxPGTextCtrlEditor
::OnTextCtrlEvent( wxPropertyGrid
* propGrid
,
398 wxPGProperty
* WXUNUSED(property
),
405 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
407 if ( propGrid
->IsEditorsValueModified() )
412 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
415 // Pass this event outside wxPropertyGrid so that,
416 // if necessary, program can tell when user is editing
418 // FIXME: Is it safe to change event id in the middle of event
419 // processing (seems to work, but...)?
421 event
.SetId(propGrid
->GetId());
423 propGrid
->EditorsValueWasModified();
429 bool wxPGTextCtrlEditor
::OnEvent( wxPropertyGrid
* propGrid
,
430 wxPGProperty
* property
,
432 wxEvent
& event
) const
434 return wxPGTextCtrlEditor
::OnTextCtrlEvent(propGrid
,property
,ctrl
,event
);
438 bool wxPGTextCtrlEditor
::GetTextCtrlValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
)
440 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
441 wxString textVal
= tc
->GetValue();
443 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
449 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
451 // Changing unspecified always causes event (returning
452 // true here should be enough to trigger it).
453 // TODO: Move to propgrid.cpp
454 if ( !res
&& variant
.IsNull() )
461 bool wxPGTextCtrlEditor
::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
463 return wxPGTextCtrlEditor
::GetTextCtrlValueFromControl(variant
, property
, ctrl
);
467 void wxPGTextCtrlEditor
::SetControlStringValue( wxPGProperty
* property
, wxWindow
* ctrl
, const wxString
& txt
) const
469 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
471 wxPropertyGrid
* pg
= property
->GetGrid();
472 wxASSERT(pg
); // Really, property grid should exist if editor does
475 pg
->SetupTextCtrlValue(txt
);
481 void wxPGTextCtrlEditor_OnFocus( wxPGProperty
* property
,
484 // Make sure there is correct text (instead of unspecified value
485 // indicator or inline help)
486 int flags
= property
->HasFlag(wxPG_PROP_READONLY
) ?
487 0 : wxPG_EDITABLE_VALUE
;
488 wxString correctText
= property
->GetValueAsString(flags
);
490 if ( tc
->GetValue() != correctText
)
492 property
->GetGrid()->SetupTextCtrlValue(correctText
);
493 tc
->SetValue(correctText
);
496 tc
->SetSelection(-1,-1);
499 void wxPGTextCtrlEditor
::OnFocus( wxPGProperty
* property
,
500 wxWindow
* wnd
) const
502 wxTextCtrl
* tc
= wxStaticCast(wnd
, wxTextCtrl
);
503 wxPGTextCtrlEditor_OnFocus(property
, tc
);
506 wxPGTextCtrlEditor
::~wxPGTextCtrlEditor() { }
509 // -----------------------------------------------------------------------
511 // -----------------------------------------------------------------------
514 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(Choice
,wxPGChoiceEditor
,wxPGEditor
)
517 // This is a special enhanced double-click processor class.
518 // In essence, it allows for double-clicks for which the
519 // first click "created" the control.
520 class wxPGDoubleClickProcessor
: public wxEvtHandler
524 wxPGDoubleClickProcessor( wxOwnerDrawnComboBox
* combo
, wxPGProperty
* property
)
527 m_timeLastMouseUp
= 0;
529 m_property
= property
;
530 m_downReceived
= false;
535 void OnMouseEvent( wxMouseEvent
& event
)
537 wxLongLong t
= ::wxGetLocalTimeMillis();
538 int evtType
= event
.GetEventType();
540 if ( m_property
->HasFlag(wxPG_PROP_USE_DCC
) &&
541 m_property
->IsKindOf(CLASSINFO(wxBoolProperty
)) &&
542 !m_combo
->IsPopupShown() )
544 // Just check that it is in the text area
545 wxPoint pt
= event
.GetPosition();
546 if ( m_combo
->GetTextRect().Contains(pt
) )
548 if ( evtType
== wxEVT_LEFT_DOWN
)
550 // Set value to avoid up-events without corresponding downs
551 m_downReceived
= true;
553 else if ( evtType
== wxEVT_LEFT_DCLICK
)
555 // We'll make our own double-clicks
556 event
.SetEventType(0);
559 else if ( evtType
== wxEVT_LEFT_UP
)
561 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
563 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
565 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
567 event
.SetEventType(wxEVT_LEFT_DCLICK
);
568 m_timeLastMouseUp
= 1;
572 m_timeLastMouseUp
= t
;
582 void OnSetFocus( wxFocusEvent
& event
)
584 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
589 wxLongLong m_timeLastMouseUp
;
590 wxOwnerDrawnComboBox
* m_combo
;
591 wxPGProperty
* m_property
; // Selected property
594 DECLARE_EVENT_TABLE()
597 BEGIN_EVENT_TABLE(wxPGDoubleClickProcessor
, wxEvtHandler
)
598 EVT_MOUSE_EVENTS(wxPGDoubleClickProcessor
::OnMouseEvent
)
599 EVT_SET_FOCUS(wxPGDoubleClickProcessor
::OnSetFocus
)
604 class wxPGComboBox
: public wxOwnerDrawnComboBox
609 : wxOwnerDrawnComboBox()
611 m_dclickProcessor
= NULL
;
612 m_sizeEventCalled
= false;
617 if ( m_dclickProcessor
)
619 RemoveEventHandler(m_dclickProcessor
);
620 delete m_dclickProcessor
;
624 bool Create(wxWindow
*parent
,
626 const wxString
& value
,
629 const wxArrayString
& choices
,
631 const wxValidator
& validator
= wxDefaultValidator
,
632 const wxString
& name
= wxS("wxOwnerDrawnComboBox"))
634 if ( !wxOwnerDrawnComboBox
::Create( parent
,
645 m_dclickProcessor
= new
646 wxPGDoubleClickProcessor( this, GetGrid()->GetSelection() );
648 PushEventHandler(m_dclickProcessor
);
653 virtual void OnDrawItem( wxDC
& dc
,
658 wxPropertyGrid
* pg
= GetGrid();
659 pg
->OnComboItemPaint( this, item
, &dc
, (wxRect
&)rect
, flags
);
662 virtual wxCoord
OnMeasureItem( size_t item
) const
664 wxPropertyGrid
* pg
= GetGrid();
668 pg
->OnComboItemPaint( this, item
, NULL
, rect
, 0 );
672 wxPropertyGrid
* GetGrid() const
674 wxPropertyGrid
* pg
= wxDynamicCast(GetParent(),
680 virtual wxCoord
OnMeasureItemWidth( size_t item
) const
682 wxPropertyGrid
* pg
= GetGrid();
686 pg
->OnComboItemPaint( this, item
, NULL
, rect
, 0 );
690 virtual void PositionTextCtrl( int textCtrlXAdjust
,
691 int WXUNUSED(textCtrlYAdjust
) )
693 wxPropertyGrid
* pg
= GetGrid();
694 #ifdef wxPG_TEXTCTRLXADJUST
695 textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
-
696 (wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1) - 1,
698 wxOwnerDrawnComboBox
::PositionTextCtrl(
700 pg
->GetSpacingY() + 2
705 wxPGDoubleClickProcessor
* m_dclickProcessor
;
706 bool m_sizeEventCalled
;
710 void wxPropertyGrid
::OnComboItemPaint( const wxPGComboBox
* pCb
,
717 wxASSERT( IsKindOf(CLASSINFO(wxPropertyGrid
)) );
719 wxPGProperty
* p
= GetSelection();
722 const wxPGChoices
& choices
= p
->GetChoices();
723 const wxPGCommonValue
* comVal
= NULL
;
724 int comVals
= p
->GetDisplayedCommonValueCount();
725 int comValIndex
= -1;
728 if ( choices
.IsOk() )
729 choiceCount
= choices
.GetCount();
731 if ( item
>= choiceCount
&& comVals
> 0 )
733 comValIndex
= item
- choiceCount
;
734 comVal
= GetCommonValue(comValIndex
);
735 if ( !p
->IsValueUnspecified() )
736 text
= comVal
->GetLabel();
740 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
742 text
= pCb
->GetString(item
);
746 if ( !p
->IsValueUnspecified() )
747 text
= p
->GetValueAsString(0);
756 const wxBitmap
* itemBitmap
= NULL
;
758 if ( item
>= 0 && choices
.IsOk() && choices
.Item(item
).GetBitmap().Ok() && comValIndex
== -1 )
759 itemBitmap
= &choices
.Item(item
).GetBitmap();
762 // Decide what custom image size to use
765 cis
.x
= itemBitmap
->GetWidth();
766 cis
.y
= itemBitmap
->GetHeight();
770 cis
= GetImageSize(p
, item
);
775 // Default measure behaviour (no flexible, custom paint image only)
776 if ( rect
.width
< 0 )
779 pCb
->GetTextExtent(text
, &x
, &y
, 0, 0);
780 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9 + x
;
783 rect
.height
= cis
.y
+ 2;
787 wxPGPaintData paintdata
;
788 paintdata
.m_parent
= NULL
;
789 paintdata
.m_choiceItem
= item
;
791 // This is by the current (1.0.0b) spec - if painting control, item is -1
792 if ( (flags
& wxODCB_PAINTING_CONTROL
) )
793 paintdata
.m_choiceItem
= -1;
796 pDc
->SetBrush(*wxWHITE_BRUSH
);
798 wxPGCellRenderer
* renderer
= NULL
;
799 const wxPGChoiceEntry
* cell
= NULL
;
807 wxPoint
pt(rect
.x
+ wxPG_CONTROL_MARGIN
- wxPG_CHOICEXADJUST
- 1,
810 int renderFlags
= wxPGCellRenderer
::DontUseCellColours
;
811 bool useCustomPaintProcedure
;
813 // If custom image had some size, we will start from the assumption
814 // that custom paint procedure is required
816 useCustomPaintProcedure
= true;
818 useCustomPaintProcedure
= false;
820 if ( flags
& wxODCB_PAINTING_SELECTED
)
821 renderFlags
|= wxPGCellRenderer
::Selected
;
823 if ( flags
& wxODCB_PAINTING_CONTROL
)
825 renderFlags
|= wxPGCellRenderer
::Control
;
827 // If wxPG_PROP_CUSTOMIMAGE was set, then that means any custom
828 // image will not appear on the control row (it may be too
829 // large to fit, for instance). Also do not draw custom image
830 // if no choice was selected.
831 if ( !p
->HasFlag(wxPG_PROP_CUSTOMIMAGE
) || item
< 0 )
832 useCustomPaintProcedure
= false;
836 renderFlags
|= wxPGCellRenderer
::ChoicePopup
;
839 // If not drawing a selected popup item, then give property's
840 // m_valueBitmap a chance.
841 if ( p
->m_valueBitmap
&& item
!= pCb
->GetSelection() )
842 useCustomPaintProcedure
= false;
843 // If current choice had a bitmap set by the application, then
844 // use it instead of any custom paint procedure.
845 else if ( itemBitmap
)
846 useCustomPaintProcedure
= false;
848 if ( useCustomPaintProcedure
)
850 pt
.x
+= wxCC_CUSTOM_IMAGE_MARGIN1
;
851 wxRect
r(pt
.x
,pt
.y
,cis
.x
,cis
.y
);
853 if ( flags
& wxODCB_PAINTING_CONTROL
)
856 r
.height
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
859 paintdata
.m_drawnWidth
= r
.width
;
861 dc
.SetPen(m_colPropFore
);
862 if ( comValIndex
>= 0 )
864 const wxPGCommonValue
* cv
= GetCommonValue(comValIndex
);
865 wxPGCellRenderer
* renderer
= cv
->GetRenderer();
866 r
.width
= rect
.width
;
867 renderer
->Render( dc
, r
, this, p
, m_selColumn
, comValIndex
, renderFlags
);
870 else if ( item
>= 0 )
872 p
->OnCustomPaint( dc
, r
, paintdata
);
876 dc
.DrawRectangle( r
);
879 pt
.x
+= paintdata
.m_drawnWidth
+ wxCC_CUSTOM_IMAGE_MARGIN2
- 1;
883 // TODO: This aligns text so that it seems to be horizontally
884 // on the same line as property values. Not really
885 // sure if its needed, but seems to not cause any harm.
888 if ( item
< 0 && (flags
& wxODCB_PAINTING_CONTROL
) )
889 item
= pCb
->GetSelection();
891 if ( choices
.IsOk() && item
>= 0 && comValIndex
< 0 )
893 cell
= &choices
.Item(item
);
894 renderer
= wxPGGlobalVars
->m_defaultRenderer
;
895 int imageOffset
= renderer
->PreDrawCell(dc
, rect
, *cell
,
898 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+
899 wxCC_CUSTOM_IMAGE_MARGIN2
;
908 pt
.y
+= (rect
.height
-m_fontHeight
)/2 - 1;
912 dc
.DrawText( text
, pt
.x
+ wxPG_XBEFORETEXT
, pt
.y
);
915 renderer
->PostDrawCell(dc
, this, *cell
, renderFlags
);
923 p
->OnCustomPaint( dc
, rect
, paintdata
);
924 rect
.height
= paintdata
.m_drawnHeight
+ 2;
925 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9;
929 bool wxPGChoiceEditor_SetCustomPaintWidth( wxPropertyGrid
* propGrid
, wxPGComboBox
* cb
, int cmnVal
)
931 wxPGProperty
* property
= propGrid
->GetSelectedProperty();
932 wxASSERT( property
);
937 // TODO: Do this always when cell has custom text.
938 if ( property
->IsValueUnspecified() )
940 cb
->SetCustomPaintWidth( 0 );
946 // Yes, a common value is being selected
947 property
->SetCommonValue( cmnVal
);
948 imageSize
= propGrid
->GetCommonValue(cmnVal
)->
949 GetRenderer()->GetImageSize(property
, 1, cmnVal
);
954 imageSize
= propGrid
->GetImageSize(property
, -1);
959 imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
960 cb
->SetCustomPaintWidth( imageSize
.x
);
965 // CreateControls calls this with CB_READONLY in extraStyle
966 wxWindow
* wxPGChoiceEditor
::CreateControlsBase( wxPropertyGrid
* propGrid
,
967 wxPGProperty
* property
,
970 long extraStyle
) const
972 const wxPGChoices
& choices
= property
->GetChoices();
974 int index
= property
->GetChoiceSelection();
977 if ( !property
->HasFlag(wxPG_PROP_READONLY
) &&
978 !property
->IsValueUnspecified() )
979 argFlags
|= wxPG_EDITABLE_VALUE
;
980 defString
= property
->GetValueAsString(argFlags
);
982 wxArrayString labels
= choices
.GetLabels();
988 po
.y
+= wxPG_CHOICEYADJUST
;
989 si
.y
-= (wxPG_CHOICEYADJUST
*2);
991 po
.x
+= wxPG_CHOICEXADJUST
;
992 si
.x
-= wxPG_CHOICEXADJUST
;
993 wxWindow
* ctrlParent
= propGrid
->GetPanel();
995 int odcbFlags
= extraStyle
| wxBORDER_NONE
| wxTE_PROCESS_ENTER
;
997 if ( (property
->GetFlags() & wxPG_PROP_USE_DCC
) &&
998 (property
->IsKindOf(CLASSINFO(wxBoolProperty
)) ) )
999 odcbFlags
|= wxODCB_DCLICK_CYCLES
;
1002 // If common value specified, use appropriate index
1003 unsigned int cmnVals
= property
->GetDisplayedCommonValueCount();
1006 if ( !property
->IsValueUnspecified() )
1008 int cmnVal
= property
->GetCommonValue();
1011 index
= labels
.size() + cmnVal
;
1016 for ( i
=0; i
<cmnVals
; i
++ )
1017 labels
.Add(propGrid
->GetCommonValueLabel(i
));
1020 cb
= new wxPGComboBox();
1024 cb
->Create(ctrlParent
,
1032 cb
->SetButtonPosition(si
.y
,0,wxRIGHT
);
1033 cb
->SetMargins(wxPG_XBEFORETEXT
-1);
1035 wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, property
->GetCommonValue() );
1037 if ( index
>= 0 && index
< (int)cb
->GetCount() )
1039 cb
->SetSelection( index
);
1040 if ( defString
.length() )
1041 cb
->SetText( defString
);
1043 else if ( !(extraStyle
& wxCB_READONLY
) && defString
.length() )
1045 propGrid
->SetupTextCtrlValue(defString
);
1046 cb
->SetValue( defString
);
1050 cb
->SetSelection( -1 );
1057 return (wxWindow
*) cb
;
1061 void wxPGChoiceEditor
::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1064 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1065 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1066 int ind
= property
->GetChoiceSelection();
1067 cb
->SetSelection(ind
);
1070 wxPGWindowList wxPGChoiceEditor
::CreateControls( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
1071 const wxPoint
& pos
, const wxSize
& sz
) const
1073 return CreateControlsBase(propGrid
,property
,pos
,sz
,wxCB_READONLY
);
1077 int wxPGChoiceEditor
::InsertItem( wxWindow
* ctrl
, const wxString
& label
, int index
) const
1080 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1081 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1084 index
= cb
->GetCount();
1086 return cb
->Insert(label
,index
);
1090 void wxPGChoiceEditor
::DeleteItem( wxWindow
* ctrl
, int index
) const
1093 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1094 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1099 bool wxPGChoiceEditor
::OnEvent( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
1100 wxWindow
* ctrl
, wxEvent
& event
) const
1102 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
1104 wxPGComboBox
* cb
= (wxPGComboBox
*)ctrl
;
1105 int index
= cb
->GetSelection();
1106 int cmnValIndex
= -1;
1107 int cmnVals
= property
->GetDisplayedCommonValueCount();
1108 int items
= cb
->GetCount();
1110 if ( index
>= (items
-cmnVals
) )
1112 // Yes, a common value is being selected
1113 cmnValIndex
= index
- (items
-cmnVals
);
1114 property
->SetCommonValue( cmnValIndex
);
1116 // Truly set value to unspecified?
1117 if ( propGrid
->GetUnspecifiedCommonValue() == cmnValIndex
)
1119 if ( !property
->IsValueUnspecified() )
1120 propGrid
->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT
);
1121 property
->SetValueToUnspecified();
1122 if ( !cb
->HasFlag(wxCB_READONLY
) )
1124 wxString unspecValueText
;
1125 unspecValueText
= propGrid
->GetUnspecifiedValueText();
1126 propGrid
->SetupTextCtrlValue(unspecValueText
);
1127 cb
->GetTextCtrl()->SetValue(unspecValueText
);
1132 return wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, cmnValIndex
);
1138 bool wxPGChoiceEditor
::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1140 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1142 int index
= cb
->GetSelection();
1144 if ( index
!= property
->GetChoiceSelection() ||
1145 // Changing unspecified always causes event (returning
1146 // true here should be enough to trigger it).
1147 property
->IsValueUnspecified()
1150 return property
->IntToValue( variant
, index
, 0 );
1156 void wxPGChoiceEditor
::SetControlStringValue( wxPGProperty
* property
,
1158 const wxString
& txt
) const
1160 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1162 property
->GetGrid()->SetupTextCtrlValue(txt
);
1167 void wxPGChoiceEditor
::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1169 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1171 cb
->SetSelection(value
);
1175 void wxPGChoiceEditor
::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
),
1176 wxWindow
* ctrl
) const
1178 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1180 if ( cb
->HasFlag(wxCB_READONLY
) )
1181 cb
->SetSelection(-1);
1185 bool wxPGChoiceEditor
::CanContainCustomImage() const
1191 wxPGChoiceEditor
::~wxPGChoiceEditor() { }
1194 // -----------------------------------------------------------------------
1195 // wxPGComboBoxEditor
1196 // -----------------------------------------------------------------------
1199 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ComboBox
,
1204 void wxPGComboBoxEditor
::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1206 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1207 wxString s
= property
->GetValueAsString(wxPG_EDITABLE_VALUE
);
1208 property
->GetGrid()->SetupTextCtrlValue(s
);
1211 // TODO: If string matches any selection, then select that.
1215 wxPGWindowList wxPGComboBoxEditor
::CreateControls( wxPropertyGrid
* propGrid
,
1216 wxPGProperty
* property
,
1218 const wxSize
& sz
) const
1220 return CreateControlsBase(propGrid
,property
,pos
,sz
,0);
1224 bool wxPGComboBoxEditor
::OnEvent( wxPropertyGrid
* propGrid
,
1225 wxPGProperty
* property
,
1227 wxEvent
& event
) const
1229 wxOwnerDrawnComboBox
* cb
= NULL
;
1230 wxWindow
* textCtrl
= NULL
;
1234 cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1235 textCtrl
= cb
->GetTextCtrl();
1238 if ( wxPGTextCtrlEditor
::OnTextCtrlEvent(propGrid
,property
,textCtrl
,event
) )
1241 return wxPGChoiceEditor
::OnEvent(propGrid
,property
,ctrl
,event
);
1245 bool wxPGComboBoxEditor
::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1247 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1248 wxString textVal
= cb
->GetValue();
1250 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
1256 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
1258 // Changing unspecified always causes event (returning
1259 // true here should be enough to trigger it).
1260 if ( !res
&& variant
.IsNull() )
1267 void wxPGComboBoxEditor
::OnFocus( wxPGProperty
* property
,
1268 wxWindow
* ctrl
) const
1270 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1271 wxPGTextCtrlEditor_OnFocus(property
, cb
->GetTextCtrl());
1275 wxPGComboBoxEditor
::~wxPGComboBoxEditor() { }
1278 // -----------------------------------------------------------------------
1279 // wxPGChoiceAndButtonEditor
1280 // -----------------------------------------------------------------------
1283 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ChoiceAndButton
,
1284 wxPGChoiceAndButtonEditor
,
1288 wxPGWindowList wxPGChoiceAndButtonEditor
::CreateControls( wxPropertyGrid
* propGrid
,
1289 wxPGProperty
* property
,
1291 const wxSize
& sz
) const
1293 // Use one two units smaller to match size of the combo's dropbutton.
1294 // (normally a bigger button is used because it looks better)
1297 wxSize
bt_sz(bt_wid
,bt_wid
);
1299 // Position of button.
1300 wxPoint
bt_pos(pos
.x
+sz
.x
-bt_sz
.x
,pos
.y
);
1307 wxWindow
* bt
= propGrid
->GenerateEditorButton( bt_pos
, bt_sz
);
1310 wxSize
ch_sz(sz
.x
-bt
->GetSize().x
,sz
.y
);
1313 ch_sz
.x
-= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1316 wxWindow
* ch
= wxPGEditor_Choice
->CreateControls(propGrid
,property
,
1317 pos
,ch_sz
).m_primary
;
1323 return wxPGWindowList(ch
, bt
);
1327 wxPGChoiceAndButtonEditor
::~wxPGChoiceAndButtonEditor() { }
1330 // -----------------------------------------------------------------------
1331 // wxPGTextCtrlAndButtonEditor
1332 // -----------------------------------------------------------------------
1334 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrlAndButton
,
1335 wxPGTextCtrlAndButtonEditor
,
1339 wxPGWindowList wxPGTextCtrlAndButtonEditor
::CreateControls( wxPropertyGrid
* propGrid
,
1340 wxPGProperty
* property
,
1342 const wxSize
& sz
) const
1345 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrlAndButton( pos
, sz
, &wnd2
,
1346 property
->GetFlags() & wxPG_PROP_NOEDITOR
, property
);
1348 return wxPGWindowList(wnd
, wnd2
);
1352 wxPGTextCtrlAndButtonEditor
::~wxPGTextCtrlAndButtonEditor() { }
1355 // -----------------------------------------------------------------------
1356 // wxPGCheckBoxEditor
1357 // -----------------------------------------------------------------------
1359 #if wxPG_INCLUDE_CHECKBOX
1361 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(CheckBox
,
1366 // Check box state flags
1369 wxSCB_STATE_UNCHECKED
= 0,
1370 wxSCB_STATE_CHECKED
= 1,
1371 wxSCB_STATE_BOLD
= 2,
1372 wxSCB_STATE_UNSPECIFIED
= 4
1375 const int wxSCB_SETVALUE_CYCLE
= 2;
1378 static void DrawSimpleCheckBox( wxDC
& dc
, const wxRect
& rect
, int box_hei
,
1379 int state
, const wxColour
& lineCol
)
1382 wxRect
r(rect
.x
+wxPG_XBEFORETEXT
,rect
.y
+((rect
.height
-box_hei
)/2),
1384 wxColour useCol
= lineCol
;
1386 if ( state
& wxSCB_STATE_UNSPECIFIED
)
1388 useCol
= wxColour(220, 220, 220);
1391 // Draw check mark first because it is likely to overdraw the
1392 // surrounding rectangle.
1393 if ( state
& wxSCB_STATE_CHECKED
)
1395 wxRect
r2(r
.x
+wxPG_CHECKMARK_XADJ
,
1396 r
.y
+wxPG_CHECKMARK_YADJ
,
1397 r
.width
+wxPG_CHECKMARK_WADJ
,
1398 r
.height
+wxPG_CHECKMARK_HADJ
);
1399 #if wxPG_CHECKMARK_DEFLATE
1400 r2
.Deflate(wxPG_CHECKMARK_DEFLATE
);
1402 dc
.DrawCheckMark(r2
);
1404 // This would draw a simple cross check mark.
1405 // dc.DrawLine(r.x,r.y,r.x+r.width-1,r.y+r.height-1);
1406 // dc.DrawLine(r.x,r.y+r.height-1,r.x+r.width-1,r.y);
1409 if ( !(state
& wxSCB_STATE_BOLD
) )
1411 // Pen for thin rectangle.
1416 // Pen for bold rectangle.
1417 wxPen
linepen(useCol
,2,wxSOLID
);
1418 linepen
.SetJoin(wxJOIN_MITER
); // This prevents round edges.
1426 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1428 dc
.DrawRectangle(r
);
1429 dc
.SetPen(*wxTRANSPARENT_PEN
);
1433 // Real simple custom-drawn checkbox-without-label class.
1435 class wxSimpleCheckBox
: public wxControl
1439 void SetValue( int value
);
1441 wxSimpleCheckBox( wxWindow
* parent
,
1443 const wxPoint
& pos
= wxDefaultPosition
,
1444 const wxSize
& size
= wxDefaultSize
)
1445 : wxControl(parent
,id
,pos
,size
,wxBORDER_NONE
|wxWANTS_CHARS
)
1447 // Due to SetOwnFont stuff necessary for GTK+ 1.2, we need to have this
1448 SetFont( parent
->GetFont() );
1453 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
1456 virtual ~wxSimpleCheckBox();
1462 void OnPaint( wxPaintEvent
& event
);
1463 void OnLeftClick( wxMouseEvent
& event
);
1464 void OnKeyDown( wxKeyEvent
& event
);
1466 void OnResize( wxSizeEvent
& event
)
1472 static wxBitmap
* ms_doubleBuffer
;
1474 DECLARE_EVENT_TABLE()
1477 BEGIN_EVENT_TABLE(wxSimpleCheckBox
, wxControl
)
1478 EVT_PAINT(wxSimpleCheckBox
::OnPaint
)
1479 EVT_LEFT_DOWN(wxSimpleCheckBox
::OnLeftClick
)
1480 EVT_LEFT_DCLICK(wxSimpleCheckBox
::OnLeftClick
)
1481 EVT_KEY_DOWN(wxSimpleCheckBox
::OnKeyDown
)
1482 EVT_SIZE(wxSimpleCheckBox
::OnResize
)
1485 wxSimpleCheckBox
::~wxSimpleCheckBox()
1487 delete ms_doubleBuffer
;
1488 ms_doubleBuffer
= NULL
;
1491 wxBitmap
* wxSimpleCheckBox
::ms_doubleBuffer
= NULL
;
1493 void wxSimpleCheckBox
::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1495 wxSize clientSize
= GetClientSize();
1496 wxAutoBufferedPaintDC
dc(this);
1499 wxRect
rect(0,0,clientSize
.x
,clientSize
.y
);
1503 wxColour bgcol
= GetBackgroundColour();
1504 dc
.SetBrush( bgcol
);
1506 dc
.DrawRectangle( rect
);
1508 wxColour txcol
= GetForegroundColour();
1510 int state
= m_state
;
1511 if ( !(state
& wxSCB_STATE_UNSPECIFIED
) &&
1512 GetFont().GetWeight() == wxBOLD
)
1513 state
|= wxSCB_STATE_BOLD
;
1515 DrawSimpleCheckBox(dc
,rect
,m_boxHeight
,state
,txcol
);
1518 void wxSimpleCheckBox
::OnLeftClick( wxMouseEvent
& event
)
1520 if ( (event
.m_x
> (wxPG_XBEFORETEXT
-2)) &&
1521 (event
.m_x
<= (wxPG_XBEFORETEXT
-2+m_boxHeight
)) )
1523 SetValue(wxSCB_SETVALUE_CYCLE
);
1527 void wxSimpleCheckBox
::OnKeyDown( wxKeyEvent
& event
)
1529 if ( event
.GetKeyCode() == WXK_SPACE
)
1531 SetValue(wxSCB_SETVALUE_CYCLE
);
1535 void wxSimpleCheckBox
::SetValue( int value
)
1537 if ( value
== wxSCB_SETVALUE_CYCLE
)
1539 if ( m_state
& wxSCB_STATE_CHECKED
)
1540 m_state
&= ~wxSCB_STATE_CHECKED
;
1542 m_state
|= wxSCB_STATE_CHECKED
;
1550 wxCommandEvent
evt(wxEVT_COMMAND_CHECKBOX_CLICKED
,GetParent()->GetId());
1552 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent();
1553 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1554 propGrid
->HandleCustomEditorEvent(evt
);
1557 wxPGWindowList wxPGCheckBoxEditor
::CreateControls( wxPropertyGrid
* propGrid
,
1558 wxPGProperty
* property
,
1560 const wxSize
& size
) const
1563 pt
.x
-= wxPG_XBEFOREWIDGET
;
1565 sz
.x
= propGrid
->GetFontHeight() + (wxPG_XBEFOREWIDGET
*2) + 4;
1567 wxSimpleCheckBox
* cb
= new wxSimpleCheckBox(propGrid
->GetPanel(),
1568 wxPG_SUBID1
, pt
, sz
);
1570 cb
->SetBackgroundColour(wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOW
));
1572 UpdateControl(property
, cb
);
1574 if ( !property
->IsValueUnspecified() )
1576 // If mouse cursor was on the item, toggle the value now.
1577 if ( propGrid
->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK
)
1579 wxPoint pt
= cb
->ScreenToClient(::wxGetMousePosition());
1580 if ( pt
.x
<= (wxPG_XBEFORETEXT
-2+cb
->m_boxHeight
) )
1582 if ( cb
->m_state
& wxSCB_STATE_CHECKED
)
1583 cb
->m_state
&= ~wxSCB_STATE_CHECKED
;
1585 cb
->m_state
|= wxSCB_STATE_CHECKED
;
1587 // Makes sure wxPG_EVT_CHANGING etc. is sent for this initial
1589 propGrid
->ChangePropertyValue(property
,
1590 wxPGVariant_Bool(cb
->m_state
));
1595 propGrid
->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR
);
1600 void wxPGCheckBoxEditor
::DrawValue( wxDC
& dc
, const wxRect
& rect
,
1601 wxPGProperty
* property
,
1602 const wxString
& WXUNUSED(text
) ) const
1604 int state
= wxSCB_STATE_UNCHECKED
;
1605 wxColour rectCol
= dc
.GetTextForeground();
1607 if ( !property
->IsValueUnspecified() )
1609 state
= property
->GetChoiceSelection();
1610 if ( dc
.GetFont().GetWeight() == wxBOLD
)
1611 state
|= wxSCB_STATE_BOLD
;
1615 state
|= wxSCB_STATE_UNSPECIFIED
;
1618 DrawSimpleCheckBox(dc
, rect
, dc
.GetCharHeight(), state
, rectCol
);
1621 void wxPGCheckBoxEditor
::UpdateControl( wxPGProperty
* property
,
1622 wxWindow
* ctrl
) const
1624 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*) ctrl
;
1627 if ( !property
->IsValueUnspecified() )
1628 cb
->m_state
= property
->GetChoiceSelection();
1630 cb
->m_state
= wxSCB_STATE_UNSPECIFIED
;
1632 wxPropertyGrid
* propGrid
= property
->GetGrid();
1633 cb
->m_boxHeight
= propGrid
->GetFontHeight();
1638 bool wxPGCheckBoxEditor
::OnEvent( wxPropertyGrid
* WXUNUSED(propGrid
), wxPGProperty
* WXUNUSED(property
),
1639 wxWindow
* WXUNUSED(ctrl
), wxEvent
& event
) const
1641 if ( event
.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED
)
1649 bool wxPGCheckBoxEditor
::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1651 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*)ctrl
;
1653 int index
= cb
->m_state
;
1655 if ( index
!= property
->GetChoiceSelection() ||
1656 // Changing unspecified always causes event (returning
1657 // true here should be enough to trigger it).
1658 property
->IsValueUnspecified()
1661 return property
->IntToValue(variant
, index
, 0);
1667 void wxPGCheckBoxEditor
::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1669 if ( value
!= 0 ) value
= 1;
1670 ((wxSimpleCheckBox
*)ctrl
)->m_state
= value
;
1675 void wxPGCheckBoxEditor
::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1677 ((wxSimpleCheckBox
*)ctrl
)->m_state
= wxSCB_STATE_UNSPECIFIED
;
1682 wxPGCheckBoxEditor
::~wxPGCheckBoxEditor() { }
1685 #endif // wxPG_INCLUDE_CHECKBOX
1687 // -----------------------------------------------------------------------
1689 wxWindow
* wxPropertyGrid
::GetEditorControl() const
1691 wxWindow
* ctrl
= m_wndEditor
;
1699 // -----------------------------------------------------------------------
1701 void wxPropertyGrid
::CorrectEditorWidgetSizeX()
1704 int newSplitterx
= m_pState
->DoGetSplitterPosition(m_selColumn
-1);
1705 int newWidth
= newSplitterx
+ m_pState
->m_colWidths
[m_selColumn
];
1709 // if width change occurred, move secondary wnd by that amount
1710 wxRect r
= m_wndEditor2
->GetRect();
1712 r
.x
= newWidth
- secWid
;
1714 m_wndEditor2
->SetSize( r
);
1716 // if primary is textctrl, then we have to add some extra space
1720 if ( m_wndEditor
&& m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1722 secWid
+= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1727 wxRect r
= m_wndEditor
->GetRect();
1729 r
.x
= newSplitterx
+m_ctrlXAdjust
;
1731 if ( !(m_iFlags
& wxPG_FL_FIXED_WIDTH_EDITOR
) )
1732 r
.width
= newWidth
- r
.x
- secWid
;
1734 m_wndEditor
->SetSize(r
);
1738 m_wndEditor2
->Refresh();
1741 // -----------------------------------------------------------------------
1743 void wxPropertyGrid
::CorrectEditorWidgetPosY()
1745 if ( GetSelection() && (m_wndEditor
|| m_wndEditor2
) )
1747 wxRect r
= GetEditorWidgetRect(GetSelection(), m_selColumn
);
1751 wxPoint pos
= m_wndEditor
->GetPosition();
1753 // Calculate y offset
1754 int offset
= pos
.y
% m_lineHeight
;
1756 m_wndEditor
->Move(pos
.x
, r
.y
+ offset
);
1761 wxPoint pos
= m_wndEditor2
->GetPosition();
1763 m_wndEditor2
->Move(pos
.x
, r
.y
);
1768 // -----------------------------------------------------------------------
1770 // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
1771 // fits into that category as well).
1772 void wxPropertyGrid
::FixPosForTextCtrl( wxWindow
* ctrl
,
1773 unsigned int WXUNUSED(forColumn
),
1774 const wxPoint
& offset
)
1776 // Center the control vertically
1777 wxRect finalPos
= ctrl
->GetRect();
1778 int y_adj
= (m_lineHeight
- finalPos
.height
)/2 + wxPG_TEXTCTRLYADJUST
;
1780 // Prevent over-sized control
1781 int sz_dec
= (y_adj
+ finalPos
.height
) - m_lineHeight
;
1782 if ( sz_dec
< 0 ) sz_dec
= 0;
1784 finalPos
.y
+= y_adj
;
1785 finalPos
.height
-= (y_adj
+sz_dec
);
1787 #ifndef wxPG_TEXTCTRLXADJUST
1788 int textCtrlXAdjust
= wxPG_XBEFORETEXT
- 1;
1790 wxTextCtrl
* tc
= static_cast<wxTextCtrl
*>(ctrl
);
1793 int textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
;
1796 finalPos
.x
+= textCtrlXAdjust
;
1797 finalPos
.width
-= textCtrlXAdjust
;
1799 finalPos
.x
+= offset
.x
;
1800 finalPos
.y
+= offset
.y
;
1802 ctrl
->SetSize(finalPos
);
1805 // -----------------------------------------------------------------------
1807 wxWindow
* wxPropertyGrid
::GenerateEditorTextCtrl( const wxPoint
& pos
,
1809 const wxString
& value
,
1810 wxWindow
* secondary
,
1813 unsigned int forColumn
)
1815 wxWindowID id
= wxPG_SUBID1
;
1816 wxPGProperty
* prop
= GetSelection();
1819 int tcFlags
= wxTE_PROCESS_ENTER
| extraStyle
;
1821 if ( prop
->HasFlag(wxPG_PROP_READONLY
) && forColumn
== 1 )
1822 tcFlags
|= wxTE_READONLY
;
1824 wxPoint
p(pos
.x
,pos
.y
);
1825 wxSize
s(sz
.x
,sz
.y
);
1827 // Need to reduce width of text control on Mac
1828 #if defined(__WXMAC__)
1832 // For label editors, trim the size to allow better splitter grabbing
1833 if ( forColumn
!= 1 )
1836 // Take button into acccount
1839 s
.x
-= (secondary
->GetSize().x
+ wxPG_TEXTCTRL_AND_BUTTON_SPACING
);
1840 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
1843 // If the height is significantly higher, then use border, and fill the rect exactly.
1844 bool hasSpecialSize
= false;
1846 if ( (sz
.y
- m_lineHeight
) > 5 )
1847 hasSpecialSize
= true;
1849 wxWindow
* ctrlParent
= GetPanel();
1851 if ( !hasSpecialSize
)
1852 tcFlags
|= wxBORDER_NONE
;
1854 wxTextCtrl
* tc
= new wxTextCtrl();
1856 #if defined(__WXMSW__)
1859 SetupTextCtrlValue(value
);
1860 tc
->Create(ctrlParent
,id
,value
, p
, s
,tcFlags
);
1862 #if defined(__WXMSW__)
1863 // On Windows, we need to override read-only text ctrl's background
1864 // colour to white. One problem with native 'grey' background is that
1865 // tc->GetBackgroundColour() doesn't seem to return correct value
1867 if ( tcFlags
& wxTE_READONLY
)
1869 wxVisualAttributes vattrs
= tc
->GetDefaultAttributes();
1870 tc
->SetBackgroundColour(vattrs
.colBg
);
1874 // Center the control vertically
1875 if ( !hasSpecialSize
)
1876 FixPosForTextCtrl(tc
, forColumn
);
1878 if ( forColumn
!= 1 )
1880 tc
->SetBackgroundColour(m_colSelBack
);
1881 tc
->SetForegroundColour(m_colSelFore
);
1890 // Set maximum length
1892 tc
->SetMaxLength( maxLen
);
1894 wxVariant attrVal
= prop
->GetAttribute(wxPG_ATTR_AUTOCOMPLETE
);
1895 if ( !attrVal
.IsNull() )
1897 wxASSERT(attrVal
.GetType() == wxS("arrstring"));
1898 tc
->AutoComplete(attrVal
.GetArrayString());
1904 // -----------------------------------------------------------------------
1906 wxWindow
* wxPropertyGrid
::GenerateEditorButton( const wxPoint
& pos
, const wxSize
& sz
)
1908 wxWindowID id
= wxPG_SUBID2
;
1909 wxPGProperty
* selected
= GetSelection();
1913 // Decorations are chunky on Mac, and we can't make the button square, so
1914 // do things a bit differently on this platform.
1916 wxPoint
p(pos
.x
+sz
.x
,
1917 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1920 wxButton
* but
= new wxButton();
1921 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1923 // Now that we know the size, move to the correct position
1924 p
.x
= pos
.x
+ sz
.x
- but
->GetSize().x
- 2;
1928 wxSize
s(sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2),
1929 sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2));
1931 // Reduce button width to lineheight
1932 if ( s
.x
> m_lineHeight
)
1936 // On wxGTK, take fixed button margins into account
1941 wxPoint
p(pos
.x
+sz
.x
-s
.x
,
1942 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1944 wxButton
* but
= new wxButton();
1948 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1951 wxFont font
= GetFont();
1952 font
.SetPointSize(font
.GetPointSize()-2);
1955 but
->SetFont(GetFont());
1959 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1965 // -----------------------------------------------------------------------
1967 wxWindow
* wxPropertyGrid
::GenerateEditorTextCtrlAndButton( const wxPoint
& pos
,
1969 wxWindow
** psecondary
,
1971 wxPGProperty
* property
)
1973 wxButton
* but
= (wxButton
*)GenerateEditorButton(pos
,sz
);
1974 *psecondary
= (wxWindow
*)but
;
1976 if ( limitedEditing
)
1979 // There is button Show in GenerateEditorTextCtrl as well
1987 if ( !property
->IsValueUnspecified() )
1988 text
= property
->GetValueAsString(property
->HasFlag(wxPG_PROP_READONLY
)?
0:wxPG_EDITABLE_VALUE
);
1990 return GenerateEditorTextCtrl(pos
,sz
,text
,but
,property
->m_maxLen
);
1993 // -----------------------------------------------------------------------
1995 void wxPropertyGrid
::SetEditorAppearance( const wxPGCell
& cell
,
1998 wxPGProperty
* property
= GetSelection();
2001 wxWindow
* ctrl
= GetEditorControl();
2005 property
->GetEditorClass()->SetControlAppearance( this,
2012 m_editorAppearance
= cell
;
2015 // -----------------------------------------------------------------------
2017 wxTextCtrl
* wxPropertyGrid
::GetEditorTextCtrl() const
2019 wxWindow
* wnd
= GetEditorControl();
2024 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2025 return wxStaticCast(wnd
, wxTextCtrl
);
2027 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
2029 wxOwnerDrawnComboBox
* cb
= wxStaticCast(wnd
, wxOwnerDrawnComboBox
);
2030 return cb
->GetTextCtrl();
2036 // -----------------------------------------------------------------------
2038 wxPGEditor
* wxPropertyGridInterface
::GetEditorByName( const wxString
& editorName
)
2040 wxPGHashMapS2P
::const_iterator it
;
2042 it
= wxPGGlobalVars
->m_mapEditorClasses
.find(editorName
);
2043 if ( it
== wxPGGlobalVars
->m_mapEditorClasses
.end() )
2045 return (wxPGEditor
*) it
->second
;
2048 // -----------------------------------------------------------------------
2049 // wxPGEditorDialogAdapter
2050 // -----------------------------------------------------------------------
2052 IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter
, wxObject
)
2054 bool wxPGEditorDialogAdapter
::ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
2056 if ( !propGrid
->EditorValidate() )
2059 bool res
= DoShowDialog( propGrid
, property
);
2063 propGrid
->ValueChangeInEvent( m_value
);
2070 // -----------------------------------------------------------------------
2072 // -----------------------------------------------------------------------
2074 wxPGMultiButton
::wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
)
2075 : wxWindow( pg
->GetPanel(), wxPG_SUBID2
, wxPoint(-100,-100), wxSize(0, sz
.y
) ),
2076 m_fullEditorSize(sz
), m_buttonsWidth(0)
2078 SetBackgroundColour(pg
->GetCellBackgroundColour());
2081 void wxPGMultiButton
::Finalize( wxPropertyGrid
* WXUNUSED(propGrid
),
2082 const wxPoint
& pos
)
2084 Move( pos
.x
+ m_fullEditorSize
.x
- m_buttonsWidth
, pos
.y
);
2087 int wxPGMultiButton
::GenId( int id
) const
2091 if ( m_buttons
.size() )
2092 id
= GetButton(m_buttons
.size()-1)->GetId() + 1;
2100 void wxPGMultiButton
::Add( const wxBitmap
& bitmap
, int id
)
2103 wxSize sz
= GetSize();
2104 wxButton
* button
= new wxBitmapButton( this, id
, bitmap
,
2106 wxSize(sz
.y
, sz
.y
) );
2107 DoAddButton( button
, sz
);
2111 void wxPGMultiButton
::Add( const wxString
& label
, int id
)
2114 wxSize sz
= GetSize();
2115 wxButton
* button
= new wxButton( this, id
, label
, wxPoint(sz
.x
, 0),
2116 wxSize(sz
.y
, sz
.y
) );
2117 DoAddButton( button
, sz
);
2120 void wxPGMultiButton
::DoAddButton( wxWindow
* button
,
2123 m_buttons
.push_back(button
);
2124 int bw
= button
->GetSize().x
;
2125 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
2126 m_buttonsWidth
+= bw
;
2129 // -----------------------------------------------------------------------
2131 #endif // wxUSE_PROPGRID