diff options
Diffstat (limited to 'svl/source/notify')
-rw-r--r-- | svl/source/notify/brdcst.cxx | 210 | ||||
-rw-r--r-- | svl/source/notify/broadcast.cxx | 148 | ||||
-rw-r--r-- | svl/source/notify/cancel.cxx | 203 | ||||
-rw-r--r-- | svl/source/notify/hint.cxx | 47 | ||||
-rw-r--r-- | svl/source/notify/isethint.cxx | 75 | ||||
-rw-r--r-- | svl/source/notify/listener.cxx | 164 | ||||
-rw-r--r-- | svl/source/notify/listenerbase.cxx | 79 | ||||
-rw-r--r-- | svl/source/notify/listenerbase.hxx | 59 | ||||
-rw-r--r-- | svl/source/notify/listeneriter.cxx | 192 | ||||
-rw-r--r-- | svl/source/notify/lstner.cxx | 191 | ||||
-rw-r--r-- | svl/source/notify/makefile.mk | 62 | ||||
-rw-r--r-- | svl/source/notify/smplhint.cxx | 47 |
12 files changed, 1477 insertions, 0 deletions
diff --git a/svl/source/notify/brdcst.cxx b/svl/source/notify/brdcst.cxx new file mode 100644 index 000000000000..82462a57f430 --- /dev/null +++ b/svl/source/notify/brdcst.cxx @@ -0,0 +1,210 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svl.hxx" + +#include <tools/debug.hxx> + +#include <svl/hint.hxx> +#include <svl/smplhint.hxx> +#include <svl/lstner.hxx> + +SV_DECL_PTRARR( SfxListenerArr_Impl, SfxListener*, 0, 2 ) + +#define _SFX_BRDCST_CXX +#include <svl/brdcst.hxx> + +//==================================================================== +DBG_NAME(SfxBroadcaster) +TYPEINIT0(SfxBroadcaster); + +//==================================================================== + +//==================================================================== +// broadcast immediately + + +void SfxBroadcaster::Broadcast( const SfxHint &rHint ) +{ + DBG_CHKTHIS(SfxBroadcaster, 0); + + // is anybody to notify? + if ( aListeners.Count() /*! || aGlobListeners.Count() */ ) + { + // notify all registered listeners exactly once + for ( USHORT n = 0; n < aListeners.Count(); ++n ) + { + SfxListener* pListener = aListeners[n]; + if ( pListener ) + pListener->Notify( *this, rHint ); + } + } +} + +//-------------------------------------------------------------------- + +// broadcast after a timeout + + +void SfxBroadcaster::BroadcastDelayed( const SfxHint& rHint ) +{ + DBG_WARNING( "not implemented" ); + Broadcast(rHint); +} +//-------------------------------------------------------------------- + +// broadcast in idle-handler + +void SfxBroadcaster::BroadcastInIdle( const SfxHint& rHint ) +{ + DBG_WARNING( "not implemented" ); + Broadcast(rHint); +} +//-------------------------------------------------------------------- + +// unregister all listeners + +SfxBroadcaster::~SfxBroadcaster() +{ + DBG_DTOR(SfxBroadcaster, 0); + + Broadcast( SfxSimpleHint(SFX_HINT_DYING) ); + + // remove all still registered listeners + for ( USHORT nPos = 0; nPos < aListeners.Count(); ++nPos ) + { + SfxListener *pListener = aListeners[nPos]; + if ( pListener ) + pListener->RemoveBroadcaster_Impl(*this); + } +} + +//-------------------------------------------------------------------- + +// simple ctor of class SfxBroadcaster + +SfxBroadcaster::SfxBroadcaster() +{ + DBG_CTOR(SfxBroadcaster, 0); +} + +//-------------------------------------------------------------------- + +// copy ctor of class SfxBroadcaster + + +SfxBroadcaster::SfxBroadcaster( const SfxBroadcaster &rBC ) +{ + DBG_CTOR(SfxBroadcaster, 0); + + for ( USHORT n = 0; n < rBC.aListeners.Count(); ++n ) + { + SfxListener *pListener = rBC.aListeners[n]; + if ( pListener ) + pListener->StartListening( *this ); + } +} + +//-------------------------------------------------------------------- + +// add a new SfxListener to the list + +BOOL SfxBroadcaster::AddListener( SfxListener& rListener ) +{ + DBG_CHKTHIS(SfxBroadcaster, 0); + const SfxListener *pListener = &rListener; + const SfxListener *pNull = 0; + USHORT nFreePos = aListeners.GetPos( pNull ); + if ( nFreePos < aListeners.Count() ) + aListeners.GetData()[nFreePos] = pListener; + else if ( aListeners.Count() < (USHRT_MAX-1) ) + aListeners.Insert( pListener, aListeners.Count() ); + else + { + DBG_ERROR( "array overflow" ); + return FALSE; + } + + DBG_ASSERT( USHRT_MAX != aListeners.GetPos(pListener), + "AddListener failed" ); + return TRUE; +} + +//-------------------------------------------------------------------- + +// called, if no more listeners exists + +void SfxBroadcaster::ListenersGone() +{ + DBG_CHKTHIS(SfxBroadcaster,0); +} + +//-------------------------------------------------------------------- + +// forward a notification to all registered listeners + +void SfxBroadcaster::Forward(SfxBroadcaster& rBC, const SfxHint& rHint) +{ + const USHORT nCount = aListeners.Count(); + for ( USHORT i = 0; i < nCount; ++i ) + { + SfxListener *pListener = aListeners[i]; + if ( pListener ) + pListener->Notify( rBC, rHint ); + } +} + +//-------------------------------------------------------------------- + +// remove one SfxListener from the list + +void SfxBroadcaster::RemoveListener( SfxListener& rListener ) +{ + {DBG_CHKTHIS(SfxBroadcaster, 0);} + const SfxListener *pListener = &rListener; + USHORT nPos = aListeners.GetPos(pListener); + DBG_ASSERT( nPos != USHRT_MAX, "RemoveListener: Listener unknown" ); + aListeners.GetData()[nPos] = 0; + if ( !HasListeners() ) + ListenersGone(); +} + +//-------------------------------------------------------------------- + +BOOL SfxBroadcaster::HasListeners() const +{ + for ( USHORT n = 0; n < aListeners.Count(); ++n ) + if ( aListeners.GetObject(n) != 0 ) + return TRUE; + return FALSE; +} + +//-------------------------------------------------------------------- + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/broadcast.cxx b/svl/source/notify/broadcast.cxx new file mode 100644 index 000000000000..16220033dbf8 --- /dev/null +++ b/svl/source/notify/broadcast.cxx @@ -0,0 +1,148 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svl.hxx" + +#include <tools/debug.hxx> + +#include "listener.hxx" +#include "listeneriter.hxx" +#include "broadcast.hxx" +#include <svl/smplhint.hxx> + + +//==================================================================== +TYPEINIT0(SvtBroadcaster); + +//==================================================================== + +// simple ctor of class SvtBroadcaster + +SvtBroadcaster::SvtBroadcaster() + : pRoot( 0 ) +{ +} + +//-------------------------------------------------------------------- + +// copy ctor of class SvtBroadcaster + +SvtBroadcaster::SvtBroadcaster( const SvtBroadcaster &rBC ) + : pRoot( 0 ) +{ + SvtListenerIter aIter( (SvtBroadcaster&)rBC ); + SvtListener* pLast = aIter.GoStart(); + if( pLast ) + do { + pLast->StartListening( *this ); + } while( 0 != ( pLast = aIter.GoNext() )); +} + +//-------------------------------------------------------------------- + +// unregister all listeners + +SvtBroadcaster::~SvtBroadcaster() +{ + Broadcast( SfxSimpleHint(SFX_HINT_DYING) ); + + SvtListenerIter aIter( *this ); + SvtListener* pLast = aIter.GoStart(); + if( pLast ) + do { + pLast->EndListening( *this ); + if( !HasListeners() ) // all gone ?? + break; + } while( 0 != ( pLast = aIter.GoNext() )); +} + +//-------------------------------------------------------------------- + +// broadcast immedeately + +void SvtBroadcaster::Broadcast( const SfxHint &rHint ) +{ + // is anybody to notify? + if( HasListeners() /* && !IsModifyLocked()*/ ) + { +// LockModify(); +// bInModify = TRUE; + + SvtListenerIter aIter( *this ); + SvtListener* pLast = aIter.GoStart(); + if( pLast ) + do { + pLast->Notify( *this, rHint ); + if( !HasListeners() ) // all gone ?? + break; + } while( 0 != ( pLast = aIter.GoNext() )); + +// bInModify = FALSE; +// UnlockModify(); + } +} + +//-------------------------------------------------------------------- + + +// called, if no more listeners exists + +void SvtBroadcaster::ListenersGone() +{ +} + +//-------------------------------------------------------------------- + +// forward a notification to all registered listeners + +void SvtBroadcaster::Forward( SvtBroadcaster& rBC, const SfxHint& rHint ) +{ + // is anybody to notify? + if( rBC.HasListeners() /* && !IsModifyLocked()*/ ) + { +// LockModify(); +// bInModify = TRUE; + + SvtListenerIter aIter( rBC ); + SvtListener* pLast = aIter.GoStart(); + if( pLast ) + do { + pLast->Notify( rBC, rHint ); + if( !rBC.HasListeners() ) // all gone ?? + break; + } while( 0 != ( pLast = aIter.GoNext() )); + +// bInModify = FALSE; +// UnlockModify(); + } +} + + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/cancel.cxx b/svl/source/notify/cancel.cxx new file mode 100644 index 000000000000..76ac32d4211d --- /dev/null +++ b/svl/source/notify/cancel.cxx @@ -0,0 +1,203 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svl.hxx" +#define _SFX_CANCEL_CXX +#include <svl/cancel.hxx> + +#include <osl/mutex.hxx> +#include <tools/debug.hxx> + +#include <svl/smplhint.hxx> +#include <svl/cnclhint.hxx> +#include <rtl/instance.hxx> + +namespace { struct lclMutex : public rtl::Static< ::osl::Mutex, lclMutex >{}; } + +//========================================================================= + +SfxCancelManager::SfxCancelManager( SfxCancelManager *pParent ) +: _pParent( pParent ) +{ +} + +//------------------------------------------------------------------------- + +SfxCancelManager::~SfxCancelManager() +{ + DBG_ASSERT( _pParent || !_aJobs.Count(), "deleting SfxCancelManager in use" ); + for ( USHORT n = _aJobs.Count(); n--; ) + _aJobs.GetObject(n)->SetManager( _pParent ); +} + +//------------------------------------------------------------------------- + +BOOL SfxCancelManager::CanCancel() const + +/* [Beschreibung] + + Liefert TRUE wenn an diesem CancelManager oder an einem Parent + ein Job l"auft. +*/ + +{ + ::osl::MutexGuard aGuard( lclMutex::get() ); + return _aJobs.Count() > 0 || ( _pParent && _pParent->CanCancel() ); +} + +//------------------------------------------------------------------------- + +void SfxCancelManager::Cancel( BOOL bDeep ) + +/* [Beschreibung] + + Diese Methode markiert alle angemeldeten <SfxCancellable>-Instanzen + als suspendiert. +*/ + +{ + ::osl::MutexGuard aGuard( lclMutex::get() ); + SfxCancelManagerWeak xWeak( this ); + for ( USHORT n = _aJobs.Count(); n-- && xWeak.Is(); ) + if ( n < _aJobs.Count() ) + _aJobs.GetObject(n)->Cancel(); + if ( xWeak.Is() && _pParent ) + _pParent->Cancel( bDeep ); +} + +//------------------------------------------------------------------------- + +void SfxCancelManager::InsertCancellable( SfxCancellable *pJob ) + +/* [Beschreibung] + + Diese interne Methode tr"agt 'pJob' in die Liste der unterbrechbaren + Jobs ein und Broadcastet dies. Jeder <SfxCancellable> darf nur + maximal einmal angemeldet sein, dies geschiet in seinem Ctor. +*/ + +{ +#ifdef GPF_ON_EMPTY_TITLE + if ( !pJob->GetTitle() ) + { + DBG_ERROR( "SfxCancellable: empty titles not allowed (Vermummungsverbot)" ) + *(int*)0 = 0; + } +#endif + + ::osl::ClearableMutexGuard aGuard( lclMutex::get() ); + _aJobs.C40_INSERT( SfxCancellable, pJob, _aJobs.Count() ); + + aGuard.clear(); + Broadcast( SfxSimpleHint( SFX_HINT_CANCELLABLE ) ); +} + +//------------------------------------------------------------------------- + + +void SfxCancelManager::RemoveCancellable( SfxCancellable *pJob ) + +/* [Beschreibung] + + Diese interne Methode tr"agt 'pJob' aus die Liste der unterbrechbaren + Jobs aus und Broadcastet dies. Dieser Aufruf mu\s paarig nach einem + <InsertCancellable> erfolgen und wird im Dtor des <SfxCancellable> + ausgel"ost. +*/ + +{ + ::osl::ClearableMutexGuard aGuard( lclMutex::get() ); + const SfxCancellable *pTmp = pJob; + USHORT nPos = _aJobs.GetPos( pTmp ); + if ( nPos != 0xFFFF ) + { + _aJobs.Remove( nPos , 1 ); + aGuard.clear(); + Broadcast( SfxSimpleHint( SFX_HINT_CANCELLABLE ) ); + Broadcast( SfxCancelHint( pJob, SFXCANCELHINT_REMOVED ) ); + } +} + +//------------------------------------------------------------------------- + +SfxCancellable::~SfxCancellable() +{ + SfxCancelManager* pMgr = _pMgr; + if ( pMgr ) + pMgr->RemoveCancellable( this ); +} + +//------------------------------------------------------------------------- + +void SfxCancellable::Cancel() + +/* [Description] + + This virtual function is called when the user hits the cancel-button. + If you overload it, you can stop your activities. Please always call + 'SfxCancellable::Cancel()'. +*/ + +{ +#ifdef GFP_ON_NO_CANCEL + if ( _bCancelled < 5 ) + ++_bCancelled; + else + { + delete this; + } +#else + _bCancelled = TRUE; +#endif +} + +//------------------------------------------------------------------------- + +void SfxCancellable::SetManager( SfxCancelManager *pMgr ) +{ + SfxCancelManager* pTmp = _pMgr; + if ( pTmp ) + pTmp->RemoveCancellable( this ); + _pMgr = pMgr; + if ( pMgr ) + pMgr->InsertCancellable( this ); +} + +//------------------------------------------------------------------------- + +TYPEINIT1(SfxCancelHint, SfxHint); + +SfxCancelHint::SfxCancelHint( SfxCancellable* pJob, USHORT _nAction ) +{ + pCancellable = pJob; + nAction = _nAction; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/hint.cxx b/svl/source/notify/hint.cxx new file mode 100644 index 000000000000..268e5e337483 --- /dev/null +++ b/svl/source/notify/hint.cxx @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svl.hxx" + +#include <svl/hint.hxx> + +//==================================================================== + +TYPEINIT0(SfxHint); + +//==================================================================== +// virtual dtor for the typical base-class Hint + +SfxHint::~SfxHint() +{ +} + + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/isethint.cxx b/svl/source/notify/isethint.cxx new file mode 100644 index 000000000000..f408044bdefb --- /dev/null +++ b/svl/source/notify/isethint.cxx @@ -0,0 +1,75 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svl.hxx" + +#include <svl/isethint.hxx> +#include <svl/itemset.hxx> + +//==================================================================== + +TYPEINIT1(SfxItemSetHint, SfxHint); + +//==================================================================== + +SfxItemSetHint::SfxItemSetHint( SfxItemSet *pItemSet ) + +/* [Beschreibung] + + Dieser Ctor "ubernimmt das als Parameter "ubergeben <SfxItemSet>, + das im Dtor gel"oscht wird. +*/ + +: _pItemSet( pItemSet ) +{ +} + +//-------------------------------------------------------------------- + +SfxItemSetHint::SfxItemSetHint( const SfxItemSet &rItemSet ) + +/* [Beschreibung] + + Dieser Ctor kopiert das als Parameter "ubergeben <SfxItemSet>. +*/ + +: _pItemSet( rItemSet.Clone() ) +{ +} + +//-------------------------------------------------------------------- + +SfxItemSetHint::~SfxItemSetHint() +{ + delete _pItemSet; +} + +//-------------------------------------------------------------------- + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/listener.cxx b/svl/source/notify/listener.cxx new file mode 100644 index 000000000000..70a4b2d23cd5 --- /dev/null +++ b/svl/source/notify/listener.cxx @@ -0,0 +1,164 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svl.hxx" + +#include <tools/debug.hxx> + +#include "broadcast.hxx" +#include "listener.hxx" +#include "listenerbase.hxx" +#include "listeneriter.hxx" + + +//==================================================================== +TYPEINIT0(SvtListener); + +//==================================================================== +// simple ctor of class SvtListener + +SvtListener::SvtListener() + : pBrdCastLst( 0 ) +{ +} +//-------------------------------------------------------------------- + +// copy ctor of class SvtListener + +SvtListener::SvtListener( const SvtListener &rListener ) + : pBrdCastLst( 0 ) +{ + SvtListenerBase* pLst = rListener.pBrdCastLst; + while( pLst ) + { + new SvtListenerBase( *this, *pLst->GetBroadcaster() ); + pLst = pLst->GetNext(); + } +} +//-------------------------------------------------------------------- + +// unregisteres the SvtListener from its SvtBroadcasters + +SvtListener::~SvtListener() +{ + EndListeningAll(); +} + +//-------------------------------------------------------------------- + +// registeres at a specific SvtBroadcaster + +BOOL SvtListener::StartListening( SvtBroadcaster& rBroadcaster ) +{ + const SvtListenerBase* pLst = pBrdCastLst; + while( pLst ) + { + if( &rBroadcaster == pLst->GetBroadcaster() ) + { + // double, than return + return FALSE; + } + pLst = pLst->GetNext(); + } + new SvtListenerBase( *this, rBroadcaster ); + return TRUE; +} + +//-------------------------------------------------------------------- + +// unregisteres at a specific SvtBroadcaster + +BOOL SvtListener::EndListening( SvtBroadcaster& rBroadcaster ) +{ + SvtListenerBase *pLst = pBrdCastLst, *pPrev = pLst; + while( pLst ) + { + if( &rBroadcaster == pLst->GetBroadcaster() ) + { + if( pBrdCastLst == pLst ) + pBrdCastLst = pLst->GetNext(); + else + pPrev->SetNext( pLst->GetNext() ); + + delete pLst; + return TRUE; + } + pPrev = pLst; + pLst = pLst->GetNext(); + } + return FALSE; +} + +//-------------------------------------------------------------------- + +// unregisteres all Broadcasters + +void SvtListener::EndListeningAll() +{ + SvtListenerBase *pLst = pBrdCastLst; + while( pLst ) + { + SvtListenerBase *pDel = pLst; + pLst = pLst->GetNext(); + + delete pDel; + } + pBrdCastLst = 0; +} + +//-------------------------------------------------------------------- + +BOOL SvtListener::IsListening( SvtBroadcaster& rBroadcaster ) const +{ + const SvtListenerBase *pLst = pBrdCastLst; + while( pLst ) + { + if( &rBroadcaster == pLst->GetBroadcaster() ) + break; + pLst = pLst->GetNext(); + } + return 0 != pLst; +} + +//-------------------------------------------------------------------- + +// base implementation of notification handler + +void SvtListener::Notify( SvtBroadcaster& +#ifdef DBG_UTIL +rBC +#endif +, const SfxHint& ) +{ + DBG_ASSERT( IsListening( rBC ), + "notification from unregistered broadcaster" ); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/listenerbase.cxx b/svl/source/notify/listenerbase.cxx new file mode 100644 index 000000000000..ffc2b1819ea6 --- /dev/null +++ b/svl/source/notify/listenerbase.cxx @@ -0,0 +1,79 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svl.hxx" + +#include <tools/debug.hxx> + +#include "listenerbase.hxx" +#include "listeneriter.hxx" +#include "listener.hxx" +#include "broadcast.hxx" + + +SvtListenerBase::SvtListenerBase( SvtListener& rLst, + SvtBroadcaster& rBroadcaster ) + : pLeft( 0 ), pRight( 0 ), + pBroadcaster( &rBroadcaster ), pListener( &rLst ) +{ + pNext = rLst.pBrdCastLst; + rLst.pBrdCastLst = this; + + if( pBroadcaster->pRoot ) + { + // set ever behind the root + pRight = pBroadcaster->pRoot->pRight; + pBroadcaster->pRoot->pRight = this; + this->pLeft = pBroadcaster->pRoot; + if( pRight ) + pRight->pLeft = this; + } + else + pBroadcaster->pRoot = this; +} + +SvtListenerBase::~SvtListenerBase() +{ + SvtListenerBase *pR = pRight, *pL = pLeft; + if( pBroadcaster->pRoot ) + pBroadcaster->pRoot = pL ? pL : pR; + + if( pL ) + pL->pRight = pR; + if( pR ) + pR->pLeft = pL; + + SvtListenerIter::RemoveListener( *this, pR ); + + if( !pBroadcaster->pRoot ) + pBroadcaster->ListenersGone(); +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/listenerbase.hxx b/svl/source/notify/listenerbase.hxx new file mode 100644 index 000000000000..db661afbee94 --- /dev/null +++ b/svl/source/notify/listenerbase.hxx @@ -0,0 +1,59 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ +#ifndef _SVT_LISTENERBASE_HXX +#define _SVT_LISTENERBASE_HXX + +class SvtBroadcaster; +class SvtListener; + +class SvtListenerBase +{ + SvtListenerBase *pNext; + SvtListenerBase *pLeft, *pRight; + SvtBroadcaster *pBroadcaster; + SvtListener *pListener; + +public: + + SvtListenerBase( SvtListener& rLst, SvtBroadcaster& rBroadcaster ); + ~SvtListenerBase(); + + SvtListenerBase* GetNext() const { return pNext; } + void SetNext( SvtListenerBase* p ) { pNext = p; } + + SvtBroadcaster* GetBroadcaster() const { return pBroadcaster; } + SvtListener* GetListener() const { return pListener; } + + SvtListenerBase* GetLeft() const { return pLeft; } + SvtListenerBase* GetRight() const { return pRight; } +}; + + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/listeneriter.cxx b/svl/source/notify/listeneriter.cxx new file mode 100644 index 000000000000..46646f441fe6 --- /dev/null +++ b/svl/source/notify/listeneriter.cxx @@ -0,0 +1,192 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svl.hxx" +#include <tools/debug.hxx> + +#include "listenerbase.hxx" +#include "listeneriter.hxx" +#include "broadcast.hxx" +#include "listener.hxx" + +SvtListenerIter* SvtListenerIter::pListenerIters = 0; + +SvtListenerIter::SvtListenerIter( SvtBroadcaster& rBrdcst ) + : rRoot( rBrdcst ) +{ + // hinten einketten! + pNxtIter = 0; + if( pListenerIters ) + { + SvtListenerIter* pTmp = pListenerIters; + while( pTmp->pNxtIter ) + pTmp = pTmp->pNxtIter; + pTmp->pNxtIter = this; + } + else + pListenerIters = this; + + pAkt = rRoot.pRoot; + pDelNext = pAkt; +} + + + +SvtListenerIter::~SvtListenerIter() +{ + if( pListenerIters ) + { + if( pListenerIters == this ) + pListenerIters = pNxtIter; + else + { + SvtListenerIter* pTmp = pListenerIters; + while( pTmp->pNxtIter != this ) + if( 0 == ( pTmp = pTmp->pNxtIter ) ) + return ; + pTmp->pNxtIter = pNxtIter; + } + } +} + +void SvtListenerIter::RemoveListener( SvtListenerBase& rDel, + SvtListenerBase* pNext ) +{ + // Update the ListenerIter + SvtListenerIter* pTmp = pListenerIters; + while( pTmp ) + { + if( pTmp->pAkt == &rDel || pTmp->pDelNext == &rDel ) + pTmp->pDelNext = pNext; + pTmp = pTmp->pNxtIter; + } +} + +SvtListener* SvtListenerIter::GoNext() +{ + if( pDelNext == pAkt ) + { + pAkt = pAkt->GetRight(); + pDelNext = pAkt; + } + else + pAkt = pDelNext; + return pAkt ? pAkt->GetListener() : 0; +} + + +SvtListener* SvtListenerIter::GoPrev() +{ + if( pDelNext == pAkt ) + pAkt = pAkt->GetLeft(); + else + pAkt = pDelNext->GetLeft(); + pDelNext = pAkt; + return pAkt ? pAkt->GetListener() : 0; +} + + +SvtListener* SvtListenerIter::GoStart() // zum Anfang des Baums +{ + pAkt = rRoot.pRoot; + if( pAkt ) + while( pAkt->GetLeft() ) + pAkt = pAkt->GetLeft(); + pDelNext = pAkt; + return pAkt ? pAkt->GetListener() : 0; +} + + +SvtListener* SvtListenerIter::GoEnd() // zum End des Baums +{ + pAkt = pDelNext; + if( !pAkt ) + pAkt = rRoot.pRoot; + if( pAkt ) + while( pAkt->GetRight() ) + pAkt = pAkt->GetRight(); + pDelNext = pAkt; + return pAkt ? pAkt->GetListener() : 0; +} + + + +SvtListener* SvtListenerIter::First( TypeId nType ) +{ + aSrchId = nType; + GoStart(); + if( pAkt ) + do { + if( pAkt->GetListener()->IsA( aSrchId ) ) + break; + + if( pDelNext == pAkt ) + { + pAkt = pAkt->GetRight(); + pDelNext = pAkt; + } + else + pAkt = pDelNext; + + } while( pAkt ); + return pAkt ? pAkt->GetListener() : 0; +} + + +SvtListener* SvtListenerIter::Next() +{ + do { + // erstmal zum naechsten + if( pDelNext == pAkt ) + { + pAkt = pAkt->GetRight(); + pDelNext = pAkt; + } + else + pAkt = pDelNext; + + if( pAkt && pAkt->GetListener()->IsA( aSrchId ) ) + break; + } while( pAkt ); + return pAkt ? pAkt->GetListener() : 0; +} + + +SvtListener* SvtListenerIter::GoRoot() // wieder ab Root anfangen +{ + pDelNext = pAkt = rRoot.pRoot; + return pAkt ? pAkt->GetListener() : 0; +} + +SvtListener* SvtListenerIter::GetCurr() const // returns the current +{ + return pDelNext ? pDelNext->GetListener() : 0; +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/lstner.cxx b/svl/source/notify/lstner.cxx new file mode 100644 index 000000000000..498862e67638 --- /dev/null +++ b/svl/source/notify/lstner.cxx @@ -0,0 +1,191 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svl.hxx" + +#include <tools/debug.hxx> + +#include <svl/hint.hxx> +#include <svl/brdcst.hxx> + +SV_DECL_PTRARR( SfxBroadcasterArr_Impl, SfxBroadcaster*, 0, 2 ) + +#define _SFX_LSTNER_CXX +#include <svl/lstner.hxx> + +//==================================================================== +DBG_NAME(SfxListener) +TYPEINIT0(SfxListener); + +//==================================================================== +// simple ctor of class SfxListener + +SfxListener::SfxListener() +{ + DBG_CTOR(SfxListener, 0); +} +//-------------------------------------------------------------------- + +// copy ctor of class SfxListener + +SfxListener::SfxListener( const SfxListener &rListener ) +{ + DBG_CTOR(SfxListener, 0); + + for ( USHORT n = 0; n < rListener.aBCs.Count(); ++n ) + StartListening( *rListener.aBCs[n] ); +} +//-------------------------------------------------------------------- + +// unregisteres the SfxListener from its SfxBroadcasters + +SfxListener::~SfxListener() +{ + DBG_DTOR(SfxListener, 0); + + // unregister at all remainding broadcasters + for ( USHORT nPos = 0; nPos < aBCs.Count(); ++nPos ) + { + SfxBroadcaster *pBC = aBCs[nPos]; + pBC->RemoveListener(*this); + } +} + +//-------------------------------------------------------------------- + +// unregisteres at a specific SfxBroadcaster + +void SfxListener::RemoveBroadcaster_Impl( SfxBroadcaster& rBC ) +{ + DBG_CHKTHIS(SfxListener, 0); + + const SfxBroadcaster *pBC = &rBC; + aBCs.Remove( aBCs.GetPos(pBC), 1 ); +} + +//-------------------------------------------------------------------- + +// registeres at a specific SfxBroadcaster + +BOOL SfxListener::StartListening( SfxBroadcaster& rBroadcaster, BOOL bPreventDups ) +{ + DBG_CHKTHIS(SfxListener, 0); + + if ( !bPreventDups || !IsListening( rBroadcaster ) ) + { + if ( rBroadcaster.AddListener(*this) ) + { + const SfxBroadcaster *pBC = &rBroadcaster; + aBCs.Insert( pBC, aBCs.Count() ); + + DBG_ASSERT( IsListening(rBroadcaster), "StartListening failed" ); + return TRUE; + } + + } + return FALSE; +} + +//-------------------------------------------------------------------- + +// unregisteres at a specific SfxBroadcaster + +BOOL SfxListener::EndListening( SfxBroadcaster& rBroadcaster, BOOL bAllDups ) +{ + DBG_CHKTHIS(SfxListener, 0); + + if ( !IsListening( rBroadcaster ) ) + return FALSE; + + do + { + rBroadcaster.RemoveListener(*this); + const SfxBroadcaster *pBC = &rBroadcaster; + aBCs.Remove( aBCs.GetPos(pBC), 1 ); + } + while ( bAllDups && IsListening( rBroadcaster ) ); + return TRUE; +} + +//-------------------------------------------------------------------- + +// unregisteres at a specific SfxBroadcaster by index + +void SfxListener::EndListening( USHORT nNo ) +{ + DBG_CHKTHIS(SfxListener, 0); + + SfxBroadcaster *pBC = aBCs.GetObject(nNo); + pBC->RemoveListener(*this); + aBCs.Remove( nNo, 1 ); +} + +//-------------------------------------------------------------------- + +// unregisteres all Broadcasters + +void SfxListener::EndListeningAll() +{ + DBG_CHKTHIS(SfxListener, 0); + + // MI: bei Optimierung beachten: Seiteneffekte von RemoveListener beachten! + while ( aBCs.Count() ) + { + SfxBroadcaster *pBC = aBCs.GetObject(0); + pBC->RemoveListener(*this); + aBCs.Remove( 0, 1 ); + } +} + +//-------------------------------------------------------------------- + +BOOL SfxListener::IsListening( SfxBroadcaster& rBroadcaster ) const +{ + const SfxBroadcaster *pBC = &rBroadcaster; + return USHRT_MAX != aBCs.GetPos( pBC ); +} + +//-------------------------------------------------------------------- + +// base implementation of notification handler + +#ifdef DBG_UTIL +void SfxListener::Notify( SfxBroadcaster& rBC, const SfxHint& ) +#else +void SfxListener::Notify( SfxBroadcaster&, const SfxHint& ) +#endif +{ + #ifdef DBG_UTIL + const SfxBroadcaster *pBC = &rBC; + DBG_ASSERT( USHRT_MAX != aBCs.GetPos(pBC), + "notification from unregistered broadcaster" ); + #endif +} + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/svl/source/notify/makefile.mk b/svl/source/notify/makefile.mk new file mode 100644 index 000000000000..c2e6648907e5 --- /dev/null +++ b/svl/source/notify/makefile.mk @@ -0,0 +1,62 @@ +#************************************************************************* +# +# DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. +# +# Copyright 2000, 2010 Oracle and/or its affiliates. +# +# OpenOffice.org - a multi-platform office productivity suite +# +# This file is part of OpenOffice.org. +# +# 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. +# +# 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). +# +# 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. +# +#************************************************************************* + +PRJ=..$/.. + +PRJNAME=svl +TARGET=notify + +# --- Settings ----------------------------------------------------- + +.INCLUDE : settings.mk +.INCLUDE : $(PRJ)$/util$/svl.pmk + +# --- Files -------------------------------------------------------- + +SLOFILES = \ + $(SLO)$/smplhint.obj \ + $(SLO)$/hint.obj \ + $(SLO)$/lstner.obj \ + $(SLO)$/isethint.obj \ + $(SLO)$/brdcst.obj \ + $(SLO)$/listener.obj \ + $(SLO)$/listenerbase.obj \ + $(SLO)$/listeneriter.obj \ + $(SLO)$/broadcast.obj + +HXX1TARGET= notify +HXX1EXT= hxx +HXX1FILES= $(INC)$/hint.hxx \ + $(INC)$/smplhint.hxx \ + $(INC)$/lstner.hxx \ + $(INC)$/brdcst.hxx +HXX1EXCL= -E:*include* + +# --- Targets ------------------------------------------------------- + +.INCLUDE : target.mk + diff --git a/svl/source/notify/smplhint.cxx b/svl/source/notify/smplhint.cxx new file mode 100644 index 000000000000..784bfb1df170 --- /dev/null +++ b/svl/source/notify/smplhint.cxx @@ -0,0 +1,47 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/************************************************************************* + * + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. + * + * Copyright 2000, 2010 Oracle and/or its affiliates. + * + * OpenOffice.org - a multi-platform office productivity suite + * + * This file is part of OpenOffice.org. + * + * 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. + * + * 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). + * + * 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. + * + ************************************************************************/ + +// MARKER(update_precomp.py): autogen include statement, do not remove +#include "precompiled_svl.hxx" + +#include <svl/smplhint.hxx> + +//==================================================================== + +TYPEINIT1(SfxSimpleHint, SfxHint); + +//==================================================================== +// creates a SimpleHint with the type nId + +SfxSimpleHint::SfxSimpleHint( ULONG nIdP ) +{ + nId = nIdP; +} + + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |