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 );
1073 return (wxWindow
*) cb
;
1077 void wxPGChoiceEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1080 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1081 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1082 int ind
= property
->GetChoiceSelection();
1083 cb
->SetSelection(ind
);
1086 wxPGWindowList
wxPGChoiceEditor::CreateControls( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
1087 const wxPoint
& pos
, const wxSize
& sz
) const
1089 return CreateControlsBase(propGrid
,property
,pos
,sz
,wxCB_READONLY
);
1093 int wxPGChoiceEditor::InsertItem( wxWindow
* ctrl
, const wxString
& label
, int index
) const
1096 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1097 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1100 index
= cb
->GetCount();
1102 return cb
->Insert(label
,index
);
1106 void wxPGChoiceEditor::DeleteItem( wxWindow
* ctrl
, int index
) const
1109 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1110 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1115 bool wxPGChoiceEditor::OnEvent( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
1116 wxWindow
* ctrl
, wxEvent
& event
) const
1118 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
1120 wxPGComboBox
* cb
= (wxPGComboBox
*)ctrl
;
1121 int index
= cb
->GetSelection();
1122 int cmnValIndex
= -1;
1123 int cmnVals
= property
->GetDisplayedCommonValueCount();
1124 int items
= cb
->GetCount();
1126 if ( index
>= (items
-cmnVals
) )
1128 // Yes, a common value is being selected
1129 cmnValIndex
= index
- (items
-cmnVals
);
1130 property
->SetCommonValue( cmnValIndex
);
1132 // Truly set value to unspecified?
1133 if ( propGrid
->GetUnspecifiedCommonValue() == cmnValIndex
)
1135 if ( !property
->IsValueUnspecified() )
1136 propGrid
->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT
);
1137 property
->SetValueToUnspecified();
1138 if ( !cb
->HasFlag(wxCB_READONLY
) )
1139 cb
->GetTextCtrl()->SetValue(wxEmptyString
);
1143 return wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, cmnValIndex
);
1149 bool wxPGChoiceEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1151 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1153 int index
= cb
->GetSelection();
1155 if ( index
!= property
->GetChoiceSelection() ||
1156 // Changing unspecified always causes event (returning
1157 // true here should be enough to trigger it).
1158 property
->IsValueUnspecified()
1161 return property
->IntToValue( variant
, index
, 0 );
1167 void wxPGChoiceEditor::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, const wxString
& txt
) const
1169 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1175 void wxPGChoiceEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1177 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1179 cb
->SetSelection(value
);
1183 void wxPGChoiceEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1185 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1186 cb
->SetSelection(-1);
1190 bool wxPGChoiceEditor::CanContainCustomImage() const
1196 wxPGChoiceEditor::~wxPGChoiceEditor() { }
1199 // -----------------------------------------------------------------------
1200 // wxPGComboBoxEditor
1201 // -----------------------------------------------------------------------
1204 WX_PG_IMPLEMENT_EDITOR_CLASS(ComboBox
,wxPGComboBoxEditor
,wxPGChoiceEditor
)
1207 void wxPGComboBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1209 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1210 cb
->SetValue(property
->GetValueString(wxPG_EDITABLE_VALUE
));
1212 // TODO: If string matches any selection, then select that.
1216 wxPGWindowList
wxPGComboBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1217 wxPGProperty
* property
,
1219 const wxSize
& sz
) const
1221 return CreateControlsBase(propGrid
,property
,pos
,sz
,0);
1225 bool wxPGComboBoxEditor::OnEvent( wxPropertyGrid
* propGrid
,
1226 wxPGProperty
* property
,
1228 wxEvent
& event
) const
1230 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*) NULL
;
1231 wxWindow
* textCtrl
= (wxWindow
*) NULL
;
1235 cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1236 textCtrl
= cb
->GetTextCtrl();
1239 if ( wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,textCtrl
,event
) )
1242 return wxPGChoiceEditor::OnEvent(propGrid
,property
,ctrl
,event
);
1246 bool wxPGComboBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1248 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1249 wxString textVal
= cb
->GetValue();
1251 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
1257 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
1259 // Changing unspecified always causes event (returning
1260 // true here should be enough to trigger it).
1261 if ( !res
&& variant
.IsNull() )
1268 void wxPGComboBoxEditor::OnFocus( wxPGProperty
*, wxWindow
* ctrl
) const
1270 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1271 cb
->GetTextCtrl()->SetSelection(-1,-1);
1275 wxPGComboBoxEditor::~wxPGComboBoxEditor() { }
1278 // -----------------------------------------------------------------------
1279 // wxPGChoiceAndButtonEditor
1280 // -----------------------------------------------------------------------
1283 // This simpler implement_editor macro doesn't define class body.
1284 WX_PG_IMPLEMENT_EDITOR_CLASS(ChoiceAndButton
,wxPGChoiceAndButtonEditor
,wxPGChoiceEditor
)
1287 wxPGWindowList
wxPGChoiceAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1288 wxPGProperty
* property
,
1290 const wxSize
& sz
) const
1292 // Use one two units smaller to match size of the combo's dropbutton.
1293 // (normally a bigger button is used because it looks better)
1296 wxSize
bt_sz(bt_wid
,bt_wid
);
1298 // Position of button.
1299 wxPoint
bt_pos(pos
.x
+sz
.x
-bt_sz
.x
,pos
.y
);
1306 wxWindow
* bt
= propGrid
->GenerateEditorButton( bt_pos
, bt_sz
);
1309 wxSize
ch_sz(sz
.x
-bt
->GetSize().x
,sz
.y
);
1312 ch_sz
.x
-= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1315 wxWindow
* ch
= wxPG_EDITOR(Choice
)->CreateControls(propGrid
,property
,
1316 pos
,ch_sz
).m_primary
;
1322 return wxPGWindowList(ch
, bt
);
1326 wxPGChoiceAndButtonEditor::~wxPGChoiceAndButtonEditor() { }
1329 // -----------------------------------------------------------------------
1330 // wxPGTextCtrlAndButtonEditor
1331 // -----------------------------------------------------------------------
1334 // This simpler implement_editor macro doesn't define class body.
1335 WX_PG_IMPLEMENT_EDITOR_CLASS(TextCtrlAndButton
,wxPGTextCtrlAndButtonEditor
,wxPGTextCtrlEditor
)
1338 wxPGWindowList
wxPGTextCtrlAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1339 wxPGProperty
* property
,
1341 const wxSize
& sz
) const
1344 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrlAndButton( pos
, sz
, &wnd2
,
1345 property
->GetFlags() & wxPG_PROP_NOEDITOR
, property
);
1347 return wxPGWindowList(wnd
, wnd2
);
1351 wxPGTextCtrlAndButtonEditor::~wxPGTextCtrlAndButtonEditor() { }
1354 // -----------------------------------------------------------------------
1355 // wxPGCheckBoxEditor
1356 // -----------------------------------------------------------------------
1358 #if wxPG_INCLUDE_CHECKBOX
1360 WX_PG_IMPLEMENT_EDITOR_CLASS(CheckBox
,wxPGCheckBoxEditor
,wxPGEditor
)
1363 // state argument: 0x01 = set if checked
1364 // 0x02 = set if rectangle should be bold
1365 static void DrawSimpleCheckBox( wxDC
& dc
, const wxRect
& rect
, int box_hei
, int state
, const wxColour
& linecol
)
1369 wxRect
r(rect
.x
+wxPG_XBEFORETEXT
,rect
.y
+((rect
.height
-box_hei
)/2),box_hei
,box_hei
);
1371 // Draw check mark first because it is likely to overdraw the
1372 // surrounding rectangle.
1375 wxRect
r2(r
.x
+wxPG_CHECKMARK_XADJ
,
1376 r
.y
+wxPG_CHECKMARK_YADJ
,
1377 r
.width
+wxPG_CHECKMARK_WADJ
,
1378 r
.height
+wxPG_CHECKMARK_HADJ
);
1379 #if wxPG_CHECKMARK_DEFLATE
1380 r2
.Deflate(wxPG_CHECKMARK_DEFLATE
);
1382 dc
.DrawCheckMark(r2
);
1384 // This would draw a simple cross check mark.
1385 // dc.DrawLine(r.x,r.y,r.x+r.width-1,r.y+r.height-1);
1386 // dc.DrawLine(r.x,r.y+r.height-1,r.x+r.width-1,r.y);
1392 // Pen for thin rectangle.
1397 // Pen for bold rectangle.
1398 wxPen
linepen(linecol
,2,wxSOLID
);
1399 linepen
.SetJoin(wxJOIN_MITER
); // This prevents round edges.
1407 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1409 dc
.DrawRectangle(r
);
1410 dc
.SetPen(*wxTRANSPARENT_PEN
);
1414 // Real simple custom-drawn checkbox-without-label class.
1416 class wxSimpleCheckBox
: public wxControl
1420 void SetValue( int value
);
1422 wxSimpleCheckBox( wxWindow
* parent
,
1424 const wxPoint
& pos
= wxDefaultPosition
,
1425 const wxSize
& size
= wxDefaultSize
)
1426 : wxControl(parent
,id
,pos
,size
,wxNO_BORDER
|wxWANTS_CHARS
)
1428 // Due to SetOwnFont stuff necessary for GTK+ 1.2, we need to have this
1429 SetFont( parent
->GetFont() );
1432 wxPropertyGrid
* pg
= (wxPropertyGrid
*) parent
->GetParent();
1433 wxASSERT( pg
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1434 m_boxHeight
= pg
->GetFontHeight();
1435 SetBackgroundStyle( wxBG_STYLE_COLOUR
);
1438 virtual ~wxSimpleCheckBox();
1440 virtual bool ProcessEvent(wxEvent
& event
);
1445 static wxBitmap
* ms_doubleBuffer
;
1449 wxSimpleCheckBox::~wxSimpleCheckBox()
1451 delete ms_doubleBuffer
;
1452 ms_doubleBuffer
= NULL
;
1456 wxBitmap
* wxSimpleCheckBox::ms_doubleBuffer
= (wxBitmap
*) NULL
;
1458 // value = 2 means toggle (sorry, too lazy to do constants)
1459 void wxSimpleCheckBox::SetValue( int value
)
1464 if ( m_state
> 1 ) m_state
= 0;
1472 wxCommandEvent
evt(wxEVT_COMMAND_CHECKBOX_CLICKED
,GetParent()->GetId());
1474 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent()->GetParent();
1475 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1476 propGrid
->OnCustomEditorEvent(evt
);
1480 bool wxSimpleCheckBox::ProcessEvent(wxEvent
& event
)
1482 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent()->GetParent();
1483 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1485 if ( event
.GetEventType() == wxEVT_NAVIGATION_KEY
)
1487 //wxLogDebug(wxT("wxEVT_NAVIGATION_KEY"));
1488 //SetFocusFromKbd();
1490 //return wxControl::ProcessEvent(event);
1493 if ( ( (event
.GetEventType() == wxEVT_LEFT_DOWN
|| event
.GetEventType() == wxEVT_LEFT_DCLICK
)
1494 && ((wxMouseEvent
&)event
).m_x
> (wxPG_XBEFORETEXT
-2)
1495 && ((wxMouseEvent
&)event
).m_x
<= (wxPG_XBEFORETEXT
-2+m_boxHeight
) )
1501 else if ( event
.GetEventType() == wxEVT_PAINT
)
1503 wxSize clientSize
= GetClientSize();
1507 // Buffered paint DC doesn't seem to do much good
1508 if ( !ms_doubleBuffer ||
1509 clientSize.x > ms_doubleBuffer->GetWidth() ||
1510 clientSize.y > ms_doubleBuffer->GetHeight() )
1512 delete ms_doubleBuffer;
1513 ms_doubleBuffer = new wxBitmap(clientSize.x+25,clientSize.y+25);
1516 wxBufferedPaintDC dc(this,*ms_doubleBuffer);
1519 wxRect
rect(0,0,clientSize
.x
,clientSize
.y
);
1524 m_boxHeight
= propGrid
->GetFontHeight();
1526 wxColour bgcol
= GetBackgroundColour();
1527 dc
.SetBrush( bgcol
);
1529 dc
.DrawRectangle( rect
);
1531 wxColour txcol
= GetForegroundColour();
1533 int state
= m_state
;
1534 if ( m_font
.GetWeight() == wxBOLD
)
1537 DrawSimpleCheckBox(dc
,rect
,m_boxHeight
,state
,txcol
);
1539 // If focused, indicate it somehow.
1541 if ( wxWindow::FindFocus() == this )
1546 wxPGDrawFocusRect(dc,rect);
1552 else if ( event
.GetEventType() == wxEVT_SIZE
||
1553 event
.GetEventType() == wxEVT_SET_FOCUS
||
1554 event
.GetEventType() == wxEVT_KILL_FOCUS
1559 else if ( event
.GetEventType() == wxEVT_KEY_DOWN
)
1561 wxKeyEvent
& keyEv
= (wxKeyEvent
&) event
;
1563 if ( keyEv
.GetKeyCode() == WXK_TAB
)
1565 propGrid
->SendNavigationKeyEvent( keyEv
.ShiftDown()?0:1 );
1569 if ( keyEv
.GetKeyCode() == WXK_SPACE
)
1575 return wxControl::ProcessEvent(event
);
1579 wxPGWindowList
wxPGCheckBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1580 wxPGProperty
* property
,
1582 const wxSize
& size
) const
1585 pt
.x
-= wxPG_XBEFOREWIDGET
;
1587 sz
.x
= propGrid
->GetFontHeight() + (wxPG_XBEFOREWIDGET
*2) + 4;
1589 wxSimpleCheckBox
* cb
= new wxSimpleCheckBox(propGrid
->GetPanel(),wxPG_SUBID1
,pt
,sz
);
1591 cb
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
1593 cb
->Connect( wxPG_SUBID1
, wxEVT_LEFT_DOWN
,
1594 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
1595 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propGrid
);
1597 cb
->Connect( wxPG_SUBID1
, wxEVT_LEFT_DCLICK
,
1598 (wxObjectEventFunction
) (wxEventFunction
) (wxCommandEventFunction
)
1599 &wxPropertyGrid::OnCustomEditorEvent
, NULL
, propGrid
);
1601 if ( property
->GetChoiceSelection() > 0 &&
1602 !property
->IsValueUnspecified() )
1605 // If mouse cursor was on the item, toggle the value now.
1606 if ( propGrid
->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK
)
1608 wxPoint pt
= cb
->ScreenToClient(::wxGetMousePosition());
1609 if ( pt
.x
<= (wxPG_XBEFORETEXT
-2+cb
->m_boxHeight
) )
1613 if ( cb
->m_state
> 1 )
1616 // Makes sure wxPG_EVT_CHANGING etc. is sent for this initial click
1617 propGrid
->ChangePropertyValue(property
, wxPGVariant_Bool(cb
->m_state
));
1621 propGrid
->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR
);
1627 class wxPGCheckBoxRenderer : public wxPGDefaultRenderer
1631 virtual void Render( wxDC& dc, const wxRect& rect,
1632 const wxPropertyGrid* WXUNUSED(propertyGrid), wxPGProperty* property,
1633 int WXUNUSED(column), int WXUNUSED(item), int WXUNUSED(flags) ) const
1636 if ( !(property->GetFlags() & wxPG_PROP_UNSPECIFIED) )
1638 state = ((wxPGProperty*)property)->GetChoiceInfo((wxPGChoiceInfo*)NULL);
1639 if ( dc.GetFont().GetWeight() == wxBOLD ) state |= 2;
1641 DrawSimpleCheckBox(dc,rect,dc.GetCharHeight(),state,dc.GetTextForeground());
1647 wxPGCheckBoxRenderer g_wxPGCheckBoxRenderer;
1649 wxPGCellRenderer* wxPGCheckBoxEditor::GetCellRenderer() const
1651 return &g_wxPGCheckBoxRenderer;
1655 void wxPGCheckBoxEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
, wxPGProperty
* property
, const wxString
& WXUNUSED(text
) ) const
1658 if ( !property
->IsValueUnspecified() )
1660 state
= property
->GetChoiceSelection();
1661 if ( dc
.GetFont().GetWeight() == wxBOLD
) state
|= 2;
1663 DrawSimpleCheckBox(dc
,rect
,dc
.GetCharHeight(),state
,dc
.GetTextForeground());
1666 void wxPGCheckBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1669 ((wxSimpleCheckBox
*)ctrl
)->m_state
= property
->GetChoiceSelection();
1674 bool wxPGCheckBoxEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propGrid
), wxPGProperty
* WXUNUSED(property
),
1675 wxWindow
* WXUNUSED(ctrl
), wxEvent
& event
) const
1677 if ( event
.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED
)
1685 bool wxPGCheckBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1687 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*)ctrl
;
1689 int index
= cb
->m_state
;
1691 if ( index
!= property
->GetChoiceSelection() ||
1692 // Changing unspecified always causes event (returning
1693 // true here should be enough to trigger it).
1694 property
->IsValueUnspecified()
1697 return property
->IntToValue(variant
, index
, 0);
1703 void wxPGCheckBoxEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1705 if ( value
!= 0 ) value
= 1;
1706 ((wxSimpleCheckBox
*)ctrl
)->m_state
= value
;
1711 void wxPGCheckBoxEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1713 ((wxSimpleCheckBox
*)ctrl
)->m_state
= 0;
1718 wxPGCheckBoxEditor::~wxPGCheckBoxEditor() { }
1721 #endif // wxPG_INCLUDE_CHECKBOX
1723 // -----------------------------------------------------------------------
1725 wxWindow
* wxPropertyGrid::GetEditorControl() const
1727 wxWindow
* ctrl
= m_wndEditor
;
1732 // If it's clipper window, return its child instead
1733 #if wxPG_ENABLE_CLIPPER_WINDOW
1734 if ( ctrl
->IsKindOf(CLASSINFO(wxPGClipperWindow
)) )
1736 return ((wxPGClipperWindow
*)ctrl
)->GetControl();
1743 // -----------------------------------------------------------------------
1745 void wxPropertyGrid::CorrectEditorWidgetSizeX()
1747 if ( m_selColumn
== -1 )
1751 int newSplitterx
= m_pState
->DoGetSplitterPosition(m_selColumn
-1);
1752 int newWidth
= newSplitterx
+ m_pState
->m_colWidths
[m_selColumn
];
1756 // if width change occurred, move secondary wnd by that amount
1757 wxRect r
= m_wndEditor2
->GetRect();
1759 r
.x
= newWidth
- secWid
;
1761 m_wndEditor2
->SetSize( r
);
1763 // if primary is textctrl, then we have to add some extra space
1767 if ( m_wndEditor
&& m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1769 secWid
+= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1774 wxRect r
= m_wndEditor
->GetRect();
1776 r
.x
= newSplitterx
+m_ctrlXAdjust
;
1778 if ( !(m_iFlags
& wxPG_FL_FIXED_WIDTH_EDITOR
) )
1779 r
.width
= newWidth
- r
.x
- secWid
;
1781 m_wndEditor
->SetSize(r
);
1785 m_wndEditor2
->Refresh();
1788 // -----------------------------------------------------------------------
1790 void wxPropertyGrid::CorrectEditorWidgetPosY()
1792 if ( m_selected
&& (m_wndEditor
|| m_wndEditor2
) )
1794 wxRect r
= GetEditorWidgetRect(m_selected
, m_selColumn
);
1798 wxPoint pos
= m_wndEditor
->GetPosition();
1800 // Calculate y offset
1801 int offset
= pos
.y
% m_lineHeight
;
1803 m_wndEditor
->Move(pos
.x
, r
.y
+ offset
);
1808 wxPoint pos
= m_wndEditor2
->GetPosition();
1810 m_wndEditor2
->Move(pos
.x
, r
.y
);
1815 // -----------------------------------------------------------------------
1817 bool wxPropertyGrid::AdjustPosForClipperWindow( wxWindow
* topCtrlWnd
, int* x
, int* y
)
1819 #if wxPG_ENABLE_CLIPPER_WINDOW
1820 // Take clipper window into account
1821 if (topCtrlWnd
->GetPosition().x
< 1 &&
1822 !topCtrlWnd
->IsKindOf(CLASSINFO(wxPGClipperWindow
)))
1824 topCtrlWnd
= topCtrlWnd
->GetParent();
1825 wxASSERT( topCtrlWnd
->IsKindOf(CLASSINFO(wxPGClipperWindow
)) );
1826 *x
-= ((wxPGClipperWindow
*)topCtrlWnd
)->GetXClip();
1827 *y
-= ((wxPGClipperWindow
*)topCtrlWnd
)->GetYClip();
1831 wxUnusedVar(topCtrlWnd
);
1838 // -----------------------------------------------------------------------
1840 // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
1841 // fits into that category as well).
1842 void wxPropertyGrid::FixPosForTextCtrl( wxWindow
* ctrl
, const wxPoint
& offset
)
1844 // Center the control vertically
1845 wxRect finalPos
= ctrl
->GetRect();
1846 int y_adj
= (m_lineHeight
- finalPos
.height
)/2 + wxPG_TEXTCTRLYADJUST
;
1848 // Prevent over-sized control
1849 int sz_dec
= (y_adj
+ finalPos
.height
) - m_lineHeight
;
1850 if ( sz_dec
< 0 ) sz_dec
= 0;
1852 finalPos
.y
+= y_adj
;
1853 finalPos
.height
-= (y_adj
+sz_dec
);
1855 const int textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
;
1857 finalPos
.x
+= textCtrlXAdjust
;
1858 finalPos
.width
-= textCtrlXAdjust
;
1860 finalPos
.x
+= offset
.x
;
1861 finalPos
.y
+= offset
.y
;
1863 ctrl
->SetSize(finalPos
);
1866 // -----------------------------------------------------------------------
1868 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint
& pos
,
1870 const wxString
& value
,
1871 wxWindow
* secondary
,
1875 wxPGProperty
* selected
= m_selected
;
1878 int tcFlags
= wxTE_PROCESS_ENTER
| extraStyle
;
1880 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1881 tcFlags
|= wxTE_READONLY
;
1883 wxPoint
p(pos
.x
,pos
.y
);
1884 wxSize
s(sz
.x
,sz
.y
);
1886 // Need to reduce width of text control on Mac
1887 #if defined(__WXMAC__)
1891 // Take button into acccount
1894 s
.x
-= (secondary
->GetSize().x
+ wxPG_TEXTCTRL_AND_BUTTON_SPACING
);
1895 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
1898 // If the height is significantly higher, then use border, and fill the rect exactly.
1899 bool hasSpecialSize
= false;
1901 if ( (sz
.y
- m_lineHeight
) > 5 )
1902 hasSpecialSize
= true;
1904 #if wxPG_NAT_TEXTCTRL_BORDER_ANY
1906 // Create clipper window
1907 wxPGClipperWindow
* wnd
= new wxPGClipperWindow();
1908 #if defined(__WXMSW__)
1911 wnd
->Create(GetPanel(),wxPG_SUBID1
,p
,s
);
1913 // This generates rect of the control inside the clipper window
1914 if ( !hasSpecialSize
)
1915 wnd
->GetControlRect(wxPG_NAT_TEXTCTRL_BORDER_X
, wxPG_NAT_TEXTCTRL_BORDER_Y
, p
, s
);
1917 wnd
->GetControlRect(0, 0, p
, s
);
1919 wxWindow
* ctrlParent
= wnd
;
1923 wxWindow
* ctrlParent
= GetPanel();
1925 if ( !hasSpecialSize
)
1926 tcFlags
|= wxNO_BORDER
;
1930 wxTextCtrl
* tc
= new wxTextCtrl();
1932 #if defined(__WXMSW__) && !wxPG_NAT_TEXTCTRL_BORDER_ANY
1935 SetupTextCtrlValue(value
);
1936 tc
->Create(ctrlParent
,wxPG_SUBID1
,value
, p
, s
,tcFlags
);
1938 #if wxPG_NAT_TEXTCTRL_BORDER_ANY
1940 wnd
->SetControl(tc
);
1945 // Center the control vertically
1946 if ( !hasSpecialSize
)
1947 FixPosForTextCtrl(ed
);
1955 // Set maximum length
1957 tc
->SetMaxLength( maxLen
);
1959 return (wxWindow
*) ed
;
1962 // -----------------------------------------------------------------------
1964 wxWindow
* wxPropertyGrid::GenerateEditorButton( const wxPoint
& pos
, const wxSize
& sz
)
1966 wxPGProperty
* selected
= m_selected
;
1970 // Decorations are chunky on Mac, and we can't make the button square, so
1971 // do things a bit differently on this platform.
1973 wxPoint
p(pos
.x
+sz
.x
,
1974 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1977 wxButton
* but
= new wxButton();
1978 but
->Create(GetPanel(),wxPG_SUBID2
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1980 // Now that we know the size, move to the correct position
1981 p
.x
= pos
.x
+ sz
.x
- but
->GetSize().x
- 2;
1985 wxSize
s(sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2),
1986 sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2));
1988 // Reduce button width to lineheight
1989 if ( s
.x
> m_lineHeight
)
1993 // On wxGTK, take fixed button margins into account
1998 wxPoint
p(pos
.x
+sz
.x
-s
.x
,
1999 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
2001 wxButton
* but
= new wxButton();
2005 but
->Create(GetPanel(),wxPG_SUBID2
,wxS("..."),p
,s
,wxWANTS_CHARS
);
2008 wxFont font
= GetFont();
2009 font
.SetPointSize(font
.GetPointSize()-2);
2012 but
->SetFont(GetFont());
2016 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
2022 // -----------------------------------------------------------------------
2024 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrlAndButton( const wxPoint
& pos
,
2026 wxWindow
** psecondary
,
2028 wxPGProperty
* property
)
2030 wxButton
* but
= (wxButton
*)GenerateEditorButton(pos
,sz
);
2031 *psecondary
= (wxWindow
*)but
;
2033 if ( limitedEditing
)
2036 // There is button Show in GenerateEditorTextCtrl as well
2039 return (wxWindow
*) NULL
;
2044 if ( !property
->IsValueUnspecified() )
2045 text
= property
->GetValueString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
2047 return GenerateEditorTextCtrl(pos
,sz
,text
,but
,property
->m_maxLen
);
2050 // -----------------------------------------------------------------------
2052 wxTextCtrl
* wxPropertyGrid::GetEditorTextCtrl() const
2054 wxWindow
* wnd
= GetEditorControl();
2059 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2060 return wxStaticCast(wnd
, wxTextCtrl
);
2062 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
2064 wxOwnerDrawnComboBox
* cb
= wxStaticCast(wnd
, wxOwnerDrawnComboBox
);
2065 return cb
->GetTextCtrl();
2071 // -----------------------------------------------------------------------
2073 wxPGEditor
* wxPropertyGridInterface::GetEditorByName( const wxString
& editorName
)
2075 wxPGHashMapS2P::const_iterator it
;
2077 it
= wxPGGlobalVars
->m_mapEditorClasses
.find(editorName
);
2078 if ( it
== wxPGGlobalVars
->m_mapEditorClasses
.end() )
2080 return (wxPGEditor
*) it
->second
;
2083 // -----------------------------------------------------------------------
2084 // wxPGEditorDialogAdapter
2085 // -----------------------------------------------------------------------
2087 IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter
, wxObject
)
2089 bool wxPGEditorDialogAdapter::ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
2091 if ( !propGrid
->EditorValidate() )
2094 bool res
= DoShowDialog( propGrid
, property
);
2098 propGrid
->ValueChangeInEvent( m_value
);
2105 // -----------------------------------------------------------------------
2107 // -----------------------------------------------------------------------
2109 wxPGMultiButton::wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
)
2110 : wxWindow( pg
->GetPanel(), wxPG_SUBID2
, wxPoint(-100,-100), wxSize(0, sz
.y
) ),
2111 m_fullEditorSize(sz
), m_buttonsWidth(0)
2113 SetBackgroundColour(pg
->GetCellBackgroundColour());
2116 int wxPGMultiButton::GenId( int id
) const
2120 if ( m_buttons
.size() )
2121 id
= GetButton(m_buttons
.size()-1)->GetId() + 1;
2129 void wxPGMultiButton::Add( const wxBitmap
& bitmap
, int id
)
2132 wxSize sz
= GetSize();
2133 wxButton
* button
= new wxBitmapButton( this, id
, bitmap
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
2134 m_buttons
.push_back(button
);
2135 int bw
= button
->GetSize().x
;
2136 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
2137 m_buttonsWidth
+= bw
;
2141 void wxPGMultiButton::Add( const wxString
& label
, int id
)
2144 wxSize sz
= GetSize();
2145 wxButton
* button
= new wxButton( this, id
, label
, wxPoint(sz
.x
, 0), wxSize(sz
.y
, sz
.y
) );
2146 m_buttons
.push_back(button
);
2147 int bw
= button
->GetSize().x
;
2148 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
2149 m_buttonsWidth
+= bw
;
2152 // -----------------------------------------------------------------------
2154 #endif // wxUSE_PROPGRID