1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: PresenterFrameworkObserver.cxx,v $
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
),
59 if ( ! mxConfigurationController
.is())
60 throw lang::IllegalArgumentException();
62 if (mxConfigurationController
->hasPendingRequests())
64 if (rsEventName
.getLength() > 0)
66 mxConfigurationController
->addConfigurationChangeListener(
71 mxConfigurationController
->addConfigurationChangeListener(
73 A2S("ConfigurationUpdateEnd"),
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(
99 A2S("ResourceActivation"),
100 ::boost::bind(&PresenterFrameworkObserver::HasResource
, rxController
, rxResourceId
),
107 void PresenterFrameworkObserver::RunOnUpdateEnd (
108 const css::uno::Reference
<css::drawing::framework::XConfigurationController
>&rxController
,
109 const Action
& rAction
)
111 new PresenterFrameworkObserver(
114 &PresenterFrameworkObserver::True
,
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)
139 bool PresenterFrameworkObserver::False (void)
147 void SAL_CALL
PresenterFrameworkObserver::disposing (void)
149 if ( ! maAction
.empty())
157 void PresenterFrameworkObserver::Shutdown (void)
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())
178 if (rEvent
.Source
== mxConfigurationController
)
180 mxConfigurationController
= NULL
;
181 if ( ! maAction
.empty())
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")))
203 else if (aPredicate())
217 } } // end of namespace ::sdext::presenter