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 "ToolDock.h"
26
27#include "../commands/CommandFunctors.h"
28#include "../commands/CommandManager.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
63 static ToolManager &Get( AudacityProject &project );
64 static const ToolManager &Get( const AudacityProject &project );
65
67 ToolManager( const ToolManager & ) PROHIBITED;
68 ToolManager &operator=( const ToolManager & ) PROHIBITED;
70
71 void CreateWindows();
72
73 void LayoutToolBars();
74
75 bool IsDocked( int type );
76
77 bool IsVisible( int type );
78
79 void ShowHide( int type );
80
81 void Expose( int type, bool show );
82
83 ToolBar *GetToolBar( int 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
100 private:
101
102 ToolBar *Float( ToolBar *t, wxPoint & pos );
103
104 void OnTimer( wxTimerEvent & event );
105 void OnMouse( wxMouseEvent & event );
106 void OnCaptureLost( wxMouseCaptureLostEvent & event );
107 void UndockBar( wxPoint mp );
108 void OnGrabber( GrabberEvent & event );
109 void HandleEscapeKey();
110 void DoneDragging();
111
112 void OnIndicatorCreate( wxWindowCreateEvent & event );
113 void OnIndicatorPaint( wxPaintEvent & event );
114
115 void ReadConfig();
116 void WriteConfig();
117 void Updated();
118
120 wxWindowRef mLastFocus{};
121
124 ToolBar *mDragBar {};
125 wxPoint mDragOffset;
127
128 wxPoint mLastPos;
129 wxRect mBarPos;
130
133 std::unique_ptr<wxRegion> mLeft, mDown;
134 wxRegion *mCurrent;
135
136 wxTimer mTimer;
138
139#if defined(__WXMAC__)
141#endif
142
143 ToolDock *mTopDock{};
144 ToolDock *mBotDock{};
145
147
148 wxPoint mPrevPosition {};
149 ToolDock *mPrevDock {};
153 bool mDidDrag{};
154 bool mClicked{};
155
156 public:
157
158 DECLARE_CLASS( ToolManager )
159 DECLARE_EVENT_TABLE()
160};
161
162
166
167class ToolFrame final : public wxFrame
168{
169public:
170
171 ToolFrame( AudacityProject *parent, ToolManager *manager, ToolBar *bar, wxPoint pos );
172
173 ~ToolFrame();
174
175 ToolBar *GetBar() { return mBar; }
176 void ClearBar() { mBar = nullptr; }
177 void LockInMinSize(ToolBar * pBar);
178
179 //
180 // Transition a toolbar from float to dragging
181 //
182 void OnGrabber( GrabberEvent & event );
183
184 //
185 // Handle toolbar updates
186 //
187 void OnToolBarUpdate( wxCommandEvent & event );
188
189 //
190 // Handle frame paint events
191 //
192 void OnPaint( wxPaintEvent & WXUNUSED(event) );
193
194 void OnMotion( wxMouseEvent & event );
195
196 void OnCaptureLost( wxMouseCaptureLostEvent & WXUNUSED(event) );
197
198 //
199 // Do not allow the window to close through keyboard accelerators
200 // (like ALT+F4 on Windows)
201 //
202 void OnClose( wxCloseEvent & event );
203
204 void OnKeyDown( wxKeyEvent &event );
205
206 void Resize( const wxSize &size );
207
208private:
209
213 wxSize mMinSize;
214 wxSize mOrigSize;
215
216public:
217
218 DECLARE_CLASS( ToolFrame )
219 DECLARE_EVENT_TABLE()
220};
221
222
223
224// Construct a static instance of this class to add a menu item that shows and
225// hides a toolbar
228 ToolBarID id, const CommandID &name, const TranslatableString &label_in,
229 const Registry::OrderingHint &hint = {},
230 // IDs of other toolbars not to be shown simultaneously with this one:
231 std::vector< ToolBarID > excludeIds = {} );
232
233 void OnShowToolBar(const CommandContext &context);
234
237 const std::vector< ToolBarID > mExcludeIds;
238};
239
240#endif
Utility ClientData::Site to register hooks into a host class that attach client data.
wxEvtHandler CommandHandlerObject
const TranslatableString name
Definition: Distortion.cpp:82
std::unique_ptr< T, Destroyer< T > > Destroy_ptr
a convenience for using Destroyer
Definition: MemoryX.h:162
static const AttachedProjectObjects::RegisteredFactory manager
ToolBarID
Definition: ToolBar.h:70
@ ToolBarCount
Definition: ToolBar.h:90
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
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
A top-level window associated with a project, and handling scrollbars and zooming.
Definition: ProjectWindow.h:40
static const Position UnspecifiedPosition
Definition: ToolDock.h:105
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:101
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:105
A dynamic panel where a ToolBar can be docked.
Definition: ToolDock.h:290
class ToolFrame
Definition: ToolManager.h:168
ToolFrame(AudacityProject *parent, ToolManager *manager, ToolBar *bar, wxPoint pos)
Definition: ToolManager.cpp:75
wxSize mOrigSize
Definition: ToolManager.h:214
ToolBar * mBar
Definition: ToolManager.h:212
void OnMotion(wxMouseEvent &event)
wxSize mMinSize
Definition: ToolManager.h:213
ToolManager * mManager
Definition: ToolManager.h:211
void Resize(const wxSize &size)
void OnClose(wxCloseEvent &event)
ToolBar * GetBar()
Definition: ToolManager.h:175
AudacityProject *const mParent
Definition: ToolManager.h:210
void OnGrabber(GrabberEvent &event)
void OnPaint(wxPaintEvent &WXUNUSED(event))
void OnCaptureLost(wxMouseCaptureLostEvent &WXUNUSED(event))
void LockInMinSize(ToolBar *pBar)
void ClearBar()
Definition: ToolManager.h:176
void OnToolBarUpdate(wxCommandEvent &event)
void OnKeyDown(wxKeyEvent &event)
class ToolManager
Definition: ToolManager.h:55
bool mLastState
Definition: ToolManager.h:137
ToolManager(const ToolManager &) PROHIBITED
bool mTransition
Definition: ToolManager.h:140
wxTimer mTimer
Definition: ToolManager.h:136
ToolFrame * mDragWindow
Definition: ToolManager.h:122
AudacityProject * mParent
Definition: ToolManager.h:119
ToolBarConfiguration mPrevConfiguration
Definition: ToolManager.h:152
std::unique_ptr< wxRegion > mDown
Definition: ToolManager.h:133
ToolBar * Float(ToolBar *t, wxPoint &pos)
ToolDock * mDragDock
Definition: ToolManager.h:123
Destroy_ptr< wxFrame > FramePtr
Definition: ToolManager.h:131
wxRegion * mCurrent
Definition: ToolManager.h:134
wxRect mBarPos
Definition: ToolManager.h:129
ToolManager & operator=(const ToolManager &) PROHIBITED
wxPoint mDragOffset
Definition: ToolManager.h:125
FramePtr mIndicator
Definition: ToolManager.h:132
wxPoint mLastPos
Definition: ToolManager.h:128
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:194
const ToolBarID mId
Definition: ToolManager.h:235
const MenuTable::AttachedItem mAttachedItem
Definition: ToolManager.h:236
const std::vector< ToolBarID > mExcludeIds
Definition: ToolManager.h:237
A convenient default parameter for class template Site.
Definition: ClientData.h:28