2010-01-23 19:44:49 +00:00
|
|
|
/**********************************************************************
|
|
|
|
|
|
|
|
Audacity: A Digital Audio Editor
|
|
|
|
|
|
|
|
AButton.h
|
|
|
|
|
|
|
|
Dominic Mazzoni
|
|
|
|
|
|
|
|
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
#ifndef __AUDACITY_BUTTON__
|
|
|
|
#define __AUDACITY_BUTTON__
|
|
|
|
|
2014-11-29 17:22:05 +00:00
|
|
|
#include <vector>
|
|
|
|
|
2019-03-23 18:28:37 +00:00
|
|
|
#include <wx/setup.h> // for wxUSE_* macros
|
2019-03-30 19:06:57 +00:00
|
|
|
#include <wx/window.h> // to inherit
|
2019-03-18 15:47:04 +00:00
|
|
|
|
2019-03-30 19:40:10 +00:00
|
|
|
#include "ImageRoll.h" // member variable
|
2010-01-23 19:44:49 +00:00
|
|
|
|
2018-11-14 20:23:25 +00:00
|
|
|
class wxImage;
|
2019-12-15 16:49:01 +00:00
|
|
|
class TranslatableString;
|
2018-11-14 20:23:25 +00:00
|
|
|
|
2020-09-28 12:50:18 +00:00
|
|
|
class AUDACITY_DLL_API 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,
|
2017-12-14 14:39:56 +00:00
|
|
|
ImageRoll overDown,
|
2010-01-23 19:44:49 +00:00
|
|
|
ImageRoll dis,
|
|
|
|
bool toggle);
|
|
|
|
|
|
|
|
virtual ~ AButton();
|
|
|
|
|
2019-12-22 19:37:01 +00:00
|
|
|
// hide the inherited function that takes naked wxString:
|
|
|
|
void SetToolTip(const TranslatableString &toolTip);
|
2019-12-15 16:49:01 +00:00
|
|
|
|
2019-12-22 19:37:01 +00:00
|
|
|
// hide the inherited function that takes naked wxString:
|
|
|
|
void SetLabel(const TranslatableString &label);
|
|
|
|
|
2016-06-23 20:35:18 +00:00
|
|
|
bool AcceptsFocus() const override { return s_AcceptsFocus; }
|
2017-07-21 04:56:47 +00:00
|
|
|
bool AcceptsFocusFromKeyboard() const override { return mEnabled; }
|
2016-06-23 20:35:18 +00:00
|
|
|
|
2016-06-25 03:23:20 +00:00
|
|
|
void SetFocusFromKbd() override;
|
|
|
|
|
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,
|
2017-12-14 14:39:56 +00:00
|
|
|
ImageRoll overDown,
|
2010-01-23 19:44:49 +00:00
|
|
|
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,
|
2017-12-14 14:39:56 +00:00
|
|
|
wxImage overDown,
|
2010-01-23 19:44:49 +00:00
|
|
|
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;}
|
2017-04-09 18:07:28 +00:00
|
|
|
// When click is over and mouse has moved away, a normal button
|
|
|
|
// should pop up.
|
|
|
|
void InteractionOver(){ if( !mToggle ) PopUp();}
|
2010-01-23 19:44:49 +00:00
|
|
|
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,
|
2017-12-14 14:39:56 +00:00
|
|
|
AButtonOverDown,
|
2010-01-23 19:44:49 +00:00
|
|
|
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:
|
2016-06-25 04:06:22 +00:00
|
|
|
static TempAllowFocus TemporarilyAllowFocus();
|
2016-06-23 20:35:18 +00:00
|
|
|
|
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,
|
2017-12-14 14:39:56 +00:00
|
|
|
ImageRoll overDown,
|
2010-01-23 19:44:49 +00:00
|
|
|
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 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
|
|
|
|
2017-12-14 14:39:56 +00:00
|
|
|
struct ImageArr { ImageRoll mArr[5]; };
|
2014-11-29 17:22:05 +00:00
|
|
|
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()
|
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|