1*c142477cSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*c142477cSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*c142477cSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*c142477cSAndrew Rist * distributed with this work for additional information
6*c142477cSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*c142477cSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*c142477cSAndrew Rist * "License"); you may not use this file except in compliance
9*c142477cSAndrew Rist * with the License. You may obtain a copy of the License at
10*c142477cSAndrew Rist *
11*c142477cSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*c142477cSAndrew Rist *
13*c142477cSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*c142477cSAndrew Rist * software distributed under the License is distributed on an
15*c142477cSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*c142477cSAndrew Rist * KIND, either express or implied. See the License for the
17*c142477cSAndrew Rist * specific language governing permissions and limitations
18*c142477cSAndrew Rist * under the License.
19*c142477cSAndrew Rist *
20*c142477cSAndrew Rist *************************************************************/
21*c142477cSAndrew Rist
22*c142477cSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sdext.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include "PresenterFrameworkObserver.hxx"
28cdf0e10cSrcweir #include <com/sun/star/lang/IllegalArgumentException.hpp>
29cdf0e10cSrcweir #include <boost/bind.hpp>
30cdf0e10cSrcweir
31cdf0e10cSrcweir using namespace ::com::sun::star;
32cdf0e10cSrcweir using namespace ::com::sun::star::uno;
33cdf0e10cSrcweir using namespace ::com::sun::star::drawing::framework;
34cdf0e10cSrcweir
35cdf0e10cSrcweir using ::rtl::OUString;
36cdf0e10cSrcweir
37cdf0e10cSrcweir #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
38cdf0e10cSrcweir
39cdf0e10cSrcweir namespace sdext { namespace presenter {
40cdf0e10cSrcweir
PresenterFrameworkObserver(const css::uno::Reference<css::drawing::framework::XConfigurationController> & rxController,const OUString & rsEventName,const Predicate & rPredicate,const Action & rAction)41cdf0e10cSrcweir PresenterFrameworkObserver::PresenterFrameworkObserver (
42cdf0e10cSrcweir const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
43cdf0e10cSrcweir const OUString& rsEventName,
44cdf0e10cSrcweir const Predicate& rPredicate,
45cdf0e10cSrcweir const Action& rAction)
46cdf0e10cSrcweir : PresenterFrameworkObserverInterfaceBase(m_aMutex),
47cdf0e10cSrcweir mxConfigurationController(rxController),
48cdf0e10cSrcweir maPredicate(rPredicate),
49cdf0e10cSrcweir maAction(rAction)
50cdf0e10cSrcweir {
51cdf0e10cSrcweir if ( ! mxConfigurationController.is())
52cdf0e10cSrcweir throw lang::IllegalArgumentException();
53cdf0e10cSrcweir
54cdf0e10cSrcweir if (mxConfigurationController->hasPendingRequests())
55cdf0e10cSrcweir {
56cdf0e10cSrcweir if (rsEventName.getLength() > 0)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener(
59cdf0e10cSrcweir this,
60cdf0e10cSrcweir rsEventName,
61cdf0e10cSrcweir Any());
62cdf0e10cSrcweir }
63cdf0e10cSrcweir mxConfigurationController->addConfigurationChangeListener(
64cdf0e10cSrcweir this,
65cdf0e10cSrcweir A2S("ConfigurationUpdateEnd"),
66cdf0e10cSrcweir Any());
67cdf0e10cSrcweir }
68cdf0e10cSrcweir else
69cdf0e10cSrcweir {
70cdf0e10cSrcweir rAction(maPredicate());
71cdf0e10cSrcweir }
72cdf0e10cSrcweir }
73cdf0e10cSrcweir
74cdf0e10cSrcweir
75cdf0e10cSrcweir
76cdf0e10cSrcweir
~PresenterFrameworkObserver(void)77cdf0e10cSrcweir PresenterFrameworkObserver::~PresenterFrameworkObserver (void)
78cdf0e10cSrcweir {
79cdf0e10cSrcweir }
80cdf0e10cSrcweir
81cdf0e10cSrcweir
82cdf0e10cSrcweir
83cdf0e10cSrcweir
RunOnResourceActivation(const css::uno::Reference<css::drawing::framework::XConfigurationController> & rxController,const css::uno::Reference<css::drawing::framework::XResourceId> & rxResourceId,const Action & rAction)84cdf0e10cSrcweir void PresenterFrameworkObserver::RunOnResourceActivation (
85cdf0e10cSrcweir const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
86cdf0e10cSrcweir const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId,
87cdf0e10cSrcweir const Action& rAction)
88cdf0e10cSrcweir {
89cdf0e10cSrcweir new PresenterFrameworkObserver(
90cdf0e10cSrcweir rxController,
91cdf0e10cSrcweir A2S("ResourceActivation"),
92cdf0e10cSrcweir ::boost::bind(&PresenterFrameworkObserver::HasResource, rxController, rxResourceId),
93cdf0e10cSrcweir rAction);
94cdf0e10cSrcweir }
95cdf0e10cSrcweir
96cdf0e10cSrcweir
97cdf0e10cSrcweir
98cdf0e10cSrcweir
RunOnUpdateEnd(const css::uno::Reference<css::drawing::framework::XConfigurationController> & rxController,const Action & rAction)99cdf0e10cSrcweir void PresenterFrameworkObserver::RunOnUpdateEnd (
100cdf0e10cSrcweir const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
101cdf0e10cSrcweir const Action& rAction)
102cdf0e10cSrcweir {
103cdf0e10cSrcweir new PresenterFrameworkObserver(
104cdf0e10cSrcweir rxController,
105cdf0e10cSrcweir OUString(),
106cdf0e10cSrcweir &PresenterFrameworkObserver::True,
107cdf0e10cSrcweir rAction);
108cdf0e10cSrcweir }
109cdf0e10cSrcweir
110cdf0e10cSrcweir
111cdf0e10cSrcweir
112cdf0e10cSrcweir
HasResource(const css::uno::Reference<css::drawing::framework::XConfigurationController> & rxController,const css::uno::Reference<css::drawing::framework::XResourceId> & rxResourceId)113cdf0e10cSrcweir bool PresenterFrameworkObserver::HasResource (
114cdf0e10cSrcweir const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
115cdf0e10cSrcweir const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId)
116cdf0e10cSrcweir {
117cdf0e10cSrcweir return rxController.is() && rxController->getResource(rxResourceId).is();
118cdf0e10cSrcweir }
119cdf0e10cSrcweir
120cdf0e10cSrcweir
121cdf0e10cSrcweir
122cdf0e10cSrcweir
True(void)123cdf0e10cSrcweir bool PresenterFrameworkObserver::True (void)
124cdf0e10cSrcweir {
125cdf0e10cSrcweir return true;
126cdf0e10cSrcweir }
127cdf0e10cSrcweir
128cdf0e10cSrcweir
129cdf0e10cSrcweir
130cdf0e10cSrcweir
False(void)131cdf0e10cSrcweir bool PresenterFrameworkObserver::False (void)
132cdf0e10cSrcweir {
133cdf0e10cSrcweir return false;
134cdf0e10cSrcweir }
135cdf0e10cSrcweir
136cdf0e10cSrcweir
137cdf0e10cSrcweir
138cdf0e10cSrcweir
disposing(void)139cdf0e10cSrcweir void SAL_CALL PresenterFrameworkObserver::disposing (void)
140cdf0e10cSrcweir {
141cdf0e10cSrcweir if ( ! maAction.empty())
142cdf0e10cSrcweir maAction(false);
143cdf0e10cSrcweir Shutdown();
144cdf0e10cSrcweir }
145cdf0e10cSrcweir
146cdf0e10cSrcweir
147cdf0e10cSrcweir
148cdf0e10cSrcweir
Shutdown(void)149cdf0e10cSrcweir void PresenterFrameworkObserver::Shutdown (void)
150cdf0e10cSrcweir {
151cdf0e10cSrcweir maAction = Action();
152cdf0e10cSrcweir maPredicate = Predicate();
153cdf0e10cSrcweir
154cdf0e10cSrcweir if (mxConfigurationController != NULL)
155cdf0e10cSrcweir {
156cdf0e10cSrcweir mxConfigurationController->removeConfigurationChangeListener(this);
157cdf0e10cSrcweir mxConfigurationController = NULL;
158cdf0e10cSrcweir }
159cdf0e10cSrcweir }
160cdf0e10cSrcweir
161cdf0e10cSrcweir
162cdf0e10cSrcweir
163cdf0e10cSrcweir
disposing(const lang::EventObject & rEvent)164cdf0e10cSrcweir void SAL_CALL PresenterFrameworkObserver::disposing (const lang::EventObject& rEvent)
165cdf0e10cSrcweir throw (RuntimeException)
166cdf0e10cSrcweir {
167cdf0e10cSrcweir if ( ! rEvent.Source.is())
168cdf0e10cSrcweir return;
169cdf0e10cSrcweir
170cdf0e10cSrcweir if (rEvent.Source == mxConfigurationController)
171cdf0e10cSrcweir {
172cdf0e10cSrcweir mxConfigurationController = NULL;
173cdf0e10cSrcweir if ( ! maAction.empty())
174cdf0e10cSrcweir maAction(false);
175cdf0e10cSrcweir }
176cdf0e10cSrcweir }
177cdf0e10cSrcweir
178cdf0e10cSrcweir
179cdf0e10cSrcweir
180cdf0e10cSrcweir
notifyConfigurationChange(const ConfigurationChangeEvent & rEvent)181cdf0e10cSrcweir void SAL_CALL PresenterFrameworkObserver::notifyConfigurationChange (
182cdf0e10cSrcweir const ConfigurationChangeEvent& rEvent)
183cdf0e10cSrcweir throw (RuntimeException)
184cdf0e10cSrcweir {
185cdf0e10cSrcweir bool bDispose(false);
186cdf0e10cSrcweir
187cdf0e10cSrcweir Action aAction (maAction);
188cdf0e10cSrcweir Predicate aPredicate (maPredicate);
189cdf0e10cSrcweir if (rEvent.Type.equals(A2S("ConfigurationUpdateEnd")))
190cdf0e10cSrcweir {
191cdf0e10cSrcweir Shutdown();
192cdf0e10cSrcweir aAction(aPredicate);
193cdf0e10cSrcweir bDispose = true;
194cdf0e10cSrcweir }
195cdf0e10cSrcweir else if (aPredicate())
196cdf0e10cSrcweir {
197cdf0e10cSrcweir Shutdown();
198cdf0e10cSrcweir aAction(true);
199cdf0e10cSrcweir bDispose = true;
200cdf0e10cSrcweir }
201cdf0e10cSrcweir
202cdf0e10cSrcweir if (bDispose)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir maAction.clear();
205cdf0e10cSrcweir dispose();
206cdf0e10cSrcweir }
207cdf0e10cSrcweir }
208cdf0e10cSrcweir
209cdf0e10cSrcweir } } // end of namespace ::sdext::presenter
210