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 9
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()->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
);
691 wxPoint
pt(rect
.x
+ wxPG_CONTROL_MARGIN
- wxPG_CHOICEXADJUST
- 1,
694 int renderFlags
= wxPGCellRenderer::DontUseCellColours
;
696 if ( flags
& wxODCB_PAINTING_CONTROL
)
697 renderFlags
|= wxPGCellRenderer::Control
;
699 renderFlags
|= wxPGCellRenderer::ChoicePopup
;
701 if ( flags
& wxODCB_PAINTING_SELECTED
)
702 renderFlags
|= wxPGCellRenderer::Selected
;
704 if ( cis
.x
> 0 && (p
->HasFlag(wxPG_PROP_CUSTOMIMAGE
) || !(flags
& wxODCB_PAINTING_CONTROL
)) &&
705 ( !p
->m_valueBitmap
|| item
== pCb
->GetSelection() ) &&
706 ( item
>= 0 || (flags
& wxODCB_PAINTING_CONTROL
) ) &&
710 pt
.x
+= wxCC_CUSTOM_IMAGE_MARGIN1
;
711 wxRect
r(pt
.x
,pt
.y
,cis
.x
,cis
.y
);
713 if ( flags
& wxODCB_PAINTING_CONTROL
)
716 r
.height
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
719 paintdata
.m_drawnWidth
= r
.width
;
721 dc
.SetPen(m_colPropFore
);
722 if ( comValIndex
>= 0 )
724 const wxPGCommonValue
* cv
= GetCommonValue(comValIndex
);
725 wxPGCellRenderer
* renderer
= cv
->GetRenderer();
726 r
.width
= rect
.width
;
727 renderer
->Render( dc
, r
, this, p
, m_selColumn
, comValIndex
, renderFlags
);
730 else if ( item
>= 0 )
732 p
->OnCustomPaint( dc
, r
, paintdata
);
736 dc
.DrawRectangle( r
);
739 pt
.x
+= paintdata
.m_drawnWidth
+ wxCC_CUSTOM_IMAGE_MARGIN2
- 1;
743 // TODO: This aligns text so that it seems to be horizontally
744 // on the same line as property values. Not really
745 // sure if its needed, but seems to not cause any harm.
748 if ( item
< 0 && (flags
& wxODCB_PAINTING_CONTROL
) )
749 item
= pCb
->GetSelection();
751 if ( choices
.IsOk() && item
>= 0 && comValIndex
< 0 )
753 const wxPGChoiceEntry
& cell
= choices
.Item(item
);
754 wxPGCellRenderer
* renderer
= wxPGGlobalVars
->m_defaultRenderer
;
755 int imageOffset
= renderer
->PreDrawCell( dc
, rect
, cell
, renderFlags
);
757 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
766 pt
.y
+= (rect
.height
-m_fontHeight
)/2 - 1;
770 dc
.DrawText( text
, pt
.x
+ wxPG_XBEFORETEXT
, pt
.y
);
778 p
->OnCustomPaint( dc
, rect
, paintdata
);
779 rect
.height
= paintdata
.m_drawnHeight
+ 2;
780 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9;
784 bool wxPGChoiceEditor_SetCustomPaintWidth( wxPropertyGrid
* propGrid
, wxPGComboBox
* cb
, int cmnVal
)
786 wxPGProperty
* property
= propGrid
->GetSelectedProperty();
787 wxASSERT( property
);
791 // Yes, a common value is being selected
792 property
->SetCommonValue( cmnVal
);
793 wxSize imageSize
= propGrid
->GetCommonValue(cmnVal
)->
794 GetRenderer()->GetImageSize(property
, 1, cmnVal
);
795 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
796 cb
->SetCustomPaintWidth( imageSize
.x
);
801 wxSize imageSize
= propGrid
->GetImageSize(property
, -1);
802 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
803 cb
->SetCustomPaintWidth( imageSize
.x
);
808 // CreateControls calls this with CB_READONLY in extraStyle
809 wxWindow
* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid
* propGrid
,
810 wxPGProperty
* property
,
813 long extraStyle
) const
815 const wxPGChoices
& choices
= property
->GetChoices();
817 int index
= property
->GetChoiceSelection();
819 bool isUnspecified
= property
->IsValueUnspecified();
821 if ( !isUnspecified
)
822 defString
= property
->GetDisplayedString();
824 wxArrayString labels
= choices
.GetLabels();
830 po
.y
+= wxPG_CHOICEYADJUST
;
831 si
.y
-= (wxPG_CHOICEYADJUST
*2);
833 po
.x
+= wxPG_CHOICEXADJUST
;
834 si
.x
-= wxPG_CHOICEXADJUST
;
835 wxWindow
* ctrlParent
= propGrid
->GetPanel();
837 int odcbFlags
= extraStyle
| wxBORDER_NONE
| wxTE_PROCESS_ENTER
;
839 if ( (property
->GetFlags() & wxPG_PROP_USE_DCC
) &&
840 (property
->IsKindOf(CLASSINFO(wxBoolProperty
)) ) )
841 odcbFlags
|= wxODCB_DCLICK_CYCLES
;
844 // If common value specified, use appropriate index
845 unsigned int cmnVals
= property
->GetDisplayedCommonValueCount();
848 if ( !isUnspecified
)
850 int cmnVal
= property
->GetCommonValue();
853 index
= labels
.size() + cmnVal
;
858 for ( i
=0; i
<cmnVals
; i
++ )
859 labels
.Add(propGrid
->GetCommonValueLabel(i
));
862 cb
= new wxPGComboBox();
866 cb
->Create(ctrlParent
,
874 cb
->SetButtonPosition(si
.y
,0,wxRIGHT
);
875 cb
->SetMargins(wxPG_XBEFORETEXT
-1);
877 wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, property
->GetCommonValue() );
879 if ( index
>= 0 && index
< (int)cb
->GetCount() )
881 cb
->SetSelection( index
);
882 if ( defString
.length() )
883 cb
->SetText( defString
);
885 else if ( !(extraStyle
& wxCB_READONLY
) && defString
.length() )
886 cb
->SetValue( defString
);
888 cb
->SetSelection( -1 );
894 return (wxWindow
*) cb
;
898 void wxPGChoiceEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
901 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
902 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
903 int ind
= property
->GetChoiceSelection();
904 cb
->SetSelection(ind
);
907 wxPGWindowList
wxPGChoiceEditor::CreateControls( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
908 const wxPoint
& pos
, const wxSize
& sz
) const
910 return CreateControlsBase(propGrid
,property
,pos
,sz
,wxCB_READONLY
);
914 int wxPGChoiceEditor::InsertItem( wxWindow
* ctrl
, const wxString
& label
, int index
) const
917 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
918 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
921 index
= cb
->GetCount();
923 return cb
->Insert(label
,index
);
927 void wxPGChoiceEditor::DeleteItem( wxWindow
* ctrl
, int index
) const
930 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
931 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
936 bool wxPGChoiceEditor::OnEvent( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
937 wxWindow
* ctrl
, wxEvent
& event
) const
939 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
941 wxPGComboBox
* cb
= (wxPGComboBox
*)ctrl
;
942 int index
= cb
->GetSelection();
943 int cmnValIndex
= -1;
944 int cmnVals
= property
->GetDisplayedCommonValueCount();
945 int items
= cb
->GetCount();
947 if ( index
>= (items
-cmnVals
) )
949 // Yes, a common value is being selected
950 cmnValIndex
= index
- (items
-cmnVals
);
951 property
->SetCommonValue( cmnValIndex
);
953 // Truly set value to unspecified?
954 if ( propGrid
->GetUnspecifiedCommonValue() == cmnValIndex
)
956 if ( !property
->IsValueUnspecified() )
957 propGrid
->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT
);
958 property
->SetValueToUnspecified();
959 if ( !cb
->HasFlag(wxCB_READONLY
) )
960 cb
->GetTextCtrl()->SetValue(wxEmptyString
);
964 return wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, cmnValIndex
);
970 bool wxPGChoiceEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
972 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
974 int index
= cb
->GetSelection();
976 if ( index
!= property
->GetChoiceSelection() ||
977 // Changing unspecified always causes event (returning
978 // true here should be enough to trigger it).
979 property
->IsValueUnspecified()
982 return property
->IntToValue( variant
, index
, 0 );
988 void wxPGChoiceEditor::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, const wxString
& txt
) const
990 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
996 void wxPGChoiceEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
998 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1000 cb
->SetSelection(value
);
1004 void wxPGChoiceEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1006 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1007 cb
->SetSelection(-1);
1011 bool wxPGChoiceEditor::CanContainCustomImage() const
1017 wxPGChoiceEditor::~wxPGChoiceEditor() { }
1020 // -----------------------------------------------------------------------
1021 // wxPGComboBoxEditor
1022 // -----------------------------------------------------------------------
1025 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ComboBox
,
1030 void wxPGComboBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1032 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1033 cb
->SetValue(property
->GetValueAsString(wxPG_EDITABLE_VALUE
));
1035 // TODO: If string matches any selection, then select that.
1039 wxPGWindowList
wxPGComboBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1040 wxPGProperty
* property
,
1042 const wxSize
& sz
) const
1044 return CreateControlsBase(propGrid
,property
,pos
,sz
,0);
1048 bool wxPGComboBoxEditor::OnEvent( wxPropertyGrid
* propGrid
,
1049 wxPGProperty
* property
,
1051 wxEvent
& event
) const
1053 wxOwnerDrawnComboBox
* cb
= NULL
;
1054 wxWindow
* textCtrl
= NULL
;
1058 cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1059 textCtrl
= cb
->GetTextCtrl();
1062 if ( wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,textCtrl
,event
) )
1065 return wxPGChoiceEditor::OnEvent(propGrid
,property
,ctrl
,event
);
1069 bool wxPGComboBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1071 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1072 wxString textVal
= cb
->GetValue();
1074 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
1080 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
1082 // Changing unspecified always causes event (returning
1083 // true here should be enough to trigger it).
1084 if ( !res
&& variant
.IsNull() )
1091 void wxPGComboBoxEditor::OnFocus( wxPGProperty
*, wxWindow
* ctrl
) const
1093 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1094 cb
->GetTextCtrl()->SetSelection(-1,-1);
1098 wxPGComboBoxEditor::~wxPGComboBoxEditor() { }
1101 // -----------------------------------------------------------------------
1102 // wxPGChoiceAndButtonEditor
1103 // -----------------------------------------------------------------------
1106 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ChoiceAndButton
,
1107 wxPGChoiceAndButtonEditor
,
1111 wxPGWindowList
wxPGChoiceAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1112 wxPGProperty
* property
,
1114 const wxSize
& sz
) const
1116 // Use one two units smaller to match size of the combo's dropbutton.
1117 // (normally a bigger button is used because it looks better)
1120 wxSize
bt_sz(bt_wid
,bt_wid
);
1122 // Position of button.
1123 wxPoint
bt_pos(pos
.x
+sz
.x
-bt_sz
.x
,pos
.y
);
1130 wxWindow
* bt
= propGrid
->GenerateEditorButton( bt_pos
, bt_sz
);
1133 wxSize
ch_sz(sz
.x
-bt
->GetSize().x
,sz
.y
);
1136 ch_sz
.x
-= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1139 wxWindow
* ch
= wxPGEditor_Choice
->CreateControls(propGrid
,property
,
1140 pos
,ch_sz
).m_primary
;
1146 return wxPGWindowList(ch
, bt
);
1150 wxPGChoiceAndButtonEditor::~wxPGChoiceAndButtonEditor() { }
1153 // -----------------------------------------------------------------------
1154 // wxPGTextCtrlAndButtonEditor
1155 // -----------------------------------------------------------------------
1157 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrlAndButton
,
1158 wxPGTextCtrlAndButtonEditor
,
1162 wxPGWindowList
wxPGTextCtrlAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1163 wxPGProperty
* property
,
1165 const wxSize
& sz
) const
1168 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrlAndButton( pos
, sz
, &wnd2
,
1169 property
->GetFlags() & wxPG_PROP_NOEDITOR
, property
);
1171 return wxPGWindowList(wnd
, wnd2
);
1175 wxPGTextCtrlAndButtonEditor::~wxPGTextCtrlAndButtonEditor() { }
1178 // -----------------------------------------------------------------------
1179 // wxPGCheckBoxEditor
1180 // -----------------------------------------------------------------------
1182 #if wxPG_INCLUDE_CHECKBOX
1184 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(CheckBox
,
1189 // Check box state flags
1192 wxSCB_STATE_UNCHECKED
= 0,
1193 wxSCB_STATE_CHECKED
= 1,
1194 wxSCB_STATE_BOLD
= 2,
1195 wxSCB_STATE_UNSPECIFIED
= 4
1198 const int wxSCB_SETVALUE_CYCLE
= 2;
1201 static void DrawSimpleCheckBox( wxDC
& dc
, const wxRect
& rect
, int box_hei
,
1202 int state
, const wxColour
& lineCol
)
1205 wxRect
r(rect
.x
+wxPG_XBEFORETEXT
,rect
.y
+((rect
.height
-box_hei
)/2),
1207 wxColour useCol
= lineCol
;
1209 if ( state
& wxSCB_STATE_UNSPECIFIED
)
1211 useCol
= wxColour(220, 220, 220);
1214 // Draw check mark first because it is likely to overdraw the
1215 // surrounding rectangle.
1216 if ( state
& wxSCB_STATE_CHECKED
)
1218 wxRect
r2(r
.x
+wxPG_CHECKMARK_XADJ
,
1219 r
.y
+wxPG_CHECKMARK_YADJ
,
1220 r
.width
+wxPG_CHECKMARK_WADJ
,
1221 r
.height
+wxPG_CHECKMARK_HADJ
);
1222 #if wxPG_CHECKMARK_DEFLATE
1223 r2
.Deflate(wxPG_CHECKMARK_DEFLATE
);
1225 dc
.DrawCheckMark(r2
);
1227 // This would draw a simple cross check mark.
1228 // dc.DrawLine(r.x,r.y,r.x+r.width-1,r.y+r.height-1);
1229 // dc.DrawLine(r.x,r.y+r.height-1,r.x+r.width-1,r.y);
1232 if ( !(state
& wxSCB_STATE_BOLD
) )
1234 // Pen for thin rectangle.
1239 // Pen for bold rectangle.
1240 wxPen
linepen(useCol
,2,wxSOLID
);
1241 linepen
.SetJoin(wxJOIN_MITER
); // This prevents round edges.
1249 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1251 dc
.DrawRectangle(r
);
1252 dc
.SetPen(*wxTRANSPARENT_PEN
);
1256 // Real simple custom-drawn checkbox-without-label class.
1258 class wxSimpleCheckBox
: public wxControl
1262 void SetValue( int value
);
1264 wxSimpleCheckBox( wxWindow
* parent
,
1266 const wxPoint
& pos
= wxDefaultPosition
,
1267 const wxSize
& size
= wxDefaultSize
)
1268 : wxControl(parent
,id
,pos
,size
,wxBORDER_NONE
|wxWANTS_CHARS
)
1270 // Due to SetOwnFont stuff necessary for GTK+ 1.2, we need to have this
1271 SetFont( parent
->GetFont() );
1276 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
1279 virtual ~wxSimpleCheckBox();
1285 void OnPaint( wxPaintEvent
& event
);
1286 void OnLeftClick( wxMouseEvent
& event
);
1287 void OnKeyDown( wxKeyEvent
& event
);
1289 void OnResize( wxSizeEvent
& event
)
1295 static wxBitmap
* ms_doubleBuffer
;
1297 DECLARE_EVENT_TABLE()
1300 BEGIN_EVENT_TABLE(wxSimpleCheckBox
, wxControl
)
1301 EVT_PAINT(wxSimpleCheckBox::OnPaint
)
1302 EVT_LEFT_DOWN(wxSimpleCheckBox::OnLeftClick
)
1303 EVT_LEFT_DCLICK(wxSimpleCheckBox::OnLeftClick
)
1304 EVT_KEY_DOWN(wxSimpleCheckBox::OnKeyDown
)
1305 EVT_SIZE(wxSimpleCheckBox::OnResize
)
1308 wxSimpleCheckBox::~wxSimpleCheckBox()
1310 delete ms_doubleBuffer
;
1311 ms_doubleBuffer
= NULL
;
1314 wxBitmap
* wxSimpleCheckBox::ms_doubleBuffer
= NULL
;
1316 void wxSimpleCheckBox::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1318 wxSize clientSize
= GetClientSize();
1319 wxAutoBufferedPaintDC
dc(this);
1322 wxRect
rect(0,0,clientSize
.x
,clientSize
.y
);
1326 wxColour bgcol
= GetBackgroundColour();
1327 dc
.SetBrush( bgcol
);
1329 dc
.DrawRectangle( rect
);
1331 wxColour txcol
= GetForegroundColour();
1333 int state
= m_state
;
1334 if ( !(state
& wxSCB_STATE_UNSPECIFIED
) &&
1335 GetFont().GetWeight() == wxBOLD
)
1336 state
|= wxSCB_STATE_BOLD
;
1338 DrawSimpleCheckBox(dc
,rect
,m_boxHeight
,state
,txcol
);
1341 void wxSimpleCheckBox::OnLeftClick( wxMouseEvent
& event
)
1343 if ( (event
.m_x
> (wxPG_XBEFORETEXT
-2)) &&
1344 (event
.m_x
<= (wxPG_XBEFORETEXT
-2+m_boxHeight
)) )
1346 SetValue(wxSCB_SETVALUE_CYCLE
);
1350 void wxSimpleCheckBox::OnKeyDown( wxKeyEvent
& event
)
1352 if ( event
.GetKeyCode() == WXK_SPACE
)
1354 SetValue(wxSCB_SETVALUE_CYCLE
);
1358 void wxSimpleCheckBox::SetValue( int value
)
1360 if ( value
== wxSCB_SETVALUE_CYCLE
)
1362 if ( m_state
& wxSCB_STATE_CHECKED
)
1363 m_state
&= ~wxSCB_STATE_CHECKED
;
1365 m_state
|= wxSCB_STATE_CHECKED
;
1373 wxCommandEvent
evt(wxEVT_COMMAND_CHECKBOX_CLICKED
,GetParent()->GetId());
1375 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent()->GetParent();
1376 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1377 propGrid
->HandleCustomEditorEvent(evt
);
1380 wxPGWindowList
wxPGCheckBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1381 wxPGProperty
* property
,
1383 const wxSize
& size
) const
1386 pt
.x
-= wxPG_XBEFOREWIDGET
;
1388 sz
.x
= propGrid
->GetFontHeight() + (wxPG_XBEFOREWIDGET
*2) + 4;
1390 wxSimpleCheckBox
* cb
= new wxSimpleCheckBox(propGrid
->GetPanel(),
1391 wxPG_SUBID1
, pt
, sz
);
1393 cb
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
1395 UpdateControl(property
, cb
);
1397 if ( !property
->IsValueUnspecified() )
1399 // If mouse cursor was on the item, toggle the value now.
1400 if ( propGrid
->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK
)
1402 wxPoint pt
= cb
->ScreenToClient(::wxGetMousePosition());
1403 if ( pt
.x
<= (wxPG_XBEFORETEXT
-2+cb
->m_boxHeight
) )
1405 if ( cb
->m_state
& wxSCB_STATE_CHECKED
)
1406 cb
->m_state
&= ~wxSCB_STATE_CHECKED
;
1408 cb
->m_state
|= wxSCB_STATE_CHECKED
;
1410 // Makes sure wxPG_EVT_CHANGING etc. is sent for this initial
1412 propGrid
->ChangePropertyValue(property
,
1413 wxPGVariant_Bool(cb
->m_state
));
1418 propGrid
->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR
);
1423 void wxPGCheckBoxEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
,
1424 wxPGProperty
* property
,
1425 const wxString
& WXUNUSED(text
) ) const
1427 int state
= wxSCB_STATE_UNCHECKED
;
1428 wxColour rectCol
= dc
.GetTextForeground();
1430 if ( !property
->IsValueUnspecified() )
1432 state
= property
->GetChoiceSelection();
1433 if ( dc
.GetFont().GetWeight() == wxBOLD
)
1434 state
|= wxSCB_STATE_BOLD
;
1438 state
|= wxSCB_STATE_UNSPECIFIED
;
1441 DrawSimpleCheckBox(dc
, rect
, dc
.GetCharHeight(), state
, rectCol
);
1444 void wxPGCheckBoxEditor::UpdateControl( wxPGProperty
* property
,
1445 wxWindow
* ctrl
) const
1447 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*) ctrl
;
1450 if ( !property
->IsValueUnspecified() )
1451 cb
->m_state
= property
->GetChoiceSelection();
1453 cb
->m_state
= wxSCB_STATE_UNSPECIFIED
;
1455 wxPropertyGrid
* propGrid
= property
->GetGrid();
1456 cb
->m_boxHeight
= propGrid
->GetFontHeight();
1461 bool wxPGCheckBoxEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propGrid
), wxPGProperty
* WXUNUSED(property
),
1462 wxWindow
* WXUNUSED(ctrl
), wxEvent
& event
) const
1464 if ( event
.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED
)
1472 bool wxPGCheckBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1474 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*)ctrl
;
1476 int index
= cb
->m_state
;
1478 if ( index
!= property
->GetChoiceSelection() ||
1479 // Changing unspecified always causes event (returning
1480 // true here should be enough to trigger it).
1481 property
->IsValueUnspecified()
1484 return property
->IntToValue(variant
, index
, 0);
1490 void wxPGCheckBoxEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1492 if ( value
!= 0 ) value
= 1;
1493 ((wxSimpleCheckBox
*)ctrl
)->m_state
= value
;
1498 void wxPGCheckBoxEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1500 ((wxSimpleCheckBox
*)ctrl
)->m_state
= 0;
1505 wxPGCheckBoxEditor::~wxPGCheckBoxEditor() { }
1508 #endif // wxPG_INCLUDE_CHECKBOX
1510 // -----------------------------------------------------------------------
1512 wxWindow
* wxPropertyGrid::GetEditorControl() const
1514 wxWindow
* ctrl
= m_wndEditor
;
1522 // -----------------------------------------------------------------------
1524 void wxPropertyGrid::CorrectEditorWidgetSizeX()
1527 int newSplitterx
= m_pState
->DoGetSplitterPosition(m_selColumn
-1);
1528 int newWidth
= newSplitterx
+ m_pState
->m_colWidths
[m_selColumn
];
1532 // if width change occurred, move secondary wnd by that amount
1533 wxRect r
= m_wndEditor2
->GetRect();
1535 r
.x
= newWidth
- secWid
;
1537 m_wndEditor2
->SetSize( r
);
1539 // if primary is textctrl, then we have to add some extra space
1543 if ( m_wndEditor
&& m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1545 secWid
+= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1550 wxRect r
= m_wndEditor
->GetRect();
1552 r
.x
= newSplitterx
+m_ctrlXAdjust
;
1554 if ( !(m_iFlags
& wxPG_FL_FIXED_WIDTH_EDITOR
) )
1555 r
.width
= newWidth
- r
.x
- secWid
;
1557 m_wndEditor
->SetSize(r
);
1561 m_wndEditor2
->Refresh();
1564 // -----------------------------------------------------------------------
1566 void wxPropertyGrid::CorrectEditorWidgetPosY()
1568 if ( GetSelection() && (m_wndEditor
|| m_wndEditor2
) )
1570 wxRect r
= GetEditorWidgetRect(GetSelection(), m_selColumn
);
1574 wxPoint pos
= m_wndEditor
->GetPosition();
1576 // Calculate y offset
1577 int offset
= pos
.y
% m_lineHeight
;
1579 m_wndEditor
->Move(pos
.x
, r
.y
+ offset
);
1584 wxPoint pos
= m_wndEditor2
->GetPosition();
1586 m_wndEditor2
->Move(pos
.x
, r
.y
);
1591 // -----------------------------------------------------------------------
1593 // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
1594 // fits into that category as well).
1595 void wxPropertyGrid::FixPosForTextCtrl( wxWindow
* ctrl
,
1596 unsigned int WXUNUSED(forColumn
),
1597 const wxPoint
& offset
)
1599 // Center the control vertically
1600 wxRect finalPos
= ctrl
->GetRect();
1601 int y_adj
= (m_lineHeight
- finalPos
.height
)/2 + wxPG_TEXTCTRLYADJUST
;
1603 // Prevent over-sized control
1604 int sz_dec
= (y_adj
+ finalPos
.height
) - m_lineHeight
;
1605 if ( sz_dec
< 0 ) sz_dec
= 0;
1607 finalPos
.y
+= y_adj
;
1608 finalPos
.height
-= (y_adj
+sz_dec
);
1610 #ifndef wxPG_TEXTCTRLXADJUST
1611 int textCtrlXAdjust
= wxPG_XBEFORETEXT
- 1;
1613 wxTextCtrl
* tc
= static_cast<wxTextCtrl
*>(ctrl
);
1616 int textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
;
1619 finalPos
.x
+= textCtrlXAdjust
;
1620 finalPos
.width
-= textCtrlXAdjust
;
1622 finalPos
.x
+= offset
.x
;
1623 finalPos
.y
+= offset
.y
;
1625 ctrl
->SetSize(finalPos
);
1628 // -----------------------------------------------------------------------
1630 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint
& pos
,
1632 const wxString
& value
,
1633 wxWindow
* secondary
,
1636 unsigned int forColumn
)
1638 wxWindowID id
= wxPG_SUBID1
;
1639 wxPGProperty
* prop
= GetSelection();
1642 int tcFlags
= wxTE_PROCESS_ENTER
| extraStyle
;
1644 if ( prop
->HasFlag(wxPG_PROP_READONLY
) && forColumn
== 1 )
1645 tcFlags
|= wxTE_READONLY
;
1647 wxPoint
p(pos
.x
,pos
.y
);
1648 wxSize
s(sz
.x
,sz
.y
);
1650 // Need to reduce width of text control on Mac
1651 #if defined(__WXMAC__)
1655 // For label editors, trim the size to allow better splitter grabbing
1656 if ( forColumn
!= 1 )
1659 // Take button into acccount
1662 s
.x
-= (secondary
->GetSize().x
+ wxPG_TEXTCTRL_AND_BUTTON_SPACING
);
1663 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
1666 // If the height is significantly higher, then use border, and fill the rect exactly.
1667 bool hasSpecialSize
= false;
1669 if ( (sz
.y
- m_lineHeight
) > 5 )
1670 hasSpecialSize
= true;
1672 wxWindow
* ctrlParent
= GetPanel();
1674 if ( !hasSpecialSize
)
1675 tcFlags
|= wxBORDER_NONE
;
1677 wxTextCtrl
* tc
= new wxTextCtrl();
1679 #if defined(__WXMSW__)
1682 SetupTextCtrlValue(value
);
1683 tc
->Create(ctrlParent
,id
,value
, p
, s
,tcFlags
);
1685 // Center the control vertically
1686 if ( !hasSpecialSize
)
1687 FixPosForTextCtrl(tc
, forColumn
);
1689 if ( forColumn
!= 1 )
1691 tc
->SetBackgroundColour(m_colSelBack
);
1692 tc
->SetForegroundColour(m_colSelFore
);
1701 // Set maximum length
1703 tc
->SetMaxLength( maxLen
);
1705 wxVariant attrVal
= prop
->GetAttribute(wxPG_ATTR_AUTOCOMPLETE
);
1706 if ( !attrVal
.IsNull() )
1708 wxASSERT(attrVal
.GetType() == wxS("arrstring"));
1709 tc
->AutoComplete(attrVal
.GetArrayString());
1715 // -----------------------------------------------------------------------
1717 wxWindow
* wxPropertyGrid::GenerateEditorButton( const wxPoint
& pos
, const wxSize
& sz
)
1719 wxWindowID id
= wxPG_SUBID2
;
1720 wxPGProperty
* selected
= GetSelection();
1724 // Decorations are chunky on Mac, and we can't make the button square, so
1725 // do things a bit differently on this platform.
1727 wxPoint
p(pos
.x
+sz
.x
,
1728 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1731 wxButton
* but
= new wxButton();
1732 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1734 // Now that we know the size, move to the correct position
1735 p
.x
= pos
.x
+ sz
.x
- but
->GetSize().x
- 2;
1739 wxSize
s(sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2),
1740 sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2));
1742 // Reduce button width to lineheight
1743 if ( s
.x
> m_lineHeight
)
1747 // On wxGTK, take fixed button margins into account
1752 wxPoint
p(pos
.x
+sz
.x
-s
.x
,
1753 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1755 wxButton
* but
= new wxButton();
1759 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1762 wxFont font
= GetFont();
1763 font
.SetPointSize(font
.GetPointSize()-2);
1766 but
->SetFont(GetFont());
1770 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1776 // -----------------------------------------------------------------------
1778 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrlAndButton( const wxPoint
& pos
,
1780 wxWindow
** psecondary
,
1782 wxPGProperty
* property
)
1784 wxButton
* but
= (wxButton
*)GenerateEditorButton(pos
,sz
);
1785 *psecondary
= (wxWindow
*)but
;
1787 if ( limitedEditing
)
1790 // There is button Show in GenerateEditorTextCtrl as well
1798 if ( !property
->IsValueUnspecified() )
1799 text
= property
->GetValueAsString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
1801 return GenerateEditorTextCtrl(pos
,sz
,text
,but
,property
->m_maxLen
);
1804 // -----------------------------------------------------------------------
1806 wxTextCtrl
* wxPropertyGrid::GetEditorTextCtrl() const
1808 wxWindow
* wnd
= GetEditorControl();
1813 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1814 return wxStaticCast(wnd
, wxTextCtrl
);
1816 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
1818 wxOwnerDrawnComboBox
* cb
= wxStaticCast(wnd
, wxOwnerDrawnComboBox
);
1819 return cb
->GetTextCtrl();
1825 // -----------------------------------------------------------------------
1827 wxPGEditor
* wxPropertyGridInterface::GetEditorByName( const wxString
& editorName
)
1829 wxPGHashMapS2P::const_iterator it
;
1831 it
= wxPGGlobalVars
->m_mapEditorClasses
.find(editorName
);
1832 if ( it
== wxPGGlobalVars
->m_mapEditorClasses
.end() )
1834 return (wxPGEditor
*) it
->second
;
1837 // -----------------------------------------------------------------------
1838 // wxPGEditorDialogAdapter
1839 // -----------------------------------------------------------------------
1841 IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter
, wxObject
)
1843 bool wxPGEditorDialogAdapter::ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
1845 if ( !propGrid
->EditorValidate() )
1848 bool res
= DoShowDialog( propGrid
, property
);
1852 propGrid
->ValueChangeInEvent( m_value
);
1859 // -----------------------------------------------------------------------
1861 // -----------------------------------------------------------------------
1863 wxPGMultiButton::wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
)
1864 : wxWindow( pg
->GetPanel(), wxPG_SUBID2
, wxPoint(-100,-100), wxSize(0, sz
.y
) ),
1865 m_fullEditorSize(sz
), m_buttonsWidth(0)
1867 SetBackgroundColour(pg
->GetCellBackgroundColour());
1870 void wxPGMultiButton::Finalize( wxPropertyGrid
* WXUNUSED(propGrid
),
1871 const wxPoint
& pos
)
1873 Move( pos
.x
+ m_fullEditorSize
.x
- m_buttonsWidth
, pos
.y
);
1876 int wxPGMultiButton::GenId( int id
) const
1880 if ( m_buttons
.size() )
1881 id
= GetButton(m_buttons
.size()-1)->GetId() + 1;
1889 void wxPGMultiButton::Add( const wxBitmap
& bitmap
, int id
)
1892 wxSize sz
= GetSize();
1893 wxButton
* button
= new wxBitmapButton( this, id
, bitmap
,
1895 wxSize(sz
.y
, sz
.y
) );
1896 DoAddButton( button
, sz
);
1900 void wxPGMultiButton::Add( const wxString
& label
, int id
)
1903 wxSize sz
= GetSize();
1904 wxButton
* button
= new wxButton( this, id
, label
, wxPoint(sz
.x
, 0),
1905 wxSize(sz
.y
, sz
.y
) );
1906 DoAddButton( button
, sz
);
1909 void wxPGMultiButton::DoAddButton( wxWindow
* button
,
1912 m_buttons
.push_back(button
);
1913 int bw
= button
->GetSize().x
;
1914 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
1915 m_buttonsWidth
+= bw
;
1918 // -----------------------------------------------------------------------
1920 #endif // wxUSE_PROPGRID