xref: /trunk/main/unotools/source/config/options.cxx (revision 79aad27f)
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_unotools.hxx"
26 
27 #include "sal/config.h"
28 #include <tools/list.hxx>
29 #include <unotools/options.hxx>
30 
31 namespace utl
32 {
33     DECLARE_LIST( IMPL_ConfigurationListenerList, ConfigurationListener* )
34 }
35 
36 using utl::detail::Options;
37 using utl::ConfigurationBroadcaster;
38 
ConfigurationBroadcaster()39 ConfigurationBroadcaster::ConfigurationBroadcaster()
40 : mpList(0)
41 , m_nBroadcastBlocked( 0 )
42 , m_nBlockedHint( 0 )
43 {
44 }
45 
~ConfigurationBroadcaster()46 ConfigurationBroadcaster::~ConfigurationBroadcaster()
47 {
48     delete mpList;
49 }
50 
AddListener(utl::ConfigurationListener * pListener)51 void ConfigurationBroadcaster::AddListener( utl::ConfigurationListener* pListener )
52 {
53     if ( !mpList )
54         mpList = new IMPL_ConfigurationListenerList;
55     mpList->Insert( pListener );
56 }
57 
RemoveListener(utl::ConfigurationListener * pListener)58 void ConfigurationBroadcaster::RemoveListener( utl::ConfigurationListener* pListener )
59 {
60     if ( mpList )
61         mpList->Remove( pListener );
62 }
63 
NotifyListeners(sal_uInt32 nHint)64 void ConfigurationBroadcaster::NotifyListeners( sal_uInt32 nHint )
65 {
66     if ( m_nBroadcastBlocked )
67         m_nBlockedHint |= nHint;
68     else
69     {
70         nHint |= m_nBlockedHint;
71         m_nBlockedHint = 0;
72 		if ( mpList )
73 			for ( sal_uInt32 n=0; n<mpList->Count(); n++ )
74 				mpList->GetObject(n)->ConfigurationChanged( this, nHint );
75 	}
76 }
77 
BlockBroadcasts(bool bBlock)78 void ConfigurationBroadcaster::BlockBroadcasts( bool bBlock )
79 {
80     if ( bBlock )
81         ++m_nBroadcastBlocked;
82     else if ( m_nBroadcastBlocked )
83     {
84         if ( --m_nBroadcastBlocked == 0 )
85             NotifyListeners( 0 );
86     }
87 }
88 
Options()89 Options::Options()
90 {
91 }
92 
~Options()93 Options::~Options()
94 {
95 }
96 
ConfigurationChanged(ConfigurationBroadcaster *,sal_uInt32 nHint)97 void Options::ConfigurationChanged( ConfigurationBroadcaster*, sal_uInt32 nHint )
98 {
99     NotifyListeners( nHint );
100 }
101 
102 
103