LCOV - code coverage report
Current view: top level - sw/source/core/doc - swserv.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 44 161 27.3 %
Date: 2015-06-13 12:38:46 Functions: 9 13 69.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 <sot/storage.hxx>
      21             : #include <sfx2/linkmgr.hxx>
      22             : #include <com/sun/star/uno/Sequence.h>
      23             : #include <doc.hxx>
      24             : #include <IDocumentLinksAdministration.hxx>
      25             : #include <IDocumentLayoutAccess.hxx>
      26             : #include <swtypes.hxx>
      27             : #include <swserv.hxx>
      28             : #include <swbaslnk.hxx>
      29             : #include <mvsave.hxx>
      30             : #include <IMark.hxx>
      31             : #include <bookmrk.hxx>
      32             : #include <pam.hxx>
      33             : #include <shellio.hxx>
      34             : #include <swerror.h>
      35             : 
      36             : using namespace ::com::sun::star;
      37             : 
      38           2 : SwServerObject::~SwServerObject()
      39             : {
      40           2 : }
      41             : 
      42           0 : bool SwServerObject::GetData( uno::Any & rData,
      43             :                                 const OUString & rMimeType, bool )
      44             : {
      45           0 :     bool bRet = false;
      46           0 :     WriterRef xWrt;
      47           0 :     switch( SotExchange::GetFormatIdFromMimeType( rMimeType ) )
      48             :     {
      49             :     case SotClipboardFormatId::STRING:
      50           0 :         ::GetASCWriter( OUString(), OUString(), xWrt );
      51           0 :         break;
      52             : 
      53             :     case SotClipboardFormatId::RTF:
      54             :         // mba: no BaseURL for data exchange
      55           0 :         ::GetRTFWriter( OUString(), OUString(), xWrt );
      56           0 :         break;
      57           0 :     default: break;
      58             :     }
      59             : 
      60           0 :     if( xWrt.Is() )
      61             :     {
      62           0 :         SwPaM* pPam = 0;
      63           0 :         switch( eType )
      64             :         {
      65             :         case BOOKMARK_SERVER:
      66           0 :             if( CNTNT_TYPE.pBkmk->IsExpanded() )
      67             :             {
      68             :                 // Span area
      69           0 :                 pPam = new SwPaM( CNTNT_TYPE.pBkmk->GetMarkPos(),
      70           0 :                                 CNTNT_TYPE.pBkmk->GetOtherMarkPos() );
      71             :             }
      72           0 :             break;
      73             : 
      74             :         case TABLE_SERVER:
      75             :             pPam = new SwPaM( *CNTNT_TYPE.pTableNd,
      76           0 :                             *CNTNT_TYPE.pTableNd->EndOfSectionNode() );
      77           0 :             break;
      78             : 
      79             :         case SECTION_SERVER:
      80           0 :             pPam = new SwPaM( SwPosition( *CNTNT_TYPE.pSectNd ) );
      81           0 :             pPam->Move( fnMoveForward );
      82           0 :             pPam->SetMark();
      83           0 :             pPam->GetPoint()->nNode = *CNTNT_TYPE.pSectNd->EndOfSectionNode();
      84           0 :             pPam->Move( fnMoveBackward );
      85           0 :             break;
      86           0 :         case NONE_SERVER: break;
      87             :         }
      88             : 
      89           0 :         if( pPam )
      90             :         {
      91             :             // Create stream
      92           0 :             SvMemoryStream aMemStm( 65535, 65535 );
      93           0 :             SwWriter aWrt( aMemStm, *pPam, false );
      94           0 :             if( !IsError( aWrt.Write( xWrt )) )
      95             :             {
      96           0 :                 aMemStm.WriteChar( '\0' );        // append a zero char
      97           0 :                 rData <<= uno::Sequence< sal_Int8 >(
      98           0 :                                         static_cast<sal_Int8 const *>(aMemStm.GetData()),
      99           0 :                                         aMemStm.Seek( STREAM_SEEK_TO_END ) );
     100           0 :                 bRet = true;
     101             :             }
     102           0 :             delete pPam;
     103             :         }
     104             :     }
     105           0 :     return bRet;
     106             : }
     107             : 
     108           1 : void SwServerObject::SendDataChanged( const SwPosition& rPos )
     109             : {
     110             :     // Is someone interested in our changes?
     111           1 :     if( HasDataLinks() )
     112             :     {
     113           1 :         bool bCall = false;
     114           1 :         const SwStartNode* pNd = 0;
     115           1 :         switch( eType )
     116             :         {
     117             :             case BOOKMARK_SERVER:
     118           1 :                 if( CNTNT_TYPE.pBkmk->IsExpanded() )
     119             :                 {
     120           1 :                     bCall = CNTNT_TYPE.pBkmk->GetMarkStart() <= rPos
     121           1 :                         && rPos < CNTNT_TYPE.pBkmk->GetMarkEnd();
     122             :                 }
     123           1 :                 break;
     124             : 
     125           0 :             case TABLE_SERVER:      pNd = CNTNT_TYPE.pTableNd;    break;
     126           0 :             case SECTION_SERVER:    pNd = CNTNT_TYPE.pSectNd;   break;
     127           0 :             case NONE_SERVER: break;
     128             :         }
     129           1 :         if( pNd )
     130             :         {
     131           0 :             sal_uLong nNd = rPos.nNode.GetIndex();
     132           0 :             bCall = pNd->GetIndex() < nNd && nNd < pNd->EndOfSectionIndex();
     133             :         }
     134             : 
     135           1 :         if( bCall )
     136             :         {
     137             :             // Recognize recursions and flag them
     138           0 :             IsLinkInServer( 0 );
     139           0 :             SvLinkSource::NotifyDataChanged();
     140             :         }
     141             :     }
     142           1 : }
     143             : 
     144           0 : void SwServerObject::SendDataChanged( const SwPaM& rRange )
     145             : {
     146             :     // Is someone interested in our changes?
     147           0 :     if( HasDataLinks() )
     148             :     {
     149           0 :         bool bCall = false;
     150           0 :         const SwStartNode* pNd = 0;
     151           0 :         const SwPosition* pStt = rRange.Start(), *pEnd = rRange.End();
     152           0 :         switch( eType )
     153             :         {
     154             :         case BOOKMARK_SERVER:
     155           0 :             if(CNTNT_TYPE.pBkmk->IsExpanded())
     156             :             {
     157           0 :                 bCall = *pStt <= CNTNT_TYPE.pBkmk->GetMarkEnd()
     158           0 :                     && *pEnd > CNTNT_TYPE.pBkmk->GetMarkStart();
     159             :             }
     160           0 :             break;
     161             : 
     162           0 :         case TABLE_SERVER:      pNd = CNTNT_TYPE.pTableNd;    break;
     163           0 :         case SECTION_SERVER:    pNd = CNTNT_TYPE.pSectNd;   break;
     164           0 :         case NONE_SERVER: break;
     165             :         }
     166           0 :         if( pNd )
     167             :         {
     168             :             // Is the start area within the node area?
     169           0 :             bCall = pStt->nNode.GetIndex() <  pNd->EndOfSectionIndex() &&
     170           0 :                     pEnd->nNode.GetIndex() >= pNd->GetIndex();
     171             :         }
     172             : 
     173           0 :         if( bCall )
     174             :         {
     175             :             // Recognize recursions and flag them
     176           0 :             IsLinkInServer( 0 );
     177           0 :             SvLinkSource::NotifyDataChanged();
     178             :         }
     179             :     }
     180           0 : }
     181             : 
     182           0 : bool SwServerObject::IsLinkInServer( const SwBaseLink* pChkLnk ) const
     183             : {
     184           0 :     sal_uLong nSttNd = 0, nEndNd = 0;
     185           0 :     sal_Int32 nStt = 0;
     186           0 :     sal_Int32 nEnd = 0;
     187           0 :     const SwNode* pNd = 0;
     188           0 :     const SwNodes* pNds = 0;
     189             : 
     190           0 :     switch( eType )
     191             :     {
     192             :     case BOOKMARK_SERVER:
     193           0 :         if( CNTNT_TYPE.pBkmk->IsExpanded() )
     194             :         {
     195           0 :             const SwPosition* pStt = &CNTNT_TYPE.pBkmk->GetMarkStart(),
     196           0 :                             * pEnd = &CNTNT_TYPE.pBkmk->GetMarkEnd();
     197             : 
     198           0 :             nSttNd = pStt->nNode.GetIndex();
     199           0 :             nStt = pStt->nContent.GetIndex();
     200           0 :             nEndNd = pEnd->nNode.GetIndex();
     201           0 :             nEnd = pEnd->nContent.GetIndex();
     202           0 :             pNds = &pStt->nNode.GetNodes();
     203             :         }
     204           0 :         break;
     205             : 
     206           0 :     case TABLE_SERVER:      pNd = CNTNT_TYPE.pTableNd;    break;
     207           0 :     case SECTION_SERVER:    pNd = CNTNT_TYPE.pSectNd;   break;
     208             : 
     209             :     case SECTION_SERVER+1:
     210           0 :         return true;
     211             :     }
     212             : 
     213           0 :     if( pNd )
     214             :     {
     215           0 :         nSttNd = pNd->GetIndex();
     216           0 :         nEndNd = pNd->EndOfSectionIndex();
     217           0 :         nStt = 0;
     218           0 :         nEnd = -1;
     219           0 :         pNds = &pNd->GetNodes();
     220             :     }
     221             : 
     222           0 :     if( nSttNd && nEndNd )
     223             :     {
     224             :         // Get LinkManager
     225           0 :         const ::sfx2::SvBaseLinks& rLnks = pNds->GetDoc()->getIDocumentLinksAdministration().GetLinkManager().GetLinks();
     226             : 
     227             :         // To avoid recursions: convert ServerType!
     228           0 :         SwServerObject::ServerModes eSave = eType;
     229           0 :         if( !pChkLnk )
     230           0 :             const_cast<SwServerObject*>(this)->eType = NONE_SERVER;
     231           0 :         for( size_t n = rLnks.size(); n; )
     232             :         {
     233           0 :             const ::sfx2::SvBaseLink* pLnk = &(*rLnks[ --n ]);
     234           0 :             if( pLnk && OBJECT_CLIENT_GRF != pLnk->GetObjType() &&
     235           0 :                 pLnk->ISA( SwBaseLink ) &&
     236           0 :                 !static_cast<const SwBaseLink*>(pLnk)->IsNoDataFlag() &&
     237           0 :                 static_cast<const SwBaseLink*>(pLnk)->IsInRange( nSttNd, nEndNd, nStt, nEnd ))
     238             :             {
     239           0 :                 if( pChkLnk )
     240             :                 {
     241           0 :                     if( pLnk == pChkLnk ||
     242           0 :                         static_cast<const SwBaseLink*>(pLnk)->IsRecursion( pChkLnk ) )
     243           0 :                         return true;
     244             :                 }
     245           0 :                 else if( static_cast<const SwBaseLink*>(pLnk)->IsRecursion( static_cast<const SwBaseLink*>(pLnk) ) )
     246           0 :                     const_cast<SwBaseLink*>(static_cast<const SwBaseLink*>(pLnk))->SetNoDataFlag();
     247             :             }
     248             :         }
     249           0 :         if( !pChkLnk )
     250           0 :             const_cast<SwServerObject*>(this)->eType = eSave;
     251             :     }
     252             : 
     253           0 :     return false;
     254             : }
     255             : 
     256           1 : void SwServerObject::SetNoServer()
     257             : {
     258           1 :     if(eType == BOOKMARK_SERVER && CNTNT_TYPE.pBkmk)
     259             :     {
     260           1 :         ::sw::mark::DdeBookmark* const pDdeBookmark = dynamic_cast< ::sw::mark::DdeBookmark* >(CNTNT_TYPE.pBkmk);
     261           1 :         if(pDdeBookmark)
     262             :         {
     263           1 :             CNTNT_TYPE.pBkmk = 0, eType = NONE_SERVER;
     264           1 :             pDdeBookmark->SetRefObject(NULL);
     265             :         }
     266             :     }
     267           1 : }
     268             : 
     269           0 : void SwServerObject::SetDdeBookmark( ::sw::mark::IMark& rBookmark)
     270             : {
     271           0 :     ::sw::mark::DdeBookmark* const pDdeBookmark = dynamic_cast< ::sw::mark::DdeBookmark* >(&rBookmark);
     272           0 :     if(pDdeBookmark)
     273             :     {
     274           0 :         eType = BOOKMARK_SERVER;
     275           0 :         CNTNT_TYPE.pBkmk = &rBookmark;
     276           0 :         pDdeBookmark->SetRefObject(this);
     277             :     }
     278             :     else
     279             :         OSL_FAIL("SwServerObject::SetNoServer(..)"
     280             :             " - setting an bookmark that is not DDE-capable");
     281           0 : }
     282             : 
     283      352186 : SwDataChanged::SwDataChanged( const SwPaM& rPam )
     284      352186 :     : pPam( &rPam ), pPos( 0 ), pDoc( rPam.GetDoc() )
     285             : {
     286      352186 :     nNode = rPam.GetPoint()->nNode.GetIndex();
     287      352186 :     nContent = rPam.GetPoint()->nContent.GetIndex();
     288      352186 : }
     289             : 
     290        1372 : SwDataChanged::SwDataChanged( SwDoc* pDc, const SwPosition& rPos )
     291        1372 :     : pPam( 0 ), pPos( &rPos ), pDoc( pDc )
     292             : {
     293        1372 :     nNode = rPos.nNode.GetIndex();
     294        1372 :     nContent = rPos.nContent.GetIndex();
     295        1372 : }
     296             : 
     297      353558 : SwDataChanged::~SwDataChanged()
     298             : {
     299             :     // JP 09.04.96: Only if the Layout is available (thus during input)
     300      353558 :     if( pDoc->getIDocumentLayoutAccess().GetCurrentViewShell() )
     301             :     {
     302       20088 :         const ::sfx2::SvLinkSources& rServers = pDoc->getIDocumentLinksAdministration().GetLinkManager().GetServers();
     303             : 
     304       20088 :         ::sfx2::SvLinkSources aTemp(rServers);
     305       20089 :         for( ::sfx2::SvLinkSources::const_iterator it = aTemp.begin(); it != aTemp.end(); ++it )
     306             :         {
     307           1 :             ::sfx2::SvLinkSourceRef refObj( *it );
     308             :             // Any one else interested in the Object?
     309           1 :             if( refObj->HasDataLinks() && refObj->ISA( SwServerObject ))
     310             :             {
     311           1 :                 SwServerObject& rObj = *static_cast<SwServerObject*>(&refObj);
     312           1 :                 if( pPos )
     313           1 :                     rObj.SendDataChanged( *pPos );
     314             :                 else
     315           0 :                     rObj.SendDataChanged( *pPam );
     316             :             }
     317             : 
     318             :             // We shouldn't have a connection anymore
     319           1 :             if( !refObj->HasDataLinks() )
     320             :             {
     321             :                 // Then remove from the list
     322           0 :                 pDoc->getIDocumentLinksAdministration().GetLinkManager().RemoveServer( *it );
     323             :             }
     324       20089 :         }
     325             :     }
     326      353735 : }
     327             : 
     328             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11