Audacity 3.2.0
Classes | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
ToolManager Class Referencefinal

class ToolManager More...

#include <ToolManager.h>

Inheritance diagram for ToolManager:
[legend]
Collaboration diagram for ToolManager:
[legend]

Classes

struct  TopPanelHook
 

Public Member Functions

 ToolManager (AudacityProject *parent)
 
 ToolManager (const ToolManager &) PROHIBITED
 
ToolManageroperator= (const ToolManager &) PROHIBITED
 
 ~ToolManager ()
 
void CreateWindows ()
 
void LayoutToolBars ()
 
bool IsDocked (Identifier type) const
 
bool IsVisible (Identifier type) const
 
void ShowHide (Identifier type)
 
void Expose (Identifier type, bool show)
 
ToolBarGetToolBar (const Identifier &type) const
 
ToolDockGetTopDock ()
 
const ToolDockGetTopDock () const
 
ToolDockGetBotDock ()
 
const ToolDockGetBotDock () const
 
void Reset ()
 
void Destroy ()
 
void RegenerateTooltips ()
 
int FilterEvent (wxEvent &event) override
 
bool RestoreFocus ()
 
template<typename F >
void ForEach (F &&fun)
 Visit bars, lexicographically by their textual ids. More...
 
size_t CountBars () const
 
- Public Member Functions inherited from ClientData::Base
virtual ~Base ()
 

Static Public Member Functions

static ToolManagerGet (AudacityProject &project)
 
static const ToolManagerGet (const AudacityProject &project)
 
static void OnResetToolBars (const CommandContext &context)
 
static void ModifyToolbarMenus (AudacityProject &project)
 
static void ModifyAllProjectToolbarMenus ()
 

Private Types

using FramePtr = Destroy_ptr< wxFrame >
 

Private Member Functions

ToolBarFloat (ToolBar *t, wxPoint &pos)
 
void OnMenuUpdate (struct MenuUpdateMessage)
 
void OnTimer (wxTimerEvent &event)
 
void OnMouse (wxMouseEvent &event)
 
void OnCaptureLost (wxMouseCaptureLostEvent &event)
 
void UndockBar (wxPoint mp)
 
void OnGrabber (GrabberEvent &event)
 
void HandleEscapeKey ()
 
void DoneDragging ()
 
void OnIndicatorCreate (wxWindowCreateEvent &event)
 
void OnIndicatorPaint (wxPaintEvent &event)
 
void ReadConfig ()
 
void WriteConfig ()
 
void Updated ()
 

Private Attributes

Observer::Subscription mMenuManagerSubscription
 
AudacityProjectmParent
 
wxWindowRef mLastFocus {}
 
ToolFramemDragWindow
 
ToolDockmDragDock
 
ToolBarmDragBar {}
 
wxPoint mDragOffset
 
ToolBarConfiguration::Position mDragBefore {}
 
wxPoint mLastPos
 
wxRect mBarPos
 
FramePtr mIndicator
 
std::unique_ptr< wxRegion > mLeft
 
std::unique_ptr< wxRegion > mDown
 
wxRegion * mCurrent
 
wxTimer mTimer
 
bool mLastState
 
bool mTransition
 
ToolDockmTopDock {}
 
ToolDockmBotDock {}
 
std::map< Identifier, ToolBar::HoldermBars
 map not unordered_map, for the promise made by ForEach More...
 
wxPoint mPrevPosition {}
 
ToolDockmPrevDock {}
 
ToolBarConfiguration::Position mPrevSlot { ToolBarConfiguration::UnspecifiedPosition }
 
ToolBarConfiguration mPrevConfiguration
 
bool mDidDrag {}
 
bool mClicked {}
 

Detailed Description

class ToolManager

Manages the ToolDocks and handles the dragging, floating, and docking of ToolBars.

Definition at line 52 of file ToolManager.h.

Member Typedef Documentation

◆ FramePtr

using ToolManager::FramePtr = Destroy_ptr<wxFrame>
private

Definition at line 152 of file ToolManager.h.

Constructor & Destructor Documentation

◆ ToolManager() [1/2]

ToolManager::ToolManager ( AudacityProject parent)

Definition at line 352 of file ToolManager.cpp.

353: wxEvtHandler()
354{
355 wxPoint pt[ 3 ];
356
357#if defined(__WXMAC__)
358 // Save original transition
359 mTransition = wxSystemOptions::GetOptionInt( wxMAC_WINDOW_PLAIN_TRANSITION );
360#endif
361
362 // Initialize everything
363 mParent = parent;
364 mLastPos.x = mBarPos.x = -1;
365 mLastPos.y = mBarPos.y = -1;
366 mDragWindow = NULL;
367 mDragDock = NULL;
368 mDragBar = NULL;
369
370 // Create the down arrow
371 pt[ 0 ].x = 0;
372 pt[ 0 ].y = 0;
373 pt[ 1 ].x = 9;
374 pt[ 1 ].y = 9;
375 pt[ 2 ].x = 18;
376 pt[ 2 ].y = 0;
377
378 // Create the shaped region
379 mDown = std::make_unique<wxRegion>( 3, &pt[0] );
380
381 // Create the down arrow
382 pt[ 0 ].x = 9;
383 pt[ 0 ].y = 0;
384 pt[ 1 ].x = 0;
385 pt[ 1 ].y = 9;
386 pt[ 2 ].x = 9;
387 pt[ 2 ].y = 18;
388
389 // Create the shaped region
390 mLeft = std::make_unique<wxRegion>( 3, &pt[0] );
391
392 // Create the indicator frame
393 // parent is null but FramePtr ensures destruction
394 mIndicator = FramePtr{ safenew wxFrame( NULL,
395 wxID_ANY,
396 wxEmptyString,
397 wxDefaultPosition,
398 wxSize( 32, 32 ),
399 wxFRAME_TOOL_WINDOW |
400 wxFRAME_SHAPED |
401 wxNO_BORDER |
402 wxFRAME_NO_TASKBAR |
403 wxSTAY_ON_TOP )
404 };
405
406 // Hook the creation event...only needed on GTK, but doesn't hurt for all
407 mIndicator->Bind( wxEVT_CREATE,
409 this );
410
411 // Hook the paint event...needed for all
412 mIndicator->Bind( wxEVT_PAINT,
414 this );
415
416 // It's a little shy
417 mIndicator->Hide();
418}
#define safenew
Definition: MemoryX.h:10
void OnIndicatorCreate(wxWindowCreateEvent &event)
ToolBar * mDragBar
Definition: ToolManager.h:145
bool mTransition
Definition: ToolManager.h:161
ToolFrame * mDragWindow
Definition: ToolManager.h:143
std::unique_ptr< wxRegion > mLeft
Definition: ToolManager.h:154
AudacityProject * mParent
Definition: ToolManager.h:140
void OnIndicatorPaint(wxPaintEvent &event)
std::unique_ptr< wxRegion > mDown
Definition: ToolManager.h:154
ToolDock * mDragDock
Definition: ToolManager.h:144
Destroy_ptr< wxFrame > FramePtr
Definition: ToolManager.h:152
wxRect mBarPos
Definition: ToolManager.h:150
FramePtr mIndicator
Definition: ToolManager.h:153
wxPoint mLastPos
Definition: ToolManager.h:149

References mBarPos, mDown, mDragBar, mDragDock, mDragWindow, mIndicator, mLastPos, mLeft, mParent, mTransition, OnIndicatorCreate(), OnIndicatorPaint(), and safenew.

Here is the call graph for this function:

◆ ToolManager() [2/2]

ToolManager::ToolManager ( const ToolManager )

◆ ~ToolManager()

ToolManager::~ToolManager ( )

Definition at line 509 of file ToolManager.cpp.

510{
511 Destroy();
512}
void Destroy()

References Destroy().

Here is the call graph for this function:

Member Function Documentation

◆ CountBars()

size_t ToolManager::CountBars ( ) const
inline

Definition at line 110 of file ToolManager.h.

111 {
112 return mBars.size();
113 }
std::map< Identifier, ToolBar::Holder > mBars
map not unordered_map, for the promise made by ForEach
Definition: ToolManager.h:168

◆ CreateWindows()

void ToolManager::CreateWindows ( )

Assign (non-persistent!) sequential ids to the toolbars

Definition at line 420 of file ToolManager.cpp.

421{
422 auto parent = mParent;
423 auto &window = GetProjectFrame( *parent );
424
425 // Hook the parents mouse events...using the parent helps greatly
426 // under GTK
427 window.Bind( wxEVT_LEFT_UP,
429 this );
430 window.Bind( wxEVT_MOTION,
432 this );
433 window.Bind( wxEVT_MOUSE_CAPTURE_LOST,
435 this );
436
437 wxWindow *topDockParent = TopPanelHook::Call( window );
438 wxASSERT(topDockParent);
439
440 // Create the top and bottom docks
441 mTopDock = safenew ToolDock( this, topDockParent, TopDockID );
442 mBotDock = safenew ToolDock( this, &window, BotDockID );
443
444 // Create all of the toolbars
445 // All have the project as parent window
446 wxASSERT(parent);
447
448 for (const auto &factory : RegisteredToolbarFactory::GetFactories()) {
449 if (factory) {
450 auto bar = factory( *parent );
451 if (bar) {
452 auto &slot = mBars[bar->GetSection()];
453 if (slot) {
454 // Oh no, name collision of registered toolbars
455 assert(false);
456 bar->Destroy();
457 continue;
458 }
459 slot = std::move(bar);
460 }
461 }
462 else
463 wxASSERT( false );
464 }
465
467 ForEach([ii = 0](ToolBar *bar) mutable { bar->SetIndex(ii++); });
468
469 // We own the timer
470 mTimer.SetOwner( this );
471
472 // Process the toolbar config settings
473 ReadConfig();
474
475 wxEvtHandler::AddFilter(this);
476
479}
AUDACITY_DLL_API wxFrame & GetProjectFrame(AudacityProject &project)
Get the top-level window associated with the project (as a wxFrame only, when you do not need to use ...
@ BotDockID
Definition: ToolDock.h:44
@ TopDockID
Definition: ToolDock.h:43
static result_type Call(Arguments &&...arguments)
Null check of the installed function is done for you.
static MenuManager & Get(AudacityProject &project)
Definition: Menus.cpp:69
Subscription Subscribe(Callback callback)
Connect a callback to the Publisher; later-connected are called earlier.
Definition: Observer.h:199
Works with ToolManager and ToolDock to provide a dockable window in which buttons can be placed.
Definition: ToolBar.h:74
void SetIndex(int index)
Set a value used for computing cascading positions of undocked bars.
Definition: ToolBar.h:114
A dynamic panel where a ToolBar can be docked.
Definition: ToolDock.h:292
void OnMenuUpdate(struct MenuUpdateMessage)
void ReadConfig()
void OnCaptureLost(wxMouseCaptureLostEvent &event)
ToolDock * mTopDock
Definition: ToolManager.h:164
wxTimer mTimer
Definition: ToolManager.h:157
Observer::Subscription mMenuManagerSubscription
Definition: ToolManager.h:139
void ForEach(F &&fun)
Visit bars, lexicographically by their textual ids.
Definition: ToolManager.h:103
void OnMouse(wxMouseEvent &event)
ToolDock * mBotDock
Definition: ToolManager.h:165
static RegisteredToolbarFactory factory
static const Functions & GetFactories()
Definition: ToolBar.cpp:1047

References BotDockID, GlobalHook< TopPanelHook, wxWindow *(wxWindow &) >::Call(), cloud::factory, ForEach(), MenuManager::Get(), RegisteredToolbarFactory::GetFactories(), GetProjectFrame(), mBars, mBotDock, mMenuManagerSubscription, mParent, mTimer, mTopDock, OnCaptureLost(), OnMenuUpdate(), OnMouse(), ReadConfig(), safenew, ToolBar::SetIndex(), Observer::Publisher< Message, NotifyAll >::Subscribe(), and TopDockID.

Referenced by InitProjectWindow().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Destroy()

void ToolManager::Destroy ( )

Definition at line 485 of file ToolManager.cpp.

486{
487 if ( mTopDock || mBotDock ) { // destroy at most once
488 wxEvtHandler::RemoveFilter(this);
489
490 // Save the toolbar states
491 WriteConfig();
492
493 // This function causes the toolbars to be destroyed, so
494 // clear the configuration of the ToolDocks which refer to
495 // these toolbars. This change was needed to stop Audacity
496 // crashing when running with Jaws on Windows 10 1703.
499
500 mTopDock = mBotDock = nullptr; // indicate that it has been destroyed
501
502 for (auto &pair : mBars)
503 pair.second.reset();
504
505 mIndicator.reset();
506 }
507}
ToolBarConfiguration & GetConfiguration()
Definition: ToolDock.h:311
void WriteConfig()

References ToolBarConfiguration::Clear(), ToolDock::GetConfiguration(), mBars, mBotDock, mIndicator, mTopDock, and WriteConfig().

Referenced by ProjectManager::OnCloseWindow(), and ~ToolManager().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ DoneDragging()

void ToolManager::DoneDragging ( )
private

Definition at line 1504 of file ToolManager.cpp.

1505{
1506 // Done dragging - ensure grabber button isn't pushed
1507 if( mDragBar )
1508 {
1509 mDragBar->SetDocked( mDragBar->GetDock(), false );
1510 }
1511
1512 // Release capture
1513 auto &window = GetProjectFrame( *mParent );
1514 if( window.HasCapture() )
1515 {
1516 window.ReleaseMouse();
1517 }
1518
1519 // Hide the indicator
1520 mIndicator->Hide();
1521
1522 mDragWindow = NULL;
1523 mDragDock = NULL;
1524 mDragBar = NULL;
1525 mPrevDock = NULL;
1528 mLastPos.x = mBarPos.x = -1;
1529 mLastPos.y = mBarPos.y = -1;
1530 mTimer.Stop();
1531 mDidDrag = false;
1532 mClicked = false;
1533
1534 RestoreFocus();
1535}
static const Position UnspecifiedPosition
Definition: ToolDock.h:106
virtual void SetDocked(ToolDock *dock, bool pushed)
Definition: ToolBar.cpp:661
ToolDock * GetDock()
Definition: ToolBar.cpp:647
ToolBarConfiguration mPrevConfiguration
Definition: ToolManager.h:174
ToolDock * mPrevDock
Definition: ToolManager.h:171
ToolBarConfiguration::Position mPrevSlot
Definition: ToolManager.h:173
bool RestoreFocus()

References ToolBarConfiguration::Clear(), ToolBar::GetDock(), GetProjectFrame(), mBarPos, mClicked, mDidDrag, mDragBar, mDragDock, mDragWindow, mIndicator, mLastPos, mParent, mPrevConfiguration, mPrevDock, mPrevSlot, mTimer, RestoreFocus(), ToolBar::SetDocked(), and ToolBarConfiguration::UnspecifiedPosition.

Referenced by HandleEscapeKey(), and OnMouse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Expose()

void ToolManager::Expose ( Identifier  type,
bool  show 
)

Definition at line 1082 of file ToolManager.cpp.

1083{
1084 ToolBar *t = mBars[type].get();
1085
1086 // Handle docked and floaters differently
1087 if( t->IsDocked() )
1088 {
1089 t->GetDock()->Expose( t->GetSection(), show );
1090 }
1091 else
1092 {
1093 t->Expose( show );
1094 }
1095}
bool IsDocked() const
Definition: ToolBar.cpp:433
Identifier GetSection()
Definition: ToolBar.cpp:400
virtual bool Expose(bool show=true)
Definition: ToolBar.cpp:459
void Expose(Identifier type, bool show)
Definition: ToolDock.cpp:858

References ToolBar::Expose(), ToolDock::Expose(), ToolBar::GetDock(), ToolBar::GetSection(), ToolBar::IsDocked(), and mBars.

Referenced by ReadConfig(), Reset(), and ShowHide().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ FilterEvent()

int ToolManager::FilterEvent ( wxEvent &  event)
override

Definition at line 690 of file ToolManager.cpp.

691{
692 // Snoop the global event stream for changes of focused window. Remember
693 // the last one of our own that is not a grabber.
694
695 if (event.GetEventType() == wxEVT_KILL_FOCUS) {
696 auto &focusEvent = static_cast<wxFocusEvent&>(event);
697 auto window = focusEvent.GetWindow();
698 auto top = wxGetTopLevelParent(window);
699 if(auto toolFrame = dynamic_cast<ToolFrame*>(top))
700 top = toolFrame->GetParent();
701 // window is that which will GET the focus
702 if ( window &&
703 !dynamic_cast<Grabber*>( window ) &&
704 !dynamic_cast<ToolFrame*>( window ) &&
705 top == FindProjectFrame( mParent ) )
706 // Note this is a dangle-proof wxWindowRef:
707 mLastFocus = window;
708 }
709
710 return Event_Skip;
711}
wxFrame * FindProjectFrame(AudacityProject *project)
Get a pointer to the window associated with a project, or null if the given pointer is null,...
The widget to the left of a ToolBar that allows it to be dragged around to NEW positions.
Definition: Grabber.h:107
class ToolFrame
Definition: ToolManager.h:190
wxWindowRef mLastFocus
Definition: ToolManager.h:141

References FindProjectFrame(), mLastFocus, and mParent.

Here is the call graph for this function:

◆ Float()

ToolBar * ToolManager::Float ( ToolBar t,
wxPoint &  pos 
)
private

◆ ForEach()

template<typename F >
void ToolManager::ForEach ( F &&  fun)
inline

Visit bars, lexicographically by their textual ids.

Definition at line 103 of file ToolManager.h.

104 {
105 std::for_each(std::begin(mBars), std::end(mBars), [&fun](auto &pair){
106 fun(pair.second.get());
107 });
108 }
auto end(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:159
auto begin(const Ptr< Type, BaseDeleter > &p)
Enables range-for.
Definition: PackedArray.h:150

References PackedArray::begin(), and PackedArray::end().

Referenced by CreateWindows(), ScreenshotCommand::kCaptureWhatStrings(), ScreenshotBigDialog::PopulateOrExchange(), ReadConfig(), RegenerateTooltips(), Reset(), and WriteConfig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Get() [1/2]

ToolManager & ToolManager::Get ( AudacityProject project)
static

◆ Get() [2/2]

const ToolManager & ToolManager::Get ( const AudacityProject project)
static

Definition at line 344 of file ToolManager.cpp.

345{
346 return Get( const_cast< AudacityProject & >( project ) );
347}
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
static ToolManager & Get(AudacityProject &project)

References Get().

Here is the call graph for this function:

◆ GetBotDock() [1/2]

ToolDock * ToolManager::GetBotDock ( )

Definition at line 1017 of file ToolManager.cpp.

1018{
1019 return mBotDock;
1020}

References mBotDock.

◆ GetBotDock() [2/2]

const ToolDock * ToolManager::GetBotDock ( ) const

Definition at line 1022 of file ToolManager.cpp.

1023{
1024 return mBotDock;
1025}

References mBotDock.

◆ GetToolBar()

ToolBar * ToolManager::GetToolBar ( const Identifier type) const

Definition at line 995 of file ToolManager.cpp.

996{
997 auto end = mBars.end(), iter = mBars.find(type);
998 return (iter == end) ? nullptr : iter->second.get();
999}

References PackedArray::end(), and mBars.

Referenced by ScreenshotCommand::CaptureToolbar(), IsDocked(), IsVisible(), OnGrabber(), ReadConfig(), Reset(), and ProjectAudioManager::Stop().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ GetTopDock() [1/2]

ToolDock * ToolManager::GetTopDock ( )

Definition at line 1004 of file ToolManager.cpp.

1005{
1006 return mTopDock;
1007}

References mTopDock.

◆ GetTopDock() [2/2]

const ToolDock * ToolManager::GetTopDock ( ) const

Definition at line 1009 of file ToolManager.cpp.

1010{
1011 return mTopDock;
1012}

References mTopDock.

◆ HandleEscapeKey()

void ToolManager::HandleEscapeKey ( )
private

Definition at line 1475 of file ToolManager.cpp.

1476{
1477 if (mDragBar) {
1478 if(mPrevDock) {
1479 // Sheriff John Stone,
1480 // Why don't you leave me alone?
1481 // Well, I feel so break up
1482 // I want to go home.
1484 mPrevDock->Dock( mDragBar, true, mPrevSlot );
1485 Updated();
1486
1487 // Done with the floater
1489 mDragWindow->Destroy();
1490 mDragWindow = nullptr;
1491 mDragBar->Refresh(false);
1492 }
1493 else {
1494 // Floater remains, and returns to where it begain
1495 auto parent = mDragBar->GetParent();
1496 parent->SetPosition(mPrevPosition);
1497 mDragBar->SetDocked(NULL, false);
1498 }
1499
1500 DoneDragging();
1501 }
1502}
void RestoreConfiguration(ToolBarConfiguration &backup)
Definition: ToolDock.cpp:848
void Dock(ToolBar *bar, bool deflate, ToolBarConfiguration::Position ndx=ToolBarConfiguration::UnspecifiedPosition)
Definition: ToolDock.cpp:438
void ClearBar()
Definition: ToolManager.h:198
wxPoint mPrevPosition
Definition: ToolManager.h:170
void DoneDragging()

References ToolFrame::ClearBar(), ToolDock::Dock(), DoneDragging(), mDragBar, mDragWindow, mPrevConfiguration, mPrevDock, mPrevPosition, mPrevSlot, ToolDock::RestoreConfiguration(), ToolBar::SetDocked(), and Updated().

Referenced by OnGrabber().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ IsDocked()

bool ToolManager::IsDocked ( Identifier  type) const

Definition at line 1041 of file ToolManager.cpp.

1042{
1043 if (auto pBar = GetToolBar(type))
1044 return pBar->IsDocked();
1045 return false;
1046}
ToolBar * GetToolBar(const Identifier &type) const

References GetToolBar().

Here is the call graph for this function:

◆ IsVisible()

bool ToolManager::IsVisible ( Identifier  type) const

Definition at line 1051 of file ToolManager.cpp.

1052{
1053 if (auto pBar = GetToolBar(type))
1054 return pBar->IsVisible();
1055 return false;
1056
1057#if 0
1058 // If toolbar is floating
1059 if( !t->IsDocked() )
1060 {
1061 // Must return state of floater window
1062 return t->GetParent()->IsShown();
1063 }
1064
1065 // Return state of docked toolbar
1066 return t->IsShown();
1067#endif
1068}

References GetToolBar().

Referenced by ScreenshotCommand::CaptureToolbar(), and ShowHide().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ LayoutToolBars()

void ToolManager::LayoutToolBars ( )

Definition at line 1100 of file ToolManager.cpp.

1101{
1102 // Update the layout
1103 if (mTopDock)
1104 {
1106 }
1107
1108 if (mBotDock)
1109 {
1111 }
1112}
void LayoutToolBars()
Definition: ToolDock.cpp:687

References ToolDock::LayoutToolBars(), mBotDock, and mTopDock.

Referenced by InitProjectWindow(), and OnMouse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ModifyAllProjectToolbarMenus()

void ToolManager::ModifyAllProjectToolbarMenus ( )
static

Definition at line 1549 of file ToolManager.cpp.

1550{
1551 for (auto pProject : AllProjects{}) {
1552 auto &project = *pProject;
1553 ModifyToolbarMenus(project);
1554 }
1555}
static void ModifyToolbarMenus(AudacityProject &project)

References ModifyToolbarMenus().

Referenced by anonymous_namespace{TrackMenus.cpp}::OnSyncLock(), anonymous_namespace{TransportMenus.cpp}::OnTogglePlayRecording(), anonymous_namespace{TransportMenus.cpp}::OnToggleSoundActivated(), anonymous_namespace{TransportMenus.cpp}::OnToggleSWPlaythrough(), anonymous_namespace{LabelMenus.cpp}::OnToggleTypeToCreateLabel(), and AdornedRulerPanel::TogglePinnedHead().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ModifyToolbarMenus()

void ToolManager::ModifyToolbarMenus ( AudacityProject project)
static

Definition at line 1558 of file ToolManager.cpp.

1559{
1560 // Refreshes can occur during shutdown and the toolmanager may already
1561 // be deleted, so protect against it.
1562 auto &toolManager = ToolManager::Get( project );
1563
1564 // Now, go through each toolbar, and call EnableDisableButtons()
1565 toolManager.ForEach([](auto bar){
1566 if (bar)
1567 bar->EnableDisableButtons();
1568 });
1569
1570 // These don't really belong here, but it's easier and especially so for
1571 // the Edit toolbar and the sync-lock menu item.
1572 bool active = SyncLockTracks.Read();
1573 SyncLockState::Get(project).SetSyncLock(active);
1574
1575 CommandManager::Get( project ).UpdateCheckmarks( project );
1576}
BoolSetting SyncLockTracks
Definition: SyncLock.cpp:172
void UpdateCheckmarks(AudacityProject &project)
static CommandManager & Get(AudacityProject &project)
bool Read(T *pVar) const
overload of Read returning a boolean that is true if the value was previously defined *‍/
Definition: Prefs.h:200
void SetSyncLock(bool flag)
Definition: SyncLock.cpp:48
static SyncLockState & Get(AudacityProject &project)
Definition: SyncLock.cpp:26

References SyncLockState::Get(), CommandManager::Get(), Get(), Setting< T >::Read(), SyncLockState::SetSyncLock(), SyncLockTracks, and CommandManager::UpdateCheckmarks().

Referenced by ModifyAllProjectToolbarMenus(), anonymous_namespace{ExtraMenus.cpp}::OnFullScreen(), OnMenuUpdate(), OnResetToolBars(), and AttachedToolBarMenuItem::OnShowToolBar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnCaptureLost()

void ToolManager::OnCaptureLost ( wxMouseCaptureLostEvent &  event)
private

Definition at line 1304 of file ToolManager.cpp.

1305{
1306 // Can't do anything if we're not dragging. This also prevents
1307 // us from intercepting events that don't belong to us from the
1308 // parent since we're Connect()ed to a couple.
1309 if( !mDragWindow )
1310 {
1311 event.Skip();
1312 return;
1313 }
1314
1315 // Simulate button up
1316 wxMouseEvent e(wxEVT_LEFT_UP);
1317 e.SetEventObject(mParent);
1318 OnMouse(e);
1319}

References mDragWindow, mParent, and OnMouse().

Referenced by CreateWindows().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnGrabber()

void ToolManager::OnGrabber ( GrabberEvent event)
private

Definition at line 1427 of file ToolManager.cpp.

1428{
1429 // No need to propagate any further
1430 event.Skip( false );
1431
1432 if(event.IsEscaping())
1433 return HandleEscapeKey();
1434
1435 // Remember which bar we're dragging
1436 mDragBar = GetToolBar(event.BarId());
1437
1438 // Remember state, in case of ESCape key later
1439 if (mDragBar->IsDocked()) {
1440 mPrevDock = dynamic_cast<ToolDock*>(mDragBar->GetParent());
1441 wxASSERT(mPrevDock);
1444 }
1445 else
1446 mPrevPosition = mDragBar->GetParent()->GetPosition();
1447
1448 // Calculate the drag offset
1449 wxPoint mp = event.GetPosition();
1450 mDragOffset = mp -
1451 mDragBar->GetParent()->ClientToScreen( mDragBar->GetPosition() ) +
1452 wxPoint( 1, 1 );
1453
1454 mClicked = true;
1455 if( mPrevDock )
1456 {
1457 mDragWindow = nullptr;
1458 }
1459 else
1460 {
1461 mDragWindow = (ToolFrame *) mDragBar->GetParent();
1462 }
1463
1464 // We want all mouse events from this point on
1465 auto &window = GetProjectFrame( *mParent );
1466 if( !window.HasCapture() )
1467 window.CaptureMouse();
1468
1469 // Start monitoring shift key changes
1470 mLastState = wxGetKeyState( WXK_SHIFT );
1471 mTimer.Start( 100 );
1472}
bool IsEscaping() const
Definition: Grabber.h:75
Identifier BarId() const
Definition: Grabber.h:77
Position Find(const ToolBar *bar) const
Definition: ToolDock.cpp:87
void WrapConfiguration(ToolBarConfiguration &backup)
Definition: ToolDock.cpp:841
bool mLastState
Definition: ToolManager.h:158
void HandleEscapeKey()
wxPoint mDragOffset
Definition: ToolManager.h:146

References GrabberEvent::BarId(), ToolBarConfiguration::Find(), ToolDock::GetConfiguration(), GetProjectFrame(), GetToolBar(), HandleEscapeKey(), ToolBar::IsDocked(), GrabberEvent::IsEscaping(), mClicked, mDragBar, mDragOffset, mDragWindow, mLastState, mParent, mPrevConfiguration, mPrevDock, mPrevPosition, mPrevSlot, mTimer, and ToolDock::WrapConfiguration().

Here is the call graph for this function:

◆ OnIndicatorCreate()

void ToolManager::OnIndicatorCreate ( wxWindowCreateEvent &  event)
private

Definition at line 1386 of file ToolManager.cpp.

1387{
1388#if defined(__WXGTK__)
1389 mIndicator->SetShape( *mCurrent );
1390#endif
1391 event.Skip();
1392}
wxRegion * mCurrent
Definition: ToolManager.h:155

References mCurrent, and mIndicator.

Referenced by ToolManager().

Here is the caller graph for this function:

◆ OnIndicatorPaint()

void ToolManager::OnIndicatorPaint ( wxPaintEvent &  event)
private

Definition at line 1369 of file ToolManager.cpp.

1370{
1371 // TODO: Better to use a bitmap than a triangular region.
1372 wxWindow *w = (wxWindow *)event.GetEventObject();
1373 wxPaintDC dc( w );
1374 // TODO: Better (faster) to use the existing spare brush.
1375 wxBrush brush( theTheme.Colour( clrTrackPanelText ) );
1376 dc.SetBackground( brush );
1377 dc.Clear();
1378}
THEME_API Theme theTheme
Definition: Theme.cpp:82
wxColour & Colour(int iIndex)

References ThemeBase::Colour(), and theTheme.

Referenced by ToolManager().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnMenuUpdate()

void ToolManager::OnMenuUpdate ( struct MenuUpdateMessage  )
private

Definition at line 1321 of file ToolManager.cpp.

1322{
1324}

References ModifyToolbarMenus(), and mParent.

Referenced by CreateWindows().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnMouse()

void ToolManager::OnMouse ( wxMouseEvent &  event)
private

Definition at line 1117 of file ToolManager.cpp.

1118{
1119 // Go ahead and set the event to propagate
1120 event.Skip();
1121
1122 // Can't do anything if we're not dragging. This also prevents
1123 // us from intercepting events that don't belong to us from the
1124 // parent since we're Connect()ed to a couple.
1125 if( !mClicked )
1126 {
1127 return;
1128 }
1129
1130#if defined(__WXMAC__)
1131 // Disable window animation
1132 wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, 1 );
1133#endif
1134
1135 // Retrieve the event position
1136 wxPoint pos =
1137 ( (wxWindow *)event.GetEventObject() )->ClientToScreen( event.GetPosition() ) - mDragOffset;
1138
1139
1140 if( !event.LeftIsDown() )
1141 {
1142 // Button was released...finish the drag
1143 // Transition the bar to a dock
1144 if (!mDidDrag) {
1145 if (mPrevDock)
1147 DoneDragging();
1148 return;
1149 }
1150 else if( mDragDock && !event.ShiftDown() )
1151 {
1152 // Trip over...everyone ashore that's going ashore...
1154 Updated();
1156
1157 // Done with the floater
1158 mDragWindow->Destroy();
1159 mDragWindow = nullptr;
1160 mDragBar->Refresh(false);
1161 }
1162 else
1163 {
1164 // Calling SetDocked() to force the grabber button to popup
1165 mDragBar->SetDocked( NULL, false );
1166 }
1167
1168 DoneDragging();
1169 }
1170 else if( event.Dragging() && pos != mLastPos )
1171 {
1172 if (!mDidDrag) {
1173 // Must set the bar afloat if it's currently docked
1174 mDidDrag = true;
1175 wxPoint mp = event.GetPosition();
1176 mp = GetProjectFrame( *mParent ).ClientToScreen(mp);
1177 if (!mDragWindow) {
1178 // We no longer have control
1179 if (mPrevDock)
1181 UndockBar(mp);
1182 // Rearrange the remaining toolbars before trying to re-insert this one.
1184 }
1185 }
1186
1187 // Make toolbar follow the mouse
1188 mDragWindow->Move( pos );
1189
1190 // Remember to prevent excessive movement
1191 mLastPos = pos;
1192
1193 // Calc the top dock hittest rectangle
1194 wxRect tr = mTopDock->GetRect();
1195 tr.SetBottom( tr.GetBottom() + 10 );
1196 tr.SetPosition( mTopDock->GetParent()->ClientToScreen( tr.GetPosition() ) );
1197
1198 // Calc the bottom dock hittest rectangle
1199 wxRect br = mBotDock->GetRect();
1200 br.SetTop( br.GetTop() - 10 );
1201 br.SetBottom( br.GetBottom() + 20 );
1202 br.SetPosition( mBotDock->GetParent()->ClientToScreen( br.GetPosition() ) );
1203
1204
1205 // Add half the bar height. We could use the actual bar height, but that would be confusing as a
1206 // bar removed at a place might not dock back there if just let go.
1207 // Also add 5 pixels in horizontal direction, so that a click without a move (or a very small move)
1208 // lands back where we started.
1209 pos += wxPoint( 5, 20 );
1210
1211
1212 // To find which dock, rather than test against pos, test against the whole dragger rect.
1213 // This means it is enough to overlap the dock to dock with it.
1214 wxRect barRect = mDragWindow->GetRect();
1215 ToolDock *dock = NULL;
1216 if( tr.Intersects( barRect ) )
1217 dock = mTopDock;
1218 else if( br.Intersects( barRect ) )
1219 dock = mBotDock;
1220
1221 // Looks like we have a winner...
1222 if( dock )
1223 {
1224 wxPoint p;
1225 wxRect r;
1226
1227 // Calculate where the bar would be placed
1228 mDragBefore = dock->PositionBar( mDragBar, pos, r );
1229
1230 // If different than the last time, the indicator must be moved
1231 if( r != mBarPos )
1232 {
1233 wxRect dr = dock->GetRect();
1234
1235 // Hide the indicator before changing the shape
1236 mIndicator->Hide();
1237
1238 // Decide which direction the arrow should point
1239 if( r.GetTop() >= dr.GetHeight() )
1240 {
1241 const auto &box = mDown->GetBox();
1242 p.x = dr.GetLeft() + ( dr.GetWidth() / 2 )
1243 - (box.GetWidth() / 2);
1244 p.y = dr.GetBottom() - box.GetHeight();
1245 mCurrent = mDown.get();
1246 }
1247 else
1248 {
1249 // r is the rectangle of the toolbar being dragged.
1250 // A tall undocked toolbar will become at most 2 tbs
1251 // high when docked, so the triangular drop indicator
1252 // needs to use that height, h, not the bar height
1253 // for calculating where to be drawn.
1254 const int tbs = toolbarSingle + toolbarGap;
1255 int h = wxMin(r.GetHeight(), 2*tbs-1);
1256 p.x = dr.GetLeft() + r.GetLeft();
1257 p.y = dr.GetTop() + r.GetTop() +
1258 ( ( h - mLeft->GetBox().GetHeight() ) / 2 );
1259 mCurrent = mLeft.get();
1260 }
1261
1262 // Change the shape while hidden and then show it if okay
1263 mIndicator->SetShape( *mCurrent );
1264 if( !event.ShiftDown() )
1265 {
1266 mIndicator->Show();
1267 mIndicator->Update();
1268 }
1269
1270 // Move it into position
1271 // LL: Do this after the Show() since KDE doesn't move the window
1272 // if it's not shown. (Do it outside if the previous IF as well)
1273 mIndicator->Move( dock->GetParent()->ClientToScreen( p ) );
1274
1275 // Remember for next go round
1276 mBarPos = r;
1277 }
1278 }
1279 else
1280 {
1281 // Hide the indicator if it's still shown
1282 if( mBarPos.x != -1 )
1283 {
1284 // Hide any
1285 mIndicator->Hide();
1286 mBarPos.x = -1;
1287 mBarPos.y = -1;
1288 }
1289 }
1290
1291 // Remember to which dock the drag bar belongs.
1292 mDragDock = dock;
1293 }
1294
1295#if defined(__WXMAC__)
1296 // Reinstate original transition
1297 wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, mTransition );
1298#endif
1299}
#define toolbarSingle
Definition: ToolBar.h:59
#define toolbarGap
Definition: ToolBar.h:64
void Remove(const ToolBar *bar)
Definition: ToolDock.cpp:224
ToolBarConfiguration::Position PositionBar(ToolBar *t, const wxPoint &pos, wxRect &rect)
Definition: ToolDock.cpp:744
void UndockBar(wxPoint mp)
void LayoutToolBars()
ToolBarConfiguration::Position mDragBefore
Definition: ToolManager.h:147

References ToolFrame::ClearBar(), ToolDock::Dock(), DoneDragging(), ToolDock::GetConfiguration(), GetProjectFrame(), LayoutToolBars(), mBarPos, mBotDock, mClicked, mCurrent, mDidDrag, mDown, mDragBar, mDragBefore, mDragDock, mDragOffset, mDragWindow, mIndicator, mLastPos, mLeft, mPrevConfiguration, mPrevDock, mTopDock, mTransition, ToolDock::PositionBar(), ToolBarConfiguration::Remove(), ToolDock::RestoreConfiguration(), ToolBar::SetDocked(), toolbarGap, toolbarSingle, UndockBar(), and Updated().

Referenced by CreateWindows(), and OnCaptureLost().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnResetToolBars()

void ToolManager::OnResetToolBars ( const CommandContext context)
static

Definition at line 566 of file ToolManager.cpp.

567{
568 auto &project = context.project;
569 auto &toolManager = ToolManager::Get( project );
570
571 toolManager.Reset();
572 Get(project).ModifyToolbarMenus(project);
573}
AudacityProject & project

References Get(), ModifyToolbarMenus(), and CommandContext::project.

Referenced by anonymous_namespace{PluginMenus.cpp}::OnResetConfig(), and anonymous_namespace{ToolbarMenus.cpp}::ToolbarsMenu().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ OnTimer()

void ToolManager::OnTimer ( wxTimerEvent &  event)
private

Definition at line 1329 of file ToolManager.cpp.

1330{
1331 // Go ahead and set the event to propagate
1332 event.Skip();
1333
1334 // Can't do anything if we're not dragging. This also prevents
1335 // us from intercepting events that don't belong to us from the
1336 // parent since we're Connect()ed to a couple.
1337 if( !mDragWindow )
1338 {
1339 return;
1340 }
1341
1342 bool state = wxGetKeyState( WXK_SHIFT );
1343 if( mLastState != state )
1344 {
1345 mLastState = state;
1346
1347#if defined(__WXMAC__)
1348 // Disable window animation
1349 wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, 1 );
1350#endif
1351
1352 mIndicator->Show( !state );
1353
1354#if defined(__WXMAC__)
1355 // Disable window animation
1356 wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, mTransition );
1357#endif
1358 }
1359
1360 return;
1361}

References mDragWindow, mIndicator, mLastState, and mTransition.

◆ operator=()

ToolManager & ToolManager::operator= ( const ToolManager )

◆ ReadConfig()

void ToolManager::ReadConfig ( )
private

Definition at line 716 of file ToolManager.cpp.

717{
718 wxString oldpath = gPrefs->GetPath();
719 std::vector<Identifier> unordered[ DockCount ];
720 std::vector<ToolBar*> dockedAndHidden;
721 std::map<Identifier, bool> show;
722 std::map<Identifier, int> width;
723 std::map<Identifier, int> height;
724 int x, y;
725 int dock;
726 bool someFound { false };
727
728#if defined(__WXMAC__)
729 // Disable window animation
730 wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, 1 );
731#endif
732
733 // Change to the bar root
734 gPrefs->SetPath( wxT("/GUI/ToolBars") );
735
736 ToolBarConfiguration::Legacy topLegacy, botLegacy;
737
738 int vMajor, vMinor, vMicro;
739 gPrefs->GetVersionKeysInit(vMajor, vMinor, vMicro);
740 bool useLegacyDock = false;
741 // note that vMajor, vMinor, and vMicro will all be zero if either it's a new audacity.cfg file
742 // or the version is less than 1.3.13 (when there were no version keys according to the comments in
743 // InitPreferences()). So for new audacity.cfg
744 // file useLegacyDock will be true, but this doesn't matter as there are no Dock or DockV2 keys in the file yet.
745 if (vMajor <= 1 ||
746 (vMajor == 2 && (vMinor <= 1 || (vMinor == 2 && vMicro <= 1)))) // version <= 2.2.1
747 useLegacyDock = true;
748
749
750 // Load and apply settings for each bar
751 ForEach([&](ToolBar *bar){
752 //wxPoint Center = mParent->GetPosition() + (mParent->GetSize() * 0.33);
753 //wxPoint Center(
754 // wxSystemSettings::GetMetric( wxSYS_SCREEN_X ) /2 ,
755 // wxSystemSettings::GetMetric( wxSYS_SCREEN_Y ) /2 );
756
757 // Change to the bar subkey
758 auto ndx = bar->GetSection();
759 gPrefs->SetPath( ndx.GET() );
760
761 const bool bShownByDefault = bar->ShownByDefault();
762 const int defaultDock = bar->DefaultDockID();
763
764 // Read in all the settings
765
766 if (useLegacyDock)
767 gPrefs->Read( wxT("Dock"), &dock, -1); // legacy version of DockV2
768 else
769 gPrefs->Read( wxT("DockV2"), &dock, -1);
770
771 const bool found = (dock != -1);
772 if (found)
773 someFound = true;
774 if (!found)
775 dock = defaultDock;
776
777 ToolDock *d;
779 switch(dock)
780 {
781 case TopDockID: d = mTopDock; pLegacy = &topLegacy; break;
782 case BotDockID: d = mBotDock; pLegacy = &botLegacy; break;
783 default: d = nullptr; pLegacy = nullptr; break;
784 }
785
786 bool ordered = ToolBarConfiguration::Read(
787 d ? &d->GetConfiguration() : nullptr,
788 pLegacy,
789 bar, show[ ndx ], bShownByDefault)
790 && found;
791
792 gPrefs->Read( wxT("X"), &x, -1 );
793 gPrefs->Read( wxT("Y"), &y, -1 );
794 gPrefs->Read( wxT("W"), &width[ ndx ], -1 );
795 gPrefs->Read( wxT("H"), &height[ ndx ], -1 );
796
797 bar->SetVisible( show[ ndx ] );
798
799 // Docked or floating?
800 if( dock )
801 {
802 // Default to top dock if the ID isn't valid
803 if( dock < NoDockID || dock > DockCount ) {
804 dock = TopDockID;
805 }
806
807 // Create the bar with the correct parent
808 if( dock == TopDockID )
809 {
810 bar->Create( mTopDock );
811 }
812 else
813 {
814 bar->Create( mBotDock );
815 }
816
817 // Set the width and height
818 if( width[ ndx ] != -1 && height[ ndx ] != -1 )
819 {
820 wxSize sz( width[ ndx ], height[ ndx ] );
821 bar->SetSize( sz );
822 bar->ResizingDone();
823 }
824
825 // Set the width
826 if( width[ ndx ] >= bar->GetSize().x )
827 {
828 wxSize sz( width[ ndx ], bar->GetSize().y );
829 bar->SetSize( sz );
830 bar->Layout();
831 }
832
833 // make a note of docked and hidden toolbars
834 if (!show[ndx])
835 dockedAndHidden.push_back(bar);
836
837 if (!ordered)
838 {
839 // These must go at the end
840 unordered[ dock - 1 ].push_back( ndx );
841 }
842 }
843 else
844 {
845 // Create the bar (with the top dock being temporary parent)
846 bar->Create( mTopDock );
847
848 // Construct a NEW floater
849 wxASSERT(mParent);
850 ToolFrame *f = safenew ToolFrame( mParent, this, bar, wxPoint( x, y ) );
851
852 // Set the width and height
853 if( width[ ndx ] != -1 && height[ ndx ] != -1 )
854 {
855 wxSize sz( width[ ndx ], height[ ndx ] );
856 f->SetSizeHints( sz );
857 f->SetSize( sz );
858 f->Layout();
859 if( (x!=-1) && (y!=-1) )
860 bar->SetPositioned();
861 }
862
863 // Required on Linux Xfce
864 wxSize msz(width[ndx],height[ndx]-1);
865 bar->GetParent()->SetMinSize(msz);
866
867 // Inform toolbar of change
868 bar->SetDocked( NULL, false );
869
870 // Show or hide it
871 Expose( bar->GetSection(), show[ ndx ] );
872 }
873
874 // Change back to the bar root
875 //gPrefs->SetPath( wxT("..") ); <-- Causes a warning...
876 // May or may not have gone into a subdirectory,
877 // so use an absolute path.
878 gPrefs->SetPath( wxT("/GUI/ToolBars") );
879 });
880
881 mTopDock->GetConfiguration().PostRead(topLegacy);
882 mBotDock->GetConfiguration().PostRead(botLegacy);
883
884 // Add all toolbars to their target dock
885 for( dock = 0; dock < DockCount; dock++ )
886 {
887 ToolDock *d = ( dock + 1 == TopDockID ? mTopDock : mBotDock );
888
889 d->LoadConfig();
890
891 // Add all unordered toolbars
892 for( int ord = 0; ord < (int) unordered[ dock ].size(); ord++ )
893 {
894 ToolBar *t = mBars[unordered[dock][ord]].get();
895
896 // Dock it
897 d->Dock( t, false );
898
899 // Show or hide the bar
900 Expose( t->GetSection(), show[ t->GetSection() ] );
901 }
902 }
903
904 // hidden docked toolbars
905 for (auto bar : dockedAndHidden) {
906 bar->SetVisible(false );
907 bar->GetDock()->Dock(bar, false);
908 bar->Expose(false);
909 }
910
911 // Restore original config path
912 gPrefs->SetPath( oldpath );
913
914#if defined(__WXMAC__)
915 // Reinstate original transition
916 wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, mTransition );
917#endif
918
919 // Setup the neighbors according to the
920 // default config
921
922 for (const auto& entry : DefaultConfigTable)
923 {
924 const auto &ndx = entry.barID;
925 const auto bar = GetToolBar(ndx);
926 bar->SetPreferredNeighbors(entry.rightOf, entry.below);
927 }
928
929 if (!someFound)
930 Reset();
931}
wxT("CloseDown"))
FileConfig * gPrefs
Definition: Prefs.cpp:70
static ProjectFileIORegistry::AttributeWriterEntry entry
@ DockCount
Definition: ToolDock.h:45
static struct DefaultConfigEntry DefaultConfigTable[]
void GetVersionKeysInit(int &major, int &minor, int &micro) const
Definition: FileConfig.h:56
virtual const wxString & GetPath() const wxOVERRIDE
Definition: FileConfig.cpp:98
virtual void SetPath(const wxString &strPath) wxOVERRIDE
Definition: FileConfig.cpp:93
static bool Read(ToolBarConfiguration *pConfiguration, Legacy *pLegacy, ToolBar *bar, bool &visible, bool defaultVisible)
Definition: ToolDock.cpp:281
void PostRead(Legacy &legacy)
Definition: ToolDock.cpp:334
void SetVisible(bool bVisible)
Definition: ToolBar.cpp:446
virtual void ResizingDone()
Definition: ToolBar.h:197
void SetPositioned()
Definition: ToolBar.h:140
void SetPreferredNeighbors(Identifier left, Identifier top={})
Definition: ToolBar.cpp:652
virtual bool ShownByDefault() const
Whether the toolbar should be shown by default. Default implementation returns true.
Definition: ToolBar.cpp:365
virtual void Create(wxWindow *parent)
Definition: ToolBar.cpp:492
virtual DockID DefaultDockID() const
Which dock the toolbar defaults into. Default implementation chooses the top dock.
Definition: ToolBar.cpp:375
void LoadConfig()
Definition: ToolDock.cpp:466
void Expose(Identifier type, bool show)

References BotDockID, ToolBar::Create(), DefaultConfigTable, ToolBar::DefaultDockID(), ToolDock::Dock(), DockCount, entry, ToolBar::Expose(), Expose(), ForEach(), ToolDock::GetConfiguration(), ToolBar::GetDock(), FileConfig::GetPath(), ToolBar::GetSection(), GetToolBar(), FileConfig::GetVersionKeysInit(), gPrefs, ToolDock::LoadConfig(), mBars, mBotDock, mParent, mTopDock, mTransition, ToolBarConfiguration::PostRead(), ToolBarConfiguration::Read(), Reset(), ToolBar::ResizingDone(), safenew, ToolBar::SetDocked(), FileConfig::SetPath(), ToolBar::SetPositioned(), ToolBar::SetPreferredNeighbors(), ToolBar::SetVisible(), ToolBar::ShownByDefault(), size, TopDockID, and wxT().

Referenced by CreateWindows().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegenerateTooltips()

void ToolManager::RegenerateTooltips ( )

Definition at line 682 of file ToolManager.cpp.

683{
684 ForEach([](auto bar){
685 if (bar)
686 bar->RegenerateTooltips();
687 });
688}

References ForEach().

Referenced by ProjectManager::New().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Reset()

void ToolManager::Reset ( )

Definition at line 576 of file ToolManager.cpp.

577{
578 // Disconnect all docked bars
579 for ( const auto &entry : DefaultConfigTable )
580 {
581 const auto &ndx = entry.barID;
582 ToolBar *bar = GetToolBar(ndx);
583 if (!bar)
584 continue;
585
587 (entry.rightOf == Identifier{}) ? nullptr : GetToolBar(entry.rightOf),
588 (entry.below == Identifier{}) ? nullptr : GetToolBar(entry.below)
589 };
590
591 bar->SetSize( 20,20 );
592
593 wxWindow *floater;
594 ToolDock *dock;
595 bool expose = true;
596
597 // Disconnect the bar
598 if( bar->IsDocked() )
599 {
600 bar->GetDock()->Undock( bar );
601 floater = NULL;
602 }
603 else
604 {
605 floater = bar->GetParent();
606 }
607
608 // Decide which dock.
609 dock = (bar->DefaultDockID() == ToolBar::TopDockID)
610 ? mTopDock : mBotDock;
611
612 // PRL: Destroy the tool frame before recreating buttons.
613 // This fixes some subtle sizing problems on macOs.
614 bar->Reparent( dock );
615 //OK (and good) to DELETE floater, as bar is no longer in it.
616 if( floater )
617 floater->Destroy();
618
619 // Recreate bar buttons (and resize it)
620 bar->SetToDefaultSize();
621 bar->ReCreateButtons();
623
624#if 0
625 if( bar->IsResizable() )
626 {
627 bar->SetSize(bar->GetBestFittingSize());
628 }
629#endif
630
631 // Hide some bars.
632 expose = bar->ShownByDefault() || bar->HideAfterReset();
633
634 // Next condition will always (?) be true, as the reset configuration is
635 // with no floating toolbars.
636 if( dock != NULL )
637 {
638 // when we dock, we reparent, so bar is no longer a child of floater.
639 dock->Dock( bar, false, position );
640 Expose( bar->GetSection(), expose );
641 }
642 else
643 {
644 // The (tool)bar has a dragger window round it, the floater.
645 // in turn floater will have mParent (the entire App) as its
646 // parent.
647
648 // Maybe construct a NEW floater
649 // this happens if we have just been bounced out of a dock.
650 if( floater == NULL ) {
651 wxASSERT(mParent);
652 floater = safenew ToolFrame( mParent, this, bar, wxPoint(-1,-1) );
653 bar->Reparent( floater );
654 }
655
656 // This bar is undocked and invisible.
657 // We are doing a reset toolbars, so even the invisible undocked bars should
658 // be moved somewhere sensible. Put bar near center of window.
659 // If there were multiple hidden toobars the * 10 adjustment means
660 // they won't overlap too much.
661 floater->CentreOnParent( );
662 const auto index = bar->GetIndex();
663 floater->Move(
664 floater->GetPosition() + wxSize{ index * 10 - 200, index * 10 });
665 bar->SetDocked( NULL, false );
666 Expose( bar->GetSection(), false );
667 }
668 }
669
670 ForEach([this](auto bar){
671 if (bar && bar->HideAfterReset())
672 Expose(bar->GetSection(), false);
673 });
674 // TODO:??
675 // If audio was playing, we stopped the VU meters,
676 // It would be nice to show them again, but hardly essential as
677 // they will show up again on the next play.
678 // SetVUMeters(AudacityProject *p);
679 Updated();
680}
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
virtual void EnableDisableButtons()=0
@ TopDockID
Definition: ToolBar.h:93
virtual void ReCreateButtons()
Definition: ToolBar.cpp:533
bool IsResizable() const
Definition: ToolBar.cpp:425
int GetIndex() const
Get a value used for computing cascading positions of undocked bars.
Definition: ToolBar.h:112
virtual void SetToDefaultSize()
Definition: ToolBar.cpp:513
virtual bool HideAfterReset() const
Default implementation returns false.
Definition: ToolBar.cpp:370
void Undock(ToolBar *bar)
Definition: ToolDock.cpp:426

References DefaultConfigTable, ToolBar::DefaultDockID(), ToolDock::Dock(), ToolBar::EnableDisableButtons(), entry, Expose(), ForEach(), ToolBar::GetDock(), ToolBar::GetIndex(), ToolBar::GetSection(), GetToolBar(), ToolBar::HideAfterReset(), ToolBar::IsDocked(), ToolBar::IsResizable(), mBotDock, mParent, mTopDock, ToolBar::ReCreateButtons(), safenew, ToolBar::SetDocked(), ToolBar::SetToDefaultSize(), ToolBar::ShownByDefault(), ToolBar::TopDockID, ToolDock::Undock(), and Updated().

Referenced by ReadConfig().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RestoreFocus()

bool ToolManager::RestoreFocus ( )

Definition at line 1537 of file ToolManager.cpp.

1538{
1539 if (mLastFocus) {
1540 auto temp1 = AButton::TemporarilyAllowFocus();
1541 auto temp2 = ASlider::TemporarilyAllowFocus();
1543 mLastFocus->SetFocus();
1544 return true;
1545 }
1546 return false;
1547}
static TempAllowFocus TemporarilyAllowFocus()
Definition: AButton.cpp:658
static TempAllowFocus TemporarilyAllowFocus()
Definition: ASlider.cpp:1894
static TempAllowFocus TemporarilyAllowFocus()

References mLastFocus, AButton::TemporarilyAllowFocus(), ASlider::TemporarilyAllowFocus(), and MeterPanelBase::TemporarilyAllowFocus().

Referenced by DoneDragging().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ShowHide()

void ToolManager::ShowHide ( Identifier  type)

Definition at line 1073 of file ToolManager.cpp.

1074{
1075 Expose( type, !mBars[type]->IsVisible() );
1076 Updated();
1077}
bool IsVisible(Identifier type) const

References Expose(), IsVisible(), mBars, and Updated().

Referenced by ScreenshotCommand::CaptureToolbar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ UndockBar()

void ToolManager::UndockBar ( wxPoint  mp)
private

Definition at line 1394 of file ToolManager.cpp.

1395{
1396#if defined(__WXMAC__)
1397 // Disable window animation
1398 wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, 1 );
1399#endif
1400
1401 // Adjust the starting position
1402 mp -= mDragOffset;
1403
1404 // Inform toolbar of change
1405 mDragBar->SetDocked( NULL, true );
1407
1408 // Construct a NEW floater
1409 wxASSERT(mParent);
1411 mDragWindow->SetLayoutDirection(wxLayout_LeftToRight);
1412 // Make sure the ferry is visible
1413 mDragWindow->Show();
1414
1415 // Notify parent of change
1416 Updated();
1417
1418#if defined(__WXMAC__)
1419 // Reinstate original transition
1420 wxSystemOptions::SetOption( wxMAC_WINDOW_PLAIN_TRANSITION, mTransition );
1421#endif
1422}

References mDragBar, mDragOffset, mDragWindow, mParent, mTransition, safenew, ToolBar::SetDocked(), ToolBar::SetPositioned(), and Updated().

Referenced by OnMouse().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Updated()

void ToolManager::Updated ( )
private

Definition at line 1031 of file ToolManager.cpp.

1032{
1033 // Queue an update event
1034 wxCommandEvent e( EVT_TOOLBAR_UPDATED );
1035 GetProjectFrame( *mParent ).GetEventHandler()->AddPendingEvent( e );
1036}

References GetProjectFrame().

Referenced by HandleEscapeKey(), OnMouse(), Reset(), ShowHide(), and UndockBar().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ WriteConfig()

void ToolManager::WriteConfig ( )
private

Definition at line 936 of file ToolManager.cpp.

937{
938 if( !gPrefs )
939 {
940 return;
941 }
942
943 wxString oldpath = gPrefs->GetPath();
944 int ndx;
945
946 // Change to the bar root
947 gPrefs->SetPath( wxT("/GUI/ToolBars") );
948
949 // Save state of each bar
950 ForEach([this](ToolBar *bar){
951 // Change to the bar subkey
952 gPrefs->SetPath( bar->GetSection().GET() );
953
954 // Search both docks for toolbar order
955 bool to = mTopDock->GetConfiguration().Contains( bar );
956 bool bo = mBotDock->GetConfiguration().Contains( bar );
957
958 // Save
959 // Note that DockV2 was introduced in 2.2.2 to fix bug #1554. Dock is retained so that
960 // the toolbar layout is not changed when opening a version before 2.2.2, and in particular
961 // its value is compatible with versions 2.1.3 to 2.2.1 which have this bug.
962 ToolDock* dock = bar->GetDock(); // dock for both shown and hidden toolbars
963 gPrefs->Write( wxT("DockV2"), static_cast<int>(dock == mTopDock ? TopDockID : dock == mBotDock ? BotDockID : NoDockID ));
964
965 gPrefs->Write( wxT("Dock"), static_cast<int>( to ? TopDockID : bo ? BotDockID : NoDockID));
966
967 dock = to ? mTopDock : bo ? mBotDock : nullptr; // dock for shown toolbars
969 (dock ? &dock->GetConfiguration() : nullptr, bar);
970
971 wxPoint pos( -1, -1 );
972 wxSize sz = bar->GetSize();
973 if( !bar->IsDocked() && bar->IsPositioned() )
974 {
975 pos = bar->GetParent()->GetPosition();
976 sz = bar->GetParent()->GetSize();
977 }
978 gPrefs->Write( wxT("X"), pos.x );
979 gPrefs->Write( wxT("Y"), pos.y );
980 gPrefs->Write( wxT("W"), sz.x );
981 gPrefs->Write( wxT("H"), sz.y );
982
983 // Change back to the bar root
984 gPrefs->SetPath( wxT("..") );
985 });
986
987 // Restore original config path
988 gPrefs->SetPath( oldpath );
989 gPrefs->Flush();
990}
@ NoDockID
Definition: ToolDock.h:42
virtual bool Flush(bool bCurrentOnly=false) wxOVERRIDE
Definition: FileConfig.cpp:143
const wxString & GET() const
Explicit conversion to wxString, meant to be ugly-looking and demanding of a comment why it's correct...
Definition: Identifier.h:66
bool Contains(const ToolBar *bar) const
Definition: ToolDock.h:235
static void Write(const ToolBarConfiguration *pConfiguration, const ToolBar *bar)
Definition: ToolDock.cpp:355
bool IsPositioned()
Definition: ToolBar.h:138

References BotDockID, ToolBarConfiguration::Contains(), FileConfig::Flush(), ForEach(), Identifier::GET(), ToolDock::GetConfiguration(), ToolBar::GetDock(), FileConfig::GetPath(), ToolBar::GetSection(), gPrefs, ToolBar::IsDocked(), ToolBar::IsPositioned(), mBotDock, mTopDock, NoDockID, FileConfig::SetPath(), TopDockID, ToolBarConfiguration::Write(), and wxT().

Referenced by Destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

Member Data Documentation

◆ mBarPos

wxRect ToolManager::mBarPos
private

Definition at line 150 of file ToolManager.h.

Referenced by DoneDragging(), OnMouse(), and ToolManager().

◆ mBars

std::map<Identifier, ToolBar::Holder> ToolManager::mBars
private

map not unordered_map, for the promise made by ForEach

Definition at line 168 of file ToolManager.h.

Referenced by CreateWindows(), Destroy(), Expose(), GetToolBar(), ReadConfig(), and ShowHide().

◆ mBotDock

ToolDock* ToolManager::mBotDock {}
private

◆ mClicked

bool ToolManager::mClicked {}
private

Definition at line 176 of file ToolManager.h.

Referenced by DoneDragging(), OnGrabber(), and OnMouse().

◆ mCurrent

wxRegion* ToolManager::mCurrent
private

Definition at line 155 of file ToolManager.h.

Referenced by OnIndicatorCreate(), and OnMouse().

◆ mDidDrag

bool ToolManager::mDidDrag {}
private

Definition at line 175 of file ToolManager.h.

Referenced by DoneDragging(), and OnMouse().

◆ mDown

std::unique_ptr<wxRegion> ToolManager::mDown
private

Definition at line 154 of file ToolManager.h.

Referenced by OnMouse(), and ToolManager().

◆ mDragBar

ToolBar* ToolManager::mDragBar {}
private

Definition at line 145 of file ToolManager.h.

Referenced by DoneDragging(), HandleEscapeKey(), OnGrabber(), OnMouse(), ToolManager(), and UndockBar().

◆ mDragBefore

ToolBarConfiguration::Position ToolManager::mDragBefore {}
private

Definition at line 147 of file ToolManager.h.

Referenced by OnMouse().

◆ mDragDock

ToolDock* ToolManager::mDragDock
private

Definition at line 144 of file ToolManager.h.

Referenced by DoneDragging(), OnMouse(), and ToolManager().

◆ mDragOffset

wxPoint ToolManager::mDragOffset
private

Definition at line 146 of file ToolManager.h.

Referenced by OnGrabber(), OnMouse(), and UndockBar().

◆ mDragWindow

ToolFrame* ToolManager::mDragWindow
private

◆ mIndicator

FramePtr ToolManager::mIndicator
private

Definition at line 153 of file ToolManager.h.

Referenced by Destroy(), DoneDragging(), OnIndicatorCreate(), OnMouse(), OnTimer(), and ToolManager().

◆ mLastFocus

wxWindowRef ToolManager::mLastFocus {}
private

Definition at line 141 of file ToolManager.h.

Referenced by FilterEvent(), and RestoreFocus().

◆ mLastPos

wxPoint ToolManager::mLastPos
private

Definition at line 149 of file ToolManager.h.

Referenced by DoneDragging(), OnMouse(), and ToolManager().

◆ mLastState

bool ToolManager::mLastState
private

Definition at line 158 of file ToolManager.h.

Referenced by OnGrabber(), and OnTimer().

◆ mLeft

std::unique_ptr<wxRegion> ToolManager::mLeft
private

Definition at line 154 of file ToolManager.h.

Referenced by OnMouse(), and ToolManager().

◆ mMenuManagerSubscription

Observer::Subscription ToolManager::mMenuManagerSubscription
private

Definition at line 139 of file ToolManager.h.

Referenced by CreateWindows().

◆ mParent

AudacityProject* ToolManager::mParent
private

◆ mPrevConfiguration

ToolBarConfiguration ToolManager::mPrevConfiguration
private

Definition at line 174 of file ToolManager.h.

Referenced by DoneDragging(), HandleEscapeKey(), OnGrabber(), and OnMouse().

◆ mPrevDock

ToolDock* ToolManager::mPrevDock {}
private

Definition at line 171 of file ToolManager.h.

Referenced by DoneDragging(), HandleEscapeKey(), OnGrabber(), and OnMouse().

◆ mPrevPosition

wxPoint ToolManager::mPrevPosition {}
private

Definition at line 170 of file ToolManager.h.

Referenced by HandleEscapeKey(), and OnGrabber().

◆ mPrevSlot

Definition at line 172 of file ToolManager.h.

Referenced by DoneDragging(), HandleEscapeKey(), and OnGrabber().

◆ mTimer

wxTimer ToolManager::mTimer
private

Definition at line 157 of file ToolManager.h.

Referenced by CreateWindows(), DoneDragging(), and OnGrabber().

◆ mTopDock

ToolDock* ToolManager::mTopDock {}
private

◆ mTransition

bool ToolManager::mTransition
private

Definition at line 161 of file ToolManager.h.

Referenced by OnMouse(), OnTimer(), ReadConfig(), ToolManager(), and UndockBar().


The documentation for this class was generated from the following files: