Audacity  2.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 *******************************************************************//*******************************************************************//**********************************************************************/
22 
23 #ifndef __AUDACITY_WIDGETS_GRABBER__
24 #define __AUDACITY_WIDGETS_GRABBER__
25 
26 #include "../Audacity.h"
27 
28 #include "wx/defs.h"
29 #include "wx/dc.h"
30 #include "wx/event.h"
31 #include "wx/gdicmn.h"
32 #include "wx/window.h"
33 
37 
38 // Custom events
39 
40 DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_GRABBER_CLICKED, -1)
41 
42 class GrabberEvent final : public wxCommandEvent
43 {
44  public:
45 
46  GrabberEvent(wxEventType type = wxEVT_NULL,
47  wxWindowID winid = 0,
48  const wxPoint& pt = wxDefaultPosition,
49  bool escaping = false)
50  : wxCommandEvent(type, winid)
51  {
52  mPos = pt;
53  mEscaping = escaping;
54  }
55 
56  GrabberEvent(const GrabberEvent & event) = default;
57 
58  // Position of event (in screen coordinates)
59  const wxPoint & GetPosition() const
60  {
61  return mPos;
62  }
63 
64  void SetPosition(const wxPoint & pos)
65  {
66  mPos = pos;
67  }
68 
69  bool IsEscaping() const { return mEscaping; }
70 
71  // Clone is required by wxwidgets; implemented via copy constructor
72  wxEvent *Clone() const override
73  {
74  return safenew GrabberEvent(*this);
75  }
76 
77  protected:
78 
79  wxPoint mPos;
80  bool mEscaping {};
81 };
82 
83 typedef void (wxEvtHandler::*GrabberEventFunction)(GrabberEvent &);
84 
85 #define GrabberEventHandler(func) \
86  (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(GrabberEventFunction, &func)
87 
88 #define EVT_GRABBER(id, fn) \
89  DECLARE_EVENT_TABLE_ENTRY(EVT_GRABBER_CLICKED, id, wxID_ANY, \
90  (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) \
91  wxStaticCastEvent(GrabberEventFunction, & fn), (wxObject *) NULL),
92 
93 // Specifies how wide the grabber will be
94 
95 #define grabberWidth 10
96 
97 class Grabber final : public wxWindow
98 {
99 
100  public:
101 
102  Grabber(wxWindow *parent, wxWindowID id);
103  virtual ~Grabber();
104 
105  // We don't need or want to accept focus since there's really
106  // not a need to dock/float a toolbar from the keyboard. If this
107  // changes, remove this and add the necessary keyboard movement
108  // handling.
109  // Note that AcceptsFocusFromKeyboard() rather than AcceptsFocus()
110  // is overridden so that ESC can cancel toolbar drag.
111  bool AcceptsFocusFromKeyboard() const override {return false;}
112 
113  void PushButton(bool state);
114  void SetAsSpacer( bool bIsSpacer );
115 
116  protected:
117 
118  void OnLeftDown(wxMouseEvent & event);
119  void OnEnter(wxMouseEvent & event);
120  void OnLeave(wxMouseEvent & event);
121  void OnPaint(wxPaintEvent & event);
122  void OnKeyDown(wxKeyEvent & event);
123 
124  private:
125 
126  void DrawGrabber(wxDC & dc);
127  void SendEvent(wxEventType type, const wxPoint & pos, bool escaping);
128 
129  bool mOver;
130  bool mPressed;
131  bool mAsSpacer;
132 
133  public:
134 
135  DECLARE_EVENT_TABLE()
136 };
137 
138 #endif
Grabber Class.
Definition: Grabber.h:42
virtual ~Grabber()
Definition: Grabber.cpp:78
bool mAsSpacer
Definition: Grabber.h:131
bool IsEscaping() const
Definition: Grabber.h:69
wxPoint mPos
Definition: Grabber.h:79
bool mPressed
Definition: Grabber.h:130
void DrawGrabber(wxDC &dc)
Definition: Grabber.cpp:113
void OnLeave(wxMouseEvent &event)
Definition: Grabber.cpp:231
#define safenew
Definition: Audacity.h:230
wxEvent * Clone() const override
Definition: Grabber.h:72
void SendEvent(wxEventType type, const wxPoint &pos, bool escaping)
Definition: Grabber.cpp:85
GrabberEvent(wxEventType type=wxEVT_NULL, wxWindowID winid=0, const wxPoint &pt=wxDefaultPosition, bool escaping=false)
Definition: Grabber.h:46
bool AcceptsFocusFromKeyboard() const override
Definition: Grabber.h:111
Grabber(wxWindow *parent, wxWindowID id)
Methods for Grabber.
Definition: Grabber.cpp:54
void OnPaint(wxPaintEvent &event)
Definition: Grabber.cpp:243
bool mOver
Definition: Grabber.h:129
void OnEnter(wxMouseEvent &event)
Definition: Grabber.cpp:212
void SetPosition(const wxPoint &pos)
Definition: Grabber.h:64
void SetAsSpacer(bool bIsSpacer)
Definition: Grabber.cpp:99
void OnLeftDown(wxMouseEvent &event)
Definition: Grabber.cpp:198
void(wxEvtHandler::* GrabberEventFunction)(GrabberEvent &)
Definition: Grabber.h:83
The widget to the left of a ToolBar that allows it to be dragged around to NEW positions.
Definition: Grabber.h:97
void OnKeyDown(wxKeyEvent &event)
Definition: Grabber.cpp:251
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_OPEN_AUDIO_FILE,-1)
void PushButton(bool state)
Definition: Grabber.cpp:183
const wxPoint & GetPosition() const
Definition: Grabber.h:59