LCOV - code coverage report
Current view: top level - sdext/source/presenter - PresenterPaneContainer.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 194 0.0 %
Date: 2014-04-14 Functions: 0 19 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 "PresenterPaneContainer.hxx"
      21             : #include "PresenterPaneBase.hxx"
      22             : #include <com/sun/star/awt/XGraphics.hpp>
      23             : #include <com/sun/star/beans/XPropertySet.hpp>
      24             : #include <com/sun/star/container/XChild.hpp>
      25             : #include <com/sun/star/drawing/framework/ResourceId.hpp>
      26             : 
      27             : using namespace ::com::sun::star;
      28             : using namespace ::com::sun::star::uno;
      29             : using namespace ::com::sun::star::drawing::framework;
      30             : 
      31             : namespace sdext { namespace presenter {
      32             : 
      33           0 : PresenterPaneContainer::PresenterPaneContainer (
      34             :     const Reference<XComponentContext>& rxContext)
      35             :     : PresenterPaneContainerInterfaceBase(m_aMutex),
      36             :       maPanes(),
      37           0 :       mxPresenterHelper()
      38             : {
      39           0 :     Reference<lang::XMultiComponentFactory> xFactory (rxContext->getServiceManager());
      40           0 :     if (xFactory.is())
      41             :     {
      42           0 :         mxPresenterHelper = Reference<drawing::XPresenterHelper>(
      43           0 :             xFactory->createInstanceWithContext(
      44             :                 OUString("com.sun.star.comp.Draw.PresenterHelper"),
      45           0 :                 rxContext),
      46           0 :             UNO_QUERY_THROW);
      47           0 :     }
      48           0 : }
      49             : 
      50           0 : PresenterPaneContainer::~PresenterPaneContainer (void)
      51             : {
      52           0 : }
      53             : 
      54           0 : void PresenterPaneContainer::PreparePane (
      55             :     const Reference<XResourceId>& rxPaneId,
      56             :     const OUString& rsViewURL,
      57             :     const OUString& rsTitle,
      58             :     const OUString& rsAccessibleTitle,
      59             :     const bool bIsOpaque,
      60             :     const ViewInitializationFunction& rViewInitialization,
      61             :     const double nLeft,
      62             :     const double nTop,
      63             :     const double nRight,
      64             :     const double nBottom)
      65             : {
      66           0 :     if ( ! rxPaneId.is())
      67           0 :         return;
      68             : 
      69           0 :     SharedPaneDescriptor pPane (FindPaneURL(rxPaneId->getResourceURL()));
      70           0 :     if (pPane.get() == NULL)
      71             :     {
      72             :         // No entry found for the given pane id.  Create a new one.
      73           0 :         SharedPaneDescriptor pDescriptor (new PaneDescriptor());
      74           0 :         pDescriptor->mxPaneId = rxPaneId;
      75           0 :         pDescriptor->msViewURL = rsViewURL;
      76           0 :         pDescriptor->mxPane = NULL;
      77           0 :         if (rsTitle.indexOf('%') < 0)
      78             :         {
      79           0 :             pDescriptor->msTitle = rsTitle;
      80           0 :             pDescriptor->msTitleTemplate = OUString();
      81             :         }
      82             :         else
      83             :         {
      84           0 :             pDescriptor->msTitleTemplate = rsTitle;
      85           0 :             pDescriptor->msTitle = OUString();
      86             :         }
      87           0 :         pDescriptor->msAccessibleTitleTemplate = rsAccessibleTitle;
      88           0 :         pDescriptor->maViewInitialization = rViewInitialization;
      89           0 :         pDescriptor->mnLeft = nLeft;
      90           0 :         pDescriptor->mnTop = nTop;
      91           0 :         pDescriptor->mnRight = nRight;
      92           0 :         pDescriptor->mnBottom = nBottom;
      93           0 :         pDescriptor->mbIsActive = true;
      94           0 :         pDescriptor->mbIsOpaque = bIsOpaque;
      95           0 :         pDescriptor->maSpriteProvider = PaneDescriptor::SpriteProvider();
      96           0 :         pDescriptor->mbIsSprite = false;
      97           0 :         pDescriptor->maCalloutAnchorLocation = awt::Point(-1,-1);
      98           0 :         pDescriptor->mbHasCalloutAnchor = false;
      99             : 
     100           0 :         maPanes.push_back(pDescriptor);
     101           0 :     }
     102             : }
     103             : 
     104           0 : void SAL_CALL PresenterPaneContainer::disposing (void)
     105             : {
     106           0 :     PaneList::iterator iPane (maPanes.begin());
     107           0 :     PaneList::const_iterator iEnd (maPanes.end());
     108           0 :     for ( ; iPane!=iEnd; ++iPane)
     109           0 :         if ((*iPane)->mxPaneId.is())
     110           0 :             RemovePane((*iPane)->mxPaneId);
     111           0 : }
     112             : 
     113             : PresenterPaneContainer::SharedPaneDescriptor
     114           0 :     PresenterPaneContainer::StorePane (const rtl::Reference<PresenterPaneBase>& rxPane)
     115             : {
     116           0 :     SharedPaneDescriptor pDescriptor;
     117             : 
     118           0 :     if (rxPane.is())
     119             :     {
     120           0 :         OUString sPaneURL;
     121           0 :         Reference<XResourceId> xPaneId (rxPane->getResourceId());
     122           0 :         if (xPaneId.is())
     123           0 :             sPaneURL = xPaneId->getResourceURL();
     124             : 
     125           0 :         pDescriptor = FindPaneURL(sPaneURL);
     126           0 :         if (pDescriptor.get() == NULL)
     127             :             PreparePane(xPaneId, OUString(), OUString(), OUString(),
     128           0 :                 false, ViewInitializationFunction(), 0,0,0,0);
     129           0 :         pDescriptor = FindPaneURL(sPaneURL);
     130           0 :         if (pDescriptor.get() != NULL)
     131             :         {
     132           0 :             Reference<awt::XWindow> xWindow (rxPane->getWindow());
     133           0 :             pDescriptor->mxContentWindow = xWindow;
     134           0 :             pDescriptor->mxPaneId = xPaneId;
     135           0 :             pDescriptor->mxPane = rxPane;
     136           0 :             pDescriptor->mxPane->SetTitle(pDescriptor->msTitle);
     137             : 
     138             :             // When there is a call out anchor location set then tell the
     139             :             // window about it.
     140           0 :             if (pDescriptor->mbHasCalloutAnchor)
     141           0 :                 pDescriptor->mxPane->SetCalloutAnchor(pDescriptor->maCalloutAnchorLocation);
     142             : 
     143           0 :             if (xWindow.is())
     144           0 :                 xWindow->addEventListener(this);
     145           0 :         }
     146             :     }
     147             : 
     148           0 :     return pDescriptor;
     149             : }
     150             : 
     151             : PresenterPaneContainer::SharedPaneDescriptor
     152           0 :     PresenterPaneContainer::StoreBorderWindow(
     153             :         const Reference<XResourceId>& rxPaneId,
     154             :         const Reference<awt::XWindow>& rxBorderWindow)
     155             : {
     156             :     // The content window may not be present.  Use the resource URL of the
     157             :     // pane id as key.
     158           0 :     OUString sPaneURL;
     159           0 :     if (rxPaneId.is())
     160           0 :         sPaneURL = rxPaneId->getResourceURL();
     161             : 
     162           0 :     SharedPaneDescriptor pDescriptor (FindPaneURL(sPaneURL));
     163           0 :     if (pDescriptor.get() != NULL)
     164             :     {
     165           0 :         pDescriptor->mxBorderWindow = rxBorderWindow;
     166           0 :         return pDescriptor;
     167             :     }
     168             :     else
     169           0 :         return SharedPaneDescriptor();
     170             : }
     171             : 
     172             : PresenterPaneContainer::SharedPaneDescriptor
     173           0 :     PresenterPaneContainer::StoreView (
     174             :         const Reference<XView>& rxView,
     175             :         const SharedBitmapDescriptor& rpViewBackground)
     176             : {
     177           0 :     SharedPaneDescriptor pDescriptor;
     178             : 
     179           0 :     if (rxView.is())
     180             :     {
     181           0 :         OUString sPaneURL;
     182           0 :         Reference<XResourceId> xViewId (rxView->getResourceId());
     183           0 :         if (xViewId.is())
     184             :         {
     185           0 :             Reference<XResourceId> xPaneId (xViewId->getAnchor());
     186           0 :             if (xPaneId.is())
     187           0 :                 sPaneURL = xPaneId->getResourceURL();
     188             :         }
     189             : 
     190           0 :         pDescriptor = FindPaneURL(sPaneURL);
     191           0 :         if (pDescriptor.get() != NULL)
     192             :         {
     193           0 :             pDescriptor->mxView = rxView;
     194           0 :             pDescriptor->mpViewBackground = rpViewBackground;
     195           0 :             if (pDescriptor->mxPane.is())
     196           0 :                 pDescriptor->mxPane->SetBackground(rpViewBackground);
     197             :             try
     198             :             {
     199           0 :                 if ( ! pDescriptor->maViewInitialization.empty())
     200           0 :                     pDescriptor->maViewInitialization(rxView);
     201             : 
     202             :                 // Activate or deactivate the pane/view.
     203           0 :                 if ( ! pDescriptor->maActivator.empty())
     204           0 :                     pDescriptor->maActivator(pDescriptor->mbIsActive);
     205             :             }
     206           0 :             catch (RuntimeException&)
     207             :             {
     208             :                 OSL_ASSERT(false);
     209             :             }
     210           0 :         }
     211             :     }
     212             : 
     213           0 :     return pDescriptor;
     214             : }
     215             : 
     216             : PresenterPaneContainer::SharedPaneDescriptor
     217           0 :     PresenterPaneContainer::RemovePane (const Reference<XResourceId>& rxPaneId)
     218             : {
     219           0 :     SharedPaneDescriptor pDescriptor (FindPaneId(rxPaneId));
     220           0 :     if (pDescriptor.get() != NULL)
     221             :     {
     222           0 :         if (pDescriptor->mxContentWindow.is())
     223           0 :             pDescriptor->mxContentWindow->removeEventListener(this);
     224           0 :         pDescriptor->mxContentWindow = NULL;
     225           0 :         pDescriptor->mxBorderWindow = NULL;
     226           0 :         pDescriptor->mxPane = NULL;
     227           0 :         pDescriptor->mxView = NULL;
     228           0 :         pDescriptor->mbIsActive = false;
     229             :     }
     230           0 :     return pDescriptor;
     231             : }
     232             : 
     233             : PresenterPaneContainer::SharedPaneDescriptor
     234           0 :     PresenterPaneContainer::RemoveView (const Reference<XView>& rxView)
     235             : {
     236           0 :     SharedPaneDescriptor pDescriptor;
     237             : 
     238           0 :     if (rxView.is())
     239             :     {
     240           0 :         OUString sPaneURL;
     241           0 :         Reference<XResourceId> xViewId (rxView->getResourceId());
     242           0 :         if (xViewId.is())
     243             :         {
     244           0 :             Reference<XResourceId> xPaneId (xViewId->getAnchor());
     245           0 :             if (xPaneId.is())
     246           0 :                 sPaneURL = xPaneId->getResourceURL();
     247             :         }
     248             : 
     249           0 :         pDescriptor = FindPaneURL(sPaneURL);
     250           0 :         if (pDescriptor.get() != NULL)
     251             :         {
     252           0 :             pDescriptor->mxView = NULL;
     253           0 :             pDescriptor->mpViewBackground = SharedBitmapDescriptor();
     254           0 :         }
     255             :     }
     256             : 
     257           0 :     return pDescriptor;
     258             : }
     259             : 
     260           0 : PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindBorderWindow (
     261             :     const Reference<awt::XWindow>& rxBorderWindow)
     262             : {
     263           0 :     PaneList::const_iterator iPane;
     264           0 :     PaneList::iterator iEnd (maPanes.end());
     265           0 :     for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
     266             :     {
     267           0 :         if ((*iPane)->mxBorderWindow == rxBorderWindow)
     268           0 :             return *iPane;
     269             :     }
     270           0 :     return SharedPaneDescriptor();
     271             : }
     272             : 
     273           0 : PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindContentWindow (
     274             :     const Reference<awt::XWindow>& rxContentWindow)
     275             : {
     276           0 :     PaneList::const_iterator iPane;
     277           0 :     PaneList::iterator iEnd (maPanes.end());
     278           0 :     for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
     279             :     {
     280           0 :         if ((*iPane)->mxContentWindow == rxContentWindow)
     281           0 :             return *iPane;
     282             :     }
     283           0 :     return SharedPaneDescriptor();
     284             : }
     285             : 
     286           0 : PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindPaneURL (
     287             :     const OUString& rsPaneURL)
     288             : {
     289           0 :     PaneList::const_iterator iPane;
     290           0 :     PaneList::const_iterator iEnd (maPanes.end());
     291           0 :     for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
     292             :     {
     293           0 :         if ((*iPane)->mxPaneId->getResourceURL() == rsPaneURL)
     294           0 :             return *iPane;
     295             :     }
     296           0 :     return SharedPaneDescriptor();
     297             : }
     298             : 
     299           0 : PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindPaneId (
     300             :     const Reference<XResourceId>& rxPaneId)
     301             : {
     302           0 :     PaneList::iterator iEnd (maPanes.end());
     303             : 
     304           0 :     if ( ! rxPaneId.is())
     305           0 :         return SharedPaneDescriptor();
     306             : 
     307           0 :     PaneList::iterator iPane;
     308           0 :     for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
     309             :     {
     310           0 :         if (rxPaneId->compareTo((*iPane)->mxPaneId) == 0)
     311           0 :             return *iPane;
     312             :     }
     313           0 :     return SharedPaneDescriptor();
     314             : }
     315             : 
     316           0 : PresenterPaneContainer::SharedPaneDescriptor PresenterPaneContainer::FindViewURL (
     317             :     const OUString& rsViewURL)
     318             : {
     319           0 :     PaneList::iterator iEnd (maPanes.end());
     320           0 :     PaneList::iterator iPane;
     321           0 :     for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
     322             :     {
     323           0 :         if (rsViewURL == (*iPane)->msViewURL)
     324           0 :             return *iPane;
     325             :     }
     326           0 :     return SharedPaneDescriptor();
     327             : }
     328             : 
     329           0 : OUString PresenterPaneContainer::GetPaneURLForViewURL (const OUString& rsViewURL)
     330             : {
     331           0 :     SharedPaneDescriptor pDescriptor (FindViewURL(rsViewURL));
     332           0 :     if (pDescriptor.get() != NULL)
     333           0 :         if (pDescriptor->mxPaneId.is())
     334           0 :             return pDescriptor->mxPaneId->getResourceURL();
     335           0 :     return OUString();
     336             : }
     337             : 
     338           0 : void PresenterPaneContainer::ToTop (const SharedPaneDescriptor& rpDescriptor)
     339             : {
     340           0 :     if (rpDescriptor.get() != NULL)
     341             :     {
     342             :         // Find iterator for pDescriptor.
     343           0 :         PaneList::iterator iPane;
     344           0 :         PaneList::iterator iEnd (maPanes.end());
     345           0 :         for (iPane=maPanes.begin(); iPane!=iEnd; ++iPane)
     346           0 :             if (iPane->get() == rpDescriptor.get())
     347           0 :                 break;
     348             :         OSL_ASSERT(iPane!=iEnd);
     349           0 :         if (iPane == iEnd)
     350           0 :             return;
     351             : 
     352           0 :         if (mxPresenterHelper.is())
     353           0 :             mxPresenterHelper->toTop(rpDescriptor->mxBorderWindow);
     354             : 
     355           0 :         maPanes.erase(iPane);
     356           0 :         maPanes.push_back(rpDescriptor);
     357             :     }
     358             : }
     359             : 
     360             : //----- XEventListener --------------------------------------------------------
     361             : 
     362           0 : void SAL_CALL PresenterPaneContainer::disposing (
     363             :     const com::sun::star::lang::EventObject& rEvent)
     364             :     throw (com::sun::star::uno::RuntimeException, std::exception)
     365             : {
     366             :     SharedPaneDescriptor pDescriptor (
     367           0 :         FindContentWindow(Reference<awt::XWindow>(rEvent.Source, UNO_QUERY)));
     368           0 :     if (pDescriptor.get() != NULL)
     369             :     {
     370           0 :         RemovePane(pDescriptor->mxPaneId);
     371           0 :     }
     372           0 : }
     373             : 
     374             : //===== PresenterPaneContainer::PaneDescriptor ================================
     375             : 
     376           0 : void PresenterPaneContainer::PaneDescriptor::SetActivationState (const bool bIsActive)
     377             : {
     378           0 :     mbIsActive = bIsActive;
     379           0 :     if ( ! maActivator.empty())
     380           0 :         maActivator(mbIsActive);
     381           0 : }
     382             : 
     383             : } } // end of namespace ::sdext::presenter
     384             : 
     385             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10