1*cdf0e10cSrcweir /************************************************************************* 2*cdf0e10cSrcweir * 3*cdf0e10cSrcweir * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4*cdf0e10cSrcweir * 5*cdf0e10cSrcweir * Copyright 2000, 2010 Oracle and/or its affiliates. 6*cdf0e10cSrcweir * 7*cdf0e10cSrcweir * OpenOffice.org - a multi-platform office productivity suite 8*cdf0e10cSrcweir * 9*cdf0e10cSrcweir * This file is part of OpenOffice.org. 10*cdf0e10cSrcweir * 11*cdf0e10cSrcweir * OpenOffice.org is free software: you can redistribute it and/or modify 12*cdf0e10cSrcweir * it under the terms of the GNU Lesser General Public License version 3 13*cdf0e10cSrcweir * only, as published by the Free Software Foundation. 14*cdf0e10cSrcweir * 15*cdf0e10cSrcweir * OpenOffice.org is distributed in the hope that it will be useful, 16*cdf0e10cSrcweir * but WITHOUT ANY WARRANTY; without even the implied warranty of 17*cdf0e10cSrcweir * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18*cdf0e10cSrcweir * GNU Lesser General Public License version 3 for more details 19*cdf0e10cSrcweir * (a copy is included in the LICENSE file that accompanied this code). 20*cdf0e10cSrcweir * 21*cdf0e10cSrcweir * You should have received a copy of the GNU Lesser General Public License 22*cdf0e10cSrcweir * version 3 along with OpenOffice.org. If not, see 23*cdf0e10cSrcweir * <http://www.openoffice.org/license.html> 24*cdf0e10cSrcweir * for a copy of the LGPLv3 License. 25*cdf0e10cSrcweir * 26*cdf0e10cSrcweir ************************************************************************/ 27*cdf0e10cSrcweir 28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 29*cdf0e10cSrcweir #include "precompiled_forms.hxx" 30*cdf0e10cSrcweir #include "clickableimage.hxx" 31*cdf0e10cSrcweir #include "controlfeatureinterception.hxx" 32*cdf0e10cSrcweir #include "urltransformer.hxx" 33*cdf0e10cSrcweir #include "componenttools.hxx" 34*cdf0e10cSrcweir #include <com/sun/star/form/XSubmit.hpp> 35*cdf0e10cSrcweir #include <com/sun/star/awt/SystemPointer.hpp> 36*cdf0e10cSrcweir #include <com/sun/star/form/FormComponentType.hpp> 37*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatch.hpp> 38*cdf0e10cSrcweir #include <com/sun/star/frame/XDispatchProvider.hpp> 39*cdf0e10cSrcweir #include <com/sun/star/frame/FrameSearchFlag.hpp> 40*cdf0e10cSrcweir #include <com/sun/star/frame/XController.hpp> 41*cdf0e10cSrcweir #include <com/sun/star/frame/XFrame.hpp> 42*cdf0e10cSrcweir #include <com/sun/star/awt/ActionEvent.hpp> 43*cdf0e10cSrcweir #include <com/sun/star/awt/XActionListener.hpp> 44*cdf0e10cSrcweir #include <tools/urlobj.hxx> 45*cdf0e10cSrcweir #include <tools/debug.hxx> 46*cdf0e10cSrcweir #include <vcl/svapp.hxx> 47*cdf0e10cSrcweir #include <sfx2/docfile.hxx> 48*cdf0e10cSrcweir #include <sfx2/objsh.hxx> 49*cdf0e10cSrcweir #include <vos/mutex.hxx> 50*cdf0e10cSrcweir #include "services.hxx" 51*cdf0e10cSrcweir #include <comphelper/container.hxx> 52*cdf0e10cSrcweir #include <comphelper/listenernotification.hxx> 53*cdf0e10cSrcweir #include <svtools/imageresourceaccess.hxx> 54*cdf0e10cSrcweir #define LOCAL_URL_PREFIX '#' 55*cdf0e10cSrcweir 56*cdf0e10cSrcweir //......................................................................... 57*cdf0e10cSrcweir namespace frm 58*cdf0e10cSrcweir { 59*cdf0e10cSrcweir //......................................................................... 60*cdf0e10cSrcweir 61*cdf0e10cSrcweir using namespace ::com::sun::star::uno; 62*cdf0e10cSrcweir using namespace ::com::sun::star::sdb; 63*cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 64*cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 65*cdf0e10cSrcweir using namespace ::com::sun::star::beans; 66*cdf0e10cSrcweir using namespace ::com::sun::star::container; 67*cdf0e10cSrcweir using namespace ::com::sun::star::form; 68*cdf0e10cSrcweir using namespace ::com::sun::star::awt; 69*cdf0e10cSrcweir using namespace ::com::sun::star::io; 70*cdf0e10cSrcweir using namespace ::com::sun::star::lang; 71*cdf0e10cSrcweir using namespace ::com::sun::star::util; 72*cdf0e10cSrcweir using namespace ::com::sun::star::frame; 73*cdf0e10cSrcweir using namespace ::com::sun::star::form::submission; 74*cdf0e10cSrcweir using ::com::sun::star::awt::MouseEvent; 75*cdf0e10cSrcweir using ::com::sun::star::task::XInteractionHandler; 76*cdf0e10cSrcweir 77*cdf0e10cSrcweir //================================================================== 78*cdf0e10cSrcweir // OClickableImageBaseControl 79*cdf0e10cSrcweir //================================================================== 80*cdf0e10cSrcweir //------------------------------------------------------------------------------ 81*cdf0e10cSrcweir Sequence<Type> OClickableImageBaseControl::_getTypes() 82*cdf0e10cSrcweir { 83*cdf0e10cSrcweir static Sequence<Type> aTypes; 84*cdf0e10cSrcweir if (!aTypes.getLength()) 85*cdf0e10cSrcweir aTypes = concatSequences(OControl::_getTypes(), OClickableImageBaseControl_BASE::getTypes()); 86*cdf0e10cSrcweir return aTypes; 87*cdf0e10cSrcweir } 88*cdf0e10cSrcweir 89*cdf0e10cSrcweir //------------------------------------------------------------------------------ 90*cdf0e10cSrcweir OClickableImageBaseControl::OClickableImageBaseControl(const Reference<XMultiServiceFactory>& _rxFactory, const ::rtl::OUString& _aService) 91*cdf0e10cSrcweir :OControl(_rxFactory, _aService) 92*cdf0e10cSrcweir ,m_pThread(NULL) 93*cdf0e10cSrcweir ,m_aSubmissionVetoListeners( m_aMutex ) 94*cdf0e10cSrcweir ,m_aApproveActionListeners( m_aMutex ) 95*cdf0e10cSrcweir ,m_aActionListeners( m_aMutex ) 96*cdf0e10cSrcweir { 97*cdf0e10cSrcweir m_pFeatureInterception.reset( new ControlFeatureInterception( _rxFactory ) ); 98*cdf0e10cSrcweir } 99*cdf0e10cSrcweir 100*cdf0e10cSrcweir //------------------------------------------------------------------------------ 101*cdf0e10cSrcweir OClickableImageBaseControl::~OClickableImageBaseControl() 102*cdf0e10cSrcweir { 103*cdf0e10cSrcweir if (!OComponentHelper::rBHelper.bDisposed) 104*cdf0e10cSrcweir { 105*cdf0e10cSrcweir acquire(); 106*cdf0e10cSrcweir dispose(); 107*cdf0e10cSrcweir } 108*cdf0e10cSrcweir } 109*cdf0e10cSrcweir 110*cdf0e10cSrcweir // UNO Anbindung 111*cdf0e10cSrcweir //------------------------------------------------------------------------------ 112*cdf0e10cSrcweir Any SAL_CALL OClickableImageBaseControl::queryAggregation(const Type& _rType) throw (RuntimeException) 113*cdf0e10cSrcweir { 114*cdf0e10cSrcweir Any aReturn = OControl::queryAggregation(_rType); 115*cdf0e10cSrcweir if (!aReturn.hasValue()) 116*cdf0e10cSrcweir aReturn = OClickableImageBaseControl_BASE::queryInterface(_rType); 117*cdf0e10cSrcweir return aReturn; 118*cdf0e10cSrcweir } 119*cdf0e10cSrcweir 120*cdf0e10cSrcweir // XApproveActionBroadcaster 121*cdf0e10cSrcweir //------------------------------------------------------------------------------ 122*cdf0e10cSrcweir void OClickableImageBaseControl::addApproveActionListener( 123*cdf0e10cSrcweir const Reference<XApproveActionListener>& l) throw( RuntimeException ) 124*cdf0e10cSrcweir { 125*cdf0e10cSrcweir m_aApproveActionListeners.addInterface(l); 126*cdf0e10cSrcweir } 127*cdf0e10cSrcweir 128*cdf0e10cSrcweir //------------------------------------------------------------------------------ 129*cdf0e10cSrcweir void OClickableImageBaseControl::removeApproveActionListener( 130*cdf0e10cSrcweir const Reference<XApproveActionListener>& l) throw( RuntimeException ) 131*cdf0e10cSrcweir { 132*cdf0e10cSrcweir m_aApproveActionListeners.removeInterface(l); 133*cdf0e10cSrcweir } 134*cdf0e10cSrcweir 135*cdf0e10cSrcweir //-------------------------------------------------------------------- 136*cdf0e10cSrcweir void SAL_CALL OClickableImageBaseControl::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException) 137*cdf0e10cSrcweir { 138*cdf0e10cSrcweir m_pFeatureInterception->registerDispatchProviderInterceptor( _rxInterceptor ); 139*cdf0e10cSrcweir } 140*cdf0e10cSrcweir 141*cdf0e10cSrcweir //-------------------------------------------------------------------- 142*cdf0e10cSrcweir void SAL_CALL OClickableImageBaseControl::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException) 143*cdf0e10cSrcweir { 144*cdf0e10cSrcweir m_pFeatureInterception->releaseDispatchProviderInterceptor( _rxInterceptor ); 145*cdf0e10cSrcweir } 146*cdf0e10cSrcweir 147*cdf0e10cSrcweir // OComponentHelper 148*cdf0e10cSrcweir //------------------------------------------------------------------------------ 149*cdf0e10cSrcweir void OClickableImageBaseControl::disposing() 150*cdf0e10cSrcweir { 151*cdf0e10cSrcweir EventObject aEvent( static_cast< XWeak* >( this ) ); 152*cdf0e10cSrcweir m_aApproveActionListeners.disposeAndClear( aEvent ); 153*cdf0e10cSrcweir m_aActionListeners.disposeAndClear( aEvent ); 154*cdf0e10cSrcweir m_aSubmissionVetoListeners.disposeAndClear( aEvent ); 155*cdf0e10cSrcweir m_pFeatureInterception->dispose(); 156*cdf0e10cSrcweir 157*cdf0e10cSrcweir { 158*cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 159*cdf0e10cSrcweir if( m_pThread ) 160*cdf0e10cSrcweir { 161*cdf0e10cSrcweir m_pThread->release(); 162*cdf0e10cSrcweir m_pThread = NULL; 163*cdf0e10cSrcweir } 164*cdf0e10cSrcweir } 165*cdf0e10cSrcweir 166*cdf0e10cSrcweir OControl::disposing(); 167*cdf0e10cSrcweir } 168*cdf0e10cSrcweir 169*cdf0e10cSrcweir //------------------------------------------------------------------------------ 170*cdf0e10cSrcweir OImageProducerThread_Impl* OClickableImageBaseControl::getImageProducerThread() 171*cdf0e10cSrcweir { 172*cdf0e10cSrcweir if ( !m_pThread ) 173*cdf0e10cSrcweir { 174*cdf0e10cSrcweir m_pThread = new OImageProducerThread_Impl( this ); 175*cdf0e10cSrcweir m_pThread->acquire(); 176*cdf0e10cSrcweir m_pThread->create(); 177*cdf0e10cSrcweir } 178*cdf0e10cSrcweir return m_pThread; 179*cdf0e10cSrcweir } 180*cdf0e10cSrcweir 181*cdf0e10cSrcweir //------------------------------------------------------------------------------ 182*cdf0e10cSrcweir bool OClickableImageBaseControl::approveAction( ) 183*cdf0e10cSrcweir { 184*cdf0e10cSrcweir sal_Bool bCancelled = sal_False; 185*cdf0e10cSrcweir EventObject aEvent( static_cast< XWeak* >( this ) ); 186*cdf0e10cSrcweir 187*cdf0e10cSrcweir ::cppu::OInterfaceIteratorHelper aIter( m_aApproveActionListeners ); 188*cdf0e10cSrcweir while( !bCancelled && aIter.hasMoreElements() ) 189*cdf0e10cSrcweir { 190*cdf0e10cSrcweir // Jede approveAction-Methode muss thread-safe sein!!! 191*cdf0e10cSrcweir if( !static_cast< XApproveActionListener* >( aIter.next() )->approveAction( aEvent ) ) 192*cdf0e10cSrcweir bCancelled = sal_True; 193*cdf0e10cSrcweir } 194*cdf0e10cSrcweir 195*cdf0e10cSrcweir return !bCancelled; 196*cdf0e10cSrcweir } 197*cdf0e10cSrcweir 198*cdf0e10cSrcweir //------------------------------------------------------------------------------ 199*cdf0e10cSrcweir // Diese Methode wird auch aus einem Thread gerufen und muss deshalb 200*cdf0e10cSrcweir // thread-safe sein. 201*cdf0e10cSrcweir void OClickableImageBaseControl::actionPerformed_Impl(sal_Bool bNotifyListener, const MouseEvent& rEvt) 202*cdf0e10cSrcweir { 203*cdf0e10cSrcweir if( bNotifyListener ) 204*cdf0e10cSrcweir { 205*cdf0e10cSrcweir if ( !approveAction() ) 206*cdf0e10cSrcweir return; 207*cdf0e10cSrcweir } 208*cdf0e10cSrcweir 209*cdf0e10cSrcweir // Ob der Rest des Codes Thread-Safe ist weiss man nicht genau. Deshalb 210*cdf0e10cSrcweir // wird das meiste bei gelocktem Solar-Mutex erledigen. 211*cdf0e10cSrcweir Reference<XPropertySet> xSet; 212*cdf0e10cSrcweir Reference< XInterface > xModelsParent; 213*cdf0e10cSrcweir FormButtonType eButtonType = FormButtonType_PUSH; 214*cdf0e10cSrcweir { 215*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 216*cdf0e10cSrcweir 217*cdf0e10cSrcweir // Parent holen 218*cdf0e10cSrcweir Reference<XFormComponent> xComp(getModel(), UNO_QUERY); 219*cdf0e10cSrcweir if (!xComp.is()) 220*cdf0e10cSrcweir return; 221*cdf0e10cSrcweir 222*cdf0e10cSrcweir xModelsParent = xComp->getParent(); 223*cdf0e10cSrcweir if (!xModelsParent.is()) 224*cdf0e10cSrcweir return; 225*cdf0e10cSrcweir 226*cdf0e10cSrcweir // which button type? 227*cdf0e10cSrcweir xSet = xSet.query( xComp ); 228*cdf0e10cSrcweir if ( !xSet.is() ) 229*cdf0e10cSrcweir return; 230*cdf0e10cSrcweir xSet->getPropertyValue(PROPERTY_BUTTONTYPE) >>= eButtonType; 231*cdf0e10cSrcweir } 232*cdf0e10cSrcweir 233*cdf0e10cSrcweir switch (eButtonType) 234*cdf0e10cSrcweir { 235*cdf0e10cSrcweir case FormButtonType_RESET: 236*cdf0e10cSrcweir { 237*cdf0e10cSrcweir // reset-Methoden muessen thread-safe sein! 238*cdf0e10cSrcweir Reference<XReset> xReset(xModelsParent, UNO_QUERY); 239*cdf0e10cSrcweir if (!xReset.is()) 240*cdf0e10cSrcweir return; 241*cdf0e10cSrcweir 242*cdf0e10cSrcweir xReset->reset(); 243*cdf0e10cSrcweir } 244*cdf0e10cSrcweir break; 245*cdf0e10cSrcweir 246*cdf0e10cSrcweir case FormButtonType_SUBMIT: 247*cdf0e10cSrcweir { 248*cdf0e10cSrcweir // if some outer component can provide an interaction handler, use it 249*cdf0e10cSrcweir Reference< XInteractionHandler > xHandler( m_pFeatureInterception->queryDispatch( "private:/InteractionHandler" ), UNO_QUERY ); 250*cdf0e10cSrcweir try 251*cdf0e10cSrcweir { 252*cdf0e10cSrcweir implSubmit( rEvt, xHandler ); 253*cdf0e10cSrcweir } 254*cdf0e10cSrcweir catch( const Exception& ) 255*cdf0e10cSrcweir { 256*cdf0e10cSrcweir // ignore 257*cdf0e10cSrcweir } 258*cdf0e10cSrcweir } 259*cdf0e10cSrcweir break; 260*cdf0e10cSrcweir 261*cdf0e10cSrcweir case FormButtonType_URL: 262*cdf0e10cSrcweir { 263*cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 264*cdf0e10cSrcweir 265*cdf0e10cSrcweir Reference< XModel > xModel = getXModel(xModelsParent); 266*cdf0e10cSrcweir if (!xModel.is()) 267*cdf0e10cSrcweir return; 268*cdf0e10cSrcweir 269*cdf0e10cSrcweir /////////////////////////////////////////////////////////////////////// 270*cdf0e10cSrcweir // Jetzt URL ausfuehren 271*cdf0e10cSrcweir Reference< XController > xController = xModel->getCurrentController(); 272*cdf0e10cSrcweir if (!xController.is()) 273*cdf0e10cSrcweir return; 274*cdf0e10cSrcweir 275*cdf0e10cSrcweir Reference< XFrame > xFrame = xController->getFrame(); 276*cdf0e10cSrcweir if( !xFrame.is() ) 277*cdf0e10cSrcweir return; 278*cdf0e10cSrcweir 279*cdf0e10cSrcweir URL aURL; 280*cdf0e10cSrcweir aURL.Complete = 281*cdf0e10cSrcweir getString(xSet->getPropertyValue(PROPERTY_TARGET_URL)); 282*cdf0e10cSrcweir 283*cdf0e10cSrcweir if (aURL.Complete.getLength() && (LOCAL_URL_PREFIX == aURL.Complete.getStr()[0])) 284*cdf0e10cSrcweir { // the URL contains a local URL only. Since the URLTransformer does not handle this case correctly 285*cdf0e10cSrcweir // (it can't: it does not know the document URL), we have to take care for this ourself. 286*cdf0e10cSrcweir // The real solution would be to not allow such relative URLs (there is a rule that at runtime, all 287*cdf0e10cSrcweir // URLs have to be absolute), but for compatibility reasons this is no option. 288*cdf0e10cSrcweir // The more as the user does not want to see a local URL as "file://<path>/<document>#mark" if it 289*cdf0e10cSrcweir // could be "#mark" as well. 290*cdf0e10cSrcweir // If we someday say that this hack (yes, it's kind of a hack) is not sustainable anymore, the complete 291*cdf0e10cSrcweir // solutiuon would be: 292*cdf0e10cSrcweir // * recognize URLs consisting of a mark only while _reading_ the document 293*cdf0e10cSrcweir // * for this, allow the INetURLObject (which at the moment is invoked when reading URLs) to 294*cdf0e10cSrcweir // transform such mark-only URLs into correct absolute URLs 295*cdf0e10cSrcweir // * at the UI, show only the mark 296*cdf0e10cSrcweir // * !!!! recognize every SAVEAS on the document, so the absolute URL can be adjusted. This seems 297*cdf0e10cSrcweir // rather impossible !!! 298*cdf0e10cSrcweir // 89752 - 23.07.2001 - frank.schoenheit@sun.com 299*cdf0e10cSrcweir aURL.Mark = aURL.Complete; 300*cdf0e10cSrcweir aURL.Complete = xModel->getURL(); 301*cdf0e10cSrcweir aURL.Complete += aURL.Mark; 302*cdf0e10cSrcweir } 303*cdf0e10cSrcweir 304*cdf0e10cSrcweir sal_Bool bDispatchUrlInternal = sal_False; 305*cdf0e10cSrcweir xSet->getPropertyValue(PROPERTY_DISPATCHURLINTERNAL) >>= bDispatchUrlInternal; 306*cdf0e10cSrcweir if ( bDispatchUrlInternal ) 307*cdf0e10cSrcweir { 308*cdf0e10cSrcweir m_pFeatureInterception->getTransformer().parseSmartWithAsciiProtocol( aURL, INET_FILE_SCHEME ); 309*cdf0e10cSrcweir 310*cdf0e10cSrcweir ::rtl::OUString aTargetFrame; 311*cdf0e10cSrcweir xSet->getPropertyValue(PROPERTY_TARGET_FRAME) >>= aTargetFrame; 312*cdf0e10cSrcweir 313*cdf0e10cSrcweir Reference< XDispatch > xDisp = Reference< XDispatchProvider > (xFrame,UNO_QUERY)->queryDispatch( aURL, aTargetFrame, 314*cdf0e10cSrcweir FrameSearchFlag::SELF | FrameSearchFlag::PARENT | 315*cdf0e10cSrcweir FrameSearchFlag::SIBLINGS | FrameSearchFlag::CREATE ); 316*cdf0e10cSrcweir 317*cdf0e10cSrcweir Sequence<PropertyValue> aArgs(1); 318*cdf0e10cSrcweir PropertyValue& rProp = aArgs.getArray()[0]; 319*cdf0e10cSrcweir rProp.Name = ::rtl::OUString::createFromAscii("Referer"); 320*cdf0e10cSrcweir rProp.Value <<= xModel->getURL(); 321*cdf0e10cSrcweir 322*cdf0e10cSrcweir if (xDisp.is()) 323*cdf0e10cSrcweir xDisp->dispatch( aURL, aArgs ); 324*cdf0e10cSrcweir } 325*cdf0e10cSrcweir else 326*cdf0e10cSrcweir { 327*cdf0e10cSrcweir URL aHyperLink = m_pFeatureInterception->getTransformer().getStrictURLFromAscii( ".uno:OpenHyperlink" ); 328*cdf0e10cSrcweir 329*cdf0e10cSrcweir Reference< XDispatch > xDisp = Reference< XDispatchProvider > (xFrame,UNO_QUERY)->queryDispatch(aHyperLink, ::rtl::OUString() , 0); 330*cdf0e10cSrcweir 331*cdf0e10cSrcweir if ( xDisp.is() ) 332*cdf0e10cSrcweir { 333*cdf0e10cSrcweir Sequence<PropertyValue> aProps(3); 334*cdf0e10cSrcweir aProps[0].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("URL")); 335*cdf0e10cSrcweir aProps[0].Value <<= aURL.Complete; 336*cdf0e10cSrcweir 337*cdf0e10cSrcweir aProps[1].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FrameName")); 338*cdf0e10cSrcweir aProps[1].Value = xSet->getPropertyValue(PROPERTY_TARGET_FRAME); 339*cdf0e10cSrcweir 340*cdf0e10cSrcweir aProps[2].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Referer")); 341*cdf0e10cSrcweir aProps[2].Value <<= xModel->getURL(); 342*cdf0e10cSrcweir 343*cdf0e10cSrcweir xDisp->dispatch( aHyperLink, aProps ); 344*cdf0e10cSrcweir } 345*cdf0e10cSrcweir } 346*cdf0e10cSrcweir } break; 347*cdf0e10cSrcweir default: 348*cdf0e10cSrcweir { 349*cdf0e10cSrcweir // notify the action listeners for a push button 350*cdf0e10cSrcweir ActionEvent aEvt(static_cast<XWeak*>(this), m_aActionCommand); 351*cdf0e10cSrcweir m_aActionListeners.notifyEach( &XActionListener::actionPerformed, aEvt ); 352*cdf0e10cSrcweir } 353*cdf0e10cSrcweir } 354*cdf0e10cSrcweir } 355*cdf0e10cSrcweir 356*cdf0e10cSrcweir 357*cdf0e10cSrcweir //-------------------------------------------------------------------- 358*cdf0e10cSrcweir void SAL_CALL OClickableImageBaseControl::addSubmissionVetoListener( const Reference< submission::XSubmissionVetoListener >& listener ) throw (NoSupportException, RuntimeException) 359*cdf0e10cSrcweir { 360*cdf0e10cSrcweir m_aSubmissionVetoListeners.addInterface( listener ); 361*cdf0e10cSrcweir } 362*cdf0e10cSrcweir 363*cdf0e10cSrcweir //-------------------------------------------------------------------- 364*cdf0e10cSrcweir void SAL_CALL OClickableImageBaseControl::removeSubmissionVetoListener( const Reference< submission::XSubmissionVetoListener >& listener ) throw (NoSupportException, RuntimeException) 365*cdf0e10cSrcweir { 366*cdf0e10cSrcweir m_aSubmissionVetoListeners.removeInterface( listener ); 367*cdf0e10cSrcweir } 368*cdf0e10cSrcweir 369*cdf0e10cSrcweir //-------------------------------------------------------------------- 370*cdf0e10cSrcweir void SAL_CALL OClickableImageBaseControl::submitWithInteraction( const Reference< XInteractionHandler >& _rxHandler ) throw (VetoException, WrappedTargetException, RuntimeException) 371*cdf0e10cSrcweir { 372*cdf0e10cSrcweir implSubmit( MouseEvent(), _rxHandler ); 373*cdf0e10cSrcweir } 374*cdf0e10cSrcweir 375*cdf0e10cSrcweir //-------------------------------------------------------------------- 376*cdf0e10cSrcweir void SAL_CALL OClickableImageBaseControl::submit( ) throw (VetoException, WrappedTargetException, RuntimeException) 377*cdf0e10cSrcweir { 378*cdf0e10cSrcweir implSubmit( MouseEvent(), NULL ); 379*cdf0e10cSrcweir } 380*cdf0e10cSrcweir 381*cdf0e10cSrcweir //-------------------------------------------------------------------- 382*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL OClickableImageBaseControl::getSupportedServiceNames( ) throw (RuntimeException) 383*cdf0e10cSrcweir { 384*cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported = OControl::getSupportedServiceNames(); 385*cdf0e10cSrcweir aSupported.realloc( aSupported.getLength() + 1 ); 386*cdf0e10cSrcweir 387*cdf0e10cSrcweir ::rtl::OUString* pArray = aSupported.getArray(); 388*cdf0e10cSrcweir pArray[ aSupported.getLength() - 1 ] = FRM_SUN_CONTROL_SUBMITBUTTON; 389*cdf0e10cSrcweir 390*cdf0e10cSrcweir return aSupported; 391*cdf0e10cSrcweir } 392*cdf0e10cSrcweir 393*cdf0e10cSrcweir //-------------------------------------------------------------------- 394*cdf0e10cSrcweir void OClickableImageBaseControl::implSubmit( const MouseEvent& _rEvent, const Reference< XInteractionHandler >& _rxHandler ) SAL_THROW((VetoException, WrappedTargetException, RuntimeException)) 395*cdf0e10cSrcweir { 396*cdf0e10cSrcweir try 397*cdf0e10cSrcweir { 398*cdf0e10cSrcweir // allow the veto listeners to join the game 399*cdf0e10cSrcweir m_aSubmissionVetoListeners.notifyEach( &XSubmissionVetoListener::submitting, EventObject( *this ) ); 400*cdf0e10cSrcweir 401*cdf0e10cSrcweir // see whether there's an "submit interceptor" set at our model 402*cdf0e10cSrcweir Reference< submission::XSubmissionSupplier > xSubmissionSupp( getModel(), UNO_QUERY ); 403*cdf0e10cSrcweir Reference< XSubmission > xSubmission; 404*cdf0e10cSrcweir if ( xSubmissionSupp.is() ) 405*cdf0e10cSrcweir xSubmission = xSubmissionSupp->getSubmission(); 406*cdf0e10cSrcweir 407*cdf0e10cSrcweir if ( xSubmission.is() ) 408*cdf0e10cSrcweir { 409*cdf0e10cSrcweir if ( !_rxHandler.is() ) 410*cdf0e10cSrcweir xSubmission->submit(); 411*cdf0e10cSrcweir else 412*cdf0e10cSrcweir xSubmission->submitWithInteraction( _rxHandler ); 413*cdf0e10cSrcweir } 414*cdf0e10cSrcweir else 415*cdf0e10cSrcweir { 416*cdf0e10cSrcweir // no "interceptor" -> ordinary (old-way) submission 417*cdf0e10cSrcweir Reference< XChild > xChild( getModel(), UNO_QUERY ); 418*cdf0e10cSrcweir Reference< XSubmit > xParentSubmission; 419*cdf0e10cSrcweir if ( xChild.is() ) 420*cdf0e10cSrcweir xParentSubmission = xParentSubmission.query( xChild->getParent() ); 421*cdf0e10cSrcweir if ( xParentSubmission.is() ) 422*cdf0e10cSrcweir xParentSubmission->submit( this, _rEvent ); 423*cdf0e10cSrcweir } 424*cdf0e10cSrcweir } 425*cdf0e10cSrcweir catch( const VetoException& ) 426*cdf0e10cSrcweir { 427*cdf0e10cSrcweir // allowed to leave 428*cdf0e10cSrcweir throw; 429*cdf0e10cSrcweir } 430*cdf0e10cSrcweir catch( const RuntimeException& ) 431*cdf0e10cSrcweir { 432*cdf0e10cSrcweir // allowed to leave 433*cdf0e10cSrcweir throw; 434*cdf0e10cSrcweir } 435*cdf0e10cSrcweir catch( const WrappedTargetException& e ) 436*cdf0e10cSrcweir { 437*cdf0e10cSrcweir // allowed to leave 438*cdf0e10cSrcweir throw; 439*cdf0e10cSrcweir } 440*cdf0e10cSrcweir catch( const Exception& e ) 441*cdf0e10cSrcweir { 442*cdf0e10cSrcweir OSL_ENSURE( sal_False, "OClickableImageBaseControl::implSubmit: caught an unknown exception!" ); 443*cdf0e10cSrcweir throw WrappedTargetException( ::rtl::OUString(), *this, makeAny( e ) ); 444*cdf0e10cSrcweir } 445*cdf0e10cSrcweir } 446*cdf0e10cSrcweir 447*cdf0e10cSrcweir //================================================================== 448*cdf0e10cSrcweir // OClickableImageBaseModel 449*cdf0e10cSrcweir //================================================================== 450*cdf0e10cSrcweir //------------------------------------------------------------------------------ 451*cdf0e10cSrcweir Sequence<Type> OClickableImageBaseModel::_getTypes() 452*cdf0e10cSrcweir { 453*cdf0e10cSrcweir return concatSequences( 454*cdf0e10cSrcweir OControlModel::_getTypes(), 455*cdf0e10cSrcweir OClickableImageBaseModel_Base::getTypes() 456*cdf0e10cSrcweir ); 457*cdf0e10cSrcweir } 458*cdf0e10cSrcweir 459*cdf0e10cSrcweir //------------------------------------------------------------------ 460*cdf0e10cSrcweir DBG_NAME( OClickableImageBaseModel ) 461*cdf0e10cSrcweir //------------------------------------------------------------------ 462*cdf0e10cSrcweir OClickableImageBaseModel::OClickableImageBaseModel( const Reference< XMultiServiceFactory >& _rxFactory, const ::rtl::OUString& _rUnoControlModelTypeName, 463*cdf0e10cSrcweir const ::rtl::OUString& rDefault ) 464*cdf0e10cSrcweir :OControlModel( _rxFactory, _rUnoControlModelTypeName, rDefault ) 465*cdf0e10cSrcweir ,OPropertyChangeListener(m_aMutex) 466*cdf0e10cSrcweir ,m_pMedium(NULL) 467*cdf0e10cSrcweir ,m_pProducer( NULL ) 468*cdf0e10cSrcweir ,m_bDispatchUrlInternal(sal_False) 469*cdf0e10cSrcweir ,m_bDownloading(sal_False) 470*cdf0e10cSrcweir ,m_bProdStarted(sal_False) 471*cdf0e10cSrcweir { 472*cdf0e10cSrcweir DBG_CTOR( OClickableImageBaseModel, NULL ); 473*cdf0e10cSrcweir implConstruct(); 474*cdf0e10cSrcweir m_eButtonType = FormButtonType_PUSH; 475*cdf0e10cSrcweir } 476*cdf0e10cSrcweir 477*cdf0e10cSrcweir //------------------------------------------------------------------ 478*cdf0e10cSrcweir OClickableImageBaseModel::OClickableImageBaseModel( const OClickableImageBaseModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory ) 479*cdf0e10cSrcweir :OControlModel( _pOriginal, _rxFactory ) 480*cdf0e10cSrcweir ,OPropertyChangeListener( m_aMutex ) 481*cdf0e10cSrcweir ,m_pMedium( NULL ) 482*cdf0e10cSrcweir ,m_pProducer( NULL ) 483*cdf0e10cSrcweir ,m_bDispatchUrlInternal(sal_False) 484*cdf0e10cSrcweir ,m_bDownloading( sal_False ) 485*cdf0e10cSrcweir ,m_bProdStarted( sal_False ) 486*cdf0e10cSrcweir { 487*cdf0e10cSrcweir DBG_CTOR( OClickableImageBaseModel, NULL ); 488*cdf0e10cSrcweir implConstruct(); 489*cdf0e10cSrcweir 490*cdf0e10cSrcweir // copy properties 491*cdf0e10cSrcweir m_eButtonType = _pOriginal->m_eButtonType; 492*cdf0e10cSrcweir m_sTargetURL = _pOriginal->m_sTargetURL; 493*cdf0e10cSrcweir m_sTargetFrame = _pOriginal->m_sTargetFrame; 494*cdf0e10cSrcweir m_bDispatchUrlInternal = _pOriginal->m_bDispatchUrlInternal; 495*cdf0e10cSrcweir } 496*cdf0e10cSrcweir 497*cdf0e10cSrcweir //------------------------------------------------------------------------------ 498*cdf0e10cSrcweir void OClickableImageBaseModel::implInitializeImageURL( ) 499*cdf0e10cSrcweir { 500*cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 501*cdf0e10cSrcweir { 502*cdf0e10cSrcweir // simulate a propertyChanged event for the ImageURL 503*cdf0e10cSrcweir // 2003-05-15 - #109591# - fs@openoffice.org 504*cdf0e10cSrcweir Any aImageURL; 505*cdf0e10cSrcweir getFastPropertyValue( aImageURL, PROPERTY_ID_IMAGE_URL ); 506*cdf0e10cSrcweir _propertyChanged( PropertyChangeEvent( *this, PROPERTY_IMAGE_URL, sal_False, PROPERTY_ID_IMAGE_URL, Any( ), aImageURL ) ); 507*cdf0e10cSrcweir } 508*cdf0e10cSrcweir osl_decrementInterlockedCount( &m_refCount ); 509*cdf0e10cSrcweir } 510*cdf0e10cSrcweir 511*cdf0e10cSrcweir //------------------------------------------------------------------------------ 512*cdf0e10cSrcweir void OClickableImageBaseModel::implConstruct() 513*cdf0e10cSrcweir { 514*cdf0e10cSrcweir m_pProducer = new ImageProducer; 515*cdf0e10cSrcweir increment( m_refCount ); 516*cdf0e10cSrcweir { 517*cdf0e10cSrcweir m_xProducer = m_pProducer; 518*cdf0e10cSrcweir 519*cdf0e10cSrcweir if ( m_xAggregateSet.is() ) 520*cdf0e10cSrcweir { 521*cdf0e10cSrcweir OPropertyChangeMultiplexer* pMultiplexer = new OPropertyChangeMultiplexer( this, m_xAggregateSet ); 522*cdf0e10cSrcweir pMultiplexer->addProperty( PROPERTY_IMAGE_URL ); 523*cdf0e10cSrcweir } 524*cdf0e10cSrcweir } 525*cdf0e10cSrcweir decrement(m_refCount); 526*cdf0e10cSrcweir } 527*cdf0e10cSrcweir 528*cdf0e10cSrcweir //------------------------------------------------------------------------------ 529*cdf0e10cSrcweir OClickableImageBaseModel::~OClickableImageBaseModel() 530*cdf0e10cSrcweir { 531*cdf0e10cSrcweir if (!OComponentHelper::rBHelper.bDisposed) 532*cdf0e10cSrcweir { 533*cdf0e10cSrcweir acquire(); 534*cdf0e10cSrcweir dispose(); 535*cdf0e10cSrcweir } 536*cdf0e10cSrcweir DBG_ASSERT(m_pMedium == NULL, "OClickableImageBaseModel::~OClickableImageBaseModel : leaving a memory leak ..."); 537*cdf0e10cSrcweir // spaetestens im dispose sollte das aufgeraeumt worden sein 538*cdf0e10cSrcweir 539*cdf0e10cSrcweir DBG_DTOR( OClickableImageBaseModel, NULL ); 540*cdf0e10cSrcweir } 541*cdf0e10cSrcweir 542*cdf0e10cSrcweir // XImageProducer 543*cdf0e10cSrcweir //-------------------------------------------------------------------- 544*cdf0e10cSrcweir void SAL_CALL OClickableImageBaseModel::addConsumer( const Reference< XImageConsumer >& _rxConsumer ) throw (RuntimeException) 545*cdf0e10cSrcweir { 546*cdf0e10cSrcweir ImageModelMethodGuard aGuard( *this ); 547*cdf0e10cSrcweir GetImageProducer()->addConsumer( _rxConsumer ); 548*cdf0e10cSrcweir } 549*cdf0e10cSrcweir 550*cdf0e10cSrcweir //-------------------------------------------------------------------- 551*cdf0e10cSrcweir void SAL_CALL OClickableImageBaseModel::removeConsumer( const Reference< XImageConsumer >& _rxConsumer ) throw (RuntimeException) 552*cdf0e10cSrcweir { 553*cdf0e10cSrcweir ImageModelMethodGuard aGuard( *this ); 554*cdf0e10cSrcweir GetImageProducer()->removeConsumer( _rxConsumer ); 555*cdf0e10cSrcweir } 556*cdf0e10cSrcweir 557*cdf0e10cSrcweir //-------------------------------------------------------------------- 558*cdf0e10cSrcweir void SAL_CALL OClickableImageBaseModel::startProduction( ) throw (RuntimeException) 559*cdf0e10cSrcweir { 560*cdf0e10cSrcweir ImageModelMethodGuard aGuard( *this ); 561*cdf0e10cSrcweir GetImageProducer()->startProduction(); 562*cdf0e10cSrcweir } 563*cdf0e10cSrcweir 564*cdf0e10cSrcweir //-------------------------------------------------------------------- 565*cdf0e10cSrcweir Reference< submission::XSubmission > SAL_CALL OClickableImageBaseModel::getSubmission() throw (RuntimeException) 566*cdf0e10cSrcweir { 567*cdf0e10cSrcweir return m_xSubmissionDelegate; 568*cdf0e10cSrcweir } 569*cdf0e10cSrcweir 570*cdf0e10cSrcweir //-------------------------------------------------------------------- 571*cdf0e10cSrcweir void SAL_CALL OClickableImageBaseModel::setSubmission( const Reference< submission::XSubmission >& _submission ) throw (RuntimeException) 572*cdf0e10cSrcweir { 573*cdf0e10cSrcweir m_xSubmissionDelegate = _submission; 574*cdf0e10cSrcweir } 575*cdf0e10cSrcweir 576*cdf0e10cSrcweir //-------------------------------------------------------------------- 577*cdf0e10cSrcweir Sequence< ::rtl::OUString > SAL_CALL OClickableImageBaseModel::getSupportedServiceNames( ) throw (RuntimeException) 578*cdf0e10cSrcweir { 579*cdf0e10cSrcweir Sequence< ::rtl::OUString > aSupported = OControlModel::getSupportedServiceNames(); 580*cdf0e10cSrcweir aSupported.realloc( aSupported.getLength() + 1 ); 581*cdf0e10cSrcweir 582*cdf0e10cSrcweir ::rtl::OUString* pArray = aSupported.getArray(); 583*cdf0e10cSrcweir pArray[ aSupported.getLength() - 1 ] = FRM_SUN_COMPONENT_SUBMITBUTTON; 584*cdf0e10cSrcweir 585*cdf0e10cSrcweir return aSupported; 586*cdf0e10cSrcweir } 587*cdf0e10cSrcweir 588*cdf0e10cSrcweir // OComponentHelper 589*cdf0e10cSrcweir //------------------------------------------------------------------------------ 590*cdf0e10cSrcweir void OClickableImageBaseModel::disposing() 591*cdf0e10cSrcweir { 592*cdf0e10cSrcweir OControlModel::disposing(); 593*cdf0e10cSrcweir if (m_pMedium) 594*cdf0e10cSrcweir { 595*cdf0e10cSrcweir delete m_pMedium; 596*cdf0e10cSrcweir m_pMedium = NULL; 597*cdf0e10cSrcweir } 598*cdf0e10cSrcweir 599*cdf0e10cSrcweir m_xProducer = NULL; 600*cdf0e10cSrcweir m_pProducer = NULL; 601*cdf0e10cSrcweir } 602*cdf0e10cSrcweir 603*cdf0e10cSrcweir //------------------------------------------------------------------------------ 604*cdf0e10cSrcweir Any SAL_CALL OClickableImageBaseModel::queryAggregation(const Type& _rType) throw (RuntimeException) 605*cdf0e10cSrcweir { 606*cdf0e10cSrcweir // order matters: 607*cdf0e10cSrcweir // we definately want to "overload" the XImageProducer interface of our aggregate, 608*cdf0e10cSrcweir // thus check OClickableImageBaseModel_Base (which provides this) first 609*cdf0e10cSrcweir Any aReturn = OClickableImageBaseModel_Base::queryInterface( _rType ); 610*cdf0e10cSrcweir 611*cdf0e10cSrcweir // BUT: _don't_ let it feel responsible for the XTypeProvider interface 612*cdf0e10cSrcweir // (as this is implemented by our base class in the proper way) 613*cdf0e10cSrcweir if ( _rType.equals( ::getCppuType( static_cast< Reference< XTypeProvider >* >( NULL ) ) ) 614*cdf0e10cSrcweir || !aReturn.hasValue() 615*cdf0e10cSrcweir ) 616*cdf0e10cSrcweir aReturn = OControlModel::queryAggregation( _rType ); 617*cdf0e10cSrcweir 618*cdf0e10cSrcweir return aReturn; 619*cdf0e10cSrcweir } 620*cdf0e10cSrcweir 621*cdf0e10cSrcweir //------------------------------------------------------------------------------ 622*cdf0e10cSrcweir void OClickableImageBaseModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const 623*cdf0e10cSrcweir { 624*cdf0e10cSrcweir switch (nHandle) 625*cdf0e10cSrcweir { 626*cdf0e10cSrcweir case PROPERTY_ID_BUTTONTYPE : rValue <<= m_eButtonType; break; 627*cdf0e10cSrcweir case PROPERTY_ID_TARGET_URL : rValue <<= m_sTargetURL; break; 628*cdf0e10cSrcweir case PROPERTY_ID_TARGET_FRAME : rValue <<= m_sTargetFrame; break; 629*cdf0e10cSrcweir case PROPERTY_ID_DISPATCHURLINTERNAL : rValue <<= m_bDispatchUrlInternal; break; 630*cdf0e10cSrcweir default: 631*cdf0e10cSrcweir OControlModel::getFastPropertyValue(rValue, nHandle); 632*cdf0e10cSrcweir } 633*cdf0e10cSrcweir } 634*cdf0e10cSrcweir 635*cdf0e10cSrcweir //------------------------------------------------------------------------------ 636*cdf0e10cSrcweir void OClickableImageBaseModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue) throw ( Exception) 637*cdf0e10cSrcweir { 638*cdf0e10cSrcweir switch (nHandle) 639*cdf0e10cSrcweir { 640*cdf0e10cSrcweir case PROPERTY_ID_BUTTONTYPE : 641*cdf0e10cSrcweir DBG_ASSERT(isA(rValue, static_cast<FormButtonType*>(NULL)), "OClickableImageBaseModel::setFastPropertyValue_NoBroadcast : invalid type !" ); 642*cdf0e10cSrcweir rValue >>= m_eButtonType; 643*cdf0e10cSrcweir break; 644*cdf0e10cSrcweir 645*cdf0e10cSrcweir case PROPERTY_ID_TARGET_URL : 646*cdf0e10cSrcweir DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_STRING, "OClickableImageBaseModel::setFastPropertyValue_NoBroadcast : invalid type !" ); 647*cdf0e10cSrcweir rValue >>= m_sTargetURL; 648*cdf0e10cSrcweir break; 649*cdf0e10cSrcweir 650*cdf0e10cSrcweir case PROPERTY_ID_TARGET_FRAME : 651*cdf0e10cSrcweir DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_STRING, "OClickableImageBaseModel::setFastPropertyValue_NoBroadcast : invalid type !" ); 652*cdf0e10cSrcweir rValue >>= m_sTargetFrame; 653*cdf0e10cSrcweir break; 654*cdf0e10cSrcweir 655*cdf0e10cSrcweir case PROPERTY_ID_DISPATCHURLINTERNAL: 656*cdf0e10cSrcweir DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_BOOLEAN, "OClickableImageBaseModel::setFastPropertyValue_NoBroadcast : invalid type !" ); 657*cdf0e10cSrcweir rValue >>= m_bDispatchUrlInternal; 658*cdf0e10cSrcweir break; 659*cdf0e10cSrcweir 660*cdf0e10cSrcweir default: 661*cdf0e10cSrcweir OControlModel::setFastPropertyValue_NoBroadcast(nHandle, rValue); 662*cdf0e10cSrcweir } 663*cdf0e10cSrcweir } 664*cdf0e10cSrcweir 665*cdf0e10cSrcweir //------------------------------------------------------------------------------ 666*cdf0e10cSrcweir sal_Bool OClickableImageBaseModel::convertFastPropertyValue(Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue) 667*cdf0e10cSrcweir throw( IllegalArgumentException ) 668*cdf0e10cSrcweir { 669*cdf0e10cSrcweir switch (nHandle) 670*cdf0e10cSrcweir { 671*cdf0e10cSrcweir case PROPERTY_ID_BUTTONTYPE : 672*cdf0e10cSrcweir return tryPropertyValueEnum( rConvertedValue, rOldValue, rValue, m_eButtonType ); 673*cdf0e10cSrcweir 674*cdf0e10cSrcweir case PROPERTY_ID_TARGET_URL : 675*cdf0e10cSrcweir return tryPropertyValue(rConvertedValue, rOldValue, rValue, m_sTargetURL); 676*cdf0e10cSrcweir 677*cdf0e10cSrcweir case PROPERTY_ID_TARGET_FRAME : 678*cdf0e10cSrcweir return tryPropertyValue(rConvertedValue, rOldValue, rValue, m_sTargetFrame); 679*cdf0e10cSrcweir 680*cdf0e10cSrcweir case PROPERTY_ID_DISPATCHURLINTERNAL : 681*cdf0e10cSrcweir return tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bDispatchUrlInternal); 682*cdf0e10cSrcweir 683*cdf0e10cSrcweir default: 684*cdf0e10cSrcweir return OControlModel::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue); 685*cdf0e10cSrcweir } 686*cdf0e10cSrcweir } 687*cdf0e10cSrcweir 688*cdf0e10cSrcweir //------------------------------------------------------------------------------ 689*cdf0e10cSrcweir void OClickableImageBaseModel::StartProduction() 690*cdf0e10cSrcweir { 691*cdf0e10cSrcweir ImageProducer *pImgProd = GetImageProducer(); 692*cdf0e10cSrcweir // grab the ImageURL 693*cdf0e10cSrcweir rtl::OUString sURL; 694*cdf0e10cSrcweir getPropertyValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("ImageURL") ) ) >>= sURL; 695*cdf0e10cSrcweir if (!m_pMedium) 696*cdf0e10cSrcweir { 697*cdf0e10cSrcweir if ( ::svt::GraphicAccess::isSupportedURL( sURL ) ) 698*cdf0e10cSrcweir pImgProd->SetImage( sURL ); 699*cdf0e10cSrcweir else 700*cdf0e10cSrcweir // caution: the medium may be NULL if somebody gave us a invalid URL to work with 701*cdf0e10cSrcweir // 11/24/2000 - 79667 - FS 702*cdf0e10cSrcweir pImgProd->SetImage(String()); 703*cdf0e10cSrcweir m_bDownloading = sal_False; 704*cdf0e10cSrcweir return; 705*cdf0e10cSrcweir } 706*cdf0e10cSrcweir if (m_pMedium->GetErrorCode()==0) 707*cdf0e10cSrcweir { 708*cdf0e10cSrcweir SvStream* pStream = m_pMedium->GetInStream(); 709*cdf0e10cSrcweir 710*cdf0e10cSrcweir pImgProd->SetImage(*pStream); 711*cdf0e10cSrcweir pImgProd->startProduction(); 712*cdf0e10cSrcweir m_bProdStarted = sal_True; 713*cdf0e10cSrcweir } 714*cdf0e10cSrcweir else 715*cdf0e10cSrcweir { 716*cdf0e10cSrcweir pImgProd->SetImage(String()); 717*cdf0e10cSrcweir delete m_pMedium; 718*cdf0e10cSrcweir m_pMedium = 0; 719*cdf0e10cSrcweir m_bDownloading = sal_False; 720*cdf0e10cSrcweir } 721*cdf0e10cSrcweir } 722*cdf0e10cSrcweir 723*cdf0e10cSrcweir //------------------------------------------------------------------------------ 724*cdf0e10cSrcweir void OClickableImageBaseModel::SetURL( const ::rtl::OUString& rURL ) 725*cdf0e10cSrcweir { 726*cdf0e10cSrcweir if (m_pMedium || !rURL.getLength()) 727*cdf0e10cSrcweir { 728*cdf0e10cSrcweir // Den Stream am Producer freigeben, bevor das Medium geloscht wird. 729*cdf0e10cSrcweir GetImageProducer()->SetImage(String()); 730*cdf0e10cSrcweir delete m_pMedium; 731*cdf0e10cSrcweir m_pMedium = NULL; 732*cdf0e10cSrcweir } 733*cdf0e10cSrcweir 734*cdf0e10cSrcweir // the SfxMedium is not allowed to be created with an invalid URL, so we have to check this first 735*cdf0e10cSrcweir // 23.01.2001 - 81927 - FS 736*cdf0e10cSrcweir INetURLObject aUrl(rURL); 737*cdf0e10cSrcweir if (INET_PROT_NOT_VALID == aUrl.GetProtocol()) 738*cdf0e10cSrcweir // we treat an invalid URL like we would treat no URL 739*cdf0e10cSrcweir return; 740*cdf0e10cSrcweir 741*cdf0e10cSrcweir if (rURL.getLength() && !::svt::GraphicAccess::isSupportedURL( rURL ) ) 742*cdf0e10cSrcweir { 743*cdf0e10cSrcweir if (m_pMedium) 744*cdf0e10cSrcweir delete m_pMedium; 745*cdf0e10cSrcweir 746*cdf0e10cSrcweir m_pMedium = new SfxMedium(rURL, STREAM_STD_READ, sal_False); 747*cdf0e10cSrcweir m_pMedium->SetDataAvailableLink( 748*cdf0e10cSrcweir STATIC_LINK(this, OClickableImageBaseModel, DataAvailableLink)); 749*cdf0e10cSrcweir 750*cdf0e10cSrcweir // Das XModel suchen, um an die Object-Shell oder zumindest den 751*cdf0e10cSrcweir // Referer zu gelangen. 752*cdf0e10cSrcweir // Das Model findet man allerdings nur beim Laden von HTML-Dokumenten 753*cdf0e10cSrcweir // und dann, wenn die URL in einem bereits geladenen Dokument 754*cdf0e10cSrcweir // geaendert wird. Waehrend des Ladens kommt man nicht an das 755*cdf0e10cSrcweir // Model ran. 756*cdf0e10cSrcweir Reference< XModel > xModel; 757*cdf0e10cSrcweir InterfaceRef xIfc( *this ); 758*cdf0e10cSrcweir while( !xModel.is() && xIfc.is() ) 759*cdf0e10cSrcweir { 760*cdf0e10cSrcweir Reference<XChild> xChild( xIfc, UNO_QUERY ); 761*cdf0e10cSrcweir xIfc = xChild->getParent(); 762*cdf0e10cSrcweir query_interface(xIfc, xModel); 763*cdf0e10cSrcweir } 764*cdf0e10cSrcweir 765*cdf0e10cSrcweir // Die Object-Shell suchen, indem wir 766*cdf0e10cSrcweir // ueber alle Object-Shells iterieren und deren XModel mit dem 767*cdf0e10cSrcweir // eigenen vergleichen. Als Optimierung probieren wir aber erstmal 768*cdf0e10cSrcweir // die aktuelle Object-Shell. 769*cdf0e10cSrcweir // wir unser XModel mit dem aller Object 770*cdf0e10cSrcweir SfxObjectShell *pObjSh = 0; 771*cdf0e10cSrcweir 772*cdf0e10cSrcweir if( xModel.is() ) 773*cdf0e10cSrcweir { 774*cdf0e10cSrcweir SfxObjectShell *pTestObjSh = SfxObjectShell::Current(); 775*cdf0e10cSrcweir if( pTestObjSh ) 776*cdf0e10cSrcweir { 777*cdf0e10cSrcweir Reference< XModel > xTestModel = pTestObjSh->GetModel(); 778*cdf0e10cSrcweir if( xTestModel == xModel ) 779*cdf0e10cSrcweir pObjSh = pTestObjSh; 780*cdf0e10cSrcweir } 781*cdf0e10cSrcweir if( !pObjSh ) 782*cdf0e10cSrcweir { 783*cdf0e10cSrcweir pTestObjSh = SfxObjectShell::GetFirst(); 784*cdf0e10cSrcweir while( !pObjSh && pTestObjSh ) 785*cdf0e10cSrcweir { 786*cdf0e10cSrcweir Reference< XModel > xTestModel = pTestObjSh->GetModel(); 787*cdf0e10cSrcweir if( xTestModel == xModel ) 788*cdf0e10cSrcweir pObjSh = pTestObjSh; 789*cdf0e10cSrcweir else 790*cdf0e10cSrcweir pTestObjSh = SfxObjectShell::GetNext( *pTestObjSh ); 791*cdf0e10cSrcweir } 792*cdf0e10cSrcweir } 793*cdf0e10cSrcweir } 794*cdf0e10cSrcweir 795*cdf0e10cSrcweir #ifdef USE_REGISTER_TRANSFER 796*cdf0e10cSrcweir if( pObjSh ) 797*cdf0e10cSrcweir { 798*cdf0e10cSrcweir // Medium registrieren, damit abgebrochen werden kann 799*cdf0e10cSrcweir pObjSh->RegisterTransfer( *m_pMedium ); 800*cdf0e10cSrcweir 801*cdf0e10cSrcweir // Target-Frame uebertragen, damit auch javascript:-URLs 802*cdf0e10cSrcweir // "geladen" werden koennen. 803*cdf0e10cSrcweir const SfxMedium *pShMedium = pObjSh->GetMedium(); 804*cdf0e10cSrcweir if( pShMedium ) 805*cdf0e10cSrcweir m_pMedium->SetLoadTargetFrame(pShMedium->GetLoadTargetFrame()); 806*cdf0e10cSrcweir } 807*cdf0e10cSrcweir else 808*cdf0e10cSrcweir { 809*cdf0e10cSrcweir // Keine Object-Shell, aber ein Medium? Dann uebernehmen wir 810*cdf0e10cSrcweir // zumindest den Referer. 811*cdf0e10cSrcweir if( xModel.is() ) 812*cdf0e10cSrcweir { 813*cdf0e10cSrcweir ::rtl::OUString sReferer( xModel->getURL() ); 814*cdf0e10cSrcweir if( sReferer.getLength() ) 815*cdf0e10cSrcweir m_pMedium->SetReferer( OUStringToString(sReferer, CHARSET_SYSTEM) ); 816*cdf0e10cSrcweir } 817*cdf0e10cSrcweir } 818*cdf0e10cSrcweir #else 819*cdf0e10cSrcweir if( pObjSh ) 820*cdf0e10cSrcweir { 821*cdf0e10cSrcweir // Target-Frame uebertragen, damit auch javascript:-URLs 822*cdf0e10cSrcweir // "geladen" werden koennen. 823*cdf0e10cSrcweir const SfxMedium *pShMedium = pObjSh->GetMedium(); 824*cdf0e10cSrcweir if( pShMedium ) 825*cdf0e10cSrcweir m_pMedium->SetLoadTargetFrame(pShMedium->GetLoadTargetFrame()); 826*cdf0e10cSrcweir } 827*cdf0e10cSrcweir 828*cdf0e10cSrcweir if( xModel.is() ) 829*cdf0e10cSrcweir { 830*cdf0e10cSrcweir ::rtl::OUString sReferer( xModel->getURL() ); 831*cdf0e10cSrcweir if( sReferer.getLength() ) 832*cdf0e10cSrcweir m_pMedium->SetReferer( sReferer ); 833*cdf0e10cSrcweir } 834*cdf0e10cSrcweir #endif 835*cdf0e10cSrcweir 836*cdf0e10cSrcweir // Downloading-Flag auf sal_True setzen. Es werden dann auch 837*cdf0e10cSrcweir // Data-Available-Links, wenn wir in den Pending-Staus gelangen. 838*cdf0e10cSrcweir m_bDownloading = sal_True; 839*cdf0e10cSrcweir m_bProdStarted = sal_False; 840*cdf0e10cSrcweir 841*cdf0e10cSrcweir // Download anstossen (Achtung: Kann auch synchron sein). 842*cdf0e10cSrcweir m_pMedium->DownLoad(STATIC_LINK(this, OClickableImageBaseModel, DownloadDoneLink)); 843*cdf0e10cSrcweir } 844*cdf0e10cSrcweir else 845*cdf0e10cSrcweir { 846*cdf0e10cSrcweir if ( ::svt::GraphicAccess::isSupportedURL( rURL ) ) 847*cdf0e10cSrcweir GetImageProducer()->SetImage( rURL ); 848*cdf0e10cSrcweir GetImageProducer()->startProduction(); 849*cdf0e10cSrcweir } 850*cdf0e10cSrcweir } 851*cdf0e10cSrcweir 852*cdf0e10cSrcweir //------------------------------------------------------------------------------ 853*cdf0e10cSrcweir void OClickableImageBaseModel::DataAvailable() 854*cdf0e10cSrcweir { 855*cdf0e10cSrcweir if (!m_bProdStarted) 856*cdf0e10cSrcweir StartProduction(); 857*cdf0e10cSrcweir 858*cdf0e10cSrcweir GetImageProducer()->NewDataAvailable(); 859*cdf0e10cSrcweir } 860*cdf0e10cSrcweir 861*cdf0e10cSrcweir //------------------------------------------------------------------------------ 862*cdf0e10cSrcweir void OClickableImageBaseModel::DownloadDone() 863*cdf0e10cSrcweir { 864*cdf0e10cSrcweir DataAvailable(); 865*cdf0e10cSrcweir m_bDownloading = sal_False; 866*cdf0e10cSrcweir } 867*cdf0e10cSrcweir 868*cdf0e10cSrcweir //------------------------------------------------------------------------------ 869*cdf0e10cSrcweir IMPL_STATIC_LINK( OClickableImageBaseModel, DownloadDoneLink, void*, EMPTYARG ) 870*cdf0e10cSrcweir { 871*cdf0e10cSrcweir ::osl::MutexGuard aGuard( pThis->m_aMutex ); 872*cdf0e10cSrcweir pThis->DownloadDone(); 873*cdf0e10cSrcweir return 0; 874*cdf0e10cSrcweir } 875*cdf0e10cSrcweir 876*cdf0e10cSrcweir //------------------------------------------------------------------------------ 877*cdf0e10cSrcweir IMPL_STATIC_LINK( OClickableImageBaseModel, DataAvailableLink, void*, EMPTYARG ) 878*cdf0e10cSrcweir { 879*cdf0e10cSrcweir ::osl::MutexGuard aGuard( pThis->m_aMutex ); 880*cdf0e10cSrcweir pThis->DataAvailable(); 881*cdf0e10cSrcweir return 0; 882*cdf0e10cSrcweir } 883*cdf0e10cSrcweir 884*cdf0e10cSrcweir //------------------------------------------------------------------------------ 885*cdf0e10cSrcweir void OClickableImageBaseModel::_propertyChanged( const PropertyChangeEvent& rEvt ) 886*cdf0e10cSrcweir throw( RuntimeException ) 887*cdf0e10cSrcweir { 888*cdf0e10cSrcweir // Wenn eine URL gesetzt worden ist, muss die noch an den ImageProducer 889*cdf0e10cSrcweir // weitergereicht werden. 890*cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 891*cdf0e10cSrcweir SetURL( getString(rEvt.NewValue) ); 892*cdf0e10cSrcweir } 893*cdf0e10cSrcweir 894*cdf0e10cSrcweir // ----------------------------------------------------------------------------- 895*cdf0e10cSrcweir Any OClickableImageBaseModel::getPropertyDefaultByHandle( sal_Int32 nHandle ) const 896*cdf0e10cSrcweir { 897*cdf0e10cSrcweir switch (nHandle) 898*cdf0e10cSrcweir { 899*cdf0e10cSrcweir case PROPERTY_ID_BUTTONTYPE : return makeAny( FormButtonType_PUSH ); 900*cdf0e10cSrcweir case PROPERTY_ID_TARGET_URL : 901*cdf0e10cSrcweir case PROPERTY_ID_TARGET_FRAME : return makeAny( ::rtl::OUString() ); 902*cdf0e10cSrcweir case PROPERTY_ID_DISPATCHURLINTERNAL : return makeAny( sal_False ); 903*cdf0e10cSrcweir default: 904*cdf0e10cSrcweir return OControlModel::getPropertyDefaultByHandle(nHandle); 905*cdf0e10cSrcweir } 906*cdf0e10cSrcweir } 907*cdf0e10cSrcweir 908*cdf0e10cSrcweir //================================================================== 909*cdf0e10cSrcweir // OImageProducerThread_Impl 910*cdf0e10cSrcweir //================================================================== 911*cdf0e10cSrcweir //------------------------------------------------------------------ 912*cdf0e10cSrcweir EventObject* OImageProducerThread_Impl::cloneEvent( const EventObject* _pEvt ) const 913*cdf0e10cSrcweir { 914*cdf0e10cSrcweir return new EventObject( *_pEvt ); 915*cdf0e10cSrcweir } 916*cdf0e10cSrcweir 917*cdf0e10cSrcweir //------------------------------------------------------------------ 918*cdf0e10cSrcweir void OImageProducerThread_Impl::processEvent( ::cppu::OComponentHelper *pCompImpl, 919*cdf0e10cSrcweir const EventObject* pEvt, 920*cdf0e10cSrcweir const Reference<XControl>&, 921*cdf0e10cSrcweir sal_Bool ) 922*cdf0e10cSrcweir { 923*cdf0e10cSrcweir ((OClickableImageBaseControl *)pCompImpl)->actionPerformed_Impl( sal_True, *(MouseEvent *)pEvt ); 924*cdf0e10cSrcweir } 925*cdf0e10cSrcweir 926*cdf0e10cSrcweir //......................................................................... 927*cdf0e10cSrcweir } // namespace frm 928*cdf0e10cSrcweir //......................................................................... 929*cdf0e10cSrcweir 930