LibreOffice Module sw (master) 1
visiturl.cxx
Go to the documentation of this file.
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>
26#include <visiturl.hxx>
27#include <hints.hxx>
28#include <ndtxt.hxx>
29#include <editsh.hxx>
30#include <docsh.hxx>
31
33 : m_rDoc( rD )
34{
36}
37
39{
41}
42
44{
45 if( !(dynamic_cast<const INetURLHistoryHint*>(&rHint) && m_rDoc.getIDocumentLayoutAccess().GetCurrentViewShell()) )
46 return;
47
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;
51
53
55 // If this is our Doc, we can also have local jumps!
56 m_rDoc.GetDocShell()->GetMedium()->GetName() == sURL )
57 sBkmk = "#" + pIURL->GetMark();
58
59 bool bAction = false, bUnLockView = false;
61 {
62 const SwFormatINetFormat* pFormatItem = dynamic_cast<const SwFormatINetFormat*>(pItem);
63 if( pFormatItem != nullptr &&
64 ( pFormatItem->GetValue() == sURL || ( !sBkmk.isEmpty() && pFormatItem->GetValue() == sBkmk )))
65 {
66 const SwTextINetFormat* pTextAttr = pFormatItem->GetTextINetFormat();
67 if (pTextAttr != nullptr)
68 {
69 const SwTextNode* pTextNd = pTextAttr->GetpTextNode();
70 if (pTextNd != nullptr)
71 {
72 if( !bAction && pESh )
73 {
74 pESh->StartAllAction();
75 bAction = true;
76 bUnLockView = !pESh->IsViewLocked();
77 pESh->LockView( true );
78 }
79 const_cast<SwTextINetFormat*>(pTextAttr)->SetVisitedValid(false);
80 const SwTextAttr* pAttr = pTextAttr;
81 SwUpdateAttr aUpdateAttr(
82 pAttr->GetStart(),
83 *pAttr->End(),
85
86 const_cast<SwTextNode*>(pTextNd)->TriggerNodeUpdate(sw::LegacyModifyHint(&aUpdateAttr, &aUpdateAttr));
87 }
88 }
89 }
90 }
91
92 if( bAction )
93 pESh->EndAllAction();
94 if( bUnLockView )
95 pESh->LockView( false );
96}
97
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!
100bool SwDoc::IsVisitedURL( std::u16string_view rURL )
101{
102 bool bRet = false;
103 if( !rURL.empty() )
104 {
106 if( '#' == rURL[0] && mpDocShell && mpDocShell->GetMedium() )
107 {
109 aIObj.SetMark( rURL.substr( 1 ) );
110 bRet = pHist->QueryUrl( aIObj );
111 }
112 else
113 bRet = pHist->QueryUrl( rURL );
114
115 // We also want to be informed about status updates in the History
116 if( !mpURLStateChgd )
117 {
118 SwDoc* pD = this;
119 pD->mpURLStateChgd.reset( new SwURLStateChanged(*this) );
120 }
121 }
122 return bRet;
123}
124
125/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
static INetURLHistory * GetOrCreate()
bool QueryUrl(const INetURLObject &rUrl) const
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
OUString GetMark(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool SetMark(std::u16string_view rTheFragment, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
Item2Range GetItemSurrogates(sal_uInt16 nWhich) const
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
const INetURLObject & GetURLObject() const
const OUString & GetName() const
SfxMedium * GetMedium() const
Definition: doc.hxx:194
SwDocShell * mpDocShell
Definition: doc.hxx:266
std::unique_ptr< SwURLStateChanged > mpURLStateChgd
Definition: doc.hxx:271
SwEditShell const * GetEditShell() const
Definition: doccorr.cxx:329
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:411
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1326
bool IsVisitedURL(std::u16string_view rURL)
Definition: visiturl.cxx:100
SwDocShell * GetDocShell()
Definition: doc.hxx:1359
void StartAllAction()
For all views of this document.
Definition: edws.cxx:86
void EndAllAction()
Definition: edws.cxx:97
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
const SwTextINetFormat * GetTextINetFormat() const
Definition: fmtinfmt.hxx:70
A wrapper around SfxPoolItem to store the start position of (usually) a text portion,...
Definition: txatbase.hxx:44
const sal_Int32 * End() const
Definition: txatbase.hxx:156
sal_Int32 GetStart() const
Definition: txatbase.hxx:88
const SwTextNode * GetpTextNode() const
Definition: txtinet.hxx:45
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:111
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: visiturl.cxx:43
virtual ~SwURLStateChanged() override
Definition: visiturl.cxx:38
SwURLStateChanged(SwDoc &rD)
Definition: visiturl.cxx:32
bool IsViewLocked() const
Definition: viewsh.hxx:471
void LockView(bool b)
Definition: viewsh.hxx:472
virtual css::uno::Reference< css::embed::XEmbeddedObject > GetObject() override
SwDoc & m_rDoc
Definition: docbm.cxx:1202
constexpr TypedWhichId< SwFormatINetFormat > RES_TXTATR_INETFMT(51)
constexpr TypedWhichId< SwFormatChg > RES_FMT_CHG(162)