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
);
178 bool wxPGEditor::GetValueFromControl( wxVariant
&, wxPGProperty
*, wxWindow
* ) const
183 void wxPGEditor::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, const wxString
& ) const
188 void wxPGEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, int ) const
193 int wxPGEditor::InsertItem( wxWindow
*, const wxString
&, int ) const
199 void wxPGEditor::DeleteItem( wxWindow
*, int ) const
205 void wxPGEditor::OnFocus( wxPGProperty
*, wxWindow
* ) const
210 bool wxPGEditor::CanContainCustomImage() const
215 // -----------------------------------------------------------------------
216 // wxPGTextCtrlEditor
217 // -----------------------------------------------------------------------
219 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrl
,wxPGTextCtrlEditor
,wxPGEditor
)
222 wxPGWindowList
wxPGTextCtrlEditor::CreateControls( wxPropertyGrid
* propGrid
,
223 wxPGProperty
* property
,
225 const wxSize
& sz
) const
230 // If has children, and limited editing is specified, then don't create.
231 if ( (property
->GetFlags() & wxPG_PROP_NOEDITOR
) &&
232 property
->GetChildCount() )
235 if ( !property
->IsValueUnspecified() )
236 text
= property
->GetValueAsString(property
->HasFlag(wxPG_PROP_READONLY
) ?
237 0 : wxPG_EDITABLE_VALUE
);
240 if ( (property
->GetFlags() & wxPG_PROP_PASSWORD
) &&
241 property
->IsKindOf(CLASSINFO(wxStringProperty
)) )
242 flags
|= wxTE_PASSWORD
;
244 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrl(pos
,sz
,text
,NULL
,flags
,
245 property
->GetMaxLength());
251 void wxPGTextCtrlEditor::DrawValue( wxDC
& dc
, wxPGProperty
* property
, const wxRect
& rect
) const
253 if ( !property
->IsValueUnspecified() )
255 wxString drawStr
= property
->GetDisplayedString();
257 // Code below should no longer be needed, as the obfuscation
258 // is now done in GetValueAsString.
259 /*if ( (property->GetFlags() & wxPG_PROP_PASSWORD) &&
260 property->IsKindOf(WX_PG_CLASSINFO(wxStringProperty)) )
262 size_t a = drawStr.length();
264 drawStr.Append(wxS('*'),a);
266 dc
.DrawText( drawStr
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
271 void wxPGTextCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
273 wxTextCtrl
* tc
= wxDynamicCast(ctrl
, wxTextCtrl
);
278 if ( tc
->HasFlag(wxTE_PASSWORD
) )
279 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
281 s
= property
->GetDisplayedString();
286 // Fix indentation, just in case (change in font boldness is one good
291 // Provided so that, for example, ComboBox editor can use the same code
292 // (multiple inheritance would get way too messy).
293 bool wxPGTextCtrlEditor::OnTextCtrlEvent( wxPropertyGrid
* propGrid
,
294 wxPGProperty
* WXUNUSED(property
),
301 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
303 if ( propGrid
->IsEditorsValueModified() )
308 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
311 // Pass this event outside wxPropertyGrid so that,
312 // if necessary, program can tell when user is editing
314 // FIXME: Is it safe to change event id in the middle of event
315 // processing (seems to work, but...)?
317 event
.SetId(propGrid
->GetId());
319 propGrid
->EditorsValueWasModified();
325 bool wxPGTextCtrlEditor::OnEvent( wxPropertyGrid
* propGrid
,
326 wxPGProperty
* property
,
328 wxEvent
& event
) const
330 return wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,ctrl
,event
);
334 bool wxPGTextCtrlEditor::GetTextCtrlValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
)
336 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
337 wxString textVal
= tc
->GetValue();
339 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
345 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
347 // Changing unspecified always causes event (returning
348 // true here should be enough to trigger it).
349 // TODO: Move to propgrid.cpp
350 if ( !res
&& variant
.IsNull() )
357 bool wxPGTextCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
359 return wxPGTextCtrlEditor::GetTextCtrlValueFromControl(variant
, property
, ctrl
);
363 void wxPGTextCtrlEditor::SetValueToUnspecified( wxPGProperty
* property
, wxWindow
* ctrl
) const
365 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
367 wxPropertyGrid
* pg
= property
->GetGrid();
368 wxASSERT(pg
); // Really, property grid should exist if editor does
370 tc
->SetValue(wxEmptyString
);
374 void wxPGTextCtrlEditor::SetControlStringValue( wxPGProperty
* property
, wxWindow
* ctrl
, const wxString
& txt
) const
376 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
378 wxPropertyGrid
* pg
= property
->GetGrid();
379 wxASSERT(pg
); // Really, property grid should exist if editor does
385 void wxPGTextCtrlEditor::OnFocus( wxPGProperty
*, wxWindow
* wnd
) const
387 wxTextCtrl
* tc
= wxStaticCast(wnd
, wxTextCtrl
);
389 tc
->SetSelection(-1,-1);
393 wxPGTextCtrlEditor::~wxPGTextCtrlEditor() { }
396 // -----------------------------------------------------------------------
398 // -----------------------------------------------------------------------
401 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(Choice
,wxPGChoiceEditor
,wxPGEditor
)
404 // This is a special enhanced double-click processor class.
405 // In essence, it allows for double-clicks for which the
406 // first click "created" the control.
407 class wxPGDoubleClickProcessor
: public wxEvtHandler
411 wxPGDoubleClickProcessor( wxOwnerDrawnComboBox
* combo
, wxPGProperty
* property
)
414 m_timeLastMouseUp
= 0;
416 m_property
= property
;
417 m_downReceived
= false;
422 void OnMouseEvent( wxMouseEvent
& event
)
424 wxLongLong t
= ::wxGetLocalTimeMillis();
425 int evtType
= event
.GetEventType();
427 if ( m_property
->HasFlag(wxPG_PROP_USE_DCC
) &&
428 m_property
->IsKindOf(CLASSINFO(wxBoolProperty
)) &&
429 !m_combo
->IsPopupShown() )
431 // Just check that it is in the text area
432 wxPoint pt
= event
.GetPosition();
433 if ( m_combo
->GetTextRect().Contains(pt
) )
435 if ( evtType
== wxEVT_LEFT_DOWN
)
437 // Set value to avoid up-events without corresponding downs
438 m_downReceived
= true;
440 else if ( evtType
== wxEVT_LEFT_DCLICK
)
442 // We'll make our own double-clicks
443 event
.SetEventType(0);
446 else if ( evtType
== wxEVT_LEFT_UP
)
448 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
450 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
452 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
454 event
.SetEventType(wxEVT_LEFT_DCLICK
);
455 m_timeLastMouseUp
= 1;
459 m_timeLastMouseUp
= t
;
469 void OnSetFocus( wxFocusEvent
& event
)
471 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
476 wxLongLong m_timeLastMouseUp
;
477 wxOwnerDrawnComboBox
* m_combo
;
478 wxPGProperty
* m_property
; // Selected property
481 DECLARE_EVENT_TABLE()
484 BEGIN_EVENT_TABLE(wxPGDoubleClickProcessor
, wxEvtHandler
)
485 EVT_MOUSE_EVENTS(wxPGDoubleClickProcessor::OnMouseEvent
)
486 EVT_SET_FOCUS(wxPGDoubleClickProcessor::OnSetFocus
)
491 class wxPGComboBox
: public wxOwnerDrawnComboBox
496 : wxOwnerDrawnComboBox()
498 m_dclickProcessor
= NULL
;
499 m_sizeEventCalled
= false;
504 if ( m_dclickProcessor
)
506 RemoveEventHandler(m_dclickProcessor
);
507 delete m_dclickProcessor
;
511 bool Create(wxWindow
*parent
,
513 const wxString
& value
,
516 const wxArrayString
& choices
,
518 const wxValidator
& validator
= wxDefaultValidator
,
519 const wxString
& name
= wxS("wxOwnerDrawnComboBox"))
521 if ( !wxOwnerDrawnComboBox::Create( parent
,
532 m_dclickProcessor
= new
533 wxPGDoubleClickProcessor( this, GetGrid()->GetSelection() );
535 PushEventHandler(m_dclickProcessor
);
540 virtual void OnDrawItem( wxDC
& dc
,
545 wxPropertyGrid
* pg
= GetGrid();
546 pg
->OnComboItemPaint( this, item
, &dc
, (wxRect
&)rect
, flags
);
549 virtual wxCoord
OnMeasureItem( size_t item
) const
551 wxPropertyGrid
* pg
= GetGrid();
555 pg
->OnComboItemPaint( this, item
, NULL
, rect
, 0 );
559 wxPropertyGrid
* GetGrid() const
561 wxPropertyGrid
* pg
= wxDynamicCast(GetParent(),
567 virtual wxCoord
OnMeasureItemWidth( size_t item
) const
569 wxPropertyGrid
* pg
= GetGrid();
573 pg
->OnComboItemPaint( this, item
, NULL
, rect
, 0 );
577 virtual void PositionTextCtrl( int textCtrlXAdjust
,
578 int WXUNUSED(textCtrlYAdjust
) )
580 wxPropertyGrid
* pg
= GetGrid();
581 #ifdef wxPG_TEXTCTRLXADJUST
582 textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
-
583 (wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1) - 1,
585 wxOwnerDrawnComboBox::PositionTextCtrl(
587 pg
->GetSpacingY() + 2
592 wxPGDoubleClickProcessor
* m_dclickProcessor
;
593 bool m_sizeEventCalled
;
597 void wxPropertyGrid::OnComboItemPaint( const wxPGComboBox
* pCb
,
604 wxASSERT( IsKindOf(CLASSINFO(wxPropertyGrid
)) );
606 wxPGProperty
* p
= GetSelection();
609 const wxPGChoices
& choices
= p
->GetChoices();
610 const wxPGCommonValue
* comVal
= NULL
;
611 int comVals
= p
->GetDisplayedCommonValueCount();
612 int comValIndex
= -1;
615 if ( choices
.IsOk() )
616 choiceCount
= choices
.GetCount();
618 if ( item
>= choiceCount
&& comVals
> 0 )
620 comValIndex
= item
- choiceCount
;
621 comVal
= GetCommonValue(comValIndex
);
622 if ( !p
->IsValueUnspecified() )
623 text
= comVal
->GetLabel();
627 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
629 text
= pCb
->GetString(item
);
633 if ( !p
->IsValueUnspecified() )
634 text
= p
->GetValueAsString(0);
643 const wxBitmap
* itemBitmap
= NULL
;
645 if ( item
>= 0 && choices
.IsOk() && choices
.Item(item
).GetBitmap().Ok() && comValIndex
== -1 )
646 itemBitmap
= &choices
.Item(item
).GetBitmap();
649 // Decide what custom image size to use
652 cis
.x
= itemBitmap
->GetWidth();
653 cis
.y
= itemBitmap
->GetHeight();
657 cis
= GetImageSize(p
, item
);
662 // Default measure behaviour (no flexible, custom paint image only)
663 if ( rect
.width
< 0 )
666 pCb
->GetTextExtent(text
, &x
, &y
, 0, 0);
667 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9 + x
;
670 rect
.height
= cis
.y
+ 2;
674 wxPGPaintData paintdata
;
675 paintdata
.m_parent
= NULL
;
676 paintdata
.m_choiceItem
= item
;
678 // This is by the current (1.0.0b) spec - if painting control, item is -1
679 if ( (flags
& wxODCB_PAINTING_CONTROL
) )
680 paintdata
.m_choiceItem
= -1;
683 pDc
->SetBrush(*wxWHITE_BRUSH
);
685 wxPGCellRenderer
* renderer
= NULL
;
686 const wxPGChoiceEntry
* cell
= NULL
;
694 wxPoint
pt(rect
.x
+ wxPG_CONTROL_MARGIN
- wxPG_CHOICEXADJUST
- 1,
697 int renderFlags
= wxPGCellRenderer::DontUseCellColours
;
699 if ( flags
& wxODCB_PAINTING_CONTROL
)
700 renderFlags
|= wxPGCellRenderer::Control
;
702 renderFlags
|= wxPGCellRenderer::ChoicePopup
;
704 if ( flags
& wxODCB_PAINTING_SELECTED
)
705 renderFlags
|= wxPGCellRenderer::Selected
;
707 if ( cis
.x
> 0 && (p
->HasFlag(wxPG_PROP_CUSTOMIMAGE
) || !(flags
& wxODCB_PAINTING_CONTROL
)) &&
708 ( !p
->m_valueBitmap
|| item
== pCb
->GetSelection() ) &&
709 ( item
>= 0 || (flags
& wxODCB_PAINTING_CONTROL
) ) &&
713 pt
.x
+= wxCC_CUSTOM_IMAGE_MARGIN1
;
714 wxRect
r(pt
.x
,pt
.y
,cis
.x
,cis
.y
);
716 if ( flags
& wxODCB_PAINTING_CONTROL
)
719 r
.height
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
722 paintdata
.m_drawnWidth
= r
.width
;
724 dc
.SetPen(m_colPropFore
);
725 if ( comValIndex
>= 0 )
727 const wxPGCommonValue
* cv
= GetCommonValue(comValIndex
);
728 wxPGCellRenderer
* renderer
= cv
->GetRenderer();
729 r
.width
= rect
.width
;
730 renderer
->Render( dc
, r
, this, p
, m_selColumn
, comValIndex
, renderFlags
);
733 else if ( item
>= 0 )
735 p
->OnCustomPaint( dc
, r
, paintdata
);
739 dc
.DrawRectangle( r
);
742 pt
.x
+= paintdata
.m_drawnWidth
+ wxCC_CUSTOM_IMAGE_MARGIN2
- 1;
746 // TODO: This aligns text so that it seems to be horizontally
747 // on the same line as property values. Not really
748 // sure if its needed, but seems to not cause any harm.
751 if ( item
< 0 && (flags
& wxODCB_PAINTING_CONTROL
) )
752 item
= pCb
->GetSelection();
754 if ( choices
.IsOk() && item
>= 0 && comValIndex
< 0 )
756 cell
= &choices
.Item(item
);
757 renderer
= wxPGGlobalVars
->m_defaultRenderer
;
758 int imageOffset
= renderer
->PreDrawCell(dc
, rect
, *cell
,
761 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+
762 wxCC_CUSTOM_IMAGE_MARGIN2
;
771 pt
.y
+= (rect
.height
-m_fontHeight
)/2 - 1;
775 dc
.DrawText( text
, pt
.x
+ wxPG_XBEFORETEXT
, pt
.y
);
778 renderer
->PostDrawCell(dc
, this, *cell
, renderFlags
);
786 p
->OnCustomPaint( dc
, rect
, paintdata
);
787 rect
.height
= paintdata
.m_drawnHeight
+ 2;
788 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9;
792 bool wxPGChoiceEditor_SetCustomPaintWidth( wxPropertyGrid
* propGrid
, wxPGComboBox
* cb
, int cmnVal
)
794 wxPGProperty
* property
= propGrid
->GetSelectedProperty();
795 wxASSERT( property
);
802 // Yes, a common value is being selected
803 property
->SetCommonValue( cmnVal
);
804 imageSize
= propGrid
->GetCommonValue(cmnVal
)->
805 GetRenderer()->GetImageSize(property
, 1, cmnVal
);
810 imageSize
= propGrid
->GetImageSize(property
, -1);
815 imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
816 cb
->SetCustomPaintWidth( imageSize
.x
);
821 // CreateControls calls this with CB_READONLY in extraStyle
822 wxWindow
* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid
* propGrid
,
823 wxPGProperty
* property
,
826 long extraStyle
) const
828 const wxPGChoices
& choices
= property
->GetChoices();
830 int index
= property
->GetChoiceSelection();
832 bool isUnspecified
= property
->IsValueUnspecified();
834 if ( !isUnspecified
)
835 defString
= property
->GetDisplayedString();
837 wxArrayString labels
= choices
.GetLabels();
843 po
.y
+= wxPG_CHOICEYADJUST
;
844 si
.y
-= (wxPG_CHOICEYADJUST
*2);
846 po
.x
+= wxPG_CHOICEXADJUST
;
847 si
.x
-= wxPG_CHOICEXADJUST
;
848 wxWindow
* ctrlParent
= propGrid
->GetPanel();
850 int odcbFlags
= extraStyle
| wxBORDER_NONE
| wxTE_PROCESS_ENTER
;
852 if ( (property
->GetFlags() & wxPG_PROP_USE_DCC
) &&
853 (property
->IsKindOf(CLASSINFO(wxBoolProperty
)) ) )
854 odcbFlags
|= wxODCB_DCLICK_CYCLES
;
857 // If common value specified, use appropriate index
858 unsigned int cmnVals
= property
->GetDisplayedCommonValueCount();
861 if ( !isUnspecified
)
863 int cmnVal
= property
->GetCommonValue();
866 index
= labels
.size() + cmnVal
;
871 for ( i
=0; i
<cmnVals
; i
++ )
872 labels
.Add(propGrid
->GetCommonValueLabel(i
));
875 cb
= new wxPGComboBox();
879 cb
->Create(ctrlParent
,
887 cb
->SetButtonPosition(si
.y
,0,wxRIGHT
);
888 cb
->SetMargins(wxPG_XBEFORETEXT
-1);
890 wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, property
->GetCommonValue() );
892 if ( index
>= 0 && index
< (int)cb
->GetCount() )
894 cb
->SetSelection( index
);
895 if ( defString
.length() )
896 cb
->SetText( defString
);
898 else if ( !(extraStyle
& wxCB_READONLY
) && defString
.length() )
899 cb
->SetValue( defString
);
901 cb
->SetSelection( -1 );
907 return (wxWindow
*) cb
;
911 void wxPGChoiceEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
914 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
915 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
916 int ind
= property
->GetChoiceSelection();
917 cb
->SetSelection(ind
);
920 wxPGWindowList
wxPGChoiceEditor::CreateControls( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
921 const wxPoint
& pos
, const wxSize
& sz
) const
923 return CreateControlsBase(propGrid
,property
,pos
,sz
,wxCB_READONLY
);
927 int wxPGChoiceEditor::InsertItem( wxWindow
* ctrl
, const wxString
& label
, int index
) const
930 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
931 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
934 index
= cb
->GetCount();
936 return cb
->Insert(label
,index
);
940 void wxPGChoiceEditor::DeleteItem( wxWindow
* ctrl
, int index
) const
943 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
944 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
949 bool wxPGChoiceEditor::OnEvent( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
950 wxWindow
* ctrl
, wxEvent
& event
) const
952 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
954 wxPGComboBox
* cb
= (wxPGComboBox
*)ctrl
;
955 int index
= cb
->GetSelection();
956 int cmnValIndex
= -1;
957 int cmnVals
= property
->GetDisplayedCommonValueCount();
958 int items
= cb
->GetCount();
960 if ( index
>= (items
-cmnVals
) )
962 // Yes, a common value is being selected
963 cmnValIndex
= index
- (items
-cmnVals
);
964 property
->SetCommonValue( cmnValIndex
);
966 // Truly set value to unspecified?
967 if ( propGrid
->GetUnspecifiedCommonValue() == cmnValIndex
)
969 if ( !property
->IsValueUnspecified() )
970 propGrid
->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT
);
971 property
->SetValueToUnspecified();
972 if ( !cb
->HasFlag(wxCB_READONLY
) )
973 cb
->GetTextCtrl()->SetValue(wxEmptyString
);
977 return wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, cmnValIndex
);
983 bool wxPGChoiceEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
985 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
987 int index
= cb
->GetSelection();
989 if ( index
!= property
->GetChoiceSelection() ||
990 // Changing unspecified always causes event (returning
991 // true here should be enough to trigger it).
992 property
->IsValueUnspecified()
995 return property
->IntToValue( variant
, index
, 0 );
1001 void wxPGChoiceEditor::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, const wxString
& txt
) const
1003 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1009 void wxPGChoiceEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1011 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1013 cb
->SetSelection(value
);
1017 void wxPGChoiceEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1019 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1020 cb
->SetSelection(-1);
1024 bool wxPGChoiceEditor::CanContainCustomImage() const
1030 wxPGChoiceEditor::~wxPGChoiceEditor() { }
1033 // -----------------------------------------------------------------------
1034 // wxPGComboBoxEditor
1035 // -----------------------------------------------------------------------
1038 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ComboBox
,
1043 void wxPGComboBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1045 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1046 cb
->SetValue(property
->GetValueAsString(wxPG_EDITABLE_VALUE
));
1048 // TODO: If string matches any selection, then select that.
1052 wxPGWindowList
wxPGComboBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1053 wxPGProperty
* property
,
1055 const wxSize
& sz
) const
1057 return CreateControlsBase(propGrid
,property
,pos
,sz
,0);
1061 bool wxPGComboBoxEditor::OnEvent( wxPropertyGrid
* propGrid
,
1062 wxPGProperty
* property
,
1064 wxEvent
& event
) const
1066 wxOwnerDrawnComboBox
* cb
= NULL
;
1067 wxWindow
* textCtrl
= NULL
;
1071 cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1072 textCtrl
= cb
->GetTextCtrl();
1075 if ( wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,textCtrl
,event
) )
1078 return wxPGChoiceEditor::OnEvent(propGrid
,property
,ctrl
,event
);
1082 bool wxPGComboBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1084 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1085 wxString textVal
= cb
->GetValue();
1087 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
1093 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
1095 // Changing unspecified always causes event (returning
1096 // true here should be enough to trigger it).
1097 if ( !res
&& variant
.IsNull() )
1104 void wxPGComboBoxEditor::OnFocus( wxPGProperty
*, wxWindow
* ctrl
) const
1106 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1107 cb
->GetTextCtrl()->SetSelection(-1,-1);
1111 wxPGComboBoxEditor::~wxPGComboBoxEditor() { }
1114 // -----------------------------------------------------------------------
1115 // wxPGChoiceAndButtonEditor
1116 // -----------------------------------------------------------------------
1119 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ChoiceAndButton
,
1120 wxPGChoiceAndButtonEditor
,
1124 wxPGWindowList
wxPGChoiceAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1125 wxPGProperty
* property
,
1127 const wxSize
& sz
) const
1129 // Use one two units smaller to match size of the combo's dropbutton.
1130 // (normally a bigger button is used because it looks better)
1133 wxSize
bt_sz(bt_wid
,bt_wid
);
1135 // Position of button.
1136 wxPoint
bt_pos(pos
.x
+sz
.x
-bt_sz
.x
,pos
.y
);
1143 wxWindow
* bt
= propGrid
->GenerateEditorButton( bt_pos
, bt_sz
);
1146 wxSize
ch_sz(sz
.x
-bt
->GetSize().x
,sz
.y
);
1149 ch_sz
.x
-= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1152 wxWindow
* ch
= wxPGEditor_Choice
->CreateControls(propGrid
,property
,
1153 pos
,ch_sz
).m_primary
;
1159 return wxPGWindowList(ch
, bt
);
1163 wxPGChoiceAndButtonEditor::~wxPGChoiceAndButtonEditor() { }
1166 // -----------------------------------------------------------------------
1167 // wxPGTextCtrlAndButtonEditor
1168 // -----------------------------------------------------------------------
1170 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrlAndButton
,
1171 wxPGTextCtrlAndButtonEditor
,
1175 wxPGWindowList
wxPGTextCtrlAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1176 wxPGProperty
* property
,
1178 const wxSize
& sz
) const
1181 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrlAndButton( pos
, sz
, &wnd2
,
1182 property
->GetFlags() & wxPG_PROP_NOEDITOR
, property
);
1184 return wxPGWindowList(wnd
, wnd2
);
1188 wxPGTextCtrlAndButtonEditor::~wxPGTextCtrlAndButtonEditor() { }
1191 // -----------------------------------------------------------------------
1192 // wxPGCheckBoxEditor
1193 // -----------------------------------------------------------------------
1195 #if wxPG_INCLUDE_CHECKBOX
1197 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(CheckBox
,
1202 // Check box state flags
1205 wxSCB_STATE_UNCHECKED
= 0,
1206 wxSCB_STATE_CHECKED
= 1,
1207 wxSCB_STATE_BOLD
= 2,
1208 wxSCB_STATE_UNSPECIFIED
= 4
1211 const int wxSCB_SETVALUE_CYCLE
= 2;
1214 static void DrawSimpleCheckBox( wxDC
& dc
, const wxRect
& rect
, int box_hei
,
1215 int state
, const wxColour
& lineCol
)
1218 wxRect
r(rect
.x
+wxPG_XBEFORETEXT
,rect
.y
+((rect
.height
-box_hei
)/2),
1220 wxColour useCol
= lineCol
;
1222 if ( state
& wxSCB_STATE_UNSPECIFIED
)
1224 useCol
= wxColour(220, 220, 220);
1227 // Draw check mark first because it is likely to overdraw the
1228 // surrounding rectangle.
1229 if ( state
& wxSCB_STATE_CHECKED
)
1231 wxRect
r2(r
.x
+wxPG_CHECKMARK_XADJ
,
1232 r
.y
+wxPG_CHECKMARK_YADJ
,
1233 r
.width
+wxPG_CHECKMARK_WADJ
,
1234 r
.height
+wxPG_CHECKMARK_HADJ
);
1235 #if wxPG_CHECKMARK_DEFLATE
1236 r2
.Deflate(wxPG_CHECKMARK_DEFLATE
);
1238 dc
.DrawCheckMark(r2
);
1240 // This would draw a simple cross check mark.
1241 // dc.DrawLine(r.x,r.y,r.x+r.width-1,r.y+r.height-1);
1242 // dc.DrawLine(r.x,r.y+r.height-1,r.x+r.width-1,r.y);
1245 if ( !(state
& wxSCB_STATE_BOLD
) )
1247 // Pen for thin rectangle.
1252 // Pen for bold rectangle.
1253 wxPen
linepen(useCol
,2,wxSOLID
);
1254 linepen
.SetJoin(wxJOIN_MITER
); // This prevents round edges.
1262 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1264 dc
.DrawRectangle(r
);
1265 dc
.SetPen(*wxTRANSPARENT_PEN
);
1269 // Real simple custom-drawn checkbox-without-label class.
1271 class wxSimpleCheckBox
: public wxControl
1275 void SetValue( int value
);
1277 wxSimpleCheckBox( wxWindow
* parent
,
1279 const wxPoint
& pos
= wxDefaultPosition
,
1280 const wxSize
& size
= wxDefaultSize
)
1281 : wxControl(parent
,id
,pos
,size
,wxBORDER_NONE
|wxWANTS_CHARS
)
1283 // Due to SetOwnFont stuff necessary for GTK+ 1.2, we need to have this
1284 SetFont( parent
->GetFont() );
1289 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
1292 virtual ~wxSimpleCheckBox();
1298 void OnPaint( wxPaintEvent
& event
);
1299 void OnLeftClick( wxMouseEvent
& event
);
1300 void OnKeyDown( wxKeyEvent
& event
);
1302 void OnResize( wxSizeEvent
& event
)
1308 static wxBitmap
* ms_doubleBuffer
;
1310 DECLARE_EVENT_TABLE()
1313 BEGIN_EVENT_TABLE(wxSimpleCheckBox
, wxControl
)
1314 EVT_PAINT(wxSimpleCheckBox::OnPaint
)
1315 EVT_LEFT_DOWN(wxSimpleCheckBox::OnLeftClick
)
1316 EVT_LEFT_DCLICK(wxSimpleCheckBox::OnLeftClick
)
1317 EVT_KEY_DOWN(wxSimpleCheckBox::OnKeyDown
)
1318 EVT_SIZE(wxSimpleCheckBox::OnResize
)
1321 wxSimpleCheckBox::~wxSimpleCheckBox()
1323 delete ms_doubleBuffer
;
1324 ms_doubleBuffer
= NULL
;
1327 wxBitmap
* wxSimpleCheckBox::ms_doubleBuffer
= NULL
;
1329 void wxSimpleCheckBox::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1331 wxSize clientSize
= GetClientSize();
1332 wxAutoBufferedPaintDC
dc(this);
1335 wxRect
rect(0,0,clientSize
.x
,clientSize
.y
);
1339 wxColour bgcol
= GetBackgroundColour();
1340 dc
.SetBrush( bgcol
);
1342 dc
.DrawRectangle( rect
);
1344 wxColour txcol
= GetForegroundColour();
1346 int state
= m_state
;
1347 if ( !(state
& wxSCB_STATE_UNSPECIFIED
) &&
1348 GetFont().GetWeight() == wxBOLD
)
1349 state
|= wxSCB_STATE_BOLD
;
1351 DrawSimpleCheckBox(dc
,rect
,m_boxHeight
,state
,txcol
);
1354 void wxSimpleCheckBox::OnLeftClick( wxMouseEvent
& event
)
1356 if ( (event
.m_x
> (wxPG_XBEFORETEXT
-2)) &&
1357 (event
.m_x
<= (wxPG_XBEFORETEXT
-2+m_boxHeight
)) )
1359 SetValue(wxSCB_SETVALUE_CYCLE
);
1363 void wxSimpleCheckBox::OnKeyDown( wxKeyEvent
& event
)
1365 if ( event
.GetKeyCode() == WXK_SPACE
)
1367 SetValue(wxSCB_SETVALUE_CYCLE
);
1371 void wxSimpleCheckBox::SetValue( int value
)
1373 if ( value
== wxSCB_SETVALUE_CYCLE
)
1375 if ( m_state
& wxSCB_STATE_CHECKED
)
1376 m_state
&= ~wxSCB_STATE_CHECKED
;
1378 m_state
|= wxSCB_STATE_CHECKED
;
1386 wxCommandEvent
evt(wxEVT_COMMAND_CHECKBOX_CLICKED
,GetParent()->GetId());
1388 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent();
1389 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1390 propGrid
->HandleCustomEditorEvent(evt
);
1393 wxPGWindowList
wxPGCheckBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1394 wxPGProperty
* property
,
1396 const wxSize
& size
) const
1399 pt
.x
-= wxPG_XBEFOREWIDGET
;
1401 sz
.x
= propGrid
->GetFontHeight() + (wxPG_XBEFOREWIDGET
*2) + 4;
1403 wxSimpleCheckBox
* cb
= new wxSimpleCheckBox(propGrid
->GetPanel(),
1404 wxPG_SUBID1
, pt
, sz
);
1406 cb
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
1408 UpdateControl(property
, cb
);
1410 if ( !property
->IsValueUnspecified() )
1412 // If mouse cursor was on the item, toggle the value now.
1413 if ( propGrid
->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK
)
1415 wxPoint pt
= cb
->ScreenToClient(::wxGetMousePosition());
1416 if ( pt
.x
<= (wxPG_XBEFORETEXT
-2+cb
->m_boxHeight
) )
1418 if ( cb
->m_state
& wxSCB_STATE_CHECKED
)
1419 cb
->m_state
&= ~wxSCB_STATE_CHECKED
;
1421 cb
->m_state
|= wxSCB_STATE_CHECKED
;
1423 // Makes sure wxPG_EVT_CHANGING etc. is sent for this initial
1425 propGrid
->ChangePropertyValue(property
,
1426 wxPGVariant_Bool(cb
->m_state
));
1431 propGrid
->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR
);
1436 void wxPGCheckBoxEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
,
1437 wxPGProperty
* property
,
1438 const wxString
& WXUNUSED(text
) ) const
1440 int state
= wxSCB_STATE_UNCHECKED
;
1441 wxColour rectCol
= dc
.GetTextForeground();
1443 if ( !property
->IsValueUnspecified() )
1445 state
= property
->GetChoiceSelection();
1446 if ( dc
.GetFont().GetWeight() == wxBOLD
)
1447 state
|= wxSCB_STATE_BOLD
;
1451 state
|= wxSCB_STATE_UNSPECIFIED
;
1454 DrawSimpleCheckBox(dc
, rect
, dc
.GetCharHeight(), state
, rectCol
);
1457 void wxPGCheckBoxEditor::UpdateControl( wxPGProperty
* property
,
1458 wxWindow
* ctrl
) const
1460 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*) ctrl
;
1463 if ( !property
->IsValueUnspecified() )
1464 cb
->m_state
= property
->GetChoiceSelection();
1466 cb
->m_state
= wxSCB_STATE_UNSPECIFIED
;
1468 wxPropertyGrid
* propGrid
= property
->GetGrid();
1469 cb
->m_boxHeight
= propGrid
->GetFontHeight();
1474 bool wxPGCheckBoxEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propGrid
), wxPGProperty
* WXUNUSED(property
),
1475 wxWindow
* WXUNUSED(ctrl
), wxEvent
& event
) const
1477 if ( event
.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED
)
1485 bool wxPGCheckBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1487 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*)ctrl
;
1489 int index
= cb
->m_state
;
1491 if ( index
!= property
->GetChoiceSelection() ||
1492 // Changing unspecified always causes event (returning
1493 // true here should be enough to trigger it).
1494 property
->IsValueUnspecified()
1497 return property
->IntToValue(variant
, index
, 0);
1503 void wxPGCheckBoxEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1505 if ( value
!= 0 ) value
= 1;
1506 ((wxSimpleCheckBox
*)ctrl
)->m_state
= value
;
1511 void wxPGCheckBoxEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1513 ((wxSimpleCheckBox
*)ctrl
)->m_state
= wxSCB_STATE_UNSPECIFIED
;
1518 wxPGCheckBoxEditor::~wxPGCheckBoxEditor() { }
1521 #endif // wxPG_INCLUDE_CHECKBOX
1523 // -----------------------------------------------------------------------
1525 wxWindow
* wxPropertyGrid::GetEditorControl() const
1527 wxWindow
* ctrl
= m_wndEditor
;
1535 // -----------------------------------------------------------------------
1537 void wxPropertyGrid::CorrectEditorWidgetSizeX()
1540 int newSplitterx
= m_pState
->DoGetSplitterPosition(m_selColumn
-1);
1541 int newWidth
= newSplitterx
+ m_pState
->m_colWidths
[m_selColumn
];
1545 // if width change occurred, move secondary wnd by that amount
1546 wxRect r
= m_wndEditor2
->GetRect();
1548 r
.x
= newWidth
- secWid
;
1550 m_wndEditor2
->SetSize( r
);
1552 // if primary is textctrl, then we have to add some extra space
1556 if ( m_wndEditor
&& m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1558 secWid
+= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1563 wxRect r
= m_wndEditor
->GetRect();
1565 r
.x
= newSplitterx
+m_ctrlXAdjust
;
1567 if ( !(m_iFlags
& wxPG_FL_FIXED_WIDTH_EDITOR
) )
1568 r
.width
= newWidth
- r
.x
- secWid
;
1570 m_wndEditor
->SetSize(r
);
1574 m_wndEditor2
->Refresh();
1577 // -----------------------------------------------------------------------
1579 void wxPropertyGrid::CorrectEditorWidgetPosY()
1581 if ( GetSelection() && (m_wndEditor
|| m_wndEditor2
) )
1583 wxRect r
= GetEditorWidgetRect(GetSelection(), m_selColumn
);
1587 wxPoint pos
= m_wndEditor
->GetPosition();
1589 // Calculate y offset
1590 int offset
= pos
.y
% m_lineHeight
;
1592 m_wndEditor
->Move(pos
.x
, r
.y
+ offset
);
1597 wxPoint pos
= m_wndEditor2
->GetPosition();
1599 m_wndEditor2
->Move(pos
.x
, r
.y
);
1604 // -----------------------------------------------------------------------
1606 // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
1607 // fits into that category as well).
1608 void wxPropertyGrid::FixPosForTextCtrl( wxWindow
* ctrl
,
1609 unsigned int WXUNUSED(forColumn
),
1610 const wxPoint
& offset
)
1612 // Center the control vertically
1613 wxRect finalPos
= ctrl
->GetRect();
1614 int y_adj
= (m_lineHeight
- finalPos
.height
)/2 + wxPG_TEXTCTRLYADJUST
;
1616 // Prevent over-sized control
1617 int sz_dec
= (y_adj
+ finalPos
.height
) - m_lineHeight
;
1618 if ( sz_dec
< 0 ) sz_dec
= 0;
1620 finalPos
.y
+= y_adj
;
1621 finalPos
.height
-= (y_adj
+sz_dec
);
1623 #ifndef wxPG_TEXTCTRLXADJUST
1624 int textCtrlXAdjust
= wxPG_XBEFORETEXT
- 1;
1626 wxTextCtrl
* tc
= static_cast<wxTextCtrl
*>(ctrl
);
1629 int textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
;
1632 finalPos
.x
+= textCtrlXAdjust
;
1633 finalPos
.width
-= textCtrlXAdjust
;
1635 finalPos
.x
+= offset
.x
;
1636 finalPos
.y
+= offset
.y
;
1638 ctrl
->SetSize(finalPos
);
1641 // -----------------------------------------------------------------------
1643 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint
& pos
,
1645 const wxString
& value
,
1646 wxWindow
* secondary
,
1649 unsigned int forColumn
)
1651 wxWindowID id
= wxPG_SUBID1
;
1652 wxPGProperty
* prop
= GetSelection();
1655 int tcFlags
= wxTE_PROCESS_ENTER
| extraStyle
;
1657 if ( prop
->HasFlag(wxPG_PROP_READONLY
) && forColumn
== 1 )
1658 tcFlags
|= wxTE_READONLY
;
1660 wxPoint
p(pos
.x
,pos
.y
);
1661 wxSize
s(sz
.x
,sz
.y
);
1663 // Need to reduce width of text control on Mac
1664 #if defined(__WXMAC__)
1668 // For label editors, trim the size to allow better splitter grabbing
1669 if ( forColumn
!= 1 )
1672 // Take button into acccount
1675 s
.x
-= (secondary
->GetSize().x
+ wxPG_TEXTCTRL_AND_BUTTON_SPACING
);
1676 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
1679 // If the height is significantly higher, then use border, and fill the rect exactly.
1680 bool hasSpecialSize
= false;
1682 if ( (sz
.y
- m_lineHeight
) > 5 )
1683 hasSpecialSize
= true;
1685 wxWindow
* ctrlParent
= GetPanel();
1687 if ( !hasSpecialSize
)
1688 tcFlags
|= wxBORDER_NONE
;
1690 wxTextCtrl
* tc
= new wxTextCtrl();
1692 #if defined(__WXMSW__)
1695 SetupTextCtrlValue(value
);
1696 tc
->Create(ctrlParent
,id
,value
, p
, s
,tcFlags
);
1698 #if defined(__WXMSW__)
1699 // On Windows, we need to override read-only text ctrl's background
1700 // colour to white. One problem with native 'grey' background is that
1701 // tc->GetBackgroundColour() doesn't seem to return correct value
1703 if ( tcFlags
& wxTE_READONLY
)
1705 wxVisualAttributes vattrs
= tc
->GetDefaultAttributes();
1706 tc
->SetBackgroundColour(vattrs
.colBg
);
1710 // Center the control vertically
1711 if ( !hasSpecialSize
)
1712 FixPosForTextCtrl(tc
, forColumn
);
1714 if ( forColumn
!= 1 )
1716 tc
->SetBackgroundColour(m_colSelBack
);
1717 tc
->SetForegroundColour(m_colSelFore
);
1726 // Set maximum length
1728 tc
->SetMaxLength( maxLen
);
1730 wxVariant attrVal
= prop
->GetAttribute(wxPG_ATTR_AUTOCOMPLETE
);
1731 if ( !attrVal
.IsNull() )
1733 wxASSERT(attrVal
.GetType() == wxS("arrstring"));
1734 tc
->AutoComplete(attrVal
.GetArrayString());
1740 // -----------------------------------------------------------------------
1742 wxWindow
* wxPropertyGrid::GenerateEditorButton( const wxPoint
& pos
, const wxSize
& sz
)
1744 wxWindowID id
= wxPG_SUBID2
;
1745 wxPGProperty
* selected
= GetSelection();
1749 // Decorations are chunky on Mac, and we can't make the button square, so
1750 // do things a bit differently on this platform.
1752 wxPoint
p(pos
.x
+sz
.x
,
1753 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1756 wxButton
* but
= new wxButton();
1757 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1759 // Now that we know the size, move to the correct position
1760 p
.x
= pos
.x
+ sz
.x
- but
->GetSize().x
- 2;
1764 wxSize
s(sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2),
1765 sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2));
1767 // Reduce button width to lineheight
1768 if ( s
.x
> m_lineHeight
)
1772 // On wxGTK, take fixed button margins into account
1777 wxPoint
p(pos
.x
+sz
.x
-s
.x
,
1778 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1780 wxButton
* but
= new wxButton();
1784 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1787 wxFont font
= GetFont();
1788 font
.SetPointSize(font
.GetPointSize()-2);
1791 but
->SetFont(GetFont());
1795 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1801 // -----------------------------------------------------------------------
1803 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrlAndButton( const wxPoint
& pos
,
1805 wxWindow
** psecondary
,
1807 wxPGProperty
* property
)
1809 wxButton
* but
= (wxButton
*)GenerateEditorButton(pos
,sz
);
1810 *psecondary
= (wxWindow
*)but
;
1812 if ( limitedEditing
)
1815 // There is button Show in GenerateEditorTextCtrl as well
1823 if ( !property
->IsValueUnspecified() )
1824 text
= property
->GetValueAsString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
1826 return GenerateEditorTextCtrl(pos
,sz
,text
,but
,property
->m_maxLen
);
1829 // -----------------------------------------------------------------------
1831 wxTextCtrl
* wxPropertyGrid::GetEditorTextCtrl() const
1833 wxWindow
* wnd
= GetEditorControl();
1838 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1839 return wxStaticCast(wnd
, wxTextCtrl
);
1841 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
1843 wxOwnerDrawnComboBox
* cb
= wxStaticCast(wnd
, wxOwnerDrawnComboBox
);
1844 return cb
->GetTextCtrl();
1850 // -----------------------------------------------------------------------
1852 wxPGEditor
* wxPropertyGridInterface::GetEditorByName( const wxString
& editorName
)
1854 wxPGHashMapS2P::const_iterator it
;
1856 it
= wxPGGlobalVars
->m_mapEditorClasses
.find(editorName
);
1857 if ( it
== wxPGGlobalVars
->m_mapEditorClasses
.end() )
1859 return (wxPGEditor
*) it
->second
;
1862 // -----------------------------------------------------------------------
1863 // wxPGEditorDialogAdapter
1864 // -----------------------------------------------------------------------
1866 IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter
, wxObject
)
1868 bool wxPGEditorDialogAdapter::ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
1870 if ( !propGrid
->EditorValidate() )
1873 bool res
= DoShowDialog( propGrid
, property
);
1877 propGrid
->ValueChangeInEvent( m_value
);
1884 // -----------------------------------------------------------------------
1886 // -----------------------------------------------------------------------
1888 wxPGMultiButton::wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
)
1889 : wxWindow( pg
->GetPanel(), wxPG_SUBID2
, wxPoint(-100,-100), wxSize(0, sz
.y
) ),
1890 m_fullEditorSize(sz
), m_buttonsWidth(0)
1892 SetBackgroundColour(pg
->GetCellBackgroundColour());
1895 void wxPGMultiButton::Finalize( wxPropertyGrid
* WXUNUSED(propGrid
),
1896 const wxPoint
& pos
)
1898 Move( pos
.x
+ m_fullEditorSize
.x
- m_buttonsWidth
, pos
.y
);
1901 int wxPGMultiButton::GenId( int id
) const
1905 if ( m_buttons
.size() )
1906 id
= GetButton(m_buttons
.size()-1)->GetId() + 1;
1914 void wxPGMultiButton::Add( const wxBitmap
& bitmap
, int id
)
1917 wxSize sz
= GetSize();
1918 wxButton
* button
= new wxBitmapButton( this, id
, bitmap
,
1920 wxSize(sz
.y
, sz
.y
) );
1921 DoAddButton( button
, sz
);
1925 void wxPGMultiButton::Add( const wxString
& label
, int id
)
1928 wxSize sz
= GetSize();
1929 wxButton
* button
= new wxButton( this, id
, label
, wxPoint(sz
.x
, 0),
1930 wxSize(sz
.y
, sz
.y
) );
1931 DoAddButton( button
, sz
);
1934 void wxPGMultiButton::DoAddButton( wxWindow
* button
,
1937 m_buttons
.push_back(button
);
1938 int bw
= button
->GetSize().x
;
1939 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
1940 m_buttonsWidth
+= bw
;
1943 // -----------------------------------------------------------------------
1945 #endif // wxUSE_PROPGRID