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"
21 #include "wx/object.h"
23 #include "wx/string.h"
26 #include "wx/window.h"
29 #include "wx/dcclient.h"
30 #include "wx/dcmemory.h"
31 #include "wx/button.h"
34 #include "wx/cursor.h"
35 #include "wx/dialog.h"
36 #include "wx/settings.h"
37 #include "wx/msgdlg.h"
38 #include "wx/choice.h"
39 #include "wx/stattext.h"
40 #include "wx/scrolwin.h"
41 #include "wx/dirdlg.h"
42 #include "wx/layout.h"
44 #include "wx/textdlg.h"
45 #include "wx/filedlg.h"
46 #include "wx/statusbr.h"
53 #include "wx/dcbuffer.h"
54 #include "wx/bmpbuttn.h"
57 // This define is necessary to prevent macro clearing
58 #define __wxPG_SOURCE_FILE__
60 #include <wx/propgrid/propgrid.h>
61 #include <wx/propgrid/editors.h>
62 #include <wx/propgrid/props.h>
64 #if wxPG_USE_RENDERER_NATIVE
65 #include <wx/renderer.h>
68 // How many pixels between textctrl and button
70 #define wxPG_TEXTCTRL_AND_BUTTON_SPACING 8
72 #define wxPG_TEXTCTRL_AND_BUTTON_SPACING 2
75 #define wxPG_BUTTON_SIZEDEC 0
77 #include <wx/odcombo.h>
80 #include <wx/msw/private.h>
83 // -----------------------------------------------------------------------
85 #if defined(__WXMSW__)
87 #define wxPG_NAT_TEXTCTRL_BORDER_X 0 // Unremovable border of native textctrl.
88 #define wxPG_NAT_TEXTCTRL_BORDER_Y 0 // Unremovable border of native textctrl.
90 #define wxPG_NAT_BUTTON_BORDER_ANY 1
91 #define wxPG_NAT_BUTTON_BORDER_X 1
92 #define wxPG_NAT_BUTTON_BORDER_Y 1
94 #define wxPG_CHECKMARK_XADJ 1
95 #define wxPG_CHECKMARK_YADJ (-1)
96 #define wxPG_CHECKMARK_WADJ 0
97 #define wxPG_CHECKMARK_HADJ 0
98 #define wxPG_CHECKMARK_DEFLATE 0
100 #define wxPG_TEXTCTRLYADJUST (m_spacingy+0)
102 #elif defined(__WXGTK__)
104 #define wxPG_CHECKMARK_XADJ 0
105 #define wxPG_CHECKMARK_YADJ 0
106 #define wxPG_CHECKMARK_WADJ (-1)
107 #define wxPG_CHECKMARK_HADJ (-1)
108 #define wxPG_CHECKMARK_DEFLATE 3
110 #define wxPG_NAT_TEXTCTRL_BORDER_X 3 // Unremovable border of native textctrl.
111 #define wxPG_NAT_TEXTCTRL_BORDER_Y 3 // Unremovable border of native textctrl.
113 #define wxPG_NAT_BUTTON_BORDER_ANY 1
114 #define wxPG_NAT_BUTTON_BORDER_X 1
115 #define wxPG_NAT_BUTTON_BORDER_Y 1
117 #define wxPG_TEXTCTRLYADJUST 0
119 #elif defined(__WXMAC__)
121 #define wxPG_CHECKMARK_XADJ 0
122 #define wxPG_CHECKMARK_YADJ 0
123 #define wxPG_CHECKMARK_WADJ 0
124 #define wxPG_CHECKMARK_HADJ 0
125 #define wxPG_CHECKMARK_DEFLATE 0
127 #define wxPG_NAT_TEXTCTRL_BORDER_X 0 // Unremovable border of native textctrl.
128 #define wxPG_NAT_TEXTCTRL_BORDER_Y 0 // Unremovable border of native textctrl.
130 #define wxPG_NAT_BUTTON_BORDER_ANY 0
131 #define wxPG_NAT_BUTTON_BORDER_X 0
132 #define wxPG_NAT_BUTTON_BORDER_Y 0
134 #define wxPG_TEXTCTRLYADJUST 3
138 #define wxPG_CHECKMARK_XADJ 0
139 #define wxPG_CHECKMARK_YADJ 0
140 #define wxPG_CHECKMARK_WADJ 0
141 #define wxPG_CHECKMARK_HADJ 0
142 #define wxPG_CHECKMARK_DEFLATE 0
144 #define wxPG_NAT_TEXTCTRL_BORDER_X 0 // Unremovable border of native textctrl.
145 #define wxPG_NAT_TEXTCTRL_BORDER_Y 0 // Unremovable border of native textctrl.
147 #define wxPG_NAT_BUTTON_BORDER_ANY 0
148 #define wxPG_NAT_BUTTON_BORDER_X 0
149 #define wxPG_NAT_BUTTON_BORDER_Y 0
151 #define wxPG_TEXTCTRLYADJUST 0
155 #if (!wxPG_NAT_TEXTCTRL_BORDER_X && !wxPG_NAT_TEXTCTRL_BORDER_Y)
156 #define wxPG_ENABLE_CLIPPER_WINDOW 0
158 #define wxPG_ENABLE_CLIPPER_WINDOW 1
163 #define wxPG_CHOICEXADJUST 0
164 #define wxPG_CHOICEYADJUST 0
166 #define ODCB_CUST_PAINT_MARGIN 6 // Number added to image width for SetCustomPaintWidth
168 // Milliseconds to wait for two mouse-ups after focus inorder
169 // to trigger a double-click.
170 #define DOUBLE_CLICK_CONVERSION_TRESHOLD 500
172 // -----------------------------------------------------------------------
174 // -----------------------------------------------------------------------
176 IMPLEMENT_ABSTRACT_CLASS(wxPGEditor
, wxObject
)
179 wxPGEditor::~wxPGEditor()
183 void wxPGEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
, wxPGProperty
* property
, const wxString
& text
) const
185 if ( !property
->IsValueUnspecified() )
186 dc
.DrawText( text
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
189 bool wxPGEditor::GetValueFromControl( wxVariant
&, wxPGProperty
*, wxWindow
* ) const
194 void wxPGEditor::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, const wxString
& ) const
199 void wxPGEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, int ) const
204 int wxPGEditor::InsertItem( wxWindow
*, const wxString
&, int ) const
210 void wxPGEditor::DeleteItem( wxWindow
*, int ) const
216 void wxPGEditor::OnFocus( wxPGProperty
*, wxWindow
* ) const
221 bool wxPGEditor::CanContainCustomImage() const
226 // -----------------------------------------------------------------------
228 // -----------------------------------------------------------------------
231 #if wxPG_ENABLE_CLIPPER_WINDOW
234 // Clipper window is used to "remove" borders from controls
235 // which otherwise insist on having them despite of supplied
236 // wxNO_BORDER window style.
238 class wxPGClipperWindow
: public wxWindow
240 DECLARE_CLASS(wxPGClipperWindow
)
246 wxPGClipperWindow::Init();
249 wxPGClipperWindow(wxWindow
* parent
,
251 const wxPoint
& pos
= wxDefaultPosition
,
252 const wxSize
& size
= wxDefaultSize
)
255 Create(parent
,id
,pos
,size
);
258 void Create(wxWindow
* parent
,
260 const wxPoint
& pos
= wxDefaultPosition
,
261 const wxSize
& size
= wxDefaultSize
);
263 virtual ~wxPGClipperWindow();
265 virtual bool ProcessEvent(wxEvent
& event
);
267 inline wxWindow
* GetControl() const { return m_ctrl
; }
269 // This is called before wxControl is constructed.
270 void GetControlRect( int xadj
, int yadj
, wxPoint
& pt
, wxSize
& sz
);
272 // This is caleed after wxControl has been constructed.
273 void SetControl( wxWindow
* ctrl
);
275 virtual void Refresh( bool eraseBackground
= true,
276 const wxRect
*rect
= (const wxRect
*) NULL
);
277 virtual void SetFocus();
279 virtual bool SetFont(const wxFont
& font
);
281 inline int GetXClip() const { return m_xadj
; }
283 inline int GetYClip() const { return m_yadj
; }
288 int m_xadj
; // Horizontal border clip.
290 int m_yadj
; // Vertical border clip.
295 m_ctrl
= (wxWindow
*) NULL
;
300 IMPLEMENT_CLASS(wxPGClipperWindow
,wxWindow
)
303 // This is called before wxControl is constructed.
304 void wxPGClipperWindow::GetControlRect( int xadj
, int yadj
, wxPoint
& pt
, wxSize
& sz
)
310 wxSize own_size
= GetSize();
311 sz
.x
= own_size
.x
+(xadj
*2);
312 sz
.y
= own_size
.y
+(yadj
*2);
316 // This is caleed after wxControl has been constructed.
317 void wxPGClipperWindow::SetControl( wxWindow
* ctrl
)
321 // GTK requires this.
322 ctrl
->SetSizeHints(3,3);
324 // Correct size of this window to match the child.
325 wxSize sz
= GetSize();
326 wxSize chsz
= ctrl
->GetSize();
328 int hei_adj
= chsz
.y
- (sz
.y
+(m_yadj
*2));
330 SetSize(sz
.x
,chsz
.y
-(m_yadj
*2));
335 void wxPGClipperWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
337 wxWindow::Refresh(false,rect
);
339 m_ctrl
->Refresh(eraseBackground
);
343 // Pass focus to control
344 void wxPGClipperWindow::SetFocus()
349 wxWindow::SetFocus();
353 bool wxPGClipperWindow::SetFont(const wxFont
& font
)
355 bool res
= wxWindow::SetFont(font
);
357 return m_ctrl
->SetFont(font
);
362 void wxPGClipperWindow::Create(wxWindow
* parent
,
367 wxWindow::Create(parent
,id
,pos
,size
);
371 wxPGClipperWindow::~wxPGClipperWindow()
376 bool wxPGClipperWindow::ProcessEvent(wxEvent
& event
)
378 if ( event
.GetEventType() == wxEVT_SIZE
)
382 // Maintain correct size relationship.
383 wxSize sz
= GetSize();
384 m_ctrl
->SetSize(sz
.x
+(m_xadj
*2),sz
.y
+(m_yadj
*2));
389 return wxWindow::ProcessEvent(event
);
392 #endif // wxPG_ENABLE_CLIPPER_WINDOW
394 /*wxWindow* wxPropertyGrid::GetActualEditorControl( wxWindow* ctrl )
396 #if wxPG_ENABLE_CLIPPER_WINDOW
397 // Pass real control instead of clipper window
398 if ( ctrl->IsKindOf(CLASSINFO(wxPGClipperWindow)) )
400 return ((wxPGClipperWindow*)ctrl)->GetControl();
407 // -----------------------------------------------------------------------
408 // wxPGTextCtrlEditor
409 // -----------------------------------------------------------------------
411 // Clipper window support macro (depending on whether it is used
412 // for this editor or not)
413 #if wxPG_NAT_TEXTCTRL_BORDER_X || wxPG_NAT_TEXTCTRL_BORDER_Y
414 #define wxPG_NAT_TEXTCTRL_BORDER_ANY 1
416 #define wxPG_NAT_TEXTCTRL_BORDER_ANY 0
419 WX_PG_IMPLEMENT_EDITOR_CLASS(TextCtrl
,wxPGTextCtrlEditor
,wxPGEditor
)
422 wxPGWindowList
wxPGTextCtrlEditor::CreateControls( wxPropertyGrid
* propGrid
,
423 wxPGProperty
* property
,
425 const wxSize
& sz
) const
430 // If has children, and limited editing is specified, then don't create.
431 if ( (property
->GetFlags() & wxPG_PROP_NOEDITOR
) &&
432 property
->GetChildCount() )
433 return (wxWindow
*) NULL
;
435 if ( !property
->IsValueUnspecified() )
436 text
= property
->GetValueString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
439 if ( (property
->GetFlags() & wxPG_PROP_PASSWORD
) &&
440 property
->IsKindOf(CLASSINFO(wxStringProperty
)) )
441 flags
|= wxTE_PASSWORD
;
443 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrl(pos
,sz
,text
,(wxWindow
*)NULL
,flags
,
444 property
->GetMaxLength());
450 void wxPGTextCtrlEditor::DrawValue( wxDC
& dc
, wxPGProperty
* property
, const wxRect
& rect
) const
452 if ( !property
->IsValueUnspecified() )
454 wxString drawStr
= property
->GetDisplayedString();
456 // Code below should no longer be needed, as the obfuscation
457 // is now done in GetValueAsString.
458 /*if ( (property->GetFlags() & wxPG_PROP_PASSWORD) &&
459 property->IsKindOf(WX_PG_CLASSINFO(wxStringProperty)) )
461 size_t a = drawStr.length();
463 drawStr.Append(wxS('*'),a);
465 dc
.DrawText( drawStr
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
470 void wxPGTextCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
472 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
476 if ( tc
->HasFlag(wxTE_PASSWORD
) )
477 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
479 s
= property
->GetDisplayedString();
485 // Provided so that, for example, ComboBox editor can use the same code
486 // (multiple inheritance would get way too messy).
487 bool wxPGTextCtrlEditor::OnTextCtrlEvent( wxPropertyGrid
* propGrid
,
488 wxPGProperty
* WXUNUSED(property
),
495 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
497 if ( propGrid
->IsEditorsValueModified() )
502 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
505 // Pass this event outside wxPropertyGrid so that,
506 // if necessary, program can tell when user is editing
508 // FIXME: Is it safe to change event id in the middle of event
509 // processing (seems to work, but...)?
511 event
.SetId(propGrid
->GetId());
513 propGrid
->EditorsValueWasModified();
519 bool wxPGTextCtrlEditor::OnEvent( wxPropertyGrid
* propGrid
,
520 wxPGProperty
* property
,
522 wxEvent
& event
) const
524 return wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,ctrl
,event
);
528 bool wxPGTextCtrlEditor::GetTextCtrlValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
)
530 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
531 wxString textVal
= tc
->GetValue();
533 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
539 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
541 // Changing unspecified always causes event (returning
542 // true here should be enough to trigger it).
543 // TODO: Move to propgrid.cpp
544 if ( !res
&& variant
.IsNull() )
551 bool wxPGTextCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
553 return wxPGTextCtrlEditor::GetTextCtrlValueFromControl(variant
, property
, ctrl
);
557 void wxPGTextCtrlEditor::SetValueToUnspecified( wxPGProperty
* property
, wxWindow
* ctrl
) const
559 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
561 wxPropertyGrid
* pg
= property
->GetGrid();
562 wxASSERT(pg
); // Really, property grid should exist if editor does
564 tc
->SetValue(wxEmptyString
);
568 void wxPGTextCtrlEditor::SetControlStringValue( wxPGProperty
* property
, wxWindow
* ctrl
, const wxString
& txt
) const
570 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
572 wxPropertyGrid
* pg
= property
->GetGrid();
573 wxASSERT(pg
); // Really, property grid should exist if editor does
579 void wxPGTextCtrlEditor::OnFocus( wxPGProperty
*, wxWindow
* wnd
) const
581 wxTextCtrl
* tc
= wxStaticCast(wnd
, wxTextCtrl
);
583 tc
->SetSelection(-1,-1);
587 wxPGTextCtrlEditor::~wxPGTextCtrlEditor() { }
590 // -----------------------------------------------------------------------
592 // -----------------------------------------------------------------------
595 WX_PG_IMPLEMENT_EDITOR_CLASS(Choice
,wxPGChoiceEditor
,wxPGEditor
)
598 // This is a special enhanced double-click processor class.
599 // In essence, it allows for double-clicks for which the
600 // first click "created" the control.
601 class wxPGDoubleClickProcessor
: public wxEvtHandler
605 wxPGDoubleClickProcessor( wxOwnerDrawnComboBox
* combo
, wxPGProperty
* property
)
608 m_timeLastMouseUp
= 0;
610 m_property
= property
;
611 m_downReceived
= false;
616 void OnMouseEvent( wxMouseEvent
& event
)
618 wxLongLong t
= ::wxGetLocalTimeMillis();
619 int evtType
= event
.GetEventType();
621 if ( m_property
->HasFlag(wxPG_PROP_USE_DCC
) &&
622 m_property
->IsKindOf(CLASSINFO(wxBoolProperty
)) &&
623 !m_combo
->IsPopupShown() )
625 // Just check that it is in the text area
626 wxPoint pt
= event
.GetPosition();
627 if ( m_combo
->GetTextRect().Contains(pt
) )
629 if ( evtType
== wxEVT_LEFT_DOWN
)
631 // Set value to avoid up-events without corresponding downs
632 m_downReceived
= true;
634 else if ( evtType
== wxEVT_LEFT_DCLICK
)
636 // We'll make our own double-clicks
637 event
.SetEventType(0);
640 else if ( evtType
== wxEVT_LEFT_UP
)
642 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
644 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
646 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
648 event
.SetEventType(wxEVT_LEFT_DCLICK
);
649 m_timeLastMouseUp
= 1;
653 m_timeLastMouseUp
= t
;
663 void OnSetFocus( wxFocusEvent
& event
)
665 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
670 wxLongLong m_timeLastMouseUp
;
671 wxOwnerDrawnComboBox
* m_combo
;
672 wxPGProperty
* m_property
; // Selected property
675 DECLARE_EVENT_TABLE()
678 BEGIN_EVENT_TABLE(wxPGDoubleClickProcessor
, wxEvtHandler
)
679 EVT_MOUSE_EVENTS(wxPGDoubleClickProcessor::OnMouseEvent
)
680 EVT_SET_FOCUS(wxPGDoubleClickProcessor::OnSetFocus
)
685 class wxPGComboBox
: public wxOwnerDrawnComboBox
690 : wxOwnerDrawnComboBox()
692 m_dclickProcessor
= (wxPGDoubleClickProcessor
*) NULL
;
693 m_sizeEventCalled
= false;
698 if ( m_dclickProcessor
)
700 RemoveEventHandler(m_dclickProcessor
);
701 delete m_dclickProcessor
;
705 bool Create(wxWindow
*parent
,
707 const wxString
& value
,
710 const wxArrayString
& choices
,
712 const wxValidator
& validator
= wxDefaultValidator
,
713 const wxString
& name
= wxS("wxOwnerDrawnComboBox"))
715 if ( !wxOwnerDrawnComboBox::Create( parent
,
726 m_dclickProcessor
= new wxPGDoubleClickProcessor(this, GetGrid()->GetSelection() );
728 PushEventHandler(m_dclickProcessor
);
733 virtual void OnDrawItem( wxDC
& dc
, const wxRect
& rect
, int item
, int flags
) const
735 wxPropertyGrid
* pg
= GetGrid();
736 pg
->OnComboItemPaint((wxPGCustomComboControl
*)this,item
,dc
,(wxRect
&)rect
,flags
);
738 virtual wxCoord
OnMeasureItem( size_t item
) const
740 wxPropertyGrid
* pg
= GetGrid();
744 pg
->OnComboItemPaint((wxPGCustomComboControl
*)this,item
,*((wxDC
*)NULL
),rect
,0);
748 wxPropertyGrid
* GetGrid() const
750 wxPropertyGrid
* pg
= wxDynamicCast(GetParent()->GetParent(),wxPropertyGrid
);
755 virtual wxCoord
OnMeasureItemWidth( size_t item
) const
757 wxPropertyGrid
* pg
= GetGrid();
761 pg
->OnComboItemPaint((wxPGCustomComboControl
*)this,item
,*((wxDC
*)NULL
),rect
,0);
765 virtual void PositionTextCtrl( int WXUNUSED(textCtrlXAdjust
), int WXUNUSED(textCtrlYAdjust
) )
767 wxPropertyGrid
* pg
= GetGrid();
768 wxOwnerDrawnComboBox::PositionTextCtrl(
769 wxPG_TEXTCTRLXADJUST
- (wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1) - 1,
770 pg
->GetSpacingY() + 2
775 wxPGDoubleClickProcessor
* m_dclickProcessor
;
776 bool m_sizeEventCalled
;
780 void wxPropertyGrid::OnComboItemPaint( wxPGCustomComboControl
* pCc
,
786 wxPGComboBox
* pCb
= (wxPGComboBox
*)pCc
;
789 wxASSERT( IsKindOf(CLASSINFO(wxPropertyGrid
)) );
791 wxPGProperty
* p
= m_selected
;
794 const wxPGChoices
* pChoices
= &p
->GetChoices();
795 const wxPGCommonValue
* comVal
= NULL
;
796 int choiceCount
= p
->GetChoiceCount();
797 int comVals
= p
->GetDisplayedCommonValueCount();
798 int comValIndex
= -1;
799 if ( item
>= choiceCount
&& comVals
> 0 )
801 comValIndex
= item
- choiceCount
;
802 comVal
= GetCommonValue(comValIndex
);
803 if ( !p
->IsValueUnspecified() )
804 text
= comVal
->GetLabel();
808 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
810 text
= pCb
->GetString(item
);
814 if ( !p
->IsValueUnspecified() )
815 text
= p
->GetValueString(0);
824 const wxBitmap
* itemBitmap
= NULL
;
826 if ( item
>= 0 && pChoices
&& pChoices
->Item(item
).GetBitmap().Ok() && comValIndex
== -1 )
827 itemBitmap
= &pChoices
->Item(item
).GetBitmap();
830 // Decide what custom image size to use
833 cis
.x
= itemBitmap
->GetWidth();
834 cis
.y
= itemBitmap
->GetHeight();
838 cis
= GetImageSize(p
, item
);
843 // Default measure behaviour (no flexible, custom paint image only)
844 if ( rect
.width
< 0 )
847 GetTextExtent(text
, &x
, &y
, 0, 0, &m_font
);
848 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9 + x
;
851 rect
.height
= cis
.y
+ 2;
855 wxPGPaintData paintdata
;
856 paintdata
.m_parent
= NULL
;
857 paintdata
.m_choiceItem
= item
;
859 // This is by the current (1.0.0b) spec - if painting control, item is -1
860 if ( (flags
& wxODCB_PAINTING_CONTROL
) )
861 paintdata
.m_choiceItem
= -1;
864 dc
.SetBrush(*wxWHITE_BRUSH
);
871 wxPoint
pt(rect
.x
+ wxPG_CONTROL_MARGIN
- wxPG_CHOICEXADJUST
- 1,
876 if ( flags
& wxODCB_PAINTING_CONTROL
)
877 renderFlags
|= wxPGCellRenderer::Control
;
879 if ( flags
& wxODCB_PAINTING_SELECTED
)
880 renderFlags
|= wxPGCellRenderer::Selected
;
882 if ( cis
.x
> 0 && (p
->HasFlag(wxPG_PROP_CUSTOMIMAGE
) || !(flags
& wxODCB_PAINTING_CONTROL
)) &&
883 ( !p
->m_valueBitmap
|| item
== pCb
->GetSelection() ) &&
884 ( item
>= 0 || (flags
& wxODCB_PAINTING_CONTROL
) ) &&
888 pt
.x
+= wxCC_CUSTOM_IMAGE_MARGIN1
;
889 wxRect
r(pt
.x
,pt
.y
,cis
.x
,cis
.y
);
891 if ( flags
& wxODCB_PAINTING_CONTROL
)
894 r
.height
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
897 paintdata
.m_drawnWidth
= r
.width
;
899 dc
.SetPen(m_colPropFore
);
900 if ( comValIndex
>= 0 )
902 const wxPGCommonValue
* cv
= GetCommonValue(comValIndex
);
903 wxPGCellRenderer
* renderer
= cv
->GetRenderer();
904 r
.width
= rect
.width
;
905 renderer
->Render( dc
, r
, this, p
, m_selColumn
, comValIndex
, renderFlags
);
908 else if ( item
>= 0 )
910 p
->OnCustomPaint( dc
, r
, paintdata
);
914 dc
.DrawRectangle( r
);
917 pt
.x
+= paintdata
.m_drawnWidth
+ wxCC_CUSTOM_IMAGE_MARGIN2
- 1;
921 // TODO: This aligns text so that it seems to be horizontally
922 // on the same line as property values. Not really
923 // sure if its needed, but seems to not cause any harm.
926 if ( item
< 0 && (flags
& wxODCB_PAINTING_CONTROL
) )
927 item
= pCb
->GetSelection();
929 if ( pChoices
&& item
>= 0 && comValIndex
< 0 )
931 const wxPGChoiceEntry
& cell
= pChoices
->Item(item
);
932 wxPGCellRenderer
* renderer
= wxPGGlobalVars
->m_defaultRenderer
;
933 int imageOffset
= renderer
->PreDrawCell( dc
, rect
, cell
, renderFlags
);
935 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
944 pt
.y
+= (rect
.height
-m_fontHeight
)/2 - 1;
948 dc
.DrawText( text
, pt
.x
+ wxPG_XBEFORETEXT
, pt
.y
);
955 p
->OnCustomPaint( dc
, rect
, paintdata
);
956 rect
.height
= paintdata
.m_drawnHeight
+ 2;
957 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9;
961 bool wxPGChoiceEditor_SetCustomPaintWidth( wxPropertyGrid
* propGrid
, wxPGComboBox
* cb
, int cmnVal
)
963 wxPGProperty
* property
= propGrid
->GetSelectedProperty();
964 wxASSERT( property
);
968 // Yes, a common value is being selected
969 property
->SetCommonValue( cmnVal
);
970 wxSize imageSize
= propGrid
->GetCommonValue(cmnVal
)->
971 GetRenderer()->GetImageSize(property
, 1, cmnVal
);
972 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
973 cb
->SetCustomPaintWidth( imageSize
.x
);
978 wxSize imageSize
= propGrid
->GetImageSize(property
, -1);
979 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
980 cb
->SetCustomPaintWidth( imageSize
.x
);
985 // CreateControls calls this with CB_READONLY in extraStyle
986 wxWindow
* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid
* propGrid
,
987 wxPGProperty
* property
,
990 long extraStyle
) const
995 int index
= property
->GetChoiceInfo( NULL
);
997 bool isUnspecified
= property
->IsValueUnspecified();
1002 defString
= property
->GetDisplayedString();
1004 const wxPGChoices
& choices
= property
->GetChoices();
1006 wxArrayString labels
= choices
.GetLabels();
1012 po
.y
+= wxPG_CHOICEYADJUST
;
1013 si
.y
-= (wxPG_CHOICEYADJUST
*2);
1015 po
.x
+= wxPG_CHOICEXADJUST
;
1016 si
.x
-= wxPG_CHOICEXADJUST
;
1017 wxWindow
* ctrlParent
= propGrid
->GetPanel();
1019 int odcbFlags
= extraStyle
| wxNO_BORDER
| wxTE_PROCESS_ENTER
;
1022 // If common value specified, use appropriate index
1023 unsigned int cmnVals
= property
->GetDisplayedCommonValueCount();
1026 if ( !isUnspecified
)
1028 int cmnVal
= property
->GetCommonValue();
1031 index
= labels
.size() + cmnVal
;
1036 for ( i
=0; i
<cmnVals
; i
++ )
1037 labels
.Add(propGrid
->GetCommonValueLabel(i
));
1040 cb
= new wxPGComboBox();
1044 cb
->Create(ctrlParent
,
1052 //int extRight = propGrid->GetClientSize().x - (po.x+si.x);
1053 //int extRight = - (po.x+si.x);
1055 cb
->SetButtonPosition(si
.y
,0,wxRIGHT
);
1056 //cb->SetPopupExtents( 1, extRight );
1057 cb
->SetTextIndent(wxPG_XBEFORETEXT
-1);
1059 wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, property
->GetCommonValue() );
1060 /*if ( property->GetFlags() & wxPG_PROP_CUSTOMIMAGE )
1062 wxSize imageSize = propGrid->GetImageSize(property, index);
1063 if ( imageSize.x ) imageSize.x += ODCB_CUST_PAINT_MARGIN;
1064 cb->SetCustomPaintWidth( imageSize.x );
1067 if ( index
>= 0 && index
< (int)cb
->GetCount() )
1069 cb
->SetSelection( index
);
1070 if ( defString
.length() )
1071 cb
->SetText( defString
);
1073 else if ( !(extraStyle
& wxCB_READONLY
) && defString
.length() )
1074 cb
->SetValue( defString
);
1076 cb
->SetSelection( -1 );
1082 return (wxWindow
*) cb
;
1086 void wxPGChoiceEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1089 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1090 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1091 int ind
= property
->GetChoiceInfo( (wxPGChoiceInfo
*)NULL
);
1092 cb
->SetSelection(ind
);
1095 wxPGWindowList
wxPGChoiceEditor::CreateControls( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
1096 const wxPoint
& pos
, const wxSize
& sz
) const
1098 return CreateControlsBase(propGrid
,property
,pos
,sz
,wxCB_READONLY
);
1102 int wxPGChoiceEditor::InsertItem( wxWindow
* ctrl
, const wxString
& label
, int index
) const
1105 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1106 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1109 index
= cb
->GetCount();
1111 return cb
->Insert(label
,index
);
1115 void wxPGChoiceEditor::DeleteItem( wxWindow
* ctrl
, int index
) const
1118 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1119 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1124 bool wxPGChoiceEditor::OnEvent( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
1125 wxWindow
* ctrl
, wxEvent
& event
) const
1127 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
1129 wxPGComboBox
* cb
= (wxPGComboBox
*)ctrl
;
1130 int index
= cb
->GetSelection();
1131 int cmnValIndex
= -1;
1132 int cmnVals
= property
->GetDisplayedCommonValueCount();
1133 int items
= cb
->GetCount();
1135 if ( index
>= (items
-cmnVals
) )
1137 // Yes, a common value is being selected
1138 cmnValIndex
= index
- (items
-cmnVals
);
1139 property
->SetCommonValue( cmnValIndex
);
1141 // Truly set value to unspecified?
1142 if ( propGrid
->GetUnspecifiedCommonValue() == cmnValIndex
)
1144 if ( !property
->IsValueUnspecified() )
1145 propGrid
->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT
);
1146 property
->SetValueToUnspecified();
1147 if ( !cb
->HasFlag(wxCB_READONLY
) )
1148 cb
->GetTextCtrl()->SetValue(wxEmptyString
);
1152 return wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, cmnValIndex
);
1158 bool wxPGChoiceEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1160 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1162 int index
= cb
->GetSelection();
1164 if ( index
!= property
->GetChoiceInfo( (wxPGChoiceInfo
*) NULL
) ||
1165 // Changing unspecified always causes event (returning
1166 // true here should be enough to trigger it).
1167 property
->IsValueUnspecified()
1170 return property
->IntToValue( variant
, index
, 0 );
1176 void wxPGChoiceEditor::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, const wxString
& txt
) const
1178 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1184 void wxPGChoiceEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1186 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1188 cb
->SetSelection(value
);
1192 void wxPGChoiceEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1194 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1195 cb
->SetSelection(-1);
1199 bool wxPGChoiceEditor::CanContainCustomImage() const
1205 wxPGChoiceEditor::~wxPGChoiceEditor() { }
1208 // -----------------------------------------------------------------------
1209 // wxPGComboBoxEditor
1210 // -----------------------------------------------------------------------
1213 WX_PG_IMPLEMENT_EDITOR_CLASS(ComboBox
,wxPGComboBoxEditor
,wxPGChoiceEditor
)
1216 void wxPGComboBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1218 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1219 cb
->SetValue(property
->GetValueString(wxPG_EDITABLE_VALUE
));
1221 // TODO: If string matches any selection, then select that.
1225 wxPGWindowList
wxPGComboBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1226 wxPGProperty
* property
,
1228 const wxSize
& sz
) const
1230 return CreateControlsBase(propGrid
,property
,pos
,sz
,0);
1234 bool wxPGComboBoxEditor::OnEvent( wxPropertyGrid
* propGrid
,
1235 wxPGProperty
* property
,
1237 wxEvent
& event
) const
1239 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*) NULL
;
1240 wxWindow
* textCtrl
= (wxWindow
*) NULL
;
1244 cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1245 textCtrl
= cb
->GetTextCtrl();
1248 if ( wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,textCtrl
,event
) )
1251 return wxPGChoiceEditor::OnEvent(propGrid
,property
,ctrl
,event
);
1255 bool wxPGComboBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1257 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1258 wxString textVal
= cb
->GetValue();
1260 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
1266 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
1268 // Changing unspecified always causes event (returning
1269 // true here should be enough to trigger it).
1270 if ( !res
&& variant
.IsNull() )
1277 void wxPGComboBoxEditor::OnFocus( wxPGProperty
*, wxWindow
* ctrl
) const
1279 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1280 cb
->GetTextCtrl()->SetSelection(-1,-1);
1284 wxPGComboBoxEditor::~wxPGComboBoxEditor() { }
1287 // -----------------------------------------------------------------------
1288 // wxPGChoiceAndButtonEditor
1289 // -----------------------------------------------------------------------
1292 // This simpler implement_editor macro doesn't define class body.
1293 WX_PG_IMPLEMENT_EDITOR_CLASS(ChoiceAndButton
,wxPGChoiceAndButtonEditor
,wxPGChoiceEditor
)
1296 wxPGWindowList
wxPGChoiceAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1297 wxPGProperty
* property
,
1299 const wxSize
& sz
) const
1301 // Use one two units smaller to match size of the combo's dropbutton.
1302 // (normally a bigger button is used because it looks better)
1305 wxSize
bt_sz(bt_wid
,bt_wid
);
1307 // Position of button.
1308 wxPoint
bt_pos(pos
.x
+sz
.x
-bt_sz
.x
,pos
.y
);
1315 wxWindow
* bt
= propGrid
->GenerateEditorButton( bt_pos
, bt_sz
);
1318 wxSize
ch_sz(sz
.x
-bt
->GetSize().x
,sz
.y
);
1321 ch_sz
.x
-= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1324 wxWindow
* ch
= wxPG_EDITOR(Choice
)->CreateControls(propGrid
,property
,
1325 pos
,ch_sz
).m_primary
;
1331 return wxPGWindowList(ch
, bt
);
1335 wxPGChoiceAndButtonEditor::~wxPGChoiceAndButtonEditor() { }
1338 // -----------------------------------------------------------------------
1339 // wxPGTextCtrlAndButtonEditor
1340 // -----------------------------------------------------------------------
1343 // This simpler implement_editor macro doesn't define class body.
1344 WX_PG_IMPLEMENT_EDITOR_CLASS(TextCtrlAndButton
,wxPGTextCtrlAndButtonEditor
,wxPGTextCtrlEditor
)
1347 wxPGWindowList
wxPGTextCtrlAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1348 wxPGProperty
* property
,
1350 const wxSize
& sz
) const
1353 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrlAndButton( pos
, sz
, &wnd2
,
1354 property
->GetFlags() & wxPG_PROP_NOEDITOR
, property
);
1356 return wxPGWindowList(wnd
, wnd2
);
1360 wxPGTextCtrlAndButtonEditor::~wxPGTextCtrlAndButtonEditor() { }
1363 // -----------------------------------------------------------------------
1364 // wxPGCheckBoxEditor
1365 // -----------------------------------------------------------------------
1367 #if wxPG_INCLUDE_CHECKBOX
1369 WX_PG_IMPLEMENT_EDITOR_CLASS(CheckBox
,wxPGCheckBoxEditor
,wxPGEditor
)
1372 // state argument: 0x01 = set if checked
1373 // 0x02 = set if rectangle should be bold
1374 static void DrawSimpleCheckBox( wxDC
& dc
, const wxRect
& rect
, int box_hei
, int state
, const wxColour
& linecol
)
1378 wxRect
r(rect
.x
+wxPG_XBEFORETEXT
,rect
.y
+((rect
.height
-box_hei
)/2),box_hei
,box_hei
);
1380 // Draw check mark first because it is likely to overdraw the
1381 // surrounding rectangle.
1384 wxRect
r2(r
.x
+wxPG_CHECKMARK_XADJ
,
1385 r
.y
+wxPG_CHECKMARK_YADJ
,
1386 r
.width
+wxPG_CHECKMARK_WADJ
,
1387 r
.height
+wxPG_CHECKMARK_HADJ
);
1388 #if wxPG_CHECKMARK_DEFLATE
1389 r2
.Deflate(wxPG_CHECKMARK_DEFLATE
);
1391 dc
.DrawCheckMark(r2
);
1393 // This would draw a simple cross check mark.
1394 // dc.DrawLine(r.x,r.y,r.x+r.width-1,r.y+r.height-1);
1395 // dc.DrawLine(r.x,r.y+r.height-1,r.x+r.width-1,r.y);
1401 // Pen for thin rectangle.
1406 // Pen for bold rectangle.
1407 wxPen
linepen(linecol
,2,wxSOLID
);
1408 linepen
.SetJoin(wxJOIN_MITER
); // This prevents round edges.
1416 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1418 dc
.DrawRectangle(r
);
1419 dc
.SetPen(*wxTRANSPARENT_PEN
);
1423 // Real simple custom-drawn checkbox-without-label class.
1425 class wxSimpleCheckBox
: public wxControl
1429 void SetValue( int value
);
1431 wxSimpleCheckBox( wxWindow
* parent
,
1433 const wxPoint
& pos
= wxDefaultPosition
,
1434 const wxSize
& size
= wxDefaultSize
)
1435 : wxControl(parent
,id
,pos
,size
,wxNO_BORDER
|wxWANTS_CHARS
)
1437 // Due to SetOwnFont stuff necessary for GTK+ 1.2, we need to have this
1438 SetFont( parent
->GetFont() );
1441 wxPropertyGrid
* pg
= (wxPropertyGrid
*) parent
->GetParent();
1442 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1443 m_boxHeight
= pg
->GetFontHeight();
1444 SetBackgroundStyle( wxBG_STYLE_COLOUR
);
1447 virtual ~wxSimpleCheckBox();
1449 virtual bool ProcessEvent(wxEvent
& event
);
1454 static wxBitmap
* ms_doubleBuffer
;
1458 wxSimpleCheckBox::~wxSimpleCheckBox()
1460 delete ms_doubleBuffer
;
1461 ms_doubleBuffer
= NULL
;
1465 wxBitmap
* wxSimpleCheckBox::ms_doubleBuffer
= (wxBitmap
*) NULL
;
1467 // value = 2 means toggle (sorry, too lazy to do constants)
1468 void wxSimpleCheckBox::SetValue( int value
)
1473 if ( m_state
> 1 ) m_state
= 0;
1481 wxCommandEvent
evt(wxEVT_COMMAND_CHECKBOX_CLICKED
,GetParent()->GetId());
1483 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent()->GetParent();
1484 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1485 propGrid
->OnCustomEditorEvent(evt
);
1489 bool wxSimpleCheckBox::ProcessEvent(wxEvent
& event
)
1491 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent()->GetParent();
1492 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1494 if ( event
.GetEventType() == wxEVT_NAVIGATION_KEY
)
1496 //wxLogDebug(wxT("wxEVT_NAVIGATION_KEY"));
1497 //SetFocusFromKbd();
1499 //return wxControl::ProcessEvent(event);
1502 if ( ( (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1503 && ((wxMouseEvent
&)event
).m_x
> (wxPG_XBEFORETEXT
-2)
1504 && ((wxMouseEvent
&)event
).m_x
<= (wxPG_XBEFORETEXT
-2+m_boxHeight
) )
1510 else if ( event
.GetEventType() == wxEVT_PAINT
)
1512 wxSize clientSize
= GetClientSize();
1516 // Buffered paint DC doesn't seem to do much good
1517 if ( !ms_doubleBuffer ||
1518 clientSize.x > ms_doubleBuffer->GetWidth() ||
1519 clientSize.y > ms_doubleBuffer->GetHeight() )
1521 delete ms_doubleBuffer;
1522 ms_doubleBuffer = new wxBitmap(clientSize.x+25,clientSize.y+25);
1525 wxBufferedPaintDC dc(this,*ms_doubleBuffer);
1528 wxRect
rect(0,0,clientSize
.x
,clientSize
.y
);
1533 m_boxHeight
= propGrid
->GetFontHeight();
1535 wxColour bgcol
= GetBackgroundColour();
1536 dc
.SetBrush( bgcol
);
1538 dc
.DrawRectangle( rect
);
1540 wxColour txcol
= GetForegroundColour();
1542 int state
= m_state
;
1543 if ( m_font
.GetWeight() == wxBOLD
)
1546 DrawSimpleCheckBox(dc
,rect
,m_boxHeight
,state
,txcol
);
1548 // If focused, indicate it somehow.
1550 if ( wxWindow::FindFocus() == this )
1555 wxPGDrawFocusRect(dc,rect);
1561 else if ( event
.GetEventType() == wxEVT_SIZE
||
1562 event
.GetEventType() == wxEVT_SET_FOCUS
||
1563 event
.GetEventType() == wxEVT_KILL_FOCUS
1568 else if ( event
.GetEventType() == wxEVT_KEY_DOWN
)
1570 wxKeyEvent
& keyEv
= (wxKeyEvent
&) event
;
1572 if ( keyEv
.GetKeyCode() == WXK_TAB
)
1574 propGrid
->SendNavigationKeyEvent( keyEv
.ShiftDown()?0:1 );
1578 if ( keyEv
.GetKeyCode() == WXK_SPACE
)
1584 return wxControl::ProcessEvent(event
);
1588 wxPGWindowList
wxPGCheckBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1589 wxPGProperty
* property
,
1591 const wxSize
& size
) const
1594 pt
.x
-= wxPG_XBEFOREWIDGET
;
1596 sz
.x
= propGrid
->GetFontHeight() + (wxPG_XBEFOREWIDGET
*2) + 4;
1598 wxSimpleCheckBox
* cb
= new wxSimpleCheckBox(propGrid
->GetPanel(),wxPG_SUBID1
,pt
,sz
);
1600 cb
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
1602 cb
->Connect( wxPG_SUBID1
, wxEVT_LEFT_DOWN
,
1603 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
1604 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propGrid
);
1606 cb
->Connect( wxPG_SUBID1
, wxEVT_LEFT_DCLICK
,
1607 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
1608 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propGrid
);
1610 if ( property
->GetChoiceInfo((wxPGChoiceInfo
*)NULL
) &&
1611 !property
->IsValueUnspecified() )
1614 // If mouse cursor was on the item, toggle the value now.
1615 if ( propGrid
->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK
)
1617 wxPoint pt
= cb
->ScreenToClient(::wxGetMousePosition());
1618 if ( pt
.x
<= (wxPG_XBEFORETEXT
-2+cb
->m_boxHeight
) )
1622 if ( cb
->m_state
> 1 )
1625 // Makes sure wxPG_EVT_CHANGING etc. is sent for this initial click
1626 propGrid
->ChangePropertyValue(property
, wxPGVariant_Bool(cb
->m_state
));
1630 propGrid
->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR
);
1636 class wxPGCheckBoxRenderer : public wxPGDefaultRenderer
1640 virtual void Render( wxDC& dc, const wxRect& rect,
1641 const wxPropertyGrid* WXUNUSED(propertyGrid), wxPGProperty* property,
1642 int WXUNUSED(column), int WXUNUSED(item), int WXUNUSED(flags) ) const
1645 if ( !(property->GetFlags() & wxPG_PROP_UNSPECIFIED) )
1647 state = ((wxPGProperty*)property)->GetChoiceInfo((wxPGChoiceInfo*)NULL);
1648 if ( dc.GetFont().GetWeight() == wxBOLD ) state |= 2;
1650 DrawSimpleCheckBox(dc,rect,dc.GetCharHeight(),state,dc.GetTextForeground());
1656 wxPGCheckBoxRenderer g_wxPGCheckBoxRenderer;
1658 wxPGCellRenderer* wxPGCheckBoxEditor::GetCellRenderer() const
1660 return &g_wxPGCheckBoxRenderer;
1664 void wxPGCheckBoxEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
, wxPGProperty
* property
, const wxString
& WXUNUSED(text
) ) const
1667 if ( !property
->IsValueUnspecified() )
1669 state
= property
->GetChoiceInfo((wxPGChoiceInfo
*)NULL
);
1670 if ( dc
.GetFont().GetWeight() == wxBOLD
) state
|= 2;
1672 DrawSimpleCheckBox(dc
,rect
,dc
.GetCharHeight(),state
,dc
.GetTextForeground());
1675 void wxPGCheckBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1678 ((wxSimpleCheckBox
*)ctrl
)->m_state
= property
->GetChoiceInfo((wxPGChoiceInfo
*)NULL
);
1683 bool wxPGCheckBoxEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propGrid
), wxPGProperty
* WXUNUSED(property
),
1684 wxWindow
* WXUNUSED(ctrl
), wxEvent
& event
) const
1686 if ( event
.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED
)
1694 bool wxPGCheckBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1696 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*)ctrl
;
1698 int index
= cb
->m_state
;
1700 if ( index
!= property
->GetChoiceInfo( (wxPGChoiceInfo
*) NULL
) ||
1701 // Changing unspecified always causes event (returning
1702 // true here should be enough to trigger it).
1703 property
->IsValueUnspecified()
1706 return property
->IntToValue(variant
, index
, 0);
1712 void wxPGCheckBoxEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1714 if ( value
!= 0 ) value
= 1;
1715 ((wxSimpleCheckBox
*)ctrl
)->m_state
= value
;
1720 void wxPGCheckBoxEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1722 ((wxSimpleCheckBox
*)ctrl
)->m_state
= 0;
1727 wxPGCheckBoxEditor::~wxPGCheckBoxEditor() { }
1730 #endif // wxPG_INCLUDE_CHECKBOX
1732 // -----------------------------------------------------------------------
1734 wxWindow
* wxPropertyGrid::GetEditorControl() const
1736 wxWindow
* ctrl
= m_wndEditor
;
1741 // If it's clipper window, return its child instead
1742 #if wxPG_ENABLE_CLIPPER_WINDOW
1743 if ( ctrl
->IsKindOf(CLASSINFO(wxPGClipperWindow
)) )
1745 return ((wxPGClipperWindow
*)ctrl
)->GetControl();
1752 // -----------------------------------------------------------------------
1754 void wxPropertyGrid::CorrectEditorWidgetSizeX()
1756 if ( m_selColumn
== -1 )
1760 int newSplitterx
= m_pState
->DoGetSplitterPosition(m_selColumn
-1);
1761 int newWidth
= newSplitterx
+ m_pState
->m_colWidths
[m_selColumn
];
1765 // if width change occurred, move secondary wnd by that amount
1766 wxRect r
= m_wndEditor2
->GetRect();
1768 r
.x
= newWidth
- secWid
;
1770 m_wndEditor2
->SetSize( r
);
1772 // if primary is textctrl, then we have to add some extra space
1776 if ( m_wndEditor
&& m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1778 secWid
+= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1783 wxRect r
= m_wndEditor
->GetRect();
1785 r
.x
= newSplitterx
+m_ctrlXAdjust
;
1787 if ( !(m_iFlags
& wxPG_FL_FIXED_WIDTH_EDITOR
) )
1788 r
.width
= newWidth
- r
.x
- secWid
;
1790 m_wndEditor
->SetSize(r
);
1794 m_wndEditor2
->Refresh();
1797 // -----------------------------------------------------------------------
1799 void wxPropertyGrid::CorrectEditorWidgetPosY()
1801 if ( m_selected
&& (m_wndEditor
|| m_wndEditor2
) )
1803 wxRect r
= GetEditorWidgetRect(m_selected
, m_selColumn
);
1807 wxPoint pos
= m_wndEditor
->GetPosition();
1809 // Calculate y offset
1810 int offset
= pos
.y
% m_lineHeight
;
1812 m_wndEditor
->Move(pos
.x
, r
.y
+ offset
);
1817 wxPoint pos
= m_wndEditor2
->GetPosition();
1819 m_wndEditor2
->Move(pos
.x
, r
.y
);
1824 // -----------------------------------------------------------------------
1826 bool wxPropertyGrid::AdjustPosForClipperWindow( wxWindow
* topCtrlWnd
, int* x
, int* y
)
1828 #if wxPG_ENABLE_CLIPPER_WINDOW
1829 // Take clipper window into account
1830 if (topCtrlWnd
->GetPosition().x
< 1 &&
1831 !topCtrlWnd
->IsKindOf(CLASSINFO(wxPGClipperWindow
)))
1833 topCtrlWnd
= topCtrlWnd
->GetParent();
1834 wxASSERT( topCtrlWnd
->IsKindOf(CLASSINFO(wxPGClipperWindow
)) );
1835 *x
-= ((wxPGClipperWindow
*)topCtrlWnd
)->GetXClip();
1836 *y
-= ((wxPGClipperWindow
*)topCtrlWnd
)->GetYClip();
1840 wxUnusedVar(topCtrlWnd
);
1847 // -----------------------------------------------------------------------
1849 // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
1850 // fits into that category as well).
1851 void wxPropertyGrid::FixPosForTextCtrl( wxWindow
* ctrl
, const wxPoint
& offset
)
1853 // Center the control vertically
1854 wxRect finalPos
= ctrl
->GetRect();
1855 int y_adj
= (m_lineHeight
- finalPos
.height
)/2 + wxPG_TEXTCTRLYADJUST
;
1857 // Prevent over-sized control
1858 int sz_dec
= (y_adj
+ finalPos
.height
) - m_lineHeight
;
1859 if ( sz_dec
< 0 ) sz_dec
= 0;
1861 finalPos
.y
+= y_adj
;
1862 finalPos
.height
-= (y_adj
+sz_dec
);
1864 const int textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
;
1866 finalPos
.x
+= textCtrlXAdjust
;
1867 finalPos
.width
-= textCtrlXAdjust
;
1869 finalPos
.x
+= offset
.x
;
1870 finalPos
.y
+= offset
.y
;
1872 ctrl
->SetSize(finalPos
);
1875 // -----------------------------------------------------------------------
1877 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint
& pos
,
1879 const wxString
& value
,
1880 wxWindow
* secondary
,
1884 wxPGProperty
* selected
= m_selected
;
1887 int tcFlags
= wxTE_PROCESS_ENTER
| extraStyle
;
1889 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1890 tcFlags
|= wxTE_READONLY
;
1892 wxPoint
p(pos
.x
,pos
.y
);
1893 wxSize
s(sz
.x
,sz
.y
);
1895 // Need to reduce width of text control on Mac
1896 #if defined(__WXMAC__)
1900 // Take button into acccount
1903 s
.x
-= (secondary
->GetSize().x
+ wxPG_TEXTCTRL_AND_BUTTON_SPACING
);
1904 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
1907 // If the height is significantly higher, then use border, and fill the rect exactly.
1908 bool hasSpecialSize
= false;
1910 if ( (sz
.y
- m_lineHeight
) > 5 )
1911 hasSpecialSize
= true;
1913 #if wxPG_NAT_TEXTCTRL_BORDER_ANY
1915 // Create clipper window
1916 wxPGClipperWindow
* wnd
= new wxPGClipperWindow();
1917 #if defined(__WXMSW__)
1920 wnd
->Create(GetPanel(),wxPG_SUBID1
,p
,s
);
1922 // This generates rect of the control inside the clipper window
1923 if ( !hasSpecialSize
)
1924 wnd
->GetControlRect(wxPG_NAT_TEXTCTRL_BORDER_X
, wxPG_NAT_TEXTCTRL_BORDER_Y
, p
, s
);
1926 wnd
->GetControlRect(0, 0, p
, s
);
1928 wxWindow
* ctrlParent
= wnd
;
1932 wxWindow
* ctrlParent
= GetPanel();
1934 if ( !hasSpecialSize
)
1935 tcFlags
|= wxNO_BORDER
;
1939 wxTextCtrl
* tc
= new wxTextCtrl();
1941 #if defined(__WXMSW__) && !wxPG_NAT_TEXTCTRL_BORDER_ANY
1944 SetupTextCtrlValue(value
);
1945 tc
->Create(ctrlParent
,wxPG_SUBID1
,value
, p
, s
,tcFlags
);
1947 #if wxPG_NAT_TEXTCTRL_BORDER_ANY
1949 wnd
->SetControl(tc
);
1954 // Center the control vertically
1955 if ( !hasSpecialSize
)
1956 FixPosForTextCtrl(ed
);
1964 // Set maximum length
1966 tc
->SetMaxLength( maxLen
);
1968 return (wxWindow
*) ed
;
1971 // -----------------------------------------------------------------------
1973 wxWindow
* wxPropertyGrid::GenerateEditorButton( const wxPoint
& pos
, const wxSize
& sz
)
1975 wxPGProperty
* selected
= m_selected
;
1979 // Decorations are chunky on Mac, and we can't make the button square, so
1980 // do things a bit differently on this platform.
1982 wxPoint
p(pos
.x
+sz
.x
,
1983 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1986 wxButton
* but
= new wxButton();
1987 but
->Create(GetPanel(),wxPG_SUBID2
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1989 // Now that we know the size, move to the correct position
1990 p
.x
= pos
.x
+ sz
.x
- but
->GetSize().x
- 2;
1994 wxSize
s(sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2),
1995 sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2));
1997 // Reduce button width to lineheight
1998 if ( s
.x
> m_lineHeight
)
2001 wxPoint
p(pos
.x
+sz
.x
-s
.x
,
2002 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
2004 wxButton
* but
= new wxButton();
2008 but
->Create(GetPanel(),wxPG_SUBID2
,wxS("..."),p
,s
,wxWANTS_CHARS
);
2010 but
->SetFont( m_captionFont
);
2013 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
2019 // -----------------------------------------------------------------------
2021 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrlAndButton( const wxPoint
& pos
,
2023 wxWindow
** psecondary
,
2025 wxPGProperty
* property
)
2027 wxButton
* but
= (wxButton
*)GenerateEditorButton(pos
,sz
);
2028 *psecondary
= (wxWindow
*)but
;
2030 if ( limitedEditing
)
2033 // There is button Show in GenerateEditorTextCtrl as well
2036 return (wxWindow
*) NULL
;
2041 if ( !property
->IsValueUnspecified() )
2042 text
= property
->GetValueString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
2044 return GenerateEditorTextCtrl(pos
,sz
,text
,but
,property
->m_maxLen
);
2047 // -----------------------------------------------------------------------
2049 wxTextCtrl
* wxPropertyGrid::GetEditorTextCtrl() const
2051 wxWindow
* wnd
= GetEditorControl();
2056 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2057 return wxStaticCast(wnd
, wxTextCtrl
);
2059 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
2061 wxOwnerDrawnComboBox
* cb
= wxStaticCast(wnd
, wxOwnerDrawnComboBox
);
2062 return cb
->GetTextCtrl();
2068 // -----------------------------------------------------------------------
2070 wxPGEditor
* wxPropertyGridInterface::GetEditorByName( const wxString
& editorName
)
2072 wxPGHashMapS2P::const_iterator it
;
2074 it
= wxPGGlobalVars
->m_mapEditorClasses
.find(editorName
);
2075 if ( it
== wxPGGlobalVars
->m_mapEditorClasses
.end() )
2077 return (wxPGEditor
*) it
->second
;
2080 // -----------------------------------------------------------------------
2081 // wxPGEditorDialogAdapter
2082 // -----------------------------------------------------------------------
2084 IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter
, wxObject
)
2086 bool wxPGEditorDialogAdapter::ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
2088 if ( !propGrid
->EditorValidate() )
2091 bool res
= DoShowDialog( propGrid
, property
);
2095 propGrid
->ValueChangeInEvent( m_value
);
2102 // -----------------------------------------------------------------------
2104 // -----------------------------------------------------------------------
2106 wxPGMultiButton::wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
)
2107 : wxWindow( pg
->GetPanel(), wxPG_SUBID2
, wxPoint(-100,-100), wxSize(0, sz
.y
) ),
2108 m_fullEditorSize(sz
), m_buttonsWidth(0)
2110 SetBackgroundColour(pg
->GetCellBackgroundColour());
2113 int wxPGMultiButton::GenId( int id
) const
2117 if ( m_buttons
.size() )
2118 id
= GetButton(m_buttons
.size()-1)->GetId() + 1;
2126 void wxPGMultiButton::Add( const wxBitmap
& bitmap
, int id
)
2129 wxSize sz
= GetSize();
2130 wxButton
* button
= new wxBitmapButton( this, id
, bitmap
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
2131 m_buttons
.push_back(button
);
2132 int bw
= button
->GetSize().x
;
2133 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
2134 m_buttonsWidth
+= bw
;
2138 void wxPGMultiButton::Add( const wxString
& label
, int id
)
2141 wxSize sz
= GetSize();
2142 wxButton
* button
= new wxButton( this, id
, label
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
2143 m_buttons
.push_back(button
);
2144 int bw
= button
->GetSize().x
;
2145 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
2146 m_buttonsWidth
+= bw
;
2149 // -----------------------------------------------------------------------