LCOV - code coverage report
Current view: top level - sdext/source/presenter - PresenterBitmapContainer.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 151 0.0 %
Date: 2014-04-14 Functions: 0 17 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 "PresenterBitmapContainer.hxx"
      21             : #include "PresenterConfigurationAccess.hxx"
      22             : 
      23             : #include <com/sun/star/deployment/XPackageInformationProvider.hpp>
      24             : #include <com/sun/star/drawing/XPresenterHelper.hpp>
      25             : #include <com/sun/star/lang/XMultiComponentFactory.hpp>
      26             : #include <com/sun/star/rendering/CompositeOperation.hpp>
      27             : #include <com/sun/star/rendering/XIntegerBitmap.hpp>
      28             : #include <boost/bind.hpp>
      29             : 
      30             : using namespace ::com::sun::star;
      31             : using namespace ::com::sun::star::uno;
      32             : using namespace ::std;
      33             : 
      34             : namespace sdext { namespace presenter {
      35             : 
      36             : //===== PresenterBitmapContainer ==============================================
      37             : 
      38           0 : PresenterBitmapContainer::PresenterBitmapContainer (
      39             :     const OUString& rsConfigurationBase,
      40             :     const ::boost::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
      41             :     const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
      42             :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
      43             :     const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper)
      44             :     : mpParentContainer(rpParentContainer),
      45             :       maIconContainer(),
      46             :       mxCanvas(rxCanvas),
      47           0 :       mxPresenterHelper(rxPresenterHelper)
      48             : {
      49           0 :     Initialize(rxComponentContext);
      50             : 
      51             :     // Get access to the configuration.
      52             :     PresenterConfigurationAccess aConfiguration (
      53             :         rxComponentContext,
      54             :         "org.openoffice.Office.PresenterScreen",
      55           0 :         PresenterConfigurationAccess::READ_ONLY);
      56             :     Reference<container::XNameAccess> xBitmapList (
      57             :         aConfiguration.GetConfigurationNode(rsConfigurationBase),
      58           0 :         UNO_QUERY_THROW);
      59             : 
      60           0 :     LoadBitmaps(xBitmapList);
      61           0 : }
      62             : 
      63           0 : PresenterBitmapContainer::PresenterBitmapContainer (
      64             :     const css::uno::Reference<css::container::XNameAccess>& rxRootNode,
      65             :     const ::boost::shared_ptr<PresenterBitmapContainer>& rpParentContainer,
      66             :     const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext,
      67             :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
      68             :     const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper)
      69             :     : mpParentContainer(rpParentContainer),
      70             :       maIconContainer(),
      71             :       mxCanvas(rxCanvas),
      72           0 :       mxPresenterHelper(rxPresenterHelper)
      73             : {
      74           0 :     Initialize(rxComponentContext);
      75             : 
      76           0 :     LoadBitmaps(rxRootNode);
      77           0 : }
      78             : 
      79           0 : void PresenterBitmapContainer::Initialize (
      80             :     const css::uno::Reference<css::uno::XComponentContext>& rxComponentContext)
      81             : {
      82           0 :     if ( ! mxPresenterHelper.is())
      83             :     {
      84             :         // Create an object that is able to load the bitmaps in a format that is
      85             :         // supported by the canvas.
      86             :         Reference<lang::XMultiComponentFactory> xFactory (
      87           0 :             rxComponentContext->getServiceManager(), UNO_QUERY);
      88           0 :         if ( ! xFactory.is())
      89           0 :             return;
      90           0 :         mxPresenterHelper = Reference<drawing::XPresenterHelper>(
      91           0 :             xFactory->createInstanceWithContext(
      92             :                 "com.sun.star.drawing.PresenterHelper",
      93           0 :                 rxComponentContext),
      94           0 :             UNO_QUERY_THROW);
      95             :     }
      96             : }
      97             : 
      98           0 : PresenterBitmapContainer::~PresenterBitmapContainer (void)
      99             : {
     100           0 :     maIconContainer.clear();
     101           0 : }
     102             : 
     103           0 : SharedBitmapDescriptor PresenterBitmapContainer::GetBitmap (
     104             :     const OUString& rsName) const
     105             : {
     106           0 :     BitmapContainer::const_iterator iSet (maIconContainer.find(rsName));
     107           0 :     if (iSet != maIconContainer.end())
     108           0 :         return iSet->second;
     109           0 :     else if (mpParentContainer.get() != NULL)
     110           0 :         return mpParentContainer->GetBitmap(rsName);
     111             :     else
     112           0 :         return SharedBitmapDescriptor();
     113             : }
     114             : 
     115           0 : void PresenterBitmapContainer::LoadBitmaps (
     116             :     const css::uno::Reference<css::container::XNameAccess>& rxBitmapList)
     117             : {
     118           0 :     if ( ! mxCanvas.is())
     119           0 :         return;
     120             : 
     121           0 :     if ( ! rxBitmapList.is())
     122           0 :         return;
     123             : 
     124             :     try
     125             :     {
     126             :         // Load all button bitmaps.
     127           0 :         if (rxBitmapList.is())
     128             :         {
     129             :             PresenterConfigurationAccess::ForAll(
     130             :                 rxBitmapList,
     131           0 :                 ::boost::bind(&PresenterBitmapContainer::ProcessBitmap, this, _1, _2));
     132             :         }
     133             :     }
     134           0 :     catch (Exception&)
     135             :     {
     136             :         OSL_ASSERT(false);
     137             :     }
     138             : }
     139             : 
     140           0 : SharedBitmapDescriptor PresenterBitmapContainer::LoadBitmap (
     141             :     const css::uno::Reference<css::container::XHierarchicalNameAccess>& rxNode,
     142             :     const OUString& rsPath,
     143             :     const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
     144             :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
     145             :     const SharedBitmapDescriptor& rpDefault)
     146             : {
     147           0 :     SharedBitmapDescriptor pBitmap;
     148             : 
     149           0 :     if (rxNode.is())
     150             :     {
     151             :         try
     152             :         {
     153             :             Reference<beans::XPropertySet> xBitmapProperties (
     154             :                 PresenterConfigurationAccess::GetConfigurationNode(rxNode, rsPath),
     155           0 :                 UNO_QUERY);
     156           0 :             if (xBitmapProperties.is())
     157           0 :                 pBitmap = LoadBitmap(
     158             :                     xBitmapProperties,
     159             :                     rxPresenterHelper,
     160             :                     rxCanvas,
     161           0 :                     rpDefault);
     162             :         }
     163           0 :         catch (Exception&)
     164             :         {
     165             :             OSL_ASSERT(false);
     166             :         }
     167             :     }
     168             : 
     169           0 :     return pBitmap;
     170             : }
     171             : 
     172           0 : void PresenterBitmapContainer::ProcessBitmap (
     173             :     const OUString& rsKey,
     174             :     const Reference<beans::XPropertySet>& rxProperties)
     175             : {
     176           0 :     OUString sName;
     177           0 :     if ( ! (PresenterConfigurationAccess::GetProperty(rxProperties, "Name") >>= sName))
     178           0 :         sName = rsKey;
     179             : 
     180           0 :     maIconContainer[sName] = LoadBitmap(
     181             :         rxProperties,
     182             :         mxPresenterHelper,
     183             :         mxCanvas,
     184           0 :         SharedBitmapDescriptor());
     185           0 : }
     186             : 
     187           0 : SharedBitmapDescriptor PresenterBitmapContainer::LoadBitmap (
     188             :     const Reference<beans::XPropertySet>& rxProperties,
     189             :     const css::uno::Reference<css::drawing::XPresenterHelper>& rxPresenterHelper,
     190             :     const css::uno::Reference<css::rendering::XCanvas>& rxCanvas,
     191             :     const SharedBitmapDescriptor& rpDefault)
     192             : {
     193             :     OSL_ASSERT(rxCanvas.is());
     194             :     OSL_ASSERT(rxPresenterHelper.is());
     195             : 
     196           0 :     SharedBitmapDescriptor pBitmap (new BitmapDescriptor(rpDefault));
     197             : 
     198           0 :     if ( ! rxProperties.is())
     199           0 :         return pBitmap;
     200             : 
     201           0 :     OUString sFileName;
     202             : 
     203             :     // Load bitmaps.
     204           0 :     if (PresenterConfigurationAccess::GetProperty(rxProperties, "NormalFileName") >>= sFileName)
     205             :         try
     206             :         {
     207             :             pBitmap->SetBitmap(
     208             :                 BitmapDescriptor::Normal,
     209           0 :                 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
     210             :         }
     211           0 :         catch (Exception&)
     212             :         {}
     213           0 :     if (PresenterConfigurationAccess::GetProperty(rxProperties, "MouseOverFileName") >>= sFileName)
     214             :         try
     215             :         {
     216             :             pBitmap->SetBitmap(
     217             :                 BitmapDescriptor::MouseOver,
     218           0 :                 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
     219             :         }
     220           0 :         catch (Exception&)
     221             :         {}
     222           0 :     if (PresenterConfigurationAccess::GetProperty(rxProperties, "ButtonDownFileName") >>= sFileName)
     223             :         try
     224             :         {
     225             :             pBitmap->SetBitmap(
     226             :                 BitmapDescriptor::ButtonDown,
     227           0 :                 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
     228             :         }
     229           0 :         catch (Exception&)
     230             :         {}
     231           0 :     if (PresenterConfigurationAccess::GetProperty(rxProperties, "DisabledFileName") >>= sFileName)
     232             :         try
     233             :         {
     234             :             pBitmap->SetBitmap(
     235             :                 BitmapDescriptor::Disabled,
     236           0 :                 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
     237             :         }
     238           0 :         catch (Exception&)
     239             :         {}
     240           0 :     if (PresenterConfigurationAccess::GetProperty(rxProperties, "MaskFileName") >>= sFileName)
     241             :         try
     242             :         {
     243             :             pBitmap->SetBitmap(
     244             :                 BitmapDescriptor::Mask,
     245           0 :                 rxPresenterHelper->loadBitmap(sFileName, rxCanvas));
     246             :         }
     247           0 :         catch (Exception&)
     248             :         {}
     249             : 
     250           0 :     PresenterConfigurationAccess::GetProperty(rxProperties, "XOffset") >>= pBitmap->mnXOffset;
     251           0 :     PresenterConfigurationAccess::GetProperty(rxProperties, "YOffset") >>= pBitmap->mnYOffset;
     252             : 
     253           0 :     PresenterConfigurationAccess::GetProperty(rxProperties, "XHotSpot") >>= pBitmap->mnXHotSpot;
     254           0 :     PresenterConfigurationAccess::GetProperty(rxProperties, "YHotSpot") >>= pBitmap->mnYHotSpot;
     255             : 
     256           0 :     PresenterConfigurationAccess::GetProperty(rxProperties, "ReplacementColor") >>= pBitmap->maReplacementColor;
     257             : 
     258           0 :     OUString sTexturingMode;
     259           0 :     if (PresenterConfigurationAccess::GetProperty(rxProperties, "HorizontalTexturingMode") >>= sTexturingMode)
     260           0 :         pBitmap->meHorizontalTexturingMode = StringToTexturingMode(sTexturingMode);
     261           0 :     if (PresenterConfigurationAccess::GetProperty(rxProperties, "VerticalTexturingMode") >>= sTexturingMode)
     262           0 :         pBitmap->meVerticalTexturingMode = StringToTexturingMode(sTexturingMode);
     263             : 
     264           0 :     return pBitmap;
     265             : }
     266             : 
     267             : PresenterBitmapContainer::BitmapDescriptor::TexturingMode
     268           0 :     PresenterBitmapContainer::StringToTexturingMode (const OUString& rsTexturingMode)
     269             : {
     270           0 :     if (rsTexturingMode == "Once")
     271           0 :         return PresenterBitmapContainer::BitmapDescriptor::Once;
     272           0 :     else if (rsTexturingMode == "Repeat")
     273           0 :         return PresenterBitmapContainer::BitmapDescriptor::Repeat;
     274           0 :     else if (rsTexturingMode == "Stretch")
     275           0 :         return PresenterBitmapContainer::BitmapDescriptor::Stretch;
     276             :     else
     277           0 :         return PresenterBitmapContainer::BitmapDescriptor::Once;
     278             : }
     279             : 
     280             : //===== PresenterBitmapContainer::BitmapSet ===================================
     281             : 
     282           0 : PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (void)
     283             :     : mnWidth(0),
     284             :       mnHeight(0),
     285             :       mnXOffset(0),
     286             :       mnYOffset(0),
     287             :       mnXHotSpot(0),
     288             :       mnYHotSpot(0),
     289             :       maReplacementColor(0x00000000),
     290             :       meHorizontalTexturingMode(Once),
     291             :       meVerticalTexturingMode(Once),
     292             :       mxNormalBitmap(),
     293             :       mxMouseOverBitmap(),
     294             :       mxButtonDownBitmap(),
     295             :       mxDisabledBitmap(),
     296           0 :       mxMaskBitmap()
     297             : {
     298           0 : }
     299             : 
     300           0 : PresenterBitmapContainer::BitmapDescriptor::BitmapDescriptor (
     301             :     const ::boost::shared_ptr<PresenterBitmapContainer::BitmapDescriptor>& rpDefault)
     302             :     : mnWidth(0),
     303             :       mnHeight(0),
     304             :       mnXOffset(0),
     305             :       mnYOffset(0),
     306             :       mnXHotSpot(0),
     307             :       mnYHotSpot(0),
     308             :       maReplacementColor(0x00000000),
     309             :       meHorizontalTexturingMode(Once),
     310             :       meVerticalTexturingMode(Once),
     311             :       mxNormalBitmap(),
     312             :       mxMouseOverBitmap(),
     313             :       mxButtonDownBitmap(),
     314             :       mxDisabledBitmap(),
     315           0 :       mxMaskBitmap()
     316             : {
     317           0 :     if (rpDefault.get() != NULL)
     318             :     {
     319           0 :         mnWidth = rpDefault->mnWidth;
     320           0 :         mnHeight = rpDefault->mnHeight;
     321           0 :         mnXOffset = rpDefault->mnXOffset;
     322           0 :         mnYOffset = rpDefault->mnYOffset;
     323           0 :         mnXHotSpot = rpDefault->mnXHotSpot;
     324           0 :         mnYHotSpot = rpDefault->mnYHotSpot;
     325           0 :         maReplacementColor = rpDefault->maReplacementColor;
     326           0 :         meHorizontalTexturingMode = rpDefault->meHorizontalTexturingMode;
     327           0 :         meVerticalTexturingMode = rpDefault->meVerticalTexturingMode;
     328           0 :         mxNormalBitmap = rpDefault->mxNormalBitmap;
     329           0 :         mxMouseOverBitmap = rpDefault->mxMouseOverBitmap;
     330           0 :         mxButtonDownBitmap = rpDefault->mxButtonDownBitmap;
     331           0 :         mxDisabledBitmap = rpDefault->mxDisabledBitmap;
     332           0 :         mxMaskBitmap = rpDefault->mxMaskBitmap;
     333             :     }
     334           0 : }
     335             : 
     336             : css::uno::Reference<css::rendering::XBitmap>
     337           0 :     PresenterBitmapContainer::BitmapDescriptor::GetNormalBitmap (void) const
     338             : {
     339           0 :     return mxNormalBitmap;
     340             : }
     341             : 
     342             : css::uno::Reference<css::rendering::XBitmap>
     343           0 :     PresenterBitmapContainer::BitmapDescriptor::GetBitmap (
     344             :         const Mode eMode,
     345             :         const bool bMissingDefaultsToNormal) const
     346             : {
     347           0 :     switch (eMode)
     348             :     {
     349             :         case Normal:
     350             :         default:
     351           0 :             return mxNormalBitmap;
     352             : 
     353             :         case MouseOver:
     354           0 :             if (mxMouseOverBitmap.is())
     355           0 :                 return mxMouseOverBitmap;
     356           0 :             else if (bMissingDefaultsToNormal)
     357           0 :                 return mxNormalBitmap;
     358             : 
     359             :         case ButtonDown:
     360           0 :             if (mxButtonDownBitmap.is())
     361           0 :                 return mxButtonDownBitmap;
     362           0 :             else if (bMissingDefaultsToNormal)
     363           0 :                 return mxNormalBitmap;
     364             : 
     365             :         case Disabled:
     366           0 :             if (mxDisabledBitmap.is())
     367           0 :                 return mxDisabledBitmap;
     368           0 :             else if (bMissingDefaultsToNormal)
     369           0 :                 return mxNormalBitmap;
     370             : 
     371             :         case Mask:
     372           0 :             return mxMaskBitmap;
     373             :     }
     374             : }
     375             : 
     376           0 : void PresenterBitmapContainer::BitmapDescriptor::SetBitmap (
     377             :     const Mode eMode,
     378             :     const css::uno::Reference<css::rendering::XBitmap>& rxBitmap)
     379             : {
     380           0 :     switch (eMode)
     381             :     {
     382             :         case Normal:
     383             :         default:
     384           0 :             mxNormalBitmap = rxBitmap;
     385           0 :             if (mxNormalBitmap.is())
     386             :             {
     387           0 :                 const geometry::IntegerSize2D aSize (mxNormalBitmap->getSize());
     388           0 :                 mnWidth = aSize.Width;
     389           0 :                 mnHeight = aSize.Height;
     390             :             }
     391           0 :             break;
     392             : 
     393             :         case MouseOver:
     394           0 :             mxMouseOverBitmap = rxBitmap;
     395           0 :             break;
     396             : 
     397             :         case ButtonDown:
     398           0 :             mxButtonDownBitmap = rxBitmap;
     399           0 :             break;
     400             : 
     401             :         case Disabled:
     402           0 :             mxDisabledBitmap = rxBitmap;
     403           0 :             break;
     404             : 
     405             :         case Mask:
     406           0 :             mxMaskBitmap = rxBitmap;
     407           0 :             break;
     408             :     }
     409           0 : }
     410             : 
     411           0 : } } // end of namespace ::sdext::presenter
     412             : 
     413             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10