xref: /trunk/main/sc/source/ui/unoobj/listenercalls.cxx (revision b3f79822)
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 
27 
28 
29 #include <com/sun/star/util/XModifyListener.hpp>
30 #include <tools/debug.hxx>
31 
32 #include "listenercalls.hxx"
33 
34 using namespace com::sun::star;
35 
36 //------------------------------------------------------------------------
37 
ScUnoListenerCalls()38 ScUnoListenerCalls::ScUnoListenerCalls()
39 {
40 }
41 
~ScUnoListenerCalls()42 ScUnoListenerCalls::~ScUnoListenerCalls()
43 {
44     DBG_ASSERT( aEntries.empty(), "unhandled listener calls remaining" );
45 }
46 
Add(const uno::Reference<util::XModifyListener> & rListener,const lang::EventObject & rEvent)47 void ScUnoListenerCalls::Add( const uno::Reference<util::XModifyListener>& rListener,
48                                 const lang::EventObject& rEvent )
49 {
50     if ( rListener.is() )
51         aEntries.push_back( ScUnoListenerEntry( rListener, rEvent ) );
52 }
53 
ExecuteAndClear()54 void ScUnoListenerCalls::ExecuteAndClear()
55 {
56     //  Execute all stored calls and remove them from the list.
57     //  During each modified() call, Add may be called again.
58     //  These new calls are executed here, too.
59 
60     if (!aEntries.empty())
61     {
62         std::list<ScUnoListenerEntry>::iterator aItr(aEntries.begin());
63         std::list<ScUnoListenerEntry>::iterator aEndItr(aEntries.end());
64         while ( aItr != aEndItr )
65         {
66             ScUnoListenerEntry aEntry = *aItr;
67             try
68             {
69                 aEntry.xListener->modified( aEntry.aEvent );
70             }
71             catch ( uno::RuntimeException )
72             {
73                 // the listener is an external object and may throw a RuntimeException
74                 // for reasons we don't know
75             }
76 
77             //  New calls that are added during the modified() call are appended to the end
78             //  of aEntries, so the loop will catch them, too (as long as erase happens
79             //  after modified).
80 
81             aItr = aEntries.erase(aItr);
82         }
83     }
84 }
85 
86