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 mResizeStart;
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  mResizeStart = ClientToScreen( event.GetPosition() );
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 - mResizeStart.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  else
242  {
243  // Remember for next go round
244  mResizeStart = pos;
245  }
246 
247  ResizeBar( r.GetSize() );
248  }
249 }
250 
251 void ToolBarResizer::ResizeBar(const wxSize &size)
252 {
253  mBar->SetSize( size );
254 
255  // Tell everyone we've changed sizes
256  mBar->Updated();
257 
258  // Refresh our world
259  mBar->GetParent()->Refresh();
260  mBar->GetParent()->Update();
261 }
262 
263 void ToolBarResizer::OnCaptureLost( wxMouseCaptureLostEvent & WXUNUSED(event) )
264 {
265  if( HasCapture() )
266  {
267  ReleaseMouse();
268  if (mOrigFocus)
269  mOrigFocus->SetFocus();
270  mOrigFocus = nullptr;
271  }
272 }
273 
274 void ToolBarResizer::OnKeyDown(wxKeyEvent &event)
275 {
276  event.Skip();
277  if (HasCapture() && WXK_ESCAPE == event.GetKeyCode()) {
278  ResizeBar( mOrigSize );
279  ReleaseMouse();
280  if (mOrigFocus)
281  mOrigFocus->SetFocus();
282  mOrigFocus = nullptr;
283  }
284 }
285 
289 
290 //
291 // Define class to RTTI
292 //
294 
295 //
296 // Custom event
297 //
298 DEFINE_EVENT_TYPE(EVT_TOOLBAR_UPDATED)
299 
300 //
301 // Event table
302 //
303 BEGIN_EVENT_TABLE( ToolBar, wxPanelWrapper )
304  EVT_PAINT( ToolBar::OnPaint )
305  EVT_ERASE_BACKGROUND( ToolBar::OnErase )
306  EVT_MOUSE_EVENTS( ToolBar::OnMouseEvents )
308 
309 //
310 // Constructor
311 //
312 ToolBar::ToolBar( int type,
313  const wxString &label,
314  const wxString &section,
315  bool resizable )
316 : wxPanelWrapper()
317 {
318  // Save parameters
319  mType = type;
320  mLabel = label;
321  mSection = section;
322  mResizable = resizable;
323 
324  // Initialize everything
325  mParent = NULL;
326  mHSizer = NULL;
327  mVisible = false;
328  mPositioned = false;
329 
330  mGrabber = NULL;
331  mResizer = NULL;
332 
333  SetId(mType);
334 }
335 
336 //
337 // Destructor
338 //
340 {
341 }
342 
343 //
344 // Returns the toolbar title
345 //
347 {
348  /* i18n-hint: %s will be replaced by the name of the kind of toolbar.*/
349  return wxString::Format( _("Audacity %s Toolbar"), GetLabel() );
350 }
351 
352 //
353 // Returns the toolbar label
354 //
356 {
357  return mLabel;
358 }
359 
360 //
361 // Returns the toolbar preferences section
362 //
364 {
365  return mSection;
366 }
367 
368 //
369 // Returns the toolbar type
370 //
372 {
373  return mType;
374 }
375 
376 //
377 // Set the toolbar label
378 //
379 void ToolBar::SetLabel(const wxString & label)
380 {
381  mLabel = label;
382 }
383 
384 //
385 // Returns whether the toolbar is resizable or not
386 //
388 {
389  return mResizable;
390 }
391 
392 //
393 // Returns the dock state of the toolbar
394 //
395 bool ToolBar::IsDocked() const
396 {
397  return const_cast<ToolBar*>(this)->GetDock() != nullptr;
398 }
399 
400 //
401 // Returns the visibility of the toolbar
402 //
403 bool ToolBar::IsVisible() const
404 {
405  return mVisible;
406 }
407 
408 void ToolBar::SetVisible( bool bVisible )
409 {
410  mVisible = bVisible;
411 }
412 
413 //
414 // Show or hide the toolbar
415 //
416 bool ToolBar::Expose( bool show )
417 {
418  bool was = mVisible;
419 
420  SetVisible( show );
421 
422  if( IsDocked() )
423  {
424  Show( show );
425  }
426  else
427  {
428  wxWindow * pParent = GetParent();
429  if( !IsPositioned() && show ){
430  SetPositioned();
431  pParent->CentreOnParent();
432  pParent->Move( pParent->GetPosition() + wxSize( mType*10, mType*10 ));
433  }
434  pParent->Show( show );
435  }
436 
437  return was;
438 }
439 
440 //
441 // Initialize the toolbar
442 //
443 void ToolBar::Create( wxWindow *parent )
444 {
445  // Save parameters
446  mParent = parent;
447 
448  // Create the window and label it
450  mType,
451  wxDefaultPosition,
452  wxDefaultSize,
453  wxNO_BORDER | wxTAB_TRAVERSAL,
454  GetTitle() );
455  wxPanelWrapper::SetLabel( GetLabel() );
456 
457  // Go do the rest of the creation
458  ReCreateButtons();
459 
460  // ToolManager depends on this appearing to be visible for proper dock construction
461  mVisible = true;
462 }
463 
465 {
466  wxSize sz3 = GetSize();
467  //wxLogDebug( "x:%i y:%i",sz3.x, sz3.y);
468 
469  // SetSizer(NULL) detaches mHSizer and deletes it.
470  // Do not use Detach() here, as that attempts to detach mHSizer from itself!
471  SetSizer( NULL );
472 
473  // Get rid of any children we may have
474  DestroyChildren();
475  mGrabber = NULL;
476  mResizer = NULL;
477 
478  {
479  // Create the main sizer
480  auto ms = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
481 
482  // Create the grabber and add it to the main sizer
483  mGrabber = safenew Grabber(this, mType);
484  ms->Add(mGrabber, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP | wxRIGHT, 1);
485 
486  // Use a box sizer for laying out controls
487  ms->Add((mHSizer = safenew wxBoxSizer(wxHORIZONTAL)), 1, wxEXPAND);
488 
489  // Go add all the rest of the gadgets
490  Populate();
491 
492  // Add some space for the resize border
493  if (IsResizable())
494  {
495  // Create the resizer and add it to the main sizer
497  ms->Add(mResizer, 0, wxEXPAND | wxALIGN_TOP | wxLEFT, 1);
498  mResizer->SetToolTip(_("Click and drag to resize toolbar"));
499  }
500 
501  // Set dock after possibly creating resizer.
502  // (Re)Establish dock state
503  SetDocked(GetDock(), false);
504 
505  // Set the sizer
506  SetSizerAndFit(ms.release());
507  }
508 
509  // Recalculate the height to be a multiple of toolbarSingle
510  const int tbs = toolbarSingle + toolbarGap;
511  wxSize sz = GetSize();
512  sz.y = ( ( ( sz.y + tbs -1) / tbs ) * tbs ) - 1;
513 
514  // Set the true AND minimum sizes and do final layout
515  if(IsResizable())
516  {
517  // JKC we're going to allow all resizable toolbars to be resized
518  // to 1 unit high, typically 27 pixels.
519  wxSize sz2 = sz;
520  sz2.SetWidth(GetMinToolbarWidth());
521  sz2.y = tbs -1;
522  SetMinSize(sz2);
523  // Initial size at least as big as minimum.
524  if( sz3.y < sz2.y )
525  sz3.y = sz2.y;
526  if( sz3.x < sz2.x )
527  sz3.x = GetInitialWidth();
528  //sz.SetWidth();
529  SetSize(sz3);
530  }
531  else
532  {
533  SetInitialSize(sz);
534  }
535  Layout();
536 }
537 
538 // The application preferences have changed, so update any elements that may
539 // depend on them.
541 {
542 #if wxUSE_TOOLTIPS
543  // Change the tooltip of the grabber
544  if ( mGrabber )
545  {
546  mGrabber->SetToolTip( GetTitle() );
547  }
548 
549  // Change the tooltip of the resizer
550  if ( mResizer )
551  {
552  mResizer->SetToolTip( _("Click and drag to resize toolbar") );
553  wxSizeEvent e;
554  GetParent()->GetEventHandler()->AddPendingEvent( e );
555  GetParent()->Refresh();
556  }
557 #endif
558 
559  return;
560 }
561 
562 //
563 // Return the pointer to the ToolBock where this bar lives
564 //
566 {
567  return dynamic_cast<ToolDock*>(GetParent());
568 }
569 
570 //
571 // Toggle the docked/floating state
572 //
573 void ToolBar::SetDocked( ToolDock *dock, bool pushed )
574 {
575  // Remember it
576 // mDock = dock;
577 
578  // Change the tooltip of the grabber
579 #if wxUSE_TOOLTIPS
580  mGrabber->SetToolTip( GetTitle() );
581 #endif
582 
583  // Set the grabber button state
584  mGrabber->PushButton( pushed );
585 
586  if (mResizer)
587  {
588  mResizer->Show(dock != NULL);
589  Layout();
590  Fit();
591  }
592 }
593 
594 //
595 // Notify parent of changes
596 //
598 {
599  if( IsDocked() )
600  GetDock()->Updated();
601  //wxCommandEvent e( EVT_TOOLBAR_UPDATED, GetId() );
602  //GetParent()->GetEventHandler()->AddPendingEvent( e );
603 }
604 
605 //
606 // Returns a pointer to the main sizer
607 //
608 wxBoxSizer *ToolBar::GetSizer()
609 {
610  return mHSizer;
611 }
612 
613 //
614 // Add a window to the main sizer
615 //
616 void ToolBar::Add( wxWindow *window,
617  int proportion,
618  int flag,
619  int border,
620  wxObject* userData )
621 {
622  mHSizer->Add( window,
623  proportion,
624  flag,
625  border,
626  userData );
627 }
628 
629 //
630 // Add a child sizer to the main sizer
631 //
632 void ToolBar::Add( wxSizer *sizer,
633  int proportion,
634  int flag,
635  int border,
636  wxObject* userData )
637 {
638  mHSizer->Add( sizer,
639  proportion,
640  flag,
641  border,
642  userData );
643 }
644 
645 //
646 // Add some space to the main sizer
647 //
648 void ToolBar::Add( int width,
649  int height,
650  int proportion,
651  int flag,
652  int border,
653  wxObject* userData )
654 {
655  mHSizer->Add( width,
656  height,
657  proportion,
658  flag,
659  border,
660  userData );
661 }
662 
663 //
664 // Adds a spacer to the main sizer
665 //
666 void ToolBar::AddSpacer( int size )
667 {
668  mHSizer->AddSpacer( size );
669 }
670 
671 //
672 // Adds a strechable spacer to the main sizer
673 //
675 {
676  mHSizer->AddStretchSpacer( prop );
677 }
678 
679 //
680 // Detach a window from the main sizer
681 //
682 void ToolBar::Detach( wxWindow *window )
683 {
684  mHSizer->Detach( window );
685 }
686 
687 //
688 // Detach a child sizer from the main sizer
689 //
690 void ToolBar::Detach( wxSizer *sizer )
691 {
692  mHSizer->Detach( sizer );
693 }
694 
696 {
697  theTheme.ReplaceImage( eBmpOut, &theTheme.Image( eBmpIn ));
698 }
699 
701 {
702  // Don't recolour the buttons...
703  MakeMacRecoloredImage( eBmpOut, eBmpIn );
704 }
705 
707 {
708 
709  bool bUseAqua = false;
710 
711 #ifdef EXPERIMENTAL_THEME_PREFS
712  gPrefs->Read( wxT("/GUI/ShowMac"), &bUseAqua, false);
713 #endif
714 
715 #ifdef USE_AQUA_THEME
716  bUseAqua = !bUseAqua;
717 #endif
718 
719  if( bUseAqua ){
720  MakeMacRecoloredImage( bmpRecoloredUpLarge, bmpMacUpButton );
721  MakeMacRecoloredImage( bmpRecoloredDownLarge, bmpMacDownButton );
722  MakeMacRecoloredImage( bmpRecoloredUpHiliteLarge, bmpMacHiliteUpButton );
723  MakeMacRecoloredImage( bmpRecoloredHiliteLarge, bmpMacHiliteButton );
724  } else {
725  MakeRecoloredImage( bmpRecoloredUpLarge, bmpUpButtonLarge );
726  MakeRecoloredImage( bmpRecoloredDownLarge, bmpDownButtonLarge );
727  MakeRecoloredImage( bmpRecoloredUpHiliteLarge, bmpHiliteUpButtonLarge );
728  MakeRecoloredImage( bmpRecoloredHiliteLarge, bmpHiliteButtonLarge );
729  }
730 }
731 
733 {
734 
735  bool bUseAqua = false;
736 
737 #ifdef EXPERIMENTAL_THEME_PREFS
738  gPrefs->Read( wxT("/GUI/ShowMac"), &bUseAqua, false);
739 #endif
740 
741 #ifdef USE_AQUA_THEME
742  bUseAqua = !bUseAqua;
743 #endif
744 
745  if( bUseAqua ){
746  MakeMacRecoloredImage( bmpRecoloredUpSmall, bmpMacUpButtonSmall );
747  MakeMacRecoloredImage( bmpRecoloredDownSmall, bmpMacDownButtonSmall );
748  MakeMacRecoloredImage( bmpRecoloredUpHiliteSmall, bmpMacHiliteUpButtonSmall );
749  MakeMacRecoloredImage( bmpRecoloredHiliteSmall, bmpMacHiliteButtonSmall );
750  } else {
751  MakeRecoloredImage( bmpRecoloredUpSmall, bmpUpButtonSmall );
752  MakeRecoloredImage( bmpRecoloredDownSmall, bmpDownButtonSmall );
753  MakeRecoloredImage( bmpRecoloredUpHiliteSmall, bmpHiliteUpButtonSmall );
754  MakeRecoloredImage( bmpRecoloredHiliteSmall, bmpHiliteButtonSmall );
755  }
756 }
757 
770 AButton * ToolBar::MakeButton(wxWindow *parent,
771  teBmps eUp,
772  teBmps eDown,
773  teBmps eHilite,
774  teBmps eDownHi,
775  teBmps eStandardUp,
776  teBmps eStandardDown,
777  teBmps eDisabled,
778  wxWindowID id,
779  wxPoint placement,
780  bool processdownevents,
781  wxSize size)
782 {
783  // wxMax to cater for case of image being bigger than the button.
784  int xoff = wxMax( 0, (size.GetWidth() - theTheme.Image(eStandardUp).GetWidth())/2);
785  int yoff = wxMax( 0, (size.GetHeight() - theTheme.Image(eStandardUp).GetHeight())/2);
786 
787  typedef std::unique_ptr<wxImage> wxImagePtr;
788  wxImagePtr up2 (OverlayImage(eUp, eStandardUp, xoff, yoff));
789  wxImagePtr hilite2 (OverlayImage(eHilite, eStandardUp, xoff, yoff));
790  wxImagePtr down2 (OverlayImage(eDown, eStandardDown, xoff + 1, yoff + 1));
791  wxImagePtr downHi2 (OverlayImage(eDownHi, eStandardDown, xoff + 1, yoff + 1));
792  wxImagePtr disable2 (OverlayImage(eUp, eDisabled, xoff, yoff));
793 
794  wxASSERT(parent); // to justify safenew
795  AButton * button =
796  safenew AButton(parent, id, placement, size, *up2, *hilite2, *down2, *downHi2,
797  *disable2, processdownevents);
798 
799  return button;
800 }
801 
802 //static
803 void ToolBar::MakeAlternateImages(AButton &button, int idx,
804  teBmps eUp,
805  teBmps eDown,
806  teBmps eHilite,
807  teBmps eDownHi,
808  teBmps eStandardUp,
809  teBmps eStandardDown,
810  teBmps eDisabled,
811  wxSize size)
812 {
813  // wxMax to cater for case of image being bigger than the button.
814  int xoff = wxMax( 0, (size.GetWidth() - theTheme.Image(eStandardUp).GetWidth())/2);
815  int yoff = wxMax( 0, (size.GetHeight() - theTheme.Image(eStandardUp).GetHeight())/2);
816 
817  typedef std::unique_ptr<wxImage> wxImagePtr;
818  wxImagePtr up (OverlayImage(eUp, eStandardUp, xoff, yoff));
819  wxImagePtr hilite (OverlayImage(eHilite, eStandardUp, xoff, yoff));
820  wxImagePtr down (OverlayImage(eDown, eStandardDown, xoff + 1, yoff + 1));
821  wxImagePtr downHi (OverlayImage(eDownHi, eStandardDown, xoff + 1, yoff + 1));
822  wxImagePtr disable (OverlayImage(eUp, eDisabled, xoff, yoff));
823 
824  button.SetAlternateImages(idx, *up, *hilite, *down, *downHi, *disable);
825 }
826 
828 (AButton &button, const LocalizedCommandNameVector &commands)
829 {
830  wxString result;
831  const auto project = GetActiveProject();
832  const auto commandManager =
833  project ? project->GetCommandManager() : nullptr;
834  if (commandManager)
835  result =
836  commandManager->DescribeCommandsAndShortcuts(commands);
837  button.SetToolTip(result);
838 }
839 
840 //
841 // This changes the state a button (from up to down or vice versa)
842 //
843 void ToolBar::SetButton( bool down, AButton * button )
844 {
845  if( down )
846  {
847  button->PushDown();
848  }
849  else
850  {
851  button->PopUp();
852  }
853 }
854 
855 //
856 // Handle background erasure
857 //
858 void ToolBar::OnErase( wxEraseEvent & WXUNUSED(event) )
859 {
860  // Ignore it to prevent flashing
861 }
862 
863 //
864 // This draws the background of a toolbar
865 //
866 void ToolBar::OnPaint( wxPaintEvent & event )
867 {
868  wxPaintDC dc( (wxWindow *) event.GetEventObject() );
869 
870  // Start with a clean background
871  //
872  // Under GTK, we specifically set the toolbar background to the background
873  // colour in the system theme.
874 #if defined( __WXGTK__ )
875  //dc.SetBackground( wxBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND ) ) );
876 #endif
877 
878  // Themed background colour.
879  dc.SetBackground( wxBrush( theTheme.Colour( clrMedium ) ) );
880  dc.Clear();
881 
882 #ifdef USE_AQUA_THEME
883  Repaint( &dc );
884 #endif
885 }
886 
887 void ToolBar::OnMouseEvents(wxMouseEvent &event)
888 {
889  // Do this hack so scrubber can detect mouse drags anywhere
890  event.ResumePropagation(wxEVENT_PROPAGATE_MAX);
891  event.Skip();
892 }
893 
895 {
896  return RWIDTH;
897 }
void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:732
bool IsDocked() const
Definition: ToolBar.cpp:395
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
IMPLEMENT_CLASS(ToolBar, wxPanelWrapper)
Methods for ToolBar.
virtual void UpdatePrefs()
Definition: ToolBar.cpp:540
virtual int GetMinToolbarWidth()
Definition: ToolBar.h:130
void SetVisible(bool bVisible)
Definition: ToolBar.cpp:408
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:706
wxBoxSizer * GetSizer()
Definition: ToolBar.cpp:608
bool mResizable
Definition: ToolBar.h:233
virtual void ReCreateButtons()
Definition: ToolBar.cpp:464
wxSize mOrigSize
Definition: ToolBar.cpp:92
void OnErase(wxEraseEvent &event)
Definition: ToolBar.cpp:129
ToolDock * GetDock()
Definition: ToolBar.cpp:565
virtual ~ToolBar()
Definition: ToolBar.cpp:339
DEFINE_EVENT_TYPE(EVT_OPEN_AUDIO_FILE)
Custom events.
static void SetButtonToolTip(AButton &button, const LocalizedCommandNameVector &commands)
Definition: ToolBar.cpp:828
bool AcceptsFocusFromKeyboard() const override
Definition: ToolBar.cpp:75
virtual int GetInitialWidth()
Resizable toolbars should implement these.
Definition: ToolBar.h:129
#define toolbarGap
Definition: ToolBar.h:59
int GetResizeGrabberWidth()
Returns the width in pixels of the resizer element.
Definition: ToolBar.cpp:894
wxString label
Definition: Tags.cpp:727
wxBoxSizer * mHSizer
Definition: ToolBar.h:230
#define toolbarSingle
Definition: ToolBar.h:54
bool IsPositioned()
Definition: ToolBar.h:123
std::unique_ptr< wxImage > OverlayImage(wxImage *background, wxImage *foreground, wxImage *mask, int xoff, int yoff)
virtual bool Expose(bool show=true)
Definition: ToolBar.cpp:416
int teBmps
Definition: Theme.h:28
void Detach(wxWindow *window)
Definition: ToolBar.cpp:682
friend class ToolBarResizer
Definition: ToolBar.h:241
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:770
static void Dark(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:338
#define safenew
Definition: Audacity.h:223
int mType
Definition: ToolBar.h:221
void ReplaceImage(int iIndex, wxImage *pImage)
Replaces both the image and the bitmap.
Definition: Theme.cpp:1270
wxString mLabel
Definition: ToolBar.h:219
wxString GetLabel()
Definition: ToolBar.cpp:355
wxString mSection
Definition: ToolBar.h:220
void OnLeftUp(wxMouseEvent &event)
Definition: ToolBar.cpp:176
void OnKeyDown(wxKeyEvent &event)
Definition: ToolBar.cpp:274
void AddSpacer(int size=14)
Definition: ToolBar.cpp:666
ToolBar * mBar
Definition: ToolBar.cpp:90
void OnPaint(wxPaintEvent &event)
Definition: ToolBar.cpp:137
wxFileConfig * gPrefs
Definition: Prefs.cpp:72
END_EVENT_TABLE()
virtual void Populate()=0
ToolBarResizer(ToolBar *mBar)
Definition: ToolBar.cpp:113
void OnErase(wxEraseEvent &event)
Definition: ToolBar.cpp:858
Grabber * mGrabber
Definition: ToolBar.h:227
void OnLeftDown(wxMouseEvent &event)
Definition: ToolBar.cpp:161
bool IsVisible() const
Definition: ToolBar.cpp:403
bool mVisible
Definition: ToolBar.h:232
void OnMotion(wxMouseEvent &event)
Definition: ToolBar.cpp:207
ToolBarResizer * mResizer
Definition: ToolBar.h:228
std::vector< LocalizedCommandName > LocalizedCommandNameVector
Definition: ToolBar.h:160
#define RWIDTH
ToolBarResizer.
Definition: ToolBar.cpp:64
virtual ~ToolBarResizer()
Definition: ToolBar.cpp:120
wxImage & Image(int iIndex)
Definition: Theme.cpp:1234
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:616
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:443
wxString GetSection()
Definition: ToolBar.cpp:363
void ResizeBar(const wxSize &size)
Definition: ToolBar.cpp:251
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:122
void OnPaint(wxPaintEvent &event)
Definition: ToolBar.cpp:866
void Updated()
Definition: ToolBar.cpp:597
void OnMouseEvents(wxMouseEvent &event)
Definition: ToolBar.cpp:887
void MakeRecoloredImage(teBmps eBmpOut, teBmps eBmpIn)
Definition: ToolBar.cpp:700
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop"))), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom"))), OnMoveTrack) void TrackMenuTable::OnSetName(wxCommandEvent &)
void SetPositioned()
Definition: ToolBar.h:125
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:803
wxWindow * mParent
Definition: ToolBar.h:225
void OnEnter(wxMouseEvent &event)
Definition: ToolBar.cpp:190
void SetLabel(const wxString &label)
Definition: ToolBar.cpp:379
void OnLeave(wxMouseEvent &event)
Definition: ToolBar.cpp:201
wxWindow * mOrigFocus
Definition: ToolBar.cpp:93
void AddStretchSpacer(int prop=1)
Definition: ToolBar.cpp:674
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:300
wxString GetTitle()
Definition: ToolBar.cpp:346
int GetType()
Definition: ToolBar.cpp:371
The widget to the left of a ToolBar that allows it to be dragged around to NEW positions.
Definition: Grabber.h:97
void SetButton(bool down, AButton *button)
Definition: ToolBar.cpp:843
void Updated()
Definition: ToolDock.cpp:854
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1208
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"))
virtual void Repaint(wxDC *dc)=0
bool IsResizable() const
Definition: ToolBar.cpp:387
void OnCaptureLost(wxMouseCaptureLostEvent &event)
Definition: ToolBar.cpp:263
void PushButton(bool state)
Definition: Grabber.cpp:184
wxPoint mResizeStart
Definition: ToolBar.cpp:91
void SetDocked(ToolDock *dock, bool pushed)
Definition: ToolBar.cpp:573
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:695
A wxButton with mouse-over behaviour.
Definition: AButton.h:27