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

Generated by: LCOV version 1.10