From: Vadim Zeitlin Date: Sat, 15 Sep 2007 01:09:01 +0000 (+0000) Subject: get rid of the built-in drop target in rich text controls before setting the user... X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/20a0e99964951da1c54abf11f6dd7cd2925b8b0e get rid of the built-in drop target in rich text controls before setting the user-defined one as otherwise it fails git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@48704 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/msw/textctrl.h b/include/wx/msw/textctrl.h index 09dc91bd0d..a56a3ff7d6 100644 --- a/include/wx/msw/textctrl.h +++ b/include/wx/msw/textctrl.h @@ -139,6 +139,10 @@ public: // Implementation from now on // -------------------------- + +#if wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT + virtual void SetDropTarget(wxDropTarget *dropTarget); +#endif // wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT virtual void SetWindowStyleFlag(long style); diff --git a/src/msw/textctrl.cpp b/src/msw/textctrl.cpp index 97c0559a8b..c40ef670da 100644 --- a/src/msw/textctrl.cpp +++ b/src/msw/textctrl.cpp @@ -77,6 +77,15 @@ #include "wx/msw/missing.h" +#if wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT + +// dummy value used for m_dropTarget, different from any valid pointer value +// (which are all even under Windows) and NULL +static wxDropTarget * + wxRICHTEXT_DEFAULT_DROPTARGET = wx_reinterpret_cast(wxDropTarget *, 1); + +#endif // wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT + // ---------------------------------------------------------------------------- // private classes // ---------------------------------------------------------------------------- @@ -308,6 +317,20 @@ bool wxTextCtrl::Create(wxWindow *parent, if ( !MSWCreateText(value, pos, size) ) return false; +#if wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT + if ( IsRich() ) + { + // rich text controls have a default associated drop target which + // allows them to receive (rich) text dropped on them, which is nice, + // but prevents us from associating a user-defined drop target with + // them as we need to unregister the old one first + // + // to make it work, we set m_dropTarget to this special value initially + // and check for it in our SetDropTarget() + m_dropTarget = wxRICHTEXT_DEFAULT_DROPTARGET; + } +#endif // wxUSE_DRAG_AND_DROP && wxUSE_RICHEDIT + return true; } @@ -2405,6 +2428,22 @@ bool wxTextCtrl::MSWOnNotify(int idCtrl, WXLPARAM lParam, WXLPARAM *result) return wxTextCtrlBase::MSWOnNotify(idCtrl, lParam, result); } +#if wxUSE_DRAG_AND_DROP + +void wxTextCtrl::SetDropTarget(wxDropTarget *dropTarget) +{ + if ( m_dropTarget == wxRICHTEXT_DEFAULT_DROPTARGET ) + { + // get rid of the built-in drop target + ::RevokeDragDrop(GetHwnd()); + m_dropTarget = NULL; + } + + wxTextCtrlBase::SetDropTarget(dropTarget); +} + +#endif // wxUSE_DRAG_AND_DROP + // ---------------------------------------------------------------------------- // colour setting for the rich edit controls // ----------------------------------------------------------------------------