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

Generated by: LCOV version 1.10