1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3  * This file is part of the LibreOffice project.
4  *
5  * This Source Code Form is subject to the terms of the Mozilla Public
6  * License, v. 2.0. If a copy of the MPL was not distributed with this
7  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8  *
9  * This file incorporates work covered by the following license notice:
10  *
11  *   Licensed to the Apache Software Foundation (ASF) under one or more
12  *   contributor license agreements. See the NOTICE file distributed
13  *   with this work for additional information regarding copyright
14  *   ownership. The ASF licenses this file to you under the Apache
15  *   License, Version 2.0 (the "License"); you may not use this file
16  *   except in compliance with the License. You may obtain a copy of
17  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
18  */
19 
20 #ifndef INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERFRAMEWORKOBSERVER_HXX
21 #define INCLUDED_SDEXT_SOURCE_PRESENTER_PRESENTERFRAMEWORKOBSERVER_HXX
22 
23 #include <com/sun/star/drawing/framework/XConfigurationChangeListener.hpp>
24 #include <com/sun/star/drawing/framework/XConfigurationController.hpp>
25 #include <cppuhelper/basemutex.hxx>
26 #include <cppuhelper/compbase.hxx>
27 
28 #include <functional>
29 
30 namespace sdext::presenter {
31 
32 typedef ::cppu::WeakComponentImplHelper <
33     css::drawing::framework::XConfigurationChangeListener
34     > PresenterFrameworkObserverInterfaceBase;
35 
36 /** Watch the drawing framework for changes and run callbacks when a certain
37     change takes place.
38 */
39 class PresenterFrameworkObserver
40     : private ::cppu::BaseMutex,
41       public PresenterFrameworkObserverInterfaceBase
42 {
43 public:
44     typedef ::std::function<void (bool)> Action;
45 
46     PresenterFrameworkObserver(const PresenterFrameworkObserver&) = delete;
47     PresenterFrameworkObserver& operator=(const PresenterFrameworkObserver&) = delete;
48 
49     static void RunOnUpdateEnd (
50         const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
51         const Action& rAction);
52 
53     virtual void SAL_CALL disposing() override;
54     virtual void SAL_CALL disposing (const css::lang::EventObject& rEvent) override;
55     virtual void SAL_CALL notifyConfigurationChange (
56         const css::drawing::framework::ConfigurationChangeEvent& rEvent) override;
57 
58 private:
59     css::uno::Reference<css::drawing::framework::XConfigurationController> mxConfigurationController;
60     Action maAction;
61 
62     /** Create a new PresenterFrameworkObserver object.
63         @param rPredicate
64             This functor tests whether the action is to be executed or not.
65         @param rAction
66             The functor to execute when the predicate returns true,
67             e.g. when some resource has been created.
68     */
69     PresenterFrameworkObserver (
70         const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
71         const Action& rAction);
72     virtual ~PresenterFrameworkObserver() override;
73 
74     void Shutdown();
75 };
76 
77 }  // end of namespace ::sdext::presenter
78 
79 #endif
80 
81 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
82