Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include "PresenterFrameworkObserver.hxx"
30 : : #include <com/sun/star/lang/IllegalArgumentException.hpp>
31 : :
32 : : using namespace ::com::sun::star;
33 : : using namespace ::com::sun::star::uno;
34 : : using namespace ::com::sun::star::drawing::framework;
35 : :
36 : : using ::rtl::OUString;
37 : :
38 : : #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString)))
39 : :
40 : : namespace sdext { namespace presenter {
41 : :
42 : 0 : PresenterFrameworkObserver::PresenterFrameworkObserver (
43 : : const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
44 : : const OUString& rsEventName,
45 : : const Predicate& rPredicate,
46 : : const Action& rAction)
47 : : : PresenterFrameworkObserverInterfaceBase(m_aMutex),
48 : : mxConfigurationController(rxController),
49 : : maPredicate(rPredicate),
50 [ # # ][ # # ]: 0 : maAction(rAction)
[ # # ]
51 : : {
52 [ # # ]: 0 : if ( ! mxConfigurationController.is())
53 [ # # ]: 0 : throw lang::IllegalArgumentException();
54 : :
55 [ # # ][ # # ]: 0 : if (mxConfigurationController->hasPendingRequests())
[ # # ]
56 : : {
57 [ # # ]: 0 : if (!rsEventName.isEmpty())
58 : : {
59 [ # # ]: 0 : mxConfigurationController->addConfigurationChangeListener(
60 : : this,
61 : : rsEventName,
62 [ # # ][ # # ]: 0 : Any());
63 : : }
64 [ # # ]: 0 : mxConfigurationController->addConfigurationChangeListener(
65 : : this,
66 : : A2S("ConfigurationUpdateEnd"),
67 [ # # ][ # # ]: 0 : Any());
[ # # ]
68 : : }
69 : : else
70 : : {
71 [ # # ][ # # ]: 0 : rAction(maPredicate());
72 : : }
73 : 0 : }
74 : :
75 [ # # ][ # # ]: 0 : PresenterFrameworkObserver::~PresenterFrameworkObserver (void)
[ # # ][ # # ]
76 : : {
77 [ # # ]: 0 : }
78 : :
79 : 0 : void PresenterFrameworkObserver::RunOnUpdateEnd (
80 : : const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController,
81 : : const Action& rAction)
82 : : {
83 : : new PresenterFrameworkObserver(
84 : : rxController,
85 : : OUString(),
86 : : &PresenterFrameworkObserver::True,
87 [ # # ][ # # ]: 0 : rAction);
[ # # ]
88 : 0 : }
89 : :
90 : 0 : bool PresenterFrameworkObserver::True (void)
91 : : {
92 : 0 : return true;
93 : : }
94 : :
95 : 0 : void SAL_CALL PresenterFrameworkObserver::disposing (void)
96 : : {
97 [ # # ]: 0 : if ( ! maAction.empty())
98 : 0 : maAction(false);
99 : 0 : Shutdown();
100 : 0 : }
101 : :
102 : 0 : void PresenterFrameworkObserver::Shutdown (void)
103 : : {
104 [ # # ]: 0 : maAction = Action();
105 [ # # ]: 0 : maPredicate = Predicate();
106 : :
107 [ # # ]: 0 : if (mxConfigurationController != NULL)
108 : : {
109 [ # # ]: 0 : mxConfigurationController->removeConfigurationChangeListener(this);
110 : 0 : mxConfigurationController = NULL;
111 : : }
112 : 0 : }
113 : :
114 : 0 : void SAL_CALL PresenterFrameworkObserver::disposing (const lang::EventObject& rEvent)
115 : : throw (RuntimeException)
116 : : {
117 [ # # ]: 0 : if ( ! rEvent.Source.is())
118 : 0 : return;
119 : :
120 [ # # ]: 0 : if (rEvent.Source == mxConfigurationController)
121 : : {
122 : 0 : mxConfigurationController = NULL;
123 [ # # ]: 0 : if ( ! maAction.empty())
124 : 0 : maAction(false);
125 : : }
126 : : }
127 : :
128 : 0 : void SAL_CALL PresenterFrameworkObserver::notifyConfigurationChange (
129 : : const ConfigurationChangeEvent& rEvent)
130 : : throw (RuntimeException)
131 : : {
132 : 0 : bool bDispose(false);
133 : :
134 [ # # ]: 0 : Action aAction (maAction);
135 [ # # ]: 0 : Predicate aPredicate (maPredicate);
136 [ # # ][ # # ]: 0 : if (rEvent.Type.equals(A2S("ConfigurationUpdateEnd")))
137 : : {
138 [ # # ]: 0 : Shutdown();
139 [ # # ]: 0 : aAction(aPredicate);
140 : 0 : bDispose = true;
141 : : }
142 [ # # ][ # # ]: 0 : else if (aPredicate())
143 : : {
144 [ # # ]: 0 : Shutdown();
145 [ # # ]: 0 : aAction(true);
146 : 0 : bDispose = true;
147 : : }
148 : :
149 [ # # ]: 0 : if (bDispose)
150 : : {
151 [ # # ]: 0 : maAction.clear();
152 [ # # ]: 0 : dispose();
153 [ # # ][ # # ]: 0 : }
154 : 0 : }
155 : :
156 : : } } // end of namespace ::sdext::presenter
157 : :
158 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|