LCOV - code coverage report
Current view: top level - sfx2/source/doc - objembed.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 97 109 89.0 %
Date: 2012-08-25 Functions: 15 16 93.8 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 93 216 43.1 %

           Branch data     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 <vcl/outdev.hxx>
      38                 :            : #include <vcl/gdimtf.hxx>
      39                 :            : 
      40                 :            : using namespace ::com::sun::star;
      41                 :            : 
      42                 :            : // -----------------------------------------------------------------------
      43                 :            : // TODO/LATER: this workaround must be replaced by API in future if possible
      44                 :       4686 : SfxObjectShell* SfxObjectShell::GetParentShellByModel_Impl()
      45                 :            : {
      46                 :       4686 :     SfxObjectShell* pResult = NULL;
      47                 :            : 
      48                 :            :     try {
      49 [ +  - ][ +  - ]:       4686 :         uno::Reference< container::XChild > xChildModel( GetModel(), uno::UNO_QUERY );
      50         [ +  - ]:       4686 :         if ( xChildModel.is() )
      51                 :            :         {
      52 [ +  - ][ +  - ]:       4686 :             uno::Reference< lang::XUnoTunnel > xParentTunnel( xChildModel->getParent(), uno::UNO_QUERY );
                 [ +  - ]
      53         [ +  + ]:       4686 :             if ( xParentTunnel.is() )
      54                 :            :             {
      55         [ +  - ]:       3408 :                 SvGlobalName aSfxIdent( SFX_GLOBAL_CLASSID );
      56         [ +  - ]:       3408 :                 pResult = reinterpret_cast<SfxObjectShell*>(xParentTunnel->getSomething(
      57 [ +  - ][ +  - ]:       3408 :                                                 uno::Sequence< sal_Int8 >( aSfxIdent.GetByteSequence() ) ) );
         [ +  - ][ +  - ]
      58                 :       4686 :             }
      59         [ #  # ]:       4686 :         }
      60                 :            :     }
      61                 :          0 :     catch( uno::Exception& )
      62                 :            :     {
      63                 :            :         // TODO: error handling
      64                 :            :     }
      65                 :            : 
      66                 :       4686 :     return pResult;
      67                 :            : }
      68                 :            : 
      69                 :            : // -----------------------------------------------------------------------
      70                 :       3408 : Printer* SfxObjectShell::GetDocumentPrinter()
      71                 :            : {
      72                 :       3408 :     SfxObjectShell* pParent = GetParentShellByModel_Impl();
      73         [ +  + ]:       3408 :     if ( pParent )
      74                 :       2556 :         return pParent->GetDocumentPrinter();
      75                 :       3408 :     return NULL;
      76                 :            : }
      77                 :            : 
      78                 :            : // -----------------------------------------------------------------------
      79                 :       1278 : OutputDevice* SfxObjectShell::GetDocumentRefDev()
      80                 :            : {
      81                 :       1278 :     SfxObjectShell* pParent = GetParentShellByModel_Impl();
      82         [ +  + ]:       1278 :     if ( pParent )
      83                 :        852 :         return pParent->GetDocumentRefDev();
      84                 :       1278 :     return NULL;
      85                 :            : }
      86                 :            : 
      87                 :            : // -----------------------------------------------------------------------
      88                 :          0 : void SfxObjectShell::OnDocumentPrinterChanged( Printer* /*pNewPrinter*/ )
      89                 :            : {
      90                 :            :     // virtual method
      91                 :          0 : }
      92                 :            : 
      93                 :            : // -----------------------------------------------------------------------
      94                 :      39098 : Rectangle SfxObjectShell::GetVisArea( sal_uInt16 nAspect ) const
      95                 :            : {
      96         [ +  - ]:      39098 :     if( nAspect == ASPECT_CONTENT )
      97                 :      39098 :         return pImp->m_aVisArea;
      98         [ #  # ]:          0 :     else if( nAspect == ASPECT_THUMBNAIL )
      99                 :            :     {
     100         [ #  # ]:          0 :         Rectangle aRect;
     101                 :            :         aRect.SetSize( OutputDevice::LogicToLogic( Size( 5000, 5000 ),
     102 [ #  # ][ #  # ]:          0 :                                          MAP_100TH_MM, GetMapUnit() ) );
         [ #  # ][ #  # ]
         [ #  # ][ #  # ]
                 [ #  # ]
     103                 :          0 :         return aRect;
     104                 :            :     }
     105                 :      39098 :     return Rectangle();
     106                 :            : }
     107                 :            : 
     108                 :            : // -----------------------------------------------------------------------
     109                 :      11542 : const Rectangle& SfxObjectShell::GetVisArea() const
     110                 :            : {
     111                 :      11542 :     pImp->m_aVisArea = GetVisArea( ASPECT_CONTENT );
     112                 :      11542 :     return pImp->m_aVisArea;
     113                 :            : }
     114                 :            : 
     115                 :            : // -----------------------------------------------------------------------
     116                 :       6189 : void SfxObjectShell::SetVisArea( const Rectangle & rVisArea )
     117                 :            : {
     118         [ +  + ]:       6189 :     if( pImp->m_aVisArea != rVisArea )
     119                 :            :     {
     120                 :       4572 :         pImp->m_aVisArea = rVisArea;
     121         [ +  + ]:       4572 :         if ( GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
     122                 :            :         {
     123         [ +  + ]:       1250 :             if ( IsEnableSetModified() )
     124                 :         33 :                 SetModified( sal_True );
     125                 :            : 
     126 [ +  - ][ +  - ]:       1250 :                SFX_APP()->NotifyEvent(SfxEventHint( SFX_EVENT_VISAREACHANGED, GlobalEventConfig::GetEventName(STR_EVENT_VISAREACHANGED), this));
         [ +  - ][ +  - ]
     127                 :            :         }
     128                 :            :     }
     129                 :       6189 : }
     130                 :            : 
     131                 :            : // -----------------------------------------------------------------------
     132                 :       1278 : void SfxObjectShell::SetVisAreaSize( const Size & rVisSize )
     133                 :            : {
     134 [ +  - ][ +  - ]:       1278 :     SetVisArea( Rectangle( GetVisArea().TopLeft(), rVisSize ) );
     135                 :       1278 : }
     136                 :            : 
     137                 :            : // -----------------------------------------------------------------------
     138                 :          2 : sal_uIntPtr SfxObjectShell::GetMiscStatus() const
     139                 :            : {
     140                 :          2 :     return 0;
     141                 :            : }
     142                 :            : 
     143                 :            : // -----------------------------------------------------------------------
     144                 :      28184 : MapUnit SfxObjectShell::GetMapUnit() const
     145                 :            : {
     146                 :      28184 :     return pImp->m_nMapUnit;
     147                 :            : }
     148                 :            : 
     149                 :            : // -----------------------------------------------------------------------
     150                 :       1553 : void SfxObjectShell::SetMapUnit( MapUnit nMapUnit )
     151                 :            : {
     152                 :       1553 :     pImp->m_nMapUnit = nMapUnit;
     153                 :       1553 : }
     154                 :            : 
     155                 :            : // -----------------------------------------------------------------------
     156                 :         22 : void SfxObjectShell::FillTransferableObjectDescriptor( TransferableObjectDescriptor& rDesc ) const
     157                 :            : {
     158                 :            :     sal_uInt32 nClipFormat;
     159 [ +  - ][ +  - ]:         22 :     String aAppName, aShortName;
     160         [ +  - ]:         22 :     FillClass( &rDesc.maClassName, &nClipFormat, &aAppName, &rDesc.maTypeName, &aShortName, SOFFICE_FILEFORMAT_CURRENT );
     161                 :            : 
     162                 :         22 :     rDesc.mnViewAspect = ASPECT_CONTENT;
     163         [ +  - ]:         22 :     rDesc.mnOle2Misc = GetMiscStatus();
     164 [ +  - ][ +  - ]:         22 :     rDesc.maSize = OutputDevice::LogicToLogic( GetVisArea().GetSize(), GetMapUnit(), MAP_100TH_MM );
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
         [ +  - ][ +  - ]
     165                 :         22 :     rDesc.maDragStartPos = Point();
     166 [ +  - ][ +  - ]:         22 :     rDesc.maDisplayName = String();
                 [ +  - ]
     167 [ +  - ][ +  - ]:         22 :     rDesc.mbCanLink = sal_False;
     168                 :         22 : }
     169                 :            : 
     170                 :            : // -----------------------------------------------------------------------
     171                 :       6847 : void SfxObjectShell::DoDraw( OutputDevice* pDev,
     172                 :            :                             const Point & rObjPos,
     173                 :            :                             const Size & rSize,
     174                 :            :                             const JobSetup & rSetup,
     175                 :            :                             sal_uInt16 nAspect )
     176                 :            : {
     177         [ +  - ]:       6847 :     MapMode aMod = pDev->GetMapMode();
     178 [ +  - ][ +  - ]:       6847 :     Size aSize = GetVisArea( nAspect ).GetSize();
     179 [ +  - ][ +  - ]:       6847 :     MapMode aWilliMode( GetMapUnit() );
     180         [ +  - ]:       6847 :     aSize = pDev->LogicToLogic( aSize, &aWilliMode, &aMod );
     181 [ +  - ][ +  - ]:       6847 :     if( aSize.Width() && aSize.Height() )
                 [ +  - ]
     182                 :            :     {
     183         [ +  - ]:       6847 :         Fraction aXF( rSize.Width(), aSize.Width() );
     184         [ +  - ]:       6847 :         Fraction aYF( rSize.Height(), aSize.Height() );
     185                 :            : 
     186         [ +  - ]:       6847 :         DoDraw_Impl( pDev, rObjPos, aXF, aYF, rSetup, nAspect );
     187 [ +  - ][ +  - ]:       6847 :     }
     188                 :       6847 : }
     189                 :            : 
     190                 :            : // -----------------------------------------------------------------------
     191                 :       6847 : void SfxObjectShell::DoDraw_Impl( OutputDevice* pDev,
     192                 :            :                                const Point & rViewPos,
     193                 :            :                                const Fraction & rScaleX,
     194                 :            :                                const Fraction & rScaleY,
     195                 :            :                                const JobSetup & rSetup,
     196                 :            :                                sal_uInt16 nAspect )
     197                 :            : {
     198         [ +  - ]:       6847 :     Rectangle aVisArea  = GetVisArea( nAspect );
     199                 :            :     // MapUnit des Ziels
     200 [ +  - ][ +  - ]:       6847 :     MapMode aMapMode( GetMapUnit() );
     201         [ +  - ]:       6847 :     aMapMode.SetScaleX( rScaleX );
     202         [ +  - ]:       6847 :     aMapMode.SetScaleY( rScaleY );
     203                 :            : 
     204                 :            :     // Target in Pixels
     205         [ +  - ]:       6847 :     Point aOrg   = pDev->LogicToLogic( rViewPos, NULL, &aMapMode );
     206                 :       6847 :     Point aDelta = aOrg - aVisArea.TopLeft();
     207                 :            : 
     208                 :            :     // Origin moved according to the viewable area
     209                 :            :     // Origin set with Scale
     210         [ +  - ]:       6847 :     aMapMode.SetOrigin( aDelta );
     211                 :            : 
     212                 :            :     // Secure the Device settings
     213         [ +  - ]:       6847 :     pDev->Push();
     214                 :            : 
     215         [ +  - ]:       6847 :     Region aRegion;
     216 [ -  + ][ #  # ]:       6847 :     if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
                 [ -  + ]
     217                 :            :     {
     218 [ #  # ][ #  # ]:          0 :         aRegion = pDev->GetClipRegion();
                 [ #  # ]
     219 [ #  # ][ #  # ]:          0 :         aRegion = pDev->LogicToPixel( aRegion );
                 [ #  # ]
     220                 :            :     }
     221         [ +  - ]:       6847 :     pDev->SetRelativeMapMode( aMapMode );
     222                 :            : 
     223                 :       6847 :     GDIMetaFile * pMtf = pDev->GetConnectMetaFile();
     224         [ +  - ]:       6847 :     if( pMtf )
     225                 :            :     {
     226 [ +  - ][ +  - ]:       6847 :         if( pMtf->IsRecord() && pDev->GetOutDevType() != OUTDEV_PRINTER )
                 [ +  - ]
     227         [ +  - ]:       6847 :             pMtf->Stop();
     228                 :            :         else
     229                 :          0 :             pMtf = NULL;
     230                 :            :     }
     231 [ -  + ][ #  # ]:       6847 :     if( pDev->IsClipRegion() && pDev->GetOutDevType() != OUTDEV_PRINTER )
                 [ -  + ]
     232                 :            :     {
     233 [ #  # ][ #  # ]:          0 :         aRegion = pDev->PixelToLogic( aRegion );
                 [ #  # ]
     234         [ #  # ]:          0 :         pDev->SetClipRegion( aRegion );
     235                 :            :     }
     236         [ +  - ]:       6847 :     if( pMtf )
     237         [ +  - ]:       6847 :         pMtf->Record( pDev );
     238                 :            : 
     239         [ +  - ]:       6847 :     Draw( pDev, rSetup, nAspect );
     240                 :            : 
     241                 :            :     // Restore Device settings
     242 [ +  - ][ +  - ]:       6847 :     pDev->Pop();
                 [ +  - ]
     243                 :            : 
     244                 :       6847 : }
     245                 :            : 
     246                 :      20566 : comphelper::EmbeddedObjectContainer& SfxObjectShell::GetEmbeddedObjectContainer() const
     247                 :            : {
     248         [ +  + ]:      20566 :     if ( !pImp->mpObjectContainer )
     249 [ +  - ][ +  - ]:       2184 :         pImp->mpObjectContainer = new comphelper::EmbeddedObjectContainer( ((SfxObjectShell*)this)->GetStorage(), GetModel() );
                 [ +  - ]
     250                 :      20566 :     return *pImp->mpObjectContainer;
     251                 :            : }
     252                 :            : 
     253                 :         22 : void SfxObjectShell::ClearEmbeddedObjects()
     254                 :            : {
     255                 :            :     // frees alle space taken by embedded objects
     256         [ -  + ]:         22 :     DELETEZ( pImp->mpObjectContainer );
     257                 :         22 : }
     258                 :            : 
     259                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10