1 /////////////////////////////////////////////////////////////////////////////
2 // Name: src/propgrid/editors.cpp
3 // Purpose: wxPropertyGrid editors
4 // Author: Jaakko Salli
8 // Copyright: (c) Jaakko Salli
9 // Licence: wxWindows license
10 /////////////////////////////////////////////////////////////////////////////
12 // For compilers that support precompilation, includes "wx/wx.h".
13 #include "wx/wxprec.h"
23 #include "wx/object.h"
25 #include "wx/string.h"
28 #include "wx/window.h"
31 #include "wx/dcclient.h"
32 #include "wx/dcmemory.h"
33 #include "wx/button.h"
36 #include "wx/cursor.h"
37 #include "wx/dialog.h"
38 #include "wx/settings.h"
39 #include "wx/msgdlg.h"
40 #include "wx/choice.h"
41 #include "wx/stattext.h"
42 #include "wx/scrolwin.h"
43 #include "wx/dirdlg.h"
45 #include "wx/textdlg.h"
46 #include "wx/filedlg.h"
47 #include "wx/statusbr.h"
54 #include "wx/dcbuffer.h"
55 #include "wx/bmpbuttn.h"
58 // This define is necessary to prevent macro clearing
59 #define __wxPG_SOURCE_FILE__
61 #include <wx/propgrid/propgrid.h>
62 #include <wx/propgrid/editors.h>
63 #include <wx/propgrid/props.h>
65 #if wxPG_USE_RENDERER_NATIVE
66 #include <wx/renderer.h>
69 // How many pixels between textctrl and button
71 #define wxPG_TEXTCTRL_AND_BUTTON_SPACING 8
73 #define wxPG_TEXTCTRL_AND_BUTTON_SPACING 2
76 #define wxPG_BUTTON_SIZEDEC 0
78 #include <wx/odcombo.h>
81 #include <wx/msw/private.h>
84 // -----------------------------------------------------------------------
86 #if defined(__WXMSW__)
88 #define wxPG_NAT_TEXTCTRL_BORDER_X 0 // Unremovable border of native textctrl.
89 #define wxPG_NAT_TEXTCTRL_BORDER_Y 0 // Unremovable border of native textctrl.
91 #define wxPG_NAT_BUTTON_BORDER_ANY 1
92 #define wxPG_NAT_BUTTON_BORDER_X 1
93 #define wxPG_NAT_BUTTON_BORDER_Y 1
95 #define wxPG_CHECKMARK_XADJ 1
96 #define wxPG_CHECKMARK_YADJ (-1)
97 #define wxPG_CHECKMARK_WADJ 0
98 #define wxPG_CHECKMARK_HADJ 0
99 #define wxPG_CHECKMARK_DEFLATE 0
101 #define wxPG_TEXTCTRLYADJUST (m_spacingy+0)
103 #elif defined(__WXGTK__)
105 #define wxPG_CHECKMARK_XADJ 0
106 #define wxPG_CHECKMARK_YADJ 0
107 #define wxPG_CHECKMARK_WADJ (-1)
108 #define wxPG_CHECKMARK_HADJ (-1)
109 #define wxPG_CHECKMARK_DEFLATE 3
111 #define wxPG_NAT_TEXTCTRL_BORDER_X 3 // Unremovable border of native textctrl.
112 #define wxPG_NAT_TEXTCTRL_BORDER_Y 3 // Unremovable border of native textctrl.
114 #define wxPG_NAT_BUTTON_BORDER_ANY 1
115 #define wxPG_NAT_BUTTON_BORDER_X 1
116 #define wxPG_NAT_BUTTON_BORDER_Y 1
118 #define wxPG_TEXTCTRLYADJUST 0
120 #elif defined(__WXMAC__)
122 #define wxPG_CHECKMARK_XADJ 0
123 #define wxPG_CHECKMARK_YADJ 0
124 #define wxPG_CHECKMARK_WADJ 0
125 #define wxPG_CHECKMARK_HADJ 0
126 #define wxPG_CHECKMARK_DEFLATE 0
128 #define wxPG_NAT_TEXTCTRL_BORDER_X 0 // Unremovable border of native textctrl.
129 #define wxPG_NAT_TEXTCTRL_BORDER_Y 0 // Unremovable border of native textctrl.
131 #define wxPG_NAT_BUTTON_BORDER_ANY 0
132 #define wxPG_NAT_BUTTON_BORDER_X 0
133 #define wxPG_NAT_BUTTON_BORDER_Y 0
135 #define wxPG_TEXTCTRLYADJUST 3
139 #define wxPG_CHECKMARK_XADJ 0
140 #define wxPG_CHECKMARK_YADJ 0
141 #define wxPG_CHECKMARK_WADJ 0
142 #define wxPG_CHECKMARK_HADJ 0
143 #define wxPG_CHECKMARK_DEFLATE 0
145 #define wxPG_NAT_TEXTCTRL_BORDER_X 0 // Unremovable border of native textctrl.
146 #define wxPG_NAT_TEXTCTRL_BORDER_Y 0 // Unremovable border of native textctrl.
148 #define wxPG_NAT_BUTTON_BORDER_ANY 0
149 #define wxPG_NAT_BUTTON_BORDER_X 0
150 #define wxPG_NAT_BUTTON_BORDER_Y 0
152 #define wxPG_TEXTCTRLYADJUST 0
156 #if (!wxPG_NAT_TEXTCTRL_BORDER_X && !wxPG_NAT_TEXTCTRL_BORDER_Y)
157 #define wxPG_ENABLE_CLIPPER_WINDOW 0
159 #define wxPG_ENABLE_CLIPPER_WINDOW 1
164 #define wxPG_CHOICEXADJUST 0
165 #define wxPG_CHOICEYADJUST 0
167 #define ODCB_CUST_PAINT_MARGIN 6 // Number added to image width for SetCustomPaintWidth
169 // Milliseconds to wait for two mouse-ups after focus inorder
170 // to trigger a double-click.
171 #define DOUBLE_CLICK_CONVERSION_TRESHOLD 500
173 // -----------------------------------------------------------------------
175 // -----------------------------------------------------------------------
177 IMPLEMENT_ABSTRACT_CLASS(wxPGEditor
, wxObject
)
180 wxPGEditor::~wxPGEditor()
184 void wxPGEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
, wxPGProperty
* property
, const wxString
& text
) const
186 if ( !property
->IsValueUnspecified() )
187 dc
.DrawText( text
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
190 bool wxPGEditor::GetValueFromControl( wxVariant
&, wxPGProperty
*, wxWindow
* ) const
195 void wxPGEditor::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, const wxString
& ) const
200 void wxPGEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, int ) const
205 int wxPGEditor::InsertItem( wxWindow
*, const wxString
&, int ) const
211 void wxPGEditor::DeleteItem( wxWindow
*, int ) const
217 void wxPGEditor::OnFocus( wxPGProperty
*, wxWindow
* ) const
222 bool wxPGEditor::CanContainCustomImage() const
227 // -----------------------------------------------------------------------
229 // -----------------------------------------------------------------------
232 #if wxPG_ENABLE_CLIPPER_WINDOW
235 // Clipper window is used to "remove" borders from controls
236 // which otherwise insist on having them despite of supplied
237 // wxNO_BORDER window style.
239 class wxPGClipperWindow
: public wxWindow
241 DECLARE_CLASS(wxPGClipperWindow
)
247 wxPGClipperWindow::Init();
250 wxPGClipperWindow(wxWindow
* parent
,
252 const wxPoint
& pos
= wxDefaultPosition
,
253 const wxSize
& size
= wxDefaultSize
)
256 Create(parent
,id
,pos
,size
);
259 void Create(wxWindow
* parent
,
261 const wxPoint
& pos
= wxDefaultPosition
,
262 const wxSize
& size
= wxDefaultSize
);
264 virtual ~wxPGClipperWindow();
266 virtual bool ProcessEvent(wxEvent
& event
);
268 inline wxWindow
* GetControl() const { return m_ctrl
; }
270 // This is called before wxControl is constructed.
271 void GetControlRect( int xadj
, int yadj
, wxPoint
& pt
, wxSize
& sz
);
273 // This is caleed after wxControl has been constructed.
274 void SetControl( wxWindow
* ctrl
);
276 virtual void Refresh( bool eraseBackground
= true,
277 const wxRect
*rect
= (const wxRect
*) NULL
);
278 virtual void SetFocus();
280 virtual bool SetFont(const wxFont
& font
);
282 inline int GetXClip() const { return m_xadj
; }
284 inline int GetYClip() const { return m_yadj
; }
289 int m_xadj
; // Horizontal border clip.
291 int m_yadj
; // Vertical border clip.
296 m_ctrl
= (wxWindow
*) NULL
;
301 IMPLEMENT_CLASS(wxPGClipperWindow
,wxWindow
)
304 // This is called before wxControl is constructed.
305 void wxPGClipperWindow::GetControlRect( int xadj
, int yadj
, wxPoint
& pt
, wxSize
& sz
)
311 wxSize own_size
= GetSize();
312 sz
.x
= own_size
.x
+(xadj
*2);
313 sz
.y
= own_size
.y
+(yadj
*2);
317 // This is caleed after wxControl has been constructed.
318 void wxPGClipperWindow::SetControl( wxWindow
* ctrl
)
322 // GTK requires this.
323 ctrl
->SetSizeHints(3,3);
325 // Correct size of this window to match the child.
326 wxSize sz
= GetSize();
327 wxSize chsz
= ctrl
->GetSize();
329 int hei_adj
= chsz
.y
- (sz
.y
+(m_yadj
*2));
331 SetSize(sz
.x
,chsz
.y
-(m_yadj
*2));
336 void wxPGClipperWindow::Refresh( bool eraseBackground
, const wxRect
*rect
)
338 wxWindow::Refresh(false,rect
);
340 m_ctrl
->Refresh(eraseBackground
);
344 // Pass focus to control
345 void wxPGClipperWindow::SetFocus()
350 wxWindow::SetFocus();
354 bool wxPGClipperWindow::SetFont(const wxFont
& font
)
356 bool res
= wxWindow::SetFont(font
);
358 return m_ctrl
->SetFont(font
);
363 void wxPGClipperWindow::Create(wxWindow
* parent
,
368 wxWindow::Create(parent
,id
,pos
,size
);
372 wxPGClipperWindow::~wxPGClipperWindow()
377 bool wxPGClipperWindow::ProcessEvent(wxEvent
& event
)
379 if ( event
.GetEventType() == wxEVT_SIZE
)
383 // Maintain correct size relationship.
384 wxSize sz
= GetSize();
385 m_ctrl
->SetSize(sz
.x
+(m_xadj
*2),sz
.y
+(m_yadj
*2));
390 return wxWindow::ProcessEvent(event
);
393 #endif // wxPG_ENABLE_CLIPPER_WINDOW
395 /*wxWindow* wxPropertyGrid::GetActualEditorControl( wxWindow* ctrl )
397 #if wxPG_ENABLE_CLIPPER_WINDOW
398 // Pass real control instead of clipper window
399 if ( ctrl->IsKindOf(CLASSINFO(wxPGClipperWindow)) )
401 return ((wxPGClipperWindow*)ctrl)->GetControl();
408 // -----------------------------------------------------------------------
409 // wxPGTextCtrlEditor
410 // -----------------------------------------------------------------------
412 // Clipper window support macro (depending on whether it is used
413 // for this editor or not)
414 #if wxPG_NAT_TEXTCTRL_BORDER_X || wxPG_NAT_TEXTCTRL_BORDER_Y
415 #define wxPG_NAT_TEXTCTRL_BORDER_ANY 1
417 #define wxPG_NAT_TEXTCTRL_BORDER_ANY 0
420 WX_PG_IMPLEMENT_EDITOR_CLASS(TextCtrl
,wxPGTextCtrlEditor
,wxPGEditor
)
423 wxPGWindowList
wxPGTextCtrlEditor::CreateControls( wxPropertyGrid
* propGrid
,
424 wxPGProperty
* property
,
426 const wxSize
& sz
) const
431 // If has children, and limited editing is specified, then don't create.
432 if ( (property
->GetFlags() & wxPG_PROP_NOEDITOR
) &&
433 property
->GetChildCount() )
434 return (wxWindow
*) NULL
;
436 if ( !property
->IsValueUnspecified() )
437 text
= property
->GetValueString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
440 if ( (property
->GetFlags() & wxPG_PROP_PASSWORD
) &&
441 property
->IsKindOf(CLASSINFO(wxStringProperty
)) )
442 flags
|= wxTE_PASSWORD
;
444 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrl(pos
,sz
,text
,(wxWindow
*)NULL
,flags
,
445 property
->GetMaxLength());
451 void wxPGTextCtrlEditor::DrawValue( wxDC
& dc
, wxPGProperty
* property
, const wxRect
& rect
) const
453 if ( !property
->IsValueUnspecified() )
455 wxString drawStr
= property
->GetDisplayedString();
457 // Code below should no longer be needed, as the obfuscation
458 // is now done in GetValueAsString.
459 /*if ( (property->GetFlags() & wxPG_PROP_PASSWORD) &&
460 property->IsKindOf(WX_PG_CLASSINFO(wxStringProperty)) )
462 size_t a = drawStr.length();
464 drawStr.Append(wxS('*'),a);
466 dc
.DrawText( drawStr
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
471 void wxPGTextCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
473 wxTextCtrl
* tc
= wxDynamicCast(ctrl
, wxTextCtrl
);
478 if ( tc
->HasFlag(wxTE_PASSWORD
) )
479 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
481 s
= property
->GetDisplayedString();
487 // Provided so that, for example, ComboBox editor can use the same code
488 // (multiple inheritance would get way too messy).
489 bool wxPGTextCtrlEditor::OnTextCtrlEvent( wxPropertyGrid
* propGrid
,
490 wxPGProperty
* WXUNUSED(property
),
497 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
499 if ( propGrid
->IsEditorsValueModified() )
504 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
507 // Pass this event outside wxPropertyGrid so that,
508 // if necessary, program can tell when user is editing
510 // FIXME: Is it safe to change event id in the middle of event
511 // processing (seems to work, but...)?
513 event
.SetId(propGrid
->GetId());
515 propGrid
->EditorsValueWasModified();
521 bool wxPGTextCtrlEditor::OnEvent( wxPropertyGrid
* propGrid
,
522 wxPGProperty
* property
,
524 wxEvent
& event
) const
526 return wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,ctrl
,event
);
530 bool wxPGTextCtrlEditor::GetTextCtrlValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
)
532 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
533 wxString textVal
= tc
->GetValue();
535 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
541 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
543 // Changing unspecified always causes event (returning
544 // true here should be enough to trigger it).
545 // TODO: Move to propgrid.cpp
546 if ( !res
&& variant
.IsNull() )
553 bool wxPGTextCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
555 return wxPGTextCtrlEditor::GetTextCtrlValueFromControl(variant
, property
, ctrl
);
559 void wxPGTextCtrlEditor::SetValueToUnspecified( wxPGProperty
* property
, wxWindow
* ctrl
) const
561 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
563 wxPropertyGrid
* pg
= property
->GetGrid();
564 wxASSERT(pg
); // Really, property grid should exist if editor does
566 tc
->SetValue(wxEmptyString
);
570 void wxPGTextCtrlEditor::SetControlStringValue( wxPGProperty
* property
, wxWindow
* ctrl
, const wxString
& txt
) const
572 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
574 wxPropertyGrid
* pg
= property
->GetGrid();
575 wxASSERT(pg
); // Really, property grid should exist if editor does
581 void wxPGTextCtrlEditor::OnFocus( wxPGProperty
*, wxWindow
* wnd
) const
583 wxTextCtrl
* tc
= wxStaticCast(wnd
, wxTextCtrl
);
585 tc
->SetSelection(-1,-1);
589 wxPGTextCtrlEditor::~wxPGTextCtrlEditor() { }
592 // -----------------------------------------------------------------------
594 // -----------------------------------------------------------------------
597 WX_PG_IMPLEMENT_EDITOR_CLASS(Choice
,wxPGChoiceEditor
,wxPGEditor
)
600 // This is a special enhanced double-click processor class.
601 // In essence, it allows for double-clicks for which the
602 // first click "created" the control.
603 class wxPGDoubleClickProcessor
: public wxEvtHandler
607 wxPGDoubleClickProcessor( wxOwnerDrawnComboBox
* combo
, wxPGProperty
* property
)
610 m_timeLastMouseUp
= 0;
612 m_property
= property
;
613 m_downReceived
= false;
618 void OnMouseEvent( wxMouseEvent
& event
)
620 wxLongLong t
= ::wxGetLocalTimeMillis();
621 int evtType
= event
.GetEventType();
623 if ( m_property
->HasFlag(wxPG_PROP_USE_DCC
) &&
624 m_property
->IsKindOf(CLASSINFO(wxBoolProperty
)) &&
625 !m_combo
->IsPopupShown() )
627 // Just check that it is in the text area
628 wxPoint pt
= event
.GetPosition();
629 if ( m_combo
->GetTextRect().Contains(pt
) )
631 if ( evtType
== wxEVT_LEFT_DOWN
)
633 // Set value to avoid up-events without corresponding downs
634 m_downReceived
= true;
636 else if ( evtType
== wxEVT_LEFT_DCLICK
)
638 // We'll make our own double-clicks
639 event
.SetEventType(0);
642 else if ( evtType
== wxEVT_LEFT_UP
)
644 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
646 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
648 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
650 event
.SetEventType(wxEVT_LEFT_DCLICK
);
651 m_timeLastMouseUp
= 1;
655 m_timeLastMouseUp
= t
;
665 void OnSetFocus( wxFocusEvent
& event
)
667 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
672 wxLongLong m_timeLastMouseUp
;
673 wxOwnerDrawnComboBox
* m_combo
;
674 wxPGProperty
* m_property
; // Selected property
677 DECLARE_EVENT_TABLE()
680 BEGIN_EVENT_TABLE(wxPGDoubleClickProcessor
, wxEvtHandler
)
681 EVT_MOUSE_EVENTS(wxPGDoubleClickProcessor::OnMouseEvent
)
682 EVT_SET_FOCUS(wxPGDoubleClickProcessor::OnSetFocus
)
687 class wxPGComboBox
: public wxOwnerDrawnComboBox
692 : wxOwnerDrawnComboBox()
694 m_dclickProcessor
= (wxPGDoubleClickProcessor
*) NULL
;
695 m_sizeEventCalled
= false;
700 if ( m_dclickProcessor
)
702 RemoveEventHandler(m_dclickProcessor
);
703 delete m_dclickProcessor
;
707 bool Create(wxWindow
*parent
,
709 const wxString
& value
,
712 const wxArrayString
& choices
,
714 const wxValidator
& validator
= wxDefaultValidator
,
715 const wxString
& name
= wxS("wxOwnerDrawnComboBox"))
717 if ( !wxOwnerDrawnComboBox::Create( parent
,
728 m_dclickProcessor
= new wxPGDoubleClickProcessor(this, GetGrid()->GetSelection() );
730 PushEventHandler(m_dclickProcessor
);
735 virtual void OnDrawItem( wxDC
& dc
, const wxRect
& rect
, int item
, int flags
) const
737 wxPropertyGrid
* pg
= GetGrid();
738 pg
->OnComboItemPaint((wxPGCustomComboControl
*)this,item
,dc
,(wxRect
&)rect
,flags
);
740 virtual wxCoord
OnMeasureItem( size_t item
) const
742 wxPropertyGrid
* pg
= GetGrid();
746 pg
->OnComboItemPaint((wxPGCustomComboControl
*)this,item
,*((wxDC
*)NULL
),rect
,0);
750 wxPropertyGrid
* GetGrid() const
752 wxPropertyGrid
* pg
= wxDynamicCast(GetParent()->GetParent(),wxPropertyGrid
);
757 virtual wxCoord
OnMeasureItemWidth( size_t item
) const
759 wxPropertyGrid
* pg
= GetGrid();
763 pg
->OnComboItemPaint((wxPGCustomComboControl
*)this,item
,*((wxDC
*)NULL
),rect
,0);
767 virtual void PositionTextCtrl( int WXUNUSED(textCtrlXAdjust
), int WXUNUSED(textCtrlYAdjust
) )
769 wxPropertyGrid
* pg
= GetGrid();
770 wxOwnerDrawnComboBox::PositionTextCtrl(
771 wxPG_TEXTCTRLXADJUST
- (wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1) - 1,
772 pg
->GetSpacingY() + 2
777 wxPGDoubleClickProcessor
* m_dclickProcessor
;
778 bool m_sizeEventCalled
;
782 void wxPropertyGrid::OnComboItemPaint( wxPGCustomComboControl
* pCc
,
788 wxPGComboBox
* pCb
= (wxPGComboBox
*)pCc
;
791 wxASSERT( IsKindOf(CLASSINFO(wxPropertyGrid
)) );
793 wxPGProperty
* p
= m_selected
;
796 const wxPGChoices
& choices
= p
->GetChoices();
797 const wxPGCommonValue
* comVal
= NULL
;
798 int comVals
= p
->GetDisplayedCommonValueCount();
799 int comValIndex
= -1;
802 if ( choices
.IsOk() )
803 choiceCount
= choices
.GetCount();
805 if ( item
>= choiceCount
&& comVals
> 0 )
807 comValIndex
= item
- choiceCount
;
808 comVal
= GetCommonValue(comValIndex
);
809 if ( !p
->IsValueUnspecified() )
810 text
= comVal
->GetLabel();
814 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
816 text
= pCb
->GetString(item
);
820 if ( !p
->IsValueUnspecified() )
821 text
= p
->GetValueString(0);
830 const wxBitmap
* itemBitmap
= NULL
;
832 if ( item
>= 0 && choices
.IsOk() && choices
.Item(item
).GetBitmap().Ok() && comValIndex
== -1 )
833 itemBitmap
= &choices
.Item(item
).GetBitmap();
836 // Decide what custom image size to use
839 cis
.x
= itemBitmap
->GetWidth();
840 cis
.y
= itemBitmap
->GetHeight();
844 cis
= GetImageSize(p
, item
);
849 // Default measure behaviour (no flexible, custom paint image only)
850 if ( rect
.width
< 0 )
853 GetTextExtent(text
, &x
, &y
, 0, 0, &m_font
);
854 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9 + x
;
857 rect
.height
= cis
.y
+ 2;
861 wxPGPaintData paintdata
;
862 paintdata
.m_parent
= NULL
;
863 paintdata
.m_choiceItem
= item
;
865 // This is by the current (1.0.0b) spec - if painting control, item is -1
866 if ( (flags
& wxODCB_PAINTING_CONTROL
) )
867 paintdata
.m_choiceItem
= -1;
870 dc
.SetBrush(*wxWHITE_BRUSH
);
877 wxPoint
pt(rect
.x
+ wxPG_CONTROL_MARGIN
- wxPG_CHOICEXADJUST
- 1,
882 if ( flags
& wxODCB_PAINTING_CONTROL
)
883 renderFlags
|= wxPGCellRenderer::Control
;
885 if ( flags
& wxODCB_PAINTING_SELECTED
)
886 renderFlags
|= wxPGCellRenderer::Selected
;
888 if ( cis
.x
> 0 && (p
->HasFlag(wxPG_PROP_CUSTOMIMAGE
) || !(flags
& wxODCB_PAINTING_CONTROL
)) &&
889 ( !p
->m_valueBitmap
|| item
== pCb
->GetSelection() ) &&
890 ( item
>= 0 || (flags
& wxODCB_PAINTING_CONTROL
) ) &&
894 pt
.x
+= wxCC_CUSTOM_IMAGE_MARGIN1
;
895 wxRect
r(pt
.x
,pt
.y
,cis
.x
,cis
.y
);
897 if ( flags
& wxODCB_PAINTING_CONTROL
)
900 r
.height
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
903 paintdata
.m_drawnWidth
= r
.width
;
905 dc
.SetPen(m_colPropFore
);
906 if ( comValIndex
>= 0 )
908 const wxPGCommonValue
* cv
= GetCommonValue(comValIndex
);
909 wxPGCellRenderer
* renderer
= cv
->GetRenderer();
910 r
.width
= rect
.width
;
911 renderer
->Render( dc
, r
, this, p
, m_selColumn
, comValIndex
, renderFlags
);
914 else if ( item
>= 0 )
916 p
->OnCustomPaint( dc
, r
, paintdata
);
920 dc
.DrawRectangle( r
);
923 pt
.x
+= paintdata
.m_drawnWidth
+ wxCC_CUSTOM_IMAGE_MARGIN2
- 1;
927 // TODO: This aligns text so that it seems to be horizontally
928 // on the same line as property values. Not really
929 // sure if its needed, but seems to not cause any harm.
932 if ( item
< 0 && (flags
& wxODCB_PAINTING_CONTROL
) )
933 item
= pCb
->GetSelection();
935 if ( choices
.IsOk() && item
>= 0 && comValIndex
< 0 )
937 const wxPGChoiceEntry
& cell
= choices
.Item(item
);
938 wxPGCellRenderer
* renderer
= wxPGGlobalVars
->m_defaultRenderer
;
939 int imageOffset
= renderer
->PreDrawCell( dc
, rect
, cell
, renderFlags
);
941 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
;
950 pt
.y
+= (rect
.height
-m_fontHeight
)/2 - 1;
954 dc
.DrawText( text
, pt
.x
+ wxPG_XBEFORETEXT
, pt
.y
);
961 p
->OnCustomPaint( dc
, rect
, paintdata
);
962 rect
.height
= paintdata
.m_drawnHeight
+ 2;
963 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9;
967 bool wxPGChoiceEditor_SetCustomPaintWidth( wxPropertyGrid
* propGrid
, wxPGComboBox
* cb
, int cmnVal
)
969 wxPGProperty
* property
= propGrid
->GetSelectedProperty();
970 wxASSERT( property
);
974 // Yes, a common value is being selected
975 property
->SetCommonValue( cmnVal
);
976 wxSize imageSize
= propGrid
->GetCommonValue(cmnVal
)->
977 GetRenderer()->GetImageSize(property
, 1, cmnVal
);
978 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
979 cb
->SetCustomPaintWidth( imageSize
.x
);
984 wxSize imageSize
= propGrid
->GetImageSize(property
, -1);
985 if ( imageSize
.x
) imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
986 cb
->SetCustomPaintWidth( imageSize
.x
);
991 // CreateControls calls this with CB_READONLY in extraStyle
992 wxWindow
* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid
* propGrid
,
993 wxPGProperty
* property
,
996 long extraStyle
) const
998 const wxPGChoices
& choices
= property
->GetChoices();
1000 int index
= property
->GetChoiceSelection();
1002 bool isUnspecified
= property
->IsValueUnspecified();
1004 if ( !isUnspecified
)
1005 defString
= property
->GetDisplayedString();
1007 wxArrayString labels
= choices
.GetLabels();
1013 po
.y
+= wxPG_CHOICEYADJUST
;
1014 si
.y
-= (wxPG_CHOICEYADJUST
*2);
1016 po
.x
+= wxPG_CHOICEXADJUST
;
1017 si
.x
-= wxPG_CHOICEXADJUST
;
1018 wxWindow
* ctrlParent
= propGrid
->GetPanel();
1020 int odcbFlags
= extraStyle
| wxNO_BORDER
| wxTE_PROCESS_ENTER
;
1023 // If common value specified, use appropriate index
1024 unsigned int cmnVals
= property
->GetDisplayedCommonValueCount();
1027 if ( !isUnspecified
)
1029 int cmnVal
= property
->GetCommonValue();
1032 index
= labels
.size() + cmnVal
;
1037 for ( i
=0; i
<cmnVals
; i
++ )
1038 labels
.Add(propGrid
->GetCommonValueLabel(i
));
1041 cb
= new wxPGComboBox();
1045 cb
->Create(ctrlParent
,
1053 cb
->SetButtonPosition(si
.y
,0,wxRIGHT
);
1054 cb
->SetTextIndent(wxPG_XBEFORETEXT
-1);
1056 wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, property
->GetCommonValue() );
1058 if ( index
>= 0 && index
< (int)cb
->GetCount() )
1060 cb
->SetSelection( index
);
1061 if ( defString
.length() )
1062 cb
->SetText( defString
);
1064 else if ( !(extraStyle
& wxCB_READONLY
) && defString
.length() )
1065 cb
->SetValue( defString
);
1067 cb
->SetSelection( -1 );
1069 // Connect event handling
1070 wxWindowID id
= cb
->GetId();
1071 propGrid
->Connect(id
, wxEVT_COMMAND_COMBOBOX_SELECTED
,
1072 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1073 propGrid
->Connect(id
, wxEVT_COMMAND_TEXT_UPDATED
,
1074 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1075 propGrid
->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
1076 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
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
->GetChoiceSelection();
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
->GetChoiceSelection() ||
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
->GetChoiceSelection() > 0 &&
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
->GetChoiceSelection();
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
->GetChoiceSelection();
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
->GetChoiceSelection() ||
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 wxWindowID id
= wxPG_SUBID1
;
1885 wxPGProperty
* selected
= m_selected
;
1888 int tcFlags
= wxTE_PROCESS_ENTER
| extraStyle
;
1890 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1891 tcFlags
|= wxTE_READONLY
;
1893 wxPoint
p(pos
.x
,pos
.y
);
1894 wxSize
s(sz
.x
,sz
.y
);
1896 // Need to reduce width of text control on Mac
1897 #if defined(__WXMAC__)
1901 // Take button into acccount
1904 s
.x
-= (secondary
->GetSize().x
+ wxPG_TEXTCTRL_AND_BUTTON_SPACING
);
1905 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
1908 // If the height is significantly higher, then use border, and fill the rect exactly.
1909 bool hasSpecialSize
= false;
1911 if ( (sz
.y
- m_lineHeight
) > 5 )
1912 hasSpecialSize
= true;
1914 #if wxPG_NAT_TEXTCTRL_BORDER_ANY
1916 // Create clipper window
1917 wxPGClipperWindow
* wnd
= new wxPGClipperWindow();
1918 #if defined(__WXMSW__)
1921 wnd
->Create(GetPanel(),id
,p
,s
);
1923 // This generates rect of the control inside the clipper window
1924 if ( !hasSpecialSize
)
1925 wnd
->GetControlRect(wxPG_NAT_TEXTCTRL_BORDER_X
, wxPG_NAT_TEXTCTRL_BORDER_Y
, p
, s
);
1927 wnd
->GetControlRect(0, 0, p
, s
);
1929 wxWindow
* ctrlParent
= wnd
;
1933 wxWindow
* ctrlParent
= GetPanel();
1935 if ( !hasSpecialSize
)
1936 tcFlags
|= wxNO_BORDER
;
1940 wxTextCtrl
* tc
= new wxTextCtrl();
1942 #if defined(__WXMSW__) && !wxPG_NAT_TEXTCTRL_BORDER_ANY
1945 SetupTextCtrlValue(value
);
1946 tc
->Create(ctrlParent
,id
,value
, p
, s
,tcFlags
);
1948 #if wxPG_NAT_TEXTCTRL_BORDER_ANY
1950 wnd
->SetControl(tc
);
1955 // Center the control vertically
1956 if ( !hasSpecialSize
)
1957 FixPosForTextCtrl(ed
);
1965 // Set maximum length
1967 tc
->SetMaxLength( maxLen
);
1969 // Connect event handling
1971 this->Connect(id
, wxEVT_COMMAND_TEXT_UPDATED
,
1972 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1973 this->Connect(id
, wxEVT_COMMAND_TEXT_ENTER
,
1974 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
1976 return (wxWindow
*) ed
;
1979 // -----------------------------------------------------------------------
1981 wxWindow
* wxPropertyGrid::GenerateEditorButton( const wxPoint
& pos
, const wxSize
& sz
)
1983 wxWindowID id
= wxPG_SUBID2
;
1984 wxPGProperty
* selected
= m_selected
;
1988 // Decorations are chunky on Mac, and we can't make the button square, so
1989 // do things a bit differently on this platform.
1991 wxPoint
p(pos
.x
+sz
.x
,
1992 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1995 wxButton
* but
= new wxButton();
1996 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1998 // Now that we know the size, move to the correct position
1999 p
.x
= pos
.x
+ sz
.x
- but
->GetSize().x
- 2;
2003 wxSize
s(sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2),
2004 sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2));
2006 // Reduce button width to lineheight
2007 if ( s
.x
> m_lineHeight
)
2011 // On wxGTK, take fixed button margins into account
2016 wxPoint
p(pos
.x
+sz
.x
-s
.x
,
2017 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
2019 wxButton
* but
= new wxButton();
2023 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
2026 wxFont font
= GetFont();
2027 font
.SetPointSize(font
.GetPointSize()-2);
2030 but
->SetFont(GetFont());
2034 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
2037 // Connect event handling
2039 this->Connect(id
, wxEVT_COMMAND_BUTTON_CLICKED
,
2040 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
2045 // -----------------------------------------------------------------------
2047 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrlAndButton( const wxPoint
& pos
,
2049 wxWindow
** psecondary
,
2051 wxPGProperty
* property
)
2053 wxButton
* but
= (wxButton
*)GenerateEditorButton(pos
,sz
);
2054 *psecondary
= (wxWindow
*)but
;
2056 if ( limitedEditing
)
2059 // There is button Show in GenerateEditorTextCtrl as well
2062 return (wxWindow
*) NULL
;
2067 if ( !property
->IsValueUnspecified() )
2068 text
= property
->GetValueString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
2070 return GenerateEditorTextCtrl(pos
,sz
,text
,but
,property
->m_maxLen
);
2073 // -----------------------------------------------------------------------
2075 wxTextCtrl
* wxPropertyGrid::GetEditorTextCtrl() const
2077 wxWindow
* wnd
= GetEditorControl();
2082 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2083 return wxStaticCast(wnd
, wxTextCtrl
);
2085 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
2087 wxOwnerDrawnComboBox
* cb
= wxStaticCast(wnd
, wxOwnerDrawnComboBox
);
2088 return cb
->GetTextCtrl();
2094 // -----------------------------------------------------------------------
2096 wxPGEditor
* wxPropertyGridInterface::GetEditorByName( const wxString
& editorName
)
2098 wxPGHashMapS2P::const_iterator it
;
2100 it
= wxPGGlobalVars
->m_mapEditorClasses
.find(editorName
);
2101 if ( it
== wxPGGlobalVars
->m_mapEditorClasses
.end() )
2103 return (wxPGEditor
*) it
->second
;
2106 // -----------------------------------------------------------------------
2107 // wxPGEditorDialogAdapter
2108 // -----------------------------------------------------------------------
2110 IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter
, wxObject
)
2112 bool wxPGEditorDialogAdapter::ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
2114 if ( !propGrid
->EditorValidate() )
2117 bool res
= DoShowDialog( propGrid
, property
);
2121 propGrid
->ValueChangeInEvent( m_value
);
2128 // -----------------------------------------------------------------------
2130 // -----------------------------------------------------------------------
2132 wxPGMultiButton::wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
)
2133 : wxWindow( pg
->GetPanel(), wxPG_SUBID2
, wxPoint(-100,-100), wxSize(0, sz
.y
) ),
2134 m_fullEditorSize(sz
), m_buttonsWidth(0)
2136 SetBackgroundColour(pg
->GetCellBackgroundColour());
2139 void wxPGMultiButton::Finalize( wxPropertyGrid
* propGrid
, const wxPoint
& pos
)
2141 Move( pos
.x
+ m_fullEditorSize
.x
- m_buttonsWidth
, pos
.y
);
2143 // Connect event handling
2144 for ( int i
=0; i
<GetCount(); i
++ )
2146 wxWindowID id
= GetButtonId(i
);
2147 propGrid
->Connect(id
, wxEVT_COMMAND_BUTTON_CLICKED
,
2148 wxCommandEventHandler(wxPropertyGrid::OnCustomEditorEvent
));
2152 int wxPGMultiButton::GenId( int id
) const
2156 if ( m_buttons
.size() )
2157 id
= GetButton(m_buttons
.size()-1)->GetId() + 1;
2165 void wxPGMultiButton::Add( const wxBitmap
& bitmap
, int id
)
2168 wxSize sz
= GetSize();
2169 wxButton
* button
= new wxBitmapButton( this, id
, bitmap
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
2170 m_buttons
.push_back(button
);
2171 int bw
= button
->GetSize().x
;
2172 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
2173 m_buttonsWidth
+= bw
;
2177 void wxPGMultiButton::Add( const wxString
& label
, int id
)
2180 wxSize sz
= GetSize();
2181 wxButton
* button
= new wxButton( this, id
, label
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
2182 m_buttons
.push_back(button
);
2183 int bw
= button
->GetSize().x
;
2184 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
2185 m_buttonsWidth
+= bw
;
2188 // -----------------------------------------------------------------------
2190 #endif // wxUSE_PROPGRID