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