1*24acc546SAndrew Rist /************************************************************** 2cdf0e10cSrcweir * 3*24acc546SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one 4*24acc546SAndrew Rist * or more contributor license agreements. See the NOTICE file 5*24acc546SAndrew Rist * distributed with this work for additional information 6*24acc546SAndrew Rist * regarding copyright ownership. The ASF licenses this file 7*24acc546SAndrew Rist * to you under the Apache License, Version 2.0 (the 8*24acc546SAndrew Rist * "License"); you may not use this file except in compliance 9*24acc546SAndrew Rist * with the License. You may obtain a copy of the License at 10*24acc546SAndrew Rist * 11*24acc546SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*24acc546SAndrew Rist * 13*24acc546SAndrew Rist * Unless required by applicable law or agreed to in writing, 14*24acc546SAndrew Rist * software distributed under the License is distributed on an 15*24acc546SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16*24acc546SAndrew Rist * KIND, either express or implied. See the License for the 17*24acc546SAndrew Rist * specific language governing permissions and limitations 18*24acc546SAndrew Rist * under the License. 19*24acc546SAndrew Rist * 20*24acc546SAndrew Rist *************************************************************/ 21*24acc546SAndrew Rist 22*24acc546SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_forms.hxx" 26cdf0e10cSrcweir #include "ImageControl.hxx" 27cdf0e10cSrcweir 28cdf0e10cSrcweir #include "property.hrc" 29cdf0e10cSrcweir #include "frm_resource.hrc" 30cdf0e10cSrcweir #include "frm_resource.hxx" 31cdf0e10cSrcweir #include "services.hxx" 32cdf0e10cSrcweir #include "componenttools.hxx" 33cdf0e10cSrcweir 34cdf0e10cSrcweir #include <svtools/imageresourceaccess.hxx> 35cdf0e10cSrcweir #include <unotools/ucblockbytes.hxx> 36cdf0e10cSrcweir #include <sfx2/filedlghelper.hxx> 37cdf0e10cSrcweir #include <com/sun/star/awt/XPopupMenu.hpp> 38cdf0e10cSrcweir #include <com/sun/star/awt/PopupMenuDirection.hpp> 39cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> 40cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExtendedFilePickerElementIds.hpp> 41cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePickerControlAccess.hpp> 42cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePicker.hpp> 43cdf0e10cSrcweir #include <com/sun/star/sdbc/DataType.hpp> 44cdf0e10cSrcweir #include <com/sun/star/awt/MouseButton.hpp> 45cdf0e10cSrcweir #include <com/sun/star/awt/XWindow.hpp> 46cdf0e10cSrcweir #include <com/sun/star/awt/XDialog.hpp> 47cdf0e10cSrcweir #include <com/sun/star/io/XActiveDataSink.hpp> 48cdf0e10cSrcweir #include <com/sun/star/io/NotConnectedException.hpp> 49cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp> 50cdf0e10cSrcweir #include <com/sun/star/graphic/XGraphic.hpp> 51cdf0e10cSrcweir #include <com/sun/star/graphic/GraphicObject.hpp> 52cdf0e10cSrcweir #include <tools/urlobj.hxx> 53cdf0e10cSrcweir #include <tools/stream.hxx> 54cdf0e10cSrcweir #include <tools/debug.hxx> 55cdf0e10cSrcweir #include <tools/diagnose_ex.h> 56cdf0e10cSrcweir #include <vcl/svapp.hxx> 57cdf0e10cSrcweir #include <unotools/streamhelper.hxx> 58cdf0e10cSrcweir #include <comphelper/extract.hxx> 59cdf0e10cSrcweir #include <comphelper/guarding.hxx> 60cdf0e10cSrcweir #include <unotools/ucbstreamhelper.hxx> 61cdf0e10cSrcweir #include <svl/urihelper.hxx> 62cdf0e10cSrcweir 63cdf0e10cSrcweir #include <memory> 64cdf0e10cSrcweir 65cdf0e10cSrcweir #define ID_OPEN_GRAPHICS 1 66cdf0e10cSrcweir #define ID_CLEAR_GRAPHICS 2 67cdf0e10cSrcweir 68cdf0e10cSrcweir //......................................................................... 69cdf0e10cSrcweir namespace frm 70cdf0e10cSrcweir { 71cdf0e10cSrcweir //......................................................................... 72cdf0e10cSrcweir using namespace ::com::sun::star; 73cdf0e10cSrcweir using namespace ::com::sun::star::uno; 74cdf0e10cSrcweir using namespace ::com::sun::star::sdb; 75cdf0e10cSrcweir using namespace ::com::sun::star::sdbc; 76cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx; 77cdf0e10cSrcweir using namespace ::com::sun::star::beans; 78cdf0e10cSrcweir using namespace ::com::sun::star::container; 79cdf0e10cSrcweir using namespace ::com::sun::star::form; 80cdf0e10cSrcweir using namespace ::com::sun::star::awt; 81cdf0e10cSrcweir using namespace ::com::sun::star::io; 82cdf0e10cSrcweir using namespace ::com::sun::star::ui::dialogs; 83cdf0e10cSrcweir using namespace ::com::sun::star::lang; 84cdf0e10cSrcweir using namespace ::com::sun::star::util; 85cdf0e10cSrcweir using namespace ::com::sun::star::graphic; 86cdf0e10cSrcweir using namespace ::com::sun::star::frame; 87cdf0e10cSrcweir 88cdf0e10cSrcweir //============================================================================== 89cdf0e10cSrcweir //= OImageControlModel 90cdf0e10cSrcweir //============================================================================== 91cdf0e10cSrcweir namespace 92cdf0e10cSrcweir { 93cdf0e10cSrcweir enum ImageStoreType 94cdf0e10cSrcweir { 95cdf0e10cSrcweir ImageStoreBinary, 96cdf0e10cSrcweir ImageStoreLink, 97cdf0e10cSrcweir 98cdf0e10cSrcweir ImageStoreInvalid 99cdf0e10cSrcweir }; 100cdf0e10cSrcweir 101cdf0e10cSrcweir ImageStoreType lcl_getImageStoreType( const sal_Int32 _nFieldType ) 102cdf0e10cSrcweir { 103cdf0e10cSrcweir // binary/longvarchar types could be used to store images in binary representation 104cdf0e10cSrcweir if ( ( _nFieldType == DataType::BINARY ) 105cdf0e10cSrcweir || ( _nFieldType == DataType::VARBINARY ) 106cdf0e10cSrcweir || ( _nFieldType == DataType::LONGVARBINARY ) 107cdf0e10cSrcweir || ( _nFieldType == DataType::OTHER ) 108cdf0e10cSrcweir || ( _nFieldType == DataType::OBJECT ) 109cdf0e10cSrcweir || ( _nFieldType == DataType::BLOB ) 110cdf0e10cSrcweir || ( _nFieldType == DataType::LONGVARCHAR ) 111cdf0e10cSrcweir || ( _nFieldType == DataType::CLOB ) 112cdf0e10cSrcweir ) 113cdf0e10cSrcweir return ImageStoreBinary; 114cdf0e10cSrcweir 115cdf0e10cSrcweir // char types could be used to store links to images 116cdf0e10cSrcweir if ( ( _nFieldType == DataType::CHAR ) 117cdf0e10cSrcweir || ( _nFieldType == DataType::VARCHAR ) 118cdf0e10cSrcweir ) 119cdf0e10cSrcweir return ImageStoreLink; 120cdf0e10cSrcweir 121cdf0e10cSrcweir return ImageStoreInvalid; 122cdf0e10cSrcweir } 123cdf0e10cSrcweir } 124cdf0e10cSrcweir 125cdf0e10cSrcweir //============================================================================== 126cdf0e10cSrcweir // OImageControlModel 127cdf0e10cSrcweir //============================================================================== 128cdf0e10cSrcweir 129cdf0e10cSrcweir //------------------------------------------------------------------------------ 130cdf0e10cSrcweir InterfaceRef SAL_CALL OImageControlModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) 131cdf0e10cSrcweir { 132cdf0e10cSrcweir return *(new OImageControlModel(_rxFactory)); 133cdf0e10cSrcweir } 134cdf0e10cSrcweir 135cdf0e10cSrcweir //------------------------------------------------------------------------------ 136cdf0e10cSrcweir Sequence<Type> OImageControlModel::_getTypes() 137cdf0e10cSrcweir { 138cdf0e10cSrcweir return concatSequences( 139cdf0e10cSrcweir OBoundControlModel::_getTypes(), 140cdf0e10cSrcweir OImageControlModel_Base::getTypes() 141cdf0e10cSrcweir ); 142cdf0e10cSrcweir } 143cdf0e10cSrcweir 144cdf0e10cSrcweir DBG_NAME(OImageControlModel) 145cdf0e10cSrcweir //------------------------------------------------------------------ 146cdf0e10cSrcweir OImageControlModel::OImageControlModel(const Reference<XMultiServiceFactory>& _rxFactory) 147cdf0e10cSrcweir :OBoundControlModel( _rxFactory, VCL_CONTROLMODEL_IMAGECONTROL, FRM_SUN_CONTROL_IMAGECONTROL, sal_False, sal_False, sal_False ) 148cdf0e10cSrcweir // use the old control name for compytibility reasons 149cdf0e10cSrcweir ,m_pImageProducer( NULL ) 150cdf0e10cSrcweir ,m_bExternalGraphic( true ) 151cdf0e10cSrcweir ,m_bReadOnly( sal_False ) 152cdf0e10cSrcweir ,m_sImageURL() 153cdf0e10cSrcweir ,m_xGraphicObject() 154cdf0e10cSrcweir { 155cdf0e10cSrcweir DBG_CTOR( OImageControlModel, NULL ); 156cdf0e10cSrcweir m_nClassId = FormComponentType::IMAGECONTROL; 157cdf0e10cSrcweir initOwnValueProperty( PROPERTY_IMAGE_URL ); 158cdf0e10cSrcweir 159cdf0e10cSrcweir implConstruct(); 160cdf0e10cSrcweir } 161cdf0e10cSrcweir 162cdf0e10cSrcweir //------------------------------------------------------------------ 163cdf0e10cSrcweir OImageControlModel::OImageControlModel( const OImageControlModel* _pOriginal, const Reference< XMultiServiceFactory >& _rxFactory ) 164cdf0e10cSrcweir :OBoundControlModel( _pOriginal, _rxFactory ) 165cdf0e10cSrcweir // use the old control name for compytibility reasons 166cdf0e10cSrcweir ,m_pImageProducer( NULL ) 167cdf0e10cSrcweir ,m_bExternalGraphic( true ) 168cdf0e10cSrcweir ,m_bReadOnly( _pOriginal->m_bReadOnly ) 169cdf0e10cSrcweir ,m_sImageURL( _pOriginal->m_sImageURL ) 170cdf0e10cSrcweir ,m_xGraphicObject( _pOriginal->m_xGraphicObject ) 171cdf0e10cSrcweir { 172cdf0e10cSrcweir DBG_CTOR( OImageControlModel, NULL ); 173cdf0e10cSrcweir implConstruct(); 174cdf0e10cSrcweir 175cdf0e10cSrcweir osl_incrementInterlockedCount( &m_refCount ); 176cdf0e10cSrcweir { 177cdf0e10cSrcweir // simulate a propertyChanged event for the ImageURL 178cdf0e10cSrcweir // 2003-05-15 - #109591# - fs@openoffice.org 179cdf0e10cSrcweir ::osl::MutexGuard aGuard( m_aMutex ); 180cdf0e10cSrcweir impl_handleNewImageURL_lck( eOther ); 181cdf0e10cSrcweir } 182cdf0e10cSrcweir osl_decrementInterlockedCount( &m_refCount ); 183cdf0e10cSrcweir } 184cdf0e10cSrcweir 185cdf0e10cSrcweir //------------------------------------------------------------------ 186cdf0e10cSrcweir void OImageControlModel::implConstruct() 187cdf0e10cSrcweir { 188cdf0e10cSrcweir m_pImageProducer = new ImageProducer; 189cdf0e10cSrcweir m_xImageProducer = m_pImageProducer; 190cdf0e10cSrcweir m_pImageProducer->SetDoneHdl( LINK( this, OImageControlModel, OnImageImportDone ) ); 191cdf0e10cSrcweir } 192cdf0e10cSrcweir 193cdf0e10cSrcweir //------------------------------------------------------------------ 194cdf0e10cSrcweir OImageControlModel::~OImageControlModel() 195cdf0e10cSrcweir { 196cdf0e10cSrcweir if (!OComponentHelper::rBHelper.bDisposed) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir acquire(); 199cdf0e10cSrcweir dispose(); 200cdf0e10cSrcweir } 201cdf0e10cSrcweir 202cdf0e10cSrcweir DBG_DTOR(OImageControlModel,NULL); 203cdf0e10cSrcweir } 204cdf0e10cSrcweir 205cdf0e10cSrcweir // XCloneable 206cdf0e10cSrcweir //------------------------------------------------------------------------------ 207cdf0e10cSrcweir IMPLEMENT_DEFAULT_CLONING( OImageControlModel ) 208cdf0e10cSrcweir 209cdf0e10cSrcweir // XServiceInfo 210cdf0e10cSrcweir //------------------------------------------------------------------------------ 211cdf0e10cSrcweir StringSequence OImageControlModel::getSupportedServiceNames() throw() 212cdf0e10cSrcweir { 213cdf0e10cSrcweir StringSequence aSupported = OBoundControlModel::getSupportedServiceNames(); 214cdf0e10cSrcweir aSupported.realloc(aSupported.getLength() + 1); 215cdf0e10cSrcweir 216cdf0e10cSrcweir ::rtl::OUString*pArray = aSupported.getArray(); 217cdf0e10cSrcweir pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_IMAGECONTROL; 218cdf0e10cSrcweir return aSupported; 219cdf0e10cSrcweir } 220cdf0e10cSrcweir 221cdf0e10cSrcweir //------------------------------------------------------------------------------ 222cdf0e10cSrcweir Any SAL_CALL OImageControlModel::queryAggregation(const Type& _rType) throw (RuntimeException) 223cdf0e10cSrcweir { 224cdf0e10cSrcweir // oder matters: we want to "override" the XImageProducer interface of the aggreate with out 225cdf0e10cSrcweir // own XImageProducer interface, thus we need to query OImageControlModel_Base first 226cdf0e10cSrcweir Any aReturn = OImageControlModel_Base::queryInterface( _rType ); 227cdf0e10cSrcweir 228cdf0e10cSrcweir // BUT: _don't_ let it feel responsible for the XTypeProvider interface 229cdf0e10cSrcweir // (as this is implemented by our base class in the proper way) 230cdf0e10cSrcweir if ( _rType.equals( ::getCppuType( static_cast< Reference< XTypeProvider >* >( NULL ) ) ) 231cdf0e10cSrcweir || !aReturn.hasValue() 232cdf0e10cSrcweir ) 233cdf0e10cSrcweir aReturn = OBoundControlModel::queryAggregation( _rType ); 234cdf0e10cSrcweir 235cdf0e10cSrcweir return aReturn; 236cdf0e10cSrcweir } 237cdf0e10cSrcweir 238cdf0e10cSrcweir //------------------------------------------------------------------------------ 239cdf0e10cSrcweir sal_Bool OImageControlModel::approveDbColumnType( sal_Int32 _nColumnType ) 240cdf0e10cSrcweir { 241cdf0e10cSrcweir return ImageStoreInvalid != lcl_getImageStoreType( _nColumnType ); 242cdf0e10cSrcweir } 243cdf0e10cSrcweir 244cdf0e10cSrcweir //------------------------------------------------------------------------------ 245cdf0e10cSrcweir void OImageControlModel::getFastPropertyValue(Any& rValue, sal_Int32 nHandle) const 246cdf0e10cSrcweir { 247cdf0e10cSrcweir switch (nHandle) 248cdf0e10cSrcweir { 249cdf0e10cSrcweir case PROPERTY_ID_READONLY: 250cdf0e10cSrcweir rValue <<= (sal_Bool)m_bReadOnly; 251cdf0e10cSrcweir break; 252cdf0e10cSrcweir case PROPERTY_ID_IMAGE_URL: 253cdf0e10cSrcweir rValue <<= m_sImageURL; 254cdf0e10cSrcweir break; 255cdf0e10cSrcweir case PROPERTY_ID_GRAPHIC: 256cdf0e10cSrcweir rValue <<= m_xGraphicObject.is() ? m_xGraphicObject->getGraphic() : Reference< XGraphic >(); 257cdf0e10cSrcweir break; 258cdf0e10cSrcweir default: 259cdf0e10cSrcweir OBoundControlModel::getFastPropertyValue(rValue, nHandle); 260cdf0e10cSrcweir } 261cdf0e10cSrcweir } 262cdf0e10cSrcweir 263cdf0e10cSrcweir //------------------------------------------------------------------------------ 264cdf0e10cSrcweir void OImageControlModel::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, const Any& rValue) throw ( ::com::sun::star::uno::Exception) 265cdf0e10cSrcweir { 266cdf0e10cSrcweir switch (nHandle) 267cdf0e10cSrcweir { 268cdf0e10cSrcweir case PROPERTY_ID_READONLY : 269cdf0e10cSrcweir DBG_ASSERT(rValue.getValueType().getTypeClass() == TypeClass_BOOLEAN, "OImageControlModel::setFastPropertyValue_NoBroadcast : invalid type !" ); 270cdf0e10cSrcweir m_bReadOnly = getBOOL(rValue); 271cdf0e10cSrcweir break; 272cdf0e10cSrcweir 273cdf0e10cSrcweir case PROPERTY_ID_IMAGE_URL: 274cdf0e10cSrcweir OSL_VERIFY( rValue >>= m_sImageURL ); 275cdf0e10cSrcweir impl_handleNewImageURL_lck( eOther ); 276cdf0e10cSrcweir { 277cdf0e10cSrcweir ControlModelLock aLock( *this ); 278cdf0e10cSrcweir // that's a fake ... onValuePropertyChange expects to receive the only lock to our instance, 279cdf0e10cSrcweir // but we're already called with our mutex locked ... 280cdf0e10cSrcweir onValuePropertyChange( aLock ); 281cdf0e10cSrcweir } 282cdf0e10cSrcweir break; 283cdf0e10cSrcweir 284cdf0e10cSrcweir case PROPERTY_ID_GRAPHIC: 285cdf0e10cSrcweir { 286cdf0e10cSrcweir Reference< XGraphic > xGraphic; 287cdf0e10cSrcweir OSL_VERIFY( rValue >>= xGraphic ); 288cdf0e10cSrcweir if ( !xGraphic.is() ) 289cdf0e10cSrcweir m_xGraphicObject.clear(); 290cdf0e10cSrcweir else 291cdf0e10cSrcweir { 292cdf0e10cSrcweir m_xGraphicObject = GraphicObject::create( m_aContext.getUNOContext() ); 293cdf0e10cSrcweir m_xGraphicObject->setGraphic( xGraphic ); 294cdf0e10cSrcweir } 295cdf0e10cSrcweir 296cdf0e10cSrcweir if ( m_bExternalGraphic ) 297cdf0e10cSrcweir { 298cdf0e10cSrcweir // if that's an external graphic, i.e. one which has not been loaded by ourselves in response to a 299cdf0e10cSrcweir // new image URL, then also adjust our ImageURL. 300cdf0e10cSrcweir ::rtl::OUString sNewImageURL; 301cdf0e10cSrcweir if ( m_xGraphicObject.is() ) 302cdf0e10cSrcweir { 303cdf0e10cSrcweir sNewImageURL = ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "vnd.sun.star.GraphicObject:" ) ); 304cdf0e10cSrcweir sNewImageURL = sNewImageURL + m_xGraphicObject->getUniqueID(); 305cdf0e10cSrcweir } 306cdf0e10cSrcweir m_sImageURL = sNewImageURL; 307cdf0e10cSrcweir // TODO: speaking strictly, this would need to be notified, since ImageURL is a bound property. However, 308cdf0e10cSrcweir // this method here is called with a locked mutex, so we cannot simply call listeners ... 309cdf0e10cSrcweir // I think the missing notification (and thus clients which potentially cannot observe the change) 310cdf0e10cSrcweir // is less severe than the potential deadlock ... 311cdf0e10cSrcweir } 312cdf0e10cSrcweir } 313cdf0e10cSrcweir break; 314cdf0e10cSrcweir 315cdf0e10cSrcweir default: 316cdf0e10cSrcweir OBoundControlModel::setFastPropertyValue_NoBroadcast(nHandle, rValue); 317cdf0e10cSrcweir break; 318cdf0e10cSrcweir } 319cdf0e10cSrcweir } 320cdf0e10cSrcweir 321cdf0e10cSrcweir //------------------------------------------------------------------------------ 322cdf0e10cSrcweir sal_Bool OImageControlModel::convertFastPropertyValue(Any& rConvertedValue, Any& rOldValue, sal_Int32 nHandle, const Any& rValue) 323cdf0e10cSrcweir throw( IllegalArgumentException ) 324cdf0e10cSrcweir { 325cdf0e10cSrcweir switch (nHandle) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir case PROPERTY_ID_READONLY : 328cdf0e10cSrcweir return tryPropertyValue(rConvertedValue, rOldValue, rValue, m_bReadOnly); 329cdf0e10cSrcweir 330cdf0e10cSrcweir case PROPERTY_ID_IMAGE_URL: 331cdf0e10cSrcweir return tryPropertyValue( rConvertedValue, rOldValue, rValue, m_sImageURL ); 332cdf0e10cSrcweir 333cdf0e10cSrcweir case PROPERTY_ID_GRAPHIC: 334cdf0e10cSrcweir { 335cdf0e10cSrcweir const Reference< XGraphic > xGraphic( getFastPropertyValue( PROPERTY_ID_GRAPHIC ), UNO_QUERY ); 336cdf0e10cSrcweir return tryPropertyValue( rConvertedValue, rOldValue, rValue, xGraphic ); 337cdf0e10cSrcweir } 338cdf0e10cSrcweir 339cdf0e10cSrcweir default: 340cdf0e10cSrcweir return OBoundControlModel::convertFastPropertyValue(rConvertedValue, rOldValue, nHandle, rValue); 341cdf0e10cSrcweir } 342cdf0e10cSrcweir } 343cdf0e10cSrcweir 344cdf0e10cSrcweir //------------------------------------------------------------------------------ 345cdf0e10cSrcweir void OImageControlModel::describeFixedProperties( Sequence< Property >& _rProps ) const 346cdf0e10cSrcweir { 347cdf0e10cSrcweir BEGIN_DESCRIBE_PROPERTIES( 4, OBoundControlModel ) 348cdf0e10cSrcweir DECL_IFACE_PROP2( GRAPHIC, XGraphic, BOUND, TRANSIENT ); 349cdf0e10cSrcweir DECL_PROP1 ( IMAGE_URL, ::rtl::OUString, BOUND ); 350cdf0e10cSrcweir DECL_BOOL_PROP1 ( READONLY, BOUND ); 351cdf0e10cSrcweir DECL_PROP1 ( TABINDEX, sal_Int16, BOUND ); 352cdf0e10cSrcweir END_DESCRIBE_PROPERTIES(); 353cdf0e10cSrcweir } 354cdf0e10cSrcweir 355cdf0e10cSrcweir //------------------------------------------------------------------------------ 356cdf0e10cSrcweir void OImageControlModel::describeAggregateProperties( Sequence< Property >& /* [out] */ o_rAggregateProperties ) const 357cdf0e10cSrcweir { 358cdf0e10cSrcweir OBoundControlModel::describeAggregateProperties( o_rAggregateProperties ); 359cdf0e10cSrcweir // remove ImageULR and Graphic properties, we "overload" them. This is because our aggregate synchronizes those 360cdf0e10cSrcweir // two, but we have an own sychronization mechanism. 361cdf0e10cSrcweir RemoveProperty( o_rAggregateProperties, PROPERTY_IMAGE_URL ); 362cdf0e10cSrcweir RemoveProperty( o_rAggregateProperties, PROPERTY_GRAPHIC ); 363cdf0e10cSrcweir } 364cdf0e10cSrcweir 365cdf0e10cSrcweir //------------------------------------------------------------------------------ 366cdf0e10cSrcweir ::rtl::OUString OImageControlModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException) 367cdf0e10cSrcweir { 368cdf0e10cSrcweir return FRM_COMPONENT_IMAGECONTROL; // old (non-sun) name for compatibility ! 369cdf0e10cSrcweir } 370cdf0e10cSrcweir 371cdf0e10cSrcweir //------------------------------------------------------------------------------ 372cdf0e10cSrcweir void OImageControlModel::write(const Reference<XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 373cdf0e10cSrcweir { 374cdf0e10cSrcweir // Basisklasse 375cdf0e10cSrcweir OBoundControlModel::write(_rxOutStream); 376cdf0e10cSrcweir // Version 377cdf0e10cSrcweir _rxOutStream->writeShort(0x0003); 378cdf0e10cSrcweir // Name 379cdf0e10cSrcweir _rxOutStream->writeBoolean(m_bReadOnly); 380cdf0e10cSrcweir writeHelpTextCompatibly(_rxOutStream); 381cdf0e10cSrcweir // from version 0x0003 : common properties 382cdf0e10cSrcweir writeCommonProperties(_rxOutStream); 383cdf0e10cSrcweir } 384cdf0e10cSrcweir 385cdf0e10cSrcweir //------------------------------------------------------------------------------ 386cdf0e10cSrcweir void OImageControlModel::read(const Reference<XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException) 387cdf0e10cSrcweir { 388cdf0e10cSrcweir OBoundControlModel::read(_rxInStream); 389cdf0e10cSrcweir 390cdf0e10cSrcweir // Version 391cdf0e10cSrcweir sal_uInt16 nVersion = _rxInStream->readShort(); 392cdf0e10cSrcweir switch (nVersion) 393cdf0e10cSrcweir { 394cdf0e10cSrcweir case 0x0001: 395cdf0e10cSrcweir m_bReadOnly = _rxInStream->readBoolean(); 396cdf0e10cSrcweir break; 397cdf0e10cSrcweir case 0x0002: 398cdf0e10cSrcweir m_bReadOnly = _rxInStream->readBoolean(); 399cdf0e10cSrcweir readHelpTextCompatibly(_rxInStream); 400cdf0e10cSrcweir break; 401cdf0e10cSrcweir case 0x0003: 402cdf0e10cSrcweir m_bReadOnly = _rxInStream->readBoolean(); 403cdf0e10cSrcweir readHelpTextCompatibly(_rxInStream); 404cdf0e10cSrcweir readCommonProperties(_rxInStream); 405cdf0e10cSrcweir break; 406cdf0e10cSrcweir default : 407cdf0e10cSrcweir DBG_ERROR("OImageControlModel::read : unknown version !"); 408cdf0e10cSrcweir m_bReadOnly = sal_False; 409cdf0e10cSrcweir defaultCommonProperties(); 410cdf0e10cSrcweir break; 411cdf0e10cSrcweir } 412cdf0e10cSrcweir // Nach dem Lesen die Defaultwerte anzeigen 413cdf0e10cSrcweir if ( getControlSource().getLength() ) 414cdf0e10cSrcweir { // (not if we don't have a control source - the "State" property acts like it is persistent, then 415cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); // resetNoBroadcast expects this mutex guarding 416cdf0e10cSrcweir resetNoBroadcast(); 417cdf0e10cSrcweir } 418cdf0e10cSrcweir } 419cdf0e10cSrcweir 420cdf0e10cSrcweir //------------------------------------------------------------------------------ 421cdf0e10cSrcweir sal_Bool OImageControlModel::impl_updateStreamForURL_lck( const ::rtl::OUString& _rURL, ValueChangeInstigator _eInstigator ) 422cdf0e10cSrcweir { 423cdf0e10cSrcweir // create a stream for the image specified by the URL 424cdf0e10cSrcweir ::std::auto_ptr< SvStream > pImageStream; 425cdf0e10cSrcweir Reference< XInputStream > xImageStream; 426cdf0e10cSrcweir 427cdf0e10cSrcweir if ( ::svt::GraphicAccess::isSupportedURL( _rURL ) ) 428cdf0e10cSrcweir { 429cdf0e10cSrcweir xImageStream = ::svt::GraphicAccess::getImageXStream( getContext().getLegacyServiceFactory(), _rURL ); 430cdf0e10cSrcweir } 431cdf0e10cSrcweir else 432cdf0e10cSrcweir { 433cdf0e10cSrcweir pImageStream.reset( ::utl::UcbStreamHelper::CreateStream( _rURL, STREAM_READ ) ); 434cdf0e10cSrcweir sal_Bool bSetNull = ( pImageStream.get() == NULL ) || ( ERRCODE_NONE != pImageStream->GetErrorCode() ); 435cdf0e10cSrcweir 436cdf0e10cSrcweir if ( !bSetNull ) 437cdf0e10cSrcweir { 438cdf0e10cSrcweir // get the size of the stream 439cdf0e10cSrcweir pImageStream->Seek(STREAM_SEEK_TO_END); 440cdf0e10cSrcweir sal_Int32 nSize = (sal_Int32)pImageStream->Tell(); 441cdf0e10cSrcweir if (pImageStream->GetBufferSize() < 8192) 442cdf0e10cSrcweir pImageStream->SetBufferSize(8192); 443cdf0e10cSrcweir pImageStream->Seek(STREAM_SEEK_TO_BEGIN); 444cdf0e10cSrcweir 445cdf0e10cSrcweir xImageStream = new ::utl::OInputStreamHelper( new SvLockBytes( pImageStream.get(), sal_False ), nSize ); 446cdf0e10cSrcweir } 447cdf0e10cSrcweir } 448cdf0e10cSrcweir 449cdf0e10cSrcweir if ( xImageStream.is() ) 450cdf0e10cSrcweir { 451cdf0e10cSrcweir if ( m_xColumnUpdate.is() ) 452cdf0e10cSrcweir m_xColumnUpdate->updateBinaryStream( xImageStream, xImageStream->available() ); 453cdf0e10cSrcweir else 454cdf0e10cSrcweir setControlValue( makeAny( xImageStream ), _eInstigator ); 455cdf0e10cSrcweir xImageStream->closeInput(); 456cdf0e10cSrcweir return sal_True; 457cdf0e10cSrcweir } 458cdf0e10cSrcweir 459cdf0e10cSrcweir return sal_False; 460cdf0e10cSrcweir } 461cdf0e10cSrcweir 462cdf0e10cSrcweir //------------------------------------------------------------------------------ 463cdf0e10cSrcweir sal_Bool OImageControlModel::impl_handleNewImageURL_lck( ValueChangeInstigator _eInstigator ) 464cdf0e10cSrcweir { 465cdf0e10cSrcweir switch ( lcl_getImageStoreType( getFieldType() ) ) 466cdf0e10cSrcweir { 467cdf0e10cSrcweir case ImageStoreBinary: 468cdf0e10cSrcweir if ( impl_updateStreamForURL_lck( m_sImageURL, _eInstigator ) ) 469cdf0e10cSrcweir return sal_True; 470cdf0e10cSrcweir break; 471cdf0e10cSrcweir 472cdf0e10cSrcweir case ImageStoreLink: 473cdf0e10cSrcweir { 474cdf0e10cSrcweir ::rtl::OUString sCommitURL( m_sImageURL ); 475cdf0e10cSrcweir if ( m_sDocumentURL.getLength() ) 476cdf0e10cSrcweir sCommitURL = URIHelper::simpleNormalizedMakeRelative( m_sDocumentURL, sCommitURL ); 477cdf0e10cSrcweir OSL_ENSURE( m_xColumnUpdate.is(), "OImageControlModel::impl_handleNewImageURL_lck: no bound field, but ImageStoreLink?!" ); 478cdf0e10cSrcweir if ( m_xColumnUpdate.is() ) 479cdf0e10cSrcweir { 480cdf0e10cSrcweir m_xColumnUpdate->updateString( sCommitURL ); 481cdf0e10cSrcweir return sal_True; 482cdf0e10cSrcweir } 483cdf0e10cSrcweir } 484cdf0e10cSrcweir break; 485cdf0e10cSrcweir 486cdf0e10cSrcweir case ImageStoreInvalid: 487cdf0e10cSrcweir OSL_ENSURE( false, "OImageControlModel::impl_handleNewImageURL_lck: image storage type type!" ); 488cdf0e10cSrcweir break; 489cdf0e10cSrcweir } 490cdf0e10cSrcweir 491cdf0e10cSrcweir // if we're here, then the above code was unable to update our field/control from the given URL 492cdf0e10cSrcweir // => fall back to NULL/VOID 493cdf0e10cSrcweir if ( m_xColumnUpdate.is() ) 494cdf0e10cSrcweir m_xColumnUpdate->updateNull(); 495cdf0e10cSrcweir else 496cdf0e10cSrcweir setControlValue( Any(), _eInstigator ); 497cdf0e10cSrcweir 498cdf0e10cSrcweir return sal_True; 499cdf0e10cSrcweir } 500cdf0e10cSrcweir 501cdf0e10cSrcweir //------------------------------------------------------------------------------ 502cdf0e10cSrcweir sal_Bool OImageControlModel::commitControlValueToDbColumn( bool _bPostReset ) 503cdf0e10cSrcweir { 504cdf0e10cSrcweir if ( _bPostReset ) 505cdf0e10cSrcweir { 506cdf0e10cSrcweir // since this is a "commit after reset", we can simply update the column 507cdf0e10cSrcweir // with null - this is our "default" which we were just reset to 508cdf0e10cSrcweir if ( m_xColumnUpdate.is() ) 509cdf0e10cSrcweir m_xColumnUpdate->updateNull(); 510cdf0e10cSrcweir } 511cdf0e10cSrcweir else 512cdf0e10cSrcweir { 513cdf0e10cSrcweir ::osl::MutexGuard aGuard(m_aMutex); 514cdf0e10cSrcweir return impl_handleNewImageURL_lck( eDbColumnBinding ); 515cdf0e10cSrcweir } 516cdf0e10cSrcweir 517cdf0e10cSrcweir return sal_True; 518cdf0e10cSrcweir } 519cdf0e10cSrcweir 520cdf0e10cSrcweir //------------------------------------------------------------------------------ 521cdf0e10cSrcweir namespace 522cdf0e10cSrcweir { 523cdf0e10cSrcweir bool lcl_isValidDocumentURL( const ::rtl::OUString& _rDocURL ) 524cdf0e10cSrcweir { 525cdf0e10cSrcweir return ( _rDocURL.getLength() && !_rDocURL.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "private:object" ) ) ); 526cdf0e10cSrcweir } 527cdf0e10cSrcweir } 528cdf0e10cSrcweir 529cdf0e10cSrcweir //------------------------------------------------------------------------------ 530cdf0e10cSrcweir void OImageControlModel::onConnectedDbColumn( const Reference< XInterface >& _rxForm ) 531cdf0e10cSrcweir { 532cdf0e10cSrcweir OBoundControlModel::onConnectedDbColumn( _rxForm ); 533cdf0e10cSrcweir 534cdf0e10cSrcweir try 535cdf0e10cSrcweir { 536cdf0e10cSrcweir Reference< XModel > xDocument( getXModel( *this ) ); 537cdf0e10cSrcweir if ( xDocument.is() ) 538cdf0e10cSrcweir { 539cdf0e10cSrcweir m_sDocumentURL = xDocument->getURL(); 540cdf0e10cSrcweir if ( !lcl_isValidDocumentURL( m_sDocumentURL ) ) 541cdf0e10cSrcweir { 542cdf0e10cSrcweir Reference< XChild > xAsChild( xDocument, UNO_QUERY ); 543cdf0e10cSrcweir while ( xAsChild.is() && !lcl_isValidDocumentURL( m_sDocumentURL ) ) 544cdf0e10cSrcweir { 545cdf0e10cSrcweir xDocument.set( xAsChild->getParent(), UNO_QUERY ); 546cdf0e10cSrcweir if ( xDocument.is() ) 547cdf0e10cSrcweir m_sDocumentURL = xDocument->getURL(); 548cdf0e10cSrcweir xAsChild.set( xDocument, UNO_QUERY ); 549cdf0e10cSrcweir } 550cdf0e10cSrcweir } 551cdf0e10cSrcweir } 552cdf0e10cSrcweir } 553cdf0e10cSrcweir catch( const Exception& ) 554cdf0e10cSrcweir { 555cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 556cdf0e10cSrcweir } 557cdf0e10cSrcweir } 558cdf0e10cSrcweir 559cdf0e10cSrcweir //------------------------------------------------------------------------------ 560cdf0e10cSrcweir void OImageControlModel::onDisconnectedDbColumn() 561cdf0e10cSrcweir { 562cdf0e10cSrcweir OBoundControlModel::onDisconnectedDbColumn(); 563cdf0e10cSrcweir 564cdf0e10cSrcweir m_sDocumentURL = ::rtl::OUString(); 565cdf0e10cSrcweir } 566cdf0e10cSrcweir 567cdf0e10cSrcweir //------------------------------------------------------------------------------ 568cdf0e10cSrcweir Any OImageControlModel::translateDbColumnToControlValue() 569cdf0e10cSrcweir { 570cdf0e10cSrcweir switch ( lcl_getImageStoreType( getFieldType() ) ) 571cdf0e10cSrcweir { 572cdf0e10cSrcweir case ImageStoreBinary: 573cdf0e10cSrcweir { 574cdf0e10cSrcweir Reference< XInputStream > xImageStream( m_xColumn->getBinaryStream() ); 575cdf0e10cSrcweir if ( m_xColumn->wasNull() ) 576cdf0e10cSrcweir xImageStream.clear(); 577cdf0e10cSrcweir return makeAny( xImageStream ); 578cdf0e10cSrcweir } 579cdf0e10cSrcweir case ImageStoreLink: 580cdf0e10cSrcweir { 581cdf0e10cSrcweir ::rtl::OUString sImageLink( m_xColumn->getString() ); 582cdf0e10cSrcweir if ( m_sDocumentURL.getLength() ) 583cdf0e10cSrcweir sImageLink = INetURLObject::GetAbsURL( m_sDocumentURL, sImageLink ); 584cdf0e10cSrcweir return makeAny( sImageLink ); 585cdf0e10cSrcweir } 586cdf0e10cSrcweir case ImageStoreInvalid: 587cdf0e10cSrcweir OSL_ENSURE( false, "OImageControlModel::translateDbColumnToControlValue: invalid field type!" ); 588cdf0e10cSrcweir break; 589cdf0e10cSrcweir } 590cdf0e10cSrcweir return Any(); 591cdf0e10cSrcweir } 592cdf0e10cSrcweir 593cdf0e10cSrcweir //------------------------------------------------------------------------------ 594cdf0e10cSrcweir Any OImageControlModel::getControlValue( ) const 595cdf0e10cSrcweir { 596cdf0e10cSrcweir return makeAny( m_sImageURL ); 597cdf0e10cSrcweir } 598cdf0e10cSrcweir 599cdf0e10cSrcweir //------------------------------------------------------------------------------ 600cdf0e10cSrcweir void OImageControlModel::doSetControlValue( const Any& _rValue ) 601cdf0e10cSrcweir { 602cdf0e10cSrcweir DBG_ASSERT( GetImageProducer() && m_xImageProducer.is(), "OImageControlModel::doSetControlValue: no image producer!" ); 603cdf0e10cSrcweir if ( !GetImageProducer() || !m_xImageProducer.is() ) 604cdf0e10cSrcweir return; 605cdf0e10cSrcweir 606cdf0e10cSrcweir bool bStartProduction = false; 607cdf0e10cSrcweir switch ( lcl_getImageStoreType( getFieldType() ) ) 608cdf0e10cSrcweir { 609cdf0e10cSrcweir case ImageStoreBinary: 610cdf0e10cSrcweir { 611cdf0e10cSrcweir // give the image producer the stream 612cdf0e10cSrcweir Reference< XInputStream > xInStream; 613cdf0e10cSrcweir _rValue >>= xInStream; 614cdf0e10cSrcweir GetImageProducer()->setImage( xInStream ); 615cdf0e10cSrcweir bStartProduction = true; 616cdf0e10cSrcweir } 617cdf0e10cSrcweir break; 618cdf0e10cSrcweir 619cdf0e10cSrcweir case ImageStoreLink: 620cdf0e10cSrcweir { 621cdf0e10cSrcweir ::rtl::OUString sImageURL; 622cdf0e10cSrcweir _rValue >>= sImageURL; 623cdf0e10cSrcweir GetImageProducer()->SetImage( sImageURL ); 624cdf0e10cSrcweir bStartProduction = true; 625cdf0e10cSrcweir } 626cdf0e10cSrcweir break; 627cdf0e10cSrcweir 628cdf0e10cSrcweir case ImageStoreInvalid: 629cdf0e10cSrcweir OSL_ENSURE( false, "OImageControlModel::doSetControlValue: invalid field type!" ); 630cdf0e10cSrcweir break; 631cdf0e10cSrcweir 632cdf0e10cSrcweir } // switch ( lcl_getImageStoreType( getFieldType() ) ) 633cdf0e10cSrcweir 634cdf0e10cSrcweir if ( bStartProduction ) 635cdf0e10cSrcweir { 636cdf0e10cSrcweir // start production 637cdf0e10cSrcweir Reference< XImageProducer > xProducer = m_xImageProducer; 638cdf0e10cSrcweir { 639cdf0e10cSrcweir // release our mutex once (it's acquired in the calling method!), as starting the image production may 640cdf0e10cSrcweir // result in the locking of the solar mutex (unfortunally the default implementation of our aggregate, 641cdf0e10cSrcweir // VCLXImageControl, does this locking) 642cdf0e10cSrcweir // FS - 74438 - 30.03.00 643cdf0e10cSrcweir MutexRelease aRelease(m_aMutex); 644cdf0e10cSrcweir xProducer->startProduction(); 645cdf0e10cSrcweir } 646cdf0e10cSrcweir } 647cdf0e10cSrcweir } 648cdf0e10cSrcweir 649cdf0e10cSrcweir // OComponentHelper 650cdf0e10cSrcweir //------------------------------------------------------------------ 651cdf0e10cSrcweir void SAL_CALL OImageControlModel::disposing() 652cdf0e10cSrcweir { 653cdf0e10cSrcweir OBoundControlModel::disposing(); 654cdf0e10cSrcweir } 655cdf0e10cSrcweir 656cdf0e10cSrcweir //------------------------------------------------------------------------------ 657cdf0e10cSrcweir void OImageControlModel::resetNoBroadcast() 658cdf0e10cSrcweir { 659cdf0e10cSrcweir if ( hasField() ) // only reset when we are connected to a column 660cdf0e10cSrcweir OBoundControlModel::resetNoBroadcast( ); 661cdf0e10cSrcweir } 662cdf0e10cSrcweir 663cdf0e10cSrcweir //-------------------------------------------------------------------- 664cdf0e10cSrcweir Reference< XImageProducer > SAL_CALL OImageControlModel::getImageProducer() throw ( RuntimeException) 665cdf0e10cSrcweir { 666cdf0e10cSrcweir return this; 667cdf0e10cSrcweir } 668cdf0e10cSrcweir 669cdf0e10cSrcweir //-------------------------------------------------------------------- 670cdf0e10cSrcweir void SAL_CALL OImageControlModel::addConsumer( const Reference< XImageConsumer >& _rxConsumer ) throw (RuntimeException) 671cdf0e10cSrcweir { 672cdf0e10cSrcweir GetImageProducer()->addConsumer( _rxConsumer ); 673cdf0e10cSrcweir } 674cdf0e10cSrcweir 675cdf0e10cSrcweir //-------------------------------------------------------------------- 676cdf0e10cSrcweir void SAL_CALL OImageControlModel::removeConsumer( const Reference< XImageConsumer >& _rxConsumer ) throw (RuntimeException) 677cdf0e10cSrcweir { 678cdf0e10cSrcweir GetImageProducer()->removeConsumer( _rxConsumer ); 679cdf0e10cSrcweir } 680cdf0e10cSrcweir 681cdf0e10cSrcweir //-------------------------------------------------------------------- 682cdf0e10cSrcweir void SAL_CALL OImageControlModel::startProduction( ) throw (RuntimeException) 683cdf0e10cSrcweir { 684cdf0e10cSrcweir GetImageProducer()->startProduction(); 685cdf0e10cSrcweir } 686cdf0e10cSrcweir 687cdf0e10cSrcweir //------------------------------------------------------------------------------ 688cdf0e10cSrcweir IMPL_LINK( OImageControlModel, OnImageImportDone, ::Graphic*, i_pGraphic ) 689cdf0e10cSrcweir { 690cdf0e10cSrcweir const Reference< XGraphic > xGraphic( i_pGraphic != NULL ? Image( i_pGraphic->GetBitmapEx() ).GetXGraphic() : NULL ); 691cdf0e10cSrcweir m_bExternalGraphic = false; 692cdf0e10cSrcweir try 693cdf0e10cSrcweir { 694cdf0e10cSrcweir setPropertyValue( PROPERTY_GRAPHIC, makeAny( xGraphic ) ); 695cdf0e10cSrcweir } 696cdf0e10cSrcweir catch ( const Exception& ) 697cdf0e10cSrcweir { 698cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 699cdf0e10cSrcweir } 700cdf0e10cSrcweir m_bExternalGraphic = true; 701cdf0e10cSrcweir return 1L; 702cdf0e10cSrcweir } 703cdf0e10cSrcweir 704cdf0e10cSrcweir //================================================================== 705cdf0e10cSrcweir // OImageControlControl 706cdf0e10cSrcweir //================================================================== 707cdf0e10cSrcweir 708cdf0e10cSrcweir //------------------------------------------------------------------ 709cdf0e10cSrcweir InterfaceRef SAL_CALL OImageControlControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory) 710cdf0e10cSrcweir { 711cdf0e10cSrcweir return *(new OImageControlControl(_rxFactory)); 712cdf0e10cSrcweir } 713cdf0e10cSrcweir 714cdf0e10cSrcweir //------------------------------------------------------------------------------ 715cdf0e10cSrcweir Sequence<Type> OImageControlControl::_getTypes() 716cdf0e10cSrcweir { 717cdf0e10cSrcweir return concatSequences( 718cdf0e10cSrcweir OBoundControl::_getTypes(), 719cdf0e10cSrcweir OImageControlControl_Base::getTypes() 720cdf0e10cSrcweir ); 721cdf0e10cSrcweir } 722cdf0e10cSrcweir 723cdf0e10cSrcweir //------------------------------------------------------------------------------ 724cdf0e10cSrcweir OImageControlControl::OImageControlControl(const Reference<XMultiServiceFactory>& _rxFactory) 725cdf0e10cSrcweir :OBoundControl(_rxFactory, VCL_CONTROL_IMAGECONTROL) 726cdf0e10cSrcweir ,m_aModifyListeners( m_aMutex ) 727cdf0e10cSrcweir { 728cdf0e10cSrcweir increment(m_refCount); 729cdf0e10cSrcweir { 730cdf0e10cSrcweir // als Focus- und MouseListener anmelden 731cdf0e10cSrcweir Reference< XWindow > xComp; 732cdf0e10cSrcweir query_aggregation( m_xAggregate, xComp ); 733cdf0e10cSrcweir if ( xComp.is() ) 734cdf0e10cSrcweir xComp->addMouseListener( this ); 735cdf0e10cSrcweir } 736cdf0e10cSrcweir decrement(m_refCount); 737cdf0e10cSrcweir } 738cdf0e10cSrcweir 739cdf0e10cSrcweir //------------------------------------------------------------------------------ 740cdf0e10cSrcweir Any SAL_CALL OImageControlControl::queryAggregation(const Type& _rType) throw (RuntimeException) 741cdf0e10cSrcweir { 742cdf0e10cSrcweir Any aReturn = OBoundControl::queryAggregation( _rType ); 743cdf0e10cSrcweir if ( !aReturn.hasValue() ) 744cdf0e10cSrcweir aReturn = ::cppu::queryInterface( 745cdf0e10cSrcweir _rType, 746cdf0e10cSrcweir static_cast< XMouseListener* >( this ), 747cdf0e10cSrcweir static_cast< XModifyBroadcaster* >( this ) 748cdf0e10cSrcweir ); 749cdf0e10cSrcweir 750cdf0e10cSrcweir return aReturn; 751cdf0e10cSrcweir } 752cdf0e10cSrcweir 753cdf0e10cSrcweir //------------------------------------------------------------------------------ 754cdf0e10cSrcweir StringSequence OImageControlControl::getSupportedServiceNames() throw() 755cdf0e10cSrcweir { 756cdf0e10cSrcweir StringSequence aSupported = OBoundControl::getSupportedServiceNames(); 757cdf0e10cSrcweir aSupported.realloc(aSupported.getLength() + 1); 758cdf0e10cSrcweir 759cdf0e10cSrcweir ::rtl::OUString*pArray = aSupported.getArray(); 760cdf0e10cSrcweir pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_IMAGECONTROL; 761cdf0e10cSrcweir return aSupported; 762cdf0e10cSrcweir } 763cdf0e10cSrcweir 764cdf0e10cSrcweir //------------------------------------------------------------------------------ 765cdf0e10cSrcweir void SAL_CALL OImageControlControl::addModifyListener( const Reference< XModifyListener >& _Listener ) throw (RuntimeException) 766cdf0e10cSrcweir { 767cdf0e10cSrcweir m_aModifyListeners.addInterface( _Listener ); 768cdf0e10cSrcweir } 769cdf0e10cSrcweir 770cdf0e10cSrcweir //------------------------------------------------------------------------------ 771cdf0e10cSrcweir void SAL_CALL OImageControlControl::removeModifyListener( const Reference< XModifyListener >& _Listener ) throw (RuntimeException) 772cdf0e10cSrcweir { 773cdf0e10cSrcweir m_aModifyListeners.removeInterface( _Listener ); 774cdf0e10cSrcweir } 775cdf0e10cSrcweir 776cdf0e10cSrcweir //------------------------------------------------------------------------------ 777cdf0e10cSrcweir void SAL_CALL OImageControlControl::disposing() 778cdf0e10cSrcweir { 779cdf0e10cSrcweir EventObject aEvent( *this ); 780cdf0e10cSrcweir m_aModifyListeners.disposeAndClear( aEvent ); 781cdf0e10cSrcweir 782cdf0e10cSrcweir OBoundControl::disposing(); 783cdf0e10cSrcweir } 784cdf0e10cSrcweir 785cdf0e10cSrcweir //------------------------------------------------------------------------------ 786cdf0e10cSrcweir void SAL_CALL OImageControlControl::disposing( const EventObject& _Event ) throw(RuntimeException) 787cdf0e10cSrcweir { 788cdf0e10cSrcweir OBoundControl::disposing( _Event ); 789cdf0e10cSrcweir } 790cdf0e10cSrcweir 791cdf0e10cSrcweir //------------------------------------------------------------------------------ 792cdf0e10cSrcweir void OImageControlControl::implClearGraphics( sal_Bool _bForce ) 793cdf0e10cSrcweir { 794cdf0e10cSrcweir Reference< XPropertySet > xSet( getModel(), UNO_QUERY ); 795cdf0e10cSrcweir if ( xSet.is() ) 796cdf0e10cSrcweir { 797cdf0e10cSrcweir if ( _bForce ) 798cdf0e10cSrcweir { 799cdf0e10cSrcweir ::rtl::OUString sOldImageURL; 800cdf0e10cSrcweir xSet->getPropertyValue( PROPERTY_IMAGE_URL ) >>= sOldImageURL; 801cdf0e10cSrcweir 802cdf0e10cSrcweir if ( !sOldImageURL.getLength() ) 803cdf0e10cSrcweir // the ImageURL is already empty, so simply setting a new empty one would not suffice 804cdf0e10cSrcweir // (since it would be ignored) 805cdf0e10cSrcweir xSet->setPropertyValue( PROPERTY_IMAGE_URL, makeAny( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "private:emptyImage" ) ) ) ); 806cdf0e10cSrcweir // (the concrete URL we're passing here doens't matter. It's important that 807cdf0e10cSrcweir // the model cannot resolve it to a a valid resource describing an image stream 808cdf0e10cSrcweir } 809cdf0e10cSrcweir 810cdf0e10cSrcweir xSet->setPropertyValue( PROPERTY_IMAGE_URL, makeAny( ::rtl::OUString() ) ); 811cdf0e10cSrcweir } 812cdf0e10cSrcweir } 813cdf0e10cSrcweir 814cdf0e10cSrcweir //------------------------------------------------------------------------------ 815cdf0e10cSrcweir bool OImageControlControl::implInsertGraphics() 816cdf0e10cSrcweir { 817cdf0e10cSrcweir Reference< XPropertySet > xSet( getModel(), UNO_QUERY ); 818cdf0e10cSrcweir if ( !xSet.is() ) 819cdf0e10cSrcweir return false; 820cdf0e10cSrcweir 821cdf0e10cSrcweir ::rtl::OUString sTitle = FRM_RES_STRING(RID_STR_IMPORT_GRAPHIC); 822cdf0e10cSrcweir // build some arguments for the upcoming dialog 823cdf0e10cSrcweir try 824cdf0e10cSrcweir { 825cdf0e10cSrcweir ::sfx2::FileDialogHelper aDialog( TemplateDescription::FILEOPEN_LINK_PREVIEW, SFXWB_GRAPHIC ); 826cdf0e10cSrcweir aDialog.SetTitle( sTitle ); 827cdf0e10cSrcweir 828cdf0e10cSrcweir Reference< XFilePickerControlAccess > xController( aDialog.GetFilePicker(), UNO_QUERY_THROW ); 829cdf0e10cSrcweir xController->setValue(ExtendedFilePickerElementIds::CHECKBOX_PREVIEW, 0, ::cppu::bool2any(sal_True)); 830cdf0e10cSrcweir 831cdf0e10cSrcweir Reference<XPropertySet> xBoundField; 832cdf0e10cSrcweir if ( hasProperty( PROPERTY_BOUNDFIELD, xSet ) ) 833cdf0e10cSrcweir xSet->getPropertyValue( PROPERTY_BOUNDFIELD ) >>= xBoundField; 834cdf0e10cSrcweir sal_Bool bHasField = xBoundField.is(); 835cdf0e10cSrcweir 836cdf0e10cSrcweir // if the control is bound to a DB field, then it's not possible to decide whether or not to link 837cdf0e10cSrcweir xController->enableControl(ExtendedFilePickerElementIds::CHECKBOX_LINK, !bHasField ); 838cdf0e10cSrcweir 839cdf0e10cSrcweir // if the control is bound to a DB field, then linking of the image depends on the type of the field 840cdf0e10cSrcweir sal_Bool bImageIsLinked = sal_True; 841cdf0e10cSrcweir if ( bHasField ) 842cdf0e10cSrcweir { 843cdf0e10cSrcweir sal_Int32 nFieldType = DataType::OTHER; 844cdf0e10cSrcweir OSL_VERIFY( xBoundField->getPropertyValue( PROPERTY_FIELDTYPE ) >>= nFieldType ); 845cdf0e10cSrcweir bImageIsLinked = ( lcl_getImageStoreType( nFieldType ) == ImageStoreLink ); 846cdf0e10cSrcweir } 847cdf0e10cSrcweir xController->setValue(ExtendedFilePickerElementIds::CHECKBOX_LINK, 0, makeAny( bImageIsLinked ) ); 848cdf0e10cSrcweir 849cdf0e10cSrcweir if ( ERRCODE_NONE == aDialog.Execute() ) 850cdf0e10cSrcweir { 851cdf0e10cSrcweir // reset the url property in case it already has the value we're about to set - in this case 852cdf0e10cSrcweir // our propertyChanged would not get called without this. 853cdf0e10cSrcweir implClearGraphics( sal_False ); 854cdf0e10cSrcweir sal_Bool bIsLink = sal_False; 855cdf0e10cSrcweir xController->getValue(ExtendedFilePickerElementIds::CHECKBOX_LINK, 0) >>= bIsLink; 856cdf0e10cSrcweir // Force bIsLink to be sal_True if we're bound to a field. Though we initialized the file picker with IsLink=TRUE 857cdf0e10cSrcweir // in this case, and disabled the respective control, there might be picker implementations which do not 858cdf0e10cSrcweir // respect this, and return IsLink=FALSE here. In this case, "normalize" the flag. 859cdf0e10cSrcweir // #i112659# / 2010-08-26 / frank.schoenheit@oracle.com 860cdf0e10cSrcweir bIsLink |= bHasField; 861cdf0e10cSrcweir if ( !bIsLink ) 862cdf0e10cSrcweir { 863cdf0e10cSrcweir Graphic aGraphic; 864cdf0e10cSrcweir aDialog.GetGraphic( aGraphic ); 865cdf0e10cSrcweir xSet->setPropertyValue( PROPERTY_GRAPHIC, makeAny( aGraphic.GetXGraphic() ) ); 866cdf0e10cSrcweir } 867cdf0e10cSrcweir else 868cdf0e10cSrcweir xSet->setPropertyValue( PROPERTY_IMAGE_URL, makeAny( ::rtl::OUString( aDialog.GetPath() ) ) ); 869cdf0e10cSrcweir 870cdf0e10cSrcweir return true; 871cdf0e10cSrcweir } 872cdf0e10cSrcweir } 873cdf0e10cSrcweir catch(Exception&) 874cdf0e10cSrcweir { 875cdf0e10cSrcweir DBG_ERROR("OImageControlControl::implInsertGraphics: caught an exception while attempting to execute the FilePicker!"); 876cdf0e10cSrcweir } 877cdf0e10cSrcweir return false; 878cdf0e10cSrcweir } 879cdf0e10cSrcweir 880cdf0e10cSrcweir //------------------------------------------------------------------------------ 881cdf0e10cSrcweir bool OImageControlControl::impl_isEmptyGraphics_nothrow() const 882cdf0e10cSrcweir { 883cdf0e10cSrcweir bool bIsEmpty = true; 884cdf0e10cSrcweir 885cdf0e10cSrcweir try 886cdf0e10cSrcweir { 887cdf0e10cSrcweir Reference< XPropertySet > xModelProps( const_cast< OImageControlControl* >( this )->getModel(), UNO_QUERY_THROW ); 888cdf0e10cSrcweir Reference< XGraphic > xGraphic; 889cdf0e10cSrcweir OSL_VERIFY( xModelProps->getPropertyValue( ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Graphic" ) ) ) >>= xGraphic ); 890cdf0e10cSrcweir bIsEmpty = !xGraphic.is(); 891cdf0e10cSrcweir } 892cdf0e10cSrcweir catch( const Exception& ) 893cdf0e10cSrcweir { 894cdf0e10cSrcweir DBG_UNHANDLED_EXCEPTION(); 895cdf0e10cSrcweir } 896cdf0e10cSrcweir 897cdf0e10cSrcweir return bIsEmpty; 898cdf0e10cSrcweir } 899cdf0e10cSrcweir 900cdf0e10cSrcweir // MouseListener 901cdf0e10cSrcweir //------------------------------------------------------------------------------ 902cdf0e10cSrcweir void OImageControlControl::mousePressed(const ::com::sun::star::awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException) 903cdf0e10cSrcweir { 904cdf0e10cSrcweir ::vos::OGuard aGuard( Application::GetSolarMutex() ); 905cdf0e10cSrcweir 906cdf0e10cSrcweir if (e.Buttons != MouseButton::LEFT) 907cdf0e10cSrcweir return; 908cdf0e10cSrcweir 909cdf0e10cSrcweir bool bModified = false; 910cdf0e10cSrcweir // is this a request for a context menu? 911cdf0e10cSrcweir if ( e.PopupTrigger ) 912cdf0e10cSrcweir { 913cdf0e10cSrcweir Reference< XPopupMenu > xMenu( m_aContext.createComponent( "com.sun.star.awt.PopupMenu" ), UNO_QUERY ); 914cdf0e10cSrcweir DBG_ASSERT( xMenu.is(), "OImageControlControl::mousePressed: could not create a popup menu!" ); 915cdf0e10cSrcweir 916cdf0e10cSrcweir Reference< XWindowPeer > xWindowPeer = getPeer(); 917cdf0e10cSrcweir DBG_ASSERT( xWindowPeer.is(), "OImageControlControl::mousePressed: no window!" ); 918cdf0e10cSrcweir 919cdf0e10cSrcweir if ( xMenu.is() && xWindowPeer.is() ) 920cdf0e10cSrcweir { 921cdf0e10cSrcweir xMenu->insertItem( ID_OPEN_GRAPHICS, FRM_RES_STRING( RID_STR_OPEN_GRAPHICS ), 0, 0 ); 922cdf0e10cSrcweir xMenu->insertItem( ID_CLEAR_GRAPHICS, FRM_RES_STRING( RID_STR_CLEAR_GRAPHICS ), 0, 1 ); 923cdf0e10cSrcweir 924cdf0e10cSrcweir // check if the ImageURL is empty 925cdf0e10cSrcweir if ( impl_isEmptyGraphics_nothrow() ) 926cdf0e10cSrcweir xMenu->enableItem( ID_CLEAR_GRAPHICS, sal_False ); 927cdf0e10cSrcweir 928cdf0e10cSrcweir awt::Rectangle aRect( e.X, e.Y, 0, 0 ); 929cdf0e10cSrcweir if ( ( e.X < 0 ) || ( e.Y < 0 ) ) 930cdf0e10cSrcweir { // context menu triggered by keyboard 931cdf0e10cSrcweir // position it in the center of the control 932cdf0e10cSrcweir // 102205 - 16.08.2002 - fs@openoffice.org 933cdf0e10cSrcweir Reference< XWindow > xWindow( static_cast< ::cppu::OWeakObject* >( this ), UNO_QUERY ); 934cdf0e10cSrcweir OSL_ENSURE( xWindow.is(), "OImageControlControl::mousePressed: me not a window? How this?" ); 935cdf0e10cSrcweir if ( xWindow.is() ) 936cdf0e10cSrcweir { 937cdf0e10cSrcweir awt::Rectangle aPosSize = xWindow->getPosSize(); 938cdf0e10cSrcweir aRect.X = aPosSize.Width / 2; 939cdf0e10cSrcweir aRect.Y = aPosSize.Height / 2; 940cdf0e10cSrcweir } 941cdf0e10cSrcweir } 942cdf0e10cSrcweir 943cdf0e10cSrcweir const sal_Int16 nResult = xMenu->execute( xWindowPeer, aRect, PopupMenuDirection::EXECUTE_DEFAULT ); 944cdf0e10cSrcweir 945cdf0e10cSrcweir switch ( nResult ) 946cdf0e10cSrcweir { 947cdf0e10cSrcweir case ID_OPEN_GRAPHICS: 948cdf0e10cSrcweir implInsertGraphics(); 949cdf0e10cSrcweir bModified = true; 950cdf0e10cSrcweir break; 951cdf0e10cSrcweir 952cdf0e10cSrcweir case ID_CLEAR_GRAPHICS: 953cdf0e10cSrcweir implClearGraphics( sal_True ); 954cdf0e10cSrcweir bModified = true; 955cdf0e10cSrcweir break; 956cdf0e10cSrcweir } 957cdf0e10cSrcweir } 958cdf0e10cSrcweir } 959cdf0e10cSrcweir else 960cdf0e10cSrcweir { 961cdf0e10cSrcweir ////////////////////////////////////////////////////////////////////// 962cdf0e10cSrcweir // Doppelclick 963cdf0e10cSrcweir if (e.ClickCount == 2) 964cdf0e10cSrcweir { 965cdf0e10cSrcweir 966cdf0e10cSrcweir Reference<XPropertySet> xSet(getModel(), UNO_QUERY); 967cdf0e10cSrcweir if (!xSet.is()) 968cdf0e10cSrcweir return; 969cdf0e10cSrcweir 970cdf0e10cSrcweir // wenn Control nicht gebunden ist, kein Dialog (da die zu schickende URL hinterher sowieso 971cdf0e10cSrcweir // versanden wuerde) 972cdf0e10cSrcweir // FS - #64946# - 19.04.99 973cdf0e10cSrcweir Reference<XPropertySet> xBoundField; 974cdf0e10cSrcweir if (hasProperty(PROPERTY_BOUNDFIELD, xSet)) 975cdf0e10cSrcweir ::cppu::extractInterface(xBoundField, xSet->getPropertyValue(PROPERTY_BOUNDFIELD)); 976cdf0e10cSrcweir if (!xBoundField.is()) 977cdf0e10cSrcweir { 978cdf0e10cSrcweir // but only if our IMAGE_URL property is handled as if it is transient, which is equivalent to 979cdf0e10cSrcweir // an empty control source 980cdf0e10cSrcweir if (!hasProperty(PROPERTY_CONTROLSOURCE, xSet) || (::comphelper::getString(xSet->getPropertyValue(PROPERTY_CONTROLSOURCE)).getLength() != 0)) 981cdf0e10cSrcweir return; 982cdf0e10cSrcweir } 983cdf0e10cSrcweir 984cdf0e10cSrcweir sal_Bool bReadOnly = false; 985cdf0e10cSrcweir xSet->getPropertyValue(PROPERTY_READONLY) >>= bReadOnly; 986cdf0e10cSrcweir if (bReadOnly) 987cdf0e10cSrcweir return; 988cdf0e10cSrcweir 989cdf0e10cSrcweir if ( implInsertGraphics() ) 990cdf0e10cSrcweir bModified = true; 991cdf0e10cSrcweir } 992cdf0e10cSrcweir } 993cdf0e10cSrcweir 994cdf0e10cSrcweir if ( bModified ) 995cdf0e10cSrcweir { 996cdf0e10cSrcweir EventObject aEvent( *this ); 997cdf0e10cSrcweir m_aModifyListeners.notifyEach( &XModifyListener::modified, aEvent ); 998cdf0e10cSrcweir } 999cdf0e10cSrcweir } 1000cdf0e10cSrcweir 1001cdf0e10cSrcweir //------------------------------------------------------------------------------ 1002cdf0e10cSrcweir void SAL_CALL OImageControlControl::mouseReleased(const awt::MouseEvent& /*e*/) throw ( RuntimeException ) 1003cdf0e10cSrcweir { 1004cdf0e10cSrcweir } 1005cdf0e10cSrcweir 1006cdf0e10cSrcweir //------------------------------------------------------------------------------ 1007cdf0e10cSrcweir void SAL_CALL OImageControlControl::mouseEntered(const awt::MouseEvent& /*e*/) throw ( RuntimeException ) 1008cdf0e10cSrcweir { 1009cdf0e10cSrcweir } 1010cdf0e10cSrcweir 1011cdf0e10cSrcweir //------------------------------------------------------------------------------ 1012cdf0e10cSrcweir void SAL_CALL OImageControlControl::mouseExited(const awt::MouseEvent& /*e*/) throw ( RuntimeException ) 1013cdf0e10cSrcweir { 1014cdf0e10cSrcweir } 1015cdf0e10cSrcweir 1016cdf0e10cSrcweir //......................................................................... 1017cdf0e10cSrcweir } // namespace frm 1018cdf0e10cSrcweir //......................................................................... 1019cdf0e10cSrcweir 1020