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

Generated by: LCOV version 1.11