2010-01-23 19:44:49 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
|
|
|
|
AButton.h
|
|
|
|
|
|
|
|
Dominic Mazzoni
|
|
|
|
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifndef __AUDACITY_BUTTON__
|
|
|
|
#define __AUDACITY_BUTTON__
|
|
|
|
|
2016-02-14 18:23:08 +00:00
|
|
|
#include "../MemoryX.h"
|
2014-11-29 17:22:05 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
#if wxUSE_ACCESSIBILITY
|
|
|
|
#include <wx/access.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <wx/image.h>
|
|
|
|
#include <wx/window.h>
|
|
|
|
|
|
|
|
#include "ImageRoll.h"
|
|
|
|
|
2016-02-24 06:06:39 +00:00
|
|
|
class AButton final : public wxWindow {
|
2010-01-23 19:44:49 +00:00
|
|
|
friend class AButtonAx;
|
2014-11-29 17:22:05 +00:00
|
|
|
class Listener;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2014-11-29 17:22:05 +00:00
|
|
|
// Construct button, specifying images (button up, highlight, button down,
|
|
|
|
// and disabled) for the default state
|
2010-01-23 19:44:49 +00:00
|
|
|
AButton(wxWindow * parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxPoint & pos,
|
|
|
|
const wxSize & size,
|
|
|
|
ImageRoll up,
|
|
|
|
ImageRoll over,
|
|
|
|
ImageRoll down,
|
|
|
|
ImageRoll dis,
|
|
|
|
bool toggle);
|
|
|
|
|
2014-11-29 17:22:05 +00:00
|
|
|
// Construct button, specifying images (button up, highlight, button down,
|
|
|
|
// and disabled) for the default state
|
2010-01-23 19:44:49 +00:00
|
|
|
AButton(wxWindow * parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxPoint & pos,
|
|
|
|
const wxSize & size,
|
|
|
|
wxImage up,
|
|
|
|
wxImage over,
|
|
|
|
wxImage down,
|
|
|
|
wxImage dis,
|
|
|
|
bool toggle);
|
|
|
|
|
|
|
|
virtual ~ AButton();
|
|
|
|
|
2016-06-23 20:35:18 +00:00
|
|
|
bool AcceptsFocus() const override { return s_AcceptsFocus; }
|
|
|
|
bool AcceptsFocusFromKeyboard() const override { return true; }
|
|
|
|
|
2014-11-29 17:22:05 +00:00
|
|
|
// Associate a set of four images (button up, highlight, button down,
|
|
|
|
// disabled) with one nondefault state of the button
|
2016-02-24 06:06:47 +00:00
|
|
|
void SetAlternateImages(unsigned idx,
|
2014-11-29 17:22:05 +00:00
|
|
|
ImageRoll up,
|
2010-01-23 19:44:49 +00:00
|
|
|
ImageRoll over,
|
|
|
|
ImageRoll down,
|
|
|
|
ImageRoll dis);
|
|
|
|
|
2014-11-29 17:22:05 +00:00
|
|
|
// Associate a set of four images (button up, highlight, button down,
|
|
|
|
// disabled) with one nondefault state of the button
|
2016-02-24 06:06:47 +00:00
|
|
|
void SetAlternateImages(unsigned idx,
|
2014-11-29 17:22:05 +00:00
|
|
|
wxImage up,
|
2010-01-23 19:44:49 +00:00
|
|
|
wxImage over,
|
|
|
|
wxImage down,
|
|
|
|
wxImage dis);
|
|
|
|
|
2014-11-29 17:22:05 +00:00
|
|
|
// Choose state of the button
|
2016-02-24 06:06:47 +00:00
|
|
|
void SetAlternateIdx(unsigned idx);
|
2014-11-29 17:22:05 +00:00
|
|
|
|
|
|
|
// Make the button change appearance with the modifier keys, no matter
|
|
|
|
// where the mouse is:
|
|
|
|
// Use state 2 when CTRL is down, else 1 when SHIFT is down, else 0
|
2016-02-24 06:06:47 +00:00
|
|
|
void FollowModifierKeys();
|
2014-11-29 17:22:05 +00:00
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
void SetFocusRect(wxRect & r);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
bool IsEnabled() const { return mEnabled; }
|
|
|
|
void Disable();
|
|
|
|
void Enable();
|
2010-01-23 19:44:49 +00:00
|
|
|
void SetEnabled(bool state) {
|
|
|
|
state ? Enable() : Disable();
|
|
|
|
}
|
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
void PushDown();
|
|
|
|
void PopUp();
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
void OnErase(wxEraseEvent & event);
|
|
|
|
void OnPaint(wxPaintEvent & event);
|
|
|
|
void OnSize(wxSizeEvent & event);
|
|
|
|
void OnMouseEvent(wxMouseEvent & event);
|
2016-06-05 23:21:26 +00:00
|
|
|
|
|
|
|
// Update the status bar message if the pointer is in the button.
|
|
|
|
// Else do nothing.
|
|
|
|
void UpdateStatus();
|
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
void OnCaptureLost(wxMouseCaptureLostEvent & event);
|
|
|
|
void OnKeyDown(wxKeyEvent & event);
|
|
|
|
void OnSetFocus(wxFocusEvent & event);
|
|
|
|
void OnKillFocus(wxFocusEvent & event);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-02-24 06:06:47 +00:00
|
|
|
bool WasShiftDown(); // returns true if shift was held down
|
2010-01-23 19:44:49 +00:00
|
|
|
// the last time the button was clicked
|
2016-02-24 06:06:47 +00:00
|
|
|
bool WasControlDown(); // returns true if control was held down
|
2010-01-23 19:44:49 +00:00
|
|
|
// the last time the button was clicked
|
|
|
|
bool IsDown(){ return mButtonIsDown;}
|
2016-05-04 01:28:39 +00:00
|
|
|
|
|
|
|
// Double click is detected, but not automatically cleared.
|
|
|
|
bool IsDoubleClicked() const { return mIsDoubleClicked; }
|
|
|
|
void ClearDoubleClicked() { mIsDoubleClicked = false; }
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
void SetButtonToggles( bool toggler ){ mToggle = toggler;}
|
|
|
|
void Toggle(){ mButtonIsDown ? PopUp() : PushDown();}
|
|
|
|
void Click();
|
|
|
|
void SetShift(bool shift);
|
2015-01-03 11:27:24 +00:00
|
|
|
void SetControl(bool control);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
enum AButtonState {
|
|
|
|
AButtonUp,
|
|
|
|
AButtonOver,
|
|
|
|
AButtonDown,
|
|
|
|
AButtonDis
|
|
|
|
};
|
|
|
|
|
|
|
|
AButtonState GetState();
|
|
|
|
|
|
|
|
void UseDisabledAsDownHiliteImage(bool flag);
|
|
|
|
|
2016-06-23 20:35:18 +00:00
|
|
|
private:
|
|
|
|
static bool s_AcceptsFocus;
|
|
|
|
struct Resetter { void operator () (bool *p) const { if(p) *p = false; } };
|
|
|
|
using TempAllowFocus = std::unique_ptr<bool, Resetter>;
|
|
|
|
|
|
|
|
public:
|
|
|
|
static TempAllowFocus TemporarilyAllowFocus() {
|
|
|
|
s_AcceptsFocus = true;
|
|
|
|
return std::move(TempAllowFocus{ &s_AcceptsFocus });
|
|
|
|
}
|
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
private:
|
|
|
|
|
2014-11-29 17:22:05 +00:00
|
|
|
bool HasAlternateImages(unsigned idx);
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
void Init(wxWindow * parent,
|
|
|
|
wxWindowID id,
|
|
|
|
const wxPoint & pos,
|
|
|
|
const wxSize & size,
|
|
|
|
ImageRoll up,
|
|
|
|
ImageRoll over,
|
|
|
|
ImageRoll down,
|
|
|
|
ImageRoll dis,
|
|
|
|
bool toggle);
|
|
|
|
|
2014-11-29 17:22:05 +00:00
|
|
|
unsigned mAlternateIdx;
|
2010-01-23 19:44:49 +00:00
|
|
|
bool mToggle; // This bool, if true, makes the button able to
|
|
|
|
// process events when it is in the down state, and
|
|
|
|
// moving to the opposite state when it is clicked.
|
|
|
|
// It is used for the Pause button, and possibly
|
|
|
|
// others. If false, it (should) behave just like
|
|
|
|
// a standard button.
|
|
|
|
|
|
|
|
bool mWasShiftDown;
|
|
|
|
bool mWasControlDown;
|
|
|
|
|
|
|
|
bool mCursorIsInWindow;
|
|
|
|
bool mButtonIsFocused;
|
|
|
|
bool mButtonIsDown;
|
|
|
|
bool mIsClicking;
|
|
|
|
bool mEnabled;
|
|
|
|
bool mUseDisabledAsDownHiliteImage;
|
2016-05-04 01:28:39 +00:00
|
|
|
bool mIsDoubleClicked {};
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2014-11-29 17:22:05 +00:00
|
|
|
struct ImageArr { ImageRoll mArr[4]; };
|
|
|
|
std::vector<ImageArr> mImages;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
wxRect mFocusRect;
|
2015-01-04 09:24:26 +00:00
|
|
|
bool mForceFocusRect;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2016-02-06 01:27:09 +00:00
|
|
|
std::unique_ptr<Listener> mListener;
|
2014-11-29 17:22:05 +00:00
|
|
|
|
2010-01-23 19:44:49 +00:00
|
|
|
public:
|
|
|
|
|
|
|
|
DECLARE_EVENT_TABLE()
|
|
|
|
};
|
|
|
|
|
|
|
|
#if wxUSE_ACCESSIBILITY
|
|
|
|
|
2016-02-24 06:06:39 +00:00
|
|
|
class AButtonAx final : public wxWindowAccessible
|
2010-01-23 19:44:49 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
AButtonAx(wxWindow * window);
|
|
|
|
|
|
|
|
virtual ~ AButtonAx();
|
|
|
|
|
|
|
|
// Performs the default action. childId is 0 (the action for this object)
|
|
|
|
// or > 0 (the action for a child).
|
|
|
|
// Return wxACC_NOT_SUPPORTED if there is no default action for this
|
|
|
|
// window (e.g. an edit control).
|
2016-02-24 06:06:47 +00:00
|
|
|
wxAccStatus DoDefaultAction(int childId) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Retrieves the address of an IDispatch interface for the specified child.
|
|
|
|
// All objects must support this property.
|
2016-02-24 06:06:47 +00:00
|
|
|
wxAccStatus GetChild(int childId, wxAccessible** child) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Gets the number of children.
|
2016-02-24 06:06:47 +00:00
|
|
|
wxAccStatus GetChildCount(int* childCount) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Gets the default action for this object (0) or > 0 (the action for a child).
|
|
|
|
// Return wxACC_OK even if there is no action. actionName is the action, or the empty
|
|
|
|
// string if there is no action.
|
|
|
|
// The retrieved string describes the action that is performed on an object,
|
|
|
|
// not what the object does as a result. For example, a toolbar button that prints
|
|
|
|
// a document has a default action of "Press" rather than "Prints the current document."
|
2016-02-24 06:06:47 +00:00
|
|
|
wxAccStatus GetDefaultAction(int childId, wxString *actionName) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Returns the description for this object or a child.
|
2016-02-24 06:06:47 +00:00
|
|
|
wxAccStatus GetDescription(int childId, wxString *description) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Gets the window with the keyboard focus.
|
|
|
|
// If childId is 0 and child is NULL, no object in
|
|
|
|
// this subhierarchy has the focus.
|
|
|
|
// If this object has the focus, child should be 'this'.
|
2016-02-24 06:06:47 +00:00
|
|
|
wxAccStatus GetFocus(int *childId, wxAccessible **child) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Returns help text for this object or a child, similar to tooltip text.
|
2016-02-24 06:06:47 +00:00
|
|
|
wxAccStatus GetHelpText(int childId, wxString *helpText) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Returns the keyboard shortcut for this object or child.
|
|
|
|
// Return e.g. ALT+K
|
2016-02-24 06:06:47 +00:00
|
|
|
wxAccStatus GetKeyboardShortcut(int childId, wxString *shortcut) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Returns the rectangle for this object (id = 0) or a child element (id > 0).
|
|
|
|
// rect is in screen coordinates.
|
2016-02-24 06:06:47 +00:00
|
|
|
wxAccStatus GetLocation(wxRect& rect, int elementId) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Gets the name of the specified object.
|
2016-02-24 06:06:47 +00:00
|
|
|
wxAccStatus GetName(int childId, wxString *name) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Returns a role constant.
|
2016-02-24 06:06:47 +00:00
|
|
|
wxAccStatus GetRole(int childId, wxAccRole *role) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Gets a variant representing the selected children
|
|
|
|
// of this object.
|
|
|
|
// Acceptable values:
|
|
|
|
// - a null variant (IsNull() returns TRUE)
|
|
|
|
// - a list variant (GetType() == wxT("list"))
|
|
|
|
// - an integer representing the selected child element,
|
|
|
|
// or 0 if this object is selected (GetType() == wxT("long"))
|
|
|
|
// - a "void*" pointer to a wxAccessible child object
|
2016-02-24 06:06:47 +00:00
|
|
|
wxAccStatus GetSelections(wxVariant *selections) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Returns a state constant.
|
2016-02-24 06:06:47 +00:00
|
|
|
wxAccStatus GetState(int childId, long* state) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
// Returns a localized string representing the value for the object
|
|
|
|
// or child.
|
2016-02-24 06:06:47 +00:00
|
|
|
wxAccStatus GetValue(int childId, wxString* strValue) override;
|
2010-01-23 19:44:49 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif // wxUSE_ACCESSIBILITY
|
|
|
|
|
|
|
|
#endif
|