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 // No bumps in a spacer grabber.
134 if( mAsSpacer )
135 return;
136 // Calculate the bump rectangle
137 r.Deflate(2, 2);
138 if ((r.GetHeight() % 4) < 2) {
139 r.Offset(0, 1);
140 }
141
142 // 2-bar toolbars and larger get padding
143 int padding = r.GetHeight() > 32 ? 22 : 6;
144
145 // Cache
146 left = r.GetLeft();
147 right = r.GetRight();
148 top = r.GetTop();
149 bottom = r.GetBottom();
150
151 // Draw the bumps
152 if (mPressed) {
153 AColor::Light(&dc, false);
154 }
155 else {
156 dc.SetPen(wxPen(theTheme.Colour(clrGrabber), 1, wxPENSTYLE_SOLID));
157 }
158
159 for (y = top + padding; y < bottom - padding; y += 5) {
160 dc.DrawRectangle(left, y, 2, 2);
161 dc.DrawRectangle(right, y, 2, 2);
162 }
163}
static void Light(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:395
static void Medium(wxDC *dc, bool selected)
Definition: AColor.cpp:406

References ThemeBase::Colour(), AColor::Light(), mAsSpacer, AColor::Medium(), mOver, mPressed, and theTheme.

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

213{
214#if defined(__WXMAC__)
215 // Bug 2416: On Mac, we can get Enter events from grabbers other
216 // than the one being dragged. So, ignore Enter events if another
217 // window has captured the mouse.
218 if (wxWindow::GetCapture() != nullptr)
219 {
220 return;
221 }
222#endif
223
224 // Bug 1201: On Mac, unsetting and re-setting the tooltip may be needed
225 // to make it pop up when we want it.
226 const auto text = GetToolTipText();
227 UnsetToolTip();
228 wxWindow::SetToolTip(text);
229
230 if( mAsSpacer )
231 return;
232
233 // Redraw highlighted
234 mOver = true;
235 Refresh(false);
236}

References mAsSpacer, and mOver.

◆ OnErase()

void Grabber::OnErase ( wxEraseEvent &  event)
protected

Definition at line 260 of file Grabber.cpp.

261{
262 // Ignore it to prevent flashing
263}

◆ OnKeyDown()

void Grabber::OnKeyDown ( wxKeyEvent &  event)
protected

Definition at line 276 of file Grabber.cpp.

277{
278 event.Skip();
279
280 if(event.GetKeyCode() == WXK_ESCAPE) {
281 // We must not only skip this key event, but propagate it up the window
282 // hierarchy, so that ToolFrame detects it too.
283 event.ResumePropagation(wxEVENT_PROPAGATE_MAX);
284 SendEvent(EVT_GRABBER_CLICKED, wxPoint{ -1, -1 }, true);
285 }
286}
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 241 of file Grabber.cpp.

242{
243#if defined(__WXMAC__)
244 // Bug 2416: On Mac, we can get Leave events from grabbers other
245 // than the one being dragged. So, ignore Leave events if another
246 // window has captured the mouse.
247 if (wxWindow::GetCapture() != nullptr)
248 {
249 return;
250 }
251#endif
252
253 if (!GetCapture()) {
254 // Redraw plain
255 mOver = false;
256 Refresh(false);
257 }
258}

References mOver.

◆ OnLeftDown()

void Grabber::OnLeftDown ( wxMouseEvent &  event)
protected

Definition at line 185 of file Grabber.cpp.

186{
187 // Button should be drawn pushed
188 PushButton(true);
189
190 // Notify parent
191 SendEvent(EVT_GRABBER_CLICKED, event.GetPosition(), false);
192
193 event.Skip();
194}
void PushButton(bool state)
Definition: Grabber.cpp:168

References PushButton(), and SendEvent().

Here is the call graph for this function:

◆ OnLeftUp()

void Grabber::OnLeftUp ( wxMouseEvent &  event)
protected

Definition at line 199 of file Grabber.cpp.

200{
201 // Normally, "left up" events are handled by the ToolManager::OnMouse() method
202 // but, if the user double clicks a grabber, the "left up" event will come here
203 // instead, so just "unpush" the button.
204 PushButton(false);
205
206 event.Skip();
207}

References PushButton().

Here is the call graph for this function:

◆ OnPaint()

void Grabber::OnPaint ( wxPaintEvent &  event)
protected

Definition at line 268 of file Grabber.cpp.

269{
270 wxPaintDC dc(this);
271
272 // Redraw the grabber
273 DrawGrabber(dc);
274}
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 168 of file Grabber.cpp.

169{
170 if( mAsSpacer )
171 return;
172 if (!state)
173 mPressed = state;
174 wxRect r = GetRect();
175 mOver = r.Contains(ScreenToClient(wxGetMousePosition()));
176
177 // Redraw button
178 mPressed = state;
179 Refresh(false);
180}

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.

◆ 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: