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

Generated by: LCOV version 1.10