Audacity  2.2.2
LabelGlyphHandle.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 LabelGlyphHandle.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 #include "../../../Audacity.h"
12 #include "LabelGlyphHandle.h"
13 #include "../../../HitTestResult.h"
14 #include "../../../LabelTrack.h"
15 #include "../../../Project.h"
16 #include "../../../RefreshCode.h"
17 #include "../../../TrackPanelMouseEvent.h"
18 #include "../../../UndoManager.h"
19 #include "../../../ViewInfo.h"
20 
21 #include "../../../MemoryX.h"
22 
23 #include <wx/cursor.h>
24 #include <wx/translation.h>
25 
27 (const std::shared_ptr<LabelTrack> &pLT,
28  const wxRect &rect, const LabelTrackHit &hit)
29  : mpLT{ pLT }
30  , mRect{ rect }
31  , mHit{ hit }
32 {
33 }
34 
36 {
38 }
39 
41 (const LabelGlyphHandle &oldState, const LabelGlyphHandle &newState)
42 {
43  if (oldState.mHit.mEdge != newState.mHit.mEdge)
44  // pointer moves between the circle and the chevron
46  return 0;
47 }
48 
50 {
51  static wxCursor arrowCursor{ wxCURSOR_ARROW };
52  return {
53  (hitCenter
54  ? _("Drag one or more label boundaries.")
55  : _("Drag label boundary.")),
56  &arrowCursor
57  };
58 }
59 
61 (std::weak_ptr<LabelGlyphHandle> &holder,
62  const wxMouseState &state,
63  const std::shared_ptr<LabelTrack> &pLT, const wxRect &rect)
64 {
65  LabelTrackHit hit{};
66  pLT->OverGlyph(hit, state.m_x, state.m_y);
67 
68  // IF edge!=0 THEN we've set the cursor and we're done.
69  // signal this by setting the tip.
70  if ( hit.mEdge & 3 )
71  {
72  auto result = std::make_shared<LabelGlyphHandle>( pLT, rect, hit );
73  result = AssignUIHandlePtr(holder, result);
74  return result;
75  }
76 
77  return {};
78 }
79 
81 {
82 }
83 
85 (const TrackPanelMouseEvent &evt, AudacityProject *pProject)
86 {
87  auto result = LabelDefaultClickHandle::Click( evt, pProject );
88 
89  const wxMouseEvent &event = evt.event;
90 
91  ViewInfo &viewInfo = pProject->GetViewInfo();
92  mpLT->HandleGlyphClick
93  (mHit, event, mRect, viewInfo, &viewInfo.selectedRegion);
94 
95  if (! mHit.mIsAdjustingLabel )
96  {
97  // The positive hit test should have ensured otherwise
98  //wxASSERT(false);
99  result |= RefreshCode::Cancelled;
100  }
101  else
102  // redraw the track.
103  result |= RefreshCode::RefreshCell;
104 
105  // handle shift+ctrl down
106  /*if (event.ShiftDown()) { // && event.ControlDown()) {
107  lTrack->SetHighlightedByKey(true);
108  Refresh(false);
109  return;
110  }*/
111 
112  return result;
113 }
114 
116 (const TrackPanelMouseEvent &evt, AudacityProject *pProject)
117 {
118  auto result = LabelDefaultClickHandle::Drag( evt, pProject );
119 
120  const wxMouseEvent &event = evt.event;
121  ViewInfo &viewInfo = pProject->GetViewInfo();
122  mpLT->HandleGlyphDragRelease
123  (mHit, event, mRect, viewInfo, &viewInfo.selectedRegion);
124 
125  // Refresh all so that the change of selection is redrawn in all tracks
127 }
128 
131 {
132  return HitPreview( (mHit.mEdge & 4 )!=0);
133 }
134 
136 (const TrackPanelMouseEvent &evt, AudacityProject *pProject,
137  wxWindow *pParent)
138 {
139  auto result = LabelDefaultClickHandle::Release( evt, pProject, pParent );
140 
141  const wxMouseEvent &event = evt.event;
142  ViewInfo &viewInfo = pProject->GetViewInfo();
143  if (mpLT->HandleGlyphDragRelease
144  (mHit, event, mRect, viewInfo, &viewInfo.selectedRegion)) {
145  pProject->PushState(_("Modified Label"),
146  _("Label Edit"),
148  }
149 
150  // Refresh all so that the change of selection is redrawn in all tracks
152 }
153 
155 {
156  pProject->RollbackState();
157  auto result = LabelDefaultClickHandle::Cancel( pProject );
158  return result | RefreshCode::RefreshAll;
159 }
LabelGlyphHandle(const std::shared_ptr< LabelTrack > &pLT, const wxRect &rect, const LabelTrackHit &hit)
Result Cancel(AudacityProject *pProject) override
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
static HitTestPreview HitPreview(bool hitCenter)
void Enter(bool forward) override
static UIHandlePtr HitTest(std::weak_ptr< LabelGlyphHandle > &holder, const wxMouseState &state, const std::shared_ptr< LabelTrack > &pLT, const wxRect &rect)
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
Result mChangeHighlight
Definition: UIHandle.h:150
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) 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
void RollbackState()
Definition: Project.cpp:4545
static UIHandle::Result NeedChangeHighlight(const LabelGlyphHandle &oldState, const LabelGlyphHandle &newState)
virtual ~LabelGlyphHandle()
std::shared_ptr< LabelTrack > mpLT
std::shared_ptr< UIHandle > UIHandlePtr
Definition: TrackPanel.h:59
_("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 &)
void PushState(const wxString &desc, const wxString &shortDesc)
Definition: Project.cpp:4505
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
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
HitTestPreview Preview(const TrackPanelMouseState &state, const AudacityProject *pProject) override
LabelTrackHit mHit
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override