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 : :
30 : : #include "Button.hxx"
31 : :
32 : : #include <com/sun/star/awt/XVclWindowPeer.hpp>
33 : :
34 : : #include <comphelper/streamsection.hxx>
35 : : #include <comphelper/basicio.hxx>
36 : : #include <tools/diagnose_ex.h>
37 : : #include <tools/debug.hxx>
38 : : #include <tools/urlobj.hxx>
39 : : #include <vcl/svapp.hxx>
40 : : #include <osl/mutex.hxx>
41 : :
42 : : //.........................................................................
43 : : namespace frm
44 : : {
45 : : //.........................................................................
46 : :
47 : : using namespace ::com::sun::star::uno;
48 : : using namespace ::com::sun::star::sdb;
49 : : using namespace ::com::sun::star::sdbc;
50 : : using namespace ::com::sun::star::sdbcx;
51 : : using namespace ::com::sun::star::beans;
52 : : using namespace ::com::sun::star::container;
53 : : using namespace ::com::sun::star::form;
54 : : using namespace ::com::sun::star::awt;
55 : : using namespace ::com::sun::star::io;
56 : : using namespace ::com::sun::star::lang;
57 : : using namespace ::com::sun::star::util;
58 : : using ::com::sun::star::frame::XDispatchProviderInterceptor;
59 : :
60 : : //==================================================================
61 : : //= OButtonModel
62 : : //==================================================================
63 : : DBG_NAME(OButtonModel)
64 : : //------------------------------------------------------------------
65 : 55 : InterfaceRef SAL_CALL OButtonModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
66 : : {
67 [ + - ]: 55 : return *(new OButtonModel(_rxFactory));
68 : : }
69 : :
70 : : //------------------------------------------------------------------
71 : 55 : OButtonModel::OButtonModel(const Reference<XMultiServiceFactory>& _rxFactory)
72 : : :OClickableImageBaseModel( _rxFactory, VCL_CONTROLMODEL_COMMANDBUTTON, FRM_SUN_CONTROL_COMMANDBUTTON )
73 : : // use the old control name for compatibility reasons
74 : : ,m_aResetHelper( *this, m_aMutex )
75 [ + - ][ + - ]: 55 : ,m_eDefaultState( STATE_NOCHECK )
[ + - ]
76 : : {
77 : : DBG_CTOR( OButtonModel, NULL );
78 : 55 : m_nClassId = FormComponentType::COMMANDBUTTON;
79 : 55 : }
80 : :
81 : : //------------------------------------------------------------------
82 : 8943 : Any SAL_CALL OButtonModel::queryAggregation( const Type& _type ) throw(RuntimeException)
83 : : {
84 : 8943 : Any aReturn = OClickableImageBaseModel::queryAggregation( _type );
85 [ + + ]: 8943 : if ( !aReturn.hasValue() )
86 [ + - ]: 748 : aReturn = OButtonModel_Base::queryInterface( _type );
87 : 8943 : return aReturn;
88 : : }
89 : :
90 : : //------------------------------------------------------------------
91 : 32 : Sequence< Type > OButtonModel::_getTypes()
92 : : {
93 : : return ::comphelper::concatSequences(
94 : : OClickableImageBaseModel::_getTypes(),
95 : : OButtonModel_Base::getTypes()
96 [ + - ][ + - ]: 32 : );
[ + - ]
97 : : }
98 : :
99 : : //------------------------------------------------------------------
100 : 0 : OButtonModel::OButtonModel( const OButtonModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
101 : : :OClickableImageBaseModel( _pOriginal, _rxFactory )
102 : : ,m_aResetHelper( *this, m_aMutex )
103 [ # # ]: 0 : ,m_eDefaultState( _pOriginal->m_eDefaultState )
104 : : {
105 : : DBG_CTOR( OButtonModel, NULL );
106 : 0 : m_nClassId = FormComponentType::COMMANDBUTTON;
107 : :
108 [ # # ]: 0 : implInitializeImageURL();
109 : 0 : }
110 : :
111 : : //------------------------------------------------------------------------------
112 [ + - ]: 50 : OButtonModel::~OButtonModel()
113 : : {
114 : : DBG_DTOR(OButtonModel, NULL);
115 [ - + ]: 100 : }
116 : :
117 : : //------------------------------------------------------------------------------
118 : 52 : void OButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const
119 : : {
120 : 52 : BEGIN_DESCRIBE_PROPERTIES( 6, OClickableImageBaseModel )
121 [ + - ]: 52 : DECL_PROP1( BUTTONTYPE, FormButtonType, BOUND );
122 [ + - ]: 52 : DECL_PROP1( DEFAULT_STATE, sal_Int16, BOUND );
123 [ + - ]: 52 : DECL_PROP1( DISPATCHURLINTERNAL, sal_Bool, BOUND );
124 [ + - ]: 52 : DECL_PROP1( TARGET_URL, ::rtl::OUString, BOUND );
125 [ + - ]: 52 : DECL_PROP1( TARGET_FRAME, ::rtl::OUString, BOUND );
126 [ + - ]: 52 : DECL_PROP1( TABINDEX, sal_Int16, BOUND );
127 : : END_DESCRIBE_PROPERTIES();
128 : 52 : }
129 : :
130 : : //------------------------------------------------------------------------------
131 [ # # ][ # # ]: 0 : IMPLEMENT_DEFAULT_CLONING( OButtonModel )
132 : :
133 : : // XServiceInfo
134 : : //------------------------------------------------------------------------------
135 : 0 : StringSequence OButtonModel::getSupportedServiceNames() throw()
136 : : {
137 : 0 : StringSequence aSupported = OClickableImageBaseModel::getSupportedServiceNames();
138 [ # # ]: 0 : aSupported.realloc( aSupported.getLength() + 1 );
139 : :
140 [ # # ]: 0 : ::rtl::OUString* pArray = aSupported.getArray();
141 [ # # ]: 0 : pArray[ aSupported.getLength() - 1 ] = FRM_SUN_COMPONENT_COMMANDBUTTON;
142 : :
143 : 0 : return aSupported;
144 : : }
145 : :
146 : : //------------------------------------------------------------------------------
147 : 0 : ::rtl::OUString OButtonModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
148 : : {
149 : 0 : return FRM_COMPONENT_COMMANDBUTTON; // old (non-sun) name for compatibility !
150 : : }
151 : :
152 : : //------------------------------------------------------------------------------
153 : 0 : void OButtonModel::write(const Reference<XObjectOutputStream>& _rxOutStream) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
154 : : {
155 : 0 : OClickableImageBaseModel::write(_rxOutStream);
156 : :
157 : 0 : _rxOutStream->writeShort(0x0003); // Version
158 : :
159 : : {
160 [ # # ][ # # ]: 0 : OStreamSection aSection( _rxOutStream.get() );
[ # # ]
161 : : // this will allow readers to skip unknown bytes in their dtor
162 : :
163 [ # # ][ # # ]: 0 : _rxOutStream->writeShort( (sal_uInt16)m_eButtonType );
164 : :
165 [ # # ]: 0 : ::rtl::OUString sTmp = INetURLObject::decode( m_sTargetURL, '%', INetURLObject::DECODE_UNAMBIGUOUS);
166 [ # # ]: 0 : _rxOutStream << sTmp;
167 [ # # ]: 0 : _rxOutStream << m_sTargetFrame;
168 [ # # ]: 0 : writeHelpTextCompatibly(_rxOutStream);
169 [ # # ][ # # ]: 0 : _rxOutStream << isDispatchUrlInternal();
170 : : }
171 : 0 : }
172 : :
173 : : //------------------------------------------------------------------------------
174 : 0 : void OButtonModel::read(const Reference<XObjectInputStream>& _rxInStream) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
175 : : {
176 : 0 : OClickableImageBaseModel::read(_rxInStream);
177 : :
178 : 0 : sal_uInt16 nVersion = _rxInStream->readShort(); // Version
179 [ # # # # ]: 0 : switch (nVersion)
180 : : {
181 : : case 0x0001:
182 : : {
183 : 0 : m_eButtonType = (FormButtonType)_rxInStream->readShort();
184 : :
185 : 0 : _rxInStream >> m_sTargetURL;
186 : 0 : _rxInStream >> m_sTargetFrame;
187 : : }
188 : 0 : break;
189 : :
190 : : case 0x0002:
191 : : {
192 : 0 : m_eButtonType = (FormButtonType)_rxInStream->readShort();
193 : :
194 : 0 : _rxInStream >> m_sTargetURL;
195 : 0 : _rxInStream >> m_sTargetFrame;
196 : 0 : readHelpTextCompatibly(_rxInStream);
197 : : }
198 : 0 : break;
199 : :
200 : : case 0x0003:
201 : : {
202 [ # # ][ # # ]: 0 : OStreamSection aSection( _rxInStream.get() );
[ # # ]
203 : : // this will skip any unknown bytes in it's dtor
204 : :
205 : : // button type
206 [ # # ][ # # ]: 0 : m_eButtonType = (FormButtonType)_rxInStream->readShort();
207 : :
208 : : // URL
209 [ # # ]: 0 : _rxInStream >> m_sTargetURL;
210 : :
211 : : // target frame
212 [ # # ]: 0 : _rxInStream >> m_sTargetFrame;
213 : :
214 : : // help text
215 [ # # ]: 0 : readHelpTextCompatibly(_rxInStream);
216 : :
217 : : // DispatchInternal
218 : : sal_Bool bDispath;
219 [ # # ]: 0 : _rxInStream >> bDispath;
220 [ # # ]: 0 : setDispatchUrlInternal(bDispath);
221 : : }
222 : 0 : break;
223 : :
224 : : default:
225 : : OSL_FAIL("OButtonModel::read : unknown version !");
226 : 0 : m_eButtonType = FormButtonType_PUSH;
227 : 0 : m_sTargetURL = ::rtl::OUString();
228 : 0 : m_sTargetFrame = ::rtl::OUString();
229 : 0 : break;
230 : : }
231 : 0 : }
232 : :
233 : : //--------------------------------------------------------------------
234 : 50 : void SAL_CALL OButtonModel::disposing()
235 : : {
236 : 50 : m_aResetHelper.disposing();
237 : 50 : OClickableImageBaseModel::disposing();
238 : 50 : }
239 : :
240 : : //--------------------------------------------------------------------
241 : 0 : void SAL_CALL OButtonModel::reset() throw (RuntimeException)
242 : : {
243 [ # # ]: 0 : if ( !m_aResetHelper.approveReset() )
244 : 0 : return;
245 : :
246 : 0 : impl_resetNoBroadcast_nothrow();
247 : :
248 : 0 : m_aResetHelper.notifyResetted();
249 : : }
250 : :
251 : : //--------------------------------------------------------------------
252 : 18 : void SAL_CALL OButtonModel::addResetListener( const Reference< XResetListener >& _listener ) throw (RuntimeException)
253 : : {
254 : 18 : m_aResetHelper.addResetListener( _listener );
255 : 18 : }
256 : :
257 : : //--------------------------------------------------------------------
258 : 18 : void SAL_CALL OButtonModel::removeResetListener( const Reference< XResetListener >& _listener ) throw (RuntimeException)
259 : : {
260 : 18 : m_aResetHelper.removeResetListener( _listener );
261 : 18 : }
262 : :
263 : : //--------------------------------------------------------------------
264 : 3781 : void SAL_CALL OButtonModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
265 : : {
266 [ + + ]: 3781 : switch ( _nHandle )
267 : : {
268 : : case PROPERTY_ID_DEFAULT_STATE:
269 [ + - ]: 52 : _rValue <<= (sal_Int16)m_eDefaultState;
270 : 52 : break;
271 : :
272 : : default:
273 : 3729 : OClickableImageBaseModel::getFastPropertyValue( _rValue, _nHandle );
274 : 3729 : break;
275 : : }
276 : 3781 : }
277 : :
278 : : //--------------------------------------------------------------------
279 : 74 : void SAL_CALL OButtonModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw (Exception)
280 : : {
281 [ - + ]: 74 : switch ( _nHandle )
282 : : {
283 : : case PROPERTY_ID_DEFAULT_STATE:
284 : : {
285 : 0 : sal_Int16 nDefaultState( (sal_Int16)STATE_NOCHECK );
286 : 0 : OSL_VERIFY( _rValue >>= nDefaultState );
287 : 0 : m_eDefaultState = (ToggleState)nDefaultState;
288 [ # # ]: 0 : impl_resetNoBroadcast_nothrow();
289 : : }
290 : 0 : break;
291 : :
292 : : default:
293 : 74 : OClickableImageBaseModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
294 : 74 : break;
295 : : }
296 : 74 : }
297 : :
298 : : //--------------------------------------------------------------------
299 : 123 : sal_Bool SAL_CALL OButtonModel::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue ) throw (IllegalArgumentException)
300 : : {
301 : 123 : sal_Bool bModified = sal_False;
302 [ - + ]: 123 : switch ( _nHandle )
303 : : {
304 : : case PROPERTY_ID_DEFAULT_STATE:
305 [ # # ]: 0 : bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_eDefaultState );
306 : 0 : break;
307 : :
308 : : default:
309 : 123 : bModified = OClickableImageBaseModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
310 : 123 : break;
311 : : }
312 : 123 : return bModified;
313 : : }
314 : :
315 : : //--------------------------------------------------------------------
316 : 0 : Any OButtonModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
317 : : {
318 : 0 : Any aDefault;
319 [ # # ]: 0 : switch ( _nHandle )
320 : : {
321 : : case PROPERTY_ID_DEFAULT_STATE:
322 [ # # ]: 0 : aDefault <<= (sal_Int16)STATE_NOCHECK;
323 : 0 : break;
324 : :
325 : : default:
326 [ # # ]: 0 : aDefault = OClickableImageBaseModel::getPropertyDefaultByHandle( _nHandle );
327 : 0 : break;
328 : : }
329 : 0 : return aDefault;
330 : : }
331 : :
332 : : //--------------------------------------------------------------------
333 : 0 : void OButtonModel::impl_resetNoBroadcast_nothrow()
334 : : {
335 : : try
336 : : {
337 [ # # ][ # # ]: 0 : setPropertyValue( PROPERTY_STATE, getPropertyValue( PROPERTY_DEFAULT_STATE ) );
[ # # ][ # # ]
[ # # ]
338 : : }
339 : 0 : catch( const Exception& )
340 : : {
341 : : DBG_UNHANDLED_EXCEPTION();
342 : : }
343 : 0 : }
344 : :
345 : : //==================================================================
346 : : // OButtonControl
347 : : //==================================================================
348 : : //------------------------------------------------------------------
349 : 77 : InterfaceRef SAL_CALL OButtonControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
350 : : {
351 [ + - ]: 77 : return *(new OButtonControl(_rxFactory));
352 : : }
353 : :
354 : : //------------------------------------------------------------------------------
355 : 64 : Sequence<Type> OButtonControl::_getTypes()
356 : : {
357 : : return ::comphelper::concatSequences(
358 : : OButtonControl_BASE::getTypes(),
359 : : OClickableImageBaseControl::_getTypes(),
360 : : OFormNavigationHelper::getTypes()
361 [ + - ][ + - ]: 64 : );
[ + - ][ + - ]
[ + - ]
362 : : }
363 : :
364 : : //------------------------------------------------------------------------------
365 : 0 : StringSequence OButtonControl::getSupportedServiceNames() throw()
366 : : {
367 : 0 : StringSequence aSupported = OClickableImageBaseControl::getSupportedServiceNames();
368 [ # # ]: 0 : aSupported.realloc(aSupported.getLength() + 1);
369 : :
370 [ # # ]: 0 : ::rtl::OUString*pArray = aSupported.getArray();
371 [ # # ]: 0 : pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_COMMANDBUTTON;
372 : 0 : return aSupported;
373 : : }
374 : :
375 : : //------------------------------------------------------------------------------
376 : 77 : OButtonControl::OButtonControl(const Reference<XMultiServiceFactory>& _rxFactory)
377 : : :OClickableImageBaseControl(_rxFactory, VCL_CONTROL_COMMANDBUTTON)
378 : : ,OFormNavigationHelper( _rxFactory )
379 : : ,m_nClickEvent( 0 )
380 : : ,m_nTargetUrlFeatureId( -1 )
381 [ + - ][ + - ]: 77 : ,m_bEnabledByPropertyValue( sal_False )
[ + - ]
382 : : {
383 [ + - ]: 77 : increment(m_refCount);
384 : : {
385 : : // Register as ActionListener
386 : 77 : Reference<XButton> xButton;
387 [ + - ]: 77 : query_aggregation( m_xAggregate, xButton);
388 [ + - ]: 77 : if (xButton.is())
389 [ + - ][ + - ]: 77 : xButton->addActionListener(this);
[ + - ]
390 : : }
391 : : // For Listener: refcount at one
392 [ + - ]: 77 : decrement(m_refCount);
393 : 77 : }
394 : :
395 : : //------------------------------------------------------------------------------
396 [ + - ][ + - ]: 77 : OButtonControl::~OButtonControl()
397 : : {
398 [ - + ]: 77 : if (m_nClickEvent)
399 [ # # ]: 0 : Application::RemoveUserEvent(m_nClickEvent);
400 [ - + ]: 154 : }
401 : :
402 : : // UNO binding
403 : : //------------------------------------------------------------------------------
404 : 2301 : Any SAL_CALL OButtonControl::queryAggregation(const Type& _rType) throw (RuntimeException)
405 : : {
406 : : // if asked for the XTypeProvider, don't let OButtonControl_BASE do this
407 : 2301 : Any aReturn;
408 [ + + ][ + - ]: 2301 : if ( !_rType.equals( ::getCppuType( static_cast< Reference< XTypeProvider >* >( NULL ) ) ) )
409 [ + - ]: 2269 : aReturn = OButtonControl_BASE::queryInterface( _rType );
410 : :
411 [ + + ]: 2301 : if ( !aReturn.hasValue() )
412 [ + - ]: 1208 : aReturn = OClickableImageBaseControl::queryAggregation( _rType );
413 : :
414 [ + + ]: 2301 : if ( !aReturn.hasValue() )
415 [ + - ]: 166 : aReturn = OFormNavigationHelper::queryInterface( _rType );
416 : :
417 : 2301 : return aReturn;
418 : : }
419 : :
420 : : //------------------------------------------------------------------------------
421 : 77 : void SAL_CALL OButtonControl::disposing()
422 : : {
423 : 77 : startOrStopModelPropertyListening( false );
424 : :
425 : 77 : OClickableImageBaseControl::disposing();
426 : 77 : OFormNavigationHelper::dispose();
427 : 77 : }
428 : :
429 : : //------------------------------------------------------------------------------
430 : 259 : void SAL_CALL OButtonControl::disposing( const EventObject& _rSource ) throw( RuntimeException )
431 : : {
432 : 259 : OControl::disposing( _rSource );
433 : 259 : OFormNavigationHelper::disposing( _rSource );
434 : 259 : }
435 : :
436 : : // ActionListener
437 : : //------------------------------------------------------------------------------
438 : 2 : void OButtonControl::actionPerformed(const ActionEvent& /*rEvent*/) throw ( ::com::sun::star::uno::RuntimeException)
439 : : {
440 : : // Asynchronous for starutil::URL-Button
441 [ + - ]: 2 : sal_uLong n = Application::PostUserEvent( LINK(this, OButtonControl,OnClick) );
442 : : {
443 [ + - ]: 2 : ::osl::MutexGuard aGuard( m_aMutex );
444 [ + - ]: 2 : m_nClickEvent = n;
445 : : }
446 : 2 : }
447 : :
448 : : //------------------------------------------------------------------------------
449 : 2 : IMPL_LINK_NOARG(OButtonControl, OnClick)
450 : : {
451 [ + - ]: 2 : ::osl::ClearableMutexGuard aGuard( m_aMutex );
452 : 2 : m_nClickEvent = 0;
453 : :
454 [ + - ][ - + ]: 2 : if (m_aApproveActionListeners.getLength())
455 : : {
456 : : // if there are listeners, start the action in an own thread, to not allow
457 : : // them to block us here (we're in the application's main thread)
458 [ # # ][ # # ]: 0 : getImageProducerThread()->addEvent();
459 : : }
460 : : else
461 : : {
462 : : // Else, don't. We then must not notify the Listeners in any case,
463 : : // not even if added later on.
464 [ + - ]: 2 : aGuard.clear();
465 : :
466 : : // recognize the button type
467 [ + - ][ + - ]: 2 : Reference<XPropertySet> xSet(getModel(), UNO_QUERY);
468 [ - + ]: 2 : if (!xSet.is())
469 : 0 : return 0L;
470 : :
471 [ + - ][ + - ]: 2 : if (FormButtonType_PUSH == *(FormButtonType*)xSet->getPropertyValue(PROPERTY_BUTTONTYPE).getValue())
[ + - ][ + - ]
472 : : {
473 : : // notify the action listeners for a push button
474 [ + - ]: 2 : ::cppu::OInterfaceIteratorHelper aIter(m_aActionListeners);
475 [ + - ][ + - ]: 2 : ActionEvent aEvt(static_cast<XWeak*>(this), m_aActionCommand);
[ # # ]
476 [ + + ]: 4 : while(aIter.hasMoreElements() )
477 : : {
478 : : // catch exceptions
479 : : // and catch them on a per-listener basis - if one listener fails, the others still need
480 : : // to get notified
481 : : try
482 : : {
483 [ + - ][ + - ]: 2 : static_cast< XActionListener* >( aIter.next() )->actionPerformed(aEvt);
484 : : }
485 : : #ifdef DBG_UTIL
486 : : catch( const RuntimeException& )
487 : : {
488 : : // silence this
489 : : }
490 : : #endif
491 [ # # ]: 0 : catch( const Exception& )
492 : : {
493 : : OSL_FAIL( "OButtonControl::OnClick: caught a exception other than RuntimeException!" );
494 : : }
495 [ + - ][ + - ]: 2 : }
496 : : }
497 : : else
498 [ # # ][ # # ]: 2 : actionPerformed_Impl( sal_False, ::com::sun::star::awt::MouseEvent() );
[ # # ][ + - ]
499 : : }
500 [ + - ]: 2 : return 0L;
501 : : }
502 : :
503 : : //------------------------------------------------------------------------------
504 : 0 : void OButtonControl::actionPerformed_Impl( sal_Bool _bNotifyListener, const ::com::sun::star::awt::MouseEvent& _rEvt )
505 : : {
506 : : {
507 : 0 : sal_Int16 nFeatureId = -1;
508 : : {
509 [ # # ]: 0 : ::osl::MutexGuard aGuard( m_aMutex );
510 [ # # ]: 0 : nFeatureId = m_nTargetUrlFeatureId;
511 : : }
512 : :
513 [ # # ]: 0 : if ( nFeatureId != -1 )
514 : : {
515 [ # # ][ # # ]: 0 : if ( !approveAction() )
516 : : return;
517 : :
518 [ # # ]: 0 : SolarMutexGuard aGuard;
519 [ # # ]: 0 : dispatch( nFeatureId );
520 [ # # ]: 0 : return;
521 : : }
522 : : }
523 : :
524 : 0 : OClickableImageBaseControl::actionPerformed_Impl( _bNotifyListener, _rEvt );
525 : : }
526 : :
527 : : // XButton
528 : : //------------------------------------------------------------------------------
529 : 2 : void OButtonControl::setLabel(const ::rtl::OUString& Label) throw( RuntimeException )
530 : : {
531 : 2 : Reference<XButton> xButton;
532 [ + - ]: 2 : query_aggregation( m_xAggregate, xButton );
533 [ + - ]: 2 : if (xButton.is())
534 [ + - ][ + - ]: 2 : xButton->setLabel(Label);
535 : 2 : }
536 : :
537 : : //------------------------------------------------------------------------------
538 : 2 : void SAL_CALL OButtonControl::setActionCommand(const ::rtl::OUString& _rCommand) throw( RuntimeException )
539 : : {
540 : : {
541 [ + - ]: 2 : ::osl::MutexGuard aGuard( m_aMutex );
542 [ + - ]: 2 : m_aActionCommand = _rCommand;
543 : : }
544 : :
545 : 2 : Reference<XButton> xButton;
546 [ + - ]: 2 : query_aggregation( m_xAggregate, xButton);
547 [ + - ]: 2 : if (xButton.is())
548 [ + - ][ + - ]: 2 : xButton->setActionCommand(_rCommand);
549 : 2 : }
550 : :
551 : : //------------------------------------------------------------------------------
552 : 10 : void SAL_CALL OButtonControl::addActionListener(const Reference<XActionListener>& _rxListener) throw( RuntimeException )
553 : : {
554 : 10 : m_aActionListeners.addInterface(_rxListener);
555 : 10 : }
556 : :
557 : : //------------------------------------------------------------------------------
558 : 10 : void SAL_CALL OButtonControl::removeActionListener(const Reference<XActionListener>& _rxListener) throw( RuntimeException )
559 : : {
560 : 10 : m_aActionListeners.removeInterface(_rxListener);
561 : 10 : }
562 : :
563 : : //------------------------------------------------------------------------------
564 : 239 : class DoPropertyListening
565 : : {
566 : : private:
567 : : Reference< XPropertySet > m_xProps;
568 : : Reference< XPropertyChangeListener > m_xListener;
569 : : bool m_bStartListening;
570 : :
571 : : public:
572 : : DoPropertyListening(
573 : : const Reference< XInterface >& _rxComponent,
574 : : const Reference< XPropertyChangeListener >& _rxListener,
575 : : bool _bStart
576 : : );
577 : :
578 : : void handleListening( const ::rtl::OUString& _rPropertyName );
579 : : };
580 : :
581 : : //..............................................................................
582 : 239 : DoPropertyListening::DoPropertyListening(
583 : : const Reference< XInterface >& _rxComponent, const Reference< XPropertyChangeListener >& _rxListener,
584 : : bool _bStart )
585 : : :m_xProps( _rxComponent, UNO_QUERY )
586 : : ,m_xListener( _rxListener )
587 : 239 : ,m_bStartListening( _bStart )
588 : : {
589 : : DBG_ASSERT( m_xProps.is() || !_rxComponent.is(), "DoPropertyListening::DoPropertyListening: valid component, but no property set!" );
590 : : DBG_ASSERT( m_xListener.is(), "DoPropertyListening::DoPropertyListening: invalid listener!" );
591 : 239 : }
592 : :
593 : : //..............................................................................
594 : 717 : void DoPropertyListening::handleListening( const ::rtl::OUString& _rPropertyName )
595 : : {
596 [ + + ]: 717 : if ( m_xProps.is() )
597 : : {
598 [ + + ]: 387 : if ( m_bStartListening )
599 : 243 : m_xProps->addPropertyChangeListener( _rPropertyName, m_xListener );
600 : : else
601 : 144 : m_xProps->removePropertyChangeListener( _rPropertyName, m_xListener );
602 : : }
603 : 717 : }
604 : :
605 : : //------------------------------------------------------------------------------
606 : 239 : void OButtonControl::startOrStopModelPropertyListening( bool _bStart )
607 : : {
608 [ + - ][ + - ]: 239 : DoPropertyListening aListeningHandler( getModel(), this, _bStart );
[ + - ]
609 [ + - ][ + - ]: 239 : aListeningHandler.handleListening( PROPERTY_TARGET_URL );
610 [ + - ][ + - ]: 239 : aListeningHandler.handleListening( PROPERTY_BUTTONTYPE );
611 [ + - ][ + - ]: 239 : aListeningHandler.handleListening( PROPERTY_ENABLED );
[ + - ]
612 : 239 : }
613 : :
614 : : //------------------------------------------------------------------------------
615 : 81 : sal_Bool SAL_CALL OButtonControl::setModel( const Reference< XControlModel >& _rxModel ) throw ( RuntimeException )
616 : : {
617 [ + - ]: 81 : startOrStopModelPropertyListening( false );
618 [ + - ]: 81 : sal_Bool bResult = OClickableImageBaseControl::setModel( _rxModel );
619 [ + - ]: 81 : startOrStopModelPropertyListening( true );
620 : :
621 : 81 : m_bEnabledByPropertyValue = sal_True;
622 [ + - ]: 81 : Reference< XPropertySet > xModelProps( _rxModel, UNO_QUERY );
623 [ + - ]: 81 : if ( xModelProps.is() )
624 [ + - ][ + - ]: 81 : xModelProps->getPropertyValue( PROPERTY_ENABLED ) >>= m_bEnabledByPropertyValue;
[ + - ]
625 : :
626 [ + - ]: 81 : modelFeatureUrlPotentiallyChanged( );
627 : :
628 : 81 : return bResult;
629 : : }
630 : :
631 : : //------------------------------------------------------------------------------
632 : 81 : void OButtonControl::modelFeatureUrlPotentiallyChanged( )
633 : : {
634 : 81 : sal_Int16 nOldUrlFeatureId = m_nTargetUrlFeatureId;
635 : :
636 : : // doe we have another TargetURL now? If so, we need to update our dispatches
637 : 81 : m_nTargetUrlFeatureId = getModelUrlFeatureId( );
638 [ - + ]: 81 : if ( nOldUrlFeatureId != m_nTargetUrlFeatureId )
639 : : {
640 : 0 : invalidateSupportedFeaturesSet();
641 [ # # ]: 0 : if ( !isDesignMode() )
642 : 0 : updateDispatches( );
643 : : }
644 : 81 : }
645 : :
646 : : //------------------------------------------------------------------------------
647 : 0 : void SAL_CALL OButtonControl::propertyChange( const PropertyChangeEvent& _rEvent ) throw ( RuntimeException )
648 : : {
649 [ # # ]: 0 : if ( _rEvent.PropertyName.equals( PROPERTY_TARGET_URL )
[ # # # # ]
[ # # ]
[ # # # # ]
650 [ # # ][ # # ]: 0 : || _rEvent.PropertyName.equals( PROPERTY_BUTTONTYPE )
[ # # ]
651 : : )
652 : : {
653 : 0 : modelFeatureUrlPotentiallyChanged( );
654 : : }
655 [ # # ]: 0 : else if ( _rEvent.PropertyName.equals( PROPERTY_ENABLED ) )
656 : : {
657 : 0 : _rEvent.NewValue >>= m_bEnabledByPropertyValue;
658 : : }
659 : 0 : }
660 : :
661 : : //------------------------------------------------------------------------------
662 : : namespace
663 : : {
664 : 0 : bool isFormControllerURL( const ::rtl::OUString& _rURL )
665 : : {
666 : 0 : const sal_Int32 nPrefixLen = URL_CONTROLLER_PREFIX.length;
667 : 0 : return ( _rURL.getLength() > nPrefixLen )
668 [ # # ][ # # ]: 0 : && ( _rURL.compareToAscii( URL_CONTROLLER_PREFIX.ascii, nPrefixLen ) == 0 );
669 : : }
670 : : }
671 : :
672 : : //------------------------------------------------------------------------------
673 : 81 : sal_Int16 OButtonControl::getModelUrlFeatureId( ) const
674 : : {
675 : 81 : sal_Int16 nFeatureId = -1;
676 : :
677 : : // some URL related properties of the model
678 : 81 : ::rtl::OUString sUrl;
679 : 81 : FormButtonType eButtonType = FormButtonType_PUSH;
680 : :
681 [ + - ][ + - ]: 81 : Reference< XPropertySet > xModelProps( const_cast< OButtonControl* >( this )->getModel(), UNO_QUERY );
682 [ + - ]: 81 : if ( xModelProps.is() )
683 : : {
684 [ + - ][ + - ]: 81 : xModelProps->getPropertyValue( PROPERTY_TARGET_URL ) >>= sUrl;
[ + - ]
685 [ + - ][ + - ]: 81 : xModelProps->getPropertyValue( PROPERTY_BUTTONTYPE ) >>= eButtonType;
[ + - ][ + - ]
686 : : }
687 : :
688 : : // are we a URL button?
689 [ - + ]: 81 : if ( eButtonType == FormButtonType_URL )
690 : : {
691 : : // is it a feature URL?
692 [ # # ]: 0 : if ( isFormControllerURL( sUrl ) )
693 : : {
694 [ # # ][ # # ]: 0 : OFormNavigationMapper aMapper( m_aContext.getLegacyServiceFactory() );
695 [ # # ][ # # ]: 0 : nFeatureId = aMapper.getFeatureId( sUrl );
696 : : }
697 : : }
698 : :
699 : 81 : return nFeatureId;
700 : : }
701 : :
702 : : //------------------------------------------------------------------
703 : 50 : void SAL_CALL OButtonControl::setDesignMode( sal_Bool _bOn ) throw( RuntimeException )
704 : : {
705 : 50 : OClickableImageBaseControl::setDesignMode( _bOn );
706 : :
707 [ + + ]: 50 : if ( _bOn )
708 : 30 : disconnectDispatchers();
709 : : else
710 : 20 : connectDispatchers();
711 : : // this will connect if not already connected and just update else
712 : 50 : }
713 : :
714 : : //------------------------------------------------------------------------------
715 : 56 : void OButtonControl::getSupportedFeatures( ::std::vector< sal_Int16 >& /* [out] */ _rFeatureIds )
716 : : {
717 [ - + ]: 56 : if ( -1 != m_nTargetUrlFeatureId )
718 : 0 : _rFeatureIds.push_back( m_nTargetUrlFeatureId );
719 : 56 : }
720 : :
721 : : //------------------------------------------------------------------
722 : 0 : void OButtonControl::featureStateChanged( sal_Int16 _nFeatureId, sal_Bool _bEnabled )
723 : : {
724 [ # # ]: 0 : if ( _nFeatureId == m_nTargetUrlFeatureId )
725 : : {
726 : : // enable or disable our peer, according to the new state
727 [ # # ][ # # ]: 0 : Reference< XVclWindowPeer > xPeer( getPeer(), UNO_QUERY );
728 [ # # ]: 0 : if ( xPeer.is() )
729 [ # # ][ # # ]: 0 : xPeer->setProperty( PROPERTY_ENABLED, makeAny( m_bEnabledByPropertyValue ? _bEnabled : sal_False ) );
[ # # ][ # # ]
[ # # ]
730 : : // if we're disabled according to our model's property, then
731 : : // we don't care for the feature state, but *are* disabled.
732 : : // If the model's property states that we're enabled, then we *do*
733 : : // care for the feature state
734 : : }
735 : :
736 : : // base class
737 : 0 : OFormNavigationHelper::featureStateChanged( _nFeatureId, _bEnabled );
738 : 0 : }
739 : :
740 : : //------------------------------------------------------------------
741 : 163 : void OButtonControl::allFeatureStatesChanged( )
742 : : {
743 [ - + ]: 163 : if ( -1 != m_nTargetUrlFeatureId )
744 : : // we have only one supported feature, so simulate it has changed ...
745 : 0 : featureStateChanged( m_nTargetUrlFeatureId, isEnabled( m_nTargetUrlFeatureId ) );
746 : :
747 : : // base class
748 : 163 : OFormNavigationHelper::allFeatureStatesChanged( );
749 : 163 : }
750 : :
751 : : //------------------------------------------------------------------
752 : 0 : bool OButtonControl::isEnabled( sal_Int16 _nFeatureId ) const
753 : : {
754 [ # # ]: 0 : if ( const_cast< OButtonControl* >( this )->isDesignMode() )
755 : : // TODO: the model property?
756 : 0 : return true;
757 : :
758 : 0 : return OFormNavigationHelper::isEnabled( _nFeatureId );
759 : : }
760 : :
761 : : //--------------------------------------------------------------------
762 : 18 : void SAL_CALL OButtonControl::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException)
763 : : {
764 : 18 : OClickableImageBaseControl::registerDispatchProviderInterceptor( _rxInterceptor );
765 : 18 : OFormNavigationHelper::registerDispatchProviderInterceptor( _rxInterceptor );
766 : 18 : }
767 : :
768 : : //--------------------------------------------------------------------
769 : 18 : void SAL_CALL OButtonControl::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException)
770 : : {
771 : 18 : OClickableImageBaseControl::releaseDispatchProviderInterceptor( _rxInterceptor );
772 : 18 : OFormNavigationHelper::releaseDispatchProviderInterceptor( _rxInterceptor );
773 : 18 : }
774 : :
775 : : //.........................................................................
776 : : } // namespace frm
777 : : //.........................................................................
778 : :
779 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|