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_sc.hxx"
30 #include "DrawModelBroadcaster.hxx"
31 #include <svx/svdmodel.hxx>
32 #include <svx/unomod.hxx>
33 #include <tools/debug.hxx>
34 
35 using namespace	::com::sun::star;
36 
37 ScDrawModelBroadcaster::ScDrawModelBroadcaster( SdrModel *pDrawModel ) :
38 	maEventListeners( maListenerMutex ),
39 	mpDrawModel( pDrawModel )
40 {
41     if (mpDrawModel)
42 	    StartListening( *mpDrawModel );
43 }
44 
45 ScDrawModelBroadcaster::~ScDrawModelBroadcaster()
46 {
47     if (mpDrawModel)
48 	    EndListening( *mpDrawModel );
49 }
50 
51 void SAL_CALL ScDrawModelBroadcaster::addEventListener( const uno::Reference< document::XEventListener >& xListener )
52     throw (uno::RuntimeException)
53 {
54 	maEventListeners.addInterface( xListener );
55 }
56 
57 void SAL_CALL ScDrawModelBroadcaster::removeEventListener( const uno::Reference< document::XEventListener >& xListener )
58     throw (uno::RuntimeException)
59 {
60 	maEventListeners.removeInterface( xListener );
61 }
62 
63 void ScDrawModelBroadcaster::Notify( SfxBroadcaster&,
64 		const SfxHint& rHint )
65 {
66 	const SdrHint *pSdrHint = PTR_CAST( SdrHint, &rHint );
67 	if( !pSdrHint )
68 		return;
69 
70     document::EventObject aEvent;
71 	if( !SvxUnoDrawMSFactory::createEvent( mpDrawModel, pSdrHint, aEvent ) )
72 		return;
73 
74 	::cppu::OInterfaceIteratorHelper aIter( maEventListeners );
75 	while( aIter.hasMoreElements() )
76 	{
77         uno::Reference < document::XEventListener > xListener( aIter.next(), uno::UNO_QUERY );
78 		try
79 		{
80 			xListener->notifyEvent( aEvent );
81 		}
82 		catch( uno::RuntimeException& r )
83 		{
84             (void) r;
85 #if OSL_DEBUG_LEVEL > 1
86 			ByteString aError( "Runtime exception caught while notifying shape.:\n" );
87 			aError += ByteString( String( r.Message), RTL_TEXTENCODING_ASCII_US );
88 			DBG_ERROR( aError.GetBuffer() );
89 #endif
90 		}
91 	}
92 }
93