/* -*- 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 .
*/
// char types could be used to store links to images if ( ( _nFieldType == DataType::CHAR )
|| ( _nFieldType == DataType::VARCHAR )
) return ImageStoreLink;
Any SAL_CALL OImageControlModel::queryAggregation(const Type& _rType)
{ // Order matters: we want to "override" the XImageProducer interface of the aggregate without // own XImageProducer interface, thus we need to query OImageControlModel_Base first
Any aReturn = OImageControlModel_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 = OBoundControlModel::queryAggregation( _rType );
case PROPERTY_ID_IMAGE_URL:
OSL_VERIFY( rValue >>= m_sImageURL );
impl_handleNewImageURL_lck( eOther );
{
ControlModelLock aLock( *this ); // that's a fake ... onValuePropertyChange expects to receive the only lock to our instance, // but we're already called with our mutex locked ...
onValuePropertyChange( aLock );
} break;
if ( m_bExternalGraphic )
{
m_sImageURL = OUString(); // TODO: speaking strictly, this would need to be notified, since ImageURL is a bound property. However, // this method here is called with a locked mutex, so we cannot simply call listeners ... // I think the missing notification (and thus clients which potentially cannot observe the change) // is less severe than the potential deadlock ...
}
} break;
void OImageControlModel::describeAggregateProperties( Sequence< Property >& /* [out] */ o_rAggregateProperties ) const
{
OBoundControlModel::describeAggregateProperties( o_rAggregateProperties ); // remove ImageURL and Graphic properties, we "override" them. // This is because our aggregate synchronizes those // two, but we have an own synchronization mechanism.
RemoveProperty( o_rAggregateProperties, PROPERTY_IMAGE_URL );
RemoveProperty( o_rAggregateProperties, PROPERTY_GRAPHIC );
}
OUString OImageControlModel::getServiceName()
{ return FRM_COMPONENT_IMAGECONTROL; // old (non-sun) name for compatibility !
}
void OImageControlModel::write(const Reference<XObjectOutputStream>& _rxOutStream)
{ // Base class
OBoundControlModel::write(_rxOutStream); // Version
_rxOutStream->writeShort(0x0003); // Name
_rxOutStream->writeBoolean(m_bReadOnly);
writeHelpTextCompatibly(_rxOutStream); // from version 0x0003 : common properties
writeCommonProperties(_rxOutStream);
}
// Version
sal_uInt16 nVersion = _rxInStream->readShort(); switch (nVersion)
{ case 0x0001:
m_bReadOnly = _rxInStream->readBoolean(); break; case 0x0002:
m_bReadOnly = _rxInStream->readBoolean();
readHelpTextCompatibly(_rxInStream); break; case 0x0003:
m_bReadOnly = _rxInStream->readBoolean();
readHelpTextCompatibly(_rxInStream);
readCommonProperties(_rxInStream); break; default :
OSL_FAIL("OImageControlModel::read : unknown version !");
m_bReadOnly = false;
defaultCommonProperties(); break;
} // Display default values after read if ( !getControlSource().isEmpty() )
{ // (not if we don't have a control source - the "State" property acts like it is persistent, then
::osl::MutexGuard aGuard(m_aMutex); // resetNoBroadcast expects this mutex guarding
resetNoBroadcast();
}
}
case ImageStoreLink:
{
OUString sCommitURL( m_sImageURL ); if ( !m_sDocumentURL.isEmpty() )
sCommitURL = URIHelper::simpleNormalizedMakeRelative( m_sDocumentURL, sCommitURL );
OSL_ENSURE( m_xColumnUpdate.is(), "OImageControlModel::impl_handleNewImageURL_lck: no bound field, but ImageStoreLink?!" ); if ( m_xColumnUpdate.is() )
{
m_xColumnUpdate->updateString( sCommitURL ); return;
}
} break;
case ImageStoreInvalid:
OSL_FAIL( "OImageControlModel::impl_handleNewImageURL_lck: image storage type type!" ); break;
}
// if we're here, then the above code was unable to update our field/control from the given URL // => fall back to NULL/VOID if ( m_xColumnUpdate.is() )
m_xColumnUpdate->updateNull(); else
setControlValue( Any(), _eInstigator );
}
bool OImageControlModel::commitControlValueToDbColumn( bool _bPostReset )
{ if ( _bPostReset )
{ // since this is a "commit after reset", we can simply update the column // with null - this is our "default" which we were just reset to if ( m_xColumnUpdate.is() )
m_xColumnUpdate->updateNull();
} else
{
::osl::MutexGuard aGuard(m_aMutex);
impl_handleNewImageURL_lck( eDbColumnBinding );
}
if ( bStartProduction )
{ // start production
rtl::Reference< ImageProducer > xProducer = m_xImageProducer;
{ // release our mutex once (it's acquired in the calling method!), as starting the image production may // result in the locking of the solar mutex (unfortunately the default implementation of our aggregate, // VCLXImageControl, does this locking)
MutexRelease aRelease(m_aMutex);
xProducer->startProduction();
}
}
}
void OImageControlModel::resetNoBroadcast()
{ if ( hasField() ) // only reset when we are connected to a column
OBoundControlModel::resetNoBroadcast( );
}
if ( sOldImageURL.isEmpty() ) // the ImageURL is already empty, so simply setting a new empty one would not suffice // (since it would be ignored)
xSet->setPropertyValue( PROPERTY_IMAGE_URL, Any( u"private:emptyImage"_ustr ) ); // (the concrete URL we're passing here doesn't matter. It's important that // the model cannot resolve it to a valid resource describing an image stream
}
// if the control is bound to a DB field, then it's not possible to decide whether or not to link
xController->enableControl(ExtendedFilePickerElementIds::CHECKBOX_LINK, !bHasField );
// if the control is bound to a DB field, then linking of the image depends on the type of the field bool bImageIsLinked = true; if ( bHasField )
{
sal_Int32 nFieldType = DataType::OTHER;
OSL_VERIFY( xBoundField->getPropertyValue( PROPERTY_FIELDTYPE ) >>= nFieldType );
bImageIsLinked = ( lcl_getImageStoreType( nFieldType ) == ImageStoreLink );
}
xController->setValue(ExtendedFilePickerElementIds::CHECKBOX_LINK, 0, Any( bImageIsLinked ) );
if ( ERRCODE_NONE == aDialog.Execute() )
{ // reset the url property in case it already has the value we're about to set - in this case // our propertyChanged would not get called without this.
implClearGraphics( false ); bool bIsLink = false;
xController->getValue(ExtendedFilePickerElementIds::CHECKBOX_LINK, 0) >>= bIsLink; // Force bIsLink to be sal_True if we're bound to a field. Though we initialized the file picker with IsLink=TRUE // in this case, and disabled the respective control, there might be picker implementations which do not // respect this, and return IsLink=FALSE here. In this case, "normalize" the flag. // #i112659#
bIsLink |= bHasField; if ( !bIsLink )
{
Graphic aGraphic;
aDialog.GetGraphic( aGraphic );
xSet->setPropertyValue( PROPERTY_GRAPHIC, Any( aGraphic.GetXGraphic() ) );
} else
xSet->setPropertyValue( PROPERTY_IMAGE_URL, Any( aDialog.GetPath() ) );
returntrue;
}
} catch(const Exception&)
{
TOOLS_WARN_EXCEPTION( "forms.component", "OImageControlControl::implInsertGraphics: caught an exception while attempting to execute the FilePicker!");
} returnfalse;
}
bool bModified = false; // is this a request for a context menu? if ( e.PopupTrigger )
{
Reference< XPopupMenu > xMenu( awt::PopupMenu::create( m_xContext ) );
DBG_ASSERT( xMenu.is(), "OImageControlControl::mousePressed: could not create a popup menu!" );
// check if the ImageURL is empty if ( impl_isEmptyGraphics_nothrow() )
xMenu->enableItem( ID_CLEAR_GRAPHICS, false );
awt::Rectangle aRect( e.X, e.Y, 0, 0 ); if ( ( e.X < 0 ) || ( e.Y < 0 ) )
{ // context menu triggered by keyboard // position it in the center of the control
Reference< XWindow > xWindow( static_cast< ::cppu::OWeakObject* >( this ), UNO_QUERY );
OSL_ENSURE( xWindow.is(), "OImageControlControl::mousePressed: me not a window? How this?" ); if ( xWindow.is() )
{
awt::Rectangle aPosSize = xWindow->getPosSize();
aRect.X = aPosSize.Width / 2;
aRect.Y = aPosSize.Height / 2;
}
}
Reference<XPropertySet> xSet(getModel(), UNO_QUERY); if (!xSet.is()) return;
// If the Control is not bound, do not display a dialog (because the to-be-sent URL would be invalid anyway)
Reference<XPropertySet> xBoundField; if (hasProperty(PROPERTY_BOUNDFIELD, xSet))
xBoundField.set(
xSet->getPropertyValue(PROPERTY_BOUNDFIELD),
css::uno::UNO_QUERY); if (!xBoundField.is())
{ // but only if our IMAGE_URL property is handled as if it is transient, which is equivalent to // an empty control source if ( !hasProperty(PROPERTY_CONTROLSOURCE, xSet) || !::comphelper::getString(xSet->getPropertyValue(PROPERTY_CONTROLSOURCE)).isEmpty() ) return;
}
bool bReadOnly = false;
xSet->getPropertyValue(PROPERTY_READONLY) >>= bReadOnly; if (bReadOnly) return;
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.