diff options
Diffstat (limited to 'forms/source/component/ImageControl.cxx')
-rw-r--r-- | forms/source/component/ImageControl.cxx | 177 |
1 files changed, 120 insertions, 57 deletions
diff --git a/forms/source/component/ImageControl.cxx b/forms/source/component/ImageControl.cxx index da88d6bc0..e9e2ce3e2 100644 --- a/forms/source/component/ImageControl.cxx +++ b/forms/source/component/ImageControl.cxx @@ -151,11 +151,14 @@ OImageControlModel::OImageControlModel(const Reference<XMultiServiceFactory>& _r :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_IMAGECONTROL, FRM_SUN_CONTROL_IMAGECONTROL, sal_False, sal_False, sal_False ) // use the old control name for compytibility reasons ,m_pImageProducer( NULL ) + ,m_bExternalGraphic( true ) ,m_bReadOnly( sal_False ) + ,m_sImageURL() + ,m_xGraphicObject() { DBG_CTOR( OImageControlModel, NULL ); m_nClassId = FormComponentType::IMAGECONTROL; - initValueProperty( PROPERTY_IMAGE_URL, PROPERTY_ID_IMAGE_URL); + initOwnValueProperty( PROPERTY_IMAGE_URL ); implConstruct(); } @@ -165,22 +168,20 @@ OImageControlModel::OImageControlModel( const OImageControlModel* _pOriginal, co :OBoundControlModel( _pOriginal, _rxFactory ) // use the old control name for compytibility reasons ,m_pImageProducer( NULL ) + ,m_bExternalGraphic( true ) + ,m_bReadOnly( _pOriginal->m_bReadOnly ) + ,m_sImageURL( _pOriginal->m_sImageURL ) + ,m_xGraphicObject( _pOriginal->m_xGraphicObject ) { DBG_CTOR( OImageControlModel, NULL ); implConstruct(); - m_bReadOnly = _pOriginal->m_bReadOnly; osl_incrementInterlockedCount( &m_refCount ); { // simulate a propertyChanged event for the ImageURL // 2003-05-15 - #109591# - fs@openoffice.org - Any aImageURL; - getFastPropertyValue( aImageURL, PROPERTY_ID_IMAGE_URL ); - ::rtl::OUString sImageURL; - aImageURL >>= sImageURL; - ::osl::MutexGuard aGuard( m_aMutex ); - impl_handleNewImageURL_lck( sImageURL, eOther ); + impl_handleNewImageURL_lck( eOther ); } osl_decrementInterlockedCount( &m_refCount ); } @@ -244,32 +245,20 @@ sal_Bool OImageControlModel::approveDbColumnType( sal_Int32 _nColumnType ) return ImageStoreInvalid != lcl_getImageStoreType( _nColumnType ); } - -//------------------------------------------------------------------------------ -void OImageControlModel::_propertyChanged( const PropertyChangeEvent& _rEvent ) - throw( RuntimeException ) -{ - if ( m_xColumnUpdate.is() ) - { - OBoundControlModel::_propertyChanged( _rEvent ); - } - else - { // we're not bound. In this case, we have to manually care for updating the - // image producer, since the base class will not do this - ::rtl::OUString sImageURL; - _rEvent.NewValue >>= sImageURL; - - ::osl::MutexGuard aGuard( m_aMutex ); - impl_handleNewImageURL_lck( sImageURL, eOther ); - } -} - //------------------------------------------------------------------------------ void OImageControlModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const { switch (nHandle) { - case PROPERTY_ID_READONLY : rValue <<= (sal_Bool)m_bReadOnly; break; + case PROPERTY_ID_READONLY: + rValue <<= (sal_Bool)m_bReadOnly; + break; + case PROPERTY_ID_IMAGE_URL: + rValue <<= m_sImageURL; + break; + case PROPERTY_ID_GRAPHIC: + rValue <<= m_xGraphicObject.is() ? m_xGraphicObject->getGraphic() : Reference< XGraphic >(); + break; default: OBoundControlModel::getFastPropertyValue(rValue, nHandle); } @@ -285,8 +274,51 @@ void OImageControlModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, con m_bReadOnly = getBOOL(rValue); break; + 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; + + case PROPERTY_ID_GRAPHIC: + { + Reference< XGraphic > xGraphic; + OSL_VERIFY( rValue >>= xGraphic ); + if ( !xGraphic.is() ) + m_xGraphicObject.clear(); + else + { + m_xGraphicObject = GraphicObject::create( m_aContext.getUNOContext() ); + m_xGraphicObject->setGraphic( xGraphic ); + } + + if ( m_bExternalGraphic ) + { + // if that's an external graphic, i.e. one which has not been loaded by ourselves in response to a + // new image URL, then also adjust our ImageURL. + ::rtl::OUString sNewImageURL; + if ( m_xGraphicObject.is() ) + { + sNewImageURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.GraphicObject:" ) ); + sNewImageURL = sNewImageURL + m_xGraphicObject->getUniqueID(); + } + m_sImageURL = sNewImageURL; + // 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; + default: OBoundControlModel::setFastPropertyValue_NoBroadcast(nHandle, rValue); + break; } } @@ -299,6 +331,15 @@ sal_Bool OImageControlModel::convertFastPropertyValue(Any& rConvertedValue, Any& case PROPERTY_ID_READONLY : return tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bReadOnly); + case PROPERTY_ID_IMAGE_URL: + return tryPropertyValue( rConvertedValue, rOldValue, rValue, m_sImageURL ); + + case PROPERTY_ID_GRAPHIC: + { + const Reference< XGraphic > xGraphic( getFastPropertyValue( PROPERTY_ID_GRAPHIC ), UNO_QUERY ); + return tryPropertyValue( rConvertedValue, rOldValue, rValue, xGraphic ); + } + default: return OBoundControlModel::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue); } @@ -307,13 +348,25 @@ sal_Bool OImageControlModel::convertFastPropertyValue(Any& rConvertedValue, Any& //------------------------------------------------------------------------------ void OImageControlModel::describeFixedProperties( Sequence< Property >& _rProps ) const { - BEGIN_DESCRIBE_PROPERTIES( 2, OBoundControlModel ) - DECL_BOOL_PROP1 ( READONLY, BOUND ); - DECL_PROP1 ( TABINDEX, sal_Int16, BOUND ); + BEGIN_DESCRIBE_PROPERTIES( 4, OBoundControlModel ) + DECL_IFACE_PROP2( GRAPHIC, XGraphic, BOUND, TRANSIENT ); + DECL_PROP1 ( IMAGE_URL, ::rtl::OUString, BOUND ); + DECL_BOOL_PROP1 ( READONLY, BOUND ); + DECL_PROP1 ( TABINDEX, sal_Int16, BOUND ); END_DESCRIBE_PROPERTIES(); } //------------------------------------------------------------------------------ +void OImageControlModel::describeAggregateProperties( Sequence< Property >& /* [out] */ o_rAggregateProperties ) const +{ + OBoundControlModel::describeAggregateProperties( o_rAggregateProperties ); + // remove ImageULR and Graphic properties, we "overload" them. This is because our aggregate synchronizes those + // two, but we have an own sychronization mechanism. + RemoveProperty( o_rAggregateProperties, PROPERTY_IMAGE_URL ); + RemoveProperty( o_rAggregateProperties, PROPERTY_GRAPHIC ); +} + +//------------------------------------------------------------------------------ ::rtl::OUString OImageControlModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException) { return FRM_COMPONENT_IMAGECONTROL; // old (non-sun) name for compatibility ! @@ -411,18 +464,18 @@ sal_Bool OImageControlModel::impl_updateStreamForURL_lck( const ::rtl::OUString& } //------------------------------------------------------------------------------ -sal_Bool OImageControlModel::impl_handleNewImageURL_lck( const ::rtl::OUString& _rURL, ValueChangeInstigator _eInstigator ) +sal_Bool OImageControlModel::impl_handleNewImageURL_lck( ValueChangeInstigator _eInstigator ) { switch ( lcl_getImageStoreType( getFieldType() ) ) { case ImageStoreBinary: - if ( impl_updateStreamForURL_lck( _rURL, _eInstigator ) ) + if ( impl_updateStreamForURL_lck( m_sImageURL, _eInstigator ) ) return sal_True; break; case ImageStoreLink: { - ::rtl::OUString sCommitURL( _rURL ); + ::rtl::OUString sCommitURL( m_sImageURL ); if ( m_sDocumentURL.getLength() ) sCommitURL = URIHelper::simpleNormalizedMakeRelative( m_sDocumentURL, sCommitURL ); OSL_ENSURE( m_xColumnUpdate.is(), "OImageControlModel::impl_handleNewImageURL_lck: no bound field, but ImageStoreLink?!" ); @@ -435,7 +488,7 @@ sal_Bool OImageControlModel::impl_handleNewImageURL_lck( const ::rtl::OUString& break; case ImageStoreInvalid: - OSL_ENSURE( false, "OImageControlModel::impl_handleNewImageURL_lck: invalid current field type!" ); + OSL_ENSURE( false, "OImageControlModel::impl_handleNewImageURL_lck: image storage type type!" ); break; } @@ -462,10 +515,7 @@ sal_Bool OImageControlModel::commitControlValueToDbColumn( bool _bPostReset ) else { ::osl::MutexGuard aGuard(m_aMutex); - - ::rtl::OUString sImageURL; - m_xAggregateSet->getPropertyValue( PROPERTY_IMAGE_URL ) >>= sImageURL; - return impl_handleNewImageURL_lck( sImageURL, eDbColumnBinding ); + return impl_handleNewImageURL_lck( eDbColumnBinding ); } return sal_True; @@ -523,7 +573,13 @@ Any OImageControlModel::translateDbColumnToControlValue() { switch ( lcl_getImageStoreType( getFieldType() ) ) { - case ImageStoreBinary: return makeAny( m_xColumn->getBinaryStream() ); + case ImageStoreBinary: + { + Reference< XInputStream > xImageStream( m_xColumn->getBinaryStream() ); + if ( m_xColumn->wasNull() ) + xImageStream.clear(); + return makeAny( xImageStream ); + } case ImageStoreLink: { ::rtl::OUString sImageLink( m_xColumn->getString() ); @@ -539,6 +595,12 @@ Any OImageControlModel::translateDbColumnToControlValue() } //------------------------------------------------------------------------------ +Any OImageControlModel::getControlValue( ) const +{ + return makeAny( m_sImageURL ); +} + +//------------------------------------------------------------------------------ void OImageControlModel::doSetControlValue( const Any& _rValue ) { DBG_ASSERT( GetImageProducer() && m_xImageProducer.is(), "OImageControlModel::doSetControlValue: no image producer!" ); @@ -593,11 +655,6 @@ void OImageControlModel::doSetControlValue( const Any& _rValue ) void SAL_CALL OImageControlModel::disposing() { OBoundControlModel::disposing(); - - { - ::osl::MutexGuard aGuard( m_aMutex ); // setControlValue expects this - setControlValue( Any(), eOther ); - } } //------------------------------------------------------------------------------ @@ -634,11 +691,17 @@ void SAL_CALL OImageControlModel::startProduction( ) throw (RuntimeException) //------------------------------------------------------------------------------ IMPL_LINK( OImageControlModel, OnImageImportDone, ::Graphic*, i_pGraphic ) { - ENSURE_OR_RETURN( i_pGraphic, "OImageControlModel::OnImageImportDone: illegal graphic!", 0L ); - setPropertyValue( - ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Graphic" ) ), - makeAny( Image( i_pGraphic->GetBitmapEx() ).GetXGraphic() ) - ); + const Reference< XGraphic > xGraphic( i_pGraphic != NULL ? Image( i_pGraphic->GetBitmapEx() ).GetXGraphic() : NULL ); + m_bExternalGraphic = false; + try + { + setPropertyValue( PROPERTY_GRAPHIC, makeAny( xGraphic ) ); + } + catch ( const Exception& ) + { + DBG_UNHANDLED_EXCEPTION(); + } + m_bExternalGraphic = true; return 1L; } @@ -794,16 +857,16 @@ bool OImageControlControl::implInsertGraphics() implClearGraphics( sal_False ); sal_Bool bIsLink = sal_False; xController->getValue(ExtendedFilePickerElementIds::CHECKBOX_LINK, 0) >>= bIsLink; + // Force bIsLink to be 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# / 2010-08-26 / frank.schoenheit@oracle.com + bIsLink |= bHasField; if ( !bIsLink ) { Graphic aGraphic; aDialog.GetGraphic( aGraphic ); - - Reference< graphic::XGraphicObject > xGrfObj = graphic::GraphicObject::create( m_aContext.getUNOContext() ); - xGrfObj->setGraphic( aGraphic.GetXGraphic() ); - rtl::OUString sObjectID( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.GraphicObject:" ) ); - sObjectID = sObjectID + xGrfObj->getUniqueID(); - xSet->setPropertyValue( PROPERTY_IMAGE_URL, makeAny( ::rtl::OUString( sObjectID ) ) ); + xSet->setPropertyValue( PROPERTY_GRAPHIC, makeAny( aGraphic.GetXGraphic() ) ); } else xSet->setPropertyValue( PROPERTY_IMAGE_URL, makeAny( ::rtl::OUString( aDialog.GetPath() ) ) ); |