1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sfx2/docfile.hxx>
21 #include <svl/inethist.hxx>
22 #include <fmtinfmt.hxx>
23 #include <txtinet.hxx>
25 #include <IDocumentLayoutAccess.hxx>
26 #include <visiturl.hxx>
32 SwURLStateChanged::SwURLStateChanged( SwDoc
& rD
)
35 StartListening( *INetURLHistory::GetOrCreate() );
38 SwURLStateChanged::~SwURLStateChanged()
40 EndListening( *INetURLHistory::GetOrCreate() );
43 void SwURLStateChanged::Notify( SfxBroadcaster
& , const SfxHint
& rHint
)
45 if( !(dynamic_cast<const INetURLHistoryHint
*>(&rHint
) && m_rDoc
.getIDocumentLayoutAccess().GetCurrentViewShell()) )
48 // This URL has been changed:
49 const INetURLObject
* pIURL
= static_cast<const INetURLHistoryHint
&>(rHint
).GetObject();
50 OUString
sURL( pIURL
->GetMainURL( INetURLObject::DecodeMechanism::NONE
) ), sBkmk
;
52 SwEditShell
* pESh
= m_rDoc
.GetEditShell();
54 if( m_rDoc
.GetDocShell() && m_rDoc
.GetDocShell()->GetMedium() &&
55 // If this is our Doc, we can also have local jumps!
56 m_rDoc
.GetDocShell()->GetMedium()->GetName() == sURL
)
57 sBkmk
= "#" + pIURL
->GetMark();
59 bool bAction
= false, bUnLockView
= false;
60 for (const SfxPoolItem
* pItem
: m_rDoc
.GetAttrPool().GetItemSurrogates(RES_TXTATR_INETFMT
))
62 const SwFormatINetFormat
* pFormatItem
= dynamic_cast<const SwFormatINetFormat
*>(pItem
);
63 if( pFormatItem
!= nullptr &&
64 ( pFormatItem
->GetValue() == sURL
|| ( !sBkmk
.isEmpty() && pFormatItem
->GetValue() == sBkmk
)))
66 const SwTextINetFormat
* pTextAttr
= pFormatItem
->GetTextINetFormat();
67 if (pTextAttr
!= nullptr)
69 const SwTextNode
* pTextNd
= pTextAttr
->GetpTextNode();
70 if (pTextNd
!= nullptr)
72 if( !bAction
&& pESh
)
74 pESh
->StartAllAction();
76 bUnLockView
= !pESh
->IsViewLocked();
77 pESh
->LockView( true );
79 const_cast<SwTextINetFormat
*>(pTextAttr
)->SetVisitedValid(false);
80 const SwTextAttr
* pAttr
= pTextAttr
;
81 SwUpdateAttr
aUpdateAttr(
86 const_cast<SwTextNode
*>(pTextNd
)->TriggerNodeUpdate(sw::LegacyModifyHint(&aUpdateAttr
, &aUpdateAttr
));
95 pESh
->LockView( false );
98 // Check if the URL has been visited before. Via the Doc, if only one Bookmark is set
99 // We need to put the Doc's name before it!
100 bool SwDoc::IsVisitedURL( std::u16string_view rURL
)
105 INetURLHistory
*pHist
= INetURLHistory::GetOrCreate();
106 if( '#' == rURL
[0] && mpDocShell
&& mpDocShell
->GetMedium() )
108 INetURLObject
aIObj( mpDocShell
->GetMedium()->GetURLObject() );
109 aIObj
.SetMark( rURL
.substr( 1 ) );
110 bRet
= pHist
->QueryUrl( aIObj
);
113 bRet
= pHist
->QueryUrl( rURL
);
115 // We also want to be informed about status updates in the History
116 if( !mpURLStateChgd
)
119 pD
->mpURLStateChgd
.reset( new SwURLStateChanged(*this) );
125 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */