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
->GetValueString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
242 if ( (property
->GetFlags() & wxPG_PROP_PASSWORD
) &&
243 property
->IsKindOf(CLASSINFO(wxStringProperty
)) )
244 flags
|= wxTE_PASSWORD
;
246 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrl(pos
,sz
,text
,(wxWindow
*)NULL
,flags
,
247 property
->GetMaxLength());
253 void wxPGTextCtrlEditor::DrawValue( wxDC
& dc
, wxPGProperty
* property
, const wxRect
& rect
) const
255 if ( !property
->IsValueUnspecified() )
257 wxString drawStr
= property
->GetDisplayedString();
259 // Code below should no longer be needed, as the obfuscation
260 // is now done in GetValueAsString.
261 /*if ( (property->GetFlags() & wxPG_PROP_PASSWORD) &&
262 property->IsKindOf(WX_PG_CLASSINFO(wxStringProperty)) )
264 size_t a = drawStr.length();
266 drawStr.Append(wxS('*'),a);
268 dc
.DrawText( drawStr
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
273 void wxPGTextCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
275 wxTextCtrl
* tc
= wxDynamicCast(ctrl
, wxTextCtrl
);
280 if ( tc
->HasFlag(wxTE_PASSWORD
) )
281 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
283 s
= property
->GetDisplayedString();
289 // Provided so that, for example, ComboBox editor can use the same code
290 // (multiple inheritance would get way too messy).
291 bool wxPGTextCtrlEditor::OnTextCtrlEvent( wxPropertyGrid
* propGrid
,
292 wxPGProperty
* WXUNUSED(property
),
299 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
301 if ( propGrid
->IsEditorsValueModified() )
306 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
309 // Pass this event outside wxPropertyGrid so that,
310 // if necessary, program can tell when user is editing
312 // FIXME: Is it safe to change event id in the middle of event
313 // processing (seems to work, but...)?
315 event
.SetId(propGrid
->GetId());
317 propGrid
->EditorsValueWasModified();
323 bool wxPGTextCtrlEditor::OnEvent( wxPropertyGrid
* propGrid
,
324 wxPGProperty
* property
,
326 wxEvent
& event
) const
328 return wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,ctrl
,event
);
332 bool wxPGTextCtrlEditor::GetTextCtrlValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
)
334 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
335 wxString textVal
= tc
->GetValue();
337 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
343 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
345 // Changing unspecified always causes event (returning
346 // true here should be enough to trigger it).
347 // TODO: Move to propgrid.cpp
348 if ( !res
&& variant
.IsNull() )
355 bool wxPGTextCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
357 return wxPGTextCtrlEditor::GetTextCtrlValueFromControl(variant
, property
, ctrl
);
361 void wxPGTextCtrlEditor::SetValueToUnspecified( wxPGProperty
* property
, wxWindow
* ctrl
) const
363 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
365 wxPropertyGrid
* pg
= property
->GetGrid();
366 wxASSERT(pg
); // Really, property grid should exist if editor does
368 tc
->SetValue(wxEmptyString
);
372 void wxPGTextCtrlEditor::SetControlStringValue( wxPGProperty
* property
, wxWindow
* ctrl
, const wxString
& txt
) const
374 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
376 wxPropertyGrid
* pg
= property
->GetGrid();
377 wxASSERT(pg
); // Really, property grid should exist if editor does
383 void wxPGTextCtrlEditor::OnFocus( wxPGProperty
*, wxWindow
* wnd
) const
385 wxTextCtrl
* tc
= wxStaticCast(wnd
, wxTextCtrl
);
387 tc
->SetSelection(-1,-1);
391 wxPGTextCtrlEditor::~wxPGTextCtrlEditor() { }
394 // -----------------------------------------------------------------------
396 // -----------------------------------------------------------------------
399 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(Choice
,wxPGChoiceEditor
,wxPGEditor
)
402 // This is a special enhanced double-click processor class.
403 // In essence, it allows for double-clicks for which the
404 // first click "created" the control.
405 class wxPGDoubleClickProcessor
: public wxEvtHandler
409 wxPGDoubleClickProcessor( wxOwnerDrawnComboBox
* combo
, wxPGProperty
* property
)
412 m_timeLastMouseUp
= 0;
414 m_property
= property
;
415 m_downReceived
= false;
420 void OnMouseEvent( wxMouseEvent
& event
)
422 wxLongLong t
= ::wxGetLocalTimeMillis();
423 int evtType
= event
.GetEventType();
425 if ( m_property
->HasFlag(wxPG_PROP_USE_DCC
) &&
426 m_property
->IsKindOf(CLASSINFO(wxBoolProperty
)) &&
427 !m_combo
->IsPopupShown() )
429 // Just check that it is in the text area
430 wxPoint pt
= event
.GetPosition();
431 if ( m_combo
->GetTextRect().Contains(pt
) )
433 if ( evtType
== wxEVT_LEFT_DOWN
)
435 // Set value to avoid up-events without corresponding downs
436 m_downReceived
= true;
438 else if ( evtType
== wxEVT_LEFT_DCLICK
)
440 // We'll make our own double-clicks
441 event
.SetEventType(0);
444 else if ( evtType
== wxEVT_LEFT_UP
)
446 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
448 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
450 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
452 event
.SetEventType(wxEVT_LEFT_DCLICK
);
453 m_timeLastMouseUp
= 1;
457 m_timeLastMouseUp
= t
;
467 void OnSetFocus( wxFocusEvent
& event
)
469 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
474 wxLongLong m_timeLastMouseUp
;
475 wxOwnerDrawnComboBox
* m_combo
;
476 wxPGProperty
* m_property
; // Selected property
479 DECLARE_EVENT_TABLE()
482 BEGIN_EVENT_TABLE(wxPGDoubleClickProcessor
, wxEvtHandler
)
483 EVT_MOUSE_EVENTS(wxPGDoubleClickProcessor::OnMouseEvent
)
484 EVT_SET_FOCUS(wxPGDoubleClickProcessor::OnSetFocus
)
489 class wxPGComboBox
: public wxOwnerDrawnComboBox
494 : wxOwnerDrawnComboBox()
496 m_dclickProcessor
= (wxPGDoubleClickProcessor
*) NULL
;
497 m_sizeEventCalled
= false;
502 if ( m_dclickProcessor
)
504 RemoveEventHandler(m_dclickProcessor
);
505 delete m_dclickProcessor
;
509 bool Create(wxWindow
*parent
,
511 const wxString
& value
,
514 const wxArrayString
& choices
,
516 const wxValidator
& validator
= wxDefaultValidator
,
517 const wxString
& name
= wxS("wxOwnerDrawnComboBox"))
519 if ( !wxOwnerDrawnComboBox::Create( parent
,
530 m_dclickProcessor
= new wxPGDoubleClickProcessor(this, GetGrid()->GetSelection() );
532 PushEventHandler(m_dclickProcessor
);
537 virtual void OnDrawItem( wxDC
& dc
, const wxRect
& rect
, int item
, int flags
) const
539 wxPropertyGrid
* pg
= GetGrid();
540 pg
->OnComboItemPaint((wxPGCustomComboControl
*)this,item
,dc
,(wxRect
&)rect
,flags
);
542 virtual wxCoord
OnMeasureItem( size_t item
) const
544 wxPropertyGrid
* pg
= GetGrid();
548 pg
->OnComboItemPaint((wxPGCustomComboControl
*)this,item
,*((wxDC
*)NULL
),rect
,0);
552 wxPropertyGrid
* GetGrid() const
554 wxPropertyGrid
* pg
= wxDynamicCast(GetParent()->GetParent(),wxPropertyGrid
);
559 virtual wxCoord
OnMeasureItemWidth( size_t item
) const
561 wxPropertyGrid
* pg
= GetGrid();
565 pg
->OnComboItemPaint((wxPGCustomComboControl
*)this,item
,*((wxDC
*)NULL
),rect
,0);
569 virtual void PositionTextCtrl( int WXUNUSED(textCtrlXAdjust
), int WXUNUSED(textCtrlYAdjust
) )
571 wxPropertyGrid
* pg
= GetGrid();
572 wxOwnerDrawnComboBox::PositionTextCtrl(
573 wxPG_TEXTCTRLXADJUST
- (wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1) - 1,
574 pg
->GetSpacingY() + 2
579 wxPGDoubleClickProcessor
* m_dclickProcessor
;
580 bool m_sizeEventCalled
;
584 void wxPropertyGrid::OnComboItemPaint( wxPGCustomComboControl
* pCc
,
590 wxPGComboBox
* pCb
= (wxPGComboBox
*)pCc
;
593 wxASSERT( IsKindOf(CLASSINFO(wxPropertyGrid
)) );
595 wxPGProperty
* p
= m_selected
;
598 const wxPGChoices
& choices
= p
->GetChoices();
599 const wxPGCommonValue
* comVal
= NULL
;
600 int comVals
= p
->GetDisplayedCommonValueCount();
601 int comValIndex
= -1;
604 if ( choices
.IsOk() )
605 choiceCount
= choices
.GetCount();
607 if ( item
>= choiceCount
&& comVals
> 0 )
609 comValIndex
= item
- choiceCount
;
610 comVal
= GetCommonValue(comValIndex
);
611 if ( !p
->IsValueUnspecified() )
612 text
= comVal
->GetLabel();
616 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
618 text
= pCb
->GetString(item
);
622 if ( !p
->IsValueUnspecified() )
623 text
= p
->GetValueString(0);
632 const wxBitmap
* itemBitmap
= NULL
;
634 if ( item
>= 0 && choices
.IsOk() && choices
.Item(item
).GetBitmap().Ok() && comValIndex
== -1 )
635 itemBitmap
= &choices
.Item(item
).GetBitmap();
638 // Decide what custom image size to use
641 cis
.x
= itemBitmap
->GetWidth();
642 cis
.y
= itemBitmap
->GetHeight();
646 cis
= GetImageSize(p
, item
);
651 // Default measure behaviour (no flexible, custom paint image only)
652 if ( rect
.width
< 0 )
655 GetTextExtent(text
, &x
, &y
, 0, 0, &m_font
);
656 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9 + x
;
659 rect
.height
= cis
.y
+ 2;
663 wxPGPaintData paintdata
;
664 paintdata
.m_parent
= NULL
;
665 paintdata
.m_choiceItem
= item
;
667 // This is by the current (1.0.0b) spec - if painting control, item is -1
668 if ( (flags
& wxODCB_PAINTING_CONTROL
) )
669 paintdata
.m_choiceItem
= -1;
672 dc
.SetBrush(*wxWHITE_BRUSH
);
679 wxPoint
pt(rect
.x
+ wxPG_CONTROL_MARGIN
- wxPG_CHOICEXADJUST
- 1,
684 if ( flags
& wxODCB_PAINTING_CONTROL
)
685 renderFlags
|= wxPGCellRenderer::Control
;
687 if ( flags
& wxODCB_PAINTING_SELECTED
)
688 renderFlags
|= wxPGCellRenderer::Selected
;
690 if ( cis
.x
> 0 && (p
->HasFlag(wxPG_PROP_CUSTOMIMAGE
) || !(flags
& wxODCB_PAINTING_CONTROL
)) &&
691 ( !p
->m_valueBitmap
|| item
== pCb
->GetSelection() ) &&
692 ( item
>= 0 || (flags
& wxODCB_PAINTING_CONTROL
) ) &&
696 pt
.x
+= wxCC_CUSTOM_IMAGE_MARGIN1
;
697 wxRect
r(pt
.x
,pt
.y
,cis
.x
,cis
.y
);
699 if ( flags
& wxODCB_PAINTING_CONTROL
)
702 r
.height
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
705 paintdata
.m_drawnWidth
= r
.width
;
707 dc
.SetPen(m_colPropFore
);
708 if ( comValIndex
>= 0 )
710 const wxPGCommonValue
* cv
= GetCommonValue(comValIndex
);
711 wxPGCellRenderer
* renderer
= cv
->GetRenderer();
712 r
.width
= rect
.width
;
713 renderer
->Render( dc
, r
, this, p
, m_selColumn
, comValIndex
, renderFlags
);
716 else if ( item
>= 0 )
718 p
->OnCustomPaint( dc
, r
, paintdata
);
722 dc
.DrawRectangle( r
);
725 pt
.x
+= paintdata
.m_drawnWidth
+ wxCC_CUSTOM_IMAGE_MARGIN2
- 1;
729 // TODO: This aligns text so that it seems to be horizontally
730 // on the same line as property values. Not really
731 // sure if its needed, but seems to not cause any harm.
734 if ( item
< 0 && (flags
& wxODCB_PAINTING_CONTROL
) )
735 item
= pCb
->GetSelection();
737 if ( choices
.IsOk() && item
>= 0 && comValIndex
< 0 )
739 const wxPGChoiceEntry
& cell
= choices
.Item(item
);
740 wxPGCellRenderer
* renderer
= wxPGGlobalVars
->m_defaultRenderer
;
741 int imageOffset
= renderer
->PreDrawCell( dc
, rect
, cell
, renderFlags
);
743 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
752 pt
.y
+= (rect
.height
-m_fontHeight
)/2 - 1;
756 dc
.DrawText( text
, pt
.x
+ wxPG_XBEFORETEXT
, pt
.y
);
763 p
->OnCustomPaint( dc
, rect
, paintdata
);
764 rect
.height
= paintdata
.m_drawnHeight
+ 2;
765 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9;
769 bool wxPGChoiceEditor_SetCustomPaintWidth( wxPropertyGrid
* propGrid
, wxPGComboBox
* cb
, int cmnVal
)
771 wxPGProperty
* property
= propGrid
->GetSelectedProperty();
772 wxASSERT( property
);
776 // Yes, a common value is being selected
777 property
->SetCommonValue( cmnVal
);
778 wxSize imageSize
= propGrid
->GetCommonValue(cmnVal
)->
779 GetRenderer()->GetImageSize(property
, 1, cmnVal
);
780 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
781 cb
->SetCustomPaintWidth( imageSize
.x
);
786 wxSize imageSize
= propGrid
->GetImageSize(property
, -1);
787 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
788 cb
->SetCustomPaintWidth( imageSize
.x
);
793 // CreateControls calls this with CB_READONLY in extraStyle
794 wxWindow
* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid
* propGrid
,
795 wxPGProperty
* property
,
798 long extraStyle
) const
800 const wxPGChoices
& choices
= property
->GetChoices();
802 int index
= property
->GetChoiceSelection();
804 bool isUnspecified
= property
->IsValueUnspecified();
806 if ( !isUnspecified
)
807 defString
= property
->GetDisplayedString();
809 wxArrayString labels
= choices
.GetLabels();
815 po
.y
+= wxPG_CHOICEYADJUST
;
816 si
.y
-= (wxPG_CHOICEYADJUST
*2);
818 po
.x
+= wxPG_CHOICEXADJUST
;
819 si
.x
-= wxPG_CHOICEXADJUST
;
820 wxWindow
* ctrlParent
= propGrid
->GetPanel();
822 int odcbFlags
= extraStyle
| wxBORDER_NONE
| wxTE_PROCESS_ENTER
;
825 // If common value specified, use appropriate index
826 unsigned int cmnVals
= property
->GetDisplayedCommonValueCount();
829 if ( !isUnspecified
)
831 int cmnVal
= property
->GetCommonValue();
834 index
= labels
.size() + cmnVal
;
839 for ( i
=0; i
<cmnVals
; i
++ )
840 labels
.Add(propGrid
->GetCommonValueLabel(i
));
843 cb
= new wxPGComboBox();
847 cb
->Create(ctrlParent
,
855 cb
->SetButtonPosition(si
.y
,0,wxRIGHT
);
856 cb
->SetTextIndent(wxPG_XBEFORETEXT
-1);
858 wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, property
->GetCommonValue() );
860 if ( index
>= 0 && index
< (int)cb
->GetCount() )
862 cb
->SetSelection( index
);
863 if ( defString
.length() )
864 cb
->SetText( defString
);
866 else if ( !(extraStyle
& wxCB_READONLY
) && defString
.length() )
867 cb
->SetValue( defString
);
869 cb
->SetSelection( -1 );
871 // Connect event handling
872 wxWindowID id
= cb
->GetId();
873 propGrid
->Connect(id
, wxEVT_COMMAND_COMBOBOX_SELECTED
,
874 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
875 propGrid
->Connect(id
, wxEVT_COMMAND_TEXT_UPDATED
,
876 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
877 propGrid
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
878 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
884 return (wxWindow
*) cb
;
888 void wxPGChoiceEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
891 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
892 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
893 int ind
= property
->GetChoiceSelection();
894 cb
->SetSelection(ind
);
897 wxPGWindowList
wxPGChoiceEditor::CreateControls( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
898 const wxPoint
& pos
, const wxSize
& sz
) const
900 return CreateControlsBase(propGrid
,property
,pos
,sz
,wxCB_READONLY
);
904 int wxPGChoiceEditor::InsertItem( wxWindow
* ctrl
, const wxString
& label
, int index
) const
907 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
908 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
911 index
= cb
->GetCount();
913 return cb
->Insert(label
,index
);
917 void wxPGChoiceEditor::DeleteItem( wxWindow
* ctrl
, int index
) const
920 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
921 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
926 bool wxPGChoiceEditor::OnEvent( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
927 wxWindow
* ctrl
, wxEvent
& event
) const
929 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
931 wxPGComboBox
* cb
= (wxPGComboBox
*)ctrl
;
932 int index
= cb
->GetSelection();
933 int cmnValIndex
= -1;
934 int cmnVals
= property
->GetDisplayedCommonValueCount();
935 int items
= cb
->GetCount();
937 if ( index
>= (items
-cmnVals
) )
939 // Yes, a common value is being selected
940 cmnValIndex
= index
- (items
-cmnVals
);
941 property
->SetCommonValue( cmnValIndex
);
943 // Truly set value to unspecified?
944 if ( propGrid
->GetUnspecifiedCommonValue() == cmnValIndex
)
946 if ( !property
->IsValueUnspecified() )
947 propGrid
->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT
);
948 property
->SetValueToUnspecified();
949 if ( !cb
->HasFlag(wxCB_READONLY
) )
950 cb
->GetTextCtrl()->SetValue(wxEmptyString
);
954 return wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, cmnValIndex
);
960 bool wxPGChoiceEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
962 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
964 int index
= cb
->GetSelection();
966 if ( index
!= property
->GetChoiceSelection() ||
967 // Changing unspecified always causes event (returning
968 // true here should be enough to trigger it).
969 property
->IsValueUnspecified()
972 return property
->IntToValue( variant
, index
, 0 );
978 void wxPGChoiceEditor::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, const wxString
& txt
) const
980 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
986 void wxPGChoiceEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
988 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
990 cb
->SetSelection(value
);
994 void wxPGChoiceEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
996 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
997 cb
->SetSelection(-1);
1001 bool wxPGChoiceEditor::CanContainCustomImage() const
1007 wxPGChoiceEditor::~wxPGChoiceEditor() { }
1010 // -----------------------------------------------------------------------
1011 // wxPGComboBoxEditor
1012 // -----------------------------------------------------------------------
1015 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ComboBox
,
1020 void wxPGComboBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1022 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1023 cb
->SetValue(property
->GetValueString(wxPG_EDITABLE_VALUE
));
1025 // TODO: If string matches any selection, then select that.
1029 wxPGWindowList
wxPGComboBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1030 wxPGProperty
* property
,
1032 const wxSize
& sz
) const
1034 return CreateControlsBase(propGrid
,property
,pos
,sz
,0);
1038 bool wxPGComboBoxEditor::OnEvent( wxPropertyGrid
* propGrid
,
1039 wxPGProperty
* property
,
1041 wxEvent
& event
) const
1043 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*) NULL
;
1044 wxWindow
* textCtrl
= (wxWindow
*) NULL
;
1048 cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1049 textCtrl
= cb
->GetTextCtrl();
1052 if ( wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,textCtrl
,event
) )
1055 return wxPGChoiceEditor::OnEvent(propGrid
,property
,ctrl
,event
);
1059 bool wxPGComboBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1061 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1062 wxString textVal
= cb
->GetValue();
1064 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
1070 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
1072 // Changing unspecified always causes event (returning
1073 // true here should be enough to trigger it).
1074 if ( !res
&& variant
.IsNull() )
1081 void wxPGComboBoxEditor::OnFocus( wxPGProperty
*, wxWindow
* ctrl
) const
1083 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1084 cb
->GetTextCtrl()->SetSelection(-1,-1);
1088 wxPGComboBoxEditor::~wxPGComboBoxEditor() { }
1091 // -----------------------------------------------------------------------
1092 // wxPGChoiceAndButtonEditor
1093 // -----------------------------------------------------------------------
1096 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ChoiceAndButton
,
1097 wxPGChoiceAndButtonEditor
,
1101 wxPGWindowList
wxPGChoiceAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1102 wxPGProperty
* property
,
1104 const wxSize
& sz
) const
1106 // Use one two units smaller to match size of the combo's dropbutton.
1107 // (normally a bigger button is used because it looks better)
1110 wxSize
bt_sz(bt_wid
,bt_wid
);
1112 // Position of button.
1113 wxPoint
bt_pos(pos
.x
+sz
.x
-bt_sz
.x
,pos
.y
);
1120 wxWindow
* bt
= propGrid
->GenerateEditorButton( bt_pos
, bt_sz
);
1123 wxSize
ch_sz(sz
.x
-bt
->GetSize().x
,sz
.y
);
1126 ch_sz
.x
-= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1129 wxWindow
* ch
= wxPGEditor_Choice
->CreateControls(propGrid
,property
,
1130 pos
,ch_sz
).m_primary
;
1136 return wxPGWindowList(ch
, bt
);
1140 wxPGChoiceAndButtonEditor::~wxPGChoiceAndButtonEditor() { }
1143 // -----------------------------------------------------------------------
1144 // wxPGTextCtrlAndButtonEditor
1145 // -----------------------------------------------------------------------
1147 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrlAndButton
,
1148 wxPGTextCtrlAndButtonEditor
,
1152 wxPGWindowList
wxPGTextCtrlAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1153 wxPGProperty
* property
,
1155 const wxSize
& sz
) const
1158 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrlAndButton( pos
, sz
, &wnd2
,
1159 property
->GetFlags() & wxPG_PROP_NOEDITOR
, property
);
1161 return wxPGWindowList(wnd
, wnd2
);
1165 wxPGTextCtrlAndButtonEditor::~wxPGTextCtrlAndButtonEditor() { }
1168 // -----------------------------------------------------------------------
1169 // wxPGCheckBoxEditor
1170 // -----------------------------------------------------------------------
1172 #if wxPG_INCLUDE_CHECKBOX
1174 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(CheckBox
,
1179 // state argument: 0x01 = set if checked
1180 // 0x02 = set if rectangle should be bold
1181 static void DrawSimpleCheckBox( wxDC
& dc
, const wxRect
& rect
, int box_hei
, int state
, const wxColour
& linecol
)
1185 wxRect
r(rect
.x
+wxPG_XBEFORETEXT
,rect
.y
+((rect
.height
-box_hei
)/2),box_hei
,box_hei
);
1187 // Draw check mark first because it is likely to overdraw the
1188 // surrounding rectangle.
1191 wxRect
r2(r
.x
+wxPG_CHECKMARK_XADJ
,
1192 r
.y
+wxPG_CHECKMARK_YADJ
,
1193 r
.width
+wxPG_CHECKMARK_WADJ
,
1194 r
.height
+wxPG_CHECKMARK_HADJ
);
1195 #if wxPG_CHECKMARK_DEFLATE
1196 r2
.Deflate(wxPG_CHECKMARK_DEFLATE
);
1198 dc
.DrawCheckMark(r2
);
1200 // This would draw a simple cross check mark.
1201 // dc.DrawLine(r.x,r.y,r.x+r.width-1,r.y+r.height-1);
1202 // dc.DrawLine(r.x,r.y+r.height-1,r.x+r.width-1,r.y);
1208 // Pen for thin rectangle.
1213 // Pen for bold rectangle.
1214 wxPen
linepen(linecol
,2,wxSOLID
);
1215 linepen
.SetJoin(wxJOIN_MITER
); // This prevents round edges.
1223 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1225 dc
.DrawRectangle(r
);
1226 dc
.SetPen(*wxTRANSPARENT_PEN
);
1230 // Real simple custom-drawn checkbox-without-label class.
1232 class wxSimpleCheckBox
: public wxControl
1236 void SetValue( int value
);
1238 wxSimpleCheckBox( wxWindow
* parent
,
1240 const wxPoint
& pos
= wxDefaultPosition
,
1241 const wxSize
& size
= wxDefaultSize
)
1242 : wxControl(parent
,id
,pos
,size
,wxBORDER_NONE
|wxWANTS_CHARS
)
1244 // Due to SetOwnFont stuff necessary for GTK+ 1.2, we need to have this
1245 SetFont( parent
->GetFont() );
1248 wxPropertyGrid
* pg
= (wxPropertyGrid
*) parent
->GetParent();
1249 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1250 m_boxHeight
= pg
->GetFontHeight();
1251 SetBackgroundStyle( wxBG_STYLE_COLOUR
);
1254 virtual ~wxSimpleCheckBox();
1256 virtual bool ProcessEvent(wxEvent
& event
);
1261 static wxBitmap
* ms_doubleBuffer
;
1265 wxSimpleCheckBox::~wxSimpleCheckBox()
1267 delete ms_doubleBuffer
;
1268 ms_doubleBuffer
= NULL
;
1272 wxBitmap
* wxSimpleCheckBox::ms_doubleBuffer
= (wxBitmap
*) NULL
;
1274 // value = 2 means toggle (sorry, too lazy to do constants)
1275 void wxSimpleCheckBox::SetValue( int value
)
1280 if ( m_state
> 1 ) m_state
= 0;
1288 wxCommandEvent
evt(wxEVT_COMMAND_CHECKBOX_CLICKED
,GetParent()->GetId());
1290 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent()->GetParent();
1291 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1292 propGrid
->OnCustomEditorEvent(evt
);
1296 bool wxSimpleCheckBox::ProcessEvent(wxEvent
& event
)
1298 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent()->GetParent();
1299 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1301 if ( ( (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1302 && ((wxMouseEvent
&)event
).m_x
> (wxPG_XBEFORETEXT
-2)
1303 && ((wxMouseEvent
&)event
).m_x
<= (wxPG_XBEFORETEXT
-2+m_boxHeight
) )
1309 else if ( event
.GetEventType() == wxEVT_PAINT
)
1311 wxSize clientSize
= GetClientSize();
1315 // Buffered paint DC doesn't seem to do much good
1316 if ( !ms_doubleBuffer ||
1317 clientSize.x > ms_doubleBuffer->GetWidth() ||
1318 clientSize.y > ms_doubleBuffer->GetHeight() )
1320 delete ms_doubleBuffer;
1321 ms_doubleBuffer = new wxBitmap(clientSize.x+25,clientSize.y+25);
1324 wxBufferedPaintDC dc(this,*ms_doubleBuffer);
1327 wxRect
rect(0,0,clientSize
.x
,clientSize
.y
);
1332 m_boxHeight
= propGrid
->GetFontHeight();
1334 wxColour bgcol
= GetBackgroundColour();
1335 dc
.SetBrush( bgcol
);
1337 dc
.DrawRectangle( rect
);
1339 wxColour txcol
= GetForegroundColour();
1341 int state
= m_state
;
1342 if ( m_font
.GetWeight() == wxBOLD
)
1345 DrawSimpleCheckBox(dc
,rect
,m_boxHeight
,state
,txcol
);
1347 // If focused, indicate it somehow.
1349 if ( wxWindow::FindFocus() == this )
1354 wxPGDrawFocusRect(dc,rect);
1360 else if ( event
.GetEventType() == wxEVT_SIZE
||
1361 event
.GetEventType() == wxEVT_SET_FOCUS
||
1362 event
.GetEventType() == wxEVT_KILL_FOCUS
1367 else if ( event
.GetEventType() == wxEVT_KEY_DOWN
)
1369 wxKeyEvent
& keyEv
= (wxKeyEvent
&) event
;
1371 if ( keyEv
.GetKeyCode() == WXK_SPACE
)
1377 return wxControl::ProcessEvent(event
);
1381 wxPGWindowList
wxPGCheckBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1382 wxPGProperty
* property
,
1384 const wxSize
& size
) const
1387 pt
.x
-= wxPG_XBEFOREWIDGET
;
1389 sz
.x
= propGrid
->GetFontHeight() + (wxPG_XBEFOREWIDGET
*2) + 4;
1391 wxSimpleCheckBox
* cb
= new wxSimpleCheckBox(propGrid
->GetPanel(),wxPG_SUBID1
,pt
,sz
);
1393 cb
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
1395 cb
->Connect( wxPG_SUBID1
, wxEVT_LEFT_DOWN
,
1396 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
1397 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propGrid
);
1399 cb
->Connect( wxPG_SUBID1
, wxEVT_LEFT_DCLICK
,
1400 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
1401 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propGrid
);
1403 if ( property
->GetChoiceSelection() > 0 &&
1404 !property
->IsValueUnspecified() )
1407 // If mouse cursor was on the item, toggle the value now.
1408 if ( propGrid
->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK
)
1410 wxPoint pt
= cb
->ScreenToClient(::wxGetMousePosition());
1411 if ( pt
.x
<= (wxPG_XBEFORETEXT
-2+cb
->m_boxHeight
) )
1415 if ( cb
->m_state
> 1 )
1418 // Makes sure wxPG_EVT_CHANGING etc. is sent for this initial click
1419 propGrid
->ChangePropertyValue(property
, wxPGVariant_Bool(cb
->m_state
));
1423 propGrid
->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR
);
1429 class wxPGCheckBoxRenderer : public wxPGDefaultRenderer
1433 virtual void Render( wxDC& dc, const wxRect& rect,
1434 const wxPropertyGrid* WXUNUSED(propertyGrid), wxPGProperty* property,
1435 int WXUNUSED(column), int WXUNUSED(item), int WXUNUSED(flags) ) const
1438 if ( !(property->GetFlags() & wxPG_PROP_UNSPECIFIED) )
1440 state = ((wxPGProperty*)property)->GetChoiceInfo((wxPGChoiceInfo*)NULL);
1441 if ( dc.GetFont().GetWeight() == wxBOLD ) state |= 2;
1443 DrawSimpleCheckBox(dc,rect,dc.GetCharHeight(),state,dc.GetTextForeground());
1449 wxPGCheckBoxRenderer g_wxPGCheckBoxRenderer;
1451 wxPGCellRenderer* wxPGCheckBoxEditor::GetCellRenderer() const
1453 return &g_wxPGCheckBoxRenderer;
1457 void wxPGCheckBoxEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
, wxPGProperty
* property
, const wxString
& WXUNUSED(text
) ) const
1460 if ( !property
->IsValueUnspecified() )
1462 state
= property
->GetChoiceSelection();
1463 if ( dc
.GetFont().GetWeight() == wxBOLD
) state
|= 2;
1465 DrawSimpleCheckBox(dc
,rect
,dc
.GetCharHeight(),state
,dc
.GetTextForeground());
1468 void wxPGCheckBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1471 ((wxSimpleCheckBox
*)ctrl
)->m_state
= property
->GetChoiceSelection();
1476 bool wxPGCheckBoxEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propGrid
), wxPGProperty
* WXUNUSED(property
),
1477 wxWindow
* WXUNUSED(ctrl
), wxEvent
& event
) const
1479 if ( event
.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED
)
1487 bool wxPGCheckBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1489 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*)ctrl
;
1491 int index
= cb
->m_state
;
1493 if ( index
!= property
->GetChoiceSelection() ||
1494 // Changing unspecified always causes event (returning
1495 // true here should be enough to trigger it).
1496 property
->IsValueUnspecified()
1499 return property
->IntToValue(variant
, index
, 0);
1505 void wxPGCheckBoxEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1507 if ( value
!= 0 ) value
= 1;
1508 ((wxSimpleCheckBox
*)ctrl
)->m_state
= value
;
1513 void wxPGCheckBoxEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1515 ((wxSimpleCheckBox
*)ctrl
)->m_state
= 0;
1520 wxPGCheckBoxEditor::~wxPGCheckBoxEditor() { }
1523 #endif // wxPG_INCLUDE_CHECKBOX
1525 // -----------------------------------------------------------------------
1527 wxWindow
* wxPropertyGrid::GetEditorControl() const
1529 wxWindow
* ctrl
= m_wndEditor
;
1537 // -----------------------------------------------------------------------
1539 void wxPropertyGrid::CorrectEditorWidgetSizeX()
1541 if ( m_selColumn
== -1 )
1545 int newSplitterx
= m_pState
->DoGetSplitterPosition(m_selColumn
-1);
1546 int newWidth
= newSplitterx
+ m_pState
->m_colWidths
[m_selColumn
];
1550 // if width change occurred, move secondary wnd by that amount
1551 wxRect r
= m_wndEditor2
->GetRect();
1553 r
.x
= newWidth
- secWid
;
1555 m_wndEditor2
->SetSize( r
);
1557 // if primary is textctrl, then we have to add some extra space
1561 if ( m_wndEditor
&& m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1563 secWid
+= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1568 wxRect r
= m_wndEditor
->GetRect();
1570 r
.x
= newSplitterx
+m_ctrlXAdjust
;
1572 if ( !(m_iFlags
& wxPG_FL_FIXED_WIDTH_EDITOR
) )
1573 r
.width
= newWidth
- r
.x
- secWid
;
1575 m_wndEditor
->SetSize(r
);
1579 m_wndEditor2
->Refresh();
1582 // -----------------------------------------------------------------------
1584 void wxPropertyGrid::CorrectEditorWidgetPosY()
1586 if ( m_selected
&& (m_wndEditor
|| m_wndEditor2
) )
1588 wxRect r
= GetEditorWidgetRect(m_selected
, m_selColumn
);
1592 wxPoint pos
= m_wndEditor
->GetPosition();
1594 // Calculate y offset
1595 int offset
= pos
.y
% m_lineHeight
;
1597 m_wndEditor
->Move(pos
.x
, r
.y
+ offset
);
1602 wxPoint pos
= m_wndEditor2
->GetPosition();
1604 m_wndEditor2
->Move(pos
.x
, r
.y
);
1609 // -----------------------------------------------------------------------
1611 // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
1612 // fits into that category as well).
1613 void wxPropertyGrid::FixPosForTextCtrl( wxWindow
* ctrl
, const wxPoint
& offset
)
1615 // Center the control vertically
1616 wxRect finalPos
= ctrl
->GetRect();
1617 int y_adj
= (m_lineHeight
- finalPos
.height
)/2 + wxPG_TEXTCTRLYADJUST
;
1619 // Prevent over-sized control
1620 int sz_dec
= (y_adj
+ finalPos
.height
) - m_lineHeight
;
1621 if ( sz_dec
< 0 ) sz_dec
= 0;
1623 finalPos
.y
+= y_adj
;
1624 finalPos
.height
-= (y_adj
+sz_dec
);
1626 const int textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
;
1628 finalPos
.x
+= textCtrlXAdjust
;
1629 finalPos
.width
-= textCtrlXAdjust
;
1631 finalPos
.x
+= offset
.x
;
1632 finalPos
.y
+= offset
.y
;
1634 ctrl
->SetSize(finalPos
);
1637 // -----------------------------------------------------------------------
1639 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint
& pos
,
1641 const wxString
& value
,
1642 wxWindow
* secondary
,
1646 wxWindowID id
= wxPG_SUBID1
;
1647 wxPGProperty
* selected
= m_selected
;
1650 int tcFlags
= wxTE_PROCESS_ENTER
| extraStyle
;
1652 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1653 tcFlags
|= wxTE_READONLY
;
1655 wxPoint
p(pos
.x
,pos
.y
);
1656 wxSize
s(sz
.x
,sz
.y
);
1658 // Need to reduce width of text control on Mac
1659 #if defined(__WXMAC__)
1663 // Take button into acccount
1666 s
.x
-= (secondary
->GetSize().x
+ wxPG_TEXTCTRL_AND_BUTTON_SPACING
);
1667 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
1670 // If the height is significantly higher, then use border, and fill the rect exactly.
1671 bool hasSpecialSize
= false;
1673 if ( (sz
.y
- m_lineHeight
) > 5 )
1674 hasSpecialSize
= true;
1676 wxWindow
* ctrlParent
= GetPanel();
1678 if ( !hasSpecialSize
)
1679 tcFlags
|= wxBORDER_NONE
;
1681 wxTextCtrl
* tc
= new wxTextCtrl();
1683 #if defined(__WXMSW__)
1686 SetupTextCtrlValue(value
);
1687 tc
->Create(ctrlParent
,id
,value
, p
, s
,tcFlags
);
1691 // Center the control vertically
1692 if ( !hasSpecialSize
)
1693 FixPosForTextCtrl(ed
);
1701 // Set maximum length
1703 tc
->SetMaxLength( maxLen
);
1705 // Connect event handling
1707 this->Connect(id
, wxEVT_COMMAND_TEXT_UPDATED
,
1708 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1709 this->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
1710 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1712 return (wxWindow
*) ed
;
1715 // -----------------------------------------------------------------------
1717 wxWindow
* wxPropertyGrid::GenerateEditorButton( const wxPoint
& pos
, const wxSize
& sz
)
1719 wxWindowID id
= wxPG_SUBID2
;
1720 wxPGProperty
* selected
= m_selected
;
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
) )
1773 // Connect event handling
1775 this->Connect(id
, wxEVT_COMMAND_BUTTON_CLICKED
,
1776 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1781 // -----------------------------------------------------------------------
1783 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrlAndButton( const wxPoint
& pos
,
1785 wxWindow
** psecondary
,
1787 wxPGProperty
* property
)
1789 wxButton
* but
= (wxButton
*)GenerateEditorButton(pos
,sz
);
1790 *psecondary
= (wxWindow
*)but
;
1792 if ( limitedEditing
)
1795 // There is button Show in GenerateEditorTextCtrl as well
1798 return (wxWindow
*) NULL
;
1803 if ( !property
->IsValueUnspecified() )
1804 text
= property
->GetValueString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
1806 return GenerateEditorTextCtrl(pos
,sz
,text
,but
,property
->m_maxLen
);
1809 // -----------------------------------------------------------------------
1811 wxTextCtrl
* wxPropertyGrid::GetEditorTextCtrl() const
1813 wxWindow
* wnd
= GetEditorControl();
1818 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1819 return wxStaticCast(wnd
, wxTextCtrl
);
1821 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
1823 wxOwnerDrawnComboBox
* cb
= wxStaticCast(wnd
, wxOwnerDrawnComboBox
);
1824 return cb
->GetTextCtrl();
1830 // -----------------------------------------------------------------------
1832 wxPGEditor
* wxPropertyGridInterface::GetEditorByName( const wxString
& editorName
)
1834 wxPGHashMapS2P::const_iterator it
;
1836 it
= wxPGGlobalVars
->m_mapEditorClasses
.find(editorName
);
1837 if ( it
== wxPGGlobalVars
->m_mapEditorClasses
.end() )
1839 return (wxPGEditor
*) it
->second
;
1842 // -----------------------------------------------------------------------
1843 // wxPGEditorDialogAdapter
1844 // -----------------------------------------------------------------------
1846 IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter
, wxObject
)
1848 bool wxPGEditorDialogAdapter::ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
1850 if ( !propGrid
->EditorValidate() )
1853 bool res
= DoShowDialog( propGrid
, property
);
1857 propGrid
->ValueChangeInEvent( m_value
);
1864 // -----------------------------------------------------------------------
1866 // -----------------------------------------------------------------------
1868 wxPGMultiButton::wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
)
1869 : wxWindow( pg
->GetPanel(), wxPG_SUBID2
, wxPoint(-100,-100), wxSize(0, sz
.y
) ),
1870 m_fullEditorSize(sz
), m_buttonsWidth(0)
1872 SetBackgroundColour(pg
->GetCellBackgroundColour());
1875 void wxPGMultiButton::Finalize( wxPropertyGrid
* propGrid
, const wxPoint
& pos
)
1877 Move( pos
.x
+ m_fullEditorSize
.x
- m_buttonsWidth
, pos
.y
);
1879 // Connect event handling
1880 for ( unsigned int i
=0; i
<GetCount(); i
++ )
1882 wxWindowID id
= GetButtonId(i
);
1883 propGrid
->Connect(id
, wxEVT_COMMAND_BUTTON_CLICKED
,
1884 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1888 int wxPGMultiButton::GenId( int id
) const
1892 if ( m_buttons
.size() )
1893 id
= GetButton(m_buttons
.size()-1)->GetId() + 1;
1901 void wxPGMultiButton::Add( const wxBitmap
& bitmap
, int id
)
1904 wxSize sz
= GetSize();
1905 wxButton
* button
= new wxBitmapButton( this, id
, bitmap
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
1906 m_buttons
.push_back(button
);
1907 int bw
= button
->GetSize().x
;
1908 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
1909 m_buttonsWidth
+= bw
;
1913 void wxPGMultiButton::Add( const wxString
& label
, int id
)
1916 wxSize sz
= GetSize();
1917 wxButton
* button
= new wxButton( this, id
, label
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
1918 m_buttons
.push_back(button
);
1919 int bw
= button
->GetSize().x
;
1920 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
1921 m_buttonsWidth
+= bw
;
1924 // -----------------------------------------------------------------------
1926 #endif // wxUSE_PROPGRID