Audacity 3.2.0
Classes | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
AButton Class Reference

A wxButton with mouse-over behaviour. More...

#include <AButton.h>

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

Classes

class  Listener
 
struct  Resetter
 

Public Types

enum  Type { TextButton , ImageButton , FrameButton , FrameTextButton }
 
enum  AButtonState {
  AButtonUp , AButtonOver , AButtonDown , AButtonOverDown ,
  AButtonDis , AButtonStateCount
}
 

Public Member Functions

 AButton (wxWindow *parent=nullptr, wxWindowID id=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, bool toggle=false)
 
 AButton (wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, const wxImage &up, const wxImage &over, const wxImage &down, const wxImage &overDown, const wxImage &dis, bool toggle)
 
virtual ~AButton ()
 
void SetButtonType (Type type)
 
void SetFrameMid (int mid)
 
void SetToolTip (const TranslatableString &toolTip)
 
void SetLabel (const TranslatableString &label)
 
bool AcceptsFocus () const override
 
bool AcceptsFocusFromKeyboard () const override
 
void SetFocusFromKbd () override
 
void SetImages (const wxImage &up, const wxImage &over, const wxImage &down, const wxImage &overDown, const wxImage &dis)
 
void SetAlternateImages (unsigned idx, const wxImage &up, const wxImage &over, const wxImage &down, const wxImage &overDown, const wxImage &dis)
 
void SetIcon (const wxImage &icon)
 
void SetIcon (AButtonState state, const wxImage &icon)
 
void SetIcons (const wxImage &up, const wxImage &down, const wxImage &disabled)
 
void SetAlternateIcon (unsigned idx, const wxImage &icon)
 
void SetAlternateIcon (unsigned idx, AButtonState state, const wxImage &icon)
 
void SetAlternateIcons (unsigned idx, const wxImage &up, const wxImage &down, const wxImage &disabled)
 
void SetAlternateIdx (unsigned idx)
 
void FollowModifierKeys ()
 
void SetFocusRect (const wxRect &r)
 
bool IsEnabled () const
 
void Disable ()
 
void Enable ()
 
void SetEnabled (bool state)
 
void PushDown ()
 
void PopUp ()
 
void OnErase (wxEraseEvent &event)
 
void OnPaint (wxPaintEvent &event)
 
void OnSize (wxSizeEvent &event)
 
void OnMouseEvent (wxMouseEvent &event)
 
void UpdateStatus ()
 
void OnCaptureLost (wxMouseCaptureLostEvent &event)
 
void OnKeyDown (wxKeyEvent &event)
 
void OnSetFocus (wxFocusEvent &event)
 
void OnKillFocus (wxFocusEvent &event)
 
void OnCharHook (wxKeyEvent &event)
 
bool WasShiftDown ()
 
bool WasControlDown ()
 
bool IsDown ()
 
bool IsDoubleClicked () const
 
void ClearDoubleClicked ()
 
void SetButtonToggles (bool toggler)
 
bool IsToggle () const noexcept
 
void InteractionOver ()
 
void Toggle ()
 
void Click ()
 
void SetShift (bool shift)
 
void SetControl (bool control)
 
wxSize DoGetBestClientSize () const override
 
AButtonState GetState ()
 
void UseDisabledAsDownHiliteImage (bool flag)
 

Static Public Member Functions

static TempAllowFocus TemporarilyAllowFocus ()
 

Private Types

using TempAllowFocus = std::unique_ptr< bool, Resetter >
 

Private Member Functions

bool HasAlternateImages (unsigned idx) const
 
void Init (wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, bool toggle)
 

Private Attributes

unsigned mAlternateIdx {0}
 
bool mToggle {false}
 
bool mWasShiftDown {false}
 
bool mWasControlDown {false}
 
bool mCursorIsInWindow {false}
 
bool mButtonIsDown {false}
 
bool mIsClicking {false}
 
bool mEnabled {true}
 
bool mUseDisabledAsDownHiliteImage {false}
 
bool mIsDoubleClicked {false}
 
std::vector< std::array< wxImage, AButtonStateCount > > mIcons
 
std::vector< std::array< wxImage, AButtonStateCount > > mImages
 
wxRect mFocusRect
 
bool mForceFocusRect {false}
 
std::unique_ptr< ListenermListener
 
Type mType {ImageButton}
 
int mFrameMid {1}
 

Static Private Attributes

static bool s_AcceptsFocus { false }
 

Friends

class AButtonAx
 

Detailed Description

A wxButton with mouse-over behaviour.

AButton is a custom button class for Audacity. The main feature it supports that a wxButton does not is mouseovers.

It uses an image for all of its states: up, over, down, and disabled, allowing any sort of customization you want. Currently it does not support transparency effects, so the image musts be rectangular and opaque.

Definition at line 104 of file AButton.h.

Member Typedef Documentation

◆ TempAllowFocus

using AButton::TempAllowFocus = std::unique_ptr<bool, Resetter>
private

Definition at line 251 of file AButton.h.

Member Enumeration Documentation

◆ AButtonState

Enumerator
AButtonUp 
AButtonOver 
AButtonDown 
AButtonOverDown 
AButtonDis 
AButtonStateCount 

Definition at line 118 of file AButton.h.

118 {
119 AButtonUp,
124
126 };
@ AButtonStateCount
Definition: AButton.h:125
@ AButtonUp
Definition: AButton.h:119
@ AButtonDis
Definition: AButton.h:123
@ AButtonOver
Definition: AButton.h:120
@ AButtonDown
Definition: AButton.h:121
@ AButtonOverDown
Definition: AButton.h:122

◆ Type

Enumerator
TextButton 
ImageButton 
FrameButton 
FrameTextButton 

Definition at line 110 of file AButton.h.

111 {
116 };
@ TextButton
Definition: AButton.h:112
@ FrameButton
Definition: AButton.h:114
@ ImageButton
Definition: AButton.h:113
@ FrameTextButton
Definition: AButton.h:115

Constructor & Destructor Documentation

◆ AButton() [1/2]

AButton::AButton ( wxWindow *  parent = nullptr,
wxWindowID  id = wxID_ANY,
const wxPoint &  pos = wxDefaultPosition,
const wxSize &  size = wxDefaultSize,
bool  toggle = false 
)

Definition at line 118 of file AButton.cpp.

119{
120 Init(parent, id, pos, size, toggle);
121}
void Init(wxWindow *parent, wxWindowID id, const wxPoint &pos, const wxSize &size, bool toggle)
Definition: AButton.cpp:174

References Init(), and size.

Here is the call graph for this function:

◆ AButton() [2/2]

AButton::AButton ( wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos,
const wxSize &  size,
const wxImage up,
const wxImage over,
const wxImage down,
const wxImage overDown,
const wxImage dis,
bool  toggle 
)

Definition at line 123 of file AButton.cpp.

133{
134 Init(parent, id, pos, size, toggle);
135
136 SetAlternateImages(0, up, over, down, overDown, dis);
137
138 SetMinSize(mImages[0][AButtonUp].GetSize());
139 SetMaxSize(mImages[0][AButtonUp].GetSize());
140}
void SetAlternateImages(unsigned idx, const wxImage &up, const wxImage &over, const wxImage &down, const wxImage &overDown, const wxImage &dis)
Definition: AButton.cpp:226
std::vector< std::array< wxImage, AButtonStateCount > > mImages
Definition: AButton.h:281

References AButtonUp, Init(), mImages, SetAlternateImages(), and size.

Here is the call graph for this function:

◆ ~AButton()

AButton::~AButton ( )
virtual

Definition at line 142 of file AButton.cpp.

143{
144 if(HasCapture())
145 ReleaseMouse();
146}

Member Function Documentation

◆ AcceptsFocus()

bool AButton::AcceptsFocus ( ) const
inlineoverride

Definition at line 158 of file AButton.h.

158{ return s_AcceptsFocus; }
static bool s_AcceptsFocus
Definition: AButton.h:249

◆ AcceptsFocusFromKeyboard()

bool AButton::AcceptsFocusFromKeyboard ( ) const
inlineoverride

Definition at line 159 of file AButton.h.

159{ return mEnabled; }
bool mEnabled
Definition: AButton.h:276

◆ ClearDoubleClicked()

void AButton::ClearDoubleClicked ( )
inline

Definition at line 230 of file AButton.h.

230{ mIsDoubleClicked = false; }
bool mIsDoubleClicked
Definition: AButton.h:278

◆ Click()

void AButton::Click ( )

Definition at line 664 of file AButton.cpp.

665{
666 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
667 event.SetEventObject(this);
668 // Be sure to use SafelyProcessEvent so that exceptions do not propagate
669 // out of DoDefaultAction
670 GetEventHandler()->SafelyProcessEvent(event);
671}
wxEVT_COMMAND_BUTTON_CLICKED

References wxEVT_COMMAND_BUTTON_CLICKED.

Referenced by OnCharHook(), and OnMouseEvent().

Here is the caller graph for this function:

◆ Disable()

void AButton::Disable ( )

Definition at line 627 of file AButton.cpp.

628{
629 // Bug 1565: Tooltips not showing on disabled buttons.
630 // The fix is to NOT tell windows that the button is disabled.
631 // The button's appearance will still change to show it is disabled
632 // since we control that rather than windows.
633#ifndef __WXMSW__
634 wxWindow::Enable(false);
635#endif
636 if (GetCapture()==this)
637 ReleaseMouse();
638 if ( mEnabled ) {
639 mEnabled = false;
640 Refresh(false);
641 }
642}

References mEnabled.

Referenced by TranscriptionToolBar::Create(), AudioSetupToolBar::EnableDisableButtons(), and RealtimeEffectPanel::ResetTrack().

Here is the caller graph for this function:

◆ DoGetBestClientSize()

wxSize AButton::DoGetBestClientSize ( ) const
override

Definition at line 683 of file AButton.cpp.

684{
685 const auto imageIdx = HasAlternateImages(mAlternateIdx) ? mAlternateIdx : 0;
686 if(imageIdx == mAlternateIdx || HasAlternateImages(imageIdx))
687 {
688 const auto& image = mImages[imageIdx][AButtonUp];
689 switch(mType)
690 {
691 case FrameButton:
692 {
693 const auto icon = !mIcons.empty() ? &mIcons[0][AButtonUp] : nullptr;
694 if(icon->IsOk())
695 return icon->GetSize();
696 return image.GetSize();
697 }
698 case FrameTextButton:
699 {
700 //Only AButtonUp is used to estimate size
701 auto icon = !mIcons.empty() ? &mIcons[0][AButtonUp] : nullptr;
702 if(!GetLabel().IsEmpty())
703 {
704 const auto border = (image.GetSize() - wxSize { mFrameMid, mFrameMid }) / 4;
705
706 wxMemoryDC dc;
707 dc.SetFont(GetFont());
708 auto bestSize = dc.GetTextExtent(GetLabel());
709 if(icon != nullptr && icon->IsOk())
710 {
711 bestSize.x = std::max(bestSize.x, icon->GetWidth());
712 bestSize.y = bestSize.y > 0
713 ? bestSize.y + border.y + icon->GetHeight()
714 : icon->GetHeight();
715 }
716 if(bestSize.x > 0)
717 bestSize.x += border.x * 2;
718 if(bestSize.y > 0)
719 bestSize.y += border.y * 2;
720 return bestSize;
721 }
722 if(icon->Ok())
723 return icon->GetSize();
724 return image.GetSize();
725 }
726 case TextButton:
727 return {-1, image.GetHeight() };
728 default:
729 return image.GetSize();
730 }
731 }
732 return wxWindow::DoGetBestClientSize();
733}
bool HasAlternateImages(unsigned idx) const
Definition: AButton.cpp:445
Type mType
Definition: AButton.h:288
std::vector< std::array< wxImage, AButtonStateCount > > mIcons
Definition: AButton.h:280
int mFrameMid
Definition: AButton.h:289
unsigned mAlternateIdx
Definition: AButton.h:262

References AButtonUp, FrameButton, FrameTextButton, HasAlternateImages(), mAlternateIdx, mFrameMid, mIcons, mImages, mType, and TextButton.

Here is the call graph for this function:

◆ Enable()

void AButton::Enable ( )

Definition at line 618 of file AButton.cpp.

619{
620 bool changed = wxWindow::Enable(true);
621 if ( !mEnabled ) {
622 mEnabled = true;
623 Refresh(false);
624 }
625}

References mEnabled.

Referenced by TranscriptionToolBar::Create(), AudioSetupToolBar::EnableDisableButtons(), and RealtimeEffectPanel::SetTrack().

Here is the caller graph for this function:

◆ FollowModifierKeys()

void AButton::FollowModifierKeys ( )

Definition at line 298 of file AButton.cpp.

299{
300 if(!mListener)
301 mListener = std::make_unique<Listener>(this);
302}
std::unique_ptr< Listener > mListener
Definition: AButton.h:286

References mListener.

Referenced by ControlToolBar::Populate(), and TranscriptionToolBar::Populate().

Here is the caller graph for this function:

◆ GetState()

AButton::AButtonState AButton::GetState ( )

Definition at line 310 of file AButton.cpp.

311{
312 AButtonState state;
313
314 if (!mEnabled && (!mToggle || !mButtonIsDown))
315 return AButtonDis;
316
317 if (mCursorIsInWindow) {
318 if (mToggle) {
319 if (mIsClicking) {
323 }
324 }
325 else {
329 }
330 }
331 }
332 else {
333 if (mIsClicking) {
335 }
336 else {
338 }
339 }
340 }
341 else {
343 }
344
345 return state;
346}
bool mUseDisabledAsDownHiliteImage
Definition: AButton.h:277
bool mButtonIsDown
Definition: AButton.h:274
bool mCursorIsInWindow
Definition: AButton.h:273
AButtonState
Definition: AButton.h:118
bool mIsClicking
Definition: AButton.h:275
bool mToggle
Definition: AButton.h:263

References AButtonDis, AButtonDown, AButtonOver, AButtonOverDown, AButtonUp, mButtonIsDown, mCursorIsInWindow, mEnabled, mIsClicking, mToggle, and mUseDisabledAsDownHiliteImage.

Referenced by OnMouseEvent(), and OnPaint().

Here is the caller graph for this function:

◆ HasAlternateImages()

bool AButton::HasAlternateImages ( unsigned  idx) const
private

Definition at line 445 of file AButton.cpp.

446{
447 if (mImages.size() <= idx)
448 return false;
449
450 const auto &arr = mImages[idx];
451 return (arr[0].Ok() &&
452 arr[1].Ok() &&
453 arr[2].Ok() &&
454 arr[3].Ok() &&
455 arr[4].Ok());
456}
@ Ok
One button.

References mImages.

Referenced by DoGetBestClientSize(), and OnPaint().

Here is the caller graph for this function:

◆ Init()

void AButton::Init ( wxWindow *  parent,
wxWindowID  id,
const wxPoint &  pos,
const wxSize &  size,
bool  toggle 
)
private

Definition at line 174 of file AButton.cpp.

175{
176 SetBackgroundStyle(wxBG_STYLE_PAINT);
177 SetBackgroundColour(theTheme.Colour(clrMedium));
178
179 // Bug in wxWidgets 2.8.12: by default pressing Enter on an AButton is interpreted as
180 // a navigation event - move to next control. As a workaround, the style wxWANTS_CHARS
181 // results in all characters being available in the OnKeyDown function below. Note
182 // that OnKeyDown now has to handle navigation.
183 Create(parent, id, pos, size, wxWANTS_CHARS);
184
185 mToggle = toggle;
186
187 mFocusRect = GetClientRect().Deflate( 3, 3 );
188
189#if wxUSE_ACCESSIBILITY
190 SetName( wxT("") );
191 SetAccessible(safenew AButtonAx(this));
192#endif
193}
wxT("CloseDown"))
#define safenew
Definition: MemoryX.h:10
THEME_API Theme theTheme
Definition: Theme.cpp:82
wxRect mFocusRect
Definition: AButton.h:283
friend class AButtonAx
Definition: AButton.h:105
wxColour & Colour(int iIndex)

References AButtonAx, ThemeBase::Colour(), mFocusRect, mToggle, safenew, size, theTheme, and wxT().

Referenced by AButton().

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

◆ InteractionOver()

void AButton::InteractionOver ( )
inline

Definition at line 236 of file AButton.h.

236{ if( !mToggle ) PopUp();}
void PopUp()
Definition: AButton.cpp:652

◆ IsDoubleClicked()

bool AButton::IsDoubleClicked ( ) const
inline

Definition at line 229 of file AButton.h.

229{ return mIsDoubleClicked; }

◆ IsDown()

bool AButton::IsDown ( )
inline

Definition at line 226 of file AButton.h.

226{ return mButtonIsDown;}

Referenced by ControlToolBar::EnableDisableButtons(), RealtimeEffectPanel::MakeMasterEffectPane(), RealtimeEffectPanel::MakeTrackEffectPane(), EffectUIHost::OnEnable(), AudioSetupToolBar::ReCreateButtons(), ControlToolBar::ReCreateButtons(), and ControlToolBar::StateForStatusBar().

Here is the caller graph for this function:

◆ IsEnabled()

bool AButton::IsEnabled ( ) const
inline

Definition at line 197 of file AButton.h.

197{ return mEnabled; }

◆ IsToggle()

bool AButton::IsToggle ( ) const
noexcept

◆ OnCaptureLost()

void AButton::OnCaptureLost ( wxMouseCaptureLostEvent &  event)

Definition at line 540 of file AButton.cpp.

541{
542 wxMouseEvent e(wxEVT_LEFT_UP);
543 e.m_x = -1;
544 e.m_y = -1;
545 OnMouseEvent(e);
546}
void OnMouseEvent(wxMouseEvent &event)
Definition: AButton.cpp:458

References OnMouseEvent().

Here is the call graph for this function:

◆ OnCharHook()

void AButton::OnCharHook ( wxKeyEvent &  event)

Definition at line 572 of file AButton.cpp.

573{
574 switch(event.GetKeyCode())
575 {
576 case WXK_RETURN:
577 case WXK_NUMPAD_ENTER:
578 if( !mEnabled )
579 break;
580 mWasShiftDown = event.ShiftDown();
581 mWasControlDown = event.ControlDown();
582 if(mToggle)
583 {
585 Refresh(false);
586#if wxUSE_ACCESSIBILITY
587 GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_NAMECHANGE,
588 this, wxOBJID_CLIENT, wxACC_SELF);
589#endif
590 }
591 Click();
592 break;
593 default:
594 event.Skip();
595 }
596}
bool mWasShiftDown
Definition: AButton.h:270
void Click()
Definition: AButton.cpp:664
bool mWasControlDown
Definition: AButton.h:271

References Click(), mButtonIsDown, mEnabled, mToggle, mWasControlDown, and mWasShiftDown.

Here is the call graph for this function:

◆ OnErase()

void AButton::OnErase ( wxEraseEvent &  event)

Definition at line 429 of file AButton.cpp.

430{
431 // Ignore it to prevent flashing
432}

◆ OnKeyDown()

void AButton::OnKeyDown ( wxKeyEvent &  event)

Definition at line 550 of file AButton.cpp.

551{
552 switch( event.GetKeyCode() )
553 {
554 case WXK_RIGHT:
555 case WXK_DOWN:
556 Navigate(wxNavigationKeyEvent::IsForward);
557 break;
558 case WXK_LEFT:
559 case WXK_UP:
560 Navigate(wxNavigationKeyEvent::IsBackward);
561 break;
562 case WXK_TAB:
563 Navigate(wxNavigationKeyEvent::FromTab | (event.ShiftDown()
564 ? wxNavigationKeyEvent::IsBackward
565 : wxNavigationKeyEvent::IsForward));
566 break;
567 default:
568 event.Skip();
569 }
570}

◆ OnKillFocus()

void AButton::OnKillFocus ( wxFocusEvent &  event)

Definition at line 603 of file AButton.cpp.

604{
605 Refresh( false );
606}

◆ OnMouseEvent()

void AButton::OnMouseEvent ( wxMouseEvent &  event)

Definition at line 458 of file AButton.cpp.

459{
460 wxSize clientSize = GetClientSize();
461 AButtonState prevState = GetState();
462
463 if (event.Entering()) {
464 // Bug 1201: On Mac, unsetting and re-setting the tooltip may be needed
465 // to make it pop up when we want it.
466 auto text = GetToolTipText();
467 UnsetToolTip();
468 wxWindow::SetToolTip(text);
469 mCursorIsInWindow = true;
470 }
471 else if (event.Leaving())
472 mCursorIsInWindow = false;
473 else
475 (event.m_x >= 0 && event.m_y >= 0 &&
476 event.m_x < clientSize.x && event.m_y < clientSize.y);
477
478 if (mEnabled && event.IsButton()) {
479 if (event.ButtonIsDown(wxMOUSE_BTN_LEFT)) {
480 mIsClicking = true;
481 if (event.ButtonDClick())
482 mIsDoubleClicked = true;
483 if( !HasCapture() )
484 CaptureMouse();
485 }
486 else if (mIsClicking) {
487 mIsClicking = false;
488
489 if (HasCapture())
490 ReleaseMouse();
491
493 if (mToggle)
495
496 mWasShiftDown = event.ShiftDown();
497 mWasControlDown = event.ControlDown();
498
499 Click();
500 }
501 }
502 }
503
504 // Only redraw and change tooltips if the state has changed.
505 AButtonState newState = GetState();
506
507 if (newState != prevState) {
508 Refresh(false);
509
511 UpdateStatus();
512 else {
513 auto pProject = FindProjectFromWindow( this );
514 if (pProject)
515 ProjectStatus::Get( *pProject ).Set({});
516 }
517 }
518 else
519 event.Skip();
520}
AudacityProject * FindProjectFromWindow(wxWindow *pWindow)
void UpdateStatus()
Definition: AButton.cpp:522
AButtonState GetState()
Definition: AButton.cpp:310
static ProjectStatus & Get(AudacityProject &project)
void Set(const TranslatableString &msg, StatusBarField field=MainStatusBarField())

References Click(), FindProjectFromWindow(), ProjectStatus::Get(), GetState(), mButtonIsDown, mCursorIsInWindow, mEnabled, mIsClicking, mIsDoubleClicked, mToggle, mWasControlDown, mWasShiftDown, ProjectStatus::Set(), and UpdateStatus().

Referenced by OnCaptureLost().

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

◆ OnPaint()

void AButton::OnPaint ( wxPaintEvent &  event)

Definition at line 348 of file AButton.cpp.

349{
350 wxBufferedPaintDC dc(this);
351
352 dc.SetPen(*wxTRANSPARENT_PEN);
353 dc.SetBrush(GetBackgroundColour());
354 dc.Clear();
355
356 const auto buttonRect = GetClientRect();
357 const auto imageIdx = HasAlternateImages(mAlternateIdx) ? mAlternateIdx : 0;
358
359 if(imageIdx == mAlternateIdx || HasAlternateImages(imageIdx))
360 {
361 const auto buttonState = GetState();
362 if(mType == ImageButton)
363 dc.DrawBitmap(mImages[imageIdx][buttonState], buttonRect.GetTopLeft());
364 else if(mType == FrameButton || mType == FrameTextButton)
365 {
366 wxBitmap bitmap = mImages[imageIdx][buttonState];
367 AColor::DrawFrame(dc, buttonRect, bitmap, mFrameMid);
368
369 const auto border = bitmap.GetSize() / 4;
370
371 wxImage* icon{};
372 if(mIcons.size() > mAlternateIdx)
373 icon = &mIcons[mAlternateIdx][buttonState];
374 if((icon == nullptr || !icon->IsOk()) && !mIcons.empty())
375 {
376 icon = &mIcons[0][buttonState];
377 if(!icon->IsOk())
378 icon = &mIcons[0][AButtonUp];
379 }
380 if(mType == FrameTextButton && !GetLabel().IsEmpty())
381 {
382 dc.SetFont(GetFont());
383 auto textRect = buttonRect;
384 if(icon != nullptr && icon->IsOk())
385 {
386 auto fontMetrics = dc.GetFontMetrics();
387 auto sumHeight = fontMetrics.height + icon->GetHeight() + border.y;
388
389 dc.DrawBitmap(*icon,
390 buttonRect.x + (buttonRect.width - icon->GetWidth()) / 2,
391 buttonRect.y + (buttonRect.height - sumHeight) / 2);
392 textRect = wxRect(
393 buttonRect.x,
394 buttonRect.y + buttonRect.height / 2 + sumHeight / 2 - fontMetrics.height,
395 buttonRect.width,
396 fontMetrics.height);
397 }
398 dc.SetPen(GetForegroundColour());
399 dc.DrawLabel(GetLabel(), textRect, wxALIGN_CENTER);
400 }
401 else if(icon != nullptr && icon->IsOk())
402 {
403 dc.DrawBitmap(*icon,
404 buttonRect.x + (buttonRect.width - icon->GetWidth()) / 2,
405 buttonRect.y + (buttonRect.height - icon->GetHeight()) / 2);
406 }
407 }
408 else
409 {
410 wxBitmap bitmap = mImages[imageIdx][buttonState];
411 AColor::DrawHStretch(dc, GetClientRect(), bitmap);
412 if(!GetLabel().IsEmpty())
413 {
414 dc.SetFont(GetFont());
415 const auto text = TrackArt::TruncateText(dc, GetLabel(), GetClientSize().GetWidth() - 6);
416 if(!text.IsEmpty())
417 {
418 dc.SetPen(GetForegroundColour());
419 dc.DrawLabel(text, GetClientRect(), wxALIGN_CENTER);
420 }
421 }
422 }
423 }
424
425 if(HasFocus())
427}
wxImage(22, 22)
static void DrawFrame(wxDC &dc, const wxRect &r, wxBitmap &bitmap, int mid)
Definition: AColor.cpp:329
static void DrawHStretch(wxDC &dc, const wxRect &rect, wxBitmap &bitmap)
Definition: AColor.cpp:312
static void DrawFocus(wxDC &dc, wxRect &r)
Definition: AColor.cpp:247
AUDACITY_DLL_API wxString TruncateText(wxDC &dc, const wxString &text, const int maxWidth)
Definition: TrackArt.cpp:173

References AButtonUp, AColor::DrawFocus(), AColor::DrawFrame(), AColor::DrawHStretch(), FrameButton, FrameTextButton, GetState(), HasAlternateImages(), ImageButton, mAlternateIdx, mFocusRect, mFrameMid, mIcons, mImages, mType, TrackArt::TruncateText(), and wxImage().

Here is the call graph for this function:

◆ OnSetFocus()

void AButton::OnSetFocus ( wxFocusEvent &  event)

Definition at line 598 of file AButton.cpp.

599{
600 Refresh( false );
601}

◆ OnSize()

void AButton::OnSize ( wxSizeEvent &  event)

Definition at line 434 of file AButton.cpp.

435{
436 if (!mForceFocusRect)
437 {
438 mFocusRect = GetClientRect().Deflate( 3, 3 );
439 }
440 Refresh(false);
441}
bool mForceFocusRect
Definition: AButton.h:284

References mFocusRect, and mForceFocusRect.

◆ PopUp()

void AButton::PopUp ( )

◆ PushDown()

void AButton::PushDown ( )

◆ SetAlternateIcon() [1/2]

void AButton::SetAlternateIcon ( unsigned  idx,
AButtonState  state,
const wxImage icon 
)

Definition at line 267 of file AButton.cpp.

268{
269 if(1 + idx > mIcons.size())
270 mIcons.resize(1 + idx);
271 mIcons[idx][state] = icon;
272 Refresh(false);
273}

References mIcons.

◆ SetAlternateIcon() [2/2]

void AButton::SetAlternateIcon ( unsigned  idx,
const wxImage icon 
)

Definition at line 257 of file AButton.cpp.

258{
259 if(1 + idx > mIcons.size())
260 mIcons.resize(1 + idx);
261 mIcons[idx][AButtonUp] = icon;
262 mIcons[idx][AButtonOver] = mIcons[idx][AButtonDown] =
263 mIcons[idx][AButtonDis] = mIcons[idx][AButtonOverDown] = wxNullImage;
264 Refresh(false);
265}

References AButtonDis, AButtonDown, AButtonOver, AButtonOverDown, AButtonUp, and mIcons.

Referenced by SetIcon().

Here is the caller graph for this function:

◆ SetAlternateIcons()

void AButton::SetAlternateIcons ( unsigned  idx,
const wxImage up,
const wxImage down,
const wxImage disabled 
)

Definition at line 275 of file AButton.cpp.

276{
277 if(1 + idx > mIcons.size())
278 mIcons.resize(1 + idx);
279 mIcons[idx][AButtonUp] = up;
280 mIcons[idx][AButtonOver] = up;
281 mIcons[idx][AButtonDown] = down;
282 mIcons[idx][AButtonOverDown] = down;
283 mIcons[idx][AButtonDis] = disabled;
284 Refresh(false);
285}

References AButtonDis, AButtonDown, AButtonOver, AButtonOverDown, AButtonUp, and mIcons.

Referenced by ControlToolBar::Populate(), and SetIcons().

Here is the caller graph for this function:

◆ SetAlternateIdx()

void AButton::SetAlternateIdx ( unsigned  idx)

Definition at line 287 of file AButton.cpp.

288{
289 // If alternate-image-state is already correct then
290 // nothing to do (saves repainting button).
291 if( mAlternateIdx == idx )
292 return;
293 mAlternateIdx = idx;
294 Refresh(false);
295 PostSizeEventToParent();
296}

References mAlternateIdx.

Referenced by MixerTrackCluster::OnButton_Mute(), MixerTrackCluster::OnButton_Solo(), ControlToolBar::OnIdle(), ControlToolBar::ReCreateButtons(), ControlToolBar::SetPlay(), TranscriptionToolBar::SetPlaying(), and MixerTrackCluster::UpdateForStateChange().

Here is the caller graph for this function:

◆ SetAlternateImages()

void AButton::SetAlternateImages ( unsigned  idx,
const wxImage up,
const wxImage over,
const wxImage down,
const wxImage overDown,
const wxImage dis 
)

Definition at line 226 of file AButton.cpp.

232{
233 if (1 + idx > mImages.size())
234 mImages.resize(1 + idx);
235 mImages[idx][AButtonUp] = up;
236 mImages[idx][AButtonOver] = over;
237 mImages[idx][AButtonDown] = down;
238 mImages[idx][AButtonOverDown] = overDown;
239 mImages[idx][AButtonDis] = dis;
240}

References AButtonDis, AButtonDown, AButtonOver, AButtonOverDown, AButtonUp, and mImages.

Referenced by AButton(), ToolBar::MakeAlternateImages(), and SetImages().

Here is the caller graph for this function:

◆ SetButtonToggles()

void AButton::SetButtonToggles ( bool  toggler)
inline

Definition at line 232 of file AButton.h.

232{ mToggle = toggler;}

Referenced by ControlToolBar::Populate().

Here is the caller graph for this function:

◆ SetButtonType()

void AButton::SetButtonType ( Type  type)

Definition at line 148 of file AButton.cpp.

149{
150 if(mType != type)
151 {
152 mType = type;
153 InvalidateBestSize();
154 Refresh(false);
155 PostSizeEventToParent();
156 }
157}

References mType.

Referenced by AudioSetupToolBar::MakeAudioSetupButton(), SelectionBar::MakeSetupButton(), audacity::cloud::ShareAudioToolbar::MakeShareAudioButton(), and MeterToolBar::Populate().

Here is the caller graph for this function:

◆ SetControl()

void AButton::SetControl ( bool  control)

Definition at line 678 of file AButton.cpp.

679{
680 mWasControlDown = control;
681}

References mWasControlDown.

Referenced by ControlToolBar::SetPlay().

Here is the caller graph for this function:

◆ SetEnabled()

void AButton::SetEnabled ( bool  state)
inline

Definition at line 200 of file AButton.h.

200 {
201 state ? Enable() : Disable();
202 }
void Disable()
Definition: AButton.cpp:627
void Enable()
Definition: AButton.cpp:618

Referenced by audacity::cloud::ShareAudioToolbar::EnableDisableButtons(), ControlToolBar::EnableDisableButtons(), TranscriptionToolBar::EnableDisableButtons(), RealtimeEffectListWindow::ReloadEffectsList(), and TranscriptionToolBar::SetEnabled().

Here is the caller graph for this function:

◆ SetFocusFromKbd()

void AButton::SetFocusFromKbd ( )
override

Definition at line 215 of file AButton.cpp.

216{
217 auto temp = TemporarilyAllowFocus();
218 SetFocus();
219}
static TempAllowFocus TemporarilyAllowFocus()
Definition: AButton.cpp:735
void SetFocus(const WindowPlacement &focus)
Set the window that accepts keyboard input.
Definition: BasicUI.h:392

References BasicUI::SetFocus(), and TemporarilyAllowFocus().

Here is the call graph for this function:

◆ SetFocusRect()

void AButton::SetFocusRect ( const wxRect &  r)

Definition at line 304 of file AButton.cpp.

305{
306 mFocusRect = r;
307 mForceFocusRect = true;
308}

References mFocusRect, and mForceFocusRect.

Referenced by ToolBar::MakeButton().

Here is the caller graph for this function:

◆ SetFrameMid()

void AButton::SetFrameMid ( int  mid)

Definition at line 159 of file AButton.cpp.

160{
161 if(mid == mFrameMid)
162 return;
163 mFrameMid = mid;
164
165 if(mType == FrameButton)
166 {
167 InvalidateBestSize();
168 Refresh(false);
169 PostSizeEventToParent();
170 }
171}

References FrameButton, mFrameMid, and mType.

Referenced by MeterToolBar::Populate().

Here is the caller graph for this function:

◆ SetIcon() [1/2]

void AButton::SetIcon ( AButtonState  state,
const wxImage icon 
)

Definition at line 247 of file AButton.cpp.

248{
249 SetAlternateIcon(0, state, icon);
250}
void SetAlternateIcon(unsigned idx, const wxImage &icon)
Definition: AButton.cpp:257

References SetAlternateIcon().

Here is the call graph for this function:

◆ SetIcon() [2/2]

void AButton::SetIcon ( const wxImage icon)

Definition at line 242 of file AButton.cpp.

243{
244 SetAlternateIcon(0, icon);
245}

References SetAlternateIcon().

Referenced by AudioSetupToolBar::MakeAudioSetupButton(), audacity::cloud::ShareAudioToolbar::MakeShareAudioButton(), and MeterToolBar::Populate().

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

◆ SetIcons()

void AButton::SetIcons ( const wxImage up,
const wxImage down,
const wxImage disabled 
)

Definition at line 252 of file AButton.cpp.

253{
254 SetAlternateIcons(0, up, down, disabled);
255}
void SetAlternateIcons(unsigned idx, const wxImage &up, const wxImage &down, const wxImage &disabled)
Definition: AButton.cpp:275

References SetAlternateIcons().

Here is the call graph for this function:

◆ SetImages()

void AButton::SetImages ( const wxImage up,
const wxImage over,
const wxImage down,
const wxImage overDown,
const wxImage dis 
)

Definition at line 221 of file AButton.cpp.

222{
223 SetAlternateImages(0, up, over, down, overDown, dis);
224}

References SetAlternateImages().

Referenced by AudioSetupToolBar::MakeAudioSetupButton(), audacity::cloud::ShareAudioToolbar::MakeShareAudioButton(), and MeterToolBar::Populate().

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

◆ SetLabel()

void AButton::SetLabel ( const TranslatableString label)

Definition at line 205 of file AButton.cpp.

206{
207 wxWindow::SetLabel( toolTip.Stripped().Translation() );
208 if(mType == FrameButton)
209 InvalidateBestSize();
210}

References FrameButton, mType, TranslatableString::Stripped(), and TranslatableString::Translation().

Referenced by TranscriptionToolBar::AddButton(), AudioSetupToolBar::MakeAudioSetupButton(), ToolBar::MakeButton(), audacity::cloud::ShareAudioToolbar::MakeShareAudioButton(), MeterToolBar::Populate(), and AdornedRulerPanel::UpdateButtonStates().

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

◆ SetShift()

void AButton::SetShift ( bool  shift)

Definition at line 673 of file AButton.cpp.

674{
675 mWasShiftDown = shift;
676}

References mWasShiftDown.

Referenced by ControlToolBar::SetPlay().

Here is the caller graph for this function:

◆ SetToolTip()

void AButton::SetToolTip ( const TranslatableString toolTip)

Definition at line 200 of file AButton.cpp.

201{
202 wxWindow::SetToolTip( toolTip.Stripped().Translation() );
203}
wxString Translation() const
TranslatableString Stripped(unsigned options=MenuCodes) const
non-mutating, constructs another TranslatableString object

References TranslatableString::Stripped(), and TranslatableString::Translation().

Referenced by MeterToolBar::Populate(), TranscriptionToolBar::RegenerateTooltips(), and ToolBar::SetButtonToolTip().

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

◆ TemporarilyAllowFocus()

auto AButton::TemporarilyAllowFocus ( )
static

Definition at line 735 of file AButton.cpp.

735 {
736 s_AcceptsFocus = true;
738}
std::unique_ptr< bool, Resetter > TempAllowFocus
Definition: AButton.h:251

References s_AcceptsFocus.

Referenced by anonymous_namespace{NavigationMenus.cpp}::NextOrPrevFrame(), ToolManager::RestoreFocus(), and SetFocusFromKbd().

Here is the caller graph for this function:

◆ Toggle()

void AButton::Toggle ( )
inline

Definition at line 237 of file AButton.h.

237{ mButtonIsDown ? PopUp() : PushDown();}
void PushDown()
Definition: AButton.cpp:644

◆ UpdateStatus()

void AButton::UpdateStatus ( )

Definition at line 522 of file AButton.cpp.

523{
524 if (mCursorIsInWindow) {
525#if wxUSE_TOOLTIPS // Not available in wxX11
526 // Display the tooltip in the status bar
527 wxToolTip * pTip = this->GetToolTip();
528 if( pTip ) {
529 auto tipText = Verbatim( pTip->GetTip() );
530 if (!mEnabled)
531 tipText.Join( XO("(disabled)"), " " );
532 auto pProject = FindProjectFromWindow( this );
533 if (pProject)
534 ProjectStatus::Get( *pProject ).Set( tipText );
535 }
536#endif
537 }
538}
XO("Cut/Copy/Paste")
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.

References FindProjectFromWindow(), ProjectStatus::Get(), mCursorIsInWindow, mEnabled, ProjectStatus::Set(), Verbatim(), and XO().

Referenced by OnMouseEvent(), and AdornedRulerPanel::UpdateButtonStates().

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

◆ UseDisabledAsDownHiliteImage()

void AButton::UseDisabledAsDownHiliteImage ( bool  flag)

Definition at line 195 of file AButton.cpp.

196{
198}
static std::once_flag flag

References flag, and mUseDisabledAsDownHiliteImage.

◆ WasControlDown()

bool AButton::WasControlDown ( )

Definition at line 613 of file AButton.cpp.

614{
615 return mWasControlDown;
616}

References mWasControlDown.

Referenced by TranscriptionToolBar::OnPlaySpeed(), and ControlToolBar::PlayDefault().

Here is the caller graph for this function:

◆ WasShiftDown()

bool AButton::WasShiftDown ( )

Definition at line 608 of file AButton.cpp.

609{
610 return mWasShiftDown;
611}

References mWasShiftDown.

Referenced by MixerTrackCluster::OnButton_Mute(), MixerTrackCluster::OnButton_Solo(), ControlToolBar::OnFF(), ControlToolBar::OnRecord(), ControlToolBar::OnRewind(), ControlToolBar::PlayDefault(), and ControlToolBar::ReCreateButtons().

Here is the caller graph for this function:

Friends And Related Function Documentation

◆ AButtonAx

friend class AButtonAx
friend

Definition at line 105 of file AButton.h.

Referenced by Init().

Member Data Documentation

◆ mAlternateIdx

unsigned AButton::mAlternateIdx {0}
private

Definition at line 262 of file AButton.h.

Referenced by DoGetBestClientSize(), OnPaint(), and SetAlternateIdx().

◆ mButtonIsDown

bool AButton::mButtonIsDown {false}
private

Definition at line 274 of file AButton.h.

Referenced by GetState(), OnCharHook(), OnMouseEvent(), PopUp(), and PushDown().

◆ mCursorIsInWindow

bool AButton::mCursorIsInWindow {false}
private

Definition at line 273 of file AButton.h.

Referenced by GetState(), OnMouseEvent(), and UpdateStatus().

◆ mEnabled

bool AButton::mEnabled {true}
private

Definition at line 276 of file AButton.h.

Referenced by Disable(), Enable(), GetState(), OnCharHook(), OnMouseEvent(), and UpdateStatus().

◆ mFocusRect

wxRect AButton::mFocusRect
private

Definition at line 283 of file AButton.h.

Referenced by Init(), OnPaint(), OnSize(), and SetFocusRect().

◆ mForceFocusRect

bool AButton::mForceFocusRect {false}
private

Definition at line 284 of file AButton.h.

Referenced by OnSize(), and SetFocusRect().

◆ mFrameMid

int AButton::mFrameMid {1}
private

Definition at line 289 of file AButton.h.

Referenced by DoGetBestClientSize(), OnPaint(), and SetFrameMid().

◆ mIcons

std::vector<std::array<wxImage, AButtonStateCount> > AButton::mIcons
private

Definition at line 280 of file AButton.h.

Referenced by DoGetBestClientSize(), OnPaint(), SetAlternateIcon(), and SetAlternateIcons().

◆ mImages

std::vector<std::array<wxImage, AButtonStateCount> > AButton::mImages
private

◆ mIsClicking

bool AButton::mIsClicking {false}
private

Definition at line 275 of file AButton.h.

Referenced by GetState(), and OnMouseEvent().

◆ mIsDoubleClicked

bool AButton::mIsDoubleClicked {false}
private

Definition at line 278 of file AButton.h.

Referenced by OnMouseEvent().

◆ mListener

std::unique_ptr<Listener> AButton::mListener
private

Definition at line 286 of file AButton.h.

Referenced by FollowModifierKeys().

◆ mToggle

bool AButton::mToggle {false}
private

Definition at line 263 of file AButton.h.

Referenced by GetState(), Init(), OnCharHook(), and OnMouseEvent().

◆ mType

Type AButton::mType {ImageButton}
private

Definition at line 288 of file AButton.h.

Referenced by DoGetBestClientSize(), OnPaint(), SetButtonType(), SetFrameMid(), and SetLabel().

◆ mUseDisabledAsDownHiliteImage

bool AButton::mUseDisabledAsDownHiliteImage {false}
private

Definition at line 277 of file AButton.h.

Referenced by GetState(), and UseDisabledAsDownHiliteImage().

◆ mWasControlDown

bool AButton::mWasControlDown {false}
private

Definition at line 271 of file AButton.h.

Referenced by OnCharHook(), OnMouseEvent(), SetControl(), and WasControlDown().

◆ mWasShiftDown

bool AButton::mWasShiftDown {false}
private

Definition at line 270 of file AButton.h.

Referenced by OnCharHook(), OnMouseEvent(), SetShift(), and WasShiftDown().

◆ s_AcceptsFocus

bool AButton::s_AcceptsFocus { false }
staticprivate

Definition at line 249 of file AButton.h.

Referenced by TemporarilyAllowFocus().


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