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();
290 // Provided so that, for example, ComboBox editor can use the same code
291 // (multiple inheritance would get way too messy).
292 bool wxPGTextCtrlEditor::OnTextCtrlEvent( wxPropertyGrid
* propGrid
,
293 wxPGProperty
* WXUNUSED(property
),
300 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
302 if ( propGrid
->IsEditorsValueModified() )
307 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
310 // Pass this event outside wxPropertyGrid so that,
311 // if necessary, program can tell when user is editing
313 // FIXME: Is it safe to change event id in the middle of event
314 // processing (seems to work, but...)?
316 event
.SetId(propGrid
->GetId());
318 propGrid
->EditorsValueWasModified();
324 bool wxPGTextCtrlEditor::OnEvent( wxPropertyGrid
* propGrid
,
325 wxPGProperty
* property
,
327 wxEvent
& event
) const
329 return wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,ctrl
,event
);
333 bool wxPGTextCtrlEditor::GetTextCtrlValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
)
335 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
336 wxString textVal
= tc
->GetValue();
338 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
344 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
346 // Changing unspecified always causes event (returning
347 // true here should be enough to trigger it).
348 // TODO: Move to propgrid.cpp
349 if ( !res
&& variant
.IsNull() )
356 bool wxPGTextCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
358 return wxPGTextCtrlEditor::GetTextCtrlValueFromControl(variant
, property
, ctrl
);
362 void wxPGTextCtrlEditor::SetValueToUnspecified( wxPGProperty
* property
, wxWindow
* ctrl
) const
364 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
366 wxPropertyGrid
* pg
= property
->GetGrid();
367 wxASSERT(pg
); // Really, property grid should exist if editor does
369 tc
->SetValue(wxEmptyString
);
373 void wxPGTextCtrlEditor::SetControlStringValue( wxPGProperty
* property
, wxWindow
* ctrl
, const wxString
& txt
) const
375 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
377 wxPropertyGrid
* pg
= property
->GetGrid();
378 wxASSERT(pg
); // Really, property grid should exist if editor does
384 void wxPGTextCtrlEditor::OnFocus( wxPGProperty
*, wxWindow
* wnd
) const
386 wxTextCtrl
* tc
= wxStaticCast(wnd
, wxTextCtrl
);
388 tc
->SetSelection(-1,-1);
392 wxPGTextCtrlEditor::~wxPGTextCtrlEditor() { }
395 // -----------------------------------------------------------------------
397 // -----------------------------------------------------------------------
400 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(Choice
,wxPGChoiceEditor
,wxPGEditor
)
403 // This is a special enhanced double-click processor class.
404 // In essence, it allows for double-clicks for which the
405 // first click "created" the control.
406 class wxPGDoubleClickProcessor
: public wxEvtHandler
410 wxPGDoubleClickProcessor( wxOwnerDrawnComboBox
* combo
, wxPGProperty
* property
)
413 m_timeLastMouseUp
= 0;
415 m_property
= property
;
416 m_downReceived
= false;
421 void OnMouseEvent( wxMouseEvent
& event
)
423 wxLongLong t
= ::wxGetLocalTimeMillis();
424 int evtType
= event
.GetEventType();
426 if ( m_property
->HasFlag(wxPG_PROP_USE_DCC
) &&
427 m_property
->IsKindOf(CLASSINFO(wxBoolProperty
)) &&
428 !m_combo
->IsPopupShown() )
430 // Just check that it is in the text area
431 wxPoint pt
= event
.GetPosition();
432 if ( m_combo
->GetTextRect().Contains(pt
) )
434 if ( evtType
== wxEVT_LEFT_DOWN
)
436 // Set value to avoid up-events without corresponding downs
437 m_downReceived
= true;
439 else if ( evtType
== wxEVT_LEFT_DCLICK
)
441 // We'll make our own double-clicks
442 event
.SetEventType(0);
445 else if ( evtType
== wxEVT_LEFT_UP
)
447 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
449 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
451 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
453 event
.SetEventType(wxEVT_LEFT_DCLICK
);
454 m_timeLastMouseUp
= 1;
458 m_timeLastMouseUp
= t
;
468 void OnSetFocus( wxFocusEvent
& event
)
470 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
475 wxLongLong m_timeLastMouseUp
;
476 wxOwnerDrawnComboBox
* m_combo
;
477 wxPGProperty
* m_property
; // Selected property
480 DECLARE_EVENT_TABLE()
483 BEGIN_EVENT_TABLE(wxPGDoubleClickProcessor
, wxEvtHandler
)
484 EVT_MOUSE_EVENTS(wxPGDoubleClickProcessor::OnMouseEvent
)
485 EVT_SET_FOCUS(wxPGDoubleClickProcessor::OnSetFocus
)
490 class wxPGComboBox
: public wxOwnerDrawnComboBox
495 : wxOwnerDrawnComboBox()
497 m_dclickProcessor
= (wxPGDoubleClickProcessor
*) NULL
;
498 m_sizeEventCalled
= false;
503 if ( m_dclickProcessor
)
505 RemoveEventHandler(m_dclickProcessor
);
506 delete m_dclickProcessor
;
510 bool Create(wxWindow
*parent
,
512 const wxString
& value
,
515 const wxArrayString
& choices
,
517 const wxValidator
& validator
= wxDefaultValidator
,
518 const wxString
& name
= wxS("wxOwnerDrawnComboBox"))
520 if ( !wxOwnerDrawnComboBox::Create( parent
,
531 m_dclickProcessor
= new
532 wxPGDoubleClickProcessor( this, GetGrid()->GetSelection() );
534 PushEventHandler(m_dclickProcessor
);
539 virtual void OnDrawItem( wxDC
& dc
,
544 wxPropertyGrid
* pg
= GetGrid();
545 pg
->OnComboItemPaint( this, item
, &dc
, (wxRect
&)rect
, flags
);
548 virtual wxCoord
OnMeasureItem( size_t item
) const
550 wxPropertyGrid
* pg
= GetGrid();
554 pg
->OnComboItemPaint( this, item
, NULL
, rect
, 0 );
558 wxPropertyGrid
* GetGrid() const
560 wxPropertyGrid
* pg
= wxDynamicCast(GetParent()->GetParent(),
566 virtual wxCoord
OnMeasureItemWidth( size_t item
) const
568 wxPropertyGrid
* pg
= GetGrid();
572 pg
->OnComboItemPaint( this, item
, NULL
, rect
, 0 );
576 virtual void PositionTextCtrl( int WXUNUSED(textCtrlXAdjust
),
577 int WXUNUSED(textCtrlYAdjust
) )
579 wxPropertyGrid
* pg
= GetGrid();
580 wxOwnerDrawnComboBox::PositionTextCtrl(
581 wxPG_TEXTCTRLXADJUST
-
582 (wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1) - 1,
583 pg
->GetSpacingY() + 2
588 wxPGDoubleClickProcessor
* m_dclickProcessor
;
589 bool m_sizeEventCalled
;
593 void wxPropertyGrid::OnComboItemPaint( const wxPGComboBox
* pCb
,
600 wxASSERT( IsKindOf(CLASSINFO(wxPropertyGrid
)) );
602 wxPGProperty
* p
= m_selected
;
605 const wxPGChoices
& choices
= p
->GetChoices();
606 const wxPGCommonValue
* comVal
= NULL
;
607 int comVals
= p
->GetDisplayedCommonValueCount();
608 int comValIndex
= -1;
611 if ( choices
.IsOk() )
612 choiceCount
= choices
.GetCount();
614 if ( item
>= choiceCount
&& comVals
> 0 )
616 comValIndex
= item
- choiceCount
;
617 comVal
= GetCommonValue(comValIndex
);
618 if ( !p
->IsValueUnspecified() )
619 text
= comVal
->GetLabel();
623 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
625 text
= pCb
->GetString(item
);
629 if ( !p
->IsValueUnspecified() )
630 text
= p
->GetValueAsString(0);
639 const wxBitmap
* itemBitmap
= NULL
;
641 if ( item
>= 0 && choices
.IsOk() && choices
.Item(item
).GetBitmap().Ok() && comValIndex
== -1 )
642 itemBitmap
= &choices
.Item(item
).GetBitmap();
645 // Decide what custom image size to use
648 cis
.x
= itemBitmap
->GetWidth();
649 cis
.y
= itemBitmap
->GetHeight();
653 cis
= GetImageSize(p
, item
);
658 // Default measure behaviour (no flexible, custom paint image only)
659 if ( rect
.width
< 0 )
662 GetTextExtent(text
, &x
, &y
, 0, 0, &m_font
);
663 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9 + x
;
666 rect
.height
= cis
.y
+ 2;
670 wxPGPaintData paintdata
;
671 paintdata
.m_parent
= NULL
;
672 paintdata
.m_choiceItem
= item
;
674 // This is by the current (1.0.0b) spec - if painting control, item is -1
675 if ( (flags
& wxODCB_PAINTING_CONTROL
) )
676 paintdata
.m_choiceItem
= -1;
679 pDc
->SetBrush(*wxWHITE_BRUSH
);
687 wxPoint
pt(rect
.x
+ wxPG_CONTROL_MARGIN
- wxPG_CHOICEXADJUST
- 1,
690 int renderFlags
= wxPGCellRenderer::DontUseCellColours
;
692 if ( flags
& wxODCB_PAINTING_CONTROL
)
693 renderFlags
|= wxPGCellRenderer::Control
;
695 if ( flags
& wxODCB_PAINTING_SELECTED
)
696 renderFlags
|= wxPGCellRenderer::Selected
;
698 if ( cis
.x
> 0 && (p
->HasFlag(wxPG_PROP_CUSTOMIMAGE
) || !(flags
& wxODCB_PAINTING_CONTROL
)) &&
699 ( !p
->m_valueBitmap
|| item
== pCb
->GetSelection() ) &&
700 ( item
>= 0 || (flags
& wxODCB_PAINTING_CONTROL
) ) &&
704 pt
.x
+= wxCC_CUSTOM_IMAGE_MARGIN1
;
705 wxRect
r(pt
.x
,pt
.y
,cis
.x
,cis
.y
);
707 if ( flags
& wxODCB_PAINTING_CONTROL
)
710 r
.height
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
713 paintdata
.m_drawnWidth
= r
.width
;
715 dc
.SetPen(m_colPropFore
);
716 if ( comValIndex
>= 0 )
718 const wxPGCommonValue
* cv
= GetCommonValue(comValIndex
);
719 wxPGCellRenderer
* renderer
= cv
->GetRenderer();
720 r
.width
= rect
.width
;
721 renderer
->Render( dc
, r
, this, p
, m_selColumn
, comValIndex
, renderFlags
);
724 else if ( item
>= 0 )
726 p
->OnCustomPaint( dc
, r
, paintdata
);
730 dc
.DrawRectangle( r
);
733 pt
.x
+= paintdata
.m_drawnWidth
+ wxCC_CUSTOM_IMAGE_MARGIN2
- 1;
737 // TODO: This aligns text so that it seems to be horizontally
738 // on the same line as property values. Not really
739 // sure if its needed, but seems to not cause any harm.
742 if ( item
< 0 && (flags
& wxODCB_PAINTING_CONTROL
) )
743 item
= pCb
->GetSelection();
745 if ( choices
.IsOk() && item
>= 0 && comValIndex
< 0 )
747 const wxPGChoiceEntry
& cell
= choices
.Item(item
);
748 wxPGCellRenderer
* renderer
= wxPGGlobalVars
->m_defaultRenderer
;
749 int imageOffset
= renderer
->PreDrawCell( dc
, rect
, cell
, renderFlags
);
751 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
760 pt
.y
+= (rect
.height
-m_fontHeight
)/2 - 1;
764 dc
.DrawText( text
, pt
.x
+ wxPG_XBEFORETEXT
, pt
.y
);
772 p
->OnCustomPaint( dc
, rect
, paintdata
);
773 rect
.height
= paintdata
.m_drawnHeight
+ 2;
774 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9;
778 bool wxPGChoiceEditor_SetCustomPaintWidth( wxPropertyGrid
* propGrid
, wxPGComboBox
* cb
, int cmnVal
)
780 wxPGProperty
* property
= propGrid
->GetSelectedProperty();
781 wxASSERT( property
);
785 // Yes, a common value is being selected
786 property
->SetCommonValue( cmnVal
);
787 wxSize imageSize
= propGrid
->GetCommonValue(cmnVal
)->
788 GetRenderer()->GetImageSize(property
, 1, cmnVal
);
789 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
790 cb
->SetCustomPaintWidth( imageSize
.x
);
795 wxSize imageSize
= propGrid
->GetImageSize(property
, -1);
796 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
797 cb
->SetCustomPaintWidth( imageSize
.x
);
802 // CreateControls calls this with CB_READONLY in extraStyle
803 wxWindow
* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid
* propGrid
,
804 wxPGProperty
* property
,
807 long extraStyle
) const
809 const wxPGChoices
& choices
= property
->GetChoices();
811 int index
= property
->GetChoiceSelection();
813 bool isUnspecified
= property
->IsValueUnspecified();
815 if ( !isUnspecified
)
816 defString
= property
->GetDisplayedString();
818 wxArrayString labels
= choices
.GetLabels();
824 po
.y
+= wxPG_CHOICEYADJUST
;
825 si
.y
-= (wxPG_CHOICEYADJUST
*2);
827 po
.x
+= wxPG_CHOICEXADJUST
;
828 si
.x
-= wxPG_CHOICEXADJUST
;
829 wxWindow
* ctrlParent
= propGrid
->GetPanel();
831 int odcbFlags
= extraStyle
| wxBORDER_NONE
| wxTE_PROCESS_ENTER
;
834 // If common value specified, use appropriate index
835 unsigned int cmnVals
= property
->GetDisplayedCommonValueCount();
838 if ( !isUnspecified
)
840 int cmnVal
= property
->GetCommonValue();
843 index
= labels
.size() + cmnVal
;
848 for ( i
=0; i
<cmnVals
; i
++ )
849 labels
.Add(propGrid
->GetCommonValueLabel(i
));
852 cb
= new wxPGComboBox();
856 cb
->Create(ctrlParent
,
864 cb
->SetButtonPosition(si
.y
,0,wxRIGHT
);
865 cb
->SetTextIndent(wxPG_XBEFORETEXT
-1);
867 wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, property
->GetCommonValue() );
869 if ( index
>= 0 && index
< (int)cb
->GetCount() )
871 cb
->SetSelection( index
);
872 if ( defString
.length() )
873 cb
->SetText( defString
);
875 else if ( !(extraStyle
& wxCB_READONLY
) && defString
.length() )
876 cb
->SetValue( defString
);
878 cb
->SetSelection( -1 );
880 // Connect event handling
881 wxWindowID id
= cb
->GetId();
882 propGrid
->Connect(id
, wxEVT_COMMAND_COMBOBOX_SELECTED
,
883 wxEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
884 propGrid
->Connect(id
, wxEVT_COMMAND_TEXT_UPDATED
,
885 wxEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
886 propGrid
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
887 wxEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
893 return (wxWindow
*) cb
;
897 void wxPGChoiceEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
900 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
901 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
902 int ind
= property
->GetChoiceSelection();
903 cb
->SetSelection(ind
);
906 wxPGWindowList
wxPGChoiceEditor::CreateControls( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
907 const wxPoint
& pos
, const wxSize
& sz
) const
909 return CreateControlsBase(propGrid
,property
,pos
,sz
,wxCB_READONLY
);
913 int wxPGChoiceEditor::InsertItem( wxWindow
* ctrl
, const wxString
& label
, int index
) const
916 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
917 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
920 index
= cb
->GetCount();
922 return cb
->Insert(label
,index
);
926 void wxPGChoiceEditor::DeleteItem( wxWindow
* ctrl
, int index
) const
929 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
930 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
935 bool wxPGChoiceEditor::OnEvent( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
936 wxWindow
* ctrl
, wxEvent
& event
) const
938 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
940 wxPGComboBox
* cb
= (wxPGComboBox
*)ctrl
;
941 int index
= cb
->GetSelection();
942 int cmnValIndex
= -1;
943 int cmnVals
= property
->GetDisplayedCommonValueCount();
944 int items
= cb
->GetCount();
946 if ( index
>= (items
-cmnVals
) )
948 // Yes, a common value is being selected
949 cmnValIndex
= index
- (items
-cmnVals
);
950 property
->SetCommonValue( cmnValIndex
);
952 // Truly set value to unspecified?
953 if ( propGrid
->GetUnspecifiedCommonValue() == cmnValIndex
)
955 if ( !property
->IsValueUnspecified() )
956 propGrid
->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT
);
957 property
->SetValueToUnspecified();
958 if ( !cb
->HasFlag(wxCB_READONLY
) )
959 cb
->GetTextCtrl()->SetValue(wxEmptyString
);
963 return wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, cmnValIndex
);
969 bool wxPGChoiceEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
971 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
973 int index
= cb
->GetSelection();
975 if ( index
!= property
->GetChoiceSelection() ||
976 // Changing unspecified always causes event (returning
977 // true here should be enough to trigger it).
978 property
->IsValueUnspecified()
981 return property
->IntToValue( variant
, index
, 0 );
987 void wxPGChoiceEditor::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, const wxString
& txt
) const
989 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
995 void wxPGChoiceEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
997 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
999 cb
->SetSelection(value
);
1003 void wxPGChoiceEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1005 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1006 cb
->SetSelection(-1);
1010 bool wxPGChoiceEditor::CanContainCustomImage() const
1016 wxPGChoiceEditor::~wxPGChoiceEditor() { }
1019 // -----------------------------------------------------------------------
1020 // wxPGComboBoxEditor
1021 // -----------------------------------------------------------------------
1024 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ComboBox
,
1029 void wxPGComboBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1031 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1032 cb
->SetValue(property
->GetValueAsString(wxPG_EDITABLE_VALUE
));
1034 // TODO: If string matches any selection, then select that.
1038 wxPGWindowList
wxPGComboBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1039 wxPGProperty
* property
,
1041 const wxSize
& sz
) const
1043 return CreateControlsBase(propGrid
,property
,pos
,sz
,0);
1047 bool wxPGComboBoxEditor::OnEvent( wxPropertyGrid
* propGrid
,
1048 wxPGProperty
* property
,
1050 wxEvent
& event
) const
1052 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*) NULL
;
1053 wxWindow
* textCtrl
= (wxWindow
*) NULL
;
1057 cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1058 textCtrl
= cb
->GetTextCtrl();
1061 if ( wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,textCtrl
,event
) )
1064 return wxPGChoiceEditor::OnEvent(propGrid
,property
,ctrl
,event
);
1068 bool wxPGComboBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1070 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1071 wxString textVal
= cb
->GetValue();
1073 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
1079 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
1081 // Changing unspecified always causes event (returning
1082 // true here should be enough to trigger it).
1083 if ( !res
&& variant
.IsNull() )
1090 void wxPGComboBoxEditor::OnFocus( wxPGProperty
*, wxWindow
* ctrl
) const
1092 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1093 cb
->GetTextCtrl()->SetSelection(-1,-1);
1097 wxPGComboBoxEditor::~wxPGComboBoxEditor() { }
1100 // -----------------------------------------------------------------------
1101 // wxPGChoiceAndButtonEditor
1102 // -----------------------------------------------------------------------
1105 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ChoiceAndButton
,
1106 wxPGChoiceAndButtonEditor
,
1110 wxPGWindowList
wxPGChoiceAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1111 wxPGProperty
* property
,
1113 const wxSize
& sz
) const
1115 // Use one two units smaller to match size of the combo's dropbutton.
1116 // (normally a bigger button is used because it looks better)
1119 wxSize
bt_sz(bt_wid
,bt_wid
);
1121 // Position of button.
1122 wxPoint
bt_pos(pos
.x
+sz
.x
-bt_sz
.x
,pos
.y
);
1129 wxWindow
* bt
= propGrid
->GenerateEditorButton( bt_pos
, bt_sz
);
1132 wxSize
ch_sz(sz
.x
-bt
->GetSize().x
,sz
.y
);
1135 ch_sz
.x
-= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1138 wxWindow
* ch
= wxPGEditor_Choice
->CreateControls(propGrid
,property
,
1139 pos
,ch_sz
).m_primary
;
1145 return wxPGWindowList(ch
, bt
);
1149 wxPGChoiceAndButtonEditor::~wxPGChoiceAndButtonEditor() { }
1152 // -----------------------------------------------------------------------
1153 // wxPGTextCtrlAndButtonEditor
1154 // -----------------------------------------------------------------------
1156 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrlAndButton
,
1157 wxPGTextCtrlAndButtonEditor
,
1161 wxPGWindowList
wxPGTextCtrlAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1162 wxPGProperty
* property
,
1164 const wxSize
& sz
) const
1167 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrlAndButton( pos
, sz
, &wnd2
,
1168 property
->GetFlags() & wxPG_PROP_NOEDITOR
, property
);
1170 return wxPGWindowList(wnd
, wnd2
);
1174 wxPGTextCtrlAndButtonEditor::~wxPGTextCtrlAndButtonEditor() { }
1177 // -----------------------------------------------------------------------
1178 // wxPGCheckBoxEditor
1179 // -----------------------------------------------------------------------
1181 #if wxPG_INCLUDE_CHECKBOX
1183 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(CheckBox
,
1188 // state argument: 0x01 = set if checked
1189 // 0x02 = set if rectangle should be bold
1190 static void DrawSimpleCheckBox( wxDC
& dc
, const wxRect
& rect
, int box_hei
, int state
, const wxColour
& linecol
)
1194 wxRect
r(rect
.x
+wxPG_XBEFORETEXT
,rect
.y
+((rect
.height
-box_hei
)/2),box_hei
,box_hei
);
1196 // Draw check mark first because it is likely to overdraw the
1197 // surrounding rectangle.
1200 wxRect
r2(r
.x
+wxPG_CHECKMARK_XADJ
,
1201 r
.y
+wxPG_CHECKMARK_YADJ
,
1202 r
.width
+wxPG_CHECKMARK_WADJ
,
1203 r
.height
+wxPG_CHECKMARK_HADJ
);
1204 #if wxPG_CHECKMARK_DEFLATE
1205 r2
.Deflate(wxPG_CHECKMARK_DEFLATE
);
1207 dc
.DrawCheckMark(r2
);
1209 // This would draw a simple cross check mark.
1210 // dc.DrawLine(r.x,r.y,r.x+r.width-1,r.y+r.height-1);
1211 // dc.DrawLine(r.x,r.y+r.height-1,r.x+r.width-1,r.y);
1217 // Pen for thin rectangle.
1222 // Pen for bold rectangle.
1223 wxPen
linepen(linecol
,2,wxSOLID
);
1224 linepen
.SetJoin(wxJOIN_MITER
); // This prevents round edges.
1232 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1234 dc
.DrawRectangle(r
);
1235 dc
.SetPen(*wxTRANSPARENT_PEN
);
1239 // Real simple custom-drawn checkbox-without-label class.
1241 class wxSimpleCheckBox
: public wxControl
1245 void SetValue( int value
);
1247 wxSimpleCheckBox( wxWindow
* parent
,
1249 const wxPoint
& pos
= wxDefaultPosition
,
1250 const wxSize
& size
= wxDefaultSize
)
1251 : wxControl(parent
,id
,pos
,size
,wxBORDER_NONE
|wxWANTS_CHARS
)
1253 // Due to SetOwnFont stuff necessary for GTK+ 1.2, we need to have this
1254 SetFont( parent
->GetFont() );
1257 wxPropertyGrid
* pg
= (wxPropertyGrid
*) parent
->GetParent();
1258 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1259 m_boxHeight
= pg
->GetFontHeight();
1260 SetBackgroundStyle( wxBG_STYLE_COLOUR
);
1263 virtual ~wxSimpleCheckBox();
1265 virtual bool ProcessEvent(wxEvent
& event
);
1270 static wxBitmap
* ms_doubleBuffer
;
1274 wxSimpleCheckBox::~wxSimpleCheckBox()
1276 delete ms_doubleBuffer
;
1277 ms_doubleBuffer
= NULL
;
1281 wxBitmap
* wxSimpleCheckBox::ms_doubleBuffer
= (wxBitmap
*) NULL
;
1283 // value = 2 means toggle (sorry, too lazy to do constants)
1284 void wxSimpleCheckBox::SetValue( int value
)
1289 if ( m_state
> 1 ) m_state
= 0;
1297 wxCommandEvent
evt(wxEVT_COMMAND_CHECKBOX_CLICKED
,GetParent()->GetId());
1299 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent()->GetParent();
1300 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1301 propGrid
->OnCustomEditorEvent(evt
);
1305 bool wxSimpleCheckBox::ProcessEvent(wxEvent
& event
)
1307 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent()->GetParent();
1308 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1310 if ( ( (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1311 && ((wxMouseEvent
&)event
).m_x
> (wxPG_XBEFORETEXT
-2)
1312 && ((wxMouseEvent
&)event
).m_x
<= (wxPG_XBEFORETEXT
-2+m_boxHeight
) )
1318 else if ( event
.GetEventType() == wxEVT_PAINT
)
1320 wxSize clientSize
= GetClientSize();
1324 // Buffered paint DC doesn't seem to do much good
1325 if ( !ms_doubleBuffer ||
1326 clientSize.x > ms_doubleBuffer->GetWidth() ||
1327 clientSize.y > ms_doubleBuffer->GetHeight() )
1329 delete ms_doubleBuffer;
1330 ms_doubleBuffer = new wxBitmap(clientSize.x+25,clientSize.y+25);
1333 wxBufferedPaintDC dc(this,*ms_doubleBuffer);
1336 wxRect
rect(0,0,clientSize
.x
,clientSize
.y
);
1341 m_boxHeight
= propGrid
->GetFontHeight();
1343 wxColour bgcol
= GetBackgroundColour();
1344 dc
.SetBrush( bgcol
);
1346 dc
.DrawRectangle( rect
);
1348 wxColour txcol
= GetForegroundColour();
1350 int state
= m_state
;
1351 if ( m_font
.GetWeight() == wxBOLD
)
1354 DrawSimpleCheckBox(dc
,rect
,m_boxHeight
,state
,txcol
);
1356 // If focused, indicate it somehow.
1358 if ( wxWindow::FindFocus() == this )
1363 wxPGDrawFocusRect(dc,rect);
1369 else if ( event
.GetEventType() == wxEVT_SIZE
||
1370 event
.GetEventType() == wxEVT_SET_FOCUS
||
1371 event
.GetEventType() == wxEVT_KILL_FOCUS
1376 else if ( event
.GetEventType() == wxEVT_KEY_DOWN
)
1378 wxKeyEvent
& keyEv
= (wxKeyEvent
&) event
;
1380 if ( keyEv
.GetKeyCode() == WXK_SPACE
)
1386 return wxControl::ProcessEvent(event
);
1390 wxPGWindowList
wxPGCheckBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1391 wxPGProperty
* property
,
1393 const wxSize
& size
) const
1396 pt
.x
-= wxPG_XBEFOREWIDGET
;
1398 sz
.x
= propGrid
->GetFontHeight() + (wxPG_XBEFOREWIDGET
*2) + 4;
1400 wxSimpleCheckBox
* cb
= new wxSimpleCheckBox(propGrid
->GetPanel(),wxPG_SUBID1
,pt
,sz
);
1402 cb
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
1404 cb
->Connect( wxPG_SUBID1
, wxEVT_LEFT_DOWN
,
1405 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
1406 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propGrid
);
1408 cb
->Connect( wxPG_SUBID1
, wxEVT_LEFT_DCLICK
,
1409 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
1410 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propGrid
);
1412 if ( property
->GetChoiceSelection() > 0 &&
1413 !property
->IsValueUnspecified() )
1416 // If mouse cursor was on the item, toggle the value now.
1417 if ( propGrid
->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK
)
1419 wxPoint pt
= cb
->ScreenToClient(::wxGetMousePosition());
1420 if ( pt
.x
<= (wxPG_XBEFORETEXT
-2+cb
->m_boxHeight
) )
1424 if ( cb
->m_state
> 1 )
1427 // Makes sure wxPG_EVT_CHANGING etc. is sent for this initial click
1428 propGrid
->ChangePropertyValue(property
, wxPGVariant_Bool(cb
->m_state
));
1432 propGrid
->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR
);
1438 class wxPGCheckBoxRenderer : public wxPGDefaultRenderer
1442 virtual void Render( wxDC& dc, const wxRect& rect,
1443 const wxPropertyGrid* WXUNUSED(propertyGrid), wxPGProperty* property,
1444 int WXUNUSED(column), int WXUNUSED(item), int WXUNUSED(flags) ) const
1447 if ( !(property->GetFlags() & wxPG_PROP_UNSPECIFIED) )
1449 state = ((wxPGProperty*)property)->GetChoiceInfo((wxPGChoiceInfo*)NULL);
1450 if ( dc.GetFont().GetWeight() == wxBOLD ) state |= 2;
1452 DrawSimpleCheckBox(dc,rect,dc.GetCharHeight(),state,dc.GetTextForeground());
1458 wxPGCheckBoxRenderer g_wxPGCheckBoxRenderer;
1460 wxPGCellRenderer* wxPGCheckBoxEditor::GetCellRenderer() const
1462 return &g_wxPGCheckBoxRenderer;
1466 void wxPGCheckBoxEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
, wxPGProperty
* property
, const wxString
& WXUNUSED(text
) ) const
1469 if ( !property
->IsValueUnspecified() )
1471 state
= property
->GetChoiceSelection();
1472 if ( dc
.GetFont().GetWeight() == wxBOLD
) state
|= 2;
1474 DrawSimpleCheckBox(dc
,rect
,dc
.GetCharHeight(),state
,dc
.GetTextForeground());
1477 void wxPGCheckBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1480 ((wxSimpleCheckBox
*)ctrl
)->m_state
= property
->GetChoiceSelection();
1485 bool wxPGCheckBoxEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propGrid
), wxPGProperty
* WXUNUSED(property
),
1486 wxWindow
* WXUNUSED(ctrl
), wxEvent
& event
) const
1488 if ( event
.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED
)
1496 bool wxPGCheckBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1498 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*)ctrl
;
1500 int index
= cb
->m_state
;
1502 if ( index
!= property
->GetChoiceSelection() ||
1503 // Changing unspecified always causes event (returning
1504 // true here should be enough to trigger it).
1505 property
->IsValueUnspecified()
1508 return property
->IntToValue(variant
, index
, 0);
1514 void wxPGCheckBoxEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1516 if ( value
!= 0 ) value
= 1;
1517 ((wxSimpleCheckBox
*)ctrl
)->m_state
= value
;
1522 void wxPGCheckBoxEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1524 ((wxSimpleCheckBox
*)ctrl
)->m_state
= 0;
1529 wxPGCheckBoxEditor::~wxPGCheckBoxEditor() { }
1532 #endif // wxPG_INCLUDE_CHECKBOX
1534 // -----------------------------------------------------------------------
1536 wxWindow
* wxPropertyGrid::GetEditorControl() const
1538 wxWindow
* ctrl
= m_wndEditor
;
1546 // -----------------------------------------------------------------------
1548 void wxPropertyGrid::CorrectEditorWidgetSizeX()
1550 if ( m_selColumn
== -1 )
1554 int newSplitterx
= m_pState
->DoGetSplitterPosition(m_selColumn
-1);
1555 int newWidth
= newSplitterx
+ m_pState
->m_colWidths
[m_selColumn
];
1559 // if width change occurred, move secondary wnd by that amount
1560 wxRect r
= m_wndEditor2
->GetRect();
1562 r
.x
= newWidth
- secWid
;
1564 m_wndEditor2
->SetSize( r
);
1566 // if primary is textctrl, then we have to add some extra space
1570 if ( m_wndEditor
&& m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1572 secWid
+= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1577 wxRect r
= m_wndEditor
->GetRect();
1579 r
.x
= newSplitterx
+m_ctrlXAdjust
;
1581 if ( !(m_iFlags
& wxPG_FL_FIXED_WIDTH_EDITOR
) )
1582 r
.width
= newWidth
- r
.x
- secWid
;
1584 m_wndEditor
->SetSize(r
);
1588 m_wndEditor2
->Refresh();
1591 // -----------------------------------------------------------------------
1593 void wxPropertyGrid::CorrectEditorWidgetPosY()
1595 if ( m_selected
&& (m_wndEditor
|| m_wndEditor2
) )
1597 wxRect r
= GetEditorWidgetRect(m_selected
, m_selColumn
);
1601 wxPoint pos
= m_wndEditor
->GetPosition();
1603 // Calculate y offset
1604 int offset
= pos
.y
% m_lineHeight
;
1606 m_wndEditor
->Move(pos
.x
, r
.y
+ offset
);
1611 wxPoint pos
= m_wndEditor2
->GetPosition();
1613 m_wndEditor2
->Move(pos
.x
, r
.y
);
1618 // -----------------------------------------------------------------------
1620 // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
1621 // fits into that category as well).
1622 void wxPropertyGrid::FixPosForTextCtrl( wxWindow
* ctrl
, const wxPoint
& offset
)
1624 // Center the control vertically
1625 wxRect finalPos
= ctrl
->GetRect();
1626 int y_adj
= (m_lineHeight
- finalPos
.height
)/2 + wxPG_TEXTCTRLYADJUST
;
1628 // Prevent over-sized control
1629 int sz_dec
= (y_adj
+ finalPos
.height
) - m_lineHeight
;
1630 if ( sz_dec
< 0 ) sz_dec
= 0;
1632 finalPos
.y
+= y_adj
;
1633 finalPos
.height
-= (y_adj
+sz_dec
);
1635 const int textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
;
1637 finalPos
.x
+= textCtrlXAdjust
;
1638 finalPos
.width
-= textCtrlXAdjust
;
1640 finalPos
.x
+= offset
.x
;
1641 finalPos
.y
+= offset
.y
;
1643 ctrl
->SetSize(finalPos
);
1646 // -----------------------------------------------------------------------
1648 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint
& pos
,
1650 const wxString
& value
,
1651 wxWindow
* secondary
,
1655 wxWindowID id
= wxPG_SUBID1
;
1656 wxPGProperty
* selected
= m_selected
;
1659 int tcFlags
= wxTE_PROCESS_ENTER
| extraStyle
;
1661 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1662 tcFlags
|= wxTE_READONLY
;
1664 wxPoint
p(pos
.x
,pos
.y
);
1665 wxSize
s(sz
.x
,sz
.y
);
1667 // Need to reduce width of text control on Mac
1668 #if defined(__WXMAC__)
1672 // Take button into acccount
1675 s
.x
-= (secondary
->GetSize().x
+ wxPG_TEXTCTRL_AND_BUTTON_SPACING
);
1676 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
1679 // If the height is significantly higher, then use border, and fill the rect exactly.
1680 bool hasSpecialSize
= false;
1682 if ( (sz
.y
- m_lineHeight
) > 5 )
1683 hasSpecialSize
= true;
1685 wxWindow
* ctrlParent
= GetPanel();
1687 if ( !hasSpecialSize
)
1688 tcFlags
|= wxBORDER_NONE
;
1690 wxTextCtrl
* tc
= new wxTextCtrl();
1692 #if defined(__WXMSW__)
1695 SetupTextCtrlValue(value
);
1696 tc
->Create(ctrlParent
,id
,value
, p
, s
,tcFlags
);
1700 // Center the control vertically
1701 if ( !hasSpecialSize
)
1702 FixPosForTextCtrl(ed
);
1710 // Set maximum length
1712 tc
->SetMaxLength( maxLen
);
1714 // Connect event handling
1716 this->Connect(id
, wxEVT_COMMAND_TEXT_UPDATED
,
1717 wxEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1718 this->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
1719 wxEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1721 return (wxWindow
*) ed
;
1724 // -----------------------------------------------------------------------
1726 wxWindow
* wxPropertyGrid::GenerateEditorButton( const wxPoint
& pos
, const wxSize
& sz
)
1728 wxWindowID id
= wxPG_SUBID2
;
1729 wxPGProperty
* selected
= m_selected
;
1733 // Decorations are chunky on Mac, and we can't make the button square, so
1734 // do things a bit differently on this platform.
1736 wxPoint
p(pos
.x
+sz
.x
,
1737 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1740 wxButton
* but
= new wxButton();
1741 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1743 // Now that we know the size, move to the correct position
1744 p
.x
= pos
.x
+ sz
.x
- but
->GetSize().x
- 2;
1748 wxSize
s(sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2),
1749 sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2));
1751 // Reduce button width to lineheight
1752 if ( s
.x
> m_lineHeight
)
1756 // On wxGTK, take fixed button margins into account
1761 wxPoint
p(pos
.x
+sz
.x
-s
.x
,
1762 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1764 wxButton
* but
= new wxButton();
1768 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1771 wxFont font
= GetFont();
1772 font
.SetPointSize(font
.GetPointSize()-2);
1775 but
->SetFont(GetFont());
1779 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1782 // Connect event handling
1784 this->Connect(id
, wxEVT_COMMAND_BUTTON_CLICKED
,
1785 wxEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1790 // -----------------------------------------------------------------------
1792 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrlAndButton( const wxPoint
& pos
,
1794 wxWindow
** psecondary
,
1796 wxPGProperty
* property
)
1798 wxButton
* but
= (wxButton
*)GenerateEditorButton(pos
,sz
);
1799 *psecondary
= (wxWindow
*)but
;
1801 if ( limitedEditing
)
1804 // There is button Show in GenerateEditorTextCtrl as well
1807 return (wxWindow
*) NULL
;
1812 if ( !property
->IsValueUnspecified() )
1813 text
= property
->GetValueAsString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
1815 return GenerateEditorTextCtrl(pos
,sz
,text
,but
,property
->m_maxLen
);
1818 // -----------------------------------------------------------------------
1820 wxTextCtrl
* wxPropertyGrid::GetEditorTextCtrl() const
1822 wxWindow
* wnd
= GetEditorControl();
1827 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1828 return wxStaticCast(wnd
, wxTextCtrl
);
1830 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
1832 wxOwnerDrawnComboBox
* cb
= wxStaticCast(wnd
, wxOwnerDrawnComboBox
);
1833 return cb
->GetTextCtrl();
1839 // -----------------------------------------------------------------------
1841 wxPGEditor
* wxPropertyGridInterface::GetEditorByName( const wxString
& editorName
)
1843 wxPGHashMapS2P::const_iterator it
;
1845 it
= wxPGGlobalVars
->m_mapEditorClasses
.find(editorName
);
1846 if ( it
== wxPGGlobalVars
->m_mapEditorClasses
.end() )
1848 return (wxPGEditor
*) it
->second
;
1851 // -----------------------------------------------------------------------
1852 // wxPGEditorDialogAdapter
1853 // -----------------------------------------------------------------------
1855 IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter
, wxObject
)
1857 bool wxPGEditorDialogAdapter::ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
1859 if ( !propGrid
->EditorValidate() )
1862 bool res
= DoShowDialog( propGrid
, property
);
1866 propGrid
->ValueChangeInEvent( m_value
);
1873 // -----------------------------------------------------------------------
1875 // -----------------------------------------------------------------------
1877 wxPGMultiButton::wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
)
1878 : wxWindow( pg
->GetPanel(), wxPG_SUBID2
, wxPoint(-100,-100), wxSize(0, sz
.y
) ),
1879 m_fullEditorSize(sz
), m_buttonsWidth(0)
1881 SetBackgroundColour(pg
->GetCellBackgroundColour());
1884 void wxPGMultiButton::Finalize( wxPropertyGrid
* propGrid
, const wxPoint
& pos
)
1886 Move( pos
.x
+ m_fullEditorSize
.x
- m_buttonsWidth
, pos
.y
);
1888 // Connect event handling
1889 for ( unsigned int i
=0; i
<GetCount(); i
++ )
1891 wxWindowID id
= GetButtonId(i
);
1892 propGrid
->Connect(id
, wxEVT_COMMAND_BUTTON_CLICKED
,
1893 wxEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1897 int wxPGMultiButton::GenId( int id
) const
1901 if ( m_buttons
.size() )
1902 id
= GetButton(m_buttons
.size()-1)->GetId() + 1;
1910 void wxPGMultiButton::Add( const wxBitmap
& bitmap
, int id
)
1913 wxSize sz
= GetSize();
1914 wxButton
* button
= new wxBitmapButton( this, id
, bitmap
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
1915 m_buttons
.push_back(button
);
1916 int bw
= button
->GetSize().x
;
1917 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
1918 m_buttonsWidth
+= bw
;
1922 void wxPGMultiButton::Add( const wxString
& label
, int id
)
1925 wxSize sz
= GetSize();
1926 wxButton
* button
= new wxButton( this, id
, label
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
1927 m_buttons
.push_back(button
);
1928 int bw
= button
->GetSize().x
;
1929 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
1930 m_buttonsWidth
+= bw
;
1933 // -----------------------------------------------------------------------
1935 #endif // wxUSE_PROPGRID