Audacity 3.2.0
ToolManager.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ToolManager.h
6
7 Dominic Mazzoni
8 Shane T. Mueller
9 Leland Lucius
10
11**********************************************************************/
12
13#ifndef __AUDACITY_TOOLMANAGER__
14#define __AUDACITY_TOOLMANAGER__
15
16#include <functional>
17
18#include <wx/defs.h>
19#include <wx/eventfilter.h> // to inherit
20#include <wx/frame.h> // to inherit
21#include <wx/timer.h> // member variable
22
23#include "ClientData.h"
24#include "GlobalVariable.h"
25#include "Observer.h"
26#include "ToolDock.h"
27
28#include "../commands/CommandFunctors.h"
29#include "../commands/CommandManager.h"
30
31
32class wxCommandEvent;
33class wxFrame;
34class wxMouseEvent;
35class wxPaintEvent;
36class wxPoint;
37class wxRect;
38class wxRegion;
39class wxSize;
40class wxTimer;
41class wxTimerEvent;
42class wxWindow;
43
44class AudacityProject;
45class ProjectWindow;
46class ToolFrame;
47
51
52class AUDACITY_DLL_API ToolManager final
53 : public wxEvtHandler
54 , public wxEventFilter
55 , public ClientData::Base
56{
57
58 public:
59 // a hook function to break dependency of ToolManager on ProjectWindow
60 struct AUDACITY_DLL_API TopPanelHook : GlobalHook<TopPanelHook,
61 wxWindow*( wxWindow& )
62 >{};
63
65 static const ToolManager &Get( const AudacityProject &project );
66
68 ToolManager( const ToolManager & ) = delete;
69 ToolManager &operator=( const ToolManager & ) = delete;
71
72 void CreateWindows();
73
74 void LayoutToolBars();
75
76 bool IsDocked( Identifier type ) const;
77
78 bool IsVisible( Identifier type ) const;
79
80 void ShowHide( Identifier type );
81
82 void Expose( Identifier type, bool show );
83
84 ToolBar *GetToolBar(const Identifier &type) const;
85
86 ToolDock *GetTopDock();
87 const ToolDock *GetTopDock() const;
88 ToolDock *GetBotDock();
89 const ToolDock *GetBotDock() const;
90
91 void Reset();
92 static void OnResetToolBars(const CommandContext &context);
93
94 void Destroy();
95 void RegenerateTooltips();
96
97 int FilterEvent(wxEvent &event) override;
98
99 bool RestoreFocus();
100
102 template< typename F >
103 void ForEach(F &&fun)
104 {
105 std::for_each(std::begin(mBars), std::end(mBars), [&fun](auto &pair){
106 fun(pair.second.get());
107 });
108 }
109
110 size_t CountBars() const
111 {
112 return mBars.size();
113 }
114
115 static void ModifyToolbarMenus(AudacityProject &project);
116 // Calls ModifyToolbarMenus() on all projects
117 static void ModifyAllProjectToolbarMenus();
118
119 private:
120
121 ToolBar *Float( ToolBar *t, wxPoint & pos );
122
123 void OnMenuUpdate(struct MenuUpdateMessage);
124 void OnTimer( wxTimerEvent & event );
125 void OnMouse( wxMouseEvent & event );
126 void OnCaptureLost( wxMouseCaptureLostEvent & event );
127 void UndockBar( wxPoint mp );
128 void OnGrabber( GrabberEvent & event );
129 void HandleEscapeKey();
130 void DoneDragging();
131
132 void OnIndicatorCreate( wxWindowCreateEvent & event );
133 void OnIndicatorPaint( wxPaintEvent & event );
134
135 void ReadConfig();
136 void WriteConfig();
137 void Updated();
138
141 wxWindowRef mLastFocus{};
142
145 ToolBar *mDragBar {};
146 wxPoint mDragOffset;
148
149 wxPoint mLastPos;
150 wxRect mBarPos;
151
154 std::unique_ptr<wxRegion> mLeft, mDown;
155 wxRegion *mCurrent;
156
157 wxTimer mTimer;
159
160#if defined(__WXMAC__)
162#endif
163
164 ToolDock *mTopDock{};
165 ToolDock *mBotDock{};
166
168 std::map<Identifier, ToolBar::Holder> mBars;
169
170 wxPoint mPrevPosition {};
171 ToolDock *mPrevDock {};
175 bool mDidDrag{};
176 bool mClicked{};
177
178 public:
179
180 DECLARE_CLASS( ToolManager )
181 DECLARE_EVENT_TABLE()
182};
183
184
188
189class ToolFrame final : public wxFrame
190{
191public:
192
193 ToolFrame( AudacityProject *parent, ToolManager *manager, ToolBar *bar, wxPoint pos );
194
195 ~ToolFrame();
196
197 ToolBar *GetBar() { return mBar; }
198 void ClearBar() { mBar = nullptr; }
199 void LockInMinSize(ToolBar * pBar);
200
201 //
202 // Transition a toolbar from float to dragging
203 //
204 void OnGrabber( GrabberEvent & event );
205
206 //
207 // Handle toolbar updates
208 //
209 void OnToolBarUpdate( wxCommandEvent & event );
210
211 //
212 // Handle frame paint events
213 //
214 void OnPaint( wxPaintEvent & WXUNUSED(event) );
215
216 void OnMotion( wxMouseEvent & event );
217
218 void OnCaptureLost( wxMouseCaptureLostEvent & WXUNUSED(event) );
219
220 //
221 // Do not allow the window to close through keyboard accelerators
222 // (like ALT+F4 on Windows)
223 //
224 void OnClose( wxCloseEvent & event );
225
226 void OnKeyDown( wxKeyEvent &event );
227
228 void Resize( const wxSize &size );
229
230private:
231
235 wxSize mMinSize;
236 wxSize mOrigSize;
237
238public:
239
240 DECLARE_CLASS( ToolFrame )
241 DECLARE_EVENT_TABLE()
242};
243
244
245
246// Construct a static instance of this class to add a menu item that shows and
247// hides a toolbar
250 Identifier id, const CommandID &name, const TranslatableString &label_in,
251 const Registry::OrderingHint &hint = {},
252 // IDs of other toolbars not to be shown simultaneously with this one:
253 std::vector< Identifier > excludeIds = {} );
254
255 void OnShowToolBar(const CommandContext &context);
256
259 const std::vector< Identifier > mExcludeIds;
260};
261
262#endif
Utility ClientData::Site to register hooks into a host class that attach client data.
wxEvtHandler CommandHandlerObject
const TranslatableString name
Definition: Distortion.cpp:76
std::unique_ptr< T, Destroyer< T > > Destroy_ptr
a convenience for using Destroyer
Definition: MemoryX.h:162
static const AttachedProjectObjects::RegisteredFactory manager
const auto project
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Global function-valued variable, adding a convenient Call()
Grabber Class.
Definition: Grabber.h:48
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
A move-only handle representing a connection to a Publisher.
Definition: Observer.h:70
A top-level window associated with a project, and handling scrollbars and zooming.
Definition: ProjectWindow.h:41
static const Position UnspecifiedPosition
Definition: ToolDock.h:106
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:74
A dynamic panel where a ToolBar can be docked.
Definition: ToolDock.h:292
class ToolFrame
Definition: ToolManager.h:190
ToolFrame(AudacityProject *parent, ToolManager *manager, ToolBar *bar, wxPoint pos)
Definition: ToolManager.cpp:73
wxSize mOrigSize
Definition: ToolManager.h:236
ToolBar * mBar
Definition: ToolManager.h:234
void OnMotion(wxMouseEvent &event)
wxSize mMinSize
Definition: ToolManager.h:235
ToolManager * mManager
Definition: ToolManager.h:233
void Resize(const wxSize &size)
void OnClose(wxCloseEvent &event)
ToolBar * GetBar()
Definition: ToolManager.h:197
AudacityProject *const mParent
Definition: ToolManager.h:232
void OnGrabber(GrabberEvent &event)
void OnPaint(wxPaintEvent &WXUNUSED(event))
void OnCaptureLost(wxMouseCaptureLostEvent &WXUNUSED(event))
void LockInMinSize(ToolBar *pBar)
void ClearBar()
Definition: ToolManager.h:198
void OnToolBarUpdate(wxCommandEvent &event)
void OnKeyDown(wxKeyEvent &event)
class ToolManager
Definition: ToolManager.h:56
ToolManager & operator=(const ToolManager &)=delete
bool mLastState
Definition: ToolManager.h:158
ToolManager(const ToolManager &)=delete
bool mTransition
Definition: ToolManager.h:161
std::map< Identifier, ToolBar::Holder > mBars
map not unordered_map, for the promise made by ForEach
Definition: ToolManager.h:168
wxTimer mTimer
Definition: ToolManager.h:157
ToolFrame * mDragWindow
Definition: ToolManager.h:143
size_t CountBars() const
Definition: ToolManager.h:110
Observer::Subscription mMenuManagerSubscription
Definition: ToolManager.h:139
AudacityProject * mParent
Definition: ToolManager.h:140
ToolBarConfiguration mPrevConfiguration
Definition: ToolManager.h:174
std::unique_ptr< wxRegion > mDown
Definition: ToolManager.h:154
ToolBar * Float(ToolBar *t, wxPoint &pos)
void ForEach(F &&fun)
Visit bars, lexicographically by their textual ids.
Definition: ToolManager.h:103
ToolDock * mDragDock
Definition: ToolManager.h:144
Destroy_ptr< wxFrame > FramePtr
Definition: ToolManager.h:152
wxRegion * mCurrent
Definition: ToolManager.h:155
wxRect mBarPos
Definition: ToolManager.h:150
wxPoint mDragOffset
Definition: ToolManager.h:146
FramePtr mIndicator
Definition: ToolManager.h:153
wxPoint mLastPos
Definition: ToolManager.h:149
Holds a msgid for the translation catalog; may also bind format arguments.
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:196
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150
const std::vector< Identifier > mExcludeIds
Definition: ToolManager.h:259
const Identifier mId
Definition: ToolManager.h:257
const MenuTable::AttachedItem mAttachedItem
Definition: ToolManager.h:258
A convenient default parameter for class template Site.
Definition: ClientData.h:28
Sent when menus update (such as for changing enablement of items)
Definition: Menus.h:74