Audacity  3.0.3
BackgroundCell.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3 Audacity: A Digital Audio Editor
4 
5 BackgroundCell.cpp
6 
7 Paul Licameli split from TrackPanel.cpp
8 
9 **********************************************************************/
10 
11 
12 #include "BackgroundCell.h"
13 
14 #include "AColor.h"
15 #include "../../HitTestResult.h"
16 #include "Project.h"
17 #include "../../RefreshCode.h"
18 #include "../../SelectionState.h"
19 #include "../../Track.h"
20 #include "../../TrackArtist.h"
21 #include "../../TrackPanel.h"
22 #include "../../TrackPanelConstants.h"
23 #include "../../TrackPanelDrawingContext.h"
24 #include "../../TrackPanelMouseEvent.h"
25 #include "../../UIHandle.h"
26 #include "ViewInfo.h"
27 
28 #include <wx/cursor.h>
29 #include <wx/event.h>
30 
31 // Define this, just so the click to deselect can dispatch here
32 // This handle class, unlike most, doesn't associate with any particular cell.
33 class BackgroundHandle : public UIHandle
34 {
37 
38 public:
40 
43 
45  {
46  static wxCursor arrowCursor{ wxCURSOR_ARROW };
47  return { {}, &arrowCursor };
48  }
49 
51  {}
52 
54  (const TrackPanelMouseEvent &evt, AudacityProject *pProject) override
55  {
56  using namespace RefreshCode;
57  const wxMouseEvent &event = evt.event;
58  // Do not start a drag
59  Result result = Cancelled;
60 
61  // AS: If the user clicked outside all tracks, make nothing
62  // selected.
63  if ((event.ButtonDown() || event.ButtonDClick())) {
64  SelectionState::Get( *pProject ).SelectNone(
65  TrackList::Get( *pProject ) );
66  result |= RefreshAll;
67  }
68 
69  return result;
70  }
71 
73  (const TrackPanelMouseEvent &, AudacityProject *) override
74  { return RefreshCode::RefreshNone; }
75 
77  (const TrackPanelMouseState &, AudacityProject *) override
78  { return HitPreview(); }
79 
82  wxWindow *) override
83  { return RefreshCode::RefreshNone; }
84 
86  { return RefreshCode::RefreshNone; }
87 };
88 
90  []( AudacityProject &parent ){
91  auto result = std::make_shared< BackgroundCell >( &parent );
92  TrackPanel::Get( parent ).SetBackgroundCell( result );
93  return result;
94  }
95 };
96 
98 {
99  return project.AttachedObjects::Get< BackgroundCell >( key );
100 }
101 
103 {
104  return Get( const_cast< AudacityProject & >( project ) );
105 }
106 
108 {
109 }
110 
111 std::vector<UIHandlePtr> BackgroundCell::HitTest
112 (const TrackPanelMouseState &,
113  const AudacityProject *)
114 {
115  auto result = AssignUIHandlePtr(mHandle, std::make_shared<BackgroundHandle>());
116  return { result };
117 }
118 
119 std::shared_ptr<Track> BackgroundCell::DoFindTrack()
120 {
121  return {};
122 }
123 
125  TrackPanelDrawingContext &context,
126  const wxRect &rect, unsigned iPass )
127 {
128  if ( iPass == TrackArtist::PassBackground ) {
129  auto &dc = context.dc;
130  // Paint over the part below the tracks
131  AColor::TrackPanelBackground( &dc, false );
132  dc.DrawRectangle( rect );
133  }
134 }
135 
138  const wxRect &rect, const wxRect &, unsigned iPass )
139 {
140  if ( iPass == TrackArtist::PassBackground )
141  // If there are any tracks, extend the drawing area up, to cover the
142  // bottom ends of any zooming guide lines.
143  return {
144  rect.x,
145  rect.y - kTopMargin,
146  rect.width,
147  rect.height + kTopMargin
148  };
149  else
150  return rect;
151 }
152 
154  const wxRect &, const wxPoint *, AudacityProject * )
155  -> std::vector<MenuItem>
156 {
157  // These commands exist in toolbar menus too, but maybe with other labels
158  // TODO: devise a system of registration so that BackgroundCell has no
159  // special knowledge about track sub-types
160  return {
161  { L"NewMonoTrack", XO("Add Mono Track")},
162  { L"NewStereoTrack", XO("Add Stereo Track") },
163  { L"NewLabelTrack", XO("Add Label Track"), },
164  {},
165  { L"Export", XO("Export Audio..."), },
166  {},
167  { L"SelectAll", XO("Select All") },
168  };
169 }
BackgroundCell
Class representing the background of a Track. It provides the hit test function that tells us what wa...
Definition: BackgroundCell.h:28
BackgroundCell::GetMenuItems
std::vector< MenuItem > GetMenuItems(const wxRect &rect, const wxPoint *pPosition, AudacityProject *pProject) override
Return a list of items for DoContextMenu() (empties for separators)
Definition: BackgroundCell.cpp:153
BackgroundHandle::HitPreview
static HitTestPreview HitPreview()
Definition: BackgroundCell.cpp:44
AColor::TrackPanelBackground
static void TrackPanelBackground(wxDC *dc, bool selected)
Definition: AColor.cpp:362
BackgroundHandle::Preview
HitTestPreview Preview(const TrackPanelMouseState &, AudacityProject *) override
Definition: BackgroundCell.cpp:77
RefreshCode::RefreshAll
@ RefreshAll
Definition: RefreshCode.h:26
BackgroundHandle::BackgroundHandle
BackgroundHandle(BackgroundHandle &&)=default
RefreshCode::RefreshNone
@ RefreshNone
Definition: RefreshCode.h:21
BackgroundCell::DrawingArea
wxRect DrawingArea(TrackPanelDrawingContext &, const wxRect &rect, const wxRect &panelRect, unsigned iPass) override
Definition: BackgroundCell.cpp:136
Project.h
TrackPanelDrawingContext
Definition: TrackPanelDrawingContext.h:22
RefreshCode::Cancelled
@ Cancelled
Definition: RefreshCode.h:23
TrackPanel::Get
static TrackPanel & Get(AudacityProject &project)
Definition: TrackPanel.cpp:227
XO
#define XO(s)
Definition: Internat.h:31
TrackPanelDrawingContext::dc
wxDC & dc
Definition: TrackPanelDrawingContext.h:23
BackgroundHandle::operator=
BackgroundHandle & operator=(BackgroundHandle &&)=default
BackgroundHandle::Click
Result Click(const TrackPanelMouseEvent &evt, AudacityProject *pProject) override
Definition: BackgroundCell.cpp:54
ClientData::Site::RegisteredFactory
Client code makes static instance from a factory of attachments; passes it to Get or Find as a retrie...
Definition: ClientData.h:266
BackgroundCell::~BackgroundCell
virtual ~BackgroundCell()
Definition: BackgroundCell.cpp:107
UIHandle
Short-lived drawing and event-handling object associated with a TrackPanelCell.
Definition: UIHandle.h:35
BackgroundCell::DoFindTrack
std::shared_ptr< Track > DoFindTrack() override
Definition: BackgroundCell.cpp:119
BackgroundHandle::BackgroundHandle
BackgroundHandle()
Definition: BackgroundCell.cpp:39
BackgroundHandle::Release
Result Release(const TrackPanelMouseEvent &, AudacityProject *, wxWindow *) override
Definition: BackgroundCell.cpp:81
BackgroundHandle::BackgroundHandle
BackgroundHandle(const BackgroundHandle &)=delete
BasicUI::Get
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
SelectionState::SelectNone
void SelectNone(TrackList &tracks)
Definition: SelectionState.cpp:93
BackgroundHandle::Cancel
Result Cancel(AudacityProject *) override
Definition: BackgroundCell.cpp:85
UIHandle::Result
unsigned Result
Definition: UIHandle.h:38
BackgroundCell::Draw
void Draw(TrackPanelDrawingContext &context, const wxRect &rect, unsigned iPass) override
Definition: BackgroundCell.cpp:124
BackgroundCell::Get
static BackgroundCell & Get(AudacityProject &project)
Definition: BackgroundCell.cpp:97
kTopMargin
@ kTopMargin
Definition: TrackPanelConstants.h:21
HitTestPreview
Definition: HitTestResult.h:20
TrackPanel::SetBackgroundCell
void SetBackgroundCell(const std::shared_ptr< CommonTrackPanelCell > &pCell)
Definition: TrackPanel.cpp:871
ViewInfo.h
SelectionState::Get
static SelectionState & Get(AudacityProject &project)
Definition: SelectionState.cpp:20
TrackList::Get
static TrackList & Get(AudacityProject &project)
Definition: Track.cpp:506
AudacityProject
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:92
TrackPanelMouseEvent
Definition: TrackPanelMouseEvent.h:46
TrackPanelMouseState
Definition: TrackPanelMouseEvent.h:28
BackgroundHandle::~BackgroundHandle
virtual ~BackgroundHandle()
Definition: BackgroundCell.cpp:50
BackgroundCell::HitTest
std::vector< UIHandlePtr > HitTest(const TrackPanelMouseState &state, const AudacityProject *) override
Definition: BackgroundCell.cpp:112
BackgroundHandle::operator=
BackgroundHandle & operator=(const BackgroundHandle &)=delete
BackgroundCell.h
AssignUIHandlePtr
std::shared_ptr< Subclass > AssignUIHandlePtr(std::weak_ptr< Subclass > &holder, const std::shared_ptr< Subclass > &pNew)
Definition: UIHandle.h:151
BackgroundHandle
Definition: BackgroundCell.cpp:34
RefreshCode
Namespace containing an enum 'what to do on a refresh?'.
Definition: RefreshCode.h:16
TrackArtist::PassBackground
@ PassBackground
Definition: TrackArtist.h:86
AColor.h
TrackPanelMouseEvent::event
wxMouseEvent & event
Definition: TrackPanelMouseEvent.h:58
BackgroundHandle::Drag
Result Drag(const TrackPanelMouseEvent &, AudacityProject *) override
Definition: BackgroundCell.cpp:73
key
static const AudacityProject::AttachedObjects::RegisteredFactory key
Definition: BackgroundCell.cpp:89