1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-12-22 08:31:14 +01:00

Changed lifetime management of UIHandle objects, no singletons...

... Rather, construct them during hit tests (also capturing more state sooner
rather than at Click time, and adding some accessors for later use)

This also fixes bug 1677 by other means and avoids similar problems.

A cell may be implemented to re-use a previously hit handle object, not yet
clicked, in a later hit test, by remembering a weak pointer, but TrackPanel
holds the strong pointers that determine when the object is destroyed.

And the objects will surely be destroyed after drag-release, or ESC key.

For now they are also destroyed whenever not dragging, and hit-testing is
re-invoked; that will be changed later, so that the re-use mentioned above
becomes effective, but still they will be destroyed when the pointer moves
from one cell to another.
This commit is contained in:
Paul Licameli
2017-07-05 16:45:55 -04:00
parent d2fbca83b2
commit 2c1a16f593
75 changed files with 891 additions and 678 deletions

View File

@@ -17,21 +17,15 @@ Paul Licameli split from TrackPanel.cpp
#include "../../Track.h"
#include "../../TrackPanel.h"
MinimizeButtonHandle::MinimizeButtonHandle()
: ButtonHandle{ TrackPanel::IsMinimizing }
{
}
MinimizeButtonHandle::MinimizeButtonHandle
( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
: ButtonHandle{ pTrack, rect, TrackPanel::IsMinimizing }
{}
MinimizeButtonHandle::~MinimizeButtonHandle()
{
}
MinimizeButtonHandle &MinimizeButtonHandle::Instance()
{
static MinimizeButtonHandle instance;
return instance;
}
UIHandle::Result MinimizeButtonHandle::CommitChanges
(const wxMouseEvent &, AudacityProject *pProject, wxWindow*)
{
@@ -55,16 +49,19 @@ UIHandle::Result MinimizeButtonHandle::CommitChanges
}
HitTestResult MinimizeButtonHandle::HitTest
(const wxMouseState &state, const wxRect &rect)
(std::weak_ptr<MinimizeButtonHandle> &holder,
const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
{
wxRect buttonRect;
TrackInfo::GetMinimizeRect(rect, buttonRect);
if (buttonRect.Contains(state.m_x, state.m_y)) {
Instance().mRect = buttonRect;
auto pTrack = static_cast<CommonTrackPanelCell*>(pCell)->FindTrack();
auto result = std::make_shared<MinimizeButtonHandle>( pTrack, buttonRect );
result = AssignUIHandlePtr(holder, result);
return {
HitPreview(),
&Instance()
result
};
}
else
@@ -73,21 +70,15 @@ HitTestResult MinimizeButtonHandle::HitTest
////////////////////////////////////////////////////////////////////////////////
CloseButtonHandle::CloseButtonHandle()
: ButtonHandle{ TrackPanel::IsClosing }
{
}
CloseButtonHandle::CloseButtonHandle
( const std::shared_ptr<Track> &pTrack, const wxRect &rect )
: ButtonHandle{ pTrack, rect, TrackPanel::IsClosing }
{}
CloseButtonHandle::~CloseButtonHandle()
{
}
CloseButtonHandle &CloseButtonHandle::Instance()
{
static CloseButtonHandle instance;
return instance;
}
UIHandle::Result CloseButtonHandle::CommitChanges
(const wxMouseEvent &, AudacityProject *pProject, wxWindow*)
{
@@ -112,16 +103,19 @@ UIHandle::Result CloseButtonHandle::CommitChanges
}
HitTestResult CloseButtonHandle::HitTest
(const wxMouseState &state, const wxRect &rect)
(std::weak_ptr<CloseButtonHandle> &holder,
const wxMouseState &state, const wxRect &rect, TrackPanelCell *pCell)
{
wxRect buttonRect;
TrackInfo::GetCloseBoxRect(rect, buttonRect);
if (buttonRect.Contains(state.m_x, state.m_y)) {
Instance().mRect = buttonRect;
auto pTrack = static_cast<CommonTrackPanelCell*>(pCell)->FindTrack();
auto result = std::make_shared<CloseButtonHandle>( pTrack, buttonRect );
result = AssignUIHandlePtr(holder, result);
return {
HitPreview(),
&Instance()
result
};
}
else
@@ -130,21 +124,17 @@ HitTestResult CloseButtonHandle::HitTest
////////////////////////////////////////////////////////////////////////////////
MenuButtonHandle::MenuButtonHandle()
: ButtonHandle{ TrackPanel::IsPopping }
{
}
MenuButtonHandle::MenuButtonHandle
( const std::shared_ptr<TrackPanelCell> &pCell,
const std::shared_ptr<Track> &pTrack, const wxRect &rect )
: ButtonHandle{ pTrack, rect, TrackPanel::IsPopping }
, mpCell{ pCell }
{}
MenuButtonHandle::~MenuButtonHandle()
{
}
MenuButtonHandle &MenuButtonHandle::Instance()
{
static MenuButtonHandle instance;
return instance;
}
UIHandle::Result MenuButtonHandle::CommitChanges
(const wxMouseEvent &, AudacityProject *, wxWindow *pParent)
{
@@ -155,18 +145,20 @@ UIHandle::Result MenuButtonHandle::CommitChanges
}
HitTestResult MenuButtonHandle::HitTest
(const wxMouseState &state, const wxRect &rect,
(std::weak_ptr<MenuButtonHandle> &holder,
const wxMouseState &state, const wxRect &rect,
const std::shared_ptr<TrackPanelCell> &pCell)
{
wxRect buttonRect;
TrackInfo::GetTitleBarRect(rect, buttonRect);
if (buttonRect.Contains(state.m_x, state.m_y)) {
Instance().mpCell = pCell;
Instance().mRect = buttonRect;
auto pTrack = static_cast<CommonTrackPanelCell*>(pCell.get())->FindTrack();
auto result = std::make_shared<MenuButtonHandle>( pCell, pTrack, buttonRect );
result = AssignUIHandlePtr(holder, result);
return {
HitPreview(),
&Instance()
result
};
}
else