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