Add wxAuiTabCtrl::DoEndDragging()
No real changes, just refactor the code to reset all drag-related variables in a single function instead of doing it manually in several places. As this function also resets m_clickTab, which could previosuly remain a dangling pointer, change the code to get its value before calling it.
This commit is contained in:
parent
0fd15e405f
commit
a0f7980295
2 changed files with 24 additions and 12 deletions
|
|
@ -239,11 +239,16 @@ protected:
|
|||
wxPoint m_clickPt = wxDefaultPosition;
|
||||
wxWindow* m_clickTab = nullptr;
|
||||
bool m_isDragging = false;
|
||||
|
||||
wxAuiTabContainerButton* m_hoverButton = nullptr;
|
||||
wxAuiTabContainerButton* m_pressedButton = nullptr;
|
||||
|
||||
void SetHoverTab(wxWindow* wnd);
|
||||
|
||||
private:
|
||||
// Reset dragging-related fields above to their initial values.
|
||||
void DoEndDragging();
|
||||
|
||||
#ifndef SWIG
|
||||
wxDECLARE_CLASS(wxAuiTabCtrl);
|
||||
wxDECLARE_EVENT_TABLE();
|
||||
|
|
|
|||
|
|
@ -1019,6 +1019,13 @@ wxAuiTabCtrl::~wxAuiTabCtrl()
|
|||
{
|
||||
}
|
||||
|
||||
void wxAuiTabCtrl::DoEndDragging()
|
||||
{
|
||||
m_clickPt = wxDefaultPosition;
|
||||
m_isDragging = false;
|
||||
m_clickTab = nullptr;
|
||||
}
|
||||
|
||||
void wxAuiTabCtrl::OnPaint(wxPaintEvent&)
|
||||
{
|
||||
wxPaintDC dc(this);
|
||||
|
|
@ -1053,9 +1060,9 @@ void wxAuiTabCtrl::OnSize(wxSizeEvent& evt)
|
|||
void wxAuiTabCtrl::OnLeftDown(wxMouseEvent& evt)
|
||||
{
|
||||
CaptureMouse();
|
||||
m_clickPt = wxDefaultPosition;
|
||||
m_isDragging = false;
|
||||
m_clickTab = nullptr;
|
||||
|
||||
// Reset any previous values first.
|
||||
DoEndDragging();
|
||||
m_pressedButton = nullptr;
|
||||
|
||||
|
||||
|
|
@ -1095,11 +1102,12 @@ void wxAuiTabCtrl::OnCaptureLost(wxMouseCaptureLostEvent& WXUNUSED(event))
|
|||
{
|
||||
if (m_isDragging)
|
||||
{
|
||||
m_clickPt = wxDefaultPosition;
|
||||
m_isDragging = false;
|
||||
const auto clickTab = m_clickTab;
|
||||
|
||||
DoEndDragging();
|
||||
|
||||
wxAuiNotebookEvent evt(wxEVT_AUINOTEBOOK_CANCEL_DRAG, m_windowId);
|
||||
evt.SetSelection(GetIdxFromWindow(m_clickTab));
|
||||
evt.SetSelection(GetIdxFromWindow(clickTab));
|
||||
evt.SetOldSelection(evt.GetSelection());
|
||||
evt.SetEventObject(this);
|
||||
GetEventHandler()->ProcessEvent(evt);
|
||||
|
|
@ -1113,11 +1121,12 @@ void wxAuiTabCtrl::OnLeftUp(wxMouseEvent& evt)
|
|||
|
||||
if (m_isDragging)
|
||||
{
|
||||
m_clickPt = wxDefaultPosition;
|
||||
m_isDragging = false;
|
||||
const auto clickTab = m_clickTab;
|
||||
|
||||
DoEndDragging();
|
||||
|
||||
wxAuiNotebookEvent e(wxEVT_AUINOTEBOOK_END_DRAG, m_windowId);
|
||||
e.SetSelection(GetIdxFromWindow(m_clickTab));
|
||||
e.SetSelection(GetIdxFromWindow(clickTab));
|
||||
e.SetOldSelection(e.GetSelection());
|
||||
e.SetEventObject(this);
|
||||
GetEventHandler()->ProcessEvent(e);
|
||||
|
|
@ -1154,9 +1163,7 @@ void wxAuiTabCtrl::OnLeftUp(wxMouseEvent& evt)
|
|||
m_pressedButton = nullptr;
|
||||
}
|
||||
|
||||
m_clickPt = wxDefaultPosition;
|
||||
m_isDragging = false;
|
||||
m_clickTab = nullptr;
|
||||
DoEndDragging();
|
||||
}
|
||||
|
||||
void wxAuiTabCtrl::OnMiddleUp(wxMouseEvent& evt)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue