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  : pDoc( pD )
34 {
36 }
37 
39 {
41 }
42 
44 {
45  if( dynamic_cast<const INetURLHistoryHint*>(&rHint) && pDoc->getIDocumentLayoutAccess().GetCurrentViewShell() )
46  {
47  // This URL has been changed:
48  const INetURLObject* pIURL = static_cast<const INetURLHistoryHint&>(rHint).GetObject();
49  OUString sURL( pIURL->GetMainURL( INetURLObject::DecodeMechanism::NONE ) ), sBkmk;
50 
51  SwEditShell* pESh = pDoc->GetEditShell();
52 
53  if( pDoc->GetDocShell() && pDoc->GetDocShell()->GetMedium() &&
54  // If this is our Doc, we can also have local jumps!
55  pDoc->GetDocShell()->GetMedium()->GetName() == sURL )
56  sBkmk = "#" + pIURL->GetMark();
57 
58  bool bAction = false, bUnLockView = false;
60  {
61  const SwFormatINetFormat* pFormatItem = dynamic_cast<const SwFormatINetFormat*>(pItem);
62  if( pFormatItem != nullptr &&
63  ( pFormatItem->GetValue() == sURL || ( !sBkmk.isEmpty() && pFormatItem->GetValue() == sBkmk )))
64  {
65  const SwTextINetFormat* pTextAttr = pFormatItem->GetTextINetFormat();
66  if (pTextAttr != nullptr)
67  {
68  const SwTextNode* pTextNd = pTextAttr->GetpTextNode();
69  if (pTextNd != nullptr)
70  {
71  if( !bAction && pESh )
72  {
73  pESh->StartAllAction();
74  bAction = true;
75  bUnLockView = !pESh->IsViewLocked();
76  pESh->LockView( true );
77  }
78  const_cast<SwTextINetFormat*>(pTextAttr)->SetVisitedValid(false);
79  const SwTextAttr* pAttr = pTextAttr;
80  SwUpdateAttr aUpdateAttr(
81  pAttr->GetStart(),
82  *pAttr->End(),
83  RES_FMT_CHG);
84 
85  const_cast< SwTextNode* >(pTextNd)->ModifyNotification(&aUpdateAttr, &aUpdateAttr);
86  }
87  }
88  }
89  }
90 
91  if( bAction )
92  pESh->EndAllAction();
93  if( bUnLockView )
94  pESh->LockView( false );
95  }
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:1340
const OUString & GetName() const
Definition: doc.hxx:185
bool IsVisitedURL(const OUString &rURL)
Definition: visiturl.cxx:100
SwURLStateChanged(SwDoc *pD)
Definition: visiturl.cxx:32
const SwTextINetFormat * GetTextINetFormat() const
Definition: fmtinfmt.hxx:70
std::unique_ptr< SwURLStateChanged > mpURLStateChgd
Definition: doc.hxx:262
const OUString & GetValue() const
Definition: fmtinfmt.hxx:75
sal_Int32 GetStart() const
Definition: txatbase.hxx:82
SwDocShell * mpDocShell
Definition: doc.hxx:257
static INetURLHistory * GetOrCreate()
SwEditShell const * GetEditShell() const
Definition: doccorr.cxx:323
virtual ~SwURLStateChanged() override
Definition: visiturl.cxx:38
void StartListening(SfxBroadcaster &rBroadcaster, DuplicateHandling eDuplicateHanding=DuplicateHandling::Unexpected)
const SwTextNode * GetpTextNode() const
Definition: txtinet.hxx:46
#define RES_FMT_CHG
Definition: hintids.hxx:284
#define RES_TXTATR_INETFMT
Definition: hintids.hxx:141
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:437
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:79
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:1307
SfxMedium * GetMedium() const