1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
20 #include <sal/config.h>
21 #include <unotools/options.hxx>
25 using utl::detail::Options
;
26 using utl::ConfigurationBroadcaster
;
28 utl::ConfigurationListener::~ConfigurationListener() {}
30 ConfigurationBroadcaster::ConfigurationBroadcaster()
31 : m_nBroadcastBlocked( 0 )
32 , m_nBlockedHint( ConfigurationHints::NONE
)
36 ConfigurationBroadcaster::ConfigurationBroadcaster(ConfigurationBroadcaster
const & rSource
)
37 : mpList( rSource
.mpList
? new IMPL_ConfigurationListenerList(*rSource
.mpList
) : nullptr )
38 , m_nBroadcastBlocked( rSource
.m_nBroadcastBlocked
)
39 , m_nBlockedHint( rSource
.m_nBlockedHint
)
43 ConfigurationBroadcaster::~ConfigurationBroadcaster()
47 ConfigurationBroadcaster
& ConfigurationBroadcaster::operator =(
48 ConfigurationBroadcaster
const & other
)
52 other
.mpList
== nullptr ? nullptr : new IMPL_ConfigurationListenerList(*other
.mpList
));
53 m_nBroadcastBlocked
= other
.m_nBroadcastBlocked
;
54 m_nBlockedHint
= other
.m_nBlockedHint
;
59 void ConfigurationBroadcaster::AddListener( utl::ConfigurationListener
* pListener
)
62 mpList
.reset(new IMPL_ConfigurationListenerList
);
63 mpList
->push_back( pListener
);
66 void ConfigurationBroadcaster::RemoveListener( utl::ConfigurationListener
const * pListener
)
69 auto it
= std::find(mpList
->begin(), mpList
->end(), pListener
);
70 if ( it
!= mpList
->end() )
75 void ConfigurationBroadcaster::NotifyListeners( ConfigurationHints nHint
)
77 if ( m_nBroadcastBlocked
)
78 m_nBlockedHint
|= nHint
;
81 nHint
|= m_nBlockedHint
;
82 m_nBlockedHint
= ConfigurationHints::NONE
;
84 for ( size_t n
= 0; n
< mpList
->size(); n
++ )
85 (*mpList
)[ n
]->ConfigurationChanged( this, nHint
);
90 void ConfigurationBroadcaster::BlockBroadcasts( bool bBlock
)
93 ++m_nBroadcastBlocked
;
94 else if ( m_nBroadcastBlocked
)
96 if ( --m_nBroadcastBlocked
== 0 )
97 NotifyListeners( ConfigurationHints::NONE
);
109 void Options::ConfigurationChanged( ConfigurationBroadcaster
*, ConfigurationHints nHint
)
111 NotifyListeners( nHint
);
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */