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.hxx,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 #ifndef SDEXT_PRESENTER_PRESENTER_FRAMEWORK_OBSERVER_HXX
33 #define SDEXT_PRESENTER_PRESENTER_FRAMEWORK_OBSERVER_HXX
35 #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp>
36 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
37 #include <cppuhelper/basemutex.hxx>
38 #include <cppuhelper/compbase1.hxx>
39 #include <boost/function.hpp>
40 #include <boost/noncopyable.hpp>
42 namespace css
= ::com::sun::star
;
44 namespace sdext
{ namespace presenter
{
47 typedef ::cppu::WeakComponentImplHelper1
<
48 ::com::sun::star::drawing::framework::XConfigurationChangeListener
49 > PresenterFrameworkObserverInterfaceBase
;
51 /** Watch the drawing framework for changes and run callbacks when a certain
54 class PresenterFrameworkObserver
55 : private ::boost::noncopyable
,
56 private ::cppu::BaseMutex
,
57 public PresenterFrameworkObserverInterfaceBase
60 typedef ::boost::function
<bool(void)> Predicate
;
61 typedef ::boost::function
<void(bool)> Action
;
63 /** Register an action callback to be run when the specified resource is
64 activated. The action may be called synchronously when the resource
65 is already active or asynchronously when the resource is actived in
68 The controller gives access to the drawing framework.
70 The id of the resource to watch for activation.
72 The callback that is called when the resource is activated.
74 static void RunOnResourceActivation (
75 const css::uno::Reference
<css::drawing::framework::XConfigurationController
>&rxController
,
76 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxResourceId
,
77 const Action
& rAction
);
78 static void RunOnUpdateEnd (
79 const css::uno::Reference
<css::drawing::framework::XConfigurationController
>&rxController
,
80 const Action
& rAction
);
82 virtual void SAL_CALL
disposing (void);
83 virtual void SAL_CALL
disposing (const css::lang::EventObject
& rEvent
)
84 throw (css::uno::RuntimeException
);
85 virtual void SAL_CALL
notifyConfigurationChange (
86 const css::drawing::framework::ConfigurationChangeEvent
& rEvent
)
87 throw (css::uno::RuntimeException
);
90 ::rtl::OUString msEventType
;
91 ::css::uno::Reference
<css::drawing::framework::XConfigurationController
> mxConfigurationController
;
92 Predicate maPredicate
;
95 /** Create a new PresenterFrameworkObserver object.
97 An event name other than ConfigurationUpdateEnd. When the
98 observer shall only listen for ConfigurationUpdateEnd then pass
101 This functor tests whether the action is to be executed or not.
103 The functor to execute when the predicate returns true,
104 e.g. when some resource has been created.
106 PresenterFrameworkObserver (
107 const css::uno::Reference
<css::drawing::framework::XConfigurationController
>&rxController
,
108 const ::rtl::OUString
& rsEventName
,
109 const Predicate
& rPredicate
,
110 const Action
& rAction
);
111 virtual ~PresenterFrameworkObserver (void);
113 void Shutdown (void);
115 /** Predicate that returns true when the specified resource is active
116 with respect to the given configuration controller.
118 static bool HasResource (
119 const css::uno::Reference
<css::drawing::framework::XConfigurationController
>&rxController
,
120 const css::uno::Reference
<css::drawing::framework::XResourceId
>& rxResourceId
);
122 /** Predicate that always returns true.
124 static bool True (void);
126 /** Predicate that always returns false.
128 static bool False (void);
132 } } // end of namespace ::sdext::presenter