mirror of
https://github.com/cookiengineer/audacity
synced 2025-09-18 09:00:52 +02:00
TrackPanel::mpClickedTrack is a safe weak_ptr
This commit is contained in:
parent
6684c7b9b0
commit
e424f8e54e
@ -765,16 +765,11 @@ void TrackPanel::CancelDragging()
|
|||||||
{
|
{
|
||||||
if (mUIHandle) {
|
if (mUIHandle) {
|
||||||
UIHandle::Result refreshResult = mUIHandle->Cancel(GetProject());
|
UIHandle::Result refreshResult = mUIHandle->Cancel(GetProject());
|
||||||
{
|
auto pTrack = GetTracks()->Lock(mpClickedTrack);
|
||||||
// TODO: avoid dangling pointers to mpClickedTrack
|
if (pTrack)
|
||||||
// when the undo stack management of the typical Cancel override
|
ProcessUIHandleResult(
|
||||||
// causes it to relocate. That is implement some means to
|
this, mRuler, pTrack.get(), NULL, refreshResult);
|
||||||
// re-fetch the track according to its position in the list.
|
mpClickedTrack.reset();
|
||||||
// (Or should all Tracks be managed always by std::shared_ptr?)
|
|
||||||
mpClickedTrack = NULL;
|
|
||||||
}
|
|
||||||
ProcessUIHandleResult(this, mRuler, mpClickedTrack, NULL, refreshResult);
|
|
||||||
mpClickedTrack = NULL;
|
|
||||||
mUIHandle = NULL;
|
mUIHandle = NULL;
|
||||||
Uncapture();
|
Uncapture();
|
||||||
}
|
}
|
||||||
@ -1458,16 +1453,17 @@ try
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (mUIHandle) {
|
if (mUIHandle) {
|
||||||
|
auto pClickedTrack = GetTracks()->Lock(mpClickedTrack);
|
||||||
if (event.Dragging()) {
|
if (event.Dragging()) {
|
||||||
// UIHANDLE DRAG
|
// UIHANDLE DRAG
|
||||||
const UIHandle::Result refreshResult =
|
const UIHandle::Result refreshResult =
|
||||||
mUIHandle->Drag( tpmEvent, GetProject() );
|
mUIHandle->Drag( tpmEvent, GetProject() );
|
||||||
ProcessUIHandleResult
|
ProcessUIHandleResult
|
||||||
(this, mRuler, mpClickedTrack, pTrack.get(), refreshResult);
|
(this, mRuler, pClickedTrack.get(), pTrack.get(), refreshResult);
|
||||||
if (refreshResult & RefreshCode::Cancelled) {
|
if (refreshResult & RefreshCode::Cancelled) {
|
||||||
// Drag decided to abort itself
|
// Drag decided to abort itself
|
||||||
mUIHandle = NULL;
|
mUIHandle = NULL;
|
||||||
mpClickedTrack = NULL;
|
mpClickedTrack.reset();
|
||||||
Uncapture( &event );
|
Uncapture( &event );
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -1483,8 +1479,8 @@ try
|
|||||||
UIHandle::Result refreshResult =
|
UIHandle::Result refreshResult =
|
||||||
uiHandle->Release( tpmEvent, GetProject(), this );
|
uiHandle->Release( tpmEvent, GetProject(), this );
|
||||||
ProcessUIHandleResult
|
ProcessUIHandleResult
|
||||||
(this, mRuler, mpClickedTrack, pTrack.get(), refreshResult);
|
(this, mRuler, pClickedTrack.get(), pTrack.get(), refreshResult);
|
||||||
mpClickedTrack = NULL;
|
mpClickedTrack.reset();
|
||||||
// will also Uncapture() below
|
// will also Uncapture() below
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1544,7 +1540,7 @@ void TrackPanel::HandleClick( const TrackPanelMouseEvent &tpmEvent )
|
|||||||
if (refreshResult & RefreshCode::Cancelled)
|
if (refreshResult & RefreshCode::Cancelled)
|
||||||
mUIHandle = NULL;
|
mUIHandle = NULL;
|
||||||
else
|
else
|
||||||
mpClickedTrack = pTrack.get();
|
mpClickedTrack = pTrack;
|
||||||
ProcessUIHandleResult
|
ProcessUIHandleResult
|
||||||
(this, mRuler, pTrack.get(), pTrack.get(), refreshResult);
|
(this, mRuler, pTrack.get(), pTrack.get(), refreshResult);
|
||||||
HandleCursor( tpmEvent );
|
HandleCursor( tpmEvent );
|
||||||
@ -2181,7 +2177,8 @@ void TrackPanel::DrawOutside(Track * t, wxDC * dc, const wxRect & rec)
|
|||||||
// when TrackPanelCell gets a virtual function into which we move this
|
// when TrackPanelCell gets a virtual function into which we move this
|
||||||
// drawing code.
|
// drawing code.
|
||||||
MouseCaptureEnum(TrackControls::gCaptureState);
|
MouseCaptureEnum(TrackControls::gCaptureState);
|
||||||
const bool captured = (t == mpClickedTrack);
|
auto pClickedTrack = GetTracks()->Lock(mpClickedTrack);
|
||||||
|
const bool captured = (t == pClickedTrack.get());
|
||||||
|
|
||||||
TrackInfo::DrawItems( dc, rect, *t, mouseCapture, captured );
|
TrackInfo::DrawItems( dc, rect, *t, mouseCapture, captured );
|
||||||
|
|
||||||
|
@ -527,7 +527,7 @@ protected:
|
|||||||
wxSize vrulerSize;
|
wxSize vrulerSize;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Track *mpClickedTrack {};
|
std::weak_ptr<Track> mpClickedTrack;
|
||||||
// TrackPanel is not responsible for memory management:
|
// TrackPanel is not responsible for memory management:
|
||||||
UIHandle *mUIHandle {};
|
UIHandle *mUIHandle {};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user