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
771{
772 // Don't recolour the buttons...
773 MakeMacRecoloredImage( eBmpOut, eBmpIn );
774}
775
777{
778
779 bool bUseAqua = false;
780
781#ifdef EXPERIMENTAL_THEME_PREFS
782 gPrefs->Read( wxT("/GUI/ShowMac"), &bUseAqua, false);
783#endif
784
785#ifdef USE_AQUA_THEME
786 bUseAqua = !bUseAqua;
787#endif
788
789 if( bUseAqua ){
790 MakeMacRecoloredImage( bmpRecoloredUpLarge, bmpMacUpButton );
791 MakeMacRecoloredImage( bmpRecoloredDownLarge, bmpMacDownButton );
792 MakeMacRecoloredImage( bmpRecoloredUpHiliteLarge, bmpMacHiliteUpButton );
793 MakeMacRecoloredImage( bmpRecoloredHiliteLarge, bmpMacHiliteButton );
794 } else {
795 MakeRecoloredImage( bmpRecoloredUpLarge, bmpUpButtonLarge );
796 MakeRecoloredImage( bmpRecoloredDownLarge, bmpDownButtonLarge );
797 MakeRecoloredImage( bmpRecoloredUpHiliteLarge, bmpHiliteUpButtonLarge );
798 MakeRecoloredImage( bmpRecoloredHiliteLarge, bmpHiliteButtonLarge );
799 }
800}
801
803{
804
805 bool bUseAqua = false;
806
807#ifdef EXPERIMENTAL_THEME_PREFS
808 gPrefs->Read( wxT("/GUI/ShowMac"), &bUseAqua, false);
809#endif
810
811#ifdef USE_AQUA_THEME
812 bUseAqua = !bUseAqua;
813#endif
814
815 if( bUseAqua ){
816 MakeMacRecoloredImage( bmpRecoloredUpSmall, bmpMacUpButtonSmall );
817 MakeMacRecoloredImage( bmpRecoloredDownSmall, bmpMacDownButtonSmall );
818 MakeMacRecoloredImage( bmpRecoloredUpHiliteSmall, bmpMacHiliteUpButtonSmall );
819 MakeMacRecoloredImage( bmpRecoloredHiliteSmall, bmpMacHiliteButtonSmall );
820 } else {
821 MakeRecoloredImage( bmpRecoloredUpSmall, bmpUpButtonSmall );
822 MakeRecoloredImage( bmpRecoloredDownSmall, bmpDownButtonSmall );
823 MakeRecoloredImage( bmpRecoloredUpHiliteSmall, bmpHiliteUpButtonSmall );
824 MakeRecoloredImage( bmpRecoloredHiliteSmall, bmpHiliteButtonSmall );
825 }
826}
827
840AButton * ToolBar::MakeButton(wxWindow *parent,
841 teBmps eUp,
842 teBmps eDown,
843 teBmps eHilite,
844 teBmps eDownHi,
845 teBmps eStandardUp,
846 teBmps eStandardDown,
847 teBmps eDisabled,
848 wxWindowID id,
849 wxPoint placement,
850 bool processdownevents,
851 wxSize size)
852{
853 // wxMax to cater for case of image being bigger than the button.
854 int xoff = wxMax( 0, (size.GetWidth() - theTheme.Image(eStandardUp).GetWidth())/2);
855 int yoff = wxMax( 0, (size.GetHeight() - theTheme.Image(eStandardUp).GetHeight())/2);
856
857 typedef std::unique_ptr<wxImage> wxImagePtr;
858 wxImagePtr up2 (OverlayImage(eUp, eStandardUp, xoff, yoff));
859 wxImagePtr hilite2 (OverlayImage(eHilite, eStandardUp, xoff, yoff));
860 wxImagePtr down2 (OverlayImage(eDown, eStandardDown, xoff + 1, yoff + 1));
861 wxImagePtr downHi2 (OverlayImage(eDownHi, eStandardDown, xoff + 1, yoff + 1));
862 wxImagePtr disable2 (OverlayImage(eUp, eDisabled, xoff, yoff));
863
864 wxASSERT(parent); // to justify safenew
865 AButton * button =
866 safenew AButton(parent, id, placement, size, *up2, *hilite2, *down2, *downHi2,
867 *disable2, processdownevents);
868
869 return button;
870}
871
872//static
874 teBmps eUp,
875 teBmps eDown,
876 teBmps eHilite,
877 teBmps eDownHi,
878 teBmps eStandardUp,
879 teBmps eStandardDown,
880 teBmps eDisabled,
881 wxSize size)
882{
883 // wxMax to cater for case of image being bigger than the button.
884 int xoff = wxMax( 0, (size.GetWidth() - theTheme.Image(eStandardUp).GetWidth())/2);
885 int yoff = wxMax( 0, (size.GetHeight() - theTheme.Image(eStandardUp).GetHeight())/2);
886
887 typedef std::unique_ptr<wxImage> wxImagePtr;
888 wxImagePtr up (OverlayImage(eUp, eStandardUp, xoff, yoff));
889 wxImagePtr hilite (OverlayImage(eHilite, eStandardUp, xoff, yoff));
890 wxImagePtr down (OverlayImage(eDown, eStandardDown, xoff + 1, yoff + 1));
891 wxImagePtr downHi (OverlayImage(eDownHi, eStandardDown, xoff + 1, yoff + 1));
892 wxImagePtr disable (OverlayImage(eUp, eDisabled, xoff, yoff));
893
894 button.SetAlternateImages(idx, *up, *hilite, *down, *downHi, *disable);
895}
896
898(AudacityProject &theProject,
899 AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
900{
901 TranslatableString result;
902 const auto project = &theProject;
903 const auto commandManager =
904 project ? &CommandManager::Get( *project ) : nullptr;
905 if (commandManager)
906 result =
907 commandManager->DescribeCommandsAndShortcuts(commands, nCommands);
908 button.SetToolTip( result );
909}
910
911//
912// This changes the state a button (from up to down or vice versa)
913//
914void ToolBar::SetButton( bool down, AButton * button )
915{
916 if( down )
917 {
918 button->PushDown();
919 }
920 else
921 {
922 button->PopUp();
923 }
924}
925
926//
927// Handle background erasure
928//
929void ToolBar::OnErase( wxEraseEvent & WXUNUSED(event) )
930{
931 // Ignore it to prevent flashing
932}
933
934//
935// This draws the background of a toolbar
936//
937void ToolBar::OnPaint( wxPaintEvent & WXUNUSED(event) )
938{
939 wxPaintDC dc( this );
940
941 // Themed background colour.
942 dc.SetBackground( wxBrush( theTheme.Colour( clrMedium ) ) );
943 dc.Clear();
944
945 Repaint( &dc );
946}
947
948void ToolBar::OnMouseEvents(wxMouseEvent &event)
949{
950 // Do this hack so scrubber can detect mouse drags anywhere
951 event.ResumePropagation(wxEVENT_PROPAGATE_MAX);
952 event.Skip();
953}
954
956{
957 return RWIDTH;
958}
959
960namespace {
961
963{
965 return factories;
966}
967
968}
969
971 int id, const Function &function)
972{
973 wxASSERT( id >= 0 && id < ToolBarCount );
974 GetFunctions()[ id ] = function;
975}
976
978{
979 return GetFunctions();
980}
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:87
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:25
void PushDown()
Definition: AButton.cpp:597
void SetToolTip(const TranslatableString &toolTip)
Definition: AButton.cpp:269
void SetAlternateImages(unsigned idx, ImageRoll up, ImageRoll over, ImageRoll down, ImageRoll overDown, ImageRoll dis)
Definition: AButton.cpp:304
void PopUp()
Definition: AButton.cpp:605
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:420
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)
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:98
int mType
Definition: ToolBar.h:238
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:873
friend class ToolBarResizer
Definition: ToolBar.h:258
bool mVisible
Definition: ToolBar.h:249
bool IsDocked() const
Definition: ToolBar.cpp:423
virtual void Populate()=0
wxSize GetSmartDockedSize()
Definition: ToolBar.cpp:503
wxWindow * mParent
Definition: ToolBar.h:242
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:144
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:840
void SetVisible(bool bVisible)
Definition: ToolBar.cpp:436
TranslatableString mLabel
Definition: ToolBar.h:236
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:776
virtual void ResizingDone()
Definition: ToolBar.h:186
wxBoxSizer * mHSizer
Definition: ToolBar.h:247
ToolDock * GetDock()
Definition: ToolBar.cpp:630
void OnPaint(wxPaintEvent &event)
Definition: ToolBar.cpp:937
bool IsPositioned()
Definition: ToolBar.h:137
void SetButton(bool down, AButton *button)
Definition: ToolBar.cpp:914
static void MakeButtonBackgroundsSmall()
Definition: ToolBar.cpp:802
void SetPositioned()
Definition: ToolBar.h:139
void AddStretchSpacer(int prop=1)
Definition: ToolBar.cpp:744
bool mResizable
Definition: ToolBar.h:250
virtual int GetInitialWidth()
Resizable toolbars should implement these.
Definition: ToolBar.h:143
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:955
virtual void Repaint(wxDC *dc)=0
Grabber * mGrabber
Definition: ToolBar.h:244
ToolBarResizer * mResizer
Definition: ToolBar.h:245
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:948
TranslatableString GetLabel()
Definition: ToolBar.cpp:374
wxString mSection
Definition: ToolBar.h:237
void Detach(wxWindow *window)
Definition: ToolBar.cpp:752
void OnErase(wxEraseEvent &event)
Definition: ToolBar.cpp:929
static void SetButtonToolTip(AudacityProject &project, AButton &button, const ComponentInterfaceSymbol commands[], size_t nCommands)
Definition: ToolBar.cpp:898
static void MakeRecoloredImage(teBmps eBmpOut, teBmps eBmpIn)
Definition: ToolBar.cpp:770
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:962
std::vector< Function > Functions
Definition: ToolBar.h:263
std::function< ToolBar::Holder(AudacityProject &) > Function
Definition: ToolBar.h:262
static const Functions & GetFactories()
Definition: ToolBar.cpp:977
RegisteredToolbarFactory(int id, const Function &function)
Definition: ToolBar.cpp:970