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 : #include <sal/config.h>
21 : #include <unotools/options.hxx>
22 :
23 : using utl::detail::Options;
24 : using utl::ConfigurationBroadcaster;
25 :
26 54314610 : utl::ConfigurationListener::~ConfigurationListener() {}
27 :
28 54328731 : ConfigurationBroadcaster::ConfigurationBroadcaster()
29 : : mpList(0)
30 : , m_nBroadcastBlocked( 0 )
31 54328731 : , m_nBlockedHint( 0 )
32 : {
33 54328731 : }
34 :
35 54324627 : ConfigurationBroadcaster::~ConfigurationBroadcaster()
36 : {
37 54324627 : delete mpList;
38 54324627 : }
39 :
40 192901 : void ConfigurationBroadcaster::AddListener( utl::ConfigurationListener* pListener )
41 : {
42 192901 : if ( !mpList )
43 64148 : mpList = new IMPL_ConfigurationListenerList;
44 192901 : mpList->push_back( pListener );
45 192901 : }
46 :
47 190759 : void ConfigurationBroadcaster::RemoveListener( utl::ConfigurationListener* pListener )
48 : {
49 190759 : if ( mpList ) {
50 2754060 : for ( IMPL_ConfigurationListenerList::iterator it = mpList->begin();
51 1836040 : it != mpList->end();
52 : ++it
53 : ) {
54 918020 : if ( *it == pListener ) {
55 190759 : mpList->erase( it );
56 190759 : break;
57 : }
58 : }
59 : }
60 190759 : }
61 :
62 534 : void ConfigurationBroadcaster::NotifyListeners( sal_uInt32 nHint )
63 : {
64 534 : if ( m_nBroadcastBlocked )
65 0 : m_nBlockedHint |= nHint;
66 : else
67 : {
68 534 : nHint |= m_nBlockedHint;
69 534 : m_nBlockedHint = 0;
70 534 : if ( mpList ) {
71 928 : for ( size_t n = 0; n < mpList->size(); n++ ) {
72 591 : (*mpList)[ n ]->ConfigurationChanged( this, nHint );
73 : }
74 : }
75 : }
76 534 : }
77 :
78 24 : void ConfigurationBroadcaster::BlockBroadcasts( bool bBlock )
79 : {
80 24 : if ( bBlock )
81 12 : ++m_nBroadcastBlocked;
82 12 : else if ( m_nBroadcastBlocked )
83 : {
84 12 : if ( --m_nBroadcastBlocked == 0 )
85 12 : NotifyListeners( 0 );
86 : }
87 24 : }
88 :
89 54303829 : Options::Options()
90 : {
91 54303829 : }
92 :
93 54301437 : Options::~Options()
94 : {
95 54301437 : }
96 :
97 356 : void Options::ConfigurationChanged( ConfigurationBroadcaster*, sal_uInt32 nHint )
98 : {
99 356 : NotifyListeners( nHint );
100 356 : }
101 :
102 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|