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
, wxPGProperty
* property
, const wxString
& text
) const
174 if ( !property
->IsValueUnspecified() )
175 dc
.DrawText( text
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
177 dc
.DrawText( property
->GetGrid()->GetUnspecifiedValueText(),
178 rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
181 bool wxPGEditor
::GetValueFromControl( wxVariant
&, wxPGProperty
*, wxWindow
* ) const
186 void wxPGEditor
::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, const wxString
& ) const
191 void wxPGEditor
::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, int ) const
196 int wxPGEditor
::InsertItem( wxWindow
*, const wxString
&, int ) const
202 void wxPGEditor
::DeleteItem( wxWindow
*, int ) const
208 void wxPGEditor
::OnFocus( wxPGProperty
*, wxWindow
* ) const
213 bool wxPGEditor
::CanContainCustomImage() const
218 // -----------------------------------------------------------------------
219 // wxPGTextCtrlEditor
220 // -----------------------------------------------------------------------
222 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrl
,wxPGTextCtrlEditor
,wxPGEditor
)
225 wxPGWindowList wxPGTextCtrlEditor
::CreateControls( wxPropertyGrid
* propGrid
,
226 wxPGProperty
* property
,
228 const wxSize
& sz
) const
233 // If has children, and limited editing is specified, then don't create.
234 if ( (property
->GetFlags() & wxPG_PROP_NOEDITOR
) &&
235 property
->GetChildCount() )
238 int argFlags
= property
->HasFlag(wxPG_PROP_READONLY
) ?
239 0 : wxPG_EDITABLE_VALUE
;
240 text
= property
->GetValueAsString(argFlags
);
243 if ( (property
->GetFlags() & wxPG_PROP_PASSWORD
) &&
244 property
->IsKindOf(CLASSINFO(wxStringProperty
)) )
245 flags
|= wxTE_PASSWORD
;
247 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrl(pos
,sz
,text
,NULL
,flags
,
248 property
->GetMaxLength());
254 void wxPGTextCtrlEditor
::DrawValue( wxDC
& dc
, wxPGProperty
* property
, const wxRect
& rect
) const
256 if ( !property
->IsValueUnspecified() )
258 wxString drawStr
= property
->GetDisplayedString();
260 // Code below should no longer be needed, as the obfuscation
261 // is now done in GetValueAsString.
262 /*if ( (property->GetFlags() & wxPG_PROP_PASSWORD) &&
263 property->IsKindOf(WX_PG_CLASSINFO(wxStringProperty)) )
265 size_t a = drawStr.length();
267 drawStr.Append(wxS('*'),a);
269 dc
.DrawText( drawStr
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
274 void wxPGTextCtrlEditor
::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
276 wxTextCtrl
* tc
= wxDynamicCast(ctrl
, wxTextCtrl
);
281 if ( tc
->HasFlag(wxTE_PASSWORD
) )
282 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
284 s
= property
->GetDisplayedString();
286 wxPropertyGrid
* pg
= property
->GetGrid();
288 pg
->SetupTextCtrlValue(s
);
292 // Fix indentation, just in case (change in font boldness is one good
297 // Provided so that, for example, ComboBox editor can use the same code
298 // (multiple inheritance would get way too messy).
299 bool wxPGTextCtrlEditor
::OnTextCtrlEvent( wxPropertyGrid
* propGrid
,
300 wxPGProperty
* WXUNUSED(property
),
307 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
309 if ( propGrid
->IsEditorsValueModified() )
314 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
317 // Pass this event outside wxPropertyGrid so that,
318 // if necessary, program can tell when user is editing
320 // FIXME: Is it safe to change event id in the middle of event
321 // processing (seems to work, but...)?
323 event
.SetId(propGrid
->GetId());
325 propGrid
->EditorsValueWasModified();
331 bool wxPGTextCtrlEditor
::OnEvent( wxPropertyGrid
* propGrid
,
332 wxPGProperty
* property
,
334 wxEvent
& event
) const
336 return wxPGTextCtrlEditor
::OnTextCtrlEvent(propGrid
,property
,ctrl
,event
);
340 bool wxPGTextCtrlEditor
::GetTextCtrlValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
)
342 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
343 wxString textVal
= tc
->GetValue();
345 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
351 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
353 // Changing unspecified always causes event (returning
354 // true here should be enough to trigger it).
355 // TODO: Move to propgrid.cpp
356 if ( !res
&& variant
.IsNull() )
363 bool wxPGTextCtrlEditor
::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
365 return wxPGTextCtrlEditor
::GetTextCtrlValueFromControl(variant
, property
, ctrl
);
369 void wxPGTextCtrlEditor
::SetValueToUnspecified( wxPGProperty
* property
, wxWindow
* ctrl
) const
371 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
373 wxPropertyGrid
* pg
= property
->GetGrid();
374 wxASSERT(pg
); // Really, property grid should exist if editor does
377 wxString unspecValueText
= pg
->GetUnspecifiedValueText();
378 pg
->SetupTextCtrlValue(unspecValueText
);
379 tc
->SetValue(unspecValueText
);
384 void wxPGTextCtrlEditor
::SetControlStringValue( wxPGProperty
* property
, wxWindow
* ctrl
, const wxString
& txt
) const
386 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
388 wxPropertyGrid
* pg
= property
->GetGrid();
389 wxASSERT(pg
); // Really, property grid should exist if editor does
392 pg
->SetupTextCtrlValue(txt
);
398 void wxPGTextCtrlEditor
::OnFocus( wxPGProperty
*, wxWindow
* wnd
) const
400 wxTextCtrl
* tc
= wxStaticCast(wnd
, wxTextCtrl
);
402 tc
->SetSelection(-1,-1);
406 wxPGTextCtrlEditor
::~wxPGTextCtrlEditor() { }
409 // -----------------------------------------------------------------------
411 // -----------------------------------------------------------------------
414 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(Choice
,wxPGChoiceEditor
,wxPGEditor
)
417 // This is a special enhanced double-click processor class.
418 // In essence, it allows for double-clicks for which the
419 // first click "created" the control.
420 class wxPGDoubleClickProcessor
: public wxEvtHandler
424 wxPGDoubleClickProcessor( wxOwnerDrawnComboBox
* combo
, wxPGProperty
* property
)
427 m_timeLastMouseUp
= 0;
429 m_property
= property
;
430 m_downReceived
= false;
435 void OnMouseEvent( wxMouseEvent
& event
)
437 wxLongLong t
= ::wxGetLocalTimeMillis();
438 int evtType
= event
.GetEventType();
440 if ( m_property
->HasFlag(wxPG_PROP_USE_DCC
) &&
441 m_property
->IsKindOf(CLASSINFO(wxBoolProperty
)) &&
442 !m_combo
->IsPopupShown() )
444 // Just check that it is in the text area
445 wxPoint pt
= event
.GetPosition();
446 if ( m_combo
->GetTextRect().Contains(pt
) )
448 if ( evtType
== wxEVT_LEFT_DOWN
)
450 // Set value to avoid up-events without corresponding downs
451 m_downReceived
= true;
453 else if ( evtType
== wxEVT_LEFT_DCLICK
)
455 // We'll make our own double-clicks
456 event
.SetEventType(0);
459 else if ( evtType
== wxEVT_LEFT_UP
)
461 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
463 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
465 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
467 event
.SetEventType(wxEVT_LEFT_DCLICK
);
468 m_timeLastMouseUp
= 1;
472 m_timeLastMouseUp
= t
;
482 void OnSetFocus( wxFocusEvent
& event
)
484 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
489 wxLongLong m_timeLastMouseUp
;
490 wxOwnerDrawnComboBox
* m_combo
;
491 wxPGProperty
* m_property
; // Selected property
494 DECLARE_EVENT_TABLE()
497 BEGIN_EVENT_TABLE(wxPGDoubleClickProcessor
, wxEvtHandler
)
498 EVT_MOUSE_EVENTS(wxPGDoubleClickProcessor
::OnMouseEvent
)
499 EVT_SET_FOCUS(wxPGDoubleClickProcessor
::OnSetFocus
)
504 class wxPGComboBox
: public wxOwnerDrawnComboBox
509 : wxOwnerDrawnComboBox()
511 m_dclickProcessor
= NULL
;
512 m_sizeEventCalled
= false;
517 if ( m_dclickProcessor
)
519 RemoveEventHandler(m_dclickProcessor
);
520 delete m_dclickProcessor
;
524 bool Create(wxWindow
*parent
,
526 const wxString
& value
,
529 const wxArrayString
& choices
,
531 const wxValidator
& validator
= wxDefaultValidator
,
532 const wxString
& name
= wxS("wxOwnerDrawnComboBox"))
534 if ( !wxOwnerDrawnComboBox
::Create( parent
,
545 m_dclickProcessor
= new
546 wxPGDoubleClickProcessor( this, GetGrid()->GetSelection() );
548 PushEventHandler(m_dclickProcessor
);
553 virtual void OnDrawItem( wxDC
& dc
,
558 wxPropertyGrid
* pg
= GetGrid();
559 pg
->OnComboItemPaint( this, item
, &dc
, (wxRect
&)rect
, flags
);
562 virtual wxCoord
OnMeasureItem( size_t item
) const
564 wxPropertyGrid
* pg
= GetGrid();
568 pg
->OnComboItemPaint( this, item
, NULL
, rect
, 0 );
572 wxPropertyGrid
* GetGrid() const
574 wxPropertyGrid
* pg
= wxDynamicCast(GetParent(),
580 virtual wxCoord
OnMeasureItemWidth( size_t item
) const
582 wxPropertyGrid
* pg
= GetGrid();
586 pg
->OnComboItemPaint( this, item
, NULL
, rect
, 0 );
590 virtual void PositionTextCtrl( int textCtrlXAdjust
,
591 int WXUNUSED(textCtrlYAdjust
) )
593 wxPropertyGrid
* pg
= GetGrid();
594 #ifdef wxPG_TEXTCTRLXADJUST
595 textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
-
596 (wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1) - 1,
598 wxOwnerDrawnComboBox
::PositionTextCtrl(
600 pg
->GetSpacingY() + 2
605 wxPGDoubleClickProcessor
* m_dclickProcessor
;
606 bool m_sizeEventCalled
;
610 void wxPropertyGrid
::OnComboItemPaint( const wxPGComboBox
* pCb
,
617 wxASSERT( IsKindOf(CLASSINFO(wxPropertyGrid
)) );
619 wxPGProperty
* p
= GetSelection();
622 const wxPGChoices
& choices
= p
->GetChoices();
623 const wxPGCommonValue
* comVal
= NULL
;
624 int comVals
= p
->GetDisplayedCommonValueCount();
625 int comValIndex
= -1;
628 if ( choices
.IsOk() )
629 choiceCount
= choices
.GetCount();
631 if ( item
>= choiceCount
&& comVals
> 0 )
633 comValIndex
= item
- choiceCount
;
634 comVal
= GetCommonValue(comValIndex
);
635 if ( !p
->IsValueUnspecified() )
636 text
= comVal
->GetLabel();
640 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
642 text
= pCb
->GetString(item
);
646 if ( !p
->IsValueUnspecified() )
647 text
= p
->GetValueAsString(0);
656 const wxBitmap
* itemBitmap
= NULL
;
658 if ( item
>= 0 && choices
.IsOk() && choices
.Item(item
).GetBitmap().Ok() && comValIndex
== -1 )
659 itemBitmap
= &choices
.Item(item
).GetBitmap();
662 // Decide what custom image size to use
665 cis
.x
= itemBitmap
->GetWidth();
666 cis
.y
= itemBitmap
->GetHeight();
670 cis
= GetImageSize(p
, item
);
675 // Default measure behaviour (no flexible, custom paint image only)
676 if ( rect
.width
< 0 )
679 pCb
->GetTextExtent(text
, &x
, &y
, 0, 0);
680 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9 + x
;
683 rect
.height
= cis
.y
+ 2;
687 wxPGPaintData paintdata
;
688 paintdata
.m_parent
= NULL
;
689 paintdata
.m_choiceItem
= item
;
691 // This is by the current (1.0.0b) spec - if painting control, item is -1
692 if ( (flags
& wxODCB_PAINTING_CONTROL
) )
693 paintdata
.m_choiceItem
= -1;
696 pDc
->SetBrush(*wxWHITE_BRUSH
);
698 wxPGCellRenderer
* renderer
= NULL
;
699 const wxPGChoiceEntry
* cell
= NULL
;
707 wxPoint
pt(rect
.x
+ wxPG_CONTROL_MARGIN
- wxPG_CHOICEXADJUST
- 1,
710 int renderFlags
= wxPGCellRenderer
::DontUseCellColours
;
712 if ( flags
& wxODCB_PAINTING_CONTROL
)
713 renderFlags
|= wxPGCellRenderer
::Control
;
715 renderFlags
|= wxPGCellRenderer
::ChoicePopup
;
717 if ( flags
& wxODCB_PAINTING_SELECTED
)
718 renderFlags
|= wxPGCellRenderer
::Selected
;
720 if ( cis
.x
> 0 && (p
->HasFlag(wxPG_PROP_CUSTOMIMAGE
) || !(flags
& wxODCB_PAINTING_CONTROL
)) &&
721 ( !p
->m_valueBitmap
|| item
== pCb
->GetSelection() ) &&
722 ( item
>= 0 || (flags
& wxODCB_PAINTING_CONTROL
) ) &&
726 pt
.x
+= wxCC_CUSTOM_IMAGE_MARGIN1
;
727 wxRect
r(pt
.x
,pt
.y
,cis
.x
,cis
.y
);
729 if ( flags
& wxODCB_PAINTING_CONTROL
)
732 r
.height
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
735 paintdata
.m_drawnWidth
= r
.width
;
737 dc
.SetPen(m_colPropFore
);
738 if ( comValIndex
>= 0 )
740 const wxPGCommonValue
* cv
= GetCommonValue(comValIndex
);
741 wxPGCellRenderer
* renderer
= cv
->GetRenderer();
742 r
.width
= rect
.width
;
743 renderer
->Render( dc
, r
, this, p
, m_selColumn
, comValIndex
, renderFlags
);
746 else if ( item
>= 0 )
748 p
->OnCustomPaint( dc
, r
, paintdata
);
752 dc
.DrawRectangle( r
);
755 pt
.x
+= paintdata
.m_drawnWidth
+ wxCC_CUSTOM_IMAGE_MARGIN2
- 1;
759 // TODO: This aligns text so that it seems to be horizontally
760 // on the same line as property values. Not really
761 // sure if its needed, but seems to not cause any harm.
764 if ( item
< 0 && (flags
& wxODCB_PAINTING_CONTROL
) )
765 item
= pCb
->GetSelection();
767 if ( choices
.IsOk() && item
>= 0 && comValIndex
< 0 )
769 cell
= &choices
.Item(item
);
770 renderer
= wxPGGlobalVars
->m_defaultRenderer
;
771 int imageOffset
= renderer
->PreDrawCell(dc
, rect
, *cell
,
774 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+
775 wxCC_CUSTOM_IMAGE_MARGIN2
;
784 pt
.y
+= (rect
.height
-m_fontHeight
)/2 - 1;
788 dc
.DrawText( text
, pt
.x
+ wxPG_XBEFORETEXT
, pt
.y
);
791 renderer
->PostDrawCell(dc
, this, *cell
, renderFlags
);
799 p
->OnCustomPaint( dc
, rect
, paintdata
);
800 rect
.height
= paintdata
.m_drawnHeight
+ 2;
801 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9;
805 bool wxPGChoiceEditor_SetCustomPaintWidth( wxPropertyGrid
* propGrid
, wxPGComboBox
* cb
, int cmnVal
)
807 wxPGProperty
* property
= propGrid
->GetSelectedProperty();
808 wxASSERT( property
);
815 // Yes, a common value is being selected
816 property
->SetCommonValue( cmnVal
);
817 imageSize
= propGrid
->GetCommonValue(cmnVal
)->
818 GetRenderer()->GetImageSize(property
, 1, cmnVal
);
823 imageSize
= propGrid
->GetImageSize(property
, -1);
828 imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
829 cb
->SetCustomPaintWidth( imageSize
.x
);
834 // CreateControls calls this with CB_READONLY in extraStyle
835 wxWindow
* wxPGChoiceEditor
::CreateControlsBase( wxPropertyGrid
* propGrid
,
836 wxPGProperty
* property
,
839 long extraStyle
) const
841 const wxPGChoices
& choices
= property
->GetChoices();
843 int index
= property
->GetChoiceSelection();
845 bool isUnspecified
= property
->IsValueUnspecified();
847 if ( !isUnspecified
)
848 defString
= property
->GetDisplayedString();
850 wxArrayString labels
= choices
.GetLabels();
856 po
.y
+= wxPG_CHOICEYADJUST
;
857 si
.y
-= (wxPG_CHOICEYADJUST
*2);
859 po
.x
+= wxPG_CHOICEXADJUST
;
860 si
.x
-= wxPG_CHOICEXADJUST
;
861 wxWindow
* ctrlParent
= propGrid
->GetPanel();
863 int odcbFlags
= extraStyle
| wxBORDER_NONE
| wxTE_PROCESS_ENTER
;
865 if ( (property
->GetFlags() & wxPG_PROP_USE_DCC
) &&
866 (property
->IsKindOf(CLASSINFO(wxBoolProperty
)) ) )
867 odcbFlags
|= wxODCB_DCLICK_CYCLES
;
870 // If common value specified, use appropriate index
871 unsigned int cmnVals
= property
->GetDisplayedCommonValueCount();
874 if ( !isUnspecified
)
876 int cmnVal
= property
->GetCommonValue();
879 index
= labels
.size() + cmnVal
;
884 for ( i
=0; i
<cmnVals
; i
++ )
885 labels
.Add(propGrid
->GetCommonValueLabel(i
));
888 cb
= new wxPGComboBox();
892 cb
->Create(ctrlParent
,
900 cb
->SetButtonPosition(si
.y
,0,wxRIGHT
);
901 cb
->SetMargins(wxPG_XBEFORETEXT
-1);
903 wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, property
->GetCommonValue() );
905 if ( index
>= 0 && index
< (int)cb
->GetCount() )
907 cb
->SetSelection( index
);
908 if ( defString
.length() )
909 cb
->SetText( defString
);
911 else if ( !(extraStyle
& wxCB_READONLY
) && defString
.length() )
913 propGrid
->SetupTextCtrlValue(defString
);
914 cb
->SetValue( defString
);
918 cb
->SetSelection( -1 );
925 return (wxWindow
*) cb
;
929 void wxPGChoiceEditor
::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
932 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
933 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
934 int ind
= property
->GetChoiceSelection();
935 cb
->SetSelection(ind
);
938 wxPGWindowList wxPGChoiceEditor
::CreateControls( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
939 const wxPoint
& pos
, const wxSize
& sz
) const
941 return CreateControlsBase(propGrid
,property
,pos
,sz
,wxCB_READONLY
);
945 int wxPGChoiceEditor
::InsertItem( wxWindow
* ctrl
, const wxString
& label
, int index
) const
948 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
949 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
952 index
= cb
->GetCount();
954 return cb
->Insert(label
,index
);
958 void wxPGChoiceEditor
::DeleteItem( wxWindow
* ctrl
, int index
) const
961 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
962 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
967 bool wxPGChoiceEditor
::OnEvent( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
968 wxWindow
* ctrl
, wxEvent
& event
) const
970 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
972 wxPGComboBox
* cb
= (wxPGComboBox
*)ctrl
;
973 int index
= cb
->GetSelection();
974 int cmnValIndex
= -1;
975 int cmnVals
= property
->GetDisplayedCommonValueCount();
976 int items
= cb
->GetCount();
978 if ( index
>= (items
-cmnVals
) )
980 // Yes, a common value is being selected
981 cmnValIndex
= index
- (items
-cmnVals
);
982 property
->SetCommonValue( cmnValIndex
);
984 // Truly set value to unspecified?
985 if ( propGrid
->GetUnspecifiedCommonValue() == cmnValIndex
)
987 if ( !property
->IsValueUnspecified() )
988 propGrid
->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT
);
989 property
->SetValueToUnspecified();
990 if ( !cb
->HasFlag(wxCB_READONLY
) )
992 wxString unspecValueText
;
993 unspecValueText
= propGrid
->GetUnspecifiedValueText();
994 propGrid
->SetupTextCtrlValue(unspecValueText
);
995 cb
->GetTextCtrl()->SetValue(unspecValueText
);
1000 return wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, cmnValIndex
);
1006 bool wxPGChoiceEditor
::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1008 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1010 int index
= cb
->GetSelection();
1012 if ( index
!= property
->GetChoiceSelection() ||
1013 // Changing unspecified always causes event (returning
1014 // true here should be enough to trigger it).
1015 property
->IsValueUnspecified()
1018 return property
->IntToValue( variant
, index
, 0 );
1024 void wxPGChoiceEditor
::SetControlStringValue( wxPGProperty
* property
,
1026 const wxString
& txt
) const
1028 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1030 property
->GetGrid()->SetupTextCtrlValue(txt
);
1035 void wxPGChoiceEditor
::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1037 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1039 cb
->SetSelection(value
);
1043 void wxPGChoiceEditor
::SetValueToUnspecified( wxPGProperty
* property
,
1044 wxWindow
* ctrl
) const
1046 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1048 if ( !cb
->HasFlag(wxCB_READONLY
) )
1050 wxPropertyGrid
* pg
= property
->GetGrid();
1053 wxString tcText
= pg
->GetUnspecifiedValueText();
1054 pg
->SetupTextCtrlValue(tcText
);
1055 cb
->SetValue(tcText
);
1060 cb
->SetSelection(-1);
1065 bool wxPGChoiceEditor
::CanContainCustomImage() const
1071 wxPGChoiceEditor
::~wxPGChoiceEditor() { }
1074 // -----------------------------------------------------------------------
1075 // wxPGComboBoxEditor
1076 // -----------------------------------------------------------------------
1079 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ComboBox
,
1084 void wxPGComboBoxEditor
::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1086 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1087 wxString s
= property
->GetValueAsString(wxPG_EDITABLE_VALUE
);
1088 property
->GetGrid()->SetupTextCtrlValue(s
);
1091 // TODO: If string matches any selection, then select that.
1095 wxPGWindowList wxPGComboBoxEditor
::CreateControls( wxPropertyGrid
* propGrid
,
1096 wxPGProperty
* property
,
1098 const wxSize
& sz
) const
1100 return CreateControlsBase(propGrid
,property
,pos
,sz
,0);
1104 bool wxPGComboBoxEditor
::OnEvent( wxPropertyGrid
* propGrid
,
1105 wxPGProperty
* property
,
1107 wxEvent
& event
) const
1109 wxOwnerDrawnComboBox
* cb
= NULL
;
1110 wxWindow
* textCtrl
= NULL
;
1114 cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1115 textCtrl
= cb
->GetTextCtrl();
1118 if ( wxPGTextCtrlEditor
::OnTextCtrlEvent(propGrid
,property
,textCtrl
,event
) )
1121 return wxPGChoiceEditor
::OnEvent(propGrid
,property
,ctrl
,event
);
1125 bool wxPGComboBoxEditor
::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1127 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1128 wxString textVal
= cb
->GetValue();
1130 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
1136 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
1138 // Changing unspecified always causes event (returning
1139 // true here should be enough to trigger it).
1140 if ( !res
&& variant
.IsNull() )
1147 void wxPGComboBoxEditor
::OnFocus( wxPGProperty
*, wxWindow
* ctrl
) const
1149 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1150 cb
->GetTextCtrl()->SetSelection(-1,-1);
1154 wxPGComboBoxEditor
::~wxPGComboBoxEditor() { }
1157 // -----------------------------------------------------------------------
1158 // wxPGChoiceAndButtonEditor
1159 // -----------------------------------------------------------------------
1162 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ChoiceAndButton
,
1163 wxPGChoiceAndButtonEditor
,
1167 wxPGWindowList wxPGChoiceAndButtonEditor
::CreateControls( wxPropertyGrid
* propGrid
,
1168 wxPGProperty
* property
,
1170 const wxSize
& sz
) const
1172 // Use one two units smaller to match size of the combo's dropbutton.
1173 // (normally a bigger button is used because it looks better)
1176 wxSize
bt_sz(bt_wid
,bt_wid
);
1178 // Position of button.
1179 wxPoint
bt_pos(pos
.x
+sz
.x
-bt_sz
.x
,pos
.y
);
1186 wxWindow
* bt
= propGrid
->GenerateEditorButton( bt_pos
, bt_sz
);
1189 wxSize
ch_sz(sz
.x
-bt
->GetSize().x
,sz
.y
);
1192 ch_sz
.x
-= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1195 wxWindow
* ch
= wxPGEditor_Choice
->CreateControls(propGrid
,property
,
1196 pos
,ch_sz
).m_primary
;
1202 return wxPGWindowList(ch
, bt
);
1206 wxPGChoiceAndButtonEditor
::~wxPGChoiceAndButtonEditor() { }
1209 // -----------------------------------------------------------------------
1210 // wxPGTextCtrlAndButtonEditor
1211 // -----------------------------------------------------------------------
1213 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrlAndButton
,
1214 wxPGTextCtrlAndButtonEditor
,
1218 wxPGWindowList wxPGTextCtrlAndButtonEditor
::CreateControls( wxPropertyGrid
* propGrid
,
1219 wxPGProperty
* property
,
1221 const wxSize
& sz
) const
1224 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrlAndButton( pos
, sz
, &wnd2
,
1225 property
->GetFlags() & wxPG_PROP_NOEDITOR
, property
);
1227 return wxPGWindowList(wnd
, wnd2
);
1231 wxPGTextCtrlAndButtonEditor
::~wxPGTextCtrlAndButtonEditor() { }
1234 // -----------------------------------------------------------------------
1235 // wxPGCheckBoxEditor
1236 // -----------------------------------------------------------------------
1238 #if wxPG_INCLUDE_CHECKBOX
1240 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(CheckBox
,
1245 // Check box state flags
1248 wxSCB_STATE_UNCHECKED
= 0,
1249 wxSCB_STATE_CHECKED
= 1,
1250 wxSCB_STATE_BOLD
= 2,
1251 wxSCB_STATE_UNSPECIFIED
= 4
1254 const int wxSCB_SETVALUE_CYCLE
= 2;
1257 static void DrawSimpleCheckBox( wxDC
& dc
, const wxRect
& rect
, int box_hei
,
1258 int state
, const wxColour
& lineCol
)
1261 wxRect
r(rect
.x
+wxPG_XBEFORETEXT
,rect
.y
+((rect
.height
-box_hei
)/2),
1263 wxColour useCol
= lineCol
;
1265 if ( state
& wxSCB_STATE_UNSPECIFIED
)
1267 useCol
= wxColour(220, 220, 220);
1270 // Draw check mark first because it is likely to overdraw the
1271 // surrounding rectangle.
1272 if ( state
& wxSCB_STATE_CHECKED
)
1274 wxRect
r2(r
.x
+wxPG_CHECKMARK_XADJ
,
1275 r
.y
+wxPG_CHECKMARK_YADJ
,
1276 r
.width
+wxPG_CHECKMARK_WADJ
,
1277 r
.height
+wxPG_CHECKMARK_HADJ
);
1278 #if wxPG_CHECKMARK_DEFLATE
1279 r2
.Deflate(wxPG_CHECKMARK_DEFLATE
);
1281 dc
.DrawCheckMark(r2
);
1283 // This would draw a simple cross check mark.
1284 // dc.DrawLine(r.x,r.y,r.x+r.width-1,r.y+r.height-1);
1285 // dc.DrawLine(r.x,r.y+r.height-1,r.x+r.width-1,r.y);
1288 if ( !(state
& wxSCB_STATE_BOLD
) )
1290 // Pen for thin rectangle.
1295 // Pen for bold rectangle.
1296 wxPen
linepen(useCol
,2,wxSOLID
);
1297 linepen
.SetJoin(wxJOIN_MITER
); // This prevents round edges.
1305 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1307 dc
.DrawRectangle(r
);
1308 dc
.SetPen(*wxTRANSPARENT_PEN
);
1312 // Real simple custom-drawn checkbox-without-label class.
1314 class wxSimpleCheckBox
: public wxControl
1318 void SetValue( int value
);
1320 wxSimpleCheckBox( wxWindow
* parent
,
1322 const wxPoint
& pos
= wxDefaultPosition
,
1323 const wxSize
& size
= wxDefaultSize
)
1324 : wxControl(parent
,id
,pos
,size
,wxBORDER_NONE
|wxWANTS_CHARS
)
1326 // Due to SetOwnFont stuff necessary for GTK+ 1.2, we need to have this
1327 SetFont( parent
->GetFont() );
1332 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
1335 virtual ~wxSimpleCheckBox();
1341 void OnPaint( wxPaintEvent
& event
);
1342 void OnLeftClick( wxMouseEvent
& event
);
1343 void OnKeyDown( wxKeyEvent
& event
);
1345 void OnResize( wxSizeEvent
& event
)
1351 static wxBitmap
* ms_doubleBuffer
;
1353 DECLARE_EVENT_TABLE()
1356 BEGIN_EVENT_TABLE(wxSimpleCheckBox
, wxControl
)
1357 EVT_PAINT(wxSimpleCheckBox
::OnPaint
)
1358 EVT_LEFT_DOWN(wxSimpleCheckBox
::OnLeftClick
)
1359 EVT_LEFT_DCLICK(wxSimpleCheckBox
::OnLeftClick
)
1360 EVT_KEY_DOWN(wxSimpleCheckBox
::OnKeyDown
)
1361 EVT_SIZE(wxSimpleCheckBox
::OnResize
)
1364 wxSimpleCheckBox
::~wxSimpleCheckBox()
1366 delete ms_doubleBuffer
;
1367 ms_doubleBuffer
= NULL
;
1370 wxBitmap
* wxSimpleCheckBox
::ms_doubleBuffer
= NULL
;
1372 void wxSimpleCheckBox
::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1374 wxSize clientSize
= GetClientSize();
1375 wxAutoBufferedPaintDC
dc(this);
1378 wxRect
rect(0,0,clientSize
.x
,clientSize
.y
);
1382 wxColour bgcol
= GetBackgroundColour();
1383 dc
.SetBrush( bgcol
);
1385 dc
.DrawRectangle( rect
);
1387 wxColour txcol
= GetForegroundColour();
1389 int state
= m_state
;
1390 if ( !(state
& wxSCB_STATE_UNSPECIFIED
) &&
1391 GetFont().GetWeight() == wxBOLD
)
1392 state
|= wxSCB_STATE_BOLD
;
1394 DrawSimpleCheckBox(dc
,rect
,m_boxHeight
,state
,txcol
);
1397 void wxSimpleCheckBox
::OnLeftClick( wxMouseEvent
& event
)
1399 if ( (event
.m_x
> (wxPG_XBEFORETEXT
-2)) &&
1400 (event
.m_x
<= (wxPG_XBEFORETEXT
-2+m_boxHeight
)) )
1402 SetValue(wxSCB_SETVALUE_CYCLE
);
1406 void wxSimpleCheckBox
::OnKeyDown( wxKeyEvent
& event
)
1408 if ( event
.GetKeyCode() == WXK_SPACE
)
1410 SetValue(wxSCB_SETVALUE_CYCLE
);
1414 void wxSimpleCheckBox
::SetValue( int value
)
1416 if ( value
== wxSCB_SETVALUE_CYCLE
)
1418 if ( m_state
& wxSCB_STATE_CHECKED
)
1419 m_state
&= ~wxSCB_STATE_CHECKED
;
1421 m_state
|= wxSCB_STATE_CHECKED
;
1429 wxCommandEvent
evt(wxEVT_COMMAND_CHECKBOX_CLICKED
,GetParent()->GetId());
1431 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent();
1432 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1433 propGrid
->HandleCustomEditorEvent(evt
);
1436 wxPGWindowList wxPGCheckBoxEditor
::CreateControls( wxPropertyGrid
* propGrid
,
1437 wxPGProperty
* property
,
1439 const wxSize
& size
) const
1442 pt
.x
-= wxPG_XBEFOREWIDGET
;
1444 sz
.x
= propGrid
->GetFontHeight() + (wxPG_XBEFOREWIDGET
*2) + 4;
1446 wxSimpleCheckBox
* cb
= new wxSimpleCheckBox(propGrid
->GetPanel(),
1447 wxPG_SUBID1
, pt
, sz
);
1449 cb
->SetBackgroundColour(wxSystemSettings
::GetColour(wxSYS_COLOUR_WINDOW
));
1451 UpdateControl(property
, cb
);
1453 if ( !property
->IsValueUnspecified() )
1455 // If mouse cursor was on the item, toggle the value now.
1456 if ( propGrid
->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK
)
1458 wxPoint pt
= cb
->ScreenToClient(::wxGetMousePosition());
1459 if ( pt
.x
<= (wxPG_XBEFORETEXT
-2+cb
->m_boxHeight
) )
1461 if ( cb
->m_state
& wxSCB_STATE_CHECKED
)
1462 cb
->m_state
&= ~wxSCB_STATE_CHECKED
;
1464 cb
->m_state
|= wxSCB_STATE_CHECKED
;
1466 // Makes sure wxPG_EVT_CHANGING etc. is sent for this initial
1468 propGrid
->ChangePropertyValue(property
,
1469 wxPGVariant_Bool(cb
->m_state
));
1474 propGrid
->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR
);
1479 void wxPGCheckBoxEditor
::DrawValue( wxDC
& dc
, const wxRect
& rect
,
1480 wxPGProperty
* property
,
1481 const wxString
& WXUNUSED(text
) ) const
1483 int state
= wxSCB_STATE_UNCHECKED
;
1484 wxColour rectCol
= dc
.GetTextForeground();
1486 if ( !property
->IsValueUnspecified() )
1488 state
= property
->GetChoiceSelection();
1489 if ( dc
.GetFont().GetWeight() == wxBOLD
)
1490 state
|= wxSCB_STATE_BOLD
;
1494 state
|= wxSCB_STATE_UNSPECIFIED
;
1497 DrawSimpleCheckBox(dc
, rect
, dc
.GetCharHeight(), state
, rectCol
);
1500 void wxPGCheckBoxEditor
::UpdateControl( wxPGProperty
* property
,
1501 wxWindow
* ctrl
) const
1503 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*) ctrl
;
1506 if ( !property
->IsValueUnspecified() )
1507 cb
->m_state
= property
->GetChoiceSelection();
1509 cb
->m_state
= wxSCB_STATE_UNSPECIFIED
;
1511 wxPropertyGrid
* propGrid
= property
->GetGrid();
1512 cb
->m_boxHeight
= propGrid
->GetFontHeight();
1517 bool wxPGCheckBoxEditor
::OnEvent( wxPropertyGrid
* WXUNUSED(propGrid
), wxPGProperty
* WXUNUSED(property
),
1518 wxWindow
* WXUNUSED(ctrl
), wxEvent
& event
) const
1520 if ( event
.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED
)
1528 bool wxPGCheckBoxEditor
::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1530 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*)ctrl
;
1532 int index
= cb
->m_state
;
1534 if ( index
!= property
->GetChoiceSelection() ||
1535 // Changing unspecified always causes event (returning
1536 // true here should be enough to trigger it).
1537 property
->IsValueUnspecified()
1540 return property
->IntToValue(variant
, index
, 0);
1546 void wxPGCheckBoxEditor
::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1548 if ( value
!= 0 ) value
= 1;
1549 ((wxSimpleCheckBox
*)ctrl
)->m_state
= value
;
1554 void wxPGCheckBoxEditor
::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1556 ((wxSimpleCheckBox
*)ctrl
)->m_state
= wxSCB_STATE_UNSPECIFIED
;
1561 wxPGCheckBoxEditor
::~wxPGCheckBoxEditor() { }
1564 #endif // wxPG_INCLUDE_CHECKBOX
1566 // -----------------------------------------------------------------------
1568 wxWindow
* wxPropertyGrid
::GetEditorControl() const
1570 wxWindow
* ctrl
= m_wndEditor
;
1578 // -----------------------------------------------------------------------
1580 void wxPropertyGrid
::CorrectEditorWidgetSizeX()
1583 int newSplitterx
= m_pState
->DoGetSplitterPosition(m_selColumn
-1);
1584 int newWidth
= newSplitterx
+ m_pState
->m_colWidths
[m_selColumn
];
1588 // if width change occurred, move secondary wnd by that amount
1589 wxRect r
= m_wndEditor2
->GetRect();
1591 r
.x
= newWidth
- secWid
;
1593 m_wndEditor2
->SetSize( r
);
1595 // if primary is textctrl, then we have to add some extra space
1599 if ( m_wndEditor
&& m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1601 secWid
+= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1606 wxRect r
= m_wndEditor
->GetRect();
1608 r
.x
= newSplitterx
+m_ctrlXAdjust
;
1610 if ( !(m_iFlags
& wxPG_FL_FIXED_WIDTH_EDITOR
) )
1611 r
.width
= newWidth
- r
.x
- secWid
;
1613 m_wndEditor
->SetSize(r
);
1617 m_wndEditor2
->Refresh();
1620 // -----------------------------------------------------------------------
1622 void wxPropertyGrid
::CorrectEditorWidgetPosY()
1624 if ( GetSelection() && (m_wndEditor
|| m_wndEditor2
) )
1626 wxRect r
= GetEditorWidgetRect(GetSelection(), m_selColumn
);
1630 wxPoint pos
= m_wndEditor
->GetPosition();
1632 // Calculate y offset
1633 int offset
= pos
.y
% m_lineHeight
;
1635 m_wndEditor
->Move(pos
.x
, r
.y
+ offset
);
1640 wxPoint pos
= m_wndEditor2
->GetPosition();
1642 m_wndEditor2
->Move(pos
.x
, r
.y
);
1647 // -----------------------------------------------------------------------
1649 // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
1650 // fits into that category as well).
1651 void wxPropertyGrid
::FixPosForTextCtrl( wxWindow
* ctrl
,
1652 unsigned int WXUNUSED(forColumn
),
1653 const wxPoint
& offset
)
1655 // Center the control vertically
1656 wxRect finalPos
= ctrl
->GetRect();
1657 int y_adj
= (m_lineHeight
- finalPos
.height
)/2 + wxPG_TEXTCTRLYADJUST
;
1659 // Prevent over-sized control
1660 int sz_dec
= (y_adj
+ finalPos
.height
) - m_lineHeight
;
1661 if ( sz_dec
< 0 ) sz_dec
= 0;
1663 finalPos
.y
+= y_adj
;
1664 finalPos
.height
-= (y_adj
+sz_dec
);
1666 #ifndef wxPG_TEXTCTRLXADJUST
1667 int textCtrlXAdjust
= wxPG_XBEFORETEXT
- 1;
1669 wxTextCtrl
* tc
= static_cast<wxTextCtrl
*>(ctrl
);
1672 int textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
;
1675 finalPos
.x
+= textCtrlXAdjust
;
1676 finalPos
.width
-= textCtrlXAdjust
;
1678 finalPos
.x
+= offset
.x
;
1679 finalPos
.y
+= offset
.y
;
1681 ctrl
->SetSize(finalPos
);
1684 // -----------------------------------------------------------------------
1686 wxWindow
* wxPropertyGrid
::GenerateEditorTextCtrl( const wxPoint
& pos
,
1688 const wxString
& value
,
1689 wxWindow
* secondary
,
1692 unsigned int forColumn
)
1694 wxWindowID id
= wxPG_SUBID1
;
1695 wxPGProperty
* prop
= GetSelection();
1698 int tcFlags
= wxTE_PROCESS_ENTER
| extraStyle
;
1700 if ( prop
->HasFlag(wxPG_PROP_READONLY
) && forColumn
== 1 )
1701 tcFlags
|= wxTE_READONLY
;
1703 wxPoint
p(pos
.x
,pos
.y
);
1704 wxSize
s(sz
.x
,sz
.y
);
1706 // Need to reduce width of text control on Mac
1707 #if defined(__WXMAC__)
1711 // For label editors, trim the size to allow better splitter grabbing
1712 if ( forColumn
!= 1 )
1715 // Take button into acccount
1718 s
.x
-= (secondary
->GetSize().x
+ wxPG_TEXTCTRL_AND_BUTTON_SPACING
);
1719 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
1722 // If the height is significantly higher, then use border, and fill the rect exactly.
1723 bool hasSpecialSize
= false;
1725 if ( (sz
.y
- m_lineHeight
) > 5 )
1726 hasSpecialSize
= true;
1728 wxWindow
* ctrlParent
= GetPanel();
1730 if ( !hasSpecialSize
)
1731 tcFlags
|= wxBORDER_NONE
;
1733 wxTextCtrl
* tc
= new wxTextCtrl();
1735 #if defined(__WXMSW__)
1738 SetupTextCtrlValue(value
);
1739 tc
->Create(ctrlParent
,id
,value
, p
, s
,tcFlags
);
1741 #if defined(__WXMSW__)
1742 // On Windows, we need to override read-only text ctrl's background
1743 // colour to white. One problem with native 'grey' background is that
1744 // tc->GetBackgroundColour() doesn't seem to return correct value
1746 if ( tcFlags
& wxTE_READONLY
)
1748 wxVisualAttributes vattrs
= tc
->GetDefaultAttributes();
1749 tc
->SetBackgroundColour(vattrs
.colBg
);
1753 // Center the control vertically
1754 if ( !hasSpecialSize
)
1755 FixPosForTextCtrl(tc
, forColumn
);
1757 if ( forColumn
!= 1 )
1759 tc
->SetBackgroundColour(m_colSelBack
);
1760 tc
->SetForegroundColour(m_colSelFore
);
1769 // Set maximum length
1771 tc
->SetMaxLength( maxLen
);
1773 wxVariant attrVal
= prop
->GetAttribute(wxPG_ATTR_AUTOCOMPLETE
);
1774 if ( !attrVal
.IsNull() )
1776 wxASSERT(attrVal
.GetType() == wxS("arrstring"));
1777 tc
->AutoComplete(attrVal
.GetArrayString());
1783 // -----------------------------------------------------------------------
1785 wxWindow
* wxPropertyGrid
::GenerateEditorButton( const wxPoint
& pos
, const wxSize
& sz
)
1787 wxWindowID id
= wxPG_SUBID2
;
1788 wxPGProperty
* selected
= GetSelection();
1792 // Decorations are chunky on Mac, and we can't make the button square, so
1793 // do things a bit differently on this platform.
1795 wxPoint
p(pos
.x
+sz
.x
,
1796 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1799 wxButton
* but
= new wxButton();
1800 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1802 // Now that we know the size, move to the correct position
1803 p
.x
= pos
.x
+ sz
.x
- but
->GetSize().x
- 2;
1807 wxSize
s(sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2),
1808 sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2));
1810 // Reduce button width to lineheight
1811 if ( s
.x
> m_lineHeight
)
1815 // On wxGTK, take fixed button margins into account
1820 wxPoint
p(pos
.x
+sz
.x
-s
.x
,
1821 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1823 wxButton
* but
= new wxButton();
1827 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1830 wxFont font
= GetFont();
1831 font
.SetPointSize(font
.GetPointSize()-2);
1834 but
->SetFont(GetFont());
1838 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1844 // -----------------------------------------------------------------------
1846 wxWindow
* wxPropertyGrid
::GenerateEditorTextCtrlAndButton( const wxPoint
& pos
,
1848 wxWindow
** psecondary
,
1850 wxPGProperty
* property
)
1852 wxButton
* but
= (wxButton
*)GenerateEditorButton(pos
,sz
);
1853 *psecondary
= (wxWindow
*)but
;
1855 if ( limitedEditing
)
1858 // There is button Show in GenerateEditorTextCtrl as well
1866 if ( !property
->IsValueUnspecified() )
1867 text
= property
->GetValueAsString(property
->HasFlag(wxPG_PROP_READONLY
)?
0:wxPG_EDITABLE_VALUE
);
1869 return GenerateEditorTextCtrl(pos
,sz
,text
,but
,property
->m_maxLen
);
1872 // -----------------------------------------------------------------------
1874 wxTextCtrl
* wxPropertyGrid
::GetEditorTextCtrl() const
1876 wxWindow
* wnd
= GetEditorControl();
1881 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1882 return wxStaticCast(wnd
, wxTextCtrl
);
1884 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
1886 wxOwnerDrawnComboBox
* cb
= wxStaticCast(wnd
, wxOwnerDrawnComboBox
);
1887 return cb
->GetTextCtrl();
1893 // -----------------------------------------------------------------------
1895 wxPGEditor
* wxPropertyGridInterface
::GetEditorByName( const wxString
& editorName
)
1897 wxPGHashMapS2P
::const_iterator it
;
1899 it
= wxPGGlobalVars
->m_mapEditorClasses
.find(editorName
);
1900 if ( it
== wxPGGlobalVars
->m_mapEditorClasses
.end() )
1902 return (wxPGEditor
*) it
->second
;
1905 // -----------------------------------------------------------------------
1906 // wxPGEditorDialogAdapter
1907 // -----------------------------------------------------------------------
1909 IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter
, wxObject
)
1911 bool wxPGEditorDialogAdapter
::ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
1913 if ( !propGrid
->EditorValidate() )
1916 bool res
= DoShowDialog( propGrid
, property
);
1920 propGrid
->ValueChangeInEvent( m_value
);
1927 // -----------------------------------------------------------------------
1929 // -----------------------------------------------------------------------
1931 wxPGMultiButton
::wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
)
1932 : wxWindow( pg
->GetPanel(), wxPG_SUBID2
, wxPoint(-100,-100), wxSize(0, sz
.y
) ),
1933 m_fullEditorSize(sz
), m_buttonsWidth(0)
1935 SetBackgroundColour(pg
->GetCellBackgroundColour());
1938 void wxPGMultiButton
::Finalize( wxPropertyGrid
* WXUNUSED(propGrid
),
1939 const wxPoint
& pos
)
1941 Move( pos
.x
+ m_fullEditorSize
.x
- m_buttonsWidth
, pos
.y
);
1944 int wxPGMultiButton
::GenId( int id
) const
1948 if ( m_buttons
.size() )
1949 id
= GetButton(m_buttons
.size()-1)->GetId() + 1;
1957 void wxPGMultiButton
::Add( const wxBitmap
& bitmap
, int id
)
1960 wxSize sz
= GetSize();
1961 wxButton
* button
= new wxBitmapButton( this, id
, bitmap
,
1963 wxSize(sz
.y
, sz
.y
) );
1964 DoAddButton( button
, sz
);
1968 void wxPGMultiButton
::Add( const wxString
& label
, int id
)
1971 wxSize sz
= GetSize();
1972 wxButton
* button
= new wxButton( this, id
, label
, wxPoint(sz
.x
, 0),
1973 wxSize(sz
.y
, sz
.y
) );
1974 DoAddButton( button
, sz
);
1977 void wxPGMultiButton
::DoAddButton( wxWindow
* button
,
1980 m_buttons
.push_back(button
);
1981 int bw
= button
->GetSize().x
;
1982 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
1983 m_buttonsWidth
+= bw
;
1986 // -----------------------------------------------------------------------
1988 #endif // wxUSE_PROPGRID