LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sd/source/ui/view - ToolBarManager.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 393 534 73.6 %
Date: 2013-07-09 Functions: 62 79 78.5 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10