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(),
84  RES_FMT_CHG);
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!
100 bool SwDoc::IsVisitedURL( const OUString& rURL )
101 {
102  bool bRet = false;
103  if( !rURL.isEmpty() )
104  {
106  if( '#' == rURL[0] && mpDocShell && mpDocShell->GetMedium() )
107  {
109  aIObj.SetMark( rURL.copy( 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: */
SwDocShell * GetDocShell()
Definition: doc.hxx:1350
const OUString & GetName() const
Definition: doc.hxx:186
bool IsVisitedURL(const OUString &rURL)
Definition: visiturl.cxx:100
const SwTextINetFormat * GetTextINetFormat() const
Definition: fmtinfmt.hxx:70
std::unique_ptr< SwURLStateChanged > mpURLStateChgd
Definition: doc.hxx:263
SwDoc & m_rDoc
Definition: docbm.cxx:1205
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
constexpr TypedWhichId< SwFormatChg > RES_FMT_CHG(160)
SwDocShell * mpDocShell
Definition: doc.hxx:258
constexpr TypedWhichId< SwFormatINetFormat > RES_TXTATR_INETFMT(51)
static INetURLHistory * GetOrCreate()
SwEditShell const * GetEditShell() const
Definition: doccorr.cxx:328
virtual ~SwURLStateChanged() override
Definition: visiturl.cxx:38
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
const SwTextNode * GetpTextNode() const
Definition: txtinet.hxx:46
SwURLStateChanged(SwDoc &rD)
Definition: visiturl.cxx:32
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:405
bool QueryUrl(const INetURLObject &rUrl)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
SwTextNode is a paragraph in the document model.
Definition: ndtxt.hxx:80
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
Item2Range GetItemSurrogates(sal_uInt16 nWhich) const
void EndListening(SfxBroadcaster &rBroadcaster, bool bRemoveAllDuplicates=false)
const sal_Int32 * End() const
Definition: txatbase.hxx:148
const INetURLObject & GetURLObject() const
bool SetMark(OUString const &rTheFragment, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8)
virtual void Notify(SfxBroadcaster &rBC, const SfxHint &rHint) override
Definition: visiturl.cxx:43
OUString GetMark(DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
const SwAttrPool & GetAttrPool() const
Definition: doc.hxx:1317
SfxMedium * GetMedium() const