Audacity  2.2.2
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 #include "../../../Audacity.h"
13 #include "../../../HitTestResult.h"
14 #include "../../../LabelTrack.h"
15 #include "../../../Project.h"
16 #include "../../../RefreshCode.h"
17 #include "../../../TrackPanelMouseEvent.h"
18 #include "../../../ViewInfo.h"
19 
21 {
22 }
23 
25 {
26 }
27 
29  std::vector< std::pair< std::weak_ptr<LabelTrack>, LabelTrack::Flags > > mPairs;
30 };
31 
33 {
34  mLabelState = std::make_shared<LabelState>();
35  auto &pairs = mLabelState->mPairs;
36  TrackList *const tracks = pProject->GetTracks();
37  TrackListIterator iter(tracks);
38  Track *n = iter.First();
39 
40  while (n) {
41  if (n->GetKind() == Track::Label) {
42  LabelTrack *const lt = static_cast<LabelTrack*>(n);
43  pairs.push_back( std::make_pair(
44  Track::Pointer<LabelTrack>( lt ),
45  lt->SaveFlags() )
46  );
47  }
48  n = iter.Next();
49  }
50 }
51 
53 {
54  if ( mLabelState ) {
55  for ( const auto &pair : mLabelState->mPairs )
56  if (auto pLt = pProject->GetTracks()->Lock(pair.first))
57  pLt->RestoreFlags( pair.second );
58  mLabelState.reset();
59  }
60 }
61 
63 (const TrackPanelMouseEvent &evt, AudacityProject *pProject)
64 {
65  using namespace RefreshCode;
66  // Redraw to show the change of text box selection status
68 
69  if (evt.event.LeftDown())
70  {
71  SaveState( pProject );
72 
73  TrackList *const tracks = pProject->GetTracks();
74  TrackListIterator iter(tracks);
75  Track *n = iter.First();
76 
77  while (n) {
78  if (n->GetKind() == Track::Label && evt.pCell.get() != n) {
79  LabelTrack *const lt = static_cast<LabelTrack*>(n);
80  lt->ResetFlags();
81  lt->Unselect();
82  }
83  n = iter.Next();
84  }
85  }
86 
87  return result;
88 }
89 
91 (const TrackPanelMouseEvent &WXUNUSED(evt), AudacityProject *WXUNUSED(pProject))
92 {
94 }
95 
97 (const TrackPanelMouseEvent &WXUNUSED(evt), AudacityProject *WXUNUSED(pProject),
98  wxWindow *WXUNUSED(pParent))
99 {
100  mLabelState.reset();
102 }
103 
105 {
107  RestoreState( pProject );
108  return result;
109 }
std::shared_ptr< LabelState > mLabelState
A list of TrackListNode items.
Definition: Track.h:618
void Unselect()
Result Cancel(AudacityProject *pProject) override
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
virtual int GetKind() const
Definition: Track.h:329
A LabelTrack is a Track that holds labels (LabelStruct).
Definition: LabelTrack.h:113
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:176
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
unsigned Result
Definition: UIHandle.h:37
std::vector< std::pair< std::weak_ptr< LabelTrack >, LabelTrack::Flags > > mPairs
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:101
void SaveState(AudacityProject *pProject)
virtual Track * First(TrackList *val=nullptr)
Definition: Track.cpp:418
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:733
An iterator for a TrackList.
Definition: Track.h:401
virtual Track * Next(bool skiplinked=false)
Definition: Track.cpp:460
std::shared_ptr< TrackPanelCell > pCell
Flags SaveFlags() const
Definition: LabelTrack.h:193
void RestoreState(AudacityProject *pProject)
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
TrackList * GetTracks()
Definition: Project.h:192
void ResetFlags()
Definition: LabelTrack.cpp:268