LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/embeddedobj/source/commonembedding - visobj.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 51 85 60.0 %
Date: 2013-07-09 Functions: 4 4 100.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             : #include <com/sun/star/embed/Aspects.hpp>
      21             : #include <com/sun/star/embed/EmbedStates.hpp>
      22             : #include <com/sun/star/datatransfer/XTransferable.hpp>
      23             : #include <com/sun/star/uno/Sequence.hxx>
      24             : #include <com/sun/star/lang/DisposedException.hpp>
      25             : 
      26             : 
      27             : #include <commonembobj.hxx>
      28             : 
      29             : 
      30             : using namespace ::com::sun::star;
      31             : 
      32          57 : void SAL_CALL OCommonEmbeddedObject::setVisualAreaSize( sal_Int64 nAspect, const awt::Size& aSize )
      33             :         throw ( lang::IllegalArgumentException,
      34             :                 embed::WrongStateException,
      35             :                 uno::Exception,
      36             :                 uno::RuntimeException )
      37             : {
      38             :     SAL_WARN( "embeddedobj.common", "embeddedobj (mv76033) OCommonEmbeddedObject::setVisualAreaSize" );
      39             : 
      40          57 :     ::osl::MutexGuard aGuard( m_aMutex );
      41          57 :     if ( m_bDisposed )
      42           0 :         throw lang::DisposedException(); // TODO
      43             : 
      44             :     SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
      45          57 :     if ( nAspect == embed::Aspects::MSOLE_ICON )
      46             :         // no representation can be retrieved
      47             :         throw embed::WrongStateException( OUString( "Illegal call!\n" ),
      48           0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
      49             : 
      50          57 :     if ( m_nObjectState == -1 )
      51             :         throw embed::WrongStateException( OUString( "The own object has no persistence!\n" ),
      52           0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
      53             : 
      54          57 :     m_bHasClonedSize = sal_False;
      55             : 
      56          57 :     sal_Bool bBackToLoaded = sal_False;
      57          57 :     if ( m_nObjectState == embed::EmbedStates::LOADED )
      58             :     {
      59           0 :         changeState( embed::EmbedStates::RUNNING );
      60             : 
      61             :         // the links should be switched back to loaded state for now to avoid locking problems
      62           0 :         bBackToLoaded = m_bIsLink;
      63             :     }
      64             : 
      65          57 :     sal_Bool bSuccess = m_pDocHolder->SetExtent( nAspect, aSize );
      66             : 
      67          57 :     if ( bBackToLoaded )
      68           0 :         changeState( embed::EmbedStates::LOADED );
      69             : 
      70          57 :     if ( !bSuccess )
      71           0 :         throw uno::Exception(); // TODO:
      72          57 : }
      73             : 
      74         118 : awt::Size SAL_CALL OCommonEmbeddedObject::getVisualAreaSize( sal_Int64 nAspect )
      75             :         throw ( lang::IllegalArgumentException,
      76             :                 embed::WrongStateException,
      77             :                 uno::Exception,
      78             :                 uno::RuntimeException )
      79             : {
      80             :     SAL_WARN( "embeddedobj.common", "embeddedobj (mv76033) OCommonEmbeddedObject::getVisualAreaSize" );
      81             : 
      82         118 :     ::osl::MutexGuard aGuard( m_aMutex );
      83         118 :     if ( m_bDisposed )
      84           0 :         throw lang::DisposedException(); // TODO
      85             : 
      86         118 :     if ( m_nObjectState == -1 )
      87             :         throw embed::WrongStateException( OUString( "The own object has no persistence!\n" ),
      88           0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
      89             : 
      90             :     SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
      91             : 
      92         118 :     if ( m_bHasClonedSize )
      93           0 :         return m_aClonedSize;
      94             : 
      95         118 :     sal_Bool bBackToLoaded = sal_False;
      96         118 :     if ( m_nObjectState == embed::EmbedStates::LOADED )
      97             :     {
      98           1 :         changeState( embed::EmbedStates::RUNNING );
      99             : 
     100             :         // the links should be switched back to loaded state for now to avoid locking problems
     101           0 :         bBackToLoaded = m_bIsLink;
     102             :     }
     103             : 
     104         117 :     awt::Size aResult;
     105         117 :     sal_Bool bSuccess = m_pDocHolder->GetExtent( nAspect, &aResult );
     106             : 
     107         117 :     if ( bBackToLoaded )
     108           0 :         changeState( embed::EmbedStates::LOADED );
     109             : 
     110         117 :     if ( !bSuccess )
     111           0 :         throw uno::Exception(); // TODO:
     112             : 
     113         118 :     return aResult;
     114             : }
     115             : 
     116         172 : sal_Int32 SAL_CALL OCommonEmbeddedObject::getMapUnit( sal_Int64 nAspect )
     117             :         throw ( uno::Exception,
     118             :                 uno::RuntimeException)
     119             : {
     120         172 :     ::osl::MutexGuard aGuard( m_aMutex );
     121         172 :     if ( m_bDisposed )
     122           0 :         throw lang::DisposedException(); // TODO
     123             : 
     124             :     SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
     125         172 :     if ( nAspect == embed::Aspects::MSOLE_ICON )
     126             :         // no representation can be retrieved
     127             :         throw embed::WrongStateException( OUString( "Illegal call!\n" ),
     128           0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
     129             : 
     130         172 :     if ( m_nObjectState == -1 )
     131             :         throw embed::WrongStateException( OUString( "The own object has no persistence!\n" ),
     132           0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
     133             : 
     134         172 :     if ( m_bHasClonedSize )
     135           0 :         return m_nClonedMapUnit;
     136             : 
     137         172 :     sal_Bool bBackToLoaded = sal_False;
     138         172 :     if ( m_nObjectState == embed::EmbedStates::LOADED )
     139             :     {
     140           1 :         changeState( embed::EmbedStates::RUNNING );
     141             : 
     142             :         // the links should be switched back to loaded state for now to avoid locking problems
     143           0 :         bBackToLoaded = m_bIsLink;
     144             :     }
     145             : 
     146         171 :     sal_Int32 nResult = m_pDocHolder->GetMapUnit( nAspect );
     147             : 
     148         171 :     if ( bBackToLoaded )
     149           0 :         changeState( embed::EmbedStates::LOADED );
     150             : 
     151         171 :     if ( nResult < 0  )
     152           0 :         throw uno::Exception(); // TODO:
     153             : 
     154         172 :     return nResult;
     155             : }
     156             : 
     157        2664 : embed::VisualRepresentation SAL_CALL OCommonEmbeddedObject::getPreferredVisualRepresentation( sal_Int64 nAspect )
     158             :         throw ( lang::IllegalArgumentException,
     159             :                 embed::WrongStateException,
     160             :                 uno::Exception,
     161             :                 uno::RuntimeException )
     162             : {
     163             :     SAL_WARN( "embeddedobj.common", "embeddedobj (mv76033) OCommonEmbeddedObject::getPrefferedVisualRepresentation" );
     164             : 
     165        2664 :     ::osl::MutexGuard aGuard( m_aMutex );
     166        2664 :     if ( m_bDisposed )
     167           0 :         throw lang::DisposedException(); // TODO
     168             : 
     169        2664 :     if ( m_nObjectState == -1 )
     170             :         throw embed::WrongStateException( OUString( "The own object has no persistence!\n" ),
     171           0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
     172             : 
     173             : 
     174             :     SAL_WARN_IF( nAspect == embed::Aspects::MSOLE_ICON, "embeddedobj.common", "For iconified objects no graphical replacement is required!" );
     175        2664 :     if ( nAspect == embed::Aspects::MSOLE_ICON )
     176             :         // no representation can be retrieved
     177             :         throw embed::WrongStateException( OUString( "Illegal call!\n" ),
     178           0 :                                     uno::Reference< uno::XInterface >( static_cast< ::cppu::OWeakObject* >(this) ) );
     179             : 
     180        2664 :     sal_Bool bBackToLoaded = sal_False;
     181        2664 :     if ( m_nObjectState == embed::EmbedStates::LOADED )
     182             :     {
     183           0 :         changeState( embed::EmbedStates::RUNNING );
     184             : 
     185             :         // the links should be switched back to loaded state for now to avoid locking problems
     186           0 :         bBackToLoaded = m_bIsLink;
     187             :     }
     188             : 
     189             :     SAL_WARN_IF( !m_pDocHolder->GetComponent().is(), "embeddedobj.common", "Running or Active object has no component!" );
     190             : 
     191             :     // TODO: return for the aspect of the document
     192        2664 :     embed::VisualRepresentation aVisualRepresentation;
     193             : 
     194        5328 :     uno::Reference< embed::XVisualObject > xVisualObject( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
     195        2664 :     if( xVisualObject.is())
     196             :     {
     197        2664 :         aVisualRepresentation = xVisualObject->getPreferredVisualRepresentation( nAspect );
     198             :     }
     199             :     else
     200             :     {
     201           0 :         uno::Reference< datatransfer::XTransferable > xTransferable( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
     202           0 :         if (!xTransferable.is() )
     203           0 :             throw uno::RuntimeException();
     204             : 
     205             :         datatransfer::DataFlavor aDataFlavor(
     206             :                 OUString( "application/x-openoffice-gdimetafile;windows_formatname=\"GDIMetaFile\"" ),
     207             :                 OUString( "GDIMetaFile" ),
     208           0 :                 ::getCppuType( (const uno::Sequence< sal_Int8 >*) NULL ) );
     209             : 
     210           0 :         if( xTransferable->isDataFlavorSupported( aDataFlavor ))
     211             :         {
     212           0 :             aVisualRepresentation.Data = xTransferable->getTransferData( aDataFlavor );
     213           0 :             aVisualRepresentation.Flavor = aDataFlavor;
     214             :         }
     215             :         else
     216           0 :             throw uno::RuntimeException();
     217             :     }
     218             : 
     219        2664 :     if ( bBackToLoaded )
     220           0 :         changeState( embed::EmbedStates::LOADED );
     221             : 
     222        5328 :     return aVisualRepresentation;
     223             : }
     224             : 
     225             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10