| 1 |
/*!******************************************************************** |
| 2 |
* |
| 3 |
Audacity: A Digital Audio Editor |
| 4 |
|
| 5 |
WaveTrackAffordanceControls.h |
| 6 |
|
| 7 |
Vitaly Sverchinsky |
| 8 |
|
| 9 |
**********************************************************************/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include <wx/font.h> |
| 14 |
|
| 15 |
#include "Channel.h" |
| 16 |
#include "Observer.h" |
| 17 |
#include "ViewInfo.h" |
| 18 |
#include "WaveTrack.h" |
| 19 |
#include "tracks/ui/CommonTrackPanelCell.h" |
| 20 |
#include "tracks/ui/TextEditHelper.h" |
| 21 |
|
| 22 |
|
| 23 |
struct TrackListEvent; |
| 24 |
|
| 25 |
class AffordanceHandle; |
| 26 |
class SelectHandle; |
| 27 |
class WaveClip; |
| 28 |
class TrackPanelResizeHandle; |
| 29 |
class WaveClipTitleEditHandle; |
| 30 |
class ClipOverflowButtonHandle; |
| 31 |
class ClipPitchAndSpeedButtonHandle; |
| 32 |
class WaveTrackAffordanceHandle; |
| 33 |
class WaveClipAdjustBorderHandle; |
| 34 |
class TrackList; |
| 35 |
|
| 36 |
//Handles clip movement, selection, navigation and |
| 37 |
//allow name change |
| 38 |
class AUDACITY_DLL_API WaveTrackAffordanceControls : |
| 39 |
public CommonTrackCell, |
| 40 |
public TextEditDelegate, |
| 41 |
public std::enable_shared_from_this<WaveTrackAffordanceControls> |
| 42 |
{ |
| 43 |
using IntervalIterator = ChannelGroup::IntervalIterator<WaveTrack::Interval>; |
| 44 |
|
| 45 |
IntervalIterator mFocusInterval; |
| 46 |
std::weak_ptr<ClipOverflowButtonHandle> mOverflowButtonHandle; |
| 47 |
std::weak_ptr<ClipPitchAndSpeedButtonHandle> mPitchButtonHandle; |
| 48 |
std::weak_ptr<ClipPitchAndSpeedButtonHandle> mSpeedButtonHandle; |
| 49 |
std::weak_ptr<WaveTrackAffordanceHandle> mAffordanceHandle; |
| 50 |
std::weak_ptr<TrackPanelResizeHandle> mResizeHandle; |
| 51 |
std::weak_ptr<WaveClipTitleEditHandle> mTitleEditHandle; |
| 52 |
std::weak_ptr<SelectHandle> mSelectHandle; |
| 53 |
std::weak_ptr<WaveClipAdjustBorderHandle> mClipBorderAdjustHandle; |
| 54 |
|
| 55 |
IntervalIterator mEditedInterval; |
| 56 |
std::shared_ptr<TextEditHelper> mTextEditHelper; |
| 57 |
|
| 58 |
wxFont mClipNameFont; |
| 59 |
|
| 60 |
//Helper container used to track clips names visibility |
| 61 |
std::vector<IntervalIterator> mVisibleIntervals; |
| 62 |
|
| 63 |
public: |
| 64 |
WaveTrackAffordanceControls(const std::shared_ptr<Track>& pTrack); |
| 65 |
|
| 66 |
std::vector<UIHandlePtr> HitTest(const TrackPanelMouseState& state, const AudacityProject* pProject) override; |
| 67 |
|
| 68 |
void Draw(TrackPanelDrawingContext& context, const wxRect& rect, unsigned iPass) override; |
| 69 |
|
| 70 |
IntervalIterator GetSelectedInterval() const; |
| 71 |
|
| 72 |
unsigned CaptureKey |
| 73 |
(wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent, |
| 74 |
AudacityProject* project) override; |
| 75 |
|
| 76 |
unsigned KeyDown (wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent, |
| 77 |
AudacityProject* project) override; |
| 78 |
|
| 79 |
unsigned Char |
| 80 |
(wxKeyEvent& event, ViewInfo& viewInfo, wxWindow* pParent, |
| 81 |
AudacityProject* project) override; |
| 82 |
|
| 83 |
unsigned LoseFocus(AudacityProject *project) override; |
| 84 |
|
| 85 |
void OnTextEditFinished(AudacityProject* project, const wxString& text) override; |
| 86 |
void OnTextEditCancelled(AudacityProject* project) override; |
| 87 |
void OnTextModified(AudacityProject* project, const wxString& text) override; |
| 88 |
void OnTextContextMenu(AudacityProject* project, const wxPoint& position) override; |
| 89 |
|
| 90 |
unsigned OnAffordanceClick(const TrackPanelMouseEvent& event, AudacityProject* project); |
| 91 |
|
| 92 |
bool OnTextCopy(AudacityProject& project); |
| 93 |
bool OnTextCut(AudacityProject& project); |
| 94 |
bool OnTextPaste(AudacityProject& project); |
| 95 |
bool OnTextSelect(AudacityProject& project); |
| 96 |
|
| 97 |
void StartEditSelectedClipName(AudacityProject& project); |
| 98 |
|
| 99 |
void StartEditSelectedClipSpeed(AudacityProject& project); |
| 100 |
|
| 101 |
void OnRenderClipStretching(AudacityProject& project) const; |
| 102 |
|
| 103 |
std::vector<MenuItem> GetMenuItems( |
| 104 |
const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject ) |
| 105 |
override; |
| 106 |
private: |
| 107 |
|
| 108 |
bool IsIntervalVisible(const IntervalIterator& it) const noexcept; |
| 109 |
///@brief Starts in-place clip name editing or shows a Clip Name Edit dialog, depending on prefs |
| 110 |
///@param clip to be edited. Should belong to the same `WaveTrack` as returned by `FindTrack()` |
| 111 |
bool StartEditClipName(AudacityProject& project, IntervalIterator it); |
| 112 |
|
| 113 |
void ResetClipNameEdit(); |
| 114 |
|
| 115 |
void OnTrackListEvent(const TrackListEvent& evt); |
| 116 |
|
| 117 |
void OnSelectionChange(NotifyingSelectedRegionMessage); |
| 118 |
|
| 119 |
unsigned ExitTextEditing(); |
| 120 |
|
| 121 |
std::shared_ptr<TextEditHelper> MakeTextEditHelper(const wxString& text); |
| 122 |
|
| 123 |
Observer::Subscription mTrackListEventSubscription; |
| 124 |
Observer::Subscription mSelectionChangeSubscription; |
| 125 |
}; |