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

Generated by: LCOV version 1.10