LCOV - code coverage report
Current view: top level - embeddedobj/source/commonembedding - visobj.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 50 85 58.8 %
Date: 2012-08-25 Functions: 4 4 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 40 178 22.5 %

           Branch data     Line data    Source code
       1                 :            : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2                 :            : /*************************************************************************
       3                 :            :  *
       4                 :            :  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       5                 :            :  *
       6                 :            :  * Copyright 2000, 2010 Oracle and/or its affiliates.
       7                 :            :  *
       8                 :            :  * OpenOffice.org - a multi-platform office productivity suite
       9                 :            :  *
      10                 :            :  * This file is part of OpenOffice.org.
      11                 :            :  *
      12                 :            :  * OpenOffice.org is free software: you can redistribute it and/or modify
      13                 :            :  * it under the terms of the GNU Lesser General Public License version 3
      14                 :            :  * only, as published by the Free Software Foundation.
      15                 :            :  *
      16                 :            :  * OpenOffice.org is distributed in the hope that it will be useful,
      17                 :            :  * but WITHOUT ANY WARRANTY; without even the implied warranty of
      18                 :            :  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      19                 :            :  * GNU Lesser General Public License version 3 for more details
      20                 :            :  * (a copy is included in the LICENSE file that accompanied this code).
      21                 :            :  *
      22                 :            :  * You should have received a copy of the GNU Lesser General Public License
      23                 :            :  * version 3 along with OpenOffice.org.  If not, see
      24                 :            :  * <http://www.openoffice.org/license.html>
      25                 :            :  * for a copy of the LGPLv3 License.
      26                 :            :  *
      27                 :            :  ************************************************************************/
      28                 :            : 
      29                 :            : #include <com/sun/star/embed/Aspects.hpp>
      30                 :            : #include <com/sun/star/embed/EmbedStates.hpp>
      31                 :            : #include <com/sun/star/datatransfer/XTransferable.hpp>
      32                 :            : #include <com/sun/star/uno/Sequence.hxx>
      33                 :            : #include <com/sun/star/lang/DisposedException.hpp>
      34                 :            : 
      35                 :            : #include <rtl/logfile.hxx>
      36                 :            : 
      37                 :            : 
      38                 :            : #include <commonembobj.hxx>
      39                 :            : 
      40                 :            : 
      41                 :            : using namespace ::com::sun::star;
      42                 :            : 
      43                 :         29 : void SAL_CALL OCommonEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
      44                 :            :         throw ( lang::IllegalArgumentException,
      45                 :            :                 embed::WrongStateException,
      46                 :            :                 uno::Exception,
      47                 :            :                 uno::RuntimeException )
      48                 :            : {
      49                 :            :     RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::setVisualAreaSize" );
      50                 :            : 
      51         [ +  - ]:         29 :     ::osl::MutexGuard aGuard( m_aMutex );
      52         [ -  + ]:         29 :     if ( m_bDisposed )
      53         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
      54                 :            : 
      55                 :            :     OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
      56         [ -  + ]:         29 :     if ( nAspect == embed::Aspects::MSOLE_ICON )
      57                 :            :         // no representation can be retrieved
      58                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Illegal call!\n" )),
      59 [ #  # ][ #  # ]:          0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
      60                 :            : 
      61         [ -  + ]:         29 :     if ( m_nObjectState == -1 )
      62                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The own object has no persistence!\n" )),
      63 [ #  # ][ #  # ]:          0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
      64                 :            : 
      65                 :         29 :     m_bHasClonedSize = sal_False;
      66                 :            : 
      67                 :         29 :     sal_Bool bBackToLoaded = sal_False;
      68         [ -  + ]:         29 :     if ( m_nObjectState == embed::EmbedStates::LOADED )
      69                 :            :     {
      70         [ #  # ]:          0 :         changeState( embed::EmbedStates::RUNNING );
      71                 :            : 
      72                 :            :         // the links should be switched back to loaded state for now to avoid locking problems
      73                 :          0 :         bBackToLoaded = m_bIsLink;
      74                 :            :     }
      75                 :            : 
      76         [ +  - ]:         29 :     sal_Bool bSuccess = m_pDocHolder->SetExtent( nAspect, aSize );
      77                 :            : 
      78         [ -  + ]:         29 :     if ( bBackToLoaded )
      79         [ #  # ]:          0 :         changeState( embed::EmbedStates::LOADED );
      80                 :            : 
      81         [ -  + ]:         29 :     if ( !bSuccess )
      82 [ #  # ][ +  - ]:         29 :         throw uno::Exception(); // TODO:
      83                 :         29 : }
      84                 :            : 
      85                 :        312 : awt::Size SAL_CALL OCommonEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
      86                 :            :         throw ( lang::IllegalArgumentException,
      87                 :            :                 embed::WrongStateException,
      88                 :            :                 uno::Exception,
      89                 :            :                 uno::RuntimeException )
      90                 :            : {
      91                 :            :     RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::getVisualAreaSize" );
      92                 :            : 
      93         [ +  - ]:        312 :     ::osl::MutexGuard aGuard( m_aMutex );
      94         [ -  + ]:        312 :     if ( m_bDisposed )
      95         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
      96                 :            : 
      97         [ -  + ]:        312 :     if ( m_nObjectState == -1 )
      98                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The own object has no persistence!\n" )),
      99 [ #  # ][ #  # ]:          0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     100                 :            : 
     101                 :            :     OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
     102                 :            : 
     103         [ -  + ]:        312 :     if ( m_bHasClonedSize )
     104                 :          0 :         return m_aClonedSize;
     105                 :            : 
     106                 :        312 :     sal_Bool bBackToLoaded = sal_False;
     107         [ -  + ]:        312 :     if ( m_nObjectState == embed::EmbedStates::LOADED )
     108                 :            :     {
     109         [ #  # ]:          0 :         changeState( embed::EmbedStates::RUNNING );
     110                 :            : 
     111                 :            :         // the links should be switched back to loaded state for now to avoid locking problems
     112                 :          0 :         bBackToLoaded = m_bIsLink;
     113                 :            :     }
     114                 :            : 
     115                 :        312 :     awt::Size aResult;
     116         [ +  - ]:        312 :     sal_Bool bSuccess = m_pDocHolder->GetExtent( nAspect, &aResult );
     117                 :            : 
     118         [ -  + ]:        312 :     if ( bBackToLoaded )
     119         [ #  # ]:          0 :         changeState( embed::EmbedStates::LOADED );
     120                 :            : 
     121         [ -  + ]:        312 :     if ( !bSuccess )
     122         [ #  # ]:          0 :         throw uno::Exception(); // TODO:
     123                 :            : 
     124         [ +  - ]:        312 :     return aResult;
     125                 :            : }
     126                 :            : 
     127                 :        339 : sal_Int32 SAL_CALL OCommonEmbeddedObject::getMapUnit( sal_Int64 nAspect )
     128                 :            :         throw ( uno::Exception,
     129                 :            :                 uno::RuntimeException)
     130                 :            : {
     131         [ +  - ]:        339 :     ::osl::MutexGuard aGuard( m_aMutex );
     132         [ -  + ]:        339 :     if ( m_bDisposed )
     133         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     134                 :            : 
     135                 :            :     OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
     136         [ -  + ]:        339 :     if ( nAspect == embed::Aspects::MSOLE_ICON )
     137                 :            :         // no representation can be retrieved
     138                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Illegal call!\n" )),
     139 [ #  # ][ #  # ]:          0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     140                 :            : 
     141         [ -  + ]:        339 :     if ( m_nObjectState == -1 )
     142                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The own object has no persistence!\n" )),
     143 [ #  # ][ #  # ]:          0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     144                 :            : 
     145         [ -  + ]:        339 :     if ( m_bHasClonedSize )
     146                 :          0 :         return m_nClonedMapUnit;
     147                 :            : 
     148                 :        339 :     sal_Bool bBackToLoaded = sal_False;
     149         [ -  + ]:        339 :     if ( m_nObjectState == embed::EmbedStates::LOADED )
     150                 :            :     {
     151         [ #  # ]:          0 :         changeState( embed::EmbedStates::RUNNING );
     152                 :            : 
     153                 :            :         // the links should be switched back to loaded state for now to avoid locking problems
     154                 :          0 :         bBackToLoaded = m_bIsLink;
     155                 :            :     }
     156                 :            : 
     157         [ +  - ]:        339 :     sal_Int32 nResult = m_pDocHolder->GetMapUnit( nAspect );
     158                 :            : 
     159         [ -  + ]:        339 :     if ( bBackToLoaded )
     160         [ #  # ]:          0 :         changeState( embed::EmbedStates::LOADED );
     161                 :            : 
     162         [ -  + ]:        339 :     if ( nResult < 0  )
     163         [ #  # ]:          0 :         throw uno::Exception(); // TODO:
     164                 :            : 
     165         [ +  - ]:        339 :     return nResult;
     166                 :            : }
     167                 :            : 
     168                 :       6906 : embed::VisualRepresentation SAL_CALL OCommonEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
     169                 :            :         throw ( lang::IllegalArgumentException,
     170                 :            :                 embed::WrongStateException,
     171                 :            :                 uno::Exception,
     172                 :            :                 uno::RuntimeException )
     173                 :            : {
     174                 :            :     RTL_LOGFILE_CONTEXT( aLog, "embeddedobj (mv76033) OCommonEmbeddedObject::getPrefferedVisualRepresentation" );
     175                 :            : 
     176         [ +  - ]:       6906 :     ::osl::MutexGuard aGuard( m_aMutex );
     177         [ -  + ]:       6906 :     if ( m_bDisposed )
     178         [ #  # ]:          0 :         throw lang::DisposedException(); // TODO
     179                 :            : 
     180         [ -  + ]:       6906 :     if ( m_nObjectState == -1 )
     181                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "The own object has no persistence!\n" )),
     182 [ #  # ][ #  # ]:          0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     183                 :            : 
     184                 :            : 
     185                 :            :     OSL_ENSURE( nAspect != embed::Aspects::MSOLE_ICON, "For iconified objects no graphical replacement is required!\n" );
     186         [ -  + ]:       6906 :     if ( nAspect == embed::Aspects::MSOLE_ICON )
     187                 :            :         // no representation can be retrieved
     188                 :            :         throw embed::WrongStateException( ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "Illegal call!\n" )),
     189 [ #  # ][ #  # ]:          0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
                 [ #  # ]
     190                 :            : 
     191                 :       6906 :     sal_Bool bBackToLoaded = sal_False;
     192         [ -  + ]:       6906 :     if ( m_nObjectState == embed::EmbedStates::LOADED )
     193                 :            :     {
     194         [ #  # ]:          0 :         changeState( embed::EmbedStates::RUNNING );
     195                 :            : 
     196                 :            :         // the links should be switched back to loaded state for now to avoid locking problems
     197                 :          0 :         bBackToLoaded = m_bIsLink;
     198                 :            :     }
     199                 :            : 
     200                 :            :     OSL_ENSURE( m_pDocHolder->GetComponent().is(), "Running or Active object has no component!\n" );
     201                 :            : 
     202                 :            :     // TODO: return for the aspect of the document
     203                 :       6906 :     embed::VisualRepresentation aVisualRepresentation;
     204                 :            : 
     205 [ +  - ][ +  - ]:       6906 :     uno::Reference< embed::XVisualObject > xVisualObject( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
     206         [ +  - ]:       6906 :     if( xVisualObject.is())
     207                 :            :     {
     208 [ +  - ][ +  - ]:       6906 :         aVisualRepresentation = xVisualObject->getPreferredVisualRepresentation( nAspect );
     209                 :            :     }
     210                 :            :     else
     211                 :            :     {
     212 [ #  # ][ #  # ]:          0 :         uno::Reference< datatransfer::XTransferable > xTransferable( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
     213         [ #  # ]:          0 :         if (!xTransferable.is() )
     214         [ #  # ]:          0 :             throw uno::RuntimeException();
     215                 :            : 
     216                 :            :         datatransfer::DataFlavor aDataFlavor(
     217                 :            :                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" )),
     218                 :            :                 ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM( "GDIMetaFile" )),
     219 [ #  # ][ #  # ]:          0 :                 ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
                 [ #  # ]
     220                 :            : 
     221 [ #  # ][ #  # ]:          0 :         if( xTransferable->isDataFlavorSupported( aDataFlavor ))
                 [ #  # ]
     222                 :            :         {
     223 [ #  # ][ #  # ]:          0 :             aVisualRepresentation.Data = xTransferable->getTransferData( aDataFlavor );
     224                 :          0 :             aVisualRepresentation.Flavor = aDataFlavor;
     225                 :            :         }
     226                 :            :         else
     227         [ #  # ]:          0 :             throw uno::RuntimeException();
     228                 :            :     }
     229                 :            : 
     230         [ -  + ]:       6906 :     if ( bBackToLoaded )
     231         [ #  # ]:          0 :         changeState( embed::EmbedStates::LOADED );
     232                 :            : 
     233         [ +  - ]:       6906 :     return aVisualRepresentation;
     234                 :            : }
     235                 :            : 
     236                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10