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
46
47//
48// Custom event
49//
50DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TOOLBAR_UPDATED, -1);
51
53constexpr static auto toolbarSingle { 31 };
55constexpr static auto toolbarMargin { 5 };
57constexpr static auto toolbarSpacing { 2 };
58//constexpr static auto toolbarGap { }
59
60//
61// Size of border around toolbars
62//
63#define toolbarGap 1
64
65// How may pixels padding each side of a floating toolbar
66enum { ToolBarFloatMargin = 1 };
67
68class AudacityProject;
69
70class AUDACITY_DLL_API ToolBar /* not final */
71: public wxPanelWrapper
72, protected PrefsListener
73{
74
75 public:
76
77 using Holder = wxWindowPtr<ToolBar>;
78
80 const TranslatableString & label, const Identifier &section,
81 bool resizable = false);
82 virtual ~ToolBar();
83
85 virtual bool ShownByDefault() const;
86
88 virtual bool HideAfterReset() const;
89
91 enum DockID {
93 BotDockID = 2
94 };
95
97 virtual DockID DefaultDockID() const;
98
99 bool AcceptsFocus() const override { return false; };
100 bool AcceptsFocusFromKeyboard() const override;
101
102 virtual void SetToDefaultSize();
103 //NEW virtuals:
104 virtual void Create(wxWindow *parent);
105 virtual void EnableDisableButtons() = 0;
106 virtual void ReCreateButtons();
107 void UpdatePrefs() override;
108 virtual void RegenerateTooltips() = 0;
109
111 int GetIndex() const { return mIndex; }
113 void SetIndex(int index) { mIndex = index; }
114
115 TranslatableString GetTitle();
116 TranslatableString GetLabel();
117 Identifier GetSection();
118 ToolDock *GetDock();
119
120 void SetPreferredNeighbors(Identifier left, Identifier top = {});
121
122private:
123 void SetLabel(const wxString & label) override;
124public:
125 void SetLabel(const TranslatableString & label);
126 virtual void SetDocked(ToolDock *dock, bool pushed);
127
129 std::pair<Identifier, Identifier> PreferredNeighbors() const noexcept;
130
131 // NEW virtual:
132 virtual bool Expose(bool show = true);
133
134 bool IsResizable() const;
135 bool IsVisible() const;
136 bool IsDocked() const;
137 bool IsPositioned(){ return mPositioned; };
138 void SetVisible( bool bVisible );
139 void SetPositioned(){ mPositioned = true;};
140
142 // NEW virtuals:
143 virtual int GetInitialWidth() { return -1; }
144 virtual int GetMinToolbarWidth() { return GetInitialWidth(); }
145 virtual wxSize GetDockedSize() { return GetMinSize(); }
146
147 // Utility function for certain resizable toolbars.
148 // Allows them to dock at normal or double size.
149 wxSize GetSmartDockedSize();
150
151 public:
152 static
153 AButton *MakeButton(wxWindow *parent,
154 teBmps eUp,
155 teBmps eDown,
156 teBmps eHilite,
157 teBmps eDownHi,
158 teBmps eStandardUp,
159 teBmps eStandardDown,
160 teBmps eDisabled,
161 wxWindowID id,
162 wxPoint placement,
163 bool processdownevents,
164 wxSize size);
165
166
167 static
168 AButton *MakeButton(ToolBar *parent,
169 teBmps eEnabledUp,
170 teBmps eEnabledDown,
171 teBmps eDisabled,
172 int id,
173 bool processdownevents,
175
176 static
177 void MakeAlternateImages(AButton &button, int idx,
178 teBmps eUp,
179 teBmps eDown,
180 teBmps eHilite,
181 teBmps eDownHi,
182 teBmps eStandardUp,
183 teBmps eStandardDown,
184 teBmps eDisabled,
185 wxSize size);
186
187 static
188 void SetButtonToolTip
190 // If a shortcut key is defined for the command, then it is appended,
191 // parenthesized, after the translated name.
192 const ComponentInterfaceSymbol commands[], size_t nCommands);
193
194 static void MakeButtonBackgroundsSmall();
195 static void MakeButtonBackgroundsLarge();
196 virtual void ResizingDone() {};
197
198 protected:
199 void SetButton(bool down, AButton *button);
200
201 static void MakeMacRecoloredImage(teBmps eBmpOut, teBmps eBmpIn);
202 static void MakeMacRecoloredImageSize(teBmps eBmpOut, teBmps eBmpIn, const wxSize& size);
203 static void MakeRecoloredImage(teBmps eBmpOut, teBmps eBmpIn);
204 static void MakeRecoloredImageSize(teBmps eBmpOut, teBmps eBmpIn, const wxSize& size);
205
206 wxBoxSizer *GetSizer();
207
208 void Add(wxWindow *window,
209 int proportion = 0,
210 int flag = wxALIGN_TOP,
211 int border = 0,
212 wxObject *userData = NULL);
213
214 // Takes ownership of sizer
215 void Add(wxSizer *sizer,
216 int proportion = 0,
217 int flag = 0,
218 int border = 0,
219 wxObject *userData = NULL);
220
221 void Add(int width,
222 int height,
223 int proportion = 0,
224 int flag = 0,
225 int border = 0,
226 wxObject *userData = NULL);
227
228 void AddSpacer(int size = 14);
229 void AddStretchSpacer(int prop = 1);
230
231 void Detach(wxWindow *window);
232 void Detach(wxSizer *sizer);
233
234 void Updated();
235
237 int GetResizeGrabberWidth();
238
239 virtual void Populate() = 0;
240 virtual void Repaint(wxDC *dc) = 0;
241
242 void OnErase(wxEraseEvent & event);
243 void OnPaint(wxPaintEvent & event);
244 void OnMouseEvents(wxMouseEvent &event);
245
246 protected:
250 int mIndex{0};
251 private:
252 void Init(wxWindow *parent, int type, const wxString & title, const wxString & label);
253
254 wxWindow *mParent;
255
258
259 wxBoxSizer *mHSizer;
260
263
266 bool mPositioned; // true if position floating determined.
267
268 public:
269
270 DECLARE_CLASS(ToolBar)
271 DECLARE_EVENT_TABLE()
272
273 friend class ToolBarResizer;
274};
275
276struct AUDACITY_DLL_API RegisteredToolbarFactory {
277 using Function = std::function< ToolBar::Holder( AudacityProject & ) >;
278 using Functions = std::vector< Function >;
279
280 RegisteredToolbarFactory( const Function &function );
281
282 static const Functions &GetFactories();
283};
284
285#endif
int teBmps
static const auto title
TranslatableString label
Definition: TagsEditor.cpp:165
const auto project
static constexpr auto toolbarSpacing
Preferred spacing between inner toolbar elements.
Definition: ToolBar.h:57
static constexpr auto toolbarSingle
Height of a single line toolbar.
Definition: ToolBar.h:53
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TOOLBAR_UPDATED, -1)
class ToolBar
static constexpr auto toolbarMargin
Preferred inner toolbar margin.
Definition: ToolBar.h:55
@ ToolBarFloatMargin
Definition: ToolBar.h:66
@ 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:73
Identifier mPreferredTopNeighbor
Definition: ToolBar.h:262
Identifier mSection
Definition: ToolBar.h:249
void SetIndex(int index)
Set a value used for computing cascading positions of undocked bars.
Definition: ToolBar.h:113
AudacityProject & mProject
Definition: ToolBar.h:247
bool mVisible
Definition: ToolBar.h:264
bool AcceptsFocus() const override
Definition: ToolBar.h:99
virtual void EnableDisableButtons()=0
virtual void Populate()=0
wxWindow * mParent
Definition: ToolBar.h:254
DockID
Identifies one of the docking areas for toolbars.
Definition: ToolBar.h:91
Identifier mPreferredLeftNeighbor
Definition: ToolBar.h:261
virtual int GetMinToolbarWidth()
Definition: ToolBar.h:144
TranslatableString mLabel
Definition: ToolBar.h:248
int GetIndex() const
Get a value used for computing cascading positions of undocked bars.
Definition: ToolBar.h:111
virtual void ResizingDone()
Definition: ToolBar.h:196
wxBoxSizer * mHSizer
Definition: ToolBar.h:259
void Init(wxWindow *parent, int type, const wxString &title, const wxString &label)
virtual void RegenerateTooltips()=0
bool mPositioned
Definition: ToolBar.h:266
void SetPositioned()
Definition: ToolBar.h:139
bool mResizable
Definition: ToolBar.h:265
virtual int GetInitialWidth()
Resizable toolbars should implement these.
Definition: ToolBar.h:143
virtual void Repaint(wxDC *dc)=0
Grabber * mGrabber
Definition: ToolBar.h:256
ToolBarResizer * mResizer
Definition: ToolBar.h:257
virtual wxSize GetDockedSize()
Definition: ToolBar.h:145
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:77
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:278
std::function< ToolBar::Holder(AudacityProject &) > Function
Definition: ToolBar.h:277