Audacity  3.0.3
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 "ToolDock.h"
25 
26 #include "../commands/CommandFunctors.h"
27 #include "../commands/CommandManager.h"
28 
29 
30 class wxCommandEvent;
31 class wxFrame;
32 class wxMouseEvent;
33 class wxPaintEvent;
34 class wxPoint;
35 class wxRect;
36 class wxRegion;
37 class wxSize;
38 class wxTimer;
39 class wxTimerEvent;
40 class wxWindow;
41 
42 class AudacityProject;
43 class ProjectWindow;
44 class ToolFrame;
45 
49 
50 class AUDACITY_DLL_API ToolManager final
51  : public wxEvtHandler
52  , public wxEventFilter
53  , public ClientData::Base
54 {
55 
56  public:
57  // a hook function to break dependency of ToolManager on ProjectWindow
58  using GetTopPanelHook = std::function< wxWindow*( wxWindow& ) >;
59  static GetTopPanelHook SetGetTopPanelHook( const GetTopPanelHook& );
60 
61  static ToolManager &Get( AudacityProject &project );
62  static const ToolManager &Get( const AudacityProject &project );
63 
64  ToolManager( AudacityProject *parent );
65  ToolManager( const ToolManager & ) PROHIBITED;
66  ToolManager &operator=( const ToolManager & ) PROHIBITED;
67  ~ToolManager();
68 
69  void CreateWindows();
70 
71  void LayoutToolBars();
72 
73  bool IsDocked( int type );
74 
75  bool IsVisible( int type );
76 
77  void ShowHide( int type );
78 
79  void Expose( int type, bool show );
80 
81  ToolBar *GetToolBar( int type ) const;
82 
83  ToolDock *GetTopDock();
84  const ToolDock *GetTopDock() const;
85  ToolDock *GetBotDock();
86  const ToolDock *GetBotDock() const;
87 
88  void Reset();
89  static void OnResetToolBars(const CommandContext &context);
90 
91  void Destroy();
92  void RegenerateTooltips();
93 
94  int FilterEvent(wxEvent &event) override;
95 
96  bool RestoreFocus();
97 
98  private:
99 
100  ToolBar *Float( ToolBar *t, wxPoint & pos );
101 
102  void OnTimer( wxTimerEvent & event );
103  void OnMouse( wxMouseEvent & event );
104  void OnCaptureLost( wxMouseCaptureLostEvent & event );
105  void UndockBar( wxPoint mp );
106  void OnGrabber( GrabberEvent & event );
107  void HandleEscapeKey();
108  void DoneDragging();
109 
110  void OnIndicatorCreate( wxWindowCreateEvent & event );
111  void OnIndicatorPaint( wxPaintEvent & event );
112 
113  void ReadConfig();
114  void WriteConfig();
115  void Updated();
116 
118  wxWindowRef mLastFocus{};
119 
122  ToolBar *mDragBar {};
123  wxPoint mDragOffset;
125 
126  wxPoint mLastPos;
127  wxRect mBarPos;
128 
131  std::unique_ptr<wxRegion> mLeft, mDown;
132  wxRegion *mCurrent;
133 
134  wxTimer mTimer;
136 
137 #if defined(__WXMAC__)
138  bool mTransition;
139 #endif
140 
141  ToolDock *mTopDock{};
142  ToolDock *mBotDock{};
143 
145 
146  wxPoint mPrevPosition {};
147  ToolDock *mPrevDock {};
151  bool mDidDrag{};
152  bool mClicked{};
153 
154  public:
155 
156  DECLARE_CLASS( ToolManager )
157  DECLARE_EVENT_TABLE()
158 };
159 
160 
164 
165 class ToolFrame final : public wxFrame
166 {
167 public:
168 
169  ToolFrame( AudacityProject *parent, ToolManager *manager, ToolBar *bar, wxPoint pos );
170 
171  ~ToolFrame();
172 
173  ToolBar *GetBar() { return mBar; }
174  void ClearBar() { mBar = nullptr; }
175  void LockInMinSize(ToolBar * pBar);
176 
177  //
178  // Transition a toolbar from float to dragging
179  //
180  void OnGrabber( GrabberEvent & event );
181 
182  //
183  // Handle toolbar updates
184  //
185  void OnToolBarUpdate( wxCommandEvent & event );
186 
187  //
188  // Handle frame paint events
189  //
190  void OnPaint( wxPaintEvent & WXUNUSED(event) );
191 
192  void OnMotion( wxMouseEvent & event );
193 
194  void OnCaptureLost( wxMouseCaptureLostEvent & WXUNUSED(event) );
195 
196  //
197  // Do not allow the window to close through keyboard accelerators
198  // (like ALT+F4 on Windows)
199  //
200  void OnClose( wxCloseEvent & event );
201 
202  void OnKeyDown( wxKeyEvent &event );
203 
204  void Resize( const wxSize &size );
205 
206 private:
207 
211  wxSize mMinSize;
212  wxSize mOrigSize;
213 
214 public:
215 
216  DECLARE_CLASS( ToolFrame )
217  DECLARE_EVENT_TABLE()
218 };
219 
220 
221 
222 // Construct a static instance of this class to add a menu item that shows and
223 // hides a toolbar
226  ToolBarID id, const CommandID &name, const TranslatableString &label_in,
227  const Registry::OrderingHint &hint = {},
228  // IDs of other toolbars not to be shown simultaneously with this one:
229  std::vector< ToolBarID > excludeIds = {} );
230 
231  void OnShowToolBar(const CommandContext &context);
232 
233  const ToolBarID mId;
235  const std::vector< ToolBarID > mExcludeIds;
236 };
237 
238 #endif
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
ToolBarConfiguration
Definition: ToolDock.h:50
AttachedToolBarMenuItem::mId
const ToolBarID mId
Definition: ToolManager.h:233
ToolFrame::mMinSize
wxSize mMinSize
Definition: ToolManager.h:211
ToolDock
A dynamic panel where a ToolBar can be docked.
Definition: ToolDock.h:290
ToolBarCount
@ ToolBarCount
Definition: ToolBar.h:87
ToolBarConfiguration::Position
Definition: ToolDock.h:70
ToolManager::mCurrent
wxRegion * mCurrent
Definition: ToolManager.h:132
ToolManager::operator=
ToolManager & operator=(const ToolManager &) PROHIBITED
ToolFrame
class ToolFrame
Definition: ToolManager.h:166
ToolFrame::LockInMinSize
void LockInMinSize(ToolBar *pBar)
Definition: ToolManager.cpp:156
ToolFrame::ClearBar
void ClearBar()
Definition: ToolManager.h:174
ToolFrame::mParent
AudacityProject *const mParent
Definition: ToolManager.h:208
ToolFrame::mBar
ToolBar * mBar
Definition: ToolManager.h:210
ToolManager::mDragDock
ToolDock * mDragDock
Definition: ToolManager.h:121
ClientData::Base
A convenient default parameter for class template Site.
Definition: ClientData.h:28
ToolBar::Holder
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:102
MenuTable::AttachedItem
Definition: CommandManager.h:708
ClientData.h
Utility ClientData::Site to register hooks into a host class that attach client data.
ToolManager::mParent
AudacityProject * mParent
Definition: ToolManager.h:117
ToolFrame::OnCaptureLost
void OnCaptureLost(wxMouseCaptureLostEvent &WXUNUSED(event))
Definition: ToolManager.cpp:283
AttachedToolBarMenuItem
Definition: ToolManager.h:224
ToolFrame::OnToolBarUpdate
void OnToolBarUpdate(wxCommandEvent &event)
Definition: ToolManager.cpp:171
ToolManager::mIndicator
FramePtr mIndicator
Definition: ToolManager.h:130
ToolFrame::GetBar
ToolBar * GetBar()
Definition: ToolManager.h:173
ToolManager::mLastState
bool mLastState
Definition: ToolManager.h:135
ToolDock.h
ToolManager::mLeft
std::unique_ptr< wxRegion > mLeft
Definition: ToolManager.h:131
ToolFrame::OnKeyDown
void OnKeyDown(wxKeyEvent &event)
Definition: ToolManager.cpp:296
AttachedToolBarMenuItem::mAttachedItem
const MenuTable::AttachedItem mAttachedItem
Definition: ToolManager.h:234
ToolManager::FramePtr
Destroy_ptr< wxFrame > FramePtr
Definition: ToolManager.h:129
ToolFrame::~ToolFrame
~ToolFrame()
Definition: ToolManager.cpp:142
ToolManager::mDragOffset
wxPoint mDragOffset
Definition: ToolManager.h:123
CommandContext
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Definition: CommandContext.h:34
BasicUI::Get
Services * Get()
Fetch the global instance, or nullptr if none is yet installed.
Definition: BasicUI.cpp:26
ToolFrame::mManager
ToolManager * mManager
Definition: ToolManager.h:209
ProjectWindow
A top-level window associated with a project, and handling scrollbars and zooming.
Definition: ProjectWindow.h:32
ToolFrame::OnClose
void OnClose(wxCloseEvent &event)
Definition: ToolManager.cpp:291
ToolBarConfiguration::UnspecifiedPosition
static const Position UnspecifiedPosition
Definition: ToolDock.h:105
ToolManager::mLastPos
wxPoint mLastPos
Definition: ToolManager.h:126
ToolManager::mPrevConfiguration
ToolBarConfiguration mPrevConfiguration
Definition: ToolManager.h:150
name
const TranslatableString name
Definition: Distortion.cpp:98
ToolFrame::OnPaint
void OnPaint(wxPaintEvent &WXUNUSED(event))
Definition: ToolManager.cpp:182
ToolManager::mTimer
wxTimer mTimer
Definition: ToolManager.h:134
ToolManager::GetTopPanelHook
std::function< wxWindow *(wxWindow &) > GetTopPanelHook
Definition: ToolManager.h:58
ToolManager::ToolManager
ToolManager(const ToolManager &) PROHIBITED
ToolFrame::mOrigSize
wxSize mOrigSize
Definition: ToolManager.h:212
ToolManager::mBarPos
wxRect mBarPos
Definition: ToolManager.h:127
GrabberEvent
Grabber Class.
Definition: Grabber.h:48
Registry::OrderingHint
Definition: Registry.h:24
ToolManager::Float
ToolBar * Float(ToolBar *t, wxPoint &pos)
ToolFrame::ToolFrame
ToolFrame(AudacityProject *parent, ToolManager *manager, ToolBar *bar, wxPoint pos)
Definition: ToolManager.cpp:75
ToolBarID
ToolBarID
Definition: ToolBar.h:70
TaggedIdentifier< CommandIdTag, false >
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
CommandHandlerObject
wxEvtHandler CommandHandlerObject
Definition: CommandFunctors.h:28
ToolBar
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:98
ToolFrame::OnMotion
void OnMotion(wxMouseEvent &event)
Definition: ToolManager.cpp:209
Destroy_ptr
std::unique_ptr< T, Destroyer< T > > Destroy_ptr
a convenience for using Destroyer
Definition: MemoryX.h:290
AttachedToolBarMenuItem::mExcludeIds
const std::vector< ToolBarID > mExcludeIds
Definition: ToolManager.h:235
ToolFrame::Resize
void Resize(const wxSize &size)
Definition: ToolManager.cpp:305
ToolManager::mDragWindow
ToolFrame * mDragWindow
Definition: ToolManager.h:120
ToolManager
class ToolManager
Definition: ToolManager.h:54
ToolFrame::OnGrabber
void OnGrabber(GrabberEvent &event)
Definition: ToolManager.cpp:148