xref: /trunk/main/sw/source/core/doc/visiturl.cxx (revision cdf0e10c4e3984b49a9502b011690b615761d4a3)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include <sfx2/docfile.hxx>
33 #include <svl/inethist.hxx>
34 #include <fmtinfmt.hxx>
35 #include <txtinet.hxx>
36 #include <doc.hxx>
37 #include <visiturl.hxx>
38 #include <hints.hxx>
39 #include <ndtxt.hxx>
40 #include <editsh.hxx>
41 #include <docsh.hxx>
42 
43 
44 SwURLStateChanged::SwURLStateChanged( const SwDoc* pD )
45     : pDoc( pD )
46 {
47     StartListening( *INetURLHistory::GetOrCreate() );
48 }
49 
50 SwURLStateChanged::~SwURLStateChanged()
51 {
52     EndListening( *INetURLHistory::GetOrCreate() );
53 }
54 
55 void SwURLStateChanged::Notify( SfxBroadcaster& , const SfxHint& rHint )
56 {
57     if( rHint.ISA( INetURLHistoryHint ) && pDoc->GetCurrentViewShell() )    //swmod 071108//swmod 071225
58     {
59         // diese URL wurde veraendert:
60         const INetURLObject* pIURL = ((INetURLHistoryHint&)rHint).GetObject();
61         String sURL( pIURL->GetMainURL( INetURLObject::NO_DECODE ) ), sBkmk;
62 
63         SwEditShell* pESh = pDoc->GetEditShell();
64 
65         if( pDoc->GetDocShell() && pDoc->GetDocShell()->GetMedium() &&
66             // falls das unser Doc ist, kann es auch lokale Spruenge geben!
67             sURL == pDoc->GetDocShell()->GetMedium()->GetName() )
68             (sBkmk = pIURL->GetMark()).Insert( INET_MARK_TOKEN, 0 );
69 
70         sal_Bool bAction = sal_False, bUnLockView = sal_False;
71         const SwFmtINetFmt* pItem;
72         const SwTxtINetFmt* pTxtAttr;
73         const SwTxtNode* pTxtNd;
74         sal_uInt32 n, nMaxItems = pDoc->GetAttrPool().GetItemCount2( RES_TXTATR_INETFMT );
75         for( n = 0; n < nMaxItems; ++n )
76             if( 0 != (pItem = (SwFmtINetFmt*)pDoc->GetAttrPool().GetItem2(
77                 RES_TXTATR_INETFMT, n ) ) &&
78                 ( pItem->GetValue() == sURL ||
79                     ( sBkmk.Len() && pItem->GetValue() == sBkmk )) &&
80                 0 != ( pTxtAttr = pItem->GetTxtINetFmt()) &&
81                 0 != ( pTxtNd = pTxtAttr->GetpTxtNode() ) )
82             {
83                 if( !bAction && pESh )
84                 {
85                     pESh->StartAllAction();
86                     bAction = sal_True;
87                     bUnLockView = !pESh->IsViewLocked();
88                     pESh->LockView( sal_True );
89                 }
90                 const_cast<SwTxtINetFmt*>(pTxtAttr)->SetVisitedValid( false );
91                 const SwTxtAttr* pAttr = pTxtAttr;
92                 SwUpdateAttr aUpdateAttr( *pAttr->GetStart(),
93                                           *pAttr->GetEnd(),
94                                           RES_FMT_CHG );
95                 ((SwTxtNode*)pTxtNd)->ModifyNotification( &aUpdateAttr, &aUpdateAttr );
96             }
97 
98         if( bAction )
99             pESh->EndAllAction();
100         if( bUnLockView )
101             pESh->LockView( sal_False );
102     }
103 }
104 
105     // erfrage ob die URL besucht war. Uebers Doc, falls nur ein Bookmark
106     // angegeben ist. Dann muss der Doc. Name davor gesetzt werden!
107 sal_Bool SwDoc::IsVisitedURL( const String& rURL ) const
108 {
109 #if OSL_DEBUG_LEVEL > 1
110     static long nTmp = 0;
111     ++nTmp;
112 #endif
113 
114     sal_Bool bRet = sal_False;
115     if( rURL.Len() )
116     {
117         INetURLHistory *pHist = INetURLHistory::GetOrCreate();
118         if( '#' == rURL.GetChar( 0 ) && pDocShell && pDocShell->GetMedium() )
119         {
120             INetURLObject aIObj( pDocShell->GetMedium()->GetURLObject() );
121             aIObj.SetMark( rURL.Copy( 1 ) );
122             bRet = pHist->QueryUrl( aIObj );
123         }
124         else
125             bRet = pHist->QueryUrl( rURL );
126 
127         // dann  wollen wird auch ueber Statusaenderungen in der History
128         // informiert werden!
129         if( !pURLStateChgd )
130         {
131             SwDoc* pD = (SwDoc*)this;
132             pD->pURLStateChgd = new SwURLStateChanged( this );
133         }
134     }
135     return bRet;
136 }
137 
138 
139 
140