Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : :
21 : : #include "sal/config.h"
22 : : #include <unotools/options.hxx>
23 : :
24 : : using utl::detail::Options;
25 : : using utl::ConfigurationBroadcaster;
26 : :
27 [ - + ]: 627433 : utl::ConfigurationListener::~ConfigurationListener() {}
28 : :
29 : 641694 : ConfigurationBroadcaster::ConfigurationBroadcaster()
30 : : : mpList(0)
31 : : , m_nBroadcastBlocked( 0 )
32 : 641694 : , m_nBlockedHint( 0 )
33 : : {
34 : 641694 : }
35 : :
36 : 637624 : ConfigurationBroadcaster::~ConfigurationBroadcaster()
37 : : {
38 [ + + ]: 637624 : delete mpList;
39 [ - + ]: 637624 : }
40 : :
41 : 178745 : void ConfigurationBroadcaster::AddListener( utl::ConfigurationListener* pListener )
42 : : {
43 [ + + ]: 178745 : if ( !mpList )
44 [ + - ]: 61095 : mpList = new IMPL_ConfigurationListenerList;
45 : 178745 : mpList->push_back( pListener );
46 : 178745 : }
47 : :
48 : 176751 : void ConfigurationBroadcaster::RemoveListener( utl::ConfigurationListener* pListener )
49 : : {
50 [ + - ]: 176751 : if ( mpList ) {
51 [ + - + - ]: 1602333 : for ( IMPL_ConfigurationListenerList::iterator it = mpList->begin();
[ + - ]
52 : 712791 : it != mpList->end();
53 : : ++it
54 : : ) {
55 [ + - ][ + + ]: 712791 : if ( *it == pListener ) {
56 [ + - ]: 176751 : mpList->erase( it );
57 : 176751 : break;
58 : : }
59 : : }
60 : : }
61 : 176751 : }
62 : :
63 : 1392 : void ConfigurationBroadcaster::NotifyListeners( sal_uInt32 nHint )
64 : : {
65 [ - + ]: 1392 : if ( m_nBroadcastBlocked )
66 : 0 : m_nBlockedHint |= nHint;
67 : : else
68 : : {
69 : 1392 : nHint |= m_nBlockedHint;
70 : 1392 : m_nBlockedHint = 0;
71 [ + + ]: 1392 : if ( mpList ) {
72 [ + + ]: 1626 : for ( size_t n = 0; n < mpList->size(); n++ ) {
73 : 1068 : (*mpList)[ n ]->ConfigurationChanged( this, nHint );
74 : : }
75 : : }
76 : : }
77 : 1392 : }
78 : :
79 : 48 : void ConfigurationBroadcaster::BlockBroadcasts( bool bBlock )
80 : : {
81 [ + + ]: 48 : if ( bBlock )
82 : 24 : ++m_nBroadcastBlocked;
83 [ + - ]: 24 : else if ( m_nBroadcastBlocked )
84 : : {
85 [ + - ]: 24 : if ( --m_nBroadcastBlocked == 0 )
86 : 24 : NotifyListeners( 0 );
87 : : }
88 : 48 : }
89 : :
90 : 621793 : Options::Options()
91 : : {
92 : 621793 : }
93 : :
94 [ + - ]: 620417 : Options::~Options()
95 : : {
96 [ - + ]: 620417 : }
97 : :
98 : 876 : void Options::ConfigurationChanged( ConfigurationBroadcaster*, sal_uInt32 nHint )
99 : : {
100 : 876 : NotifyListeners( nHint );
101 : 876 : }
102 : :
103 : :
104 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|