LCOV - code coverage report
Current view: top level - sw/source/core/doc - visiturl.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 39 55 70.9 %
Date: 2014-11-03 Functions: 7 7 100.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 <sfx2/docfile.hxx>
      21             : #include <svl/inethist.hxx>
      22             : #include <fmtinfmt.hxx>
      23             : #include <txtinet.hxx>
      24             : #include <doc.hxx>
      25             : #include <IDocumentLayoutAccess.hxx>
      26             : #include <visiturl.hxx>
      27             : #include <hints.hxx>
      28             : #include <ndtxt.hxx>
      29             : #include <editsh.hxx>
      30             : #include <docsh.hxx>
      31             : 
      32         298 : SwURLStateChanged::SwURLStateChanged( SwDoc* pD )
      33         298 :     : pDoc( pD )
      34             : {
      35         298 :     StartListening( *INetURLHistory::GetOrCreate() );
      36         298 : }
      37             : 
      38         894 : SwURLStateChanged::~SwURLStateChanged()
      39             : {
      40         298 :     EndListening( *INetURLHistory::GetOrCreate() );
      41         596 : }
      42             : 
      43         256 : void SwURLStateChanged::Notify( SfxBroadcaster& , const SfxHint& rHint )
      44             : {
      45         256 :     if( dynamic_cast<const INetURLHistoryHint*>(&rHint) && pDoc->getIDocumentLayoutAccess().GetCurrentViewShell() )
      46             :     {
      47             :         // This URL has been changed:
      48         256 :         const INetURLObject* pIURL = ((INetURLHistoryHint&)rHint).GetObject();
      49         512 :         OUString sURL( pIURL->GetMainURL( INetURLObject::NO_DECODE ) ), sBkmk;
      50             : 
      51         256 :         SwEditShell* pESh = pDoc->GetEditShell();
      52             : 
      53         512 :         if( pDoc->GetDocShell() && pDoc->GetDocShell()->GetMedium() &&
      54             :             // If this is our Doc, we can also have local jumps!
      55         256 :             pDoc->GetDocShell()->GetMedium()->GetName().equals(sURL) )
      56         256 :             sBkmk = "#" + pIURL->GetMark();
      57             : 
      58         256 :         bool bAction = false, bUnLockView = false;
      59         256 :         sal_uInt32 nMaxItems = pDoc->GetAttrPool().GetItemCount2( RES_TXTATR_INETFMT );
      60        1990 :         for( sal_uInt32 n = 0; n < nMaxItems; ++n )
      61             :         {
      62        1734 :             const SwFmtINetFmt* pItem = (SwFmtINetFmt*)pDoc->GetAttrPool().GetItem2(RES_TXTATR_INETFMT, n );
      63        3084 :             if( pItem != 0 &&
      64        2700 :                 ( pItem->GetValue() == sURL || ( !sBkmk.isEmpty() && pItem->GetValue() == sBkmk )))
      65             :             {
      66           0 :                 const SwTxtINetFmt* pTxtAttr = pItem->GetTxtINetFmt();
      67           0 :                 if (pTxtAttr != 0)
      68             :                 {
      69           0 :                     const SwTxtNode* pTxtNd = pTxtAttr->GetpTxtNode();
      70           0 :                     if (pTxtNd != 0)
      71             :                     {
      72           0 :                         if( !bAction && pESh )
      73             :                         {
      74           0 :                             pESh->StartAllAction();
      75           0 :                             bAction = true;
      76           0 :                             bUnLockView = !pESh->IsViewLocked();
      77           0 :                             pESh->LockView( true );
      78             :                         }
      79           0 :                         const_cast<SwTxtINetFmt*>(pTxtAttr)->SetVisitedValid(false);
      80           0 :                         const SwTxtAttr* pAttr = pTxtAttr;
      81             :                         SwUpdateAttr aUpdateAttr(
      82           0 :                             pAttr->GetStart(),
      83           0 :                             *pAttr->End(),
      84           0 :                             RES_FMT_CHG);
      85             : 
      86           0 :                         const_cast< SwTxtNode* >(pTxtNd)->ModifyNotification(&aUpdateAttr, &aUpdateAttr);
      87             :                     }
      88             :                 }
      89             :             }
      90             :         }
      91             : 
      92         256 :         if( bAction )
      93           0 :             pESh->EndAllAction();
      94         256 :         if( bUnLockView )
      95         256 :             pESh->LockView( false );
      96             :     }
      97         256 : }
      98             : 
      99             : // Check if the URL has been visited before. Via the Doc, if only one Bookmark is set
     100             : // We need to put the Doc's name before it!
     101        2852 : bool SwDoc::IsVisitedURL( const OUString& rURL )
     102             : {
     103        2852 :     bool bRet = false;
     104        2852 :     if( !rURL.isEmpty() )
     105             :     {
     106        2844 :         INetURLHistory *pHist = INetURLHistory::GetOrCreate();
     107        2844 :         if( '#' == rURL[0] && mpDocShell && mpDocShell->GetMedium() )
     108             :         {
     109        1932 :             INetURLObject aIObj( mpDocShell->GetMedium()->GetURLObject() );
     110        1932 :             aIObj.SetMark( rURL.copy( 1 ) );
     111        1932 :             bRet = pHist->QueryUrl( aIObj );
     112             :         }
     113             :         else
     114         912 :             bRet = pHist->QueryUrl( rURL );
     115             : 
     116             :         // We also want to be informed about status updates in the History
     117        2844 :         if( !mpURLStateChgd )
     118             :         {
     119         298 :             SwDoc* pD = (SwDoc*)this;
     120         298 :             pD->mpURLStateChgd = new SwURLStateChanged( this );
     121             :         }
     122             :     }
     123        2852 :     return bRet;
     124         270 : }
     125             : 
     126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10