Audacity  3.0.3
Classes | Public Types | Public Member Functions | Static 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
 

Public Types

using Hook = std::function< unsigned(const TrackPanelMouseEvent &evt, AudacityProject *pProject) >
 

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 &) PROHIBITED
 
TrackPanelCelloperator= (const TrackPanelCell &) PROHIBITED
 
virtual ~TrackPanelCell ()=0
 
virtual std::vector< UIHandlePtrHitTest (const TrackPanelMouseState &state, const AudacityProject *pProject)=0
 
virtual std::shared_ptr< TrackPanelCellContextMenuDelegate ()
 
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)
 

Static Public Member Functions

static Hook InstallMouseWheelHook (const Hook &hook)
 
- 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)
 

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
 

Detailed Description

Definition at line 26 of file CommonTrackPanelCell.h.

Member Typedef Documentation

◆ Hook

using CommonTrackPanelCell::Hook = std::function< unsigned(const TrackPanelMouseEvent &evt, AudacityProject *pProject) >

Definition at line 31 of file CommonTrackPanelCell.h.

Constructor & Destructor Documentation

◆ CommonTrackPanelCell()

CommonTrackPanelCell::CommonTrackPanelCell ( )
inline

Definition at line 37 of file CommonTrackPanelCell.h.

38  {}

◆ ~CommonTrackPanelCell()

CommonTrackPanelCell::~CommonTrackPanelCell ( )
pure virtual

Definition at line 44 of file CommonTrackPanelCell.cpp.

45 {
46 }

Member Function Documentation

◆ DefaultPreview()

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

Reimplemented from TrackPanelCell.

Definition at line 48 of file CommonTrackPanelCell.cpp.

50 {
51  static wxCursor defaultCursor{ wxCURSOR_ARROW };
52  return { {}, &defaultCursor, {} };
53 }

◆ DoContextMenu()

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

Reimplemented from TrackPanelCell.

Definition at line 62 of file CommonTrackPanelCell.cpp.

64 {
65  const auto items = GetMenuItems( rect, pPoint, pProject );
66  if (items.empty())
68 
69  // Set up command context with extras
70  CommandContext context{ *pProject };
71  SelectedRegion region;
72  if (pPoint) {
73  auto time = ViewInfo::Get(*pProject).PositionToTime(pPoint->x, rect.x);
74  region = { time, time };
75  context.temporarySelection.pSelectedRegion = &region;
76  }
77  context.temporarySelection.pTrack = FindTrack().get();
78 
79  auto &commandManager = CommandManager::Get(*pProject);
80  auto flags = MenuManager::Get( *pProject ).GetUpdateFlags();
81 
82  // Common dispatcher for the menu items
83  auto dispatcher = [&]( wxCommandEvent &evt ){
84  auto idx = evt.GetId() - 1;
85  if (idx >= 0 && idx < items.size()) {
86  if (auto &action = items[idx].action)
87  action( context );
88  else
89  commandManager.HandleTextualCommand(
90  items[idx].symbol.Internal(), context, flags, false);
91  }
92  };
93 
94  wxMenu menu;
95  int ii = 1;
96  for (const auto &item: items) {
97  if ( const auto &commandID = item.symbol.Internal();
98  commandID.empty() )
99  menu.AppendSeparator();
100  else {
101  // Generate a menu item with the same shortcut key as in the toolbar
102  // menu, and as determined by keyboard preferences
103  auto label =
104  commandManager.FormatLabelForMenu( commandID, &item.symbol.Msgid() );
105  menu.Append( ii, label );
106  menu.Bind( wxEVT_COMMAND_MENU_SELECTED, dispatcher );
107  bool enabled = item.enabled &&
108  (item.action || commandManager.GetEnabled( commandID ));
109  menu.Enable( ii, enabled );
110  }
111  ++ii;
112  }
113 
114  BasicUI::Point point;
115  if (pPoint)
116  point = { pPoint->x, pPoint->y };
117  BasicMenu::Handle{ &menu }.Popup(
118  wxWidgetsWindowPlacement{ pParent },
119  point
120  );
121 
123 }

References FindTrack(), ViewInfo::Get(), CommandManager::Get(), MenuManager::Get(), GetMenuItems(), MenuManager::GetUpdateFlags(), 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

Definition at line 46 of file CommonTrackPanelCell.h.

46 { return DoFindTrack(); }

Referenced by BrushHandleHitTest(), WaveTrackView::CaptureKey(), anonymous_namespace{SelectHandle.cpp}::ChooseBoundary(), CommonTrackView::ContextMenuDelegate(), SpectrumView::DetailedHitTest(), TimeTrackView::DetailedHitTest(), CommonTrackControls::DoContextMenu(), DoContextMenu(), WaveTrackVRulerControls::DoDraw(), SpectrumView::DoSetMinimized(), WaveformView::DoSetMinimized(), SelectHandle::Drag(), TimeShiftHandle::Drag(), LabelTrackView::Draw(), TrackPanelResizerCell::Draw(), NoteTrackAffordanceControls::Draw(), NoteTrackView::Draw(), NoteTrackVRulerControls::Draw(), SpectrumView::Draw(), WaveformView::Draw(), WaveTrackAffordanceControls::Draw(), TimeTrackView::Draw(), TimeTrackVRulerControls::Draw(), CommonTrackControls::Draw(), TrackVRulerControls::Draw(), WaveTrackAffordanceControls::ExitTextEditing(), LabelTrackView::FindLabelTrack(), TrackPanel::FindRulerRects(), WaveTrackView::GetAffordanceControls(), CommonTrackView::GetMinimizedHeight(), NoteTrackVRulerControls::HandleWheelRotation(), SpectrumVRulerControls::HandleWheelRotation(), WaveformVRulerControls::HandleWheelRotation(), TrackPanelResizerCell::HitTest(), CommonTrackView::HitTest(), SpectrumVRulerControls::HitTest(), WaveformVRulerControls::HitTest(), TimeTrackVRulerControls::HitTest(), CommonTrackControls::HitTest(), NoteTrackAffordanceControls::HitTest(), NoteTrackControls::HitTest(), NoteTrackVRulerControls::HitTest(), WaveTrackAffordanceControls::HitTest(), WaveTrackControls::HitTest(), SelectHandle::HitTest(), anonymous_namespace{WaveTrackView.cpp}::SubViewCloseHandle::HitTest(), WaveClipTrimHandle::HitTest(), anonymous_namespace{BrushHandle.cpp}::isSpectralSelectionView(), anonymous_namespace{SelectHandle.cpp}::isSpectralSelectionView(), SelectHandle::MoveSnappingFreqSelection(), LabelTrackView::OnLabelAdded(), LabelTrackView::OnLabelDeleted(), LabelTrackView::OnLabelPermuted(), LabelTrackView::OnSelectionChange(), WaveTrackAffordanceControls::SelectNextClip(), TrackView::SetExpandedHeight(), TrackView::SetMinimized(), SpectrumView::SpectrumView(), WaveTrackAffordanceControls::StartEditNameOfMatchingClip(), SelectHandle::StartFreqSelection(), NoteTrackVRulerControls::UpdateRuler(), SpectrumVRulerControls::UpdateRuler(), WaveformVRulerControls::UpdateRuler(), and TimeTrackVRulerControls::UpdateRuler().

◆ FindTrack() [2/2]

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

Definition at line 47 of file CommonTrackPanelCell.h.

48  { 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 BackgroundCell, and WaveTrackSubView.

Definition at line 55 of file CommonTrackPanelCell.cpp.

58 {
59  return {};
60 }

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 125 of file CommonTrackPanelCell.cpp.

127 {
128  auto hook = GetHook();
129  return hook ? hook( evt, pProject ) : RefreshCode::Cancelled;
130 }

References RefreshCode::Cancelled, and anonymous_namespace{CommonTrackPanelCell.cpp}::GetHook().

Here is the call graph for this function:

◆ InstallMouseWheelHook()

auto CommonTrackPanelCell::InstallMouseWheelHook ( const Hook hook)
static

Definition at line 35 of file CommonTrackPanelCell.cpp.

37 {
38  auto &theHook = GetHook();
39  auto result = theHook;
40  theHook = hook;
41  return result;
42 }

References anonymous_namespace{CommonTrackPanelCell.cpp}::GetHook().

Referenced by anonymous_namespace{ProjectWindow.cpp}::MouseWheelHandler::MouseWheelHandler().

Here is the call graph for this function:
Here is the caller graph for this function:

The documentation for this class was generated from the following files:
ViewInfo::Get
static ViewInfo & Get(AudacityProject &project)
Definition: ViewInfo.cpp:241
BasicUI::Point
A pair of screen coordinates, x increasing rightward, y downward.
Definition: BasicUIPoint.h:18
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
CommonTrackPanelCell::FindTrack
std::shared_ptr< Track > FindTrack()
Definition: CommonTrackPanelCell.h:46
RefreshCode::Cancelled
@ Cancelled
Definition: RefreshCode.h:23
CommonTrackPanelCell::GetMenuItems
virtual std::vector< MenuItem > GetMenuItems(const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject)
Return a list of items for DoContextMenu() (empties for separators)
Definition: CommonTrackPanelCell.cpp:55
wxWidgetsWindowPlacement
Window placement information for wxWidgetsBasicUI can be constructed from a wxWindow pointer.
Definition: wxWidgetsWindowPlacement.h:22
BasicUI::Point::x
int x
Definition: BasicUIPoint.h:22
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:34
label
TranslatableString label
Definition: Tags.cpp:756
MenuManager::Get
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:70
CommonTrackPanelCell::DoFindTrack
virtual std::shared_ptr< Track > DoFindTrack()=0
anonymous_namespace{CommonTrackPanelCell.cpp}::GetHook
CommonTrackPanelCell::Hook & GetHook()
Definition: CommonTrackPanelCell.cpp:28
CommonTrackPanelCell
Definition: CommonTrackPanelCell.h:28
CommandManager::Get
static CommandManager & Get(AudacityProject &project)
Definition: CommandManager.cpp:207
RefreshCode
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
BasicMenu::Handle::Popup
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:207
MenuManager::GetUpdateFlags
CommandFlag GetUpdateFlags(bool checkActive=false) const
Definition: Menus.cpp:545
ZoomInfo::PositionToTime
double PositionToTime(wxInt64 position, wxInt64 origin=0, bool ignoreFisheye=false) const
Definition: ZoomInfo.cpp:39
BasicMenu::Handle
Definition: BasicMenu.h:26
SelectedRegion
Defines a selected portion of a project.
Definition: SelectedRegion.h:35