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 6 : SwURLStateChanged::SwURLStateChanged( const SwDoc* pD )
33 6 : : pDoc( pD )
34 : {
35 6 : StartListening( *INetURLHistory::GetOrCreate() );
36 6 : }
37 :
38 12 : SwURLStateChanged::~SwURLStateChanged()
39 : {
40 4 : EndListening( *INetURLHistory::GetOrCreate() );
41 8 : }
42 :
43 48 : void SwURLStateChanged::Notify( SfxBroadcaster& , const SfxHint& rHint )
44 : {
45 48 : if( rHint.ISA( INetURLHistoryHint ) && pDoc->GetCurrentViewShell() ) //swmod 071108//swmod 071225
46 : {
47 : // This URL has been changed:
48 46 : const INetURLObject* pIURL = ((INetURLHistoryHint&)rHint).GetObject();
49 46 : String sURL( pIURL->GetMainURL( INetURLObject::NO_DECODE ) ), sBkmk;
50 :
51 46 : SwEditShell* pESh = pDoc->GetEditShell();
52 :
53 184 : if( pDoc->GetDocShell() && pDoc->GetDocShell()->GetMedium() &&
54 : // If this is our Doc, we can also have local jumps!
55 138 : pDoc->GetDocShell()->GetMedium()->GetName().equals(sURL) )
56 2 : (sBkmk = pIURL->GetMark()).Insert( INET_MARK_TOKEN, 0 );
57 :
58 46 : bool bAction = false, bUnLockView = false;
59 : const SwFmtINetFmt* pItem;
60 : const SwTxtINetFmt* pTxtAttr;
61 : const SwTxtNode* pTxtNd;
62 46 : sal_uInt32 n, nMaxItems = pDoc->GetAttrPool().GetItemCount2( RES_TXTATR_INETFMT );
63 183 : for( n = 0; n < nMaxItems; ++n )
64 368 : if( 0 != (pItem = (SwFmtINetFmt*)pDoc->GetAttrPool().GetItem2(
65 137 : RES_TXTATR_INETFMT, n ) ) &&
66 46 : ( pItem->GetValue() == sURL ||
67 48 : ( 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 46 : if( bAction )
87 0 : pESh->EndAllAction();
88 46 : if( bUnLockView )
89 0 : pESh->LockView( sal_False );
90 : }
91 48 : }
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 8 : bool SwDoc::IsVisitedURL( const String& rURL ) const
96 : {
97 8 : bool bRet = false;
98 8 : if( rURL.Len() )
99 : {
100 8 : INetURLHistory *pHist = INetURLHistory::GetOrCreate();
101 8 : 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 8 : bRet = pHist->QueryUrl( rURL );
109 :
110 : // We also want to be informed about status updates in the History
111 8 : if( !pURLStateChgd )
112 : {
113 6 : SwDoc* pD = (SwDoc*)this;
114 6 : pD->pURLStateChgd = new SwURLStateChanged( this );
115 : }
116 : }
117 8 : return bRet;
118 : }
119 :
120 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|