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 4
73 #define wxPG_TEXTCTRL_AND_BUTTON_SPACING 2
76 #define wxPG_BUTTON_SIZEDEC 0
78 #include "wx/odcombo.h"
80 // -----------------------------------------------------------------------
82 #if defined(__WXMSW__)
84 #define wxPG_NAT_BUTTON_BORDER_ANY 1
85 #define wxPG_NAT_BUTTON_BORDER_X 1
86 #define wxPG_NAT_BUTTON_BORDER_Y 1
88 #define wxPG_CHECKMARK_XADJ 1
89 #define wxPG_CHECKMARK_YADJ (-1)
90 #define wxPG_CHECKMARK_WADJ 0
91 #define wxPG_CHECKMARK_HADJ 0
92 #define wxPG_CHECKMARK_DEFLATE 0
94 #define wxPG_TEXTCTRLYADJUST (m_spacingy+0)
96 #elif defined(__WXGTK__)
98 #define wxPG_CHECKMARK_XADJ 0
99 #define wxPG_CHECKMARK_YADJ 0
100 #define wxPG_CHECKMARK_WADJ (-1)
101 #define wxPG_CHECKMARK_HADJ (-1)
102 #define wxPG_CHECKMARK_DEFLATE 3
104 #define wxPG_NAT_BUTTON_BORDER_ANY 1
105 #define wxPG_NAT_BUTTON_BORDER_X 1
106 #define wxPG_NAT_BUTTON_BORDER_Y 1
108 #define wxPG_TEXTCTRLYADJUST 0
110 #elif defined(__WXMAC__)
112 #define wxPG_CHECKMARK_XADJ 0
113 #define wxPG_CHECKMARK_YADJ 0
114 #define wxPG_CHECKMARK_WADJ 0
115 #define wxPG_CHECKMARK_HADJ 0
116 #define wxPG_CHECKMARK_DEFLATE 0
118 #define wxPG_NAT_BUTTON_BORDER_ANY 0
119 #define wxPG_NAT_BUTTON_BORDER_X 0
120 #define wxPG_NAT_BUTTON_BORDER_Y 0
122 #define wxPG_TEXTCTRLYADJUST 0
126 #define wxPG_CHECKMARK_XADJ 0
127 #define wxPG_CHECKMARK_YADJ 0
128 #define wxPG_CHECKMARK_WADJ 0
129 #define wxPG_CHECKMARK_HADJ 0
130 #define wxPG_CHECKMARK_DEFLATE 0
132 #define wxPG_NAT_BUTTON_BORDER_ANY 0
133 #define wxPG_NAT_BUTTON_BORDER_X 0
134 #define wxPG_NAT_BUTTON_BORDER_Y 0
136 #define wxPG_TEXTCTRLYADJUST 0
142 #define wxPG_CHOICEXADJUST -3 // required because wxComboCtrl reserves 3pixels for wxTextCtrl's focus ring
143 #define wxPG_CHOICEYADJUST -3
145 #define wxPG_CHOICEXADJUST 0
146 #define wxPG_CHOICEYADJUST 0
149 // Number added to image width for SetCustomPaintWidth
150 #define ODCB_CUST_PAINT_MARGIN 6
152 // Milliseconds to wait for two mouse-ups after focus inorder
153 // to trigger a double-click.
154 #define DOUBLE_CLICK_CONVERSION_TRESHOLD 500
156 // -----------------------------------------------------------------------
158 // -----------------------------------------------------------------------
160 IMPLEMENT_ABSTRACT_CLASS(wxPGEditor
, wxObject
)
163 wxPGEditor::~wxPGEditor()
167 wxString
wxPGEditor::GetName() const
169 return GetClassInfo()->GetClassName();
172 void wxPGEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
,
173 wxPGProperty
* WXUNUSED(property
),
174 const wxString
& text
) const
176 dc
.DrawText( text
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
179 bool wxPGEditor::GetValueFromControl( wxVariant
&, wxPGProperty
*, wxWindow
* ) const
184 void wxPGEditor::SetControlStringValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, const wxString
& ) const
189 void wxPGEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
*, int ) const
194 int wxPGEditor::InsertItem( wxWindow
*, const wxString
&, int ) const
200 void wxPGEditor::DeleteItem( wxWindow
*, int ) const
206 void wxPGEditor::OnFocus( wxPGProperty
*, wxWindow
* ) const
210 void wxPGEditor::SetControlAppearance( wxPropertyGrid
* pg
,
211 wxPGProperty
* property
,
213 const wxPGCell
& cell
,
214 const wxPGCell
& oCell
,
215 bool unspecified
) const
217 // Get old editor appearance
218 wxTextCtrl
* tc
= NULL
;
219 wxComboCtrl
* cb
= NULL
;
220 if ( ctrl
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
222 tc
= (wxTextCtrl
*) ctrl
;
226 if ( ctrl
->IsKindOf(CLASSINFO(wxComboCtrl
)) )
228 cb
= (wxComboCtrl
*) ctrl
;
229 tc
= cb
->GetTextCtrl();
236 bool changeText
= false;
238 if ( cell
.HasText() && !pg
->IsEditorFocused() )
240 tcText
= cell
.GetText();
243 else if ( oCell
.HasText() )
245 tcText
= property
->GetValueAsString(
246 property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
252 // This prevents value from being modified
255 pg
->SetupTextCtrlValue(tcText
);
256 tc
->SetValue(tcText
);
265 // Do not make the mistake of calling GetClassDefaultAttributes()
266 // here. It is static, while GetDefaultAttributes() is virtual
267 // and the correct one to use.
268 wxVisualAttributes vattrs
= ctrl
->GetDefaultAttributes();
271 const wxColour
& fgCol
= cell
.GetFgCol();
274 ctrl
->SetForegroundColour(fgCol
);
276 else if ( oCell
.GetFgCol().IsOk() )
278 ctrl
->SetForegroundColour(vattrs
.colFg
);
282 const wxColour
& bgCol
= cell
.GetBgCol();
285 ctrl
->SetBackgroundColour(bgCol
);
287 else if ( oCell
.GetBgCol().IsOk() )
289 ctrl
->SetBackgroundColour(vattrs
.colBg
);
293 const wxFont
& font
= cell
.GetFont();
298 else if ( oCell
.GetFont().IsOk() )
300 ctrl
->SetFont(vattrs
.font
);
303 // Also call the old SetValueToUnspecified()
305 SetValueToUnspecified(property
, ctrl
);
308 void wxPGEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
),
309 wxWindow
* WXUNUSED(ctrl
) ) const
313 bool wxPGEditor::CanContainCustomImage() const
318 // -----------------------------------------------------------------------
319 // wxPGTextCtrlEditor
320 // -----------------------------------------------------------------------
322 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrl
,wxPGTextCtrlEditor
,wxPGEditor
)
325 wxPGWindowList
wxPGTextCtrlEditor::CreateControls( wxPropertyGrid
* propGrid
,
326 wxPGProperty
* property
,
328 const wxSize
& sz
) const
333 // If has children, and limited editing is specified, then don't create.
334 if ( (property
->GetFlags() & wxPG_PROP_NOEDITOR
) &&
335 property
->GetChildCount() )
339 if ( !property
->HasFlag(wxPG_PROP_READONLY
) &&
340 !property
->IsValueUnspecified() )
341 argFlags
|= wxPG_EDITABLE_VALUE
;
342 text
= property
->GetValueAsString(argFlags
);
345 if ( (property
->GetFlags() & wxPG_PROP_PASSWORD
) &&
346 property
->IsKindOf(CLASSINFO(wxStringProperty
)) )
347 flags
|= wxTE_PASSWORD
;
349 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrl(pos
,sz
,text
,NULL
,flags
,
350 property
->GetMaxLength());
356 void wxPGTextCtrlEditor::DrawValue( wxDC
& dc
, wxPGProperty
* property
, const wxRect
& rect
) const
358 if ( !property
->IsValueUnspecified() )
360 wxString drawStr
= property
->GetDisplayedString();
362 // Code below should no longer be needed, as the obfuscation
363 // is now done in GetValueAsString.
364 /*if ( (property->GetFlags() & wxPG_PROP_PASSWORD) &&
365 property->IsKindOf(WX_PG_CLASSINFO(wxStringProperty)) )
367 size_t a = drawStr.length();
369 drawStr.Append(wxS('*'),a);
371 dc
.DrawText( drawStr
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
376 void wxPGTextCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
378 wxTextCtrl
* tc
= wxDynamicCast(ctrl
, wxTextCtrl
);
383 if ( tc
->HasFlag(wxTE_PASSWORD
) )
384 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
386 s
= property
->GetDisplayedString();
388 wxPropertyGrid
* pg
= property
->GetGrid();
390 pg
->SetupTextCtrlValue(s
);
394 // Fix indentation, just in case (change in font boldness is one good
399 // Provided so that, for example, ComboBox editor can use the same code
400 // (multiple inheritance would get way too messy).
401 bool wxPGTextCtrlEditor::OnTextCtrlEvent( wxPropertyGrid
* propGrid
,
402 wxPGProperty
* WXUNUSED(property
),
409 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
411 if ( propGrid
->IsEditorsValueModified() )
416 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
419 // Pass this event outside wxPropertyGrid so that,
420 // if necessary, program can tell when user is editing
422 // FIXME: Is it safe to change event id in the middle of event
423 // processing (seems to work, but...)?
425 event
.SetId(propGrid
->GetId());
427 propGrid
->EditorsValueWasModified();
433 bool wxPGTextCtrlEditor::OnEvent( wxPropertyGrid
* propGrid
,
434 wxPGProperty
* property
,
436 wxEvent
& event
) const
438 return wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,ctrl
,event
);
442 bool wxPGTextCtrlEditor::GetTextCtrlValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
)
444 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
445 wxString textVal
= tc
->GetValue();
447 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
453 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
455 // Changing unspecified always causes event (returning
456 // true here should be enough to trigger it).
457 // TODO: Move to propgrid.cpp
458 if ( !res
&& variant
.IsNull() )
465 bool wxPGTextCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
467 return wxPGTextCtrlEditor::GetTextCtrlValueFromControl(variant
, property
, ctrl
);
471 void wxPGTextCtrlEditor::SetControlStringValue( wxPGProperty
* property
, wxWindow
* ctrl
, const wxString
& txt
) const
473 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
475 wxPropertyGrid
* pg
= property
->GetGrid();
476 wxASSERT(pg
); // Really, property grid should exist if editor does
479 pg
->SetupTextCtrlValue(txt
);
485 void wxPGTextCtrlEditor_OnFocus( wxPGProperty
* property
,
488 // Make sure there is correct text (instead of unspecified value
489 // indicator or hint text)
490 int flags
= property
->HasFlag(wxPG_PROP_READONLY
) ?
491 0 : wxPG_EDITABLE_VALUE
;
492 wxString correctText
= property
->GetValueAsString(flags
);
494 if ( tc
->GetValue() != correctText
)
496 property
->GetGrid()->SetupTextCtrlValue(correctText
);
497 tc
->SetValue(correctText
);
500 tc
->SetSelection(-1,-1);
503 void wxPGTextCtrlEditor::OnFocus( wxPGProperty
* property
,
504 wxWindow
* wnd
) const
506 wxTextCtrl
* tc
= wxStaticCast(wnd
, wxTextCtrl
);
507 wxPGTextCtrlEditor_OnFocus(property
, tc
);
510 wxPGTextCtrlEditor::~wxPGTextCtrlEditor() { }
513 // -----------------------------------------------------------------------
515 // -----------------------------------------------------------------------
518 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(Choice
,wxPGChoiceEditor
,wxPGEditor
)
521 // This is a special enhanced double-click processor class.
522 // In essence, it allows for double-clicks for which the
523 // first click "created" the control.
524 class wxPGDoubleClickProcessor
: public wxEvtHandler
528 wxPGDoubleClickProcessor( wxOwnerDrawnComboBox
* combo
, wxPGProperty
* property
)
531 m_timeLastMouseUp
= 0;
533 m_property
= property
;
534 m_downReceived
= false;
539 void OnMouseEvent( wxMouseEvent
& event
)
541 wxLongLong t
= ::wxGetLocalTimeMillis();
542 int evtType
= event
.GetEventType();
544 if ( m_property
->HasFlag(wxPG_PROP_USE_DCC
) &&
545 m_property
->IsKindOf(CLASSINFO(wxBoolProperty
)) &&
546 !m_combo
->IsPopupShown() )
548 // Just check that it is in the text area
549 wxPoint pt
= event
.GetPosition();
550 if ( m_combo
->GetTextRect().Contains(pt
) )
552 if ( evtType
== wxEVT_LEFT_DOWN
)
554 // Set value to avoid up-events without corresponding downs
555 m_downReceived
= true;
557 else if ( evtType
== wxEVT_LEFT_DCLICK
)
559 // We'll make our own double-clicks
560 event
.SetEventType(0);
563 else if ( evtType
== wxEVT_LEFT_UP
)
565 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
567 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
569 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
571 event
.SetEventType(wxEVT_LEFT_DCLICK
);
572 m_timeLastMouseUp
= 1;
576 m_timeLastMouseUp
= t
;
586 void OnSetFocus( wxFocusEvent
& event
)
588 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
593 wxLongLong m_timeLastMouseUp
;
594 wxOwnerDrawnComboBox
* m_combo
;
595 wxPGProperty
* m_property
; // Selected property
598 DECLARE_EVENT_TABLE()
601 BEGIN_EVENT_TABLE(wxPGDoubleClickProcessor
, wxEvtHandler
)
602 EVT_MOUSE_EVENTS(wxPGDoubleClickProcessor::OnMouseEvent
)
603 EVT_SET_FOCUS(wxPGDoubleClickProcessor::OnSetFocus
)
608 class wxPGComboBox
: public wxOwnerDrawnComboBox
613 : wxOwnerDrawnComboBox()
615 m_dclickProcessor
= NULL
;
616 m_sizeEventCalled
= false;
621 if ( m_dclickProcessor
)
623 RemoveEventHandler(m_dclickProcessor
);
624 delete m_dclickProcessor
;
628 bool Create(wxWindow
*parent
,
630 const wxString
& value
,
633 const wxArrayString
& choices
,
635 const wxValidator
& validator
= wxDefaultValidator
,
636 const wxString
& name
= wxS("wxOwnerDrawnComboBox"))
638 if ( !wxOwnerDrawnComboBox::Create( parent
,
649 m_dclickProcessor
= new
650 wxPGDoubleClickProcessor( this, GetGrid()->GetSelection() );
652 PushEventHandler(m_dclickProcessor
);
657 virtual void OnDrawItem( wxDC
& dc
,
662 wxPropertyGrid
* pg
= GetGrid();
664 // Handle hint text via super class
665 if ( (flags
& wxODCB_PAINTING_CONTROL
) &&
666 ShouldUseHintText(flags
) )
668 wxOwnerDrawnComboBox::OnDrawItem(dc
, rect
, item
, flags
);
672 pg
->OnComboItemPaint( this, item
, &dc
, (wxRect
&)rect
, flags
);
676 virtual wxCoord
OnMeasureItem( size_t item
) const
678 wxPropertyGrid
* pg
= GetGrid();
682 pg
->OnComboItemPaint( this, item
, NULL
, rect
, 0 );
686 wxPropertyGrid
* GetGrid() const
688 wxPropertyGrid
* pg
= wxDynamicCast(GetParent(),
694 virtual wxCoord
OnMeasureItemWidth( size_t item
) const
696 wxPropertyGrid
* pg
= GetGrid();
700 pg
->OnComboItemPaint( this, item
, NULL
, rect
, 0 );
704 virtual void PositionTextCtrl( int textCtrlXAdjust
,
705 int WXUNUSED(textCtrlYAdjust
) )
707 wxPropertyGrid
* pg
= GetGrid();
708 #ifdef wxPG_TEXTCTRLXADJUST
709 textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
-
710 (wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1) - 1,
712 wxOwnerDrawnComboBox::PositionTextCtrl(
714 pg
->GetSpacingY() + 2
719 wxPGDoubleClickProcessor
* m_dclickProcessor
;
720 bool m_sizeEventCalled
;
724 void wxPropertyGrid::OnComboItemPaint( const wxPGComboBox
* pCb
,
731 wxASSERT( IsKindOf(CLASSINFO(wxPropertyGrid
)) );
733 wxPGProperty
* p
= GetSelection();
736 const wxPGChoices
& choices
= p
->GetChoices();
737 const wxPGCommonValue
* comVal
= NULL
;
738 int comVals
= p
->GetDisplayedCommonValueCount();
739 int comValIndex
= -1;
742 if ( choices
.IsOk() )
743 choiceCount
= choices
.GetCount();
745 if ( item
>= choiceCount
&& comVals
> 0 )
747 comValIndex
= item
- choiceCount
;
748 comVal
= GetCommonValue(comValIndex
);
749 if ( !p
->IsValueUnspecified() )
750 text
= comVal
->GetLabel();
754 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
756 text
= pCb
->GetString(item
);
760 if ( !p
->IsValueUnspecified() )
761 text
= p
->GetValueAsString(0);
770 const wxBitmap
* itemBitmap
= NULL
;
772 if ( item
>= 0 && choices
.IsOk() && choices
.Item(item
).GetBitmap().Ok() && comValIndex
== -1 )
773 itemBitmap
= &choices
.Item(item
).GetBitmap();
776 // Decide what custom image size to use
779 cis
.x
= itemBitmap
->GetWidth();
780 cis
.y
= itemBitmap
->GetHeight();
784 cis
= GetImageSize(p
, item
);
789 // Default measure behaviour (no flexible, custom paint image only)
790 if ( rect
.width
< 0 )
793 pCb
->GetTextExtent(text
, &x
, &y
, 0, 0);
794 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9 + x
;
797 rect
.height
= cis
.y
+ 2;
801 wxPGPaintData paintdata
;
802 paintdata
.m_parent
= NULL
;
803 paintdata
.m_choiceItem
= item
;
805 // This is by the current (1.0.0b) spec - if painting control, item is -1
806 if ( (flags
& wxODCB_PAINTING_CONTROL
) )
807 paintdata
.m_choiceItem
= -1;
810 pDc
->SetBrush(*wxWHITE_BRUSH
);
812 wxPGCellRenderer
* renderer
= NULL
;
813 const wxPGChoiceEntry
* cell
= NULL
;
821 wxPoint
pt(rect
.x
+ wxPG_CONTROL_MARGIN
- wxPG_CHOICEXADJUST
- 1,
824 int renderFlags
= wxPGCellRenderer::DontUseCellColours
;
825 bool useCustomPaintProcedure
;
827 // If custom image had some size, we will start from the assumption
828 // that custom paint procedure is required
830 useCustomPaintProcedure
= true;
832 useCustomPaintProcedure
= false;
834 if ( flags
& wxODCB_PAINTING_SELECTED
)
835 renderFlags
|= wxPGCellRenderer::Selected
;
837 if ( flags
& wxODCB_PAINTING_CONTROL
)
839 renderFlags
|= wxPGCellRenderer::Control
;
841 // If wxPG_PROP_CUSTOMIMAGE was set, then that means any custom
842 // image will not appear on the control row (it may be too
843 // large to fit, for instance). Also do not draw custom image
844 // if no choice was selected.
845 if ( !p
->HasFlag(wxPG_PROP_CUSTOMIMAGE
) || item
< 0 )
846 useCustomPaintProcedure
= false;
850 renderFlags
|= wxPGCellRenderer::ChoicePopup
;
853 // If not drawing a selected popup item, then give property's
854 // m_valueBitmap a chance.
855 if ( p
->m_valueBitmap
&& item
!= pCb
->GetSelection() )
856 useCustomPaintProcedure
= false;
857 // If current choice had a bitmap set by the application, then
858 // use it instead of any custom paint procedure.
859 else if ( itemBitmap
)
860 useCustomPaintProcedure
= false;
862 if ( useCustomPaintProcedure
)
864 pt
.x
+= wxCC_CUSTOM_IMAGE_MARGIN1
;
865 wxRect
r(pt
.x
,pt
.y
,cis
.x
,cis
.y
);
867 if ( flags
& wxODCB_PAINTING_CONTROL
)
870 r
.height
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
873 paintdata
.m_drawnWidth
= r
.width
;
875 dc
.SetPen(m_colPropFore
);
876 if ( comValIndex
>= 0 )
878 const wxPGCommonValue
* cv
= GetCommonValue(comValIndex
);
879 wxPGCellRenderer
* renderer
= cv
->GetRenderer();
880 r
.width
= rect
.width
;
881 renderer
->Render( dc
, r
, this, p
, m_selColumn
, comValIndex
, renderFlags
);
884 else if ( item
>= 0 )
886 p
->OnCustomPaint( dc
, r
, paintdata
);
890 dc
.DrawRectangle( r
);
893 pt
.x
+= paintdata
.m_drawnWidth
+ wxCC_CUSTOM_IMAGE_MARGIN2
- 1;
897 // TODO: This aligns text so that it seems to be horizontally
898 // on the same line as property values. Not really
899 // sure if its needed, but seems to not cause any harm.
902 if ( item
< 0 && (flags
& wxODCB_PAINTING_CONTROL
) )
903 item
= pCb
->GetSelection();
905 if ( choices
.IsOk() && item
>= 0 && comValIndex
< 0 )
907 cell
= &choices
.Item(item
);
908 renderer
= wxPGGlobalVars
->m_defaultRenderer
;
909 int imageOffset
= renderer
->PreDrawCell(dc
, rect
, *cell
,
912 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+
913 wxCC_CUSTOM_IMAGE_MARGIN2
;
922 pt
.y
+= (rect
.height
-m_fontHeight
)/2 - 1;
926 dc
.DrawText( text
, pt
.x
+ wxPG_XBEFORETEXT
, pt
.y
);
929 renderer
->PostDrawCell(dc
, this, *cell
, renderFlags
);
937 p
->OnCustomPaint( dc
, rect
, paintdata
);
938 rect
.height
= paintdata
.m_drawnHeight
+ 2;
939 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9;
943 bool wxPGChoiceEditor_SetCustomPaintWidth( wxPropertyGrid
* propGrid
, wxPGComboBox
* cb
, int cmnVal
)
945 wxPGProperty
* property
= propGrid
->GetSelectedProperty();
946 wxASSERT( property
);
951 // TODO: Do this always when cell has custom text.
952 if ( property
->IsValueUnspecified() )
954 cb
->SetCustomPaintWidth( 0 );
960 // Yes, a common value is being selected
961 property
->SetCommonValue( cmnVal
);
962 imageSize
= propGrid
->GetCommonValue(cmnVal
)->
963 GetRenderer()->GetImageSize(property
, 1, cmnVal
);
968 imageSize
= propGrid
->GetImageSize(property
, -1);
973 imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
974 cb
->SetCustomPaintWidth( imageSize
.x
);
979 // CreateControls calls this with CB_READONLY in extraStyle
980 wxWindow
* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid
* propGrid
,
981 wxPGProperty
* property
,
984 long extraStyle
) const
986 // Since it is not possible (yet) to create a read-only combo box in
987 // the same sense that wxTextCtrl is read-only, simply do not create
988 // the control in this case.
989 if ( property
->HasFlag(wxPG_PROP_READONLY
) )
992 const wxPGChoices
& choices
= property
->GetChoices();
994 int index
= property
->GetChoiceSelection();
997 if ( !property
->HasFlag(wxPG_PROP_READONLY
) &&
998 !property
->IsValueUnspecified() )
999 argFlags
|= wxPG_EDITABLE_VALUE
;
1000 defString
= property
->GetValueAsString(argFlags
);
1002 wxArrayString labels
= choices
.GetLabels();
1008 po
.y
+= wxPG_CHOICEYADJUST
;
1009 si
.y
-= (wxPG_CHOICEYADJUST
*2);
1011 po
.x
+= wxPG_CHOICEXADJUST
;
1012 si
.x
-= wxPG_CHOICEXADJUST
;
1013 wxWindow
* ctrlParent
= propGrid
->GetPanel();
1015 int odcbFlags
= extraStyle
| wxBORDER_NONE
| wxTE_PROCESS_ENTER
;
1017 if ( (property
->GetFlags() & wxPG_PROP_USE_DCC
) &&
1018 (property
->IsKindOf(CLASSINFO(wxBoolProperty
)) ) )
1019 odcbFlags
|= wxODCB_DCLICK_CYCLES
;
1022 // If common value specified, use appropriate index
1023 unsigned int cmnVals
= property
->GetDisplayedCommonValueCount();
1026 if ( !property
->IsValueUnspecified() )
1028 int cmnVal
= property
->GetCommonValue();
1031 index
= labels
.size() + cmnVal
;
1036 for ( i
=0; i
<cmnVals
; i
++ )
1037 labels
.Add(propGrid
->GetCommonValueLabel(i
));
1040 cb
= new wxPGComboBox();
1044 cb
->Create(ctrlParent
,
1052 cb
->SetButtonPosition(si
.y
,0,wxRIGHT
);
1053 cb
->SetMargins(wxPG_XBEFORETEXT
-1);
1056 cb
->SetHint(property
->GetHintText());
1058 wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
,
1059 property
->GetCommonValue() );
1061 if ( index
>= 0 && index
< (int)cb
->GetCount() )
1063 cb
->SetSelection( index
);
1064 if ( defString
.length() )
1065 cb
->SetText( defString
);
1067 else if ( !(extraStyle
& wxCB_READONLY
) && defString
.length() )
1069 propGrid
->SetupTextCtrlValue(defString
);
1070 cb
->SetValue( defString
);
1074 cb
->SetSelection( -1 );
1081 return (wxWindow
*) cb
;
1085 void wxPGChoiceEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1088 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1089 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1090 int ind
= property
->GetChoiceSelection();
1091 cb
->SetSelection(ind
);
1094 wxPGWindowList
wxPGChoiceEditor::CreateControls( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
1095 const wxPoint
& pos
, const wxSize
& sz
) const
1097 return CreateControlsBase(propGrid
,property
,pos
,sz
,wxCB_READONLY
);
1101 int wxPGChoiceEditor::InsertItem( wxWindow
* ctrl
, const wxString
& label
, int index
) const
1104 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1105 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1108 index
= cb
->GetCount();
1110 return cb
->Insert(label
,index
);
1114 void wxPGChoiceEditor::DeleteItem( wxWindow
* ctrl
, int index
) const
1117 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1118 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1123 bool wxPGChoiceEditor::OnEvent( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
1124 wxWindow
* ctrl
, wxEvent
& event
) const
1126 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
1128 wxPGComboBox
* cb
= (wxPGComboBox
*)ctrl
;
1129 int index
= cb
->GetSelection();
1130 int cmnValIndex
= -1;
1131 int cmnVals
= property
->GetDisplayedCommonValueCount();
1132 int items
= cb
->GetCount();
1134 if ( index
>= (items
-cmnVals
) )
1136 // Yes, a common value is being selected
1137 cmnValIndex
= index
- (items
-cmnVals
);
1138 property
->SetCommonValue( cmnValIndex
);
1140 // Truly set value to unspecified?
1141 if ( propGrid
->GetUnspecifiedCommonValue() == cmnValIndex
)
1143 if ( !property
->IsValueUnspecified() )
1144 propGrid
->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT
);
1145 property
->SetValueToUnspecified();
1146 if ( !cb
->HasFlag(wxCB_READONLY
) )
1148 wxString unspecValueText
;
1149 unspecValueText
= propGrid
->GetUnspecifiedValueText();
1150 propGrid
->SetupTextCtrlValue(unspecValueText
);
1151 cb
->GetTextCtrl()->SetValue(unspecValueText
);
1156 return wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, cmnValIndex
);
1162 bool wxPGChoiceEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1164 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1166 int index
= cb
->GetSelection();
1168 if ( index
!= property
->GetChoiceSelection() ||
1169 // Changing unspecified always causes event (returning
1170 // true here should be enough to trigger it).
1171 property
->IsValueUnspecified()
1174 return property
->IntToValue( variant
, index
, 0 );
1180 void wxPGChoiceEditor::SetControlStringValue( wxPGProperty
* property
,
1182 const wxString
& txt
) const
1184 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1186 property
->GetGrid()->SetupTextCtrlValue(txt
);
1191 void wxPGChoiceEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1193 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1195 cb
->SetSelection(value
);
1199 void wxPGChoiceEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
),
1200 wxWindow
* ctrl
) const
1202 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1204 if ( cb
->HasFlag(wxCB_READONLY
) )
1205 cb
->SetSelection(-1);
1209 bool wxPGChoiceEditor::CanContainCustomImage() const
1215 wxPGChoiceEditor::~wxPGChoiceEditor() { }
1218 // -----------------------------------------------------------------------
1219 // wxPGComboBoxEditor
1220 // -----------------------------------------------------------------------
1223 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ComboBox
,
1228 void wxPGComboBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1230 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1231 wxString s
= property
->GetValueAsString(wxPG_EDITABLE_VALUE
);
1232 property
->GetGrid()->SetupTextCtrlValue(s
);
1235 // TODO: If string matches any selection, then select that.
1239 wxPGWindowList
wxPGComboBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1240 wxPGProperty
* property
,
1242 const wxSize
& sz
) const
1244 return CreateControlsBase(propGrid
,property
,pos
,sz
,0);
1248 bool wxPGComboBoxEditor::OnEvent( wxPropertyGrid
* propGrid
,
1249 wxPGProperty
* property
,
1251 wxEvent
& event
) const
1253 wxOwnerDrawnComboBox
* cb
= NULL
;
1254 wxWindow
* textCtrl
= NULL
;
1258 cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1259 textCtrl
= cb
->GetTextCtrl();
1262 if ( wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,textCtrl
,event
) )
1265 return wxPGChoiceEditor::OnEvent(propGrid
,property
,ctrl
,event
);
1269 bool wxPGComboBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1271 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1272 wxString textVal
= cb
->GetValue();
1274 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
1280 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
1282 // Changing unspecified always causes event (returning
1283 // true here should be enough to trigger it).
1284 if ( !res
&& variant
.IsNull() )
1291 void wxPGComboBoxEditor::OnFocus( wxPGProperty
* property
,
1292 wxWindow
* ctrl
) const
1294 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1295 wxPGTextCtrlEditor_OnFocus(property
, cb
->GetTextCtrl());
1299 wxPGComboBoxEditor::~wxPGComboBoxEditor() { }
1302 // -----------------------------------------------------------------------
1303 // wxPGChoiceAndButtonEditor
1304 // -----------------------------------------------------------------------
1307 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ChoiceAndButton
,
1308 wxPGChoiceAndButtonEditor
,
1312 wxPGWindowList
wxPGChoiceAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1313 wxPGProperty
* property
,
1315 const wxSize
& sz
) const
1317 // Use one two units smaller to match size of the combo's dropbutton.
1318 // (normally a bigger button is used because it looks better)
1321 wxSize
bt_sz(bt_wid
,bt_wid
);
1323 // Position of button.
1324 wxPoint
bt_pos(pos
.x
+sz
.x
-bt_sz
.x
,pos
.y
);
1331 wxWindow
* bt
= propGrid
->GenerateEditorButton( bt_pos
, bt_sz
);
1334 wxSize
ch_sz(sz
.x
-bt
->GetSize().x
,sz
.y
);
1337 ch_sz
.x
-= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1340 wxWindow
* ch
= wxPGEditor_Choice
->CreateControls(propGrid
,property
,
1341 pos
,ch_sz
).m_primary
;
1347 return wxPGWindowList(ch
, bt
);
1351 wxPGChoiceAndButtonEditor::~wxPGChoiceAndButtonEditor() { }
1354 // -----------------------------------------------------------------------
1355 // wxPGTextCtrlAndButtonEditor
1356 // -----------------------------------------------------------------------
1358 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrlAndButton
,
1359 wxPGTextCtrlAndButtonEditor
,
1363 wxPGWindowList
wxPGTextCtrlAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1364 wxPGProperty
* property
,
1366 const wxSize
& sz
) const
1369 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrlAndButton( pos
, sz
, &wnd2
,
1370 property
->GetFlags() & wxPG_PROP_NOEDITOR
, property
);
1372 return wxPGWindowList(wnd
, wnd2
);
1376 wxPGTextCtrlAndButtonEditor::~wxPGTextCtrlAndButtonEditor() { }
1379 // -----------------------------------------------------------------------
1380 // wxPGCheckBoxEditor
1381 // -----------------------------------------------------------------------
1383 #if wxPG_INCLUDE_CHECKBOX
1385 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(CheckBox
,
1390 // Check box state flags
1393 wxSCB_STATE_UNCHECKED
= 0,
1394 wxSCB_STATE_CHECKED
= 1,
1395 wxSCB_STATE_BOLD
= 2,
1396 wxSCB_STATE_UNSPECIFIED
= 4
1399 const int wxSCB_SETVALUE_CYCLE
= 2;
1402 static void DrawSimpleCheckBox( wxDC
& dc
, const wxRect
& rect
, int box_hei
,
1406 wxRect
r(rect
.x
+wxPG_XBEFORETEXT
,rect
.y
+((rect
.height
-box_hei
)/2),
1408 wxColour useCol
= dc
.GetTextForeground();
1410 if ( state
& wxSCB_STATE_UNSPECIFIED
)
1412 useCol
= wxColour(220, 220, 220);
1415 // Draw check mark first because it is likely to overdraw the
1416 // surrounding rectangle.
1417 if ( state
& wxSCB_STATE_CHECKED
)
1419 wxRect
r2(r
.x
+wxPG_CHECKMARK_XADJ
,
1420 r
.y
+wxPG_CHECKMARK_YADJ
,
1421 r
.width
+wxPG_CHECKMARK_WADJ
,
1422 r
.height
+wxPG_CHECKMARK_HADJ
);
1423 #if wxPG_CHECKMARK_DEFLATE
1424 r2
.Deflate(wxPG_CHECKMARK_DEFLATE
);
1426 dc
.DrawCheckMark(r2
);
1428 // This would draw a simple cross check mark.
1429 // dc.DrawLine(r.x,r.y,r.x+r.width-1,r.y+r.height-1);
1430 // dc.DrawLine(r.x,r.y+r.height-1,r.x+r.width-1,r.y);
1433 if ( !(state
& wxSCB_STATE_BOLD
) )
1435 // Pen for thin rectangle.
1440 // Pen for bold rectangle.
1441 wxPen
linepen(useCol
,2,wxSOLID
);
1442 linepen
.SetJoin(wxJOIN_MITER
); // This prevents round edges.
1450 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1452 dc
.DrawRectangle(r
);
1453 dc
.SetPen(*wxTRANSPARENT_PEN
);
1457 // Real simple custom-drawn checkbox-without-label class.
1459 class wxSimpleCheckBox
: public wxControl
1463 void SetValue( int value
);
1465 wxSimpleCheckBox( wxWindow
* parent
,
1467 const wxPoint
& pos
= wxDefaultPosition
,
1468 const wxSize
& size
= wxDefaultSize
)
1469 : wxControl(parent
,id
,pos
,size
,wxBORDER_NONE
|wxWANTS_CHARS
)
1471 // Due to SetOwnFont stuff necessary for GTK+ 1.2, we need to have this
1472 SetFont( parent
->GetFont() );
1477 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
1480 virtual ~wxSimpleCheckBox();
1486 void OnPaint( wxPaintEvent
& event
);
1487 void OnLeftClick( wxMouseEvent
& event
);
1488 void OnKeyDown( wxKeyEvent
& event
);
1490 void OnResize( wxSizeEvent
& event
)
1496 static wxBitmap
* ms_doubleBuffer
;
1498 DECLARE_EVENT_TABLE()
1501 BEGIN_EVENT_TABLE(wxSimpleCheckBox
, wxControl
)
1502 EVT_PAINT(wxSimpleCheckBox::OnPaint
)
1503 EVT_LEFT_DOWN(wxSimpleCheckBox::OnLeftClick
)
1504 EVT_LEFT_DCLICK(wxSimpleCheckBox::OnLeftClick
)
1505 EVT_KEY_DOWN(wxSimpleCheckBox::OnKeyDown
)
1506 EVT_SIZE(wxSimpleCheckBox::OnResize
)
1509 wxSimpleCheckBox::~wxSimpleCheckBox()
1511 delete ms_doubleBuffer
;
1512 ms_doubleBuffer
= NULL
;
1515 wxBitmap
* wxSimpleCheckBox::ms_doubleBuffer
= NULL
;
1517 void wxSimpleCheckBox::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1519 wxSize clientSize
= GetClientSize();
1520 wxAutoBufferedPaintDC
dc(this);
1523 wxRect
rect(0,0,clientSize
.x
,clientSize
.y
);
1527 wxColour bgcol
= GetBackgroundColour();
1528 dc
.SetBrush( bgcol
);
1530 dc
.DrawRectangle( rect
);
1532 dc
.SetTextForeground(GetForegroundColour());
1534 int state
= m_state
;
1535 if ( !(state
& wxSCB_STATE_UNSPECIFIED
) &&
1536 GetFont().GetWeight() == wxBOLD
)
1537 state
|= wxSCB_STATE_BOLD
;
1539 DrawSimpleCheckBox(dc
, rect
, m_boxHeight
, state
);
1542 void wxSimpleCheckBox::OnLeftClick( wxMouseEvent
& event
)
1544 if ( (event
.m_x
> (wxPG_XBEFORETEXT
-2)) &&
1545 (event
.m_x
<= (wxPG_XBEFORETEXT
-2+m_boxHeight
)) )
1547 SetValue(wxSCB_SETVALUE_CYCLE
);
1551 void wxSimpleCheckBox::OnKeyDown( wxKeyEvent
& event
)
1553 if ( event
.GetKeyCode() == WXK_SPACE
)
1555 SetValue(wxSCB_SETVALUE_CYCLE
);
1559 void wxSimpleCheckBox::SetValue( int value
)
1561 if ( value
== wxSCB_SETVALUE_CYCLE
)
1563 if ( m_state
& wxSCB_STATE_CHECKED
)
1564 m_state
&= ~wxSCB_STATE_CHECKED
;
1566 m_state
|= wxSCB_STATE_CHECKED
;
1574 wxCommandEvent
evt(wxEVT_COMMAND_CHECKBOX_CLICKED
,GetParent()->GetId());
1576 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent();
1577 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1578 propGrid
->HandleCustomEditorEvent(evt
);
1581 wxPGWindowList
wxPGCheckBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1582 wxPGProperty
* property
,
1584 const wxSize
& size
) const
1586 if ( property
->HasFlag(wxPG_PROP_READONLY
) )
1590 pt
.x
-= wxPG_XBEFOREWIDGET
;
1592 sz
.x
= propGrid
->GetFontHeight() + (wxPG_XBEFOREWIDGET
*2) + 4;
1594 wxSimpleCheckBox
* cb
= new wxSimpleCheckBox(propGrid
->GetPanel(),
1595 wxPG_SUBID1
, pt
, sz
);
1597 cb
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
1599 UpdateControl(property
, cb
);
1601 if ( !property
->IsValueUnspecified() )
1603 // If mouse cursor was on the item, toggle the value now.
1604 if ( propGrid
->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK
)
1606 wxPoint pt
= cb
->ScreenToClient(::wxGetMousePosition());
1607 if ( pt
.x
<= (wxPG_XBEFORETEXT
-2+cb
->m_boxHeight
) )
1609 if ( cb
->m_state
& wxSCB_STATE_CHECKED
)
1610 cb
->m_state
&= ~wxSCB_STATE_CHECKED
;
1612 cb
->m_state
|= wxSCB_STATE_CHECKED
;
1614 // Makes sure wxPG_EVT_CHANGING etc. is sent for this initial
1616 propGrid
->ChangePropertyValue(property
,
1617 wxPGVariant_Bool(cb
->m_state
));
1622 propGrid
->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR
);
1627 void wxPGCheckBoxEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
,
1628 wxPGProperty
* property
,
1629 const wxString
& WXUNUSED(text
) ) const
1631 int state
= wxSCB_STATE_UNCHECKED
;
1633 if ( !property
->IsValueUnspecified() )
1635 state
= property
->GetChoiceSelection();
1636 if ( dc
.GetFont().GetWeight() == wxBOLD
)
1637 state
|= wxSCB_STATE_BOLD
;
1641 state
|= wxSCB_STATE_UNSPECIFIED
;
1644 DrawSimpleCheckBox(dc
, rect
, dc
.GetCharHeight(), state
);
1647 void wxPGCheckBoxEditor::UpdateControl( wxPGProperty
* property
,
1648 wxWindow
* ctrl
) const
1650 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*) ctrl
;
1653 if ( !property
->IsValueUnspecified() )
1654 cb
->m_state
= property
->GetChoiceSelection();
1656 cb
->m_state
= wxSCB_STATE_UNSPECIFIED
;
1658 wxPropertyGrid
* propGrid
= property
->GetGrid();
1659 cb
->m_boxHeight
= propGrid
->GetFontHeight();
1664 bool wxPGCheckBoxEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propGrid
), wxPGProperty
* WXUNUSED(property
),
1665 wxWindow
* WXUNUSED(ctrl
), wxEvent
& event
) const
1667 if ( event
.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED
)
1675 bool wxPGCheckBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1677 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*)ctrl
;
1679 int index
= cb
->m_state
;
1681 if ( index
!= property
->GetChoiceSelection() ||
1682 // Changing unspecified always causes event (returning
1683 // true here should be enough to trigger it).
1684 property
->IsValueUnspecified()
1687 return property
->IntToValue(variant
, index
, 0);
1693 void wxPGCheckBoxEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1695 if ( value
!= 0 ) value
= 1;
1696 ((wxSimpleCheckBox
*)ctrl
)->m_state
= value
;
1701 void wxPGCheckBoxEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1703 ((wxSimpleCheckBox
*)ctrl
)->m_state
= wxSCB_STATE_UNSPECIFIED
;
1708 wxPGCheckBoxEditor::~wxPGCheckBoxEditor() { }
1711 #endif // wxPG_INCLUDE_CHECKBOX
1713 // -----------------------------------------------------------------------
1715 wxWindow
* wxPropertyGrid::GetEditorControl() const
1717 wxWindow
* ctrl
= m_wndEditor
;
1725 // -----------------------------------------------------------------------
1727 void wxPropertyGrid::CorrectEditorWidgetSizeX()
1731 // Use fixed selColumn 1 for main editor widgets
1732 int newSplitterx
= m_pState
->DoGetSplitterPosition(0);
1733 int newWidth
= newSplitterx
+ m_pState
->m_colWidths
[1];
1737 // if width change occurred, move secondary wnd by that amount
1738 wxRect r
= m_wndEditor2
->GetRect();
1740 r
.x
= newWidth
- secWid
;
1742 m_wndEditor2
->SetSize( r
);
1744 // if primary is textctrl, then we have to add some extra space
1748 if ( m_wndEditor
&& m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1750 secWid
+= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1755 wxRect r
= m_wndEditor
->GetRect();
1757 r
.x
= newSplitterx
+m_ctrlXAdjust
;
1759 if ( !(m_iFlags
& wxPG_FL_FIXED_WIDTH_EDITOR
) )
1760 r
.width
= newWidth
- r
.x
- secWid
;
1762 m_wndEditor
->SetSize(r
);
1766 m_wndEditor2
->Refresh();
1769 // -----------------------------------------------------------------------
1771 void wxPropertyGrid::CorrectEditorWidgetPosY()
1773 wxPGProperty
* selected
= GetSelection();
1777 if ( m_labelEditor
)
1779 wxRect r
= GetEditorWidgetRect(selected
, m_selColumn
);
1780 wxPoint pos
= m_labelEditor
->GetPosition();
1782 // Calculate y offset
1783 int offset
= pos
.y
% m_lineHeight
;
1785 m_labelEditor
->Move(pos
.x
, r
.y
+ offset
);
1788 if ( m_wndEditor
|| m_wndEditor2
)
1790 wxRect r
= GetEditorWidgetRect(selected
, 1);
1794 wxPoint pos
= m_wndEditor
->GetPosition();
1796 // Calculate y offset
1797 int offset
= pos
.y
% m_lineHeight
;
1799 m_wndEditor
->Move(pos
.x
, r
.y
+ offset
);
1804 wxPoint pos
= m_wndEditor2
->GetPosition();
1806 m_wndEditor2
->Move(pos
.x
, r
.y
);
1812 // -----------------------------------------------------------------------
1814 // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
1815 // fits into that category as well).
1816 void wxPropertyGrid::FixPosForTextCtrl( wxWindow
* ctrl
,
1817 unsigned int WXUNUSED(forColumn
),
1818 const wxPoint
& offset
)
1820 // Center the control vertically
1821 wxRect finalPos
= ctrl
->GetRect();
1822 int y_adj
= (m_lineHeight
- finalPos
.height
)/2 + wxPG_TEXTCTRLYADJUST
;
1824 // Prevent over-sized control
1825 int sz_dec
= (y_adj
+ finalPos
.height
) - m_lineHeight
;
1826 if ( sz_dec
< 0 ) sz_dec
= 0;
1828 finalPos
.y
+= y_adj
;
1829 finalPos
.height
-= (y_adj
+sz_dec
);
1831 #ifndef wxPG_TEXTCTRLXADJUST
1832 int textCtrlXAdjust
= wxPG_XBEFORETEXT
- 1;
1834 wxTextCtrl
* tc
= static_cast<wxTextCtrl
*>(ctrl
);
1837 int textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
;
1840 finalPos
.x
+= textCtrlXAdjust
;
1841 finalPos
.width
-= textCtrlXAdjust
;
1843 finalPos
.x
+= offset
.x
;
1844 finalPos
.y
+= offset
.y
;
1846 ctrl
->SetSize(finalPos
);
1849 // -----------------------------------------------------------------------
1851 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint
& pos
,
1853 const wxString
& value
,
1854 wxWindow
* secondary
,
1857 unsigned int forColumn
)
1859 wxWindowID id
= wxPG_SUBID1
;
1860 wxPGProperty
* prop
= GetSelection();
1863 int tcFlags
= wxTE_PROCESS_ENTER
| extraStyle
;
1865 if ( prop
->HasFlag(wxPG_PROP_READONLY
) && forColumn
== 1 )
1866 tcFlags
|= wxTE_READONLY
;
1868 wxPoint
p(pos
.x
,pos
.y
);
1869 wxSize
s(sz
.x
,sz
.y
);
1871 // Need to reduce width of text control on Mac
1872 #if defined(__WXMAC__)
1876 // For label editors, trim the size to allow better splitter grabbing
1877 if ( forColumn
!= 1 )
1880 // Take button into acccount
1883 s
.x
-= (secondary
->GetSize().x
+ wxPG_TEXTCTRL_AND_BUTTON_SPACING
);
1884 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
1887 // If the height is significantly higher, then use border, and fill the rect exactly.
1888 bool hasSpecialSize
= false;
1890 if ( (sz
.y
- m_lineHeight
) > 5 )
1891 hasSpecialSize
= true;
1893 wxWindow
* ctrlParent
= GetPanel();
1895 if ( !hasSpecialSize
)
1896 tcFlags
|= wxBORDER_NONE
;
1898 wxTextCtrl
* tc
= new wxTextCtrl();
1900 #if defined(__WXMSW__)
1903 SetupTextCtrlValue(value
);
1904 tc
->Create(ctrlParent
,id
,value
, p
, s
,tcFlags
);
1906 #if defined(__WXMSW__)
1907 // On Windows, we need to override read-only text ctrl's background
1908 // colour to white. One problem with native 'grey' background is that
1909 // tc->GetBackgroundColour() doesn't seem to return correct value
1911 if ( tcFlags
& wxTE_READONLY
)
1913 wxVisualAttributes vattrs
= tc
->GetDefaultAttributes();
1914 tc
->SetBackgroundColour(vattrs
.colBg
);
1918 // Center the control vertically
1919 if ( !hasSpecialSize
)
1920 FixPosForTextCtrl(tc
, forColumn
);
1922 if ( forColumn
!= 1 )
1924 tc
->SetBackgroundColour(m_colSelBack
);
1925 tc
->SetForegroundColour(m_colSelFore
);
1934 // Set maximum length
1936 tc
->SetMaxLength( maxLen
);
1938 wxVariant attrVal
= prop
->GetAttribute(wxPG_ATTR_AUTOCOMPLETE
);
1939 if ( !attrVal
.IsNull() )
1941 wxASSERT(attrVal
.GetType() == wxS("arrstring"));
1942 tc
->AutoComplete(attrVal
.GetArrayString());
1946 tc
->SetHint(prop
->GetHintText());
1951 // -----------------------------------------------------------------------
1953 wxWindow
* wxPropertyGrid::GenerateEditorButton( const wxPoint
& pos
, const wxSize
& sz
)
1955 wxWindowID id
= wxPG_SUBID2
;
1956 wxPGProperty
* selected
= GetSelection();
1960 // Decorations are chunky on Mac, and we can't make the button square, so
1961 // do things a bit differently on this platform.
1963 wxPoint
p(pos
.x
+sz
.x
,
1964 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1967 wxButton
* but
= new wxButton();
1968 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1970 // Now that we know the size, move to the correct position
1971 p
.x
= pos
.x
+ sz
.x
- but
->GetSize().x
- 2;
1975 wxSize
s(sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2),
1976 sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2));
1978 // Reduce button width to lineheight
1979 if ( s
.x
> m_lineHeight
)
1983 // On wxGTK, take fixed button margins into account
1988 wxPoint
p(pos
.x
+sz
.x
-s
.x
,
1989 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1991 wxButton
* but
= new wxButton();
1995 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1998 wxFont font
= GetFont();
1999 font
.SetPointSize(font
.GetPointSize()-2);
2002 but
->SetFont(GetFont());
2006 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
2012 // -----------------------------------------------------------------------
2014 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrlAndButton( const wxPoint
& pos
,
2016 wxWindow
** psecondary
,
2018 wxPGProperty
* property
)
2020 wxButton
* but
= (wxButton
*)GenerateEditorButton(pos
,sz
);
2021 *psecondary
= (wxWindow
*)but
;
2023 if ( limitedEditing
)
2026 // There is button Show in GenerateEditorTextCtrl as well
2034 if ( !property
->IsValueUnspecified() )
2035 text
= property
->GetValueAsString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
2037 return GenerateEditorTextCtrl(pos
,sz
,text
,but
,property
->m_maxLen
);
2040 // -----------------------------------------------------------------------
2042 void wxPropertyGrid::SetEditorAppearance( const wxPGCell
& cell
,
2045 wxPGProperty
* property
= GetSelection();
2048 wxWindow
* ctrl
= GetEditorControl();
2052 property
->GetEditorClass()->SetControlAppearance( this,
2059 m_editorAppearance
= cell
;
2062 // -----------------------------------------------------------------------
2064 wxTextCtrl
* wxPropertyGrid::GetEditorTextCtrl() const
2066 wxWindow
* wnd
= GetEditorControl();
2071 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2072 return wxStaticCast(wnd
, wxTextCtrl
);
2074 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
2076 wxOwnerDrawnComboBox
* cb
= wxStaticCast(wnd
, wxOwnerDrawnComboBox
);
2077 return cb
->GetTextCtrl();
2083 // -----------------------------------------------------------------------
2085 wxPGEditor
* wxPropertyGridInterface::GetEditorByName( const wxString
& editorName
)
2087 wxPGHashMapS2P::const_iterator it
;
2089 it
= wxPGGlobalVars
->m_mapEditorClasses
.find(editorName
);
2090 if ( it
== wxPGGlobalVars
->m_mapEditorClasses
.end() )
2092 return (wxPGEditor
*) it
->second
;
2095 // -----------------------------------------------------------------------
2096 // wxPGEditorDialogAdapter
2097 // -----------------------------------------------------------------------
2099 IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter
, wxObject
)
2101 bool wxPGEditorDialogAdapter::ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
2103 if ( !propGrid
->EditorValidate() )
2106 bool res
= DoShowDialog( propGrid
, property
);
2110 propGrid
->ValueChangeInEvent( m_value
);
2117 // -----------------------------------------------------------------------
2119 // -----------------------------------------------------------------------
2121 wxPGMultiButton::wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
)
2122 : wxWindow( pg
->GetPanel(), wxPG_SUBID2
, wxPoint(-100,-100), wxSize(0, sz
.y
) ),
2123 m_fullEditorSize(sz
), m_buttonsWidth(0)
2125 SetBackgroundColour(pg
->GetCellBackgroundColour());
2128 void wxPGMultiButton::Finalize( wxPropertyGrid
* WXUNUSED(propGrid
),
2129 const wxPoint
& pos
)
2131 Move( pos
.x
+ m_fullEditorSize
.x
- m_buttonsWidth
, pos
.y
);
2134 int wxPGMultiButton::GenId( int id
) const
2138 if ( m_buttons
.size() )
2139 id
= GetButton(m_buttons
.size()-1)->GetId() + 1;
2147 void wxPGMultiButton::Add( const wxBitmap
& bitmap
, int id
)
2150 wxSize sz
= GetSize();
2151 wxButton
* button
= new wxBitmapButton( this, id
, bitmap
,
2153 wxSize(sz
.y
, sz
.y
) );
2154 DoAddButton( button
, sz
);
2158 void wxPGMultiButton::Add( const wxString
& label
, int id
)
2161 wxSize sz
= GetSize();
2162 wxButton
* button
= new wxButton( this, id
, label
, wxPoint(sz
.x
, 0),
2163 wxSize(sz
.y
, sz
.y
) );
2164 DoAddButton( button
, sz
);
2167 void wxPGMultiButton::DoAddButton( wxWindow
* button
,
2170 m_buttons
.push_back(button
);
2171 int bw
= button
->GetSize().x
;
2172 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
2173 m_buttonsWidth
+= bw
;
2176 // -----------------------------------------------------------------------
2178 #endif // wxUSE_PROPGRID