Audacity 3.2.0
ToolBar.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 ToolBar.h
6
7 Dominic Mazzoni
8 Shane T. Mueller
9 Leland Lucius
10
11**********************************************************************/
12
13#ifndef __AUDACITY_TOOLBAR__
14#define __AUDACITY_TOOLBAR__
15
16#include <functional>
17#include <vector>
18#include <wx/defs.h>
19
20#include "Prefs.h"
21#include "Theme.h"
22#include "wxPanelWrapper.h" // to inherit
23#include <wx/windowptr.h>
24
25class wxBoxSizer;
26class wxDC;
27class wxEraseEvent;
28class wxMouseEvent;
29class wxObject;
30class wxPaintEvent;
31class wxPoint;
32class wxSize;
33class wxSizeEvent;
34class wxString;
35class wxWindow;
36
37class AButton;
38class Grabber;
39class ToolDock;
40
41class ToolBarResizer;
42
43#ifdef __WXMAC__
44#define USE_AQUA_THEME 1
45#endif
46
50
51//
52// Custom event
53//
54DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TOOLBAR_UPDATED, -1);
55
56//
57// Height of a single line toolbar
58//
59#define toolbarSingle 27
60
61//
62// Size of border around toolbars
63//
64#define toolbarGap 1
65
66// How may pixels padding each side of a floating toolbar
67enum { ToolBarFloatMargin = 1 };
68
69class AudacityProject;
70
71class AUDACITY_DLL_API ToolBar /* not final */
72: public wxPanelWrapper
73, protected PrefsListener
74{
75
76 public:
77
78 using Holder = wxWindowPtr<ToolBar>;
79
81 const TranslatableString & label, const Identifier &section,
82 bool resizable = false);
83 virtual ~ToolBar();
84
86 virtual bool ShownByDefault() const;
87
89 virtual bool HideAfterReset() const;
90
92 enum DockID {
94 BotDockID = 2
95 };
96
98 virtual DockID DefaultDockID() const;
99
100 bool AcceptsFocus() const override { return false; };
101 bool AcceptsFocusFromKeyboard() const override;
102
103 virtual void SetToDefaultSize();
104 //NEW virtuals:
105 virtual void Create(wxWindow *parent);
106 virtual void EnableDisableButtons() = 0;
107 virtual void ReCreateButtons();
108 void UpdatePrefs() override;
109 virtual void RegenerateTooltips() = 0;
110
112 int GetIndex() const { return mIndex; }
114 void SetIndex(int index) { mIndex = index; }
115
116 TranslatableString GetTitle();
117 TranslatableString GetLabel();
118 Identifier GetSection();
119 ToolDock *GetDock();
120
121 void SetPreferredNeighbors(Identifier left, Identifier top = {});
122
123private:
124 void SetLabel(const wxString & label) override;
125public:
126 void SetLabel(const TranslatableString & label);
127 virtual void SetDocked(ToolDock *dock, bool pushed);
128
130 std::pair<Identifier, Identifier> PreferredNeighbors() const noexcept;
131
132 // NEW virtual:
133 virtual bool Expose(bool show = true);
134
135 bool IsResizable() const;
136 bool IsVisible() const;
137 bool IsDocked() const;
138 bool IsPositioned(){ return mPositioned; };
139 void SetVisible( bool bVisible );
140 void SetPositioned(){ mPositioned = true;};
141
143 // NEW virtuals:
144 virtual int GetInitialWidth() { return -1; }
145 virtual int GetMinToolbarWidth() { return GetInitialWidth(); }
146 virtual wxSize GetDockedSize() { return GetMinSize(); }
147
148 // Utility function for certain resizable toolbars.
149 // Allows them to dock at normal or double size.
150 wxSize GetSmartDockedSize();
151
152 public:
153 static
154 AButton *MakeButton(wxWindow *parent,
155 teBmps eUp,
156 teBmps eDown,
157 teBmps eHilite,
158 teBmps eDownHi,
159 teBmps eStandardUp,
160 teBmps eStandardDown,
161 teBmps eDisabled,
162 wxWindowID id,
163 wxPoint placement,
164 bool processdownevents,
165 wxSize size);
166
167
168 static
169 AButton *MakeButton(ToolBar *parent,
170 teBmps eEnabledUp,
171 teBmps eEnabledDown,
172 teBmps eDisabled,
173 int id,
174 bool processdownevents,
176
177 static
178 void MakeAlternateImages(AButton &button, int idx,
179 teBmps eUp,
180 teBmps eDown,
181 teBmps eHilite,
182 teBmps eDownHi,
183 teBmps eStandardUp,
184 teBmps eStandardDown,
185 teBmps eDisabled,
186 wxSize size);
187
188 static
189 void SetButtonToolTip
191 // If a shortcut key is defined for the command, then it is appended,
192 // parenthesized, after the translated name.
193 const ComponentInterfaceSymbol commands[], size_t nCommands);
194
195 static void MakeButtonBackgroundsSmall();
196 static void MakeButtonBackgroundsLarge();
197 virtual void ResizingDone() {};
198
199 protected:
200 void SetButton(bool down, AButton *button);
201
202 static void MakeMacRecoloredImage(teBmps eBmpOut, teBmps eBmpIn);
203 static void MakeMacRecoloredImageSize(teBmps eBmpOut, teBmps eBmpIn, const wxSize& size);
204 static void MakeRecoloredImage(teBmps eBmpOut, teBmps eBmpIn);
205 static void MakeRecoloredImageSize(teBmps eBmpOut, teBmps eBmpIn, const wxSize& size);
206
207 wxBoxSizer *GetSizer();
208
209 void Add(wxWindow *window,
210 int proportion = 0,
211 int flag = wxALIGN_TOP,
212 int border = 0,
213 wxObject *userData = NULL);
214
215 // Takes ownership of sizer
216 void Add(wxSizer *sizer,
217 int proportion = 0,
218 int flag = 0,
219 int border = 0,
220 wxObject *userData = NULL);
221
222 void Add(int width,
223 int height,
224 int proportion = 0,
225 int flag = 0,
226 int border = 0,
227 wxObject *userData = NULL);
228
229 void AddSpacer(int size = 14);
230 void AddStretchSpacer(int prop = 1);
231
232 void Detach(wxWindow *window);
233 void Detach(wxSizer *sizer);
234
235 void Updated();
236
238 int GetResizeGrabberWidth();
239
240 virtual void Populate() = 0;
241 virtual void Repaint(wxDC *dc) = 0;
242
243 void OnErase(wxEraseEvent & event);
244 void OnPaint(wxPaintEvent & event);
245 void OnMouseEvents(wxMouseEvent &event);
246
247 protected:
251 int mIndex{0};
252 private:
253 void Init(wxWindow *parent, int type, const wxString & title, const wxString & label);
254
255 wxWindow *mParent;
256
259
260 wxBoxSizer *mHSizer;
261
264
267 bool mPositioned; // true if position floating determined.
268
269 public:
270
271 DECLARE_CLASS(ToolBar)
272 DECLARE_EVENT_TABLE()
273
274 friend class ToolBarResizer;
275};
276
277struct AUDACITY_DLL_API RegisteredToolbarFactory {
278 using Function = std::function< ToolBar::Holder( AudacityProject & ) >;
279 using Functions = std::vector< Function >;
280
281 RegisteredToolbarFactory( const Function &function );
282
283 static const Functions &GetFactories();
284};
285
286#endif
int teBmps
static const auto title
TranslatableString label
Definition: TagsEditor.cpp:165
const auto project
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TOOLBAR_UPDATED, -1)
class ToolBar
@ ToolBarFloatMargin
Definition: ToolBar.h:67
@ BotDockID
Definition: ToolDock.h:44
@ TopDockID
Definition: ToolDock.h:43
static std::once_flag flag
A wxButton with mouse-over behaviour.
Definition: AButton.h:104
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
The widget to the left of a ToolBar that allows it to be dragged around to NEW positions.
Definition: Grabber.h:107
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
A listener notified of changes in preferences.
Definition: Prefs.h:652
virtual void UpdatePrefs()=0
Definition: Prefs.cpp:154
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:74
Identifier mPreferredTopNeighbor
Definition: ToolBar.h:263
Identifier mSection
Definition: ToolBar.h:250
void SetIndex(int index)
Set a value used for computing cascading positions of undocked bars.
Definition: ToolBar.h:114
AudacityProject & mProject
Definition: ToolBar.h:248
bool mVisible
Definition: ToolBar.h:265
bool AcceptsFocus() const override
Definition: ToolBar.h:100
virtual void EnableDisableButtons()=0
virtual void Populate()=0
wxWindow * mParent
Definition: ToolBar.h:255
DockID
Identifies one of the docking areas for toolbars.
Definition: ToolBar.h:92
Identifier mPreferredLeftNeighbor
Definition: ToolBar.h:262
virtual int GetMinToolbarWidth()
Definition: ToolBar.h:145
TranslatableString mLabel
Definition: ToolBar.h:249
int GetIndex() const
Get a value used for computing cascading positions of undocked bars.
Definition: ToolBar.h:112
virtual void ResizingDone()
Definition: ToolBar.h:197
wxBoxSizer * mHSizer
Definition: ToolBar.h:260
void Init(wxWindow *parent, int type, const wxString &title, const wxString &label)
virtual void RegenerateTooltips()=0
bool mPositioned
Definition: ToolBar.h:267
void SetPositioned()
Definition: ToolBar.h:140
bool mResizable
Definition: ToolBar.h:266
virtual int GetInitialWidth()
Resizable toolbars should implement these.
Definition: ToolBar.h:144
virtual void Repaint(wxDC *dc)=0
Grabber * mGrabber
Definition: ToolBar.h:257
ToolBarResizer * mResizer
Definition: ToolBar.h:258
virtual wxSize GetDockedSize()
Definition: ToolBar.h:146
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:78
a wxWindow that provides the resizer for a toolbar on the right hand side. Responsible for drawing th...
Definition: ToolBar.cpp:69
A dynamic panel where a ToolBar can be docked.
Definition: ToolDock.h:292
Holds a msgid for the translation catalog; may also bind format arguments.
void SetLabel(const TranslatableString &label)
bool Create(wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
PROJECT_FILE_IO_API void Add(const FilePath &path)
std::vector< Function > Functions
Definition: ToolBar.h:279
std::function< ToolBar::Holder(AudacityProject &) > Function
Definition: ToolBar.h:278