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 8
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 3
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
145 #define wxPG_CHOICEXADJUST 0
146 #define wxPG_CHOICEYADJUST 0
148 #define ODCB_CUST_PAINT_MARGIN 6 // Number added to image width for SetCustomPaintWidth
150 // Milliseconds to wait for two mouse-ups after focus inorder
151 // to trigger a double-click.
152 #define DOUBLE_CLICK_CONVERSION_TRESHOLD 500
154 // -----------------------------------------------------------------------
156 // -----------------------------------------------------------------------
158 IMPLEMENT_ABSTRACT_CLASS(wxPGEditor
, wxObject
)
161 wxPGEditor::~wxPGEditor()
165 void wxPGEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
, wxPGProperty
* property
, const wxString
& text
) const
167 if ( !property
->IsValueUnspecified() )
168 dc
.DrawText( text
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
171 bool wxPGEditor::GetValueFromControl( wxVariant
&, wxPGProperty
*, wxWindow
* ) const
176 void wxPGEditor::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, const wxString
& ) const
181 void wxPGEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, int ) const
186 int wxPGEditor::InsertItem( wxWindow
*, const wxString
&, int ) const
192 void wxPGEditor::DeleteItem( wxWindow
*, int ) const
198 void wxPGEditor::OnFocus( wxPGProperty
*, wxWindow
* ) const
203 bool wxPGEditor::CanContainCustomImage() const
208 // -----------------------------------------------------------------------
209 // wxPGTextCtrlEditor
210 // -----------------------------------------------------------------------
212 WX_PG_IMPLEMENT_EDITOR_CLASS(TextCtrl
,wxPGTextCtrlEditor
,wxPGEditor
)
215 wxPGWindowList
wxPGTextCtrlEditor::CreateControls( wxPropertyGrid
* propGrid
,
216 wxPGProperty
* property
,
218 const wxSize
& sz
) const
223 // If has children, and limited editing is specified, then don't create.
224 if ( (property
->GetFlags() & wxPG_PROP_NOEDITOR
) &&
225 property
->GetChildCount() )
226 return (wxWindow
*) NULL
;
228 if ( !property
->IsValueUnspecified() )
229 text
= property
->GetValueString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
232 if ( (property
->GetFlags() & wxPG_PROP_PASSWORD
) &&
233 property
->IsKindOf(CLASSINFO(wxStringProperty
)) )
234 flags
|= wxTE_PASSWORD
;
236 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrl(pos
,sz
,text
,(wxWindow
*)NULL
,flags
,
237 property
->GetMaxLength());
243 void wxPGTextCtrlEditor::DrawValue( wxDC
& dc
, wxPGProperty
* property
, const wxRect
& rect
) const
245 if ( !property
->IsValueUnspecified() )
247 wxString drawStr
= property
->GetDisplayedString();
249 // Code below should no longer be needed, as the obfuscation
250 // is now done in GetValueAsString.
251 /*if ( (property->GetFlags() & wxPG_PROP_PASSWORD) &&
252 property->IsKindOf(WX_PG_CLASSINFO(wxStringProperty)) )
254 size_t a = drawStr.length();
256 drawStr.Append(wxS('*'),a);
258 dc
.DrawText( drawStr
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
263 void wxPGTextCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
265 wxTextCtrl
* tc
= wxDynamicCast(ctrl
, wxTextCtrl
);
270 if ( tc
->HasFlag(wxTE_PASSWORD
) )
271 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
273 s
= property
->GetDisplayedString();
279 // Provided so that, for example, ComboBox editor can use the same code
280 // (multiple inheritance would get way too messy).
281 bool wxPGTextCtrlEditor::OnTextCtrlEvent( wxPropertyGrid
* propGrid
,
282 wxPGProperty
* WXUNUSED(property
),
289 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
291 if ( propGrid
->IsEditorsValueModified() )
296 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
299 // Pass this event outside wxPropertyGrid so that,
300 // if necessary, program can tell when user is editing
302 // FIXME: Is it safe to change event id in the middle of event
303 // processing (seems to work, but...)?
305 event
.SetId(propGrid
->GetId());
307 propGrid
->EditorsValueWasModified();
313 bool wxPGTextCtrlEditor::OnEvent( wxPropertyGrid
* propGrid
,
314 wxPGProperty
* property
,
316 wxEvent
& event
) const
318 return wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,ctrl
,event
);
322 bool wxPGTextCtrlEditor::GetTextCtrlValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
)
324 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
325 wxString textVal
= tc
->GetValue();
327 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
333 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
335 // Changing unspecified always causes event (returning
336 // true here should be enough to trigger it).
337 // TODO: Move to propgrid.cpp
338 if ( !res
&& variant
.IsNull() )
345 bool wxPGTextCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
347 return wxPGTextCtrlEditor::GetTextCtrlValueFromControl(variant
, property
, ctrl
);
351 void wxPGTextCtrlEditor::SetValueToUnspecified( wxPGProperty
* property
, wxWindow
* ctrl
) const
353 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
355 wxPropertyGrid
* pg
= property
->GetGrid();
356 wxASSERT(pg
); // Really, property grid should exist if editor does
358 tc
->SetValue(wxEmptyString
);
362 void wxPGTextCtrlEditor::SetControlStringValue( wxPGProperty
* property
, wxWindow
* ctrl
, const wxString
& txt
) const
364 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
366 wxPropertyGrid
* pg
= property
->GetGrid();
367 wxASSERT(pg
); // Really, property grid should exist if editor does
373 void wxPGTextCtrlEditor::OnFocus( wxPGProperty
*, wxWindow
* wnd
) const
375 wxTextCtrl
* tc
= wxStaticCast(wnd
, wxTextCtrl
);
377 tc
->SetSelection(-1,-1);
381 wxPGTextCtrlEditor::~wxPGTextCtrlEditor() { }
384 // -----------------------------------------------------------------------
386 // -----------------------------------------------------------------------
389 WX_PG_IMPLEMENT_EDITOR_CLASS(Choice
,wxPGChoiceEditor
,wxPGEditor
)
392 // This is a special enhanced double-click processor class.
393 // In essence, it allows for double-clicks for which the
394 // first click "created" the control.
395 class wxPGDoubleClickProcessor
: public wxEvtHandler
399 wxPGDoubleClickProcessor( wxOwnerDrawnComboBox
* combo
, wxPGProperty
* property
)
402 m_timeLastMouseUp
= 0;
404 m_property
= property
;
405 m_downReceived
= false;
410 void OnMouseEvent( wxMouseEvent
& event
)
412 wxLongLong t
= ::wxGetLocalTimeMillis();
413 int evtType
= event
.GetEventType();
415 if ( m_property
->HasFlag(wxPG_PROP_USE_DCC
) &&
416 m_property
->IsKindOf(CLASSINFO(wxBoolProperty
)) &&
417 !m_combo
->IsPopupShown() )
419 // Just check that it is in the text area
420 wxPoint pt
= event
.GetPosition();
421 if ( m_combo
->GetTextRect().Contains(pt
) )
423 if ( evtType
== wxEVT_LEFT_DOWN
)
425 // Set value to avoid up-events without corresponding downs
426 m_downReceived
= true;
428 else if ( evtType
== wxEVT_LEFT_DCLICK
)
430 // We'll make our own double-clicks
431 event
.SetEventType(0);
434 else if ( evtType
== wxEVT_LEFT_UP
)
436 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
438 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
440 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
442 event
.SetEventType(wxEVT_LEFT_DCLICK
);
443 m_timeLastMouseUp
= 1;
447 m_timeLastMouseUp
= t
;
457 void OnSetFocus( wxFocusEvent
& event
)
459 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
464 wxLongLong m_timeLastMouseUp
;
465 wxOwnerDrawnComboBox
* m_combo
;
466 wxPGProperty
* m_property
; // Selected property
469 DECLARE_EVENT_TABLE()
472 BEGIN_EVENT_TABLE(wxPGDoubleClickProcessor
, wxEvtHandler
)
473 EVT_MOUSE_EVENTS(wxPGDoubleClickProcessor::OnMouseEvent
)
474 EVT_SET_FOCUS(wxPGDoubleClickProcessor::OnSetFocus
)
479 class wxPGComboBox
: public wxOwnerDrawnComboBox
484 : wxOwnerDrawnComboBox()
486 m_dclickProcessor
= (wxPGDoubleClickProcessor
*) NULL
;
487 m_sizeEventCalled
= false;
492 if ( m_dclickProcessor
)
494 RemoveEventHandler(m_dclickProcessor
);
495 delete m_dclickProcessor
;
499 bool Create(wxWindow
*parent
,
501 const wxString
& value
,
504 const wxArrayString
& choices
,
506 const wxValidator
& validator
= wxDefaultValidator
,
507 const wxString
& name
= wxS("wxOwnerDrawnComboBox"))
509 if ( !wxOwnerDrawnComboBox::Create( parent
,
520 m_dclickProcessor
= new wxPGDoubleClickProcessor(this, GetGrid()->GetSelection() );
522 PushEventHandler(m_dclickProcessor
);
527 virtual void OnDrawItem( wxDC
& dc
, const wxRect
& rect
, int item
, int flags
) const
529 wxPropertyGrid
* pg
= GetGrid();
530 pg
->OnComboItemPaint((wxPGCustomComboControl
*)this,item
,dc
,(wxRect
&)rect
,flags
);
532 virtual wxCoord
OnMeasureItem( size_t item
) const
534 wxPropertyGrid
* pg
= GetGrid();
538 pg
->OnComboItemPaint((wxPGCustomComboControl
*)this,item
,*((wxDC
*)NULL
),rect
,0);
542 wxPropertyGrid
* GetGrid() const
544 wxPropertyGrid
* pg
= wxDynamicCast(GetParent()->GetParent(),wxPropertyGrid
);
549 virtual wxCoord
OnMeasureItemWidth( size_t item
) const
551 wxPropertyGrid
* pg
= GetGrid();
555 pg
->OnComboItemPaint((wxPGCustomComboControl
*)this,item
,*((wxDC
*)NULL
),rect
,0);
559 virtual void PositionTextCtrl( int WXUNUSED(textCtrlXAdjust
), int WXUNUSED(textCtrlYAdjust
) )
561 wxPropertyGrid
* pg
= GetGrid();
562 wxOwnerDrawnComboBox::PositionTextCtrl(
563 wxPG_TEXTCTRLXADJUST
- (wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1) - 1,
564 pg
->GetSpacingY() + 2
569 wxPGDoubleClickProcessor
* m_dclickProcessor
;
570 bool m_sizeEventCalled
;
574 void wxPropertyGrid::OnComboItemPaint( wxPGCustomComboControl
* pCc
,
580 wxPGComboBox
* pCb
= (wxPGComboBox
*)pCc
;
583 wxASSERT( IsKindOf(CLASSINFO(wxPropertyGrid
)) );
585 wxPGProperty
* p
= m_selected
;
588 const wxPGChoices
& choices
= p
->GetChoices();
589 const wxPGCommonValue
* comVal
= NULL
;
590 int comVals
= p
->GetDisplayedCommonValueCount();
591 int comValIndex
= -1;
594 if ( choices
.IsOk() )
595 choiceCount
= choices
.GetCount();
597 if ( item
>= choiceCount
&& comVals
> 0 )
599 comValIndex
= item
- choiceCount
;
600 comVal
= GetCommonValue(comValIndex
);
601 if ( !p
->IsValueUnspecified() )
602 text
= comVal
->GetLabel();
606 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
608 text
= pCb
->GetString(item
);
612 if ( !p
->IsValueUnspecified() )
613 text
= p
->GetValueString(0);
622 const wxBitmap
* itemBitmap
= NULL
;
624 if ( item
>= 0 && choices
.IsOk() && choices
.Item(item
).GetBitmap().Ok() && comValIndex
== -1 )
625 itemBitmap
= &choices
.Item(item
).GetBitmap();
628 // Decide what custom image size to use
631 cis
.x
= itemBitmap
->GetWidth();
632 cis
.y
= itemBitmap
->GetHeight();
636 cis
= GetImageSize(p
, item
);
641 // Default measure behaviour (no flexible, custom paint image only)
642 if ( rect
.width
< 0 )
645 GetTextExtent(text
, &x
, &y
, 0, 0, &m_font
);
646 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9 + x
;
649 rect
.height
= cis
.y
+ 2;
653 wxPGPaintData paintdata
;
654 paintdata
.m_parent
= NULL
;
655 paintdata
.m_choiceItem
= item
;
657 // This is by the current (1.0.0b) spec - if painting control, item is -1
658 if ( (flags
& wxODCB_PAINTING_CONTROL
) )
659 paintdata
.m_choiceItem
= -1;
662 dc
.SetBrush(*wxWHITE_BRUSH
);
669 wxPoint
pt(rect
.x
+ wxPG_CONTROL_MARGIN
- wxPG_CHOICEXADJUST
- 1,
674 if ( flags
& wxODCB_PAINTING_CONTROL
)
675 renderFlags
|= wxPGCellRenderer::Control
;
677 if ( flags
& wxODCB_PAINTING_SELECTED
)
678 renderFlags
|= wxPGCellRenderer::Selected
;
680 if ( cis
.x
> 0 && (p
->HasFlag(wxPG_PROP_CUSTOMIMAGE
) || !(flags
& wxODCB_PAINTING_CONTROL
)) &&
681 ( !p
->m_valueBitmap
|| item
== pCb
->GetSelection() ) &&
682 ( item
>= 0 || (flags
& wxODCB_PAINTING_CONTROL
) ) &&
686 pt
.x
+= wxCC_CUSTOM_IMAGE_MARGIN1
;
687 wxRect
r(pt
.x
,pt
.y
,cis
.x
,cis
.y
);
689 if ( flags
& wxODCB_PAINTING_CONTROL
)
692 r
.height
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
695 paintdata
.m_drawnWidth
= r
.width
;
697 dc
.SetPen(m_colPropFore
);
698 if ( comValIndex
>= 0 )
700 const wxPGCommonValue
* cv
= GetCommonValue(comValIndex
);
701 wxPGCellRenderer
* renderer
= cv
->GetRenderer();
702 r
.width
= rect
.width
;
703 renderer
->Render( dc
, r
, this, p
, m_selColumn
, comValIndex
, renderFlags
);
706 else if ( item
>= 0 )
708 p
->OnCustomPaint( dc
, r
, paintdata
);
712 dc
.DrawRectangle( r
);
715 pt
.x
+= paintdata
.m_drawnWidth
+ wxCC_CUSTOM_IMAGE_MARGIN2
- 1;
719 // TODO: This aligns text so that it seems to be horizontally
720 // on the same line as property values. Not really
721 // sure if its needed, but seems to not cause any harm.
724 if ( item
< 0 && (flags
& wxODCB_PAINTING_CONTROL
) )
725 item
= pCb
->GetSelection();
727 if ( choices
.IsOk() && item
>= 0 && comValIndex
< 0 )
729 const wxPGChoiceEntry
& cell
= choices
.Item(item
);
730 wxPGCellRenderer
* renderer
= wxPGGlobalVars
->m_defaultRenderer
;
731 int imageOffset
= renderer
->PreDrawCell( dc
, rect
, cell
, renderFlags
);
733 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
742 pt
.y
+= (rect
.height
-m_fontHeight
)/2 - 1;
746 dc
.DrawText( text
, pt
.x
+ wxPG_XBEFORETEXT
, pt
.y
);
753 p
->OnCustomPaint( dc
, rect
, paintdata
);
754 rect
.height
= paintdata
.m_drawnHeight
+ 2;
755 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9;
759 bool wxPGChoiceEditor_SetCustomPaintWidth( wxPropertyGrid
* propGrid
, wxPGComboBox
* cb
, int cmnVal
)
761 wxPGProperty
* property
= propGrid
->GetSelectedProperty();
762 wxASSERT( property
);
766 // Yes, a common value is being selected
767 property
->SetCommonValue( cmnVal
);
768 wxSize imageSize
= propGrid
->GetCommonValue(cmnVal
)->
769 GetRenderer()->GetImageSize(property
, 1, cmnVal
);
770 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
771 cb
->SetCustomPaintWidth( imageSize
.x
);
776 wxSize imageSize
= propGrid
->GetImageSize(property
, -1);
777 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
778 cb
->SetCustomPaintWidth( imageSize
.x
);
783 // CreateControls calls this with CB_READONLY in extraStyle
784 wxWindow
* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid
* propGrid
,
785 wxPGProperty
* property
,
788 long extraStyle
) const
790 const wxPGChoices
& choices
= property
->GetChoices();
792 int index
= property
->GetChoiceSelection();
794 bool isUnspecified
= property
->IsValueUnspecified();
796 if ( !isUnspecified
)
797 defString
= property
->GetDisplayedString();
799 wxArrayString labels
= choices
.GetLabels();
805 po
.y
+= wxPG_CHOICEYADJUST
;
806 si
.y
-= (wxPG_CHOICEYADJUST
*2);
808 po
.x
+= wxPG_CHOICEXADJUST
;
809 si
.x
-= wxPG_CHOICEXADJUST
;
810 wxWindow
* ctrlParent
= propGrid
->GetPanel();
812 int odcbFlags
= extraStyle
| wxBORDER_NONE
| wxTE_PROCESS_ENTER
;
815 // If common value specified, use appropriate index
816 unsigned int cmnVals
= property
->GetDisplayedCommonValueCount();
819 if ( !isUnspecified
)
821 int cmnVal
= property
->GetCommonValue();
824 index
= labels
.size() + cmnVal
;
829 for ( i
=0; i
<cmnVals
; i
++ )
830 labels
.Add(propGrid
->GetCommonValueLabel(i
));
833 cb
= new wxPGComboBox();
837 cb
->Create(ctrlParent
,
845 cb
->SetButtonPosition(si
.y
,0,wxRIGHT
);
846 cb
->SetTextIndent(wxPG_XBEFORETEXT
-1);
848 wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, property
->GetCommonValue() );
850 if ( index
>= 0 && index
< (int)cb
->GetCount() )
852 cb
->SetSelection( index
);
853 if ( defString
.length() )
854 cb
->SetText( defString
);
856 else if ( !(extraStyle
& wxCB_READONLY
) && defString
.length() )
857 cb
->SetValue( defString
);
859 cb
->SetSelection( -1 );
861 // Connect event handling
862 wxWindowID id
= cb
->GetId();
863 propGrid
->Connect(id
, wxEVT_COMMAND_COMBOBOX_SELECTED
,
864 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
865 propGrid
->Connect(id
, wxEVT_COMMAND_TEXT_UPDATED
,
866 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
867 propGrid
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
868 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
874 return (wxWindow
*) cb
;
878 void wxPGChoiceEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
881 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
882 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
883 int ind
= property
->GetChoiceSelection();
884 cb
->SetSelection(ind
);
887 wxPGWindowList
wxPGChoiceEditor::CreateControls( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
888 const wxPoint
& pos
, const wxSize
& sz
) const
890 return CreateControlsBase(propGrid
,property
,pos
,sz
,wxCB_READONLY
);
894 int wxPGChoiceEditor::InsertItem( wxWindow
* ctrl
, const wxString
& label
, int index
) const
897 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
898 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
901 index
= cb
->GetCount();
903 return cb
->Insert(label
,index
);
907 void wxPGChoiceEditor::DeleteItem( wxWindow
* ctrl
, int index
) const
910 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
911 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
916 bool wxPGChoiceEditor::OnEvent( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
917 wxWindow
* ctrl
, wxEvent
& event
) const
919 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
921 wxPGComboBox
* cb
= (wxPGComboBox
*)ctrl
;
922 int index
= cb
->GetSelection();
923 int cmnValIndex
= -1;
924 int cmnVals
= property
->GetDisplayedCommonValueCount();
925 int items
= cb
->GetCount();
927 if ( index
>= (items
-cmnVals
) )
929 // Yes, a common value is being selected
930 cmnValIndex
= index
- (items
-cmnVals
);
931 property
->SetCommonValue( cmnValIndex
);
933 // Truly set value to unspecified?
934 if ( propGrid
->GetUnspecifiedCommonValue() == cmnValIndex
)
936 if ( !property
->IsValueUnspecified() )
937 propGrid
->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT
);
938 property
->SetValueToUnspecified();
939 if ( !cb
->HasFlag(wxCB_READONLY
) )
940 cb
->GetTextCtrl()->SetValue(wxEmptyString
);
944 return wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, cmnValIndex
);
950 bool wxPGChoiceEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
952 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
954 int index
= cb
->GetSelection();
956 if ( index
!= property
->GetChoiceSelection() ||
957 // Changing unspecified always causes event (returning
958 // true here should be enough to trigger it).
959 property
->IsValueUnspecified()
962 return property
->IntToValue( variant
, index
, 0 );
968 void wxPGChoiceEditor::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, const wxString
& txt
) const
970 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
976 void wxPGChoiceEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
978 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
980 cb
->SetSelection(value
);
984 void wxPGChoiceEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
986 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
987 cb
->SetSelection(-1);
991 bool wxPGChoiceEditor::CanContainCustomImage() const
997 wxPGChoiceEditor::~wxPGChoiceEditor() { }
1000 // -----------------------------------------------------------------------
1001 // wxPGComboBoxEditor
1002 // -----------------------------------------------------------------------
1005 WX_PG_IMPLEMENT_EDITOR_CLASS(ComboBox
,wxPGComboBoxEditor
,wxPGChoiceEditor
)
1008 void wxPGComboBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1010 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1011 cb
->SetValue(property
->GetValueString(wxPG_EDITABLE_VALUE
));
1013 // TODO: If string matches any selection, then select that.
1017 wxPGWindowList
wxPGComboBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1018 wxPGProperty
* property
,
1020 const wxSize
& sz
) const
1022 return CreateControlsBase(propGrid
,property
,pos
,sz
,0);
1026 bool wxPGComboBoxEditor::OnEvent( wxPropertyGrid
* propGrid
,
1027 wxPGProperty
* property
,
1029 wxEvent
& event
) const
1031 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*) NULL
;
1032 wxWindow
* textCtrl
= (wxWindow
*) NULL
;
1036 cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1037 textCtrl
= cb
->GetTextCtrl();
1040 if ( wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,textCtrl
,event
) )
1043 return wxPGChoiceEditor::OnEvent(propGrid
,property
,ctrl
,event
);
1047 bool wxPGComboBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1049 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1050 wxString textVal
= cb
->GetValue();
1052 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
1058 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
1060 // Changing unspecified always causes event (returning
1061 // true here should be enough to trigger it).
1062 if ( !res
&& variant
.IsNull() )
1069 void wxPGComboBoxEditor::OnFocus( wxPGProperty
*, wxWindow
* ctrl
) const
1071 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1072 cb
->GetTextCtrl()->SetSelection(-1,-1);
1076 wxPGComboBoxEditor::~wxPGComboBoxEditor() { }
1079 // -----------------------------------------------------------------------
1080 // wxPGChoiceAndButtonEditor
1081 // -----------------------------------------------------------------------
1084 // This simpler implement_editor macro doesn't define class body.
1085 WX_PG_IMPLEMENT_EDITOR_CLASS(ChoiceAndButton
,wxPGChoiceAndButtonEditor
,wxPGChoiceEditor
)
1088 wxPGWindowList
wxPGChoiceAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1089 wxPGProperty
* property
,
1091 const wxSize
& sz
) const
1093 // Use one two units smaller to match size of the combo's dropbutton.
1094 // (normally a bigger button is used because it looks better)
1097 wxSize
bt_sz(bt_wid
,bt_wid
);
1099 // Position of button.
1100 wxPoint
bt_pos(pos
.x
+sz
.x
-bt_sz
.x
,pos
.y
);
1107 wxWindow
* bt
= propGrid
->GenerateEditorButton( bt_pos
, bt_sz
);
1110 wxSize
ch_sz(sz
.x
-bt
->GetSize().x
,sz
.y
);
1113 ch_sz
.x
-= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1116 wxWindow
* ch
= wxPG_EDITOR(Choice
)->CreateControls(propGrid
,property
,
1117 pos
,ch_sz
).m_primary
;
1123 return wxPGWindowList(ch
, bt
);
1127 wxPGChoiceAndButtonEditor::~wxPGChoiceAndButtonEditor() { }
1130 // -----------------------------------------------------------------------
1131 // wxPGTextCtrlAndButtonEditor
1132 // -----------------------------------------------------------------------
1135 // This simpler implement_editor macro doesn't define class body.
1136 WX_PG_IMPLEMENT_EDITOR_CLASS(TextCtrlAndButton
,wxPGTextCtrlAndButtonEditor
,wxPGTextCtrlEditor
)
1139 wxPGWindowList
wxPGTextCtrlAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1140 wxPGProperty
* property
,
1142 const wxSize
& sz
) const
1145 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrlAndButton( pos
, sz
, &wnd2
,
1146 property
->GetFlags() & wxPG_PROP_NOEDITOR
, property
);
1148 return wxPGWindowList(wnd
, wnd2
);
1152 wxPGTextCtrlAndButtonEditor::~wxPGTextCtrlAndButtonEditor() { }
1155 // -----------------------------------------------------------------------
1156 // wxPGCheckBoxEditor
1157 // -----------------------------------------------------------------------
1159 #if wxPG_INCLUDE_CHECKBOX
1161 WX_PG_IMPLEMENT_EDITOR_CLASS(CheckBox
,wxPGCheckBoxEditor
,wxPGEditor
)
1164 // state argument: 0x01 = set if checked
1165 // 0x02 = set if rectangle should be bold
1166 static void DrawSimpleCheckBox( wxDC
& dc
, const wxRect
& rect
, int box_hei
, int state
, const wxColour
& linecol
)
1170 wxRect
r(rect
.x
+wxPG_XBEFORETEXT
,rect
.y
+((rect
.height
-box_hei
)/2),box_hei
,box_hei
);
1172 // Draw check mark first because it is likely to overdraw the
1173 // surrounding rectangle.
1176 wxRect
r2(r
.x
+wxPG_CHECKMARK_XADJ
,
1177 r
.y
+wxPG_CHECKMARK_YADJ
,
1178 r
.width
+wxPG_CHECKMARK_WADJ
,
1179 r
.height
+wxPG_CHECKMARK_HADJ
);
1180 #if wxPG_CHECKMARK_DEFLATE
1181 r2
.Deflate(wxPG_CHECKMARK_DEFLATE
);
1183 dc
.DrawCheckMark(r2
);
1185 // This would draw a simple cross check mark.
1186 // dc.DrawLine(r.x,r.y,r.x+r.width-1,r.y+r.height-1);
1187 // dc.DrawLine(r.x,r.y+r.height-1,r.x+r.width-1,r.y);
1193 // Pen for thin rectangle.
1198 // Pen for bold rectangle.
1199 wxPen
linepen(linecol
,2,wxSOLID
);
1200 linepen
.SetJoin(wxJOIN_MITER
); // This prevents round edges.
1208 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1210 dc
.DrawRectangle(r
);
1211 dc
.SetPen(*wxTRANSPARENT_PEN
);
1215 // Real simple custom-drawn checkbox-without-label class.
1217 class wxSimpleCheckBox
: public wxControl
1221 void SetValue( int value
);
1223 wxSimpleCheckBox( wxWindow
* parent
,
1225 const wxPoint
& pos
= wxDefaultPosition
,
1226 const wxSize
& size
= wxDefaultSize
)
1227 : wxControl(parent
,id
,pos
,size
,wxBORDER_NONE
|wxWANTS_CHARS
)
1229 // Due to SetOwnFont stuff necessary for GTK+ 1.2, we need to have this
1230 SetFont( parent
->GetFont() );
1233 wxPropertyGrid
* pg
= (wxPropertyGrid
*) parent
->GetParent();
1234 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1235 m_boxHeight
= pg
->GetFontHeight();
1236 SetBackgroundStyle( wxBG_STYLE_COLOUR
);
1239 virtual ~wxSimpleCheckBox();
1241 virtual bool ProcessEvent(wxEvent
& event
);
1246 static wxBitmap
* ms_doubleBuffer
;
1250 wxSimpleCheckBox::~wxSimpleCheckBox()
1252 delete ms_doubleBuffer
;
1253 ms_doubleBuffer
= NULL
;
1257 wxBitmap
* wxSimpleCheckBox::ms_doubleBuffer
= (wxBitmap
*) NULL
;
1259 // value = 2 means toggle (sorry, too lazy to do constants)
1260 void wxSimpleCheckBox::SetValue( int value
)
1265 if ( m_state
> 1 ) m_state
= 0;
1273 wxCommandEvent
evt(wxEVT_COMMAND_CHECKBOX_CLICKED
,GetParent()->GetId());
1275 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent()->GetParent();
1276 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1277 propGrid
->OnCustomEditorEvent(evt
);
1281 bool wxSimpleCheckBox::ProcessEvent(wxEvent
& event
)
1283 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent()->GetParent();
1284 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1286 if ( event
.GetEventType() == wxEVT_NAVIGATION_KEY
)
1288 //wxLogDebug(wxT("wxEVT_NAVIGATION_KEY"));
1289 //SetFocusFromKbd();
1291 //return wxControl::ProcessEvent(event);
1294 if ( ( (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1295 && ((wxMouseEvent
&)event
).m_x
> (wxPG_XBEFORETEXT
-2)
1296 && ((wxMouseEvent
&)event
).m_x
<= (wxPG_XBEFORETEXT
-2+m_boxHeight
) )
1302 else if ( event
.GetEventType() == wxEVT_PAINT
)
1304 wxSize clientSize
= GetClientSize();
1308 // Buffered paint DC doesn't seem to do much good
1309 if ( !ms_doubleBuffer ||
1310 clientSize.x > ms_doubleBuffer->GetWidth() ||
1311 clientSize.y > ms_doubleBuffer->GetHeight() )
1313 delete ms_doubleBuffer;
1314 ms_doubleBuffer = new wxBitmap(clientSize.x+25,clientSize.y+25);
1317 wxBufferedPaintDC dc(this,*ms_doubleBuffer);
1320 wxRect
rect(0,0,clientSize
.x
,clientSize
.y
);
1325 m_boxHeight
= propGrid
->GetFontHeight();
1327 wxColour bgcol
= GetBackgroundColour();
1328 dc
.SetBrush( bgcol
);
1330 dc
.DrawRectangle( rect
);
1332 wxColour txcol
= GetForegroundColour();
1334 int state
= m_state
;
1335 if ( m_font
.GetWeight() == wxBOLD
)
1338 DrawSimpleCheckBox(dc
,rect
,m_boxHeight
,state
,txcol
);
1340 // If focused, indicate it somehow.
1342 if ( wxWindow::FindFocus() == this )
1347 wxPGDrawFocusRect(dc,rect);
1353 else if ( event
.GetEventType() == wxEVT_SIZE
||
1354 event
.GetEventType() == wxEVT_SET_FOCUS
||
1355 event
.GetEventType() == wxEVT_KILL_FOCUS
1360 else if ( event
.GetEventType() == wxEVT_KEY_DOWN
)
1362 wxKeyEvent
& keyEv
= (wxKeyEvent
&) event
;
1364 if ( keyEv
.GetKeyCode() == WXK_TAB
)
1366 propGrid
->SendNavigationKeyEvent( keyEv
.ShiftDown()?0:1 );
1370 if ( keyEv
.GetKeyCode() == WXK_SPACE
)
1376 return wxControl::ProcessEvent(event
);
1380 wxPGWindowList
wxPGCheckBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1381 wxPGProperty
* property
,
1383 const wxSize
& size
) const
1386 pt
.x
-= wxPG_XBEFOREWIDGET
;
1388 sz
.x
= propGrid
->GetFontHeight() + (wxPG_XBEFOREWIDGET
*2) + 4;
1390 wxSimpleCheckBox
* cb
= new wxSimpleCheckBox(propGrid
->GetPanel(),wxPG_SUBID1
,pt
,sz
);
1392 cb
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
1394 cb
->Connect( wxPG_SUBID1
, wxEVT_LEFT_DOWN
,
1395 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
1396 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propGrid
);
1398 cb
->Connect( wxPG_SUBID1
, wxEVT_LEFT_DCLICK
,
1399 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
1400 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propGrid
);
1402 if ( property
->GetChoiceSelection() > 0 &&
1403 !property
->IsValueUnspecified() )
1406 // If mouse cursor was on the item, toggle the value now.
1407 if ( propGrid
->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK
)
1409 wxPoint pt
= cb
->ScreenToClient(::wxGetMousePosition());
1410 if ( pt
.x
<= (wxPG_XBEFORETEXT
-2+cb
->m_boxHeight
) )
1414 if ( cb
->m_state
> 1 )
1417 // Makes sure wxPG_EVT_CHANGING etc. is sent for this initial click
1418 propGrid
->ChangePropertyValue(property
, wxPGVariant_Bool(cb
->m_state
));
1422 propGrid
->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR
);
1428 class wxPGCheckBoxRenderer : public wxPGDefaultRenderer
1432 virtual void Render( wxDC& dc, const wxRect& rect,
1433 const wxPropertyGrid* WXUNUSED(propertyGrid), wxPGProperty* property,
1434 int WXUNUSED(column), int WXUNUSED(item), int WXUNUSED(flags) ) const
1437 if ( !(property->GetFlags() & wxPG_PROP_UNSPECIFIED) )
1439 state = ((wxPGProperty*)property)->GetChoiceInfo((wxPGChoiceInfo*)NULL);
1440 if ( dc.GetFont().GetWeight() == wxBOLD ) state |= 2;
1442 DrawSimpleCheckBox(dc,rect,dc.GetCharHeight(),state,dc.GetTextForeground());
1448 wxPGCheckBoxRenderer g_wxPGCheckBoxRenderer;
1450 wxPGCellRenderer* wxPGCheckBoxEditor::GetCellRenderer() const
1452 return &g_wxPGCheckBoxRenderer;
1456 void wxPGCheckBoxEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
, wxPGProperty
* property
, const wxString
& WXUNUSED(text
) ) const
1459 if ( !property
->IsValueUnspecified() )
1461 state
= property
->GetChoiceSelection();
1462 if ( dc
.GetFont().GetWeight() == wxBOLD
) state
|= 2;
1464 DrawSimpleCheckBox(dc
,rect
,dc
.GetCharHeight(),state
,dc
.GetTextForeground());
1467 void wxPGCheckBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1470 ((wxSimpleCheckBox
*)ctrl
)->m_state
= property
->GetChoiceSelection();
1475 bool wxPGCheckBoxEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propGrid
), wxPGProperty
* WXUNUSED(property
),
1476 wxWindow
* WXUNUSED(ctrl
), wxEvent
& event
) const
1478 if ( event
.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED
)
1486 bool wxPGCheckBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1488 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*)ctrl
;
1490 int index
= cb
->m_state
;
1492 if ( index
!= property
->GetChoiceSelection() ||
1493 // Changing unspecified always causes event (returning
1494 // true here should be enough to trigger it).
1495 property
->IsValueUnspecified()
1498 return property
->IntToValue(variant
, index
, 0);
1504 void wxPGCheckBoxEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1506 if ( value
!= 0 ) value
= 1;
1507 ((wxSimpleCheckBox
*)ctrl
)->m_state
= value
;
1512 void wxPGCheckBoxEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1514 ((wxSimpleCheckBox
*)ctrl
)->m_state
= 0;
1519 wxPGCheckBoxEditor::~wxPGCheckBoxEditor() { }
1522 #endif // wxPG_INCLUDE_CHECKBOX
1524 // -----------------------------------------------------------------------
1526 wxWindow
* wxPropertyGrid::GetEditorControl() const
1528 wxWindow
* ctrl
= m_wndEditor
;
1536 // -----------------------------------------------------------------------
1538 void wxPropertyGrid::CorrectEditorWidgetSizeX()
1540 if ( m_selColumn
== -1 )
1544 int newSplitterx
= m_pState
->DoGetSplitterPosition(m_selColumn
-1);
1545 int newWidth
= newSplitterx
+ m_pState
->m_colWidths
[m_selColumn
];
1549 // if width change occurred, move secondary wnd by that amount
1550 wxRect r
= m_wndEditor2
->GetRect();
1552 r
.x
= newWidth
- secWid
;
1554 m_wndEditor2
->SetSize( r
);
1556 // if primary is textctrl, then we have to add some extra space
1560 if ( m_wndEditor
&& m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1562 secWid
+= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1567 wxRect r
= m_wndEditor
->GetRect();
1569 r
.x
= newSplitterx
+m_ctrlXAdjust
;
1571 if ( !(m_iFlags
& wxPG_FL_FIXED_WIDTH_EDITOR
) )
1572 r
.width
= newWidth
- r
.x
- secWid
;
1574 m_wndEditor
->SetSize(r
);
1578 m_wndEditor2
->Refresh();
1581 // -----------------------------------------------------------------------
1583 void wxPropertyGrid::CorrectEditorWidgetPosY()
1585 if ( m_selected
&& (m_wndEditor
|| m_wndEditor2
) )
1587 wxRect r
= GetEditorWidgetRect(m_selected
, m_selColumn
);
1591 wxPoint pos
= m_wndEditor
->GetPosition();
1593 // Calculate y offset
1594 int offset
= pos
.y
% m_lineHeight
;
1596 m_wndEditor
->Move(pos
.x
, r
.y
+ offset
);
1601 wxPoint pos
= m_wndEditor2
->GetPosition();
1603 m_wndEditor2
->Move(pos
.x
, r
.y
);
1608 // -----------------------------------------------------------------------
1610 // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
1611 // fits into that category as well).
1612 void wxPropertyGrid::FixPosForTextCtrl( wxWindow
* ctrl
, const wxPoint
& offset
)
1614 // Center the control vertically
1615 wxRect finalPos
= ctrl
->GetRect();
1616 int y_adj
= (m_lineHeight
- finalPos
.height
)/2 + wxPG_TEXTCTRLYADJUST
;
1618 // Prevent over-sized control
1619 int sz_dec
= (y_adj
+ finalPos
.height
) - m_lineHeight
;
1620 if ( sz_dec
< 0 ) sz_dec
= 0;
1622 finalPos
.y
+= y_adj
;
1623 finalPos
.height
-= (y_adj
+sz_dec
);
1625 const int textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
;
1627 finalPos
.x
+= textCtrlXAdjust
;
1628 finalPos
.width
-= textCtrlXAdjust
;
1630 finalPos
.x
+= offset
.x
;
1631 finalPos
.y
+= offset
.y
;
1633 ctrl
->SetSize(finalPos
);
1636 // -----------------------------------------------------------------------
1638 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint
& pos
,
1640 const wxString
& value
,
1641 wxWindow
* secondary
,
1645 wxWindowID id
= wxPG_SUBID1
;
1646 wxPGProperty
* selected
= m_selected
;
1649 int tcFlags
= wxTE_PROCESS_ENTER
| extraStyle
;
1651 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1652 tcFlags
|= wxTE_READONLY
;
1654 wxPoint
p(pos
.x
,pos
.y
);
1655 wxSize
s(sz
.x
,sz
.y
);
1657 // Need to reduce width of text control on Mac
1658 #if defined(__WXMAC__)
1662 // Take button into acccount
1665 s
.x
-= (secondary
->GetSize().x
+ wxPG_TEXTCTRL_AND_BUTTON_SPACING
);
1666 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
1669 // If the height is significantly higher, then use border, and fill the rect exactly.
1670 bool hasSpecialSize
= false;
1672 if ( (sz
.y
- m_lineHeight
) > 5 )
1673 hasSpecialSize
= true;
1675 wxWindow
* ctrlParent
= GetPanel();
1677 if ( !hasSpecialSize
)
1678 tcFlags
|= wxBORDER_NONE
;
1680 wxTextCtrl
* tc
= new wxTextCtrl();
1682 #if defined(__WXMSW__)
1685 SetupTextCtrlValue(value
);
1686 tc
->Create(ctrlParent
,id
,value
, p
, s
,tcFlags
);
1690 // Center the control vertically
1691 if ( !hasSpecialSize
)
1692 FixPosForTextCtrl(ed
);
1700 // Set maximum length
1702 tc
->SetMaxLength( maxLen
);
1704 // Connect event handling
1706 this->Connect(id
, wxEVT_COMMAND_TEXT_UPDATED
,
1707 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1708 this->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
1709 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1711 return (wxWindow
*) ed
;
1714 // -----------------------------------------------------------------------
1716 wxWindow
* wxPropertyGrid::GenerateEditorButton( const wxPoint
& pos
, const wxSize
& sz
)
1718 wxWindowID id
= wxPG_SUBID2
;
1719 wxPGProperty
* selected
= m_selected
;
1723 // Decorations are chunky on Mac, and we can't make the button square, so
1724 // do things a bit differently on this platform.
1726 wxPoint
p(pos
.x
+sz
.x
,
1727 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1730 wxButton
* but
= new wxButton();
1731 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1733 // Now that we know the size, move to the correct position
1734 p
.x
= pos
.x
+ sz
.x
- but
->GetSize().x
- 2;
1738 wxSize
s(sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2),
1739 sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2));
1741 // Reduce button width to lineheight
1742 if ( s
.x
> m_lineHeight
)
1746 // On wxGTK, take fixed button margins into account
1751 wxPoint
p(pos
.x
+sz
.x
-s
.x
,
1752 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1754 wxButton
* but
= new wxButton();
1758 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1761 wxFont font
= GetFont();
1762 font
.SetPointSize(font
.GetPointSize()-2);
1765 but
->SetFont(GetFont());
1769 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1772 // Connect event handling
1774 this->Connect(id
, wxEVT_COMMAND_BUTTON_CLICKED
,
1775 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1780 // -----------------------------------------------------------------------
1782 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrlAndButton( const wxPoint
& pos
,
1784 wxWindow
** psecondary
,
1786 wxPGProperty
* property
)
1788 wxButton
* but
= (wxButton
*)GenerateEditorButton(pos
,sz
);
1789 *psecondary
= (wxWindow
*)but
;
1791 if ( limitedEditing
)
1794 // There is button Show in GenerateEditorTextCtrl as well
1797 return (wxWindow
*) NULL
;
1802 if ( !property
->IsValueUnspecified() )
1803 text
= property
->GetValueString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
1805 return GenerateEditorTextCtrl(pos
,sz
,text
,but
,property
->m_maxLen
);
1808 // -----------------------------------------------------------------------
1810 wxTextCtrl
* wxPropertyGrid::GetEditorTextCtrl() const
1812 wxWindow
* wnd
= GetEditorControl();
1817 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1818 return wxStaticCast(wnd
, wxTextCtrl
);
1820 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
1822 wxOwnerDrawnComboBox
* cb
= wxStaticCast(wnd
, wxOwnerDrawnComboBox
);
1823 return cb
->GetTextCtrl();
1829 // -----------------------------------------------------------------------
1831 wxPGEditor
* wxPropertyGridInterface::GetEditorByName( const wxString
& editorName
)
1833 wxPGHashMapS2P::const_iterator it
;
1835 it
= wxPGGlobalVars
->m_mapEditorClasses
.find(editorName
);
1836 if ( it
== wxPGGlobalVars
->m_mapEditorClasses
.end() )
1838 return (wxPGEditor
*) it
->second
;
1841 // -----------------------------------------------------------------------
1842 // wxPGEditorDialogAdapter
1843 // -----------------------------------------------------------------------
1845 IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter
, wxObject
)
1847 bool wxPGEditorDialogAdapter::ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
1849 if ( !propGrid
->EditorValidate() )
1852 bool res
= DoShowDialog( propGrid
, property
);
1856 propGrid
->ValueChangeInEvent( m_value
);
1863 // -----------------------------------------------------------------------
1865 // -----------------------------------------------------------------------
1867 wxPGMultiButton::wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
)
1868 : wxWindow( pg
->GetPanel(), wxPG_SUBID2
, wxPoint(-100,-100), wxSize(0, sz
.y
) ),
1869 m_fullEditorSize(sz
), m_buttonsWidth(0)
1871 SetBackgroundColour(pg
->GetCellBackgroundColour());
1874 void wxPGMultiButton::Finalize( wxPropertyGrid
* propGrid
, const wxPoint
& pos
)
1876 Move( pos
.x
+ m_fullEditorSize
.x
- m_buttonsWidth
, pos
.y
);
1878 // Connect event handling
1879 for ( int i
=0; i
<GetCount(); i
++ )
1881 wxWindowID id
= GetButtonId(i
);
1882 propGrid
->Connect(id
, wxEVT_COMMAND_BUTTON_CLICKED
,
1883 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1887 int wxPGMultiButton::GenId( int id
) const
1891 if ( m_buttons
.size() )
1892 id
= GetButton(m_buttons
.size()-1)->GetId() + 1;
1900 void wxPGMultiButton::Add( const wxBitmap
& bitmap
, int id
)
1903 wxSize sz
= GetSize();
1904 wxButton
* button
= new wxBitmapButton( this, id
, bitmap
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
1905 m_buttons
.push_back(button
);
1906 int bw
= button
->GetSize().x
;
1907 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
1908 m_buttonsWidth
+= bw
;
1912 void wxPGMultiButton::Add( const wxString
& label
, int id
)
1915 wxSize sz
= GetSize();
1916 wxButton
* button
= new wxButton( this, id
, label
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
1917 m_buttons
.push_back(button
);
1918 int bw
= button
->GetSize().x
;
1919 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
1920 m_buttonsWidth
+= bw
;
1923 // -----------------------------------------------------------------------
1925 #endif // wxUSE_PROPGRID