Line data Source code
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 : #include "PresenterFrameworkObserver.hxx"
21 : #include <com/sun/star/lang/IllegalArgumentException.hpp>
22 :
23 : using namespace ::com::sun::star;
24 : using namespace ::com::sun::star::uno;
25 : using namespace ::com::sun::star::drawing::framework;
26 :
27 :
28 : namespace sdext { namespace presenter {
29 :
30 0 : PresenterFrameworkObserver::PresenterFrameworkObserver (
31 : const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
32 : const OUString& rsEventName,
33 : const Predicate& rPredicate,
34 : const Action& rAction)
35 : : PresenterFrameworkObserverInterfaceBase(m_aMutex),
36 : mxConfigurationController(rxController),
37 : maPredicate(rPredicate),
38 0 : maAction(rAction)
39 : {
40 0 : if ( ! mxConfigurationController.is())
41 0 : throw lang::IllegalArgumentException();
42 :
43 0 : if (mxConfigurationController->hasPendingRequests())
44 : {
45 0 : if (!rsEventName.isEmpty())
46 : {
47 0 : mxConfigurationController->addConfigurationChangeListener(
48 : this,
49 : rsEventName,
50 0 : Any());
51 : }
52 0 : mxConfigurationController->addConfigurationChangeListener(
53 : this,
54 : "ConfigurationUpdateEnd",
55 0 : Any());
56 : }
57 : else
58 : {
59 0 : rAction(maPredicate());
60 : }
61 0 : }
62 :
63 0 : PresenterFrameworkObserver::~PresenterFrameworkObserver (void)
64 : {
65 0 : }
66 :
67 0 : void PresenterFrameworkObserver::RunOnUpdateEnd (
68 : const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
69 : const Action& rAction)
70 : {
71 : new PresenterFrameworkObserver(
72 : rxController,
73 : OUString(),
74 : &PresenterFrameworkObserver::True,
75 0 : rAction);
76 0 : }
77 :
78 0 : bool PresenterFrameworkObserver::True (void)
79 : {
80 0 : return true;
81 : }
82 :
83 0 : void SAL_CALL PresenterFrameworkObserver::disposing (void)
84 : {
85 0 : if ( ! maAction.empty())
86 0 : maAction(false);
87 0 : Shutdown();
88 0 : }
89 :
90 0 : void PresenterFrameworkObserver::Shutdown (void)
91 : {
92 0 : maAction = Action();
93 0 : maPredicate = Predicate();
94 :
95 0 : if (mxConfigurationController != NULL)
96 : {
97 0 : mxConfigurationController->removeConfigurationChangeListener(this);
98 0 : mxConfigurationController = NULL;
99 : }
100 0 : }
101 :
102 0 : void SAL_CALL PresenterFrameworkObserver::disposing (const lang::EventObject& rEvent)
103 : throw (RuntimeException, std::exception)
104 : {
105 0 : if ( ! rEvent.Source.is())
106 0 : return;
107 :
108 0 : if (rEvent.Source == mxConfigurationController)
109 : {
110 0 : mxConfigurationController = NULL;
111 0 : if ( ! maAction.empty())
112 0 : maAction(false);
113 : }
114 : }
115 :
116 0 : void SAL_CALL PresenterFrameworkObserver::notifyConfigurationChange (
117 : const ConfigurationChangeEvent& rEvent)
118 : throw (RuntimeException, std::exception)
119 : {
120 0 : bool bDispose(false);
121 :
122 0 : Action aAction (maAction);
123 0 : Predicate aPredicate (maPredicate);
124 0 : if (rEvent.Type.equals("ConfigurationUpdateEnd"))
125 : {
126 0 : Shutdown();
127 0 : aAction(aPredicate);
128 0 : bDispose = true;
129 : }
130 0 : else if (aPredicate())
131 : {
132 0 : Shutdown();
133 0 : aAction(true);
134 0 : bDispose = true;
135 : }
136 :
137 0 : if (bDispose)
138 : {
139 0 : maAction.clear();
140 0 : dispose();
141 0 : }
142 0 : }
143 :
144 : } } // end of namespace ::sdext::presenter
145 :
146 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|