Audacity 3.2.0
Public Member Functions | Static Public Member Functions | Private Member Functions | Private Attributes | List of all members
SnappingToolBar Class Referencefinal

#include <SnappingToolBar.h>

Inheritance diagram for SnappingToolBar:
[legend]
Collaboration diagram for SnappingToolBar:
[legend]

Public Member Functions

 SnappingToolBar (AudacityProject &project)
 
virtual ~SnappingToolBar ()
 
bool ShownByDefault () const override
 Whether the toolbar should be shown by default. Default implementation returns true. More...
 
DockID DefaultDockID () const override
 Which dock the toolbar defaults into. Default implementation chooses the top dock. More...
 
void Create (wxWindow *parent) override
 
void Populate () override
 
void Repaint (wxDC *WXUNUSED(dc)) override
 
void EnableDisableButtons () override
 
void UpdatePrefs () override
 
void RegenerateTooltips () override
 
- Public Member Functions inherited from ToolBar
 ToolBar (AudacityProject &project, const TranslatableString &label, const Identifier &section, bool resizable=false)
 
virtual ~ToolBar ()
 
virtual bool ShownByDefault () const
 Whether the toolbar should be shown by default. Default implementation returns true. More...
 
virtual bool HideAfterReset () const
 Default implementation returns false. More...
 
virtual DockID DefaultDockID () const
 Which dock the toolbar defaults into. Default implementation chooses the top dock. More...
 
bool AcceptsFocus () const override
 
bool AcceptsFocusFromKeyboard () const override
 
virtual void SetToDefaultSize ()
 
virtual void Create (wxWindow *parent)
 
virtual void EnableDisableButtons ()=0
 
virtual void ReCreateButtons ()
 
void UpdatePrefs () override
 
virtual void RegenerateTooltips ()=0
 
int GetIndex () const
 Get a value used for computing cascading positions of undocked bars. More...
 
void SetIndex (int index)
 Set a value used for computing cascading positions of undocked bars. More...
 
TranslatableString GetTitle ()
 
TranslatableString GetLabel ()
 
Identifier GetSection ()
 
ToolDockGetDock ()
 
void SetPreferredNeighbors (Identifier left, Identifier top={})
 
void SetLabel (const TranslatableString &label)
 
virtual void SetDocked (ToolDock *dock, bool pushed)
 
std::pair< Identifier, IdentifierPreferredNeighbors () const noexcept
 Defaults to (NoBarID, NoBarId) More...
 
virtual bool Expose (bool show=true)
 
bool IsResizable () const
 
bool IsVisible () const
 
bool IsDocked () const
 
bool IsPositioned ()
 
void SetVisible (bool bVisible)
 
void SetPositioned ()
 
virtual int GetInitialWidth ()
 Resizable toolbars should implement these. More...
 
virtual int GetMinToolbarWidth ()
 
virtual wxSize GetDockedSize ()
 
wxSize GetSmartDockedSize ()
 
virtual void ResizingDone ()
 
- Public Member Functions inherited from wxPanelWrapper
 wxPanelWrapper ()
 
 wxPanelWrapper (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"))
 
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 SetLabel (const TranslatableString &label)
 
void SetName (const TranslatableString &name)
 
void SetToolTip (const TranslatableString &toolTip)
 
void SetName ()
 
- Public Member Functions inherited from wxTabTraversalWrapper< wxPanel >
 wxTabTraversalWrapper (Args &&... args)
 
 wxTabTraversalWrapper (const wxTabTraversalWrapper &)=delete
 
 wxTabTraversalWrapper (wxTabTraversalWrapper &&)=delete
 
wxTabTraversalWrapperoperator= (const wxTabTraversalWrapper &)=delete
 
wxTabTraversalWrapperoperator= (wxTabTraversalWrapper &&)=delete
 

Static Public Member Functions

static Identifier ID ()
 
static SnappingToolBarGet (AudacityProject &project)
 
static const SnappingToolBarGet (const AudacityProject &project)
 
- Static Public Member Functions inherited from ToolBar
static AButtonMakeButton (wxWindow *parent, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eDownHi, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxWindowID id, wxPoint placement, bool processdownevents, wxSize size)
 
static AButtonMakeButton (ToolBar *parent, teBmps eEnabledUp, teBmps eEnabledDown, teBmps eDisabled, int id, bool processdownevents, const TranslatableString &label)
 
static void MakeAlternateImages (AButton &button, int idx, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eDownHi, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxSize size)
 
static void SetButtonToolTip (AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
 
static void MakeButtonBackgroundsSmall ()
 
static void MakeButtonBackgroundsLarge ()
 

Private Member Functions

void OnSize (wxSizeEvent &evt)
 
void OnSnapModeChanged ()
 

Private Attributes

wxWeakRef< wxCheckBox > mSnapModeCheckBox
 
wxWeakRef< wxComboCtrl > mSnapToCombo
 
Observer::Subscription mSnappingModeChangedSubscription
 

Additional Inherited Members

- Public Types inherited from ToolBar
enum  DockID { TopDockID = 1 , BotDockID = 2 }
 Identifies one of the docking areas for toolbars. More...
 
using Holder = wxWindowPtr< ToolBar >
 
- Protected Member Functions inherited from ToolBar
void SetButton (bool down, AButton *button)
 
wxBoxSizer * GetSizer ()
 
void Add (wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
 
void Add (wxSizer *sizer, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 
void Add (int width, int height, int proportion=0, int flag=0, int border=0, wxObject *userData=NULL)
 
void AddSpacer (int size=14)
 
void AddStretchSpacer (int prop=1)
 
void Detach (wxWindow *window)
 
void Detach (wxSizer *sizer)
 
void Updated ()
 
int GetResizeGrabberWidth ()
 Returns the width in pixels of the resizer element. More...
 
virtual void Populate ()=0
 
virtual void Repaint (wxDC *dc)=0
 
void OnErase (wxEraseEvent &event)
 
void OnPaint (wxPaintEvent &event)
 
void OnMouseEvents (wxMouseEvent &event)
 
- Protected Member Functions inherited from PrefsListener
virtual void UpdateSelectedPrefs (int id)
 
 PrefsListener ()
 
virtual ~PrefsListener ()
 
virtual void UpdatePrefs ()=0
 
- Static Protected Member Functions inherited from ToolBar
static void MakeMacRecoloredImage (teBmps eBmpOut, teBmps eBmpIn)
 
static void MakeMacRecoloredImageSize (teBmps eBmpOut, teBmps eBmpIn, const wxSize &size)
 
static void MakeRecoloredImage (teBmps eBmpOut, teBmps eBmpIn)
 
static void MakeRecoloredImageSize (teBmps eBmpOut, teBmps eBmpIn, const wxSize &size)
 
- Static Protected Member Functions inherited from PrefsListener
static void Broadcast (int id=0)
 Call this static function to notify all PrefsListener objects. More...
 
- Protected Attributes inherited from ToolBar
AudacityProjectmProject
 
TranslatableString mLabel
 
Identifier mSection
 
int mIndex {0}
 

Detailed Description

Definition at line 30 of file SnappingToolBar.h.

Constructor & Destructor Documentation

◆ SnappingToolBar()

SnappingToolBar::SnappingToolBar ( AudacityProject project)

Definition at line 244 of file SnappingToolBar.cpp.

245 : ToolBar(project, XO("Snapping"), ID())
247 [this](auto settings)
248 {
250 mSnapModeCheckBox->SetValue(
251 settings.newSnapMode != SnapMode::SNAP_OFF);
252
253 if (mSnapToCombo)
254 mSnapToCombo->Enable(settings.newSnapMode != SnapMode::SNAP_OFF);
255 }))
256{
257#ifdef __WXGTK__
258 const auto height = 2 * toolbarSingle;
259 SetMinSize({ -1, height });
260 SetMaxSize({ -1, height });
261#endif
262}
XO("Cut/Copy/Paste")
const auto project
static constexpr auto toolbarSingle
Height of a single line toolbar.
Definition: ToolBar.h:53
static Settings & settings()
Definition: TrackInfo.cpp:51
static ProjectSnap & Get(AudacityProject &project)
Definition: ProjectSnap.cpp:27
static Identifier ID()
Observer::Subscription mSnappingModeChangedSubscription
wxWeakRef< wxComboCtrl > mSnapToCombo
wxWeakRef< wxCheckBox > mSnapModeCheckBox
AudacityProject & mProject
Definition: ToolBar.h:247
ToolBar(AudacityProject &project, const TranslatableString &label, const Identifier &section, bool resizable=false)
Definition: ToolBar.cpp:328

References mSnapModeCheckBox, mSnapToCombo, settings(), and SNAP_OFF.

Here is the call graph for this function:

◆ ~SnappingToolBar()

SnappingToolBar::~SnappingToolBar ( )
virtual

Definition at line 264 of file SnappingToolBar.cpp.

265{
266}

Member Function Documentation

◆ Create()

void SnappingToolBar::Create ( wxWindow *  parent)
overridevirtual

Reimplemented from ToolBar.

Definition at line 289 of file SnappingToolBar.cpp.

290{
291 ToolBar::Create(parent);
292 UpdatePrefs();
293}
void UpdatePrefs() override
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:492

References ToolBar::Create(), and UpdatePrefs().

Here is the call graph for this function:

◆ DefaultDockID()

ToolBar::DockID SnappingToolBar::DefaultDockID ( ) const
overridevirtual

Which dock the toolbar defaults into. Default implementation chooses the top dock.

Reimplemented from ToolBar.

Definition at line 273 of file SnappingToolBar.cpp.

274{
275 return BotDockID;
276}
@ BotDockID
Definition: ToolBar.h:93

References ToolBar::BotDockID.

◆ EnableDisableButtons()

void SnappingToolBar::EnableDisableButtons ( )
inlineoverridevirtual

Implements ToolBar.

Definition at line 48 of file SnappingToolBar.h.

48{};

◆ Get() [1/2]

SnappingToolBar & SnappingToolBar::Get ( AudacityProject project)
static

Definition at line 278 of file SnappingToolBar.cpp.

279{
280 auto &toolManager = ToolManager::Get( project );
281 return *static_cast<SnappingToolBar*>(toolManager.GetToolBar(ID()));
282}
static ToolManager & Get(AudacityProject &project)

References ToolManager::Get(), ID(), and project.

Referenced by Get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get() [2/2]

const SnappingToolBar & SnappingToolBar::Get ( const AudacityProject project)
static

Definition at line 284 of file SnappingToolBar.cpp.

285{
286 return Get( const_cast<AudacityProject&>( project )) ;
287}
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static SnappingToolBar & Get(AudacityProject &project)

References Get(), and project.

Here is the call graph for this function:

◆ ID()

Identifier SnappingToolBar::ID ( )
static

Definition at line 239 of file SnappingToolBar.cpp.

240{
241 return wxT("Snapping");
242}
wxT("CloseDown"))

References wxT().

Referenced by Get().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnSize()

void SnappingToolBar::OnSize ( wxSizeEvent &  evt)
private

Definition at line 406 of file SnappingToolBar.cpp.

407{
408 Refresh( true );
409
410 evt.Skip();
411}

◆ OnSnapModeChanged()

void SnappingToolBar::OnSnapModeChanged ( )
private

Definition at line 413 of file SnappingToolBar.cpp.

414{
415 const bool snapEnabled = mSnapModeCheckBox->GetValue();
416
419
420 mSnapToCombo->Enable(snapEnabled);
421
422
423 // wxEVT_KILL_FOCUS is not always sent by wxWidgets.
424 // Remove any selection from the combo box if we've disabled it.
425 if (!snapEnabled)
426 mSnapToCombo->SelectNone();
427}
void SetSnapMode(SnapMode mode)
Definition: ProjectSnap.cpp:41

References ProjectSnap::Get(), ToolBar::mProject, mSnapModeCheckBox, mSnapToCombo, ProjectSnap::SetSnapMode(), SNAP_NEAREST, and SNAP_OFF.

Referenced by Populate().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Populate()

void SnappingToolBar::Populate ( )
overridevirtual

Implements ToolBar.

Definition at line 295 of file SnappingToolBar.cpp.

296{
297 SetBackgroundColour( theTheme.Colour( clrMedium ) );
298
299 auto sizer = safenew wxFlexGridSizer(1, 1, 1);
300 Add(sizer, 0, wxALIGN_CENTER_VERTICAL | wxLEFT, 5);
301
302 auto boxSizer = safenew wxBoxSizer(wxHORIZONTAL);
303
304 mSnapModeCheckBox = safenew wxCheckBox(this, wxID_ANY, {});
305
307#if wxUSE_ACCESSIBILITY
308 // so that name can be set on a standard control
309 mSnapModeCheckBox->SetAccessible(
311#endif
312
313 auto snapLabelCtrl = safenew auStaticText(this, SnapLabel.Translation());
314
315 boxSizer->Add(mSnapModeCheckBox, 0, wxEXPAND, 0);
316 boxSizer->Add(snapLabelCtrl, 0, wxEXPAND, 0);
317
318 sizer->Add(boxSizer, 0, wxBOTTOM | wxRIGHT | wxEXPAND, 5);
319
320 const bool snapEnabled =
322
323 mSnapModeCheckBox->SetValue(snapEnabled);
324
325
326 mSnapToCombo = safenew wxComboCtrl(
327 this, wxID_ANY, {}, wxDefaultPosition, wxDefaultSize /*, wxCB_READONLY*/);
328#if wxUSE_ACCESSIBILITY
329 // so that name can be set on a standard control
330 mSnapToCombo->GetTextCtrl()->SetAccessible(
331 safenew WindowAccessible(mSnapToCombo->GetTextCtrl()));
332#endif
333
334 //mSnapToCombo->SetEditable(false);
335 mSnapToCombo->SetPopupControl(safenew SnapModePopup(mProject));
336 /* i18n-hint: combo box is the type of the control/widget */
337 mSnapToCombo->GetTextCtrl()->SetName(XO("Snap to combo box").Translation());
338 /* Narrator screen reader by default reads the accessibility name of the
339 containing window, which by default is combobox, so set it to an empty string. */
340 mSnapToCombo->SetLabel(wxT(""));
341 mSnapToCombo->Enable(snapEnabled);
342 mSnapToCombo->SetMinSize(wxSize(150, -1));
343
344 sizer->Add(mSnapToCombo, 1, wxRIGHT | wxEXPAND, 5);
345
346 mSnapModeCheckBox->Bind(
347 wxEVT_CHECKBOX, [this](auto&) { OnSnapModeChanged(); });
348
349 mSnapModeCheckBox->Bind(
350 wxEVT_CHAR_HOOK,
351 [this](auto& evt)
352 {
353 const auto keyCode = evt.GetKeyCode();
354
355 if (keyCode != WXK_NUMPAD_ENTER && keyCode != WXK_RETURN)
356 {
357 evt.Skip();
358 return;
359 }
360
361 mSnapModeCheckBox->SetValue(!mSnapModeCheckBox->GetValue());
362
364 });
365
366 mSnapModeCheckBox->Bind(
367 wxEVT_SET_FOCUS,
368 [snapLabelCtrl](auto&) { snapLabelCtrl->SetSelected(true); });
369
370 mSnapModeCheckBox->Bind(
371 wxEVT_KILL_FOCUS,
372 [snapLabelCtrl](auto&) { snapLabelCtrl->SetSelected(false); });
373
374 // When the focus is lost, clear out any text selection.
375 // See https://github.com/audacity/audacity/issues/4427
376 mSnapToCombo->Bind(
377 wxEVT_KILL_FOCUS, [this](auto&) { mSnapToCombo->SelectNone(); });
378
379 snapLabelCtrl->Bind(
380 wxEVT_LEFT_UP,
381 [this](auto&)
382 {
383 mSnapModeCheckBox->SetValue(!mSnapModeCheckBox->GetValue());
385 });
386
388 Fit();
389 Layout();
390}
#define safenew
Definition: MemoryX.h:10
THEME_API Theme theTheme
Definition: Theme.cpp:82
SnapMode GetSnapMode() const
Definition: ProjectSnap.cpp:54
void RegenerateTooltips() override
wxColour & Colour(int iIndex)
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:709
wxString Translation() const
TranslatableString Stripped(unsigned options=MenuCodes) const
non-mutating, constructs another TranslatableString object
An alternative to using wxWindowAccessible, which in wxWidgets 3.1.1 contained GetParent() which was ...
is like wxStaticText, except it can be themed. wxStaticText can't be.
Definition: auStaticText.h:20

References ToolBar::Add(), ThemeBase::Colour(), ProjectSnap::Get(), ProjectSnap::GetSnapMode(), ToolBar::mProject, mSnapModeCheckBox, mSnapToCombo, OnSnapModeChanged(), RegenerateTooltips(), safenew, SNAP_OFF, anonymous_namespace{SnappingToolBar.cpp}::SnapLabel, TranslatableString::Stripped(), theTheme, TranslatableString::Translation(), wxT(), and XO().

Here is the call graph for this function:

◆ RegenerateTooltips()

void SnappingToolBar::RegenerateTooltips ( )
overridevirtual

Implements ToolBar.

Definition at line 402 of file SnappingToolBar.cpp.

403{
404}

Referenced by Populate(), and UpdatePrefs().

Here is the caller graph for this function:

◆ Repaint()

void SnappingToolBar::Repaint ( wxDC *  WXUNUSEDdc)
inlineoverride

Definition at line 47 of file SnappingToolBar.h.

47{};

◆ ShownByDefault()

bool SnappingToolBar::ShownByDefault ( ) const
overridevirtual

Whether the toolbar should be shown by default. Default implementation returns true.

Reimplemented from ToolBar.

Definition at line 268 of file SnappingToolBar.cpp.

269{
270 return true;
271}

◆ UpdatePrefs()

void SnappingToolBar::UpdatePrefs ( )
overridevirtual

Implements PrefsListener.

Definition at line 392 of file SnappingToolBar.cpp.

393{
394 // Set label to pull in language change
395 SetLabel(XO("Snapping"));
396
398 // Give base class a chance
400}
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:408
void UpdatePrefs() override
Definition: ToolBar.cpp:622

References RegenerateTooltips(), ToolBar::SetLabel(), ToolBar::UpdatePrefs(), and XO().

Referenced by Create().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mSnapModeCheckBox

wxWeakRef<wxCheckBox> SnappingToolBar::mSnapModeCheckBox
private

Definition at line 57 of file SnappingToolBar.h.

Referenced by OnSnapModeChanged(), Populate(), and SnappingToolBar().

◆ mSnappingModeChangedSubscription

Observer::Subscription SnappingToolBar::mSnappingModeChangedSubscription
private

Definition at line 60 of file SnappingToolBar.h.

◆ mSnapToCombo

wxWeakRef<wxComboCtrl> SnappingToolBar::mSnapToCombo
private

Definition at line 58 of file SnappingToolBar.h.

Referenced by OnSnapModeChanged(), Populate(), and SnappingToolBar().


The documentation for this class was generated from the following files: