Update ooo320-m1
[ooovba.git] / sdext / source / presenter / PresenterFrameworkObserver.cxx
blob8b7e7ef1a3ec3286b649009b0e6d8a40771070a3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterFrameworkObserver.cxx,v $
11 * $Revision: 1.5 $
13 * This file is part of OpenOffice.org.
15 * OpenOffice.org is free software: you can redistribute it and/or modify
16 * it under the terms of the GNU Lesser General Public License version 3
17 * only, as published by the Free Software Foundation.
19 * OpenOffice.org is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Lesser General Public License version 3 for more details
23 * (a copy is included in the LICENSE file that accompanied this code).
25 * You should have received a copy of the GNU Lesser General Public License
26 * version 3 along with OpenOffice.org. If not, see
27 * <http://www.openoffice.org/license.html>
28 * for a copy of the LGPLv3 License.
30 ************************************************************************/
32 // MARKER(update_precomp.py): autogen include statement, do not remove
33 #include "precompiled_sdext.hxx"
35 #include "PresenterFrameworkObserver.hxx"
36 #include <com/sun/star/lang/IllegalArgumentException.hpp>
37 #include <boost/bind.hpp>
39 using namespace ::com::sun::star;
40 using namespace ::com::sun::star::uno;
41 using namespace ::com::sun::star::drawing::framework;
43 using ::rtl::OUString;
45 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
47 namespace sdext { namespace presenter {
49 PresenterFrameworkObserver::PresenterFrameworkObserver (
50 const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
51 const OUString& rsEventName,
52 const Predicate& rPredicate,
53 const Action& rAction)
54 : PresenterFrameworkObserverInterfaceBase(m_aMutex),
55 mxConfigurationController(rxController),
56 maPredicate(rPredicate),
57 maAction(rAction)
59 if ( ! mxConfigurationController.is())
60 throw lang::IllegalArgumentException();
62 if (mxConfigurationController->hasPendingRequests())
64 if (rsEventName.getLength() > 0)
66 mxConfigurationController->addConfigurationChangeListener(
67 this,
68 rsEventName,
69 Any());
71 mxConfigurationController->addConfigurationChangeListener(
72 this,
73 A2S("ConfigurationUpdateEnd"),
74 Any());
76 else
78 rAction(maPredicate());
85 PresenterFrameworkObserver::~PresenterFrameworkObserver (void)
92 void PresenterFrameworkObserver::RunOnResourceActivation (
93 const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
94 const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId,
95 const Action& rAction)
97 new PresenterFrameworkObserver(
98 rxController,
99 A2S("ResourceActivation"),
100 ::boost::bind(&PresenterFrameworkObserver::HasResource, rxController, rxResourceId),
101 rAction);
107 void PresenterFrameworkObserver::RunOnUpdateEnd (
108 const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
109 const Action& rAction)
111 new PresenterFrameworkObserver(
112 rxController,
113 OUString(),
114 &PresenterFrameworkObserver::True,
115 rAction);
121 bool PresenterFrameworkObserver::HasResource (
122 const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
123 const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId)
125 return rxController.is() && rxController->getResource(rxResourceId).is();
131 bool PresenterFrameworkObserver::True (void)
133 return true;
139 bool PresenterFrameworkObserver::False (void)
141 return false;
147 void SAL_CALL PresenterFrameworkObserver::disposing (void)
149 if ( ! maAction.empty())
150 maAction(false);
151 Shutdown();
157 void PresenterFrameworkObserver::Shutdown (void)
159 maAction = Action();
160 maPredicate = Predicate();
162 if (mxConfigurationController != NULL)
164 mxConfigurationController->removeConfigurationChangeListener(this);
165 mxConfigurationController = NULL;
172 void SAL_CALL PresenterFrameworkObserver::disposing (const lang::EventObject& rEvent)
173 throw (RuntimeException)
175 if ( ! rEvent.Source.is())
176 return;
178 if (rEvent.Source == mxConfigurationController)
180 mxConfigurationController = NULL;
181 if ( ! maAction.empty())
182 maAction(false);
189 void SAL_CALL PresenterFrameworkObserver::notifyConfigurationChange (
190 const ConfigurationChangeEvent& rEvent)
191 throw (RuntimeException)
193 bool bDispose(false);
195 Action aAction (maAction);
196 Predicate aPredicate (maPredicate);
197 if (rEvent.Type.equals(A2S("ConfigurationUpdateEnd")))
199 Shutdown();
200 aAction(aPredicate);
201 bDispose = true;
203 else if (aPredicate())
205 Shutdown();
206 aAction(true);
207 bDispose = true;
210 if (bDispose)
212 maAction.clear();
213 dispose();
217 } } // end of namespace ::sdext::presenter