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"
44 #include "wx/layout.h"
46 #include "wx/textdlg.h"
47 #include "wx/filedlg.h"
48 #include "wx/statusbr.h"
55 #include "wx/dcbuffer.h"
56 #include "wx/bmpbuttn.h"
59 // This define is necessary to prevent macro clearing
60 #define __wxPG_SOURCE_FILE__
62 #include <wx/propgrid/propgrid.h>
63 #include <wx/propgrid/editors.h>
64 #include <wx/propgrid/props.h>
66 #if wxPG_USE_RENDERER_NATIVE
67 #include <wx/renderer.h>
70 // How many pixels between textctrl and button
72 #define wxPG_TEXTCTRL_AND_BUTTON_SPACING 8
74 #define wxPG_TEXTCTRL_AND_BUTTON_SPACING 2
77 #define wxPG_BUTTON_SIZEDEC 0
79 #include <wx/odcombo.h>
82 #include <wx/msw/private.h>
85 // -----------------------------------------------------------------------
87 #if defined(__WXMSW__)
89 #define wxPG_NAT_TEXTCTRL_BORDER_X 0 // Unremovable border of native textctrl.
90 #define wxPG_NAT_TEXTCTRL_BORDER_Y 0 // Unremovable border of native textctrl.
92 #define wxPG_NAT_BUTTON_BORDER_ANY 1
93 #define wxPG_NAT_BUTTON_BORDER_X 1
94 #define wxPG_NAT_BUTTON_BORDER_Y 1
96 #define wxPG_CHECKMARK_XADJ 1
97 #define wxPG_CHECKMARK_YADJ (-1)
98 #define wxPG_CHECKMARK_WADJ 0
99 #define wxPG_CHECKMARK_HADJ 0
100 #define wxPG_CHECKMARK_DEFLATE 0
102 #define wxPG_TEXTCTRLYADJUST (m_spacingy+0)
104 #elif defined(__WXGTK__)
106 #define wxPG_CHECKMARK_XADJ 0
107 #define wxPG_CHECKMARK_YADJ 0
108 #define wxPG_CHECKMARK_WADJ (-1)
109 #define wxPG_CHECKMARK_HADJ (-1)
110 #define wxPG_CHECKMARK_DEFLATE 3
112 #define wxPG_NAT_TEXTCTRL_BORDER_X 3 // Unremovable border of native textctrl.
113 #define wxPG_NAT_TEXTCTRL_BORDER_Y 3 // Unremovable border of native textctrl.
115 #define wxPG_NAT_BUTTON_BORDER_ANY 1
116 #define wxPG_NAT_BUTTON_BORDER_X 1
117 #define wxPG_NAT_BUTTON_BORDER_Y 1
119 #define wxPG_TEXTCTRLYADJUST 0
121 #elif defined(__WXMAC__)
123 #define wxPG_CHECKMARK_XADJ 0
124 #define wxPG_CHECKMARK_YADJ 0
125 #define wxPG_CHECKMARK_WADJ 0
126 #define wxPG_CHECKMARK_HADJ 0
127 #define wxPG_CHECKMARK_DEFLATE 0
129 #define wxPG_NAT_TEXTCTRL_BORDER_X 0 // Unremovable border of native textctrl.
130 #define wxPG_NAT_TEXTCTRL_BORDER_Y 0 // Unremovable border of native textctrl.
132 #define wxPG_NAT_BUTTON_BORDER_ANY 0
133 #define wxPG_NAT_BUTTON_BORDER_X 0
134 #define wxPG_NAT_BUTTON_BORDER_Y 0
136 #define wxPG_TEXTCTRLYADJUST 3
140 #define wxPG_CHECKMARK_XADJ 0
141 #define wxPG_CHECKMARK_YADJ 0
142 #define wxPG_CHECKMARK_WADJ 0
143 #define wxPG_CHECKMARK_HADJ 0
144 #define wxPG_CHECKMARK_DEFLATE 0
146 #define wxPG_NAT_TEXTCTRL_BORDER_X 0 // Unremovable border of native textctrl.
147 #define wxPG_NAT_TEXTCTRL_BORDER_Y 0 // Unremovable border of native textctrl.
149 #define wxPG_NAT_BUTTON_BORDER_ANY 0
150 #define wxPG_NAT_BUTTON_BORDER_X 0
151 #define wxPG_NAT_BUTTON_BORDER_Y 0
153 #define wxPG_TEXTCTRLYADJUST 0
157 #if (!wxPG_NAT_TEXTCTRL_BORDER_X && !wxPG_NAT_TEXTCTRL_BORDER_Y)
158 #define wxPG_ENABLE_CLIPPER_WINDOW 0
160 #define wxPG_ENABLE_CLIPPER_WINDOW 1
165 #define wxPG_CHOICEXADJUST 0
166 #define wxPG_CHOICEYADJUST 0
168 #define ODCB_CUST_PAINT_MARGIN 6 // Number added to image width for SetCustomPaintWidth
170 // Milliseconds to wait for two mouse-ups after focus inorder
171 // to trigger a double-click.
172 #define DOUBLE_CLICK_CONVERSION_TRESHOLD 500
174 // -----------------------------------------------------------------------
176 // -----------------------------------------------------------------------
178 IMPLEMENT_ABSTRACT_CLASS(wxPGEditor
, wxObject
)
181 wxPGEditor::~wxPGEditor()
185 void wxPGEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
, wxPGProperty
* property
, const wxString
& text
) const
187 if ( !property
->IsValueUnspecified() )
188 dc
.DrawText( text
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
191 bool wxPGEditor::GetValueFromControl( wxVariant
&, wxPGProperty
*, wxWindow
* ) const
196 void wxPGEditor::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, const wxString
& ) const
201 void wxPGEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, int ) const
206 int wxPGEditor::InsertItem( wxWindow
*, const wxString
&, int ) const
212 void wxPGEditor::DeleteItem( wxWindow
*, int ) const
218 void wxPGEditor::OnFocus( wxPGProperty
*, wxWindow
* ) const
223 bool wxPGEditor::CanContainCustomImage() const
228 // -----------------------------------------------------------------------
230 // -----------------------------------------------------------------------
233 #if wxPG_ENABLE_CLIPPER_WINDOW
236 // Clipper window is used to "remove" borders from controls
237 // which otherwise insist on having them despite of supplied
238 // wxNO_BORDER window style.
240 class wxPGClipperWindow
: public wxWindow
242 DECLARE_CLASS(wxPGClipperWindow
)
248 wxPGClipperWindow::Init();
251 wxPGClipperWindow(wxWindow
* parent
,
253 const wxPoint
& pos
= wxDefaultPosition
,
254 const wxSize
& size
= wxDefaultSize
)
257 Create(parent
,id
,pos
,size
);
260 void Create(wxWindow
* parent
,
262 const wxPoint
& pos
= wxDefaultPosition
,
263 const wxSize
& size
= wxDefaultSize
);
265 virtual ~wxPGClipperWindow();
267 virtual bool ProcessEvent(wxEvent
& event
);
269 inline wxWindow
* GetControl() const { return m_ctrl
; }
271 // This is called before wxControl is constructed.
272 void GetControlRect( int xadj
, int yadj
, wxPoint
& pt
, wxSize
& sz
);
274 // This is caleed after wxControl has been constructed.
275 void SetControl( wxWindow
* ctrl
);
277 virtual void Refresh( bool eraseBackground
= true,
278 const wxRect
*rect
= (const wxRect
*) NULL
);
279 virtual void SetFocus();
281 virtual bool SetFont(const wxFont
& font
);
283 inline int GetXClip() const { return m_xadj
; }
285 inline int GetYClip() const { return m_yadj
; }
290 int m_xadj
; // Horizontal border clip.
292 int m_yadj
; // Vertical border clip.
297 m_ctrl
= (wxWindow
*) NULL
;
302 IMPLEMENT_CLASS(wxPGClipperWindow
,wxWindow
)
305 // This is called before wxControl is constructed.
306 void wxPGClipperWindow::GetControlRect( int xadj
, int yadj
, wxPoint
& pt
, wxSize
& sz
)
312 wxSize own_size
= GetSize();
313 sz
.x
= own_size
.x
+(xadj
*2);
314 sz
.y
= own_size
.y
+(yadj
*2);
318 // This is caleed after wxControl has been constructed.
319 void wxPGClipperWindow::SetControl( wxWindow
* ctrl
)
323 // GTK requires this.
324 ctrl
->SetSizeHints(3,3);
326 // Correct size of this window to match the child.
327 wxSize sz
= GetSize();
328 wxSize chsz
= ctrl
->GetSize();
330 int hei_adj
= chsz
.y
- (sz
.y
+(m_yadj
*2));
332 SetSize(sz
.x
,chsz
.y
-(m_yadj
*2));
337 void wxPGClipperWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
339 wxWindow::Refresh(false,rect
);
341 m_ctrl
->Refresh(eraseBackground
);
345 // Pass focus to control
346 void wxPGClipperWindow::SetFocus()
351 wxWindow::SetFocus();
355 bool wxPGClipperWindow::SetFont(const wxFont
& font
)
357 bool res
= wxWindow::SetFont(font
);
359 return m_ctrl
->SetFont(font
);
364 void wxPGClipperWindow::Create(wxWindow
* parent
,
369 wxWindow::Create(parent
,id
,pos
,size
);
373 wxPGClipperWindow::~wxPGClipperWindow()
378 bool wxPGClipperWindow::ProcessEvent(wxEvent
& event
)
380 if ( event
.GetEventType() == wxEVT_SIZE
)
384 // Maintain correct size relationship.
385 wxSize sz
= GetSize();
386 m_ctrl
->SetSize(sz
.x
+(m_xadj
*2),sz
.y
+(m_yadj
*2));
391 return wxWindow::ProcessEvent(event
);
394 #endif // wxPG_ENABLE_CLIPPER_WINDOW
396 /*wxWindow* wxPropertyGrid::GetActualEditorControl( wxWindow* ctrl )
398 #if wxPG_ENABLE_CLIPPER_WINDOW
399 // Pass real control instead of clipper window
400 if ( ctrl->IsKindOf(CLASSINFO(wxPGClipperWindow)) )
402 return ((wxPGClipperWindow*)ctrl)->GetControl();
409 // -----------------------------------------------------------------------
410 // wxPGTextCtrlEditor
411 // -----------------------------------------------------------------------
413 // Clipper window support macro (depending on whether it is used
414 // for this editor or not)
415 #if wxPG_NAT_TEXTCTRL_BORDER_X || wxPG_NAT_TEXTCTRL_BORDER_Y
416 #define wxPG_NAT_TEXTCTRL_BORDER_ANY 1
418 #define wxPG_NAT_TEXTCTRL_BORDER_ANY 0
421 WX_PG_IMPLEMENT_EDITOR_CLASS(TextCtrl
,wxPGTextCtrlEditor
,wxPGEditor
)
424 wxPGWindowList
wxPGTextCtrlEditor::CreateControls( wxPropertyGrid
* propGrid
,
425 wxPGProperty
* property
,
427 const wxSize
& sz
) const
432 // If has children, and limited editing is specified, then don't create.
433 if ( (property
->GetFlags() & wxPG_PROP_NOEDITOR
) &&
434 property
->GetChildCount() )
435 return (wxWindow
*) NULL
;
437 if ( !property
->IsValueUnspecified() )
438 text
= property
->GetValueString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
441 if ( (property
->GetFlags() & wxPG_PROP_PASSWORD
) &&
442 property
->IsKindOf(CLASSINFO(wxStringProperty
)) )
443 flags
|= wxTE_PASSWORD
;
445 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrl(pos
,sz
,text
,(wxWindow
*)NULL
,flags
,
446 property
->GetMaxLength());
452 void wxPGTextCtrlEditor::DrawValue( wxDC
& dc
, wxPGProperty
* property
, const wxRect
& rect
) const
454 if ( !property
->IsValueUnspecified() )
456 wxString drawStr
= property
->GetDisplayedString();
458 // Code below should no longer be needed, as the obfuscation
459 // is now done in GetValueAsString.
460 /*if ( (property->GetFlags() & wxPG_PROP_PASSWORD) &&
461 property->IsKindOf(WX_PG_CLASSINFO(wxStringProperty)) )
463 size_t a = drawStr.length();
465 drawStr.Append(wxS('*'),a);
467 dc
.DrawText( drawStr
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
472 void wxPGTextCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
474 wxTextCtrl
* tc
= wxDynamicCast(ctrl
, wxTextCtrl
);
479 if ( tc
->HasFlag(wxTE_PASSWORD
) )
480 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
482 s
= property
->GetDisplayedString();
488 // Provided so that, for example, ComboBox editor can use the same code
489 // (multiple inheritance would get way too messy).
490 bool wxPGTextCtrlEditor::OnTextCtrlEvent( wxPropertyGrid
* propGrid
,
491 wxPGProperty
* WXUNUSED(property
),
498 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
500 if ( propGrid
->IsEditorsValueModified() )
505 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
508 // Pass this event outside wxPropertyGrid so that,
509 // if necessary, program can tell when user is editing
511 // FIXME: Is it safe to change event id in the middle of event
512 // processing (seems to work, but...)?
514 event
.SetId(propGrid
->GetId());
516 propGrid
->EditorsValueWasModified();
522 bool wxPGTextCtrlEditor::OnEvent( wxPropertyGrid
* propGrid
,
523 wxPGProperty
* property
,
525 wxEvent
& event
) const
527 return wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,ctrl
,event
);
531 bool wxPGTextCtrlEditor::GetTextCtrlValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
)
533 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
534 wxString textVal
= tc
->GetValue();
536 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
542 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
544 // Changing unspecified always causes event (returning
545 // true here should be enough to trigger it).
546 // TODO: Move to propgrid.cpp
547 if ( !res
&& variant
.IsNull() )
554 bool wxPGTextCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
556 return wxPGTextCtrlEditor::GetTextCtrlValueFromControl(variant
, property
, ctrl
);
560 void wxPGTextCtrlEditor::SetValueToUnspecified( wxPGProperty
* property
, wxWindow
* ctrl
) const
562 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
564 wxPropertyGrid
* pg
= property
->GetGrid();
565 wxASSERT(pg
); // Really, property grid should exist if editor does
567 tc
->SetValue(wxEmptyString
);
571 void wxPGTextCtrlEditor::SetControlStringValue( wxPGProperty
* property
, wxWindow
* ctrl
, const wxString
& txt
) const
573 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
575 wxPropertyGrid
* pg
= property
->GetGrid();
576 wxASSERT(pg
); // Really, property grid should exist if editor does
582 void wxPGTextCtrlEditor::OnFocus( wxPGProperty
*, wxWindow
* wnd
) const
584 wxTextCtrl
* tc
= wxStaticCast(wnd
, wxTextCtrl
);
586 tc
->SetSelection(-1,-1);
590 wxPGTextCtrlEditor::~wxPGTextCtrlEditor() { }
593 // -----------------------------------------------------------------------
595 // -----------------------------------------------------------------------
598 WX_PG_IMPLEMENT_EDITOR_CLASS(Choice
,wxPGChoiceEditor
,wxPGEditor
)
601 // This is a special enhanced double-click processor class.
602 // In essence, it allows for double-clicks for which the
603 // first click "created" the control.
604 class wxPGDoubleClickProcessor
: public wxEvtHandler
608 wxPGDoubleClickProcessor( wxOwnerDrawnComboBox
* combo
, wxPGProperty
* property
)
611 m_timeLastMouseUp
= 0;
613 m_property
= property
;
614 m_downReceived
= false;
619 void OnMouseEvent( wxMouseEvent
& event
)
621 wxLongLong t
= ::wxGetLocalTimeMillis();
622 int evtType
= event
.GetEventType();
624 if ( m_property
->HasFlag(wxPG_PROP_USE_DCC
) &&
625 m_property
->IsKindOf(CLASSINFO(wxBoolProperty
)) &&
626 !m_combo
->IsPopupShown() )
628 // Just check that it is in the text area
629 wxPoint pt
= event
.GetPosition();
630 if ( m_combo
->GetTextRect().Contains(pt
) )
632 if ( evtType
== wxEVT_LEFT_DOWN
)
634 // Set value to avoid up-events without corresponding downs
635 m_downReceived
= true;
637 else if ( evtType
== wxEVT_LEFT_DCLICK
)
639 // We'll make our own double-clicks
640 event
.SetEventType(0);
643 else if ( evtType
== wxEVT_LEFT_UP
)
645 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
647 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
649 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
651 event
.SetEventType(wxEVT_LEFT_DCLICK
);
652 m_timeLastMouseUp
= 1;
656 m_timeLastMouseUp
= t
;
666 void OnSetFocus( wxFocusEvent
& event
)
668 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
673 wxLongLong m_timeLastMouseUp
;
674 wxOwnerDrawnComboBox
* m_combo
;
675 wxPGProperty
* m_property
; // Selected property
678 DECLARE_EVENT_TABLE()
681 BEGIN_EVENT_TABLE(wxPGDoubleClickProcessor
, wxEvtHandler
)
682 EVT_MOUSE_EVENTS(wxPGDoubleClickProcessor::OnMouseEvent
)
683 EVT_SET_FOCUS(wxPGDoubleClickProcessor::OnSetFocus
)
688 class wxPGComboBox
: public wxOwnerDrawnComboBox
693 : wxOwnerDrawnComboBox()
695 m_dclickProcessor
= (wxPGDoubleClickProcessor
*) NULL
;
696 m_sizeEventCalled
= false;
701 if ( m_dclickProcessor
)
703 RemoveEventHandler(m_dclickProcessor
);
704 delete m_dclickProcessor
;
708 bool Create(wxWindow
*parent
,
710 const wxString
& value
,
713 const wxArrayString
& choices
,
715 const wxValidator
& validator
= wxDefaultValidator
,
716 const wxString
& name
= wxS("wxOwnerDrawnComboBox"))
718 if ( !wxOwnerDrawnComboBox::Create( parent
,
729 m_dclickProcessor
= new wxPGDoubleClickProcessor(this, GetGrid()->GetSelection() );
731 PushEventHandler(m_dclickProcessor
);
736 virtual void OnDrawItem( wxDC
& dc
, const wxRect
& rect
, int item
, int flags
) const
738 wxPropertyGrid
* pg
= GetGrid();
739 pg
->OnComboItemPaint((wxPGCustomComboControl
*)this,item
,dc
,(wxRect
&)rect
,flags
);
741 virtual wxCoord
OnMeasureItem( size_t item
) const
743 wxPropertyGrid
* pg
= GetGrid();
747 pg
->OnComboItemPaint((wxPGCustomComboControl
*)this,item
,*((wxDC
*)NULL
),rect
,0);
751 wxPropertyGrid
* GetGrid() const
753 wxPropertyGrid
* pg
= wxDynamicCast(GetParent()->GetParent(),wxPropertyGrid
);
758 virtual wxCoord
OnMeasureItemWidth( size_t item
) const
760 wxPropertyGrid
* pg
= GetGrid();
764 pg
->OnComboItemPaint((wxPGCustomComboControl
*)this,item
,*((wxDC
*)NULL
),rect
,0);
768 virtual void PositionTextCtrl( int WXUNUSED(textCtrlXAdjust
), int WXUNUSED(textCtrlYAdjust
) )
770 wxPropertyGrid
* pg
= GetGrid();
771 wxOwnerDrawnComboBox::PositionTextCtrl(
772 wxPG_TEXTCTRLXADJUST
- (wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1) - 1,
773 pg
->GetSpacingY() + 2
778 wxPGDoubleClickProcessor
* m_dclickProcessor
;
779 bool m_sizeEventCalled
;
783 void wxPropertyGrid::OnComboItemPaint( wxPGCustomComboControl
* pCc
,
789 wxPGComboBox
* pCb
= (wxPGComboBox
*)pCc
;
792 wxASSERT( IsKindOf(CLASSINFO(wxPropertyGrid
)) );
794 wxPGProperty
* p
= m_selected
;
797 const wxPGChoices
* pChoices
= &p
->GetChoices();
798 const wxPGCommonValue
* comVal
= NULL
;
799 int choiceCount
= p
->GetChoiceCount();
800 int comVals
= p
->GetDisplayedCommonValueCount();
801 int comValIndex
= -1;
802 if ( item
>= choiceCount
&& comVals
> 0 )
804 comValIndex
= item
- choiceCount
;
805 comVal
= GetCommonValue(comValIndex
);
806 if ( !p
->IsValueUnspecified() )
807 text
= comVal
->GetLabel();
811 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
813 text
= pCb
->GetString(item
);
817 if ( !p
->IsValueUnspecified() )
818 text
= p
->GetValueString(0);
827 const wxBitmap
* itemBitmap
= NULL
;
829 if ( item
>= 0 && pChoices
&& pChoices
->Item(item
).GetBitmap().Ok() && comValIndex
== -1 )
830 itemBitmap
= &pChoices
->Item(item
).GetBitmap();
833 // Decide what custom image size to use
836 cis
.x
= itemBitmap
->GetWidth();
837 cis
.y
= itemBitmap
->GetHeight();
841 cis
= GetImageSize(p
, item
);
846 // Default measure behaviour (no flexible, custom paint image only)
847 if ( rect
.width
< 0 )
850 GetTextExtent(text
, &x
, &y
, 0, 0, &m_font
);
851 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9 + x
;
854 rect
.height
= cis
.y
+ 2;
858 wxPGPaintData paintdata
;
859 paintdata
.m_parent
= NULL
;
860 paintdata
.m_choiceItem
= item
;
862 // This is by the current (1.0.0b) spec - if painting control, item is -1
863 if ( (flags
& wxODCB_PAINTING_CONTROL
) )
864 paintdata
.m_choiceItem
= -1;
867 dc
.SetBrush(*wxWHITE_BRUSH
);
874 wxPoint
pt(rect
.x
+ wxPG_CONTROL_MARGIN
- wxPG_CHOICEXADJUST
- 1,
879 if ( flags
& wxODCB_PAINTING_CONTROL
)
880 renderFlags
|= wxPGCellRenderer::Control
;
882 if ( flags
& wxODCB_PAINTING_SELECTED
)
883 renderFlags
|= wxPGCellRenderer::Selected
;
885 if ( cis
.x
> 0 && (p
->HasFlag(wxPG_PROP_CUSTOMIMAGE
) || !(flags
& wxODCB_PAINTING_CONTROL
)) &&
886 ( !p
->m_valueBitmap
|| item
== pCb
->GetSelection() ) &&
887 ( item
>= 0 || (flags
& wxODCB_PAINTING_CONTROL
) ) &&
891 pt
.x
+= wxCC_CUSTOM_IMAGE_MARGIN1
;
892 wxRect
r(pt
.x
,pt
.y
,cis
.x
,cis
.y
);
894 if ( flags
& wxODCB_PAINTING_CONTROL
)
897 r
.height
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
900 paintdata
.m_drawnWidth
= r
.width
;
902 dc
.SetPen(m_colPropFore
);
903 if ( comValIndex
>= 0 )
905 const wxPGCommonValue
* cv
= GetCommonValue(comValIndex
);
906 wxPGCellRenderer
* renderer
= cv
->GetRenderer();
907 r
.width
= rect
.width
;
908 renderer
->Render( dc
, r
, this, p
, m_selColumn
, comValIndex
, renderFlags
);
911 else if ( item
>= 0 )
913 p
->OnCustomPaint( dc
, r
, paintdata
);
917 dc
.DrawRectangle( r
);
920 pt
.x
+= paintdata
.m_drawnWidth
+ wxCC_CUSTOM_IMAGE_MARGIN2
- 1;
924 // TODO: This aligns text so that it seems to be horizontally
925 // on the same line as property values. Not really
926 // sure if its needed, but seems to not cause any harm.
929 if ( item
< 0 && (flags
& wxODCB_PAINTING_CONTROL
) )
930 item
= pCb
->GetSelection();
932 if ( pChoices
&& item
>= 0 && comValIndex
< 0 )
934 const wxPGChoiceEntry
& cell
= pChoices
->Item(item
);
935 wxPGCellRenderer
* renderer
= wxPGGlobalVars
->m_defaultRenderer
;
936 int imageOffset
= renderer
->PreDrawCell( dc
, rect
, cell
, renderFlags
);
938 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
947 pt
.y
+= (rect
.height
-m_fontHeight
)/2 - 1;
951 dc
.DrawText( text
, pt
.x
+ wxPG_XBEFORETEXT
, pt
.y
);
958 p
->OnCustomPaint( dc
, rect
, paintdata
);
959 rect
.height
= paintdata
.m_drawnHeight
+ 2;
960 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9;
964 bool wxPGChoiceEditor_SetCustomPaintWidth( wxPropertyGrid
* propGrid
, wxPGComboBox
* cb
, int cmnVal
)
966 wxPGProperty
* property
= propGrid
->GetSelectedProperty();
967 wxASSERT( property
);
971 // Yes, a common value is being selected
972 property
->SetCommonValue( cmnVal
);
973 wxSize imageSize
= propGrid
->GetCommonValue(cmnVal
)->
974 GetRenderer()->GetImageSize(property
, 1, cmnVal
);
975 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
976 cb
->SetCustomPaintWidth( imageSize
.x
);
981 wxSize imageSize
= propGrid
->GetImageSize(property
, -1);
982 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
983 cb
->SetCustomPaintWidth( imageSize
.x
);
988 // CreateControls calls this with CB_READONLY in extraStyle
989 wxWindow
* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid
* propGrid
,
990 wxPGProperty
* property
,
993 long extraStyle
) const
998 int index
= property
->GetChoiceInfo( NULL
);
1000 bool isUnspecified
= property
->IsValueUnspecified();
1002 if ( isUnspecified
)
1005 defString
= property
->GetDisplayedString();
1007 const wxPGChoices
& choices
= property
->GetChoices();
1009 wxArrayString labels
= choices
.GetLabels();
1015 po
.y
+= wxPG_CHOICEYADJUST
;
1016 si
.y
-= (wxPG_CHOICEYADJUST
*2);
1018 po
.x
+= wxPG_CHOICEXADJUST
;
1019 si
.x
-= wxPG_CHOICEXADJUST
;
1020 wxWindow
* ctrlParent
= propGrid
->GetPanel();
1022 int odcbFlags
= extraStyle
| wxNO_BORDER
| wxTE_PROCESS_ENTER
;
1025 // If common value specified, use appropriate index
1026 unsigned int cmnVals
= property
->GetDisplayedCommonValueCount();
1029 if ( !isUnspecified
)
1031 int cmnVal
= property
->GetCommonValue();
1034 index
= labels
.size() + cmnVal
;
1039 for ( i
=0; i
<cmnVals
; i
++ )
1040 labels
.Add(propGrid
->GetCommonValueLabel(i
));
1043 cb
= new wxPGComboBox();
1047 cb
->Create(ctrlParent
,
1055 //int extRight = propGrid->GetClientSize().x - (po.x+si.x);
1056 //int extRight = - (po.x+si.x);
1058 cb
->SetButtonPosition(si
.y
,0,wxRIGHT
);
1059 //cb->SetPopupExtents( 1, extRight );
1060 cb
->SetTextIndent(wxPG_XBEFORETEXT
-1);
1062 wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, property
->GetCommonValue() );
1063 /*if ( property->GetFlags() & wxPG_PROP_CUSTOMIMAGE )
1065 wxSize imageSize = propGrid->GetImageSize(property, index);
1066 if ( imageSize.x ) imageSize.x += ODCB_CUST_PAINT_MARGIN;
1067 cb->SetCustomPaintWidth( imageSize.x );
1070 if ( index
>= 0 && index
< (int)cb
->GetCount() )
1072 cb
->SetSelection( index
);
1073 if ( defString
.length() )
1074 cb
->SetText( defString
);
1076 else if ( !(extraStyle
& wxCB_READONLY
) && defString
.length() )
1077 cb
->SetValue( defString
);
1079 cb
->SetSelection( -1 );
1085 return (wxWindow
*) cb
;
1089 void wxPGChoiceEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1092 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1093 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1094 int ind
= property
->GetChoiceInfo( (wxPGChoiceInfo
*)NULL
);
1095 cb
->SetSelection(ind
);
1098 wxPGWindowList
wxPGChoiceEditor::CreateControls( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
1099 const wxPoint
& pos
, const wxSize
& sz
) const
1101 return CreateControlsBase(propGrid
,property
,pos
,sz
,wxCB_READONLY
);
1105 int wxPGChoiceEditor::InsertItem( wxWindow
* ctrl
, const wxString
& label
, int index
) const
1108 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1109 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1112 index
= cb
->GetCount();
1114 return cb
->Insert(label
,index
);
1118 void wxPGChoiceEditor::DeleteItem( wxWindow
* ctrl
, int index
) const
1121 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1122 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1127 bool wxPGChoiceEditor::OnEvent( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
1128 wxWindow
* ctrl
, wxEvent
& event
) const
1130 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
1132 wxPGComboBox
* cb
= (wxPGComboBox
*)ctrl
;
1133 int index
= cb
->GetSelection();
1134 int cmnValIndex
= -1;
1135 int cmnVals
= property
->GetDisplayedCommonValueCount();
1136 int items
= cb
->GetCount();
1138 if ( index
>= (items
-cmnVals
) )
1140 // Yes, a common value is being selected
1141 cmnValIndex
= index
- (items
-cmnVals
);
1142 property
->SetCommonValue( cmnValIndex
);
1144 // Truly set value to unspecified?
1145 if ( propGrid
->GetUnspecifiedCommonValue() == cmnValIndex
)
1147 if ( !property
->IsValueUnspecified() )
1148 propGrid
->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT
);
1149 property
->SetValueToUnspecified();
1150 if ( !cb
->HasFlag(wxCB_READONLY
) )
1151 cb
->GetTextCtrl()->SetValue(wxEmptyString
);
1155 return wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, cmnValIndex
);
1161 bool wxPGChoiceEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1163 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1165 int index
= cb
->GetSelection();
1167 if ( index
!= property
->GetChoiceInfo( (wxPGChoiceInfo
*) NULL
) ||
1168 // Changing unspecified always causes event (returning
1169 // true here should be enough to trigger it).
1170 property
->IsValueUnspecified()
1173 return property
->IntToValue( variant
, index
, 0 );
1179 void wxPGChoiceEditor::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, const wxString
& txt
) const
1181 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1187 void wxPGChoiceEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1189 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1191 cb
->SetSelection(value
);
1195 void wxPGChoiceEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1197 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1198 cb
->SetSelection(-1);
1202 bool wxPGChoiceEditor::CanContainCustomImage() const
1208 wxPGChoiceEditor::~wxPGChoiceEditor() { }
1211 // -----------------------------------------------------------------------
1212 // wxPGComboBoxEditor
1213 // -----------------------------------------------------------------------
1216 WX_PG_IMPLEMENT_EDITOR_CLASS(ComboBox
,wxPGComboBoxEditor
,wxPGChoiceEditor
)
1219 void wxPGComboBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1221 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1222 cb
->SetValue(property
->GetValueString(wxPG_EDITABLE_VALUE
));
1224 // TODO: If string matches any selection, then select that.
1228 wxPGWindowList
wxPGComboBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1229 wxPGProperty
* property
,
1231 const wxSize
& sz
) const
1233 return CreateControlsBase(propGrid
,property
,pos
,sz
,0);
1237 bool wxPGComboBoxEditor::OnEvent( wxPropertyGrid
* propGrid
,
1238 wxPGProperty
* property
,
1240 wxEvent
& event
) const
1242 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*) NULL
;
1243 wxWindow
* textCtrl
= (wxWindow
*) NULL
;
1247 cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1248 textCtrl
= cb
->GetTextCtrl();
1251 if ( wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,textCtrl
,event
) )
1254 return wxPGChoiceEditor::OnEvent(propGrid
,property
,ctrl
,event
);
1258 bool wxPGComboBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1260 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1261 wxString textVal
= cb
->GetValue();
1263 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
1269 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
1271 // Changing unspecified always causes event (returning
1272 // true here should be enough to trigger it).
1273 if ( !res
&& variant
.IsNull() )
1280 void wxPGComboBoxEditor::OnFocus( wxPGProperty
*, wxWindow
* ctrl
) const
1282 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1283 cb
->GetTextCtrl()->SetSelection(-1,-1);
1287 wxPGComboBoxEditor::~wxPGComboBoxEditor() { }
1290 // -----------------------------------------------------------------------
1291 // wxPGChoiceAndButtonEditor
1292 // -----------------------------------------------------------------------
1295 // This simpler implement_editor macro doesn't define class body.
1296 WX_PG_IMPLEMENT_EDITOR_CLASS(ChoiceAndButton
,wxPGChoiceAndButtonEditor
,wxPGChoiceEditor
)
1299 wxPGWindowList
wxPGChoiceAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1300 wxPGProperty
* property
,
1302 const wxSize
& sz
) const
1304 // Use one two units smaller to match size of the combo's dropbutton.
1305 // (normally a bigger button is used because it looks better)
1308 wxSize
bt_sz(bt_wid
,bt_wid
);
1310 // Position of button.
1311 wxPoint
bt_pos(pos
.x
+sz
.x
-bt_sz
.x
,pos
.y
);
1318 wxWindow
* bt
= propGrid
->GenerateEditorButton( bt_pos
, bt_sz
);
1321 wxSize
ch_sz(sz
.x
-bt
->GetSize().x
,sz
.y
);
1324 ch_sz
.x
-= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1327 wxWindow
* ch
= wxPG_EDITOR(Choice
)->CreateControls(propGrid
,property
,
1328 pos
,ch_sz
).m_primary
;
1334 return wxPGWindowList(ch
, bt
);
1338 wxPGChoiceAndButtonEditor::~wxPGChoiceAndButtonEditor() { }
1341 // -----------------------------------------------------------------------
1342 // wxPGTextCtrlAndButtonEditor
1343 // -----------------------------------------------------------------------
1346 // This simpler implement_editor macro doesn't define class body.
1347 WX_PG_IMPLEMENT_EDITOR_CLASS(TextCtrlAndButton
,wxPGTextCtrlAndButtonEditor
,wxPGTextCtrlEditor
)
1350 wxPGWindowList
wxPGTextCtrlAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1351 wxPGProperty
* property
,
1353 const wxSize
& sz
) const
1356 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrlAndButton( pos
, sz
, &wnd2
,
1357 property
->GetFlags() & wxPG_PROP_NOEDITOR
, property
);
1359 return wxPGWindowList(wnd
, wnd2
);
1363 wxPGTextCtrlAndButtonEditor::~wxPGTextCtrlAndButtonEditor() { }
1366 // -----------------------------------------------------------------------
1367 // wxPGCheckBoxEditor
1368 // -----------------------------------------------------------------------
1370 #if wxPG_INCLUDE_CHECKBOX
1372 WX_PG_IMPLEMENT_EDITOR_CLASS(CheckBox
,wxPGCheckBoxEditor
,wxPGEditor
)
1375 // state argument: 0x01 = set if checked
1376 // 0x02 = set if rectangle should be bold
1377 static void DrawSimpleCheckBox( wxDC
& dc
, const wxRect
& rect
, int box_hei
, int state
, const wxColour
& linecol
)
1381 wxRect
r(rect
.x
+wxPG_XBEFORETEXT
,rect
.y
+((rect
.height
-box_hei
)/2),box_hei
,box_hei
);
1383 // Draw check mark first because it is likely to overdraw the
1384 // surrounding rectangle.
1387 wxRect
r2(r
.x
+wxPG_CHECKMARK_XADJ
,
1388 r
.y
+wxPG_CHECKMARK_YADJ
,
1389 r
.width
+wxPG_CHECKMARK_WADJ
,
1390 r
.height
+wxPG_CHECKMARK_HADJ
);
1391 #if wxPG_CHECKMARK_DEFLATE
1392 r2
.Deflate(wxPG_CHECKMARK_DEFLATE
);
1394 dc
.DrawCheckMark(r2
);
1396 // This would draw a simple cross check mark.
1397 // dc.DrawLine(r.x,r.y,r.x+r.width-1,r.y+r.height-1);
1398 // dc.DrawLine(r.x,r.y+r.height-1,r.x+r.width-1,r.y);
1404 // Pen for thin rectangle.
1409 // Pen for bold rectangle.
1410 wxPen
linepen(linecol
,2,wxSOLID
);
1411 linepen
.SetJoin(wxJOIN_MITER
); // This prevents round edges.
1419 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1421 dc
.DrawRectangle(r
);
1422 dc
.SetPen(*wxTRANSPARENT_PEN
);
1426 // Real simple custom-drawn checkbox-without-label class.
1428 class wxSimpleCheckBox
: public wxControl
1432 void SetValue( int value
);
1434 wxSimpleCheckBox( wxWindow
* parent
,
1436 const wxPoint
& pos
= wxDefaultPosition
,
1437 const wxSize
& size
= wxDefaultSize
)
1438 : wxControl(parent
,id
,pos
,size
,wxNO_BORDER
|wxWANTS_CHARS
)
1440 // Due to SetOwnFont stuff necessary for GTK+ 1.2, we need to have this
1441 SetFont( parent
->GetFont() );
1444 wxPropertyGrid
* pg
= (wxPropertyGrid
*) parent
->GetParent();
1445 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1446 m_boxHeight
= pg
->GetFontHeight();
1447 SetBackgroundStyle( wxBG_STYLE_COLOUR
);
1450 virtual ~wxSimpleCheckBox();
1452 virtual bool ProcessEvent(wxEvent
& event
);
1457 static wxBitmap
* ms_doubleBuffer
;
1461 wxSimpleCheckBox::~wxSimpleCheckBox()
1463 delete ms_doubleBuffer
;
1464 ms_doubleBuffer
= NULL
;
1468 wxBitmap
* wxSimpleCheckBox::ms_doubleBuffer
= (wxBitmap
*) NULL
;
1470 // value = 2 means toggle (sorry, too lazy to do constants)
1471 void wxSimpleCheckBox::SetValue( int value
)
1476 if ( m_state
> 1 ) m_state
= 0;
1484 wxCommandEvent
evt(wxEVT_COMMAND_CHECKBOX_CLICKED
,GetParent()->GetId());
1486 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent()->GetParent();
1487 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1488 propGrid
->OnCustomEditorEvent(evt
);
1492 bool wxSimpleCheckBox::ProcessEvent(wxEvent
& event
)
1494 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent()->GetParent();
1495 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1497 if ( event
.GetEventType() == wxEVT_NAVIGATION_KEY
)
1499 //wxLogDebug(wxT("wxEVT_NAVIGATION_KEY"));
1500 //SetFocusFromKbd();
1502 //return wxControl::ProcessEvent(event);
1505 if ( ( (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1506 && ((wxMouseEvent
&)event
).m_x
> (wxPG_XBEFORETEXT
-2)
1507 && ((wxMouseEvent
&)event
).m_x
<= (wxPG_XBEFORETEXT
-2+m_boxHeight
) )
1513 else if ( event
.GetEventType() == wxEVT_PAINT
)
1515 wxSize clientSize
= GetClientSize();
1519 // Buffered paint DC doesn't seem to do much good
1520 if ( !ms_doubleBuffer ||
1521 clientSize.x > ms_doubleBuffer->GetWidth() ||
1522 clientSize.y > ms_doubleBuffer->GetHeight() )
1524 delete ms_doubleBuffer;
1525 ms_doubleBuffer = new wxBitmap(clientSize.x+25,clientSize.y+25);
1528 wxBufferedPaintDC dc(this,*ms_doubleBuffer);
1531 wxRect
rect(0,0,clientSize
.x
,clientSize
.y
);
1536 m_boxHeight
= propGrid
->GetFontHeight();
1538 wxColour bgcol
= GetBackgroundColour();
1539 dc
.SetBrush( bgcol
);
1541 dc
.DrawRectangle( rect
);
1543 wxColour txcol
= GetForegroundColour();
1545 int state
= m_state
;
1546 if ( m_font
.GetWeight() == wxBOLD
)
1549 DrawSimpleCheckBox(dc
,rect
,m_boxHeight
,state
,txcol
);
1551 // If focused, indicate it somehow.
1553 if ( wxWindow::FindFocus() == this )
1558 wxPGDrawFocusRect(dc,rect);
1564 else if ( event
.GetEventType() == wxEVT_SIZE
||
1565 event
.GetEventType() == wxEVT_SET_FOCUS
||
1566 event
.GetEventType() == wxEVT_KILL_FOCUS
1571 else if ( event
.GetEventType() == wxEVT_KEY_DOWN
)
1573 wxKeyEvent
& keyEv
= (wxKeyEvent
&) event
;
1575 if ( keyEv
.GetKeyCode() == WXK_TAB
)
1577 propGrid
->SendNavigationKeyEvent( keyEv
.ShiftDown()?0:1 );
1581 if ( keyEv
.GetKeyCode() == WXK_SPACE
)
1587 return wxControl::ProcessEvent(event
);
1591 wxPGWindowList
wxPGCheckBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1592 wxPGProperty
* property
,
1594 const wxSize
& size
) const
1597 pt
.x
-= wxPG_XBEFOREWIDGET
;
1599 sz
.x
= propGrid
->GetFontHeight() + (wxPG_XBEFOREWIDGET
*2) + 4;
1601 wxSimpleCheckBox
* cb
= new wxSimpleCheckBox(propGrid
->GetPanel(),wxPG_SUBID1
,pt
,sz
);
1603 cb
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
1605 cb
->Connect( wxPG_SUBID1
, wxEVT_LEFT_DOWN
,
1606 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
1607 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propGrid
);
1609 cb
->Connect( wxPG_SUBID1
, wxEVT_LEFT_DCLICK
,
1610 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
1611 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propGrid
);
1613 if ( property
->GetChoiceInfo((wxPGChoiceInfo
*)NULL
) &&
1614 !property
->IsValueUnspecified() )
1617 // If mouse cursor was on the item, toggle the value now.
1618 if ( propGrid
->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK
)
1620 wxPoint pt
= cb
->ScreenToClient(::wxGetMousePosition());
1621 if ( pt
.x
<= (wxPG_XBEFORETEXT
-2+cb
->m_boxHeight
) )
1625 if ( cb
->m_state
> 1 )
1628 // Makes sure wxPG_EVT_CHANGING etc. is sent for this initial click
1629 propGrid
->ChangePropertyValue(property
, wxPGVariant_Bool(cb
->m_state
));
1633 propGrid
->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR
);
1639 class wxPGCheckBoxRenderer : public wxPGDefaultRenderer
1643 virtual void Render( wxDC& dc, const wxRect& rect,
1644 const wxPropertyGrid* WXUNUSED(propertyGrid), wxPGProperty* property,
1645 int WXUNUSED(column), int WXUNUSED(item), int WXUNUSED(flags) ) const
1648 if ( !(property->GetFlags() & wxPG_PROP_UNSPECIFIED) )
1650 state = ((wxPGProperty*)property)->GetChoiceInfo((wxPGChoiceInfo*)NULL);
1651 if ( dc.GetFont().GetWeight() == wxBOLD ) state |= 2;
1653 DrawSimpleCheckBox(dc,rect,dc.GetCharHeight(),state,dc.GetTextForeground());
1659 wxPGCheckBoxRenderer g_wxPGCheckBoxRenderer;
1661 wxPGCellRenderer* wxPGCheckBoxEditor::GetCellRenderer() const
1663 return &g_wxPGCheckBoxRenderer;
1667 void wxPGCheckBoxEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
, wxPGProperty
* property
, const wxString
& WXUNUSED(text
) ) const
1670 if ( !property
->IsValueUnspecified() )
1672 state
= property
->GetChoiceInfo((wxPGChoiceInfo
*)NULL
);
1673 if ( dc
.GetFont().GetWeight() == wxBOLD
) state
|= 2;
1675 DrawSimpleCheckBox(dc
,rect
,dc
.GetCharHeight(),state
,dc
.GetTextForeground());
1678 void wxPGCheckBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1681 ((wxSimpleCheckBox
*)ctrl
)->m_state
= property
->GetChoiceInfo((wxPGChoiceInfo
*)NULL
);
1686 bool wxPGCheckBoxEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propGrid
), wxPGProperty
* WXUNUSED(property
),
1687 wxWindow
* WXUNUSED(ctrl
), wxEvent
& event
) const
1689 if ( event
.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED
)
1697 bool wxPGCheckBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1699 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*)ctrl
;
1701 int index
= cb
->m_state
;
1703 if ( index
!= property
->GetChoiceInfo( (wxPGChoiceInfo
*) NULL
) ||
1704 // Changing unspecified always causes event (returning
1705 // true here should be enough to trigger it).
1706 property
->IsValueUnspecified()
1709 return property
->IntToValue(variant
, index
, 0);
1715 void wxPGCheckBoxEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1717 if ( value
!= 0 ) value
= 1;
1718 ((wxSimpleCheckBox
*)ctrl
)->m_state
= value
;
1723 void wxPGCheckBoxEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1725 ((wxSimpleCheckBox
*)ctrl
)->m_state
= 0;
1730 wxPGCheckBoxEditor::~wxPGCheckBoxEditor() { }
1733 #endif // wxPG_INCLUDE_CHECKBOX
1735 // -----------------------------------------------------------------------
1737 wxWindow
* wxPropertyGrid::GetEditorControl() const
1739 wxWindow
* ctrl
= m_wndEditor
;
1744 // If it's clipper window, return its child instead
1745 #if wxPG_ENABLE_CLIPPER_WINDOW
1746 if ( ctrl
->IsKindOf(CLASSINFO(wxPGClipperWindow
)) )
1748 return ((wxPGClipperWindow
*)ctrl
)->GetControl();
1755 // -----------------------------------------------------------------------
1757 void wxPropertyGrid::CorrectEditorWidgetSizeX()
1759 if ( m_selColumn
== -1 )
1763 int newSplitterx
= m_pState
->DoGetSplitterPosition(m_selColumn
-1);
1764 int newWidth
= newSplitterx
+ m_pState
->m_colWidths
[m_selColumn
];
1768 // if width change occurred, move secondary wnd by that amount
1769 wxRect r
= m_wndEditor2
->GetRect();
1771 r
.x
= newWidth
- secWid
;
1773 m_wndEditor2
->SetSize( r
);
1775 // if primary is textctrl, then we have to add some extra space
1779 if ( m_wndEditor
&& m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1781 secWid
+= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1786 wxRect r
= m_wndEditor
->GetRect();
1788 r
.x
= newSplitterx
+m_ctrlXAdjust
;
1790 if ( !(m_iFlags
& wxPG_FL_FIXED_WIDTH_EDITOR
) )
1791 r
.width
= newWidth
- r
.x
- secWid
;
1793 m_wndEditor
->SetSize(r
);
1797 m_wndEditor2
->Refresh();
1800 // -----------------------------------------------------------------------
1802 void wxPropertyGrid::CorrectEditorWidgetPosY()
1804 if ( m_selected
&& (m_wndEditor
|| m_wndEditor2
) )
1806 wxRect r
= GetEditorWidgetRect(m_selected
, m_selColumn
);
1810 wxPoint pos
= m_wndEditor
->GetPosition();
1812 // Calculate y offset
1813 int offset
= pos
.y
% m_lineHeight
;
1815 m_wndEditor
->Move(pos
.x
, r
.y
+ offset
);
1820 wxPoint pos
= m_wndEditor2
->GetPosition();
1822 m_wndEditor2
->Move(pos
.x
, r
.y
);
1827 // -----------------------------------------------------------------------
1829 bool wxPropertyGrid::AdjustPosForClipperWindow( wxWindow
* topCtrlWnd
, int* x
, int* y
)
1831 #if wxPG_ENABLE_CLIPPER_WINDOW
1832 // Take clipper window into account
1833 if (topCtrlWnd
->GetPosition().x
< 1 &&
1834 !topCtrlWnd
->IsKindOf(CLASSINFO(wxPGClipperWindow
)))
1836 topCtrlWnd
= topCtrlWnd
->GetParent();
1837 wxASSERT( topCtrlWnd
->IsKindOf(CLASSINFO(wxPGClipperWindow
)) );
1838 *x
-= ((wxPGClipperWindow
*)topCtrlWnd
)->GetXClip();
1839 *y
-= ((wxPGClipperWindow
*)topCtrlWnd
)->GetYClip();
1843 wxUnusedVar(topCtrlWnd
);
1850 // -----------------------------------------------------------------------
1852 // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
1853 // fits into that category as well).
1854 void wxPropertyGrid::FixPosForTextCtrl( wxWindow
* ctrl
, const wxPoint
& offset
)
1856 // Center the control vertically
1857 wxRect finalPos
= ctrl
->GetRect();
1858 int y_adj
= (m_lineHeight
- finalPos
.height
)/2 + wxPG_TEXTCTRLYADJUST
;
1860 // Prevent over-sized control
1861 int sz_dec
= (y_adj
+ finalPos
.height
) - m_lineHeight
;
1862 if ( sz_dec
< 0 ) sz_dec
= 0;
1864 finalPos
.y
+= y_adj
;
1865 finalPos
.height
-= (y_adj
+sz_dec
);
1867 const int textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
;
1869 finalPos
.x
+= textCtrlXAdjust
;
1870 finalPos
.width
-= textCtrlXAdjust
;
1872 finalPos
.x
+= offset
.x
;
1873 finalPos
.y
+= offset
.y
;
1875 ctrl
->SetSize(finalPos
);
1878 // -----------------------------------------------------------------------
1880 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint
& pos
,
1882 const wxString
& value
,
1883 wxWindow
* secondary
,
1887 wxPGProperty
* selected
= m_selected
;
1890 int tcFlags
= wxTE_PROCESS_ENTER
| extraStyle
;
1892 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1893 tcFlags
|= wxTE_READONLY
;
1895 wxPoint
p(pos
.x
,pos
.y
);
1896 wxSize
s(sz
.x
,sz
.y
);
1898 // Need to reduce width of text control on Mac
1899 #if defined(__WXMAC__)
1903 // Take button into acccount
1906 s
.x
-= (secondary
->GetSize().x
+ wxPG_TEXTCTRL_AND_BUTTON_SPACING
);
1907 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
1910 // If the height is significantly higher, then use border, and fill the rect exactly.
1911 bool hasSpecialSize
= false;
1913 if ( (sz
.y
- m_lineHeight
) > 5 )
1914 hasSpecialSize
= true;
1916 #if wxPG_NAT_TEXTCTRL_BORDER_ANY
1918 // Create clipper window
1919 wxPGClipperWindow
* wnd
= new wxPGClipperWindow();
1920 #if defined(__WXMSW__)
1923 wnd
->Create(GetPanel(),wxPG_SUBID1
,p
,s
);
1925 // This generates rect of the control inside the clipper window
1926 if ( !hasSpecialSize
)
1927 wnd
->GetControlRect(wxPG_NAT_TEXTCTRL_BORDER_X
, wxPG_NAT_TEXTCTRL_BORDER_Y
, p
, s
);
1929 wnd
->GetControlRect(0, 0, p
, s
);
1931 wxWindow
* ctrlParent
= wnd
;
1935 wxWindow
* ctrlParent
= GetPanel();
1937 if ( !hasSpecialSize
)
1938 tcFlags
|= wxNO_BORDER
;
1942 wxTextCtrl
* tc
= new wxTextCtrl();
1944 #if defined(__WXMSW__) && !wxPG_NAT_TEXTCTRL_BORDER_ANY
1947 SetupTextCtrlValue(value
);
1948 tc
->Create(ctrlParent
,wxPG_SUBID1
,value
, p
, s
,tcFlags
);
1950 #if wxPG_NAT_TEXTCTRL_BORDER_ANY
1952 wnd
->SetControl(tc
);
1957 // Center the control vertically
1958 if ( !hasSpecialSize
)
1959 FixPosForTextCtrl(ed
);
1967 // Set maximum length
1969 tc
->SetMaxLength( maxLen
);
1971 return (wxWindow
*) ed
;
1974 // -----------------------------------------------------------------------
1976 wxWindow
* wxPropertyGrid::GenerateEditorButton( const wxPoint
& pos
, const wxSize
& sz
)
1978 wxPGProperty
* selected
= m_selected
;
1982 // Decorations are chunky on Mac, and we can't make the button square, so
1983 // do things a bit differently on this platform.
1985 wxPoint
p(pos
.x
+sz
.x
,
1986 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1989 wxButton
* but
= new wxButton();
1990 but
->Create(GetPanel(),wxPG_SUBID2
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1992 // Now that we know the size, move to the correct position
1993 p
.x
= pos
.x
+ sz
.x
- but
->GetSize().x
- 2;
1997 wxSize
s(sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2),
1998 sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2));
2000 // Reduce button width to lineheight
2001 if ( s
.x
> m_lineHeight
)
2005 // On wxGTK, take fixed button margins into account
2010 wxPoint
p(pos
.x
+sz
.x
-s
.x
,
2011 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
2013 wxButton
* but
= new wxButton();
2017 but
->Create(GetPanel(),wxPG_SUBID2
,wxS("..."),p
,s
,wxWANTS_CHARS
);
2020 wxFont font
= GetFont();
2021 font
.SetPointSize(font
.GetPointSize()-2);
2024 but
->SetFont(GetFont());
2028 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
2034 // -----------------------------------------------------------------------
2036 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrlAndButton( const wxPoint
& pos
,
2038 wxWindow
** psecondary
,
2040 wxPGProperty
* property
)
2042 wxButton
* but
= (wxButton
*)GenerateEditorButton(pos
,sz
);
2043 *psecondary
= (wxWindow
*)but
;
2045 if ( limitedEditing
)
2048 // There is button Show in GenerateEditorTextCtrl as well
2051 return (wxWindow
*) NULL
;
2056 if ( !property
->IsValueUnspecified() )
2057 text
= property
->GetValueString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
2059 return GenerateEditorTextCtrl(pos
,sz
,text
,but
,property
->m_maxLen
);
2062 // -----------------------------------------------------------------------
2064 wxTextCtrl
* wxPropertyGrid::GetEditorTextCtrl() const
2066 wxWindow
* wnd
= GetEditorControl();
2071 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2072 return wxStaticCast(wnd
, wxTextCtrl
);
2074 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
2076 wxOwnerDrawnComboBox
* cb
= wxStaticCast(wnd
, wxOwnerDrawnComboBox
);
2077 return cb
->GetTextCtrl();
2083 // -----------------------------------------------------------------------
2085 wxPGEditor
* wxPropertyGridInterface::GetEditorByName( const wxString
& editorName
)
2087 wxPGHashMapS2P::const_iterator it
;
2089 it
= wxPGGlobalVars
->m_mapEditorClasses
.find(editorName
);
2090 if ( it
== wxPGGlobalVars
->m_mapEditorClasses
.end() )
2092 return (wxPGEditor
*) it
->second
;
2095 // -----------------------------------------------------------------------
2096 // wxPGEditorDialogAdapter
2097 // -----------------------------------------------------------------------
2099 IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter
, wxObject
)
2101 bool wxPGEditorDialogAdapter::ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
2103 if ( !propGrid
->EditorValidate() )
2106 bool res
= DoShowDialog( propGrid
, property
);
2110 propGrid
->ValueChangeInEvent( m_value
);
2117 // -----------------------------------------------------------------------
2119 // -----------------------------------------------------------------------
2121 wxPGMultiButton::wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
)
2122 : wxWindow( pg
->GetPanel(), wxPG_SUBID2
, wxPoint(-100,-100), wxSize(0, sz
.y
) ),
2123 m_fullEditorSize(sz
), m_buttonsWidth(0)
2125 SetBackgroundColour(pg
->GetCellBackgroundColour());
2128 int wxPGMultiButton::GenId( int id
) const
2132 if ( m_buttons
.size() )
2133 id
= GetButton(m_buttons
.size()-1)->GetId() + 1;
2141 void wxPGMultiButton::Add( const wxBitmap
& bitmap
, int id
)
2144 wxSize sz
= GetSize();
2145 wxButton
* button
= new wxBitmapButton( this, id
, bitmap
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
2146 m_buttons
.push_back(button
);
2147 int bw
= button
->GetSize().x
;
2148 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
2149 m_buttonsWidth
+= bw
;
2153 void wxPGMultiButton::Add( const wxString
& label
, int id
)
2156 wxSize sz
= GetSize();
2157 wxButton
* button
= new wxButton( this, id
, label
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
2158 m_buttons
.push_back(button
);
2159 int bw
= button
->GetSize().x
;
2160 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
2161 m_buttonsWidth
+= bw
;
2164 // -----------------------------------------------------------------------
2166 #endif // wxUSE_PROPGRID