xref: /trunk/main/sw/source/core/doc/visiturl.cxx (revision cf6516809c57e1bb0a940545cca99cdad54d4ce2)
1efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5efeef26fSAndrew Rist  * distributed with this work for additional information
6efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10cdf0e10cSrcweir  *
11efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12cdf0e10cSrcweir  *
13efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17efeef26fSAndrew Rist  * specific language governing permissions and limitations
18efeef26fSAndrew Rist  * under the License.
19cdf0e10cSrcweir  *
20efeef26fSAndrew Rist  *************************************************************/
21efeef26fSAndrew Rist 
22efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir 
28cdf0e10cSrcweir #include <sfx2/docfile.hxx>
29cdf0e10cSrcweir #include <svl/inethist.hxx>
30cdf0e10cSrcweir #include <fmtinfmt.hxx>
31cdf0e10cSrcweir #include <txtinet.hxx>
32cdf0e10cSrcweir #include <doc.hxx>
33cdf0e10cSrcweir #include <visiturl.hxx>
34cdf0e10cSrcweir #include <hints.hxx>
35cdf0e10cSrcweir #include <ndtxt.hxx>
36cdf0e10cSrcweir #include <editsh.hxx>
37cdf0e10cSrcweir #include <docsh.hxx>
38cdf0e10cSrcweir 
39cdf0e10cSrcweir 
SwURLStateChanged(const SwDoc * pD)40cdf0e10cSrcweir SwURLStateChanged::SwURLStateChanged( const SwDoc* pD )
41cdf0e10cSrcweir     : pDoc( pD )
42cdf0e10cSrcweir {
43cdf0e10cSrcweir     StartListening( *INetURLHistory::GetOrCreate() );
44cdf0e10cSrcweir }
45cdf0e10cSrcweir 
~SwURLStateChanged()46cdf0e10cSrcweir SwURLStateChanged::~SwURLStateChanged()
47cdf0e10cSrcweir {
48cdf0e10cSrcweir     EndListening( *INetURLHistory::GetOrCreate() );
49cdf0e10cSrcweir }
50cdf0e10cSrcweir 
Notify(SfxBroadcaster &,const SfxHint & rHint)51cdf0e10cSrcweir void SwURLStateChanged::Notify( SfxBroadcaster& , const SfxHint& rHint )
52cdf0e10cSrcweir {
53cdf0e10cSrcweir     if( rHint.ISA( INetURLHistoryHint ) && pDoc->GetCurrentViewShell() )    //swmod 071108//swmod 071225
54cdf0e10cSrcweir     {
55cdf0e10cSrcweir         // diese URL wurde veraendert:
56cdf0e10cSrcweir         const INetURLObject* pIURL = ((INetURLHistoryHint&)rHint).GetObject();
57cdf0e10cSrcweir         String sURL( pIURL->GetMainURL( INetURLObject::NO_DECODE ) ), sBkmk;
58cdf0e10cSrcweir 
59cdf0e10cSrcweir         SwEditShell* pESh = pDoc->GetEditShell();
60cdf0e10cSrcweir 
61cdf0e10cSrcweir         if( pDoc->GetDocShell() && pDoc->GetDocShell()->GetMedium() &&
62cdf0e10cSrcweir             // falls das unser Doc ist, kann es auch lokale Spruenge geben!
63cdf0e10cSrcweir             sURL == pDoc->GetDocShell()->GetMedium()->GetName() )
64cdf0e10cSrcweir             (sBkmk = pIURL->GetMark()).Insert( INET_MARK_TOKEN, 0 );
65cdf0e10cSrcweir 
66cdf0e10cSrcweir         sal_Bool bAction = sal_False, bUnLockView = sal_False;
67cdf0e10cSrcweir         const SwFmtINetFmt* pItem;
68cdf0e10cSrcweir         const SwTxtINetFmt* pTxtAttr;
69cdf0e10cSrcweir         const SwTxtNode* pTxtNd;
70cdf0e10cSrcweir         sal_uInt32 n, nMaxItems = pDoc->GetAttrPool().GetItemCount2( RES_TXTATR_INETFMT );
71cdf0e10cSrcweir         for( n = 0; n < nMaxItems; ++n )
72cdf0e10cSrcweir             if( 0 != (pItem = (SwFmtINetFmt*)pDoc->GetAttrPool().GetItem2(
73cdf0e10cSrcweir                 RES_TXTATR_INETFMT, n ) ) &&
74cdf0e10cSrcweir                 ( pItem->GetValue() == sURL ||
75cdf0e10cSrcweir                     ( sBkmk.Len() && pItem->GetValue() == sBkmk )) &&
76cdf0e10cSrcweir                 0 != ( pTxtAttr = pItem->GetTxtINetFmt()) &&
77cdf0e10cSrcweir                 0 != ( pTxtNd = pTxtAttr->GetpTxtNode() ) )
78cdf0e10cSrcweir             {
79cdf0e10cSrcweir                 if( !bAction && pESh )
80cdf0e10cSrcweir                 {
81cdf0e10cSrcweir                     pESh->StartAllAction();
82cdf0e10cSrcweir                     bAction = sal_True;
83cdf0e10cSrcweir                     bUnLockView = !pESh->IsViewLocked();
84cdf0e10cSrcweir                     pESh->LockView( sal_True );
85cdf0e10cSrcweir                 }
86cdf0e10cSrcweir                 const_cast<SwTxtINetFmt*>(pTxtAttr)->SetVisitedValid(false);
87cdf0e10cSrcweir                 const SwTxtAttr* pAttr = pTxtAttr;
88*56b35d86SArmin Le Grand                 SwUpdateAttr aUpdateAttr(
89*56b35d86SArmin Le Grand                     *pAttr->GetStart(),
9069a74367SOliver-Rainer Wittmann                     *pAttr->End(),
91cdf0e10cSrcweir                     RES_FMT_CHG);
92*56b35d86SArmin Le Grand 
93*56b35d86SArmin Le Grand                 const_cast< SwTxtNode* >(pTxtNd)->ModifyNotification(&aUpdateAttr, &aUpdateAttr);
94cdf0e10cSrcweir             }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         if( bAction )
97cdf0e10cSrcweir             pESh->EndAllAction();
98cdf0e10cSrcweir         if( bUnLockView )
99cdf0e10cSrcweir             pESh->LockView( sal_False );
100cdf0e10cSrcweir     }
101cdf0e10cSrcweir }
102cdf0e10cSrcweir 
103cdf0e10cSrcweir     // erfrage ob die URL besucht war. Uebers Doc, falls nur ein Bookmark
104cdf0e10cSrcweir     // angegeben ist. Dann muss der Doc. Name davor gesetzt werden!
IsVisitedURL(const String & rURL) const105cdf0e10cSrcweir sal_Bool SwDoc::IsVisitedURL( const String& rURL ) const
106cdf0e10cSrcweir {
107cdf0e10cSrcweir #if OSL_DEBUG_LEVEL > 1
108cdf0e10cSrcweir     static long nTmp = 0;
109cdf0e10cSrcweir     ++nTmp;
110cdf0e10cSrcweir #endif
111cdf0e10cSrcweir 
112cdf0e10cSrcweir     sal_Bool bRet = sal_False;
113cdf0e10cSrcweir     if( rURL.Len() )
114cdf0e10cSrcweir     {
115cdf0e10cSrcweir         INetURLHistory *pHist = INetURLHistory::GetOrCreate();
116cdf0e10cSrcweir         if( '#' == rURL.GetChar( 0 ) && pDocShell && pDocShell->GetMedium() )
117cdf0e10cSrcweir         {
118cdf0e10cSrcweir             INetURLObject aIObj( pDocShell->GetMedium()->GetURLObject() );
119cdf0e10cSrcweir             aIObj.SetMark( rURL.Copy( 1 ) );
120cdf0e10cSrcweir             bRet = pHist->QueryUrl( aIObj );
121cdf0e10cSrcweir         }
122cdf0e10cSrcweir         else
123cdf0e10cSrcweir             bRet = pHist->QueryUrl( rURL );
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         // dann  wollen wird auch ueber Statusaenderungen in der History
126cdf0e10cSrcweir         // informiert werden!
127cdf0e10cSrcweir         if( !pURLStateChgd )
128cdf0e10cSrcweir         {
129cdf0e10cSrcweir             SwDoc* pD = (SwDoc*)this;
130cdf0e10cSrcweir             pD->pURLStateChgd = new SwURLStateChanged( this );
131cdf0e10cSrcweir         }
132cdf0e10cSrcweir     }
133cdf0e10cSrcweir     return bRet;
134cdf0e10cSrcweir }
135