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