Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Static Private Member Functions | Private Attributes | List of all members
LabelTextHandle Class Referencefinal

#include <LabelTextHandle.h>

Inheritance diagram for LabelTextHandle:
[legend]
Collaboration diagram for LabelTextHandle:
[legend]

Public Member Functions

LabelTextHandleoperator= (const LabelTextHandle &)=default
 
 LabelTextHandle (const std::shared_ptr< LabelTrack > &pLT, int labelNum)
 
virtual ~LabelTextHandle ()
 
std::shared_ptr< const TrackFindTrack () const override
 
int GetLabelNum () const
 
void Enter (bool forward, AudacityProject *) override
 
bool HandlesRightClick () override
 Whether the handle has any special right-button handling. More...
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *pProject) override
 
Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
 
Result Cancel (AudacityProject *pProject) override
 
- Public Member Functions inherited from LabelDefaultClickHandle
 LabelDefaultClickHandle ()
 
virtual ~LabelDefaultClickHandle ()
 
LabelDefaultClickHandleoperator= (const LabelDefaultClickHandle &)=default
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
 
Result Cancel (AudacityProject *pProject) override
 
- Public Member Functions inherited from UIHandle
virtual ~UIHandle ()=0
 
virtual void Enter (bool forward, AudacityProject *pProject)
 
virtual bool HasRotation () const
 
virtual bool Rotate (bool forward)
 
virtual bool HasEscape (AudacityProject *pProject) const
 
virtual bool Escape (AudacityProject *pProject)
 
virtual bool HandlesRightClick ()
 Whether the handle has any special right-button handling. More...
 
virtual Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
 
virtual Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject)=0
 
virtual HitTestPreview Preview (const TrackPanelMouseState &state, AudacityProject *pProject)=0
 
virtual Result Release (const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent)=0
 
virtual Result Cancel (AudacityProject *pProject)=0
 
virtual bool StopsOnKeystroke ()
 
virtual void OnProjectChange (AudacityProject *pProject)
 
virtual std::shared_ptr< const TrackFindTrack () const =0
 
virtual bool IsDragging () const
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 
- Public Member Functions inherited from TrackPanelDrawable
virtual ~TrackPanelDrawable ()=0
 
virtual void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
 
virtual wxRect DrawingArea (TrackPanelDrawingContext &context, const wxRect &rect, const wxRect &panelRect, unsigned iPass)
 

Static Public Member Functions

static UIHandlePtr HitTest (std::weak_ptr< LabelTextHandle > &holder, const wxMouseState &state, const std::shared_ptr< LabelTrack > &pLT)
 
- Static Public Member Functions inherited from UIHandle
static UIHandle::Result NeedChangeHighlight (const UIHandle &, const UIHandle &)
 
static std::shared_ptr< const TrackTrackFromChannel (const std::shared_ptr< const Channel > &pChannel)
 A frequent convenience in the definition of UIHandles. More...
 
- Static Public Member Functions inherited from TrackPanelDrawable
static wxRect MaximizeWidth (const wxRect &rect, const wxRect &panelRect)
 
static wxRect MaximizeHeight (const wxRect &rect, const wxRect &panelRect)
 

Private Member Functions

void HandleTextClick (AudacityProject &project, const wxMouseEvent &evt)
 
void HandleTextDragRelease (AudacityProject &project, const wxMouseEvent &evt)
 

Static Private Member Functions

static HitTestPreview HitPreview ()
 

Private Attributes

std::weak_ptr< LabelTrackmpLT {}
 
int mLabelNum { -1 }
 
int mLabelTrackStartXPos { -1 }
 
int mLabelTrackStartYPos { -1 }
 
bool mRightDragging { false }
 flag to tell if it's a valid dragging More...
 

Additional Inherited Members

- Public Types inherited from UIHandle
using Result = unsigned
 
using Cell = TrackPanelCell
 
- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Definition at line 22 of file LabelTextHandle.h.

Constructor & Destructor Documentation

◆ LabelTextHandle()

LabelTextHandle::LabelTextHandle ( const std::shared_ptr< LabelTrack > &  pLT,
int  labelNum 
)
explicit

Definition at line 28 of file LabelTextHandle.cpp.

30 : mpLT{ pLT }
31 , mLabelNum{ labelNum }
32{
33}
std::weak_ptr< LabelTrack > mpLT

◆ ~LabelTextHandle()

LabelTextHandle::~LabelTextHandle ( )
virtual

Definition at line 69 of file LabelTextHandle.cpp.

70{
71}

Member Function Documentation

◆ Cancel()

UIHandle::Result LabelTextHandle::Cancel ( AudacityProject pProject)
overridevirtual

Reimplemented from LabelDefaultClickHandle.

Definition at line 286 of file LabelTextHandle.cpp.

287{
288 auto result = LabelDefaultClickHandle::Cancel( pProject );
289 return result | RefreshCode::RefreshAll;
290}
Result Cancel(AudacityProject *pProject) override

References LabelDefaultClickHandle::Cancel(), and RefreshCode::RefreshAll.

Here is the call graph for this function:

◆ Click()

UIHandle::Result LabelTextHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Reimplemented from LabelDefaultClickHandle.

Definition at line 154 of file LabelTextHandle.cpp.

156{
157 auto pLT = mpLT.lock();
158 if (!pLT)
160
161 auto result = LabelDefaultClickHandle::Click( evt, pProject );
162
163 const wxMouseEvent &event = evt.event;
164 auto &viewInfo = ViewInfo::Get( *pProject );
165
166 HandleTextClick(*pProject, event);
167
168 return result | RefreshCode::RefreshCell;
169}
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
void HandleTextClick(AudacityProject &project, const wxMouseEvent &evt)
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235

References RefreshCode::Cancelled, LabelDefaultClickHandle::Click(), TrackPanelMouseEvent::event, ViewInfo::Get(), HandleTextClick(), mpLT, and RefreshCode::RefreshCell.

Here is the call graph for this function:

◆ Drag()

UIHandle::Result LabelTextHandle::Drag ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Reimplemented from LabelDefaultClickHandle.

Definition at line 224 of file LabelTextHandle.cpp.

226{
227 auto &project = *pProject;
228 using namespace RefreshCode;
229 auto result = LabelDefaultClickHandle::Drag( evt, pProject );
230
231 const wxMouseEvent &event = evt.event;
232 auto pLT = TrackList::Get( *pProject ).Lock(mpLT);
233 if(pLT)
235
236 // locate the initial mouse position
237 if (event.LeftIsDown()) {
238 if (mLabelTrackStartXPos == -1) {
239 mLabelTrackStartXPos = event.m_x;
240 mLabelTrackStartYPos = event.m_y;
241
242 auto pView = pLT ? &LabelTrackView::Get( *pLT ) : nullptr;
243 if (pLT && (pView->GetTextEditIndex( project ) != -1) &&
245 pLT->GetLabel(pView->GetTextEditIndex( project )),
249 }
250 // if initial mouse position in the text box
251 // then only drag text
252 if (mLabelTrackStartYPos == -1)
253 result |= RefreshCell;
254 }
255
256 return result;
257}
const auto project
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
void HandleTextDragRelease(AudacityProject &project, const wxMouseEvent &evt)
static LabelTrackView & Get(LabelTrack &)
static bool OverTextBox(const LabelStruct *pLabel, int x, int y)
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:1079
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:314
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16

References LabelDefaultClickHandle::Drag(), TrackPanelMouseEvent::event, TrackList::Get(), LabelTrackView::Get(), HandleTextDragRelease(), TrackList::Lock(), mLabelTrackStartXPos, mLabelTrackStartYPos, mpLT, LabelTrackView::OverTextBox(), project, and RefreshCode::RefreshCell.

Here is the call graph for this function:

◆ Enter()

void LabelTextHandle::Enter ( bool  forward,
AudacityProject  
)
overridevirtual

Reimplemented from UIHandle.

Definition at line 35 of file LabelTextHandle.cpp.

36{
37#ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
39#endif
40}
Result mChangeHighlight
Definition: UIHandle.h:152

References UIHandle::mChangeHighlight, and RefreshCode::RefreshCell.

◆ FindTrack()

std::shared_ptr< const Track > LabelTextHandle::FindTrack ( ) const
overridevirtual
Returns
pointer to associated track, if any

Implements UIHandle.

Definition at line 73 of file LabelTextHandle.cpp.

74{
75 return mpLT.lock();
76}

References mpLT.

Referenced by LabelTrackView::Draw().

Here is the caller graph for this function:

◆ GetLabelNum()

int LabelTextHandle::GetLabelNum ( ) const
inline

Definition at line 38 of file LabelTextHandle.h.

38{ return mLabelNum; }

References mLabelNum.

◆ HandlesRightClick()

bool LabelTextHandle::HandlesRightClick ( )
overridevirtual

Whether the handle has any special right-button handling.

If not, then Click() will not be called for right click. Default is always false

Reimplemented from UIHandle.

Definition at line 149 of file LabelTextHandle.cpp.

150{
151 return true;
152}

◆ HandleTextClick()

void LabelTextHandle::HandleTextClick ( AudacityProject project,
const wxMouseEvent &  evt 
)
private

Definition at line 78 of file LabelTextHandle.cpp.

79{
80 auto pTrack = mpLT.lock();
81 if (!pTrack)
82 return;
83
84 auto &view = LabelTrackView::Get( *pTrack );
85 if (evt.ButtonDown())
86 {
87 const auto selIndex = LabelTrackView::OverATextBox( *pTrack, evt.m_x, evt.m_y );
88 if ( selIndex != -1 ) {
89 if (evt.LeftDown()) {
90 mRightDragging = false;
91 // Find the NEW drag end
92 auto position = view.FindCursorPosition(selIndex, evt.m_x );
93
94 // Anchor shift-drag at the farther end of the previous highlight
95 // that is farther from the click, on Mac, for consistency with
96 // its text editors, but on the others, re-use the previous
97 // anchor.
98 auto initial = view.GetInitialCursorPosition();
99 if (evt.ShiftDown()) {
100#ifdef __WXMAC__
101 // Set the drag anchor at the end of the previous selection
102 // that is farther from the NEW drag end
103 const auto current = view.GetCurrentCursorPosition();
104 if ( abs( position - current ) > abs( position - initial ) )
105 initial = current;
106#else
107 // initial position remains as before
108#endif
109 }
110 else
111 initial = position;
112
113 view.SetTextSelection(selIndex, initial, position );
114 }
115 else
116 {
117 if (!view.IsTextSelected(project))
118 {
119 auto position = view.FindCursorPosition(selIndex, evt.m_x);
120 view.SetTextSelection(selIndex, position, position);
121 }
122 // Actually this might be right or middle down
123 mRightDragging = true;
124 }
125 // Middle click on GTK: paste from primary selection
126#if defined(__WXGTK__) && (HAVE_GTK)
127 if (evt.MiddleDown()) {
128 // Check for a click outside of the selected label's text box; in this
129 // case PasteSelectedText() will start a NEW label at the click
130 // location
131 if (!LabelTrackView::OverTextBox(&labelStruct, evt.m_x, evt.m_y))
132 view.ResetTextSelection();
133 double t = zoomInfo.PositionToTime(evt.m_x, r.x);
134 newSel = SelectedRegion(t, t);
135 }
136#endif
137 }
138#if defined(__WXGTK__) && (HAVE_GTK)
139 if (evt.MiddleDown()) {
140 // Paste text, making a NEW label if none is selected.
141 wxTheClipboard->UsePrimarySelection(true);
142 view.PasteSelectedText(project, newSel.t0(), newSel.t1());
143 wxTheClipboard->UsePrimarySelection(false);
144 }
145#endif
146 }
147}
bool mRightDragging
flag to tell if it's a valid dragging
static int OverATextBox(const LabelTrack &track, int xx, int yy)
Defines a selected portion of a project.

References LabelTrackView::Get(), mpLT, mRightDragging, LabelTrackView::OverATextBox(), LabelTrackView::OverTextBox(), and project.

Referenced by Click().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HandleTextDragRelease()

void LabelTextHandle::HandleTextDragRelease ( AudacityProject project,
const wxMouseEvent &  evt 
)
private

Definition at line 171 of file LabelTextHandle.cpp.

173{
174 auto pTrack = mpLT.lock();
175 if (!pTrack)
176 return;
177 auto &view = LabelTrackView::Get( *pTrack );
178
179 if(evt.LeftUp())
180 {
181#if 0
182 // AWD: Due to wxWidgets bug #7491 (fix not ported to 2.8 branch) we
183 // should never write the primary selection. We can enable this block
184 // when we move to the 3.0 branch (or if a fixed 2.8 version is released
185 // and we can do a runtime version check)
186#if defined (__WXGTK__) && defined (HAVE_GTK)
187 // On GTK, if we just dragged out a text selection, set the primary
188 // selection
189 if (mInitialCursorPos != mCurrentCursorPos) {
190 wxTheClipboard->UsePrimarySelection(true);
191 CopySelectedText();
192 wxTheClipboard->UsePrimarySelection(false);
193 }
194#endif
195#endif
196
197 return;
198 }
199
200 if(evt.Dragging())
201 {
202 auto index = view.GetTextEditIndex(project);
203 if (!mRightDragging && index != -1)
204 // Update drag end
205 view.SetCurrentCursorPosition(view.FindCursorPosition(index, evt.m_x ));
206 return;
207 }
208
209 if (evt.RightUp())
210 {
211 auto index = view.GetTextEditIndex(project);
212 if(index != -1 &&
213 LabelTrackView::OverTextBox(pTrack->GetLabel(index), evt.m_x, evt.m_y))
214 {
215 // popup menu for editing
216 // TODO: handle context menus via CellularPanel?
217 view.ShowContextMenu( project );
218 }
219 }
220
221 return;
222}

References LabelTrackView::Get(), mpLT, mRightDragging, LabelTrackView::OverTextBox(), and project.

Referenced by Drag(), and Release().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HitPreview()

HitTestPreview LabelTextHandle::HitPreview ( )
staticprivate

Definition at line 42 of file LabelTextHandle.cpp.

43{
44 static auto ibeamCursor =
45 ::MakeCursor(wxCURSOR_IBEAM, IBeamCursorXpm, 17, 16);
46 return {
47 XO("Click to edit label text"),
48 ibeamCursor.get()
49 };
50}
XO("Cut/Copy/Paste")
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:189

References MakeCursor(), and XO().

Referenced by Preview().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ HitTest()

UIHandlePtr LabelTextHandle::HitTest ( std::weak_ptr< LabelTextHandle > &  holder,
const wxMouseState &  state,
const std::shared_ptr< LabelTrack > &  pLT 
)
static

Definition at line 52 of file LabelTextHandle.cpp.

55{
56 // If Control is down, let the select handle be hit instead
57 int labelNum;
58 if (!state.ControlDown() &&
59 (labelNum =
60 LabelTrackView::OverATextBox(*pLT, state.m_x, state.m_y) ) >= 0) {
61 auto result = std::make_shared<LabelTextHandle>( pLT, labelNum );
62 result = AssignUIHandlePtr(holder, result);
63 return result;
64 }
65
66 return {};
67}
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:164

References AssignUIHandlePtr(), and LabelTrackView::OverATextBox().

Referenced by LabelTrackView::DetailedHitTest().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ operator=()

LabelTextHandle & LabelTextHandle::operator= ( const LabelTextHandle )
default

◆ Preview()

HitTestPreview LabelTextHandle::Preview ( const TrackPanelMouseState state,
AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 259 of file LabelTextHandle.cpp.

261{
262 return HitPreview();
263}
static HitTestPreview HitPreview()

References HitPreview().

Here is the call graph for this function:

◆ Release()

UIHandle::Result LabelTextHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
overridevirtual

Reimplemented from LabelDefaultClickHandle.

Definition at line 265 of file LabelTextHandle.cpp.

268{
269 auto result = LabelDefaultClickHandle::Release( evt, pProject, pParent );
270
271 // Only selected a part of a text string and changed track selectedness.
272 // No undoable effects.
273
274 const wxMouseEvent &event = evt.event;
275 auto pLT = TrackList::Get( *pProject ).Lock(mpLT);
276 if (pLT)
277 HandleTextDragRelease( *pProject, event );
278
279 // handle mouse left button up
280 if (event.LeftUp())
282
283 return result | RefreshCode::RefreshNone;
284}
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override

References TrackPanelMouseEvent::event, TrackList::Get(), HandleTextDragRelease(), TrackList::Lock(), mLabelTrackStartXPos, mpLT, RefreshCode::RefreshNone, and LabelDefaultClickHandle::Release().

Here is the call graph for this function:

Member Data Documentation

◆ mLabelNum

int LabelTextHandle::mLabelNum { -1 }
private

Definition at line 67 of file LabelTextHandle.h.

Referenced by GetLabelNum().

◆ mLabelTrackStartXPos

int LabelTextHandle::mLabelTrackStartXPos { -1 }
private

Definition at line 68 of file LabelTextHandle.h.

Referenced by Drag(), and Release().

◆ mLabelTrackStartYPos

int LabelTextHandle::mLabelTrackStartYPos { -1 }
private

Definition at line 69 of file LabelTextHandle.h.

Referenced by Drag().

◆ mpLT

std::weak_ptr<LabelTrack> LabelTextHandle::mpLT {}
private

◆ mRightDragging

bool LabelTextHandle::mRightDragging { false }
private

flag to tell if it's a valid dragging

Definition at line 72 of file LabelTextHandle.h.

Referenced by HandleTextClick(), and HandleTextDragRelease().


The documentation for this class was generated from the following files: