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,
83#ifdef EXPERIMENTAL_SPECTRAL_EDITING
84 SpectralSelectionBarID,
85#endif
88};
89
90// How may pixels padding each side of a floating toolbar
91enum { ToolBarFloatMargin = 1 };
92
93class AudacityProject;
94
95class AUDACITY_DLL_API ToolBar /* not final */
96: public wxPanelWrapper
97, protected PrefsListener
98{
99
100 public:
101
102 using Holder = wxWindowPtr<ToolBar>;
103
104 ToolBar( AudacityProject &project,
105 int type, const TranslatableString & label, const wxString & section,
106 bool resizable = false);
107 virtual ~ToolBar();
108
109 bool AcceptsFocus() const override { return false; };
110
111 virtual void SetToDefaultSize();
112 //NEW virtuals:
113 virtual void Create(wxWindow *parent);
114 virtual void EnableDisableButtons() = 0;
115 virtual void ReCreateButtons();
116 void UpdatePrefs() override;
117 virtual void RegenerateTooltips() = 0;
118
119 int GetType();
120 TranslatableString GetTitle();
121 TranslatableString GetLabel();
122 wxString GetSection();
123 ToolDock *GetDock();
124
125private:
126 void SetLabel(const wxString & label) override;
127public:
128 void SetLabel(const TranslatableString & label);
129 virtual void SetDocked(ToolDock *dock, bool pushed);
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 static
167 void MakeAlternateImages(AButton &button, int idx,
168 teBmps eUp,
169 teBmps eDown,
170 teBmps eHilite,
171 teBmps eDownHi,
172 teBmps eStandardUp,
173 teBmps eStandardDown,
174 teBmps eDisabled,
175 wxSize size);
176
177 static
178 void SetButtonToolTip
179 (AudacityProject &project, AButton &button,
180 // If a shortcut key is defined for the command, then it is appended,
181 // parenthesized, after the translated name.
182 const ComponentInterfaceSymbol commands[], size_t nCommands);
183
184 static void MakeButtonBackgroundsSmall();
185 static void MakeButtonBackgroundsLarge();
186 virtual void ResizingDone() {};
187
188 protected:
189 void SetButton(bool down, AButton *button);
190
191 static void MakeMacRecoloredImage(teBmps eBmpOut, teBmps eBmpIn);
192 static void MakeRecoloredImage(teBmps eBmpOut, teBmps eBmpIn);
193
194 wxBoxSizer *GetSizer();
195
196 void Add(wxWindow *window,
197 int proportion = 0,
198 int flag = wxALIGN_TOP,
199 int border = 0,
200 wxObject *userData = NULL);
201
202 // Takes ownership of sizer
203 void Add(wxSizer *sizer,
204 int proportion = 0,
205 int flag = 0,
206 int border = 0,
207 wxObject *userData = NULL);
208
209 void Add(int width,
210 int height,
211 int proportion = 0,
212 int flag = 0,
213 int border = 0,
214 wxObject *userData = NULL);
215
216 void AddSpacer(int size = 14);
217 void AddStretchSpacer(int prop = 1);
218
219 void Detach(wxWindow *window);
220 void Detach(wxSizer *sizer);
221
222 void Updated();
223
225 int GetResizeGrabberWidth();
226
227 virtual void Populate() = 0;
228 virtual void Repaint(wxDC *dc) = 0;
229
230 void OnErase(wxEraseEvent & event);
231 void OnPaint(wxPaintEvent & event);
232 void OnMouseEvents(wxMouseEvent &event);
233
234 protected:
237 wxString mSection;
238 int mType;
239 private:
240 void Init(wxWindow *parent, int type, const wxString & title, const wxString & label);
241
242 wxWindow *mParent;
243
246
247 wxBoxSizer *mHSizer;
248
251 bool mPositioned; // true if position floating determined.
252
253 public:
254
255 DECLARE_CLASS(ToolBar)
256 DECLARE_EVENT_TABLE()
257
258 friend class ToolBarResizer;
259};
260
261struct AUDACITY_DLL_API RegisteredToolbarFactory {
262 using Function = std::function< ToolBar::Holder( AudacityProject & ) >;
263 using Functions = std::vector< Function >;
264
265 RegisteredToolbarFactory( int id, const Function &function );
266
267 static const Functions &GetFactories();
268};
269
270#endif
int teBmps
static const auto title
TranslatableString label
Definition: TagsEditor.cpp:163
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TOOLBAR_UPDATED, -1)
class ToolBar
@ ToolBarFloatMargin
Definition: ToolBar.h:91
ToolBarID
Definition: ToolBar.h:70
@ NoBarID
Definition: ToolBar.h:71
@ ScrubbingBarID
Definition: ToolBar.h:80
@ RecordMeterBarID
Definition: ToolBar.h:75
@ PlayMeterBarID
Definition: ToolBar.h:76
@ DeviceBarID
Definition: ToolBar.h:81
@ SelectionBarID
Definition: ToolBar.h:82
@ TranscriptionBarID
Definition: ToolBar.h:79
@ TimeBarID
Definition: ToolBar.h:86
@ TransportBarID
Definition: ToolBar.h:72
@ MeterBarID
Definition: ToolBar.h:74
@ MixerBarID
Definition: ToolBar.h:77
@ ToolsBarID
Definition: ToolBar.h:73
@ ToolBarCount
Definition: ToolBar.h:87
@ EditBarID
Definition: ToolBar.h:78
static std::once_flag flag
A wxButton with mouse-over behaviour.
Definition: AButton.h:25
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:474
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:98
int mType
Definition: ToolBar.h:238
AudacityProject & mProject
Definition: ToolBar.h:235
bool mVisible
Definition: ToolBar.h:249
bool AcceptsFocus() const override
Definition: ToolBar.h:109
virtual void EnableDisableButtons()=0
virtual void Populate()=0
wxWindow * mParent
Definition: ToolBar.h:242
virtual int GetMinToolbarWidth()
Definition: ToolBar.h:144
TranslatableString mLabel
Definition: ToolBar.h:236
virtual void ResizingDone()
Definition: ToolBar.h:186
wxBoxSizer * mHSizer
Definition: ToolBar.h:247
void Init(wxWindow *parent, int type, const wxString &title, const wxString &label)
virtual void RegenerateTooltips()=0
bool IsPositioned()
Definition: ToolBar.h:137
bool mPositioned
Definition: ToolBar.h:251
void SetPositioned()
Definition: ToolBar.h:139
bool mResizable
Definition: ToolBar.h:250
virtual int GetInitialWidth()
Resizable toolbars should implement these.
Definition: ToolBar.h:143
virtual void Repaint(wxDC *dc)=0
Grabber * mGrabber
Definition: ToolBar.h:244
ToolBarResizer * mResizer
Definition: ToolBar.h:245
wxString mSection
Definition: ToolBar.h:237
virtual wxSize GetDockedSize()
Definition: ToolBar.h:145
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:102
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:263
std::function< ToolBar::Holder(AudacityProject &) > Function
Definition: ToolBar.h:262