Audacity 3.2.0
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
28#include "ToolBar.h"
29
30// For compilers that support precompilation, includes "wx/wx.h".
31#include <wx/wxprec.h>
32
33#include <wx/setup.h> // for wxUSE_* macros
34
35#ifndef WX_PRECOMP
36#include <wx/dcclient.h>
37#include <wx/defs.h>
38#include <wx/gdicmn.h>
39#include <wx/image.h>
40#include <wx/intl.h>
41#include <wx/settings.h>
42#include <wx/sizer.h>
43#include <wx/sysopt.h>
44#include <wx/window.h>
45#endif /* */
46
47#include "ToolDock.h"
48
49#include "AllThemeResources.h"
50#include "AColor.h"
51#include "ImageManipulation.h"
52#include "Project.h"
53#include "../commands/CommandManager.h"
54#include "../widgets/AButton.h"
55#include "../widgets/Grabber.h"
56#include "Prefs.h"
57
61
62//
63// Width of the resize grab area
64//
65#define RWIDTH 4
66
70class ToolBarResizer final : public wxWindow
71{
72public:
74 virtual ~ToolBarResizer();
75
76 // We don't need or want to accept focus.
77 // Note that AcceptsFocusFromKeyboard() is overridden rather than
78 // AcceptsFocus(), so that resize can be cancelled by ESC
79 bool AcceptsFocusFromKeyboard() const override {return false;}
80
81private:
82 void OnErase(wxEraseEvent & event);
83 void OnPaint(wxPaintEvent & event);
84 void OnLeftDown(wxMouseEvent & event);
85 void OnLeftUp(wxMouseEvent & event);
86 void OnEnter(wxMouseEvent & event);
87 void OnLeave(wxMouseEvent & event);
88 void OnMotion(wxMouseEvent & event);
89 void ResizeBar(const wxSize &size);
90 void OnCaptureLost(wxMouseCaptureLostEvent & event);
91 void OnKeyDown(wxKeyEvent &event);
92
93private:
96 wxSize mOrigSize;
97 wxWindowRef mOrigFocus{};
98
99 DECLARE_EVENT_TABLE()
100};
101
102//
103// Event table
104//
105BEGIN_EVENT_TABLE( ToolBarResizer, wxWindow )
106 EVT_ERASE_BACKGROUND( ToolBarResizer::OnErase )
107 EVT_PAINT( ToolBarResizer::OnPaint )
108 EVT_LEFT_DOWN( ToolBarResizer::OnLeftDown )
109 EVT_LEFT_UP( ToolBarResizer::OnLeftUp )
110 EVT_ENTER_WINDOW( ToolBarResizer::OnEnter )
111 EVT_LEAVE_WINDOW( ToolBarResizer::OnLeave )
112 EVT_MOTION( ToolBarResizer::OnMotion )
113 EVT_MOUSE_CAPTURE_LOST( ToolBarResizer::OnCaptureLost )
114 EVT_KEY_DOWN( ToolBarResizer::OnKeyDown )
116
118: wxWindow(bar, wxID_ANY, wxDefaultPosition, wxSize(RWIDTH, -1))
119{
120 mBar = bar;
121 SetCursor( wxCURSOR_SIZEWE );
122}
123
125{
126 if(HasCapture())
127 ReleaseMouse();
128}
129
130//
131// Handle background erasure
132//
133void ToolBarResizer::OnErase( wxEraseEvent & WXUNUSED(event) )
134{
135 // Ignore it to prevent flashing
136}
137
138//
139// This draws the background of a toolbar
140//
141void ToolBarResizer::OnPaint( wxPaintEvent & event )
142{
143 wxPaintDC dc( (wxWindow *) event.GetEventObject() );
144
145 // Start with a clean background
146 //
147 // Under GTK, we specifically set the toolbar background to the background
148 // colour in the system theme.
149#if defined( __WXGTK__ )
150// dc.SetBackground( wxBrush( wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND ) ) );
151#endif
152 dc.SetBackground( wxBrush( theTheme.Colour( clrMedium ) ) );
153 dc.Clear();
154
155 wxSize sz = GetSize();
156
157 AColor::Dark( &dc, false );
158 AColor::Line(dc, sz.x - 4, 0, sz.x - 4, sz.y );
159 AColor::Line(dc, sz.x - 1, 0, sz.x - 1, sz.y );
160}
161
162//
163// Handle toolbar resizing
164//
165void ToolBarResizer::OnLeftDown( wxMouseEvent & event )
166{
167 // Go ahead and set the event to propagate
168 event.Skip();
169
170 // Retrieve the mouse position
171 // Bug 1896: This is at time of processing the event, rather than at time
172 // of generation of event. Works around event.GetPosition() giving
173 // incorrect values if position of resizer is changing.
174 mResizeOffset = wxGetMousePosition()-mBar->GetRect().GetBottomRight();
175
176 mOrigSize = mBar->GetSize();
177
178 // We want all of the mouse events
179 if( !HasCapture() )
180 CaptureMouse();
181}
182
183void ToolBarResizer::OnLeftUp( wxMouseEvent & event )
184{
185 // Go ahead and set the event to propagate
186 event.Skip();
187
188 if( HasCapture() )
189 {
190 ReleaseMouse();
191 if (mOrigFocus)
192 mOrigFocus->SetFocus();
193 mOrigFocus = nullptr;
195 }
196}
197
198void ToolBarResizer::OnEnter( wxMouseEvent & /*event*/ )
199{
200 // Bug 1201: On Mac, unsetting and re-setting the tooltip may be needed
201 // to make it pop up when we want it.
202 const auto text = GetToolTipText();
203 UnsetToolTip();
204 SetToolTip(text);
205 if (!mOrigFocus)
206 mOrigFocus = FindFocus();
207}
208
209void ToolBarResizer::OnLeave( wxMouseEvent & /*event*/ )
210{
211 if (!GetCapture())
212 mOrigFocus = nullptr;
213}
214
215void ToolBarResizer::OnMotion( wxMouseEvent & event )
216{
217 // Go ahead and set the event to propagate
218 event.Skip();
219
220 if( HasCapture() && event.Dragging() )
221 {
222 // Retrieve the mouse position
223 // Bug 1896: This is at time of processing the event, rather than at time
224 // of generation of event. Works around event.GetPosition() giving
225 // incorrect values if position of resizer is changing.
226 wxPoint pos = wxGetMousePosition();
227
228 wxRect r = mBar->GetRect();
229 wxSize minsz = mBar->GetMinSize();
230 wxSize maxsz = mBar->GetMaxSize();
231 wxSize psz = mBar->GetParent()->GetClientSize();
232
233 // Adjust the size based on updated mouse position.
234 r.width = ( pos.x - mResizeOffset.x ) - r.x;
235
236 // Keep it within max size, if specified
237 if( maxsz != wxDefaultSize )
238 {
239 if( r.width > maxsz.x )
240 {
241 r.width = maxsz.x;
242 }
243 if( r.height > maxsz.y )
244 {
245 r.height = maxsz.y;
246 }
247 }
248
249 // Constrain
250 if( r.width < minsz.x )
251 {
252 // Don't allow resizing to go too small
253 r.width = minsz.x;
254 }
255 else if( r.GetRight() > psz.x - 3 )
256 {
257 // Don't allow resizing to go too large
258 //
259 // The 3 magic pixels are because I'm too chicken to change the
260 // calculations in ToolDock::LayoutToolBars() even though I'm
261 // the one that set them up. :-)
262 r.SetRight( psz.x - 3 );
263 }
264
265 ResizeBar( r.GetSize() );
266 }
267}
268
270{
271 mBar->SetSize( size );
272
273 // Tell everyone we've changed sizes
274 mBar->Updated();
275
276 // Refresh our world
277 mBar->GetParent()->Refresh();
278 mBar->GetParent()->Update();
279}
280
281void ToolBarResizer::OnCaptureLost( wxMouseCaptureLostEvent & WXUNUSED(event) )
282{
283 if( HasCapture() )
284 {
285 ReleaseMouse();
286 if (mOrigFocus)
287 mOrigFocus->SetFocus();
288 mOrigFocus = nullptr;
289 }
290}
291
292void ToolBarResizer::OnKeyDown(wxKeyEvent &event)
293{
294 event.Skip();
295 if (HasCapture() && WXK_ESCAPE == event.GetKeyCode()) {
297 ReleaseMouse();
298 if (mOrigFocus)
299 mOrigFocus->SetFocus();
300 mOrigFocus = nullptr;
301 }
302}
303
307
308//
309// Define class to RTTI
310//
312
313//
314// Custom event
315//
316DEFINE_EVENT_TYPE(EVT_TOOLBAR_UPDATED)
317
318//
319// Event table
320//
321BEGIN_EVENT_TABLE( ToolBar, wxPanelWrapper )
322 EVT_PAINT( ToolBar::OnPaint )
323 EVT_ERASE_BACKGROUND( ToolBar::OnErase )
324 EVT_MOUSE_EVENTS( ToolBar::OnMouseEvents )
326
327//
328// Constructor
329//
331 int type,
333 const wxString &section,
334 bool resizable )
336, mProject{ project }
337{
338 // Save parameters
339 mType = type;
340 mLabel = label;
341 mSection = section;
342 mResizable = resizable;
343
344 // Initialize everything
345 mParent = NULL;
346 mHSizer = NULL;
347 mVisible = false;
348 mPositioned = false;
349
350 mGrabber = NULL;
351 mResizer = NULL;
352 SetId(mType);
353}
354
355//
356// Destructor
357//
359{
360}
361
362//
363// Returns the toolbar title
364//
366{
367 /* i18n-hint: %s will be replaced by the name of the kind of toolbar.*/
368 return XO("Audacity %s Toolbar").Format( GetLabel() );
369}
370
371//
372// Returns the toolbar label
373//
375{
376 return mLabel;
377}
378
379//
380// Returns the toolbar preferences section
381//
383{
384 return mSection;
385}
386
387//
388// Returns the toolbar type
389//
391{
392 return mType;
393}
394
395//
396// Set the toolbar label
397//
398void ToolBar::SetLabel(const wxString & label)
399{
400 // Probably shouldn't reach this overload, but perhaps virtual function
401 // dispatch will take us here from a pointer to the wxPanel base class
402 mLabel = Verbatim( label );
403}
404
406{
407 // Only this overload is publicly accessible when you have a pointer to
408 // Toolbar or a subclass of it
409 mLabel = label;
410}
411
412//
413// Returns whether the toolbar is resizable or not
414//
416{
417 return mResizable;
418}
419
420//
421// Returns the dock state of the toolbar
422//
424{
425 return const_cast<ToolBar*>(this)->GetDock() != nullptr;
426}
427
428//
429// Returns the visibility of the toolbar
430//
432{
433 return mVisible;
434}
435
436void ToolBar::SetVisible( bool bVisible )
437{
438 mVisible = bVisible;
439}
440
441//
442// Show or hide the toolbar
443//
444bool ToolBar::Expose( bool show )
445{
446 bool was = mVisible;
447
448 SetVisible( show );
449
450 if( IsDocked() )
451 {
452 Show( show );
453 if( show )
454 {
455 Refresh();
456 }
457 }
458 else
459 {
460 wxWindow * pParent = GetParent();
461 if( !IsPositioned() && show ){
463 pParent->CentreOnParent();
464 pParent->Move( pParent->GetPosition() + wxSize( mType*10, mType*10 ));
465 }
466 pParent->Show( show );
467 }
468
469 return was;
470}
471
472//
473// Initialize the toolbar
474//
475void ToolBar::Create( wxWindow *parent )
476{
477 // Save parameters
478 mParent = parent;
479
480 // Create the window and label it
482 mType,
483 wxDefaultPosition,
484 wxDefaultSize,
485 wxNO_BORDER | wxTAB_TRAVERSAL,
486 GetTitle() );
488
489 // Go do the rest of the creation
491
492 // ToolManager depends on this appearing to be visible for proper dock construction
493 mVisible = true;
494}
495
497 wxSize sz;
498 sz.SetHeight( -1 );
499 sz.SetWidth( GetInitialWidth());
500 SetSize( sz );
501}
502
504{
505 const int tbs = toolbarSingle + toolbarGap;
506 wxSize sz = GetSize();
507 // 46 is the size where we switch from expanded to compact.
508 if( sz.y < 46 )
509 sz.y = tbs-1;
510 else
511 sz.y = 2 * tbs -1;
512 return sz;
513}
514
515
517{
518 wxSize sz3 = GetSize();
519 //wxLogDebug( "x:%i y:%i",sz3.x, sz3.y);
520
521 // SetSizer(NULL) detaches mHSizer and deletes it.
522 // Do not use Detach() here, as that attempts to detach mHSizer from itself!
523 SetSizer( NULL );
524
525 // Get rid of any children we may have
526 DestroyChildren();
527 mGrabber = NULL;
528 mResizer = NULL;
529 SetLayoutDirection(wxLayout_LeftToRight);
530
531 // Refresh the background before populating
532 if (!IsDocked())
533 {
534 GetParent()->Refresh();
535 }
536
537 {
538 // Create the main sizer
539 auto ms = std::make_unique<wxBoxSizer>(wxHORIZONTAL);
540
541 // Create the grabber and add it to the main sizer
542 mGrabber = safenew Grabber(this, mType);
543 ms->Add(mGrabber, 0, wxEXPAND | wxALIGN_LEFT | wxALIGN_TOP | wxRIGHT, 1);
544
545 // Use a box sizer for laying out controls
546 ms->Add((mHSizer = safenew wxBoxSizer(wxHORIZONTAL)), 1, wxEXPAND);
547
548 // Go add all the rest of the gadgets
549 Populate();
550
551 // Add some space for the resize border
552 if (IsResizable())
553 {
554 // Create the resizer and add it to the main sizer
556 ms->Add(mResizer, 0, wxEXPAND | wxALIGN_TOP | wxLEFT, 1);
557 mResizer->SetToolTip(_("Click and drag to resize toolbar"));
558 }
559
560 // Set dock after possibly creating resizer.
561 // (Re)Establish dock state
562 SetDocked(GetDock(), false);
563
564 // Set the sizer
565 SetSizerAndFit(ms.release());
566 }
567
568 // Recalculate the height to be a multiple of toolbarSingle
569 const int tbs = toolbarSingle + toolbarGap;
570 wxSize sz = GetSize();
571 sz.y = ( ( ( sz.y + tbs -1) / tbs ) * tbs ) - 1;
572
573 // Set the true AND minimum sizes and do final layout
574 if(IsResizable())
575 {
576 // JKC we're going to allow all resizable toolbars to be resized
577 // to 1 unit high, typically 27 pixels.
578 wxSize sz2 = sz;
579 sz2.SetWidth(GetMinToolbarWidth());
580 sz2.y = tbs -1;
581 SetMinSize(sz2);
582
583 // sz2 is now the minimum size.
584 // sz3 is the size we were.
585
586 // We're recreating buttons, and we want to preserve original size.
587 // But not if that makes the size too small.
588
589 // Size at least as big as minimum.
590 if( sz3.y < sz2.y )
591 sz3.y = sz2.y;
592 if( sz3.x < sz2.x )
593 sz3.x = sz2.x;
594 SetSize(sz3);
595 }
596 else
597 {
598 SetInitialSize(sz);
599 }
600 Layout();
601}
602
603// The application preferences have changed, so update any elements that may
604// depend on them.
606{
607#if wxUSE_TOOLTIPS
608 // Change the tooltip of the grabber
609 if ( mGrabber )
610 {
612 }
613
614 // Change the tooltip of the resizer
615 if ( mResizer )
616 {
617 mResizer->SetToolTip( _("Click and drag to resize toolbar") );
618 wxSizeEvent e;
619 GetParent()->GetEventHandler()->AddPendingEvent( e );
620 GetParent()->Refresh();
621 }
622#endif
623
624 return;
625}
626
627//
628// Return the pointer to the ToolBock where this bar lives
629//
631{
632 return dynamic_cast<ToolDock*>(GetParent());
633}
634
635//
636// Toggle the docked/floating state
637//
638void ToolBar::SetDocked( ToolDock *dock, bool pushed )
639{
640 // Remember it
641// mDock = dock;
642
643 // Change the tooltip of the grabber
644#if wxUSE_TOOLTIPS
646#endif
647
648 // Set the grabber button state
649 mGrabber->PushButton( pushed );
650
651 if (mResizer)
652 {
653 mResizer->Show(dock != NULL);
654 Layout();
655 }
656}
657
658//
659// Notify parent of changes
660//
662{
663 if( IsDocked() )
664 GetDock()->Updated();
665 else
666 // Bug 2120. Changing the choice also changes the size of the toolbar so
667 // we need to update the client size, even if undocked.
668 // If modifying/improving this, remember to test both changing the choice,
669 // and clicking on the choice but not actually changing it.
670 GetParent()->SetClientSize( GetSize() + wxSize( 2,2));
671 //wxCommandEvent e( EVT_TOOLBAR_UPDATED, GetId() );
672 //GetParent()->GetEventHandler()->AddPendingEvent( e );
673}
674
675//
676// Returns a pointer to the main sizer
677//
678wxBoxSizer *ToolBar::GetSizer()
679{
680 return mHSizer;
681}
682
683//
684// Add a window to the main sizer
685//
686void ToolBar::Add( wxWindow *window,
687 int proportion,
688 int flag,
689 int border,
690 wxObject* userData )
691{
692 mHSizer->Add( window,
693 proportion,
694 flag,
695 border,
696 userData );
697}
698
699//
700// Add a child sizer to the main sizer
701//
702void ToolBar::Add( wxSizer *sizer,
703 int proportion,
704 int flag,
705 int border,
706 wxObject* userData )
707{
708 mHSizer->Add( sizer,
709 proportion,
710 flag,
711 border,
712 userData );
713}
714
715//
716// Add some space to the main sizer
717//
718void ToolBar::Add( int width,
719 int height,
720 int proportion,
721 int flag,
722 int border,
723 wxObject* userData )
724{
725 mHSizer->Add( width,
726 height,
727 proportion,
728 flag,
729 border,
730 userData );
731}
732
733//
734// Adds a spacer to the main sizer
735//
737{
738 mHSizer->AddSpacer( size );
739}
740
741//
742// Adds a strechable spacer to the main sizer
743//
745{
746 mHSizer->AddStretchSpacer( prop );
747}
748
749//
750// Detach a window from the main sizer
751//
752void ToolBar::Detach( wxWindow *window )
753{
754 mHSizer->Detach( window );
755}
756
757//
758// Detach a child sizer from the main sizer
759//
760void ToolBar::Detach( wxSizer *sizer )
761{
762 mHSizer->Detach( sizer );
763}
764
766{
767 theTheme.ReplaceImage( eBmpOut, &theTheme.Image( eBmpIn ));
768}
769
770void ToolBar::MakeMacRecoloredImageSize(teBmps eBmpOut, teBmps eBmpIn, const wxSize& size)
771{
772 MakeMacRecoloredImage( eBmpOut, eBmpIn );
773 theTheme.Image( eBmpOut ).Rescale( size.GetWidth(), size.GetHeight() );
774}
775
777{
778 // Don't recolour the buttons...
779 MakeMacRecoloredImage( eBmpOut, eBmpIn );
780}
781
782void ToolBar::MakeRecoloredImageSize(teBmps eBmpOut, teBmps eBmpIn, const wxSize& size)
783{
784 MakeRecoloredImage( eBmpOut, eBmpIn );
785 theTheme.Image( eBmpOut ).Rescale( size.GetWidth(), size.GetHeight() );
786}
787
789{
790
791 bool bUseAqua = false;
792
793#ifdef EXPERIMENTAL_THEME_PREFS
794 gPrefs->Read( wxT("/GUI/ShowMac"), &bUseAqua, false);
795#endif
796
797#ifdef USE_AQUA_THEME
798 bUseAqua = !bUseAqua;
799#endif
800
801 if( bUseAqua ){
802 MakeMacRecoloredImage( bmpRecoloredUpLarge, bmpMacUpButton );
803 MakeMacRecoloredImage( bmpRecoloredDownLarge, bmpMacDownButton );
804 MakeMacRecoloredImage( bmpRecoloredUpHiliteLarge, bmpMacHiliteUpButton );
805 MakeMacRecoloredImage( bmpRecoloredHiliteLarge, bmpMacHiliteButton );
806 } else {
807 MakeRecoloredImage( bmpRecoloredUpLarge, bmpUpButtonLarge );
808 MakeRecoloredImage( bmpRecoloredDownLarge, bmpDownButtonLarge );
809 MakeRecoloredImage( bmpRecoloredUpHiliteLarge, bmpHiliteUpButtonLarge );
810 MakeRecoloredImage( bmpRecoloredHiliteLarge, bmpHiliteButtonLarge );
811 }
812}
813
815{
816
817 bool bUseAqua = false;
818
819#ifdef EXPERIMENTAL_THEME_PREFS
820 gPrefs->Read( wxT("/GUI/ShowMac"), &bUseAqua, false);
821#endif
822
823#ifdef USE_AQUA_THEME
824 bUseAqua = !bUseAqua;
825#endif
826
827 if( bUseAqua ){
828 MakeMacRecoloredImage( bmpRecoloredUpSmall, bmpMacUpButtonSmall );
829 MakeMacRecoloredImage( bmpRecoloredDownSmall, bmpMacDownButtonSmall );
830 MakeMacRecoloredImage( bmpRecoloredUpHiliteSmall, bmpMacHiliteUpButtonSmall );
831 MakeMacRecoloredImage( bmpRecoloredHiliteSmall, bmpMacHiliteButtonSmall );
832 } else {
833 MakeRecoloredImage( bmpRecoloredUpSmall, bmpUpButtonSmall );
834 MakeRecoloredImage( bmpRecoloredDownSmall, bmpDownButtonSmall );
835 MakeRecoloredImage( bmpRecoloredUpHiliteSmall, bmpHiliteUpButtonSmall );
836 MakeRecoloredImage( bmpRecoloredHiliteSmall, bmpHiliteButtonSmall );
837 }
838}
839
852AButton * ToolBar::MakeButton(wxWindow *parent,
853 teBmps eUp,
854 teBmps eDown,
855 teBmps eHilite,
856 teBmps eDownHi,
857 teBmps eStandardUp,
858 teBmps eStandardDown,
859 teBmps eDisabled,
860 wxWindowID id,
861 wxPoint placement,
862 bool processdownevents,
863 wxSize size)
864{
865 // wxMax to cater for case of image being bigger than the button.
866 int xoff = wxMax( 0, (size.GetWidth() - theTheme.Image(eStandardUp).GetWidth())/2);
867 int yoff = wxMax( 0, (size.GetHeight() - theTheme.Image(eStandardUp).GetHeight())/2);
868
869 typedef std::unique_ptr<wxImage> wxImagePtr;
870 wxImagePtr up2 (OverlayImage(eUp, eStandardUp, xoff, yoff));
871 wxImagePtr hilite2 (OverlayImage(eHilite, eStandardUp, xoff, yoff));
872 wxImagePtr down2 (OverlayImage(eDown, eStandardDown, xoff + 1, yoff + 1));
873 wxImagePtr downHi2 (OverlayImage(eDownHi, eStandardDown, xoff + 1, yoff + 1));
874 wxImagePtr disable2 (OverlayImage(eUp, eDisabled, xoff, yoff));
875
876 wxASSERT(parent); // to justify safenew
877 AButton * button =
878 safenew AButton(parent, id, placement, size, *up2, *hilite2, *down2, *downHi2,
879 *disable2, processdownevents);
880
881 return button;
882}
883
884// This is a convenience function that allows for button creation in
885// MakeButtons() with fewer arguments
894 teBmps eEnabledUp,
895 teBmps eEnabledDown,
896 teBmps eDisabled,
897 int id,
898 bool processdownevents,
900{
901 AButton *r = ToolBar::MakeButton(parent,
902 bmpRecoloredUpLarge, bmpRecoloredDownLarge, bmpRecoloredUpHiliteLarge, bmpRecoloredHiliteLarge,
903 eEnabledUp, eEnabledDown, eDisabled,
904 wxWindowID( id ),
905 wxDefaultPosition, processdownevents,
906 theTheme.ImageSize( bmpRecoloredUpLarge ));
907 r->SetLabel( label );
908 enum {
909 deflation =
910#ifdef __WXMAC__
911 6
912#else
913 12
914#endif
915 };
916 r->SetFocusRect( r->GetClientRect().Deflate( deflation, deflation ) );
917
918 return r;
919}
920
921//static
923 teBmps eUp,
924 teBmps eDown,
925 teBmps eHilite,
926 teBmps eDownHi,
927 teBmps eStandardUp,
928 teBmps eStandardDown,
929 teBmps eDisabled,
930 wxSize size)
931{
932 // wxMax to cater for case of image being bigger than the button.
933 int xoff = wxMax( 0, (size.GetWidth() - theTheme.Image(eStandardUp).GetWidth())/2);
934 int yoff = wxMax( 0, (size.GetHeight() - theTheme.Image(eStandardUp).GetHeight())/2);
935
936 typedef std::unique_ptr<wxImage> wxImagePtr;
937 wxImagePtr up (OverlayImage(eUp, eStandardUp, xoff, yoff));
938 wxImagePtr hilite (OverlayImage(eHilite, eStandardUp, xoff, yoff));
939 wxImagePtr down (OverlayImage(eDown, eStandardDown, xoff + 1, yoff + 1));
940 wxImagePtr downHi (OverlayImage(eDownHi, eStandardDown, xoff + 1, yoff + 1));
941 wxImagePtr disable (OverlayImage(eUp, eDisabled, xoff, yoff));
942
943 button.SetAlternateImages(idx, *up, *hilite, *down, *downHi, *disable);
944}
945
947(AudacityProject &theProject,
948 AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
949{
950 TranslatableString result;
951 const auto project = &theProject;
952 const auto commandManager =
953 project ? &CommandManager::Get( *project ) : nullptr;
954 if (commandManager)
955 result =
956 commandManager->DescribeCommandsAndShortcuts(commands, nCommands);
957 button.SetToolTip( result );
958}
959
960//
961// This changes the state a button (from up to down or vice versa)
962//
963void ToolBar::SetButton( bool down, AButton * button )
964{
965 if( down )
966 {
967 button->PushDown();
968 }
969 else
970 {
971 button->PopUp();
972 }
973}
974
975//
976// Handle background erasure
977//
978void ToolBar::OnErase( wxEraseEvent & WXUNUSED(event) )
979{
980 // Ignore it to prevent flashing
981}
982
983//
984// This draws the background of a toolbar
985//
986void ToolBar::OnPaint( wxPaintEvent & WXUNUSED(event) )
987{
988 wxPaintDC dc( this );
989
990 // Themed background colour.
991 dc.SetBackground( wxBrush( theTheme.Colour( clrMedium ) ) );
992 dc.Clear();
993
994 Repaint( &dc );
995}
996
997void ToolBar::OnMouseEvents(wxMouseEvent &event)
998{
999 // Do this hack so scrubber can detect mouse drags anywhere
1000 event.ResumePropagation(wxEVENT_PROPAGATE_MAX);
1001 event.Skip();
1002}
1003
1005{
1006 return RWIDTH;
1007}
1008
1009namespace {
1010
1012{
1014 return factories;
1015}
1016
1017}
1018
1020 int id, const Function &function)
1021{
1022 wxASSERT( id >= 0 && id < ToolBarCount );
1023 GetFunctions()[ id ] = function;
1024}
1025
1027{
1028 return GetFunctions();
1029}
wxT("CloseDown"))
DEFINE_EVENT_TYPE(EVT_FREQWINDOW_RECALC)
std::unique_ptr< wxImage > OverlayImage(wxImage *background, wxImage *foreground, wxImage *mask, int xoff, int yoff)
int teBmps
#define XO(s)
Definition: Internat.h:31
#define _(s)
Definition: Internat.h:75
#define safenew
Definition: MemoryX.h:10
FileConfig * gPrefs
Definition: Prefs.cpp:71
TranslatableString label
Definition: TagsEditor.cpp:163
THEME_API Theme theTheme
Definition: Theme.cpp:82
END_EVENT_TABLE()
IMPLEMENT_CLASS(ToolBar, wxPanelWrapper)
Methods for ToolBar.
#define RWIDTH
ToolBarResizer.
Definition: ToolBar.cpp:65
#define toolbarSingle
Definition: ToolBar.h:59
#define toolbarGap
Definition: ToolBar.h:64
@ ToolBarCount
Definition: ToolBar.h:90
TranslatableString Verbatim(wxString str)
Require calls to the one-argument constructor to go through this distinct global function name.
int id
static std::once_flag flag
A wxButton with mouse-over behaviour.
Definition: AButton.h:26
void PushDown()
Definition: AButton.cpp:642
void SetToolTip(const TranslatableString &toolTip)
Definition: AButton.cpp:262
void SetFocusRect(const wxRect &r)
Definition: AButton.cpp:327
void PopUp()
Definition: AButton.cpp:650
void SetAlternateImages(unsigned idx, const wxImage &up, const wxImage &over, const wxImage &down, const wxImage &overDown, const wxImage &dis)
Definition: AButton.cpp:288
void SetLabel(const TranslatableString &label)
Definition: AButton.cpp:267
static void Line(wxDC &dc, wxCoord x1, wxCoord y1, wxCoord x2, wxCoord y2)
Definition: AColor.cpp:187
static void Dark(wxDC *dc, bool selected, bool highlight=false)
Definition: AColor.cpp:443
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:89
static CommandManager & Get(AudacityProject &project)
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
The widget to the left of a ToolBar that allows it to be dragged around to NEW positions.
Definition: Grabber.h:103
void SetToolTip(const TranslatableString &toolTip)
Definition: Grabber.cpp:110
void PushButton(bool state)
Definition: Grabber.cpp:188
wxColour & Colour(int iIndex)
wxImage & Image(int iIndex)
void ReplaceImage(int iIndex, wxImage *pImage)
wxSize ImageSize(int iIndex)
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:101
int mType
Definition: ToolBar.h:253
virtual ~ToolBar()
Definition: ToolBar.cpp:358
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:922
friend class ToolBarResizer
Definition: ToolBar.h:273
bool mVisible
Definition: ToolBar.h:264
bool IsDocked() const
Definition: ToolBar.cpp:423
virtual void Populate()=0
wxSize GetSmartDockedSize()
Definition: ToolBar.cpp:503
static void MakeRecoloredImageSize(teBmps eBmpOut, teBmps eBmpIn, const wxSize &size)
Definition: ToolBar.cpp:782
wxWindow * mParent
Definition: ToolBar.h:257
static void MakeMacRecoloredImage(teBmps eBmpOut, teBmps eBmpIn)
Definition: ToolBar.cpp:765
void Add(wxWindow *window, int proportion=0, int flag=wxALIGN_TOP, int border=0, wxObject *userData=NULL)
Definition: ToolBar.cpp:686
virtual void SetDocked(ToolDock *dock, bool pushed)
Definition: ToolBar.cpp:638
virtual int GetMinToolbarWidth()
Definition: ToolBar.h:147
virtual void ReCreateButtons()
Definition: ToolBar.cpp:516
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:852
void SetVisible(bool bVisible)
Definition: ToolBar.cpp:436
TranslatableString mLabel
Definition: ToolBar.h:251
bool IsResizable() const
Definition: ToolBar.cpp:415
void AddSpacer(int size=14)
Definition: ToolBar.cpp:736
wxString GetSection()
Definition: ToolBar.cpp:382
void SetLabel(const wxString &label) override
Definition: ToolBar.cpp:398
TranslatableString GetTitle()
Definition: ToolBar.cpp:365
static void MakeButtonBackgroundsLarge()
Definition: ToolBar.cpp:788
virtual void ResizingDone()
Definition: ToolBar.h:199
wxBoxSizer * mHSizer
Definition: ToolBar.h:262
ToolDock * GetDock()
Definition: ToolBar.cpp:630
void OnPaint(wxPaintEvent &event)
Definition: ToolBar.cpp:986
bool IsPositioned()
Definition: ToolBar.h:140
void SetButton(bool down, AButton *button)
Definition: ToolBar.cpp:963
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:814
void SetPositioned()
Definition: ToolBar.h:142
void AddStretchSpacer(int prop=1)
Definition: ToolBar.cpp:744
bool mResizable
Definition: ToolBar.h:265
virtual int GetInitialWidth()
Resizable toolbars should implement these.
Definition: ToolBar.h:146
bool IsVisible() const
Definition: ToolBar.cpp:431
virtual bool Expose(bool show=true)
Definition: ToolBar.cpp:444
wxBoxSizer * GetSizer()
Definition: ToolBar.cpp:678
virtual void SetToDefaultSize()
Definition: ToolBar.cpp:496
void UpdatePrefs() override
Definition: ToolBar.cpp:605
int GetResizeGrabberWidth()
Returns the width in pixels of the resizer element.
Definition: ToolBar.cpp:1004
static void MakeMacRecoloredImageSize(teBmps eBmpOut, teBmps eBmpIn, const wxSize &size)
Definition: ToolBar.cpp:770
virtual void Repaint(wxDC *dc)=0
Grabber * mGrabber
Definition: ToolBar.h:259
ToolBarResizer * mResizer
Definition: ToolBar.h:260
void Updated()
Definition: ToolBar.cpp:661
int GetType()
Definition: ToolBar.cpp:390
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:475
void OnMouseEvents(wxMouseEvent &event)
Definition: ToolBar.cpp:997
TranslatableString GetLabel()
Definition: ToolBar.cpp:374
wxString mSection
Definition: ToolBar.h:252
void Detach(wxWindow *window)
Definition: ToolBar.cpp:752
void OnErase(wxEraseEvent &event)
Definition: ToolBar.cpp:978
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:947
static void MakeRecoloredImage(teBmps eBmpOut, teBmps eBmpIn)
Definition: ToolBar.cpp:776
a wxWindow that provides the resizer for a toolbar on the right hand side. Responsible for drawing th...
Definition: ToolBar.cpp:71
ToolBar * mBar
Definition: ToolBar.cpp:94
wxWindowRef mOrigFocus
Definition: ToolBar.cpp:97
ToolBarResizer(ToolBar *mBar)
Definition: ToolBar.cpp:117
void OnLeave(wxMouseEvent &event)
Definition: ToolBar.cpp:209
bool AcceptsFocusFromKeyboard() const override
Definition: ToolBar.cpp:79
void OnMotion(wxMouseEvent &event)
Definition: ToolBar.cpp:215
virtual ~ToolBarResizer()
Definition: ToolBar.cpp:124
void OnCaptureLost(wxMouseCaptureLostEvent &event)
Definition: ToolBar.cpp:281
void OnKeyDown(wxKeyEvent &event)
Definition: ToolBar.cpp:292
wxSize mOrigSize
Definition: ToolBar.cpp:96
void ResizeBar(const wxSize &size)
Definition: ToolBar.cpp:269
void OnLeftDown(wxMouseEvent &event)
Definition: ToolBar.cpp:165
void OnLeftUp(wxMouseEvent &event)
Definition: ToolBar.cpp:183
void OnErase(wxEraseEvent &event)
Definition: ToolBar.cpp:133
wxPoint mResizeOffset
Definition: ToolBar.cpp:95
void OnPaint(wxPaintEvent &event)
Definition: ToolBar.cpp:141
void OnEnter(wxMouseEvent &event)
Definition: ToolBar.cpp:198
A dynamic panel where a ToolBar can be docked.
Definition: ToolDock.h:290
void Updated()
Definition: ToolDock.cpp:853
Holds a msgid for the translation catalog; may also bind format arguments.
void SetLabel(const TranslatableString &label)
bool Create(wxWindow *parent, wxWindowID winid=wxID_ANY, const wxPoint &pos=wxDefaultPosition, const wxSize &size=wxDefaultSize, long style=wxTAB_TRAVERSAL|wxNO_BORDER, const TranslatableString &name=XO("Panel"))
RegisteredToolbarFactory::Functions & GetFunctions()
Definition: ToolBar.cpp:1011
std::vector< Function > Functions
Definition: ToolBar.h:278
std::function< ToolBar::Holder(AudacityProject &) > Function
Definition: ToolBar.h:277
static const Functions & GetFactories()
Definition: ToolBar.cpp:1026
RegisteredToolbarFactory(int id, const Function &function)
Definition: ToolBar.cpp:1019