mirror of
https://github.com/cookiengineer/audacity
synced 2025-05-03 00:59:43 +02:00
Iterators over TrackPanelCell give shared_ptr
This commit is contained in:
parent
58fea6d520
commit
f8b74db76e
@ -855,7 +855,7 @@ void TrackPanel::HandleCursor( wxMouseEvent *pEvent )
|
||||
auto &rect = foundCell.rect;
|
||||
auto &pCell = foundCell.pCell;
|
||||
const auto size = GetSize();
|
||||
const TrackPanelMouseEvent tpmEvent{ event, rect, size, pCell };
|
||||
const TrackPanelMouseEvent tpmEvent{ event, rect, size, pCell.get() };
|
||||
HandleCursor( tpmEvent );
|
||||
}
|
||||
|
||||
@ -1382,7 +1382,7 @@ try
|
||||
auto &pTrack = foundCell.pTrack;
|
||||
|
||||
const auto size = GetSize();
|
||||
TrackPanelMouseEvent tpmEvent{ event, rect, size, pCell };
|
||||
TrackPanelMouseEvent tpmEvent{ event, rect, size, pCell.get() };
|
||||
|
||||
#if defined(__WXMAC__) && defined(EVT_MAGNIFY)
|
||||
// PRL:
|
||||
@ -1461,7 +1461,8 @@ try
|
||||
// UIHANDLE DRAG
|
||||
const UIHandle::Result refreshResult =
|
||||
mUIHandle->Drag( tpmEvent, GetProject() );
|
||||
ProcessUIHandleResult(this, mRuler, mpClickedTrack, pTrack, refreshResult);
|
||||
ProcessUIHandleResult
|
||||
(this, mRuler, mpClickedTrack, pTrack.get(), refreshResult);
|
||||
if (refreshResult & RefreshCode::Cancelled) {
|
||||
// Drag decided to abort itself
|
||||
mUIHandle = NULL;
|
||||
@ -1480,7 +1481,8 @@ try
|
||||
mUIHandle = nullptr;
|
||||
UIHandle::Result refreshResult =
|
||||
uiHandle->Release( tpmEvent, GetProject(), this );
|
||||
ProcessUIHandleResult(this, mRuler, mpClickedTrack, pTrack, refreshResult);
|
||||
ProcessUIHandleResult
|
||||
(this, mRuler, mpClickedTrack, pTrack.get(), refreshResult);
|
||||
mpClickedTrack = NULL;
|
||||
// will also Uncapture() below
|
||||
}
|
||||
@ -1508,7 +1510,7 @@ try
|
||||
const auto foundCell = FindCell(event.m_x, event.m_y);
|
||||
auto t = foundCell.pTrack;
|
||||
if ( t )
|
||||
EnsureVisible(t);
|
||||
EnsureVisible(t.get());
|
||||
}
|
||||
}
|
||||
catch( ... )
|
||||
@ -2511,7 +2513,8 @@ TrackPanel::FoundCell TrackPanel::FindCell(int mouseX, int mouseY)
|
||||
iter = prev;
|
||||
auto found = *iter;
|
||||
return {
|
||||
static_cast<CommonTrackPanelCell*>( found.first )->FindTrack(),
|
||||
Track::Pointer(
|
||||
static_cast<CommonTrackPanelCell*>( found.first.get() )->FindTrack() ),
|
||||
found.first,
|
||||
found.second
|
||||
};
|
||||
@ -3085,12 +3088,15 @@ IteratorRange< TrackPanelCellIterator > TrackPanel::Cells()
|
||||
TrackPanelCellIterator::TrackPanelCellIterator(TrackPanel *trackPanel, bool begin)
|
||||
: mPanel{ trackPanel }
|
||||
, mIter{ trackPanel->GetProject() }
|
||||
, mpTrack{ begin ? mIter.First() : nullptr }
|
||||
, mpCell{ begin
|
||||
? ( mpTrack ? mpTrack : trackPanel->GetBackgroundCell().get() )
|
||||
: nullptr
|
||||
}
|
||||
{
|
||||
if (begin) {
|
||||
mpTrack = Track::Pointer( mIter.First() );
|
||||
if (mpTrack)
|
||||
mpCell = mpTrack;
|
||||
else
|
||||
mpCell = trackPanel->GetBackgroundCell();
|
||||
}
|
||||
|
||||
const auto size = mPanel->GetSize();
|
||||
mRect = { 0, 0, size.x, size.y };
|
||||
UpdateRect();
|
||||
@ -3100,7 +3106,7 @@ TrackPanelCellIterator &TrackPanelCellIterator::operator++ ()
|
||||
{
|
||||
if ( mpTrack ) {
|
||||
if ( ++ mType == CellType::Background )
|
||||
mType = CellType::Track, mpTrack = mIter.Next();
|
||||
mType = CellType::Track, mpTrack = Track::Pointer( mIter.Next() );
|
||||
}
|
||||
if ( mpTrack ) {
|
||||
if ( mType == CellType::Label &&
|
||||
@ -3112,25 +3118,25 @@ TrackPanelCellIterator &TrackPanelCellIterator::operator++ ()
|
||||
mpCell = mpTrack;
|
||||
break;
|
||||
case CellType::Label:
|
||||
mpCell = mpTrack->GetTrackControl().get();
|
||||
mpCell = mpTrack->GetTrackControl();
|
||||
break;
|
||||
case CellType::VRuler:
|
||||
mpCell = mpTrack->GetVRulerControl().get();
|
||||
mpCell = mpTrack->GetVRulerControl();
|
||||
break;
|
||||
case CellType::Resizer: {
|
||||
mpCell = mpTrack->GetResizer().get();
|
||||
mpCell = mpTrack->GetResizer();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
// should not happen
|
||||
mpCell = nullptr;
|
||||
mpCell.reset();
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if ( !mDidBackground )
|
||||
mpCell = mPanel->GetBackgroundCell().get(), mDidBackground = true;
|
||||
mpCell = mPanel->GetBackgroundCell(), mDidBackground = true;
|
||||
else
|
||||
mpCell = nullptr;
|
||||
mpCell.reset();
|
||||
|
||||
UpdateRect();
|
||||
|
||||
|
@ -366,8 +366,8 @@ protected:
|
||||
|
||||
// Find track info by coordinate
|
||||
struct FoundCell {
|
||||
Track *pTrack;
|
||||
TrackPanelCell *pCell;
|
||||
std::shared_ptr<Track> pTrack;
|
||||
std::shared_ptr<TrackPanelCell> pCell;
|
||||
wxRect rect;
|
||||
};
|
||||
FoundCell FindCell(int mouseX, int mouseY);
|
||||
|
@ -14,6 +14,7 @@ Paul Licameli
|
||||
#include "Track.h"
|
||||
#include <wx/gdicmn.h>
|
||||
#include <iterator>
|
||||
#include "MemoryX.h"
|
||||
|
||||
class Track;
|
||||
class TrackPanelCell;
|
||||
@ -24,7 +25,7 @@ class TrackPanel;
|
||||
class TrackPanelCellIterator
|
||||
: public std::iterator<
|
||||
std::forward_iterator_tag,
|
||||
const std::pair<TrackPanelCell*, wxRect>
|
||||
const std::pair< std::shared_ptr< TrackPanelCell >, wxRect>
|
||||
>
|
||||
{
|
||||
public:
|
||||
@ -45,7 +46,6 @@ public:
|
||||
return lhs.mpCell == rhs.mpCell;
|
||||
}
|
||||
|
||||
using value_type = std::pair<TrackPanelCell*, wxRect>;
|
||||
value_type operator * () const;
|
||||
|
||||
private:
|
||||
@ -53,8 +53,8 @@ private:
|
||||
|
||||
TrackPanel *mPanel;
|
||||
VisibleTrackIterator mIter;
|
||||
Track *mpTrack;
|
||||
TrackPanelCell *mpCell;
|
||||
std::shared_ptr<Track> mpTrack;
|
||||
std::shared_ptr<TrackPanelCell> mpCell;
|
||||
CellType mType{ CellType::Track };
|
||||
bool mDidBackground{ false };
|
||||
wxRect mRect;
|
||||
|
@ -106,7 +106,7 @@ void EditCursorOverlay::Draw(OverlayPanel &panel, wxDC &dc)
|
||||
// Draw cursor in all selected tracks
|
||||
for ( const auto &data : tp->Cells() )
|
||||
{
|
||||
Track *const pTrack = dynamic_cast<Track*>(data.first);
|
||||
Track *const pTrack = dynamic_cast<Track*>(data.first.get());
|
||||
if (!pTrack)
|
||||
continue;
|
||||
if (pTrack->GetSelected() ||
|
||||
|
@ -72,7 +72,7 @@ void PlayIndicatorOverlayBase::Draw(OverlayPanel &panel, wxDC &dc)
|
||||
// Draw indicator in all visible tracks
|
||||
for ( const auto &data : tp->Cells() )
|
||||
{
|
||||
Track *const pTrack = dynamic_cast<Track*>(data.first);
|
||||
Track *const pTrack = dynamic_cast<Track*>(data.first.get());
|
||||
if (!pTrack)
|
||||
continue;
|
||||
|
||||
|
@ -1841,7 +1841,7 @@ void QuickPlayIndicatorOverlay::Draw(OverlayPanel &panel, wxDC &dc)
|
||||
// Draw indicator in all visible tracks
|
||||
for ( const auto &data : static_cast<TrackPanel&>(panel).Cells() )
|
||||
{
|
||||
Track *const pTrack = dynamic_cast<Track*>(data.first);
|
||||
Track *const pTrack = dynamic_cast<Track*>(data.first.get());
|
||||
if (!pTrack)
|
||||
continue;
|
||||
const wxRect &rect = data.second;
|
||||
|
Loading…
x
Reference in New Issue
Block a user