LCOV - code coverage report
Current view: top level - sfx2/source/doc - objembed.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 97 109 89.0 %
Date: 2015-06-13 12:38:46 Functions: 15 16 93.8 %
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/container/XChild.hpp>
      21             : #include <com/sun/star/embed/XEmbedObjectCreator.hpp>
      22             : #include <com/sun/star/embed/XComponentSupplier.hpp>
      23             : #include <com/sun/star/embed/XEmbedPersist.hpp>
      24             : #include <com/sun/star/util/XCloseable.hpp>
      25             : #include <com/sun/star/embed/EmbedStates.hpp>
      26             : 
      27             : #include <sfx2/objsh.hxx>
      28             : #include <sfx2/app.hxx>
      29             : #include "objshimp.hxx"
      30             : #include <sfx2/sfx.hrc>
      31             : #include <sfx2/event.hxx>
      32             : 
      33             : #include <comphelper/seqstream.hxx>
      34             : #include <comphelper/processfactory.hxx>
      35             : #include <comphelper/storagehelper.hxx>
      36             : #include <svtools/embedtransfer.hxx>
      37             : #include <tools/fract.hxx>
      38             : #include <vcl/outdev.hxx>
      39             : #include <vcl/gdimtf.hxx>
      40             : 
      41             : using namespace ::com::sun::star;
      42             : 
      43             : 
      44             : // TODO/LATER: this workaround must be replaced by API in future if possible
      45        3450 : SfxObjectShell* SfxObjectShell::GetParentShellByModel_Impl()
      46             : {
      47        3450 :     SfxObjectShell* pResult = NULL;
      48             : 
      49             :     try {
      50        3450 :         uno::Reference< container::XChild > xChildModel( GetModel(), uno::UNO_QUERY );
      51        3450 :         if ( xChildModel.is() )
      52             :         {
      53        3450 :             uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
      54        3396 :             if ( xParentTunnel.is() )
      55             :             {
      56        2470 :                 SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
      57        2470 :                 pResult = reinterpret_cast<SfxObjectShell*>(xParentTunnel->getSomething(
      58        2470 :                                                 uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
      59        3396 :             }
      60        3450 :         }
      61             :     }
      62          54 :     catch( uno::Exception& )
      63             :     {
      64             :         // TODO: error handling
      65             :     }
      66             : 
      67        3450 :     return pResult;
      68             : }
      69             : 
      70             : 
      71        2446 : Printer* SfxObjectShell::GetDocumentPrinter()
      72             : {
      73        2446 :     SfxObjectShell* pParent = GetParentShellByModel_Impl();
      74        2446 :     if ( pParent )
      75        1786 :         return pParent->GetDocumentPrinter();
      76         660 :     return NULL;
      77             : }
      78             : 
      79             : 
      80        1004 : OutputDevice* SfxObjectShell::GetDocumentRefDev()
      81             : {
      82        1004 :     SfxObjectShell* pParent = GetParentShellByModel_Impl();
      83        1004 :     if ( pParent )
      84         684 :         return pParent->GetDocumentRefDev();
      85         320 :     return NULL;
      86             : }
      87             : 
      88             : 
      89           0 : void SfxObjectShell::OnDocumentPrinterChanged( Printer* /*pNewPrinter*/ )
      90             : {
      91             :     // virtual method
      92           0 : }
      93             : 
      94             : 
      95       38100 : Rectangle SfxObjectShell::GetVisArea( sal_uInt16 nAspect ) const
      96             : {
      97       38100 :     if( nAspect == ASPECT_CONTENT )
      98       38100 :         return pImp->m_aVisArea;
      99           0 :     else if( nAspect == ASPECT_THUMBNAIL )
     100             :     {
     101           0 :         Rectangle aRect;
     102             :         aRect.SetSize( OutputDevice::LogicToLogic( Size( 5000, 5000 ),
     103           0 :                                          MAP_100TH_MM, GetMapUnit() ) );
     104           0 :         return aRect;
     105             :     }
     106           0 :     return Rectangle();
     107             : }
     108             : 
     109             : 
     110        7844 : const Rectangle& SfxObjectShell::GetVisArea() const
     111             : {
     112        7844 :     pImp->m_aVisArea = GetVisArea( ASPECT_CONTENT );
     113        7844 :     return pImp->m_aVisArea;
     114             : }
     115             : 
     116             : 
     117       17647 : void SfxObjectShell::SetVisArea( const Rectangle & rVisArea )
     118             : {
     119       17647 :     if( pImp->m_aVisArea != rVisArea )
     120             :     {
     121       15158 :         pImp->m_aVisArea = rVisArea;
     122       15158 :         if ( GetCreateMode() == SfxObjectCreateMode::EMBEDDED )
     123             :         {
     124        1198 :             if ( IsEnableSetModified() )
     125          49 :                 SetModified( true );
     126             : 
     127        1198 :                SfxGetpApp()->NotifyEvent(SfxEventHint( SFX_EVENT_VISAREACHANGED, GlobalEventConfig::GetEventName(GlobalEventId::VISAREACHANGED), this));
     128             :         }
     129             :     }
     130       17647 : }
     131             : 
     132             : 
     133         880 : void SfxObjectShell::SetVisAreaSize( const Size & rVisSize )
     134             : {
     135         880 :     SetVisArea( Rectangle( GetVisArea().TopLeft(), rVisSize ) );
     136         880 : }
     137             : 
     138             : 
     139          17 : sal_uIntPtr SfxObjectShell::GetMiscStatus() const
     140             : {
     141          17 :     return 0;
     142             : }
     143             : 
     144             : 
     145       67616 : MapUnit SfxObjectShell::GetMapUnit() const
     146             : {
     147       67616 :     return pImp->m_nMapUnit;
     148             : }
     149             : 
     150             : 
     151        2963 : void SfxObjectShell::SetMapUnit( MapUnit nMapUnit )
     152             : {
     153        2963 :     pImp->m_nMapUnit = nMapUnit;
     154        2963 : }
     155             : 
     156             : 
     157          68 : void SfxObjectShell::FillTransferableObjectDescriptor( TransferableObjectDescriptor& rDesc ) const
     158             : {
     159             :     SotClipboardFormatId nClipFormat;
     160         136 :     OUString aAppName, aShortName;
     161          68 :     FillClass( &rDesc.maClassName, &nClipFormat, &aAppName, &rDesc.maTypeName, &aShortName, SOFFICE_FILEFORMAT_CURRENT );
     162             : 
     163          68 :     rDesc.mnViewAspect = ASPECT_CONTENT;
     164          68 :     rDesc.mnOle2Misc = GetMiscStatus();
     165          68 :     rDesc.maSize = OutputDevice::LogicToLogic( GetVisArea().GetSize(), GetMapUnit(), MAP_100TH_MM );
     166          68 :     rDesc.maDragStartPos = Point();
     167          68 :     rDesc.maDisplayName.clear();
     168         136 :     rDesc.mbCanLink = false;
     169          68 : }
     170             : 
     171             : 
     172        4981 : void SfxObjectShell::DoDraw( OutputDevice* pDev,
     173             :                             const Point & rObjPos,
     174             :                             const Size & rSize,
     175             :                             const JobSetup & rSetup,
     176             :                             sal_uInt16 nAspect )
     177             : {
     178        4981 :     MapMode aMod = pDev->GetMapMode();
     179        4981 :     Size aSize = GetVisArea( nAspect ).GetSize();
     180        9962 :     MapMode aWilliMode( GetMapUnit() );
     181        4981 :     aSize = pDev->LogicToLogic( aSize, &aWilliMode, &aMod );
     182        4981 :     if( aSize.Width() && aSize.Height() )
     183             :     {
     184        4981 :         Fraction aXF( rSize.Width(), aSize.Width() );
     185        9962 :         Fraction aYF( rSize.Height(), aSize.Height() );
     186             : 
     187        9962 :         DoDraw_Impl( pDev, rObjPos, aXF, aYF, rSetup, nAspect );
     188        4981 :     }
     189        4981 : }
     190             : 
     191             : 
     192        4981 : void SfxObjectShell::DoDraw_Impl( OutputDevice* pDev,
     193             :                                const Point & rViewPos,
     194             :                                const Fraction & rScaleX,
     195             :                                const Fraction & rScaleY,
     196             :                                const JobSetup & rSetup,
     197             :                                sal_uInt16 nAspect )
     198             : {
     199        4981 :     Rectangle aVisArea  = GetVisArea( nAspect );
     200             :     // MapUnit des Ziels
     201        4981 :     MapMode aMapMode( GetMapUnit() );
     202        4981 :     aMapMode.SetScaleX( rScaleX );
     203        4981 :     aMapMode.SetScaleY( rScaleY );
     204             : 
     205             :     // Target in Pixels
     206        4981 :     Point aOrg   = pDev->LogicToLogic( rViewPos, NULL, &aMapMode );
     207        4981 :     Point aDelta = aOrg - aVisArea.TopLeft();
     208             : 
     209             :     // Origin moved according to the viewable area
     210             :     // Origin set with Scale
     211        4981 :     aMapMode.SetOrigin( aDelta );
     212             : 
     213             :     // Secure the Device settings
     214        4981 :     pDev->Push();
     215             : 
     216        9962 :     vcl::Region aRegion;
     217        4981 :     if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
     218             :     {
     219           0 :         aRegion = pDev->GetClipRegion();
     220           0 :         aRegion = pDev->LogicToPixel( aRegion );
     221             :     }
     222        4981 :     pDev->SetRelativeMapMode( aMapMode );
     223             : 
     224        4981 :     GDIMetaFile * pMtf = pDev->GetConnectMetaFile();
     225        4981 :     if( pMtf )
     226             :     {
     227        4981 :         if( pMtf->IsRecord() && pDev->GetOutDevType() != OUTDEV_PRINTER )
     228        4981 :             pMtf->Stop();
     229             :         else
     230           0 :             pMtf = NULL;
     231             :     }
     232        4981 :     if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
     233             :     {
     234           0 :         aRegion = pDev->PixelToLogic( aRegion );
     235           0 :         pDev->SetClipRegion( aRegion );
     236             :     }
     237        4981 :     if( pMtf )
     238        4981 :         pMtf->Record( pDev );
     239             : 
     240        4981 :     Draw( pDev, rSetup, nAspect );
     241             : 
     242             :     // Restore Device settings
     243        9962 :     pDev->Pop();
     244             : 
     245        4981 : }
     246             : 
     247       22125 : comphelper::EmbeddedObjectContainer& SfxObjectShell::GetEmbeddedObjectContainer() const
     248             : {
     249       22125 :     if ( !pImp->mpObjectContainer )
     250        2255 :         pImp->mpObjectContainer = new comphelper::EmbeddedObjectContainer( const_cast<SfxObjectShell*>(this)->GetStorage(), GetModel() );
     251       22125 :     return *pImp->mpObjectContainer;
     252             : }
     253             : 
     254          13 : void SfxObjectShell::ClearEmbeddedObjects()
     255             : {
     256             :     // frees alle space taken by embedded objects
     257          13 :     DELETEZ( pImp->mpObjectContainer );
     258          13 : }
     259             : 
     260             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11