1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir #ifndef SDEXT_PRESENTER_PRESENTER_FRAMEWORK_OBSERVER_HXX
29*cdf0e10cSrcweir #define SDEXT_PRESENTER_PRESENTER_FRAMEWORK_OBSERVER_HXX
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp>
32*cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
33*cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx>
34*cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx>
35*cdf0e10cSrcweir #include <boost/function.hpp>
36*cdf0e10cSrcweir #include <boost/noncopyable.hpp>
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir namespace css = ::com::sun::star;
39*cdf0e10cSrcweir 
40*cdf0e10cSrcweir namespace sdext { namespace presenter {
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir 
43*cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper1 <
44*cdf0e10cSrcweir     ::com::sun::star::drawing::framework::XConfigurationChangeListener
45*cdf0e10cSrcweir     > PresenterFrameworkObserverInterfaceBase;
46*cdf0e10cSrcweir 
47*cdf0e10cSrcweir /** Watch the drawing framework for changes and run callbacks when a certain
48*cdf0e10cSrcweir     change takes place.
49*cdf0e10cSrcweir */
50*cdf0e10cSrcweir class PresenterFrameworkObserver
51*cdf0e10cSrcweir     : private ::boost::noncopyable,
52*cdf0e10cSrcweir       private ::cppu::BaseMutex,
53*cdf0e10cSrcweir       public PresenterFrameworkObserverInterfaceBase
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir public:
56*cdf0e10cSrcweir     typedef ::boost::function<bool(void)> Predicate;
57*cdf0e10cSrcweir     typedef ::boost::function<void(bool)> Action;
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir     /** Register an action callback to be run when the specified resource is
60*cdf0e10cSrcweir         activated.  The action may be called synchronously when the resource
61*cdf0e10cSrcweir         is already active or asynchronously when the resource is actived in
62*cdf0e10cSrcweir         the future.
63*cdf0e10cSrcweir         @param rxController
64*cdf0e10cSrcweir             The controller gives access to the drawing framework.
65*cdf0e10cSrcweir         @param rxResourceId
66*cdf0e10cSrcweir             The id of the resource to watch for activation.
67*cdf0e10cSrcweir         @param rAction
68*cdf0e10cSrcweir             The callback that is called when the resource is activated.
69*cdf0e10cSrcweir     */
70*cdf0e10cSrcweir     static void RunOnResourceActivation (
71*cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
72*cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId,
73*cdf0e10cSrcweir         const Action& rAction);
74*cdf0e10cSrcweir     static void RunOnUpdateEnd (
75*cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
76*cdf0e10cSrcweir         const Action& rAction);
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir     virtual void SAL_CALL disposing (void);
79*cdf0e10cSrcweir     virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent)
80*cdf0e10cSrcweir         throw (css::uno::RuntimeException);
81*cdf0e10cSrcweir     virtual void SAL_CALL notifyConfigurationChange (
82*cdf0e10cSrcweir         const css::drawing::framework::ConfigurationChangeEvent& rEvent)
83*cdf0e10cSrcweir         throw (css::uno::RuntimeException);
84*cdf0e10cSrcweir 
85*cdf0e10cSrcweir private:
86*cdf0e10cSrcweir     ::rtl::OUString msEventType;
87*cdf0e10cSrcweir     ::css::uno::Reference<css::drawing::framework::XConfigurationController> mxConfigurationController;
88*cdf0e10cSrcweir     Predicate maPredicate;
89*cdf0e10cSrcweir     Action maAction;
90*cdf0e10cSrcweir 
91*cdf0e10cSrcweir     /** Create a new PresenterFrameworkObserver object.
92*cdf0e10cSrcweir         @param rsEventName
93*cdf0e10cSrcweir             An event name other than ConfigurationUpdateEnd.  When the
94*cdf0e10cSrcweir             observer shall only listen for ConfigurationUpdateEnd then pass
95*cdf0e10cSrcweir             an empty name.
96*cdf0e10cSrcweir         @param rPredicate
97*cdf0e10cSrcweir             This functor tests whether the action is to be executed or not.
98*cdf0e10cSrcweir         @param rAction
99*cdf0e10cSrcweir             The functor to execute when the predicate returns true,
100*cdf0e10cSrcweir             e.g. when some resource has been created.
101*cdf0e10cSrcweir     */
102*cdf0e10cSrcweir     PresenterFrameworkObserver (
103*cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
104*cdf0e10cSrcweir         const ::rtl::OUString& rsEventName,
105*cdf0e10cSrcweir         const Predicate& rPredicate,
106*cdf0e10cSrcweir         const Action& rAction);
107*cdf0e10cSrcweir     virtual ~PresenterFrameworkObserver (void);
108*cdf0e10cSrcweir 
109*cdf0e10cSrcweir     void Shutdown (void);
110*cdf0e10cSrcweir 
111*cdf0e10cSrcweir     /** Predicate that returns true when the specified resource is active
112*cdf0e10cSrcweir         with respect to the given configuration controller.
113*cdf0e10cSrcweir     */
114*cdf0e10cSrcweir     static bool HasResource (
115*cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
116*cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId);
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     /** Predicate that always returns true.
119*cdf0e10cSrcweir     */
120*cdf0e10cSrcweir     static bool True (void);
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     /** Predicate that always returns false.
123*cdf0e10cSrcweir     */
124*cdf0e10cSrcweir     static bool False (void);
125*cdf0e10cSrcweir };
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir 
128*cdf0e10cSrcweir } }  // end of namespace ::sdext::presenter
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir #endif
131