Audacity 3.2.0
CommonTrackPanelCell.cpp
Go to the documentation of this file.
1/**********************************************************************
2
3Audacity: A Digital Audio Editor
4
5CommonTrackPanelCell.cpp
6
7Paul Licameli split from TrackPanel.cpp
8
9**********************************************************************/
10
12
13#include <wx/cursor.h>
14#include <wx/event.h>
15#include <wx/menu.h>
16
17#include "../../widgets/BasicMenu.h"
18#include "BasicUI.h"
19#include "CommandContext.h"
20#include "CommandManager.h"
21#include "../../HitTestResult.h"
22#include "../../RefreshCode.h"
23#include "../../TrackPanelMouseEvent.h"
24#include "Track.h"
25#include "ViewInfo.h"
27
29{
30}
31
34{
35 static wxCursor defaultCursor{ wxCURSOR_ARROW };
36 return { {}, &defaultCursor, {} };
37}
38
40 const wxRect&, const wxPoint *, AudacityProject * )
41 -> std::vector<MenuItem>
42{
43 return {};
44}
45
46unsigned CommonTrackPanelCell::DoContextMenu( const wxRect &rect,
47 wxWindow *pParent, const wxPoint *pPoint, AudacityProject *const pProject)
48{
49 const auto items = GetMenuItems( rect, pPoint, pProject );
50 if (items.empty())
52
53 auto &commandManager = CommandManager::Get(*pProject);
54 commandManager.UpdateMenus();
55
56 // Set up command context with extras
57 CommandContext context{ *pProject };
58 SelectedRegion region;
59 if (pPoint) {
60 auto time = ViewInfo::Get(*pProject).PositionToTime(pPoint->x, rect.x);
61 region = { time, time };
62 context.temporarySelection.pSelectedRegion = &region;
63 }
64 context.temporarySelection.pTrack = FindTrack().get();
65
66 auto flags = commandManager.GetUpdateFlags();
67
68 // Common dispatcher for the menu items
69 auto dispatcher = [&]( wxCommandEvent &evt ){
70 auto idx = evt.GetId() - 1;
71 if (idx >= 0 && idx < items.size()) {
72 if (auto &action = items[idx].action)
73 action( context );
74 else
75 commandManager.HandleTextualCommand(
76 items[idx].symbol.Internal(), context, flags, false);
77 }
78 };
79
80 wxMenu menu;
81 int ii = 1;
82 for (const auto &item: items) {
83 if ( const auto &commandID = item.symbol.Internal();
84 commandID.empty() )
85 menu.AppendSeparator();
86 else {
87 // Generate a menu item with the same shortcut key as in the toolbar
88 // menu, and as determined by keyboard preferences
89 auto label =
90 commandManager.FormatLabelForMenu( commandID, &item.symbol.Msgid() );
91 menu.Append( ii, label );
92 menu.Bind( wxEVT_COMMAND_MENU_SELECTED, dispatcher );
93 bool enabled = item.enabled &&
94 (item.action || commandManager.GetEnabled( commandID ));
95 menu.Enable( ii, enabled );
96 }
97 ++ii;
98 }
99
100 BasicUI::Point point;
101 if (pPoint)
102 point = { pPoint->x, pPoint->y };
103 BasicMenu::Handle{ &menu }.Popup(
104 wxWidgetsWindowPlacement{ pParent },
105 point
106 );
107
109}
110
112(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
113{
114 auto &hook = MouseWheelHook::Get();
115 return hook ? hook( evt, pProject ) : RefreshCode::Cancelled;
116}
117
118CommonTrackCell::CommonTrackCell(const std::shared_ptr<Track> &parent)
119 : mwTrack{ parent }
120{
121}
122
124
125void CommonTrackCell::Reparent(const std::shared_ptr<Track> &parent)
126{
127 mwTrack = parent;
128}
129
130std::shared_ptr<Track> CommonTrackCell::DoFindTrack()
131{
132 return mwTrack.lock();
133}
134
135CommonChannelCell::CommonChannelCell(const std::shared_ptr<Channel> &parent)
136 : mwChannel{ parent }
137{
138}
139
141
143 const std::shared_ptr<Track> &parent, size_t iChannel)
144{
145 mwChannel = parent->NthChannel(iChannel);
146}
147
148std::shared_ptr<Track> CommonChannelCell::DoFindTrack()
149{
150 Track *pTrack{};
151 if (const auto pChannel = mwChannel.lock())
152 pTrack = dynamic_cast<Track *>(&pChannel->GetChannelGroup());
153 return pTrack ? pTrack->SharedPointer() : nullptr;
154}
155
156std::shared_ptr<Channel> CommonChannelCell::DoFindChannel()
157{
158 return mwChannel.lock();
159}
160
161std::shared_ptr<const Channel> CommonChannelCell::DoFindChannel() const
162{
163 return const_cast<CommonChannelCell*>(this)->FindChannel();
164}
Toolkit-neutral facade for basic user interface services.
TranslatableString label
Definition: TagsEditor.cpp:165
declares abstract base class Track, TrackList, and iterators over TrackList
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
void Popup(const BasicUI::WindowPlacement &window, const Point &pos={})
Display the menu at pos, invoke at most one action, then hide it.
Definition: BasicMenu.cpp:209
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
static CommandManager & Get(AudacityProject &project)
CommonChannelCell(const std::shared_ptr< Channel > &pChannel)
Construct from a channel.
std::shared_ptr< Track > DoFindTrack() override
void Reparent(const std::shared_ptr< Track > &parent, size_t iChannel) override
Object may be shared among tracks but hold a special back-pointer to one of them; reassign it.
auto FindChannel() -> std::shared_ptr< Subtype >
May return null.
std::shared_ptr< Channel > DoFindChannel()
std::weak_ptr< Channel > mwChannel
std::shared_ptr< Track > DoFindTrack() override
void Reparent(const std::shared_ptr< Track > &parent) override
Object may be shared among tracks but hold a special back-pointer to one of them; reassign it.
CommonTrackCell(const std::shared_ptr< Track > &pTrack)
Construct from a track.
std::weak_ptr< Track > mwTrack
unsigned HandleWheelRotation(const TrackPanelMouseEvent &event, AudacityProject *pProject) override
HitTestPreview DefaultPreview(const TrackPanelMouseState &, const AudacityProject *) override
std::shared_ptr< Track > FindTrack()
virtual std::vector< MenuItem > GetMenuItems(const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject)
Return a list of items for DoContextMenu() (empties for separators)
unsigned DoContextMenu(const wxRect &rect, wxWindow *pParent, const wxPoint *pPosition, AudacityProject *pProject) override
Defines a selected portion of a project.
Abstract base class for an object holding data associated with points on a time axis.
Definition: Track.h:110
std::shared_ptr< Subclass > SharedPointer()
Definition: Track.h:146
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
double PositionToTime(int64 position, int64 origin=0, bool ignoreFisheye=false) const
Definition: ZoomInfo.cpp:34
A pair of screen coordinates, x increasing rightward, y downward.
Definition: BasicUIPoint.h:18
Window placement information for wxWidgetsBasicUI can be constructed from a wxWindow pointer.