/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
::comphelper::OInterfaceIteratorHelper3 aIter( m_aApproveActionListeners ); while( !bCancelled && aIter.hasMoreElements() )
{ // Every approveAction method must be thread-safe! if( !aIter.next()->approveAction( aEvent ) )
bCancelled = true;
}
return !bCancelled;
}
// This method is also called from a thread and thus must be thread-safe. void OClickableImageBaseControl::actionPerformed_Impl(bool bNotifyListener, const MouseEvent& rEvt)
{ if( bNotifyListener )
{ if ( !approveAction() ) return;
}
// Whether the rest of the code is thread-safe, one can't tell. Therefore // we do most of the work on a locked solar mutex.
Reference<XPropertySet> xSet;
Reference< XInterface > xModelsParent;
FormButtonType eButtonType = FormButtonType_PUSH;
{
SolarMutexGuard aGuard;
// Get parent
Reference<XFormComponent> xComp(getModel(), UNO_QUERY); if (!xComp.is()) return;
xModelsParent = xComp->getParent(); if (!xModelsParent.is()) return;
// Which button type?
xSet.set(xComp, css::uno::UNO_QUERY); if ( !xSet.is() ) return;
xSet->getPropertyValue(PROPERTY_BUTTONTYPE) >>= eButtonType;
}
switch (eButtonType)
{ case FormButtonType_RESET:
{ // Reset methods must be thread-safe!
Reference<XReset> xReset(xModelsParent, UNO_QUERY); if (!xReset.is()) return;
xReset->reset();
} break;
case FormButtonType_SUBMIT:
{ // if some outer component can provide an interaction handler, use it
Reference< XInteractionHandler > xHandler( m_aFeatureInterception.queryDispatch( u"private:/InteractionHandler"_ustr ), UNO_QUERY ); try
{
implSubmit( rEvt, xHandler );
} catch( const Exception& )
{ // ignore
}
} break;
case FormButtonType_URL:
{
SolarMutexGuard aGuard;
Reference< XModel > xModel = getXModel(xModelsParent); if (!xModel.is()) return;
// Execute URL now
Reference< XController > xController = xModel->getCurrentController(); if (!xController.is()) return;
if (!aURL.Complete.isEmpty() && (LOCAL_URL_PREFIX == aURL.Complete[0]))
{ // FIXME: The URL contains a local URL only. Since the URLTransformer does not handle this case correctly // (it can't: it does not know the document URL), we have to take care for this ourself. // The real solution would be to not allow such relative URLs (there is a rule that at runtime, all // URLs have to be absolute), but for compatibility reasons this is no option. // The more as the user does not want to see a local URL as "file://<path>/<document>#mark" if it // could be "#mark" as well. // If we someday say that this hack (yes, it's kind of a hack) is not sustainable anymore, the complete // solution would be: // * recognize URLs consisting of a mark only while _reading_ the document // * for this, allow the INetURLObject (which at the moment is invoked when reading URLs) to // transform such mark-only URLs into correct absolute URLs // * at the UI, show only the mark // * !!! recognize every SAVEAS on the document, so the absolute URL can be adjusted. This seems // rather impossible !!!
aURL.Mark = aURL.Complete;
aURL.Complete = xModel->getURL();
aURL.Complete += aURL.Mark;
}
void OClickableImageBaseControl::implSubmit( const MouseEvent& _rEvent, const Reference< XInteractionHandler >& _rxHandler )
{ try
{ // allow the veto listeners to join the game
m_aSubmissionVetoListeners.notifyEach( &XSubmissionVetoListener::submitting, EventObject( *this ) );
// see whether there's an "submit interceptor" set at our model
Reference< submission::XSubmissionSupplier > xSubmissionSupp( getModel(), UNO_QUERY );
Reference< XSubmission > xSubmission; if ( xSubmissionSupp.is() )
xSubmission = xSubmissionSupp->getSubmission();
OClickableImageBaseModel::~OClickableImageBaseModel()
{ if (!OComponentHelper::rBHelper.bDisposed)
{
acquire();
dispose();
}
DBG_ASSERT(m_pMedium == nullptr, "OClickableImageBaseModel::~OClickableImageBaseModel : leaving a memory leak ..."); // This should be cleaned up at least in the dispose
Any SAL_CALL OClickableImageBaseModel::queryAggregation(const Type& _rType)
{ // order matters: // we definitely want to "override" the XImageProducer interface of our aggregate, // thus check OClickableImageBaseModel_Base (which provides this) first
Any aReturn = OClickableImageBaseModel_Base::queryInterface( _rType );
// BUT: _don't_ let it feel responsible for the XTypeProvider interface // (as this is implemented by our base class in the proper way) if ( _rType.equals( cppu::UnoType<XTypeProvider>::get() )
|| !aReturn.hasValue()
)
aReturn = OControlModel::queryAggregation( _rType );
void OClickableImageBaseModel::StartProduction()
{
ImageProducer *pImgProd = GetImageProducer(); // grab the ImageURL
OUString sURL;
getPropertyValue(u"ImageURL"_ustr) >>= sURL; if (!m_pMedium)
{ if ( ::svt::GraphicAccess::isSupportedURL( sURL ) )
pImgProd->SetImage( sURL ); else // caution: the medium may be NULL if somebody gave us an invalid URL to work with
pImgProd->SetImage(OUString()); return;
} if (m_pMedium->GetErrorCode()==ERRCODE_NONE)
{
SvStream* pStream = m_pMedium->GetInStream();
SfxObjectShell* OClickableImageBaseModel::GetObjectShell()
{ // Find the XModel to get to the Object shell or at least the // Referer. // There's only a Model if we load HTML documents and the URL is // changed in a document that is already loaded. There's no way // we can get to the Model during loading.
Reference< XModel > xModel;
css::uno::Reference<css::uno::XInterface> xIfc( *this ); while( !xModel.is() && xIfc.is() )
{
Reference<XChild> xChild( xIfc, UNO_QUERY );
xIfc = xChild->getParent();
xModel.set(xIfc, css::uno::UNO_QUERY);
}
// Search for the Object shell by iterating over all Object shells // and comparing their XModel to ours. // As an optimization, we try the current Object shell first.
SfxObjectShell *pObjSh = nullptr;
void OClickableImageBaseModel::SetURL( const OUString& rURL )
{ if (m_pMedium || rURL.isEmpty())
{ // Free the stream at the Producer, before the medium is deleted
GetImageProducer()->SetImage(OUString());
m_pMedium.reset();
}
// the SfxMedium is not allowed to be created with an invalid URL, so we have to check this first
INetURLObject aUrl(rURL); if (INetProtocol::NotValid == aUrl.GetProtocol() || aUrl.IsExoticProtocol()) // we treat an invalid URL like we would treat no URL return;
if( pObjSh )
{ // Transfer target frame, so that javascript: URLs // can also be "loaded" const SfxMedium *pShMedium = pObjSh->GetMedium(); if( pShMedium )
m_pMedium->SetLoadTargetFrame(pShMedium->GetLoadTargetFrame());
}
m_bProdStarted = false;
OUString referer;
getPropertyValue(u"Referer"_ustr) >>= referer; if (!SvtSecurityOptions::isUntrustedReferer(referer)) { // Kick off download (caution: can be synchronous).
m_pMedium->Download(LINK(this, OClickableImageBaseModel, DownloadDoneLink));
}
} else
{ if ( ::svt::GraphicAccess::isSupportedURL( rURL ) )
GetImageProducer()->SetImage( rURL );
GetImageProducer()->startProduction();
}
}
void OClickableImageBaseModel::DataAvailable()
{ if (!m_bProdStarted)
StartProduction();
void OClickableImageBaseModel::_propertyChanged( const PropertyChangeEvent& rEvt )
{ // If a URL was set, it needs to be passed onto the ImageProducer.
::osl::MutexGuard aGuard(m_aMutex);
SetURL( getString(rEvt.NewValue) );
}
Any OClickableImageBaseModel::getPropertyDefaultByHandle( sal_Int32 nHandle ) const
{ switch (nHandle)
{ case PROPERTY_ID_BUTTONTYPE : return Any( FormButtonType_PUSH ); case PROPERTY_ID_TARGET_URL : case PROPERTY_ID_TARGET_FRAME : return Any( OUString() ); case PROPERTY_ID_DISPATCHURLINTERNAL : return Any( false ); default: return OControlModel::getPropertyDefaultByHandle(nHandle);
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.