106bcd5d2SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
306bcd5d2SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
406bcd5d2SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
506bcd5d2SAndrew Rist  * distributed with this work for additional information
606bcd5d2SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
706bcd5d2SAndrew Rist  * to you under the Apache License, Version 2.0 (the
806bcd5d2SAndrew Rist  * "License"); you may not use this file except in compliance
906bcd5d2SAndrew Rist  * with the License.  You may obtain a copy of the License at
1006bcd5d2SAndrew Rist  *
1106bcd5d2SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
1206bcd5d2SAndrew Rist  *
1306bcd5d2SAndrew Rist  * Unless required by applicable law or agreed to in writing,
1406bcd5d2SAndrew Rist  * software distributed under the License is distributed on an
1506bcd5d2SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
1606bcd5d2SAndrew Rist  * KIND, either express or implied.  See the License for the
1706bcd5d2SAndrew Rist  * specific language governing permissions and limitations
1806bcd5d2SAndrew Rist  * under the License.
1906bcd5d2SAndrew Rist  *
2006bcd5d2SAndrew Rist  *************************************************************/
2106bcd5d2SAndrew Rist 
2206bcd5d2SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef SDEXT_PRESENTER_PRESENTER_FRAMEWORK_OBSERVER_HXX
25cdf0e10cSrcweir #define SDEXT_PRESENTER_PRESENTER_FRAMEWORK_OBSERVER_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp>
28cdf0e10cSrcweir #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
29cdf0e10cSrcweir #include <cppuhelper/basemutex.hxx>
30cdf0e10cSrcweir #include <cppuhelper/compbase1.hxx>
31cdf0e10cSrcweir #include <boost/function.hpp>
32cdf0e10cSrcweir #include <boost/noncopyable.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir namespace css = ::com::sun::star;
35cdf0e10cSrcweir 
36cdf0e10cSrcweir namespace sdext { namespace presenter {
37cdf0e10cSrcweir 
38cdf0e10cSrcweir 
39cdf0e10cSrcweir typedef ::cppu::WeakComponentImplHelper1 <
40cdf0e10cSrcweir     ::com::sun::star::drawing::framework::XConfigurationChangeListener
41cdf0e10cSrcweir     > PresenterFrameworkObserverInterfaceBase;
42cdf0e10cSrcweir 
43cdf0e10cSrcweir /** Watch the drawing framework for changes and run callbacks when a certain
44cdf0e10cSrcweir     change takes place.
45cdf0e10cSrcweir */
46cdf0e10cSrcweir class PresenterFrameworkObserver
47cdf0e10cSrcweir     : private ::boost::noncopyable,
48cdf0e10cSrcweir       private ::cppu::BaseMutex,
49cdf0e10cSrcweir       public PresenterFrameworkObserverInterfaceBase
50cdf0e10cSrcweir {
51cdf0e10cSrcweir public:
52cdf0e10cSrcweir     typedef ::boost::function<bool(void)> Predicate;
53cdf0e10cSrcweir     typedef ::boost::function<void(bool)> Action;
54cdf0e10cSrcweir 
55cdf0e10cSrcweir     /** Register an action callback to be run when the specified resource is
56cdf0e10cSrcweir         activated.  The action may be called synchronously when the resource
57*86e1cf34SPedro Giffuni         is already active or asynchronously when the resource is activated in
58cdf0e10cSrcweir         the future.
59cdf0e10cSrcweir         @param rxController
60cdf0e10cSrcweir             The controller gives access to the drawing framework.
61cdf0e10cSrcweir         @param rxResourceId
62cdf0e10cSrcweir             The id of the resource to watch for activation.
63cdf0e10cSrcweir         @param rAction
64cdf0e10cSrcweir             The callback that is called when the resource is activated.
65cdf0e10cSrcweir     */
66cdf0e10cSrcweir     static void RunOnResourceActivation (
67cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
68cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId,
69cdf0e10cSrcweir         const Action& rAction);
70cdf0e10cSrcweir     static void RunOnUpdateEnd (
71cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
72cdf0e10cSrcweir         const Action& rAction);
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     virtual void SAL_CALL disposing (void);
75cdf0e10cSrcweir     virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent)
76cdf0e10cSrcweir         throw (css::uno::RuntimeException);
77cdf0e10cSrcweir     virtual void SAL_CALL notifyConfigurationChange (
78cdf0e10cSrcweir         const css::drawing::framework::ConfigurationChangeEvent& rEvent)
79cdf0e10cSrcweir         throw (css::uno::RuntimeException);
80cdf0e10cSrcweir 
81cdf0e10cSrcweir private:
82cdf0e10cSrcweir     ::rtl::OUString msEventType;
83cdf0e10cSrcweir     ::css::uno::Reference<css::drawing::framework::XConfigurationController> mxConfigurationController;
84cdf0e10cSrcweir     Predicate maPredicate;
85cdf0e10cSrcweir     Action maAction;
86cdf0e10cSrcweir 
87cdf0e10cSrcweir     /** Create a new PresenterFrameworkObserver object.
88cdf0e10cSrcweir         @param rsEventName
89cdf0e10cSrcweir             An event name other than ConfigurationUpdateEnd.  When the
90cdf0e10cSrcweir             observer shall only listen for ConfigurationUpdateEnd then pass
91cdf0e10cSrcweir             an empty name.
92cdf0e10cSrcweir         @param rPredicate
93cdf0e10cSrcweir             This functor tests whether the action is to be executed or not.
94cdf0e10cSrcweir         @param rAction
95cdf0e10cSrcweir             The functor to execute when the predicate returns true,
96cdf0e10cSrcweir             e.g. when some resource has been created.
97cdf0e10cSrcweir     */
98cdf0e10cSrcweir     PresenterFrameworkObserver (
99cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
100cdf0e10cSrcweir         const ::rtl::OUString& rsEventName,
101cdf0e10cSrcweir         const Predicate& rPredicate,
102cdf0e10cSrcweir         const Action& rAction);
103cdf0e10cSrcweir     virtual ~PresenterFrameworkObserver (void);
104cdf0e10cSrcweir 
105cdf0e10cSrcweir     void Shutdown (void);
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     /** Predicate that returns true when the specified resource is active
108cdf0e10cSrcweir         with respect to the given configuration controller.
109cdf0e10cSrcweir     */
110cdf0e10cSrcweir     static bool HasResource (
111cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
112cdf0e10cSrcweir         const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId);
113cdf0e10cSrcweir 
114cdf0e10cSrcweir     /** Predicate that always returns true.
115cdf0e10cSrcweir     */
116cdf0e10cSrcweir     static bool True (void);
117cdf0e10cSrcweir 
118cdf0e10cSrcweir     /** Predicate that always returns false.
119cdf0e10cSrcweir     */
120cdf0e10cSrcweir     static bool False (void);
121cdf0e10cSrcweir };
122cdf0e10cSrcweir 
123cdf0e10cSrcweir 
124cdf0e10cSrcweir } }  // end of namespace ::sdext::presenter
125cdf0e10cSrcweir 
126cdf0e10cSrcweir #endif
127