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 WXUNUSED(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 wxVisualAttributes vattrs
= ctrl
->GetDefaultAttributes();
268 const wxColour
& fgCol
= cell
.GetFgCol();
271 ctrl
->SetForegroundColour(fgCol
);
273 else if ( oCell
.GetFgCol().IsOk() )
275 ctrl
->SetForegroundColour(vattrs
.colFg
);
279 const wxColour
& bgCol
= cell
.GetBgCol();
282 ctrl
->SetBackgroundColour(bgCol
);
284 else if ( oCell
.GetBgCol().IsOk() )
286 ctrl
->SetBackgroundColour(vattrs
.colBg
);
290 const wxFont
& font
= cell
.GetFont();
295 else if ( oCell
.GetFont().IsOk() )
297 ctrl
->SetFont(vattrs
.font
);
300 // Also call the old SetValueToUnspecified()
301 SetValueToUnspecified(property
, ctrl
);
304 void wxPGEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
),
305 wxWindow
* WXUNUSED(ctrl
) ) const
309 bool wxPGEditor::CanContainCustomImage() const
314 // -----------------------------------------------------------------------
315 // wxPGTextCtrlEditor
316 // -----------------------------------------------------------------------
318 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrl
,wxPGTextCtrlEditor
,wxPGEditor
)
321 wxPGWindowList
wxPGTextCtrlEditor::CreateControls( wxPropertyGrid
* propGrid
,
322 wxPGProperty
* property
,
324 const wxSize
& sz
) const
329 // If has children, and limited editing is specified, then don't create.
330 if ( (property
->GetFlags() & wxPG_PROP_NOEDITOR
) &&
331 property
->GetChildCount() )
335 if ( !property
->HasFlag(wxPG_PROP_READONLY
) &&
336 !property
->IsValueUnspecified() )
337 argFlags
|= wxPG_EDITABLE_VALUE
;
338 text
= property
->GetValueAsString(argFlags
);
341 if ( (property
->GetFlags() & wxPG_PROP_PASSWORD
) &&
342 property
->IsKindOf(CLASSINFO(wxStringProperty
)) )
343 flags
|= wxTE_PASSWORD
;
345 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrl(pos
,sz
,text
,NULL
,flags
,
346 property
->GetMaxLength());
352 void wxPGTextCtrlEditor::DrawValue( wxDC
& dc
, wxPGProperty
* property
, const wxRect
& rect
) const
354 if ( !property
->IsValueUnspecified() )
356 wxString drawStr
= property
->GetDisplayedString();
358 // Code below should no longer be needed, as the obfuscation
359 // is now done in GetValueAsString.
360 /*if ( (property->GetFlags() & wxPG_PROP_PASSWORD) &&
361 property->IsKindOf(WX_PG_CLASSINFO(wxStringProperty)) )
363 size_t a = drawStr.length();
365 drawStr.Append(wxS('*'),a);
367 dc
.DrawText( drawStr
, rect
.x
+wxPG_XBEFORETEXT
, rect
.y
);
372 void wxPGTextCtrlEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
374 wxTextCtrl
* tc
= wxDynamicCast(ctrl
, wxTextCtrl
);
379 if ( tc
->HasFlag(wxTE_PASSWORD
) )
380 s
= property
->GetValueAsString(wxPG_FULL_VALUE
);
382 s
= property
->GetDisplayedString();
384 wxPropertyGrid
* pg
= property
->GetGrid();
386 pg
->SetupTextCtrlValue(s
);
390 // Fix indentation, just in case (change in font boldness is one good
395 // Provided so that, for example, ComboBox editor can use the same code
396 // (multiple inheritance would get way too messy).
397 bool wxPGTextCtrlEditor::OnTextCtrlEvent( wxPropertyGrid
* propGrid
,
398 wxPGProperty
* WXUNUSED(property
),
405 if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_ENTER
)
407 if ( propGrid
->IsEditorsValueModified() )
412 else if ( event
.GetEventType() == wxEVT_COMMAND_TEXT_UPDATED
)
415 // Pass this event outside wxPropertyGrid so that,
416 // if necessary, program can tell when user is editing
418 // FIXME: Is it safe to change event id in the middle of event
419 // processing (seems to work, but...)?
421 event
.SetId(propGrid
->GetId());
423 propGrid
->EditorsValueWasModified();
429 bool wxPGTextCtrlEditor::OnEvent( wxPropertyGrid
* propGrid
,
430 wxPGProperty
* property
,
432 wxEvent
& event
) const
434 return wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,ctrl
,event
);
438 bool wxPGTextCtrlEditor::GetTextCtrlValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
)
440 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
441 wxString textVal
= tc
->GetValue();
443 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
449 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
451 // Changing unspecified always causes event (returning
452 // true here should be enough to trigger it).
453 // TODO: Move to propgrid.cpp
454 if ( !res
&& variant
.IsNull() )
461 bool wxPGTextCtrlEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
463 return wxPGTextCtrlEditor::GetTextCtrlValueFromControl(variant
, property
, ctrl
);
467 void wxPGTextCtrlEditor::SetControlStringValue( wxPGProperty
* property
, wxWindow
* ctrl
, const wxString
& txt
) const
469 wxTextCtrl
* tc
= wxStaticCast(ctrl
, wxTextCtrl
);
471 wxPropertyGrid
* pg
= property
->GetGrid();
472 wxASSERT(pg
); // Really, property grid should exist if editor does
475 pg
->SetupTextCtrlValue(txt
);
481 void wxPGTextCtrlEditor_OnFocus( wxPGProperty
* property
,
484 // Make sure there is correct text (instead of unspecified value
485 // indicator or inline help)
486 int flags
= property
->HasFlag(wxPG_PROP_READONLY
) ?
487 0 : wxPG_EDITABLE_VALUE
;
488 wxString correctText
= property
->GetValueAsString(flags
);
490 if ( tc
->GetValue() != correctText
)
492 property
->GetGrid()->SetupTextCtrlValue(correctText
);
493 tc
->SetValue(correctText
);
496 tc
->SetSelection(-1,-1);
499 void wxPGTextCtrlEditor::OnFocus( wxPGProperty
* property
,
500 wxWindow
* wnd
) const
502 wxTextCtrl
* tc
= wxStaticCast(wnd
, wxTextCtrl
);
503 wxPGTextCtrlEditor_OnFocus(property
, tc
);
506 wxPGTextCtrlEditor::~wxPGTextCtrlEditor() { }
509 // -----------------------------------------------------------------------
511 // -----------------------------------------------------------------------
514 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(Choice
,wxPGChoiceEditor
,wxPGEditor
)
517 // This is a special enhanced double-click processor class.
518 // In essence, it allows for double-clicks for which the
519 // first click "created" the control.
520 class wxPGDoubleClickProcessor
: public wxEvtHandler
524 wxPGDoubleClickProcessor( wxOwnerDrawnComboBox
* combo
, wxPGProperty
* property
)
527 m_timeLastMouseUp
= 0;
529 m_property
= property
;
530 m_downReceived
= false;
535 void OnMouseEvent( wxMouseEvent
& event
)
537 wxLongLong t
= ::wxGetLocalTimeMillis();
538 int evtType
= event
.GetEventType();
540 if ( m_property
->HasFlag(wxPG_PROP_USE_DCC
) &&
541 m_property
->IsKindOf(CLASSINFO(wxBoolProperty
)) &&
542 !m_combo
->IsPopupShown() )
544 // Just check that it is in the text area
545 wxPoint pt
= event
.GetPosition();
546 if ( m_combo
->GetTextRect().Contains(pt
) )
548 if ( evtType
== wxEVT_LEFT_DOWN
)
550 // Set value to avoid up-events without corresponding downs
551 m_downReceived
= true;
553 else if ( evtType
== wxEVT_LEFT_DCLICK
)
555 // We'll make our own double-clicks
556 event
.SetEventType(0);
559 else if ( evtType
== wxEVT_LEFT_UP
)
561 if ( m_downReceived
|| m_timeLastMouseUp
== 1 )
563 wxLongLong timeFromLastUp
= (t
-m_timeLastMouseUp
);
565 if ( timeFromLastUp
< DOUBLE_CLICK_CONVERSION_TRESHOLD
)
567 event
.SetEventType(wxEVT_LEFT_DCLICK
);
568 m_timeLastMouseUp
= 1;
572 m_timeLastMouseUp
= t
;
582 void OnSetFocus( wxFocusEvent
& event
)
584 m_timeLastMouseUp
= ::wxGetLocalTimeMillis();
589 wxLongLong m_timeLastMouseUp
;
590 wxOwnerDrawnComboBox
* m_combo
;
591 wxPGProperty
* m_property
; // Selected property
594 DECLARE_EVENT_TABLE()
597 BEGIN_EVENT_TABLE(wxPGDoubleClickProcessor
, wxEvtHandler
)
598 EVT_MOUSE_EVENTS(wxPGDoubleClickProcessor::OnMouseEvent
)
599 EVT_SET_FOCUS(wxPGDoubleClickProcessor::OnSetFocus
)
604 class wxPGComboBox
: public wxOwnerDrawnComboBox
609 : wxOwnerDrawnComboBox()
611 m_dclickProcessor
= NULL
;
612 m_sizeEventCalled
= false;
617 if ( m_dclickProcessor
)
619 RemoveEventHandler(m_dclickProcessor
);
620 delete m_dclickProcessor
;
624 bool Create(wxWindow
*parent
,
626 const wxString
& value
,
629 const wxArrayString
& choices
,
631 const wxValidator
& validator
= wxDefaultValidator
,
632 const wxString
& name
= wxS("wxOwnerDrawnComboBox"))
634 if ( !wxOwnerDrawnComboBox::Create( parent
,
645 m_dclickProcessor
= new
646 wxPGDoubleClickProcessor( this, GetGrid()->GetSelection() );
648 PushEventHandler(m_dclickProcessor
);
653 virtual void OnDrawItem( wxDC
& dc
,
658 wxPropertyGrid
* pg
= GetGrid();
659 pg
->OnComboItemPaint( this, item
, &dc
, (wxRect
&)rect
, flags
);
662 virtual wxCoord
OnMeasureItem( size_t item
) const
664 wxPropertyGrid
* pg
= GetGrid();
668 pg
->OnComboItemPaint( this, item
, NULL
, rect
, 0 );
672 wxPropertyGrid
* GetGrid() const
674 wxPropertyGrid
* pg
= wxDynamicCast(GetParent(),
680 virtual wxCoord
OnMeasureItemWidth( size_t item
) const
682 wxPropertyGrid
* pg
= GetGrid();
686 pg
->OnComboItemPaint( this, item
, NULL
, rect
, 0 );
690 virtual void PositionTextCtrl( int textCtrlXAdjust
,
691 int WXUNUSED(textCtrlYAdjust
) )
693 wxPropertyGrid
* pg
= GetGrid();
694 #ifdef wxPG_TEXTCTRLXADJUST
695 textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
-
696 (wxPG_XBEFOREWIDGET
+wxPG_CONTROL_MARGIN
+1) - 1,
698 wxOwnerDrawnComboBox::PositionTextCtrl(
700 pg
->GetSpacingY() + 2
705 wxPGDoubleClickProcessor
* m_dclickProcessor
;
706 bool m_sizeEventCalled
;
710 void wxPropertyGrid::OnComboItemPaint( const wxPGComboBox
* pCb
,
717 wxASSERT( IsKindOf(CLASSINFO(wxPropertyGrid
)) );
719 wxPGProperty
* p
= GetSelection();
722 const wxPGChoices
& choices
= p
->GetChoices();
723 const wxPGCommonValue
* comVal
= NULL
;
724 int comVals
= p
->GetDisplayedCommonValueCount();
725 int comValIndex
= -1;
728 if ( choices
.IsOk() )
729 choiceCount
= choices
.GetCount();
731 if ( item
>= choiceCount
&& comVals
> 0 )
733 comValIndex
= item
- choiceCount
;
734 comVal
= GetCommonValue(comValIndex
);
735 if ( !p
->IsValueUnspecified() )
736 text
= comVal
->GetLabel();
740 if ( !(flags
& wxODCB_PAINTING_CONTROL
) )
742 text
= pCb
->GetString(item
);
746 if ( !p
->IsValueUnspecified() )
747 text
= p
->GetValueAsString(0);
756 const wxBitmap
* itemBitmap
= NULL
;
758 if ( item
>= 0 && choices
.IsOk() && choices
.Item(item
).GetBitmap().Ok() && comValIndex
== -1 )
759 itemBitmap
= &choices
.Item(item
).GetBitmap();
762 // Decide what custom image size to use
765 cis
.x
= itemBitmap
->GetWidth();
766 cis
.y
= itemBitmap
->GetHeight();
770 cis
= GetImageSize(p
, item
);
775 // Default measure behaviour (no flexible, custom paint image only)
776 if ( rect
.width
< 0 )
779 pCb
->GetTextExtent(text
, &x
, &y
, 0, 0);
780 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9 + x
;
783 rect
.height
= cis
.y
+ 2;
787 wxPGPaintData paintdata
;
788 paintdata
.m_parent
= NULL
;
789 paintdata
.m_choiceItem
= item
;
791 // This is by the current (1.0.0b) spec - if painting control, item is -1
792 if ( (flags
& wxODCB_PAINTING_CONTROL
) )
793 paintdata
.m_choiceItem
= -1;
796 pDc
->SetBrush(*wxWHITE_BRUSH
);
798 wxPGCellRenderer
* renderer
= NULL
;
799 const wxPGChoiceEntry
* cell
= NULL
;
807 wxPoint
pt(rect
.x
+ wxPG_CONTROL_MARGIN
- wxPG_CHOICEXADJUST
- 1,
810 int renderFlags
= wxPGCellRenderer::DontUseCellColours
;
812 if ( flags
& wxODCB_PAINTING_CONTROL
)
813 renderFlags
|= wxPGCellRenderer::Control
;
815 renderFlags
|= wxPGCellRenderer::ChoicePopup
;
817 if ( flags
& wxODCB_PAINTING_SELECTED
)
818 renderFlags
|= wxPGCellRenderer::Selected
;
820 if ( cis
.x
> 0 && (p
->HasFlag(wxPG_PROP_CUSTOMIMAGE
) || !(flags
& wxODCB_PAINTING_CONTROL
)) &&
821 ( !p
->m_valueBitmap
|| item
== pCb
->GetSelection() ) &&
822 ( item
>= 0 || (flags
& wxODCB_PAINTING_CONTROL
) ) &&
826 pt
.x
+= wxCC_CUSTOM_IMAGE_MARGIN1
;
827 wxRect
r(pt
.x
,pt
.y
,cis
.x
,cis
.y
);
829 if ( flags
& wxODCB_PAINTING_CONTROL
)
832 r
.height
= wxPG_STD_CUST_IMAGE_HEIGHT(m_lineHeight
);
835 paintdata
.m_drawnWidth
= r
.width
;
837 dc
.SetPen(m_colPropFore
);
838 if ( comValIndex
>= 0 )
840 const wxPGCommonValue
* cv
= GetCommonValue(comValIndex
);
841 wxPGCellRenderer
* renderer
= cv
->GetRenderer();
842 r
.width
= rect
.width
;
843 renderer
->Render( dc
, r
, this, p
, m_selColumn
, comValIndex
, renderFlags
);
846 else if ( item
>= 0 )
848 p
->OnCustomPaint( dc
, r
, paintdata
);
852 dc
.DrawRectangle( r
);
855 pt
.x
+= paintdata
.m_drawnWidth
+ wxCC_CUSTOM_IMAGE_MARGIN2
- 1;
859 // TODO: This aligns text so that it seems to be horizontally
860 // on the same line as property values. Not really
861 // sure if its needed, but seems to not cause any harm.
864 if ( item
< 0 && (flags
& wxODCB_PAINTING_CONTROL
) )
865 item
= pCb
->GetSelection();
867 if ( choices
.IsOk() && item
>= 0 && comValIndex
< 0 )
869 cell
= &choices
.Item(item
);
870 renderer
= wxPGGlobalVars
->m_defaultRenderer
;
871 int imageOffset
= renderer
->PreDrawCell(dc
, rect
, *cell
,
874 imageOffset
+= wxCC_CUSTOM_IMAGE_MARGIN1
+
875 wxCC_CUSTOM_IMAGE_MARGIN2
;
884 pt
.y
+= (rect
.height
-m_fontHeight
)/2 - 1;
888 dc
.DrawText( text
, pt
.x
+ wxPG_XBEFORETEXT
, pt
.y
);
891 renderer
->PostDrawCell(dc
, this, *cell
, renderFlags
);
899 p
->OnCustomPaint( dc
, rect
, paintdata
);
900 rect
.height
= paintdata
.m_drawnHeight
+ 2;
901 rect
.width
= cis
.x
+ wxCC_CUSTOM_IMAGE_MARGIN1
+ wxCC_CUSTOM_IMAGE_MARGIN2
+ 9;
905 bool wxPGChoiceEditor_SetCustomPaintWidth( wxPropertyGrid
* propGrid
, wxPGComboBox
* cb
, int cmnVal
)
907 wxPGProperty
* property
= propGrid
->GetSelectedProperty();
908 wxASSERT( property
);
913 // TODO: Do this always when cell has custom text.
914 if ( property
->IsValueUnspecified() )
916 cb
->SetCustomPaintWidth( 0 );
922 // Yes, a common value is being selected
923 property
->SetCommonValue( cmnVal
);
924 imageSize
= propGrid
->GetCommonValue(cmnVal
)->
925 GetRenderer()->GetImageSize(property
, 1, cmnVal
);
930 imageSize
= propGrid
->GetImageSize(property
, -1);
935 imageSize
.x
+= ODCB_CUST_PAINT_MARGIN
;
936 cb
->SetCustomPaintWidth( imageSize
.x
);
941 // CreateControls calls this with CB_READONLY in extraStyle
942 wxWindow
* wxPGChoiceEditor::CreateControlsBase( wxPropertyGrid
* propGrid
,
943 wxPGProperty
* property
,
946 long extraStyle
) const
948 const wxPGChoices
& choices
= property
->GetChoices();
950 int index
= property
->GetChoiceSelection();
953 if ( !property
->HasFlag(wxPG_PROP_READONLY
) &&
954 !property
->IsValueUnspecified() )
955 argFlags
|= wxPG_EDITABLE_VALUE
;
956 defString
= property
->GetValueAsString(argFlags
);
958 wxArrayString labels
= choices
.GetLabels();
964 po
.y
+= wxPG_CHOICEYADJUST
;
965 si
.y
-= (wxPG_CHOICEYADJUST
*2);
967 po
.x
+= wxPG_CHOICEXADJUST
;
968 si
.x
-= wxPG_CHOICEXADJUST
;
969 wxWindow
* ctrlParent
= propGrid
->GetPanel();
971 int odcbFlags
= extraStyle
| wxBORDER_NONE
| wxTE_PROCESS_ENTER
;
973 if ( (property
->GetFlags() & wxPG_PROP_USE_DCC
) &&
974 (property
->IsKindOf(CLASSINFO(wxBoolProperty
)) ) )
975 odcbFlags
|= wxODCB_DCLICK_CYCLES
;
978 // If common value specified, use appropriate index
979 unsigned int cmnVals
= property
->GetDisplayedCommonValueCount();
982 if ( !property
->IsValueUnspecified() )
984 int cmnVal
= property
->GetCommonValue();
987 index
= labels
.size() + cmnVal
;
992 for ( i
=0; i
<cmnVals
; i
++ )
993 labels
.Add(propGrid
->GetCommonValueLabel(i
));
996 cb
= new wxPGComboBox();
1000 cb
->Create(ctrlParent
,
1008 cb
->SetButtonPosition(si
.y
,0,wxRIGHT
);
1009 cb
->SetMargins(wxPG_XBEFORETEXT
-1);
1011 wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, property
->GetCommonValue() );
1013 if ( index
>= 0 && index
< (int)cb
->GetCount() )
1015 cb
->SetSelection( index
);
1016 if ( defString
.length() )
1017 cb
->SetText( defString
);
1019 else if ( !(extraStyle
& wxCB_READONLY
) && defString
.length() )
1021 propGrid
->SetupTextCtrlValue(defString
);
1022 cb
->SetValue( defString
);
1026 cb
->SetSelection( -1 );
1033 return (wxWindow
*) cb
;
1037 void wxPGChoiceEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1040 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1041 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1042 int ind
= property
->GetChoiceSelection();
1043 cb
->SetSelection(ind
);
1046 wxPGWindowList
wxPGChoiceEditor::CreateControls( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
1047 const wxPoint
& pos
, const wxSize
& sz
) const
1049 return CreateControlsBase(propGrid
,property
,pos
,sz
,wxCB_READONLY
);
1053 int wxPGChoiceEditor::InsertItem( wxWindow
* ctrl
, const wxString
& label
, int index
) const
1056 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1057 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1060 index
= cb
->GetCount();
1062 return cb
->Insert(label
,index
);
1066 void wxPGChoiceEditor::DeleteItem( wxWindow
* ctrl
, int index
) const
1069 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1070 wxASSERT( cb
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)));
1075 bool wxPGChoiceEditor::OnEvent( wxPropertyGrid
* propGrid
, wxPGProperty
* property
,
1076 wxWindow
* ctrl
, wxEvent
& event
) const
1078 if ( event
.GetEventType() == wxEVT_COMMAND_COMBOBOX_SELECTED
)
1080 wxPGComboBox
* cb
= (wxPGComboBox
*)ctrl
;
1081 int index
= cb
->GetSelection();
1082 int cmnValIndex
= -1;
1083 int cmnVals
= property
->GetDisplayedCommonValueCount();
1084 int items
= cb
->GetCount();
1086 if ( index
>= (items
-cmnVals
) )
1088 // Yes, a common value is being selected
1089 cmnValIndex
= index
- (items
-cmnVals
);
1090 property
->SetCommonValue( cmnValIndex
);
1092 // Truly set value to unspecified?
1093 if ( propGrid
->GetUnspecifiedCommonValue() == cmnValIndex
)
1095 if ( !property
->IsValueUnspecified() )
1096 propGrid
->SetInternalFlag(wxPG_FL_VALUE_CHANGE_IN_EVENT
);
1097 property
->SetValueToUnspecified();
1098 if ( !cb
->HasFlag(wxCB_READONLY
) )
1100 wxString unspecValueText
;
1101 unspecValueText
= propGrid
->GetUnspecifiedValueText();
1102 propGrid
->SetupTextCtrlValue(unspecValueText
);
1103 cb
->GetTextCtrl()->SetValue(unspecValueText
);
1108 return wxPGChoiceEditor_SetCustomPaintWidth( propGrid
, cb
, cmnValIndex
);
1114 bool wxPGChoiceEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1116 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1118 int index
= cb
->GetSelection();
1120 if ( index
!= property
->GetChoiceSelection() ||
1121 // Changing unspecified always causes event (returning
1122 // true here should be enough to trigger it).
1123 property
->IsValueUnspecified()
1126 return property
->IntToValue( variant
, index
, 0 );
1132 void wxPGChoiceEditor::SetControlStringValue( wxPGProperty
* property
,
1134 const wxString
& txt
) const
1136 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1138 property
->GetGrid()->SetupTextCtrlValue(txt
);
1143 void wxPGChoiceEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1145 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1147 cb
->SetSelection(value
);
1151 void wxPGChoiceEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
),
1152 wxWindow
* ctrl
) const
1154 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1156 if ( cb
->HasFlag(wxCB_READONLY
) )
1157 cb
->SetSelection(-1);
1161 bool wxPGChoiceEditor::CanContainCustomImage() const
1167 wxPGChoiceEditor::~wxPGChoiceEditor() { }
1170 // -----------------------------------------------------------------------
1171 // wxPGComboBoxEditor
1172 // -----------------------------------------------------------------------
1175 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ComboBox
,
1180 void wxPGComboBoxEditor::UpdateControl( wxPGProperty
* property
, wxWindow
* ctrl
) const
1182 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1183 wxString s
= property
->GetValueAsString(wxPG_EDITABLE_VALUE
);
1184 property
->GetGrid()->SetupTextCtrlValue(s
);
1187 // TODO: If string matches any selection, then select that.
1191 wxPGWindowList
wxPGComboBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1192 wxPGProperty
* property
,
1194 const wxSize
& sz
) const
1196 return CreateControlsBase(propGrid
,property
,pos
,sz
,0);
1200 bool wxPGComboBoxEditor::OnEvent( wxPropertyGrid
* propGrid
,
1201 wxPGProperty
* property
,
1203 wxEvent
& event
) const
1205 wxOwnerDrawnComboBox
* cb
= NULL
;
1206 wxWindow
* textCtrl
= NULL
;
1210 cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1211 textCtrl
= cb
->GetTextCtrl();
1214 if ( wxPGTextCtrlEditor::OnTextCtrlEvent(propGrid
,property
,textCtrl
,event
) )
1217 return wxPGChoiceEditor::OnEvent(propGrid
,property
,ctrl
,event
);
1221 bool wxPGComboBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1223 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1224 wxString textVal
= cb
->GetValue();
1226 if ( property
->UsesAutoUnspecified() && !textVal
.length() )
1232 bool res
= property
->StringToValue(variant
, textVal
, wxPG_EDITABLE_VALUE
);
1234 // Changing unspecified always causes event (returning
1235 // true here should be enough to trigger it).
1236 if ( !res
&& variant
.IsNull() )
1243 void wxPGComboBoxEditor::OnFocus( wxPGProperty
* property
,
1244 wxWindow
* ctrl
) const
1246 wxOwnerDrawnComboBox
* cb
= (wxOwnerDrawnComboBox
*)ctrl
;
1247 wxPGTextCtrlEditor_OnFocus(property
, cb
->GetTextCtrl());
1251 wxPGComboBoxEditor::~wxPGComboBoxEditor() { }
1254 // -----------------------------------------------------------------------
1255 // wxPGChoiceAndButtonEditor
1256 // -----------------------------------------------------------------------
1259 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(ChoiceAndButton
,
1260 wxPGChoiceAndButtonEditor
,
1264 wxPGWindowList
wxPGChoiceAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1265 wxPGProperty
* property
,
1267 const wxSize
& sz
) const
1269 // Use one two units smaller to match size of the combo's dropbutton.
1270 // (normally a bigger button is used because it looks better)
1273 wxSize
bt_sz(bt_wid
,bt_wid
);
1275 // Position of button.
1276 wxPoint
bt_pos(pos
.x
+sz
.x
-bt_sz
.x
,pos
.y
);
1283 wxWindow
* bt
= propGrid
->GenerateEditorButton( bt_pos
, bt_sz
);
1286 wxSize
ch_sz(sz
.x
-bt
->GetSize().x
,sz
.y
);
1289 ch_sz
.x
-= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1292 wxWindow
* ch
= wxPGEditor_Choice
->CreateControls(propGrid
,property
,
1293 pos
,ch_sz
).m_primary
;
1299 return wxPGWindowList(ch
, bt
);
1303 wxPGChoiceAndButtonEditor::~wxPGChoiceAndButtonEditor() { }
1306 // -----------------------------------------------------------------------
1307 // wxPGTextCtrlAndButtonEditor
1308 // -----------------------------------------------------------------------
1310 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(TextCtrlAndButton
,
1311 wxPGTextCtrlAndButtonEditor
,
1315 wxPGWindowList
wxPGTextCtrlAndButtonEditor::CreateControls( wxPropertyGrid
* propGrid
,
1316 wxPGProperty
* property
,
1318 const wxSize
& sz
) const
1321 wxWindow
* wnd
= propGrid
->GenerateEditorTextCtrlAndButton( pos
, sz
, &wnd2
,
1322 property
->GetFlags() & wxPG_PROP_NOEDITOR
, property
);
1324 return wxPGWindowList(wnd
, wnd2
);
1328 wxPGTextCtrlAndButtonEditor::~wxPGTextCtrlAndButtonEditor() { }
1331 // -----------------------------------------------------------------------
1332 // wxPGCheckBoxEditor
1333 // -----------------------------------------------------------------------
1335 #if wxPG_INCLUDE_CHECKBOX
1337 WX_PG_IMPLEMENT_INTERNAL_EDITOR_CLASS(CheckBox
,
1342 // Check box state flags
1345 wxSCB_STATE_UNCHECKED
= 0,
1346 wxSCB_STATE_CHECKED
= 1,
1347 wxSCB_STATE_BOLD
= 2,
1348 wxSCB_STATE_UNSPECIFIED
= 4
1351 const int wxSCB_SETVALUE_CYCLE
= 2;
1354 static void DrawSimpleCheckBox( wxDC
& dc
, const wxRect
& rect
, int box_hei
,
1355 int state
, const wxColour
& lineCol
)
1358 wxRect
r(rect
.x
+wxPG_XBEFORETEXT
,rect
.y
+((rect
.height
-box_hei
)/2),
1360 wxColour useCol
= lineCol
;
1362 if ( state
& wxSCB_STATE_UNSPECIFIED
)
1364 useCol
= wxColour(220, 220, 220);
1367 // Draw check mark first because it is likely to overdraw the
1368 // surrounding rectangle.
1369 if ( state
& wxSCB_STATE_CHECKED
)
1371 wxRect
r2(r
.x
+wxPG_CHECKMARK_XADJ
,
1372 r
.y
+wxPG_CHECKMARK_YADJ
,
1373 r
.width
+wxPG_CHECKMARK_WADJ
,
1374 r
.height
+wxPG_CHECKMARK_HADJ
);
1375 #if wxPG_CHECKMARK_DEFLATE
1376 r2
.Deflate(wxPG_CHECKMARK_DEFLATE
);
1378 dc
.DrawCheckMark(r2
);
1380 // This would draw a simple cross check mark.
1381 // dc.DrawLine(r.x,r.y,r.x+r.width-1,r.y+r.height-1);
1382 // dc.DrawLine(r.x,r.y+r.height-1,r.x+r.width-1,r.y);
1385 if ( !(state
& wxSCB_STATE_BOLD
) )
1387 // Pen for thin rectangle.
1392 // Pen for bold rectangle.
1393 wxPen
linepen(useCol
,2,wxSOLID
);
1394 linepen
.SetJoin(wxJOIN_MITER
); // This prevents round edges.
1402 dc
.SetBrush(*wxTRANSPARENT_BRUSH
);
1404 dc
.DrawRectangle(r
);
1405 dc
.SetPen(*wxTRANSPARENT_PEN
);
1409 // Real simple custom-drawn checkbox-without-label class.
1411 class wxSimpleCheckBox
: public wxControl
1415 void SetValue( int value
);
1417 wxSimpleCheckBox( wxWindow
* parent
,
1419 const wxPoint
& pos
= wxDefaultPosition
,
1420 const wxSize
& size
= wxDefaultSize
)
1421 : wxControl(parent
,id
,pos
,size
,wxBORDER_NONE
|wxWANTS_CHARS
)
1423 // Due to SetOwnFont stuff necessary for GTK+ 1.2, we need to have this
1424 SetFont( parent
->GetFont() );
1429 SetBackgroundStyle( wxBG_STYLE_CUSTOM
);
1432 virtual ~wxSimpleCheckBox();
1438 void OnPaint( wxPaintEvent
& event
);
1439 void OnLeftClick( wxMouseEvent
& event
);
1440 void OnKeyDown( wxKeyEvent
& event
);
1442 void OnResize( wxSizeEvent
& event
)
1448 static wxBitmap
* ms_doubleBuffer
;
1450 DECLARE_EVENT_TABLE()
1453 BEGIN_EVENT_TABLE(wxSimpleCheckBox
, wxControl
)
1454 EVT_PAINT(wxSimpleCheckBox::OnPaint
)
1455 EVT_LEFT_DOWN(wxSimpleCheckBox::OnLeftClick
)
1456 EVT_LEFT_DCLICK(wxSimpleCheckBox::OnLeftClick
)
1457 EVT_KEY_DOWN(wxSimpleCheckBox::OnKeyDown
)
1458 EVT_SIZE(wxSimpleCheckBox::OnResize
)
1461 wxSimpleCheckBox::~wxSimpleCheckBox()
1463 delete ms_doubleBuffer
;
1464 ms_doubleBuffer
= NULL
;
1467 wxBitmap
* wxSimpleCheckBox::ms_doubleBuffer
= NULL
;
1469 void wxSimpleCheckBox::OnPaint( wxPaintEvent
& WXUNUSED(event
) )
1471 wxSize clientSize
= GetClientSize();
1472 wxAutoBufferedPaintDC
dc(this);
1475 wxRect
rect(0,0,clientSize
.x
,clientSize
.y
);
1479 wxColour bgcol
= GetBackgroundColour();
1480 dc
.SetBrush( bgcol
);
1482 dc
.DrawRectangle( rect
);
1484 wxColour txcol
= GetForegroundColour();
1486 int state
= m_state
;
1487 if ( !(state
& wxSCB_STATE_UNSPECIFIED
) &&
1488 GetFont().GetWeight() == wxBOLD
)
1489 state
|= wxSCB_STATE_BOLD
;
1491 DrawSimpleCheckBox(dc
,rect
,m_boxHeight
,state
,txcol
);
1494 void wxSimpleCheckBox::OnLeftClick( wxMouseEvent
& event
)
1496 if ( (event
.m_x
> (wxPG_XBEFORETEXT
-2)) &&
1497 (event
.m_x
<= (wxPG_XBEFORETEXT
-2+m_boxHeight
)) )
1499 SetValue(wxSCB_SETVALUE_CYCLE
);
1503 void wxSimpleCheckBox::OnKeyDown( wxKeyEvent
& event
)
1505 if ( event
.GetKeyCode() == WXK_SPACE
)
1507 SetValue(wxSCB_SETVALUE_CYCLE
);
1511 void wxSimpleCheckBox::SetValue( int value
)
1513 if ( value
== wxSCB_SETVALUE_CYCLE
)
1515 if ( m_state
& wxSCB_STATE_CHECKED
)
1516 m_state
&= ~wxSCB_STATE_CHECKED
;
1518 m_state
|= wxSCB_STATE_CHECKED
;
1526 wxCommandEvent
evt(wxEVT_COMMAND_CHECKBOX_CLICKED
,GetParent()->GetId());
1528 wxPropertyGrid
* propGrid
= (wxPropertyGrid
*) GetParent();
1529 wxASSERT( propGrid
->IsKindOf(CLASSINFO(wxPropertyGrid
)) );
1530 propGrid
->HandleCustomEditorEvent(evt
);
1533 wxPGWindowList
wxPGCheckBoxEditor::CreateControls( wxPropertyGrid
* propGrid
,
1534 wxPGProperty
* property
,
1536 const wxSize
& size
) const
1539 pt
.x
-= wxPG_XBEFOREWIDGET
;
1541 sz
.x
= propGrid
->GetFontHeight() + (wxPG_XBEFOREWIDGET
*2) + 4;
1543 wxSimpleCheckBox
* cb
= new wxSimpleCheckBox(propGrid
->GetPanel(),
1544 wxPG_SUBID1
, pt
, sz
);
1546 cb
->SetBackgroundColour(wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOW
));
1548 UpdateControl(property
, cb
);
1550 if ( !property
->IsValueUnspecified() )
1552 // If mouse cursor was on the item, toggle the value now.
1553 if ( propGrid
->GetInternalFlags() & wxPG_FL_ACTIVATION_BY_CLICK
)
1555 wxPoint pt
= cb
->ScreenToClient(::wxGetMousePosition());
1556 if ( pt
.x
<= (wxPG_XBEFORETEXT
-2+cb
->m_boxHeight
) )
1558 if ( cb
->m_state
& wxSCB_STATE_CHECKED
)
1559 cb
->m_state
&= ~wxSCB_STATE_CHECKED
;
1561 cb
->m_state
|= wxSCB_STATE_CHECKED
;
1563 // Makes sure wxPG_EVT_CHANGING etc. is sent for this initial
1565 propGrid
->ChangePropertyValue(property
,
1566 wxPGVariant_Bool(cb
->m_state
));
1571 propGrid
->SetInternalFlag( wxPG_FL_FIXED_WIDTH_EDITOR
);
1576 void wxPGCheckBoxEditor::DrawValue( wxDC
& dc
, const wxRect
& rect
,
1577 wxPGProperty
* property
,
1578 const wxString
& WXUNUSED(text
) ) const
1580 int state
= wxSCB_STATE_UNCHECKED
;
1581 wxColour rectCol
= dc
.GetTextForeground();
1583 if ( !property
->IsValueUnspecified() )
1585 state
= property
->GetChoiceSelection();
1586 if ( dc
.GetFont().GetWeight() == wxBOLD
)
1587 state
|= wxSCB_STATE_BOLD
;
1591 state
|= wxSCB_STATE_UNSPECIFIED
;
1594 DrawSimpleCheckBox(dc
, rect
, dc
.GetCharHeight(), state
, rectCol
);
1597 void wxPGCheckBoxEditor::UpdateControl( wxPGProperty
* property
,
1598 wxWindow
* ctrl
) const
1600 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*) ctrl
;
1603 if ( !property
->IsValueUnspecified() )
1604 cb
->m_state
= property
->GetChoiceSelection();
1606 cb
->m_state
= wxSCB_STATE_UNSPECIFIED
;
1608 wxPropertyGrid
* propGrid
= property
->GetGrid();
1609 cb
->m_boxHeight
= propGrid
->GetFontHeight();
1614 bool wxPGCheckBoxEditor::OnEvent( wxPropertyGrid
* WXUNUSED(propGrid
), wxPGProperty
* WXUNUSED(property
),
1615 wxWindow
* WXUNUSED(ctrl
), wxEvent
& event
) const
1617 if ( event
.GetEventType() == wxEVT_COMMAND_CHECKBOX_CLICKED
)
1625 bool wxPGCheckBoxEditor::GetValueFromControl( wxVariant
& variant
, wxPGProperty
* property
, wxWindow
* ctrl
) const
1627 wxSimpleCheckBox
* cb
= (wxSimpleCheckBox
*)ctrl
;
1629 int index
= cb
->m_state
;
1631 if ( index
!= property
->GetChoiceSelection() ||
1632 // Changing unspecified always causes event (returning
1633 // true here should be enough to trigger it).
1634 property
->IsValueUnspecified()
1637 return property
->IntToValue(variant
, index
, 0);
1643 void wxPGCheckBoxEditor::SetControlIntValue( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
, int value
) const
1645 if ( value
!= 0 ) value
= 1;
1646 ((wxSimpleCheckBox
*)ctrl
)->m_state
= value
;
1651 void wxPGCheckBoxEditor::SetValueToUnspecified( wxPGProperty
* WXUNUSED(property
), wxWindow
* ctrl
) const
1653 ((wxSimpleCheckBox
*)ctrl
)->m_state
= wxSCB_STATE_UNSPECIFIED
;
1658 wxPGCheckBoxEditor::~wxPGCheckBoxEditor() { }
1661 #endif // wxPG_INCLUDE_CHECKBOX
1663 // -----------------------------------------------------------------------
1665 wxWindow
* wxPropertyGrid::GetEditorControl() const
1667 wxWindow
* ctrl
= m_wndEditor
;
1675 // -----------------------------------------------------------------------
1677 void wxPropertyGrid::CorrectEditorWidgetSizeX()
1680 int newSplitterx
= m_pState
->DoGetSplitterPosition(m_selColumn
-1);
1681 int newWidth
= newSplitterx
+ m_pState
->m_colWidths
[m_selColumn
];
1685 // if width change occurred, move secondary wnd by that amount
1686 wxRect r
= m_wndEditor2
->GetRect();
1688 r
.x
= newWidth
- secWid
;
1690 m_wndEditor2
->SetSize( r
);
1692 // if primary is textctrl, then we have to add some extra space
1696 if ( m_wndEditor
&& m_wndEditor
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
1698 secWid
+= wxPG_TEXTCTRL_AND_BUTTON_SPACING
;
1703 wxRect r
= m_wndEditor
->GetRect();
1705 r
.x
= newSplitterx
+m_ctrlXAdjust
;
1707 if ( !(m_iFlags
& wxPG_FL_FIXED_WIDTH_EDITOR
) )
1708 r
.width
= newWidth
- r
.x
- secWid
;
1710 m_wndEditor
->SetSize(r
);
1714 m_wndEditor2
->Refresh();
1717 // -----------------------------------------------------------------------
1719 void wxPropertyGrid::CorrectEditorWidgetPosY()
1721 if ( GetSelection() && (m_wndEditor
|| m_wndEditor2
) )
1723 wxRect r
= GetEditorWidgetRect(GetSelection(), m_selColumn
);
1727 wxPoint pos
= m_wndEditor
->GetPosition();
1729 // Calculate y offset
1730 int offset
= pos
.y
% m_lineHeight
;
1732 m_wndEditor
->Move(pos
.x
, r
.y
+ offset
);
1737 wxPoint pos
= m_wndEditor2
->GetPosition();
1739 m_wndEditor2
->Move(pos
.x
, r
.y
);
1744 // -----------------------------------------------------------------------
1746 // Fixes position of wxTextCtrl-like control (wxSpinCtrl usually
1747 // fits into that category as well).
1748 void wxPropertyGrid::FixPosForTextCtrl( wxWindow
* ctrl
,
1749 unsigned int WXUNUSED(forColumn
),
1750 const wxPoint
& offset
)
1752 // Center the control vertically
1753 wxRect finalPos
= ctrl
->GetRect();
1754 int y_adj
= (m_lineHeight
- finalPos
.height
)/2 + wxPG_TEXTCTRLYADJUST
;
1756 // Prevent over-sized control
1757 int sz_dec
= (y_adj
+ finalPos
.height
) - m_lineHeight
;
1758 if ( sz_dec
< 0 ) sz_dec
= 0;
1760 finalPos
.y
+= y_adj
;
1761 finalPos
.height
-= (y_adj
+sz_dec
);
1763 #ifndef wxPG_TEXTCTRLXADJUST
1764 int textCtrlXAdjust
= wxPG_XBEFORETEXT
- 1;
1766 wxTextCtrl
* tc
= static_cast<wxTextCtrl
*>(ctrl
);
1769 int textCtrlXAdjust
= wxPG_TEXTCTRLXADJUST
;
1772 finalPos
.x
+= textCtrlXAdjust
;
1773 finalPos
.width
-= textCtrlXAdjust
;
1775 finalPos
.x
+= offset
.x
;
1776 finalPos
.y
+= offset
.y
;
1778 ctrl
->SetSize(finalPos
);
1781 // -----------------------------------------------------------------------
1783 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrl( const wxPoint
& pos
,
1785 const wxString
& value
,
1786 wxWindow
* secondary
,
1789 unsigned int forColumn
)
1791 wxWindowID id
= wxPG_SUBID1
;
1792 wxPGProperty
* prop
= GetSelection();
1795 int tcFlags
= wxTE_PROCESS_ENTER
| extraStyle
;
1797 if ( prop
->HasFlag(wxPG_PROP_READONLY
) && forColumn
== 1 )
1798 tcFlags
|= wxTE_READONLY
;
1800 wxPoint
p(pos
.x
,pos
.y
);
1801 wxSize
s(sz
.x
,sz
.y
);
1803 // Need to reduce width of text control on Mac
1804 #if defined(__WXMAC__)
1808 // For label editors, trim the size to allow better splitter grabbing
1809 if ( forColumn
!= 1 )
1812 // Take button into acccount
1815 s
.x
-= (secondary
->GetSize().x
+ wxPG_TEXTCTRL_AND_BUTTON_SPACING
);
1816 m_iFlags
&= ~(wxPG_FL_PRIMARY_FILLS_ENTIRE
);
1819 // If the height is significantly higher, then use border, and fill the rect exactly.
1820 bool hasSpecialSize
= false;
1822 if ( (sz
.y
- m_lineHeight
) > 5 )
1823 hasSpecialSize
= true;
1825 wxWindow
* ctrlParent
= GetPanel();
1827 if ( !hasSpecialSize
)
1828 tcFlags
|= wxBORDER_NONE
;
1830 wxTextCtrl
* tc
= new wxTextCtrl();
1832 #if defined(__WXMSW__)
1835 SetupTextCtrlValue(value
);
1836 tc
->Create(ctrlParent
,id
,value
, p
, s
,tcFlags
);
1838 #if defined(__WXMSW__)
1839 // On Windows, we need to override read-only text ctrl's background
1840 // colour to white. One problem with native 'grey' background is that
1841 // tc->GetBackgroundColour() doesn't seem to return correct value
1843 if ( tcFlags
& wxTE_READONLY
)
1845 wxVisualAttributes vattrs
= tc
->GetDefaultAttributes();
1846 tc
->SetBackgroundColour(vattrs
.colBg
);
1850 // Center the control vertically
1851 if ( !hasSpecialSize
)
1852 FixPosForTextCtrl(tc
, forColumn
);
1854 if ( forColumn
!= 1 )
1856 tc
->SetBackgroundColour(m_colSelBack
);
1857 tc
->SetForegroundColour(m_colSelFore
);
1866 // Set maximum length
1868 tc
->SetMaxLength( maxLen
);
1870 wxVariant attrVal
= prop
->GetAttribute(wxPG_ATTR_AUTOCOMPLETE
);
1871 if ( !attrVal
.IsNull() )
1873 wxASSERT(attrVal
.GetType() == wxS("arrstring"));
1874 tc
->AutoComplete(attrVal
.GetArrayString());
1880 // -----------------------------------------------------------------------
1882 wxWindow
* wxPropertyGrid::GenerateEditorButton( const wxPoint
& pos
, const wxSize
& sz
)
1884 wxWindowID id
= wxPG_SUBID2
;
1885 wxPGProperty
* selected
= GetSelection();
1889 // Decorations are chunky on Mac, and we can't make the button square, so
1890 // do things a bit differently on this platform.
1892 wxPoint
p(pos
.x
+sz
.x
,
1893 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1896 wxButton
* but
= new wxButton();
1897 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1899 // Now that we know the size, move to the correct position
1900 p
.x
= pos
.x
+ sz
.x
- but
->GetSize().x
- 2;
1904 wxSize
s(sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2),
1905 sz
.y
-(wxPG_BUTTON_SIZEDEC
*2)+(wxPG_NAT_BUTTON_BORDER_Y
*2));
1907 // Reduce button width to lineheight
1908 if ( s
.x
> m_lineHeight
)
1912 // On wxGTK, take fixed button margins into account
1917 wxPoint
p(pos
.x
+sz
.x
-s
.x
,
1918 pos
.y
+wxPG_BUTTON_SIZEDEC
-wxPG_NAT_BUTTON_BORDER_Y
);
1920 wxButton
* but
= new wxButton();
1924 but
->Create(GetPanel(),id
,wxS("..."),p
,s
,wxWANTS_CHARS
);
1927 wxFont font
= GetFont();
1928 font
.SetPointSize(font
.GetPointSize()-2);
1931 but
->SetFont(GetFont());
1935 if ( selected
->HasFlag(wxPG_PROP_READONLY
) )
1941 // -----------------------------------------------------------------------
1943 wxWindow
* wxPropertyGrid::GenerateEditorTextCtrlAndButton( const wxPoint
& pos
,
1945 wxWindow
** psecondary
,
1947 wxPGProperty
* property
)
1949 wxButton
* but
= (wxButton
*)GenerateEditorButton(pos
,sz
);
1950 *psecondary
= (wxWindow
*)but
;
1952 if ( limitedEditing
)
1955 // There is button Show in GenerateEditorTextCtrl as well
1963 if ( !property
->IsValueUnspecified() )
1964 text
= property
->GetValueAsString(property
->HasFlag(wxPG_PROP_READONLY
)?0:wxPG_EDITABLE_VALUE
);
1966 return GenerateEditorTextCtrl(pos
,sz
,text
,but
,property
->m_maxLen
);
1969 // -----------------------------------------------------------------------
1971 void wxPropertyGrid::SetEditorAppearance( const wxPGCell
& cell
,
1974 wxPGProperty
* property
= GetSelection();
1977 wxWindow
* ctrl
= GetEditorControl();
1981 property
->GetEditorClass()->SetControlAppearance( this,
1988 m_editorAppearance
= cell
;
1991 // -----------------------------------------------------------------------
1993 wxTextCtrl
* wxPropertyGrid::GetEditorTextCtrl() const
1995 wxWindow
* wnd
= GetEditorControl();
2000 if ( wnd
->IsKindOf(CLASSINFO(wxTextCtrl
)) )
2001 return wxStaticCast(wnd
, wxTextCtrl
);
2003 if ( wnd
->IsKindOf(CLASSINFO(wxOwnerDrawnComboBox
)) )
2005 wxOwnerDrawnComboBox
* cb
= wxStaticCast(wnd
, wxOwnerDrawnComboBox
);
2006 return cb
->GetTextCtrl();
2012 // -----------------------------------------------------------------------
2014 wxPGEditor
* wxPropertyGridInterface::GetEditorByName( const wxString
& editorName
)
2016 wxPGHashMapS2P::const_iterator it
;
2018 it
= wxPGGlobalVars
->m_mapEditorClasses
.find(editorName
);
2019 if ( it
== wxPGGlobalVars
->m_mapEditorClasses
.end() )
2021 return (wxPGEditor
*) it
->second
;
2024 // -----------------------------------------------------------------------
2025 // wxPGEditorDialogAdapter
2026 // -----------------------------------------------------------------------
2028 IMPLEMENT_ABSTRACT_CLASS(wxPGEditorDialogAdapter
, wxObject
)
2030 bool wxPGEditorDialogAdapter::ShowDialog( wxPropertyGrid
* propGrid
, wxPGProperty
* property
)
2032 if ( !propGrid
->EditorValidate() )
2035 bool res
= DoShowDialog( propGrid
, property
);
2039 propGrid
->ValueChangeInEvent( m_value
);
2046 // -----------------------------------------------------------------------
2048 // -----------------------------------------------------------------------
2050 wxPGMultiButton::wxPGMultiButton( wxPropertyGrid
* pg
, const wxSize
& sz
)
2051 : wxWindow( pg
->GetPanel(), wxPG_SUBID2
, wxPoint(-100,-100), wxSize(0, sz
.y
) ),
2052 m_fullEditorSize(sz
), m_buttonsWidth(0)
2054 SetBackgroundColour(pg
->GetCellBackgroundColour());
2057 void wxPGMultiButton::Finalize( wxPropertyGrid
* WXUNUSED(propGrid
),
2058 const wxPoint
& pos
)
2060 Move( pos
.x
+ m_fullEditorSize
.x
- m_buttonsWidth
, pos
.y
);
2063 int wxPGMultiButton::GenId( int id
) const
2067 if ( m_buttons
.size() )
2068 id
= GetButton(m_buttons
.size()-1)->GetId() + 1;
2076 void wxPGMultiButton::Add( const wxBitmap
& bitmap
, int id
)
2079 wxSize sz
= GetSize();
2080 wxButton
* button
= new wxBitmapButton( this, id
, bitmap
,
2082 wxSize(sz
.y
, sz
.y
) );
2083 DoAddButton( button
, sz
);
2087 void wxPGMultiButton::Add( const wxString
& label
, int id
)
2090 wxSize sz
= GetSize();
2091 wxButton
* button
= new wxButton( this, id
, label
, wxPoint(sz
.x
, 0),
2092 wxSize(sz
.y
, sz
.y
) );
2093 DoAddButton( button
, sz
);
2096 void wxPGMultiButton::DoAddButton( wxWindow
* button
,
2099 m_buttons
.push_back(button
);
2100 int bw
= button
->GetSize().x
;
2101 SetSize(wxSize(sz
.x
+bw
,sz
.y
));
2102 m_buttonsWidth
+= bw
;
2105 // -----------------------------------------------------------------------
2107 #endif // wxUSE_PROPGRID