1
0
mirror of https://github.com/cookiengineer/audacity synced 2025-06-22 23:30:07 +02:00

Iterators over TrackPanelCell give shared_ptr

This commit is contained in:
Paul Licameli 2017-06-26 16:53:12 -04:00
parent 58fea6d520
commit f8b74db76e
6 changed files with 33 additions and 27 deletions

View File

@ -855,7 +855,7 @@ void TrackPanel::HandleCursor( wxMouseEvent *pEvent )
auto &rect = foundCell.rect; auto &rect = foundCell.rect;
auto &pCell = foundCell.pCell; auto &pCell = foundCell.pCell;
const auto size = GetSize(); const auto size = GetSize();
const TrackPanelMouseEvent tpmEvent{ event, rect, size, pCell }; const TrackPanelMouseEvent tpmEvent{ event, rect, size, pCell.get() };
HandleCursor( tpmEvent ); HandleCursor( tpmEvent );
} }
@ -1382,7 +1382,7 @@ try
auto &pTrack = foundCell.pTrack; auto &pTrack = foundCell.pTrack;
const auto size = GetSize(); const auto size = GetSize();
TrackPanelMouseEvent tpmEvent{ event, rect, size, pCell }; TrackPanelMouseEvent tpmEvent{ event, rect, size, pCell.get() };
#if defined(__WXMAC__) && defined(EVT_MAGNIFY) #if defined(__WXMAC__) && defined(EVT_MAGNIFY)
// PRL: // PRL:
@ -1461,7 +1461,8 @@ try
// UIHANDLE DRAG // UIHANDLE DRAG
const UIHandle::Result refreshResult = const UIHandle::Result refreshResult =
mUIHandle->Drag( tpmEvent, GetProject() ); mUIHandle->Drag( tpmEvent, GetProject() );
ProcessUIHandleResult(this, mRuler, mpClickedTrack, pTrack, refreshResult); ProcessUIHandleResult
(this, mRuler, mpClickedTrack, 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;
@ -1480,7 +1481,8 @@ try
mUIHandle = nullptr; mUIHandle = nullptr;
UIHandle::Result refreshResult = UIHandle::Result refreshResult =
uiHandle->Release( tpmEvent, GetProject(), this ); uiHandle->Release( tpmEvent, GetProject(), this );
ProcessUIHandleResult(this, mRuler, mpClickedTrack, pTrack, refreshResult); ProcessUIHandleResult
(this, mRuler, mpClickedTrack, pTrack.get(), refreshResult);
mpClickedTrack = NULL; mpClickedTrack = NULL;
// will also Uncapture() below // will also Uncapture() below
} }
@ -1508,7 +1510,7 @@ try
const auto foundCell = FindCell(event.m_x, event.m_y); const auto foundCell = FindCell(event.m_x, event.m_y);
auto t = foundCell.pTrack; auto t = foundCell.pTrack;
if ( t ) if ( t )
EnsureVisible(t); EnsureVisible(t.get());
} }
} }
catch( ... ) catch( ... )
@ -2511,7 +2513,8 @@ TrackPanel::FoundCell TrackPanel::FindCell(int mouseX, int mouseY)
iter = prev; iter = prev;
auto found = *iter; auto found = *iter;
return { return {
static_cast<CommonTrackPanelCell*>( found.first )->FindTrack(), Track::Pointer(
static_cast<CommonTrackPanelCell*>( found.first.get() )->FindTrack() ),
found.first, found.first,
found.second found.second
}; };
@ -3085,12 +3088,15 @@ IteratorRange< TrackPanelCellIterator > TrackPanel::Cells()
TrackPanelCellIterator::TrackPanelCellIterator(TrackPanel *trackPanel, bool begin) TrackPanelCellIterator::TrackPanelCellIterator(TrackPanel *trackPanel, bool begin)
: mPanel{ trackPanel } : mPanel{ trackPanel }
, mIter{ trackPanel->GetProject() } , 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(); const auto size = mPanel->GetSize();
mRect = { 0, 0, size.x, size.y }; mRect = { 0, 0, size.x, size.y };
UpdateRect(); UpdateRect();
@ -3100,7 +3106,7 @@ TrackPanelCellIterator &TrackPanelCellIterator::operator++ ()
{ {
if ( mpTrack ) { if ( mpTrack ) {
if ( ++ mType == CellType::Background ) if ( ++ mType == CellType::Background )
mType = CellType::Track, mpTrack = mIter.Next(); mType = CellType::Track, mpTrack = Track::Pointer( mIter.Next() );
} }
if ( mpTrack ) { if ( mpTrack ) {
if ( mType == CellType::Label && if ( mType == CellType::Label &&
@ -3112,25 +3118,25 @@ TrackPanelCellIterator &TrackPanelCellIterator::operator++ ()
mpCell = mpTrack; mpCell = mpTrack;
break; break;
case CellType::Label: case CellType::Label:
mpCell = mpTrack->GetTrackControl().get(); mpCell = mpTrack->GetTrackControl();
break; break;
case CellType::VRuler: case CellType::VRuler:
mpCell = mpTrack->GetVRulerControl().get(); mpCell = mpTrack->GetVRulerControl();
break; break;
case CellType::Resizer: { case CellType::Resizer: {
mpCell = mpTrack->GetResizer().get(); mpCell = mpTrack->GetResizer();
break; break;
} }
default: default:
// should not happen // should not happen
mpCell = nullptr; mpCell.reset();
break; break;
} }
} }
else if ( !mDidBackground ) else if ( !mDidBackground )
mpCell = mPanel->GetBackgroundCell().get(), mDidBackground = true; mpCell = mPanel->GetBackgroundCell(), mDidBackground = true;
else else
mpCell = nullptr; mpCell.reset();
UpdateRect(); UpdateRect();

View File

@ -366,8 +366,8 @@ protected:
// Find track info by coordinate // Find track info by coordinate
struct FoundCell { struct FoundCell {
Track *pTrack; std::shared_ptr<Track> pTrack;
TrackPanelCell *pCell; std::shared_ptr<TrackPanelCell> pCell;
wxRect rect; wxRect rect;
}; };
FoundCell FindCell(int mouseX, int mouseY); FoundCell FindCell(int mouseX, int mouseY);

View File

@ -14,6 +14,7 @@ Paul Licameli
#include "Track.h" #include "Track.h"
#include <wx/gdicmn.h> #include <wx/gdicmn.h>
#include <iterator> #include <iterator>
#include "MemoryX.h"
class Track; class Track;
class TrackPanelCell; class TrackPanelCell;
@ -24,7 +25,7 @@ class TrackPanel;
class TrackPanelCellIterator class TrackPanelCellIterator
: public std::iterator< : public std::iterator<
std::forward_iterator_tag, std::forward_iterator_tag,
const std::pair<TrackPanelCell*, wxRect> const std::pair< std::shared_ptr< TrackPanelCell >, wxRect>
> >
{ {
public: public:
@ -45,7 +46,6 @@ public:
return lhs.mpCell == rhs.mpCell; return lhs.mpCell == rhs.mpCell;
} }
using value_type = std::pair<TrackPanelCell*, wxRect>;
value_type operator * () const; value_type operator * () const;
private: private:
@ -53,8 +53,8 @@ private:
TrackPanel *mPanel; TrackPanel *mPanel;
VisibleTrackIterator mIter; VisibleTrackIterator mIter;
Track *mpTrack; std::shared_ptr<Track> mpTrack;
TrackPanelCell *mpCell; std::shared_ptr<TrackPanelCell> mpCell;
CellType mType{ CellType::Track }; CellType mType{ CellType::Track };
bool mDidBackground{ false }; bool mDidBackground{ false };
wxRect mRect; wxRect mRect;

View File

@ -106,7 +106,7 @@ void EditCursorOverlay::Draw(OverlayPanel &panel, wxDC &dc)
// Draw cursor in all selected tracks // Draw cursor in all selected tracks
for ( const auto &data : tp->Cells() ) 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) if (!pTrack)
continue; continue;
if (pTrack->GetSelected() || if (pTrack->GetSelected() ||

View File

@ -72,7 +72,7 @@ void PlayIndicatorOverlayBase::Draw(OverlayPanel &panel, wxDC &dc)
// Draw indicator in all visible tracks // Draw indicator in all visible tracks
for ( const auto &data : tp->Cells() ) 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) if (!pTrack)
continue; continue;

View File

@ -1841,7 +1841,7 @@ void QuickPlayIndicatorOverlay::Draw(OverlayPanel &panel, wxDC &dc)
// Draw indicator in all visible tracks // Draw indicator in all visible tracks
for ( const auto &data : static_cast<TrackPanel&>(panel).Cells() ) 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) if (!pTrack)
continue; continue;
const wxRect &rect = data.second; const wxRect &rect = data.second;