xref: /aoo41x/main/sw/source/core/doc/visiturl.cxx (revision 69a74367)
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( *pAttr->GetStart(),
89 										  *pAttr->End(),
90 										  RES_FMT_CHG );
91                 ((SwTxtNode*)pTxtNd)->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
92 			}
93 
94 		if( bAction )
95 			pESh->EndAllAction();
96  		if( bUnLockView )
97      		pESh->LockView( sal_False );
98 	}
99 }
100 
101 	// erfrage ob die URL besucht war. Uebers Doc, falls nur ein Bookmark
102 	// angegeben ist. Dann muss der Doc. Name davor gesetzt werden!
IsVisitedURL(const String & rURL) const103 sal_Bool SwDoc::IsVisitedURL( const String& rURL ) const
104 {
105 #if OSL_DEBUG_LEVEL > 1
106 	static long nTmp = 0;
107 	++nTmp;
108 #endif
109 
110 	sal_Bool bRet = sal_False;
111 	if( rURL.Len() )
112 	{
113 		INetURLHistory *pHist = INetURLHistory::GetOrCreate();
114 		if( '#' == rURL.GetChar( 0 ) && pDocShell && pDocShell->GetMedium() )
115 		{
116 			INetURLObject aIObj( pDocShell->GetMedium()->GetURLObject() );
117 			aIObj.SetMark( rURL.Copy( 1 ) );
118 			bRet = pHist->QueryUrl( aIObj );
119 		}
120 		else
121 			bRet = pHist->QueryUrl( rURL );
122 
123 		// dann  wollen wird auch ueber Statusaenderungen in der History
124 		// informiert werden!
125 		if( !pURLStateChgd )
126 		{
127 			SwDoc* pD = (SwDoc*)this;
128 			pD->pURLStateChgd = new SwURLStateChanged( this );
129 		}
130 	}
131 	return bRet;
132 }
133 
134 
135 
136