1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sdext.hxx" 26 27 #include "PresenterFrameworkObserver.hxx" 28 #include <com/sun/star/lang/IllegalArgumentException.hpp> 29 #include <boost/bind.hpp> 30 31 using namespace ::com::sun::star; 32 using namespace ::com::sun::star::uno; 33 using namespace ::com::sun::star::drawing::framework; 34 35 using ::rtl::OUString; 36 37 #define A2S(pString) (::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(pString))) 38 39 namespace sdext { namespace presenter { 40 41 PresenterFrameworkObserver::PresenterFrameworkObserver ( 42 const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController, 43 const OUString& rsEventName, 44 const Predicate& rPredicate, 45 const Action& rAction) 46 : PresenterFrameworkObserverInterfaceBase(m_aMutex), 47 mxConfigurationController(rxController), 48 maPredicate(rPredicate), 49 maAction(rAction) 50 { 51 if ( ! mxConfigurationController.is()) 52 throw lang::IllegalArgumentException(); 53 54 if (mxConfigurationController->hasPendingRequests()) 55 { 56 if (rsEventName.getLength() > 0) 57 { 58 mxConfigurationController->addConfigurationChangeListener( 59 this, 60 rsEventName, 61 Any()); 62 } 63 mxConfigurationController->addConfigurationChangeListener( 64 this, 65 A2S("ConfigurationUpdateEnd"), 66 Any()); 67 } 68 else 69 { 70 rAction(maPredicate()); 71 } 72 } 73 74 75 76 77 PresenterFrameworkObserver::~PresenterFrameworkObserver (void) 78 { 79 } 80 81 82 83 84 void PresenterFrameworkObserver::RunOnResourceActivation ( 85 const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController, 86 const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId, 87 const Action& rAction) 88 { 89 new PresenterFrameworkObserver( 90 rxController, 91 A2S("ResourceActivation"), 92 ::boost::bind(&PresenterFrameworkObserver::HasResource, rxController, rxResourceId), 93 rAction); 94 } 95 96 97 98 99 void PresenterFrameworkObserver::RunOnUpdateEnd ( 100 const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController, 101 const Action& rAction) 102 { 103 new PresenterFrameworkObserver( 104 rxController, 105 OUString(), 106 &PresenterFrameworkObserver::True, 107 rAction); 108 } 109 110 111 112 113 bool PresenterFrameworkObserver::HasResource ( 114 const css::uno::Reference<css::drawing::framework::XConfigurationController>&rxController, 115 const css::uno::Reference<css::drawing::framework::XResourceId>& rxResourceId) 116 { 117 return rxController.is() && rxController->getResource(rxResourceId).is(); 118 } 119 120 121 122 123 bool PresenterFrameworkObserver::True (void) 124 { 125 return true; 126 } 127 128 129 130 131 bool PresenterFrameworkObserver::False (void) 132 { 133 return false; 134 } 135 136 137 138 139 void SAL_CALL PresenterFrameworkObserver::disposing (void) 140 { 141 if ( ! maAction.empty()) 142 maAction(false); 143 Shutdown(); 144 } 145 146 147 148 149 void PresenterFrameworkObserver::Shutdown (void) 150 { 151 maAction = Action(); 152 maPredicate = Predicate(); 153 154 if (mxConfigurationController != NULL) 155 { 156 mxConfigurationController->removeConfigurationChangeListener(this); 157 mxConfigurationController = NULL; 158 } 159 } 160 161 162 163 164 void SAL_CALL PresenterFrameworkObserver::disposing (const lang::EventObject& rEvent) 165 throw (RuntimeException) 166 { 167 if ( ! rEvent.Source.is()) 168 return; 169 170 if (rEvent.Source == mxConfigurationController) 171 { 172 mxConfigurationController = NULL; 173 if ( ! maAction.empty()) 174 maAction(false); 175 } 176 } 177 178 179 180 181 void SAL_CALL PresenterFrameworkObserver::notifyConfigurationChange ( 182 const ConfigurationChangeEvent& rEvent) 183 throw (RuntimeException) 184 { 185 bool bDispose(false); 186 187 Action aAction (maAction); 188 Predicate aPredicate (maPredicate); 189 if (rEvent.Type.equals(A2S("ConfigurationUpdateEnd"))) 190 { 191 Shutdown(); 192 aAction(aPredicate); 193 bDispose = true; 194 } 195 else if (aPredicate()) 196 { 197 Shutdown(); 198 aAction(true); 199 bDispose = true; 200 } 201 202 if (bDispose) 203 { 204 maAction.clear(); 205 dispose(); 206 } 207 } 208 209 } } // end of namespace ::sdext::presenter 210