LCOV - code coverage report
Current view: top level - libreoffice/sdext/source/presenter - PresenterPaneFactory.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 0 145 0.0 %
Date: 2012-12-27 Functions: 0 13 0.0 %
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             : #include "PresenterPaneFactory.hxx"
      21             : #include "PresenterController.hxx"
      22             : #include "PresenterPane.hxx"
      23             : #include "PresenterPaneBorderPainter.hxx"
      24             : #include "PresenterPaneContainer.hxx"
      25             : #include "PresenterSpritePane.hxx"
      26             : #include <com/sun/star/container/XChild.hpp>
      27             : #include <com/sun/star/drawing/framework/ResourceId.hpp>
      28             : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
      29             : #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
      30             : #include <com/sun/star/frame/XController.hpp>
      31             : #include <com/sun/star/lang/XComponent.hpp>
      32             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      33             : #include <boost/bind.hpp>
      34             : 
      35             : using namespace ::com::sun::star;
      36             : using namespace ::com::sun::star::uno;
      37             : using namespace ::com::sun::star::lang;
      38             : using namespace ::com::sun::star::drawing::framework;
      39             : using ::rtl::OUString;
      40             : 
      41             : namespace sdext { namespace presenter {
      42             : 
      43           0 : const ::rtl::OUString PresenterPaneFactory::msCurrentSlidePreviewPaneURL(
      44           0 :     "private:resource/pane/Presenter/Pane1");
      45           0 : const ::rtl::OUString PresenterPaneFactory::msNextSlidePreviewPaneURL(
      46           0 :     "private:resource/pane/Presenter/Pane2");
      47           0 : const ::rtl::OUString PresenterPaneFactory::msNotesPaneURL(
      48           0 :     "private:resource/pane/Presenter/Pane3");
      49           0 : const ::rtl::OUString PresenterPaneFactory::msToolBarPaneURL(
      50           0 :     "private:resource/pane/Presenter/Pane4");
      51           0 : const ::rtl::OUString PresenterPaneFactory::msSlideSorterPaneURL(
      52           0 :     "private:resource/pane/Presenter/Pane5");
      53           0 : const ::rtl::OUString PresenterPaneFactory::msHelpPaneURL(
      54           0 :     "private:resource/pane/Presenter/Pane6");
      55             : 
      56           0 : const ::rtl::OUString PresenterPaneFactory::msOverlayPaneURL(
      57           0 :     "private:resource/pane/Presenter/Overlay");
      58             : 
      59             : //===== PresenterPaneFactory ==================================================
      60             : 
      61           0 : Reference<drawing::framework::XResourceFactory> PresenterPaneFactory::Create (
      62             :     const Reference<uno::XComponentContext>& rxContext,
      63             :     const Reference<frame::XController>& rxController,
      64             :     const ::rtl::Reference<PresenterController>& rpPresenterController)
      65             : {
      66             :     rtl::Reference<PresenterPaneFactory> pFactory (
      67           0 :         new PresenterPaneFactory(rxContext,rpPresenterController));
      68           0 :     pFactory->Register(rxController);
      69             :     return Reference<drawing::framework::XResourceFactory>(
      70           0 :         static_cast<XWeak*>(pFactory.get()), UNO_QUERY);
      71             : }
      72             : 
      73           0 : PresenterPaneFactory::PresenterPaneFactory (
      74             :     const Reference<uno::XComponentContext>& rxContext,
      75             :     const ::rtl::Reference<PresenterController>& rpPresenterController)
      76             :     : PresenterPaneFactoryInterfaceBase(m_aMutex),
      77             :       mxComponentContextWeak(rxContext),
      78             :       mxConfigurationControllerWeak(),
      79             :       mpPresenterController(rpPresenterController),
      80           0 :       mpResourceCache()
      81             : {
      82           0 : }
      83             : 
      84           0 : void PresenterPaneFactory::Register (const Reference<frame::XController>& rxController)
      85             : {
      86           0 :     Reference<XConfigurationController> xCC;
      87             :     try
      88             :     {
      89             :         // Get the configuration controller.
      90           0 :         Reference<XControllerManager> xCM (rxController, UNO_QUERY_THROW);
      91           0 :         xCC = Reference<XConfigurationController>(xCM->getConfigurationController());
      92           0 :         mxConfigurationControllerWeak = xCC;
      93           0 :         if ( ! xCC.is())
      94             :         {
      95           0 :             throw RuntimeException();
      96             :         }
      97             :         else
      98             :         {
      99           0 :             xCC->addResourceFactory(
     100             :                 OUString("private:resource/pane/Presenter/*"),
     101           0 :                 this);
     102           0 :         }
     103             :     }
     104           0 :     catch (RuntimeException&)
     105             :     {
     106             :         OSL_ASSERT(false);
     107           0 :         if (xCC.is())
     108           0 :             xCC->removeResourceFactoryForReference(this);
     109           0 :         mxConfigurationControllerWeak = WeakReference<XConfigurationController>();
     110             : 
     111           0 :         throw;
     112           0 :     }
     113           0 : }
     114             : 
     115           0 : PresenterPaneFactory::~PresenterPaneFactory (void)
     116             : {
     117           0 : }
     118             : 
     119           0 : void SAL_CALL PresenterPaneFactory::disposing (void)
     120             :     throw (RuntimeException)
     121             : {
     122           0 :     Reference<XConfigurationController> xCC (mxConfigurationControllerWeak);
     123           0 :     if (xCC.is())
     124           0 :         xCC->removeResourceFactoryForReference(this);
     125           0 :     mxConfigurationControllerWeak = WeakReference<XConfigurationController>();
     126             : 
     127             :     // Dispose the panes in the cache.
     128           0 :     if (mpResourceCache.get() != NULL)
     129             :     {
     130           0 :         ResourceContainer::const_iterator iPane (mpResourceCache->begin());
     131           0 :         ResourceContainer::const_iterator iEnd (mpResourceCache->end());
     132           0 :         for ( ; iPane!=iEnd; ++iPane)
     133             :         {
     134           0 :             Reference<lang::XComponent> xPaneComponent (iPane->second, UNO_QUERY);
     135           0 :             if (xPaneComponent.is())
     136           0 :                 xPaneComponent->dispose();
     137           0 :         }
     138           0 :         mpResourceCache.reset();
     139           0 :     }
     140           0 : }
     141             : 
     142             : //----- XPaneFactory ----------------------------------------------------------
     143             : 
     144           0 : Reference<XResource> SAL_CALL PresenterPaneFactory::createResource (
     145             :     const Reference<XResourceId>& rxPaneId)
     146             :     throw (RuntimeException, IllegalArgumentException, WrappedTargetException)
     147             : {
     148           0 :     ThrowIfDisposed();
     149             : 
     150           0 :     if ( ! rxPaneId.is())
     151           0 :         return NULL;
     152             : 
     153           0 :     const OUString sPaneURL (rxPaneId->getResourceURL());
     154           0 :     if (sPaneURL.isEmpty())
     155           0 :         return NULL;
     156             : 
     157           0 :     if (mpResourceCache.get() != NULL)
     158             :     {
     159             :         // Has the requested resource already been created?
     160           0 :         ResourceContainer::const_iterator iResource (mpResourceCache->find(sPaneURL));
     161           0 :         if (iResource != mpResourceCache->end())
     162             :         {
     163             :             // Yes.  Mark it as active.
     164             :             rtl::Reference<PresenterPaneContainer> pPaneContainer(
     165           0 :                 mpPresenterController->GetPaneContainer());
     166             :             PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
     167           0 :                 pPaneContainer->FindPaneURL(sPaneURL));
     168           0 :             if (pDescriptor.get() != NULL)
     169             :             {
     170           0 :                 pDescriptor->SetActivationState(true);
     171           0 :                 if (pDescriptor->mxBorderWindow.is())
     172           0 :                     pDescriptor->mxBorderWindow->setVisible(sal_True);
     173           0 :                 pPaneContainer->StorePane(pDescriptor->mxPane);
     174             :             }
     175             : 
     176           0 :             return iResource->second;
     177             :         }
     178             :     }
     179             : 
     180             :     // No.  Create a new one.
     181           0 :     Reference<XResource> xResource = CreatePane(rxPaneId, OUString());
     182           0 :     return xResource;
     183             : }
     184             : 
     185           0 : void SAL_CALL PresenterPaneFactory::releaseResource (const Reference<XResource>& rxResource)
     186             :     throw (RuntimeException)
     187             : {
     188           0 :     ThrowIfDisposed();
     189             : 
     190           0 :     if ( ! rxResource.is())
     191           0 :         throw lang::IllegalArgumentException();
     192             : 
     193             :     // Mark the pane as inactive.
     194             :     rtl::Reference<PresenterPaneContainer> pPaneContainer(
     195           0 :         mpPresenterController->GetPaneContainer());
     196           0 :     const OUString sPaneURL (rxResource->getResourceId()->getResourceURL());
     197             :     PresenterPaneContainer::SharedPaneDescriptor pDescriptor (
     198           0 :         pPaneContainer->FindPaneURL(sPaneURL));
     199           0 :     if (pDescriptor.get() != NULL)
     200             :     {
     201           0 :         pDescriptor->SetActivationState(false);
     202           0 :         if (pDescriptor->mxBorderWindow.is())
     203           0 :             pDescriptor->mxBorderWindow->setVisible(sal_False);
     204             : 
     205           0 :         if (mpResourceCache.get() != NULL)
     206             :         {
     207             :             // Store the pane in the cache.
     208           0 :             (*mpResourceCache)[sPaneURL] = rxResource;
     209             :         }
     210             :         else
     211             :         {
     212             :             // Dispose the pane.
     213           0 :             Reference<lang::XComponent> xPaneComponent (rxResource, UNO_QUERY);
     214           0 :             if (xPaneComponent.is())
     215           0 :                 xPaneComponent->dispose();
     216             :         }
     217           0 :     }
     218           0 : }
     219             : 
     220             : //-----------------------------------------------------------------------------
     221             : 
     222           0 : Reference<XResource> PresenterPaneFactory::CreatePane (
     223             :     const Reference<XResourceId>& rxPaneId,
     224             :     const OUString& rsTitle)
     225             : {
     226           0 :     if ( ! rxPaneId.is())
     227           0 :         return NULL;
     228             : 
     229           0 :     Reference<XConfigurationController> xCC (mxConfigurationControllerWeak);
     230           0 :     if ( ! xCC.is())
     231           0 :         return NULL;
     232             : 
     233           0 :     Reference<XComponentContext> xContext (mxComponentContextWeak);
     234           0 :     if ( ! xContext.is())
     235           0 :         return NULL;
     236             : 
     237           0 :     Reference<XPane> xParentPane (xCC->getResource(rxPaneId->getAnchor()), UNO_QUERY);
     238           0 :     if ( ! xParentPane.is())
     239           0 :         return NULL;
     240             : 
     241             :     try
     242             :     {
     243             :         return CreatePane(
     244             :             rxPaneId,
     245             :             rsTitle,
     246             :             xParentPane,
     247           0 :             rxPaneId->getFullResourceURL().Arguments.compareToAscii("Sprite=1") == 0);
     248             :     }
     249           0 :     catch (Exception&)
     250             :     {
     251             :         OSL_ASSERT(false);
     252             :     }
     253             : 
     254           0 :     return NULL;
     255             : }
     256             : 
     257           0 : Reference<XResource> PresenterPaneFactory::CreatePane (
     258             :     const Reference<XResourceId>& rxPaneId,
     259             :     const OUString& rsTitle,
     260             :     const Reference<drawing::framework::XPane>& rxParentPane,
     261             :     const bool bIsSpritePane)
     262             : {
     263           0 :     Reference<XComponentContext> xContext (mxComponentContextWeak);
     264             :     Reference<lang::XMultiComponentFactory> xFactory (
     265           0 :         xContext->getServiceManager(), UNO_QUERY_THROW);
     266             : 
     267             :     // Create a border window and canvas and store it in the pane
     268             :     // container.
     269             : 
     270             :     // Create the pane.
     271           0 :     ::rtl::Reference<PresenterPaneBase> xPane;
     272           0 :     if (bIsSpritePane)
     273             :     {
     274             :         xPane = ::rtl::Reference<PresenterPaneBase>(
     275           0 :             new PresenterSpritePane(xContext, mpPresenterController));
     276             :     }
     277             :     else
     278             :     {
     279             :         xPane = ::rtl::Reference<PresenterPaneBase>(
     280           0 :             new PresenterPane(xContext, mpPresenterController));
     281             :     }
     282             : 
     283             :     // Supply arguments.
     284           0 :     Sequence<Any> aArguments (6);
     285           0 :     aArguments[0] <<= rxPaneId;
     286           0 :     aArguments[1] <<= rxParentPane->getWindow();
     287           0 :     aArguments[2] <<= rxParentPane->getCanvas();
     288           0 :     aArguments[3] <<= rsTitle;
     289           0 :     aArguments[4] <<= Reference<drawing::framework::XPaneBorderPainter>(
     290           0 :         static_cast<XWeak*>(mpPresenterController->GetPaneBorderPainter().get()),
     291           0 :         UNO_QUERY);
     292           0 :     aArguments[5] <<= bIsSpritePane ? false : true;
     293           0 :     xPane->initialize(aArguments);
     294             : 
     295             :     // Store pane and canvases and windows in container.
     296             :     ::rtl::Reference<PresenterPaneContainer> pContainer (
     297           0 :         mpPresenterController->GetPaneContainer());
     298             :     PresenterPaneContainer::SharedPaneDescriptor pDescriptor(
     299           0 :         pContainer->StoreBorderWindow(rxPaneId, xPane->GetBorderWindow()));
     300           0 :     pContainer->StorePane(xPane);
     301           0 :     if (pDescriptor.get() != NULL)
     302             :     {
     303           0 :         if (bIsSpritePane)
     304             :         {
     305           0 :             pDescriptor->maSpriteProvider = ::boost::bind(
     306             :                 &PresenterSpritePane::GetSprite,
     307           0 :                 dynamic_cast<PresenterSpritePane*>(xPane.get()));
     308           0 :             pDescriptor->mbIsSprite = true;
     309           0 :             pDescriptor->mbNeedsClipping = false;
     310             :         }
     311             :         else
     312             :         {
     313           0 :             pDescriptor->mbIsSprite = false;
     314           0 :             pDescriptor->mbNeedsClipping = true;
     315             :         }
     316             : 
     317             :         // Get the window of the frame and make that visible.
     318           0 :         Reference<awt::XWindow> xWindow (pDescriptor->mxBorderWindow, UNO_QUERY_THROW);
     319           0 :         xWindow->setVisible(sal_True);
     320             :     }
     321             : 
     322           0 :     return Reference<XResource>(static_cast<XWeak*>(xPane.get()), UNO_QUERY_THROW);
     323             : }
     324             : 
     325           0 : void PresenterPaneFactory::ThrowIfDisposed (void) const
     326             :     throw (::com::sun::star::lang::DisposedException)
     327             : {
     328           0 :     if (rBHelper.bDisposed || rBHelper.bInDispose)
     329             :     {
     330             :         throw lang::DisposedException (
     331             :             OUString( "PresenterPaneFactory object has already been disposed"),
     332           0 :             const_cast<uno::XWeak*>(static_cast<const uno::XWeak*>(this)));
     333             :     }
     334           0 : }
     335             : 
     336           0 : } } // end of namespace sdext::presenter
     337             : 
     338             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10