Audacity  3.0.3
LabelDefaultClickHandle.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 LabelDefaultClickHandle.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 
13 
14 #include "LabelTrackView.h"
15 #include "../../../HitTestResult.h"
16 #include "../../../LabelTrack.h"
17 #include "../../../RefreshCode.h"
18 #include "../../../TrackPanelMouseEvent.h"
19 
21 {
22 }
23 
25 {
26 }
27 
29  std::vector<
30  std::pair< std::weak_ptr<LabelTrack>, LabelTrackView::Flags >
31  > mPairs;
32 };
33 
35 {
36  mLabelState = std::make_shared<LabelState>();
37  auto &pairs = mLabelState->mPairs;
38  auto &tracks = TrackList::Get( *pProject );
39 
40  for (auto lt : tracks.Any<LabelTrack>()) {
41  auto &view = LabelTrackView::Get( *lt );
42  pairs.push_back( std::make_pair(
43  lt->SharedPointer<LabelTrack>(), view.SaveFlags() ) );
44  }
45 }
46 
48 {
49  if ( mLabelState ) {
50  for ( const auto &pair : mLabelState->mPairs )
51  if (auto pLt = TrackList::Get( *pProject ).Lock(pair.first)) {
52  auto &view = LabelTrackView::Get( *pLt );
53  view.RestoreFlags( pair.second );
54  }
55  mLabelState.reset();
56  }
57 }
58 
60 (const TrackPanelMouseEvent &evt, AudacityProject *pProject)
61 {
62  using namespace RefreshCode;
63  // Redraw to show the change of text box selection status
65 
66  if (evt.event.LeftDown())
67  {
68  SaveState( pProject );
69 
70  const auto pLT = evt.pCell.get();
71  for (auto lt : TrackList::Get( *pProject ).Any<LabelTrack>()) {
72  if (pLT != &TrackView::Get( *lt )) {
73  auto &view = LabelTrackView::Get( *lt );
74  view.ResetFlags();
75  }
76  }
77  }
78 
79  return result;
80 }
81 
83 (const TrackPanelMouseEvent &WXUNUSED(evt), AudacityProject *WXUNUSED(pProject))
84 {
86 }
87 
89 (const TrackPanelMouseEvent &WXUNUSED(evt), AudacityProject *WXUNUSED(pProject),
90  wxWindow *WXUNUSED(pParent))
91 {
92  mLabelState.reset();
94 }
95 
97 {
99  RestoreState( pProject );
100  return result;
101 }
TrackPanelMouseEvent::pCell
std::shared_ptr< TrackPanelCell > pCell
Definition: TrackPanelMouseEvent.h:61
LabelDefaultClickHandle::LabelDefaultClickHandle
LabelDefaultClickHandle()
Definition: LabelDefaultClickHandle.cpp:20
LabelDefaultClickHandle::Drag
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
Definition: LabelDefaultClickHandle.cpp:83
LabelDefaultClickHandle::Click
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
Definition: LabelDefaultClickHandle.cpp:60
RefreshCode::RefreshAll
@ RefreshAll
Definition: RefreshCode.h:26
TrackView::Get
static TrackView & Get(Track &)
Definition: TrackView.cpp:63
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
TrackList::Lock
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1542
LabelDefaultClickHandle.h
LabelTrack
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:88
LabelDefaultClickHandle::RestoreState
void RestoreState(AudacityProject *pProject)
Definition: LabelDefaultClickHandle.cpp:47
LabelDefaultClickHandle::Cancel
Result Cancel(AudacityProject *pProject) override
Definition: LabelDefaultClickHandle.cpp:96
UIHandle::Result
unsigned Result
Definition: UIHandle.h:38
LabelDefaultClickHandle::LabelState
Definition: LabelDefaultClickHandle.cpp:28
LabelTrackView.h
LabelTrackView::Get
static LabelTrackView & Get(LabelTrack &)
Definition: LabelTrackView.cpp:162
LabelDefaultClickHandle::LabelState::mPairs
std::vector< std::pair< std::weak_ptr< LabelTrack >, LabelTrackView::Flags > > mPairs
Definition: LabelDefaultClickHandle.cpp:31
LabelDefaultClickHandle::Release
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
Definition: LabelDefaultClickHandle.cpp:89
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:506
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
LabelDefaultClickHandle::~LabelDefaultClickHandle
virtual ~LabelDefaultClickHandle()
Definition: LabelDefaultClickHandle.cpp:24
TrackPanelMouseEvent
Definition: TrackPanelMouseEvent.h:46
LabelDefaultClickHandle::SaveState
void SaveState(AudacityProject *pProject)
Definition: LabelDefaultClickHandle.cpp:34
LabelDefaultClickHandle::mLabelState
std::shared_ptr< LabelState > mLabelState
Definition: LabelDefaultClickHandle.h:45
TrackList::Any
auto Any() -> TrackIterRange< TrackType >
Definition: Track.h:1371
RefreshCode
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
TrackPanelMouseEvent::event
wxMouseEvent & event
Definition: TrackPanelMouseEvent.h:58
LabelTrackView::Flags
Definition: LabelTrackView.h:144