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-17 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          82 : 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          82 :     ::osl::MutexGuard aGuard( m_aMutex );
      43          82 :     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          82 :     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          82 :     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          82 :     m_bHasClonedSize = sal_False;
      57             : 
      58          82 :     sal_Bool bBackToLoaded = sal_False;
      59          82 :     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          82 :     sal_Bool bSuccess = m_pDocHolder->SetExtent( nAspect, aSize );
      68             : 
      69          82 :     if ( bBackToLoaded )
      70           0 :         changeState( embed::EmbedStates::LOADED );
      71             : 
      72          82 :     if ( !bSuccess )
      73           0 :         throw uno::Exception(); // TODO:
      74          82 : }
      75             : 
      76         202 : 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         202 :     ::osl::MutexGuard aGuard( m_aMutex );
      85         202 :     if ( m_bDisposed )
      86           0 :         throw lang::DisposedException(); // TODO
      87             : 
      88         202 :     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         202 :     if ( m_bHasClonedSize )
      95           0 :         return m_aClonedSize;
      96             : 
      97         202 :     sal_Bool bBackToLoaded = sal_False;
      98         202 :     if ( m_nObjectState == embed::EmbedStates::LOADED )
      99             :     {
     100           2 :         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         200 :     awt::Size aResult;
     107         200 :     sal_Bool bSuccess = m_pDocHolder->GetExtent( nAspect, &aResult );
     108             : 
     109         200 :     if ( bBackToLoaded )
     110           0 :         changeState( embed::EmbedStates::LOADED );
     111             : 
     112         200 :     if ( !bSuccess )
     113           0 :         throw uno::Exception(); // TODO:
     114             : 
     115         202 :     return aResult;
     116             : }
     117             : 
     118         284 : sal_Int32 SAL_CALL OCommonEmbeddedObject::getMapUnit( sal_Int64 nAspect )
     119             :         throw ( uno::Exception,
     120             :                 uno::RuntimeException)
     121             : {
     122         284 :     ::osl::MutexGuard aGuard( m_aMutex );
     123         284 :     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         284 :     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         284 :     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         284 :     if ( m_bHasClonedSize )
     137           0 :         return m_nClonedMapUnit;
     138             : 
     139         284 :     sal_Bool bBackToLoaded = sal_False;
     140         284 :     if ( m_nObjectState == embed::EmbedStates::LOADED )
     141             :     {
     142           2 :         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         282 :     sal_Int32 nResult = m_pDocHolder->GetMapUnit( nAspect );
     149             : 
     150         282 :     if ( bBackToLoaded )
     151           0 :         changeState( embed::EmbedStates::LOADED );
     152             : 
     153         282 :     if ( nResult < 0  )
     154           0 :         throw uno::Exception(); // TODO:
     155             : 
     156         284 :     return nResult;
     157             : }
     158             : 
     159        4544 : 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        4544 :     ::osl::MutexGuard aGuard( m_aMutex );
     168        4544 :     if ( m_bDisposed )
     169           0 :         throw lang::DisposedException(); // TODO
     170             : 
     171        4544 :     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        4544 :     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        4544 :     sal_Bool bBackToLoaded = sal_False;
     183        4544 :     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        4544 :     embed::VisualRepresentation aVisualRepresentation;
     195             : 
     196        4544 :     uno::Reference< embed::XVisualObject > xVisualObject( m_pDocHolder->GetComponent(), uno::UNO_QUERY );
     197        4544 :     if( xVisualObject.is())
     198             :     {
     199        4544 :         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        4544 :     if ( bBackToLoaded )
     222           0 :         changeState( embed::EmbedStates::LOADED );
     223             : 
     224        4544 :     return aVisualRepresentation;
     225             : }
     226             : 
     227             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10