bump product version to 5.0.4.1
[LibreOffice.git] / sd / source / ui / view / ToolBarManager.cxx
blobe2bafba0142d7b339ab5b4b8377c467b015f5cfa
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include "ToolBarManager.hxx"
22 #include "DrawViewShell.hxx"
23 #include "EventMultiplexer.hxx"
24 #include "ViewShellBase.hxx"
25 #include "ViewShellManager.hxx"
26 #include <com/sun/star/beans/XPropertySet.hpp>
27 #include <com/sun/star/frame/XLayoutManager.hpp>
28 #include <com/sun/star/ui/UIElementType.hpp>
30 #include <cppuhelper/implbase1.hxx>
31 #include <osl/mutex.hxx>
32 #include <rtl/ref.hxx>
33 #include <sfx2/app.hxx>
34 #include <sfx2/docfile.hxx>
35 #include <sfx2/objsh.hxx>
36 #include <sfx2/request.hxx>
37 #include <sfx2/viewfrm.hxx>
38 #include <svl/eitem.hxx>
39 #include <svx/dialogs.hrc>
40 #include <svx/extrusionbar.hxx>
41 #include <svx/fontworkbar.hxx>
42 #include <toolkit/helper/vclunohelper.hxx>
43 #include <tools/link.hxx>
45 #include <map>
46 #include <utility>
47 #include <vector>
49 using namespace ::com::sun::star;
50 using namespace ::com::sun::star::uno;
52 namespace {
54 using namespace sd;
56 class ToolBarRules;
58 /** Lock of the frame::XLayoutManager.
60 class LayouterLock
62 public:
63 LayouterLock (const Reference<frame::XLayoutManager>& rxLayouter);
64 ~LayouterLock();
65 private:
66 Reference<frame::XLayoutManager> mxLayouter;
69 typedef ::std::vector<OUString> NameList;
71 /** Store a list of tool bars for each of the tool bar groups. From
72 this the list of requested tool bars is built.
74 class ToolBarList
76 public:
77 ToolBarList();
79 void ClearGroup (sd::ToolBarManager::ToolBarGroup eGroup);
80 void AddToolBar (sd::ToolBarManager::ToolBarGroup eGroup, const OUString& rsName);
81 bool RemoveToolBar (sd::ToolBarManager::ToolBarGroup eGroup, const OUString& rsName);
83 void GetToolBarsToActivate (NameList& rToolBars) const;
84 void GetToolBarsToDeactivate (NameList& rToolBars) const;
86 void MarkToolBarAsActive (const OUString& rsName);
87 void MarkToolBarAsNotActive (const OUString& rsName);
88 void MarkAllToolBarsAsNotActive();
90 private:
91 typedef ::std::map<sd::ToolBarManager::ToolBarGroup,NameList> Groups;
92 Groups maGroups;
93 NameList maActiveToolBars;
95 void MakeRequestedToolBarList (NameList& rToolBars) const;
98 /** Manage tool bars that are implemented as sub shells of a view shell.
99 The typical procedure of updating the sub shells of a view shell is to
100 rebuild a list of sub shells that the caller would like to have active.
101 The methods ClearGroup() and AddShellId() allow the caller to do that. A
102 final call to UpdateShells() activates the requested shells that are not
103 active and deactivates the active shells that are not requested .
105 This is done by maintaining two lists. One (the current list)
106 reflects the current state. The other (the requested list) contains the
107 currently requested shells. UpdateShells() makes the requested
108 list the current list and clears the current list.
110 Each shell belongs to one group. Different groups can be modified
111 separately.
113 class ToolBarShellList
115 public:
116 /** Create a new object with an empty current list and an empty
117 requested list.
119 ToolBarShellList();
121 /** Remove all shells from a group. Calling this method should normally
122 not be necessary because after the construction or after a call to
123 UpdateShells() the requested list is empty.
124 @param eGroup
125 The group to clear. Shells in other groups are not modified.
127 void ClearGroup (sd::ToolBarManager::ToolBarGroup eGroup);
129 /** Add a shell. When the specified shell has alreadt been requested
130 for another group then it is moved to this group.
131 @param eGroup
132 The group to which to add the shell.
133 @param nId
134 The id of the shell to add.
136 void AddShellId (sd::ToolBarManager::ToolBarGroup eGroup, sd::ShellId nId);
138 /** Releasing all shells means that the given ToolBarRules object is
139 informed that every shell mananged by the called ToolBarShellList is
140 about to be removed and that the associated framework tool bars can
141 be removed as well. The caller still has to call UpdateShells().
143 void ReleaseAllShells (ToolBarRules& rRules);
145 /** The requested list is made the current list by activating all
146 shells in the requested list and by deactivating the shells in the
147 current list that are not in the requested list.
148 @param pMainViewShell
149 The shells that are activated or deactivated are sub shells of
150 this view shell.
151 @param rManager
152 This ViewShellManager is used to activate or deactivate shells.
154 void UpdateShells (
155 const ::boost::shared_ptr<ViewShell>& rpMainViewShell,
156 const ::boost::shared_ptr<ViewShellManager>& rpManager);
158 private:
159 class ShellDescriptor
160 {public:
161 ShellDescriptor (ShellId nId,sd::ToolBarManager::ToolBarGroup eGroup);
162 ShellId mnId;
163 sd::ToolBarManager::ToolBarGroup meGroup;
164 friend bool operator<(const ShellDescriptor& r1, const ShellDescriptor& r2)
165 { return r1.mnId < r2.mnId; }
168 /** The requested list of tool bar shells that will be active after the
169 next call to UpdateShells().
171 typedef ::std::set<ShellDescriptor> GroupedShellList;
172 GroupedShellList maNewList;
174 /** The list of tool bar shells that are currently on the shell stack.
175 Using a GroupedShellList is not strictly necessary but it makes
176 things easier and does not waste too much memory.
178 GroupedShellList maCurrentList;
181 /** This class concentrates the knowledge about when to show what tool bars
182 in one place.
184 class ToolBarRules
186 public:
187 ToolBarRules (
188 const ::boost::shared_ptr<ToolBarManager>& rpToolBarManager,
189 const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager);
191 /** This method calls MainViewShellChanged() and SelectionHasChanged()
192 for the current main view shell and its view.
194 void Update (ViewShellBase& rBase);
196 /** Reset all tool bars in all groups and add tool bars and tool bar
197 shells to the TBG_PERMANENT group for the specified ViewShell type.
199 void MainViewShellChanged (ViewShell::ShellType nShellType);
201 /** Reset all tool bars in all groups and add tool bars and tool bar
202 shells to the TBG_PERMANENT group for the specified ViewShell.
204 void MainViewShellChanged (const ViewShell& rMainViewShell);
206 /** Reset all tool bars in the TBG_FUNCTION group and add tool bars and tool bar
207 shells to this group for the current selection.
209 void SelectionHasChanged (
210 const ::sd::ViewShell& rViewShell,
211 const SdrView& rView);
213 /** Add a tool bar for the specified tool bar shell.
215 void SubShellAdded (
216 ::sd::ToolBarManager::ToolBarGroup eGroup,
217 sd::ShellId nShellId);
219 /** Remove a tool bar for the specified tool bar shell.
221 void SubShellRemoved (
222 ::sd::ToolBarManager::ToolBarGroup eGroup,
223 sd::ShellId nShellId);
225 private:
226 ::boost::shared_ptr<ToolBarManager> mpToolBarManager;
227 ::boost::shared_ptr<ViewShellManager> mpViewShellManager;
230 } // end of anonymous namespace
232 namespace sd {
234 //===== ToolBarManager::Implementation ========================================
236 class ToolBarManager::Implementation
238 public:
239 /** This constructor takes three arguments even though the
240 ToolBarManager could be taken from the ViewShellBase. This is so to
241 state explicitly which information has to be present when this
242 constructor is called. The ViewShellBase may not have been fully
243 initialized at this point and must not be asked for this values.
245 Implementation (
246 ViewShellBase& rBase,
247 const ::boost::shared_ptr<sd::tools::EventMultiplexer>& rpMultiplexer,
248 const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager,
249 const ::boost::shared_ptr<ToolBarManager>& rpToolBarManager);
250 ~Implementation();
252 void SetValid (bool bValid);
254 void ResetToolBars (ToolBarGroup eGroup);
255 void ResetAllToolBars();
256 void AddToolBar (ToolBarGroup eGroup, const OUString& rsToolBarName);
257 void AddToolBarShell (ToolBarGroup eGroup, ShellId nToolBarId);
258 void RemoveToolBar (ToolBarGroup eGroup, const OUString& rsToolBarName);
260 /** Release all tool bar shells and the associated framework tool bars.
261 Typically called when the main view shell is being replaced by
262 another, all tool bar shells are released. In that process the
263 shells are destroyed anyway and without calling this method they
264 would still be referenced.
266 void ReleaseAllToolBarShells();
268 void ToolBarsDestroyed();
270 void RequestUpdate();
272 void PreUpdate();
273 void PostUpdate();
274 /** Tell the XLayoutManager about the tool bars that we would like to be
275 shown.
276 @param rpLayouterLock
277 This typically is the mpSynchronousLayouterLock that is used in
278 this method and that is either released at its end or assigned
279 to mpAsynchronousLock in order to be unlocked later.
281 void Update (::std::unique_ptr<LayouterLock> pLayouterLock);
283 class UpdateLockImplementation
285 public:
286 UpdateLockImplementation (Implementation& rImplementation)
287 : mrImplementation(rImplementation) { mrImplementation.LockUpdate(); }
288 ~UpdateLockImplementation() { mrImplementation.UnlockUpdate(); }
289 private:
290 Implementation& mrImplementation;
293 void LockViewShellManager();
294 void LockUpdate();
295 void UnlockUpdate();
297 ToolBarRules& GetToolBarRules() { return maToolBarRules;}
299 private:
300 const static OUString msToolBarResourcePrefix;
302 mutable ::osl::Mutex maMutex;
303 ViewShellBase& mrBase;
304 ::boost::shared_ptr<sd::tools::EventMultiplexer> mpEventMultiplexer;
305 bool mbIsValid;
306 ToolBarList maToolBarList;
307 ToolBarShellList maToolBarShellList;
308 Reference<frame::XLayoutManager> mxLayouter;
309 sal_Int32 mnLockCount;
310 bool mbPreUpdatePending;
311 bool mbPostUpdatePending;
312 /** The layouter locks manage the locking of the XLayoutManager. The
313 lock() and unlock() functions are not called directly because the
314 (final) unlocking is usually done asynchronously *after* the
315 list of requested toolbars is updated.
317 ::std::unique_ptr<LayouterLock> mpSynchronousLayouterLock;
318 ::std::unique_ptr<LayouterLock> mpAsynchronousLayouterLock;
319 ::std::unique_ptr<ViewShellManager::UpdateLock> mpViewShellManagerLock;
320 ImplSVEvent * mnPendingUpdateCall;
321 ImplSVEvent * mnPendingSetValidCall;
322 ToolBarRules maToolBarRules;
324 static OUString GetToolBarResourceName (const OUString& rsBaseName);
325 bool CheckPlugInMode (const OUString& rsName) const;
327 DECL_LINK(UpdateCallback, void *);
328 DECL_LINK(EventMultiplexerCallback, sd::tools::EventMultiplexerEvent*);
329 DECL_LINK(SetValidCallback,void*);
332 //===== ToolBarManager ========================================================
334 const OUString ToolBarManager::msToolBar("toolbar");
335 const OUString ToolBarManager::msOptionsToolBar("optionsbar");
336 const OUString ToolBarManager::msCommonTaskToolBar("commontaskbar");
337 const OUString ToolBarManager::msViewerToolBar("viewerbar");
338 const OUString ToolBarManager::msSlideSorterToolBar("slideviewtoolbar");
339 const OUString ToolBarManager::msSlideSorterObjectBar("slideviewobjectbar");
340 const OUString ToolBarManager::msOutlineToolBar("outlinetoolbar");
341 const OUString ToolBarManager::msMasterViewToolBar("masterviewtoolbar");
342 const OUString ToolBarManager::msDrawingObjectToolBar("drawingobjectbar");
343 const OUString ToolBarManager::msGluePointsToolBar("gluepointsobjectbar");
344 const OUString ToolBarManager::msTextObjectBar("textobjectbar");
345 const OUString ToolBarManager::msBezierObjectBar("bezierobjectbar");
346 const OUString ToolBarManager::msGraphicObjectBar("graphicobjectbar");
347 const OUString ToolBarManager::msMediaObjectBar("mediaobjectbar");
348 const OUString ToolBarManager::msTableObjectBar("tableobjectbar");
350 ::boost::shared_ptr<ToolBarManager> ToolBarManager::Create (
351 ViewShellBase& rBase,
352 const ::boost::shared_ptr<sd::tools::EventMultiplexer>& rpMultiplexer,
353 const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager)
355 ::boost::shared_ptr<ToolBarManager> pManager (new ToolBarManager());
356 pManager->mpImpl.reset(
357 new Implementation(rBase,rpMultiplexer,rpViewShellManager,pManager));
358 return pManager;
361 ToolBarManager::ToolBarManager()
362 : mpImpl()
366 ToolBarManager::~ToolBarManager()
370 void ToolBarManager::Shutdown()
372 if (mpImpl.get() != NULL)
373 mpImpl.reset();
376 void ToolBarManager::ResetToolBars (ToolBarGroup eGroup)
378 if (mpImpl.get() != NULL)
380 UpdateLock aLock (shared_from_this());
381 mpImpl->ResetToolBars(eGroup);
385 void ToolBarManager::ResetAllToolBars()
387 if (mpImpl.get() != NULL)
389 UpdateLock aLock (shared_from_this());
390 mpImpl->ResetAllToolBars();
394 void ToolBarManager::AddToolBar (
395 ToolBarGroup eGroup,
396 const OUString& rsToolBarName)
398 if (mpImpl.get() != NULL)
400 UpdateLock aLock (shared_from_this());
401 mpImpl->AddToolBar(eGroup,rsToolBarName);
405 void ToolBarManager::AddToolBarShell (
406 ToolBarGroup eGroup,
407 ShellId nToolBarId)
409 if (mpImpl.get() != NULL)
411 UpdateLock aLock (shared_from_this());
412 mpImpl->AddToolBarShell(eGroup,nToolBarId);
416 void ToolBarManager::RemoveToolBar (
417 ToolBarGroup eGroup,
418 const OUString& rsToolBarName)
420 if (mpImpl.get() != NULL)
422 UpdateLock aLock (shared_from_this());
423 mpImpl->RemoveToolBar(eGroup,rsToolBarName);
427 void ToolBarManager::SetToolBar (
428 ToolBarGroup eGroup,
429 const OUString& rsToolBarName)
431 if (mpImpl.get() != NULL)
433 UpdateLock aLock (shared_from_this());
434 mpImpl->ResetToolBars(eGroup);
435 mpImpl->AddToolBar(eGroup,rsToolBarName);
439 void ToolBarManager::SetToolBarShell (
440 ToolBarGroup eGroup,
441 ShellId nToolBarId)
443 if (mpImpl.get() != NULL)
445 UpdateLock aLock (shared_from_this());
446 mpImpl->ResetToolBars(eGroup);
447 mpImpl->AddToolBarShell(eGroup,nToolBarId);
451 void ToolBarManager::PreUpdate()
453 if (mpImpl.get()!=NULL)
454 mpImpl->PreUpdate();
457 void ToolBarManager::RequestUpdate()
459 if (mpImpl.get()!=NULL)
460 mpImpl->RequestUpdate();
463 void ToolBarManager::LockViewShellManager()
465 if (mpImpl.get() != NULL)
466 mpImpl->LockViewShellManager();
469 void ToolBarManager::LockUpdate()
471 if (mpImpl.get()!=NULL)
472 mpImpl->LockUpdate();
475 void ToolBarManager::UnlockUpdate()
477 if (mpImpl.get()!=NULL)
478 mpImpl->UnlockUpdate();
481 void ToolBarManager::MainViewShellChanged (ViewShell::ShellType nShellType)
483 if (mpImpl.get() != NULL)
485 mpImpl->ReleaseAllToolBarShells();
486 mpImpl->GetToolBarRules().MainViewShellChanged(nShellType);
490 void ToolBarManager::MainViewShellChanged (const ViewShell& rMainViewShell)
492 if (mpImpl.get() != NULL)
494 mpImpl->ReleaseAllToolBarShells();
495 mpImpl->GetToolBarRules().MainViewShellChanged(rMainViewShell);
499 void ToolBarManager::SelectionHasChanged (
500 const ViewShell& rViewShell,
501 const SdrView& rView)
503 if (mpImpl.get() != NULL)
504 mpImpl->GetToolBarRules().SelectionHasChanged(rViewShell,rView);
507 void ToolBarManager::ToolBarsDestroyed()
509 if (mpImpl.get() != NULL)
510 mpImpl->ToolBarsDestroyed();
513 //===== ToolBarManager::Implementation =======================================
515 const OUString ToolBarManager::Implementation::msToolBarResourcePrefix("private:resource/toolbar/");
517 ToolBarManager::Implementation::Implementation (
518 ViewShellBase& rBase,
519 const ::boost::shared_ptr<sd::tools::EventMultiplexer>& rpMultiplexer,
520 const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager,
521 const ::boost::shared_ptr<ToolBarManager>& rpToolBarManager)
522 : maMutex(),
523 mrBase(rBase),
524 mpEventMultiplexer(rpMultiplexer),
525 mbIsValid(false),
526 maToolBarList(),
527 maToolBarShellList(),
528 mxLayouter(NULL),
529 mnLockCount(0),
530 mbPreUpdatePending(false),
531 mbPostUpdatePending(false),
532 mpSynchronousLayouterLock(),
533 mpAsynchronousLayouterLock(),
534 mpViewShellManagerLock(),
535 mnPendingUpdateCall(0),
536 mnPendingSetValidCall(0),
537 maToolBarRules(rpToolBarManager,rpViewShellManager)
539 Link<> aLink (LINK(this,ToolBarManager::Implementation,EventMultiplexerCallback));
540 mpEventMultiplexer->AddEventListener(
541 aLink,
542 tools::EventMultiplexerEvent::EID_CONTROLLER_ATTACHED
543 | tools::EventMultiplexerEvent::EID_CONTROLLER_DETACHED
544 | tools::EventMultiplexerEvent::EID_PANE_MANAGER_DYING);
547 /** The order of statements is important.
548 First unregister listeners, which may post user events.
549 Then remove pending user events.
551 ToolBarManager::Implementation::~Implementation()
553 // Unregister at broadcasters.
554 Link<> aLink (LINK(this,ToolBarManager::Implementation,EventMultiplexerCallback));
555 mpEventMultiplexer->RemoveEventListener(aLink);
557 // Abort pending user calls.
558 if (mnPendingUpdateCall != 0)
559 Application::RemoveUserEvent(mnPendingUpdateCall);
560 if (mnPendingSetValidCall != 0)
561 Application::RemoveUserEvent(mnPendingSetValidCall);
564 void ToolBarManager::Implementation::ToolBarsDestroyed()
566 maToolBarList.MarkAllToolBarsAsNotActive();
569 void ToolBarManager::Implementation::SetValid (bool bValid)
571 ::osl::MutexGuard aGuard(maMutex);
573 if (mbIsValid != bValid)
575 UpdateLockImplementation aUpdateLock (*this);
577 mbIsValid = bValid;
578 if (mbIsValid)
580 Reference<frame::XFrame> xFrame;
581 if (mrBase.GetViewFrame() != NULL)
582 xFrame = mrBase.GetViewFrame()->GetFrame().GetFrameInterface();
585 Reference<beans::XPropertySet> xFrameProperties (xFrame, UNO_QUERY_THROW);
586 Any aValue (xFrameProperties->getPropertyValue("LayoutManager"));
587 aValue >>= mxLayouter;
589 catch (const RuntimeException&)
593 GetToolBarRules().Update(mrBase);
595 else
597 ResetAllToolBars();
598 mxLayouter = NULL;
603 void ToolBarManager::Implementation::ResetToolBars (ToolBarGroup eGroup)
605 ::osl::MutexGuard aGuard(maMutex);
607 maToolBarList.ClearGroup(eGroup);
608 maToolBarShellList.ClearGroup(eGroup);
610 mbPreUpdatePending = true;
613 void ToolBarManager::Implementation::ResetAllToolBars()
615 SAL_INFO("sd.view", OSL_THIS_FUNC << ": resetting all tool bars");
616 for (int i=TBG__FIRST; i<=TBG__LAST; ++i)
617 ResetToolBars((ToolBarGroup)i);
620 void ToolBarManager::Implementation::AddToolBar (
621 ToolBarGroup eGroup,
622 const OUString& rsToolBarName)
624 ::osl::MutexGuard aGuard(maMutex);
626 if (CheckPlugInMode(rsToolBarName))
628 maToolBarList.AddToolBar(eGroup,rsToolBarName);
630 mbPostUpdatePending = true;
631 if (mnLockCount == 0)
632 PostUpdate();
636 void ToolBarManager::Implementation::RemoveToolBar (
637 ToolBarGroup eGroup,
638 const OUString& rsToolBarName)
640 ::osl::MutexGuard aGuard(maMutex);
642 if (maToolBarList.RemoveToolBar(eGroup,rsToolBarName))
644 mbPreUpdatePending = true;
645 if (mnLockCount == 0)
646 PreUpdate();
650 void ToolBarManager::Implementation::AddToolBarShell (
651 ToolBarGroup eGroup,
652 ShellId nToolBarId)
654 ViewShell* pMainViewShell = mrBase.GetMainViewShell().get();
655 if (pMainViewShell != NULL)
657 maToolBarShellList.AddShellId(eGroup,nToolBarId);
658 GetToolBarRules().SubShellAdded(eGroup, nToolBarId);
662 void ToolBarManager::Implementation::ReleaseAllToolBarShells()
664 maToolBarShellList.ReleaseAllShells(GetToolBarRules());
665 maToolBarShellList.UpdateShells(mrBase.GetMainViewShell(), mrBase.GetViewShellManager());
668 void ToolBarManager::Implementation::RequestUpdate()
670 if (mnPendingUpdateCall == 0)
672 mnPendingUpdateCall = Application::PostUserEvent(
673 LINK(this,ToolBarManager::Implementation,UpdateCallback));
677 void ToolBarManager::Implementation::PreUpdate()
679 ::osl::MutexGuard aGuard(maMutex);
681 if (mbIsValid
682 && mbPreUpdatePending
683 && mxLayouter.is())
685 mbPreUpdatePending = false;
687 SAL_INFO("sd.view", OSL_THIS_FUNC << ": ToolBarManager::PreUpdate [");
689 // Get the list of tool bars that are not used anymore and are to be
690 // deactivated.
691 NameList aToolBars;
692 maToolBarList.GetToolBarsToDeactivate(aToolBars);
694 // Turn off the tool bars.
695 NameList::const_iterator iToolBar;
696 for (iToolBar=aToolBars.begin(); iToolBar!=aToolBars.end(); ++iToolBar)
698 OUString sFullName (GetToolBarResourceName(*iToolBar));
699 SAL_INFO("sd.view", OSL_THIS_FUNC << ": turning off tool bar " <<
700 OUStringToOString(sFullName, RTL_TEXTENCODING_UTF8).getStr());
701 mxLayouter->destroyElement(sFullName);
702 maToolBarList.MarkToolBarAsNotActive(*iToolBar);
705 SAL_INFO("sd.view", OSL_THIS_FUNC << ": ToolBarManager::PreUpdate ]");
709 void ToolBarManager::Implementation::PostUpdate()
711 ::osl::MutexGuard aGuard(maMutex);
713 if (mbIsValid
714 && mbPostUpdatePending
715 && mxLayouter.is())
717 mbPostUpdatePending = false;
719 // Create the list of requested tool bars.
720 NameList aToolBars;
721 maToolBarList.GetToolBarsToActivate(aToolBars);
723 SAL_INFO("sd.view", OSL_THIS_FUNC << ": ToolBarManager::PostUpdate [");
725 // Turn on the tool bars that are visible in the new context.
726 NameList::const_iterator iToolBar;
727 for (iToolBar=aToolBars.begin(); iToolBar!=aToolBars.end(); ++iToolBar)
729 OUString sFullName (GetToolBarResourceName(*iToolBar));
730 SAL_INFO("sd.view", OSL_THIS_FUNC << ": turning on tool bar " <<
731 OUStringToOString(sFullName, RTL_TEXTENCODING_UTF8).getStr());
732 mxLayouter->requestElement(sFullName);
733 maToolBarList.MarkToolBarAsActive(*iToolBar);
736 SAL_INFO("sd.view", OSL_THIS_FUNC << ": ToolBarManager::PostUpdate ]");
740 void ToolBarManager::Implementation::LockViewShellManager()
742 if (mpViewShellManagerLock.get() == NULL)
743 mpViewShellManagerLock.reset(
744 new ViewShellManager::UpdateLock(mrBase.GetViewShellManager()));
747 void ToolBarManager::Implementation::LockUpdate()
749 SAL_INFO("sd.view", OSL_THIS_FUNC << ": LockUpdate " << mnLockCount);
750 ::osl::MutexGuard aGuard(maMutex);
752 DBG_ASSERT(mnLockCount<100, "ToolBarManager lock count unusually high");
753 if (mnLockCount == 0)
755 OSL_ASSERT(mpSynchronousLayouterLock.get()==NULL);
757 mpSynchronousLayouterLock.reset(new LayouterLock(mxLayouter));
759 ++mnLockCount;
762 void ToolBarManager::Implementation::UnlockUpdate()
764 SAL_INFO("sd.view", OSL_THIS_FUNC << ": UnlockUpdate " << mnLockCount);
765 ::osl::MutexGuard aGuard(maMutex);
767 OSL_ASSERT(mnLockCount>0);
768 --mnLockCount;
769 if (mnLockCount == 0)
771 Update(std::move(mpSynchronousLayouterLock));
775 void ToolBarManager::Implementation::Update (
776 ::std::unique_ptr<LayouterLock> pLocalLayouterLock)
778 // When the lock is released and there are pending changes to the set of
779 // tool bars then update this set now.
780 if (mnLockCount == 0)
782 // During ceation of ViewShellBase we may have the situation that
783 // the controller has already been created and attached to the frame
784 // but that the ToolBarManager has not yet completed its
785 // initialization (by initializing the mxLayouter member.) We do
786 // this here so that we do not have to wait for the next Update()
787 // call to show the tool bars.
788 if (mnPendingSetValidCall != 0)
790 Application::RemoveUserEvent(mnPendingSetValidCall);
791 mnPendingSetValidCall = 0;
792 SetValid(true);
795 if (mbIsValid && mxLayouter.is() && (mbPreUpdatePending || mbPostUpdatePending))
797 // 1) Release UNO tool bars that are not longer used. Do this
798 // now so that they are not updated when the SFX shell stack is
799 // modified.
800 if (mbPreUpdatePending)
801 PreUpdate();
803 // 2) Update the requested shells that represent tool bar
804 // functionality. Those that are not used anymore are
805 // deactivated now. Those that are missing are activated in the
806 // next step together with the view shells.
807 if (mpViewShellManagerLock.get() == NULL)
808 mpViewShellManagerLock.reset(
809 new ViewShellManager::UpdateLock(mrBase.GetViewShellManager()));
810 maToolBarShellList.UpdateShells(
811 mrBase.GetMainViewShell(),
812 mrBase.GetViewShellManager());
814 // 3) Unlock the ViewShellManager::UpdateLock. This updates the
815 // shell stack. We have to be carfull here. The deletion of
816 // the lock may end in a synchronous call to LockUpdate(). When
817 // at this time the lock has been deleted but the unique_ptr has
818 // not yet been reset then the lock is deleted a second time.
819 ViewShellManager::UpdateLock* pLock = mpViewShellManagerLock.release();
820 delete pLock;
822 // 4) Make the UNO tool bars visible. The outstanding call to
823 // PostUpdate() is done via PostUserEvent() so that it is
824 // guaranteed to be executed when the SFX shell stack has been
825 // updated (under the assumption that our lock to the
826 // ViewShellManager was the only one open. If that is not the
827 // case then all should still be well but not as fast.)
829 // Note that the lock count may have been increased since
830 // entering this method. In that case one of the next
831 // UnlockUpdate() calls will post the UpdateCallback.
832 if (mnPendingUpdateCall==0 && mnLockCount==0)
834 mpAsynchronousLayouterLock = std::move(pLocalLayouterLock);
835 mnPendingUpdateCall = Application::PostUserEvent(
836 LINK(this,ToolBarManager::Implementation,UpdateCallback));
839 else
841 //do this in two steps, first clear mpViewShellManagerLock to be NULL
842 ViewShellManager::UpdateLock* pLock = mpViewShellManagerLock.release();
843 //now delete the lock so reentry to this method triggered by this
844 //delete will encounter an empty mpViewShellManagerLock
845 delete pLock;
846 pLocalLayouterLock.reset();
851 IMPL_LINK_NOARG(ToolBarManager::Implementation, UpdateCallback)
853 mnPendingUpdateCall = 0;
854 if (mnLockCount == 0)
856 if (mbPreUpdatePending)
857 PreUpdate();
858 if (mbPostUpdatePending)
859 PostUpdate();
860 if (mbIsValid && mxLayouter.is())
861 mpAsynchronousLayouterLock.reset();
863 return 0;
866 IMPL_LINK(ToolBarManager::Implementation,EventMultiplexerCallback,
867 sd::tools::EventMultiplexerEvent*,pEvent)
869 if (pEvent != NULL)
871 switch (pEvent->meEventId)
873 case tools::EventMultiplexerEvent::EID_CONTROLLER_ATTACHED:
874 if (mnPendingSetValidCall == 0)
875 mnPendingSetValidCall
876 = Application::PostUserEvent(LINK(this,Implementation,SetValidCallback));
877 break;
879 case tools::EventMultiplexerEvent::EID_CONTROLLER_DETACHED:
880 SetValid(false);
881 break;
883 case tools::EventMultiplexerEvent::EID_PANE_MANAGER_DYING:
884 SetValid(false);
885 break;
888 return 0;
891 IMPL_LINK_NOARG(ToolBarManager::Implementation, SetValidCallback)
893 mnPendingSetValidCall = 0;
894 SetValid(true);
895 return 0;
898 OUString ToolBarManager::Implementation::GetToolBarResourceName (
899 const OUString& rsBaseName)
901 OUString sToolBarName (msToolBarResourcePrefix);
902 sToolBarName += rsBaseName;
903 return sToolBarName;
906 bool ToolBarManager::Implementation::CheckPlugInMode (const OUString& rsName) const
908 bool bValid (false);
910 // Determine the plug in mode.
911 bool bIsPlugInMode (false);
914 SfxObjectShell* pObjectShell = mrBase.GetObjectShell();
915 if (pObjectShell == NULL)
916 break;
918 SfxMedium* pMedium = pObjectShell->GetMedium();
919 if (pMedium == NULL)
920 break;
922 SFX_ITEMSET_ARG(pMedium->GetItemSet(),pViewOnlyItem,SfxBoolItem,SID_VIEWONLY,false);
923 if (pViewOnlyItem == NULL)
924 break;
926 bIsPlugInMode = pViewOnlyItem->GetValue();
928 while (false);
930 if (rsName.equals(msViewerToolBar))
931 bValid = bIsPlugInMode;
932 else
933 bValid = ! bIsPlugInMode;
935 return bValid;
938 } // end of namespace sd
940 namespace {
942 using namespace ::sd;
944 //===== LayouterLock ==========================================================
946 LayouterLock::LayouterLock (const Reference<frame::XLayoutManager>& rxLayouter)
947 : mxLayouter(rxLayouter)
949 SAL_INFO("sd.view", OSL_THIS_FUNC << ": LayouterLock " << (mxLayouter.is() ? 1 :0));
950 if (mxLayouter.is())
951 mxLayouter->lock();
954 LayouterLock::~LayouterLock()
956 SAL_INFO("sd.view", OSL_THIS_FUNC << ": ~LayouterLock " << (mxLayouter.is() ? 1 :0));
957 if (mxLayouter.is())
958 mxLayouter->unlock();
961 //===== ToolBarRules ==========================================================
963 ToolBarRules::ToolBarRules (
964 const ::boost::shared_ptr<sd::ToolBarManager>& rpToolBarManager,
965 const ::boost::shared_ptr<sd::ViewShellManager>& rpViewShellManager)
966 : mpToolBarManager(rpToolBarManager),
967 mpViewShellManager(rpViewShellManager)
971 void ToolBarRules::Update (ViewShellBase& rBase)
973 ViewShell* pMainViewShell = rBase.GetMainViewShell().get();
974 if (pMainViewShell != NULL)
976 MainViewShellChanged(pMainViewShell->GetShellType());
977 if (pMainViewShell->GetView())
978 SelectionHasChanged (*pMainViewShell, *pMainViewShell->GetView());
980 else
981 MainViewShellChanged(ViewShell::ST_NONE);
984 void ToolBarRules::MainViewShellChanged (ViewShell::ShellType nShellType)
986 ::sd::ToolBarManager::UpdateLock aToolBarManagerLock (mpToolBarManager);
987 ::sd::ViewShellManager::UpdateLock aViewShellManagerLock (mpViewShellManager);
989 mpToolBarManager->ResetAllToolBars();
991 switch(nShellType)
993 case ::sd::ViewShell::ST_IMPRESS:
994 case ::sd::ViewShell::ST_NOTES:
995 case ::sd::ViewShell::ST_HANDOUT:
996 mpToolBarManager->AddToolBar(
997 ToolBarManager::TBG_PERMANENT,
998 ToolBarManager::msToolBar);
999 mpToolBarManager->AddToolBar(
1000 ToolBarManager::TBG_PERMANENT,
1001 ToolBarManager::msOptionsToolBar);
1002 mpToolBarManager->AddToolBar(
1003 ToolBarManager::TBG_PERMANENT,
1004 ToolBarManager::msViewerToolBar);
1005 break;
1007 case ::sd::ViewShell::ST_DRAW:
1008 mpToolBarManager->AddToolBar(
1009 ToolBarManager::TBG_PERMANENT,
1010 ToolBarManager::msToolBar);
1011 mpToolBarManager->AddToolBar(
1012 ToolBarManager::TBG_PERMANENT,
1013 ToolBarManager::msOptionsToolBar);
1014 mpToolBarManager->AddToolBar(
1015 ToolBarManager::TBG_PERMANENT,
1016 ToolBarManager::msViewerToolBar);
1017 break;
1019 case ViewShell::ST_OUTLINE:
1020 mpToolBarManager->AddToolBar(
1021 ToolBarManager::TBG_PERMANENT,
1022 ToolBarManager::msOutlineToolBar);
1023 mpToolBarManager->AddToolBar(
1024 ToolBarManager::TBG_PERMANENT,
1025 ToolBarManager::msViewerToolBar);
1026 mpToolBarManager->AddToolBarShell(
1027 ToolBarManager::TBG_PERMANENT, RID_DRAW_TEXT_TOOLBOX);
1028 break;
1030 case ViewShell::ST_SLIDE_SORTER:
1031 mpToolBarManager->AddToolBar(
1032 ToolBarManager::TBG_PERMANENT,
1033 ToolBarManager::msViewerToolBar);
1034 mpToolBarManager->AddToolBar(
1035 ToolBarManager::TBG_PERMANENT,
1036 ToolBarManager::msSlideSorterToolBar);
1037 mpToolBarManager->AddToolBar(
1038 ToolBarManager::TBG_PERMANENT,
1039 ToolBarManager::msSlideSorterObjectBar);
1040 break;
1042 case ViewShell::ST_NONE:
1043 case ViewShell::ST_PRESENTATION:
1044 case ViewShell::ST_SIDEBAR:
1045 default:
1046 break;
1050 void ToolBarRules::MainViewShellChanged (const ViewShell& rMainViewShell)
1052 ::sd::ToolBarManager::UpdateLock aToolBarManagerLock (mpToolBarManager);
1053 ::sd::ViewShellManager::UpdateLock aViewShellManagerLock (mpViewShellManager);
1055 MainViewShellChanged(rMainViewShell.GetShellType());
1056 switch(rMainViewShell.GetShellType())
1058 case ::sd::ViewShell::ST_IMPRESS:
1059 case ::sd::ViewShell::ST_DRAW:
1060 case ::sd::ViewShell::ST_NOTES:
1062 const DrawViewShell* pDrawViewShell
1063 = dynamic_cast<const DrawViewShell*>(&rMainViewShell);
1064 if (pDrawViewShell != NULL)
1066 if (pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
1067 mpToolBarManager->AddToolBar(
1068 ToolBarManager::TBG_MASTER_MODE,
1069 ToolBarManager::msMasterViewToolBar);
1070 else if ( rMainViewShell.GetShellType() != ::sd::ViewShell::ST_DRAW )
1071 mpToolBarManager->AddToolBar(
1072 ToolBarManager::TBG_COMMON_TASK,
1073 ToolBarManager::msCommonTaskToolBar);
1075 break;
1078 default:
1079 break;
1083 void ToolBarRules::SelectionHasChanged (
1084 const ::sd::ViewShell& rViewShell,
1085 const SdrView& rView)
1087 ::sd::ToolBarManager::UpdateLock aLock (mpToolBarManager);
1088 mpToolBarManager->LockViewShellManager();
1089 bool bTextEdit = rView.IsTextEdit();
1091 mpToolBarManager->ResetToolBars(ToolBarManager::TBG_FUNCTION);
1093 switch (rView.GetContext())
1095 case SDRCONTEXT_GRAPHIC:
1096 if( !bTextEdit )
1097 mpToolBarManager->SetToolBarShell(ToolBarManager::TBG_FUNCTION, RID_DRAW_GRAF_TOOLBOX);
1098 break;
1100 case SDRCONTEXT_MEDIA:
1101 if( !bTextEdit )
1102 mpToolBarManager->SetToolBarShell(ToolBarManager::TBG_FUNCTION, RID_DRAW_MEDIA_TOOLBOX);
1103 break;
1105 case SDRCONTEXT_TABLE:
1106 mpToolBarManager->SetToolBarShell(ToolBarManager::TBG_FUNCTION, RID_DRAW_TABLE_TOOLBOX);
1107 bTextEdit = true;
1108 break;
1110 case SDRCONTEXT_STANDARD:
1111 default:
1112 if( !bTextEdit )
1114 switch(rViewShell.GetShellType())
1116 case ::sd::ViewShell::ST_IMPRESS:
1117 case ::sd::ViewShell::ST_DRAW:
1118 case ::sd::ViewShell::ST_NOTES:
1119 case ::sd::ViewShell::ST_HANDOUT:
1120 mpToolBarManager->SetToolBar(
1121 ToolBarManager::TBG_FUNCTION,
1122 ToolBarManager::msDrawingObjectToolBar);
1123 break;
1124 default:
1125 break;
1127 break;
1131 if( bTextEdit )
1132 mpToolBarManager->AddToolBarShell(ToolBarManager::TBG_FUNCTION, RID_DRAW_TEXT_TOOLBOX);
1134 SdrView* pView = &const_cast<SdrView&>(rView);
1135 // Check if the extrusion tool bar and the fontwork tool bar have to
1136 // be activated.
1137 if (svx::checkForSelectedCustomShapes(pView, true /* bOnlyExtruded */ ))
1138 mpToolBarManager->AddToolBarShell(ToolBarManager::TBG_FUNCTION, RID_SVX_EXTRUSION_BAR);
1139 sal_uInt32 nCheckStatus = 0;
1140 if (svx::checkForSelectedFontWork(pView, nCheckStatus))
1141 mpToolBarManager->AddToolBarShell(ToolBarManager::TBG_FUNCTION, RID_SVX_FONTWORK_BAR);
1143 // Switch on additional context-sensitive tool bars.
1144 if (rView.GetContext() == SDRCONTEXT_POINTEDIT)
1145 mpToolBarManager->AddToolBarShell(ToolBarManager::TBG_FUNCTION, RID_BEZIER_TOOLBOX);
1148 void ToolBarRules::SubShellAdded (
1149 ::sd::ToolBarManager::ToolBarGroup eGroup,
1150 sd::ShellId nShellId)
1152 // For some tool bar shells (those defined in sd) we have to add the
1153 // actual tool bar here.
1154 switch (nShellId)
1156 case RID_DRAW_GRAF_TOOLBOX:
1157 mpToolBarManager->AddToolBar(eGroup, ToolBarManager::msGraphicObjectBar);
1158 break;
1160 case RID_DRAW_MEDIA_TOOLBOX:
1161 mpToolBarManager->AddToolBar(eGroup, ToolBarManager::msMediaObjectBar);
1162 break;
1164 case RID_DRAW_TEXT_TOOLBOX:
1165 mpToolBarManager->AddToolBar(eGroup, ToolBarManager::msTextObjectBar);
1166 break;
1168 case RID_BEZIER_TOOLBOX:
1169 mpToolBarManager->AddToolBar(eGroup, ToolBarManager::msBezierObjectBar);
1170 break;
1172 case RID_DRAW_TABLE_TOOLBOX:
1173 mpToolBarManager->AddToolBar(eGroup, ToolBarManager::msTableObjectBar);
1174 break;
1178 void ToolBarRules::SubShellRemoved (
1179 ::sd::ToolBarManager::ToolBarGroup eGroup,
1180 sd::ShellId nShellId)
1182 // For some tool bar shells (those defined in sd) we have to add the
1183 // actual tool bar here.
1184 switch (nShellId)
1186 case RID_DRAW_GRAF_TOOLBOX:
1187 mpToolBarManager->RemoveToolBar(eGroup, ToolBarManager::msGraphicObjectBar);
1188 break;
1190 case RID_DRAW_MEDIA_TOOLBOX:
1191 mpToolBarManager->RemoveToolBar(eGroup, ToolBarManager::msMediaObjectBar);
1192 break;
1194 case RID_DRAW_TEXT_TOOLBOX:
1195 mpToolBarManager->RemoveToolBar(eGroup, ToolBarManager::msTextObjectBar);
1196 break;
1198 case RID_BEZIER_TOOLBOX:
1199 mpToolBarManager->RemoveToolBar(eGroup, ToolBarManager::msBezierObjectBar);
1200 break;
1202 case RID_DRAW_TABLE_TOOLBOX:
1203 mpToolBarManager->RemoveToolBar(eGroup, ToolBarManager::msTableObjectBar);
1204 break;
1208 //===== ToolBarList ===========================================================
1210 ToolBarList::ToolBarList()
1211 : maGroups(),
1212 maActiveToolBars()
1216 void ToolBarList::ClearGroup (sd::ToolBarManager::ToolBarGroup eGroup)
1218 Groups::iterator iGroup (maGroups.find(eGroup));
1219 if (iGroup != maGroups.end())
1221 if ( ! iGroup->second.empty())
1223 iGroup->second.clear();
1228 void ToolBarList::AddToolBar (
1229 sd::ToolBarManager::ToolBarGroup eGroup,
1230 const OUString& rsName)
1232 Groups::iterator iGroup (maGroups.find(eGroup));
1233 if (iGroup == maGroups.end())
1234 iGroup = maGroups.insert(Groups::value_type(eGroup,NameList())).first;
1236 if (iGroup != maGroups.end())
1238 NameList::const_iterator iBar (
1239 ::std::find(iGroup->second.begin(),iGroup->second.end(),rsName));
1240 if (iBar == iGroup->second.end())
1242 iGroup->second.push_back(rsName);
1247 bool ToolBarList::RemoveToolBar (
1248 sd::ToolBarManager::ToolBarGroup eGroup,
1249 const OUString& rsName)
1251 Groups::iterator iGroup (maGroups.find(eGroup));
1252 if (iGroup != maGroups.end())
1254 NameList::iterator iBar (
1255 ::std::find(iGroup->second.begin(),iGroup->second.end(),rsName));
1256 if (iBar != iGroup->second.end())
1258 iGroup->second.erase(iBar);
1259 return true;
1262 return false;
1265 void ToolBarList::MakeRequestedToolBarList (NameList& rRequestedToolBars) const
1267 for (int i=sd::ToolBarManager::TBG__FIRST; i<=sd::ToolBarManager::TBG__LAST; ++i)
1269 ::sd::ToolBarManager::ToolBarGroup eGroup = (::sd::ToolBarManager::ToolBarGroup)i;
1270 Groups::const_iterator iGroup (maGroups.find(eGroup));
1271 if (iGroup != maGroups.end())
1272 ::std::copy(
1273 iGroup->second.begin(),
1274 iGroup->second.end(),
1275 ::std::inserter(rRequestedToolBars,rRequestedToolBars.end()));
1279 void ToolBarList::GetToolBarsToActivate (NameList& rToolBars) const
1281 NameList aRequestedToolBars;
1282 MakeRequestedToolBarList(aRequestedToolBars);
1284 NameList::const_iterator iToolBar;
1285 for (iToolBar=aRequestedToolBars.begin(); iToolBar!=aRequestedToolBars.end(); ++iToolBar)
1287 if (::std::find(maActiveToolBars.begin(),maActiveToolBars.end(),*iToolBar)
1288 == maActiveToolBars.end())
1290 rToolBars.push_back(*iToolBar);
1295 void ToolBarList::GetToolBarsToDeactivate (NameList& rToolBars) const
1297 NameList aRequestedToolBars;
1298 MakeRequestedToolBarList(aRequestedToolBars);
1300 NameList::const_iterator iToolBar;
1301 for (iToolBar=maActiveToolBars.begin(); iToolBar!=maActiveToolBars.end(); ++iToolBar)
1303 if (::std::find(aRequestedToolBars.begin(),aRequestedToolBars.end(),*iToolBar)
1304 == aRequestedToolBars.end())
1306 rToolBars.push_back(*iToolBar);
1311 void ToolBarList::MarkToolBarAsActive (const OUString& rsName)
1313 maActiveToolBars.push_back(rsName);
1316 void ToolBarList::MarkToolBarAsNotActive (const OUString& rsName)
1318 maActiveToolBars.erase(
1319 ::std::find(maActiveToolBars.begin(),maActiveToolBars.end(), rsName));
1322 void ToolBarList::MarkAllToolBarsAsNotActive()
1324 maActiveToolBars.clear();
1327 //===== ToolBarShellList ======================================================
1329 ToolBarShellList::ShellDescriptor::ShellDescriptor (
1330 ShellId nId,
1331 sd::ToolBarManager::ToolBarGroup eGroup)
1332 : mnId(nId),
1333 meGroup(eGroup)
1337 ToolBarShellList::ToolBarShellList()
1338 : maNewList()
1339 , maCurrentList()
1343 void ToolBarShellList::ClearGroup (sd::ToolBarManager::ToolBarGroup eGroup)
1345 // In every loop we erase the first member of the specified group.
1346 // Because that invalidates the iterator another loop is started after
1347 // that. The loop is left only when no member of the group is found and
1348 // no element is erased
1349 bool bLoop;
1352 bLoop = false;
1354 GroupedShellList::iterator iDescriptor;
1355 for (iDescriptor=maNewList.begin(); iDescriptor!=maNewList.end(); ++iDescriptor)
1356 if (iDescriptor->meGroup == eGroup)
1358 maNewList.erase(iDescriptor);
1359 // Erasing the descriptor invalidated the iterator so we
1360 // have to exit the for loop and start anew to search for
1361 // further elements of the group.
1362 bLoop = true;
1363 break;
1366 while (bLoop);
1369 void ToolBarShellList::AddShellId (sd::ToolBarManager::ToolBarGroup eGroup, sd::ShellId nId)
1371 // Make sure that the shell is not added twice (and possibly in
1372 // different groups.)
1373 ShellDescriptor aDescriptor (nId,eGroup);
1374 GroupedShellList::iterator iDescriptor (maNewList.find(aDescriptor));
1375 if (iDescriptor != maNewList.end())
1377 // The shell is already requested.
1378 if (iDescriptor->meGroup != eGroup)
1380 // It is now being requested for another group.
1381 // (Is this an error?)
1382 // Move it to that group.
1383 maNewList.erase(iDescriptor);
1384 maNewList.insert(aDescriptor);
1386 // else nothing to do.
1388 else
1389 maNewList.insert(aDescriptor);
1392 void ToolBarShellList::ReleaseAllShells (ToolBarRules& rRules)
1394 // Release the currently active tool bars.
1395 GroupedShellList aList (maCurrentList);
1396 GroupedShellList::iterator iDescriptor;
1397 for (iDescriptor=aList.begin(); iDescriptor!=aList.end(); ++iDescriptor)
1399 rRules.SubShellRemoved(iDescriptor->meGroup, iDescriptor->mnId);
1402 // Clear the list of requested tool bars.
1403 maNewList.clear();
1406 void ToolBarShellList::UpdateShells (
1407 const ::boost::shared_ptr<ViewShell>& rpMainViewShell,
1408 const ::boost::shared_ptr<ViewShellManager>& rpManager)
1410 if (rpMainViewShell.get() != NULL)
1412 GroupedShellList aList;
1414 // Deactivate shells that are in maCurrentList, but not in
1415 // maNewList.
1416 ::std::set_difference(maCurrentList.begin(), maCurrentList.end(),
1417 maNewList.begin(), maNewList.end(),
1418 std::insert_iterator<GroupedShellList>(aList,aList.begin()));
1419 for (GroupedShellList::iterator iShell=aList.begin(); iShell!=aList.end(); ++iShell)
1421 SAL_INFO("sd.view", OSL_THIS_FUNC << ": deactivating tool bar shell " << iShell->mnId);
1422 rpManager->DeactivateSubShell(*rpMainViewShell, iShell->mnId);
1425 // Activate shells that are in maNewList, but not in
1426 // maCurrentList.
1427 aList.clear();
1428 ::std::set_difference(maNewList.begin(), maNewList.end(),
1429 maCurrentList.begin(), maCurrentList.end(),
1430 std::insert_iterator<GroupedShellList>(aList,aList.begin()));
1431 for (GroupedShellList::iterator iShell=aList.begin(); iShell!=aList.end(); ++iShell)
1433 SAL_INFO("sd.view", OSL_THIS_FUNC << ": activating tool bar shell " << iShell->mnId);
1434 rpManager->ActivateSubShell(*rpMainViewShell, iShell->mnId);
1437 // The maNewList now refelects the current state and thus is made
1438 // maCurrentList.
1439 maCurrentList = maNewList;
1443 } // end of anonymous namespace
1445 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */