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, Identifier 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

const Identifier mIdentifier
 
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 106 of file Grabber.h.

Constructor & Destructor Documentation

◆ Grabber()

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

Methods for Grabber.

Definition at line 54 of file Grabber.cpp.

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

◆ ~Grabber()

Grabber::~Grabber ( )
virtual

Definition at line 78 of file Grabber.cpp.

79{
80}

Member Function Documentation

◆ AcceptsFocusFromKeyboard()

bool Grabber::AcceptsFocusFromKeyboard ( ) const
inlineoverride

Definition at line 120 of file Grabber.h.

120{return false;}

◆ DrawGrabber()

void Grabber::DrawGrabber ( wxDC &  dc)
private

Definition at line 117 of file Grabber.cpp.

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

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 231 of file Grabber.cpp.

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

References mAsSpacer, and mOver.

◆ OnErase()

void Grabber::OnErase ( wxEraseEvent &  event)
protected

Definition at line 279 of file Grabber.cpp.

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

◆ OnKeyDown()

void Grabber::OnKeyDown ( wxKeyEvent &  event)
protected

Definition at line 295 of file Grabber.cpp.

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

References SendEvent().

Here is the call graph for this function:

◆ OnLeave()

void Grabber::OnLeave ( wxMouseEvent &  event)
protected

Definition at line 260 of file Grabber.cpp.

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

References mOver.

◆ OnLeftDown()

void Grabber::OnLeftDown ( wxMouseEvent &  event)
protected

Definition at line 204 of file Grabber.cpp.

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

References PushButton(), and SendEvent().

Here is the call graph for this function:

◆ OnLeftUp()

void Grabber::OnLeftUp ( wxMouseEvent &  event)
protected

Definition at line 218 of file Grabber.cpp.

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

References PushButton().

Here is the call graph for this function:

◆ OnPaint()

void Grabber::OnPaint ( wxPaintEvent &  event)
protected

Definition at line 287 of file Grabber.cpp.

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

References DrawGrabber().

Here is the call graph for this function:

◆ PushButton()

void Grabber::PushButton ( bool  state)

Definition at line 187 of file Grabber.cpp.

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

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 85 of file Grabber.cpp.

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

References mIdentifier.

Referenced by OnKeyDown(), and OnLeftDown().

Here is the caller graph for this function:

◆ SetAsSpacer()

void Grabber::SetAsSpacer ( bool  bIsSpacer)

Definition at line 99 of file Grabber.cpp.

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

References mAsSpacer.

Referenced by AdornedRulerPanel::ReCreateButtons().

Here is the caller graph for this function:

◆ SetToolTip()

void Grabber::SetToolTip ( const TranslatableString toolTip)

Definition at line 109 of file Grabber.cpp.

110{
111 wxWindow::SetToolTip( toolTip.Stripped().Translation() );
112}
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 146 of file Grabber.h.

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

◆ mIdentifier

const Identifier Grabber::mIdentifier
private

Definition at line 143 of file Grabber.h.

Referenced by SendEvent().

◆ mOver

bool Grabber::mOver
private

Definition at line 144 of file Grabber.h.

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

◆ mPressed

bool Grabber::mPressed
private

Definition at line 145 of file Grabber.h.

Referenced by DrawGrabber(), and PushButton().


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