Audacity  2.2.2
ToolBar.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 
3  Audacity: A Digital Audio Editor
4 
5  ToolBar.cpp
6 
7  Dominic Mazzoni
8  Shane T. Mueller
9  Leland Lucius
10 
11  See ToolBar.h for details.
12 
13 *******************************************************************//*******************************************************************//**********************************************************************/
26 
27 #include "../Audacity.h"
28 
29 // For compilers that support precompilation, includes "wx/wx.h".
30 #include <wx/wxprec.h>
31 
32 #ifndef WX_PRECOMP
33 #include <wx/defs.h>
34 #include <wx/gdicmn.h>
35 #include <wx/image.h>
36 #include <wx/intl.h>
37 #include <wx/settings.h>
38 #include <wx/sizer.h>
39 #include <wx/sysopt.h>
40 #include <wx/window.h>
41 #endif /* */
42 
43 #include "ToolBar.h"
44 #include "ToolDock.h"
45 #include "../Experimental.h"
46 
47 #include "../AllThemeResources.h"
48 #include "../AColor.h"
49 #include "../ImageManipulation.h"
50 #include "../Project.h"
51 #include "../Theme.h"
52 #include "../commands/Keyboard.h"
53 #include "../widgets/AButton.h"
54 #include "../widgets/Grabber.h"
55 #include "../Prefs.h"
56 
60 
61 //
62 // Width of the resize grab area
63 //
64 #define RWIDTH 4
65 
66 class ToolBarResizer final : public wxWindow
67 {
68 public:
70  virtual ~ToolBarResizer();
71 
72  // We don't need or want to accept focus.
73  // Note that AcceptsFocusFromKeyboard() is overriden rather than
74  // AcceptsFocus(), so that resize can be cancelled by ESC
75  bool AcceptsFocusFromKeyboard() const override {return false;}
76 
77 private:
78  void OnErase(wxEraseEvent & event);
79  void OnPaint(wxPaintEvent & event);
80  void OnLeftDown(wxMouseEvent & event);
81  void OnLeftUp(wxMouseEvent & event);
82  void OnEnter(wxMouseEvent & event);
83  void OnLeave(wxMouseEvent & event);
84  void OnMotion(wxMouseEvent & event);
85  void ResizeBar(const wxSize &size);
86  void OnCaptureLost(wxMouseCaptureLostEvent & event);
87  void OnKeyDown(wxKeyEvent &event);
88 
89 private:
91  wxPoint mResizeOffset;
92  wxSize mOrigSize;
93  wxWindow *mOrigFocus{};
94 
95  DECLARE_EVENT_TABLE()
96 };
97 
98 //
99 // Event table
100 //
101 BEGIN_EVENT_TABLE( ToolBarResizer, wxWindow )
102  EVT_ERASE_BACKGROUND( ToolBarResizer::OnErase )
103  EVT_PAINT( ToolBarResizer::OnPaint )
104  EVT_LEFT_DOWN( ToolBarResizer::OnLeftDown )
105  EVT_LEFT_UP( ToolBarResizer::OnLeftUp )
106  EVT_ENTER_WINDOW( ToolBarResizer::OnEnter )
107  EVT_LEAVE_WINDOW( ToolBarResizer::OnLeave )
108  EVT_MOTION( ToolBarResizer::OnMotion )
109  EVT_MOUSE_CAPTURE_LOST( ToolBarResizer::OnCaptureLost )
110  EVT_KEY_DOWN( ToolBarResizer::OnKeyDown )
112 
114 : wxWindow(bar, wxID_ANY, wxDefaultPosition, wxSize(RWIDTH, -1))
115 {
116  mBar = bar;
117  SetCursor( wxCURSOR_SIZEWE );
118 }
119 
121 {
122  if(HasCapture())
123  ReleaseMouse();
124 }
125 
126 //
127 // Handle background erasure
128 //
129 void ToolBarResizer::OnErase( wxEraseEvent & WXUNUSED(event) )
130 {
131  // Ignore it to prevent flashing
132 }
133 
134 //
135 // This draws the background of a toolbar
136 //
137 void ToolBarResizer::OnPaint( wxPaintEvent & event )
138 {
139  wxPaintDC dc( (wxWindow *) event.GetEventObject() );
140 
141  // Start with a clean background
142  //
143  // Under GTK, we specifically set the toolbar background to the background
144  // colour in the system theme.
145 #if defined( __WXGTK__ )
146 // dc.SetBackground( wxBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND ) ) );
147 #endif
148  dc.SetBackground( wxBrush( theTheme.Colour( clrMedium ) ) );
149  dc.Clear();
150 
151  wxSize sz = GetSize();
152 
153  AColor::Dark( &dc, false );
154  AColor::Line(dc, sz.x - 4, 0, sz.x - 4, sz.y );
155  AColor::Line(dc, sz.x - 1, 0, sz.x - 1, sz.y );
156 }
157 
158 //
159 // Handle toolbar resizing
160 //
161 void ToolBarResizer::OnLeftDown( wxMouseEvent & event )
162 {
163  // Go ahead and set the event to propagate
164  event.Skip();
165 
166  // Retrieve the mouse position
167  mResizeOffset = ClientToScreen( event.GetPosition() )-mBar->GetRect().GetBottomRight();
168 
169  mOrigSize = mBar->GetSize();
170 
171  // We want all of the mouse events
172  if( !HasCapture() )
173  CaptureMouse();
174 }
175 
176 void ToolBarResizer::OnLeftUp( wxMouseEvent & event )
177 {
178  // Go ahead and set the event to propagate
179  event.Skip();
180 
181  if( HasCapture() )
182  {
183  ReleaseMouse();
184  if (mOrigFocus)
185  mOrigFocus->SetFocus();
186  mOrigFocus = nullptr;
187  }
188 }
189 
190 void ToolBarResizer::OnEnter( wxMouseEvent & /*event*/ )
191 {
192  // Bug 1201: On Mac, unsetting and re-setting the tooltip may be needed
193  // to make it pop up when we want it.
194  const auto text = GetToolTipText();
195  UnsetToolTip();
196  SetToolTip(text);
197  if (!mOrigFocus)
198  mOrigFocus = FindFocus();
199 }
200 
201 void ToolBarResizer::OnLeave( wxMouseEvent & /*event*/ )
202 {
203  if (!GetCapture())
204  mOrigFocus = nullptr;
205 }
206 
207 void ToolBarResizer::OnMotion( wxMouseEvent & event )
208 {
209  // Go ahead and set the event to propagate
210  event.Skip();
211 
212  // Retrieve the mouse position
213  wxPoint raw_pos = event.GetPosition();
214  wxPoint pos = ClientToScreen( raw_pos );
215 
216  if( HasCapture() && event.Dragging() )
217  {
218  wxRect r = mBar->GetRect();
219  wxSize msz = mBar->GetMinSize();
220  wxSize psz = mBar->GetParent()->GetClientSize();
221 
222  // Adjust the size by the difference between the
223  // last mouse and current mouse positions.
224  r.width = ( pos.x - mResizeOffset.x ) - r.x;
225 
226  // Constrain
227  if( r.width < msz.x )
228  {
229  // Don't allow resizing to go too small
230  r.width = msz.x;
231  }
232  else if( r.GetRight() > psz.x - 3 )
233  {
234  // Don't allow resizing to go too large
235  //
236  // The 3 magic pixels are because I'm too chicken to change the
237  // calculations in ToolDock::LayoutToolBars() even though I'm
238  // the one that set them up. :-)
239  r.SetRight( psz.x - 3 );
240  }
241 
242  ResizeBar( r.GetSize() );
243  }
244 }
245 
246 void ToolBarResizer::ResizeBar(const wxSize &size)
247 {
248  mBar->SetSize( size );
249 
250  // Tell everyone we've changed sizes
251  mBar->Updated();
252 
253  // Refresh our world
254  mBar->GetParent()->Refresh();
255  mBar->GetParent()->Update();
256 }
257 
258 void ToolBarResizer::OnCaptureLost( wxMouseCaptureLostEvent & WXUNUSED(event) )
259 {
260  if( HasCapture() )
261  {
262  ReleaseMouse();
263  if (mOrigFocus)
264  mOrigFocus->SetFocus();
265  mOrigFocus = nullptr;
266  }
267 }
268 
269 void ToolBarResizer::OnKeyDown(wxKeyEvent &event)
270 {
271  event.Skip();
272  if (HasCapture() && WXK_ESCAPE == event.GetKeyCode()) {
273  ResizeBar( mOrigSize );
274  ReleaseMouse();
275  if (mOrigFocus)
276  mOrigFocus->SetFocus();
277  mOrigFocus = nullptr;
278  }
279 }
280 
284 
285 //
286 // Define class to RTTI
287 //
289 
290 //
291 // Custom event
292 //
293 DEFINE_EVENT_TYPE(EVT_TOOLBAR_UPDATED)
294 
295 //
296 // Event table
297 //
298 BEGIN_EVENT_TABLE( ToolBar, wxPanelWrapper )
299  EVT_PAINT( ToolBar::OnPaint )
300  EVT_ERASE_BACKGROUND( ToolBar::OnErase )
301  EVT_MOUSE_EVENTS( ToolBar::OnMouseEvents )
303 
304 //
305 // Constructor
306 //
307 ToolBar::ToolBar( int type,
308  const wxString &label,
309  const wxString &section,
310  bool resizable )
311 : wxPanelWrapper()
312 {
313  // Save parameters
314  mType = type;
315  mLabel = label;
316  mSection = section;
317  mResizable = resizable;
318 
319  // Initialize everything
320  mParent = NULL;
321  mHSizer = NULL;
322  mVisible = false;
323  mPositioned = false;
324 
325  mGrabber = NULL;
326  mResizer = NULL;
327 
328  SetId(mType);
329 }
330 
331 //
332 // Destructor
333 //
335 {
336 }
337 
338 //
339 // Returns the toolbar title
340 //
342 {
343  /* i18n-hint: %s will be replaced by the name of the kind of toolbar.*/
344  return wxString::Format( _("Audacity %s Toolbar"), GetLabel() );
345 }
346 
347 //
348 // Returns the toolbar label
349 //
351 {
352  return mLabel;
353 }
354 
355 //
356 // Returns the toolbar preferences section
357 //
359 {
360  return mSection;
361 }
362 
363 //
364 // Returns the toolbar type
365 //
367 {
368  return mType;
369 }
370 
371 //
372 // Set the toolbar label
373 //
374 void ToolBar::SetLabel(const wxString & label)
375 {
376  mLabel = label;
377 }
378 
379 //
380 // Returns whether the toolbar is resizable or not
381 //
383 {
384  return mResizable;
385 }
386 
387 //
388 // Returns the dock state of the toolbar
389 //
390 bool ToolBar::IsDocked() const
391 {
392  return const_cast<ToolBar*>(this)->GetDock() != nullptr;
393 }
394 
395 //
396 // Returns the visibility of the toolbar
397 //
398 bool ToolBar::IsVisible() const
399 {
400  return mVisible;
401 }
402 
403 void ToolBar::SetVisible( bool bVisible )
404 {
405  mVisible = bVisible;
406 }
407 
408 //
409 // Show or hide the toolbar
410 //
411 bool ToolBar::Expose( bool show )
412 {
413  bool was = mVisible;
414 
415  SetVisible( show );
416 
417  if( IsDocked() )
418  {
419  Show( show );
420  }
421  else
422  {
423  wxWindow * pParent = GetParent();
424  if( !IsPositioned() && show ){
425  SetPositioned();
426  pParent->CentreOnParent();
427  pParent->Move( pParent->GetPosition() + wxSize( mType*10, mType*10 ));
428  }
429  pParent->Show( show );
430  }
431 
432  return was;
433 }
434 
435 //
436 // Initialize the toolbar
437 //
438 void ToolBar::Create( wxWindow *parent )
439 {
440  // Save parameters
441  mParent = parent;
442 
443  // Create the window and label it
445  mType,
446  wxDefaultPosition,
447  wxDefaultSize,
448  wxNO_BORDER | wxTAB_TRAVERSAL,
449  GetTitle() );
450  wxPanelWrapper::SetLabel( GetLabel() );
451 
452  // Go do the rest of the creation
453  ReCreateButtons();
454 
455  // ToolManager depends on this appearing to be visible for proper dock construction
456  mVisible = true;
457 }
458 
460 {
461  wxSize sz3 = GetSize();
462  //wxLogDebug( "x:%i y:%i",sz3.x, sz3.y);
463 
464  // SetSizer(NULL) detaches mHSizer and deletes it.
465  // Do not use Detach() here, as that attempts to detach mHSizer from itself!
466  SetSizer( NULL );
467 
468  // Get rid of any children we may have
469  DestroyChildren();
470  mGrabber = NULL;
471  mResizer = NULL;
472 
473  {
474  // Create the main sizer
475  auto ms = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
476 
477  // Create the grabber and add it to the main sizer
478  mGrabber = safenew Grabber(this, mType);
479  ms->Add(mGrabber, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP | wxRIGHT, 1);
480 
481  // Use a box sizer for laying out controls
482  ms->Add((mHSizer = safenew wxBoxSizer(wxHORIZONTAL)), 1, wxEXPAND);
483 
484  // Go add all the rest of the gadgets
485  Populate();
486 
487  // Add some space for the resize border
488  if (IsResizable())
489  {
490  // Create the resizer and add it to the main sizer
492  ms->Add(mResizer, 0, wxEXPAND | wxALIGN_TOP | wxLEFT, 1);
493  mResizer->SetToolTip(_("Click and drag to resize toolbar"));
494  }
495 
496  // Set dock after possibly creating resizer.
497  // (Re)Establish dock state
498  SetDocked(GetDock(), false);
499 
500  // Set the sizer
501  SetSizerAndFit(ms.release());
502  }
503 
504  // Recalculate the height to be a multiple of toolbarSingle
505  const int tbs = toolbarSingle + toolbarGap;
506  wxSize sz = GetSize();
507  sz.y = ( ( ( sz.y + tbs -1) / tbs ) * tbs ) - 1;
508 
509  // Set the true AND minimum sizes and do final layout
510  if(IsResizable())
511  {
512  // JKC we're going to allow all resizable toolbars to be resized
513  // to 1 unit high, typically 27 pixels.
514  wxSize sz2 = sz;
515  sz2.SetWidth(GetMinToolbarWidth());
516  sz2.y = tbs -1;
517  SetMinSize(sz2);
518  // Initial size at least as big as minimum.
519  if( sz3.y < sz2.y )
520  sz3.y = sz2.y;
521  if( sz3.x < sz2.x )
522  sz3.x = GetInitialWidth();
523  //sz.SetWidth();
524  SetSize(sz3);
525  }
526  else
527  {
528  SetInitialSize(sz);
529  }
530  Layout();
531 }
532 
533 // The application preferences have changed, so update any elements that may
534 // depend on them.
536 {
537 #if wxUSE_TOOLTIPS
538  // Change the tooltip of the grabber
539  if ( mGrabber )
540  {
541  mGrabber->SetToolTip( GetTitle() );
542  }
543 
544  // Change the tooltip of the resizer
545  if ( mResizer )
546  {
547  mResizer->SetToolTip( _("Click and drag to resize toolbar") );
548  wxSizeEvent e;
549  GetParent()->GetEventHandler()->AddPendingEvent( e );
550  GetParent()->Refresh();
551  }
552 #endif
553 
554  return;
555 }
556 
557 //
558 // Return the pointer to the ToolBock where this bar lives
559 //
561 {
562  return dynamic_cast<ToolDock*>(GetParent());
563 }
564 
565 //
566 // Toggle the docked/floating state
567 //
568 void ToolBar::SetDocked( ToolDock *dock, bool pushed )
569 {
570  // Remember it
571 // mDock = dock;
572 
573  // Change the tooltip of the grabber
574 #if wxUSE_TOOLTIPS
575  mGrabber->SetToolTip( GetTitle() );
576 #endif
577 
578  // Set the grabber button state
579  mGrabber->PushButton( pushed );
580 
581  if (mResizer)
582  {
583  mResizer->Show(dock != NULL);
584  Layout();
585  Fit();
586  }
587 }
588 
589 //
590 // Notify parent of changes
591 //
593 {
594  if( IsDocked() )
595  GetDock()->Updated();
596  //wxCommandEvent e( EVT_TOOLBAR_UPDATED, GetId() );
597  //GetParent()->GetEventHandler()->AddPendingEvent( e );
598 }
599 
600 //
601 // Returns a pointer to the main sizer
602 //
603 wxBoxSizer *ToolBar::GetSizer()
604 {
605  return mHSizer;
606 }
607 
608 //
609 // Add a window to the main sizer
610 //
611 void ToolBar::Add( wxWindow *window,
612  int proportion,
613  int flag,
614  int border,
615  wxObject* userData )
616 {
617  mHSizer->Add( window,
618  proportion,
619  flag,
620  border,
621  userData );
622 }
623 
624 //
625 // Add a child sizer to the main sizer
626 //
627 void ToolBar::Add( wxSizer *sizer,
628  int proportion,
629  int flag,
630  int border,
631  wxObject* userData )
632 {
633  mHSizer->Add( sizer,
634  proportion,
635  flag,
636  border,
637  userData );
638 }
639 
640 //
641 // Add some space to the main sizer
642 //
643 void ToolBar::Add( int width,
644  int height,
645  int proportion,
646  int flag,
647  int border,
648  wxObject* userData )
649 {
650  mHSizer->Add( width,
651  height,
652  proportion,
653  flag,
654  border,
655  userData );
656 }
657 
658 //
659 // Adds a spacer to the main sizer
660 //
661 void ToolBar::AddSpacer( int size )
662 {
663  mHSizer->AddSpacer( size );
664 }
665 
666 //
667 // Adds a strechable spacer to the main sizer
668 //
670 {
671  mHSizer->AddStretchSpacer( prop );
672 }
673 
674 //
675 // Detach a window from the main sizer
676 //
677 void ToolBar::Detach( wxWindow *window )
678 {
679  mHSizer->Detach( window );
680 }
681 
682 //
683 // Detach a child sizer from the main sizer
684 //
685 void ToolBar::Detach( wxSizer *sizer )
686 {
687  mHSizer->Detach( sizer );
688 }
689 
691 {
692  theTheme.ReplaceImage( eBmpOut, &theTheme.Image( eBmpIn ));
693 }
694 
696 {
697  // Don't recolour the buttons...
698  MakeMacRecoloredImage( eBmpOut, eBmpIn );
699 }
700 
702 {
703 
704  bool bUseAqua = false;
705 
706 #ifdef EXPERIMENTAL_THEME_PREFS
707  gPrefs->Read( wxT("/GUI/ShowMac"), &bUseAqua, false);
708 #endif
709 
710 #ifdef USE_AQUA_THEME
711  bUseAqua = !bUseAqua;
712 #endif
713 
714  if( bUseAqua ){
715  MakeMacRecoloredImage( bmpRecoloredUpLarge, bmpMacUpButton );
716  MakeMacRecoloredImage( bmpRecoloredDownLarge, bmpMacDownButton );
717  MakeMacRecoloredImage( bmpRecoloredUpHiliteLarge, bmpMacHiliteUpButton );
718  MakeMacRecoloredImage( bmpRecoloredHiliteLarge, bmpMacHiliteButton );
719  } else {
720  MakeRecoloredImage( bmpRecoloredUpLarge, bmpUpButtonLarge );
721  MakeRecoloredImage( bmpRecoloredDownLarge, bmpDownButtonLarge );
722  MakeRecoloredImage( bmpRecoloredUpHiliteLarge, bmpHiliteUpButtonLarge );
723  MakeRecoloredImage( bmpRecoloredHiliteLarge, bmpHiliteButtonLarge );
724  }
725 }
726 
728 {
729 
730  bool bUseAqua = false;
731 
732 #ifdef EXPERIMENTAL_THEME_PREFS
733  gPrefs->Read( wxT("/GUI/ShowMac"), &bUseAqua, false);
734 #endif
735 
736 #ifdef USE_AQUA_THEME
737  bUseAqua = !bUseAqua;
738 #endif
739 
740  if( bUseAqua ){
741  MakeMacRecoloredImage( bmpRecoloredUpSmall, bmpMacUpButtonSmall );
742  MakeMacRecoloredImage( bmpRecoloredDownSmall, bmpMacDownButtonSmall );
743  MakeMacRecoloredImage( bmpRecoloredUpHiliteSmall, bmpMacHiliteUpButtonSmall );
744  MakeMacRecoloredImage( bmpRecoloredHiliteSmall, bmpMacHiliteButtonSmall );
745  } else {
746  MakeRecoloredImage( bmpRecoloredUpSmall, bmpUpButtonSmall );
747  MakeRecoloredImage( bmpRecoloredDownSmall, bmpDownButtonSmall );
748  MakeRecoloredImage( bmpRecoloredUpHiliteSmall, bmpHiliteUpButtonSmall );
749  MakeRecoloredImage( bmpRecoloredHiliteSmall, bmpHiliteButtonSmall );
750  }
751 }
752 
765 AButton * ToolBar::MakeButton(wxWindow *parent,
766  teBmps eUp,
767  teBmps eDown,
768  teBmps eHilite,
769  teBmps eDownHi,
770  teBmps eStandardUp,
771  teBmps eStandardDown,
772  teBmps eDisabled,
773  wxWindowID id,
774  wxPoint placement,
775  bool processdownevents,
776  wxSize size)
777 {
778  // wxMax to cater for case of image being bigger than the button.
779  int xoff = wxMax( 0, (size.GetWidth() - theTheme.Image(eStandardUp).GetWidth())/2);
780  int yoff = wxMax( 0, (size.GetHeight() - theTheme.Image(eStandardUp).GetHeight())/2);
781 
782  typedef std::unique_ptr<wxImage> wxImagePtr;
783  wxImagePtr up2 (OverlayImage(eUp, eStandardUp, xoff, yoff));
784  wxImagePtr hilite2 (OverlayImage(eHilite, eStandardUp, xoff, yoff));
785  wxImagePtr down2 (OverlayImage(eDown, eStandardDown, xoff + 1, yoff + 1));
786  wxImagePtr downHi2 (OverlayImage(eDownHi, eStandardDown, xoff + 1, yoff + 1));
787  wxImagePtr disable2 (OverlayImage(eUp, eDisabled, xoff, yoff));
788 
789  wxASSERT(parent); // to justify safenew
790  AButton * button =
791  safenew AButton(parent, id, placement, size, *up2, *hilite2, *down2, *downHi2,
792  *disable2, processdownevents);
793 
794  return button;
795 }
796 
797 //static
798 void ToolBar::MakeAlternateImages(AButton &button, int idx,
799  teBmps eUp,
800  teBmps eDown,
801  teBmps eHilite,
802  teBmps eDownHi,
803  teBmps eStandardUp,
804  teBmps eStandardDown,
805  teBmps eDisabled,
806  wxSize size)
807 {
808  // wxMax to cater for case of image being bigger than the button.
809  int xoff = wxMax( 0, (size.GetWidth() - theTheme.Image(eStandardUp).GetWidth())/2);
810  int yoff = wxMax( 0, (size.GetHeight() - theTheme.Image(eStandardUp).GetHeight())/2);
811 
812  typedef std::unique_ptr<wxImage> wxImagePtr;
813  wxImagePtr up (OverlayImage(eUp, eStandardUp, xoff, yoff));
814  wxImagePtr hilite (OverlayImage(eHilite, eStandardUp, xoff, yoff));
815  wxImagePtr down (OverlayImage(eDown, eStandardDown, xoff + 1, yoff + 1));
816  wxImagePtr downHi (OverlayImage(eDownHi, eStandardDown, xoff + 1, yoff + 1));
817  wxImagePtr disable (OverlayImage(eUp, eDisabled, xoff, yoff));
818 
819  button.SetAlternateImages(idx, *up, *hilite, *down, *downHi, *disable);
820 }
821 
823 (AButton &button, const TranslatedInternalString commands[], size_t nCommands)
824 {
825  wxString result;
826  const auto project = GetActiveProject();
827  const auto commandManager =
828  project ? project->GetCommandManager() : nullptr;
829  if (commandManager)
830  result =
831  commandManager->DescribeCommandsAndShortcuts(commands, nCommands);
832  button.SetToolTip(result);
833 }
834 
835 //
836 // This changes the state a button (from up to down or vice versa)
837 //
838 void ToolBar::SetButton( bool down, AButton * button )
839 {
840  if( down )
841  {
842  button->PushDown();
843  }
844  else
845  {
846  button->PopUp();
847  }
848 }
849 
850 //
851 // Handle background erasure
852 //
853 void ToolBar::OnErase( wxEraseEvent & WXUNUSED(event) )
854 {
855  // Ignore it to prevent flashing
856 }
857 
858 //
859 // This draws the background of a toolbar
860 //
861 void ToolBar::OnPaint( wxPaintEvent & event )
862 {
863  //wxPaintDC dc( (wxWindow *) event.GetEventObject() );
864  wxPaintDC dc( this );
865  // Start with a clean background
866  //
867  // Under GTK, we specifically set the toolbar background to the background
868  // colour in the system theme.
869 #if defined( __WXGTK__ )
870  //dc.SetBackground( wxBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND ) ) );
871 #endif
872 
873  // Themed background colour.
874  dc.SetBackground( wxBrush( theTheme.Colour( clrMedium ) ) );
875  dc.Clear();
876 
877 #ifdef USE_AQUA_THEME
878  Repaint( &dc );
879 #endif
880 }
881 
882 void ToolBar::OnMouseEvents(wxMouseEvent &event)
883 {
884  // Do this hack so scrubber can detect mouse drags anywhere
885  event.ResumePropagation(wxEVENT_PROPAGATE_MAX);
886  event.Skip();
887 }
888 
890 {
891  return RWIDTH;
892 }
void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:727
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
bool IsDocked() const
Definition: ToolBar.cpp:390
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
IMPLEMENT_CLASS(ToolBar, wxPanelWrapper)
Methods for ToolBar.
virtual void UpdatePrefs()
Definition: ToolBar.cpp:535
virtual int GetMinToolbarWidth()
Definition: ToolBar.h:128
void SetVisible(bool bVisible)
Definition: ToolBar.cpp:403
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:374
void SetAlternateImages(unsigned idx, ImageRoll up, ImageRoll over, ImageRoll down, ImageRoll overDown, ImageRoll dis)
Definition: AButton.cpp:232
A dynamic panel where a ToolBar can be docked.
Definition: ToolDock.h:290
void PopUp()
Definition: AButton.cpp:525
void MakeButtonBackgroundsLarge()
Definition: ToolBar.cpp:701
wxBoxSizer * GetSizer()
Definition: ToolBar.cpp:603
bool mResizable
Definition: ToolBar.h:227
virtual void ReCreateButtons()
Definition: ToolBar.cpp:459
wxSize mOrigSize
Definition: ToolBar.cpp:92
void OnErase(wxEraseEvent &event)
Definition: ToolBar.cpp:129
ToolDock * GetDock()
Definition: ToolBar.cpp:560
virtual ~ToolBar()
Definition: ToolBar.cpp:334
DEFINE_EVENT_TYPE(EVT_OPEN_AUDIO_FILE)
Custom events.
bool AcceptsFocusFromKeyboard() const override
Definition: ToolBar.cpp:75
virtual int GetInitialWidth()
Resizable toolbars should implement these.
Definition: ToolBar.h:127
#define toolbarGap
Definition: ToolBar.h:59
int GetResizeGrabberWidth()
Returns the width in pixels of the resizer element.
Definition: ToolBar.cpp:889
wxString label
Definition: Tags.cpp:727
wxBoxSizer * mHSizer
Definition: ToolBar.h:224
#define toolbarSingle
Definition: ToolBar.h:54
bool IsPositioned()
Definition: ToolBar.h:121
std::unique_ptr< wxImage > OverlayImage(wxImage *background, wxImage *foreground, wxImage *mask, int xoff, int yoff)
virtual bool Expose(bool show=true)
Definition: ToolBar.cpp:411
int teBmps
Definition: Theme.h:28
void Detach(wxWindow *window)
Definition: ToolBar.cpp:677
friend class ToolBarResizer
Definition: ToolBar.h:235
static AButton * MakeButton(wxWindow *parent, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eDownHi, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxWindowID id, wxPoint placement, bool processdownevents, wxSize size)
Definition: ToolBar.cpp:765
static void Dark(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:338
#define safenew
Definition: Audacity.h:230
int mType
Definition: ToolBar.h:215
void ReplaceImage(int iIndex, wxImage *pImage)
Replaces both the image and the bitmap.
Definition: Theme.cpp:1287
wxString mLabel
Definition: ToolBar.h:213
wxString GetLabel()
Definition: ToolBar.cpp:350
wxString mSection
Definition: ToolBar.h:214
void OnLeftUp(wxMouseEvent &event)
Definition: ToolBar.cpp:176
void OnKeyDown(wxKeyEvent &event)
Definition: ToolBar.cpp:269
void AddSpacer(int size=14)
Definition: ToolBar.cpp:661
ToolBar * mBar
Definition: ToolBar.cpp:90
void OnPaint(wxPaintEvent &event)
Definition: ToolBar.cpp:137
END_EVENT_TABLE()
virtual void Populate()=0
ToolBarResizer(ToolBar *mBar)
Definition: ToolBar.cpp:113
void OnErase(wxEraseEvent &event)
Definition: ToolBar.cpp:853
Grabber * mGrabber
Definition: ToolBar.h:221
void OnLeftDown(wxMouseEvent &event)
Definition: ToolBar.cpp:161
bool IsVisible() const
Definition: ToolBar.cpp:398
bool mVisible
Definition: ToolBar.h:226
void OnMotion(wxMouseEvent &event)
Definition: ToolBar.cpp:207
ToolBarResizer * mResizer
Definition: ToolBar.h:222
#define RWIDTH
ToolBarResizer.
Definition: ToolBar.cpp:64
virtual ~ToolBarResizer()
Definition: ToolBar.cpp:120
wxImage & Image(int iIndex)
Definition: Theme.cpp:1251
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:611
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:438
wxString GetSection()
Definition: ToolBar.cpp:358
void ResizeBar(const wxSize &size)
Definition: ToolBar.cpp:246
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:122
void OnPaint(wxPaintEvent &event)
Definition: ToolBar.cpp:861
void Updated()
Definition: ToolBar.cpp:592
void OnMouseEvents(wxMouseEvent &event)
Definition: ToolBar.cpp:882
void MakeRecoloredImage(teBmps eBmpOut, teBmps eBmpIn)
Definition: ToolBar.cpp:695
void SetPositioned()
Definition: ToolBar.h:123
static void MakeAlternateImages(AButton &button, int idx, teBmps eUp, teBmps eDown, teBmps eHilite, teBmps eDownHi, teBmps eStandardUp, teBmps eStandardDown, teBmps eDisabled, wxSize size)
Definition: ToolBar.cpp:798
wxWindow * mParent
Definition: ToolBar.h:219
void OnEnter(wxMouseEvent &event)
Definition: ToolBar.cpp:190
_("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
void OnLeave(wxMouseEvent &event)
Definition: ToolBar.cpp:201
wxWindow * mOrigFocus
Definition: ToolBar.cpp:93
wxPoint mResizeOffset
Definition: ToolBar.cpp:91
void AddStretchSpacer(int prop=1)
Definition: ToolBar.cpp:669
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
wxString GetTitle()
Definition: ToolBar.cpp:341
int GetType()
Definition: ToolBar.cpp:366
The widget to the left of a ToolBar that allows it to be dragged around to NEW positions.
Definition: Grabber.h:98
void SetButton(bool down, AButton *button)
Definition: ToolBar.cpp:838
void Updated()
Definition: ToolDock.cpp:854
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
void PushDown()
Definition: AButton.cpp:517
bool Create(wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const wxString &name=_("Panel"))
static void SetButtonToolTip(AButton &button, const TranslatedInternalString commands[], size_t nCommands)
Definition: ToolBar.cpp:823
virtual void Repaint(wxDC *dc)=0
bool IsResizable() const
Definition: ToolBar.cpp:382
void OnCaptureLost(wxMouseCaptureLostEvent &event)
Definition: ToolBar.cpp:258
void PushButton(bool state)
Definition: Grabber.cpp:185
void SetDocked(ToolDock *dock, bool pushed)
Definition: ToolBar.cpp:568
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed...
Definition: ToolBar.h:87
void MakeMacRecoloredImage(teBmps eBmpOut, teBmps eBmpIn)
Definition: ToolBar.cpp:690
A wxButton with mouse-over behaviour.
Definition: AButton.h:28