Audacity  2.2.2
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:

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)
 

Protected Member Functions

void OnLeftDown (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 98 of file Grabber.h.

Constructor & Destructor Documentation

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

Methods for Grabber.

Definition at line 56 of file Grabber.cpp.

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

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 
73  SetLabel(_("Grabber"));
74  SetName(_("Grabber"));
75 }
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
bool mAsSpacer
Definition: Grabber.h:133
bool mPressed
Definition: Grabber.h:132
#define grabberWidth
Definition: Grabber.h:96
bool mOver
Definition: Grabber.h:131
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
Grabber::~Grabber ( )
virtual

Definition at line 80 of file Grabber.cpp.

81 {
82 }

Member Function Documentation

bool Grabber::AcceptsFocusFromKeyboard ( ) const
inlineoverride

Definition at line 112 of file Grabber.h.

112 {return false;}
void Grabber::DrawGrabber ( wxDC &  dc)
private

Definition at line 115 of file Grabber.cpp.

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

Referenced by OnPaint().

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

Definition at line 214 of file Grabber.cpp.

References mAsSpacer, and mOver.

215 {
216  // Bug 1201: On Mac, unsetting and re-setting the tooltip may be needed
217  // to make it pop up when we want it.
218  const auto text = GetToolTipText();
219  UnsetToolTip();
220  SetToolTip(text);
221 
222  if( mAsSpacer )
223  return;
224 
225  // Redraw highlighted
226  mOver = true;
227  Refresh(false);
228 }
bool mAsSpacer
Definition: Grabber.h:133
bool mOver
Definition: Grabber.h:131
void Grabber::OnErase ( wxEraseEvent &  event)
protected

Definition at line 242 of file Grabber.cpp.

243 {
244  // Ignore it to prevent flashing
245 }
void Grabber::OnKeyDown ( wxKeyEvent &  event)
protected

Definition at line 258 of file Grabber.cpp.

References SendEvent().

259 {
260  event.Skip();
261 
262  if(event.GetKeyCode() == WXK_ESCAPE) {
263  // We must not only skip this key event, but propagate it up the window
264  // hierarchy, so that ToolFrame detects it too.
265  event.ResumePropagation(wxEVENT_PROPAGATE_MAX);
266  SendEvent(EVT_GRABBER_CLICKED, wxPoint{ -1, -1 }, true);
267  }
268 }
void SendEvent(wxEventType type, const wxPoint &pos, bool escaping)
Definition: Grabber.cpp:87
void Grabber::OnLeave ( wxMouseEvent &  event)
protected

Definition at line 233 of file Grabber.cpp.

References mOver.

234 {
235  if (!GetCapture()) {
236  // Redraw plain
237  mOver = false;
238  Refresh(false);
239  }
240 }
bool mOver
Definition: Grabber.h:131
void Grabber::OnLeftDown ( wxMouseEvent &  event)
protected

Definition at line 200 of file Grabber.cpp.

References PushButton(), and SendEvent().

201 {
202  // Button should be drawn pushed
203  PushButton(true);
204 
205  // Notify parent
206  SendEvent(EVT_GRABBER_CLICKED, event.GetPosition(), false);
207 
208  event.Skip();
209 }
void SendEvent(wxEventType type, const wxPoint &pos, bool escaping)
Definition: Grabber.cpp:87
void PushButton(bool state)
Definition: Grabber.cpp:185
void Grabber::OnPaint ( wxPaintEvent &  event)
protected

Definition at line 250 of file Grabber.cpp.

References DrawGrabber().

251 {
252  wxPaintDC dc(this);
253 
254  // Redraw the grabber
255  DrawGrabber(dc);
256 }
void DrawGrabber(wxDC &dc)
Definition: Grabber.cpp:115
void Grabber::PushButton ( bool  state)

Definition at line 185 of file Grabber.cpp.

References mAsSpacer, mOver, and mPressed.

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

186 {
187  if( mAsSpacer )
188  return;
189  wxRect r = GetRect();
190  mOver = r.Contains(ScreenToClient(wxGetMousePosition()));
191 
192  // Redraw button
193  mPressed = state;
194  Refresh(false);
195 }
bool mAsSpacer
Definition: Grabber.h:133
bool mPressed
Definition: Grabber.h:132
bool mOver
Definition: Grabber.h:131
void Grabber::SendEvent ( wxEventType  type,
const wxPoint &  pos,
bool  escaping 
)
private

Definition at line 87 of file Grabber.cpp.

Referenced by OnKeyDown(), and OnLeftDown().

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

Definition at line 101 of file Grabber.cpp.

References mAsSpacer.

Referenced by AdornedRulerPanel::ReCreateButtons().

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

Member Data Documentation

bool Grabber::mAsSpacer
private

Definition at line 133 of file Grabber.h.

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

bool Grabber::mOver
private

Definition at line 131 of file Grabber.h.

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

bool Grabber::mPressed
private

Definition at line 132 of file Grabber.h.

Referenced by DrawGrabber(), and PushButton().


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