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 , FrameTextVButton ,
  FrameTextHButton
}
 
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 252 of file AButton.h.

Member Enumeration Documentation

◆ AButtonState

Enumerator
AButtonUp 
AButtonOver 
AButtonDown 
AButtonOverDown 
AButtonDis 
AButtonStateCount 

Definition at line 119 of file AButton.h.

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

◆ Type

Enumerator
TextButton 
ImageButton 
FrameButton 
FrameTextVButton 
FrameTextHButton 

Definition at line 110 of file AButton.h.

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

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:282

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 159 of file AButton.h.

159{ return s_AcceptsFocus; }
static bool s_AcceptsFocus
Definition: AButton.h:250

◆ AcceptsFocusFromKeyboard()

bool AButton::AcceptsFocusFromKeyboard ( ) const
inlineoverride

Definition at line 160 of file AButton.h.

160{ return mEnabled; }
bool mEnabled
Definition: AButton.h:277

◆ ClearDoubleClicked()

void AButton::ClearDoubleClicked ( )
inline

Definition at line 231 of file AButton.h.

231{ mIsDoubleClicked = false; }
bool mIsDoubleClicked
Definition: AButton.h:279

◆ Click()

void AButton::Click ( )

Definition at line 684 of file AButton.cpp.

685{
686 wxCommandEvent event(wxEVT_COMMAND_BUTTON_CLICKED, GetId());
687 event.SetEventObject(this);
688 // Be sure to use SafelyProcessEvent so that exceptions do not propagate
689 // out of DoDefaultAction
690 GetEventHandler()->SafelyProcessEvent(event);
691}
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 647 of file AButton.cpp.

648{
649 // Bug 1565: Tooltips not showing on disabled buttons.
650 // The fix is to NOT tell windows that the button is disabled.
651 // The button's appearance will still change to show it is disabled
652 // since we control that rather than windows.
653#ifndef __WXMSW__
654 wxWindow::Enable(false);
655#endif
656 if (GetCapture()==this)
657 ReleaseMouse();
658 if ( mEnabled ) {
659 mEnabled = false;
660 Refresh(false);
661 }
662}

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 703 of file AButton.cpp.

704{
705 const auto imageIdx = HasAlternateImages(mAlternateIdx) ? mAlternateIdx : 0;
706 if(imageIdx == mAlternateIdx || HasAlternateImages(imageIdx))
707 {
708 const auto& image = mImages[imageIdx][AButtonUp];
709 switch(mType)
710 {
711 case FrameButton:
712 {
713 const auto icon = !mIcons.empty() ? &mIcons[0][AButtonUp] : nullptr;
714 if(icon->IsOk())
715 return icon->GetSize();
716 return image.GetSize();
717 }
718 case FrameTextVButton:
719 case FrameTextHButton:
720 {
721 //Only AButtonUp is used to estimate size
722 auto icon = !mIcons.empty() ? &mIcons[0][AButtonUp] : nullptr;
723 if(!GetLabel().IsEmpty())
724 {
725 const auto border = (image.GetSize() - wxSize { mFrameMid, mFrameMid }) / 4;
726
727 wxMemoryDC dc;
728 dc.SetFont(GetFont());
729 auto bestSize = dc.GetTextExtent(GetLabel());
730 if(icon != nullptr && icon->IsOk())
731 {
733 {
734 bestSize.x = std::max(bestSize.x, icon->GetWidth());
735 bestSize.y = bestSize.y > 0
736 ? bestSize.y + border.y + icon->GetHeight()
737 : icon->GetHeight();
738 }
739 else
740 {
741 bestSize.x += image.GetWidth() + border.x;
742 bestSize.y = std::max(image.GetHeight(), bestSize.y);
743 }
744 }
745 if(bestSize.x > 0)
746 bestSize.x += border.x * 2;
747 if(bestSize.y > 0)
748 bestSize.y += border.y * 2;
749 return bestSize;
750 }
751 if(icon->Ok())
752 return icon->GetSize();
753 return image.GetSize();
754 }
755 case TextButton:
756 return {-1, image.GetHeight() };
757 default:
758 return image.GetSize();
759 }
760 }
761 return wxWindow::DoGetBestClientSize();
762}
bool HasAlternateImages(unsigned idx) const
Definition: AButton.cpp:465
Type mType
Definition: AButton.h:289
std::vector< std::array< wxImage, AButtonStateCount > > mIcons
Definition: AButton.h:281
int mFrameMid
Definition: AButton.h:290
unsigned mAlternateIdx
Definition: AButton.h:263

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

Here is the call graph for this function:

◆ Enable()

void AButton::Enable ( )

Definition at line 638 of file AButton.cpp.

639{
640 bool changed = wxWindow::Enable(true);
641 if ( !mEnabled ) {
642 mEnabled = true;
643 Refresh(false);
644 }
645}

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:287

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:278
bool mButtonIsDown
Definition: AButton.h:275
bool mCursorIsInWindow
Definition: AButton.h:274
AButtonState
Definition: AButton.h:119
bool mIsClicking
Definition: AButton.h:276
bool mToggle
Definition: AButton.h:264

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 465 of file AButton.cpp.

466{
467 if (mImages.size() <= idx)
468 return false;
469
470 const auto &arr = mImages[idx];
471 return (arr[0].Ok() &&
472 arr[1].Ok() &&
473 arr[2].Ok() &&
474 arr[3].Ok() &&
475 arr[4].Ok());
476}
@ 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:284
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 237 of file AButton.h.

237{ if( !mToggle ) PopUp();}
void PopUp()
Definition: AButton.cpp:672

◆ IsDoubleClicked()

bool AButton::IsDoubleClicked ( ) const
inline

Definition at line 230 of file AButton.h.

230{ return mIsDoubleClicked; }

◆ IsDown()

bool AButton::IsDown ( )
inline

Definition at line 227 of file AButton.h.

227{ 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 198 of file AButton.h.

198{ return mEnabled; }

◆ IsToggle()

bool AButton::IsToggle ( ) const
noexcept

◆ OnCaptureLost()

void AButton::OnCaptureLost ( wxMouseCaptureLostEvent &  event)

Definition at line 560 of file AButton.cpp.

561{
562 wxMouseEvent e(wxEVT_LEFT_UP);
563 e.m_x = -1;
564 e.m_y = -1;
565 OnMouseEvent(e);
566}
void OnMouseEvent(wxMouseEvent &event)
Definition: AButton.cpp:478

References OnMouseEvent().

Here is the call graph for this function:

◆ OnCharHook()

void AButton::OnCharHook ( wxKeyEvent &  event)

Definition at line 592 of file AButton.cpp.

593{
594 switch(event.GetKeyCode())
595 {
596 case WXK_RETURN:
597 case WXK_NUMPAD_ENTER:
598 if( !mEnabled )
599 break;
600 mWasShiftDown = event.ShiftDown();
601 mWasControlDown = event.ControlDown();
602 if(mToggle)
603 {
605 Refresh(false);
606#if wxUSE_ACCESSIBILITY
607 GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_NAMECHANGE,
608 this, wxOBJID_CLIENT, wxACC_SELF);
609#endif
610 }
611 Click();
612 break;
613 default:
614 event.Skip();
615 }
616}
bool mWasShiftDown
Definition: AButton.h:271
void Click()
Definition: AButton.cpp:684
bool mWasControlDown
Definition: AButton.h:272

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 449 of file AButton.cpp.

450{
451 // Ignore it to prevent flashing
452}

◆ OnKeyDown()

void AButton::OnKeyDown ( wxKeyEvent &  event)

Definition at line 570 of file AButton.cpp.

571{
572 switch( event.GetKeyCode() )
573 {
574 case WXK_RIGHT:
575 case WXK_DOWN:
576 Navigate(wxNavigationKeyEvent::IsForward);
577 break;
578 case WXK_LEFT:
579 case WXK_UP:
580 Navigate(wxNavigationKeyEvent::IsBackward);
581 break;
582 case WXK_TAB:
583 Navigate(wxNavigationKeyEvent::FromTab | (event.ShiftDown()
584 ? wxNavigationKeyEvent::IsBackward
585 : wxNavigationKeyEvent::IsForward));
586 break;
587 default:
588 event.Skip();
589 }
590}

◆ OnKillFocus()

void AButton::OnKillFocus ( wxFocusEvent &  event)

Definition at line 623 of file AButton.cpp.

624{
625 Refresh( false );
626}

◆ OnMouseEvent()

void AButton::OnMouseEvent ( wxMouseEvent &  event)

Definition at line 478 of file AButton.cpp.

479{
480 wxSize clientSize = GetClientSize();
481 AButtonState prevState = GetState();
482
483 if (event.Entering()) {
484 // Bug 1201: On Mac, unsetting and re-setting the tooltip may be needed
485 // to make it pop up when we want it.
486 auto text = GetToolTipText();
487 UnsetToolTip();
488 wxWindow::SetToolTip(text);
489 mCursorIsInWindow = true;
490 }
491 else if (event.Leaving())
492 mCursorIsInWindow = false;
493 else
495 (event.m_x >= 0 && event.m_y >= 0 &&
496 event.m_x < clientSize.x && event.m_y < clientSize.y);
497
498 if (mEnabled && event.IsButton()) {
499 if (event.ButtonIsDown(wxMOUSE_BTN_LEFT)) {
500 mIsClicking = true;
501 if (event.ButtonDClick())
502 mIsDoubleClicked = true;
503 if( !HasCapture() )
504 CaptureMouse();
505 }
506 else if (mIsClicking) {
507 mIsClicking = false;
508
509 if (HasCapture())
510 ReleaseMouse();
511
513 if (mToggle)
515
516 mWasShiftDown = event.ShiftDown();
517 mWasControlDown = event.ControlDown();
518
519 Click();
520 }
521 }
522 }
523
524 // Only redraw and change tooltips if the state has changed.
525 AButtonState newState = GetState();
526
527 if (newState != prevState) {
528 Refresh(false);
529
531 UpdateStatus();
532 else {
533 auto pProject = FindProjectFromWindow( this );
534 if (pProject)
535 ProjectStatus::Get( *pProject ).Set({});
536 }
537 }
538 else
539 event.Skip();
540}
AudacityProject * FindProjectFromWindow(wxWindow *pWindow)
void UpdateStatus()
Definition: AButton.cpp:542
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 const auto isFrameTextButton = mType == FrameTextVButton || mType == FrameTextHButton;
363 if(mType == ImageButton)
364 dc.DrawBitmap(mImages[imageIdx][buttonState], buttonRect.GetTopLeft());
365 else if(mType == FrameButton || isFrameTextButton)
366 {
367 wxBitmap bitmap = mImages[imageIdx][buttonState];
368 AColor::DrawFrame(dc, buttonRect, bitmap, mFrameMid);
369
370 const auto border = bitmap.GetSize() / 4;
371
372 wxImage* icon{};
373 if(mIcons.size() > mAlternateIdx)
374 icon = &mIcons[mAlternateIdx][buttonState];
375 if((icon == nullptr || !icon->IsOk()) && !mIcons.empty())
376 {
377 icon = &mIcons[0][buttonState];
378 if(!icon->IsOk())
379 icon = &mIcons[0][AButtonUp];
380 }
381 if(isFrameTextButton && !GetLabel().IsEmpty())
382 {
383 dc.SetFont(GetFont());
384 auto textRect = buttonRect;
385 if(icon != nullptr && icon->IsOk())
386 {
387 const auto fontMetrics = dc.GetFontMetrics();
389 {
390 const auto sumHeight = fontMetrics.height + icon->GetHeight() + border.y;
391
392 dc.DrawBitmap(*icon,
393 buttonRect.x + (buttonRect.width - icon->GetWidth()) / 2,
394 buttonRect.y + (buttonRect.height - sumHeight) / 2);
395 textRect = wxRect(
396 buttonRect.x,
397 buttonRect.y + buttonRect.height / 2 + sumHeight / 2 - fontMetrics.height,
398 buttonRect.width,
399 fontMetrics.height);
400 }
401 else
402 {
403 const auto sumWidth = icon->GetWidth() + border.x + dc.GetTextExtent(GetLabel()).GetWidth();
404 const auto iconCenter = buttonRect.height / 2;
405 const auto textLeft = iconCenter + icon->GetWidth() / 2 + border.x;
406
407 dc.DrawBitmap(*icon,
408 buttonRect.x + iconCenter - icon->GetWidth() / 2,
409 buttonRect.y + iconCenter - icon->GetHeight() / 2);
410 textRect = wxRect(
411 buttonRect.x + textLeft,
412 buttonRect.y + border.y,
413 buttonRect.width - textLeft,
414 buttonRect.height - border.y * 2
415 );
416 }
417 }
418 dc.SetPen(GetForegroundColour());
419 dc.DrawLabel(GetLabel(), textRect, wxALIGN_CENTER);
420 }
421 else if(icon != nullptr && icon->IsOk())
422 {
423 dc.DrawBitmap(*icon,
424 buttonRect.x + (buttonRect.width - icon->GetWidth()) / 2,
425 buttonRect.y + (buttonRect.height - icon->GetHeight()) / 2);
426 }
427 }
428 else
429 {
430 wxBitmap bitmap = mImages[imageIdx][buttonState];
431 AColor::DrawHStretch(dc, GetClientRect(), bitmap);
432 if(!GetLabel().IsEmpty())
433 {
434 dc.SetFont(GetFont());
435 const auto text = TrackArt::TruncateText(dc, GetLabel(), GetClientSize().GetWidth() - 6);
436 if(!text.IsEmpty())
437 {
438 dc.SetPen(GetForegroundColour());
439 dc.DrawLabel(text, GetClientRect(), wxALIGN_CENTER);
440 }
441 }
442 }
443 }
444
445 if(HasFocus())
447}
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, FrameTextHButton, FrameTextVButton, 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 618 of file AButton.cpp.

619{
620 Refresh( false );
621}

◆ OnSize()

void AButton::OnSize ( wxSizeEvent &  event)

Definition at line 454 of file AButton.cpp.

455{
456 if (!mForceFocusRect)
457 {
458 mFocusRect = GetClientRect().Deflate( 3, 3 );
459 }
460 Refresh(false);
461}
bool mForceFocusRect
Definition: AButton.h:285

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 233 of file AButton.h.

233{ 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 698 of file AButton.cpp.

699{
700 mWasControlDown = control;
701}

References mWasControlDown.

Referenced by ControlToolBar::SetPlay().

Here is the caller graph for this function:

◆ SetEnabled()

void AButton::SetEnabled ( bool  state)
inline

Definition at line 201 of file AButton.h.

201 {
202 state ? Enable() : Disable();
203 }
void Disable()
Definition: AButton.cpp:647
void Enable()
Definition: AButton.cpp:638

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:764
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 693 of file AButton.cpp.

694{
695 mWasShiftDown = shift;
696}

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 764 of file AButton.cpp.

764 {
765 s_AcceptsFocus = true;
767}
std::unique_ptr< bool, Resetter > TempAllowFocus
Definition: AButton.h:252

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 238 of file AButton.h.

238{ mButtonIsDown ? PopUp() : PushDown();}
void PushDown()
Definition: AButton.cpp:664

◆ UpdateStatus()

void AButton::UpdateStatus ( )

Definition at line 542 of file AButton.cpp.

543{
544 if (mCursorIsInWindow) {
545#if wxUSE_TOOLTIPS // Not available in wxX11
546 // Display the tooltip in the status bar
547 wxToolTip * pTip = this->GetToolTip();
548 if( pTip ) {
549 auto tipText = Verbatim( pTip->GetTip() );
550 if (!mEnabled)
551 tipText.Join( XO("(disabled)"), " " );
552 auto pProject = FindProjectFromWindow( this );
553 if (pProject)
554 ProjectStatus::Get( *pProject ).Set( tipText );
555 }
556#endif
557 }
558}
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 633 of file AButton.cpp.

634{
635 return mWasControlDown;
636}

References mWasControlDown.

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

Here is the caller graph for this function:

◆ WasShiftDown()

bool AButton::WasShiftDown ( )

Definition at line 628 of file AButton.cpp.

629{
630 return mWasShiftDown;
631}

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 263 of file AButton.h.

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

◆ mButtonIsDown

bool AButton::mButtonIsDown {false}
private

Definition at line 275 of file AButton.h.

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

◆ mCursorIsInWindow

bool AButton::mCursorIsInWindow {false}
private

Definition at line 274 of file AButton.h.

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

◆ mEnabled

bool AButton::mEnabled {true}
private

Definition at line 277 of file AButton.h.

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

◆ mFocusRect

wxRect AButton::mFocusRect
private

Definition at line 284 of file AButton.h.

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

◆ mForceFocusRect

bool AButton::mForceFocusRect {false}
private

Definition at line 285 of file AButton.h.

Referenced by OnSize(), and SetFocusRect().

◆ mFrameMid

int AButton::mFrameMid {1}
private

Definition at line 290 of file AButton.h.

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

◆ mIcons

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

Definition at line 281 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 276 of file AButton.h.

Referenced by GetState(), and OnMouseEvent().

◆ mIsDoubleClicked

bool AButton::mIsDoubleClicked {false}
private

Definition at line 279 of file AButton.h.

Referenced by OnMouseEvent().

◆ mListener

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

Definition at line 287 of file AButton.h.

Referenced by FollowModifierKeys().

◆ mToggle

bool AButton::mToggle {false}
private

Definition at line 264 of file AButton.h.

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

◆ mType

Type AButton::mType {ImageButton}
private

Definition at line 289 of file AButton.h.

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

◆ mUseDisabledAsDownHiliteImage

bool AButton::mUseDisabledAsDownHiliteImage {false}
private

Definition at line 278 of file AButton.h.

Referenced by GetState(), and UseDisabledAsDownHiliteImage().

◆ mWasControlDown

bool AButton::mWasControlDown {false}
private

Definition at line 272 of file AButton.h.

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

◆ mWasShiftDown

bool AButton::mWasShiftDown {false}
private

Definition at line 271 of file AButton.h.

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

◆ s_AcceptsFocus

bool AButton::s_AcceptsFocus { false }
staticprivate

Definition at line 250 of file AButton.h.

Referenced by TemporarilyAllowFocus().


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