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 "tools/SlotStateListener.hxx"
31 : : #include <com/sun/star/frame/XStatusListener.hpp>
32 : : #include <com/sun/star/frame/XDispatchProvider.hpp>
33 : : #include <com/sun/star/frame/XDispatch.hpp>
34 : : #include <com/sun/star/util/URLTransformer.hpp>
35 : : #include <com/sun/star/util/XURLTransformer.hpp>
36 : : #include <com/sun/star/beans/PropertyChangeEvent.hpp>
37 : :
38 : : #include <comphelper/processfactory.hxx>
39 : :
40 : : using namespace ::com::sun::star;
41 : : using namespace ::rtl;
42 : :
43 : : namespace sd { namespace tools {
44 : :
45 : :
46 : 15 : SlotStateListener::SlotStateListener (
47 : : Link& rCallback,
48 : : const uno::Reference<frame::XDispatchProvider>& rxDispatchProvider,
49 : : const ::rtl::OUString& rSlotName)
50 : : : SlotStateListenerInterfaceBase(maMutex),
51 : : maCallback(),
52 [ + - ][ + - ]: 15 : mxDispatchProviderWeak(NULL)
[ + - ][ + - ]
53 : : {
54 [ + - ]: 15 : SetCallback(rCallback);
55 [ + - ]: 15 : ConnectToDispatchProvider(rxDispatchProvider);
56 [ + - ]: 15 : ObserveSlot(rSlotName);
57 : 15 : }
58 : :
59 : :
60 : :
61 : :
62 [ + - ][ + - ]: 15 : SlotStateListener::~SlotStateListener (void)
63 : : {
64 [ + - ]: 15 : ReleaseListeners();
65 [ - + ]: 30 : }
66 : :
67 : :
68 : :
69 : :
70 : 15 : void SlotStateListener::SetCallback (const Link& rCallback)
71 : : {
72 : 15 : ThrowIfDisposed();
73 : :
74 : 15 : maCallback = rCallback;
75 : 15 : }
76 : :
77 : :
78 : :
79 : :
80 : 15 : void SlotStateListener::ConnectToDispatchProvider (
81 : : const uno::Reference<frame::XDispatchProvider>& rxDispatchProvider)
82 : : {
83 : 15 : ThrowIfDisposed();
84 : :
85 : : // When we are listening to state changes of slots of another frame then
86 : : // release these listeners first.
87 [ - + ]: 15 : if ( ! maRegisteredURLList.empty())
88 : 0 : ReleaseListeners();
89 : :
90 : 15 : mxDispatchProviderWeak = rxDispatchProvider;
91 : 15 : }
92 : :
93 : :
94 : :
95 : :
96 : 15 : void SlotStateListener::ObserveSlot (const ::rtl::OUString& rSlotName)
97 : : {
98 : 15 : ThrowIfDisposed();
99 : :
100 [ + - ]: 15 : if (maCallback.IsSet())
101 : : {
102 : : // Connect the state change listener.
103 [ + - ]: 15 : util::URL aURL (MakeURL(rSlotName));
104 [ + - ]: 15 : uno::Reference<frame::XDispatch> xDispatch (GetDispatch(aURL));
105 [ + - ]: 15 : if (xDispatch.is())
106 : : {
107 [ + - ]: 15 : maRegisteredURLList.push_back(aURL);
108 [ + - ][ + - ]: 15 : xDispatch->addStatusListener(this,aURL);
[ + - ]
109 : 15 : }
110 : : }
111 : 15 : }
112 : :
113 : :
114 : :
115 : :
116 : 15 : void SlotStateListener::disposing (void)
117 : : {
118 : 15 : ReleaseListeners();
119 [ + - ][ + - ]: 15 : mxDispatchProviderWeak = uno::WeakReference<frame::XDispatchProvider>(NULL);
[ + - ]
120 : 15 : maCallback = Link();
121 : 15 : }
122 : :
123 : :
124 : :
125 : :
126 : 15 : util::URL SlotStateListener::MakeURL (const OUString& rSlotName) const
127 : : {
128 : 15 : util::URL aURL;
129 : 15 : aURL.Complete = rSlotName;
130 : :
131 [ + - ][ + - ]: 15 : uno::Reference<util::XURLTransformer> xTransformer(util::URLTransformer::create(::comphelper::getProcessComponentContext()));
132 [ + - ][ + - ]: 15 : xTransformer->parseStrict(aURL);
133 : :
134 : 15 : return aURL;
135 : : }
136 : :
137 : :
138 : :
139 : :
140 : : uno::Reference<frame::XDispatch>
141 : 45 : SlotStateListener::GetDispatch (const util::URL& rURL) const
142 : : {
143 : 45 : uno::Reference<frame::XDispatch> xDispatch;
144 : :
145 [ + - ]: 45 : uno::Reference<frame::XDispatchProvider> xDispatchProvider (mxDispatchProviderWeak);
146 [ + + ]: 45 : if (xDispatchProvider.is())
147 [ + - ][ + - ]: 30 : xDispatch = xDispatchProvider->queryDispatch(rURL, OUString(), 0);
[ + - ]
148 : :
149 : 45 : return xDispatch;
150 : : }
151 : :
152 : :
153 : :
154 : :
155 : 18 : void SlotStateListener::statusChanged (
156 : : const frame::FeatureStateEvent& rState)
157 : : throw (uno::RuntimeException)
158 : : {
159 [ + - ]: 18 : ThrowIfDisposed();
160 : 18 : OUString sSlotName (rState.FeatureURL.Complete);
161 [ + - ][ + - ]: 18 : if (maCallback.IsSet())
162 [ + - ]: 18 : maCallback.Call(&sSlotName);
163 : 18 : }
164 : :
165 : :
166 : :
167 : :
168 : 30 : void SlotStateListener::ReleaseListeners (void)
169 : : {
170 [ + - ]: 30 : if ( ! maRegisteredURLList.empty())
171 : : {
172 : 30 : RegisteredURLList::iterator iURL (maRegisteredURLList.begin());
173 : 30 : RegisteredURLList::iterator iEnd (maRegisteredURLList.end());
174 [ + - ][ + + ]: 60 : for (; iURL!=iEnd; ++iURL)
175 : : {
176 [ + - ]: 30 : uno::Reference<frame::XDispatch> xDispatch (GetDispatch(*iURL));
177 [ - + ]: 30 : if (xDispatch.is())
178 : : {
179 [ # # ][ # # ]: 0 : xDispatch->removeStatusListener(this,*iURL);
[ # # ]
180 : : }
181 : 30 : }
182 : : }
183 : 30 : }
184 : :
185 : :
186 : :
187 : :
188 : : //===== lang::XEventListener ================================================
189 : :
190 : 0 : void SAL_CALL SlotStateListener::disposing (
191 : : const lang::EventObject& )
192 : : throw (uno::RuntimeException)
193 : : {
194 : 0 : }
195 : :
196 : :
197 : :
198 : :
199 : 63 : void SlotStateListener::ThrowIfDisposed (void)
200 : : throw (lang::DisposedException)
201 : : {
202 [ + - ][ - + ]: 63 : if (rBHelper.bDisposed || rBHelper.bInDispose)
203 : : {
204 : : throw lang::DisposedException ("SlideSorterController object has already been disposed",
205 [ # # ][ # # ]: 0 : static_cast<uno::XWeak*>(this));
206 : : }
207 : 63 : }
208 : :
209 : :
210 : :
211 : :
212 : : } } // end of namespace ::sd::tools
213 : :
214 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|