merge the formfield patch from ooo-build
[ooovba.git] / sd / source / ui / view / ToolBarManager.cxx
blobf4727b711b168794c513a2e3770795048066e227
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ToolBarManager.cxx,v $
10 * $Revision: 1.11 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sd.hxx"
34 #include "ToolBarManager.hxx"
36 #include "DrawViewShell.hxx"
37 #include "EventMultiplexer.hxx"
38 #include "ViewShellBase.hxx"
39 #include "ViewShellManager.hxx"
40 #include <com/sun/star/beans/XPropertySet.hpp>
41 #include <com/sun/star/frame/XLayoutManager.hpp>
42 #include <com/sun/star/ui/UIElementType.hpp>
44 #include <cppuhelper/implbase1.hxx>
45 #include <osl/mutex.hxx>
46 #include <rtl/ref.hxx>
47 #include <sfx2/app.hxx>
48 #include <sfx2/docfile.hxx>
49 #include <sfx2/objsh.hxx>
50 #include <sfx2/request.hxx>
51 #include <sfx2/viewfrm.hxx>
52 #include <svtools/eitem.hxx>
53 #include <svx/dialogs.hrc>
54 #include <svx/extrusionbar.hxx>
55 #include <svx/fontworkbar.hxx>
56 #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_
57 #include <toolkit/unohlp.hxx>
58 #endif
59 #include <tools/link.hxx>
61 #include <map>
62 #include <vector>
64 using namespace ::com::sun::star;
65 using namespace ::com::sun::star::uno;
67 #undef VERBOSE
69 #undef OUSTRING // Remove definition made in the SFX
70 #define OUSTRING(s) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s)))
72 namespace {
74 using namespace sd;
76 class ToolBarRules;
78 /** Lock of the frame::XLayoutManager.
80 class LayouterLock
82 public:
83 LayouterLock (const Reference<frame::XLayoutManager>& rxLayouter);
84 ~LayouterLock (void);
85 private:
86 Reference<frame::XLayoutManager> mxLayouter;
90 typedef ::std::vector<rtl::OUString> NameList;
92 /** Store a list of tool bars for each of the tool bar groups. From
93 this the list of requested tool bars is built.
95 class ToolBarList
97 public:
98 ToolBarList (void);
100 void ClearGroup (sd::ToolBarManager::ToolBarGroup eGroup);
101 void AddToolBar (sd::ToolBarManager::ToolBarGroup eGroup, const ::rtl::OUString& rsName);
102 bool RemoveToolBar (sd::ToolBarManager::ToolBarGroup eGroup, const ::rtl::OUString& rsName);
104 void GetToolBarsToActivate (NameList& rToolBars) const;
105 void GetToolBarsToDeactivate (NameList& rToolBars) const;
107 void MarkToolBarAsActive (const ::rtl::OUString& rsName);
108 void MarkToolBarAsNotActive (const ::rtl::OUString& rsName);
109 void MarkAllToolBarsAsNotActive (void);
111 private:
112 typedef ::std::map<sd::ToolBarManager::ToolBarGroup,NameList> Groups;
113 Groups maGroups;
114 NameList maActiveToolBars;
116 void MakeRequestedToolBarList (NameList& rToolBars) const;
122 /** Manage tool bars that are implemented as sub shells of a view shell.
123 The typical procedure of updating the sub shells of a view shell is to
124 rebuild a list of sub shells that the caller would like to have active.
125 The methods ClearGroup(), AddShellId(), and RemoveShellId() allow the
126 caller to do that. A final call to UpdateShells() activates the
127 requested shells that are not active and deactivates the active shells
128 that are not requested.
130 This is done by maintaining two lists. One (the current list)
131 reflects the current state. The other (the requested list) contains the
132 currently requested shells. UpdateShells() makes the requested
133 list the current list and clears the current list.
135 Each shell belongs to one group. Different groups can be modified
136 seperately.
138 class ToolBarShellList
140 public:
141 /** Create a new object with an empty current list and an empty
142 requested list.
144 ToolBarShellList (void);
146 /** Remove all shells from a group. Calling this method should normally
147 not be necessary because after the construction or after a call to
148 UpdateShells() the requested list is empty.
149 @param eGroup
150 The group to clear. Shells in other groups are not modified.
152 void ClearGroup (sd::ToolBarManager::ToolBarGroup eGroup);
154 /** Add a shell. When the specified shell has alreadt been requested
155 for another group then it is moved to this group.
156 @param eGroup
157 The group to which to add the shell.
158 @param nId
159 The id of the shell to add.
161 void AddShellId (sd::ToolBarManager::ToolBarGroup eGroup, sd::ShellId nId);
163 /** Remove a shell. This is done only when the specified shell is a
164 member of the specified group. If it has been requested for another
165 group or if it has not been requested then this call is ignored.
166 @param eGroup
167 The group from which to remove the shell.
168 @param nId
169 The id of the shell to remove.
170 @return
171 Returns whether the shell is removed.
173 bool RemoveShellId (sd::ToolBarManager::ToolBarGroup eGroup, sd::ShellId nId);
175 /** Releasing all shells means that the given ToolBarRules object is
176 informed that every shell mananged by the called ToolBarShellList is
177 about to be removed and that the associated framework tool bars can
178 be removed as well. The caller still has to call UpdateShells().
180 void ReleaseAllShells (ToolBarRules& rRules);
182 /** The requested list is made the current list by activating all
183 shells in the requested list and by deactivating the shells in the
184 current list that are not in the requested list.
185 @param pMainViewShell
186 The shells that are activated or deactivated are sub shells of
187 this view shell.
188 @param rManager
189 This ViewShellManager is used to activate or deactivate shells.
191 void UpdateShells (
192 const ::boost::shared_ptr<ViewShell>& rpMainViewShell,
193 const ::boost::shared_ptr<ViewShellManager>& rpManager);
195 private:
196 class ShellDescriptor
197 {public:
198 ShellDescriptor (ShellId nId,sd::ToolBarManager::ToolBarGroup eGroup);
199 ShellId mnId;
200 sd::ToolBarManager::ToolBarGroup meGroup;
201 friend bool operator<(const ShellDescriptor& r1, const ShellDescriptor& r2)
202 { return r1.mnId < r2.mnId; }
205 /** The requested list of tool bar shells that will be active after the
206 next call to UpdateShells().
208 typedef ::std::set<ShellDescriptor> GroupedShellList;
209 GroupedShellList maNewList;
211 /** The list of tool bar shells that are currently on the shell stack.
212 Using a GroupedShellList is not strictly necessary but it makes
213 things easier and does not waste too much memory.
215 GroupedShellList maCurrentList;
221 /** This class concentrates the knowledge about when to show what tool bars
222 in one place.
224 class ToolBarRules
226 public:
227 ToolBarRules (
228 const ::boost::shared_ptr<ToolBarManager>& rpToolBarManager,
229 const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager);
231 /** This method calls MainViewShellChanged() and SelectionHasChanged()
232 for the current main view shell and its view.
234 void Update (ViewShellBase& rBase);
236 /** Reset all tool bars in all groups and add tool bars and tool bar
237 shells to the TBG_PERMANENT group for the specified ViewShell type.
239 void MainViewShellChanged (ViewShell::ShellType nShellType);
241 /** Reset all tool bars in all groups and add tool bars and tool bar
242 shells to the TBG_PERMANENT group for the specified ViewShell.
244 void MainViewShellChanged (const ViewShell& rMainViewShell);
246 /** Reset all tool bars in the TBG_FUNCTION group and add tool bars and tool bar
247 shells to this group for the current selection.
249 void SelectionHasChanged (
250 const ::sd::ViewShell& rViewShell,
251 const SdrView& rView);
253 /** Add a tool bar for the specified tool bar shell.
255 void SubShellAdded (
256 ::sd::ToolBarManager::ToolBarGroup eGroup,
257 sd::ShellId nShellId);
259 /** Remove a tool bar for the specified tool bar shell.
261 void SubShellRemoved (
262 ::sd::ToolBarManager::ToolBarGroup eGroup,
263 sd::ShellId nShellId);
265 private:
266 ::boost::shared_ptr<ToolBarManager> mpToolBarManager;
267 ::boost::shared_ptr<ViewShellManager> mpViewShellManager;
270 } // end of anonymous namespace
275 namespace sd {
277 //===== ToolBarManager::Implementation ========================================
279 class ToolBarManager::Implementation
281 public:
282 /** This constructor takes three arguments even though the
283 ToolBarManager could be taken from the ViewShellBase. This is so to
284 state explicitly which information has to be present when this
285 constructor is called. The ViewShellBase may not have been fully
286 initialized at this point and must not be asked for this values.
288 Implementation (
289 ViewShellBase& rBase,
290 const ::boost::shared_ptr<sd::tools::EventMultiplexer>& rpMultiplexer,
291 const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager,
292 const ::boost::shared_ptr<ToolBarManager>& rpToolBarManager);
293 ~Implementation (void);
295 void SetValid (bool bValid);
297 void ResetToolBars (ToolBarGroup eGroup);
298 void ResetAllToolBars (void);
299 void AddToolBar (ToolBarGroup eGroup, const ::rtl::OUString& rsToolBarName);
300 void AddToolBarShell (ToolBarGroup eGroup, ShellId nToolBarId);
301 void RemoveToolBar (ToolBarGroup eGroup, const ::rtl::OUString& rsToolBarName);
302 void RemoveToolBarShell (ToolBarGroup eGroup, ShellId nToolBarId);
304 /** Release all tool bar shells and the associated framework tool bars.
305 Typically called when the main view shell is being replaced by
306 another, all tool bar shells are released. In that process the
307 shells are destroyed anyway and whithout calling this method they
308 would still be referenced.
310 void ReleaseAllToolBarShells (void);
312 void ToolBarsDestroyed(void);
314 void RequestUpdate (void);
316 void PreUpdate (void);
317 void PostUpdate (void);
318 /** Tell the XLayoutManager about the tool bars that we would like to be
319 shown.
320 @param rpLayouterLock
321 This typically is the mpSynchronousLayouterLock that is used in
322 this method and that is either released at its end or assigned
323 to mpAsynchronousLock in order to be unlocked later.
325 void Update (::std::auto_ptr<LayouterLock> pLayouterLock);
327 class UpdateLockImplementation
329 public:
330 UpdateLockImplementation (Implementation& rImplementation)
331 : mrImplementation(rImplementation) { mrImplementation.LockUpdate(); }
332 ~UpdateLockImplementation (void) { mrImplementation.UnlockUpdate(); }
333 private:
334 Implementation& mrImplementation;
337 void LockViewShellManager (void);
338 bool IsUpdateLocked (void) const;
339 void LockUpdate (void);
340 void UnlockUpdate (void);
342 ToolBarRules& GetToolBarRules (void);
344 private:
345 const static ::rtl::OUString msToolBarResourcePrefix;
347 mutable ::osl::Mutex maMutex;
348 ViewShellBase& mrBase;
349 ::boost::shared_ptr<sd::tools::EventMultiplexer> mpEventMultiplexer;
350 bool mbIsValid;
351 ToolBarList maToolBarList;
352 ToolBarShellList maToolBarShellList;
353 Reference<frame::XLayoutManager> mxLayouter;
354 sal_Int32 mnLockCount;
355 bool mbPreUpdatePending;
356 bool mbPostUpdatePending;
357 /** The layouter locks manage the locking of the XLayoutManager. The
358 lock() and unlock() functions are not called directly because the
359 (final) unlocking is usually done asynchronously *after* the
360 list of requested toolbars is updated.
362 ::std::auto_ptr<LayouterLock> mpSynchronousLayouterLock;
363 ::std::auto_ptr<LayouterLock> mpAsynchronousLayouterLock;
364 ::std::auto_ptr<ViewShellManager::UpdateLock> mpViewShellManagerLock;
365 ULONG mnPendingUpdateCall;
366 ULONG mnPendingSetValidCall;
367 ToolBarRules maToolBarRules;
369 ::rtl::OUString GetToolBarResourceName (const ::rtl::OUString& rsBaseName) const;
370 bool CheckPlugInMode (const ::rtl::OUString& rsName) const;
372 DECL_LINK(UpdateCallback,bool*);
373 DECL_LINK(EventMultiplexerCallback, sd::tools::EventMultiplexerEvent*);
374 DECL_LINK(SetValidCallback,void*);
379 //===== ToolBarManager ========================================================
381 const ::rtl::OUString ToolBarManager::msToolBar(OUSTRING("toolbar"));
382 const ::rtl::OUString ToolBarManager::msOptionsToolBar(OUSTRING("optionsbar"));
383 const ::rtl::OUString ToolBarManager::msCommonTaskToolBar(OUSTRING("commontaskbar"));
384 const ::rtl::OUString ToolBarManager::msViewerToolBar(OUSTRING("viewerbar"));
385 const ::rtl::OUString ToolBarManager::msSlideSorterToolBar(OUSTRING("slideviewtoolbar"));
386 const ::rtl::OUString ToolBarManager::msSlideSorterObjectBar(OUSTRING("slideviewobjectbar"));
387 const ::rtl::OUString ToolBarManager::msOutlineToolBar(OUSTRING("outlinetoolbar"));
388 const ::rtl::OUString ToolBarManager::msMasterViewToolBar(OUSTRING("masterviewtoolbar"));
389 const ::rtl::OUString ToolBarManager::msDrawingObjectToolBar(OUSTRING("drawingobjectbar"));
390 const ::rtl::OUString ToolBarManager::msGluePointsToolBar(OUSTRING("gluepointsobjectbar"));
391 const ::rtl::OUString ToolBarManager::msTextObjectBar(OUSTRING("textobjectbar"));
392 const ::rtl::OUString ToolBarManager::msBezierObjectBar(OUSTRING("bezierobjectbar"));
393 const ::rtl::OUString ToolBarManager::msGraphicObjectBar(OUSTRING("graphicobjectbar"));
394 const ::rtl::OUString ToolBarManager::msMediaObjectBar(OUSTRING("mediaobjectbar"));
395 const ::rtl::OUString ToolBarManager::msTableObjectBar(OUSTRING("tableobjectbar"));
398 ::boost::shared_ptr<ToolBarManager> ToolBarManager::Create (
399 ViewShellBase& rBase,
400 const ::boost::shared_ptr<sd::tools::EventMultiplexer>& rpMultiplexer,
401 const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager)
403 ::boost::shared_ptr<ToolBarManager> pManager (new ToolBarManager());
404 pManager->mpImpl.reset(
405 new Implementation(rBase,rpMultiplexer,rpViewShellManager,pManager));
406 return pManager;
412 ToolBarManager::ToolBarManager (void)
413 : mpImpl()
420 ToolBarManager::~ToolBarManager (void)
427 void ToolBarManager::Shutdown (void)
429 if (mpImpl.get() != NULL)
430 mpImpl.reset();
436 void ToolBarManager::SetValid (bool bValid)
438 if (mpImpl.get() != NULL)
439 mpImpl->SetValid(bValid);
445 void ToolBarManager::ResetToolBars (ToolBarGroup eGroup)
447 if (mpImpl.get() != NULL)
449 UpdateLock aLock (shared_from_this());
450 mpImpl->ResetToolBars(eGroup);
457 void ToolBarManager::ResetAllToolBars (void)
459 if (mpImpl.get() != NULL)
461 UpdateLock aLock (shared_from_this());
462 mpImpl->ResetAllToolBars();
469 void ToolBarManager::AddToolBar (
470 ToolBarGroup eGroup,
471 const ::rtl::OUString& rsToolBarName)
473 if (mpImpl.get() != NULL)
475 UpdateLock aLock (shared_from_this());
476 mpImpl->AddToolBar(eGroup,rsToolBarName);
483 void ToolBarManager::AddToolBarShell (
484 ToolBarGroup eGroup,
485 ShellId nToolBarId)
487 if (mpImpl.get() != NULL)
489 UpdateLock aLock (shared_from_this());
490 mpImpl->AddToolBarShell(eGroup,nToolBarId);
497 void ToolBarManager::RemoveToolBar (
498 ToolBarGroup eGroup,
499 const ::rtl::OUString& rsToolBarName)
501 if (mpImpl.get() != NULL)
503 UpdateLock aLock (shared_from_this());
504 mpImpl->RemoveToolBar(eGroup,rsToolBarName);
511 void ToolBarManager::RemoveToolBarShell (
512 ToolBarGroup eGroup,
513 ShellId nToolBarId)
515 if (mpImpl.get() != NULL)
517 UpdateLock aLock (shared_from_this());
518 mpImpl->RemoveToolBarShell(eGroup,nToolBarId);
525 void ToolBarManager::SetToolBar (
526 ToolBarGroup eGroup,
527 const ::rtl::OUString& rsToolBarName)
529 if (mpImpl.get() != NULL)
531 UpdateLock aLock (shared_from_this());
532 mpImpl->ResetToolBars(eGroup);
533 mpImpl->AddToolBar(eGroup,rsToolBarName);
540 void ToolBarManager::SetToolBarShell (
541 ToolBarGroup eGroup,
542 ShellId nToolBarId)
544 if (mpImpl.get() != NULL)
546 UpdateLock aLock (shared_from_this());
547 mpImpl->ResetToolBars(eGroup);
548 mpImpl->AddToolBarShell(eGroup,nToolBarId);
555 void ToolBarManager::PreUpdate (void)
557 if (mpImpl.get()!=NULL)
558 mpImpl->PreUpdate();
564 void ToolBarManager::RequestUpdate (void)
566 if (mpImpl.get()!=NULL)
567 mpImpl->RequestUpdate();
573 void ToolBarManager::LockViewShellManager (void)
575 if (mpImpl.get() != NULL)
576 mpImpl->LockViewShellManager();
582 bool ToolBarManager::IsUpdateLocked (void) const
584 if (mpImpl.get() != NULL)
585 return mpImpl->IsUpdateLocked();
586 else
587 return false;
593 void ToolBarManager::LockUpdate (void)
595 if (mpImpl.get()!=NULL)
596 mpImpl->LockUpdate();
602 void ToolBarManager::UnlockUpdate (void)
604 if (mpImpl.get()!=NULL)
605 mpImpl->UnlockUpdate();
611 void ToolBarManager::MainViewShellChanged (ViewShell::ShellType nShellType)
613 if (mpImpl.get() != NULL)
615 mpImpl->ReleaseAllToolBarShells();
616 mpImpl->GetToolBarRules().MainViewShellChanged(nShellType);
623 void ToolBarManager::MainViewShellChanged (const ViewShell& rMainViewShell)
625 if (mpImpl.get() != NULL)
627 mpImpl->ReleaseAllToolBarShells();
628 mpImpl->GetToolBarRules().MainViewShellChanged(rMainViewShell);
635 void ToolBarManager::SelectionHasChanged (
636 const ViewShell& rViewShell,
637 const SdrView& rView)
639 if (mpImpl.get() != NULL)
640 mpImpl->GetToolBarRules().SelectionHasChanged(rViewShell,rView);
644 void ToolBarManager::ToolBarsDestroyed(void)
646 if (mpImpl.get() != NULL)
647 mpImpl->ToolBarsDestroyed();
651 //===== ToolBarManager::Implementation =======================================
653 const ::rtl::OUString ToolBarManager::Implementation::msToolBarResourcePrefix(
654 OUSTRING("private:resource/toolbar/"));
656 ToolBarManager::Implementation::Implementation (
657 ViewShellBase& rBase,
658 const ::boost::shared_ptr<sd::tools::EventMultiplexer>& rpMultiplexer,
659 const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager,
660 const ::boost::shared_ptr<ToolBarManager>& rpToolBarManager)
661 : maMutex(),
662 mrBase(rBase),
663 mpEventMultiplexer(rpMultiplexer),
664 mbIsValid(false),
665 maToolBarList(),
666 maToolBarShellList(),
667 mxLayouter(NULL),
668 mnLockCount(0),
669 mbPreUpdatePending(false),
670 mbPostUpdatePending(false),
671 mpSynchronousLayouterLock(),
672 mpAsynchronousLayouterLock(),
673 mpViewShellManagerLock(),
674 mnPendingUpdateCall(0),
675 mnPendingSetValidCall(0),
676 maToolBarRules(rpToolBarManager,rpViewShellManager)
678 Link aLink (LINK(this,ToolBarManager::Implementation,EventMultiplexerCallback));
679 mpEventMultiplexer->AddEventListener(
680 aLink,
681 tools::EventMultiplexerEvent::EID_CONTROLLER_ATTACHED
682 | tools::EventMultiplexerEvent::EID_CONTROLLER_DETACHED
683 | tools::EventMultiplexerEvent::EID_PANE_MANAGER_DYING);
688 /** The order of statements is important.
689 First unregister listeners, which may post user events.
690 Then remove pending user events.
692 ToolBarManager::Implementation::~Implementation (void)
694 // Unregister at broadcasters.
695 Link aLink (LINK(this,ToolBarManager::Implementation,EventMultiplexerCallback));
696 mpEventMultiplexer->RemoveEventListener(aLink);
698 // Abort pending user calls.
699 if (mnPendingUpdateCall != 0)
700 Application::RemoveUserEvent(mnPendingUpdateCall);
701 if (mnPendingSetValidCall != 0)
702 Application::RemoveUserEvent(mnPendingSetValidCall);
706 void ToolBarManager::Implementation::ToolBarsDestroyed(void)
708 maToolBarList.MarkAllToolBarsAsNotActive();
712 void ToolBarManager::Implementation::SetValid (bool bValid)
714 ::osl::MutexGuard aGuard(maMutex);
716 if (mbIsValid != bValid)
718 UpdateLockImplementation aUpdateLock (*this);
720 mbIsValid = bValid;
721 if (mbIsValid)
723 Reference<frame::XFrame> xFrame;
724 if (mrBase.GetViewFrame() != NULL && mrBase.GetViewFrame()->GetFrame())
725 xFrame = mrBase.GetViewFrame()->GetFrame()->GetFrameInterface();
728 Reference<beans::XPropertySet> xFrameProperties (xFrame, UNO_QUERY_THROW);
729 Any aValue (xFrameProperties->getPropertyValue(OUSTRING("LayoutManager")));
730 aValue >>= mxLayouter;
732 catch (RuntimeException aException)
736 GetToolBarRules().Update(mrBase);
738 else
740 ResetAllToolBars();
741 mxLayouter = NULL;
749 void ToolBarManager::Implementation::ResetToolBars (ToolBarGroup eGroup)
751 ::osl::MutexGuard aGuard(maMutex);
753 maToolBarList.ClearGroup(eGroup);
754 maToolBarShellList.ClearGroup(eGroup);
756 mbPreUpdatePending = true;
762 void ToolBarManager::Implementation::ResetAllToolBars (void)
764 #ifdef VERBOSE
765 OSL_TRACE("resetting all tool bars\n");
766 #endif
767 for (int i=TBG__FIRST; i<=TBG__LAST; ++i)
768 ResetToolBars((ToolBarGroup)i);
774 void ToolBarManager::Implementation::AddToolBar (
775 ToolBarGroup eGroup,
776 const ::rtl::OUString& rsToolBarName)
778 ::osl::MutexGuard aGuard(maMutex);
780 if (CheckPlugInMode(rsToolBarName))
782 maToolBarList.AddToolBar(eGroup,rsToolBarName);
784 mbPostUpdatePending = true;
785 if (mnLockCount == 0)
786 PostUpdate();
793 void ToolBarManager::Implementation::RemoveToolBar (
794 ToolBarGroup eGroup,
795 const ::rtl::OUString& rsToolBarName)
797 ::osl::MutexGuard aGuard(maMutex);
799 if (maToolBarList.RemoveToolBar(eGroup,rsToolBarName))
801 mbPreUpdatePending = true;
802 if (mnLockCount == 0)
803 PreUpdate();
810 void ToolBarManager::Implementation::AddToolBarShell (
811 ToolBarGroup eGroup,
812 ShellId nToolBarId)
814 ViewShell* pMainViewShell = mrBase.GetMainViewShell().get();
815 if (pMainViewShell != NULL)
817 maToolBarShellList.AddShellId(eGroup,nToolBarId);
818 GetToolBarRules().SubShellAdded(eGroup, nToolBarId);
825 void ToolBarManager::Implementation::RemoveToolBarShell (
826 ToolBarGroup eGroup,
827 ShellId nToolBarId)
829 ViewShell* pMainViewShell = mrBase.GetMainViewShell().get();
830 if (pMainViewShell != NULL)
832 GetToolBarRules().SubShellRemoved(eGroup, nToolBarId);
833 maToolBarShellList.RemoveShellId(eGroup,nToolBarId);
840 void ToolBarManager::Implementation::ReleaseAllToolBarShells (void)
842 maToolBarShellList.ReleaseAllShells(GetToolBarRules());
843 maToolBarShellList.UpdateShells(mrBase.GetMainViewShell(), mrBase.GetViewShellManager());
849 void ToolBarManager::Implementation::RequestUpdate (void)
851 if (mnPendingUpdateCall == 0)
853 mnPendingUpdateCall = Application::PostUserEvent(
854 LINK(this,ToolBarManager::Implementation,UpdateCallback));
861 void ToolBarManager::Implementation::PreUpdate (void)
863 ::osl::MutexGuard aGuard(maMutex);
865 if (mbIsValid
866 && mbPreUpdatePending
867 && mxLayouter.is())
869 mbPreUpdatePending = false;
871 #ifdef VERBOSE
872 OSL_TRACE("ToolBarManager::PreUpdate [");
873 #endif
875 // Get the list of tool bars that are not used anymore and are to be
876 // deactivated.
877 NameList aToolBars;
878 maToolBarList.GetToolBarsToDeactivate(aToolBars);
880 // Turn off the tool bars.
881 NameList::const_iterator iToolBar;
882 for (iToolBar=aToolBars.begin(); iToolBar!=aToolBars.end(); ++iToolBar)
884 ::rtl::OUString sFullName (GetToolBarResourceName(*iToolBar));
885 #ifdef VERBOSE
886 OSL_TRACE(" turning off tool bar %s",
887 ::rtl::OUStringToOString(sFullName, RTL_TEXTENCODING_UTF8).getStr());
888 #endif
889 mxLayouter->destroyElement(sFullName);
890 maToolBarList.MarkToolBarAsNotActive(*iToolBar);
893 #ifdef VERBOSE
894 OSL_TRACE("ToolBarManager::PreUpdate ]\n");
895 #endif
902 void ToolBarManager::Implementation::PostUpdate (void)
904 ::osl::MutexGuard aGuard(maMutex);
906 if (mbIsValid
907 && mbPostUpdatePending
908 && mxLayouter.is())
910 mbPostUpdatePending = false;
912 // Create the list of requested tool bars.
913 NameList aToolBars;
914 maToolBarList.GetToolBarsToActivate(aToolBars);
916 #ifdef VERBOSE
917 OSL_TRACE("ToolBarManager::PostUpdate [");
918 #endif
920 // Turn on the tool bars that are visible in the new context.
921 NameList::const_iterator iToolBar;
922 for (iToolBar=aToolBars.begin(); iToolBar!=aToolBars.end(); ++iToolBar)
924 ::rtl::OUString sFullName (GetToolBarResourceName(*iToolBar));
925 #ifdef VERBOSE
926 OSL_TRACE(" turning on tool bar %s",
927 ::rtl::OUStringToOString(sFullName, RTL_TEXTENCODING_UTF8).getStr());
928 #endif
929 mxLayouter->requestElement(sFullName);
930 maToolBarList.MarkToolBarAsActive(*iToolBar);
933 #ifdef VERBOSE
934 OSL_TRACE("ToolBarManager::PostUpdate ]\n");
935 #endif
942 void ToolBarManager::Implementation::LockViewShellManager (void)
944 if (mpViewShellManagerLock.get() == NULL)
945 mpViewShellManagerLock.reset(
946 new ViewShellManager::UpdateLock(mrBase.GetViewShellManager()));
952 bool ToolBarManager::Implementation::IsUpdateLocked (void) const
954 return mnLockCount;
960 void ToolBarManager::Implementation::LockUpdate (void)
962 #ifdef VERBOSE
963 OSL_TRACE("LockUpdate %d\n", mnLockCount);
964 #endif
965 ::osl::MutexGuard aGuard(maMutex);
967 DBG_ASSERT(mnLockCount<100, "ToolBarManager lock count unusually high");
968 if (mnLockCount == 0)
970 OSL_ASSERT(mpSynchronousLayouterLock.get()==NULL);
972 mpSynchronousLayouterLock.reset(new LayouterLock(mxLayouter));
974 ++mnLockCount;
980 void ToolBarManager::Implementation::UnlockUpdate (void)
982 #ifdef VERBOSE
983 OSL_TRACE("UnlockUpdate %d\n", mnLockCount);
984 #endif
985 ::osl::MutexGuard aGuard(maMutex);
987 OSL_ASSERT(mnLockCount>0);
988 --mnLockCount;
989 if (mnLockCount == 0)
991 Update(mpSynchronousLayouterLock);
998 void ToolBarManager::Implementation::Update (
999 ::std::auto_ptr<LayouterLock> pLocalLayouterLock)
1001 // When the lock is released and there are pending changes to the set of
1002 // tool bars then update this set now.
1003 if (mnLockCount == 0)
1005 // During ceation of ViewShellBase we may have the situation that
1006 // the controller has already been created and attached to the frame
1007 // but that the ToolBarManager has not yet completed its
1008 // initialization (by initializing the mxLayouter member.) We do
1009 // this here so that we do not have to wait for the next Update()
1010 // call to show the tool bars.
1011 if (mnPendingSetValidCall != 0)
1013 Application::RemoveUserEvent(mnPendingSetValidCall);
1014 mnPendingSetValidCall = 0;
1015 SetValid(true);
1018 if (mbIsValid && mxLayouter.is() && (mbPreUpdatePending || mbPostUpdatePending))
1020 // 1) Release UNO tool bars that are not longer used. Do this
1021 // now so that they are not updated when the SFX shell stack is
1022 // modified.
1023 if (mbPreUpdatePending)
1024 PreUpdate();
1026 // 2) Update the requested shells that represent tool bar
1027 // functionality. Those that are not used anymore are
1028 // deactivated now. Those that are missing are activated in the
1029 // next step together with the view shells.
1030 if (mpViewShellManagerLock.get() == NULL)
1031 mpViewShellManagerLock.reset(
1032 new ViewShellManager::UpdateLock(mrBase.GetViewShellManager()));
1033 maToolBarShellList.UpdateShells(
1034 mrBase.GetMainViewShell(),
1035 mrBase.GetViewShellManager());
1037 // 3) Unlock the ViewShellManager::UpdateLock. This updates the
1038 // shell stack. We have to be carfull here. The deletion of
1039 // the lock may end in a synchronous call to LockUpdate(). When
1040 // at this time the lock has been deleted but the auto_ptr has
1041 // not yet been reset then the lock is deleted a second time.
1042 ViewShellManager::UpdateLock* pLock = mpViewShellManagerLock.release();
1043 delete pLock;
1045 // 4) Make the UNO tool bars visible. The outstanding call to
1046 // PostUpdate() is done via PostUserEvent() so that it is
1047 // guaranteed to be executed when the SFX shell stack has been
1048 // updated (under the assumption that our lock to the
1049 // ViewShellManager was the only one open. If that is not the
1050 // case then all should still be well but not as fast.)
1052 // Note that the lock count may have been increased since
1053 // entering this method. In that case one of the next
1054 // UnlockUpdate() calls will post the UpdateCallback.
1055 if (mnPendingUpdateCall==0 && mnLockCount==0)
1057 mpAsynchronousLayouterLock = pLocalLayouterLock;
1058 mnPendingUpdateCall = Application::PostUserEvent(
1059 LINK(this,ToolBarManager::Implementation,UpdateCallback));
1062 else
1064 mpViewShellManagerLock.reset();
1065 pLocalLayouterLock.reset();
1073 ToolBarRules& ToolBarManager::Implementation::GetToolBarRules (void)
1075 return maToolBarRules;
1081 IMPL_LINK(ToolBarManager::Implementation,UpdateCallback,bool*,EMPTYARG)
1083 mnPendingUpdateCall = 0;
1084 if (mnLockCount == 0)
1086 if (mbPreUpdatePending)
1087 PreUpdate();
1088 if (mbPostUpdatePending)
1089 PostUpdate();
1090 if (mbIsValid && mxLayouter.is())
1091 mpAsynchronousLayouterLock.reset();
1093 return 0;
1099 IMPL_LINK(ToolBarManager::Implementation,EventMultiplexerCallback,
1100 sd::tools::EventMultiplexerEvent*,pEvent)
1102 if (pEvent != NULL)
1104 switch (pEvent->meEventId)
1106 case tools::EventMultiplexerEvent::EID_CONTROLLER_ATTACHED:
1107 if (mnPendingSetValidCall == 0)
1108 mnPendingSetValidCall
1109 = Application::PostUserEvent(LINK(this,Implementation,SetValidCallback));
1110 break;
1112 case tools::EventMultiplexerEvent::EID_CONTROLLER_DETACHED:
1113 SetValid(false);
1114 break;
1116 case tools::EventMultiplexerEvent::EID_PANE_MANAGER_DYING:
1117 SetValid(false);
1118 break;
1121 return 0;
1127 IMPL_LINK(ToolBarManager::Implementation, SetValidCallback,void*,EMPTYARG)
1129 mnPendingSetValidCall = 0;
1130 SetValid(true);
1131 return 0;
1138 ::rtl::OUString ToolBarManager::Implementation::GetToolBarResourceName (
1139 const ::rtl::OUString& rsBaseName) const
1141 ::rtl::OUString sToolBarName (msToolBarResourcePrefix);
1142 sToolBarName += rsBaseName;
1143 return sToolBarName;
1149 bool ToolBarManager::Implementation::CheckPlugInMode (const ::rtl::OUString& rsName) const
1151 bool bValid (false);
1153 // Determine the plug in mode.
1154 bool bIsPlugInMode (false);
1157 SfxObjectShell* pObjectShell = mrBase.GetObjectShell();
1158 if (pObjectShell == NULL)
1159 break;
1161 SfxMedium* pMedium = pObjectShell->GetMedium();
1162 if (pMedium == NULL)
1163 break;
1165 SFX_ITEMSET_ARG(pMedium->GetItemSet(),pViewOnlyItem,SfxBoolItem,SID_VIEWONLY,sal_False);
1166 if (pViewOnlyItem == NULL)
1167 break;
1169 bIsPlugInMode = pViewOnlyItem->GetValue();
1171 while (false);
1173 if (rsName.equals(msViewerToolBar))
1174 bValid = bIsPlugInMode;
1175 else
1176 bValid = ! bIsPlugInMode;
1178 return bValid;
1184 } // end of namespace sd
1189 namespace {
1191 using namespace ::sd;
1193 //===== LayouterLock ==========================================================
1195 LayouterLock::LayouterLock (const Reference<frame::XLayoutManager>& rxLayouter)
1196 : mxLayouter(rxLayouter)
1198 #ifdef VERBOSE
1199 OSL_TRACE("LayouterLock %d", mxLayouter.is() ? 1 :0);
1200 #endif
1201 if (mxLayouter.is())
1202 mxLayouter->lock();
1208 LayouterLock::~LayouterLock (void)
1210 #ifdef VERBOSE
1211 OSL_TRACE("~LayouterLock %d", mxLayouter.is() ? 1 :0);
1212 #endif
1213 if (mxLayouter.is())
1214 mxLayouter->unlock();
1220 //===== ToolBarRules ==========================================================
1222 ToolBarRules::ToolBarRules (
1223 const ::boost::shared_ptr<sd::ToolBarManager>& rpToolBarManager,
1224 const ::boost::shared_ptr<sd::ViewShellManager>& rpViewShellManager)
1225 : mpToolBarManager(rpToolBarManager),
1226 mpViewShellManager(rpViewShellManager)
1233 void ToolBarRules::Update (ViewShellBase& rBase)
1235 ViewShell* pMainViewShell = rBase.GetMainViewShell().get();
1236 if (pMainViewShell != NULL)
1238 MainViewShellChanged(pMainViewShell->GetShellType());
1239 if (pMainViewShell->GetView())
1240 SelectionHasChanged (*pMainViewShell, *pMainViewShell->GetView());
1242 else
1243 MainViewShellChanged(ViewShell::ST_NONE);
1249 void ToolBarRules::MainViewShellChanged (ViewShell::ShellType nShellType)
1251 ::sd::ToolBarManager::UpdateLock aToolBarManagerLock (mpToolBarManager);
1252 ::sd::ViewShellManager::UpdateLock aViewShellManagerLock (mpViewShellManager);
1254 mpToolBarManager->ResetAllToolBars();
1256 switch(nShellType)
1258 case ::sd::ViewShell::ST_IMPRESS:
1259 case ::sd::ViewShell::ST_NOTES:
1260 case ::sd::ViewShell::ST_HANDOUT:
1261 mpToolBarManager->AddToolBar(
1262 ToolBarManager::TBG_PERMANENT,
1263 ToolBarManager::msToolBar);
1264 mpToolBarManager->AddToolBar(
1265 ToolBarManager::TBG_PERMANENT,
1266 ToolBarManager::msOptionsToolBar);
1267 mpToolBarManager->AddToolBar(
1268 ToolBarManager::TBG_PERMANENT,
1269 ToolBarManager::msCommonTaskToolBar);
1270 mpToolBarManager->AddToolBar(
1271 ToolBarManager::TBG_PERMANENT,
1272 ToolBarManager::msViewerToolBar);
1273 break;
1275 case ::sd::ViewShell::ST_DRAW:
1276 mpToolBarManager->AddToolBar(
1277 ToolBarManager::TBG_PERMANENT,
1278 ToolBarManager::msToolBar);
1279 mpToolBarManager->AddToolBar(
1280 ToolBarManager::TBG_PERMANENT,
1281 ToolBarManager::msOptionsToolBar);
1282 mpToolBarManager->AddToolBar(
1283 ToolBarManager::TBG_PERMANENT,
1284 ToolBarManager::msViewerToolBar);
1285 break;
1287 case ViewShell::ST_OUTLINE:
1288 mpToolBarManager->AddToolBar(
1289 ToolBarManager::TBG_PERMANENT,
1290 ToolBarManager::msOutlineToolBar);
1291 mpToolBarManager->AddToolBar(
1292 ToolBarManager::TBG_PERMANENT,
1293 ToolBarManager::msViewerToolBar);
1294 mpToolBarManager->AddToolBarShell(
1295 ToolBarManager::TBG_PERMANENT, RID_DRAW_TEXT_TOOLBOX);
1296 break;
1298 case ViewShell::ST_SLIDE_SORTER:
1299 mpToolBarManager->AddToolBar(
1300 ToolBarManager::TBG_PERMANENT,
1301 ToolBarManager::msViewerToolBar);
1302 mpToolBarManager->AddToolBar(
1303 ToolBarManager::TBG_PERMANENT,
1304 ToolBarManager::msSlideSorterToolBar);
1305 mpToolBarManager->AddToolBar(
1306 ToolBarManager::TBG_PERMANENT,
1307 ToolBarManager::msSlideSorterObjectBar);
1308 break;
1310 case ViewShell::ST_NONE:
1311 case ViewShell::ST_PRESENTATION:
1312 case ViewShell::ST_TASK_PANE:
1313 default:
1314 break;
1321 void ToolBarRules::MainViewShellChanged (const ViewShell& rMainViewShell)
1323 ::sd::ToolBarManager::UpdateLock aToolBarManagerLock (mpToolBarManager);
1324 ::sd::ViewShellManager::UpdateLock aViewShellManagerLock (mpViewShellManager);
1326 MainViewShellChanged(rMainViewShell.GetShellType());
1327 switch(rMainViewShell.GetShellType())
1329 case ::sd::ViewShell::ST_IMPRESS:
1330 case ::sd::ViewShell::ST_DRAW:
1331 case ::sd::ViewShell::ST_NOTES:
1333 const DrawViewShell* pDrawViewShell
1334 = dynamic_cast<const DrawViewShell*>(&rMainViewShell);
1335 if (pDrawViewShell != NULL)
1336 if (pDrawViewShell->GetEditMode() == EM_MASTERPAGE)
1337 mpToolBarManager->AddToolBar(
1338 ToolBarManager::TBG_MASTER_MODE,
1339 ToolBarManager::msMasterViewToolBar);
1340 break;
1343 default:
1344 break;
1351 void ToolBarRules::SelectionHasChanged (
1352 const ::sd::ViewShell& rViewShell,
1353 const SdrView& rView)
1355 ::sd::ToolBarManager::UpdateLock aLock (mpToolBarManager);
1356 mpToolBarManager->LockViewShellManager();
1357 bool bTextEdit = rView.IsTextEdit();
1359 mpToolBarManager->ResetToolBars(ToolBarManager::TBG_FUNCTION);
1361 switch (rView.GetContext())
1363 case SDRCONTEXT_GRAPHIC:
1364 if( !bTextEdit )
1365 mpToolBarManager->SetToolBarShell(ToolBarManager::TBG_FUNCTION, RID_DRAW_GRAF_TOOLBOX);
1366 break;
1368 case SDRCONTEXT_MEDIA:
1369 if( !bTextEdit )
1370 mpToolBarManager->SetToolBarShell(ToolBarManager::TBG_FUNCTION, RID_DRAW_MEDIA_TOOLBOX);
1371 break;
1373 case SDRCONTEXT_TABLE:
1374 mpToolBarManager->SetToolBarShell(ToolBarManager::TBG_FUNCTION, RID_DRAW_TABLE_TOOLBOX);
1375 bTextEdit = true;
1376 break;
1378 case SDRCONTEXT_STANDARD:
1379 default:
1380 if( !bTextEdit )
1382 switch(rViewShell.GetShellType())
1384 case ::sd::ViewShell::ST_IMPRESS:
1385 case ::sd::ViewShell::ST_DRAW:
1386 case ::sd::ViewShell::ST_NOTES:
1387 case ::sd::ViewShell::ST_HANDOUT:
1388 mpToolBarManager->SetToolBar(
1389 ToolBarManager::TBG_FUNCTION,
1390 ToolBarManager::msDrawingObjectToolBar);
1391 break;
1392 default:
1393 break;
1395 break;
1399 if( bTextEdit )
1400 mpToolBarManager->AddToolBarShell(ToolBarManager::TBG_FUNCTION, RID_DRAW_TEXT_TOOLBOX);
1402 SdrView* pView = &const_cast<SdrView&>(rView);
1403 // Check if the extrusion tool bar and the fontwork tool bar have to
1404 // be activated.
1405 if (svx::checkForSelectedCustomShapes(pView, true /* bOnlyExtruded */ ))
1406 mpToolBarManager->AddToolBarShell(ToolBarManager::TBG_FUNCTION, RID_SVX_EXTRUSION_BAR);
1407 sal_uInt32 nCheckStatus = 0;
1408 if (svx::checkForSelectedFontWork(pView, nCheckStatus))
1409 mpToolBarManager->AddToolBarShell(ToolBarManager::TBG_FUNCTION, RID_SVX_FONTWORK_BAR);
1411 // Switch on additional context-sensitive tool bars.
1412 if (rView.GetContext() == SDRCONTEXT_POINTEDIT)
1413 mpToolBarManager->AddToolBarShell(ToolBarManager::TBG_FUNCTION, RID_BEZIER_TOOLBOX);
1419 void ToolBarRules::SubShellAdded (
1420 ::sd::ToolBarManager::ToolBarGroup eGroup,
1421 sd::ShellId nShellId)
1423 // For some tool bar shells (those defined in sd) we have to add the
1424 // actual tool bar here.
1425 switch (nShellId)
1427 case RID_DRAW_GRAF_TOOLBOX:
1428 mpToolBarManager->AddToolBar(eGroup, ToolBarManager::msGraphicObjectBar);
1429 break;
1431 case RID_DRAW_MEDIA_TOOLBOX:
1432 mpToolBarManager->AddToolBar(eGroup, ToolBarManager::msMediaObjectBar);
1433 break;
1435 case RID_DRAW_TEXT_TOOLBOX:
1436 mpToolBarManager->AddToolBar(eGroup, ToolBarManager::msTextObjectBar);
1437 break;
1439 case RID_BEZIER_TOOLBOX:
1440 mpToolBarManager->AddToolBar(eGroup, ToolBarManager::msBezierObjectBar);
1441 break;
1443 case RID_DRAW_TABLE_TOOLBOX:
1444 mpToolBarManager->AddToolBar(eGroup, ToolBarManager::msTableObjectBar);
1445 break;
1452 void ToolBarRules::SubShellRemoved (
1453 ::sd::ToolBarManager::ToolBarGroup eGroup,
1454 sd::ShellId nShellId)
1456 // For some tool bar shells (those defined in sd) we have to add the
1457 // actual tool bar here.
1458 switch (nShellId)
1460 case RID_DRAW_GRAF_TOOLBOX:
1461 mpToolBarManager->RemoveToolBar(eGroup, ToolBarManager::msGraphicObjectBar);
1462 break;
1464 case RID_DRAW_MEDIA_TOOLBOX:
1465 mpToolBarManager->RemoveToolBar(eGroup, ToolBarManager::msMediaObjectBar);
1466 break;
1468 case RID_DRAW_TEXT_TOOLBOX:
1469 mpToolBarManager->RemoveToolBar(eGroup, ToolBarManager::msTextObjectBar);
1470 break;
1472 case RID_BEZIER_TOOLBOX:
1473 mpToolBarManager->RemoveToolBar(eGroup, ToolBarManager::msBezierObjectBar);
1474 break;
1476 case RID_DRAW_TABLE_TOOLBOX:
1477 mpToolBarManager->RemoveToolBar(eGroup, ToolBarManager::msTableObjectBar);
1478 break;
1485 //===== ToolBarList ===========================================================
1487 ToolBarList::ToolBarList (void)
1488 : maGroups(),
1489 maActiveToolBars()
1496 void ToolBarList::ClearGroup (sd::ToolBarManager::ToolBarGroup eGroup)
1498 Groups::iterator iGroup (maGroups.find(eGroup));
1499 if (iGroup != maGroups.end())
1501 if ( ! iGroup->second.empty())
1503 iGroup->second.clear();
1511 void ToolBarList::AddToolBar (
1512 sd::ToolBarManager::ToolBarGroup eGroup,
1513 const ::rtl::OUString& rsName)
1515 Groups::iterator iGroup (maGroups.find(eGroup));
1516 if (iGroup == maGroups.end())
1517 iGroup = maGroups.insert(Groups::value_type(eGroup,NameList())).first;
1519 if (iGroup != maGroups.end())
1521 NameList::const_iterator iBar (
1522 ::std::find(iGroup->second.begin(),iGroup->second.end(),rsName));
1523 if (iBar == iGroup->second.end())
1525 iGroup->second.push_back(rsName);
1533 bool ToolBarList::RemoveToolBar (
1534 sd::ToolBarManager::ToolBarGroup eGroup,
1535 const ::rtl::OUString& rsName)
1537 Groups::iterator iGroup (maGroups.find(eGroup));
1538 if (iGroup != maGroups.end())
1540 NameList::iterator iBar (
1541 ::std::find(iGroup->second.begin(),iGroup->second.end(),rsName));
1542 if (iBar != iGroup->second.end())
1544 iGroup->second.erase(iBar);
1545 return true;
1548 return false;
1554 void ToolBarList::MakeRequestedToolBarList (NameList& rRequestedToolBars) const
1556 for (int i=sd::ToolBarManager::TBG__FIRST; i<=sd::ToolBarManager::TBG__LAST; ++i)
1558 ::sd::ToolBarManager::ToolBarGroup eGroup = (::sd::ToolBarManager::ToolBarGroup)i;
1559 Groups::const_iterator iGroup (maGroups.find(eGroup));
1560 if (iGroup != maGroups.end())
1561 ::std::copy(
1562 iGroup->second.begin(),
1563 iGroup->second.end(),
1564 ::std::inserter(rRequestedToolBars,rRequestedToolBars.end()));
1571 void ToolBarList::GetToolBarsToActivate (NameList& rToolBars) const
1573 NameList aRequestedToolBars;
1574 MakeRequestedToolBarList(aRequestedToolBars);
1576 NameList::const_iterator iToolBar;
1577 for (iToolBar=aRequestedToolBars.begin(); iToolBar!=aRequestedToolBars.end(); ++iToolBar)
1579 if (::std::find(maActiveToolBars.begin(),maActiveToolBars.end(),*iToolBar)
1580 == maActiveToolBars.end())
1582 rToolBars.push_back(*iToolBar);
1590 void ToolBarList::GetToolBarsToDeactivate (NameList& rToolBars) const
1592 NameList aRequestedToolBars;
1593 MakeRequestedToolBarList(aRequestedToolBars);
1595 NameList::const_iterator iToolBar;
1596 for (iToolBar=maActiveToolBars.begin(); iToolBar!=maActiveToolBars.end(); ++iToolBar)
1598 if (::std::find(aRequestedToolBars.begin(),aRequestedToolBars.end(),*iToolBar)
1599 == aRequestedToolBars.end())
1601 rToolBars.push_back(*iToolBar);
1609 void ToolBarList::MarkToolBarAsActive (const ::rtl::OUString& rsName)
1611 maActiveToolBars.push_back(rsName);
1617 void ToolBarList::MarkToolBarAsNotActive (const ::rtl::OUString& rsName)
1619 maActiveToolBars.erase(
1620 ::std::find(maActiveToolBars.begin(),maActiveToolBars.end(), rsName));
1626 void ToolBarList::MarkAllToolBarsAsNotActive (void)
1628 maActiveToolBars.clear();
1634 //===== ToolBarShellList ======================================================
1636 ToolBarShellList::ShellDescriptor::ShellDescriptor (
1637 ShellId nId,
1638 sd::ToolBarManager::ToolBarGroup eGroup)
1639 : mnId(nId),
1640 meGroup(eGroup)
1647 ToolBarShellList::ToolBarShellList (void)
1648 : maNewList()
1649 , maCurrentList()
1656 void ToolBarShellList::ClearGroup (sd::ToolBarManager::ToolBarGroup eGroup)
1658 // In every loop we erase the first member of the specified group.
1659 // Because that invalidates the iterator another loop is started after
1660 // that. The loop is left only when no member of the group is found and
1661 // no element is erased
1662 bool bLoop;
1665 bLoop = false;
1667 GroupedShellList::iterator iDescriptor;
1668 for (iDescriptor=maNewList.begin(); iDescriptor!=maNewList.end(); ++iDescriptor)
1669 if (iDescriptor->meGroup == eGroup)
1671 maNewList.erase(iDescriptor);
1672 // Erasing the descriptor invalidated the iterator so we
1673 // have to exit the for loop and start anew to search for
1674 // further elements of the group.
1675 bLoop = true;
1676 break;
1679 while (bLoop);
1685 void ToolBarShellList::AddShellId (sd::ToolBarManager::ToolBarGroup eGroup, sd::ShellId nId)
1687 // Make sure that the shell is not added twice (and possibly in
1688 // different groups.)
1689 ShellDescriptor aDescriptor (nId,eGroup);
1690 GroupedShellList::iterator iDescriptor (maNewList.find(aDescriptor));
1691 if (iDescriptor != maNewList.end())
1693 // The shell is already requested.
1694 if (iDescriptor->meGroup != eGroup)
1696 // It is now being requested for another group.
1697 // (Is this an error?)
1698 // Move it to that group.
1699 maNewList.erase(iDescriptor);
1700 maNewList.insert(aDescriptor);
1702 // else nothing to do.
1704 else
1705 maNewList.insert(aDescriptor);
1711 bool ToolBarShellList::RemoveShellId (sd::ToolBarManager::ToolBarGroup eGroup, sd::ShellId nId)
1713 bool bRemoved (false);
1715 GroupedShellList::iterator iDescriptor (maNewList.find(ShellDescriptor(nId,eGroup)));
1716 if (iDescriptor != maNewList.end())
1718 if (iDescriptor->meGroup == eGroup)
1720 maNewList.erase(iDescriptor);
1721 bRemoved = true;
1725 return bRemoved;
1731 void ToolBarShellList::ReleaseAllShells (ToolBarRules& rRules)
1733 // Release the currently active tool bars.
1734 GroupedShellList aList (maCurrentList);
1735 GroupedShellList::iterator iDescriptor;
1736 for (iDescriptor=aList.begin(); iDescriptor!=aList.end(); ++iDescriptor)
1738 rRules.SubShellRemoved(iDescriptor->meGroup, iDescriptor->mnId);
1741 // Clear the list of requested tool bars.
1742 maNewList.clear();
1748 void ToolBarShellList::UpdateShells (
1749 const ::boost::shared_ptr<ViewShell>& rpMainViewShell,
1750 const ::boost::shared_ptr<ViewShellManager>& rpManager)
1752 if (rpMainViewShell.get() != NULL)
1754 GroupedShellList aList;
1756 // Deactivate shells that are in maCurrentList, but not in
1757 // maNewList.
1758 ::std::set_difference(maCurrentList.begin(), maCurrentList.end(),
1759 maNewList.begin(), maNewList.end(),
1760 std::insert_iterator<GroupedShellList>(aList,aList.begin()));
1761 for (GroupedShellList::iterator iShell=aList.begin(); iShell!=aList.end(); ++iShell)
1763 #ifdef VERBOSE
1764 OSL_TRACE("deactivating tool bar shell %d\n", iShell->mnId);
1765 #endif
1766 rpManager->DeactivateSubShell(*rpMainViewShell, iShell->mnId);
1769 // Activate shells that are in maNewList, but not in
1770 // maCurrentList.
1771 aList.clear();
1772 ::std::set_difference(maNewList.begin(), maNewList.end(),
1773 maCurrentList.begin(), maCurrentList.end(),
1774 std::insert_iterator<GroupedShellList>(aList,aList.begin()));
1775 for (GroupedShellList::iterator iShell=aList.begin(); iShell!=aList.end(); ++iShell)
1777 #ifdef VERBOSE
1778 OSL_TRACE("activating tool bar shell %d\n", iShell->mnId);
1779 #endif
1780 rpManager->ActivateSubShell(*rpMainViewShell, iShell->mnId);
1783 // The maNewList now refelects the current state and thus is made
1784 // maCurrentList.
1785 maCurrentList = maNewList;
1792 } // end of anonymous namespace