Audacity  3.0.3
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 
25 class wxBoxSizer;
26 class wxDC;
27 class wxEraseEvent;
28 class wxMouseEvent;
29 class wxObject;
30 class wxPaintEvent;
31 class wxPoint;
32 class wxSize;
33 class wxSizeEvent;
34 class wxString;
35 class wxWindow;
36 
37 class AButton;
38 class Grabber;
39 class ToolDock;
40 
41 class ToolBarResizer;
42 
43 #ifdef __WXMAC__
44 #define USE_AQUA_THEME 1
45 #endif
46 
50 
51 //
52 // Custom event
53 //
54 DECLARE_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
91 enum { ToolBarFloatMargin = 1 };
92 
93 class AudacityProject;
94 
95 class 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 
125 private:
126  void SetLabel(const wxString & label) override;
127 public:
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 
249  bool mVisible;
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 
261 struct 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
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
ToolBar::Populate
virtual void Populate()=0
TimeBarID
@ TimeBarID
Definition: ToolBar.h:86
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
teBmps
int teBmps
Definition: ImageManipulation.h:48
ToolDock
A dynamic panel where a ToolBar can be docked.
Definition: ToolDock.h:290
ToolBar::Init
void Init(wxWindow *parent, int type, const wxString &title, const wxString &label)
RegisteredToolbarFactory::Functions
std::vector< Function > Functions
Definition: ToolBar.h:263
ToolBarCount
@ ToolBarCount
Definition: ToolBar.h:87
ToolBar::ResizingDone
virtual void ResizingDone()
Definition: ToolBar.h:186
flag
static std::once_flag flag
Definition: WaveformView.cpp:1119
AButton
A wxButton with mouse-over behaviour.
Definition: AButton.h:25
wxPanelWrapper
Definition: wxPanelWrapper.h:41
wxPanelWrapper::SetLabel
void SetLabel(const TranslatableString &label)
Definition: wxPanelWrapper.cpp:46
ToolBar::mProject
AudacityProject & mProject
Definition: ToolBar.h:235
DeviceBarID
@ DeviceBarID
Definition: ToolBar.h:81
PlayMeterBarID
@ PlayMeterBarID
Definition: ToolBar.h:76
ToolBar::mResizable
bool mResizable
Definition: ToolBar.h:250
ToolBar::EnableDisableButtons
virtual void EnableDisableButtons()=0
ToolBar::mVisible
bool mVisible
Definition: ToolBar.h:249
ToolBar::mSection
wxString mSection
Definition: ToolBar.h:237
ToolBar::Holder
wxWindowPtr< ToolBar > Holder
Definition: ToolBar.h:102
ToolBar::mParent
wxWindow * mParent
Definition: ToolBar.h:242
Grabber
The widget to the left of a ToolBar that allows it to be dragged around to NEW positions.
Definition: Grabber.h:103
DECLARE_EXPORTED_EVENT_TYPE
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_TOOLBAR_UPDATED, -1)
class ToolBar
TransportBarID
@ TransportBarID
Definition: ToolBar.h:72
ComponentInterfaceSymbol
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
Definition: ComponentInterfaceSymbol.h:27
ToolBar::mLabel
TranslatableString mLabel
Definition: ToolBar.h:236
PrefsListener
A listener notified of changes in preferences.
Definition: Prefs.h:392
ToolsBarID
@ ToolsBarID
Definition: ToolBar.h:73
ToolBar::IsPositioned
bool IsPositioned()
Definition: ToolBar.h:137
label
TranslatableString label
Definition: Tags.cpp:756
MixerBarID
@ MixerBarID
Definition: ToolBar.h:77
ToolBar::mPositioned
bool mPositioned
Definition: ToolBar.h:251
ToolBar::mType
int mType
Definition: ToolBar.h:238
ScrubbingBarID
@ ScrubbingBarID
Definition: ToolBar.h:80
ToolBar::SetPositioned
void SetPositioned()
Definition: ToolBar.h:139
ToolBar::Repaint
virtual void Repaint(wxDC *dc)=0
Theme.h
RegisteredToolbarFactory::Function
std::function< ToolBar::Holder(AudacityProject &) > Function
Definition: ToolBar.h:262
ToolBar::mHSizer
wxBoxSizer * mHSizer
Definition: ToolBar.h:247
ToolBarFloatMargin
@ ToolBarFloatMargin
Definition: ToolBar.h:91
ToolBar::GetInitialWidth
virtual int GetInitialWidth()
Resizable toolbars should implement these.
Definition: ToolBar.h:143
ToolBar::mGrabber
Grabber * mGrabber
Definition: ToolBar.h:244
ToolBar::GetDockedSize
virtual wxSize GetDockedSize()
Definition: ToolBar.h:145
SelectionBarID
@ SelectionBarID
Definition: ToolBar.h:82
TranscriptionBarID
@ TranscriptionBarID
Definition: ToolBar.h:79
RegisteredToolbarFactory
Definition: ToolBar.h:261
title
static const auto title
Definition: NoUpdatesAvailableDialog.cpp:22
ToolBarID
ToolBarID
Definition: ToolBar.h:70
ToolBar::GetMinToolbarWidth
virtual int GetMinToolbarWidth()
Definition: ToolBar.h:144
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
EditBarID
@ EditBarID
Definition: ToolBar.h:78
ToolBarResizer
a wxWindow that provides the resizer for a toolbar on the right hand side. Responsible for drawing th...
Definition: ToolBar.cpp:71
ToolBar::AcceptsFocus
bool AcceptsFocus() const override
Definition: ToolBar.h:109
ToolBar
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:98
wxPanelWrapper::Create
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"))
Definition: wxPanelWrapper.h:59
PrefsListener::UpdatePrefs
virtual void UpdatePrefs()=0
MeterBarID
@ MeterBarID
Definition: ToolBar.h:74
ToolBar::RegenerateTooltips
virtual void RegenerateTooltips()=0
Prefs.h
RecordMeterBarID
@ RecordMeterBarID
Definition: ToolBar.h:75
ToolBar::mResizer
ToolBarResizer * mResizer
Definition: ToolBar.h:245
ActiveProjects::Add
void Add(const FilePath &path)
NoBarID
@ NoBarID
Definition: ToolBar.h:71