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