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

Generated by: LCOV version 1.10