34#include <wx/dcbuffer.h>
35#include <wx/eventfilter.h>
40#include "../ProjectWindowBase.h"
41#include <wx/tooltip.h>
44BEGIN_EVENT_TABLE(
AButton, wxWindow)
59 : public wxEventFilter
65 int FilterEvent(wxEvent &event)
override;
76 wxEvtHandler::AddFilter(
this);
81 wxEvtHandler::RemoveFilter(
this);
86 if (!mButton->IsDown())
94 if (wxGetKeyState(WXK_CONTROL) && mButton->HasAlternateImages(2))
96 else if (wxGetKeyState(WXK_SHIFT) && mButton->HasAlternateImages(1))
101 mButton->SetAlternateIdx(idx);
107 if (event.GetEventType() == wxEVT_KEY_DOWN ||
108 event.GetEventType() == wxEVT_KEY_UP)
110 else if (event.GetEventType() == wxEVT_SET_FOCUS)
120 Init(parent,
id, pos,
size, toggle);
134 Init(parent,
id, pos,
size, toggle);
153 InvalidateBestSize();
155 PostSizeEventToParent();
167 InvalidateBestSize();
169 PostSizeEventToParent();
174void AButton::Init(wxWindow* parent, wxWindowID
id,
const wxPoint& pos,
const wxSize&
size,
bool toggle)
176 SetBackgroundStyle(wxBG_STYLE_PAINT);
183 Create(parent,
id, pos,
size, wxWANTS_CHARS);
189#if wxUSE_ACCESSIBILITY
209 InvalidateBestSize();
259 if(1 + idx >
mIcons.size())
269 if(1 + idx >
mIcons.size())
271 mIcons[idx][state] = icon;
277 if(1 + idx >
mIcons.size())
295 PostSizeEventToParent();
301 mListener = std::make_unique<Listener>(
this);
350 wxBufferedPaintDC dc(
this);
352 dc.SetPen(*wxTRANSPARENT_PEN);
353 dc.SetBrush(GetBackgroundColour());
356 const auto buttonRect = GetClientRect();
361 const auto buttonState =
GetState();
364 dc.DrawBitmap(
mImages[imageIdx][buttonState], buttonRect.GetTopLeft());
367 wxBitmap bitmap =
mImages[imageIdx][buttonState];
370 const auto border = bitmap.GetSize() / 4;
375 if((icon ==
nullptr || !icon->IsOk()) && !
mIcons.empty())
377 icon = &
mIcons[0][buttonState];
381 if(isFrameTextButton && !GetLabel().IsEmpty())
383 dc.SetFont(GetFont());
384 auto textRect = buttonRect;
385 if(icon !=
nullptr && icon->IsOk())
387 const auto fontMetrics = dc.GetFontMetrics();
390 const auto sumHeight = fontMetrics.height + icon->GetHeight() + border.y;
393 buttonRect.x + (buttonRect.width - icon->GetWidth()) / 2,
394 buttonRect.y + (buttonRect.height - sumHeight) / 2);
397 buttonRect.y + buttonRect.height / 2 + sumHeight / 2 - fontMetrics.height,
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;
408 buttonRect.x + iconCenter - icon->GetWidth() / 2,
409 buttonRect.y + iconCenter - icon->GetHeight() / 2);
411 buttonRect.x + textLeft,
412 buttonRect.y + border.y,
413 buttonRect.width - textLeft,
414 buttonRect.height - border.y * 2
418 dc.SetPen(GetForegroundColour());
419 dc.DrawLabel(GetLabel(), textRect, wxALIGN_CENTER);
421 else if(icon !=
nullptr && icon->IsOk())
424 buttonRect.x + (buttonRect.width - icon->GetWidth()) / 2,
425 buttonRect.y + (buttonRect.height - icon->GetHeight()) / 2);
430 wxBitmap bitmap =
mImages[imageIdx][buttonState];
432 if(!GetLabel().IsEmpty())
434 dc.SetFont(GetFont());
438 dc.SetPen(GetForegroundColour());
439 dc.DrawLabel(text, GetClientRect(), wxALIGN_CENTER);
470 const auto &arr =
mImages[idx];
471 return (arr[0].Ok() &&
480 wxSize clientSize = GetClientSize();
483 if (event.Entering()) {
486 auto text = GetToolTipText();
488 wxWindow::SetToolTip(text);
491 else if (event.Leaving())
495 (
event.m_x >= 0 &&
event.m_y >= 0 &&
496 event.m_x < clientSize.x &&
event.m_y < clientSize.y);
499 if (event.ButtonIsDown(wxMOUSE_BTN_LEFT)) {
501 if (event.ButtonDClick())
527 if (newState != prevState) {
547 wxToolTip * pTip = this->GetToolTip();
549 auto tipText =
Verbatim( pTip->GetTip() );
551 tipText.Join(
XO(
"(disabled)"),
" " );
562 wxMouseEvent e(wxEVT_LEFT_UP);
572 switch( event.GetKeyCode() )
576 Navigate(wxNavigationKeyEvent::IsForward);
580 Navigate(wxNavigationKeyEvent::IsBackward);
583 Navigate(wxNavigationKeyEvent::FromTab | (event.ShiftDown()
584 ? wxNavigationKeyEvent::IsBackward
585 : wxNavigationKeyEvent::IsForward));
594 switch(event.GetKeyCode())
597 case WXK_NUMPAD_ENTER:
606#if wxUSE_ACCESSIBILITY
607 GetAccessible()->NotifyEvent(wxACC_EVENT_OBJECT_NAMECHANGE,
608 this, wxOBJID_CLIENT, wxACC_SELF);
640 bool changed = wxWindow::Enable(
true);
654 wxWindow::Enable(
false);
656 if (GetCapture()==
this)
668 this->Refresh(
false);
677 this->Refresh(
false);
680 if (GetCapture()==
this)
687 event.SetEventObject(
this);
690 GetEventHandler()->SafelyProcessEvent(event);
715 return icon->GetSize();
716 return image.GetSize();
723 if(!GetLabel().IsEmpty())
728 dc.SetFont(GetFont());
729 auto bestSize = dc.GetTextExtent(GetLabel());
730 if(icon !=
nullptr && icon->IsOk())
734 bestSize.x = std::max(bestSize.x, icon->GetWidth());
735 bestSize.y = bestSize.y > 0
736 ? bestSize.y + border.y + icon->GetHeight()
741 bestSize.x += image.GetWidth() + border.x;
742 bestSize.y = std::max(image.GetHeight(), bestSize.y);
746 bestSize.x += border.x * 2;
748 bestSize.y += border.y * 2;
752 return icon->GetSize();
753 return image.GetSize();
756 return {-1, image.GetHeight() };
758 return image.GetSize();
761 return wxWindow::DoGetBestClientSize();
769#if wxUSE_ACCESSIBILITY
771AButtonAx::AButtonAx( wxWindow *window ):
776AButtonAx::~AButtonAx()
784wxAccStatus AButtonAx::DoDefaultAction(
int WXUNUSED(childId))
804wxAccStatus AButtonAx::GetChild(
int childId, wxAccessible** child )
806 if( childId == wxACC_SELF )
819wxAccStatus AButtonAx::GetChildCount(
int* childCount)
833wxAccStatus AButtonAx::GetDefaultAction(
int WXUNUSED(childId), wxString* actionName)
835 *actionName =
_(
"Press" );
841wxAccStatus AButtonAx::GetDescription(
int WXUNUSED(childId), wxString *description )
843 description->clear();
852wxAccStatus AButtonAx::GetFocus(
int* childId, wxAccessible** child)
861wxAccStatus AButtonAx::GetHelpText(
int WXUNUSED(childId), wxString *helpText )
866 wxToolTip *pTip = ab->GetToolTip();
869 *helpText = pTip->GetTip();
876 return wxACC_NOT_SUPPORTED;
882wxAccStatus AButtonAx::GetKeyboardShortcut(
int WXUNUSED(childId), wxString *shortcut )
891wxAccStatus AButtonAx::GetLocation( wxRect& rect,
int WXUNUSED(elementId) )
895 rect = ab->GetRect();
896 rect.SetPosition( ab->GetParent()->ClientToScreen( rect.GetPosition() ) );
902wxAccStatus AButtonAx::GetName(
int WXUNUSED(childId), wxString*
name)
906 *
name = ab->GetName();
909 *
name = ab->GetLabel();
929 (ab->
IsDown() ?
_(
"pressed") +
wxT(
'\a') :
_(
"not pressed"));
936wxAccStatus AButtonAx::GetRole(
int WXUNUSED(childId), wxAccRole* role)
941 *role = ab->
mToggle ? wxROLE_SYSTEM_STATICTEXT : wxROLE_SYSTEM_PUSHBUTTON;
954wxAccStatus AButtonAx::GetSelections( wxVariant * WXUNUSED(selections) )
956 return wxACC_NOT_IMPLEMENTED;
960wxAccStatus AButtonAx::GetState(
int WXUNUSED(childId),
long* state)
965 *state = wxACC_STATE_SYSTEM_UNAVAILABLE;
970 *state |= wxACC_STATE_SYSTEM_PRESSED;
973 *state |= wxACC_STATE_SYSTEM_HOTTRACKED;
975 *state |= wxACC_STATE_SYSTEM_FOCUSABLE;
977 *state |= wxACC_STATE_SYSTEM_FOCUSED;
984wxAccStatus AButtonAx::GetValue(
int WXUNUSED(childId), wxString* WXUNUSED(strValue))
986 return wxACC_NOT_SUPPORTED;
wxEVT_COMMAND_BUTTON_CLICKED
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 DrawFrame(wxDC &dc, const wxRect &r, wxBitmap &bitmap, int mid)
static void DrawHStretch(wxDC &dc, const wxRect &rect, wxBitmap &bitmap)
static void DrawFocus(wxDC &dc, wxRect &r)
static ProjectStatus & Get(AudacityProject &project)
void Set(const TranslatableString &msg, StatusBarField field=MainStatusBarField())
wxColour & Colour(int iIndex)
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)