32#include <wx/dcbuffer.h>
33#include <wx/eventfilter.h>
38#include "../ProjectWindowBase.h"
39#include <wx/tooltip.h>
43BEGIN_EVENT_TABLE(
AButton, wxWindow)
58 : public wxEventFilter
64 int FilterEvent(wxEvent &event)
override;
75 wxEvtHandler::AddFilter(
this);
80 wxEvtHandler::RemoveFilter(
this);
85 if (!mButton->IsDown())
93 if (wxGetKeyState(WXK_CONTROL) && mButton->HasAlternateImages(2))
95 else if (wxGetKeyState(WXK_SHIFT) && mButton->HasAlternateImages(1))
100 mButton->SetAlternateIdx(idx);
106 if (event.GetEventType() == wxEVT_KEY_DOWN ||
107 event.GetEventType() == wxEVT_KEY_UP)
109 else if (event.GetEventType() == wxEVT_SET_FOCUS)
119 Init(parent,
id, pos,
size, toggle);
133 Init(parent,
id, pos,
size, toggle);
152 InvalidateBestSize();
154 PostSizeEventToParent();
159void AButton::Init(wxWindow* parent, wxWindowID
id,
const wxPoint& pos,
const wxSize&
size,
bool toggle)
161 SetBackgroundStyle(wxBG_STYLE_PAINT);
167 Create(parent,
id, pos,
size, wxWANTS_CHARS);
173#if wxUSE_ACCESSIBILITY
193 InvalidateBestSize();
240 PostSizeEventToParent();
246 mListener = std::make_unique<Listener>(
this);
295 wxBufferedPaintDC dc(
this);
297 dc.SetPen(*wxTRANSPARENT_PEN);
298 dc.SetBrush(GetBackgroundColour());
301 const auto buttonRect = GetClientRect();
312 const auto border = bitmap.GetSize() / 4;
314 if(!GetLabel().IsEmpty())
316 dc.SetFont(GetFont());
317 auto textRect = buttonRect;
320 auto fontMetrics = dc.GetFontMetrics();
321 auto sumHeight = fontMetrics.height +
mIcon.GetHeight() + border.y;
323 buttonRect.x + (buttonRect.width -
mIcon.GetWidth()) / 2,
324 buttonRect.y + (buttonRect.height - sumHeight) / 2);
327 buttonRect.y + buttonRect.height / 2 + sumHeight / 2 - fontMetrics.height,
331 dc.SetPen(GetForegroundColour());
332 dc.DrawLabel(GetLabel(), textRect, wxALIGN_CENTER);
334 else if(
mIcon.IsOk())
337 buttonRect.x + (buttonRect.width -
mIcon.GetWidth()) / 2,
338 buttonRect.y + (buttonRect.height -
mIcon.GetHeight()) / 2);
345 if(!GetLabel().IsEmpty())
347 dc.SetFont(GetFont());
351 dc.SetPen(GetForegroundColour());
352 dc.DrawLabel(text, GetClientRect(), wxALIGN_CENTER);
383 const auto &arr =
mImages[idx];
384 return (arr[0].Ok() &&
393 wxSize clientSize = GetClientSize();
396 if (event.Entering()) {
399 auto text = GetToolTipText();
401 wxWindow::SetToolTip(text);
404 else if (event.Leaving())
408 (
event.m_x >= 0 &&
event.m_y >= 0 &&
409 event.m_x < clientSize.x &&
event.m_y < clientSize.y);
412 if (event.ButtonIsDown(wxMOUSE_BTN_LEFT)) {
414 if (event.ButtonDClick())
440 if (newState != prevState) {
460 wxToolTip * pTip = this->GetToolTip();
462 auto tipText =
Verbatim( pTip->GetTip() );
464 tipText.Join(
XO(
"(disabled)"),
" " );
475 wxMouseEvent e(wxEVT_LEFT_UP);
485 switch( event.GetKeyCode() )
489 Navigate(wxNavigationKeyEvent::IsForward);
493 Navigate(wxNavigationKeyEvent::IsBackward);
496 Navigate(wxNavigationKeyEvent::FromTab | (event.ShiftDown()
497 ? wxNavigationKeyEvent::IsBackward
498 : wxNavigationKeyEvent::IsForward));
507 switch(event.GetKeyCode())
510 case WXK_NUMPAD_ENTER:
519#if wxUSE_ACCESSIBILITY
520 GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_NAMECHANGE,
521 this, wxOBJID_CLIENT, wxACC_SELF);
553 bool changed = wxWindow::Enable(
true);
567 wxWindow::Enable(
false);
569 if (GetCapture()==
this)
581 this->Refresh(
false);
590 this->Refresh(
false);
593 if (GetCapture()==
this)
600 event.SetEventObject(
this);
603 GetEventHandler()->SafelyProcessEvent(event);
625 if(!GetLabel().IsEmpty())
627 const auto border = image.GetSize() / 4;
630 dc.SetFont(GetFont());
631 auto bestSize = dc.GetTextExtent(GetLabel());
634 bestSize.x = std::max(bestSize.x,
mIcon.GetWidth());
635 bestSize.y = bestSize.y > 0
636 ? bestSize.y + border.y +
mIcon.GetHeight()
640 bestSize.x += border.x * 2;
642 bestSize.y += border.y * 2;
646 return mIcon.GetSize();
647 return image.GetSize();
650 return {-1, image.GetHeight() };
652 return image.GetSize();
655 return wxWindow::DoGetBestClientSize();
663#if wxUSE_ACCESSIBILITY
665AButtonAx::AButtonAx( wxWindow *window ):
670AButtonAx::~AButtonAx()
678wxAccStatus AButtonAx::DoDefaultAction(
int WXUNUSED(childId))
698wxAccStatus AButtonAx::GetChild(
int childId, wxAccessible** child )
700 if( childId == wxACC_SELF )
713wxAccStatus AButtonAx::GetChildCount(
int* childCount)
727wxAccStatus AButtonAx::GetDefaultAction(
int WXUNUSED(childId), wxString* actionName)
729 *actionName =
_(
"Press" );
735wxAccStatus AButtonAx::GetDescription(
int WXUNUSED(childId), wxString *description )
737 description->clear();
746wxAccStatus AButtonAx::GetFocus(
int* childId, wxAccessible** child)
755wxAccStatus AButtonAx::GetHelpText(
int WXUNUSED(childId), wxString *helpText )
760 wxToolTip *pTip = ab->GetToolTip();
763 *helpText = pTip->GetTip();
770 return wxACC_NOT_SUPPORTED;
776wxAccStatus AButtonAx::GetKeyboardShortcut(
int WXUNUSED(childId), wxString *shortcut )
785wxAccStatus AButtonAx::GetLocation( wxRect& rect,
int WXUNUSED(elementId) )
789 rect = ab->GetRect();
790 rect.SetPosition( ab->GetParent()->ClientToScreen( rect.GetPosition() ) );
796wxAccStatus AButtonAx::GetName(
int WXUNUSED(childId), wxString*
name)
800 *
name = ab->GetName();
803 *
name = ab->GetLabel();
823 (ab->
IsDown() ?
_(
"pressed") +
wxT(
'\a') :
_(
"not pressed"));
830wxAccStatus AButtonAx::GetRole(
int WXUNUSED(childId), wxAccRole* role)
835 *role = ab->
mToggle ? wxROLE_SYSTEM_STATICTEXT : wxROLE_SYSTEM_PUSHBUTTON;
848wxAccStatus AButtonAx::GetSelections( wxVariant * WXUNUSED(selections) )
850 return wxACC_NOT_IMPLEMENTED;
854wxAccStatus AButtonAx::GetState(
int WXUNUSED(childId),
long* state)
859 *state = wxACC_STATE_SYSTEM_UNAVAILABLE;
864 *state |= wxACC_STATE_SYSTEM_PRESSED;
867 *state |= wxACC_STATE_SYSTEM_HOTTRACKED;
869 *state |= wxACC_STATE_SYSTEM_FOCUSABLE;
871 *state |= wxACC_STATE_SYSTEM_FOCUSED;
878wxAccStatus AButtonAx::GetValue(
int WXUNUSED(childId), wxString* WXUNUSED(strValue))
880 return wxACC_NOT_SUPPORTED;
wxEVT_COMMAND_BUTTON_CLICKED
const TranslatableString name
AudacityProject * FindProjectFromWindow(wxWindow *pWindow)
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
static void DrawHStretch(wxDC &dc, const wxRect &rect, wxBitmap &bitmap)
static void DrawFrame(wxDC &dc, const wxRect &r, wxBitmap &bitmap)
static void DrawFocus(wxDC &dc, wxRect &r)
static ProjectStatus & Get(AudacityProject &project)
void Set(const TranslatableString &msg, StatusBarField field=mainStatusBarField)
Holds a msgid for the translation catalog; may also bind format arguments.
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 ...
void SetFocus(const WindowPlacement &focus)
Set the window that accepts keyboard input.
AUDACITY_DLL_API wxString TruncateText(wxDC &dc, const wxString &text, const int maxWidth)