Files
libreoffice/sw/source/core/doc/visiturl.cxx

146 lines
4.8 KiB
C++
Raw Normal View History

2000-09-18 23:08:29 +00:00
/*************************************************************************
*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
2000-09-18 23:08:29 +00:00
*
* Copyright 2008 by Sun Microsystems, Inc.
2000-09-18 23:08:29 +00:00
*
* OpenOffice.org - a multi-platform office productivity suite
2000-09-18 23:08:29 +00:00
*
* $RCSfile: visiturl.cxx,v $
* $Revision: 1.9 $
2000-09-18 23:08:29 +00:00
*
* This file is part of OpenOffice.org.
2000-09-18 23:08:29 +00:00
*
* OpenOffice.org is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License version 3
* only, as published by the Free Software Foundation.
2000-09-18 23:08:29 +00:00
*
* OpenOffice.org is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License version 3 for more details
* (a copy is included in the LICENSE file that accompanied this code).
2000-09-18 23:08:29 +00:00
*
* You should have received a copy of the GNU Lesser General Public License
* version 3 along with OpenOffice.org. If not, see
* <http://www.openoffice.org/license.html>
* for a copy of the LGPLv3 License.
2000-09-18 23:08:29 +00:00
*
************************************************************************/
// MARKER(update_precomp.py): autogen include statement, do not remove
#include "precompiled_sw.hxx"
2000-09-18 23:08:29 +00:00
#include <sfx2/docfile.hxx>
#include <svtools/inethist.hxx>
#include <fmtinfmt.hxx>
#include <txtinet.hxx>
#include <doc.hxx>
#include <visiturl.hxx>
#include <hints.hxx>
#include <ndtxt.hxx>
#include <editsh.hxx>
#ifndef _DOCSH_HXX
#include <docsh.hxx>
#endif
SwURLStateChanged::SwURLStateChanged( const SwDoc* pD )
: pDoc( pD )
{
StartListening( *INetURLHistory::GetOrCreate() );
}
SwURLStateChanged::~SwURLStateChanged()
{
EndListening( *INetURLHistory::GetOrCreate() );
}
void SwURLStateChanged::Notify( SfxBroadcaster& , const SfxHint& rHint )
2000-09-18 23:08:29 +00:00
{
if( rHint.ISA( INetURLHistoryHint ) && pDoc->GetRootFrm() )
{
// diese URL wurde veraendert:
const INetURLObject* pIURL = ((INetURLHistoryHint&)rHint).GetObject();
String sURL( pIURL->GetMainURL( INetURLObject::NO_DECODE ) ), sBkmk;
2000-09-18 23:08:29 +00:00
SwEditShell* pESh = pDoc->GetEditShell();
if( pDoc->GetDocShell() && pDoc->GetDocShell()->GetMedium() &&
// falls das unser Doc ist, kann es auch lokale Spruenge geben!
sURL == pDoc->GetDocShell()->GetMedium()->GetName() )
(sBkmk = pIURL->GetMark()).Insert( INET_MARK_TOKEN, 0 );
BOOL bAction = FALSE, bUnLockView = FALSE;
const SwFmtINetFmt* pItem;
const SwTxtINetFmt* pTxtAttr;
const SwTxtNode* pTxtNd;
USHORT n, nMaxItems = pDoc->GetAttrPool().GetItemCount( RES_TXTATR_INETFMT );
for( n = 0; n < nMaxItems; ++n )
if( 0 != (pItem = (SwFmtINetFmt*)pDoc->GetAttrPool().GetItem(
RES_TXTATR_INETFMT, n ) ) &&
( pItem->GetValue() == sURL ||
( sBkmk.Len() && pItem->GetValue() == sBkmk )) &&
0 != ( pTxtAttr = pItem->GetTxtINetFmt()) &&
0 != ( pTxtNd = pTxtAttr->GetpTxtNode() ) )
{
if( !bAction && pESh )
{
pESh->StartAllAction();
bAction = TRUE;
bUnLockView = !pESh->IsViewLocked();
pESh->LockView( TRUE );
}
((SwTxtINetFmt*)pTxtAttr)->SetValidVis( FALSE );
const SwTxtAttr* pAttr = pTxtAttr;
SwUpdateAttr aUpdateAttr( *pAttr->GetStart(),
*pAttr->GetEnd(),
RES_FMT_CHG );
((SwTxtNode*)pTxtNd)->SwCntntNode::Modify( &aUpdateAttr,
&aUpdateAttr );
}
if( bAction )
pESh->EndAllAction();
if( bUnLockView )
pESh->LockView( FALSE );
}
}
// erfrage ob die URL besucht war. Uebers Doc, falls nur ein Bookmark
// angegeben ist. Dann muss der Doc. Name davor gesetzt werden!
BOOL SwDoc::IsVisitedURL( const String& rURL ) const
{
#if OSL_DEBUG_LEVEL > 1
2000-09-18 23:08:29 +00:00
static long nTmp = 0;
++nTmp;
#endif
BOOL bRet = FALSE;
if( rURL.Len() )
{
INetURLHistory *pHist = INetURLHistory::GetOrCreate();
if( '#' == rURL.GetChar( 0 ) && pDocShell && pDocShell->GetMedium() )
{
INetURLObject aIObj( pDocShell->GetMedium()->GetURLObject() );
aIObj.SetMark( rURL.Copy( 1 ) );
bRet = pHist->QueryUrl( aIObj );
}
else
bRet = pHist->QueryUrl( rURL );
// dann wollen wird auch ueber Statusaenderungen in der History
// informiert werden!
if( !pURLStateChgd )
{
SwDoc* pD = (SwDoc*)this;
pD->pURLStateChgd = new SwURLStateChanged( this );
}
}
return bRet;
}