LCOV - code coverage report
Current view: top level - libreoffice/sw/source/core/doc - visiturl.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 35 51 68.6 %
Date: 2012-12-17 Functions: 5 5 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 <visiturl.hxx>
      26             : #include <hints.hxx>
      27             : #include <ndtxt.hxx>
      28             : #include <editsh.hxx>
      29             : #include <docsh.hxx>
      30             : 
      31             : 
      32          12 : SwURLStateChanged::SwURLStateChanged( const SwDoc* pD )
      33          12 :     : pDoc( pD )
      34             : {
      35          12 :     StartListening( *INetURLHistory::GetOrCreate() );
      36          12 : }
      37             : 
      38          24 : SwURLStateChanged::~SwURLStateChanged()
      39             : {
      40           8 :     EndListening( *INetURLHistory::GetOrCreate() );
      41          16 : }
      42             : 
      43          96 : void SwURLStateChanged::Notify( SfxBroadcaster& , const SfxHint& rHint )
      44             : {
      45          96 :     if( rHint.ISA( INetURLHistoryHint ) && pDoc->GetCurrentViewShell() )    //swmod 071108//swmod 071225
      46             :     {
      47             :         // This URL has been changed:
      48          92 :         const INetURLObject* pIURL = ((INetURLHistoryHint&)rHint).GetObject();
      49          92 :         String sURL( pIURL->GetMainURL( INetURLObject::NO_DECODE ) ), sBkmk;
      50             : 
      51          92 :         SwEditShell* pESh = pDoc->GetEditShell();
      52             : 
      53         368 :         if( pDoc->GetDocShell() && pDoc->GetDocShell()->GetMedium() &&
      54             :             // If this is our Doc, we can also have local jumps!
      55         276 :             pDoc->GetDocShell()->GetMedium()->GetName().equals(sURL) )
      56           4 :             (sBkmk = pIURL->GetMark()).Insert( INET_MARK_TOKEN, 0 );
      57             : 
      58          92 :         bool bAction = false, bUnLockView = false;
      59             :         const SwFmtINetFmt* pItem;
      60             :         const SwTxtINetFmt* pTxtAttr;
      61             :         const SwTxtNode* pTxtNd;
      62          92 :         sal_uInt32 n, nMaxItems = pDoc->GetAttrPool().GetItemCount2( RES_TXTATR_INETFMT );
      63         366 :         for( n = 0; n < nMaxItems; ++n )
      64         736 :             if( 0 != (pItem = (SwFmtINetFmt*)pDoc->GetAttrPool().GetItem2(
      65         274 :                 RES_TXTATR_INETFMT, n ) ) &&
      66          92 :                 ( pItem->GetValue() == sURL ||
      67          96 :                     ( sBkmk.Len() && pItem->GetValue() == sBkmk )) &&
      68             :                 0 != ( pTxtAttr = pItem->GetTxtINetFmt()) &&
      69             :                 0 != ( pTxtNd = pTxtAttr->GetpTxtNode() ) )
      70             :             {
      71           0 :                 if( !bAction && pESh )
      72             :                 {
      73           0 :                     pESh->StartAllAction();
      74           0 :                     bAction = true;
      75           0 :                     bUnLockView = !pESh->IsViewLocked();
      76           0 :                     pESh->LockView( sal_True );
      77             :                 }
      78           0 :                 const_cast<SwTxtINetFmt*>(pTxtAttr)->SetVisitedValid( false );
      79           0 :                 const SwTxtAttr* pAttr = pTxtAttr;
      80           0 :                 SwUpdateAttr aUpdateAttr( *pAttr->GetStart(),
      81           0 :                                           *pAttr->GetEnd(),
      82           0 :                                           RES_FMT_CHG );
      83           0 :                 ((SwTxtNode*)pTxtNd)->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
      84             :             }
      85             : 
      86          92 :         if( bAction )
      87           0 :             pESh->EndAllAction();
      88          92 :          if( bUnLockView )
      89           0 :              pESh->LockView( sal_False );
      90             :     }
      91          96 : }
      92             : 
      93             : // Check if the URL has been visited before. Via the Doc, if only one Bookmark is set
      94             : // We need to put the Doc's name before it!
      95          16 : bool SwDoc::IsVisitedURL( const String& rURL ) const
      96             : {
      97          16 :     bool bRet = false;
      98          16 :     if( rURL.Len() )
      99             :     {
     100          16 :         INetURLHistory *pHist = INetURLHistory::GetOrCreate();
     101          16 :         if( '#' == rURL.GetChar( 0 ) && pDocShell && pDocShell->GetMedium() )
     102             :         {
     103           0 :             INetURLObject aIObj( pDocShell->GetMedium()->GetURLObject() );
     104           0 :             aIObj.SetMark( rURL.Copy( 1 ) );
     105           0 :             bRet = pHist->QueryUrl( aIObj );
     106             :         }
     107             :         else
     108          16 :             bRet = pHist->QueryUrl( rURL );
     109             : 
     110             :         // We also want to be informed about status updates in the History
     111          16 :         if( !pURLStateChgd )
     112             :         {
     113          12 :             SwDoc* pD = (SwDoc*)this;
     114          12 :             pD->pURLStateChgd = new SwURLStateChanged( this );
     115             :         }
     116             :     }
     117          16 :     return bRet;
     118             : }
     119             : 
     120             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10