LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/graphic - ndgrf.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 142 521 27.3 %
Date: 2012-12-27 Functions: 16 38 42.1 %
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 <hintids.hxx>
      21             : #include <tools/helpers.hxx>
      22             : #include <tools/urlobj.hxx>
      23             : #include <svl/undo.hxx>
      24             : #include <svl/fstathelper.hxx>
      25             : #include <svtools/imap.hxx>
      26             : #include <svtools/filter.hxx>
      27             : #include <sot/storage.hxx>
      28             : #include <sfx2/linkmgr.hxx>
      29             : #include <editeng/boxitem.hxx>
      30             : #include <sot/formats.hxx>
      31             : #include <fmtfsize.hxx>
      32             : #include <fmturl.hxx>
      33             : #include <frmfmt.hxx>
      34             : #include <doc.hxx>
      35             : #include <frmatr.hxx>
      36             : #include <grfatr.hxx>
      37             : #include <swtypes.hxx>
      38             : #include <ndgrf.hxx>
      39             : #include <fmtcol.hxx>
      40             : #include <hints.hxx>
      41             : #include <swbaslnk.hxx>
      42             : #include <pagefrm.hxx>
      43             : #include <editsh.hxx>
      44             : #include <pam.hxx>
      45             : 
      46             : #include <rtl/ustring.hxx>
      47             : #include <unotools/ucbstreamhelper.hxx>
      48             : #include <com/sun/star/embed/ElementModes.hpp>
      49             : #include <com/sun/star/embed/XTransactedObject.hpp>
      50             : #include <vcl/svapp.hxx>
      51             : #include <com/sun/star/io/XSeekable.hpp>
      52             : // #i73788#
      53             : #include <retrieveinputstreamconsumer.hxx>
      54             : 
      55             : using namespace com::sun::star;
      56             : 
      57             : // --------------------
      58             : // SwGrfNode
      59             : // --------------------
      60          41 : SwGrfNode::SwGrfNode(
      61             :         const SwNodeIndex & rWhere,
      62             :         const String& rGrfName, const String& rFltName,
      63             :         const Graphic* pGraphic,
      64             :         SwGrfFmtColl *pGrfColl,
      65             :         SwAttrSet* pAutoAttr ) :
      66             :     SwNoTxtNode( rWhere, ND_GRFNODE, pGrfColl, pAutoAttr ),
      67             :     aGrfObj(),
      68             :     mpReplacementGraphic(0),
      69             :     // #i73788#
      70             :     mbLinkedInputStreamReady( false ),
      71          41 :     mbIsStreamReadOnly( sal_False )
      72             : {
      73          41 :     aGrfObj.SetSwapStreamHdl( LINK( this, SwGrfNode, SwapGraphic ) );
      74             :     bInSwapIn = bChgTwipSize = bChgTwipSizeFromPixel = bLoadLowResGrf =
      75          41 :         bFrameInPaint = bScaleImageMap = sal_False;
      76             : 
      77          41 :     bGrafikArrived = sal_True;
      78          41 :     ReRead(rGrfName,rFltName, pGraphic, 0, sal_False);
      79          41 : }
      80             : 
      81           0 : SwGrfNode::SwGrfNode( const SwNodeIndex & rWhere,
      82             :                           const GraphicObject& rGrfObj,
      83             :                       SwGrfFmtColl *pGrfColl, SwAttrSet* pAutoAttr ) :
      84             :     SwNoTxtNode( rWhere, ND_GRFNODE, pGrfColl, pAutoAttr ),
      85             :     aGrfObj(),
      86             :     mpReplacementGraphic(0),
      87             :     // #i73788#
      88             :     mbLinkedInputStreamReady( false ),
      89           0 :     mbIsStreamReadOnly( sal_False )
      90             : {
      91           0 :     aGrfObj = rGrfObj;
      92           0 :     aGrfObj.SetSwapStreamHdl( LINK( this, SwGrfNode, SwapGraphic ) );
      93           0 :     if( rGrfObj.HasUserData() && rGrfObj.IsSwappedOut() )
      94           0 :         aGrfObj.SetSwapState();
      95             :     bInSwapIn = bChgTwipSize = bChgTwipSizeFromPixel= bLoadLowResGrf =
      96           0 :         bFrameInPaint = bScaleImageMap = sal_False;
      97           0 :     bGrafikArrived = sal_True;
      98           0 : }
      99             : 
     100             : // Konstruktor fuer den SW/G-Reader. Dieser ctor wird verwendet,
     101             : // wenn eine gelinkte Grafik gelesen wird. Sie liest diese NICHT ein.
     102             : 
     103             : 
     104           0 : SwGrfNode::SwGrfNode( const SwNodeIndex & rWhere,
     105             :                       const String& rGrfName, const String& rFltName,
     106             :                       SwGrfFmtColl *pGrfColl,
     107             :                       SwAttrSet* pAutoAttr ) :
     108             :     SwNoTxtNode( rWhere, ND_GRFNODE, pGrfColl, pAutoAttr ),
     109             :     aGrfObj(),
     110             :     mpReplacementGraphic(0),
     111             :     // #i73788#
     112             :     mbLinkedInputStreamReady( false ),
     113           0 :     mbIsStreamReadOnly( sal_False )
     114             : {
     115           0 :     aGrfObj.SetSwapStreamHdl( LINK( this, SwGrfNode, SwapGraphic ) );
     116             : 
     117           0 :     Graphic aGrf; aGrf.SetDefaultType();
     118           0 :     aGrfObj.SetGraphic( aGrf, rGrfName );
     119             : 
     120             :     bInSwapIn = bChgTwipSize = bChgTwipSizeFromPixel = bLoadLowResGrf =
     121           0 :         bFrameInPaint = bScaleImageMap = sal_False;
     122           0 :     bGrafikArrived = sal_True;
     123             : 
     124           0 :     InsertLink( rGrfName, rFltName );
     125           0 :     if( IsLinkedFile() )
     126             :     {
     127           0 :         INetURLObject aUrl( rGrfName );
     128           0 :         if( INET_PROT_FILE == aUrl.GetProtocol() &&
     129           0 :             FStatHelper::IsDocument( aUrl.GetMainURL( INetURLObject::NO_DECODE ) ))
     130             :         {
     131             :             // File vorhanden, Verbindung herstellen ohne ein Update
     132           0 :             ((SwBaseLink*)&refLink)->Connect();
     133           0 :         }
     134           0 :     }
     135           0 : }
     136             : 
     137          41 : sal_Bool SwGrfNode::ReRead(
     138             :     const String& rGrfName, const String& rFltName,
     139             :     const Graphic* pGraphic, const GraphicObject* pGrfObj,
     140             :     sal_Bool bNewGrf )
     141             : {
     142          41 :     sal_Bool bReadGrf = sal_False, bSetTwipSize = sal_True;
     143          41 :     delete mpReplacementGraphic;
     144          41 :     mpReplacementGraphic = 0;
     145             : 
     146             :     OSL_ENSURE( pGraphic || pGrfObj || rGrfName.Len(),
     147             :             "GraphicNode without a name, Graphic or GraphicObject" );
     148             : 
     149             :     // ReadRead mit Namen
     150          41 :     if( refLink.Is() )
     151             :     {
     152             :         OSL_ENSURE( !bInSwapIn, "ReRead: stehe noch im SwapIn" );
     153             : 
     154           0 :         if( rGrfName.Len() )
     155             :         {
     156             :             // Besonderheit: steht im FltNamen DDE, handelt es sich um eine
     157             :             //                  DDE-gelinkte Grafik
     158           0 :             String sCmd( rGrfName );
     159           0 :             if( rFltName.Len() )
     160             :             {
     161             :                 sal_uInt16 nNewType;
     162           0 :                 if( rFltName.EqualsAscii( "DDE" ))
     163           0 :                     nNewType = OBJECT_CLIENT_DDE;
     164             :                 else
     165             :                 {
     166           0 :                     sfx2::MakeLnkName( sCmd, 0, rGrfName, aEmptyStr, &rFltName );
     167           0 :                     nNewType = OBJECT_CLIENT_GRF;
     168             :                 }
     169             : 
     170           0 :                 if( nNewType != refLink->GetObjType() )
     171             :                 {
     172           0 :                     refLink->Disconnect();
     173           0 :                     ((SwBaseLink*)&refLink)->SetObjType( nNewType );
     174             :                 }
     175             :             }
     176             : 
     177           0 :             refLink->SetLinkSourceName( sCmd );
     178             :         }
     179             :         else        // kein Name mehr, Link aufheben
     180             :         {
     181           0 :             GetDoc()->GetLinkManager().Remove( refLink );
     182           0 :             refLink.Clear();
     183             :         }
     184             : 
     185           0 :         if( pGraphic )
     186             :         {
     187           0 :             aGrfObj.SetGraphic( *pGraphic, rGrfName );
     188           0 :             bReadGrf = sal_True;
     189             :         }
     190           0 :         else if( pGrfObj )
     191             :         {
     192           0 :             aGrfObj = *pGrfObj;
     193           0 :             if( pGrfObj->HasUserData() && pGrfObj->IsSwappedOut() )
     194           0 :                 aGrfObj.SetSwapState();
     195           0 :             aGrfObj.SetLink( rGrfName );
     196           0 :             bReadGrf = sal_True;
     197             :         }
     198             :         else
     199             :         {
     200             :             // MIB 25.02.97: Daten der alten Grafik zuruecksetzen, damit
     201             :             // die korrekte Ersatz-Darstellung erscheint, wenn die
     202             :             // der neue Link nicht geladen werden konnte.
     203           0 :             Graphic aGrf; aGrf.SetDefaultType();
     204           0 :             aGrfObj.SetGraphic( aGrf, rGrfName );
     205             : 
     206           0 :             if( refLink.Is() )
     207             :             {
     208           0 :                 if( getLayoutFrm( GetDoc()->GetCurrentLayout() ) )
     209             :                 {
     210           0 :                     SwMsgPoolItem aMsgHint( RES_GRF_REREAD_AND_INCACHE );
     211           0 :                     ModifyNotification( &aMsgHint, &aMsgHint );
     212             :                 }
     213             :                 // #i59688#
     214             :                 // do not load linked graphic, if it isn't a new linked graphic.
     215             : //                else {
     216           0 :                 else if ( bNewGrf )
     217             :                 {
     218             :                     //TODO refLink->setInputStream(getInputStream());
     219           0 :                     ((SwBaseLink*)&refLink)->SwapIn();
     220             :                 }
     221             :             }
     222           0 :             bSetTwipSize = sal_False;
     223             :         }
     224             :     }
     225          41 :     else if( pGraphic && !rGrfName.Len() )
     226             :     {
     227             :         // MIB 27.02.2001: Old stream must be deleted before the new one is set.
     228          40 :         if( HasStreamName() )
     229           0 :             DelStreamName();
     230             : 
     231          40 :         aGrfObj.SetGraphic( *pGraphic );
     232          40 :         bReadGrf = sal_True;
     233             :     }
     234           1 :     else if( pGrfObj && !rGrfName.Len() )
     235             :     {
     236             :         // MIB 27.02.2001: Old stream must be deleted before the new one is set.
     237           0 :         if( HasStreamName() )
     238           0 :             DelStreamName();
     239             : 
     240           0 :         aGrfObj = *pGrfObj;
     241           0 :         if( pGrfObj->HasUserData() && pGrfObj->IsSwappedOut() )
     242           0 :             aGrfObj.SetSwapState();
     243           0 :         bReadGrf = sal_True;
     244             :     }
     245             :         // Import einer Grafik:
     246             :         // Ist die Grafik bereits geladen?
     247           1 :     else if( !bNewGrf && GRAPHIC_NONE != aGrfObj.GetType() )
     248           0 :         return sal_True;
     249             : 
     250             :     else
     251             :     {
     252           1 :         if( HasStreamName() )
     253           0 :             DelStreamName();
     254             : 
     255             :         // einen neuen Grafik-Link anlegen
     256           1 :         InsertLink( rGrfName, rFltName );
     257             : 
     258           1 :         if( GetNodes().IsDocNodes() )
     259             :         {
     260           1 :             if( pGraphic )
     261             :             {
     262           0 :                 aGrfObj.SetGraphic( *pGraphic, rGrfName );
     263           0 :                 bReadGrf = sal_True;
     264             :                 // Verbindung herstellen ohne ein Update; Grafik haben wir!
     265           0 :                 ((SwBaseLink*)&refLink)->Connect();
     266             :             }
     267           1 :             else if( pGrfObj )
     268             :             {
     269           0 :                 aGrfObj = *pGrfObj;
     270           0 :                 aGrfObj.SetLink( rGrfName );
     271           0 :                 bReadGrf = sal_True;
     272             :                 // Verbindung herstellen ohne ein Update; Grafik haben wir!
     273           0 :                 ((SwBaseLink*)&refLink)->Connect();
     274             :             }
     275             :             else
     276             :             {
     277             :                 // MIB 25.02.97: Daten der alten Grafik zuruecksetzen, damit
     278             :                 // die korrekte Ersatz-Darstellung erscheint, wenn die
     279             :                 // der neue Kink nicht geladen werden konnte.
     280           1 :                 Graphic aGrf; aGrf.SetDefaultType();
     281           1 :                 aGrfObj.SetGraphic( aGrf, rGrfName );
     282             :                 // #i59688# - do not load linked graphic, if it isn't a new linked graphic.
     283           1 :                 if ( bNewGrf )
     284             :                 {
     285           0 :                     ((SwBaseLink*)&refLink)->SwapIn();
     286           1 :                 }
     287             :             }
     288             :         }
     289             :     }
     290             : 
     291             :     // Bug 39281: Size nicht sofort loeschen - Events auf ImageMaps
     292             :     //            sollten nicht beim Austauschen nicht ins "leere greifen"
     293          41 :     if( bSetTwipSize )
     294          41 :         SetTwipSize( ::GetGraphicSizeTwip( aGrfObj.GetGraphic(), 0 ) );
     295             : 
     296             :     // erzeuge noch einen Update auf die Frames
     297          41 :     if( bReadGrf && bNewGrf )
     298             :     {
     299           0 :         SwMsgPoolItem aMsgHint( RES_UPDATE_ATTR );
     300           0 :         ModifyNotification( &aMsgHint, &aMsgHint );
     301             :     }
     302             : 
     303          41 :     return bReadGrf;
     304             : }
     305             : 
     306             : 
     307          60 : SwGrfNode::~SwGrfNode()
     308             : {
     309          20 :     delete mpReplacementGraphic;
     310          20 :     mpReplacementGraphic = 0;
     311             : 
     312             :     // #i73788#
     313          20 :     mpThreadConsumer.reset();
     314             : 
     315          20 :     SwDoc* pDoc = GetDoc();
     316          20 :     if( refLink.Is() )
     317             :     {
     318             :         OSL_ENSURE( !bInSwapIn, "DTOR: stehe noch im SwapIn" );
     319           1 :         pDoc->GetLinkManager().Remove( refLink );
     320           1 :         refLink->Disconnect();
     321             :     }
     322             :     else
     323             :     {
     324             :         // #i40014# - A graphic node, which are in linked
     325             :         // section, whose link is another section is the document, doesn't
     326             :         // have to remove the stream from the storage.
     327             :         // Because it's hard to detect this case here and it would only fix
     328             :         // one problem with shared graphic files - there are also problems,
     329             :         // a certain graphic file is referenced by two independent graphic nodes,
     330             :         // brush item or drawing objects, the stream isn't no longer removed here.
     331             :         // To do this stuff correct, a reference counting on shared streams
     332             :         // inside one document have to be implemented.
     333             : //        if( !pDoc->IsInDtor() && HasStreamName() )
     334             : //          DelStreamName();
     335             :     }
     336             :     //#39289# Die Frames muessen hier bereits geloescht weil der DTor der
     337             :     //Frms die Grafik noch fuer StopAnimation braucht.
     338          20 :     if( GetDepends() )
     339           0 :         DelFrms();
     340          40 : }
     341             : 
     342             : 
     343           0 : const GraphicObject* SwGrfNode::GetReplacementGrfObj() const
     344             : {
     345           0 :     if(!mpReplacementGraphic)
     346             :     {
     347           0 :         const SvgDataPtr& rSvgDataPtr = GetGrfObj().GetGraphic().getSvgData();
     348             : 
     349           0 :         if(rSvgDataPtr.get())
     350             :         {
     351           0 :             const_cast< SwGrfNode* >(this)->mpReplacementGraphic = new GraphicObject(rSvgDataPtr->getReplacement());
     352             :         }
     353             :     }
     354             : 
     355           0 :     return mpReplacementGraphic;
     356             : }
     357             : 
     358           0 : SwCntntNode *SwGrfNode::SplitCntntNode( const SwPosition & )
     359             : {
     360           0 :     return this;
     361             : }
     362             : 
     363             : 
     364          41 : SwGrfNode * SwNodes::MakeGrfNode( const SwNodeIndex & rWhere,
     365             :                                 const String& rGrfName,
     366             :                                 const String& rFltName,
     367             :                                 const Graphic* pGraphic,
     368             :                                 SwGrfFmtColl* pGrfColl,
     369             :                                 SwAttrSet* pAutoAttr,
     370             :                                 sal_Bool bDelayed )
     371             : {
     372             :     OSL_ENSURE( pGrfColl, "MakeGrfNode: Formatpointer ist 0." );
     373             :     SwGrfNode *pNode;
     374             :     // Delayed erzeugen nur aus dem SW/G-Reader
     375          41 :     if( bDelayed )
     376             :         pNode = new SwGrfNode( rWhere, rGrfName,
     377           0 :                                 rFltName, pGrfColl, pAutoAttr );
     378             :     else
     379             :         pNode = new SwGrfNode( rWhere, rGrfName,
     380          41 :                                 rFltName, pGraphic, pGrfColl, pAutoAttr );
     381          41 :     return pNode;
     382             : }
     383             : 
     384           0 : SwGrfNode * SwNodes::MakeGrfNode( const SwNodeIndex & rWhere,
     385             :                                 const GraphicObject& rGrfObj,
     386             :                                 SwGrfFmtColl* pGrfColl,
     387             :                                 SwAttrSet* pAutoAttr )
     388             : {
     389             :     OSL_ENSURE( pGrfColl, "MakeGrfNode: Formatpointer ist 0." );
     390           0 :     return new SwGrfNode( rWhere, rGrfObj, pGrfColl, pAutoAttr );
     391             : }
     392             : 
     393             : 
     394          19 : Size SwGrfNode::GetTwipSize() const
     395             : {
     396          19 :     return nGrfSize;
     397             : }
     398             : 
     399           0 : sal_Bool SwGrfNode::ImportGraphic( SvStream& rStrm )
     400             : {
     401           0 :     Graphic aGraphic;
     402           0 :     const String aURL(aGrfObj.GetUserData());
     403             : 
     404           0 :     if(!GraphicFilter::GetGraphicFilter().ImportGraphic(aGraphic, aURL, rStrm))
     405             :     {
     406           0 :         delete mpReplacementGraphic;
     407           0 :         mpReplacementGraphic = 0;
     408             : 
     409           0 :         aGrfObj.SetGraphic( aGraphic );
     410           0 :         aGrfObj.SetUserData( aURL );
     411           0 :         return sal_True;
     412             :     }
     413             : 
     414           0 :     return sal_False;
     415             : }
     416             : 
     417             : // Returnwert:
     418             : // -1 : ReRead erfolgreich
     419             : //  0 : nicht geladen
     420             : //  1 : Einlesen erfolgreich
     421             : 
     422           8 : short SwGrfNode::SwapIn( sal_Bool bWaitForData )
     423             : {
     424           8 :     if( bInSwapIn )                 // nicht rekuriv!!
     425           0 :         return !aGrfObj.IsSwappedOut();
     426             : 
     427           8 :     short nRet = 0;
     428           8 :     bInSwapIn = sal_True;
     429           8 :     SwBaseLink* pLink = (SwBaseLink*)(::sfx2::SvBaseLink*) refLink;
     430             : 
     431           8 :     if( pLink )
     432             :     {
     433           0 :         if( GRAPHIC_NONE == aGrfObj.GetType() ||
     434           0 :             GRAPHIC_DEFAULT == aGrfObj.GetType() )
     435             :         {
     436             :             // noch nicht geladener Link
     437             :             //TODO pLink->setInputStream(getInputStream());
     438           0 :             if( pLink->SwapIn( bWaitForData ) )
     439           0 :                 nRet = -1;
     440           0 :             else if( GRAPHIC_DEFAULT == aGrfObj.GetType() )
     441             :             {
     442             :                 // keine default Bitmap mehr, also neu Painten!
     443           0 :                 delete mpReplacementGraphic;
     444           0 :                 mpReplacementGraphic = 0;
     445             : 
     446           0 :                 aGrfObj.SetGraphic( Graphic() );
     447           0 :                 SwMsgPoolItem aMsgHint( RES_GRAPHIC_PIECE_ARRIVED );
     448           0 :                 ModifyNotification( &aMsgHint, &aMsgHint );
     449             :             }
     450             :         }
     451           0 :         else if( aGrfObj.IsSwappedOut() ) {
     452             :             // nachzuladender Link
     453             :             //TODO pLink->setInputStream(getInputStream());
     454           0 :             nRet = pLink->SwapIn( bWaitForData ) ? 1 : 0;
     455             :         }
     456             :         else
     457           0 :             nRet = 1;
     458             :     }
     459           8 :     else if( aGrfObj.IsSwappedOut() )
     460             :     {
     461             :         // Die Grafik ist im Storage oder im TempFile drin
     462           0 :         if( !HasStreamName() )
     463           0 :             nRet = (short)aGrfObj.SwapIn();
     464             :         else
     465             :         {
     466             : 
     467             :             // #i48434# - usage of new method <_GetStreamForEmbedGrf(..)>
     468             :             try
     469             :             {
     470             :                 // #i53025# - needed correction of new method <_GetStreamForEmbedGrf(..)>
     471           0 :                 String aStrmName, aPicStgName;
     472           0 :                 _GetStreamStorageNames( aStrmName, aPicStgName );
     473           0 :                 uno::Reference < embed::XStorage > refPics = _GetDocSubstorageOrRoot( aPicStgName );
     474           0 :                 SvStream* pStrm = _GetStreamForEmbedGrf( refPics, aStrmName );
     475           0 :                 if ( pStrm )
     476             :                 {
     477           0 :                     if ( ImportGraphic( *pStrm ) )
     478           0 :                         nRet = 1;
     479           0 :                     delete pStrm;
     480           0 :                 }
     481             :             }
     482           0 :             catch (const uno::Exception&)
     483             :             {
     484             :                 // #i48434#
     485             :                 OSL_FAIL( "<SwGrfNode::SwapIn(..)> - unhandled exception!" );
     486             :             }
     487             :         }
     488             : 
     489           0 :         if( 1 == nRet )
     490             :         {
     491           0 :             SwMsgPoolItem aMsg( RES_GRAPHIC_SWAPIN );
     492           0 :             ModifyNotification( &aMsg, &aMsg );
     493             :         }
     494             :     }
     495             :     else
     496           8 :         nRet = 1;
     497             :     OSL_ENSURE( nRet, "Grafik kann nicht eingeswapt werden" );
     498             : 
     499           8 :     if( nRet )
     500             :     {
     501           8 :         if( !nGrfSize.Width() && !nGrfSize.Height() )
     502           0 :             SetTwipSize( ::GetGraphicSizeTwip( aGrfObj.GetGraphic(), 0 ) );
     503             :     }
     504           8 :     bInSwapIn = sal_False;
     505           8 :     return nRet;
     506             : }
     507             : 
     508             : 
     509           0 : short SwGrfNode::SwapOut()
     510             : {
     511           0 :     if( aGrfObj.GetType() != GRAPHIC_DEFAULT &&
     512           0 :         aGrfObj.GetType() != GRAPHIC_NONE &&
     513           0 :         !aGrfObj.IsSwappedOut() && !bInSwapIn )
     514             :     {
     515           0 :         if( !refLink.Is() )
     516             :         {
     517             :             // Das Swapping brauchen wir nur fuer Embedded Pictures
     518             :             // Die Grafik wird in eine TempFile geschrieben, wenn
     519             :             // sie frisch eingefuegt war, d.h. wenn es noch keinen
     520             :             // Streamnamen im Storage gibt.
     521           0 :             if( !HasStreamName() )
     522           0 :                 if( !aGrfObj.SwapOut() )
     523           0 :                     return 0;
     524             :         }
     525             :         // Geschriebene Grafiken oder Links werden jetzt weggeschmissen
     526           0 :         return (short) aGrfObj.SwapOut( NULL );
     527             :     }
     528           0 :     return 1;
     529             : }
     530             : 
     531             : 
     532           0 : bool SwGrfNode::GetFileFilterNms( String* pFileNm, String* pFilterNm ) const
     533             : {
     534           0 :     bool bRet = false;
     535           0 :     if( refLink.Is() && refLink->GetLinkManager() )
     536             :     {
     537           0 :         sal_uInt16 nType = refLink->GetObjType();
     538           0 :         if( OBJECT_CLIENT_GRF == nType )
     539             :             bRet = refLink->GetLinkManager()->GetDisplayNames(
     540           0 :                     refLink, 0, pFileNm, 0, pFilterNm );
     541           0 :         else if( OBJECT_CLIENT_DDE == nType && pFileNm && pFilterNm )
     542             :         {
     543           0 :             String sApp, sTopic, sItem;
     544           0 :             if( refLink->GetLinkManager()->GetDisplayNames(
     545           0 :                     refLink, &sApp, &sTopic, &sItem ) )
     546             :             {
     547           0 :                 ( *pFileNm = sApp ) += sfx2::cTokenSeperator;
     548           0 :                 ( *pFileNm += sTopic ) += sfx2::cTokenSeperator;
     549           0 :                 *pFileNm += sItem;
     550           0 :                 pFilterNm->AssignAscii( RTL_CONSTASCII_STRINGPARAM( "DDE" ));
     551           0 :                 bRet = true;
     552           0 :             }
     553             :         }
     554             :     }
     555           0 :     return bRet;
     556             : }
     557             : 
     558             : 
     559             : // Eine Grafik Undo-faehig machen. Falls sie sich bereits in
     560             : // einem Storage befindet, muss sie geladen werden.
     561             : 
     562           0 : sal_Bool SwGrfNode::SavePersistentData()
     563             : {
     564           0 :     if( refLink.Is() )
     565             :     {
     566             :         OSL_ENSURE( !bInSwapIn, "SavePersistentData: stehe noch im SwapIn" );
     567           0 :         GetDoc()->GetLinkManager().Remove( refLink );
     568           0 :         return sal_True;
     569             :     }
     570             : 
     571             :     // Erst mal reinswappen, falls sie im Storage ist
     572           0 :     if( HasStreamName() && !SwapIn() )
     573           0 :         return sal_False;
     574             : 
     575             :     // #i44367#
     576             :     // Do not delete graphic file in storage, because the graphic file could
     577             :     // be referenced by other graphic nodes.
     578             :     // Because it's hard to detect this case here and it would only fix
     579             :     // one problem with shared graphic files - there are also problems,
     580             :     // a certain graphic file is referenced by two independent graphic nodes,
     581             :     // brush item or drawing objects, the stream isn't no longer removed here.
     582             :     // To do this stuff correct, a reference counting on shared streams
     583             :     // inside one document have to be implemented.
     584             :     // Important note: see also fix for #i40014#
     585             : //    if( HasStreamName() )
     586             : //        DelStreamName();
     587             : 
     588             :     // Und in TempFile rausswappen
     589           0 :     return (sal_Bool) SwapOut();
     590             : }
     591             : 
     592             : 
     593           0 : sal_Bool SwGrfNode::RestorePersistentData()
     594             : {
     595           0 :     if( refLink.Is() )
     596             :     {
     597           0 :         IDocumentLinksAdministration* pIDLA = getIDocumentLinksAdministration();
     598           0 :         refLink->SetVisible( pIDLA->IsVisibleLinks() );
     599           0 :         pIDLA->GetLinkManager().InsertDDELink( refLink );
     600           0 :         if( getIDocumentLayoutAccess()->GetCurrentLayout() )    //swmod 080218
     601           0 :             refLink->Update();
     602             :     }
     603           0 :     return sal_True;
     604             : }
     605             : 
     606             : 
     607           1 : void SwGrfNode::InsertLink( const String& rGrfName, const String& rFltName )
     608             : {
     609           1 :     refLink = new SwBaseLink( sfx2::LINKUPDATE_ONCALL, FORMAT_GDIMETAFILE, this );
     610             : 
     611           1 :     IDocumentLinksAdministration* pIDLA = getIDocumentLinksAdministration();
     612           1 :     if( GetNodes().IsDocNodes() )
     613             :     {
     614           1 :         refLink->SetVisible( pIDLA->IsVisibleLinks() );
     615           1 :         if( rFltName.EqualsAscii( "DDE" ))
     616             :         {
     617           0 :             sal_uInt16 nTmp = 0;
     618           0 :             String sApp, sTopic, sItem;
     619           0 :             sApp = rGrfName.GetToken( 0, sfx2::cTokenSeperator, nTmp );
     620           0 :             sTopic = rGrfName.GetToken( 0, sfx2::cTokenSeperator, nTmp );
     621           0 :             sItem = rGrfName.Copy( nTmp );
     622           0 :             pIDLA->GetLinkManager().InsertDDELink( refLink,
     623           0 :                                             sApp, sTopic, sItem );
     624             :         }
     625             :         else
     626             :         {
     627           1 :             sal_Bool bSync = rFltName.EqualsAscii( "SYNCHRON" );
     628           1 :             refLink->SetSynchron( bSync );
     629           1 :             refLink->SetContentType( SOT_FORMATSTR_ID_SVXB );
     630             : 
     631           1 :             pIDLA->GetLinkManager().InsertFileLink( *refLink,
     632             :                                             OBJECT_CLIENT_GRF, rGrfName,
     633           2 :                                 (!bSync && rFltName.Len() ? &rFltName : 0) );
     634             :         }
     635             :     }
     636           1 :     aGrfObj.SetLink( rGrfName );
     637           1 : }
     638             : 
     639             : 
     640           0 : void SwGrfNode::ReleaseLink()
     641             : {
     642           0 :     if( refLink.Is() )
     643             :     {
     644             :         {
     645           0 :             bInSwapIn = sal_True;
     646           0 :             SwBaseLink* pLink = (SwBaseLink*)(::sfx2::SvBaseLink*) refLink;
     647             :             //TODO pLink->setInputStream(getInputStream());
     648           0 :             pLink->SwapIn( sal_True, sal_True );
     649           0 :             bInSwapIn = sal_False;
     650             :         }
     651           0 :         getIDocumentLinksAdministration()->GetLinkManager().Remove( refLink );
     652           0 :         refLink.Clear();
     653           0 :         aGrfObj.SetLink();
     654             :     }
     655           0 : }
     656             : 
     657             : 
     658          41 : void SwGrfNode::SetTwipSize( const Size& rSz )
     659             : {
     660          41 :     nGrfSize = rSz;
     661          41 :     if( IsScaleImageMap() && nGrfSize.Width() && nGrfSize.Height() )
     662             :     {
     663             :         // Image-Map an Grafik-Groesse anpassen
     664           0 :         ScaleImageMap();
     665             : 
     666             :         // Image-Map nicht noch einmal skalieren
     667           0 :         SetScaleImageMap( sal_False );
     668             :     }
     669          41 : }
     670             : 
     671           0 : void SwGrfNode::ScaleImageMap()
     672             : {
     673           0 :     if( !nGrfSize.Width() || !nGrfSize.Height() )
     674             :         return;
     675             : 
     676             :     // dann die Image-Map skalieren
     677           0 :     SwFrmFmt* pFmt = GetFlyFmt();
     678             : 
     679           0 :     if( !pFmt )
     680             :         return;
     681             : 
     682           0 :     SwFmtURL aURL( pFmt->GetURL() );
     683           0 :     if ( !aURL.GetMap() )
     684             :         return;
     685             : 
     686           0 :     bool bScale = false;
     687           0 :     Fraction aScaleX( 1, 1 );
     688           0 :     Fraction aScaleY( 1, 1 );
     689             : 
     690           0 :     const SwFmtFrmSize& rFrmSize = pFmt->GetFrmSize();
     691           0 :     const SvxBoxItem& rBox = pFmt->GetBox();
     692             : 
     693           0 :     if( !rFrmSize.GetWidthPercent() )
     694             :     {
     695           0 :         SwTwips nWidth = rFrmSize.GetWidth();
     696             : 
     697           0 :         nWidth -= rBox.CalcLineSpace(BOX_LINE_LEFT) +
     698           0 :                   rBox.CalcLineSpace(BOX_LINE_RIGHT);
     699             : 
     700             :         OSL_ENSURE( nWidth>0, "Gibt es 0 twip breite Grafiken!?" );
     701             : 
     702           0 :         if( nGrfSize.Width() != nWidth )
     703             :         {
     704           0 :             aScaleX = Fraction( nGrfSize.Width(), nWidth );
     705           0 :             bScale = true;
     706             :         }
     707             :     }
     708           0 :     if( !rFrmSize.GetHeightPercent() )
     709             :     {
     710           0 :         SwTwips nHeight = rFrmSize.GetHeight();
     711             : 
     712           0 :         nHeight -= rBox.CalcLineSpace(BOX_LINE_TOP) +
     713           0 :                    rBox.CalcLineSpace(BOX_LINE_BOTTOM);
     714             : 
     715             :         OSL_ENSURE( nHeight>0, "Gibt es 0 twip hohe Grafiken!?" );
     716             : 
     717           0 :         if( nGrfSize.Height() != nHeight )
     718             :         {
     719           0 :             aScaleY = Fraction( nGrfSize.Height(), nHeight );
     720           0 :             bScale = true;
     721             :         }
     722             :     }
     723             : 
     724           0 :     if( bScale )
     725             :     {
     726           0 :         aURL.GetMap()->Scale( aScaleX, aScaleY );
     727           0 :         pFmt->SetFmtAttr( aURL );
     728           0 :     }
     729             : }
     730             : 
     731             : 
     732           0 : void SwGrfNode::DelStreamName()
     733             : {
     734           0 :     if( HasStreamName() )
     735             :     {
     736             :         // Dann die Grafik im Storage loeschen
     737           0 :         uno::Reference < embed::XStorage > xDocStg = GetDoc()->GetDocStorage();
     738           0 :         if( xDocStg.is() )
     739             :         {
     740             :             try
     741             :             {
     742           0 :                 String aPicStgName, aStrmName;
     743           0 :                 _GetStreamStorageNames( aStrmName, aPicStgName );
     744           0 :                 uno::Reference < embed::XStorage > refPics = xDocStg;
     745           0 :                 if ( aPicStgName.Len() )
     746           0 :                     refPics = xDocStg->openStorageElement( aPicStgName, embed::ElementModes::READWRITE );
     747           0 :                 refPics->removeElement( aStrmName );
     748           0 :                 uno::Reference < embed::XTransactedObject > xTrans( refPics, uno::UNO_QUERY );
     749           0 :                 if ( xTrans.is() )
     750           0 :                     xTrans->commit();
     751             :             }
     752           0 :             catch (const uno::Exception&)
     753             :             {
     754             :                 // #i48434#
     755             :                 OSL_FAIL( "<SwGrfNode::DelStreamName()> - unhandled exception!" );
     756             :             }
     757             :         }
     758             : 
     759           0 :         aGrfObj.SetUserData();
     760             :     }
     761           0 : }
     762             : 
     763             : /** helper method to get a substorage of the document storage for readonly access.
     764             : 
     765             :     OD, MAV 2005-08-17 #i53025#
     766             :     A substorage with the specified name will be opened readonly. If the provided
     767             :     name is empty the root storage will be returned.
     768             : */
     769           0 : uno::Reference< embed::XStorage > SwGrfNode::_GetDocSubstorageOrRoot( const String& aStgName ) const
     770             : {
     771             :     uno::Reference < embed::XStorage > refStor =
     772           0 :         const_cast<SwGrfNode*>(this)->GetDoc()->GetDocStorage();
     773             :     OSL_ENSURE( refStor.is(), "Kein Storage am Doc" );
     774             : 
     775           0 :     if ( aStgName.Len() )
     776             :     {
     777           0 :         if( refStor.is() )
     778           0 :             return refStor->openStorageElement( aStgName, embed::ElementModes::READ );
     779             :     }
     780             : 
     781           0 :     return refStor;
     782             : }
     783             : 
     784             : /** helper method to determine stream for the embedded graphic.
     785             : 
     786             :     OD 2005-05-04 #i48434#
     787             :     Important note: caller of this method has to handle the thrown exceptions
     788             :     OD, MAV 2005-08-17 #i53025#
     789             :     Storage, which should contain the stream of the embedded graphic, is
     790             :     provided via parameter. Otherwise the returned stream will be closed
     791             :     after the the method returns, because its parent stream is closed and deleted.
     792             :     Proposed name of embedded graphic stream is also provided by parameter.
     793             : 
     794             :     @author OD
     795             : */
     796           0 : SvStream* SwGrfNode::_GetStreamForEmbedGrf(
     797             :             const uno::Reference< embed::XStorage >& _refPics,
     798             :             String& _aStrmName ) const
     799             : {
     800           0 :     SvStream* pStrm( 0L );
     801             : 
     802           0 :     if( _refPics.is() && _aStrmName.Len() )
     803             :     {
     804             :         // If stream doesn't exist in the storage, try access the graphic file by
     805             :         // re-generating its name.
     806             :         // A save action can have changed the filename of the embedded graphic,
     807             :         // because a changed unique ID of the graphic is calculated.
     808             :         // --> recursive calls of <GetUniqueID()> have to be avoided.
     809             :         // Thus, use local static boolean to assure this.
     810           0 :         if ( !_refPics->hasByName( _aStrmName ) ||
     811           0 :                !_refPics->isStreamElement( _aStrmName ) )
     812             :         {
     813           0 :             xub_StrLen nExtPos = _aStrmName.Search( '.' );
     814           0 :             String aExtStr = _aStrmName.Copy( nExtPos );
     815           0 :             if ( GetGrfObj().GetType() != GRAPHIC_NONE )
     816             :             {
     817           0 :                 _aStrmName = rtl::OStringToOUString(GetGrfObj().GetUniqueID(),
     818           0 :                     RTL_TEXTENCODING_ASCII_US);
     819           0 :                 _aStrmName += aExtStr;
     820           0 :             }
     821             :         }
     822             : 
     823             :         // assure that graphic file exist in the storage.
     824           0 :         if ( _refPics->hasByName( _aStrmName ) &&
     825           0 :              _refPics->isStreamElement( _aStrmName ) )
     826             :         {
     827           0 :             uno::Reference < io::XStream > refStrm = _refPics->openStreamElement( _aStrmName, embed::ElementModes::READ );
     828           0 :             pStrm = utl::UcbStreamHelper::CreateStream( refStrm );
     829             :         }
     830             :         else
     831             :         {
     832             :             OSL_FAIL( "<SwGrfNode::_GetStreamForEmbedGrf(..)> - embedded graphic file not found!" );
     833             :         }
     834             :     }
     835             : 
     836           0 :     return pStrm;
     837             : }
     838             : 
     839             : 
     840             : // #i53025# - stream couldn't be in a 3.1 - 5.2 storage any more.
     841             : // Thus, removing corresponding code.
     842           0 : void SwGrfNode::_GetStreamStorageNames( String& rStrmName,
     843             :                                         String& rStorName ) const
     844             : {
     845           0 :     rStorName.Erase();
     846           0 :     rStrmName.Erase();
     847             : 
     848           0 :     String aUserData( aGrfObj.GetUserData() );
     849           0 :     if( !aUserData.Len() )
     850           0 :         return;
     851             : 
     852           0 :     if (aNewStrmName.Len()>0) {
     853           0 :         aUserData=aNewStrmName;
     854             :     }
     855             : 
     856           0 :     String aProt( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.Package:" ) );
     857           0 :     if( 0 == aUserData.CompareTo( aProt, aProt.Len() ) )
     858             :     {
     859             :         // 6.0 (XML) Package
     860           0 :         xub_StrLen nPos = aUserData.Search( '/' );
     861           0 :         if( STRING_NOTFOUND == nPos )
     862             :         {
     863           0 :             rStrmName = aUserData.Copy( aProt.Len() );
     864             :         }
     865             :         else
     866             :         {
     867           0 :             xub_StrLen nPathStart = aProt.Len();
     868           0 :             if( 0 == aUserData.CompareToAscii( "./", 2 ) )
     869           0 :                 nPathStart += 2;
     870           0 :             rStorName = aUserData.Copy( nPathStart, nPos-nPathStart );
     871           0 :             rStrmName = aUserData.Copy( nPos+1 );
     872             :         }
     873             :     }
     874             :     else
     875             :     {
     876             :         OSL_FAIL( "<SwGrfNode::_GetStreamStorageNames(..)> - unknown graphic URL type. Code for handling 3.1 - 5.2 storages has been deleted by issue i53025." );
     877             :     }
     878             :     OSL_ENSURE( STRING_NOTFOUND == rStrmName.Search( '/' ),
     879           0 :             "invalid graphic stream name" );
     880             : }
     881             : 
     882           1 : SwCntntNode* SwGrfNode::MakeCopy( SwDoc* pDoc, const SwNodeIndex& rIdx ) const
     883             : {
     884             :     // kopiere die Formate in das andere Dokument:
     885           1 :     SwGrfFmtColl* pColl = pDoc->CopyGrfColl( *GetGrfColl() );
     886             : 
     887           1 :     Graphic aTmpGrf;
     888           1 :     SwBaseLink* pLink = (SwBaseLink*)(::sfx2::SvBaseLink*) refLink;
     889           1 :     if( !pLink && HasStreamName() )
     890             :     {
     891             :         // #i48434# - usage of new method <_GetStreamForEmbedGrf(..)>
     892             :         try
     893             :         {
     894             :             // #i53025# - needed correction of new method <_GetStreamForEmbedGrf(..)>
     895           0 :             String aStrmName, aPicStgName;
     896           0 :             _GetStreamStorageNames( aStrmName, aPicStgName );
     897           0 :             uno::Reference < embed::XStorage > refPics = _GetDocSubstorageOrRoot( aPicStgName );
     898           0 :             SvStream* pStrm = _GetStreamForEmbedGrf( refPics, aStrmName );
     899           0 :             if ( pStrm )
     900             :             {
     901           0 :                 const String aURL(aGrfObj.GetUserData());
     902           0 :                 GraphicFilter::GetGraphicFilter().ImportGraphic(aTmpGrf, aURL, *pStrm);
     903           0 :                 delete pStrm;
     904           0 :             }
     905             :         }
     906           0 :         catch (const uno::Exception& e)
     907             :         {
     908             :             // #i48434#
     909             :             SAL_WARN("sw.core", "<SwGrfNode::MakeCopy(..)> - unhandled exception!" << e.Message);
     910             :         }
     911             :     }
     912             :     else
     913             :     {
     914           1 :         if( aGrfObj.IsSwappedOut() )
     915           0 :             const_cast<SwGrfNode*>(this)->SwapIn();
     916           1 :         aTmpGrf = aGrfObj.GetGraphic();
     917             :     }
     918             : 
     919           1 :     const sfx2::LinkManager& rMgr = getIDocumentLinksAdministration()->GetLinkManager();
     920           1 :     String sFile, sFilter;
     921           1 :     if( IsLinkedFile() )
     922           0 :         rMgr.GetDisplayNames( refLink, 0, &sFile, 0, &sFilter );
     923           1 :     else if( IsLinkedDDE() )
     924             :     {
     925           0 :         String sTmp1, sTmp2;
     926           0 :         rMgr.GetDisplayNames( refLink, &sTmp1, &sTmp2, &sFilter );
     927           0 :         sfx2::MakeLnkName( sFile, &sTmp1, sTmp2, sFilter );
     928           0 :         sFilter.AssignAscii( RTL_CONSTASCII_STRINGPARAM( "DDE" ));
     929             :     }
     930             : 
     931           1 :     SwGrfNode* pGrfNd = pDoc->GetNodes().MakeGrfNode( rIdx, sFile, sFilter,
     932             :                                                     &aTmpGrf, pColl,
     933           2 :                                             (SwAttrSet*)GetpSwAttrSet() );
     934           1 :     pGrfNd->SetTitle( GetTitle() );
     935           1 :     pGrfNd->SetDescription( GetDescription() );
     936           1 :     pGrfNd->SetContour( HasContour(), HasAutomaticContour() );
     937           1 :     return pGrfNd;
     938             : }
     939             : 
     940          16 : IMPL_LINK( SwGrfNode, SwapGraphic, GraphicObject*, pGrfObj )
     941             : {
     942             :     SvStream* pRet;
     943             : 
     944             :     // Keep graphic while in swap in. That's at least important
     945             :     // when breaking links, because in this situation a reschedule call and
     946             :     // a DataChanged call lead to a paint of the graphic.
     947           8 :     if( pGrfObj->IsInSwapOut() && (IsSelected() || bInSwapIn) )
     948           0 :         pRet = GRFMGR_AUTOSWAPSTREAM_NONE;
     949           8 :     else if( refLink.Is() )
     950             :     {
     951           0 :         if( pGrfObj->IsInSwapIn() )
     952             :         {
     953             :             // then make it by your self
     954           0 :             if( !bInSwapIn )
     955             :             {
     956           0 :                 bool bIsModifyLocked = IsModifyLocked();
     957           0 :                 LockModify();
     958           0 :                 SwapIn( sal_False );
     959           0 :                 if( !bIsModifyLocked )
     960           0 :                     UnlockModify();
     961             :             }
     962           0 :             pRet = GRFMGR_AUTOSWAPSTREAM_NONE;
     963             :         }
     964             :         else
     965           0 :             pRet = GRFMGR_AUTOSWAPSTREAM_LINK;
     966             :     }
     967             :     else
     968             :     {
     969           8 :         pRet = GRFMGR_AUTOSWAPSTREAM_TEMP;
     970             : 
     971           8 :         if( HasStreamName() )
     972             :         {
     973             :             // #i48434# - usage of new method <_GetStreamForEmbedGrf(..)>
     974             :             try
     975             :             {
     976             :                 // #i53025# - needed correction of new method <_GetStreamForEmbedGrf(..)>
     977           0 :                 String aStrmName, aPicStgName;
     978           0 :                 _GetStreamStorageNames( aStrmName, aPicStgName );
     979           0 :                 uno::Reference < embed::XStorage > refPics = _GetDocSubstorageOrRoot( aPicStgName );
     980           0 :                 SvStream* pStrm = _GetStreamForEmbedGrf( refPics, aStrmName );
     981           0 :                 if ( pStrm )
     982             :                 {
     983           0 :                     if( pGrfObj->IsInSwapOut() )
     984             :                     {
     985           0 :                         pRet = GRFMGR_AUTOSWAPSTREAM_LINK;
     986             :                     }
     987             :                     else
     988             :                     {
     989           0 :                         ImportGraphic( *pStrm );
     990           0 :                         pRet = GRFMGR_AUTOSWAPSTREAM_LOADED;
     991             :                     }
     992           0 :                     delete pStrm;
     993           0 :                 }
     994             :             }
     995           0 :             catch (const uno::Exception&)
     996             :             {
     997             :                 // #i48434#
     998             :                 OSL_FAIL( "<SwapGraphic> - unhandled exception!" );
     999             :             }
    1000             :         }
    1001             :     }
    1002             : 
    1003           8 :     return (long)pRet;
    1004             : }
    1005             : 
    1006             : 
    1007             : // alle QuickDraw-Bitmaps eines speziellen Docs loeschen
    1008           0 : void DelAllGrfCacheEntries( SwDoc* pDoc )
    1009             : {
    1010           0 :     if( pDoc )
    1011             :     {
    1012             :         // alle Graphic-Links mit dem Namen aus dem Cache loeschen
    1013           0 :         const sfx2::LinkManager& rLnkMgr = pDoc->GetLinkManager();
    1014           0 :         const ::sfx2::SvBaseLinks& rLnks = rLnkMgr.GetLinks();
    1015             :         SwGrfNode* pGrfNd;
    1016           0 :         String sFileNm;
    1017           0 :         for( sal_uInt16 n = rLnks.size(); n; )
    1018             :         {
    1019           0 :             ::sfx2::SvBaseLink* pLnk = &(*rLnks[ --n ]);
    1020           0 :             if( pLnk && OBJECT_CLIENT_GRF == pLnk->GetObjType() &&
    1021           0 :                 rLnkMgr.GetDisplayNames( pLnk, 0, &sFileNm ) &&
    1022           0 :                 pLnk->ISA( SwBaseLink ) && 0 != ( pGrfNd =
    1023           0 :                 ((SwBaseLink*)pLnk)->GetCntntNode()->GetGrfNode()) )
    1024             :             {
    1025           0 :                 pGrfNd->GetGrfObj().ReleaseFromCache();
    1026             :             }
    1027           0 :         }
    1028             :     }
    1029           0 : }
    1030             : 
    1031             : // returns the with our graphic attributes filled Graphic-Attr-Structure
    1032          16 : GraphicAttr& SwGrfNode::GetGraphicAttr( GraphicAttr& rGA,
    1033             :                                         const SwFrm* pFrm ) const
    1034             : {
    1035          16 :     const SwAttrSet& rSet = GetSwAttrSet();
    1036             : 
    1037          16 :     rGA.SetDrawMode( (GraphicDrawMode)rSet.GetDrawModeGrf().GetValue() );
    1038             : 
    1039          16 :     const SwMirrorGrf & rMirror = rSet.GetMirrorGrf();
    1040          16 :     sal_uLong nMirror = BMP_MIRROR_NONE;
    1041          16 :     if( rMirror.IsGrfToggle() && pFrm && !pFrm->FindPageFrm()->OnRightPage() )
    1042             :     {
    1043           0 :         switch( rMirror.GetValue() )
    1044             :         {
    1045           0 :         case RES_MIRROR_GRAPH_DONT:     nMirror = BMP_MIRROR_HORZ; break;
    1046           0 :         case RES_MIRROR_GRAPH_VERT:     nMirror = BMP_MIRROR_NONE; break;
    1047           0 :         case RES_MIRROR_GRAPH_HOR:  nMirror = BMP_MIRROR_HORZ|BMP_MIRROR_VERT;
    1048           0 :                                     break;
    1049           0 :         default:                    nMirror = BMP_MIRROR_VERT; break;
    1050             :         }
    1051             :     }
    1052             :     else
    1053          16 :         switch( rMirror.GetValue() )
    1054             :         {
    1055           0 :         case RES_MIRROR_GRAPH_BOTH:     nMirror = BMP_MIRROR_HORZ|BMP_MIRROR_VERT;
    1056           0 :                                     break;
    1057           0 :         case RES_MIRROR_GRAPH_VERT: nMirror = BMP_MIRROR_HORZ; break;
    1058           0 :         case RES_MIRROR_GRAPH_HOR:  nMirror = BMP_MIRROR_VERT; break;
    1059             :         }
    1060             : 
    1061          16 :     rGA.SetMirrorFlags( nMirror );
    1062             : 
    1063          16 :     const SwCropGrf& rCrop = rSet.GetCropGrf();
    1064          32 :     rGA.SetCrop( TWIP_TO_MM100( rCrop.GetLeft() ),
    1065          32 :                  TWIP_TO_MM100( rCrop.GetTop() ),
    1066          32 :                  TWIP_TO_MM100( rCrop.GetRight() ),
    1067         112 :                  TWIP_TO_MM100( rCrop.GetBottom() ));
    1068             : 
    1069          16 :     const SwRotationGrf& rRotation = rSet.GetRotationGrf();
    1070          16 :     rGA.SetRotation( rRotation.GetValue() );
    1071             : 
    1072          16 :     rGA.SetLuminance( rSet.GetLuminanceGrf().GetValue() );
    1073          16 :     rGA.SetContrast( rSet.GetContrastGrf().GetValue() );
    1074          16 :     rGA.SetChannelR( rSet.GetChannelRGrf().GetValue() );
    1075          16 :     rGA.SetChannelG( rSet.GetChannelGGrf().GetValue() );
    1076          16 :     rGA.SetChannelB( rSet.GetChannelBGrf().GetValue() );
    1077          16 :     rGA.SetGamma( rSet.GetGammaGrf().GetValue() );
    1078          16 :     rGA.SetInvert( rSet.GetInvertGrf().GetValue() );
    1079             : 
    1080          16 :     const sal_uInt16 nTrans = rSet.GetTransparencyGrf().GetValue();
    1081             :     rGA.SetTransparency( (sal_uInt8) FRound(
    1082          16 :                                 Min( nTrans, (sal_uInt16) 100 )  * 2.55 ) );
    1083             : 
    1084          16 :     return rGA;
    1085             : }
    1086             : 
    1087          24 : sal_Bool SwGrfNode::IsTransparent() const
    1088             : {
    1089          24 :     sal_Bool bRet = aGrfObj.IsTransparent();
    1090          24 :     if( !bRet ) // ask the attribut
    1091          12 :         bRet = 0 != GetSwAttrSet().GetTransparencyGrf().GetValue();
    1092             : 
    1093          24 :     return bRet;
    1094             : }
    1095             : 
    1096             : 
    1097           8 : sal_Bool SwGrfNode::IsSelected() const
    1098             : {
    1099           8 :     sal_Bool bRet = sal_False;
    1100           8 :     const SwEditShell* pESh = GetDoc()->GetEditShell();
    1101           8 :     if( pESh )
    1102             :     {
    1103           8 :         const SwNode* pN = this;
    1104           8 :         const ViewShell* pV = pESh;
    1105           8 :         do {
    1106          16 :             if( pV->ISA( SwEditShell ) && pN == &((SwCrsrShell*)pV)
    1107           8 :                                 ->GetCrsr()->GetPoint()->nNode.GetNode() )
    1108             :             {
    1109           0 :                 bRet = sal_True;
    1110           0 :                 break;
    1111             :             }
    1112             :         }
    1113           8 :         while( pESh != ( pV = (ViewShell*)pV->GetNext() ));
    1114             :     }
    1115           8 :     return bRet;
    1116             : }
    1117             : 
    1118             : // #i73788#
    1119           0 : boost::weak_ptr< SwAsyncRetrieveInputStreamThreadConsumer > SwGrfNode::GetThreadConsumer()
    1120             : {
    1121           0 :     return mpThreadConsumer;
    1122             : }
    1123             : 
    1124           0 : void SwGrfNode::TriggerAsyncRetrieveInputStream()
    1125             : {
    1126           0 :     if ( !IsLinkedFile() )
    1127             :     {
    1128             :         OSL_FAIL( "<SwGrfNode::TriggerAsyncLoad()> - Method is misused. Method call is only valid for graphic nodes, which refer a linked graphic file" );
    1129           0 :         return;
    1130             :     }
    1131             : 
    1132           0 :     if ( mpThreadConsumer.get() == 0 )
    1133             :     {
    1134           0 :         mpThreadConsumer.reset( new SwAsyncRetrieveInputStreamThreadConsumer( *this ) );
    1135             : 
    1136           0 :         String sGrfNm;
    1137           0 :         refLink->GetLinkManager()->GetDisplayNames( refLink, 0, &sGrfNm, 0, 0 );
    1138             : 
    1139           0 :         mpThreadConsumer->CreateThread( sGrfNm );
    1140             :     }
    1141             : }
    1142             : 
    1143          16 : bool SwGrfNode::IsLinkedInputStreamReady() const
    1144             : {
    1145          16 :     return mbLinkedInputStreamReady;
    1146             : }
    1147             : 
    1148           0 : void SwGrfNode::ApplyInputStream(
    1149             :     com::sun::star::uno::Reference<com::sun::star::io::XInputStream> xInputStream,
    1150             :     const sal_Bool bIsStreamReadOnly )
    1151             : {
    1152           0 :     if ( IsLinkedFile() )
    1153             :     {
    1154           0 :         if ( xInputStream.is() )
    1155             :         {
    1156           0 :             mxInputStream = xInputStream;
    1157           0 :             mbIsStreamReadOnly = bIsStreamReadOnly;
    1158           0 :             mbLinkedInputStreamReady = true;
    1159           0 :             SwMsgPoolItem aMsgHint( RES_LINKED_GRAPHIC_STREAM_ARRIVED );
    1160           0 :             ModifyNotification( &aMsgHint, &aMsgHint );
    1161             :         }
    1162             :     }
    1163           0 : }
    1164             : 
    1165           0 : void SwGrfNode::UpdateLinkWithInputStream()
    1166             : {
    1167             :     // --> OD #i85105#
    1168             :     // do not work on link, if a <SwapIn> has been triggered.
    1169           0 :     if ( !bInSwapIn && IsLinkedFile() )
    1170             :     // <--
    1171             :     {
    1172           0 :         GetLink()->setStreamToLoadFrom( mxInputStream, mbIsStreamReadOnly );
    1173           0 :         GetLink()->Update();
    1174           0 :         SwMsgPoolItem aMsgHint( RES_GRAPHIC_ARRIVED );
    1175           0 :         ModifyNotification( &aMsgHint, &aMsgHint );
    1176             : 
    1177             :         // #i88291#
    1178           0 :         mxInputStream.clear();
    1179           0 :         GetLink()->clearStreamToLoadFrom();
    1180           0 :         mbLinkedInputStreamReady = false;
    1181           0 :         mpThreadConsumer.reset();
    1182             :     }
    1183           0 : }
    1184             : 
    1185             : // #i90395#
    1186           0 : bool SwGrfNode::IsAsyncRetrieveInputStreamPossible() const
    1187             : {
    1188           0 :     bool bRet = false;
    1189             : 
    1190           0 :     if ( IsLinkedFile() )
    1191             :     {
    1192           0 :         String sGrfNm;
    1193           0 :         refLink->GetLinkManager()->GetDisplayNames( refLink, 0, &sGrfNm, 0, 0 );
    1194           0 :         String sProtocol( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.pkg:" ) );
    1195           0 :         if ( sGrfNm.CompareTo( sProtocol, sProtocol.Len() ) != 0 )
    1196             :         {
    1197           0 :             bRet = true;
    1198           0 :         }
    1199             :     }
    1200             : 
    1201           0 :     return bRet;
    1202             : }
    1203             : 
    1204             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10