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 "CommandFunctors.h"
29
30
31class wxCommandEvent;
32class wxFrame;
33class wxMouseEvent;
34class wxPaintEvent;
35class wxPoint;
36class wxRect;
37class wxRegion;
38class wxSize;
39class wxTimer;
40class wxTimerEvent;
41class wxWindow;
42
43class AudacityProject;
44class ProjectWindow;
45class ToolFrame;
46
50
51class AUDACITY_DLL_API ToolManager final
52 : public wxEvtHandler
53 , public wxEventFilter
54 , public ClientData::Base
55{
56
57 public:
58 // a hook function to break dependency of ToolManager on ProjectWindow
59 struct AUDACITY_DLL_API TopPanelHook : GlobalHook<TopPanelHook,
60 wxWindow*( wxWindow& )
61 >{};
62
64 static const ToolManager &Get( const AudacityProject &project );
65
67 ToolManager( const ToolManager & ) = delete;
68 ToolManager &operator=( const ToolManager & ) = delete;
70
71 void CreateWindows();
72
73 void LayoutToolBars();
74
75 bool IsDocked( Identifier type ) const;
76
77 bool IsVisible( Identifier type ) const;
78
79 void ShowHide( Identifier type );
80
81 void Expose( Identifier type, bool show );
82
83 ToolBar *GetToolBar(const Identifier &type) const;
84
85 ToolDock *GetTopDock();
86 const ToolDock *GetTopDock() const;
87 ToolDock *GetBotDock();
88 const ToolDock *GetBotDock() const;
89
90 void Reset();
91 static void OnResetToolBars(const CommandContext &context);
92
93 void Destroy();
94 void RegenerateTooltips();
95
96 int FilterEvent(wxEvent &event) override;
97
98 bool RestoreFocus();
99
101 template< typename F >
102 void ForEach(F &&fun)
103 {
104 std::for_each(std::begin(mBars), std::end(mBars), [&fun](auto &pair){
105 fun(pair.second.get());
106 });
107 }
108
109 size_t CountBars() const
110 {
111 return mBars.size();
112 }
113
114 static void ModifyToolbarMenus(AudacityProject &project);
115 // Calls ModifyToolbarMenus() on all projects
116 static void ModifyAllProjectToolbarMenus();
117
118 private:
119
120 ToolBar *Float( ToolBar *t, wxPoint & pos );
121
122 void OnMenuUpdate(struct MenuUpdateMessage);
123 void OnTimer( wxTimerEvent & event );
124 void OnMouse( wxMouseEvent & event );
125 void OnCaptureLost( wxMouseCaptureLostEvent & event );
126 void UndockBar( wxPoint mp );
127 void OnGrabber( GrabberEvent & event );
128 void HandleEscapeKey();
129 void DoneDragging();
130
131 void OnIndicatorCreate( wxWindowCreateEvent & event );
132 void OnIndicatorPaint( wxPaintEvent & event );
133
134 void ReadConfig();
135 void WriteConfig();
136 void Updated();
137
140 wxWindowRef mLastFocus{};
141
144 ToolBar *mDragBar {};
145 wxPoint mDragOffset;
147
148 wxPoint mLastPos;
149 wxRect mBarPos;
150
153 std::unique_ptr<wxRegion> mLeft, mDown;
154 wxRegion *mCurrent;
155
156 wxTimer mTimer;
158
159#if defined(__WXMAC__)
161#endif
162
163 ToolDock *mTopDock{};
164 ToolDock *mBotDock{};
165
167 std::map<Identifier, ToolBar::Holder> mBars;
168
169 wxPoint mPrevPosition {};
170 ToolDock *mPrevDock {};
174 bool mDidDrag{};
175 bool mClicked{};
176
177 public:
178
179 DECLARE_CLASS( ToolManager )
180 DECLARE_EVENT_TABLE()
181};
182
183
187
188class ToolFrame final : public wxFrame
189{
190public:
191
192 ToolFrame( AudacityProject *parent, ToolManager *manager, ToolBar *bar, wxPoint pos );
193
194 ~ToolFrame();
195
196 ToolBar *GetBar() { return mBar; }
197 void ClearBar() { mBar = nullptr; }
198 void LockInMinSize(ToolBar * pBar);
199
200 //
201 // Transition a toolbar from float to dragging
202 //
203 void OnGrabber( GrabberEvent & event );
204
205 //
206 // Handle toolbar updates
207 //
208 void OnToolBarUpdate( wxCommandEvent & event );
209
210 //
211 // Handle frame paint events
212 //
213 void OnPaint( wxPaintEvent & WXUNUSED(event) );
214
215 void OnMotion( wxMouseEvent & event );
216
217 void OnCaptureLost( wxMouseCaptureLostEvent & WXUNUSED(event) );
218
219 //
220 // Do not allow the window to close through keyboard accelerators
221 // (like ALT+F4 on Windows)
222 //
223 void OnClose( wxCloseEvent & event );
224
225 void OnKeyDown( wxKeyEvent &event );
226
227 void Resize( const wxSize &size );
228
229private:
230
234 wxSize mMinSize;
235 wxSize mOrigSize;
236
237public:
238
239 DECLARE_CLASS( ToolFrame )
240 DECLARE_EVENT_TABLE()
241};
242
243#include "MenuRegistry.h"
244
245// Construct a static instance of this class to add a menu item that shows and
246// hides a toolbar
249 Identifier id, const CommandID &name, const TranslatableString &label_in,
250 const Registry::OrderingHint &hint = {},
251 // IDs of other toolbars not to be shown simultaneously with this one:
252 std::vector< Identifier > excludeIds = {} );
253
254 void OnShowToolBar(const CommandContext &context);
255
258 const std::vector< Identifier > mExcludeIds;
259};
260
261#endif
Utility ClientData::Site to register hooks into a host class that attach client data.
wxEvtHandler CommandHandlerObject
std::unique_ptr< T, Destroyer< T > > Destroy_ptr
a convenience for using Destroyer
Definition: MemoryX.h:164
static const AttachedProjectObjects::RegisteredFactory manager
wxString name
Definition: TagsEditor.cpp:166
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:36
Generates classes whose instances register items at construction.
Definition: Registry.h:388
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:73
A dynamic panel where a ToolBar can be docked.
Definition: ToolDock.h:292
class ToolFrame
Definition: ToolManager.h:189
ToolFrame(AudacityProject *parent, ToolManager *manager, ToolBar *bar, wxPoint pos)
Definition: ToolManager.cpp:73
wxSize mOrigSize
Definition: ToolManager.h:235
ToolBar * mBar
Definition: ToolManager.h:233
void OnMotion(wxMouseEvent &event)
wxSize mMinSize
Definition: ToolManager.h:234
ToolManager * mManager
Definition: ToolManager.h:232
void Resize(const wxSize &size)
void OnClose(wxCloseEvent &event)
ToolBar * GetBar()
Definition: ToolManager.h:196
AudacityProject *const mParent
Definition: ToolManager.h:231
void OnGrabber(GrabberEvent &event)
void OnPaint(wxPaintEvent &WXUNUSED(event))
void OnCaptureLost(wxMouseCaptureLostEvent &WXUNUSED(event))
void LockInMinSize(ToolBar *pBar)
void ClearBar()
Definition: ToolManager.h:197
void OnToolBarUpdate(wxCommandEvent &event)
void OnKeyDown(wxKeyEvent &event)
class ToolManager
Definition: ToolManager.h:55
ToolManager & operator=(const ToolManager &)=delete
bool mLastState
Definition: ToolManager.h:157
ToolManager(const ToolManager &)=delete
bool mTransition
Definition: ToolManager.h:160
std::map< Identifier, ToolBar::Holder > mBars
map not unordered_map, for the promise made by ForEach
Definition: ToolManager.h:167
wxTimer mTimer
Definition: ToolManager.h:156
ToolFrame * mDragWindow
Definition: ToolManager.h:142
size_t CountBars() const
Definition: ToolManager.h:109
Observer::Subscription mMenuManagerSubscription
Definition: ToolManager.h:138
AudacityProject * mParent
Definition: ToolManager.h:139
ToolBarConfiguration mPrevConfiguration
Definition: ToolManager.h:173
std::unique_ptr< wxRegion > mDown
Definition: ToolManager.h:153
ToolBar * Float(ToolBar *t, wxPoint &pos)
void ForEach(F &&fun)
Visit bars, lexicographically by their textual ids.
Definition: ToolManager.h:102
ToolDock * mDragDock
Definition: ToolManager.h:143
Destroy_ptr< wxFrame > FramePtr
Definition: ToolManager.h:151
wxRegion * mCurrent
Definition: ToolManager.h:154
wxRect mBarPos
Definition: ToolManager.h:149
wxPoint mDragOffset
Definition: ToolManager.h:145
FramePtr mIndicator
Definition: ToolManager.h:152
wxPoint mLastPos
Definition: ToolManager.h:148
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:202
const char * end(const char *str) noexcept
Definition: StringUtils.h:106
const char * begin(const char *str) noexcept
Definition: StringUtils.h:101
const MenuRegistry::AttachedItem mAttachedItem
Definition: ToolManager.h:257
const std::vector< Identifier > mExcludeIds
Definition: ToolManager.h:258
const Identifier mId
Definition: ToolManager.h:256
A convenient default parameter for class template Site.
Definition: ClientData.h:29
Sent when menus update (such as for changing enablement of items)