Audacity 3.2.0
Public Member Functions | Protected Member Functions | Private Member Functions | Private Attributes | List of all members
Grabber Class Referencefinal

The widget to the left of a ToolBar that allows it to be dragged around to NEW positions. More...

#include <Grabber.h>

Inheritance diagram for Grabber:
[legend]
Collaboration diagram for Grabber:
[legend]

Public Member Functions

 Grabber (wxWindow *parent, wxWindowID id)
 Methods for Grabber. More...
 
virtual ~Grabber ()
 
bool AcceptsFocusFromKeyboard () const override
 
void PushButton (bool state)
 
void SetAsSpacer (bool bIsSpacer)
 
void SetToolTip (const TranslatableString &toolTip)
 

Protected Member Functions

void OnLeftDown (wxMouseEvent &event)
 
void OnLeftUp (wxMouseEvent &event)
 
void OnEnter (wxMouseEvent &event)
 
void OnLeave (wxMouseEvent &event)
 
void OnErase (wxEraseEvent &event)
 
void OnPaint (wxPaintEvent &event)
 
void OnKeyDown (wxKeyEvent &event)
 

Private Member Functions

void DrawGrabber (wxDC &dc)
 
void SendEvent (wxEventType type, const wxPoint &pos, bool escaping)
 

Private Attributes

bool mOver
 
bool mPressed
 
bool mAsSpacer
 

Detailed Description

The widget to the left of a ToolBar that allows it to be dragged around to NEW positions.

Definition at line 102 of file Grabber.h.

Constructor & Destructor Documentation

◆ Grabber()

Grabber::Grabber ( wxWindow *  parent,
wxWindowID  id 
)

Methods for Grabber.

Definition at line 56 of file Grabber.cpp.

57: wxWindow(parent,
58 id,
59 wxDefaultPosition,
60 wxSize(grabberWidth, 27),
61 wxFULL_REPAINT_ON_RESIZE)
62{
63 mOver = false;
64 mPressed = false;
65 mAsSpacer = false;
66 SetBackgroundColour( theTheme.Colour( clrMedium ) );
67
68 /* i18n-hint: A 'Grabber' is a region you can click and drag on
69 It's used to drag a track around (when in multi-tool mode) rather
70 than requiring that you use the drag tool. It's shown as a series
71 of horizontal bumps */
72 SetLabel(_("Grabber"));
73 SetName(_("Grabber"));
74}
#define grabberWidth
Definition: Grabber.h:100
#define _(s)
Definition: Internat.h:75
THEME_API Theme theTheme
Definition: Theme.cpp:82
bool mAsSpacer
Definition: Grabber.h:141
bool mOver
Definition: Grabber.h:139
bool mPressed
Definition: Grabber.h:140
wxColour & Colour(int iIndex)

References _, ThemeBase::Colour(), and theTheme.

Here is the call graph for this function:

◆ ~Grabber()

Grabber::~Grabber ( )
virtual

Definition at line 79 of file Grabber.cpp.

80{
81}

Member Function Documentation

◆ AcceptsFocusFromKeyboard()

bool Grabber::AcceptsFocusFromKeyboard ( ) const
inlineoverride

Definition at line 116 of file Grabber.h.

116{return false;}

◆ DrawGrabber()

void Grabber::DrawGrabber ( wxDC &  dc)
private

Definition at line 118 of file Grabber.cpp.

119{
120 wxRect r = GetRect();
121 // PaintDC positions are relative to the grabber, not the parent window.
122 // So use 0,0 as origin for draw, so that the grabber draws right if
123 // positioned in its parent at some non zero position.
124 r.SetPosition( wxPoint(0,0) );
125 int y, left, right, top, bottom;
126
127 AColor::Medium(&dc, mOver );
128 dc.DrawRectangle(r);
129
130 // HACK: We used a wider rectangle to also cover one pixel of space just to the right.
131 if( mAsSpacer )
132 r.width -= 1;
133
134#ifndef __WXMAC__
135
136 // Add a box
137 r.width -= 1;
138 r.height -= 1;
139 AColor::Bevel(dc, !mPressed, r);
140 r.width += 1;
141 r.height += 1;
142
143#endif
144
145 // No bumps in a spacer grabber.
146 if( mAsSpacer )
147 return;
148 // Calculate the bump rectangle
149 r.Deflate(3, 3);
150 if ((r.GetHeight() % 4) < 2) {
151 r.Offset(0, 1);
152 }
153
154 // Cache
155 left = r.GetLeft();
156 right = r.GetRight();
157 top = r.GetTop();
158 bottom = r.GetBottom();
159
160 // Draw the raised bumps
161 if (mPressed) {
162 AColor::Dark(&dc, false);
163 }
164 else {
165 AColor::Light(&dc, false);
166 }
167
168 for (y = top; y < bottom; y += 4) {
169 AColor::Line(dc, left, y, right, y);
170 }
171
172 // Draw the pushed bumps
173 if (mPressed) {
174 AColor::Light(&dc, false);
175 }
176 else {
177 AColor::Dark(&dc, false);
178 }
179
180 for (y = top + 1; y <= bottom; y += 4) {
181 AColor::Line(dc, left, y, right, y);
182 }
183}
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:187
static void Bevel(wxDC &dc, bool up, const wxRect &r)
Definition: AColor.cpp:266
static void Light(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:390
static void Dark(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:420
static void Medium(wxDC *dc, bool selected)
Definition: AColor.cpp:401

References AColor::Bevel(), AColor::Dark(), AColor::Light(), AColor::Line(), mAsSpacer, AColor::Medium(), mOver, and mPressed.

Referenced by OnPaint().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnEnter()

void Grabber::OnEnter ( wxMouseEvent &  event)
protected

Definition at line 232 of file Grabber.cpp.

233{
234#if defined(__WXMAC__)
235 // Bug 2416: On Mac, we can get Enter events from grabbers other
236 // than the one being dragged. So, ignore Enter events if another
237 // window has captured the mouse.
238 if (wxWindow::GetCapture() != nullptr)
239 {
240 return;
241 }
242#endif
243
244 // Bug 1201: On Mac, unsetting and re-setting the tooltip may be needed
245 // to make it pop up when we want it.
246 const auto text = GetToolTipText();
247 UnsetToolTip();
248 wxWindow::SetToolTip(text);
249
250 if( mAsSpacer )
251 return;
252
253 // Redraw highlighted
254 mOver = true;
255 Refresh(false);
256}

References mAsSpacer, and mOver.

◆ OnErase()

void Grabber::OnErase ( wxEraseEvent &  event)
protected

Definition at line 280 of file Grabber.cpp.

281{
282 // Ignore it to prevent flashing
283}

◆ OnKeyDown()

void Grabber::OnKeyDown ( wxKeyEvent &  event)
protected

Definition at line 296 of file Grabber.cpp.

297{
298 event.Skip();
299
300 if(event.GetKeyCode() == WXK_ESCAPE) {
301 // We must not only skip this key event, but propagate it up the window
302 // hierarchy, so that ToolFrame detects it too.
303 event.ResumePropagation(wxEVENT_PROPAGATE_MAX);
304 SendEvent(EVT_GRABBER_CLICKED, wxPoint{ -1, -1 }, true);
305 }
306}
void SendEvent(wxEventType type, const wxPoint &pos, bool escaping)
Definition: Grabber.cpp:86

References SendEvent().

Here is the call graph for this function:

◆ OnLeave()

void Grabber::OnLeave ( wxMouseEvent &  event)
protected

Definition at line 261 of file Grabber.cpp.

262{
263#if defined(__WXMAC__)
264 // Bug 2416: On Mac, we can get Leave events from grabbers other
265 // than the one being dragged. So, ignore Leave events if another
266 // window has captured the mouse.
267 if (wxWindow::GetCapture() != nullptr)
268 {
269 return;
270 }
271#endif
272
273 if (!GetCapture()) {
274 // Redraw plain
275 mOver = false;
276 Refresh(false);
277 }
278}

References mOver.

◆ OnLeftDown()

void Grabber::OnLeftDown ( wxMouseEvent &  event)
protected

Definition at line 205 of file Grabber.cpp.

206{
207 // Button should be drawn pushed
208 PushButton(true);
209
210 // Notify parent
211 SendEvent(EVT_GRABBER_CLICKED, event.GetPosition(), false);
212
213 event.Skip();
214}
void PushButton(bool state)
Definition: Grabber.cpp:188

References PushButton(), and SendEvent().

Here is the call graph for this function:

◆ OnLeftUp()

void Grabber::OnLeftUp ( wxMouseEvent &  event)
protected

Definition at line 219 of file Grabber.cpp.

220{
221 // Normally, "left up" events are handled by the ToolManager::OnMouse() method
222 // but, if the user double clicks a grabber, the "left up" event will come here
223 // instead, so just "unpush" the button.
224 PushButton(false);
225
226 event.Skip();
227}

References PushButton().

Here is the call graph for this function:

◆ OnPaint()

void Grabber::OnPaint ( wxPaintEvent &  event)
protected

Definition at line 288 of file Grabber.cpp.

289{
290 wxPaintDC dc(this);
291
292 // Redraw the grabber
293 DrawGrabber(dc);
294}
void DrawGrabber(wxDC &dc)
Definition: Grabber.cpp:118

References DrawGrabber().

Here is the call graph for this function:

◆ PushButton()

void Grabber::PushButton ( bool  state)

Definition at line 188 of file Grabber.cpp.

189{
190 if( mAsSpacer )
191 return;
192 if (!state)
193 mPressed = state;
194 wxRect r = GetRect();
195 mOver = r.Contains(ScreenToClient(wxGetMousePosition()));
196
197 // Redraw button
198 mPressed = state;
199 Refresh(false);
200}

References mAsSpacer, mOver, and mPressed.

Referenced by OnLeftDown(), OnLeftUp(), and ToolBar::SetDocked().

Here is the caller graph for this function:

◆ SendEvent()

void Grabber::SendEvent ( wxEventType  type,
const wxPoint &  pos,
bool  escaping 
)
private

Definition at line 86 of file Grabber.cpp.

87{
88 wxWindow *parent = GetParent();
89
90 // Initialize event and convert mouse coordinates to screen space
91 GrabberEvent e(type, GetId(), parent->ClientToScreen(pos), escaping);
92
93 // Set the object of our desire
94 e.SetEventObject(parent);
95
96 // Queue the event
97 parent->GetEventHandler()->AddPendingEvent(e);
98}
Grabber Class.
Definition: Grabber.h:48

Referenced by OnKeyDown(), and OnLeftDown().

Here is the caller graph for this function:

◆ SetAsSpacer()

void Grabber::SetAsSpacer ( bool  bIsSpacer)

Definition at line 100 of file Grabber.cpp.

100 {
101 if( mAsSpacer != bIsSpacer ){
102 // HACK: Use a wider rectangle to also cover one pixel of space just to the right.
103 wxSize siz = GetSize();
104 siz.IncBy( bIsSpacer ? 1:-1, 0 );
105 SetSize( siz );
106 }
107 mAsSpacer = bIsSpacer;
108};

References mAsSpacer.

Referenced by AdornedRulerPanel::ReCreateButtons().

Here is the caller graph for this function:

◆ SetToolTip()

void Grabber::SetToolTip ( const TranslatableString toolTip)

Definition at line 110 of file Grabber.cpp.

111{
112 wxWindow::SetToolTip( toolTip.Stripped().Translation() );
113}
wxString Translation() const
TranslatableString Stripped(unsigned options=MenuCodes) const
non-mutating, constructs another TranslatableString object

References TranslatableString::Stripped(), and TranslatableString::Translation().

Referenced by ToolBar::SetDocked(), and ToolBar::UpdatePrefs().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mAsSpacer

bool Grabber::mAsSpacer
private

Definition at line 141 of file Grabber.h.

Referenced by DrawGrabber(), OnEnter(), PushButton(), and SetAsSpacer().

◆ mOver

bool Grabber::mOver
private

Definition at line 139 of file Grabber.h.

Referenced by DrawGrabber(), OnEnter(), OnLeave(), and PushButton().

◆ mPressed

bool Grabber::mPressed
private

Definition at line 140 of file Grabber.h.

Referenced by DrawGrabber(), and PushButton().


The documentation for this class was generated from the following files: