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