LCOV - code coverage report
Current view: top level - sw/source/core/doc - visiturl.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 39 55 70.9 %
Date: 2015-06-13 12:38:46 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         167 : SwURLStateChanged::SwURLStateChanged( SwDoc* pD )
      33         167 :     : pDoc( pD )
      34             : {
      35         167 :     StartListening( *INetURLHistory::GetOrCreate() );
      36         167 : }
      37             : 
      38         501 : SwURLStateChanged::~SwURLStateChanged()
      39             : {
      40         167 :     EndListening( *INetURLHistory::GetOrCreate() );
      41         334 : }
      42             : 
      43         145 : void SwURLStateChanged::Notify( SfxBroadcaster& , const SfxHint& rHint )
      44             : {
      45         145 :     if( dynamic_cast<const INetURLHistoryHint*>(&rHint) && pDoc->getIDocumentLayoutAccess().GetCurrentViewShell() )
      46             :     {
      47             :         // This URL has been changed:
      48         145 :         const INetURLObject* pIURL = static_cast<const INetURLHistoryHint&>(rHint).GetObject();
      49         290 :         OUString sURL( pIURL->GetMainURL( INetURLObject::NO_DECODE ) ), sBkmk;
      50             : 
      51         145 :         SwEditShell* pESh = pDoc->GetEditShell();
      52             : 
      53         290 :         if( pDoc->GetDocShell() && pDoc->GetDocShell()->GetMedium() &&
      54             :             // If this is our Doc, we can also have local jumps!
      55         145 :             pDoc->GetDocShell()->GetMedium()->GetName().equals(sURL) )
      56         145 :             sBkmk = "#" + pIURL->GetMark();
      57             : 
      58         145 :         bool bAction = false, bUnLockView = false;
      59         145 :         sal_uInt32 nMaxItems = pDoc->GetAttrPool().GetItemCount2( RES_TXTATR_INETFMT );
      60        1164 :         for( sal_uInt32 n = 0; n < nMaxItems; ++n )
      61             :         {
      62        1019 :             const SwFormatINetFormat* pItem = static_cast<const SwFormatINetFormat*>(pDoc->GetAttrPool().GetItem2(RES_TXTATR_INETFMT, n ));
      63        1815 :             if( pItem != 0 &&
      64        1592 :                 ( pItem->GetValue() == sURL || ( !sBkmk.isEmpty() && pItem->GetValue() == sBkmk )))
      65             :             {
      66           0 :                 const SwTextINetFormat* pTextAttr = pItem->GetTextINetFormat();
      67           0 :                 if (pTextAttr != 0)
      68             :                 {
      69           0 :                     const SwTextNode* pTextNd = pTextAttr->GetpTextNode();
      70           0 :                     if (pTextNd != 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<SwTextINetFormat*>(pTextAttr)->SetVisitedValid(false);
      80           0 :                         const SwTextAttr* pAttr = pTextAttr;
      81             :                         SwUpdateAttr aUpdateAttr(
      82           0 :                             pAttr->GetStart(),
      83           0 :                             *pAttr->End(),
      84           0 :                             RES_FMT_CHG);
      85             : 
      86           0 :                         const_cast< SwTextNode* >(pTextNd)->ModifyNotification(&aUpdateAttr, &aUpdateAttr);
      87             :                     }
      88             :                 }
      89             :             }
      90             :         }
      91             : 
      92         145 :         if( bAction )
      93           0 :             pESh->EndAllAction();
      94         145 :         if( bUnLockView )
      95         145 :             pESh->LockView( false );
      96             :     }
      97         145 : }
      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        1792 : bool SwDoc::IsVisitedURL( const OUString& rURL )
     102             : {
     103        1792 :     bool bRet = false;
     104        1792 :     if( !rURL.isEmpty() )
     105             :     {
     106        1792 :         INetURLHistory *pHist = INetURLHistory::GetOrCreate();
     107        1792 :         if( '#' == rURL[0] && mpDocShell && mpDocShell->GetMedium() )
     108             :         {
     109        1201 :             INetURLObject aIObj( mpDocShell->GetMedium()->GetURLObject() );
     110        1201 :             aIObj.SetMark( rURL.copy( 1 ) );
     111        1201 :             bRet = pHist->QueryUrl( aIObj );
     112             :         }
     113             :         else
     114         591 :             bRet = pHist->QueryUrl( rURL );
     115             : 
     116             :         // We also want to be informed about status updates in the History
     117        1792 :         if( !mpURLStateChgd )
     118             :         {
     119         167 :             SwDoc* pD = this;
     120         167 :             pD->mpURLStateChgd = new SwURLStateChanged( this );
     121             :         }
     122             :     }
     123        1792 :     return bRet;
     124         177 : }
     125             : 
     126             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11