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"
81 #include "wx/msw/private.h"
84 // -----------------------------------------------------------------------
86 #if defined(__WXMSW__)
88 #define wxPG_NAT_BUTTON_BORDER_ANY 1
89 #define wxPG_NAT_BUTTON_BORDER_X 1
90 #define wxPG_NAT_BUTTON_BORDER_Y 1
92 #define wxPG_CHECKMARK_XADJ 1
93 #define wxPG_CHECKMARK_YADJ (-1)
94 #define wxPG_CHECKMARK_WADJ 0
95 #define wxPG_CHECKMARK_HADJ 0
96 #define wxPG_CHECKMARK_DEFLATE 0
98 #define wxPG_TEXTCTRLYADJUST (m_spacingy+0)
100 #elif defined(__WXGTK__)
102 #define wxPG_CHECKMARK_XADJ 0
103 #define wxPG_CHECKMARK_YADJ 0
104 #define wxPG_CHECKMARK_WADJ (-1)
105 #define wxPG_CHECKMARK_HADJ (-1)
106 #define wxPG_CHECKMARK_DEFLATE 3
108 #define wxPG_NAT_BUTTON_BORDER_ANY 1
109 #define wxPG_NAT_BUTTON_BORDER_X 1
110 #define wxPG_NAT_BUTTON_BORDER_Y 1
112 #define wxPG_TEXTCTRLYADJUST 0
114 #elif defined(__WXMAC__)
116 #define wxPG_CHECKMARK_XADJ 0
117 #define wxPG_CHECKMARK_YADJ 0
118 #define wxPG_CHECKMARK_WADJ 0
119 #define wxPG_CHECKMARK_HADJ 0
120 #define wxPG_CHECKMARK_DEFLATE 0
122 #define wxPG_NAT_BUTTON_BORDER_ANY 0
123 #define wxPG_NAT_BUTTON_BORDER_X 0
124 #define wxPG_NAT_BUTTON_BORDER_Y 0
126 #define wxPG_TEXTCTRLYADJUST 0
130 #define wxPG_CHECKMARK_XADJ 0
131 #define wxPG_CHECKMARK_YADJ 0
132 #define wxPG_CHECKMARK_WADJ 0
133 #define wxPG_CHECKMARK_HADJ 0
134 #define wxPG_CHECKMARK_DEFLATE 0
136 #define wxPG_NAT_BUTTON_BORDER_ANY 0
137 #define wxPG_NAT_BUTTON_BORDER_X 0
138 #define wxPG_NAT_BUTTON_BORDER_Y 0
140 #define wxPG_TEXTCTRLYADJUST 0
146 #define wxPG_CHOICEXADJUST -3 // required because wxComboCtrl reserves 3pixels for wxTextCtrl's focus ring
147 #define wxPG_CHOICEYADJUST -3
149 #define wxPG_CHOICEXADJUST 0
150 #define wxPG_CHOICEYADJUST 0
153 #define ODCB_CUST_PAINT_MARGIN 6 // Number added to image width for SetCustomPaintWidth
155 // Milliseconds to wait for two mouse-ups after focus inorder
156 // to trigger a double-click.
157 #define DOUBLE_CLICK_CONVERSION_TRESHOLD 500
159 // -----------------------------------------------------------------------
161 // -----------------------------------------------------------------------
163 IMPLEMENT_ABSTRACT_CLASS(wxPGEditor
, wxObject
)
166 wxPGEditor::~wxPGEditor()
170 wxString
wxPGEditor::GetName() const
172 return GetClassInfo()->GetClassName();
175 void wxPGEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
, wxPGProperty
* property
, const wxString
& text
) const
177 if ( !property
->IsValueUnspecified() )
178 dc
.DrawText( text
, 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() )
236 return (wxWindow
*) NULL
;
238 if ( !property
->IsValueUnspecified() )
239 text
= property
->GetValueAsString(property
->HasFlag(wxPG_PROP_READONLY
) ?
240 0 : wxPG_EDITABLE_VALUE
);
243 if ( (property
->GetFlags() & wxPG_PROP_PASSWORD
) &&
244 property
->IsKindOf(CLASSINFO(wxStringProperty
)) )
245 flags
|= wxTE_PASSWORD
;
247 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrl(pos
,sz
,text
,(wxWindow
*)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();
288 // Update font boldness
289 wxPropertyGrid
* pg
= property
->GetGrid();
290 if ( pg
->HasFlag(wxPG_BOLD_MODIFIED
) )
292 if ( property
->HasFlag(wxPG_PROP_MODIFIED
) )
293 tc
->SetFont(pg
->GetCaptionFont());
295 tc
->SetFont(pg
->GetFont());
297 #if defined(__WXMSW__) && !defined(__WXWINCE__)
298 ::SendMessage(GetHwndOf(tc
), EM_SETMARGINS
, EC_LEFTMARGIN
| EC_RIGHTMARGIN
, MAKELONG(0, 0));
303 // Provided so that, for example, ComboBox editor can use the same code
304 // (multiple inheritance would get way too messy).
305 bool wxPGTextCtrlEditor::OnTextCtrlEvent( wxPropertyGrid
* propGrid
,
306 wxPGProperty
* WXUNUSED(property
),
313 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
315 if ( propGrid
->IsEditorsValueModified() )
320 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
323 // Pass this event outside wxPropertyGrid so that,
324 // if necessary, program can tell when user is editing
326 // FIXME: Is it safe to change event id in the middle of event
327 // processing (seems to work, but...)?
329 event
.SetId(propGrid
->GetId());
331 propGrid
->EditorsValueWasModified();
337 bool wxPGTextCtrlEditor::OnEvent( wxPropertyGrid
* propGrid
,
338 wxPGProperty
* property
,
340 wxEvent
& event
) const
342 return wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,ctrl
,event
);
346 bool wxPGTextCtrlEditor::GetTextCtrlValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
)
348 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
349 wxString textVal
= tc
->GetValue();
351 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
357 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
359 // Changing unspecified always causes event (returning
360 // true here should be enough to trigger it).
361 // TODO: Move to propgrid.cpp
362 if ( !res
&& variant
.IsNull() )
369 bool wxPGTextCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
371 return wxPGTextCtrlEditor::GetTextCtrlValueFromControl(variant
, property
, ctrl
);
375 void wxPGTextCtrlEditor::SetValueToUnspecified( wxPGProperty
* property
, wxWindow
* ctrl
) const
377 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
379 wxPropertyGrid
* pg
= property
->GetGrid();
380 wxASSERT(pg
); // Really, property grid should exist if editor does
382 tc
->SetValue(wxEmptyString
);
386 void wxPGTextCtrlEditor::SetControlStringValue( wxPGProperty
* property
, wxWindow
* ctrl
, const wxString
& txt
) const
388 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
390 wxPropertyGrid
* pg
= property
->GetGrid();
391 wxASSERT(pg
); // Really, property grid should exist if editor does
397 void wxPGTextCtrlEditor::OnFocus( wxPGProperty
*, wxWindow
* wnd
) const
399 wxTextCtrl
* tc
= wxStaticCast(wnd
, wxTextCtrl
);
401 tc
->SetSelection(-1,-1);
405 wxPGTextCtrlEditor::~wxPGTextCtrlEditor() { }
408 // -----------------------------------------------------------------------
410 // -----------------------------------------------------------------------
413 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(Choice
,wxPGChoiceEditor
,wxPGEditor
)
416 // This is a special enhanced double-click processor class.
417 // In essence, it allows for double-clicks for which the
418 // first click "created" the control.
419 class wxPGDoubleClickProcessor
: public wxEvtHandler
423 wxPGDoubleClickProcessor( wxOwnerDrawnComboBox
* combo
, wxPGProperty
* property
)
426 m_timeLastMouseUp
= 0;
428 m_property
= property
;
429 m_downReceived
= false;
434 void OnMouseEvent( wxMouseEvent
& event
)
436 wxLongLong t
= ::wxGetLocalTimeMillis();
437 int evtType
= event
.GetEventType();
439 if ( m_property
->HasFlag(wxPG_PROP_USE_DCC
) &&
440 m_property
->IsKindOf(CLASSINFO(wxBoolProperty
)) &&
441 !m_combo
->IsPopupShown() )
443 // Just check that it is in the text area
444 wxPoint pt
= event
.GetPosition();
445 if ( m_combo
->GetTextRect().Contains(pt
) )
447 if ( evtType
== wxEVT_LEFT_DOWN
)
449 // Set value to avoid up-events without corresponding downs
450 m_downReceived
= true;
452 else if ( evtType
== wxEVT_LEFT_DCLICK
)
454 // We'll make our own double-clicks
455 event
.SetEventType(0);
458 else if ( evtType
== wxEVT_LEFT_UP
)
460 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
462 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
464 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
466 event
.SetEventType(wxEVT_LEFT_DCLICK
);
467 m_timeLastMouseUp
= 1;
471 m_timeLastMouseUp
= t
;
481 void OnSetFocus( wxFocusEvent
& event
)
483 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
488 wxLongLong m_timeLastMouseUp
;
489 wxOwnerDrawnComboBox
* m_combo
;
490 wxPGProperty
* m_property
; // Selected property
493 DECLARE_EVENT_TABLE()
496 BEGIN_EVENT_TABLE(wxPGDoubleClickProcessor
, wxEvtHandler
)
497 EVT_MOUSE_EVENTS(wxPGDoubleClickProcessor::OnMouseEvent
)
498 EVT_SET_FOCUS(wxPGDoubleClickProcessor::OnSetFocus
)
503 class wxPGComboBox
: public wxOwnerDrawnComboBox
508 : wxOwnerDrawnComboBox()
510 m_dclickProcessor
= (wxPGDoubleClickProcessor
*) NULL
;
511 m_sizeEventCalled
= false;
516 if ( m_dclickProcessor
)
518 RemoveEventHandler(m_dclickProcessor
);
519 delete m_dclickProcessor
;
523 bool Create(wxWindow
*parent
,
525 const wxString
& value
,
528 const wxArrayString
& choices
,
530 const wxValidator
& validator
= wxDefaultValidator
,
531 const wxString
& name
= wxS("wxOwnerDrawnComboBox"))
533 if ( !wxOwnerDrawnComboBox::Create( parent
,
544 m_dclickProcessor
= new
545 wxPGDoubleClickProcessor( this, GetGrid()->GetSelection() );
547 PushEventHandler(m_dclickProcessor
);
552 virtual void OnDrawItem( wxDC
& dc
,
557 wxPropertyGrid
* pg
= GetGrid();
558 pg
->OnComboItemPaint( this, item
, &dc
, (wxRect
&)rect
, flags
);
561 virtual wxCoord
OnMeasureItem( size_t item
) const
563 wxPropertyGrid
* pg
= GetGrid();
567 pg
->OnComboItemPaint( this, item
, NULL
, rect
, 0 );
571 wxPropertyGrid
* GetGrid() const
573 wxPropertyGrid
* pg
= wxDynamicCast(GetParent()->GetParent(),
579 virtual wxCoord
OnMeasureItemWidth( size_t item
) const
581 wxPropertyGrid
* pg
= GetGrid();
585 pg
->OnComboItemPaint( this, item
, NULL
, rect
, 0 );
589 virtual void PositionTextCtrl( int WXUNUSED(textCtrlXAdjust
),
590 int WXUNUSED(textCtrlYAdjust
) )
592 wxPropertyGrid
* pg
= GetGrid();
593 wxOwnerDrawnComboBox::PositionTextCtrl(
594 wxPG_TEXTCTRLXADJUST
-
595 (wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1) - 1,
596 pg
->GetSpacingY() + 2
601 wxPGDoubleClickProcessor
* m_dclickProcessor
;
602 bool m_sizeEventCalled
;
606 void wxPropertyGrid::OnComboItemPaint( const wxPGComboBox
* pCb
,
613 wxASSERT( IsKindOf(CLASSINFO(wxPropertyGrid
)) );
615 wxPGProperty
* p
= m_selected
;
618 const wxPGChoices
& choices
= p
->GetChoices();
619 const wxPGCommonValue
* comVal
= NULL
;
620 int comVals
= p
->GetDisplayedCommonValueCount();
621 int comValIndex
= -1;
624 if ( choices
.IsOk() )
625 choiceCount
= choices
.GetCount();
627 if ( item
>= choiceCount
&& comVals
> 0 )
629 comValIndex
= item
- choiceCount
;
630 comVal
= GetCommonValue(comValIndex
);
631 if ( !p
->IsValueUnspecified() )
632 text
= comVal
->GetLabel();
636 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
638 text
= pCb
->GetString(item
);
642 if ( !p
->IsValueUnspecified() )
643 text
= p
->GetValueAsString(0);
652 const wxBitmap
* itemBitmap
= NULL
;
654 if ( item
>= 0 && choices
.IsOk() && choices
.Item(item
).GetBitmap().Ok() && comValIndex
== -1 )
655 itemBitmap
= &choices
.Item(item
).GetBitmap();
658 // Decide what custom image size to use
661 cis
.x
= itemBitmap
->GetWidth();
662 cis
.y
= itemBitmap
->GetHeight();
666 cis
= GetImageSize(p
, item
);
671 // Default measure behaviour (no flexible, custom paint image only)
672 if ( rect
.width
< 0 )
675 GetTextExtent(text
, &x
, &y
, 0, 0, &m_font
);
676 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9 + x
;
679 rect
.height
= cis
.y
+ 2;
683 wxPGPaintData paintdata
;
684 paintdata
.m_parent
= NULL
;
685 paintdata
.m_choiceItem
= item
;
687 // This is by the current (1.0.0b) spec - if painting control, item is -1
688 if ( (flags
& wxODCB_PAINTING_CONTROL
) )
689 paintdata
.m_choiceItem
= -1;
692 pDc
->SetBrush(*wxWHITE_BRUSH
);
700 wxPoint
pt(rect
.x
+ wxPG_CONTROL_MARGIN
- wxPG_CHOICEXADJUST
- 1,
703 int renderFlags
= wxPGCellRenderer::DontUseCellColours
;
705 if ( flags
& wxODCB_PAINTING_CONTROL
)
706 renderFlags
|= wxPGCellRenderer::Control
;
708 renderFlags
|= wxPGCellRenderer::ChoicePopup
;
710 if ( flags
& wxODCB_PAINTING_SELECTED
)
711 renderFlags
|= wxPGCellRenderer::Selected
;
713 if ( cis
.x
> 0 && (p
->HasFlag(wxPG_PROP_CUSTOMIMAGE
) || !(flags
& wxODCB_PAINTING_CONTROL
)) &&
714 ( !p
->m_valueBitmap
|| item
== pCb
->GetSelection() ) &&
715 ( item
>= 0 || (flags
& wxODCB_PAINTING_CONTROL
) ) &&
719 pt
.x
+= wxCC_CUSTOM_IMAGE_MARGIN1
;
720 wxRect
r(pt
.x
,pt
.y
,cis
.x
,cis
.y
);
722 if ( flags
& wxODCB_PAINTING_CONTROL
)
725 r
.height
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
728 paintdata
.m_drawnWidth
= r
.width
;
730 dc
.SetPen(m_colPropFore
);
731 if ( comValIndex
>= 0 )
733 const wxPGCommonValue
* cv
= GetCommonValue(comValIndex
);
734 wxPGCellRenderer
* renderer
= cv
->GetRenderer();
735 r
.width
= rect
.width
;
736 renderer
->Render( dc
, r
, this, p
, m_selColumn
, comValIndex
, renderFlags
);
739 else if ( item
>= 0 )
741 p
->OnCustomPaint( dc
, r
, paintdata
);
745 dc
.DrawRectangle( r
);
748 pt
.x
+= paintdata
.m_drawnWidth
+ wxCC_CUSTOM_IMAGE_MARGIN2
- 1;
752 // TODO: This aligns text so that it seems to be horizontally
753 // on the same line as property values. Not really
754 // sure if its needed, but seems to not cause any harm.
757 if ( item
< 0 && (flags
& wxODCB_PAINTING_CONTROL
) )
758 item
= pCb
->GetSelection();
760 if ( choices
.IsOk() && item
>= 0 && comValIndex
< 0 )
762 const wxPGChoiceEntry
& cell
= choices
.Item(item
);
763 wxPGCellRenderer
* renderer
= wxPGGlobalVars
->m_defaultRenderer
;
764 int imageOffset
= renderer
->PreDrawCell( dc
, rect
, cell
, renderFlags
);
766 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
775 pt
.y
+= (rect
.height
-m_fontHeight
)/2 - 1;
779 dc
.DrawText( text
, pt
.x
+ wxPG_XBEFORETEXT
, pt
.y
);
787 p
->OnCustomPaint( dc
, rect
, paintdata
);
788 rect
.height
= paintdata
.m_drawnHeight
+ 2;
789 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9;
793 bool wxPGChoiceEditor_SetCustomPaintWidth( wxPropertyGrid
* propGrid
, wxPGComboBox
* cb
, int cmnVal
)
795 wxPGProperty
* property
= propGrid
->GetSelectedProperty();
796 wxASSERT( property
);
800 // Yes, a common value is being selected
801 property
->SetCommonValue( cmnVal
);
802 wxSize imageSize
= propGrid
->GetCommonValue(cmnVal
)->
803 GetRenderer()->GetImageSize(property
, 1, cmnVal
);
804 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
805 cb
->SetCustomPaintWidth( imageSize
.x
);
810 wxSize imageSize
= propGrid
->GetImageSize(property
, -1);
811 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
812 cb
->SetCustomPaintWidth( imageSize
.x
);
817 // CreateControls calls this with CB_READONLY in extraStyle
818 wxWindow
* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid
* propGrid
,
819 wxPGProperty
* property
,
822 long extraStyle
) const
824 const wxPGChoices
& choices
= property
->GetChoices();
826 int index
= property
->GetChoiceSelection();
828 bool isUnspecified
= property
->IsValueUnspecified();
830 if ( !isUnspecified
)
831 defString
= property
->GetDisplayedString();
833 wxArrayString labels
= choices
.GetLabels();
839 po
.y
+= wxPG_CHOICEYADJUST
;
840 si
.y
-= (wxPG_CHOICEYADJUST
*2);
842 po
.x
+= wxPG_CHOICEXADJUST
;
843 si
.x
-= wxPG_CHOICEXADJUST
;
844 wxWindow
* ctrlParent
= propGrid
->GetPanel();
846 int odcbFlags
= extraStyle
| wxBORDER_NONE
| wxTE_PROCESS_ENTER
;
849 // If common value specified, use appropriate index
850 unsigned int cmnVals
= property
->GetDisplayedCommonValueCount();
853 if ( !isUnspecified
)
855 int cmnVal
= property
->GetCommonValue();
858 index
= labels
.size() + cmnVal
;
863 for ( i
=0; i
<cmnVals
; i
++ )
864 labels
.Add(propGrid
->GetCommonValueLabel(i
));
867 cb
= new wxPGComboBox();
871 cb
->Create(ctrlParent
,
879 cb
->SetButtonPosition(si
.y
,0,wxRIGHT
);
880 cb
->SetTextIndent(wxPG_XBEFORETEXT
-1);
882 wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, property
->GetCommonValue() );
884 if ( index
>= 0 && index
< (int)cb
->GetCount() )
886 cb
->SetSelection( index
);
887 if ( defString
.length() )
888 cb
->SetText( defString
);
890 else if ( !(extraStyle
& wxCB_READONLY
) && defString
.length() )
891 cb
->SetValue( defString
);
893 cb
->SetSelection( -1 );
899 return (wxWindow
*) cb
;
903 void wxPGChoiceEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
906 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
907 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
908 int ind
= property
->GetChoiceSelection();
909 cb
->SetSelection(ind
);
912 wxPGWindowList
wxPGChoiceEditor::CreateControls( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
913 const wxPoint
& pos
, const wxSize
& sz
) const
915 return CreateControlsBase(propGrid
,property
,pos
,sz
,wxCB_READONLY
);
919 int wxPGChoiceEditor::InsertItem( wxWindow
* ctrl
, const wxString
& label
, int index
) const
922 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
923 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
926 index
= cb
->GetCount();
928 return cb
->Insert(label
,index
);
932 void wxPGChoiceEditor::DeleteItem( wxWindow
* ctrl
, int index
) const
935 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
936 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
941 bool wxPGChoiceEditor::OnEvent( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
942 wxWindow
* ctrl
, wxEvent
& event
) const
944 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
946 wxPGComboBox
* cb
= (wxPGComboBox
*)ctrl
;
947 int index
= cb
->GetSelection();
948 int cmnValIndex
= -1;
949 int cmnVals
= property
->GetDisplayedCommonValueCount();
950 int items
= cb
->GetCount();
952 if ( index
>= (items
-cmnVals
) )
954 // Yes, a common value is being selected
955 cmnValIndex
= index
- (items
-cmnVals
);
956 property
->SetCommonValue( cmnValIndex
);
958 // Truly set value to unspecified?
959 if ( propGrid
->GetUnspecifiedCommonValue() == cmnValIndex
)
961 if ( !property
->IsValueUnspecified() )
962 propGrid
->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT
);
963 property
->SetValueToUnspecified();
964 if ( !cb
->HasFlag(wxCB_READONLY
) )
965 cb
->GetTextCtrl()->SetValue(wxEmptyString
);
969 return wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, cmnValIndex
);
975 bool wxPGChoiceEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
977 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
979 int index
= cb
->GetSelection();
981 if ( index
!= property
->GetChoiceSelection() ||
982 // Changing unspecified always causes event (returning
983 // true here should be enough to trigger it).
984 property
->IsValueUnspecified()
987 return property
->IntToValue( variant
, index
, 0 );
993 void wxPGChoiceEditor::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, const wxString
& txt
) const
995 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1001 void wxPGChoiceEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1003 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1005 cb
->SetSelection(value
);
1009 void wxPGChoiceEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1011 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1012 cb
->SetSelection(-1);
1016 bool wxPGChoiceEditor::CanContainCustomImage() const
1022 wxPGChoiceEditor::~wxPGChoiceEditor() { }
1025 // -----------------------------------------------------------------------
1026 // wxPGComboBoxEditor
1027 // -----------------------------------------------------------------------
1030 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ComboBox
,
1035 void wxPGComboBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1037 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1038 cb
->SetValue(property
->GetValueAsString(wxPG_EDITABLE_VALUE
));
1040 // TODO: If string matches any selection, then select that.
1044 wxPGWindowList
wxPGComboBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1045 wxPGProperty
* property
,
1047 const wxSize
& sz
) const
1049 return CreateControlsBase(propGrid
,property
,pos
,sz
,0);
1053 bool wxPGComboBoxEditor::OnEvent( wxPropertyGrid
* propGrid
,
1054 wxPGProperty
* property
,
1056 wxEvent
& event
) const
1058 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*) NULL
;
1059 wxWindow
* textCtrl
= (wxWindow
*) NULL
;
1063 cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1064 textCtrl
= cb
->GetTextCtrl();
1067 if ( wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,textCtrl
,event
) )
1070 return wxPGChoiceEditor::OnEvent(propGrid
,property
,ctrl
,event
);
1074 bool wxPGComboBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1076 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1077 wxString textVal
= cb
->GetValue();
1079 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
1085 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
1087 // Changing unspecified always causes event (returning
1088 // true here should be enough to trigger it).
1089 if ( !res
&& variant
.IsNull() )
1096 void wxPGComboBoxEditor::OnFocus( wxPGProperty
*, wxWindow
* ctrl
) const
1098 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1099 cb
->GetTextCtrl()->SetSelection(-1,-1);
1103 wxPGComboBoxEditor::~wxPGComboBoxEditor() { }
1106 // -----------------------------------------------------------------------
1107 // wxPGChoiceAndButtonEditor
1108 // -----------------------------------------------------------------------
1111 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ChoiceAndButton
,
1112 wxPGChoiceAndButtonEditor
,
1116 wxPGWindowList
wxPGChoiceAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1117 wxPGProperty
* property
,
1119 const wxSize
& sz
) const
1121 // Use one two units smaller to match size of the combo's dropbutton.
1122 // (normally a bigger button is used because it looks better)
1125 wxSize
bt_sz(bt_wid
,bt_wid
);
1127 // Position of button.
1128 wxPoint
bt_pos(pos
.x
+sz
.x
-bt_sz
.x
,pos
.y
);
1135 wxWindow
* bt
= propGrid
->GenerateEditorButton( bt_pos
, bt_sz
);
1138 wxSize
ch_sz(sz
.x
-bt
->GetSize().x
,sz
.y
);
1141 ch_sz
.x
-= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1144 wxWindow
* ch
= wxPGEditor_Choice
->CreateControls(propGrid
,property
,
1145 pos
,ch_sz
).m_primary
;
1151 return wxPGWindowList(ch
, bt
);
1155 wxPGChoiceAndButtonEditor::~wxPGChoiceAndButtonEditor() { }
1158 // -----------------------------------------------------------------------
1159 // wxPGTextCtrlAndButtonEditor
1160 // -----------------------------------------------------------------------
1162 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrlAndButton
,
1163 wxPGTextCtrlAndButtonEditor
,
1167 wxPGWindowList
wxPGTextCtrlAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1168 wxPGProperty
* property
,
1170 const wxSize
& sz
) const
1173 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrlAndButton( pos
, sz
, &wnd2
,
1174 property
->GetFlags() & wxPG_PROP_NOEDITOR
, property
);
1176 return wxPGWindowList(wnd
, wnd2
);
1180 wxPGTextCtrlAndButtonEditor::~wxPGTextCtrlAndButtonEditor() { }
1183 // -----------------------------------------------------------------------
1184 // wxPGCheckBoxEditor
1185 // -----------------------------------------------------------------------
1187 #if wxPG_INCLUDE_CHECKBOX
1189 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(CheckBox
,
1194 // state argument: 0x01 = set if checked
1195 // 0x02 = set if rectangle should be bold
1196 static void DrawSimpleCheckBox( wxDC
& dc
, const wxRect
& rect
, int box_hei
, int state
, const wxColour
& linecol
)
1200 wxRect
r(rect
.x
+wxPG_XBEFORETEXT
,rect
.y
+((rect
.height
-box_hei
)/2),box_hei
,box_hei
);
1202 // Draw check mark first because it is likely to overdraw the
1203 // surrounding rectangle.
1206 wxRect
r2(r
.x
+wxPG_CHECKMARK_XADJ
,
1207 r
.y
+wxPG_CHECKMARK_YADJ
,
1208 r
.width
+wxPG_CHECKMARK_WADJ
,
1209 r
.height
+wxPG_CHECKMARK_HADJ
);
1210 #if wxPG_CHECKMARK_DEFLATE
1211 r2
.Deflate(wxPG_CHECKMARK_DEFLATE
);
1213 dc
.DrawCheckMark(r2
);
1215 // This would draw a simple cross check mark.
1216 // dc.DrawLine(r.x,r.y,r.x+r.width-1,r.y+r.height-1);
1217 // dc.DrawLine(r.x,r.y+r.height-1,r.x+r.width-1,r.y);
1223 // Pen for thin rectangle.
1228 // Pen for bold rectangle.
1229 wxPen
linepen(linecol
,2,wxSOLID
);
1230 linepen
.SetJoin(wxJOIN_MITER
); // This prevents round edges.
1238 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1240 dc
.DrawRectangle(r
);
1241 dc
.SetPen(*wxTRANSPARENT_PEN
);
1245 // Real simple custom-drawn checkbox-without-label class.
1247 class wxSimpleCheckBox
: public wxControl
1251 void SetValue( int value
);
1253 wxSimpleCheckBox( wxWindow
* parent
,
1255 const wxPoint
& pos
= wxDefaultPosition
,
1256 const wxSize
& size
= wxDefaultSize
)
1257 : wxControl(parent
,id
,pos
,size
,wxBORDER_NONE
|wxWANTS_CHARS
)
1259 // Due to SetOwnFont stuff necessary for GTK+ 1.2, we need to have this
1260 SetFont( parent
->GetFont() );
1263 wxPropertyGrid
* pg
= (wxPropertyGrid
*) parent
->GetParent();
1264 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1265 m_boxHeight
= pg
->GetFontHeight();
1266 SetBackgroundStyle( wxBG_STYLE_COLOUR
);
1269 virtual ~wxSimpleCheckBox();
1271 virtual bool ProcessEvent(wxEvent
& event
);
1276 static wxBitmap
* ms_doubleBuffer
;
1280 wxSimpleCheckBox::~wxSimpleCheckBox()
1282 delete ms_doubleBuffer
;
1283 ms_doubleBuffer
= NULL
;
1287 wxBitmap
* wxSimpleCheckBox::ms_doubleBuffer
= (wxBitmap
*) NULL
;
1289 // value = 2 means toggle (sorry, too lazy to do constants)
1290 void wxSimpleCheckBox::SetValue( int value
)
1295 if ( m_state
> 1 ) m_state
= 0;
1303 wxCommandEvent
evt(wxEVT_COMMAND_CHECKBOX_CLICKED
,GetParent()->GetId());
1305 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent()->GetParent();
1306 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1307 propGrid
->HandleCustomEditorEvent(evt
);
1311 bool wxSimpleCheckBox::ProcessEvent(wxEvent
& event
)
1313 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent()->GetParent();
1314 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1316 if ( ( (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1317 && ((wxMouseEvent
&)event
).m_x
> (wxPG_XBEFORETEXT
-2)
1318 && ((wxMouseEvent
&)event
).m_x
<= (wxPG_XBEFORETEXT
-2+m_boxHeight
) )
1324 else if ( event
.GetEventType() == wxEVT_PAINT
)
1326 wxSize clientSize
= GetClientSize();
1330 // Buffered paint DC doesn't seem to do much good
1331 if ( !ms_doubleBuffer ||
1332 clientSize.x > ms_doubleBuffer->GetWidth() ||
1333 clientSize.y > ms_doubleBuffer->GetHeight() )
1335 delete ms_doubleBuffer;
1336 ms_doubleBuffer = new wxBitmap(clientSize.x+25,clientSize.y+25);
1339 wxBufferedPaintDC dc(this,*ms_doubleBuffer);
1342 wxRect
rect(0,0,clientSize
.x
,clientSize
.y
);
1347 m_boxHeight
= propGrid
->GetFontHeight();
1349 wxColour bgcol
= GetBackgroundColour();
1350 dc
.SetBrush( bgcol
);
1352 dc
.DrawRectangle( rect
);
1354 wxColour txcol
= GetForegroundColour();
1356 int state
= m_state
;
1357 if ( m_font
.GetWeight() == wxBOLD
)
1360 DrawSimpleCheckBox(dc
,rect
,m_boxHeight
,state
,txcol
);
1362 // If focused, indicate it somehow.
1364 if ( wxWindow::FindFocus() == this )
1369 wxPGDrawFocusRect(dc,rect);
1375 else if ( event
.GetEventType() == wxEVT_SIZE
||
1376 event
.GetEventType() == wxEVT_SET_FOCUS
||
1377 event
.GetEventType() == wxEVT_KILL_FOCUS
1382 else if ( event
.GetEventType() == wxEVT_KEY_DOWN
)
1384 wxKeyEvent
& keyEv
= (wxKeyEvent
&) event
;
1386 if ( keyEv
.GetKeyCode() == WXK_SPACE
)
1392 return wxControl::ProcessEvent(event
);
1396 wxPGWindowList
wxPGCheckBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1397 wxPGProperty
* property
,
1399 const wxSize
& size
) const
1402 pt
.x
-= wxPG_XBEFOREWIDGET
;
1404 sz
.x
= propGrid
->GetFontHeight() + (wxPG_XBEFOREWIDGET
*2) + 4;
1406 wxSimpleCheckBox
* cb
= new wxSimpleCheckBox(propGrid
->GetPanel(),wxPG_SUBID1
,pt
,sz
);
1408 cb
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
1410 if ( property
->GetChoiceSelection() > 0 &&
1411 !property
->IsValueUnspecified() )
1414 // If mouse cursor was on the item, toggle the value now.
1415 if ( propGrid
->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK
)
1417 wxPoint pt
= cb
->ScreenToClient(::wxGetMousePosition());
1418 if ( pt
.x
<= (wxPG_XBEFORETEXT
-2+cb
->m_boxHeight
) )
1422 if ( cb
->m_state
> 1 )
1425 // Makes sure wxPG_EVT_CHANGING etc. is sent for this initial click
1426 propGrid
->ChangePropertyValue(property
, wxPGVariant_Bool(cb
->m_state
));
1430 propGrid
->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR
);
1436 class wxPGCheckBoxRenderer : public wxPGDefaultRenderer
1440 virtual void Render( wxDC& dc, const wxRect& rect,
1441 const wxPropertyGrid* WXUNUSED(propertyGrid), wxPGProperty* property,
1442 int WXUNUSED(column), int WXUNUSED(item), int WXUNUSED(flags) ) const
1445 if ( !(property->GetFlags() & wxPG_PROP_UNSPECIFIED) )
1447 state = ((wxPGProperty*)property)->GetChoiceInfo((wxPGChoiceInfo*)NULL);
1448 if ( dc.GetFont().GetWeight() == wxBOLD ) state |= 2;
1450 DrawSimpleCheckBox(dc,rect,dc.GetCharHeight(),state,dc.GetTextForeground());
1456 wxPGCheckBoxRenderer g_wxPGCheckBoxRenderer;
1458 wxPGCellRenderer* wxPGCheckBoxEditor::GetCellRenderer() const
1460 return &g_wxPGCheckBoxRenderer;
1464 void wxPGCheckBoxEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
, wxPGProperty
* property
, const wxString
& WXUNUSED(text
) ) const
1467 if ( !property
->IsValueUnspecified() )
1469 state
= property
->GetChoiceSelection();
1470 if ( dc
.GetFont().GetWeight() == wxBOLD
) state
|= 2;
1472 DrawSimpleCheckBox(dc
,rect
,dc
.GetCharHeight(),state
,dc
.GetTextForeground());
1475 void wxPGCheckBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1478 ((wxSimpleCheckBox
*)ctrl
)->m_state
= property
->GetChoiceSelection();
1483 bool wxPGCheckBoxEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propGrid
), wxPGProperty
* WXUNUSED(property
),
1484 wxWindow
* WXUNUSED(ctrl
), wxEvent
& event
) const
1486 if ( event
.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED
)
1494 bool wxPGCheckBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1496 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*)ctrl
;
1498 int index
= cb
->m_state
;
1500 if ( index
!= property
->GetChoiceSelection() ||
1501 // Changing unspecified always causes event (returning
1502 // true here should be enough to trigger it).
1503 property
->IsValueUnspecified()
1506 return property
->IntToValue(variant
, index
, 0);
1512 void wxPGCheckBoxEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1514 if ( value
!= 0 ) value
= 1;
1515 ((wxSimpleCheckBox
*)ctrl
)->m_state
= value
;
1520 void wxPGCheckBoxEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1522 ((wxSimpleCheckBox
*)ctrl
)->m_state
= 0;
1527 wxPGCheckBoxEditor::~wxPGCheckBoxEditor() { }
1530 #endif // wxPG_INCLUDE_CHECKBOX
1532 // -----------------------------------------------------------------------
1534 wxWindow
* wxPropertyGrid::GetEditorControl() const
1536 wxWindow
* ctrl
= m_wndEditor
;
1544 // -----------------------------------------------------------------------
1546 void wxPropertyGrid::CorrectEditorWidgetSizeX()
1548 if ( m_selColumn
== -1 )
1552 int newSplitterx
= m_pState
->DoGetSplitterPosition(m_selColumn
-1);
1553 int newWidth
= newSplitterx
+ m_pState
->m_colWidths
[m_selColumn
];
1557 // if width change occurred, move secondary wnd by that amount
1558 wxRect r
= m_wndEditor2
->GetRect();
1560 r
.x
= newWidth
- secWid
;
1562 m_wndEditor2
->SetSize( r
);
1564 // if primary is textctrl, then we have to add some extra space
1568 if ( m_wndEditor
&& m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1570 secWid
+= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1575 wxRect r
= m_wndEditor
->GetRect();
1577 r
.x
= newSplitterx
+m_ctrlXAdjust
;
1579 if ( !(m_iFlags
& wxPG_FL_FIXED_WIDTH_EDITOR
) )
1580 r
.width
= newWidth
- r
.x
- secWid
;
1582 m_wndEditor
->SetSize(r
);
1586 m_wndEditor2
->Refresh();
1589 // -----------------------------------------------------------------------
1591 void wxPropertyGrid::CorrectEditorWidgetPosY()
1593 if ( m_selColumn
== -1 )
1596 if ( m_selected
&& (m_wndEditor
|| m_wndEditor2
) )
1598 wxRect r
= GetEditorWidgetRect(m_selected
, m_selColumn
);
1602 wxPoint pos
= m_wndEditor
->GetPosition();
1604 // Calculate y offset
1605 int offset
= pos
.y
% m_lineHeight
;
1607 m_wndEditor
->Move(pos
.x
, r
.y
+ offset
);
1612 wxPoint pos
= m_wndEditor2
->GetPosition();
1614 m_wndEditor2
->Move(pos
.x
, r
.y
);
1619 // -----------------------------------------------------------------------
1621 // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
1622 // fits into that category as well).
1623 void wxPropertyGrid::FixPosForTextCtrl( wxWindow
* ctrl
, const wxPoint
& offset
)
1625 // Center the control vertically
1626 wxRect finalPos
= ctrl
->GetRect();
1627 int y_adj
= (m_lineHeight
- finalPos
.height
)/2 + wxPG_TEXTCTRLYADJUST
;
1629 // Prevent over-sized control
1630 int sz_dec
= (y_adj
+ finalPos
.height
) - m_lineHeight
;
1631 if ( sz_dec
< 0 ) sz_dec
= 0;
1633 finalPos
.y
+= y_adj
;
1634 finalPos
.height
-= (y_adj
+sz_dec
);
1636 const int textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
;
1638 finalPos
.x
+= textCtrlXAdjust
;
1639 finalPos
.width
-= textCtrlXAdjust
;
1641 finalPos
.x
+= offset
.x
;
1642 finalPos
.y
+= offset
.y
;
1644 ctrl
->SetSize(finalPos
);
1647 // -----------------------------------------------------------------------
1649 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint
& pos
,
1651 const wxString
& value
,
1652 wxWindow
* secondary
,
1656 wxWindowID id
= wxPG_SUBID1
;
1657 wxPGProperty
* selected
= m_selected
;
1660 int tcFlags
= wxTE_PROCESS_ENTER
| extraStyle
;
1662 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1663 tcFlags
|= wxTE_READONLY
;
1665 wxPoint
p(pos
.x
,pos
.y
);
1666 wxSize
s(sz
.x
,sz
.y
);
1668 // Need to reduce width of text control on Mac
1669 #if defined(__WXMAC__)
1673 // Take button into acccount
1676 s
.x
-= (secondary
->GetSize().x
+ wxPG_TEXTCTRL_AND_BUTTON_SPACING
);
1677 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
1680 // If the height is significantly higher, then use border, and fill the rect exactly.
1681 bool hasSpecialSize
= false;
1683 if ( (sz
.y
- m_lineHeight
) > 5 )
1684 hasSpecialSize
= true;
1686 wxWindow
* ctrlParent
= GetPanel();
1688 if ( !hasSpecialSize
)
1689 tcFlags
|= wxBORDER_NONE
;
1691 wxTextCtrl
* tc
= new wxTextCtrl();
1693 #if defined(__WXMSW__)
1696 SetupTextCtrlValue(value
);
1697 tc
->Create(ctrlParent
,id
,value
, p
, s
,tcFlags
);
1701 // Center the control vertically
1702 if ( !hasSpecialSize
)
1703 FixPosForTextCtrl(ed
);
1711 // Set maximum length
1713 tc
->SetMaxLength( maxLen
);
1715 return (wxWindow
*) ed
;
1718 // -----------------------------------------------------------------------
1720 wxWindow
* wxPropertyGrid::GenerateEditorButton( const wxPoint
& pos
, const wxSize
& sz
)
1722 wxWindowID id
= wxPG_SUBID2
;
1723 wxPGProperty
* selected
= m_selected
;
1727 // Decorations are chunky on Mac, and we can't make the button square, so
1728 // do things a bit differently on this platform.
1730 wxPoint
p(pos
.x
+sz
.x
,
1731 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1734 wxButton
* but
= new wxButton();
1735 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1737 // Now that we know the size, move to the correct position
1738 p
.x
= pos
.x
+ sz
.x
- but
->GetSize().x
- 2;
1742 wxSize
s(sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2),
1743 sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2));
1745 // Reduce button width to lineheight
1746 if ( s
.x
> m_lineHeight
)
1750 // On wxGTK, take fixed button margins into account
1755 wxPoint
p(pos
.x
+sz
.x
-s
.x
,
1756 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1758 wxButton
* but
= new wxButton();
1762 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1765 wxFont font
= GetFont();
1766 font
.SetPointSize(font
.GetPointSize()-2);
1769 but
->SetFont(GetFont());
1773 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1779 // -----------------------------------------------------------------------
1781 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrlAndButton( const wxPoint
& pos
,
1783 wxWindow
** psecondary
,
1785 wxPGProperty
* property
)
1787 wxButton
* but
= (wxButton
*)GenerateEditorButton(pos
,sz
);
1788 *psecondary
= (wxWindow
*)but
;
1790 if ( limitedEditing
)
1793 // There is button Show in GenerateEditorTextCtrl as well
1796 return (wxWindow
*) NULL
;
1801 if ( !property
->IsValueUnspecified() )
1802 text
= property
->GetValueAsString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
1804 return GenerateEditorTextCtrl(pos
,sz
,text
,but
,property
->m_maxLen
);
1807 // -----------------------------------------------------------------------
1809 wxTextCtrl
* wxPropertyGrid::GetEditorTextCtrl() const
1811 wxWindow
* wnd
= GetEditorControl();
1816 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1817 return wxStaticCast(wnd
, wxTextCtrl
);
1819 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
1821 wxOwnerDrawnComboBox
* cb
= wxStaticCast(wnd
, wxOwnerDrawnComboBox
);
1822 return cb
->GetTextCtrl();
1828 // -----------------------------------------------------------------------
1830 wxPGEditor
* wxPropertyGridInterface::GetEditorByName( const wxString
& editorName
)
1832 wxPGHashMapS2P::const_iterator it
;
1834 it
= wxPGGlobalVars
->m_mapEditorClasses
.find(editorName
);
1835 if ( it
== wxPGGlobalVars
->m_mapEditorClasses
.end() )
1837 return (wxPGEditor
*) it
->second
;
1840 // -----------------------------------------------------------------------
1841 // wxPGEditorDialogAdapter
1842 // -----------------------------------------------------------------------
1844 IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter
, wxObject
)
1846 bool wxPGEditorDialogAdapter::ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
1848 if ( !propGrid
->EditorValidate() )
1851 bool res
= DoShowDialog( propGrid
, property
);
1855 propGrid
->ValueChangeInEvent( m_value
);
1862 // -----------------------------------------------------------------------
1864 // -----------------------------------------------------------------------
1866 wxPGMultiButton::wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
)
1867 : wxWindow( pg
->GetPanel(), wxPG_SUBID2
, wxPoint(-100,-100), wxSize(0, sz
.y
) ),
1868 m_fullEditorSize(sz
), m_buttonsWidth(0)
1870 SetBackgroundColour(pg
->GetCellBackgroundColour());
1873 void wxPGMultiButton::Finalize( wxPropertyGrid
* WXUNUSED(propGrid
),
1874 const wxPoint
& pos
)
1876 Move( pos
.x
+ m_fullEditorSize
.x
- m_buttonsWidth
, pos
.y
);
1879 int wxPGMultiButton::GenId( int id
) const
1883 if ( m_buttons
.size() )
1884 id
= GetButton(m_buttons
.size()-1)->GetId() + 1;
1892 void wxPGMultiButton::Add( const wxBitmap
& bitmap
, int id
)
1895 wxSize sz
= GetSize();
1896 wxButton
* button
= new wxBitmapButton( this, id
, bitmap
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
1897 m_buttons
.push_back(button
);
1898 int bw
= button
->GetSize().x
;
1899 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
1900 m_buttonsWidth
+= bw
;
1904 void wxPGMultiButton::Add( const wxString
& label
, int id
)
1907 wxSize sz
= GetSize();
1908 wxButton
* button
= new wxButton( this, id
, label
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
1909 m_buttons
.push_back(button
);
1910 int bw
= button
->GetSize().x
;
1911 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
1912 m_buttonsWidth
+= bw
;
1915 // -----------------------------------------------------------------------
1917 #endif // wxUSE_PROPGRID