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 94927 : utl::ConfigurationListener::~ConfigurationListener() {}
28 :
29 101337 : ConfigurationBroadcaster::ConfigurationBroadcaster()
30 : : mpList(0)
31 : , m_nBroadcastBlocked( 0 )
32 101337 : , m_nBlockedHint( 0 )
33 : {
34 101337 : }
35 :
36 96533 : ConfigurationBroadcaster::~ConfigurationBroadcaster()
37 : {
38 96533 : delete mpList;
39 96533 : }
40 :
41 18278 : void ConfigurationBroadcaster::AddListener( utl::ConfigurationListener* pListener )
42 : {
43 18278 : if ( !mpList )
44 3822 : mpList = new IMPL_ConfigurationListenerList;
45 18278 : mpList->push_back( pListener );
46 18278 : }
47 :
48 15080 : void ConfigurationBroadcaster::RemoveListener( utl::ConfigurationListener* pListener )
49 : {
50 15080 : if ( mpList ) {
51 257427 : for ( IMPL_ConfigurationListenerList::iterator it = mpList->begin();
52 171618 : it != mpList->end();
53 : ++it
54 : ) {
55 85809 : if ( *it == pListener ) {
56 15080 : mpList->erase( it );
57 15080 : break;
58 : }
59 : }
60 : }
61 15080 : }
62 :
63 528 : void ConfigurationBroadcaster::NotifyListeners( sal_uInt32 nHint )
64 : {
65 528 : if ( m_nBroadcastBlocked )
66 0 : m_nBlockedHint |= nHint;
67 : else
68 : {
69 528 : nHint |= m_nBlockedHint;
70 528 : m_nBlockedHint = 0;
71 528 : if ( mpList ) {
72 528 : for ( size_t n = 0; n < mpList->size(); n++ ) {
73 352 : (*mpList)[ n ]->ConfigurationChanged( this, nHint );
74 : }
75 : }
76 : }
77 528 : }
78 :
79 0 : void ConfigurationBroadcaster::BlockBroadcasts( bool bBlock )
80 : {
81 0 : if ( bBlock )
82 0 : ++m_nBroadcastBlocked;
83 0 : else if ( m_nBroadcastBlocked )
84 : {
85 0 : if ( --m_nBroadcastBlocked == 0 )
86 0 : NotifyListeners( 0 );
87 : }
88 0 : }
89 :
90 96811 : Options::Options()
91 : {
92 96811 : }
93 :
94 94279 : Options::~Options()
95 : {
96 94279 : }
97 :
98 352 : void Options::ConfigurationChanged( ConfigurationBroadcaster*, sal_uInt32 nHint )
99 : {
100 352 : NotifyListeners( nHint );
101 352 : }
102 :
103 :
104 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|