Audacity 3.2.0
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
22class wxImage;
24
25class 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
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
179 bool mIsDoubleClicked {};
180
181 struct ImageArr { ImageRoll mArr[5]; };
182 std::vector<ImageArr> mImages;
183
186
187 std::unique_ptr<Listener> mListener;
188
189public:
190
191 DECLARE_EVENT_TABLE()
192};
193
194#endif
TranslatableString label
Definition: TagsEditor.cpp:163
static void OnSize(wxSizeEvent &evt)
Definition: VSTEffect.cpp:2243
static std::once_flag flag
A wxButton with mouse-over behaviour.
Definition: AButton.h:25
std::vector< ImageArr > mImages
Definition: AButton.h:182
wxRect mFocusRect
Definition: AButton.h:184
bool mUseDisabledAsDownHiliteImage
Definition: AButton.h:178
bool mButtonIsDown
Definition: AButton.h:175
bool mCursorIsInWindow
Definition: AButton.h:174
AButtonState
Definition: AButton.h:128
@ AButtonUp
Definition: AButton.h:129
@ AButtonOver
Definition: AButton.h:130
@ AButtonDown
Definition: AButton.h:131
@ AButtonOverDown
Definition: AButton.h:132
bool IsDoubleClicked() const
Definition: AButton.h:116
std::unique_ptr< bool, Resetter > TempAllowFocus
Definition: AButton.h:143
bool mIsClicking
Definition: AButton.h:176
bool mWasShiftDown
Definition: AButton.h:171
bool IsDown()
Definition: AButton.h:113
void SetButtonToggles(bool toggler)
Definition: AButton.h:119
void InteractionOver()
Definition: AButton.h:122
static bool s_AcceptsFocus
Definition: AButton.h:141
void ClearDoubleClicked()
Definition: AButton.h:117
std::unique_ptr< Listener > mListener
Definition: AButton.h:187
bool IsEnabled() const
Definition: AButton.h:85
bool mEnabled
Definition: AButton.h:177
bool AcceptsFocusFromKeyboard() const override
Definition: AButton.h:53
void Toggle()
Definition: AButton.h:123
void SetEnabled(bool state)
Definition: AButton.h:88
bool mToggle
Definition: AButton.h:164
unsigned mAlternateIdx
Definition: AButton.h:163
bool mWasControlDown
Definition: AButton.h:172
bool AcceptsFocus() const override
Definition: AButton.h:52
bool mForceFocusRect
Definition: AButton.h:185
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
Holds a msgid for the translation catalog; may also bind format arguments.