Audacity 3.2.0
Grabber.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Grabber.cpp
6
7 Leland Lucius
8
9*******************************************************************//*******************************************************************//*******************************************************************//**********************************************************************/
28
29#ifndef __AUDACITY_WIDGETS_GRABBER__
30#define __AUDACITY_WIDGETS_GRABBER__
31
32
33
34#include <wx/defs.h>
35#include <wx/statbmp.h> // to inherit
36
38
42
43// Custom events
44
45DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_GRABBER_CLICKED, -1)
46
47class GrabberEvent final : public wxCommandEvent
48{
49 public:
50
51 GrabberEvent(wxEventType type = wxEVT_NULL,
52 wxWindowID winid = 0,
53 const wxPoint& pt = wxDefaultPosition,
54 bool escaping = false)
55 : wxCommandEvent(type, winid)
56 {
57 mPos = pt;
58 mEscaping = escaping;
59 }
60
61 GrabberEvent(const GrabberEvent & event) = default;
62
63 // Position of event (in screen coordinates)
64 const wxPoint & GetPosition() const
65 {
66 return mPos;
67 }
68
69 void SetPosition(const wxPoint & pos)
70 {
71 mPos = pos;
72 }
73
74 bool IsEscaping() const { return mEscaping; }
75
76 // Clone is required by wxwidgets; implemented via copy constructor
77 wxEvent *Clone() const override
78 {
79 return safenew GrabberEvent(*this);
80 }
81
82 protected:
83
84 wxPoint mPos;
85 bool mEscaping {};
86};
87
88typedef void (wxEvtHandler::*GrabberEventFunction)(GrabberEvent &);
89
90#define GrabberEventHandler(func) \
91 (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(GrabberEventFunction, &func)
92
93#define EVT_GRABBER(id, fn) \
94 DECLARE_EVENT_TABLE_ENTRY(EVT_GRABBER_CLICKED, id, wxID_ANY, \
95 (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) \
96 wxStaticCastEvent(GrabberEventFunction, & fn), (wxObject *) NULL),
97
98// Specifies how wide the grabber will be
99
100#define grabberWidth 10
101
102class AUDACITY_DLL_API Grabber final : public wxWindow
103{
104
105 public:
106
107 Grabber(wxWindow *parent, wxWindowID id);
108 virtual ~Grabber();
109
110 // We don't need or want to accept focus since there's really
111 // not a need to dock/float a toolbar from the keyboard. If this
112 // changes, remove this and add the necessary keyboard movement
113 // handling.
114 // Note that AcceptsFocusFromKeyboard() rather than AcceptsFocus()
115 // is overridden so that ESC can cancel toolbar drag.
116 bool AcceptsFocusFromKeyboard() const override {return false;}
117
118 void PushButton(bool state);
119 void SetAsSpacer( bool bIsSpacer );
120
121 // overload and hide the inherited function that takes naked wxString:
122 void SetToolTip(const TranslatableString &toolTip);
123
124 protected:
125
126 void OnLeftDown(wxMouseEvent & event);
127 void OnLeftUp(wxMouseEvent & event);
128 void OnEnter(wxMouseEvent & event);
129 void OnLeave(wxMouseEvent & event);
130 void OnErase(wxEraseEvent & event);
131 void OnPaint(wxPaintEvent & event);
132 void OnKeyDown(wxKeyEvent & event);
133
134 private:
135
136 void DrawGrabber(wxDC & dc);
137 void SendEvent(wxEventType type, const wxPoint & pos, bool escaping);
138
139 bool mOver;
142
143 public:
144
145 DECLARE_EVENT_TABLE()
146};
147
148// Piggy back in same source file as Grabber.
149// Audacity Flicker-free StaticBitmap.
150class AUDACITY_DLL_API AStaticBitmap : public wxStaticBitmap {
151 public:
152 AStaticBitmap(wxWindow *parent,
153 wxWindowID id,
154 const wxBitmap& label,
155 const wxPoint& pos = wxDefaultPosition,
156 const wxSize& size = wxDefaultSize,
157 long style = 0,
158 const wxString& name = wxStaticBitmapNameStr) :
159
160 wxStaticBitmap(parent,
161 id,
162 label,
163 pos ,
164 size ,
165 style,
166 name )
167 {};
168 void OnErase(wxEraseEvent& event) {
169 static_cast<void>(event);
170 };
171 DECLARE_EVENT_TABLE()
172};
173
174
175
176#endif
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, wxEVT_APP_COMMAND_RECEIVED, -1)
const TranslatableString name
Definition: Distortion.cpp:82
void(wxEvtHandler::* GrabberEventFunction)(GrabberEvent &)
Definition: Grabber.h:88
#define safenew
Definition: MemoryX.h:10
TranslatableString label
Definition: TagsEditor.cpp:163
int id
A widget for bitmaps which ignores the erase event for flicker-free use.
Definition: Grabber.h:150
AStaticBitmap(wxWindow *parent, wxWindowID id, const wxBitmap &label, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=0, const wxString &name=wxStaticBitmapNameStr)
Definition: Grabber.h:152
void OnErase(wxEraseEvent &event)
Definition: Grabber.h:168
Grabber Class.
Definition: Grabber.h:48
const wxPoint & GetPosition() const
Definition: Grabber.h:64
void SetPosition(const wxPoint &pos)
Definition: Grabber.h:69
GrabberEvent(wxEventType type=wxEVT_NULL, wxWindowID winid=0, const wxPoint &pt=wxDefaultPosition, bool escaping=false)
Definition: Grabber.h:51
wxPoint mPos
Definition: Grabber.h:84
GrabberEvent(const GrabberEvent &event)=default
bool IsEscaping() const
Definition: Grabber.h:74
wxEvent * Clone() const override
Definition: Grabber.h:77
The widget to the left of a ToolBar that allows it to be dragged around to NEW positions.
Definition: Grabber.h:103
bool mAsSpacer
Definition: Grabber.h:141
bool mOver
Definition: Grabber.h:139
bool AcceptsFocusFromKeyboard() const override
Definition: Grabber.h:116
bool mPressed
Definition: Grabber.h:140
Holds a msgid for the translation catalog; may also bind format arguments.