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 "../../commands/CommandContext.h"
20#include "../../commands/CommandManager.h"
21#include "../../HitTestResult.h"
22#include "../../RefreshCode.h"
23#include "../../TrackPanelMouseEvent.h"
24#include "ViewInfo.h"
25#include "../../widgets/wxWidgetsWindowPlacement.h"
26
28{
29}
30
33{
34 static wxCursor defaultCursor{ wxCURSOR_ARROW };
35 return { {}, &defaultCursor, {} };
36}
37
39 const wxRect&, const wxPoint *, AudacityProject * )
40 -> std::vector<MenuItem>
41{
42 return {};
43}
44
45unsigned CommonTrackPanelCell::DoContextMenu( const wxRect &rect,
46 wxWindow *pParent, const wxPoint *pPoint, AudacityProject *pProject)
47{
48 const auto items = GetMenuItems( rect, pPoint, pProject );
49 if (items.empty())
51
52 // Set up command context with extras
53 CommandContext context{ *pProject };
54 SelectedRegion region;
55 if (pPoint) {
56 auto time = ViewInfo::Get(*pProject).PositionToTime(pPoint->x, rect.x);
57 region = { time, time };
58 context.temporarySelection.pSelectedRegion = &region;
59 }
60 context.temporarySelection.pTrack = FindTrack().get();
61
62 auto &commandManager = CommandManager::Get(*pProject);
63 auto flags = MenuManager::Get( *pProject ).GetUpdateFlags();
64
65 // Common dispatcher for the menu items
66 auto dispatcher = [&]( wxCommandEvent &evt ){
67 auto idx = evt.GetId() - 1;
68 if (idx >= 0 && idx < items.size()) {
69 if (auto &action = items[idx].action)
70 action( context );
71 else
72 commandManager.HandleTextualCommand(
73 items[idx].symbol.Internal(), context, flags, false);
74 }
75 };
76
77 wxMenu menu;
78 int ii = 1;
79 for (const auto &item: items) {
80 if ( const auto &commandID = item.symbol.Internal();
81 commandID.empty() )
82 menu.AppendSeparator();
83 else {
84 // Generate a menu item with the same shortcut key as in the toolbar
85 // menu, and as determined by keyboard preferences
86 auto label =
87 commandManager.FormatLabelForMenu( commandID, &item.symbol.Msgid() );
88 menu.Append( ii, label );
89 menu.Bind( wxEVT_COMMAND_MENU_SELECTED, dispatcher );
90 bool enabled = item.enabled &&
91 (item.action || commandManager.GetEnabled( commandID ));
92 menu.Enable( ii, enabled );
93 }
94 ++ii;
95 }
96
97 BasicUI::Point point;
98 if (pPoint)
99 point = { pPoint->x, pPoint->y };
100 BasicMenu::Handle{ &menu }.Popup(
101 wxWidgetsWindowPlacement{ pParent },
102 point
103 );
104
106}
107
109(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
110{
111 auto &hook = MouseWheelHook::Get();
112 return hook ? hook( evt, pProject ) : RefreshCode::Cancelled;
113}
114
115CommonTrackCell::CommonTrackCell( const std::shared_ptr< Track > &parent )
116 : mwTrack { parent }
117{}
118
120
121void CommonTrackCell::Reparent( const std::shared_ptr<Track> &parent )
122{
123 mwTrack = parent;
124}
125
126std::shared_ptr<Track> CommonTrackCell::DoFindTrack()
127{
128 return mwTrack.lock();
129}
Toolkit-neutral facade for basic user interface services.
TranslatableString label
Definition: TagsEditor.cpp:163
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
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)
std::shared_ptr< Track > DoFindTrack() override
std::weak_ptr< Track > mwTrack
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)
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
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:71
CommandFlag GetUpdateFlags(bool checkActive=false) const
Definition: Menus.cpp:553
Defines a selected portion of a project.
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:235
double PositionToTime(wxInt64 position, wxInt64 origin=0, bool ignoreFisheye=false) const
Definition: ZoomInfo.cpp:41
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.