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

Generated by: LCOV version 1.10