26#include <com/sun/star/beans/XPropertySet.hpp>
27#include <com/sun/star/frame/XLayoutManager.hpp>
30#include <osl/mutex.hxx>
39#include <svx/svxids.hrc>
46#include <osl/diagnose.h>
66 Reference<frame::XLayoutManager> mxLayouter;
68 explicit LayouterLock (
const Reference<frame::XLayoutManager>& rxLayouter);
70 bool is()
const {
return mxLayouter.is(); }
85 void GetToolBarsToActivate (std::vector<OUString>& rToolBars)
const;
86 void GetToolBarsToDeactivate (std::vector<OUString>& rToolBars)
const;
88 void MarkToolBarAsActive (
const OUString& rsName);
89 void MarkToolBarAsNotActive (
const OUString& rsName);
90 void MarkAllToolBarsAsNotActive();
93 typedef ::std::map<sd::ToolBarManager::ToolBarGroup, std::vector<OUString> >
Groups;
95 std::vector<OUString> maActiveToolBars;
97 void MakeRequestedToolBarList (std::vector<OUString>& rToolBars)
const;
115class ToolBarShellList
145 void ReleaseAllShells (ToolBarRules& rRules);
157 const std::shared_ptr<ViewShell>& rpMainViewShell,
158 const std::shared_ptr<ViewShellManager>& rpManager);
161 class ShellDescriptor
166 friend bool operator<(
const ShellDescriptor& r1,
const ShellDescriptor& r2)
167 {
return r1.mnId < r2.mnId; }
173 typedef ::std::set<ShellDescriptor> GroupedShellList;
174 GroupedShellList maNewList;
180 GroupedShellList maCurrentList;
190 std::shared_ptr<ToolBarManager> pToolBarManager,
191 std::shared_ptr<ViewShellManager> pViewShellManager);
206 void MainViewShellChanged (
const ViewShell& rMainViewShell);
211 void SelectionHasChanged (
212 const ::sd::ViewShell& rViewShell,
223 void SubShellRemoved (
228 std::shared_ptr<ToolBarManager> mpToolBarManager;
229 std::shared_ptr<ViewShellManager> mpViewShellManager;
249 std::shared_ptr<sd::tools::EventMultiplexer> pMultiplexer,
250 const std::shared_ptr<ViewShellManager>& rpViewShellManager,
251 const std::shared_ptr<ToolBarManager>& rpToolBarManager);
283 void Update (::std::unique_ptr<LayouterLock> pLayouterLock);
319 ::std::unique_ptr<ViewShellManager::UpdateLock, o3tl::default_delete<ViewShellManager::UpdateLock>>
mpViewShellManagerLock;
336 const std::shared_ptr<sd::tools::EventMultiplexer>& rpMultiplexer,
337 const std::shared_ptr<ViewShellManager>& rpViewShellManager)
340 pManager->mpImpl.reset(
341 new Implementation(rBase,rpMultiplexer,rpViewShellManager,pManager));
364 mpImpl->ResetToolBars(eGroup);
373 mpImpl->ResetAllToolBars();
379 const OUString& rsToolBarName)
384 mpImpl->AddToolBar(eGroup,rsToolBarName);
395 mpImpl->AddToolBarShell(eGroup,nToolBarId);
401 const OUString& rsToolBarName)
406 mpImpl->RemoveToolBar(eGroup,rsToolBarName);
412 const OUString& rsToolBarName)
417 mpImpl->ResetToolBars(eGroup);
418 mpImpl->AddToolBar(eGroup,rsToolBarName);
429 mpImpl->ResetToolBars(eGroup);
430 mpImpl->AddToolBarShell(eGroup,nToolBarId);
449 mpImpl->LockViewShellManager();
468 mpImpl->ReleaseAllToolBarShells();
477 mpImpl->ReleaseAllToolBarShells();
478 mpImpl->GetToolBarRules().MainViewShellChanged(rMainViewShell);
487 mpImpl->GetToolBarRules().SelectionHasChanged(rViewShell,rView);
493 mpImpl->ToolBarsDestroyed();
500 std::shared_ptr<sd::tools::EventMultiplexer> pMultiplexer,
501 const std::shared_ptr<ViewShellManager>& rpViewShellManager,
502 const std::shared_ptr<ToolBarManager>& rpToolBarManager)
507 mbPreUpdatePending(false),
508 mbPostUpdatePending(false),
509 mnPendingUpdateCall(nullptr),
510 mnPendingSetValidCall(nullptr),
511 maToolBarRules(rpToolBarManager,rpViewShellManager)
528 if (mnPendingUpdateCall !=
nullptr)
530 if (mnPendingSetValidCall !=
nullptr)
536 maToolBarList.MarkAllToolBarsAsNotActive();
541 ::osl::MutexGuard aGuard(
maMutex);
543 if (mbIsValid == bValid)
551 Reference<frame::XFrame>
xFrame = mrBase.GetViewFrame().GetFrame().GetFrameInterface();
554 Reference<beans::XPropertySet> xFrameProperties (
xFrame, UNO_QUERY_THROW);
555 Any aValue (xFrameProperties->getPropertyValue(
"LayoutManager"));
556 aValue >>= mxLayouter;
559 if (mpSynchronousLayouterLock && !mpSynchronousLayouterLock->is())
560 mpSynchronousLayouterLock.reset(
new LayouterLock(mxLayouter));
562 catch (
const RuntimeException&)
566 GetToolBarRules().Update(mrBase);
571 mxLayouter =
nullptr;
577 ::osl::MutexGuard aGuard(
maMutex);
579 maToolBarList.ClearGroup(eGroup);
580 maToolBarShellList.ClearGroup(eGroup);
582 mbPreUpdatePending =
true;
587 SAL_INFO(
"sd.view", __func__ <<
": resetting all tool bars");
594 const OUString& rsToolBarName)
596 ::osl::MutexGuard aGuard(
maMutex);
598 if (CheckPlugInMode(rsToolBarName))
600 maToolBarList.AddToolBar(eGroup,rsToolBarName);
602 mbPostUpdatePending =
true;
603 if (mnLockCount == 0)
610 const OUString& rsToolBarName)
612 ::osl::MutexGuard aGuard(
maMutex);
614 if (maToolBarList.RemoveToolBar(eGroup,rsToolBarName))
616 mbPreUpdatePending =
true;
617 if (mnLockCount == 0)
626 ViewShell* pMainViewShell = mrBase.GetMainViewShell().get();
627 if (pMainViewShell !=
nullptr)
629 maToolBarShellList.AddShellId(eGroup,nToolBarId);
630 GetToolBarRules().SubShellAdded(eGroup, nToolBarId);
636 maToolBarShellList.ReleaseAllShells(GetToolBarRules());
637 maToolBarShellList.UpdateShells(mrBase.GetMainViewShell(), mrBase.GetViewShellManager());
642 if (mnPendingUpdateCall ==
nullptr)
651 ::osl::MutexGuard aGuard(
maMutex);
654 && mbPreUpdatePending
658 mbPreUpdatePending =
false;
660 SAL_INFO(
"sd.view", __func__ <<
": ToolBarManager::PreUpdate [");
664 std::vector<OUString> aToolBars;
665 maToolBarList.GetToolBarsToDeactivate(aToolBars);
668 for (
const auto& aToolBar : aToolBars)
670 OUString sFullName (GetToolBarResourceName(aToolBar));
671 SAL_INFO(
"sd.view", __func__ <<
": turning off tool bar " << sFullName);
672 mxLayouter->destroyElement(sFullName);
673 maToolBarList.MarkToolBarAsNotActive(aToolBar);
676 SAL_INFO(
"sd.view", __func__ <<
": ToolBarManager::PreUpdate ]");
681 ::osl::MutexGuard aGuard(
maMutex);
684 && mbPostUpdatePending
688 mbPostUpdatePending =
false;
691 std::vector<OUString> aToolBars;
692 maToolBarList.GetToolBarsToActivate(aToolBars);
694 SAL_INFO(
"sd.view", __func__ <<
": ToolBarManager::PostUpdate [");
697 for (
const auto& aToolBar : aToolBars)
699 OUString sFullName (GetToolBarResourceName(aToolBar));
700 SAL_INFO(
"sd.view", __func__ <<
": turning on tool bar " << sFullName);
701 mxLayouter->requestElement(sFullName);
702 maToolBarList.MarkToolBarAsActive(aToolBar);
705 SAL_INFO(
"sd.view", __func__ <<
": ToolBarManager::PostUpdate ]");
710 if (mpViewShellManagerLock ==
nullptr)
711 mpViewShellManagerLock.reset(
717 SAL_INFO(
"sd.view", __func__ <<
": LockUpdate " << mnLockCount);
718 ::osl::MutexGuard aGuard(
maMutex);
720 DBG_ASSERT(mnLockCount<100,
"ToolBarManager lock count unusually high");
721 if (mnLockCount == 0)
723 OSL_ASSERT(mpSynchronousLayouterLock ==
nullptr);
725 mpSynchronousLayouterLock.reset(
new LayouterLock(mxLayouter));
732 SAL_INFO(
"sd.view", __func__ <<
": UnlockUpdate " << mnLockCount);
733 ::osl::MutexGuard aGuard(
maMutex);
735 OSL_ASSERT(mnLockCount>0);
737 if (mnLockCount == 0)
739 Update(std::move(mpSynchronousLayouterLock));
744 ::std::unique_ptr<LayouterLock> pLocalLayouterLock)
748 if (mnLockCount != 0)
757 if (mnPendingSetValidCall !=
nullptr)
760 mnPendingSetValidCall =
nullptr;
764 if (mbIsValid && mxLayouter.is() && (mbPreUpdatePending || mbPostUpdatePending))
769 if (mbPreUpdatePending)
776 if (mpViewShellManagerLock ==
nullptr)
777 mpViewShellManagerLock.reset(
779 maToolBarShellList.UpdateShells(
780 mrBase.GetMainViewShell(),
781 mrBase.GetViewShellManager());
785 mpViewShellManagerLock.reset();
799 mpAsynchronousLayouterLock = std::move(pLocalLayouterLock);
800 if (mnPendingUpdateCall==
nullptr)
809 mpViewShellManagerLock.reset();
810 pLocalLayouterLock.reset();
816 mnPendingUpdateCall =
nullptr;
817 if (mnLockCount == 0)
819 if (mbPreUpdatePending)
821 if (mbPostUpdatePending)
823 if (mbIsValid && mxLayouter.is())
824 mpAsynchronousLayouterLock.reset();
832 switch (rEvent.meEventId)
835 if (mnPendingSetValidCall ==
nullptr)
836 mnPendingSetValidCall
850 mnPendingSetValidCall =
nullptr;
855 std::u16string_view rsBaseName)
857 return OUString::Concat(
"private:resource/toolbar/") + rsBaseName;
865 bool bIsPlugInMode (
false);
869 if (pObjectShell ==
nullptr)
873 if (pMedium ==
nullptr)
877 if (pViewOnlyItem ==
nullptr)
880 bIsPlugInMode = pViewOnlyItem->
GetValue();
885 bValid = bIsPlugInMode;
887 bValid = ! bIsPlugInMode;
900LayouterLock::LayouterLock (
const Reference<frame::XLayoutManager>& rxLayouter)
901 : mxLayouter(rxLayouter)
908LayouterLock::~LayouterLock()
910 SAL_INFO(
"sd.view", __func__ <<
": ~LayouterLock " << (mxLayouter.is() ? 1 :0));
912 mxLayouter->unlock();
917ToolBarRules::ToolBarRules (
918 std::shared_ptr<sd::ToolBarManager> pToolBarManager,
919 std::shared_ptr<sd::ViewShellManager> pViewShellManager)
920 : mpToolBarManager(
std::move(pToolBarManager)),
921 mpViewShellManager(
std::move(pViewShellManager))
928 if (pMainViewShell !=
nullptr)
943 mpToolBarManager->ResetAllToolBars();
947 case ::sd::ViewShell::ST_IMPRESS:
948 case ::sd::ViewShell::ST_NOTES:
949 case ::sd::ViewShell::ST_HANDOUT:
950 mpToolBarManager->AddToolBar(
953 mpToolBarManager->AddToolBar(
956 mpToolBarManager->AddToolBar(
961 case ::sd::ViewShell::ST_DRAW:
962 mpToolBarManager->AddToolBar(
965 mpToolBarManager->AddToolBar(
968 mpToolBarManager->AddToolBar(
974 mpToolBarManager->AddToolBar(
977 mpToolBarManager->AddToolBar(
980 mpToolBarManager->AddToolBarShell(
985 mpToolBarManager->AddToolBar(
988 mpToolBarManager->AddToolBar(
991 mpToolBarManager->AddToolBar(
1004void ToolBarRules::MainViewShellChanged (
const ViewShell& rMainViewShell)
1012 case ::sd::ViewShell::ST_IMPRESS:
1013 case ::sd::ViewShell::ST_DRAW:
1014 case ::sd::ViewShell::ST_NOTES:
1018 if (pDrawViewShell !=
nullptr)
1021 mpToolBarManager->AddToolBar(
1025 mpToolBarManager->AddToolBar(
1037void ToolBarRules::SelectionHasChanged (
1038 const ::sd::ViewShell& rViewShell,
1042 mpToolBarManager->LockViewShellManager();
1051 case SdrViewContext::Graphic:
1054 ToolbarId::Draw_Graf_Toolbox);
1057 case SdrViewContext::Media:
1060 ToolbarId::Draw_Media_Toolbox);
1063 case SdrViewContext::Table:
1065 ToolbarId::Draw_Table_Toolbox);
1069 case SdrViewContext::Standard:
1073 switch(rViewShell.GetShellType())
1075 case ::sd::ViewShell::ST_IMPRESS:
1076 case ::sd::ViewShell::ST_DRAW:
1077 case ::sd::ViewShell::ST_NOTES:
1078 case ::sd::ViewShell::ST_HANDOUT:
1103 if (rView.
GetContext() == SdrViewContext::PointEdit)
1107void ToolBarRules::SubShellAdded (
1115 case ToolbarId::Draw_Graf_Toolbox:
1119 case ToolbarId::Draw_Media_Toolbox:
1123 case ToolbarId::Draw_Text_Toolbox_Sd:
1127 case ToolbarId::Bezier_Toolbox_Sd:
1131 case ToolbarId::Draw_Table_Toolbox:
1140void ToolBarRules::SubShellRemoved (
1148 case ToolbarId::Draw_Graf_Toolbox:
1152 case ToolbarId::Draw_Media_Toolbox:
1156 case ToolbarId::Draw_Text_Toolbox_Sd:
1160 case ToolbarId::Bezier_Toolbox_Sd:
1164 case ToolbarId::Draw_Table_Toolbox:
1175ToolBarList::ToolBarList()
1181 Groups::iterator iGroup (maGroups.find(eGroup));
1182 if (iGroup != maGroups.end())
1184 iGroup->second.clear();
1188void ToolBarList::AddToolBar (
1190 const OUString& rsName)
1192 Groups::iterator iGroup (maGroups.find(eGroup));
1193 if (iGroup == maGroups.end())
1194 iGroup = maGroups.emplace(eGroup,std::vector<OUString>()).first;
1196 if (iGroup != maGroups.end())
1198 auto iBar (std::find(iGroup->second.cbegin(),iGroup->second.cend(),rsName));
1199 if (iBar == iGroup->second.cend())
1201 iGroup->second.push_back(rsName);
1206bool ToolBarList::RemoveToolBar (
1208 const OUString& rsName)
1210 Groups::iterator iGroup (maGroups.find(eGroup));
1211 if (iGroup != maGroups.end())
1213 auto iBar (std::find(iGroup->second.begin(),iGroup->second.end(),rsName));
1214 if (iBar != iGroup->second.end())
1216 iGroup->second.erase(iBar);
1223void ToolBarList::MakeRequestedToolBarList (std::vector<OUString>& rRequestedToolBars)
const
1227 Groups::const_iterator iGroup (maGroups.find(eGroup));
1228 if (iGroup != maGroups.end())
1229 rRequestedToolBars.insert( rRequestedToolBars.end(),
1230 iGroup->second.begin(),
1231 iGroup->second.end() );
1235void ToolBarList::GetToolBarsToActivate (std::vector<OUString>& rToolBars)
const
1237 std::vector<OUString> aRequestedToolBars;
1238 MakeRequestedToolBarList(aRequestedToolBars);
1240 for (
const auto& aToolBar : aRequestedToolBars)
1242 if (::std::find(maActiveToolBars.begin(),maActiveToolBars.end(),aToolBar)
1243 == maActiveToolBars.end())
1245 rToolBars.push_back(aToolBar);
1250void ToolBarList::GetToolBarsToDeactivate (std::vector<OUString>& rToolBars)
const
1252 std::vector<OUString> aRequestedToolBars;
1253 MakeRequestedToolBarList(aRequestedToolBars);
1255 for (
auto& aToolBar : maActiveToolBars)
1257 if (::std::find(aRequestedToolBars.begin(),aRequestedToolBars.end(),aToolBar)
1258 == aRequestedToolBars.end())
1260 rToolBars.push_back(aToolBar);
1265void ToolBarList::MarkToolBarAsActive (
const OUString& rsName)
1267 maActiveToolBars.push_back(rsName);
1270void ToolBarList::MarkToolBarAsNotActive (
const OUString& rsName)
1272 maActiveToolBars.erase(
1273 ::std::find(maActiveToolBars.begin(),maActiveToolBars.end(), rsName));
1276void ToolBarList::MarkAllToolBarsAsNotActive()
1278 maActiveToolBars.clear();
1283ToolBarShellList::ShellDescriptor::ShellDescriptor (
1291ToolBarShellList::ToolBarShellList()
1297 for (GroupedShellList::iterator iDescriptor = maNewList.begin(); iDescriptor != maNewList.end(); )
1298 if (iDescriptor->meGroup == eGroup)
1299 iDescriptor = maNewList.erase(iDescriptor);
1308 ShellDescriptor aDescriptor (nId,eGroup);
1309 GroupedShellList::iterator iDescriptor (maNewList.find(aDescriptor));
1310 if (iDescriptor != maNewList.end())
1313 if (iDescriptor->meGroup != eGroup)
1318 maNewList.erase(iDescriptor);
1319 maNewList.insert(aDescriptor);
1324 maNewList.insert(aDescriptor);
1327void ToolBarShellList::ReleaseAllShells (ToolBarRules& rRules)
1330 GroupedShellList aList (maCurrentList);
1331 for (
const auto& rDescriptor : aList)
1333 rRules.SubShellRemoved(rDescriptor.meGroup, rDescriptor.mnId);
1340void ToolBarShellList::UpdateShells (
1341 const std::shared_ptr<ViewShell>& rpMainViewShell,
1342 const std::shared_ptr<ViewShellManager>& rpManager)
1344 if (rpMainViewShell ==
nullptr)
1347 GroupedShellList aList;
1351 ::std::set_difference(maCurrentList.begin(), maCurrentList.end(),
1352 maNewList.begin(), maNewList.end(),
1353 std::insert_iterator<GroupedShellList>(aList,aList.begin()));
1354 for (
const auto& rShell : aList)
1356 SAL_INFO(
"sd.view", __func__ <<
": deactivating tool bar shell " <<
static_cast<sal_uInt32
>(rShell.mnId));
1357 rpManager->DeactivateSubShell(*rpMainViewShell, rShell.mnId);
1363 ::std::set_difference(maNewList.begin(), maNewList.end(),
1364 maCurrentList.begin(), maCurrentList.end(),
1365 std::insert_iterator<GroupedShellList>(aList,aList.begin()));
1366 for (
const auto& rShell : aList)
1368 SAL_INFO(
"sd.view", __func__ <<
": activating tool bar shell " <<
static_cast<sal_uInt32
>(rShell.mnId));
1369 rpManager->ActivateSubShell(*rpMainViewShell, rShell.mnId);
1374 maCurrentList = maNewList;
@ ControllerDetached
A UNO controller has been detached to the UNO frame.
@ ControllerAttached
A UNO controller has been attached to the UNO frame.
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
static void RemoveUserEvent(ImplSVEvent *nUserEvent)
virtual bool IsTextEdit() const final override
virtual SdrViewContext GetContext() const
const SfxPoolItem * GetItem(sal_uInt16 nWhich, bool bSearchInParent=true) const
SfxItemSet & GetItemSet() const
SfxMedium * GetMedium() const
Base class of the stacked shells that provide graphical views to Draw and Impress documents and editi...
EditMode GetEditMode() const
SfxViewShell descendant that the stacked Draw/Impress shells are based on.
std::shared_ptr< ViewShell > GetMainViewShell() const
Return the main view shell stacked on the called ViewShellBase object.
Use this class to safely lock updates of the view shell stack.
Base class of the stacked shell hierarchy.
::sd::View * GetView() const
SD_DLLPUBLIC ShellType GetShellType() const
Return the type of the shell.
static bool IsActive(bool bConsiderSingleToolbar=false)
#define DBG_ASSERT(sCon, aError)
EventMultiplexerImpl * mpEventMultiplexer
#define LINK(Instance, Class, Member)
#define SAL_INFO(area, stream)
IMPL_LINK_NOARG(MainSequence, onTimerHdl, Timer *, void)
IMPL_LINK(SdCharHeightPropertyBox, implMenuSelectHdl, const OUString &, rIdent, void)
bool checkForSelectedCustomShapes(SdrView const *pSdrView, bool bOnlyExtruded)
bool checkForSelectedFontWork(SdrView const *pSdrView)
Reference< XFrame > xFrame
bool operator<(const wwFont &r1, const wwFont &r2)