1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sdext.hxx" 30 31 #include "PresenterFrameworkObserver.hxx" 32 #include <com/sun/star/lang/IllegalArgumentException.hpp> 33 #include <boost/bind.hpp> 34 35 using namespace ::com::sun::star; 36 using namespace ::com::sun::star::uno; 37 using namespace ::com::sun::star::drawing::framework; 38 39 using ::rtl::OUString; 40 41 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString))) 42 43 namespace sdext { namespace presenter { 44 45 PresenterFrameworkObserver::PresenterFrameworkObserver ( 46 const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController, 47 const OUString& rsEventName, 48 const Predicate& rPredicate, 49 const Action& rAction) 50 : PresenterFrameworkObserverInterfaceBase(m_aMutex), 51 mxConfigurationController(rxController), 52 maPredicate(rPredicate), 53 maAction(rAction) 54 { 55 if ( ! mxConfigurationController.is()) 56 throw lang::IllegalArgumentException(); 57 58 if (mxConfigurationController->hasPendingRequests()) 59 { 60 if (rsEventName.getLength() > 0) 61 { 62 mxConfigurationController->addConfigurationChangeListener( 63 this, 64 rsEventName, 65 Any()); 66 } 67 mxConfigurationController->addConfigurationChangeListener( 68 this, 69 A2S("ConfigurationUpdateEnd"), 70 Any()); 71 } 72 else 73 { 74 rAction(maPredicate()); 75 } 76 } 77 78 79 80 81 PresenterFrameworkObserver::~PresenterFrameworkObserver (void) 82 { 83 } 84 85 86 87 88 void PresenterFrameworkObserver::RunOnResourceActivation ( 89 const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController, 90 const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId, 91 const Action& rAction) 92 { 93 new PresenterFrameworkObserver( 94 rxController, 95 A2S("ResourceActivation"), 96 ::boost::bind(&PresenterFrameworkObserver::HasResource, rxController, rxResourceId), 97 rAction); 98 } 99 100 101 102 103 void PresenterFrameworkObserver::RunOnUpdateEnd ( 104 const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController, 105 const Action& rAction) 106 { 107 new PresenterFrameworkObserver( 108 rxController, 109 OUString(), 110 &PresenterFrameworkObserver::True, 111 rAction); 112 } 113 114 115 116 117 bool PresenterFrameworkObserver::HasResource ( 118 const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController, 119 const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId) 120 { 121 return rxController.is() && rxController->getResource(rxResourceId).is(); 122 } 123 124 125 126 127 bool PresenterFrameworkObserver::True (void) 128 { 129 return true; 130 } 131 132 133 134 135 bool PresenterFrameworkObserver::False (void) 136 { 137 return false; 138 } 139 140 141 142 143 void SAL_CALL PresenterFrameworkObserver::disposing (void) 144 { 145 if ( ! maAction.empty()) 146 maAction(false); 147 Shutdown(); 148 } 149 150 151 152 153 void PresenterFrameworkObserver::Shutdown (void) 154 { 155 maAction = Action(); 156 maPredicate = Predicate(); 157 158 if (mxConfigurationController != NULL) 159 { 160 mxConfigurationController->removeConfigurationChangeListener(this); 161 mxConfigurationController = NULL; 162 } 163 } 164 165 166 167 168 void SAL_CALL PresenterFrameworkObserver::disposing (const lang::EventObject& rEvent) 169 throw (RuntimeException) 170 { 171 if ( ! rEvent.Source.is()) 172 return; 173 174 if (rEvent.Source == mxConfigurationController) 175 { 176 mxConfigurationController = NULL; 177 if ( ! maAction.empty()) 178 maAction(false); 179 } 180 } 181 182 183 184 185 void SAL_CALL PresenterFrameworkObserver::notifyConfigurationChange ( 186 const ConfigurationChangeEvent& rEvent) 187 throw (RuntimeException) 188 { 189 bool bDispose(false); 190 191 Action aAction (maAction); 192 Predicate aPredicate (maPredicate); 193 if (rEvent.Type.equals(A2S("ConfigurationUpdateEnd"))) 194 { 195 Shutdown(); 196 aAction(aPredicate); 197 bDispose = true; 198 } 199 else if (aPredicate()) 200 { 201 Shutdown(); 202 aAction(true); 203 bDispose = true; 204 } 205 206 if (bDispose) 207 { 208 maAction.clear(); 209 dispose(); 210 } 211 } 212 213 } } // end of namespace ::sdext::presenter 214