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