Audacity  2.2.2
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 #include <wx/statbmp.h>
34 
38 
39 // Custom events
40 
41 DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_GRABBER_CLICKED, -1)
42 
43 class GrabberEvent final : public wxCommandEvent
44 {
45  public:
46 
47  GrabberEvent(wxEventType type = wxEVT_NULL,
48  wxWindowID winid = 0,
49  const wxPoint& pt = wxDefaultPosition,
50  bool escaping = false)
51  : wxCommandEvent(type, winid)
52  {
53  mPos = pt;
54  mEscaping = escaping;
55  }
56 
57  GrabberEvent(const GrabberEvent & event) = default;
58 
59  // Position of event (in screen coordinates)
60  const wxPoint & GetPosition() const
61  {
62  return mPos;
63  }
64 
65  void SetPosition(const wxPoint & pos)
66  {
67  mPos = pos;
68  }
69 
70  bool IsEscaping() const { return mEscaping; }
71 
72  // Clone is required by wxwidgets; implemented via copy constructor
73  wxEvent *Clone() const override
74  {
75  return safenew GrabberEvent(*this);
76  }
77 
78  protected:
79 
80  wxPoint mPos;
81  bool mEscaping {};
82 };
83 
84 typedef void (wxEvtHandler::*GrabberEventFunction)(GrabberEvent &);
85 
86 #define GrabberEventHandler(func) \
87  (wxObjectEventFunction)(wxEventFunction)wxStaticCastEvent(GrabberEventFunction, &func)
88 
89 #define EVT_GRABBER(id, fn) \
90  DECLARE_EVENT_TABLE_ENTRY(EVT_GRABBER_CLICKED, id, wxID_ANY, \
91  (wxObjectEventFunction) (wxEventFunction) (wxCommandEventFunction) \
92  wxStaticCastEvent(GrabberEventFunction, & fn), (wxObject *) NULL),
93 
94 // Specifies how wide the grabber will be
95 
96 #define grabberWidth 10
97 
98 class Grabber final : public wxWindow
99 {
100 
101  public:
102 
103  Grabber(wxWindow *parent, wxWindowID id);
104  virtual ~Grabber();
105 
106  // We don't need or want to accept focus since there's really
107  // not a need to dock/float a toolbar from the keyboard. If this
108  // changes, remove this and add the necessary keyboard movement
109  // handling.
110  // Note that AcceptsFocusFromKeyboard() rather than AcceptsFocus()
111  // is overridden so that ESC can cancel toolbar drag.
112  bool AcceptsFocusFromKeyboard() const override {return false;}
113 
114  void PushButton(bool state);
115  void SetAsSpacer( bool bIsSpacer );
116 
117  protected:
118 
119  void OnLeftDown(wxMouseEvent & event);
120  void OnEnter(wxMouseEvent & event);
121  void OnLeave(wxMouseEvent & event);
122  void OnErase(wxEraseEvent & event);
123  void OnPaint(wxPaintEvent & event);
124  void OnKeyDown(wxKeyEvent & event);
125 
126  private:
127 
128  void DrawGrabber(wxDC & dc);
129  void SendEvent(wxEventType type, const wxPoint & pos, bool escaping);
130 
131  bool mOver;
132  bool mPressed;
133  bool mAsSpacer;
134 
135  public:
136 
137  DECLARE_EVENT_TABLE()
138 };
139 
140 // Piggy back in same source file as Grabber.
141 // Audcaity Flicker-free StaticBitmap.
142 class AStaticBitmap : public wxStaticBitmap {
143  public:
144  AStaticBitmap(wxWindow *parent,
145  wxWindowID id,
146  const wxBitmap& label,
147  const wxPoint& pos = wxDefaultPosition,
148  const wxSize& size = wxDefaultSize,
149  long style = 0,
150  const wxString& name = wxStaticBitmapNameStr) :
151 
152  wxStaticBitmap(parent,
153  id,
154  label,
155  pos ,
156  size ,
157  style,
158  name )
159  {};
160  void OnErase(wxEraseEvent& event) {
161  static_cast<void>(event);
162  };
163  DECLARE_EVENT_TABLE()
164 };
165 
166 
167 
168 #endif
Grabber Class.
Definition: Grabber.h:43
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:144
virtual ~Grabber()
Definition: Grabber.cpp:80
bool mAsSpacer
Definition: Grabber.h:133
bool IsEscaping() const
Definition: Grabber.h:70
wxPoint mPos
Definition: Grabber.h:80
wxString label
Definition: Tags.cpp:727
bool mPressed
Definition: Grabber.h:132
void DrawGrabber(wxDC &dc)
Definition: Grabber.cpp:115
void OnLeave(wxMouseEvent &event)
Definition: Grabber.cpp:233
#define safenew
Definition: Audacity.h:230
wxEvent * Clone() const override
Definition: Grabber.h:73
void SendEvent(wxEventType type, const wxPoint &pos, bool escaping)
Definition: Grabber.cpp:87
GrabberEvent(wxEventType type=wxEVT_NULL, wxWindowID winid=0, const wxPoint &pt=wxDefaultPosition, bool escaping=false)
Definition: Grabber.h:47
bool AcceptsFocusFromKeyboard() const override
Definition: Grabber.h:112
Grabber(wxWindow *parent, wxWindowID id)
Methods for Grabber.
Definition: Grabber.cpp:56
void OnPaint(wxPaintEvent &event)
Definition: Grabber.cpp:250
bool mOver
Definition: Grabber.h:131
void OnEnter(wxMouseEvent &event)
Definition: Grabber.cpp:214
void SetPosition(const wxPoint &pos)
Definition: Grabber.h:65
const wxChar * name
Definition: Distortion.cpp:94
void SetAsSpacer(bool bIsSpacer)
Definition: Grabber.cpp:101
void OnLeftDown(wxMouseEvent &event)
Definition: Grabber.cpp:200
void(wxEvtHandler::* GrabberEventFunction)(GrabberEvent &)
Definition: Grabber.h:84
The widget to the left of a ToolBar that allows it to be dragged around to NEW positions.
Definition: Grabber.h:98
void OnKeyDown(wxKeyEvent &event)
Definition: Grabber.cpp:258
DECLARE_EXPORTED_EVENT_TYPE(AUDACITY_DLL_API, EVT_OPEN_AUDIO_FILE,-1)
void OnErase(wxEraseEvent &event)
Definition: Grabber.cpp:242
void OnErase(wxEraseEvent &event)
Definition: Grabber.h:160
void PushButton(bool state)
Definition: Grabber.cpp:185
const wxPoint & GetPosition() const
Definition: Grabber.h:60