1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_sd.hxx" 30*cdf0e10cSrcweir 31*cdf0e10cSrcweir #include "ToolBarManager.hxx" 32*cdf0e10cSrcweir 33*cdf0e10cSrcweir #include "DrawViewShell.hxx" 34*cdf0e10cSrcweir #include "EventMultiplexer.hxx" 35*cdf0e10cSrcweir #include "ViewShellBase.hxx" 36*cdf0e10cSrcweir #include "ViewShellManager.hxx" 37*cdf0e10cSrcweir #include <com/sun/star/beans/XPropertySet.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/frame/XLayoutManager.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/ui/UIElementType.hpp> 40*cdf0e10cSrcweir 41*cdf0e10cSrcweir #include <cppuhelper/implbase1.hxx> 42*cdf0e10cSrcweir #include <osl/mutex.hxx> 43*cdf0e10cSrcweir #include <rtl/ref.hxx> 44*cdf0e10cSrcweir #include <sfx2/app.hxx> 45*cdf0e10cSrcweir #include <sfx2/docfile.hxx> 46*cdf0e10cSrcweir #include <sfx2/objsh.hxx> 47*cdf0e10cSrcweir #include <sfx2/request.hxx> 48*cdf0e10cSrcweir #include <sfx2/viewfrm.hxx> 49*cdf0e10cSrcweir #include <svl/eitem.hxx> 50*cdf0e10cSrcweir #include <svx/dialogs.hrc> 51*cdf0e10cSrcweir #include <svx/extrusionbar.hxx> 52*cdf0e10cSrcweir #include <svx/fontworkbar.hxx> 53*cdf0e10cSrcweir #ifndef _TOOLKIT_HELPER_VCLUNOHELPER_HXX_ 54*cdf0e10cSrcweir #include <toolkit/unohlp.hxx> 55*cdf0e10cSrcweir #endif 56*cdf0e10cSrcweir #include <tools/link.hxx> 57*cdf0e10cSrcweir 58*cdf0e10cSrcweir #include <map> 59*cdf0e10cSrcweir #include <vector> 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir using namespace ::com::sun::star; 62*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 63*cdf0e10cSrcweir 64*cdf0e10cSrcweir #undef VERBOSE 65*cdf0e10cSrcweir 66*cdf0e10cSrcweir #undef OUSTRING // Remove definition made in the SFX 67*cdf0e10cSrcweir #define OUSTRING(s) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(s))) 68*cdf0e10cSrcweir 69*cdf0e10cSrcweir namespace { 70*cdf0e10cSrcweir 71*cdf0e10cSrcweir using namespace sd; 72*cdf0e10cSrcweir 73*cdf0e10cSrcweir class ToolBarRules; 74*cdf0e10cSrcweir 75*cdf0e10cSrcweir /** Lock of the frame::XLayoutManager. 76*cdf0e10cSrcweir */ 77*cdf0e10cSrcweir class LayouterLock 78*cdf0e10cSrcweir { 79*cdf0e10cSrcweir public: 80*cdf0e10cSrcweir LayouterLock (const Reference<frame::XLayoutManager>& rxLayouter); 81*cdf0e10cSrcweir ~LayouterLock (void); 82*cdf0e10cSrcweir private: 83*cdf0e10cSrcweir Reference<frame::XLayoutManager> mxLayouter; 84*cdf0e10cSrcweir }; 85*cdf0e10cSrcweir 86*cdf0e10cSrcweir 87*cdf0e10cSrcweir typedef ::std::vector<rtl::OUString> NameList; 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir /** Store a list of tool bars for each of the tool bar groups. From 90*cdf0e10cSrcweir this the list of requested tool bars is built. 91*cdf0e10cSrcweir */ 92*cdf0e10cSrcweir class ToolBarList 93*cdf0e10cSrcweir { 94*cdf0e10cSrcweir public: 95*cdf0e10cSrcweir ToolBarList (void); 96*cdf0e10cSrcweir 97*cdf0e10cSrcweir void ClearGroup (sd::ToolBarManager::ToolBarGroup eGroup); 98*cdf0e10cSrcweir void AddToolBar (sd::ToolBarManager::ToolBarGroup eGroup, const ::rtl::OUString& rsName); 99*cdf0e10cSrcweir bool RemoveToolBar (sd::ToolBarManager::ToolBarGroup eGroup, const ::rtl::OUString& rsName); 100*cdf0e10cSrcweir 101*cdf0e10cSrcweir void GetToolBarsToActivate (NameList& rToolBars) const; 102*cdf0e10cSrcweir void GetToolBarsToDeactivate (NameList& rToolBars) const; 103*cdf0e10cSrcweir 104*cdf0e10cSrcweir void MarkToolBarAsActive (const ::rtl::OUString& rsName); 105*cdf0e10cSrcweir void MarkToolBarAsNotActive (const ::rtl::OUString& rsName); 106*cdf0e10cSrcweir void MarkAllToolBarsAsNotActive (void); 107*cdf0e10cSrcweir 108*cdf0e10cSrcweir private: 109*cdf0e10cSrcweir typedef ::std::map<sd::ToolBarManager::ToolBarGroup,NameList> Groups; 110*cdf0e10cSrcweir Groups maGroups; 111*cdf0e10cSrcweir NameList maActiveToolBars; 112*cdf0e10cSrcweir 113*cdf0e10cSrcweir void MakeRequestedToolBarList (NameList& rToolBars) const; 114*cdf0e10cSrcweir }; 115*cdf0e10cSrcweir 116*cdf0e10cSrcweir 117*cdf0e10cSrcweir 118*cdf0e10cSrcweir 119*cdf0e10cSrcweir /** Manage tool bars that are implemented as sub shells of a view shell. 120*cdf0e10cSrcweir The typical procedure of updating the sub shells of a view shell is to 121*cdf0e10cSrcweir rebuild a list of sub shells that the caller would like to have active. 122*cdf0e10cSrcweir The methods ClearGroup() and AddShellId() allow the caller to do that. A 123*cdf0e10cSrcweir final call to UpdateShells() activates the requested shells that are not 124*cdf0e10cSrcweir active and deactivates the active shells that are not requested . 125*cdf0e10cSrcweir 126*cdf0e10cSrcweir This is done by maintaining two lists. One (the current list) 127*cdf0e10cSrcweir reflects the current state. The other (the requested list) contains the 128*cdf0e10cSrcweir currently requested shells. UpdateShells() makes the requested 129*cdf0e10cSrcweir list the current list and clears the current list. 130*cdf0e10cSrcweir 131*cdf0e10cSrcweir Each shell belongs to one group. Different groups can be modified 132*cdf0e10cSrcweir seperately. 133*cdf0e10cSrcweir */ 134*cdf0e10cSrcweir class ToolBarShellList 135*cdf0e10cSrcweir { 136*cdf0e10cSrcweir public: 137*cdf0e10cSrcweir /** Create a new object with an empty current list and an empty 138*cdf0e10cSrcweir requested list. 139*cdf0e10cSrcweir */ 140*cdf0e10cSrcweir ToolBarShellList (void); 141*cdf0e10cSrcweir 142*cdf0e10cSrcweir /** Remove all shells from a group. Calling this method should normally 143*cdf0e10cSrcweir not be necessary because after the construction or after a call to 144*cdf0e10cSrcweir UpdateShells() the requested list is empty. 145*cdf0e10cSrcweir @param eGroup 146*cdf0e10cSrcweir The group to clear. Shells in other groups are not modified. 147*cdf0e10cSrcweir */ 148*cdf0e10cSrcweir void ClearGroup (sd::ToolBarManager::ToolBarGroup eGroup); 149*cdf0e10cSrcweir 150*cdf0e10cSrcweir /** Add a shell. When the specified shell has alreadt been requested 151*cdf0e10cSrcweir for another group then it is moved to this group. 152*cdf0e10cSrcweir @param eGroup 153*cdf0e10cSrcweir The group to which to add the shell. 154*cdf0e10cSrcweir @param nId 155*cdf0e10cSrcweir The id of the shell to add. 156*cdf0e10cSrcweir */ 157*cdf0e10cSrcweir void AddShellId (sd::ToolBarManager::ToolBarGroup eGroup, sd::ShellId nId); 158*cdf0e10cSrcweir 159*cdf0e10cSrcweir /** Releasing all shells means that the given ToolBarRules object is 160*cdf0e10cSrcweir informed that every shell mananged by the called ToolBarShellList is 161*cdf0e10cSrcweir about to be removed and that the associated framework tool bars can 162*cdf0e10cSrcweir be removed as well. The caller still has to call UpdateShells(). 163*cdf0e10cSrcweir */ 164*cdf0e10cSrcweir void ReleaseAllShells (ToolBarRules& rRules); 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir /** The requested list is made the current list by activating all 167*cdf0e10cSrcweir shells in the requested list and by deactivating the shells in the 168*cdf0e10cSrcweir current list that are not in the requested list. 169*cdf0e10cSrcweir @param pMainViewShell 170*cdf0e10cSrcweir The shells that are activated or deactivated are sub shells of 171*cdf0e10cSrcweir this view shell. 172*cdf0e10cSrcweir @param rManager 173*cdf0e10cSrcweir This ViewShellManager is used to activate or deactivate shells. 174*cdf0e10cSrcweir */ 175*cdf0e10cSrcweir void UpdateShells ( 176*cdf0e10cSrcweir const ::boost::shared_ptr<ViewShell>& rpMainViewShell, 177*cdf0e10cSrcweir const ::boost::shared_ptr<ViewShellManager>& rpManager); 178*cdf0e10cSrcweir 179*cdf0e10cSrcweir private: 180*cdf0e10cSrcweir class ShellDescriptor 181*cdf0e10cSrcweir {public: 182*cdf0e10cSrcweir ShellDescriptor (ShellId nId,sd::ToolBarManager::ToolBarGroup eGroup); 183*cdf0e10cSrcweir ShellId mnId; 184*cdf0e10cSrcweir sd::ToolBarManager::ToolBarGroup meGroup; 185*cdf0e10cSrcweir friend bool operator<(const ShellDescriptor& r1, const ShellDescriptor& r2) 186*cdf0e10cSrcweir { return r1.mnId < r2.mnId; } 187*cdf0e10cSrcweir }; 188*cdf0e10cSrcweir 189*cdf0e10cSrcweir /** The requested list of tool bar shells that will be active after the 190*cdf0e10cSrcweir next call to UpdateShells(). 191*cdf0e10cSrcweir */ 192*cdf0e10cSrcweir typedef ::std::set<ShellDescriptor> GroupedShellList; 193*cdf0e10cSrcweir GroupedShellList maNewList; 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir /** The list of tool bar shells that are currently on the shell stack. 196*cdf0e10cSrcweir Using a GroupedShellList is not strictly necessary but it makes 197*cdf0e10cSrcweir things easier and does not waste too much memory. 198*cdf0e10cSrcweir */ 199*cdf0e10cSrcweir GroupedShellList maCurrentList; 200*cdf0e10cSrcweir }; 201*cdf0e10cSrcweir 202*cdf0e10cSrcweir 203*cdf0e10cSrcweir 204*cdf0e10cSrcweir 205*cdf0e10cSrcweir /** This class concentrates the knowledge about when to show what tool bars 206*cdf0e10cSrcweir in one place. 207*cdf0e10cSrcweir */ 208*cdf0e10cSrcweir class ToolBarRules 209*cdf0e10cSrcweir { 210*cdf0e10cSrcweir public: 211*cdf0e10cSrcweir ToolBarRules ( 212*cdf0e10cSrcweir const ::boost::shared_ptr<ToolBarManager>& rpToolBarManager, 213*cdf0e10cSrcweir const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager); 214*cdf0e10cSrcweir 215*cdf0e10cSrcweir /** This method calls MainViewShellChanged() and SelectionHasChanged() 216*cdf0e10cSrcweir for the current main view shell and its view. 217*cdf0e10cSrcweir */ 218*cdf0e10cSrcweir void Update (ViewShellBase& rBase); 219*cdf0e10cSrcweir 220*cdf0e10cSrcweir /** Reset all tool bars in all groups and add tool bars and tool bar 221*cdf0e10cSrcweir shells to the TBG_PERMANENT group for the specified ViewShell type. 222*cdf0e10cSrcweir */ 223*cdf0e10cSrcweir void MainViewShellChanged (ViewShell::ShellType nShellType); 224*cdf0e10cSrcweir 225*cdf0e10cSrcweir /** Reset all tool bars in all groups and add tool bars and tool bar 226*cdf0e10cSrcweir shells to the TBG_PERMANENT group for the specified ViewShell. 227*cdf0e10cSrcweir */ 228*cdf0e10cSrcweir void MainViewShellChanged (const ViewShell& rMainViewShell); 229*cdf0e10cSrcweir 230*cdf0e10cSrcweir /** Reset all tool bars in the TBG_FUNCTION group and add tool bars and tool bar 231*cdf0e10cSrcweir shells to this group for the current selection. 232*cdf0e10cSrcweir */ 233*cdf0e10cSrcweir void SelectionHasChanged ( 234*cdf0e10cSrcweir const ::sd::ViewShell& rViewShell, 235*cdf0e10cSrcweir const SdrView& rView); 236*cdf0e10cSrcweir 237*cdf0e10cSrcweir /** Add a tool bar for the specified tool bar shell. 238*cdf0e10cSrcweir */ 239*cdf0e10cSrcweir void SubShellAdded ( 240*cdf0e10cSrcweir ::sd::ToolBarManager::ToolBarGroup eGroup, 241*cdf0e10cSrcweir sd::ShellId nShellId); 242*cdf0e10cSrcweir 243*cdf0e10cSrcweir /** Remove a tool bar for the specified tool bar shell. 244*cdf0e10cSrcweir */ 245*cdf0e10cSrcweir void SubShellRemoved ( 246*cdf0e10cSrcweir ::sd::ToolBarManager::ToolBarGroup eGroup, 247*cdf0e10cSrcweir sd::ShellId nShellId); 248*cdf0e10cSrcweir 249*cdf0e10cSrcweir private: 250*cdf0e10cSrcweir ::boost::shared_ptr<ToolBarManager> mpToolBarManager; 251*cdf0e10cSrcweir ::boost::shared_ptr<ViewShellManager> mpViewShellManager; 252*cdf0e10cSrcweir }; 253*cdf0e10cSrcweir 254*cdf0e10cSrcweir } // end of anonymous namespace 255*cdf0e10cSrcweir 256*cdf0e10cSrcweir 257*cdf0e10cSrcweir 258*cdf0e10cSrcweir 259*cdf0e10cSrcweir namespace sd { 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir //===== ToolBarManager::Implementation ======================================== 262*cdf0e10cSrcweir 263*cdf0e10cSrcweir class ToolBarManager::Implementation 264*cdf0e10cSrcweir { 265*cdf0e10cSrcweir public: 266*cdf0e10cSrcweir /** This constructor takes three arguments even though the 267*cdf0e10cSrcweir ToolBarManager could be taken from the ViewShellBase. This is so to 268*cdf0e10cSrcweir state explicitly which information has to be present when this 269*cdf0e10cSrcweir constructor is called. The ViewShellBase may not have been fully 270*cdf0e10cSrcweir initialized at this point and must not be asked for this values. 271*cdf0e10cSrcweir */ 272*cdf0e10cSrcweir Implementation ( 273*cdf0e10cSrcweir ViewShellBase& rBase, 274*cdf0e10cSrcweir const ::boost::shared_ptr<sd::tools::EventMultiplexer>& rpMultiplexer, 275*cdf0e10cSrcweir const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager, 276*cdf0e10cSrcweir const ::boost::shared_ptr<ToolBarManager>& rpToolBarManager); 277*cdf0e10cSrcweir ~Implementation (void); 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir void SetValid (bool bValid); 280*cdf0e10cSrcweir 281*cdf0e10cSrcweir void ResetToolBars (ToolBarGroup eGroup); 282*cdf0e10cSrcweir void ResetAllToolBars (void); 283*cdf0e10cSrcweir void AddToolBar (ToolBarGroup eGroup, const ::rtl::OUString& rsToolBarName); 284*cdf0e10cSrcweir void AddToolBarShell (ToolBarGroup eGroup, ShellId nToolBarId); 285*cdf0e10cSrcweir void RemoveToolBar (ToolBarGroup eGroup, const ::rtl::OUString& rsToolBarName); 286*cdf0e10cSrcweir 287*cdf0e10cSrcweir /** Release all tool bar shells and the associated framework tool bars. 288*cdf0e10cSrcweir Typically called when the main view shell is being replaced by 289*cdf0e10cSrcweir another, all tool bar shells are released. In that process the 290*cdf0e10cSrcweir shells are destroyed anyway and whithout calling this method they 291*cdf0e10cSrcweir would still be referenced. 292*cdf0e10cSrcweir */ 293*cdf0e10cSrcweir void ReleaseAllToolBarShells (void); 294*cdf0e10cSrcweir 295*cdf0e10cSrcweir void ToolBarsDestroyed(void); 296*cdf0e10cSrcweir 297*cdf0e10cSrcweir void RequestUpdate (void); 298*cdf0e10cSrcweir 299*cdf0e10cSrcweir void PreUpdate (void); 300*cdf0e10cSrcweir void PostUpdate (void); 301*cdf0e10cSrcweir /** Tell the XLayoutManager about the tool bars that we would like to be 302*cdf0e10cSrcweir shown. 303*cdf0e10cSrcweir @param rpLayouterLock 304*cdf0e10cSrcweir This typically is the mpSynchronousLayouterLock that is used in 305*cdf0e10cSrcweir this method and that is either released at its end or assigned 306*cdf0e10cSrcweir to mpAsynchronousLock in order to be unlocked later. 307*cdf0e10cSrcweir */ 308*cdf0e10cSrcweir void Update (::std::auto_ptr<LayouterLock> pLayouterLock); 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir class UpdateLockImplementation 311*cdf0e10cSrcweir { 312*cdf0e10cSrcweir public: 313*cdf0e10cSrcweir UpdateLockImplementation (Implementation& rImplementation) 314*cdf0e10cSrcweir : mrImplementation(rImplementation) { mrImplementation.LockUpdate(); } 315*cdf0e10cSrcweir ~UpdateLockImplementation (void) { mrImplementation.UnlockUpdate(); } 316*cdf0e10cSrcweir private: 317*cdf0e10cSrcweir Implementation& mrImplementation; 318*cdf0e10cSrcweir }; 319*cdf0e10cSrcweir 320*cdf0e10cSrcweir void LockViewShellManager (void); 321*cdf0e10cSrcweir void LockUpdate (void); 322*cdf0e10cSrcweir void UnlockUpdate (void); 323*cdf0e10cSrcweir 324*cdf0e10cSrcweir ToolBarRules& GetToolBarRules (void); 325*cdf0e10cSrcweir 326*cdf0e10cSrcweir private: 327*cdf0e10cSrcweir const static ::rtl::OUString msToolBarResourcePrefix; 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir mutable ::osl::Mutex maMutex; 330*cdf0e10cSrcweir ViewShellBase& mrBase; 331*cdf0e10cSrcweir ::boost::shared_ptr<sd::tools::EventMultiplexer> mpEventMultiplexer; 332*cdf0e10cSrcweir bool mbIsValid; 333*cdf0e10cSrcweir ToolBarList maToolBarList; 334*cdf0e10cSrcweir ToolBarShellList maToolBarShellList; 335*cdf0e10cSrcweir Reference<frame::XLayoutManager> mxLayouter; 336*cdf0e10cSrcweir sal_Int32 mnLockCount; 337*cdf0e10cSrcweir bool mbPreUpdatePending; 338*cdf0e10cSrcweir bool mbPostUpdatePending; 339*cdf0e10cSrcweir /** The layouter locks manage the locking of the XLayoutManager. The 340*cdf0e10cSrcweir lock() and unlock() functions are not called directly because the 341*cdf0e10cSrcweir (final) unlocking is usually done asynchronously *after* the 342*cdf0e10cSrcweir list of requested toolbars is updated. 343*cdf0e10cSrcweir */ 344*cdf0e10cSrcweir ::std::auto_ptr<LayouterLock> mpSynchronousLayouterLock; 345*cdf0e10cSrcweir ::std::auto_ptr<LayouterLock> mpAsynchronousLayouterLock; 346*cdf0e10cSrcweir ::std::auto_ptr<ViewShellManager::UpdateLock> mpViewShellManagerLock; 347*cdf0e10cSrcweir sal_uLong mnPendingUpdateCall; 348*cdf0e10cSrcweir sal_uLong mnPendingSetValidCall; 349*cdf0e10cSrcweir ToolBarRules maToolBarRules; 350*cdf0e10cSrcweir 351*cdf0e10cSrcweir ::rtl::OUString GetToolBarResourceName (const ::rtl::OUString& rsBaseName) const; 352*cdf0e10cSrcweir bool CheckPlugInMode (const ::rtl::OUString& rsName) const; 353*cdf0e10cSrcweir 354*cdf0e10cSrcweir DECL_LINK(UpdateCallback,bool*); 355*cdf0e10cSrcweir DECL_LINK(EventMultiplexerCallback, sd::tools::EventMultiplexerEvent*); 356*cdf0e10cSrcweir DECL_LINK(SetValidCallback,void*); 357*cdf0e10cSrcweir }; 358*cdf0e10cSrcweir 359*cdf0e10cSrcweir 360*cdf0e10cSrcweir 361*cdf0e10cSrcweir //===== ToolBarManager ======================================================== 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::msToolBar(OUSTRING("toolbar")); 364*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::msOptionsToolBar(OUSTRING("optionsbar")); 365*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::msCommonTaskToolBar(OUSTRING("commontaskbar")); 366*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::msViewerToolBar(OUSTRING("viewerbar")); 367*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::msSlideSorterToolBar(OUSTRING("slideviewtoolbar")); 368*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::msSlideSorterObjectBar(OUSTRING("slideviewobjectbar")); 369*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::msOutlineToolBar(OUSTRING("outlinetoolbar")); 370*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::msMasterViewToolBar(OUSTRING("masterviewtoolbar")); 371*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::msDrawingObjectToolBar(OUSTRING("drawingobjectbar")); 372*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::msGluePointsToolBar(OUSTRING("gluepointsobjectbar")); 373*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::msTextObjectBar(OUSTRING("textobjectbar")); 374*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::msBezierObjectBar(OUSTRING("bezierobjectbar")); 375*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::msGraphicObjectBar(OUSTRING("graphicobjectbar")); 376*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::msMediaObjectBar(OUSTRING("mediaobjectbar")); 377*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::msTableObjectBar(OUSTRING("tableobjectbar")); 378*cdf0e10cSrcweir 379*cdf0e10cSrcweir 380*cdf0e10cSrcweir ::boost::shared_ptr<ToolBarManager> ToolBarManager::Create ( 381*cdf0e10cSrcweir ViewShellBase& rBase, 382*cdf0e10cSrcweir const ::boost::shared_ptr<sd::tools::EventMultiplexer>& rpMultiplexer, 383*cdf0e10cSrcweir const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager) 384*cdf0e10cSrcweir { 385*cdf0e10cSrcweir ::boost::shared_ptr<ToolBarManager> pManager (new ToolBarManager()); 386*cdf0e10cSrcweir pManager->mpImpl.reset( 387*cdf0e10cSrcweir new Implementation(rBase,rpMultiplexer,rpViewShellManager,pManager)); 388*cdf0e10cSrcweir return pManager; 389*cdf0e10cSrcweir } 390*cdf0e10cSrcweir 391*cdf0e10cSrcweir 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir 394*cdf0e10cSrcweir ToolBarManager::ToolBarManager (void) 395*cdf0e10cSrcweir : mpImpl() 396*cdf0e10cSrcweir { 397*cdf0e10cSrcweir } 398*cdf0e10cSrcweir 399*cdf0e10cSrcweir 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir 402*cdf0e10cSrcweir ToolBarManager::~ToolBarManager (void) 403*cdf0e10cSrcweir { 404*cdf0e10cSrcweir } 405*cdf0e10cSrcweir 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir 408*cdf0e10cSrcweir 409*cdf0e10cSrcweir void ToolBarManager::Shutdown (void) 410*cdf0e10cSrcweir { 411*cdf0e10cSrcweir if (mpImpl.get() != NULL) 412*cdf0e10cSrcweir mpImpl.reset(); 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir 415*cdf0e10cSrcweir 416*cdf0e10cSrcweir 417*cdf0e10cSrcweir 418*cdf0e10cSrcweir void ToolBarManager::ResetToolBars (ToolBarGroup eGroup) 419*cdf0e10cSrcweir { 420*cdf0e10cSrcweir if (mpImpl.get() != NULL) 421*cdf0e10cSrcweir { 422*cdf0e10cSrcweir UpdateLock aLock (shared_from_this()); 423*cdf0e10cSrcweir mpImpl->ResetToolBars(eGroup); 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir } 426*cdf0e10cSrcweir 427*cdf0e10cSrcweir 428*cdf0e10cSrcweir 429*cdf0e10cSrcweir 430*cdf0e10cSrcweir void ToolBarManager::ResetAllToolBars (void) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir if (mpImpl.get() != NULL) 433*cdf0e10cSrcweir { 434*cdf0e10cSrcweir UpdateLock aLock (shared_from_this()); 435*cdf0e10cSrcweir mpImpl->ResetAllToolBars(); 436*cdf0e10cSrcweir } 437*cdf0e10cSrcweir } 438*cdf0e10cSrcweir 439*cdf0e10cSrcweir 440*cdf0e10cSrcweir 441*cdf0e10cSrcweir 442*cdf0e10cSrcweir void ToolBarManager::AddToolBar ( 443*cdf0e10cSrcweir ToolBarGroup eGroup, 444*cdf0e10cSrcweir const ::rtl::OUString& rsToolBarName) 445*cdf0e10cSrcweir { 446*cdf0e10cSrcweir if (mpImpl.get() != NULL) 447*cdf0e10cSrcweir { 448*cdf0e10cSrcweir UpdateLock aLock (shared_from_this()); 449*cdf0e10cSrcweir mpImpl->AddToolBar(eGroup,rsToolBarName); 450*cdf0e10cSrcweir } 451*cdf0e10cSrcweir } 452*cdf0e10cSrcweir 453*cdf0e10cSrcweir 454*cdf0e10cSrcweir 455*cdf0e10cSrcweir 456*cdf0e10cSrcweir void ToolBarManager::AddToolBarShell ( 457*cdf0e10cSrcweir ToolBarGroup eGroup, 458*cdf0e10cSrcweir ShellId nToolBarId) 459*cdf0e10cSrcweir { 460*cdf0e10cSrcweir if (mpImpl.get() != NULL) 461*cdf0e10cSrcweir { 462*cdf0e10cSrcweir UpdateLock aLock (shared_from_this()); 463*cdf0e10cSrcweir mpImpl->AddToolBarShell(eGroup,nToolBarId); 464*cdf0e10cSrcweir } 465*cdf0e10cSrcweir } 466*cdf0e10cSrcweir 467*cdf0e10cSrcweir 468*cdf0e10cSrcweir 469*cdf0e10cSrcweir 470*cdf0e10cSrcweir void ToolBarManager::RemoveToolBar ( 471*cdf0e10cSrcweir ToolBarGroup eGroup, 472*cdf0e10cSrcweir const ::rtl::OUString& rsToolBarName) 473*cdf0e10cSrcweir { 474*cdf0e10cSrcweir if (mpImpl.get() != NULL) 475*cdf0e10cSrcweir { 476*cdf0e10cSrcweir UpdateLock aLock (shared_from_this()); 477*cdf0e10cSrcweir mpImpl->RemoveToolBar(eGroup,rsToolBarName); 478*cdf0e10cSrcweir } 479*cdf0e10cSrcweir } 480*cdf0e10cSrcweir 481*cdf0e10cSrcweir 482*cdf0e10cSrcweir 483*cdf0e10cSrcweir 484*cdf0e10cSrcweir void ToolBarManager::SetToolBar ( 485*cdf0e10cSrcweir ToolBarGroup eGroup, 486*cdf0e10cSrcweir const ::rtl::OUString& rsToolBarName) 487*cdf0e10cSrcweir { 488*cdf0e10cSrcweir if (mpImpl.get() != NULL) 489*cdf0e10cSrcweir { 490*cdf0e10cSrcweir UpdateLock aLock (shared_from_this()); 491*cdf0e10cSrcweir mpImpl->ResetToolBars(eGroup); 492*cdf0e10cSrcweir mpImpl->AddToolBar(eGroup,rsToolBarName); 493*cdf0e10cSrcweir } 494*cdf0e10cSrcweir } 495*cdf0e10cSrcweir 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir 498*cdf0e10cSrcweir 499*cdf0e10cSrcweir void ToolBarManager::SetToolBarShell ( 500*cdf0e10cSrcweir ToolBarGroup eGroup, 501*cdf0e10cSrcweir ShellId nToolBarId) 502*cdf0e10cSrcweir { 503*cdf0e10cSrcweir if (mpImpl.get() != NULL) 504*cdf0e10cSrcweir { 505*cdf0e10cSrcweir UpdateLock aLock (shared_from_this()); 506*cdf0e10cSrcweir mpImpl->ResetToolBars(eGroup); 507*cdf0e10cSrcweir mpImpl->AddToolBarShell(eGroup,nToolBarId); 508*cdf0e10cSrcweir } 509*cdf0e10cSrcweir } 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir 512*cdf0e10cSrcweir 513*cdf0e10cSrcweir 514*cdf0e10cSrcweir void ToolBarManager::PreUpdate (void) 515*cdf0e10cSrcweir { 516*cdf0e10cSrcweir if (mpImpl.get()!=NULL) 517*cdf0e10cSrcweir mpImpl->PreUpdate(); 518*cdf0e10cSrcweir } 519*cdf0e10cSrcweir 520*cdf0e10cSrcweir 521*cdf0e10cSrcweir 522*cdf0e10cSrcweir 523*cdf0e10cSrcweir void ToolBarManager::RequestUpdate (void) 524*cdf0e10cSrcweir { 525*cdf0e10cSrcweir if (mpImpl.get()!=NULL) 526*cdf0e10cSrcweir mpImpl->RequestUpdate(); 527*cdf0e10cSrcweir } 528*cdf0e10cSrcweir 529*cdf0e10cSrcweir 530*cdf0e10cSrcweir 531*cdf0e10cSrcweir 532*cdf0e10cSrcweir void ToolBarManager::LockViewShellManager (void) 533*cdf0e10cSrcweir { 534*cdf0e10cSrcweir if (mpImpl.get() != NULL) 535*cdf0e10cSrcweir mpImpl->LockViewShellManager(); 536*cdf0e10cSrcweir } 537*cdf0e10cSrcweir 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir 540*cdf0e10cSrcweir 541*cdf0e10cSrcweir void ToolBarManager::LockUpdate (void) 542*cdf0e10cSrcweir { 543*cdf0e10cSrcweir if (mpImpl.get()!=NULL) 544*cdf0e10cSrcweir mpImpl->LockUpdate(); 545*cdf0e10cSrcweir } 546*cdf0e10cSrcweir 547*cdf0e10cSrcweir 548*cdf0e10cSrcweir 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir void ToolBarManager::UnlockUpdate (void) 551*cdf0e10cSrcweir { 552*cdf0e10cSrcweir if (mpImpl.get()!=NULL) 553*cdf0e10cSrcweir mpImpl->UnlockUpdate(); 554*cdf0e10cSrcweir } 555*cdf0e10cSrcweir 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir 558*cdf0e10cSrcweir 559*cdf0e10cSrcweir void ToolBarManager::MainViewShellChanged (ViewShell::ShellType nShellType) 560*cdf0e10cSrcweir { 561*cdf0e10cSrcweir if (mpImpl.get() != NULL) 562*cdf0e10cSrcweir { 563*cdf0e10cSrcweir mpImpl->ReleaseAllToolBarShells(); 564*cdf0e10cSrcweir mpImpl->GetToolBarRules().MainViewShellChanged(nShellType); 565*cdf0e10cSrcweir } 566*cdf0e10cSrcweir } 567*cdf0e10cSrcweir 568*cdf0e10cSrcweir 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir 571*cdf0e10cSrcweir void ToolBarManager::MainViewShellChanged (const ViewShell& rMainViewShell) 572*cdf0e10cSrcweir { 573*cdf0e10cSrcweir if (mpImpl.get() != NULL) 574*cdf0e10cSrcweir { 575*cdf0e10cSrcweir mpImpl->ReleaseAllToolBarShells(); 576*cdf0e10cSrcweir mpImpl->GetToolBarRules().MainViewShellChanged(rMainViewShell); 577*cdf0e10cSrcweir } 578*cdf0e10cSrcweir } 579*cdf0e10cSrcweir 580*cdf0e10cSrcweir 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir 583*cdf0e10cSrcweir void ToolBarManager::SelectionHasChanged ( 584*cdf0e10cSrcweir const ViewShell& rViewShell, 585*cdf0e10cSrcweir const SdrView& rView) 586*cdf0e10cSrcweir { 587*cdf0e10cSrcweir if (mpImpl.get() != NULL) 588*cdf0e10cSrcweir mpImpl->GetToolBarRules().SelectionHasChanged(rViewShell,rView); 589*cdf0e10cSrcweir } 590*cdf0e10cSrcweir 591*cdf0e10cSrcweir 592*cdf0e10cSrcweir void ToolBarManager::ToolBarsDestroyed(void) 593*cdf0e10cSrcweir { 594*cdf0e10cSrcweir if (mpImpl.get() != NULL) 595*cdf0e10cSrcweir mpImpl->ToolBarsDestroyed(); 596*cdf0e10cSrcweir } 597*cdf0e10cSrcweir 598*cdf0e10cSrcweir 599*cdf0e10cSrcweir //===== ToolBarManager::Implementation ======================================= 600*cdf0e10cSrcweir 601*cdf0e10cSrcweir const ::rtl::OUString ToolBarManager::Implementation::msToolBarResourcePrefix( 602*cdf0e10cSrcweir OUSTRING("private:resource/toolbar/")); 603*cdf0e10cSrcweir 604*cdf0e10cSrcweir ToolBarManager::Implementation::Implementation ( 605*cdf0e10cSrcweir ViewShellBase& rBase, 606*cdf0e10cSrcweir const ::boost::shared_ptr<sd::tools::EventMultiplexer>& rpMultiplexer, 607*cdf0e10cSrcweir const ::boost::shared_ptr<ViewShellManager>& rpViewShellManager, 608*cdf0e10cSrcweir const ::boost::shared_ptr<ToolBarManager>& rpToolBarManager) 609*cdf0e10cSrcweir : maMutex(), 610*cdf0e10cSrcweir mrBase(rBase), 611*cdf0e10cSrcweir mpEventMultiplexer(rpMultiplexer), 612*cdf0e10cSrcweir mbIsValid(false), 613*cdf0e10cSrcweir maToolBarList(), 614*cdf0e10cSrcweir maToolBarShellList(), 615*cdf0e10cSrcweir mxLayouter(NULL), 616*cdf0e10cSrcweir mnLockCount(0), 617*cdf0e10cSrcweir mbPreUpdatePending(false), 618*cdf0e10cSrcweir mbPostUpdatePending(false), 619*cdf0e10cSrcweir mpSynchronousLayouterLock(), 620*cdf0e10cSrcweir mpAsynchronousLayouterLock(), 621*cdf0e10cSrcweir mpViewShellManagerLock(), 622*cdf0e10cSrcweir mnPendingUpdateCall(0), 623*cdf0e10cSrcweir mnPendingSetValidCall(0), 624*cdf0e10cSrcweir maToolBarRules(rpToolBarManager,rpViewShellManager) 625*cdf0e10cSrcweir { 626*cdf0e10cSrcweir Link aLink (LINK(this,ToolBarManager::Implementation,EventMultiplexerCallback)); 627*cdf0e10cSrcweir mpEventMultiplexer->AddEventListener( 628*cdf0e10cSrcweir aLink, 629*cdf0e10cSrcweir tools::EventMultiplexerEvent::EID_CONTROLLER_ATTACHED 630*cdf0e10cSrcweir | tools::EventMultiplexerEvent::EID_CONTROLLER_DETACHED 631*cdf0e10cSrcweir | tools::EventMultiplexerEvent::EID_PANE_MANAGER_DYING); 632*cdf0e10cSrcweir } 633*cdf0e10cSrcweir 634*cdf0e10cSrcweir 635*cdf0e10cSrcweir 636*cdf0e10cSrcweir /** The order of statements is important. 637*cdf0e10cSrcweir First unregister listeners, which may post user events. 638*cdf0e10cSrcweir Then remove pending user events. 639*cdf0e10cSrcweir */ 640*cdf0e10cSrcweir ToolBarManager::Implementation::~Implementation (void) 641*cdf0e10cSrcweir { 642*cdf0e10cSrcweir // Unregister at broadcasters. 643*cdf0e10cSrcweir Link aLink (LINK(this,ToolBarManager::Implementation,EventMultiplexerCallback)); 644*cdf0e10cSrcweir mpEventMultiplexer->RemoveEventListener(aLink); 645*cdf0e10cSrcweir 646*cdf0e10cSrcweir // Abort pending user calls. 647*cdf0e10cSrcweir if (mnPendingUpdateCall != 0) 648*cdf0e10cSrcweir Application::RemoveUserEvent(mnPendingUpdateCall); 649*cdf0e10cSrcweir if (mnPendingSetValidCall != 0) 650*cdf0e10cSrcweir Application::RemoveUserEvent(mnPendingSetValidCall); 651*cdf0e10cSrcweir } 652*cdf0e10cSrcweir 653*cdf0e10cSrcweir 654*cdf0e10cSrcweir void ToolBarManager::Implementation::ToolBarsDestroyed(void) 655*cdf0e10cSrcweir { 656*cdf0e10cSrcweir maToolBarList.MarkAllToolBarsAsNotActive(); 657*cdf0e10cSrcweir } 658*cdf0e10cSrcweir 659*cdf0e10cSrcweir 660*cdf0e10cSrcweir void ToolBarManager::Implementation::SetValid (bool bValid) 661*cdf0e10cSrcweir { 662*cdf0e10cSrcweir ::osl::MutexGuard aGuard(maMutex); 663*cdf0e10cSrcweir 664*cdf0e10cSrcweir if (mbIsValid != bValid) 665*cdf0e10cSrcweir { 666*cdf0e10cSrcweir UpdateLockImplementation aUpdateLock (*this); 667*cdf0e10cSrcweir 668*cdf0e10cSrcweir mbIsValid = bValid; 669*cdf0e10cSrcweir if (mbIsValid) 670*cdf0e10cSrcweir { 671*cdf0e10cSrcweir Reference<frame::XFrame> xFrame; 672*cdf0e10cSrcweir if (mrBase.GetViewFrame() != NULL) 673*cdf0e10cSrcweir xFrame = mrBase.GetViewFrame()->GetFrame().GetFrameInterface(); 674*cdf0e10cSrcweir try 675*cdf0e10cSrcweir { 676*cdf0e10cSrcweir Reference<beans::XPropertySet> xFrameProperties (xFrame, UNO_QUERY_THROW); 677*cdf0e10cSrcweir Any aValue (xFrameProperties->getPropertyValue(OUSTRING("LayoutManager"))); 678*cdf0e10cSrcweir aValue >>= mxLayouter; 679*cdf0e10cSrcweir } 680*cdf0e10cSrcweir catch (RuntimeException aException) 681*cdf0e10cSrcweir { 682*cdf0e10cSrcweir } 683*cdf0e10cSrcweir 684*cdf0e10cSrcweir GetToolBarRules().Update(mrBase); 685*cdf0e10cSrcweir } 686*cdf0e10cSrcweir else 687*cdf0e10cSrcweir { 688*cdf0e10cSrcweir ResetAllToolBars(); 689*cdf0e10cSrcweir mxLayouter = NULL; 690*cdf0e10cSrcweir } 691*cdf0e10cSrcweir } 692*cdf0e10cSrcweir } 693*cdf0e10cSrcweir 694*cdf0e10cSrcweir 695*cdf0e10cSrcweir 696*cdf0e10cSrcweir 697*cdf0e10cSrcweir void ToolBarManager::Implementation::ResetToolBars (ToolBarGroup eGroup) 698*cdf0e10cSrcweir { 699*cdf0e10cSrcweir ::osl::MutexGuard aGuard(maMutex); 700*cdf0e10cSrcweir 701*cdf0e10cSrcweir maToolBarList.ClearGroup(eGroup); 702*cdf0e10cSrcweir maToolBarShellList.ClearGroup(eGroup); 703*cdf0e10cSrcweir 704*cdf0e10cSrcweir mbPreUpdatePending = true; 705*cdf0e10cSrcweir } 706*cdf0e10cSrcweir 707*cdf0e10cSrcweir 708*cdf0e10cSrcweir 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir void ToolBarManager::Implementation::ResetAllToolBars (void) 711*cdf0e10cSrcweir { 712*cdf0e10cSrcweir #ifdef VERBOSE 713*cdf0e10cSrcweir OSL_TRACE("resetting all tool bars\n"); 714*cdf0e10cSrcweir #endif 715*cdf0e10cSrcweir for (int i=TBG__FIRST; i<=TBG__LAST; ++i) 716*cdf0e10cSrcweir ResetToolBars((ToolBarGroup)i); 717*cdf0e10cSrcweir } 718*cdf0e10cSrcweir 719*cdf0e10cSrcweir 720*cdf0e10cSrcweir 721*cdf0e10cSrcweir 722*cdf0e10cSrcweir void ToolBarManager::Implementation::AddToolBar ( 723*cdf0e10cSrcweir ToolBarGroup eGroup, 724*cdf0e10cSrcweir const ::rtl::OUString& rsToolBarName) 725*cdf0e10cSrcweir { 726*cdf0e10cSrcweir ::osl::MutexGuard aGuard(maMutex); 727*cdf0e10cSrcweir 728*cdf0e10cSrcweir if (CheckPlugInMode(rsToolBarName)) 729*cdf0e10cSrcweir { 730*cdf0e10cSrcweir maToolBarList.AddToolBar(eGroup,rsToolBarName); 731*cdf0e10cSrcweir 732*cdf0e10cSrcweir mbPostUpdatePending = true; 733*cdf0e10cSrcweir if (mnLockCount == 0) 734*cdf0e10cSrcweir PostUpdate(); 735*cdf0e10cSrcweir } 736*cdf0e10cSrcweir } 737*cdf0e10cSrcweir 738*cdf0e10cSrcweir 739*cdf0e10cSrcweir 740*cdf0e10cSrcweir 741*cdf0e10cSrcweir void ToolBarManager::Implementation::RemoveToolBar ( 742*cdf0e10cSrcweir ToolBarGroup eGroup, 743*cdf0e10cSrcweir const ::rtl::OUString& rsToolBarName) 744*cdf0e10cSrcweir { 745*cdf0e10cSrcweir ::osl::MutexGuard aGuard(maMutex); 746*cdf0e10cSrcweir 747*cdf0e10cSrcweir if (maToolBarList.RemoveToolBar(eGroup,rsToolBarName)) 748*cdf0e10cSrcweir { 749*cdf0e10cSrcweir mbPreUpdatePending = true; 750*cdf0e10cSrcweir if (mnLockCount == 0) 751*cdf0e10cSrcweir PreUpdate(); 752*cdf0e10cSrcweir } 753*cdf0e10cSrcweir } 754*cdf0e10cSrcweir 755*cdf0e10cSrcweir 756*cdf0e10cSrcweir 757*cdf0e10cSrcweir 758*cdf0e10cSrcweir void ToolBarManager::Implementation::AddToolBarShell ( 759*cdf0e10cSrcweir ToolBarGroup eGroup, 760*cdf0e10cSrcweir ShellId nToolBarId) 761*cdf0e10cSrcweir { 762*cdf0e10cSrcweir ViewShell* pMainViewShell = mrBase.GetMainViewShell().get(); 763*cdf0e10cSrcweir if (pMainViewShell != NULL) 764*cdf0e10cSrcweir { 765*cdf0e10cSrcweir maToolBarShellList.AddShellId(eGroup,nToolBarId); 766*cdf0e10cSrcweir GetToolBarRules().SubShellAdded(eGroup, nToolBarId); 767*cdf0e10cSrcweir } 768*cdf0e10cSrcweir } 769*cdf0e10cSrcweir 770*cdf0e10cSrcweir 771*cdf0e10cSrcweir 772*cdf0e10cSrcweir 773*cdf0e10cSrcweir void ToolBarManager::Implementation::ReleaseAllToolBarShells (void) 774*cdf0e10cSrcweir { 775*cdf0e10cSrcweir maToolBarShellList.ReleaseAllShells(GetToolBarRules()); 776*cdf0e10cSrcweir maToolBarShellList.UpdateShells(mrBase.GetMainViewShell(), mrBase.GetViewShellManager()); 777*cdf0e10cSrcweir } 778*cdf0e10cSrcweir 779*cdf0e10cSrcweir 780*cdf0e10cSrcweir 781*cdf0e10cSrcweir 782*cdf0e10cSrcweir void ToolBarManager::Implementation::RequestUpdate (void) 783*cdf0e10cSrcweir { 784*cdf0e10cSrcweir if (mnPendingUpdateCall == 0) 785*cdf0e10cSrcweir { 786*cdf0e10cSrcweir mnPendingUpdateCall = Application::PostUserEvent( 787*cdf0e10cSrcweir LINK(this,ToolBarManager::Implementation,UpdateCallback)); 788*cdf0e10cSrcweir } 789*cdf0e10cSrcweir } 790*cdf0e10cSrcweir 791*cdf0e10cSrcweir 792*cdf0e10cSrcweir 793*cdf0e10cSrcweir 794*cdf0e10cSrcweir void ToolBarManager::Implementation::PreUpdate (void) 795*cdf0e10cSrcweir { 796*cdf0e10cSrcweir ::osl::MutexGuard aGuard(maMutex); 797*cdf0e10cSrcweir 798*cdf0e10cSrcweir if (mbIsValid 799*cdf0e10cSrcweir && mbPreUpdatePending 800*cdf0e10cSrcweir && mxLayouter.is()) 801*cdf0e10cSrcweir { 802*cdf0e10cSrcweir mbPreUpdatePending = false; 803*cdf0e10cSrcweir 804*cdf0e10cSrcweir #ifdef VERBOSE 805*cdf0e10cSrcweir OSL_TRACE("ToolBarManager::PreUpdate ["); 806*cdf0e10cSrcweir #endif 807*cdf0e10cSrcweir 808*cdf0e10cSrcweir // Get the list of tool bars that are not used anymore and are to be 809*cdf0e10cSrcweir // deactivated. 810*cdf0e10cSrcweir NameList aToolBars; 811*cdf0e10cSrcweir maToolBarList.GetToolBarsToDeactivate(aToolBars); 812*cdf0e10cSrcweir 813*cdf0e10cSrcweir // Turn off the tool bars. 814*cdf0e10cSrcweir NameList::const_iterator iToolBar; 815*cdf0e10cSrcweir for (iToolBar=aToolBars.begin(); iToolBar!=aToolBars.end(); ++iToolBar) 816*cdf0e10cSrcweir { 817*cdf0e10cSrcweir ::rtl::OUString sFullName (GetToolBarResourceName(*iToolBar)); 818*cdf0e10cSrcweir #ifdef VERBOSE 819*cdf0e10cSrcweir OSL_TRACE(" turning off tool bar %s", 820*cdf0e10cSrcweir ::rtl::OUStringToOString(sFullName, RTL_TEXTENCODING_UTF8).getStr()); 821*cdf0e10cSrcweir #endif 822*cdf0e10cSrcweir mxLayouter->destroyElement(sFullName); 823*cdf0e10cSrcweir maToolBarList.MarkToolBarAsNotActive(*iToolBar); 824*cdf0e10cSrcweir } 825*cdf0e10cSrcweir 826*cdf0e10cSrcweir #ifdef VERBOSE 827*cdf0e10cSrcweir OSL_TRACE("ToolBarManager::PreUpdate ]\n"); 828*cdf0e10cSrcweir #endif 829*cdf0e10cSrcweir } 830*cdf0e10cSrcweir } 831*cdf0e10cSrcweir 832*cdf0e10cSrcweir 833*cdf0e10cSrcweir 834*cdf0e10cSrcweir 835*cdf0e10cSrcweir void ToolBarManager::Implementation::PostUpdate (void) 836*cdf0e10cSrcweir { 837*cdf0e10cSrcweir ::osl::MutexGuard aGuard(maMutex); 838*cdf0e10cSrcweir 839*cdf0e10cSrcweir if (mbIsValid 840*cdf0e10cSrcweir && mbPostUpdatePending 841*cdf0e10cSrcweir && mxLayouter.is()) 842*cdf0e10cSrcweir { 843*cdf0e10cSrcweir mbPostUpdatePending = false; 844*cdf0e10cSrcweir 845*cdf0e10cSrcweir // Create the list of requested tool bars. 846*cdf0e10cSrcweir NameList aToolBars; 847*cdf0e10cSrcweir maToolBarList.GetToolBarsToActivate(aToolBars); 848*cdf0e10cSrcweir 849*cdf0e10cSrcweir #ifdef VERBOSE 850*cdf0e10cSrcweir OSL_TRACE("ToolBarManager::PostUpdate ["); 851*cdf0e10cSrcweir #endif 852*cdf0e10cSrcweir 853*cdf0e10cSrcweir // Turn on the tool bars that are visible in the new context. 854*cdf0e10cSrcweir NameList::const_iterator iToolBar; 855*cdf0e10cSrcweir for (iToolBar=aToolBars.begin(); iToolBar!=aToolBars.end(); ++iToolBar) 856*cdf0e10cSrcweir { 857*cdf0e10cSrcweir ::rtl::OUString sFullName (GetToolBarResourceName(*iToolBar)); 858*cdf0e10cSrcweir #ifdef VERBOSE 859*cdf0e10cSrcweir OSL_TRACE(" turning on tool bar %s", 860*cdf0e10cSrcweir ::rtl::OUStringToOString(sFullName, RTL_TEXTENCODING_UTF8).getStr()); 861*cdf0e10cSrcweir #endif 862*cdf0e10cSrcweir mxLayouter->requestElement(sFullName); 863*cdf0e10cSrcweir maToolBarList.MarkToolBarAsActive(*iToolBar); 864*cdf0e10cSrcweir } 865*cdf0e10cSrcweir 866*cdf0e10cSrcweir #ifdef VERBOSE 867*cdf0e10cSrcweir OSL_TRACE("ToolBarManager::PostUpdate ]\n"); 868*cdf0e10cSrcweir #endif 869*cdf0e10cSrcweir } 870*cdf0e10cSrcweir } 871*cdf0e10cSrcweir 872*cdf0e10cSrcweir 873*cdf0e10cSrcweir 874*cdf0e10cSrcweir 875*cdf0e10cSrcweir void ToolBarManager::Implementation::LockViewShellManager (void) 876*cdf0e10cSrcweir { 877*cdf0e10cSrcweir if (mpViewShellManagerLock.get() == NULL) 878*cdf0e10cSrcweir mpViewShellManagerLock.reset( 879*cdf0e10cSrcweir new ViewShellManager::UpdateLock(mrBase.GetViewShellManager())); 880*cdf0e10cSrcweir } 881*cdf0e10cSrcweir 882*cdf0e10cSrcweir 883*cdf0e10cSrcweir 884*cdf0e10cSrcweir 885*cdf0e10cSrcweir void ToolBarManager::Implementation::LockUpdate (void) 886*cdf0e10cSrcweir { 887*cdf0e10cSrcweir #ifdef VERBOSE 888*cdf0e10cSrcweir OSL_TRACE("LockUpdate %d\n", mnLockCount); 889*cdf0e10cSrcweir #endif 890*cdf0e10cSrcweir ::osl::MutexGuard aGuard(maMutex); 891*cdf0e10cSrcweir 892*cdf0e10cSrcweir DBG_ASSERT(mnLockCount<100, "ToolBarManager lock count unusually high"); 893*cdf0e10cSrcweir if (mnLockCount == 0) 894*cdf0e10cSrcweir { 895*cdf0e10cSrcweir OSL_ASSERT(mpSynchronousLayouterLock.get()==NULL); 896*cdf0e10cSrcweir 897*cdf0e10cSrcweir mpSynchronousLayouterLock.reset(new LayouterLock(mxLayouter)); 898*cdf0e10cSrcweir } 899*cdf0e10cSrcweir ++mnLockCount; 900*cdf0e10cSrcweir } 901*cdf0e10cSrcweir 902*cdf0e10cSrcweir 903*cdf0e10cSrcweir 904*cdf0e10cSrcweir 905*cdf0e10cSrcweir void ToolBarManager::Implementation::UnlockUpdate (void) 906*cdf0e10cSrcweir { 907*cdf0e10cSrcweir #ifdef VERBOSE 908*cdf0e10cSrcweir OSL_TRACE("UnlockUpdate %d\n", mnLockCount); 909*cdf0e10cSrcweir #endif 910*cdf0e10cSrcweir ::osl::MutexGuard aGuard(maMutex); 911*cdf0e10cSrcweir 912*cdf0e10cSrcweir OSL_ASSERT(mnLockCount>0); 913*cdf0e10cSrcweir --mnLockCount; 914*cdf0e10cSrcweir if (mnLockCount == 0) 915*cdf0e10cSrcweir { 916*cdf0e10cSrcweir Update(mpSynchronousLayouterLock); 917*cdf0e10cSrcweir } 918*cdf0e10cSrcweir } 919*cdf0e10cSrcweir 920*cdf0e10cSrcweir 921*cdf0e10cSrcweir 922*cdf0e10cSrcweir 923*cdf0e10cSrcweir void ToolBarManager::Implementation::Update ( 924*cdf0e10cSrcweir ::std::auto_ptr<LayouterLock> pLocalLayouterLock) 925*cdf0e10cSrcweir { 926*cdf0e10cSrcweir // When the lock is released and there are pending changes to the set of 927*cdf0e10cSrcweir // tool bars then update this set now. 928*cdf0e10cSrcweir if (mnLockCount == 0) 929*cdf0e10cSrcweir { 930*cdf0e10cSrcweir // During ceation of ViewShellBase we may have the situation that 931*cdf0e10cSrcweir // the controller has already been created and attached to the frame 932*cdf0e10cSrcweir // but that the ToolBarManager has not yet completed its 933*cdf0e10cSrcweir // initialization (by initializing the mxLayouter member.) We do 934*cdf0e10cSrcweir // this here so that we do not have to wait for the next Update() 935*cdf0e10cSrcweir // call to show the tool bars. 936*cdf0e10cSrcweir if (mnPendingSetValidCall != 0) 937*cdf0e10cSrcweir { 938*cdf0e10cSrcweir Application::RemoveUserEvent(mnPendingSetValidCall); 939*cdf0e10cSrcweir mnPendingSetValidCall = 0; 940*cdf0e10cSrcweir SetValid(true); 941*cdf0e10cSrcweir } 942*cdf0e10cSrcweir 943*cdf0e10cSrcweir if (mbIsValid && mxLayouter.is() && (mbPreUpdatePending || mbPostUpdatePending)) 944*cdf0e10cSrcweir { 945*cdf0e10cSrcweir // 1) Release UNO tool bars that are not longer used. Do this 946*cdf0e10cSrcweir // now so that they are not updated when the SFX shell stack is 947*cdf0e10cSrcweir // modified. 948*cdf0e10cSrcweir if (mbPreUpdatePending) 949*cdf0e10cSrcweir PreUpdate(); 950*cdf0e10cSrcweir 951*cdf0e10cSrcweir // 2) Update the requested shells that represent tool bar 952*cdf0e10cSrcweir // functionality. Those that are not used anymore are 953*cdf0e10cSrcweir // deactivated now. Those that are missing are activated in the 954*cdf0e10cSrcweir // next step together with the view shells. 955*cdf0e10cSrcweir if (mpViewShellManagerLock.get() == NULL) 956*cdf0e10cSrcweir mpViewShellManagerLock.reset( 957*cdf0e10cSrcweir new ViewShellManager::UpdateLock(mrBase.GetViewShellManager())); 958*cdf0e10cSrcweir maToolBarShellList.UpdateShells( 959*cdf0e10cSrcweir mrBase.GetMainViewShell(), 960*cdf0e10cSrcweir mrBase.GetViewShellManager()); 961*cdf0e10cSrcweir 962*cdf0e10cSrcweir // 3) Unlock the ViewShellManager::UpdateLock. This updates the 963*cdf0e10cSrcweir // shell stack. We have to be carfull here. The deletion of 964*cdf0e10cSrcweir // the lock may end in a synchronous call to LockUpdate(). When 965*cdf0e10cSrcweir // at this time the lock has been deleted but the auto_ptr has 966*cdf0e10cSrcweir // not yet been reset then the lock is deleted a second time. 967*cdf0e10cSrcweir ViewShellManager::UpdateLock* pLock = mpViewShellManagerLock.release(); 968*cdf0e10cSrcweir delete pLock; 969*cdf0e10cSrcweir 970*cdf0e10cSrcweir // 4) Make the UNO tool bars visible. The outstanding call to 971*cdf0e10cSrcweir // PostUpdate() is done via PostUserEvent() so that it is 972*cdf0e10cSrcweir // guaranteed to be executed when the SFX shell stack has been 973*cdf0e10cSrcweir // updated (under the assumption that our lock to the 974*cdf0e10cSrcweir // ViewShellManager was the only one open. If that is not the 975*cdf0e10cSrcweir // case then all should still be well but not as fast.) 976*cdf0e10cSrcweir // 977*cdf0e10cSrcweir // Note that the lock count may have been increased since 978*cdf0e10cSrcweir // entering this method. In that case one of the next 979*cdf0e10cSrcweir // UnlockUpdate() calls will post the UpdateCallback. 980*cdf0e10cSrcweir if (mnPendingUpdateCall==0 && mnLockCount==0) 981*cdf0e10cSrcweir { 982*cdf0e10cSrcweir mpAsynchronousLayouterLock = pLocalLayouterLock; 983*cdf0e10cSrcweir mnPendingUpdateCall = Application::PostUserEvent( 984*cdf0e10cSrcweir LINK(this,ToolBarManager::Implementation,UpdateCallback)); 985*cdf0e10cSrcweir } 986*cdf0e10cSrcweir } 987*cdf0e10cSrcweir else 988*cdf0e10cSrcweir { 989*cdf0e10cSrcweir mpViewShellManagerLock.reset(); 990*cdf0e10cSrcweir pLocalLayouterLock.reset(); 991*cdf0e10cSrcweir } 992*cdf0e10cSrcweir } 993*cdf0e10cSrcweir } 994*cdf0e10cSrcweir 995*cdf0e10cSrcweir 996*cdf0e10cSrcweir 997*cdf0e10cSrcweir 998*cdf0e10cSrcweir ToolBarRules& ToolBarManager::Implementation::GetToolBarRules (void) 999*cdf0e10cSrcweir { 1000*cdf0e10cSrcweir return maToolBarRules; 1001*cdf0e10cSrcweir } 1002*cdf0e10cSrcweir 1003*cdf0e10cSrcweir 1004*cdf0e10cSrcweir 1005*cdf0e10cSrcweir 1006*cdf0e10cSrcweir IMPL_LINK(ToolBarManager::Implementation,UpdateCallback,bool*,EMPTYARG) 1007*cdf0e10cSrcweir { 1008*cdf0e10cSrcweir mnPendingUpdateCall = 0; 1009*cdf0e10cSrcweir if (mnLockCount == 0) 1010*cdf0e10cSrcweir { 1011*cdf0e10cSrcweir if (mbPreUpdatePending) 1012*cdf0e10cSrcweir PreUpdate(); 1013*cdf0e10cSrcweir if (mbPostUpdatePending) 1014*cdf0e10cSrcweir PostUpdate(); 1015*cdf0e10cSrcweir if (mbIsValid && mxLayouter.is()) 1016*cdf0e10cSrcweir mpAsynchronousLayouterLock.reset(); 1017*cdf0e10cSrcweir } 1018*cdf0e10cSrcweir return 0; 1019*cdf0e10cSrcweir } 1020*cdf0e10cSrcweir 1021*cdf0e10cSrcweir 1022*cdf0e10cSrcweir 1023*cdf0e10cSrcweir 1024*cdf0e10cSrcweir IMPL_LINK(ToolBarManager::Implementation,EventMultiplexerCallback, 1025*cdf0e10cSrcweir sd::tools::EventMultiplexerEvent*,pEvent) 1026*cdf0e10cSrcweir { 1027*cdf0e10cSrcweir if (pEvent != NULL) 1028*cdf0e10cSrcweir { 1029*cdf0e10cSrcweir switch (pEvent->meEventId) 1030*cdf0e10cSrcweir { 1031*cdf0e10cSrcweir case tools::EventMultiplexerEvent::EID_CONTROLLER_ATTACHED: 1032*cdf0e10cSrcweir if (mnPendingSetValidCall == 0) 1033*cdf0e10cSrcweir mnPendingSetValidCall 1034*cdf0e10cSrcweir = Application::PostUserEvent(LINK(this,Implementation,SetValidCallback)); 1035*cdf0e10cSrcweir break; 1036*cdf0e10cSrcweir 1037*cdf0e10cSrcweir case tools::EventMultiplexerEvent::EID_CONTROLLER_DETACHED: 1038*cdf0e10cSrcweir SetValid(false); 1039*cdf0e10cSrcweir break; 1040*cdf0e10cSrcweir 1041*cdf0e10cSrcweir case tools::EventMultiplexerEvent::EID_PANE_MANAGER_DYING: 1042*cdf0e10cSrcweir SetValid(false); 1043*cdf0e10cSrcweir break; 1044*cdf0e10cSrcweir } 1045*cdf0e10cSrcweir } 1046*cdf0e10cSrcweir return 0; 1047*cdf0e10cSrcweir } 1048*cdf0e10cSrcweir 1049*cdf0e10cSrcweir 1050*cdf0e10cSrcweir 1051*cdf0e10cSrcweir 1052*cdf0e10cSrcweir IMPL_LINK(ToolBarManager::Implementation, SetValidCallback,void*,EMPTYARG) 1053*cdf0e10cSrcweir { 1054*cdf0e10cSrcweir mnPendingSetValidCall = 0; 1055*cdf0e10cSrcweir SetValid(true); 1056*cdf0e10cSrcweir return 0; 1057*cdf0e10cSrcweir } 1058*cdf0e10cSrcweir 1059*cdf0e10cSrcweir 1060*cdf0e10cSrcweir 1061*cdf0e10cSrcweir 1062*cdf0e10cSrcweir 1063*cdf0e10cSrcweir ::rtl::OUString ToolBarManager::Implementation::GetToolBarResourceName ( 1064*cdf0e10cSrcweir const ::rtl::OUString& rsBaseName) const 1065*cdf0e10cSrcweir { 1066*cdf0e10cSrcweir ::rtl::OUString sToolBarName (msToolBarResourcePrefix); 1067*cdf0e10cSrcweir sToolBarName += rsBaseName; 1068*cdf0e10cSrcweir return sToolBarName; 1069*cdf0e10cSrcweir } 1070*cdf0e10cSrcweir 1071*cdf0e10cSrcweir 1072*cdf0e10cSrcweir 1073*cdf0e10cSrcweir 1074*cdf0e10cSrcweir bool ToolBarManager::Implementation::CheckPlugInMode (const ::rtl::OUString& rsName) const 1075*cdf0e10cSrcweir { 1076*cdf0e10cSrcweir bool bValid (false); 1077*cdf0e10cSrcweir 1078*cdf0e10cSrcweir // Determine the plug in mode. 1079*cdf0e10cSrcweir bool bIsPlugInMode (false); 1080*cdf0e10cSrcweir do 1081*cdf0e10cSrcweir { 1082*cdf0e10cSrcweir SfxObjectShell* pObjectShell = mrBase.GetObjectShell(); 1083*cdf0e10cSrcweir if (pObjectShell == NULL) 1084*cdf0e10cSrcweir break; 1085*cdf0e10cSrcweir 1086*cdf0e10cSrcweir SfxMedium* pMedium = pObjectShell->GetMedium(); 1087*cdf0e10cSrcweir if (pMedium == NULL) 1088*cdf0e10cSrcweir break; 1089*cdf0e10cSrcweir 1090*cdf0e10cSrcweir SFX_ITEMSET_ARG(pMedium->GetItemSet(),pViewOnlyItem,SfxBoolItem,SID_VIEWONLY,sal_False); 1091*cdf0e10cSrcweir if (pViewOnlyItem == NULL) 1092*cdf0e10cSrcweir break; 1093*cdf0e10cSrcweir 1094*cdf0e10cSrcweir bIsPlugInMode = pViewOnlyItem->GetValue(); 1095*cdf0e10cSrcweir } 1096*cdf0e10cSrcweir while (false); 1097*cdf0e10cSrcweir 1098*cdf0e10cSrcweir if (rsName.equals(msViewerToolBar)) 1099*cdf0e10cSrcweir bValid = bIsPlugInMode; 1100*cdf0e10cSrcweir else 1101*cdf0e10cSrcweir bValid = ! bIsPlugInMode; 1102*cdf0e10cSrcweir 1103*cdf0e10cSrcweir return bValid; 1104*cdf0e10cSrcweir } 1105*cdf0e10cSrcweir 1106*cdf0e10cSrcweir 1107*cdf0e10cSrcweir 1108*cdf0e10cSrcweir 1109*cdf0e10cSrcweir } // end of namespace sd 1110*cdf0e10cSrcweir 1111*cdf0e10cSrcweir 1112*cdf0e10cSrcweir 1113*cdf0e10cSrcweir 1114*cdf0e10cSrcweir namespace { 1115*cdf0e10cSrcweir 1116*cdf0e10cSrcweir using namespace ::sd; 1117*cdf0e10cSrcweir 1118*cdf0e10cSrcweir //===== LayouterLock ========================================================== 1119*cdf0e10cSrcweir 1120*cdf0e10cSrcweir LayouterLock::LayouterLock (const Reference<frame::XLayoutManager>& rxLayouter) 1121*cdf0e10cSrcweir : mxLayouter(rxLayouter) 1122*cdf0e10cSrcweir { 1123*cdf0e10cSrcweir #ifdef VERBOSE 1124*cdf0e10cSrcweir OSL_TRACE("LayouterLock %d", mxLayouter.is() ? 1 :0); 1125*cdf0e10cSrcweir #endif 1126*cdf0e10cSrcweir if (mxLayouter.is()) 1127*cdf0e10cSrcweir mxLayouter->lock(); 1128*cdf0e10cSrcweir } 1129*cdf0e10cSrcweir 1130*cdf0e10cSrcweir 1131*cdf0e10cSrcweir 1132*cdf0e10cSrcweir 1133*cdf0e10cSrcweir LayouterLock::~LayouterLock (void) 1134*cdf0e10cSrcweir { 1135*cdf0e10cSrcweir #ifdef VERBOSE 1136*cdf0e10cSrcweir OSL_TRACE("~LayouterLock %d", mxLayouter.is() ? 1 :0); 1137*cdf0e10cSrcweir #endif 1138*cdf0e10cSrcweir if (mxLayouter.is()) 1139*cdf0e10cSrcweir mxLayouter->unlock(); 1140*cdf0e10cSrcweir } 1141*cdf0e10cSrcweir 1142*cdf0e10cSrcweir 1143*cdf0e10cSrcweir 1144*cdf0e10cSrcweir 1145*cdf0e10cSrcweir //===== ToolBarRules ========================================================== 1146*cdf0e10cSrcweir 1147*cdf0e10cSrcweir ToolBarRules::ToolBarRules ( 1148*cdf0e10cSrcweir const ::boost::shared_ptr<sd::ToolBarManager>& rpToolBarManager, 1149*cdf0e10cSrcweir const ::boost::shared_ptr<sd::ViewShellManager>& rpViewShellManager) 1150*cdf0e10cSrcweir : mpToolBarManager(rpToolBarManager), 1151*cdf0e10cSrcweir mpViewShellManager(rpViewShellManager) 1152*cdf0e10cSrcweir { 1153*cdf0e10cSrcweir } 1154*cdf0e10cSrcweir 1155*cdf0e10cSrcweir 1156*cdf0e10cSrcweir 1157*cdf0e10cSrcweir 1158*cdf0e10cSrcweir void ToolBarRules::Update (ViewShellBase& rBase) 1159*cdf0e10cSrcweir { 1160*cdf0e10cSrcweir ViewShell* pMainViewShell = rBase.GetMainViewShell().get(); 1161*cdf0e10cSrcweir if (pMainViewShell != NULL) 1162*cdf0e10cSrcweir { 1163*cdf0e10cSrcweir MainViewShellChanged(pMainViewShell->GetShellType()); 1164*cdf0e10cSrcweir if (pMainViewShell->GetView()) 1165*cdf0e10cSrcweir SelectionHasChanged (*pMainViewShell, *pMainViewShell->GetView()); 1166*cdf0e10cSrcweir } 1167*cdf0e10cSrcweir else 1168*cdf0e10cSrcweir MainViewShellChanged(ViewShell::ST_NONE); 1169*cdf0e10cSrcweir } 1170*cdf0e10cSrcweir 1171*cdf0e10cSrcweir 1172*cdf0e10cSrcweir 1173*cdf0e10cSrcweir 1174*cdf0e10cSrcweir void ToolBarRules::MainViewShellChanged (ViewShell::ShellType nShellType) 1175*cdf0e10cSrcweir { 1176*cdf0e10cSrcweir ::sd::ToolBarManager::UpdateLock aToolBarManagerLock (mpToolBarManager); 1177*cdf0e10cSrcweir ::sd::ViewShellManager::UpdateLock aViewShellManagerLock (mpViewShellManager); 1178*cdf0e10cSrcweir 1179*cdf0e10cSrcweir mpToolBarManager->ResetAllToolBars(); 1180*cdf0e10cSrcweir 1181*cdf0e10cSrcweir switch(nShellType) 1182*cdf0e10cSrcweir { 1183*cdf0e10cSrcweir case ::sd::ViewShell::ST_IMPRESS: 1184*cdf0e10cSrcweir case ::sd::ViewShell::ST_NOTES: 1185*cdf0e10cSrcweir case ::sd::ViewShell::ST_HANDOUT: 1186*cdf0e10cSrcweir mpToolBarManager->AddToolBar( 1187*cdf0e10cSrcweir ToolBarManager::TBG_PERMANENT, 1188*cdf0e10cSrcweir ToolBarManager::msToolBar); 1189*cdf0e10cSrcweir mpToolBarManager->AddToolBar( 1190*cdf0e10cSrcweir ToolBarManager::TBG_PERMANENT, 1191*cdf0e10cSrcweir ToolBarManager::msOptionsToolBar); 1192*cdf0e10cSrcweir mpToolBarManager->AddToolBar( 1193*cdf0e10cSrcweir ToolBarManager::TBG_PERMANENT, 1194*cdf0e10cSrcweir ToolBarManager::msCommonTaskToolBar); 1195*cdf0e10cSrcweir mpToolBarManager->AddToolBar( 1196*cdf0e10cSrcweir ToolBarManager::TBG_PERMANENT, 1197*cdf0e10cSrcweir ToolBarManager::msViewerToolBar); 1198*cdf0e10cSrcweir break; 1199*cdf0e10cSrcweir 1200*cdf0e10cSrcweir case ::sd::ViewShell::ST_DRAW: 1201*cdf0e10cSrcweir mpToolBarManager->AddToolBar( 1202*cdf0e10cSrcweir ToolBarManager::TBG_PERMANENT, 1203*cdf0e10cSrcweir ToolBarManager::msToolBar); 1204*cdf0e10cSrcweir mpToolBarManager->AddToolBar( 1205*cdf0e10cSrcweir ToolBarManager::TBG_PERMANENT, 1206*cdf0e10cSrcweir ToolBarManager::msOptionsToolBar); 1207*cdf0e10cSrcweir mpToolBarManager->AddToolBar( 1208*cdf0e10cSrcweir ToolBarManager::TBG_PERMANENT, 1209*cdf0e10cSrcweir ToolBarManager::msViewerToolBar); 1210*cdf0e10cSrcweir break; 1211*cdf0e10cSrcweir 1212*cdf0e10cSrcweir case ViewShell::ST_OUTLINE: 1213*cdf0e10cSrcweir mpToolBarManager->AddToolBar( 1214*cdf0e10cSrcweir ToolBarManager::TBG_PERMANENT, 1215*cdf0e10cSrcweir ToolBarManager::msOutlineToolBar); 1216*cdf0e10cSrcweir mpToolBarManager->AddToolBar( 1217*cdf0e10cSrcweir ToolBarManager::TBG_PERMANENT, 1218*cdf0e10cSrcweir ToolBarManager::msViewerToolBar); 1219*cdf0e10cSrcweir mpToolBarManager->AddToolBarShell( 1220*cdf0e10cSrcweir ToolBarManager::TBG_PERMANENT, RID_DRAW_TEXT_TOOLBOX); 1221*cdf0e10cSrcweir break; 1222*cdf0e10cSrcweir 1223*cdf0e10cSrcweir case ViewShell::ST_SLIDE_SORTER: 1224*cdf0e10cSrcweir mpToolBarManager->AddToolBar( 1225*cdf0e10cSrcweir ToolBarManager::TBG_PERMANENT, 1226*cdf0e10cSrcweir ToolBarManager::msViewerToolBar); 1227*cdf0e10cSrcweir mpToolBarManager->AddToolBar( 1228*cdf0e10cSrcweir ToolBarManager::TBG_PERMANENT, 1229*cdf0e10cSrcweir ToolBarManager::msSlideSorterToolBar); 1230*cdf0e10cSrcweir mpToolBarManager->AddToolBar( 1231*cdf0e10cSrcweir ToolBarManager::TBG_PERMANENT, 1232*cdf0e10cSrcweir ToolBarManager::msSlideSorterObjectBar); 1233*cdf0e10cSrcweir break; 1234*cdf0e10cSrcweir 1235*cdf0e10cSrcweir case ViewShell::ST_NONE: 1236*cdf0e10cSrcweir case ViewShell::ST_PRESENTATION: 1237*cdf0e10cSrcweir case ViewShell::ST_TASK_PANE: 1238*cdf0e10cSrcweir default: 1239*cdf0e10cSrcweir break; 1240*cdf0e10cSrcweir } 1241*cdf0e10cSrcweir } 1242*cdf0e10cSrcweir 1243*cdf0e10cSrcweir 1244*cdf0e10cSrcweir 1245*cdf0e10cSrcweir 1246*cdf0e10cSrcweir void ToolBarRules::MainViewShellChanged (const ViewShell& rMainViewShell) 1247*cdf0e10cSrcweir { 1248*cdf0e10cSrcweir ::sd::ToolBarManager::UpdateLock aToolBarManagerLock (mpToolBarManager); 1249*cdf0e10cSrcweir ::sd::ViewShellManager::UpdateLock aViewShellManagerLock (mpViewShellManager); 1250*cdf0e10cSrcweir 1251*cdf0e10cSrcweir MainViewShellChanged(rMainViewShell.GetShellType()); 1252*cdf0e10cSrcweir switch(rMainViewShell.GetShellType()) 1253*cdf0e10cSrcweir { 1254*cdf0e10cSrcweir case ::sd::ViewShell::ST_IMPRESS: 1255*cdf0e10cSrcweir case ::sd::ViewShell::ST_DRAW: 1256*cdf0e10cSrcweir case ::sd::ViewShell::ST_NOTES: 1257*cdf0e10cSrcweir { 1258*cdf0e10cSrcweir const DrawViewShell* pDrawViewShell 1259*cdf0e10cSrcweir = dynamic_cast<const DrawViewShell*>(&rMainViewShell); 1260*cdf0e10cSrcweir if (pDrawViewShell != NULL) 1261*cdf0e10cSrcweir if (pDrawViewShell->GetEditMode() == EM_MASTERPAGE) 1262*cdf0e10cSrcweir mpToolBarManager->AddToolBar( 1263*cdf0e10cSrcweir ToolBarManager::TBG_MASTER_MODE, 1264*cdf0e10cSrcweir ToolBarManager::msMasterViewToolBar); 1265*cdf0e10cSrcweir break; 1266*cdf0e10cSrcweir } 1267*cdf0e10cSrcweir 1268*cdf0e10cSrcweir default: 1269*cdf0e10cSrcweir break; 1270*cdf0e10cSrcweir } 1271*cdf0e10cSrcweir } 1272*cdf0e10cSrcweir 1273*cdf0e10cSrcweir 1274*cdf0e10cSrcweir 1275*cdf0e10cSrcweir 1276*cdf0e10cSrcweir void ToolBarRules::SelectionHasChanged ( 1277*cdf0e10cSrcweir const ::sd::ViewShell& rViewShell, 1278*cdf0e10cSrcweir const SdrView& rView) 1279*cdf0e10cSrcweir { 1280*cdf0e10cSrcweir ::sd::ToolBarManager::UpdateLock aLock (mpToolBarManager); 1281*cdf0e10cSrcweir mpToolBarManager->LockViewShellManager(); 1282*cdf0e10cSrcweir bool bTextEdit = rView.IsTextEdit(); 1283*cdf0e10cSrcweir 1284*cdf0e10cSrcweir mpToolBarManager->ResetToolBars(ToolBarManager::TBG_FUNCTION); 1285*cdf0e10cSrcweir 1286*cdf0e10cSrcweir switch (rView.GetContext()) 1287*cdf0e10cSrcweir { 1288*cdf0e10cSrcweir case SDRCONTEXT_GRAPHIC: 1289*cdf0e10cSrcweir if( !bTextEdit ) 1290*cdf0e10cSrcweir mpToolBarManager->SetToolBarShell(ToolBarManager::TBG_FUNCTION, RID_DRAW_GRAF_TOOLBOX); 1291*cdf0e10cSrcweir break; 1292*cdf0e10cSrcweir 1293*cdf0e10cSrcweir case SDRCONTEXT_MEDIA: 1294*cdf0e10cSrcweir if( !bTextEdit ) 1295*cdf0e10cSrcweir mpToolBarManager->SetToolBarShell(ToolBarManager::TBG_FUNCTION, RID_DRAW_MEDIA_TOOLBOX); 1296*cdf0e10cSrcweir break; 1297*cdf0e10cSrcweir 1298*cdf0e10cSrcweir case SDRCONTEXT_TABLE: 1299*cdf0e10cSrcweir mpToolBarManager->SetToolBarShell(ToolBarManager::TBG_FUNCTION, RID_DRAW_TABLE_TOOLBOX); 1300*cdf0e10cSrcweir bTextEdit = true; 1301*cdf0e10cSrcweir break; 1302*cdf0e10cSrcweir 1303*cdf0e10cSrcweir case SDRCONTEXT_STANDARD: 1304*cdf0e10cSrcweir default: 1305*cdf0e10cSrcweir if( !bTextEdit ) 1306*cdf0e10cSrcweir { 1307*cdf0e10cSrcweir switch(rViewShell.GetShellType()) 1308*cdf0e10cSrcweir { 1309*cdf0e10cSrcweir case ::sd::ViewShell::ST_IMPRESS: 1310*cdf0e10cSrcweir case ::sd::ViewShell::ST_DRAW: 1311*cdf0e10cSrcweir case ::sd::ViewShell::ST_NOTES: 1312*cdf0e10cSrcweir case ::sd::ViewShell::ST_HANDOUT: 1313*cdf0e10cSrcweir mpToolBarManager->SetToolBar( 1314*cdf0e10cSrcweir ToolBarManager::TBG_FUNCTION, 1315*cdf0e10cSrcweir ToolBarManager::msDrawingObjectToolBar); 1316*cdf0e10cSrcweir break; 1317*cdf0e10cSrcweir default: 1318*cdf0e10cSrcweir break; 1319*cdf0e10cSrcweir } 1320*cdf0e10cSrcweir break; 1321*cdf0e10cSrcweir } 1322*cdf0e10cSrcweir } 1323*cdf0e10cSrcweir 1324*cdf0e10cSrcweir if( bTextEdit ) 1325*cdf0e10cSrcweir mpToolBarManager->AddToolBarShell(ToolBarManager::TBG_FUNCTION, RID_DRAW_TEXT_TOOLBOX); 1326*cdf0e10cSrcweir 1327*cdf0e10cSrcweir SdrView* pView = &const_cast<SdrView&>(rView); 1328*cdf0e10cSrcweir // Check if the extrusion tool bar and the fontwork tool bar have to 1329*cdf0e10cSrcweir // be activated. 1330*cdf0e10cSrcweir if (svx::checkForSelectedCustomShapes(pView, true /* bOnlyExtruded */ )) 1331*cdf0e10cSrcweir mpToolBarManager->AddToolBarShell(ToolBarManager::TBG_FUNCTION, RID_SVX_EXTRUSION_BAR); 1332*cdf0e10cSrcweir sal_uInt32 nCheckStatus = 0; 1333*cdf0e10cSrcweir if (svx::checkForSelectedFontWork(pView, nCheckStatus)) 1334*cdf0e10cSrcweir mpToolBarManager->AddToolBarShell(ToolBarManager::TBG_FUNCTION, RID_SVX_FONTWORK_BAR); 1335*cdf0e10cSrcweir 1336*cdf0e10cSrcweir // Switch on additional context-sensitive tool bars. 1337*cdf0e10cSrcweir if (rView.GetContext() == SDRCONTEXT_POINTEDIT) 1338*cdf0e10cSrcweir mpToolBarManager->AddToolBarShell(ToolBarManager::TBG_FUNCTION, RID_BEZIER_TOOLBOX); 1339*cdf0e10cSrcweir } 1340*cdf0e10cSrcweir 1341*cdf0e10cSrcweir 1342*cdf0e10cSrcweir 1343*cdf0e10cSrcweir 1344*cdf0e10cSrcweir void ToolBarRules::SubShellAdded ( 1345*cdf0e10cSrcweir ::sd::ToolBarManager::ToolBarGroup eGroup, 1346*cdf0e10cSrcweir sd::ShellId nShellId) 1347*cdf0e10cSrcweir { 1348*cdf0e10cSrcweir // For some tool bar shells (those defined in sd) we have to add the 1349*cdf0e10cSrcweir // actual tool bar here. 1350*cdf0e10cSrcweir switch (nShellId) 1351*cdf0e10cSrcweir { 1352*cdf0e10cSrcweir case RID_DRAW_GRAF_TOOLBOX: 1353*cdf0e10cSrcweir mpToolBarManager->AddToolBar(eGroup, ToolBarManager::msGraphicObjectBar); 1354*cdf0e10cSrcweir break; 1355*cdf0e10cSrcweir 1356*cdf0e10cSrcweir case RID_DRAW_MEDIA_TOOLBOX: 1357*cdf0e10cSrcweir mpToolBarManager->AddToolBar(eGroup, ToolBarManager::msMediaObjectBar); 1358*cdf0e10cSrcweir break; 1359*cdf0e10cSrcweir 1360*cdf0e10cSrcweir case RID_DRAW_TEXT_TOOLBOX: 1361*cdf0e10cSrcweir mpToolBarManager->AddToolBar(eGroup, ToolBarManager::msTextObjectBar); 1362*cdf0e10cSrcweir break; 1363*cdf0e10cSrcweir 1364*cdf0e10cSrcweir case RID_BEZIER_TOOLBOX: 1365*cdf0e10cSrcweir mpToolBarManager->AddToolBar(eGroup, ToolBarManager::msBezierObjectBar); 1366*cdf0e10cSrcweir break; 1367*cdf0e10cSrcweir 1368*cdf0e10cSrcweir case RID_DRAW_TABLE_TOOLBOX: 1369*cdf0e10cSrcweir mpToolBarManager->AddToolBar(eGroup, ToolBarManager::msTableObjectBar); 1370*cdf0e10cSrcweir break; 1371*cdf0e10cSrcweir } 1372*cdf0e10cSrcweir } 1373*cdf0e10cSrcweir 1374*cdf0e10cSrcweir 1375*cdf0e10cSrcweir 1376*cdf0e10cSrcweir 1377*cdf0e10cSrcweir void ToolBarRules::SubShellRemoved ( 1378*cdf0e10cSrcweir ::sd::ToolBarManager::ToolBarGroup eGroup, 1379*cdf0e10cSrcweir sd::ShellId nShellId) 1380*cdf0e10cSrcweir { 1381*cdf0e10cSrcweir // For some tool bar shells (those defined in sd) we have to add the 1382*cdf0e10cSrcweir // actual tool bar here. 1383*cdf0e10cSrcweir switch (nShellId) 1384*cdf0e10cSrcweir { 1385*cdf0e10cSrcweir case RID_DRAW_GRAF_TOOLBOX: 1386*cdf0e10cSrcweir mpToolBarManager->RemoveToolBar(eGroup, ToolBarManager::msGraphicObjectBar); 1387*cdf0e10cSrcweir break; 1388*cdf0e10cSrcweir 1389*cdf0e10cSrcweir case RID_DRAW_MEDIA_TOOLBOX: 1390*cdf0e10cSrcweir mpToolBarManager->RemoveToolBar(eGroup, ToolBarManager::msMediaObjectBar); 1391*cdf0e10cSrcweir break; 1392*cdf0e10cSrcweir 1393*cdf0e10cSrcweir case RID_DRAW_TEXT_TOOLBOX: 1394*cdf0e10cSrcweir mpToolBarManager->RemoveToolBar(eGroup, ToolBarManager::msTextObjectBar); 1395*cdf0e10cSrcweir break; 1396*cdf0e10cSrcweir 1397*cdf0e10cSrcweir case RID_BEZIER_TOOLBOX: 1398*cdf0e10cSrcweir mpToolBarManager->RemoveToolBar(eGroup, ToolBarManager::msBezierObjectBar); 1399*cdf0e10cSrcweir break; 1400*cdf0e10cSrcweir 1401*cdf0e10cSrcweir case RID_DRAW_TABLE_TOOLBOX: 1402*cdf0e10cSrcweir mpToolBarManager->RemoveToolBar(eGroup, ToolBarManager::msTableObjectBar); 1403*cdf0e10cSrcweir break; 1404*cdf0e10cSrcweir } 1405*cdf0e10cSrcweir } 1406*cdf0e10cSrcweir 1407*cdf0e10cSrcweir 1408*cdf0e10cSrcweir 1409*cdf0e10cSrcweir 1410*cdf0e10cSrcweir //===== ToolBarList =========================================================== 1411*cdf0e10cSrcweir 1412*cdf0e10cSrcweir ToolBarList::ToolBarList (void) 1413*cdf0e10cSrcweir : maGroups(), 1414*cdf0e10cSrcweir maActiveToolBars() 1415*cdf0e10cSrcweir { 1416*cdf0e10cSrcweir } 1417*cdf0e10cSrcweir 1418*cdf0e10cSrcweir 1419*cdf0e10cSrcweir 1420*cdf0e10cSrcweir 1421*cdf0e10cSrcweir void ToolBarList::ClearGroup (sd::ToolBarManager::ToolBarGroup eGroup) 1422*cdf0e10cSrcweir { 1423*cdf0e10cSrcweir Groups::iterator iGroup (maGroups.find(eGroup)); 1424*cdf0e10cSrcweir if (iGroup != maGroups.end()) 1425*cdf0e10cSrcweir { 1426*cdf0e10cSrcweir if ( ! iGroup->second.empty()) 1427*cdf0e10cSrcweir { 1428*cdf0e10cSrcweir iGroup->second.clear(); 1429*cdf0e10cSrcweir } 1430*cdf0e10cSrcweir } 1431*cdf0e10cSrcweir } 1432*cdf0e10cSrcweir 1433*cdf0e10cSrcweir 1434*cdf0e10cSrcweir 1435*cdf0e10cSrcweir 1436*cdf0e10cSrcweir void ToolBarList::AddToolBar ( 1437*cdf0e10cSrcweir sd::ToolBarManager::ToolBarGroup eGroup, 1438*cdf0e10cSrcweir const ::rtl::OUString& rsName) 1439*cdf0e10cSrcweir { 1440*cdf0e10cSrcweir Groups::iterator iGroup (maGroups.find(eGroup)); 1441*cdf0e10cSrcweir if (iGroup == maGroups.end()) 1442*cdf0e10cSrcweir iGroup = maGroups.insert(Groups::value_type(eGroup,NameList())).first; 1443*cdf0e10cSrcweir 1444*cdf0e10cSrcweir if (iGroup != maGroups.end()) 1445*cdf0e10cSrcweir { 1446*cdf0e10cSrcweir NameList::const_iterator iBar ( 1447*cdf0e10cSrcweir ::std::find(iGroup->second.begin(),iGroup->second.end(),rsName)); 1448*cdf0e10cSrcweir if (iBar == iGroup->second.end()) 1449*cdf0e10cSrcweir { 1450*cdf0e10cSrcweir iGroup->second.push_back(rsName); 1451*cdf0e10cSrcweir } 1452*cdf0e10cSrcweir } 1453*cdf0e10cSrcweir } 1454*cdf0e10cSrcweir 1455*cdf0e10cSrcweir 1456*cdf0e10cSrcweir 1457*cdf0e10cSrcweir 1458*cdf0e10cSrcweir bool ToolBarList::RemoveToolBar ( 1459*cdf0e10cSrcweir sd::ToolBarManager::ToolBarGroup eGroup, 1460*cdf0e10cSrcweir const ::rtl::OUString& rsName) 1461*cdf0e10cSrcweir { 1462*cdf0e10cSrcweir Groups::iterator iGroup (maGroups.find(eGroup)); 1463*cdf0e10cSrcweir if (iGroup != maGroups.end()) 1464*cdf0e10cSrcweir { 1465*cdf0e10cSrcweir NameList::iterator iBar ( 1466*cdf0e10cSrcweir ::std::find(iGroup->second.begin(),iGroup->second.end(),rsName)); 1467*cdf0e10cSrcweir if (iBar != iGroup->second.end()) 1468*cdf0e10cSrcweir { 1469*cdf0e10cSrcweir iGroup->second.erase(iBar); 1470*cdf0e10cSrcweir return true; 1471*cdf0e10cSrcweir } 1472*cdf0e10cSrcweir } 1473*cdf0e10cSrcweir return false; 1474*cdf0e10cSrcweir } 1475*cdf0e10cSrcweir 1476*cdf0e10cSrcweir 1477*cdf0e10cSrcweir 1478*cdf0e10cSrcweir 1479*cdf0e10cSrcweir void ToolBarList::MakeRequestedToolBarList (NameList& rRequestedToolBars) const 1480*cdf0e10cSrcweir { 1481*cdf0e10cSrcweir for (int i=sd::ToolBarManager::TBG__FIRST; i<=sd::ToolBarManager::TBG__LAST; ++i) 1482*cdf0e10cSrcweir { 1483*cdf0e10cSrcweir ::sd::ToolBarManager::ToolBarGroup eGroup = (::sd::ToolBarManager::ToolBarGroup)i; 1484*cdf0e10cSrcweir Groups::const_iterator iGroup (maGroups.find(eGroup)); 1485*cdf0e10cSrcweir if (iGroup != maGroups.end()) 1486*cdf0e10cSrcweir ::std::copy( 1487*cdf0e10cSrcweir iGroup->second.begin(), 1488*cdf0e10cSrcweir iGroup->second.end(), 1489*cdf0e10cSrcweir ::std::inserter(rRequestedToolBars,rRequestedToolBars.end())); 1490*cdf0e10cSrcweir } 1491*cdf0e10cSrcweir } 1492*cdf0e10cSrcweir 1493*cdf0e10cSrcweir 1494*cdf0e10cSrcweir 1495*cdf0e10cSrcweir 1496*cdf0e10cSrcweir void ToolBarList::GetToolBarsToActivate (NameList& rToolBars) const 1497*cdf0e10cSrcweir { 1498*cdf0e10cSrcweir NameList aRequestedToolBars; 1499*cdf0e10cSrcweir MakeRequestedToolBarList(aRequestedToolBars); 1500*cdf0e10cSrcweir 1501*cdf0e10cSrcweir NameList::const_iterator iToolBar; 1502*cdf0e10cSrcweir for (iToolBar=aRequestedToolBars.begin(); iToolBar!=aRequestedToolBars.end(); ++iToolBar) 1503*cdf0e10cSrcweir { 1504*cdf0e10cSrcweir if (::std::find(maActiveToolBars.begin(),maActiveToolBars.end(),*iToolBar) 1505*cdf0e10cSrcweir == maActiveToolBars.end()) 1506*cdf0e10cSrcweir { 1507*cdf0e10cSrcweir rToolBars.push_back(*iToolBar); 1508*cdf0e10cSrcweir } 1509*cdf0e10cSrcweir } 1510*cdf0e10cSrcweir } 1511*cdf0e10cSrcweir 1512*cdf0e10cSrcweir 1513*cdf0e10cSrcweir 1514*cdf0e10cSrcweir 1515*cdf0e10cSrcweir void ToolBarList::GetToolBarsToDeactivate (NameList& rToolBars) const 1516*cdf0e10cSrcweir { 1517*cdf0e10cSrcweir NameList aRequestedToolBars; 1518*cdf0e10cSrcweir MakeRequestedToolBarList(aRequestedToolBars); 1519*cdf0e10cSrcweir 1520*cdf0e10cSrcweir NameList::const_iterator iToolBar; 1521*cdf0e10cSrcweir for (iToolBar=maActiveToolBars.begin(); iToolBar!=maActiveToolBars.end(); ++iToolBar) 1522*cdf0e10cSrcweir { 1523*cdf0e10cSrcweir if (::std::find(aRequestedToolBars.begin(),aRequestedToolBars.end(),*iToolBar) 1524*cdf0e10cSrcweir == aRequestedToolBars.end()) 1525*cdf0e10cSrcweir { 1526*cdf0e10cSrcweir rToolBars.push_back(*iToolBar); 1527*cdf0e10cSrcweir } 1528*cdf0e10cSrcweir } 1529*cdf0e10cSrcweir } 1530*cdf0e10cSrcweir 1531*cdf0e10cSrcweir 1532*cdf0e10cSrcweir 1533*cdf0e10cSrcweir 1534*cdf0e10cSrcweir void ToolBarList::MarkToolBarAsActive (const ::rtl::OUString& rsName) 1535*cdf0e10cSrcweir { 1536*cdf0e10cSrcweir maActiveToolBars.push_back(rsName); 1537*cdf0e10cSrcweir } 1538*cdf0e10cSrcweir 1539*cdf0e10cSrcweir 1540*cdf0e10cSrcweir 1541*cdf0e10cSrcweir 1542*cdf0e10cSrcweir void ToolBarList::MarkToolBarAsNotActive (const ::rtl::OUString& rsName) 1543*cdf0e10cSrcweir { 1544*cdf0e10cSrcweir maActiveToolBars.erase( 1545*cdf0e10cSrcweir ::std::find(maActiveToolBars.begin(),maActiveToolBars.end(), rsName)); 1546*cdf0e10cSrcweir } 1547*cdf0e10cSrcweir 1548*cdf0e10cSrcweir 1549*cdf0e10cSrcweir 1550*cdf0e10cSrcweir 1551*cdf0e10cSrcweir void ToolBarList::MarkAllToolBarsAsNotActive (void) 1552*cdf0e10cSrcweir { 1553*cdf0e10cSrcweir maActiveToolBars.clear(); 1554*cdf0e10cSrcweir } 1555*cdf0e10cSrcweir 1556*cdf0e10cSrcweir 1557*cdf0e10cSrcweir 1558*cdf0e10cSrcweir 1559*cdf0e10cSrcweir //===== ToolBarShellList ====================================================== 1560*cdf0e10cSrcweir 1561*cdf0e10cSrcweir ToolBarShellList::ShellDescriptor::ShellDescriptor ( 1562*cdf0e10cSrcweir ShellId nId, 1563*cdf0e10cSrcweir sd::ToolBarManager::ToolBarGroup eGroup) 1564*cdf0e10cSrcweir : mnId(nId), 1565*cdf0e10cSrcweir meGroup(eGroup) 1566*cdf0e10cSrcweir { 1567*cdf0e10cSrcweir } 1568*cdf0e10cSrcweir 1569*cdf0e10cSrcweir 1570*cdf0e10cSrcweir 1571*cdf0e10cSrcweir 1572*cdf0e10cSrcweir ToolBarShellList::ToolBarShellList (void) 1573*cdf0e10cSrcweir : maNewList() 1574*cdf0e10cSrcweir , maCurrentList() 1575*cdf0e10cSrcweir { 1576*cdf0e10cSrcweir } 1577*cdf0e10cSrcweir 1578*cdf0e10cSrcweir 1579*cdf0e10cSrcweir 1580*cdf0e10cSrcweir 1581*cdf0e10cSrcweir void ToolBarShellList::ClearGroup (sd::ToolBarManager::ToolBarGroup eGroup) 1582*cdf0e10cSrcweir { 1583*cdf0e10cSrcweir // In every loop we erase the first member of the specified group. 1584*cdf0e10cSrcweir // Because that invalidates the iterator another loop is started after 1585*cdf0e10cSrcweir // that. The loop is left only when no member of the group is found and 1586*cdf0e10cSrcweir // no element is erased 1587*cdf0e10cSrcweir bool bLoop; 1588*cdf0e10cSrcweir do 1589*cdf0e10cSrcweir { 1590*cdf0e10cSrcweir bLoop = false; 1591*cdf0e10cSrcweir 1592*cdf0e10cSrcweir GroupedShellList::iterator iDescriptor; 1593*cdf0e10cSrcweir for (iDescriptor=maNewList.begin(); iDescriptor!=maNewList.end(); ++iDescriptor) 1594*cdf0e10cSrcweir if (iDescriptor->meGroup == eGroup) 1595*cdf0e10cSrcweir { 1596*cdf0e10cSrcweir maNewList.erase(iDescriptor); 1597*cdf0e10cSrcweir // Erasing the descriptor invalidated the iterator so we 1598*cdf0e10cSrcweir // have to exit the for loop and start anew to search for 1599*cdf0e10cSrcweir // further elements of the group. 1600*cdf0e10cSrcweir bLoop = true; 1601*cdf0e10cSrcweir break; 1602*cdf0e10cSrcweir } 1603*cdf0e10cSrcweir } 1604*cdf0e10cSrcweir while (bLoop); 1605*cdf0e10cSrcweir } 1606*cdf0e10cSrcweir 1607*cdf0e10cSrcweir 1608*cdf0e10cSrcweir 1609*cdf0e10cSrcweir 1610*cdf0e10cSrcweir void ToolBarShellList::AddShellId (sd::ToolBarManager::ToolBarGroup eGroup, sd::ShellId nId) 1611*cdf0e10cSrcweir { 1612*cdf0e10cSrcweir // Make sure that the shell is not added twice (and possibly in 1613*cdf0e10cSrcweir // different groups.) 1614*cdf0e10cSrcweir ShellDescriptor aDescriptor (nId,eGroup); 1615*cdf0e10cSrcweir GroupedShellList::iterator iDescriptor (maNewList.find(aDescriptor)); 1616*cdf0e10cSrcweir if (iDescriptor != maNewList.end()) 1617*cdf0e10cSrcweir { 1618*cdf0e10cSrcweir // The shell is already requested. 1619*cdf0e10cSrcweir if (iDescriptor->meGroup != eGroup) 1620*cdf0e10cSrcweir { 1621*cdf0e10cSrcweir // It is now being requested for another group. 1622*cdf0e10cSrcweir // (Is this an error?) 1623*cdf0e10cSrcweir // Move it to that group. 1624*cdf0e10cSrcweir maNewList.erase(iDescriptor); 1625*cdf0e10cSrcweir maNewList.insert(aDescriptor); 1626*cdf0e10cSrcweir } 1627*cdf0e10cSrcweir // else nothing to do. 1628*cdf0e10cSrcweir } 1629*cdf0e10cSrcweir else 1630*cdf0e10cSrcweir maNewList.insert(aDescriptor); 1631*cdf0e10cSrcweir } 1632*cdf0e10cSrcweir 1633*cdf0e10cSrcweir 1634*cdf0e10cSrcweir 1635*cdf0e10cSrcweir 1636*cdf0e10cSrcweir void ToolBarShellList::ReleaseAllShells (ToolBarRules& rRules) 1637*cdf0e10cSrcweir { 1638*cdf0e10cSrcweir // Release the currently active tool bars. 1639*cdf0e10cSrcweir GroupedShellList aList (maCurrentList); 1640*cdf0e10cSrcweir GroupedShellList::iterator iDescriptor; 1641*cdf0e10cSrcweir for (iDescriptor=aList.begin(); iDescriptor!=aList.end(); ++iDescriptor) 1642*cdf0e10cSrcweir { 1643*cdf0e10cSrcweir rRules.SubShellRemoved(iDescriptor->meGroup, iDescriptor->mnId); 1644*cdf0e10cSrcweir } 1645*cdf0e10cSrcweir 1646*cdf0e10cSrcweir // Clear the list of requested tool bars. 1647*cdf0e10cSrcweir maNewList.clear(); 1648*cdf0e10cSrcweir } 1649*cdf0e10cSrcweir 1650*cdf0e10cSrcweir 1651*cdf0e10cSrcweir 1652*cdf0e10cSrcweir 1653*cdf0e10cSrcweir void ToolBarShellList::UpdateShells ( 1654*cdf0e10cSrcweir const ::boost::shared_ptr<ViewShell>& rpMainViewShell, 1655*cdf0e10cSrcweir const ::boost::shared_ptr<ViewShellManager>& rpManager) 1656*cdf0e10cSrcweir { 1657*cdf0e10cSrcweir if (rpMainViewShell.get() != NULL) 1658*cdf0e10cSrcweir { 1659*cdf0e10cSrcweir GroupedShellList aList; 1660*cdf0e10cSrcweir 1661*cdf0e10cSrcweir // Deactivate shells that are in maCurrentList, but not in 1662*cdf0e10cSrcweir // maNewList. 1663*cdf0e10cSrcweir ::std::set_difference(maCurrentList.begin(), maCurrentList.end(), 1664*cdf0e10cSrcweir maNewList.begin(), maNewList.end(), 1665*cdf0e10cSrcweir std::insert_iterator<GroupedShellList>(aList,aList.begin())); 1666*cdf0e10cSrcweir for (GroupedShellList::iterator iShell=aList.begin(); iShell!=aList.end(); ++iShell) 1667*cdf0e10cSrcweir { 1668*cdf0e10cSrcweir #ifdef VERBOSE 1669*cdf0e10cSrcweir OSL_TRACE("deactivating tool bar shell %d\n", iShell->mnId); 1670*cdf0e10cSrcweir #endif 1671*cdf0e10cSrcweir rpManager->DeactivateSubShell(*rpMainViewShell, iShell->mnId); 1672*cdf0e10cSrcweir } 1673*cdf0e10cSrcweir 1674*cdf0e10cSrcweir // Activate shells that are in maNewList, but not in 1675*cdf0e10cSrcweir // maCurrentList. 1676*cdf0e10cSrcweir aList.clear(); 1677*cdf0e10cSrcweir ::std::set_difference(maNewList.begin(), maNewList.end(), 1678*cdf0e10cSrcweir maCurrentList.begin(), maCurrentList.end(), 1679*cdf0e10cSrcweir std::insert_iterator<GroupedShellList>(aList,aList.begin())); 1680*cdf0e10cSrcweir for (GroupedShellList::iterator iShell=aList.begin(); iShell!=aList.end(); ++iShell) 1681*cdf0e10cSrcweir { 1682*cdf0e10cSrcweir #ifdef VERBOSE 1683*cdf0e10cSrcweir OSL_TRACE("activating tool bar shell %d\n", iShell->mnId); 1684*cdf0e10cSrcweir #endif 1685*cdf0e10cSrcweir rpManager->ActivateSubShell(*rpMainViewShell, iShell->mnId); 1686*cdf0e10cSrcweir } 1687*cdf0e10cSrcweir 1688*cdf0e10cSrcweir // The maNewList now refelects the current state and thus is made 1689*cdf0e10cSrcweir // maCurrentList. 1690*cdf0e10cSrcweir maCurrentList = maNewList; 1691*cdf0e10cSrcweir } 1692*cdf0e10cSrcweir } 1693*cdf0e10cSrcweir 1694*cdf0e10cSrcweir 1695*cdf0e10cSrcweir 1696*cdf0e10cSrcweir 1697*cdf0e10cSrcweir } // end of anonymous namespace 1698