Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "ReadOnlyModeObserver.hxx"
31 : :
32 : : #include <com/sun/star/drawing/framework/XControllerManager.hpp>
33 : : #include <com/sun/star/lang/DisposedException.hpp>
34 : : #include <com/sun/star/util/URLTransformer.hpp>
35 : : #include <com/sun/star/util/XURLTransformer.hpp>
36 : : #include <comphelper/processfactory.hxx>
37 : : #include <cppuhelper/interfacecontainer.hxx>
38 : :
39 : : #include "tools/SlotStateListener.hxx"
40 : : #include "framework/FrameworkHelper.hxx"
41 : :
42 : : using namespace ::com::sun::star::uno;
43 : : using namespace ::com::sun::star;
44 : : using namespace ::com::sun::star::drawing::framework;
45 : : using ::rtl::OUString;
46 : :
47 : : namespace sd { namespace framework {
48 : :
49 : 26 : class ReadOnlyModeObserver::ModifyBroadcaster
50 : : : public ::cppu::OBroadcastHelper
51 : : {
52 : : public:
53 : 26 : explicit ModifyBroadcaster (::osl::Mutex& rOslMutex) : ::cppu::OBroadcastHelper(rOslMutex) {}
54 : : };
55 : :
56 : :
57 : :
58 : :
59 : 26 : ReadOnlyModeObserver::ReadOnlyModeObserver (
60 : : const Reference<frame::XController>& rxController)
61 : : : ReadOnlyModeObserverInterfaceBase(maMutex),
62 : : maSlotNameURL(),
63 : : mxController(rxController),
64 : : mxConfigurationController(NULL),
65 : : mxDispatch(NULL),
66 [ + - ][ + - ]: 26 : mpBroadcaster(new ModifyBroadcaster(maMutex))
[ + - ][ + - ]
67 : : {
68 : : // Create a URL object for the slot name.
69 : 26 : maSlotNameURL.Complete = ".uno:EditDoc";
70 [ + - ][ + - ]: 26 : Reference<util::XURLTransformer> xTransformer(util::URLTransformer::create(::comphelper::getProcessComponentContext()));
71 [ + - ][ + - ]: 26 : xTransformer->parseStrict(maSlotNameURL);
72 : :
73 [ + - ][ + - ]: 26 : if ( ! ConnectToDispatch())
74 : : {
75 : : // The controller is not yet connected to a frame. This means that
76 : : // the dispatcher is not yet set up. We wait for this to happen by
77 : : // waiting for configuration updates and try again.
78 [ + - ]: 26 : Reference<XControllerManager> xControllerManager (rxController, UNO_QUERY);
79 [ + - ]: 26 : if (xControllerManager.is())
80 : : {
81 [ + - ][ + - ]: 26 : mxConfigurationController = xControllerManager->getConfigurationController();
[ + - ]
82 [ + - ]: 26 : if (mxConfigurationController.is())
83 : : {
84 [ + - ]: 26 : mxConfigurationController->addConfigurationChangeListener(
85 : : this,
86 : : FrameworkHelper::msConfigurationUpdateStartEvent,
87 [ + - ][ + - ]: 26 : Any());
88 : : }
89 : 26 : }
90 : 26 : }
91 : 26 : }
92 : :
93 : :
94 : :
95 : :
96 [ + - ][ + - ]: 26 : ReadOnlyModeObserver::~ReadOnlyModeObserver (void)
97 : : {
98 [ - + ]: 52 : }
99 : :
100 : :
101 : :
102 : :
103 : 26 : void SAL_CALL ReadOnlyModeObserver::disposing (void)
104 : : {
105 [ + - ]: 26 : if (mxController.is())
106 : : {
107 [ + - ]: 26 : mxController = NULL;
108 : : }
109 [ - + ]: 26 : if (mxConfigurationController.is())
110 : : {
111 [ # # ][ # # ]: 0 : mxConfigurationController->removeConfigurationChangeListener(this);
[ # # ]
112 [ # # ]: 0 : mxConfigurationController = NULL;
113 : : }
114 [ + - ]: 26 : if (mxDispatch.is())
115 : : {
116 [ + - ][ + - ]: 26 : mxDispatch->removeStatusListener(this, maSlotNameURL);
[ + - ]
117 [ + - ]: 26 : mxDispatch = NULL;
118 : : }
119 : :
120 [ + - ]: 26 : lang::EventObject aEvent;
121 [ + - ]: 26 : aEvent.Source = static_cast<XWeak*>(this);
122 : : ::cppu::OInterfaceContainerHelper* pIterator
123 [ + - ][ + - ]: 26 : = mpBroadcaster->getContainer(getCppuType((Reference<frame::XStatusListener>*)NULL));
124 [ + - ][ + - ]: 26 : pIterator->disposeAndClear(aEvent);
125 : 26 : }
126 : :
127 : :
128 : :
129 : :
130 : 26 : void ReadOnlyModeObserver::AddStatusListener (
131 : : const Reference<frame::XStatusListener>& rxListener)
132 : : {
133 : 26 : mpBroadcaster->addListener(
134 : 26 : getCppuType((Reference<frame::XStatusListener>*)NULL),
135 : 52 : rxListener);
136 : 26 : }
137 : :
138 : :
139 : :
140 : :
141 : 52 : bool ReadOnlyModeObserver::ConnectToDispatch (void)
142 : : {
143 [ + - ]: 52 : if ( ! mxDispatch.is())
144 : : {
145 : : // Get the dispatch object.
146 [ + - ][ + - ]: 52 : Reference<frame::XDispatchProvider> xProvider (mxController->getFrame(), UNO_QUERY);
[ + - ]
147 [ + + ]: 52 : if (xProvider.is())
148 : : {
149 [ + - ][ + - ]: 26 : mxDispatch = xProvider->queryDispatch(maSlotNameURL, OUString(), 0);
[ + - ]
150 [ + - ]: 26 : if (mxDispatch.is())
151 : : {
152 [ + - ][ + - ]: 26 : mxDispatch->addStatusListener(this, maSlotNameURL);
[ + - ]
153 : : }
154 : 52 : }
155 : : }
156 : :
157 : 52 : return mxDispatch.is();
158 : : }
159 : :
160 : :
161 : :
162 : :
163 : 39 : void ReadOnlyModeObserver::statusChanged (const frame::FeatureStateEvent& rEvent)
164 : : throw (RuntimeException)
165 : : {
166 : : ::cppu::OInterfaceContainerHelper* pIterator
167 : 39 : = mpBroadcaster->getContainer(getCppuType((Reference<frame::XStatusListener>*)NULL));
168 [ + - ]: 39 : if (pIterator != NULL)
169 : : {
170 : 39 : pIterator->notifyEach(&frame::XStatusListener::statusChanged, rEvent);
171 : : }
172 : 39 : }
173 : :
174 : :
175 : :
176 : :
177 : : //----- XEventListener --------------------------------------------------------
178 : :
179 : 0 : void SAL_CALL ReadOnlyModeObserver::disposing (
180 : : const lang::EventObject& rEvent)
181 : : throw (RuntimeException)
182 : : {
183 [ # # ]: 0 : if (rEvent.Source == mxConfigurationController)
184 : 0 : mxConfigurationController = NULL;
185 [ # # ]: 0 : else if (rEvent.Source == mxDispatch)
186 : 0 : mxDispatch = NULL;
187 : :
188 : 0 : dispose();
189 : 0 : }
190 : :
191 : :
192 : :
193 : :
194 : 52 : void SAL_CALL ReadOnlyModeObserver::notifyConfigurationChange (
195 : : const ConfigurationChangeEvent& rEvent)
196 : : throw (RuntimeException)
197 : : {
198 [ + - ]: 52 : if (rEvent.Type.equals(FrameworkHelper::msConfigurationUpdateStartEvent))
199 : : {
200 [ + - ][ + - ]: 52 : if (mxController.is() && mxController->getFrame().is())
[ + - ][ + + ]
[ + - ]
[ + + # # ]
201 : : {
202 [ + - ]: 26 : if (ConnectToDispatch())
203 : : {
204 : : // We have connected successfully to the dispatcher and
205 : : // therefore can disconnect from the configuration controller.
206 [ + - ]: 26 : mxConfigurationController->removeConfigurationChangeListener(this);
207 : 26 : mxConfigurationController = NULL;
208 : : }
209 : : }
210 : : }
211 : 52 : }
212 : :
213 : : } } // end of namespace sd::framework
214 : :
215 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|