LCOV - code coverage report
Current view: top level - sd/source/ui/framework/factories - BasicViewFactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 182 212 85.8 %
Date: 2012-08-25 Functions: 25 25 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 233 506 46.0 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : 
      30                 :            : #include "BasicViewFactory.hxx"
      31                 :            : 
      32                 :            : #include "framework/ViewShellWrapper.hxx"
      33                 :            : #include "framework/FrameworkHelper.hxx"
      34                 :            : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
      35                 :            : #include <com/sun/star/lang/IllegalArgumentException.hpp>
      36                 :            : #include "framework/Pane.hxx"
      37                 :            : #include "DrawController.hxx"
      38                 :            : #include "DrawSubController.hxx"
      39                 :            : #include "ViewShellBase.hxx"
      40                 :            : #include "ViewShellManager.hxx"
      41                 :            : #include "DrawDocShell.hxx"
      42                 :            : #include "DrawViewShell.hxx"
      43                 :            : #include "GraphicViewShell.hxx"
      44                 :            : #include "OutlineViewShell.hxx"
      45                 :            : #include "taskpane/ToolPanelViewShell.hxx"
      46                 :            : #include "PresentationViewShell.hxx"
      47                 :            : #include "SlideSorterViewShell.hxx"
      48                 :            : #include "FrameView.hxx"
      49                 :            : 
      50                 :            : #include <sfx2/viewfrm.hxx>
      51                 :            : #include <vcl/wrkwin.hxx>
      52                 :            : #include <toolkit/helper/vclunohelper.hxx>
      53                 :            : 
      54                 :            : #include <boost/bind.hpp>
      55                 :            : 
      56                 :            : using namespace ::com::sun::star;
      57                 :            : using namespace ::com::sun::star::uno;
      58                 :            : using namespace ::com::sun::star::lang;
      59                 :            : using namespace ::com::sun::star::drawing::framework;
      60                 :            : 
      61                 :            : using ::rtl::OUString;
      62                 :            : using ::sd::framework::FrameworkHelper;
      63                 :            : 
      64                 :            : 
      65                 :            : namespace sd { namespace framework {
      66                 :            : 
      67                 :            : 
      68                 :        130 : Reference<XInterface> SAL_CALL BasicViewFactory_createInstance (
      69                 :            :     const Reference<XComponentContext>& rxContext)
      70                 :            : {
      71         [ +  - ]:        130 :     return Reference<XInterface>(static_cast<XWeak*>(new BasicViewFactory(rxContext)));
      72                 :            : }
      73                 :            : 
      74                 :            : 
      75                 :            : 
      76                 :            : 
      77                 :         38 : ::rtl::OUString BasicViewFactory_getImplementationName (void) throw(RuntimeException)
      78                 :            : {
      79                 :         38 :     return ::rtl::OUString("com.sun.star.comp.Draw.framework.BasicViewFactory");
      80                 :            : }
      81                 :            : 
      82                 :            : 
      83                 :            : 
      84                 :            : 
      85                 :         16 : Sequence<rtl::OUString> SAL_CALL BasicViewFactory_getSupportedServiceNames (void)
      86                 :            :     throw (RuntimeException)
      87                 :            : {
      88 [ +  - ][ +  - ]:         16 :     static const ::rtl::OUString sServiceName("com.sun.star.drawing.framework.BasicViewFactory");
      89                 :         16 :     return Sequence<rtl::OUString>(&sServiceName, 1);
      90                 :            : }
      91                 :            : 
      92                 :            : 
      93                 :            : 
      94                 :            : 
      95                 :            : //===== ViewDescriptor ========================================================
      96                 :            : 
      97 [ +  - ][ +  - ]:        572 : class BasicViewFactory::ViewDescriptor
      98                 :            : {
      99                 :            : public:
     100                 :            :     Reference<XResource> mxView;
     101                 :            :     ::boost::shared_ptr<sd::ViewShell> mpViewShell;
     102                 :            :     ViewShellWrapper* mpWrapper;
     103                 :            :     Reference<XResourceId> mxViewId;
     104                 :        312 :     static bool CompareView (const ::boost::shared_ptr<ViewDescriptor>& rpDescriptor,
     105                 :            :         const Reference<XResource>& rxView)
     106                 :        312 :     { return rpDescriptor->mxView.get() == rxView.get(); }
     107                 :            : };
     108                 :            : 
     109                 :            : 
     110                 :            : 
     111                 :            : 
     112                 :            : 
     113                 :            : //===== BasicViewFactory::ViewShellContainer ==================================
     114                 :            : 
     115                 :        130 : class BasicViewFactory::ViewShellContainer
     116                 :            :     : public ::std::vector<boost::shared_ptr<ViewDescriptor> >
     117                 :            : {
     118                 :            : public:
     119                 :        130 :     ViewShellContainer (void) {};
     120                 :            : };
     121                 :            : 
     122                 :            : 
     123                 :        130 : class BasicViewFactory::ViewCache
     124                 :            :     : public ::std::vector<boost::shared_ptr<ViewDescriptor> >
     125                 :            : {
     126                 :            : public:
     127                 :        130 :     ViewCache (void) {};
     128                 :            : };
     129                 :            : 
     130                 :            : 
     131                 :            : 
     132                 :            : 
     133                 :            : //===== ViewFactory ===========================================================
     134                 :            : 
     135                 :        130 : BasicViewFactory::BasicViewFactory (
     136                 :            :     const Reference<XComponentContext>& rxContext)
     137                 :            :     : BasicViewFactoryInterfaceBase(MutexOwner::maMutex),
     138                 :            :       mxConfigurationController(),
     139                 :          0 :       mpViewShellContainer(new ViewShellContainer()),
     140                 :            :       mpBase(NULL),
     141                 :            :       mpFrameView(NULL),
     142         [ +  - ]:        130 :       mpWindow(new WorkWindow(NULL,WB_STDWORK)),
     143                 :          0 :       mpViewCache(new ViewCache()),
     144 [ +  - ][ +  - ]:        260 :       mxLocalPane(new Pane(Reference<XResourceId>(), mpWindow.get()))
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
                 [ +  - ]
     145                 :            : {
     146                 :            :     (void)rxContext;
     147                 :        130 : }
     148                 :            : 
     149                 :            : 
     150                 :            : 
     151                 :            : 
     152 [ +  - ][ +  - ]:        130 : BasicViewFactory::~BasicViewFactory (void)
         [ +  - ][ +  - ]
     153                 :            : {
     154         [ -  + ]:        260 : }
     155                 :            : 
     156                 :            : 
     157                 :            : 
     158                 :            : 
     159                 :        130 : void SAL_CALL BasicViewFactory::disposing (void)
     160                 :            : {
     161                 :            :     // Disconnect from the frame view.
     162         [ +  - ]:        130 :     if (mpFrameView != NULL)
     163                 :            :     {
     164         [ +  - ]:        130 :         mpFrameView->Disconnect();
     165                 :        130 :         mpFrameView = NULL;
     166                 :            :     }
     167                 :            : 
     168                 :            :     // Relase the view cache.
     169                 :        130 :     ViewShellContainer::const_iterator iView;
     170 [ +  - ][ +  - ]:        286 :     for (iView=mpViewCache->begin(); iView!=mpViewCache->end(); ++iView)
                 [ +  + ]
     171                 :            :     {
     172         [ +  - ]:        156 :         ReleaseView(*iView, true);
     173                 :            :     }
     174                 :            : 
     175                 :            :     // Release the view shell container.  At this point no one other than us
     176                 :            :     // should hold references to the view shells (at the moment this is a
     177                 :            :     // trivial requirement, because no one other then us holds a shared
     178                 :            :     // pointer).
     179                 :            :     //    ViewShellContainer::const_iterator iView;
     180 [ +  - ][ +  - ]:        130 :     for (iView=mpViewShellContainer->begin(); iView!=mpViewShellContainer->end(); ++iView)
                 [ -  + ]
     181                 :            :     {
     182                 :            :         OSL_ASSERT((*iView)->mpViewShell.unique());
     183                 :            :     }
     184         [ +  - ]:        130 :     mpViewShellContainer.reset();
     185                 :        130 : }
     186                 :            : 
     187                 :            : 
     188                 :            : 
     189                 :            : 
     190                 :        442 : Reference<XResource> SAL_CALL BasicViewFactory::createResource (
     191                 :            :     const Reference<XResourceId>& rxViewId)
     192                 :            :     throw(RuntimeException, IllegalArgumentException, WrappedTargetException)
     193                 :            : {
     194                 :        442 :     Reference<XResource> xView;
     195                 :            :     const bool bIsCenterPane (
     196 [ +  - ][ +  - ]:        442 :         rxViewId->isBoundToURL(FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT));
     197                 :            : 
     198                 :            :     // Get the pane for the anchor URL.
     199                 :        442 :     Reference<XPane> xPane;
     200         [ +  - ]:        442 :     if (mxConfigurationController.is())
     201 [ +  - ][ +  - ]:        442 :         xPane = Reference<XPane>(mxConfigurationController->getResource(rxViewId->getAnchor()),
     202 [ +  - ][ +  - ]:        442 :             UNO_QUERY);
         [ +  - ][ +  - ]
     203                 :            : 
     204                 :            :     // For main views use the frame view of the last main view.
     205                 :        442 :     ::sd::FrameView* pFrameView = NULL;
     206 [ +  - ][ +  + ]:        442 :     if (xPane.is() && bIsCenterPane)
                 [ +  + ]
     207                 :            :     {
     208                 :        130 :         pFrameView = mpFrameView;
     209                 :            :     }
     210                 :            : 
     211                 :            :     // Get Window pointer for XWindow of the pane.
     212                 :        442 :     ::Window* pWindow = NULL;
     213         [ +  - ]:        442 :     if (xPane.is())
     214 [ +  - ][ +  - ]:        442 :         pWindow = VCLUnoHelper::GetWindow(xPane->getWindow());
                 [ +  - ]
     215                 :            : 
     216                 :            :     // Get the view frame.
     217                 :        442 :     SfxViewFrame* pFrame = NULL;
     218         [ +  - ]:        442 :     if (mpBase != NULL)
     219                 :        442 :         pFrame = mpBase->GetViewFrame();
     220                 :            : 
     221 [ +  - ][ +  - ]:        442 :     if (pFrame != NULL && mpBase!=NULL && pWindow!=NULL)
                 [ +  + ]
     222                 :            :     {
     223                 :            :         // Try to get the view from the cache.
     224         [ +  - ]:        286 :         ::boost::shared_ptr<ViewDescriptor> pDescriptor (GetViewFromCache(rxViewId, xPane));
     225                 :            : 
     226                 :            :         // When the requested view is not in the cache then create a new view.
     227         [ +  - ]:        286 :         if (pDescriptor.get() == NULL)
     228                 :            :         {
     229 [ +  - ][ +  - ]:        286 :             pDescriptor = CreateView(rxViewId, *pFrame, *pWindow, xPane, pFrameView, bIsCenterPane);
                 [ +  - ]
     230                 :            :         }
     231                 :            : 
     232         [ +  - ]:        286 :         if (pDescriptor.get() != NULL)
     233         [ +  - ]:        286 :             xView = pDescriptor->mxView;
     234                 :            : 
     235         [ +  - ]:        286 :         mpViewShellContainer->push_back(pDescriptor);
     236                 :            : 
     237         [ +  + ]:        286 :         if (bIsCenterPane)
     238         [ +  - ]:        130 :             ActivateCenterView(pDescriptor);
     239                 :            :         else
     240 [ +  - ][ +  - ]:        286 :             pWindow->Resize();
     241                 :            :     }
     242                 :            : 
     243                 :        442 :     return xView;
     244                 :            : }
     245                 :            : 
     246                 :            : 
     247                 :            : 
     248                 :            : 
     249                 :        286 : void SAL_CALL BasicViewFactory::releaseResource (const Reference<XResource>& rxView)
     250                 :            :     throw(RuntimeException)
     251                 :            : {
     252         [ -  + ]:        286 :     if ( ! rxView.is())
     253         [ #  # ]:          0 :         throw lang::IllegalArgumentException();
     254                 :            : 
     255 [ +  - ][ +  - ]:        286 :     if (rxView.is() && mpBase!=NULL)
                 [ +  - ]
     256                 :            :     {
     257                 :            :         ViewShellContainer::iterator iViewShell (
     258                 :            :             ::std::find_if(
     259                 :        286 :                 mpViewShellContainer->begin(),
     260                 :        286 :                 mpViewShellContainer->end(),
     261   [ +  -  +  - ]:        858 :                 ::boost::bind(&ViewDescriptor::CompareView, _1, rxView)));
                 [ +  - ]
     262 [ +  - ][ +  - ]:        286 :         if (iViewShell != mpViewShellContainer->end())
     263                 :            :         {
     264         [ +  - ]:        286 :             ::boost::shared_ptr<ViewShell> pViewShell ((*iViewShell)->mpViewShell);
     265                 :            : 
     266 [ +  - ][ +  + ]:        572 :             if ((*iViewShell)->mxViewId->isBoundToURL(
     267         [ +  - ]:        286 :                 FrameworkHelper::msCenterPaneURL, AnchorBindingMode_DIRECT))
     268                 :            :             {
     269                 :            :                 // Obtain a pointer to and connect to the frame view of the
     270                 :            :                 // view.  The next view, that is created, will be
     271                 :            :                 // initialized with this frame view.
     272         [ +  - ]:        130 :                 if (mpFrameView == NULL)
     273                 :            :                 {
     274         [ +  - ]:        130 :                     mpFrameView = pViewShell->GetFrameView();
     275         [ +  - ]:        130 :                     if (mpFrameView)
     276         [ +  - ]:        130 :                         mpFrameView->Connect();
     277                 :            :                 }
     278                 :            : 
     279                 :            :                 // With the view in the center pane the sub controller is
     280                 :            :                 // released, too.
     281         [ +  - ]:        130 :                 mpBase->GetDrawController().SetSubController(
     282         [ +  - ]:        260 :                     Reference<drawing::XDrawSubController>());
     283                 :            : 
     284         [ +  - ]:        130 :                 SfxViewShell* pSfxViewShell = pViewShell->GetViewShell();
     285         [ +  - ]:        130 :                 if (pSfxViewShell != NULL)
     286         [ +  - ]:        130 :                     pSfxViewShell->DisconnectAllClients();
     287                 :            :             }
     288                 :            : 
     289         [ +  - ]:        286 :             ReleaseView(*iViewShell);
     290                 :            : 
     291 [ +  - ][ +  - ]:        286 :             mpViewShellContainer->erase(iViewShell);
     292                 :            :         }
     293                 :            :         else
     294                 :            :         {
     295         [ #  # ]:          0 :             throw lang::IllegalArgumentException();
     296                 :            :         }
     297                 :            :     }
     298                 :        286 : }
     299                 :            : 
     300                 :            : 
     301                 :            : 
     302                 :            : 
     303                 :        130 : void SAL_CALL BasicViewFactory::initialize (const Sequence<Any>& aArguments)
     304                 :            :     throw (Exception, RuntimeException)
     305                 :            : {
     306         [ +  - ]:        130 :     if (aArguments.getLength() > 0)
     307                 :            :     {
     308                 :        130 :         Reference<XConfigurationController> xCC;
     309                 :            :         try
     310                 :            :         {
     311                 :            :             // Get the XController from the first argument.
     312         [ +  - ]:        130 :             Reference<frame::XController> xController (aArguments[0], UNO_QUERY_THROW);
     313                 :            : 
     314                 :            :             // Tunnel through the controller to obtain a ViewShellBase.
     315         [ +  - ]:        130 :             Reference<lang::XUnoTunnel> xTunnel (xController, UNO_QUERY_THROW);
     316                 :            :             ::sd::DrawController* pController = reinterpret_cast<sd::DrawController*>(
     317 [ +  - ][ +  - ]:        130 :                 xTunnel->getSomething(sd::DrawController::getUnoTunnelId()));
                 [ +  - ]
     318         [ +  - ]:        130 :             if (pController != NULL)
     319         [ +  - ]:        130 :                 mpBase = pController->GetViewShellBase();
     320                 :            : 
     321                 :            :             // Register the factory for its supported views.
     322         [ +  - ]:        130 :             Reference<XControllerManager> xCM (xController,UNO_QUERY_THROW);
     323 [ +  - ][ +  - ]:        130 :             mxConfigurationController = xCM->getConfigurationController();
                 [ +  - ]
     324         [ -  + ]:        130 :             if ( ! mxConfigurationController.is())
     325         [ #  # ]:          0 :                 throw RuntimeException();
     326 [ +  - ][ +  - ]:        130 :             mxConfigurationController->addResourceFactory(FrameworkHelper::msImpressViewURL, this);
                 [ +  - ]
     327 [ +  - ][ +  - ]:        130 :             mxConfigurationController->addResourceFactory(FrameworkHelper::msDrawViewURL, this);
                 [ +  - ]
     328 [ +  - ][ +  - ]:        130 :             mxConfigurationController->addResourceFactory(FrameworkHelper::msOutlineViewURL, this);
                 [ +  - ]
     329 [ +  - ][ +  - ]:        130 :             mxConfigurationController->addResourceFactory(FrameworkHelper::msNotesViewURL, this);
                 [ +  - ]
     330 [ +  - ][ +  - ]:        130 :             mxConfigurationController->addResourceFactory(FrameworkHelper::msHandoutViewURL, this);
                 [ +  - ]
     331 [ +  - ][ +  - ]:        130 :             mxConfigurationController->addResourceFactory(FrameworkHelper::msPresentationViewURL, this);
                 [ +  - ]
     332 [ +  - ][ +  - ]:        130 :             mxConfigurationController->addResourceFactory(FrameworkHelper::msTaskPaneURL, this);
                 [ +  - ]
     333 [ +  - ][ +  - ]:        130 :             mxConfigurationController->addResourceFactory(FrameworkHelper::msSlideSorterURL, this);
                 [ +  - ]
     334                 :            :         }
     335         [ #  # ]:          0 :         catch (RuntimeException&)
     336                 :            :         {
     337                 :          0 :             mpBase = NULL;
     338         [ #  # ]:          0 :             if (mxConfigurationController.is())
     339   [ #  #  #  #  :          0 :                 mxConfigurationController->removeResourceFactoryForReference(this);
                   #  # ]
     340                 :          0 :             throw;
     341                 :        130 :         }
     342                 :            :     }
     343                 :        130 : }
     344                 :            : 
     345                 :            : 
     346                 :            : 
     347                 :            : 
     348                 :        286 : ::boost::shared_ptr<BasicViewFactory::ViewDescriptor> BasicViewFactory::CreateView (
     349                 :            :     const Reference<XResourceId>& rxViewId,
     350                 :            :     SfxViewFrame& rFrame,
     351                 :            :     ::Window& rWindow,
     352                 :            :     const Reference<XPane>& rxPane,
     353                 :            :     FrameView* pFrameView,
     354                 :            :     const bool bIsCenterPane)
     355                 :            : {
     356 [ +  - ][ +  - ]:        286 :     ::boost::shared_ptr<ViewDescriptor> pDescriptor (new ViewDescriptor());
     357                 :            : 
     358                 :        286 :     pDescriptor->mpViewShell = CreateViewShell(
     359                 :            :         rxViewId,
     360                 :            :         rFrame,
     361                 :            :         rWindow,
     362                 :            :         pFrameView,
     363   [ +  -  +  - ]:        572 :         bIsCenterPane);
                 [ +  - ]
     364         [ +  - ]:        286 :     pDescriptor->mxViewId = rxViewId;
     365                 :            : 
     366         [ +  - ]:        286 :     if (pDescriptor->mpViewShell.get() != NULL)
     367                 :            :     {
     368         [ +  - ]:        286 :         pDescriptor->mpViewShell->Init(bIsCenterPane);
     369 [ +  - ][ +  - ]:        286 :         mpBase->GetViewShellManager()->ActivateViewShell(pDescriptor->mpViewShell.get());
                 [ +  - ]
     370                 :            : 
     371                 :        286 :         pDescriptor->mpWrapper = new ViewShellWrapper(
     372                 :        286 :             pDescriptor->mpViewShell,
     373                 :            :             rxViewId,
     374 [ +  - ][ +  - ]:        572 :             rxPane->getWindow());
           [ +  -  +  - ]
                 [ +  - ]
     375 [ +  - ][ +  - ]:        286 :         pDescriptor->mxView.set( pDescriptor->mpWrapper->queryInterface( XResource::static_type() ), UNO_QUERY_THROW );
                 [ +  - ]
     376                 :            :     }
     377                 :            : 
     378                 :        286 :     return pDescriptor;
     379                 :            : }
     380                 :            : 
     381                 :            : 
     382                 :            : 
     383                 :            : 
     384                 :        286 : ::boost::shared_ptr<ViewShell> BasicViewFactory::CreateViewShell (
     385                 :            :     const Reference<XResourceId>& rxViewId,
     386                 :            :     SfxViewFrame& rFrame,
     387                 :            :     ::Window& rWindow,
     388                 :            :     FrameView* pFrameView,
     389                 :            :     const bool bIsCenterPane)
     390                 :            : {
     391                 :        286 :     ::boost::shared_ptr<ViewShell> pViewShell;
     392 [ +  - ][ +  - ]:        286 :     const OUString& rsViewURL (rxViewId->getResourceURL());
     393         [ +  + ]:        286 :     if (rsViewURL.equals(FrameworkHelper::msImpressViewURL))
     394                 :            :     {
     395                 :            :         pViewShell.reset(
     396                 :            :             new DrawViewShell(
     397                 :            :                 &rFrame,
     398                 :            :                 *mpBase,
     399                 :            :                 &rWindow,
     400                 :            :                 PK_STANDARD,
     401 [ +  - ][ +  - ]:         26 :                 pFrameView));
                 [ +  - ]
     402                 :            :     }
     403         [ +  + ]:        260 :     else if (rsViewURL.equals(FrameworkHelper::msDrawViewURL))
     404                 :            :     {
     405                 :            :         pViewShell.reset(
     406                 :            :             new GraphicViewShell (
     407                 :            :                 &rFrame,
     408                 :            :                 *mpBase,
     409                 :            :                 &rWindow,
     410 [ +  - ][ +  - ]:        104 :                 pFrameView));
                 [ +  - ]
     411                 :            :     }
     412         [ -  + ]:        156 :     else if (rsViewURL.equals(FrameworkHelper::msOutlineViewURL))
     413                 :            :     {
     414                 :            :         pViewShell.reset(
     415                 :            :             new OutlineViewShell (
     416                 :            :                 &rFrame,
     417                 :            :                 *mpBase,
     418                 :            :                 &rWindow,
     419 [ #  # ][ #  # ]:          0 :                 pFrameView));
                 [ #  # ]
     420                 :            :     }
     421         [ -  + ]:        156 :     else if (rsViewURL.equals(FrameworkHelper::msNotesViewURL))
     422                 :            :     {
     423                 :            :         pViewShell.reset(
     424                 :            :             new DrawViewShell(
     425                 :            :                 &rFrame,
     426                 :            :                 *mpBase,
     427                 :            :                 &rWindow,
     428                 :            :                 PK_NOTES,
     429 [ #  # ][ #  # ]:          0 :                 pFrameView));
                 [ #  # ]
     430                 :            :     }
     431         [ -  + ]:        156 :     else if (rsViewURL.equals(FrameworkHelper::msHandoutViewURL))
     432                 :            :     {
     433                 :            :         pViewShell.reset(
     434                 :            :             new DrawViewShell(
     435                 :            :                 &rFrame,
     436                 :            :                 *mpBase,
     437                 :            :                 &rWindow,
     438                 :            :                 PK_HANDOUT,
     439 [ #  # ][ #  # ]:          0 :                 pFrameView));
                 [ #  # ]
     440                 :            :     }
     441         [ -  + ]:        156 :     else if (rsViewURL.equals(FrameworkHelper::msPresentationViewURL))
     442                 :            :     {
     443                 :            :         pViewShell.reset(
     444                 :            :             new PresentationViewShell(
     445                 :            :                 &rFrame,
     446                 :            :                 *mpBase,
     447                 :            :                 &rWindow,
     448 [ #  # ][ #  # ]:          0 :                 pFrameView));
                 [ #  # ]
     449                 :            :     }
     450         [ +  + ]:        156 :     else if (rsViewURL.equals(FrameworkHelper::msTaskPaneURL))
     451                 :            :     {
     452                 :            :         pViewShell.reset(
     453                 :            :             new ::sd::toolpanel::ToolPanelViewShell(
     454                 :            :                 &rFrame,
     455                 :            :                 *mpBase,
     456                 :            :                 &rWindow,
     457 [ +  - ][ +  - ]:         26 :                 pFrameView));
                 [ +  - ]
     458                 :            :     }
     459         [ +  - ]:        130 :     else if (rsViewURL.equals(FrameworkHelper::msSlideSorterURL))
     460                 :            :     {
     461                 :            :         pViewShell = ::sd::slidesorter::SlideSorterViewShell::Create (
     462                 :            :             &rFrame,
     463                 :            :             *mpBase,
     464                 :            :             &rWindow,
     465                 :            :             pFrameView,
     466 [ +  - ][ +  - ]:        130 :             bIsCenterPane);
                 [ +  - ]
     467                 :            :     }
     468                 :            : 
     469                 :        286 :     return pViewShell;
     470                 :            : }
     471                 :            : 
     472                 :            : 
     473                 :            : 
     474                 :            : 
     475                 :        442 : void BasicViewFactory::ReleaseView (
     476                 :            :     const ::boost::shared_ptr<ViewDescriptor>& rpDescriptor,
     477                 :            :     bool bDoNotCache)
     478                 :            : {
     479 [ +  + ][ +  + ]:        442 :     bool bIsCacheable (!bDoNotCache && IsCacheable(rpDescriptor));
     480                 :            : 
     481         [ +  + ]:        442 :     if (bIsCacheable)
     482                 :            :     {
     483         [ +  - ]:        156 :         Reference<XRelocatableResource> xResource (rpDescriptor->mxView, UNO_QUERY);
     484         [ +  - ]:        156 :         if (xResource.is())
     485                 :            :         {
     486         [ +  - ]:        156 :             Reference<XResource> xNewAnchor (mxLocalPane, UNO_QUERY);
     487         [ +  - ]:        156 :             if (xNewAnchor.is())
     488 [ +  - ][ +  - ]:        156 :                 if (xResource->relocateToAnchor(xNewAnchor))
                 [ +  - ]
     489         [ +  - ]:        156 :                     mpViewCache->push_back(rpDescriptor);
     490                 :            :                 else
     491                 :          0 :                     bIsCacheable = false;
     492                 :            :             else
     493                 :        156 :                 bIsCacheable = false;
     494                 :            :         }
     495                 :            :         else
     496                 :            :         {
     497                 :          0 :             bIsCacheable = false;
     498                 :        156 :         }
     499                 :            :     }
     500                 :            : 
     501         [ +  + ]:        442 :     if ( ! bIsCacheable)
     502                 :            :     {
     503                 :            :         // Shut down the current view shell.
     504         [ +  - ]:        286 :         rpDescriptor->mpViewShell->Shutdown ();
     505 [ +  - ][ +  - ]:        286 :         mpBase->GetDocShell()->Disconnect(rpDescriptor->mpViewShell.get());
     506 [ +  - ][ +  - ]:        286 :         mpBase->GetViewShellManager()->DeactivateViewShell(rpDescriptor->mpViewShell.get());
                 [ +  - ]
     507                 :            : 
     508         [ +  - ]:        286 :         Reference<XComponent> xComponent (rpDescriptor->mxView, UNO_QUERY);
     509         [ +  - ]:        286 :         if (xComponent.is())
     510 [ +  - ][ +  - ]:        286 :             xComponent->dispose();
     511                 :            :     }
     512                 :        442 : }
     513                 :            : 
     514                 :            : 
     515                 :            : 
     516                 :            : 
     517                 :        286 : bool BasicViewFactory::IsCacheable (const ::boost::shared_ptr<ViewDescriptor>& rpDescriptor)
     518                 :            : {
     519                 :        286 :     bool bIsCacheable (false);
     520                 :            : 
     521         [ +  - ]:        286 :     Reference<XRelocatableResource> xResource (rpDescriptor->mxView, UNO_QUERY);
     522         [ +  - ]:        286 :     if (xResource.is())
     523                 :            :     {
     524 [ +  + ][ +  - ]:        286 :         static ::std::vector<Reference<XResourceId> > maCacheableResources;
         [ +  - ][ #  # ]
     525         [ +  + ]:        286 :         if (maCacheableResources.empty() )
     526                 :            :         {
     527         [ +  - ]:         16 :             ::boost::shared_ptr<FrameworkHelper> pHelper (FrameworkHelper::Instance(*mpBase));
     528                 :            : 
     529                 :            :             // The slide sorter and the task panel are cacheable and relocatable.
     530                 :         16 :             maCacheableResources.push_back(pHelper->CreateResourceId(
     531 [ +  - ][ +  - ]:         16 :                 FrameworkHelper::msSlideSorterURL, FrameworkHelper::msLeftDrawPaneURL));
     532                 :         16 :             maCacheableResources.push_back(pHelper->CreateResourceId(
     533 [ +  - ][ +  - ]:         16 :                 FrameworkHelper::msSlideSorterURL, FrameworkHelper::msLeftImpressPaneURL));
     534                 :         16 :             maCacheableResources.push_back(pHelper->CreateResourceId(
     535 [ +  - ][ +  - ]:         16 :                 FrameworkHelper::msTaskPaneURL, FrameworkHelper::msRightPaneURL));
                 [ +  - ]
     536                 :            :         }
     537                 :            : 
     538                 :        286 :         ::std::vector<Reference<XResourceId> >::const_iterator iId;
     539 [ +  - ][ +  - ]:        910 :         for (iId=maCacheableResources.begin(); iId!=maCacheableResources.end(); ++iId)
                 [ +  + ]
     540                 :            :         {
     541 [ +  - ][ +  - ]:        624 :             if ((*iId)->compareTo(rpDescriptor->mxViewId) == 0)
                 [ +  + ]
     542                 :            :             {
     543                 :        156 :                 bIsCacheable = true;
     544                 :        156 :                 break;
     545                 :            :             }
     546                 :            :         }
     547                 :            :     }
     548                 :            : 
     549                 :        286 :     return bIsCacheable;
     550                 :            : }
     551                 :            : 
     552                 :            : 
     553                 :            : 
     554                 :            : 
     555                 :        286 : ::boost::shared_ptr<BasicViewFactory::ViewDescriptor> BasicViewFactory::GetViewFromCache (
     556                 :            :     const Reference<XResourceId>& rxViewId,
     557                 :            :     const Reference<XPane>& rxPane)
     558                 :            : {
     559         [ +  - ]:        286 :     ::boost::shared_ptr<ViewDescriptor> pDescriptor;
     560                 :            : 
     561                 :            :     // Search for the requested view in the cache.
     562                 :        286 :     ViewCache::iterator iEntry;
     563 [ +  - ][ -  + ]:        286 :     for (iEntry=mpViewCache->begin(); iEntry!=mpViewCache->end(); ++iEntry)
     564                 :            :     {
     565 [ #  # ][ #  # ]:          0 :         if ((*iEntry)->mxViewId->compareTo(rxViewId) == 0)
                 [ #  # ]
     566                 :            :         {
     567         [ #  # ]:          0 :             pDescriptor = *iEntry;
     568         [ #  # ]:          0 :             mpViewCache->erase(iEntry);
     569                 :          0 :             break;
     570                 :            :         }
     571                 :            :     }
     572                 :            : 
     573                 :            :     // When the view has been found then relocate it to the given pane and
     574                 :            :     // remove it from the cache.
     575         [ -  + ]:        286 :     if (pDescriptor.get() != NULL)
     576                 :            :     {
     577                 :          0 :         bool bRelocationSuccessfull (false);
     578         [ #  # ]:          0 :         Reference<XRelocatableResource> xResource (pDescriptor->mxView, UNO_QUERY);
     579         [ #  # ]:          0 :         Reference<XResource> xNewAnchor (rxPane, UNO_QUERY);
     580 [ #  # ][ #  # ]:          0 :         if (xResource.is() && xNewAnchor.is())
                 [ #  # ]
     581                 :            :         {
     582 [ #  # ][ #  # ]:          0 :             if (xResource->relocateToAnchor(xNewAnchor))
                 [ #  # ]
     583                 :          0 :                 bRelocationSuccessfull = true;
     584                 :            :         }
     585                 :            : 
     586         [ #  # ]:          0 :         if ( ! bRelocationSuccessfull)
     587                 :            :         {
     588         [ #  # ]:          0 :             ReleaseView(pDescriptor, true);
     589         [ #  # ]:          0 :             pDescriptor.reset();
     590                 :        286 :         }
     591                 :            :     }
     592                 :            : 
     593                 :        286 :     return pDescriptor;
     594                 :            : }
     595                 :            : 
     596                 :            : 
     597                 :            : 
     598                 :            : 
     599                 :        130 : void BasicViewFactory::ActivateCenterView (
     600                 :            :     const ::boost::shared_ptr<ViewDescriptor>& rpDescriptor)
     601                 :            : {
     602                 :        130 :     mpBase->GetDocShell()->Connect(rpDescriptor->mpViewShell.get());
     603                 :            : 
     604                 :            :     // During the creation of the new sub-shell, resize requests were not
     605                 :            :     // forwarded to it because it was not yet registered.  Therefore, we
     606                 :            :     // have to request a resize now.
     607                 :        130 :     rpDescriptor->mpViewShell->UIFeatureChanged();
     608         [ -  + ]:        130 :     if (mpBase->GetDocShell()->IsInPlaceActive())
     609                 :          0 :         mpBase->GetViewFrame()->Resize(sal_True);
     610                 :            : 
     611         [ +  - ]:        130 :     mpBase->GetDrawController().SetSubController(
     612         [ +  - ]:        260 :         rpDescriptor->mpViewShell->CreateSubController());
     613                 :        130 : }
     614                 :            : 
     615 [ +  - ][ +  - ]:         75 : } } // end of namespace sd::framework
     616                 :            : 
     617                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10