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 "../widgets/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//
67// ToolBar IDs
68//
70{
71 NoBarID = -1,
82#ifdef EXPERIMENTAL_SPECTRAL_EDITING
83 SpectralSelectionBarID,
84#endif
86#ifdef HAS_AUDIOCOM_UPLOAD
87 ShareAudioBarID,
88#endif
91};
92
93// How may pixels padding each side of a floating toolbar
94enum { ToolBarFloatMargin = 1 };
95
96class AudacityProject;
97
98class AUDACITY_DLL_API ToolBar /* not final */
99: public wxPanelWrapper
100, protected PrefsListener
101{
102
103 public:
104
105 using Holder = wxWindowPtr<ToolBar>;
106
107 ToolBar( AudacityProject &project,
108 int type, const TranslatableString & label, const wxString & section,
109 bool resizable = false);
110 virtual ~ToolBar();
111
112 bool AcceptsFocus() const override { return false; };
113
114 virtual void SetToDefaultSize();
115 //NEW virtuals:
116 virtual void Create(wxWindow *parent);
117 virtual void EnableDisableButtons() = 0;
118 virtual void ReCreateButtons();
119 void UpdatePrefs() override;
120 virtual void RegenerateTooltips() = 0;
121
122 int GetType();
123 TranslatableString GetTitle();
124 TranslatableString GetLabel();
125 wxString GetSection();
126 ToolDock *GetDock();
127
128private:
129 void SetLabel(const wxString & label) override;
130public:
131 void SetLabel(const TranslatableString & label);
132 virtual void SetDocked(ToolDock *dock, bool pushed);
133
134 // NEW virtual:
135 virtual bool Expose(bool show = true);
136
137 bool IsResizable() const;
138 bool IsVisible() const;
139 bool IsDocked() const;
140 bool IsPositioned(){ return mPositioned; };
141 void SetVisible( bool bVisible );
142 void SetPositioned(){ mPositioned = true;};
143
145 // NEW virtuals:
146 virtual int GetInitialWidth() { return -1; }
147 virtual int GetMinToolbarWidth() { return GetInitialWidth(); }
148 virtual wxSize GetDockedSize() { return GetMinSize(); }
149
150 // Utility function for certain resizable toolbars.
151 // Allows them to dock at normal or double size.
152 wxSize GetSmartDockedSize();
153
154 public:
155 static
156 AButton *MakeButton(wxWindow *parent,
157 teBmps eUp,
158 teBmps eDown,
159 teBmps eHilite,
160 teBmps eDownHi,
161 teBmps eStandardUp,
162 teBmps eStandardDown,
163 teBmps eDisabled,
164 wxWindowID id,
165 wxPoint placement,
166 bool processdownevents,
167 wxSize size);
168
169
170 static
171 AButton *MakeButton(ToolBar *parent,
172 teBmps eEnabledUp,
173 teBmps eEnabledDown,
174 teBmps eDisabled,
175 int id,
176 bool processdownevents,
178
179 static
180 void MakeAlternateImages(AButton &button, int idx,
181 teBmps eUp,
182 teBmps eDown,
183 teBmps eHilite,
184 teBmps eDownHi,
185 teBmps eStandardUp,
186 teBmps eStandardDown,
187 teBmps eDisabled,
188 wxSize size);
189
190 static
191 void SetButtonToolTip
192 (AudacityProject &project, AButton &button,
193 // If a shortcut key is defined for the command, then it is appended,
194 // parenthesized, after the translated name.
195 const ComponentInterfaceSymbol commands[], size_t nCommands);
196
197 static void MakeButtonBackgroundsSmall();
198 static void MakeButtonBackgroundsLarge();
199 virtual void ResizingDone() {};
200
201 protected:
202 void SetButton(bool down, AButton *button);
203
204 static void MakeMacRecoloredImage(teBmps eBmpOut, teBmps eBmpIn);
205 static void MakeMacRecoloredImageSize(teBmps eBmpOut, teBmps eBmpIn, const wxSize& size);
206 static void MakeRecoloredImage(teBmps eBmpOut, teBmps eBmpIn);
207 static void MakeRecoloredImageSize(teBmps eBmpOut, teBmps eBmpIn, const wxSize& size);
208
209 wxBoxSizer *GetSizer();
210
211 void Add(wxWindow *window,
212 int proportion = 0,
213 int flag = wxALIGN_TOP,
214 int border = 0,
215 wxObject *userData = NULL);
216
217 // Takes ownership of sizer
218 void Add(wxSizer *sizer,
219 int proportion = 0,
220 int flag = 0,
221 int border = 0,
222 wxObject *userData = NULL);
223
224 void Add(int width,
225 int height,
226 int proportion = 0,
227 int flag = 0,
228 int border = 0,
229 wxObject *userData = NULL);
230
231 void AddSpacer(int size = 14);
232 void AddStretchSpacer(int prop = 1);
233
234 void Detach(wxWindow *window);
235 void Detach(wxSizer *sizer);
236
237 void Updated();
238
240 int GetResizeGrabberWidth();
241
242 virtual void Populate() = 0;
243 virtual void Repaint(wxDC *dc) = 0;
244
245 void OnErase(wxEraseEvent & event);
246 void OnPaint(wxPaintEvent & event);
247 void OnMouseEvents(wxMouseEvent &event);
248
249 protected:
252 wxString mSection;
253 int mType;
254 private:
255 void Init(wxWindow *parent, int type, const wxString & title, const wxString & label);
256
257 wxWindow *mParent;
258
261
262 wxBoxSizer *mHSizer;
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( int id, const Function &function );
281
282 static const Functions &GetFactories();
283};
284
285#endif
int teBmps
static const auto title
TranslatableString label
Definition: TagsEditor.cpp:163
@ ToolBarFloatMargin
Definition: ToolBar.h:94
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TOOLBAR_UPDATED, -1)
class ToolBar
ToolBarID
Definition: ToolBar.h:70
@ NoBarID
Definition: ToolBar.h:71
@ ScrubbingBarID
Definition: ToolBar.h:79
@ RecordMeterBarID
Definition: ToolBar.h:75
@ PlayMeterBarID
Definition: ToolBar.h:76
@ DeviceBarID
Definition: ToolBar.h:80
@ SelectionBarID
Definition: ToolBar.h:81
@ TranscriptionBarID
Definition: ToolBar.h:78
@ TimeBarID
Definition: ToolBar.h:89
@ TransportBarID
Definition: ToolBar.h:72
@ MeterBarID
Definition: ToolBar.h:74
@ ToolsBarID
Definition: ToolBar.h:73
@ AudioSetupBarID
Definition: ToolBar.h:85
@ ToolBarCount
Definition: ToolBar.h:90
@ EditBarID
Definition: ToolBar.h:77
static std::once_flag flag
A wxButton with mouse-over behaviour.
Definition: AButton.h:26
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
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:103
A listener notified of changes in preferences.
Definition: Prefs.h:543
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:101
int mType
Definition: ToolBar.h:253
AudacityProject & mProject
Definition: ToolBar.h:250
bool mVisible
Definition: ToolBar.h:264
bool AcceptsFocus() const override
Definition: ToolBar.h:112
virtual void EnableDisableButtons()=0
virtual void Populate()=0
wxWindow * mParent
Definition: ToolBar.h:257
virtual int GetMinToolbarWidth()
Definition: ToolBar.h:147
TranslatableString mLabel
Definition: ToolBar.h:251
virtual void ResizingDone()
Definition: ToolBar.h:199
wxBoxSizer * mHSizer
Definition: ToolBar.h:262
void Init(wxWindow *parent, int type, const wxString &title, const wxString &label)
virtual void RegenerateTooltips()=0
bool IsPositioned()
Definition: ToolBar.h:140
bool mPositioned
Definition: ToolBar.h:266
void SetPositioned()
Definition: ToolBar.h:142
bool mResizable
Definition: ToolBar.h:265
virtual int GetInitialWidth()
Resizable toolbars should implement these.
Definition: ToolBar.h:146
virtual void Repaint(wxDC *dc)=0
Grabber * mGrabber
Definition: ToolBar.h:259
ToolBarResizer * mResizer
Definition: ToolBar.h:260
wxString mSection
Definition: ToolBar.h:252
virtual wxSize GetDockedSize()
Definition: ToolBar.h:148
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:105
a wxWindow that provides the resizer for a toolbar on the right hand side. Responsible for drawing th...
Definition: ToolBar.cpp:71
A dynamic panel where a ToolBar can be docked.
Definition: ToolDock.h:290
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"))
void Add(const FilePath &path)
AUDACITY_DLL_API void UpdatePrefs(wxWindow *pParent)
std::vector< Function > Functions
Definition: ToolBar.h:278
std::function< ToolBar::Holder(AudacityProject &) > Function
Definition: ToolBar.h:277