Audacity 3.2.0
Classes | Public Member Functions | Protected Member Functions | List of all members
CommonTrackPanelCell Class Referenceabstract

#include <CommonTrackPanelCell.h>

Inheritance diagram for CommonTrackPanelCell:
[legend]
Collaboration diagram for CommonTrackPanelCell:
[legend]

Classes

struct  MenuItem
 
struct  MouseWheelHook
 

Public Member Functions

 CommonTrackPanelCell ()
 
virtual ~CommonTrackPanelCell ()=0
 
HitTestPreview DefaultPreview (const TrackPanelMouseState &, const AudacityProject *) override
 
std::shared_ptr< TrackFindTrack ()
 
std::shared_ptr< const TrackFindTrack () const
 
virtual std::vector< MenuItemGetMenuItems (const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject)
 Return a list of items for DoContextMenu() (empties for separators) More...
 
- Public Member Functions inherited from TrackPanelCell
 TrackPanelCell ()=default
 
 TrackPanelCell (const TrackPanelCell &)=delete
 
TrackPanelCelloperator= (const TrackPanelCell &)=delete
 
virtual ~TrackPanelCell ()=0
 
virtual HitTestPreview DefaultPreview (const TrackPanelMouseState &state, const AudacityProject *pProject)
 
virtual std::vector< UIHandlePtrHitTest (const TrackPanelMouseState &state, const AudacityProject *pProject)=0
 
virtual unsigned HandleWheelRotation (const TrackPanelMouseEvent &event, AudacityProject *pProject)
 
virtual std::shared_ptr< TrackPanelCellContextMenuDelegate ()
 
virtual unsigned DoContextMenu (const wxRect &rect, wxWindow *pParent, const wxPoint *pPosition, AudacityProject *pProject)
 
virtual unsigned CaptureKey (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
 
virtual unsigned KeyDown (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
 
virtual unsigned KeyUp (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
 
virtual unsigned Char (wxKeyEvent &event, ViewInfo &viewInfo, wxWindow *pParent, AudacityProject *project)
 
virtual unsigned LoseFocus (AudacityProject *project)
 
- Public Member Functions inherited from TrackPanelNode
 TrackPanelNode ()
 
virtual ~TrackPanelNode ()=0
 
- Public Member Functions inherited from TrackPanelDrawable
virtual ~TrackPanelDrawable ()=0
 
virtual void Draw (TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass)
 
virtual wxRect DrawingArea (TrackPanelDrawingContext &context, const wxRect &rect, const wxRect &panelRect, unsigned iPass)
 

Protected Member Functions

virtual std::shared_ptr< TrackDoFindTrack ()=0
 
unsigned DoContextMenu (const wxRect &rect, wxWindow *pParent, const wxPoint *pPosition, AudacityProject *pProject) override
 
unsigned HandleWheelRotation (const TrackPanelMouseEvent &event, AudacityProject *pProject) override
 

Additional Inherited Members

- Static Public Member Functions inherited from TrackPanelDrawable
static wxRect MaximizeWidth (const wxRect &rect, const wxRect &panelRect)
 
static wxRect MaximizeHeight (const wxRect &rect, const wxRect &panelRect)
 

Detailed Description

Definition at line 32 of file CommonTrackPanelCell.h.

Constructor & Destructor Documentation

◆ CommonTrackPanelCell()

CommonTrackPanelCell::CommonTrackPanelCell ( )
inline

Definition at line 41 of file CommonTrackPanelCell.h.

42 {}

◆ ~CommonTrackPanelCell()

CommonTrackPanelCell::~CommonTrackPanelCell ( )
pure virtual

Definition at line 28 of file CommonTrackPanelCell.cpp.

29{
30}

Member Function Documentation

◆ DefaultPreview()

HitTestPreview CommonTrackPanelCell::DefaultPreview ( const TrackPanelMouseState ,
const AudacityProject  
)
overridevirtual

Reimplemented from TrackPanelCell.

Definition at line 32 of file CommonTrackPanelCell.cpp.

34{
35 static wxCursor defaultCursor{ wxCURSOR_ARROW };
36 return { {}, &defaultCursor, {} };
37}

◆ DoContextMenu()

unsigned CommonTrackPanelCell::DoContextMenu ( const wxRect &  rect,
wxWindow *  pParent,
const wxPoint *  pPosition,
AudacityProject pProject 
)
overrideprotectedvirtual

Reimplemented from TrackPanelCell.

Definition at line 46 of file CommonTrackPanelCell.cpp.

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}
TranslatableString label
Definition: TagsEditor.cpp:165
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 > FindTrack()
virtual std::vector< MenuItem > GetMenuItems(const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject)
Return a list of items for DoContextMenu() (empties for separators)
Defines a selected portion of a project.
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.

References FindTrack(), CommandManager::Get(), ViewInfo::Get(), GetMenuItems(), label, BasicMenu::Handle::Popup(), ZoomInfo::PositionToTime(), RefreshCode::RefreshNone, and BasicUI::Point::x.

Here is the call graph for this function:

◆ DoFindTrack()

virtual std::shared_ptr< Track > CommonTrackPanelCell::DoFindTrack ( )
protectedpure virtual

◆ FindTrack() [1/2]

std::shared_ptr< Track > CommonTrackPanelCell::FindTrack ( )
inline

◆ FindTrack() [2/2]

std::shared_ptr< const Track > CommonTrackPanelCell::FindTrack ( ) const
inline

Definition at line 51 of file CommonTrackPanelCell.h.

52 { return const_cast<CommonTrackPanelCell*>(this)->DoFindTrack(); }

◆ GetMenuItems()

auto CommonTrackPanelCell::GetMenuItems ( const wxRect &  rect,
const wxPoint *  pPosition,
AudacityProject pProject 
)
virtual

Return a list of items for DoContextMenu() (empties for separators)

If the vector is empty (as in the default), there is no context menu.

Commands are invoked with temporary selection fields of CommandContext set to a point selected region at the mouse pick, and the cell's track.

A function may be given, but if it is null, then the command can be found by name in the CommandManager.

An item in the list with no command name marks a menu separator.

The menu item is enabled only if it contains a true flag, but if looked up in the command manager, it must also satisfy the command manager's conditions.

Reimplemented in WaveChannelSubView, WaveTrackAffordanceControls, and BackgroundCell.

Definition at line 39 of file CommonTrackPanelCell.cpp.

42{
43 return {};
44}

Referenced by DoContextMenu().

Here is the caller graph for this function:

◆ HandleWheelRotation()

unsigned CommonTrackPanelCell::HandleWheelRotation ( const TrackPanelMouseEvent event,
AudacityProject pProject 
)
overrideprotectedvirtual

Reimplemented from TrackPanelCell.

Definition at line 111 of file CommonTrackPanelCell.cpp.

113{
114 auto &hook = MouseWheelHook::Get();
115 return hook ? hook( evt, pProject ) : RefreshCode::Cancelled;
116}
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16

References RefreshCode::Cancelled, and GlobalVariable< MouseWheelHook, const std::function< unsigned(const TrackPanelMouseEvent &evt, AudacityProject *pProject) >, nullptr, Options... >::Get().

Here is the call graph for this function:

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