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

#include <LabelTextHandle.h>

Inheritance diagram for LabelTextHandle:
LabelDefaultClickHandle UIHandle

Public Member Functions

LabelTextHandleoperator= (const LabelTextHandle &)=default
 
 LabelTextHandle (const std::shared_ptr< LabelTrack > &pLT, int labelNum)
 
virtual ~LabelTextHandle ()
 
std::shared_ptr< LabelTrackGetTrack () const
 
int GetLabelNum () const
 
void Enter (bool forward) override
 
Result Click (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
Result Drag (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 
HitTestPreview Preview (const TrackPanelMouseState &state, const 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
 
- Public Member Functions inherited from UIHandle
virtual ~UIHandle ()=0
 
virtual bool HasRotation () const
 
virtual bool Rotate (bool forward)
 
virtual bool HasEscape () const
 
virtual bool Escape ()
 
virtual void DrawExtras (DrawingPass pass, wxDC *dc, const wxRegion &updateRegion, const wxRect &panelRect)
 
virtual bool StopsOnKeystroke ()
 
virtual void OnProjectChange (AudacityProject *pProject)
 
Result GetChangeHighlight () const
 
void SetChangeHighlight (Result val)
 

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 Private Member Functions

static HitTestPreview HitPreview ()
 

Private Attributes

std::weak_ptr< LabelTrackmpLT {}
 
int mLabelNum { -1 }
 
int mLabelTrackStartXPos { -1 }
 
int mLabelTrackStartYPos { -1 }
 
SelectedRegion mSelectedRegion {}
 
std::shared_ptr
< SelectionStateChanger
mChanger
 

Additional Inherited Members

- Public Types inherited from UIHandle
enum  DrawingPass { Cells, Panel }
 
using Result = unsigned
 
using Cell = TrackPanelCell
 
- Protected Attributes inherited from UIHandle
Result mChangeHighlight { 0 }
 

Detailed Description

Definition at line 23 of file LabelTextHandle.h.

Constructor & Destructor Documentation

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

Definition at line 23 of file LabelTextHandle.cpp.

24  : mpLT{ pLT }
25  , mLabelNum{ labelNum }
26 {
27 }
std::weak_ptr< LabelTrack > mpLT
LabelTextHandle::~LabelTextHandle ( )
virtual

Definition at line 62 of file LabelTextHandle.cpp.

63 {
64 }

Member Function Documentation

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

Reimplemented from LabelDefaultClickHandle.

Definition at line 194 of file LabelTextHandle.cpp.

References LabelDefaultClickHandle::Cancel(), AudacityProject::GetViewInfo(), mSelectedRegion, RefreshCode::RefreshAll, and ViewInfo::selectedRegion.

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 }
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
SelectedRegion mSelectedRegion
const ViewInfo & GetViewInfo() const
Definition: Project.h:207
UIHandle::Result LabelTextHandle::Click ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Reimplemented from LabelDefaultClickHandle.

Definition at line 67 of file LabelTextHandle.cpp.

References RefreshCode::Cancelled, LabelDefaultClickHandle::Click(), TrackPanelMouseEvent::event, TrackListIterator::First(), AudacityProject::GetMixerBoard(), Track::GetSelected(), AudacityProject::GetSelectionState(), AudacityProject::GetTracks(), AudacityProject::GetViewInfo(), AudacityProject::IsAudioActive(), AudacityProject::ModifyState(), TrackListIterator::Next(), TrackPanelMouseEvent::rect, RefreshCode::RefreshCell, ViewInfo::selectedRegion, and RefreshCode::UpdateSelection.

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 
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 }
A list of TrackListNode items.
Definition: Track.h:619
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
std::shared_ptr< SelectionStateChanger > mChanger
bool GetSelected() const
Definition: Track.h:276
MixerBoard * GetMixerBoard()
Definition: Project.h:516
Result Click(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
Fundamental data object of Audacity, placed in the TrackPanel. Classes derived form it include the Wa...
Definition: Track.h:102
SelectionState & GetSelectionState()
Definition: Project.h:309
bool IsAudioActive() const
Definition: Project.cpp:1454
std::weak_ptr< LabelTrack > mpLT
void ModifyState(bool bWantsAutoSave)
Definition: Project.cpp:4747
An iterator for a TrackList.
Definition: Track.h:402
SelectedRegion mSelectedRegion
TrackList * GetTracks()
Definition: Project.h:192
const ViewInfo & GetViewInfo() const
Definition: Project.h:207
UIHandle::Result LabelTextHandle::Drag ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overridevirtual

Reimplemented from LabelDefaultClickHandle.

Definition at line 129 of file LabelTextHandle.cpp.

References LabelDefaultClickHandle::Drag(), TrackPanelMouseEvent::event, AudacityProject::GetTracks(), TrackList::Lock(), and RefreshCode::RefreshCell.

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()),
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 }
Result Drag(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:734
std::weak_ptr< LabelTrack > mpLT
TrackList * GetTracks()
Definition: Project.h:192
void LabelTextHandle::Enter ( bool  forward)
overridevirtual

Reimplemented from UIHandle.

Definition at line 29 of file LabelTextHandle.cpp.

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

30 {
31 #ifdef EXPERIMENTAL_TRACK_PANEL_HIGHLIGHTING
33 #endif
34 }
Result mChangeHighlight
Definition: UIHandle.h:150
int LabelTextHandle::GetLabelNum ( ) const
inline

Definition at line 39 of file LabelTextHandle.h.

References mLabelNum.

39 { return mLabelNum; }
std::shared_ptr<LabelTrack> LabelTextHandle::GetTrack ( ) const
inline

Definition at line 38 of file LabelTextHandle.h.

References mpLT.

Referenced by LabelTrack::Draw().

38 { return mpLT.lock(); }
std::weak_ptr< LabelTrack > mpLT
HitTestPreview LabelTextHandle::HitPreview ( )
staticprivate

Definition at line 36 of file LabelTextHandle.cpp.

References _(), and MakeCursor().

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 }
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
std::unique_ptr< wxCursor > MakeCursor(int WXUNUSED(CursorId), const char *const pXpm[36], int HotX, int HotY)
Definition: TrackPanel.cpp:274
UIHandlePtr LabelTextHandle::HitTest ( std::weak_ptr< LabelTextHandle > &  holder,
const wxMouseState &  state,
const std::shared_ptr< LabelTrack > &  pLT 
)
static

Definition at line 47 of file LabelTextHandle.cpp.

References AssignUIHandlePtr().

Referenced by LabelTrack::DetailedHitTest().

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 }
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:162
LabelTextHandle& LabelTextHandle::operator= ( const LabelTextHandle )
default
HitTestPreview LabelTextHandle::Preview ( const TrackPanelMouseState state,
const AudacityProject pProject 
)
overridevirtual

Implements UIHandle.

Definition at line 163 of file LabelTextHandle.cpp.

164 {
165  return HitPreview();
166 }
static HitTestPreview HitPreview()
UIHandle::Result LabelTextHandle::Release ( const TrackPanelMouseEvent event,
AudacityProject pProject,
wxWindow *  pParent 
)
overridevirtual

Reimplemented from LabelDefaultClickHandle.

Definition at line 169 of file LabelTextHandle.cpp.

References TrackPanelMouseEvent::event, AudacityProject::GetTracks(), TrackList::Lock(), RefreshCode::RefreshNone, and LabelDefaultClickHandle::Release().

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())
190 
191  return result | RefreshCode::RefreshNone;
192 }
std::shared_ptr< SelectionStateChanger > mChanger
std::shared_ptr< Subclass > Lock(const std::weak_ptr< Subclass > &wTrack)
Definition: Track.h:734
std::weak_ptr< LabelTrack > mpLT
Result Release(const TrackPanelMouseEvent &event, AudacityProject *pProject, wxWindow *pParent) override
TrackList * GetTracks()
Definition: Project.h:192

Member Data Documentation

std::shared_ptr<SelectionStateChanger> LabelTextHandle::mChanger
private

Definition at line 65 of file LabelTextHandle.h.

int LabelTextHandle::mLabelNum { -1 }
private

Definition at line 61 of file LabelTextHandle.h.

Referenced by GetLabelNum().

int LabelTextHandle::mLabelTrackStartXPos { -1 }
private

Definition at line 62 of file LabelTextHandle.h.

int LabelTextHandle::mLabelTrackStartYPos { -1 }
private

Definition at line 63 of file LabelTextHandle.h.

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

Definition at line 60 of file LabelTextHandle.h.

Referenced by GetTrack().

SelectedRegion LabelTextHandle::mSelectedRegion {}
private

Definition at line 64 of file LabelTextHandle.h.

Referenced by Cancel().


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