From 2bd82d72f594f824954f773d39c39942a7153a89 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sat, 14 May 2011 14:17:52 +0000 Subject: [PATCH] Cancel dragging in wxAuiNotebook on capture loss. Don't leave the display and internal variables in inconsistent state when the mouse capture is lost while a notebook page is being dragged (as can happen if Alt-Tab is pressed under Windows, for example). Closes #9976. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67737 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/aui/auibook.h | 1 + src/aui/auibook.cpp | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/include/wx/aui/auibook.h b/include/wx/aui/auibook.h index 874cbcddf5..c10cd632f3 100644 --- a/include/wx/aui/auibook.h +++ b/include/wx/aui/auibook.h @@ -627,6 +627,7 @@ protected: void OnTabBeginDrag(wxAuiNotebookEvent& evt); void OnTabDragMotion(wxAuiNotebookEvent& evt); void OnTabEndDrag(wxAuiNotebookEvent& evt); + void OnTabCancelDrag(wxAuiNotebookEvent& evt); void OnTabButton(wxAuiNotebookEvent& evt); void OnTabMiddleDown(wxAuiNotebookEvent& evt); void OnTabMiddleUp(wxAuiNotebookEvent& evt); diff --git a/src/aui/auibook.cpp b/src/aui/auibook.cpp index d308cdd4dd..961c45756b 100644 --- a/src/aui/auibook.cpp +++ b/src/aui/auibook.cpp @@ -48,6 +48,7 @@ wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_PAGE_CHANGED, wxAuiNotebookEvent); wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BUTTON, wxAuiNotebookEvent); wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BEGIN_DRAG, wxAuiNotebookEvent); wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, wxAuiNotebookEvent); +wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG, wxAuiNotebookEvent); wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, wxAuiNotebookEvent); wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_ALLOW_DND, wxAuiNotebookEvent); wxDEFINE_EVENT(wxEVT_COMMAND_AUINOTEBOOK_BG_DCLICK, wxAuiNotebookEvent); @@ -2306,6 +2307,16 @@ void wxAuiTabCtrl::OnLeftDown(wxMouseEvent& evt) void wxAuiTabCtrl::OnCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event)) { + if (m_is_dragging) + { + m_is_dragging = false; + + wxAuiNotebookEvent evt(wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG, m_windowId); + evt.SetSelection(GetIdxFromWindow(m_click_tab)); + evt.SetOldSelection(evt.GetSelection()); + evt.SetEventObject(this); + GetEventHandler()->ProcessEvent(evt); + } } void wxAuiTabCtrl::OnLeftUp(wxMouseEvent& evt) @@ -2824,6 +2835,9 @@ BEGIN_EVENT_TABLE(wxAuiNotebook, wxControl) EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, wxEVT_COMMAND_AUINOTEBOOK_END_DRAG, wxAuiNotebook::OnTabEndDrag) + EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, + wxEVT_COMMAND_AUINOTEBOOK_CANCEL_DRAG, + wxAuiNotebook::OnTabCancelDrag) EVT_AUI_RANGE(wxAuiBaseTabCtrlId, wxAuiBaseTabCtrlId+500, wxEVT_COMMAND_AUINOTEBOOK_DRAG_MOTION, wxAuiNotebook::OnTabDragMotion) @@ -4114,6 +4128,18 @@ void wxAuiNotebook::OnTabEndDrag(wxAuiNotebookEvent& evt) +void wxAuiNotebook::OnTabCancelDrag(wxAuiNotebookEvent& command_evt) +{ + wxAuiNotebookEvent& evt = (wxAuiNotebookEvent&)command_evt; + + m_mgr.HideHint(); + + wxAuiTabCtrl* src_tabs = (wxAuiTabCtrl*)evt.GetEventObject(); + wxCHECK_RET( src_tabs, _T("no source object?") ); + + src_tabs->SetCursor(wxCursor(wxCURSOR_ARROW)); +} + wxAuiTabCtrl* wxAuiNotebook::GetTabCtrlFromPoint(const wxPoint& pt) { // if we've just removed the last tab from the source