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 "../../Menus.h"
23#include "../../RefreshCode.h"
24#include "../../TrackPanelMouseEvent.h"
25#include "ViewInfo.h"
26#include "../../widgets/wxWidgetsWindowPlacement.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 *pProject)
48{
49 const auto items = GetMenuItems( rect, pPoint, pProject );
50 if (items.empty())
52
53 // Set up command context with extras
54 CommandContext context{ *pProject };
55 SelectedRegion region;
56 if (pPoint) {
57 auto time = ViewInfo::Get(*pProject).PositionToTime(pPoint->x, rect.x);
58 region = { time, time };
59 context.temporarySelection.pSelectedRegion = &region;
60 }
61 context.temporarySelection.pTrack = FindTrack().get();
62
63 auto &commandManager = CommandManager::Get(*pProject);
64 auto flags = MenuManager::Get( *pProject ).GetUpdateFlags();
65
66 // Common dispatcher for the menu items
67 auto dispatcher = [&]( wxCommandEvent &evt ){
68 auto idx = evt.GetId() - 1;
69 if (idx >= 0 && idx < items.size()) {
70 if (auto &action = items[idx].action)
71 action( context );
72 else
73 commandManager.HandleTextualCommand(
74 items[idx].symbol.Internal(), context, flags, false);
75 }
76 };
77
78 wxMenu menu;
79 int ii = 1;
80 for (const auto &item: items) {
81 if ( const auto &commandID = item.symbol.Internal();
82 commandID.empty() )
83 menu.AppendSeparator();
84 else {
85 // Generate a menu item with the same shortcut key as in the toolbar
86 // menu, and as determined by keyboard preferences
87 auto label =
88 commandManager.FormatLabelForMenu( commandID, &item.symbol.Msgid() );
89 menu.Append( ii, label );
90 menu.Bind( wxEVT_COMMAND_MENU_SELECTED, dispatcher );
91 bool enabled = item.enabled &&
92 (item.action || commandManager.GetEnabled( commandID ));
93 menu.Enable( ii, enabled );
94 }
95 ++ii;
96 }
97
98 BasicUI::Point point;
99 if (pPoint)
100 point = { pPoint->x, pPoint->y };
101 BasicMenu::Handle{ &menu }.Popup(
102 wxWidgetsWindowPlacement{ pParent },
103 point
104 );
105
107}
108
110(const TrackPanelMouseEvent &evt, AudacityProject *pProject)
111{
112 auto &hook = MouseWheelHook::Get();
113 return hook ? hook( evt, pProject ) : RefreshCode::Cancelled;
114}
115
116CommonTrackCell::CommonTrackCell( const std::shared_ptr< Track > &parent )
117 : mwTrack { parent }
118{}
119
121
122void CommonTrackCell::Reparent( const std::shared_ptr<Track> &parent )
123{
124 mwTrack = parent;
125}
126
127std::shared_ptr<Track> CommonTrackCell::DoFindTrack()
128{
129 return mwTrack.lock();
130}
Toolkit-neutral facade for basic user interface services.
TranslatableString label
Definition: TagsEditor.cpp:164
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)
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:69
CommandFlag GetUpdateFlags(bool checkActive=false) const
Definition: Menus.cpp:533
Defines a selected portion of a project.
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:234
double PositionToTime(wxInt64 position, wxInt64 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.