Audacity  3.0.3
AButton.h
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  AButton.h
6 
7  Dominic Mazzoni
8 
9 
10 **********************************************************************/
11 
12 #ifndef __AUDACITY_BUTTON__
13 #define __AUDACITY_BUTTON__
14 
15 #include <vector>
16 
17 #include <wx/setup.h> // for wxUSE_* macros
18 #include <wx/window.h> // to inherit
19 
20 #include "ImageRoll.h" // member variable
21 
22 class wxImage;
23 class TranslatableString;
24 
25 class AUDACITY_DLL_API AButton final : public wxWindow {
26  friend class AButtonAx;
27  class Listener;
28 
29  public:
30 
31  // Construct button, specifying images (button up, highlight, button down,
32  // and disabled) for the default state
33  AButton(wxWindow * parent,
34  wxWindowID id,
35  const wxPoint & pos,
36  const wxSize & size,
37  ImageRoll up,
38  ImageRoll over,
39  ImageRoll down,
40  ImageRoll overDown,
41  ImageRoll dis,
42  bool toggle);
43 
44  virtual ~ AButton();
45 
46  // hide the inherited function that takes naked wxString:
47  void SetToolTip(const TranslatableString &toolTip);
48 
49  // hide the inherited function that takes naked wxString:
50  void SetLabel(const TranslatableString &label);
51 
52  bool AcceptsFocus() const override { return s_AcceptsFocus; }
53  bool AcceptsFocusFromKeyboard() const override { return mEnabled; }
54 
55  void SetFocusFromKbd() override;
56 
57  // Associate a set of four images (button up, highlight, button down,
58  // disabled) with one nondefault state of the button
59  void SetAlternateImages(unsigned idx,
60  ImageRoll up,
61  ImageRoll over,
62  ImageRoll down,
63  ImageRoll overDown,
64  ImageRoll dis);
65 
66  // Associate a set of four images (button up, highlight, button down,
67  // disabled) with one nondefault state of the button
68  void SetAlternateImages(unsigned idx,
69  wxImage up,
70  wxImage over,
71  wxImage down,
72  wxImage overDown,
73  wxImage dis);
74 
75  // Choose state of the button
76  void SetAlternateIdx(unsigned idx);
77 
78  // Make the button change appearance with the modifier keys, no matter
79  // where the mouse is:
80  // Use state 2 when CTRL is down, else 1 when SHIFT is down, else 0
81  void FollowModifierKeys();
82 
83  void SetFocusRect(wxRect & r);
84 
85  bool IsEnabled() const { return mEnabled; }
86  void Disable();
87  void Enable();
88  void SetEnabled(bool state) {
89  state ? Enable() : Disable();
90  }
91 
92  void PushDown();
93  void PopUp();
94 
95  void OnErase(wxEraseEvent & event);
96  void OnPaint(wxPaintEvent & event);
97  void OnSize(wxSizeEvent & event);
98  void OnMouseEvent(wxMouseEvent & event);
99 
100  // Update the status bar message if the pointer is in the button.
101  // Else do nothing.
102  void UpdateStatus();
103 
104  void OnCaptureLost(wxMouseCaptureLostEvent & event);
105  void OnKeyDown(wxKeyEvent & event);
106  void OnSetFocus(wxFocusEvent & event);
107  void OnKillFocus(wxFocusEvent & event);
108 
109  bool WasShiftDown(); // returns true if shift was held down
110  // the last time the button was clicked
111  bool WasControlDown(); // returns true if control was held down
112  // the last time the button was clicked
113  bool IsDown(){ return mButtonIsDown;}
114 
115  // Double click is detected, but not automatically cleared.
116  bool IsDoubleClicked() const { return mIsDoubleClicked; }
117  void ClearDoubleClicked() { mIsDoubleClicked = false; }
118 
119  void SetButtonToggles( bool toggler ){ mToggle = toggler;}
120  // When click is over and mouse has moved away, a normal button
121  // should pop up.
122  void InteractionOver(){ if( !mToggle ) PopUp();}
123  void Toggle(){ mButtonIsDown ? PopUp() : PushDown();}
124  void Click();
125  void SetShift(bool shift);
126  void SetControl(bool control);
127 
133  AButtonDis
134  };
135 
136  AButtonState GetState();
137 
138  void UseDisabledAsDownHiliteImage(bool flag);
139 
140  private:
141  static bool s_AcceptsFocus;
142  struct Resetter { void operator () (bool *p) const { if(p) *p = false; } };
143  using TempAllowFocus = std::unique_ptr<bool, Resetter>;
144 
145  public:
146  static TempAllowFocus TemporarilyAllowFocus();
147 
148  private:
149 
150  bool HasAlternateImages(unsigned idx);
151 
152  void Init(wxWindow * parent,
153  wxWindowID id,
154  const wxPoint & pos,
155  const wxSize & size,
156  ImageRoll up,
157  ImageRoll over,
158  ImageRoll down,
159  ImageRoll overDown,
160  ImageRoll dis,
161  bool toggle);
162 
163  unsigned mAlternateIdx;
164  bool mToggle; // This bool, if true, makes the button able to
165  // process events when it is in the down state, and
166  // moving to the opposite state when it is clicked.
167  // It is used for the Pause button, and possibly
168  // others. If false, it (should) behave just like
169  // a standard button.
170 
173 
177  bool mEnabled;
179  bool mIsDoubleClicked {};
180 
181  struct ImageArr { ImageRoll mArr[5]; };
182  std::vector<ImageArr> mImages;
183 
184  wxRect mFocusRect;
186 
187  std::unique_ptr<Listener> mListener;
188 
189 public:
190 
191  DECLARE_EVENT_TABLE()
192 };
193 
194 #endif
size
size_t size
Definition: ffmpeg-2.3.6-single-header.h:412
Init
Definition: ModuleManager.h:152
TranslatableString
Holds a msgid for the translation catalog; may also bind format arguments.
Definition: TranslatableString.h:32
AButton::AButtonOverDown
@ AButtonOverDown
Definition: AButton.h:132
AButton::InteractionOver
void InteractionOver()
Definition: AButton.h:122
AButton::mUseDisabledAsDownHiliteImage
bool mUseDisabledAsDownHiliteImage
Definition: AButton.h:178
flag
static std::once_flag flag
Definition: WaveformView.cpp:1119
AButton::Toggle
void Toggle()
Definition: AButton.h:123
AButton::mButtonIsDown
bool mButtonIsDown
Definition: AButton.h:175
AButton
A wxButton with mouse-over behaviour.
Definition: AButton.h:25
AButton::IsEnabled
bool IsEnabled() const
Definition: AButton.h:85
AButton::AButtonUp
@ AButtonUp
Definition: AButton.h:129
AButton::TempAllowFocus
std::unique_ptr< bool, Resetter > TempAllowFocus
Definition: AButton.h:143
AButton::mWasShiftDown
bool mWasShiftDown
Definition: AButton.h:171
AButton::mAlternateIdx
unsigned mAlternateIdx
Definition: AButton.h:163
AButton::mToggle
bool mToggle
Definition: AButton.h:164
AButton::AButtonOver
@ AButtonOver
Definition: AButton.h:130
OnSize
static void OnSize(wxSizeEvent &evt)
Definition: VSTEffect.cpp:2784
AButton::mImages
std::vector< ImageArr > mImages
Definition: AButton.h:182
AButton::AcceptsFocusFromKeyboard
bool AcceptsFocusFromKeyboard() const override
Definition: AButton.h:53
AButton::AButtonDown
@ AButtonDown
Definition: AButton.h:131
AButton::SetEnabled
void SetEnabled(bool state)
Definition: AButton.h:88
ImageRoll.h
label
TranslatableString label
Definition: Tags.cpp:756
ImageRoll
An ImageRoll is an image that can be expanded to an arbitrary size; it is made up of both fixed piece...
Definition: ImageRoll.h:28
AButton::AcceptsFocus
bool AcceptsFocus() const override
Definition: AButton.h:52
AButton::mFocusRect
wxRect mFocusRect
Definition: AButton.h:184
AButton::mIsClicking
bool mIsClicking
Definition: AButton.h:176
AButton::s_AcceptsFocus
static bool s_AcceptsFocus
Definition: AButton.h:141
AButton::mListener
std::unique_ptr< Listener > mListener
Definition: AButton.h:187
AButton::SetButtonToggles
void SetButtonToggles(bool toggler)
Definition: AButton.h:119
AButton::AButtonState
AButtonState
Definition: AButton.h:128
AButton::mEnabled
bool mEnabled
Definition: AButton.h:177
AButton::mWasControlDown
bool mWasControlDown
Definition: AButton.h:172
AButton::IsDown
bool IsDown()
Definition: AButton.h:113
AButton::mForceFocusRect
bool mForceFocusRect
Definition: AButton.h:185
AButton::Listener
Definition: AButton.cpp:136
AButton::ImageArr
Definition: AButton.h:181
AButton::mCursorIsInWindow
bool mCursorIsInWindow
Definition: AButton.h:174
AButton::~ AButton
virtual ~ AButton()
AButton::IsDoubleClicked
bool IsDoubleClicked() const
Definition: AButton.h:116
AButton::Resetter
Definition: AButton.h:142
AButton::ClearDoubleClicked
void ClearDoubleClicked()
Definition: AButton.h:117