LCOV - code coverage report
Current view: top level - svx/source/unogallery - unogalitem.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 1 165 0.6 %
Date: 2014-11-03 Functions: 2 29 6.9 %
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             : 
      21             : #include "unogalitem.hxx"
      22             : #include "unogaltheme.hxx"
      23             : #include "svx/galtheme.hxx"
      24             : #include "svx/galmisc.hxx"
      25             : #include <svx/fmmodel.hxx>
      26             : #include <osl/mutex.hxx>
      27             : #include <vcl/svapp.hxx>
      28             : #include <vcl/graph.hxx>
      29             : #include <svl/itemprop.hxx>
      30             : #include <svl/itempool.hxx>
      31             : #include <comphelper/servicehelper.hxx>
      32             : #include <cppuhelper/supportsservice.hxx>
      33             : #include "galobj.hxx"
      34             : 
      35             : #include <com/sun/star/beans/PropertyState.hpp>
      36             : #include <com/sun/star/beans/PropertyAttribute.hpp>
      37             : #include <com/sun/star/gallery/GalleryItemType.hpp>
      38             : #include <boost/scoped_ptr.hpp>
      39             : 
      40             : #define UNOGALLERY_GALLERYITEMTYPE  1
      41             : #define UNOGALLERY_URL              2
      42             : #define UNOGALLERY_TITLE            3
      43             : #define UNOGALLERY_THUMBNAIL        4
      44             : #define UNOGALLERY_GRAPHIC          5
      45             : #define UNOGALLERY_DRAWING          6
      46             : 
      47             : using namespace ::com::sun::star;
      48             : 
      49             : namespace unogallery {
      50             : 
      51             : 
      52             : // - GalleryItem -
      53             : 
      54             : 
      55           0 : GalleryItem::GalleryItem( ::unogallery::GalleryTheme& rTheme, const GalleryObject& rObject ) :
      56             :     ::comphelper::PropertySetHelper( createPropertySetInfo() ),
      57             :     mpTheme( &rTheme ),
      58           0 :     mpGalleryObject( &rObject )
      59             : {
      60           0 :     mpTheme->implRegisterGalleryItem( *this );
      61           0 : }
      62             : 
      63             : 
      64             : 
      65           0 : GalleryItem::~GalleryItem()
      66           0 :     throw()
      67             : {
      68           0 :     if( mpTheme )
      69           0 :         mpTheme->implDeregisterGalleryItem( *this );
      70           0 : }
      71             : 
      72             : 
      73             : 
      74           0 : bool GalleryItem::isValid() const
      75             : {
      76           0 :     return( mpTheme != NULL );
      77             : }
      78             : 
      79             : 
      80             : 
      81           0 : uno::Any SAL_CALL GalleryItem::queryAggregation( const uno::Type & rType )
      82             :     throw( uno::RuntimeException, std::exception )
      83             : {
      84           0 :     uno::Any aAny;
      85             : 
      86           0 :     if( rType == cppu::UnoType<lang::XServiceInfo>::get())
      87           0 :         aAny <<= uno::Reference< lang::XServiceInfo >(this);
      88           0 :     else if( rType == cppu::UnoType<lang::XTypeProvider>::get())
      89           0 :         aAny <<= uno::Reference< lang::XTypeProvider >(this);
      90           0 :     else if( rType == cppu::UnoType<gallery::XGalleryItem>::get())
      91           0 :         aAny <<= uno::Reference< gallery::XGalleryItem >(this);
      92           0 :     else if( rType == cppu::UnoType<beans::XPropertySet>::get())
      93           0 :         aAny <<= uno::Reference< beans::XPropertySet >(this);
      94           0 :     else if( rType == cppu::UnoType<beans::XPropertyState>::get())
      95           0 :         aAny <<= uno::Reference< beans::XPropertyState >(this);
      96           0 :     else if( rType == cppu::UnoType<beans::XMultiPropertySet>::get())
      97           0 :         aAny <<= uno::Reference< beans::XMultiPropertySet >(this);
      98             :     else
      99           0 :         aAny <<= OWeakAggObject::queryAggregation( rType );
     100             : 
     101           0 :     return aAny;
     102             : }
     103             : 
     104             : 
     105             : 
     106           0 : uno::Any SAL_CALL GalleryItem::queryInterface( const uno::Type & rType )
     107             :     throw( uno::RuntimeException, std::exception )
     108             : {
     109           0 :     return OWeakAggObject::queryInterface( rType );
     110             : }
     111             : 
     112             : 
     113             : 
     114           0 : void SAL_CALL GalleryItem::acquire()
     115             :     throw()
     116             : {
     117           0 :     OWeakAggObject::acquire();
     118           0 : }
     119             : 
     120             : 
     121             : 
     122           0 : void SAL_CALL GalleryItem::release()
     123             :     throw()
     124             : {
     125           0 :     OWeakAggObject::release();
     126           0 : }
     127             : 
     128             : 
     129             : 
     130           0 : OUString GalleryItem::getImplementationName_Static()
     131             :     throw()
     132             : {
     133           0 :     return OUString( "com.sun.star.comp.gallery.GalleryItem" );
     134             : }
     135             : 
     136             : 
     137             : 
     138           0 : uno::Sequence< OUString > GalleryItem::getSupportedServiceNames_Static()
     139             :     throw()
     140             : {
     141           0 :     uno::Sequence< OUString > aSeq( 1 );
     142             : 
     143           0 :     aSeq.getArray()[ 0 ] = "com.sun.star.gallery.GalleryItem";
     144             : 
     145           0 :     return aSeq;
     146             : }
     147             : 
     148           0 : OUString SAL_CALL GalleryItem::getImplementationName()
     149             :     throw( uno::RuntimeException, std::exception )
     150             : {
     151           0 :     return getImplementationName_Static();
     152             : }
     153             : 
     154           0 : sal_Bool SAL_CALL GalleryItem::supportsService( const OUString& ServiceName )
     155             :     throw( uno::RuntimeException, std::exception )
     156             : {
     157           0 :     return cppu::supportsService(this, ServiceName);
     158             : }
     159             : 
     160           0 : uno::Sequence< OUString > SAL_CALL GalleryItem::getSupportedServiceNames()
     161             :     throw( uno::RuntimeException, std::exception )
     162             : {
     163           0 :     return getSupportedServiceNames_Static();
     164             : }
     165             : 
     166           0 : uno::Sequence< uno::Type > SAL_CALL GalleryItem::getTypes()
     167             :     throw(uno::RuntimeException, std::exception)
     168             : {
     169           0 :     uno::Sequence< uno::Type >  aTypes( 6 );
     170           0 :     uno::Type*                  pTypes = aTypes.getArray();
     171             : 
     172           0 :     *pTypes++ = cppu::UnoType<lang::XServiceInfo>::get();
     173           0 :     *pTypes++ = cppu::UnoType<lang::XTypeProvider>::get();
     174           0 :     *pTypes++ = cppu::UnoType<gallery::XGalleryItem>::get();
     175           0 :     *pTypes++ = cppu::UnoType<beans::XPropertySet>::get();
     176           0 :     *pTypes++ = cppu::UnoType<beans::XPropertyState>::get();
     177           0 :     *pTypes++ = cppu::UnoType<beans::XMultiPropertySet>::get();
     178             : 
     179           0 :     return aTypes;
     180             : }
     181             : 
     182           0 : uno::Sequence< sal_Int8 > SAL_CALL GalleryItem::getImplementationId()
     183             :     throw(uno::RuntimeException, std::exception)
     184             : {
     185           0 :     return css::uno::Sequence<sal_Int8>();
     186             : }
     187             : 
     188             : 
     189             : 
     190           0 : sal_Int8 SAL_CALL GalleryItem::getType()
     191             :     throw (uno::RuntimeException, std::exception)
     192             : {
     193           0 :     const SolarMutexGuard aGuard;
     194           0 :     sal_Int8            nRet = gallery::GalleryItemType::EMPTY;
     195             : 
     196           0 :     if( isValid() )
     197             :     {
     198           0 :         switch( implGetObject()->eObjKind )
     199             :         {
     200             :             case( SGA_OBJ_SOUND ):
     201             :             case( SGA_OBJ_VIDEO ):
     202           0 :                 nRet = gallery::GalleryItemType::MEDIA;
     203           0 :             break;
     204             : 
     205             :             case( SGA_OBJ_SVDRAW ):
     206           0 :                 nRet = gallery::GalleryItemType::DRAWING;
     207           0 :             break;
     208             : 
     209             :             default:
     210           0 :                 nRet = gallery::GalleryItemType::GRAPHIC;
     211           0 :             break;
     212             :         }
     213             :     }
     214             : 
     215           0 :     return nRet;
     216             : }
     217             : 
     218             : 
     219             : 
     220           0 : ::comphelper::PropertySetInfo* GalleryItem::createPropertySetInfo()
     221             : {
     222           0 :     SolarMutexGuard aGuard;
     223           0 :     ::comphelper::PropertySetInfo*  pRet = new ::comphelper::PropertySetInfo();
     224             : 
     225             :     static ::comphelper::PropertyMapEntry const aEntries[] =
     226             :     {
     227           0 :         { OUString("GalleryItemType"), UNOGALLERY_GALLERYITEMTYPE, cppu::UnoType<sal_Int8>::get(),
     228             :           beans::PropertyAttribute::READONLY, 0 },
     229             : 
     230           0 :         { OUString("URL"), UNOGALLERY_URL, ::cppu::UnoType<OUString>::get(),
     231             :           beans::PropertyAttribute::READONLY, 0 },
     232             : 
     233           0 :         { OUString("Title"), UNOGALLERY_TITLE, ::cppu::UnoType<OUString>::get(),
     234             :           0, 0 },
     235             : 
     236           0 :         { OUString("Thumbnail"), UNOGALLERY_THUMBNAIL, cppu::UnoType<graphic::XGraphic>::get(),
     237             :           beans::PropertyAttribute::READONLY, 0 },
     238             : 
     239           0 :         { OUString("Graphic"), UNOGALLERY_GRAPHIC, cppu::UnoType<graphic::XGraphic>::get(),
     240             :           beans::PropertyAttribute::READONLY, 0 },
     241             : 
     242           0 :         { OUString("Drawing"), UNOGALLERY_DRAWING, cppu::UnoType<lang::XComponent>::get(),
     243             :           beans::PropertyAttribute::READONLY, 0 },
     244             : 
     245             :         { OUString(), 0, css::uno::Type(), 0, 0 }
     246           0 :     };
     247             : 
     248           0 :     pRet->acquire();
     249           0 :     pRet->add( aEntries );
     250             : 
     251           0 :     return pRet;
     252             : }
     253             : 
     254           0 : void GalleryItem::_setPropertyValues( const comphelper::PropertyMapEntry** ppEntries, const uno::Any* pValues )
     255             :     throw (beans::UnknownPropertyException,
     256             :            beans::PropertyVetoException,
     257             :            lang::IllegalArgumentException,
     258             :            lang::WrappedTargetException,
     259             :            uno::RuntimeException)
     260             : {
     261           0 :     const SolarMutexGuard aGuard;
     262             : 
     263           0 :     while( *ppEntries )
     264             :     {
     265           0 :         if( UNOGALLERY_TITLE == (*ppEntries)->mnHandle )
     266             :         {
     267           0 :             OUString aNewTitle;
     268             : 
     269           0 :             if( *pValues >>= aNewTitle )
     270             :             {
     271           0 :                 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
     272             : 
     273           0 :                 if( pGalTheme )
     274             :                 {
     275           0 :                     boost::scoped_ptr<SgaObject> pObj(pGalTheme->ImplReadSgaObject( const_cast< GalleryObject* >( implGetObject() ) ));
     276             : 
     277           0 :                     if( pObj )
     278             :                     {
     279           0 :                         if( OUString( pObj->GetTitle() ) != aNewTitle )
     280             :                         {
     281           0 :                             pObj->SetTitle( aNewTitle );
     282           0 :                             pGalTheme->InsertObject( *pObj );
     283             :                         }
     284           0 :                     }
     285             :                 }
     286             :             }
     287             :             else
     288             :             {
     289           0 :                 throw lang::IllegalArgumentException();
     290           0 :             }
     291             :         }
     292             : 
     293           0 :         ++ppEntries;
     294           0 :         ++pValues;
     295           0 :     }
     296           0 : }
     297             : 
     298           0 : void GalleryItem::_getPropertyValues( const comphelper::PropertyMapEntry** ppEntries, uno::Any* pValue )
     299             :     throw (beans::UnknownPropertyException,
     300             :            lang::WrappedTargetException,
     301             :            css::uno::RuntimeException,
     302             :            std::exception)
     303             : {
     304           0 :     const SolarMutexGuard aGuard;
     305             : 
     306           0 :     while( *ppEntries )
     307             :     {
     308           0 :         switch( (*ppEntries)->mnHandle )
     309             :         {
     310             :             case( UNOGALLERY_GALLERYITEMTYPE ):
     311             :             {
     312           0 :                 *pValue <<= sal_Int8( getType() );
     313             :             }
     314           0 :             break;
     315             : 
     316             :             case( UNOGALLERY_URL ):
     317             :             {
     318           0 :                 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
     319             : 
     320           0 :                 if( pGalTheme )
     321           0 :                     *pValue <<= OUString( implGetObject()->aURL.GetMainURL( INetURLObject::NO_DECODE ) );
     322             :             }
     323           0 :             break;
     324             : 
     325             :             case( UNOGALLERY_TITLE ):
     326             :             {
     327           0 :                 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
     328             : 
     329           0 :                 if( pGalTheme )
     330             :                 {
     331           0 :                     SgaObject* pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) );
     332             : 
     333           0 :                     if( pObj )
     334             :                     {
     335           0 :                         *pValue <<= OUString( pObj->GetTitle() );
     336           0 :                         pGalTheme->ReleaseObject( pObj );
     337             :                     }
     338             :                 }
     339             :             }
     340           0 :             break;
     341             : 
     342             :             case( UNOGALLERY_THUMBNAIL ):
     343             :             {
     344           0 :                 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
     345             : 
     346           0 :                 if( pGalTheme )
     347             :                 {
     348           0 :                     SgaObject* pObj = pGalTheme->AcquireObject( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ) );
     349             : 
     350           0 :                     if( pObj )
     351             :                     {
     352           0 :                         Graphic aThumbnail;
     353             : 
     354           0 :                         if( pObj->IsThumbBitmap() )
     355           0 :                             aThumbnail = pObj->GetThumbBmp();
     356             :                         else
     357           0 :                             aThumbnail = pObj->GetThumbMtf();
     358             : 
     359           0 :                         *pValue <<= aThumbnail.GetXGraphic();
     360           0 :                         pGalTheme->ReleaseObject( pObj );
     361             :                     }
     362             :                 }
     363             :             }
     364           0 :             break;
     365             : 
     366             :             case( UNOGALLERY_GRAPHIC ):
     367             :             {
     368           0 :                 ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
     369           0 :                 Graphic         aGraphic;
     370             : 
     371           0 :                 if( pGalTheme && pGalTheme->GetGraphic( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ), aGraphic ) )
     372           0 :                     *pValue <<= aGraphic.GetXGraphic();
     373             :             }
     374           0 :             break;
     375             : 
     376             :             case( UNOGALLERY_DRAWING ):
     377             :             {
     378           0 :                 if( gallery::GalleryItemType::DRAWING == getType() )
     379             :                 {
     380           0 :                     ::GalleryTheme* pGalTheme = ( isValid() ? mpTheme->implGetTheme() : NULL );
     381           0 :                     FmFormModel*    pModel = new FmFormModel;
     382             : 
     383           0 :                     pModel->GetItemPool().FreezeIdRanges();
     384             : 
     385           0 :                     if( pGalTheme && pGalTheme->GetModel( pGalTheme->ImplGetGalleryObjectPos( implGetObject() ), *pModel ) )
     386             :                     {
     387           0 :                         uno::Reference< lang::XComponent > xDrawing( new GalleryDrawingModel( pModel ) );
     388             : 
     389           0 :                         pModel->setUnoModel( uno::Reference< uno::XInterface >::query( xDrawing ) );
     390           0 :                         *pValue <<= xDrawing;
     391             :                     }
     392             :                     else
     393           0 :                         delete pModel;
     394             :                 }
     395             :             }
     396           0 :             break;
     397             :         }
     398             : 
     399           0 :         ++ppEntries;
     400           0 :         ++pValue;
     401           0 :     }
     402           0 : }
     403             : 
     404             : 
     405             : 
     406             : 
     407             : 
     408             : 
     409           0 : void GalleryItem::implSetInvalid()
     410             : {
     411           0 :     if( mpTheme )
     412             :     {
     413           0 :         mpTheme = NULL;
     414           0 :         mpGalleryObject = NULL;
     415             :     }
     416           0 : }
     417             : 
     418             : 
     419             : // - GalleryDrawingModel -
     420             : 
     421             : 
     422           0 : GalleryDrawingModel::GalleryDrawingModel( SdrModel* pDoc )
     423             :     throw() :
     424           0 :     SvxUnoDrawingModel( pDoc )
     425             : {
     426           0 : }
     427             : 
     428             : 
     429             : 
     430           0 : GalleryDrawingModel::~GalleryDrawingModel()
     431           0 :     throw()
     432             : {
     433           0 :     delete GetDoc();
     434           0 : }
     435             : 
     436             : 
     437             : 
     438           0 : UNO3_GETIMPLEMENTATION_IMPL( GalleryDrawingModel );
     439             : 
     440         594 : }
     441             : 
     442             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10