Audacity  2.2.2
LabelTextHandle.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 LabelTextHandle.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 #include "../../../Audacity.h"
12 #include "LabelTextHandle.h"
13 #include "../../../Experimental.h"
14 #include "../../../HitTestResult.h"
15 #include "../../../LabelTrack.h"
16 #include "../../../Project.h"
17 #include "../../../RefreshCode.h"
18 #include "../../../TrackPanelMouseEvent.h"
19 #include "../../../ViewInfo.h"
20 #include "../../../images/Cursors.h"
21 
23 ( const std::shared_ptr<LabelTrack> &pLT, int labelNum )
24  : mpLT{ pLT }
25  , mLabelNum{ labelNum }
26 {
27 }
28 
30 {
31 #ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
33 #endif
34 }
35 
37 {
38  static auto ibeamCursor =
39  ::MakeCursor(wxCURSOR_IBEAM, IBeamCursorXpm, 17, 16);
40  return {
41  _("Click to edit label text"),
42  ibeamCursor.get()
43  };
44 }
45 
47 (std::weak_ptr<LabelTextHandle> &holder,
48  const wxMouseState &state, const std::shared_ptr<LabelTrack> &pLT)
49 {
50  // If Control is down, let the select handle be hit instead
51  int labelNum;
52  if (!state.ControlDown() &&
53  (labelNum = pLT->OverATextBox(state.m_x, state.m_y) ) >= 0) {
54  auto result = std::make_shared<LabelTextHandle>( pLT, labelNum );
55  result = AssignUIHandlePtr(holder, result);
56  return result;
57  }
58 
59  return {};
60 }
61 
63 {
64 }
65 
67 (const TrackPanelMouseEvent &evt, AudacityProject *pProject)
68 {
69  auto pLT = mpLT.lock();
70  if (!pLT)
72 
73  auto result = LabelDefaultClickHandle::Click( evt, pProject );
74 
75  auto &selectionState = pProject->GetSelectionState();
76  TrackList *const tracks = pProject->GetTracks();
77  mChanger =
78  std::make_shared< SelectionStateChanger >( selectionState, *tracks );
79 
80  const wxMouseEvent &event = evt.event;
81  ViewInfo &viewInfo = pProject->GetViewInfo();
82 
83  mSelectedRegion = viewInfo.selectedRegion;
84  pLT->HandleTextClick( event, evt.rect, viewInfo, &viewInfo.selectedRegion );
85  wxASSERT(pLT->IsSelected());
86 
87  {
88  // IF the user clicked a label, THEN select all other tracks by Label
89 
90  TrackListIterator iter(tracks);
91  Track *t = iter.First();
92 
93  //do nothing if at least one other track is selected
94  bool done = false;
95  while (!done && t) {
96  if (t->GetSelected() && t != pLT.get())
97  done = true;
98  t = iter.Next();
99  }
100 
101  if (!done) {
102  //otherwise, select all tracks
103  t = iter.First();
104  while (t)
105  {
106  selectionState.SelectTrack
107  ( *pProject->GetTracks(), *t, true, true,
108  pProject->GetMixerBoard() );
109  t = iter.Next();
110  }
111  }
112 
113  // Do this after, for its effect on TrackPanel's memory of last selected
114  // track (which affects shift-click actions)
115  selectionState.SelectTrack
116  ( *pProject->GetTracks(), *pLT, true, true,
117  pProject->GetMixerBoard() );
118  }
119 
120  // PRL: bug1659 -- make selection change undo correctly
121  const bool unsafe = pProject->IsAudioActive();
122  if (!unsafe)
123  pProject->ModifyState(false);
124 
126 }
127 
129 (const TrackPanelMouseEvent &evt, AudacityProject *pProject)
130 {
131  using namespace RefreshCode;
132  auto result = LabelDefaultClickHandle::Drag( evt, pProject );
133 
134  const wxMouseEvent &event = evt.event;
135  auto pLT = pProject->GetTracks()->Lock(mpLT);
136  if(pLT)
137  pLT->HandleTextDragRelease(event);
138 
139  // locate the initial mouse position
140  if (event.LeftIsDown()) {
141  if (mLabelTrackStartXPos == -1) {
142  mLabelTrackStartXPos = event.m_x;
143  mLabelTrackStartYPos = event.m_y;
144 
145  if (pLT &&
146  (pLT->getSelectedIndex() != -1) &&
147  pLT->OverTextBox(
148  pLT->GetLabel(pLT->getSelectedIndex()),
149  mLabelTrackStartXPos,
150  mLabelTrackStartYPos))
151  mLabelTrackStartYPos = -1;
152  }
153  // if initial mouse position in the text box
154  // then only drag text
155  if (mLabelTrackStartYPos == -1)
156  result |= RefreshCell;
157  }
158 
159  return result;
160 }
161 
164 {
165  return HitPreview();
166 }
167 
169 (const TrackPanelMouseEvent &evt, AudacityProject *pProject,
170  wxWindow *pParent)
171 {
172  auto result = LabelDefaultClickHandle::Release( evt, pProject, pParent );
173 
174  // Only selected a part of a text string and changed track selectedness.
175  // No undoable effects.
176 
177  if (mChanger) {
178  mChanger->Commit();
179  mChanger.reset();
180  }
181 
182  const wxMouseEvent &event = evt.event;
183  auto pLT = pProject->GetTracks()->Lock(mpLT);
184  if (pLT)
185  pLT->HandleTextDragRelease(event);
186 
187  // handle mouse left button up
188  if (event.LeftUp())
189  mLabelTrackStartXPos = -1;
190 
191  return result | RefreshCode::RefreshNone;
192 }
193 
195 {
196  // Restore the selection states of tracks
197  // Note that we are also relying on LabelDefaultClickHandle::Cancel
198  // to restore the selection state of the labels in the tracks.
199  ViewInfo &viewInfo = pProject->GetViewInfo();
200  viewInfo.selectedRegion = mSelectedRegion;
201  auto result = LabelDefaultClickHandle::Cancel( pProject );
202  return result | RefreshCode::RefreshAll;
203 }
A list of TrackListNode items.
Definition: Track.h:611
Result Cancel(AudacityProject *pProject) override
ViewInfo is used mainly to hold the zooming, selection and scroll information. It also has some statu...
Definition: ViewInfo.h:141
SelectedRegion selectedRegion
Definition: ViewInfo.h:160
bool GetSelected() const
Definition: Track.h:268
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
HitTestPreview Preview(const TrackPanelMouseState &state, const AudacityProject *pProject) override
MixerBoard * GetMixerBoard()
Definition: Project.h:500
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:274
Result mChangeHighlight
Definition: UIHandle.h:150
void Enter(bool forward) override
AudacityProject provides the main window, with tools and tracks contained within it.
Definition: Project.h:158
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
unsigned Result
Definition: UIHandle.h:37
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:94
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
static HitTestPreview HitPreview()
virtual Track * First(TrackList *val=nullptr)
Definition: Track.cpp:414
SelectionState & GetSelectionState()
Definition: Project.h:291
bool IsAudioActive() const
Definition: Project.cpp:1424
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:725
void ModifyState(bool bWantsAutoSave)
Definition: Project.cpp:4550
std::shared_ptr< UIHandle > UIHandlePtr
Definition: TrackPanel.h:59
An iterator for a TrackList.
Definition: Track.h:394
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
SelectedRegion mSelectedRegion
virtual Track * Next(bool skiplinked=false)
Definition: Track.cpp:456
LabelTextHandle(const std::shared_ptr< LabelTrack > &pLT, int labelNum)
static UIHandlePtr HitTest(std::weak_ptr< LabelTextHandle > &holder, const wxMouseState &state, const std::shared_ptr< LabelTrack > &pLT)
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
Result Cancel(AudacityProject *pProject) override
TrackList * GetTracks()
Definition: Project.h:174
const ViewInfo & GetViewInfo() const
Definition: Project.h:189
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:162
virtual ~LabelTextHandle()