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

Generated by: LCOV version 1.10