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