update dev300-m58
[ooovba.git] / forms / source / component / Button.cxx
blob5045c9fdbda87e304cc8a653c9ce7bc675ef040c
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: Button.cxx,v $
10 * $Revision: 1.22 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_forms.hxx"
34 #include "Button.hxx"
36 #include <com/sun/star/awt/XVclWindowPeer.hpp>
38 #include <comphelper/streamsection.hxx>
39 #include <comphelper/basicio.hxx>
40 #include <tools/diagnose_ex.h>
41 #include <tools/debug.hxx>
42 #include <tools/urlobj.hxx>
43 #include <vcl/svapp.hxx>
44 #include <vos/mutex.hxx>
46 //.........................................................................
47 namespace frm
49 //.........................................................................
51 using namespace ::com::sun::star::uno;
52 using namespace ::com::sun::star::sdb;
53 using namespace ::com::sun::star::sdbc;
54 using namespace ::com::sun::star::sdbcx;
55 using namespace ::com::sun::star::beans;
56 using namespace ::com::sun::star::container;
57 using namespace ::com::sun::star::form;
58 using namespace ::com::sun::star::awt;
59 using namespace ::com::sun::star::io;
60 using namespace ::com::sun::star::lang;
61 using namespace ::com::sun::star::util;
62 using ::com::sun::star::frame::XDispatchProviderInterceptor;
64 //==================================================================
65 //= OButtonModel
66 //==================================================================
67 DBG_NAME(OButtonModel)
68 //------------------------------------------------------------------
69 InterfaceRef SAL_CALL OButtonModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
71 return *(new OButtonModel(_rxFactory));
74 //------------------------------------------------------------------
75 OButtonModel::OButtonModel(const Reference<XMultiServiceFactory>& _rxFactory)
76 :OClickableImageBaseModel( _rxFactory, VCL_CONTROLMODEL_COMMANDBUTTON, FRM_SUN_CONTROL_COMMANDBUTTON )
77 // use the old control name for compatibility reasons
78 ,m_aResetHelper( *this, m_aMutex )
79 ,m_eDefaultState( STATE_NOCHECK )
81 DBG_CTOR( OButtonModel, NULL );
82 m_nClassId = FormComponentType::COMMANDBUTTON;
85 //------------------------------------------------------------------
86 Any SAL_CALL OButtonModel::queryAggregation( const Type& _type ) throw(RuntimeException)
88 Any aReturn = OClickableImageBaseModel::queryAggregation( _type );
89 if ( !aReturn.hasValue() )
90 aReturn = OButtonModel_Base::queryInterface( _type );
91 return aReturn;
94 //------------------------------------------------------------------
95 Sequence< Type > OButtonModel::_getTypes()
97 return ::comphelper::concatSequences(
98 OClickableImageBaseModel::_getTypes(),
99 OButtonModel_Base::getTypes()
103 //------------------------------------------------------------------
104 OButtonModel::OButtonModel( const OButtonModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory )
105 :OClickableImageBaseModel( _pOriginal, _rxFactory )
106 ,m_aResetHelper( *this, m_aMutex )
107 ,m_eDefaultState( _pOriginal->m_eDefaultState )
109 DBG_CTOR( OButtonModel, NULL );
110 m_nClassId = FormComponentType::COMMANDBUTTON;
112 implInitializeImageURL();
115 //------------------------------------------------------------------------------
116 OButtonModel::~OButtonModel()
118 DBG_DTOR(OButtonModel, NULL);
121 //------------------------------------------------------------------------------
122 void OButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const
124 BEGIN_DESCRIBE_PROPERTIES( 6, OClickableImageBaseModel )
125 DECL_PROP1( BUTTONTYPE, FormButtonType, BOUND );
126 DECL_PROP1( DEFAULT_STATE, sal_Int16, BOUND );
127 DECL_PROP1( DISPATCHURLINTERNAL, sal_Bool, BOUND );
128 DECL_PROP1( TARGET_URL, ::rtl::OUString, BOUND );
129 DECL_PROP1( TARGET_FRAME, ::rtl::OUString, BOUND );
130 DECL_PROP1( TABINDEX, sal_Int16, BOUND );
131 END_DESCRIBE_PROPERTIES();
134 //------------------------------------------------------------------------------
135 IMPLEMENT_DEFAULT_CLONING( OButtonModel )
137 // XServiceInfo
138 //------------------------------------------------------------------------------
139 StringSequence OButtonModel::getSupportedServiceNames() throw()
141 StringSequence aSupported = OClickableImageBaseModel::getSupportedServiceNames();
142 aSupported.realloc( aSupported.getLength() + 1 );
144 ::rtl::OUString* pArray = aSupported.getArray();
145 pArray[ aSupported.getLength() - 1 ] = FRM_SUN_COMPONENT_COMMANDBUTTON;
147 return aSupported;
150 //------------------------------------------------------------------------------
151 ::rtl::OUString OButtonModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
153 return FRM_COMPONENT_COMMANDBUTTON; // old (non-sun) name for compatibility !
156 //------------------------------------------------------------------------------
157 void OButtonModel::write(const Reference<XObjectOutputStream>& _rxOutStream) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
159 OClickableImageBaseModel::write(_rxOutStream);
161 _rxOutStream->writeShort(0x0003); // Version
164 OStreamSection aSection( _rxOutStream.get() );
165 // this will allow readers to skip unknown bytes in their dtor
167 _rxOutStream->writeShort( (sal_uInt16)m_eButtonType );
169 ::rtl::OUString sTmp = INetURLObject::decode( m_sTargetURL, '%', INetURLObject::DECODE_UNAMBIGUOUS);
170 _rxOutStream << sTmp;
171 _rxOutStream << m_sTargetFrame;
172 writeHelpTextCompatibly(_rxOutStream);
173 _rxOutStream << isDispatchUrlInternal();
177 //------------------------------------------------------------------------------
178 void OButtonModel::read(const Reference<XObjectInputStream>& _rxInStream) throw (::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
180 OClickableImageBaseModel::read(_rxInStream);
182 sal_uInt16 nVersion = _rxInStream->readShort(); // Version
183 switch (nVersion)
185 case 0x0001:
187 m_eButtonType = (FormButtonType)_rxInStream->readShort();
189 _rxInStream >> m_sTargetURL;
190 _rxInStream >> m_sTargetFrame;
192 break;
194 case 0x0002:
196 m_eButtonType = (FormButtonType)_rxInStream->readShort();
198 _rxInStream >> m_sTargetURL;
199 _rxInStream >> m_sTargetFrame;
200 readHelpTextCompatibly(_rxInStream);
202 break;
204 case 0x0003:
206 OStreamSection aSection( _rxInStream.get() );
207 // this will skip any unknown bytes in it's dtor
209 // button type
210 m_eButtonType = (FormButtonType)_rxInStream->readShort();
212 // URL
213 _rxInStream >> m_sTargetURL;
215 // target frame
216 _rxInStream >> m_sTargetFrame;
218 // help text
219 readHelpTextCompatibly(_rxInStream);
221 // DispatchInternal
222 sal_Bool bDispath;
223 _rxInStream >> bDispath;
224 setDispatchUrlInternal(bDispath);
226 break;
228 default:
229 DBG_ERROR("OButtonModel::read : unknown version !");
230 m_eButtonType = FormButtonType_PUSH;
231 m_sTargetURL = ::rtl::OUString();
232 m_sTargetFrame = ::rtl::OUString();
233 break;
237 //--------------------------------------------------------------------
238 void SAL_CALL OButtonModel::disposing()
240 m_aResetHelper.disposing();
241 OClickableImageBaseModel::disposing();
244 //--------------------------------------------------------------------
245 void SAL_CALL OButtonModel::reset() throw (RuntimeException)
247 if ( !m_aResetHelper.approveReset() )
248 return;
250 impl_resetNoBroadcast_nothrow();
252 m_aResetHelper.notifyResetted();
255 //--------------------------------------------------------------------
256 void SAL_CALL OButtonModel::addResetListener( const Reference< XResetListener >& _listener ) throw (RuntimeException)
258 m_aResetHelper.addResetListener( _listener );
261 //--------------------------------------------------------------------
262 void SAL_CALL OButtonModel::removeResetListener( const Reference< XResetListener >& _listener ) throw (RuntimeException)
264 m_aResetHelper.removeResetListener( _listener );
267 //--------------------------------------------------------------------
268 void SAL_CALL OButtonModel::getFastPropertyValue( Any& _rValue, sal_Int32 _nHandle ) const
270 switch ( _nHandle )
272 case PROPERTY_ID_DEFAULT_STATE:
273 _rValue <<= (sal_Int16)m_eDefaultState;
274 break;
276 default:
277 OClickableImageBaseModel::getFastPropertyValue( _rValue, _nHandle );
278 break;
282 //--------------------------------------------------------------------
283 void SAL_CALL OButtonModel::setFastPropertyValue_NoBroadcast( sal_Int32 _nHandle, const Any& _rValue ) throw (Exception)
285 switch ( _nHandle )
287 case PROPERTY_ID_DEFAULT_STATE:
289 sal_Int16 nDefaultState( (sal_Int16)STATE_NOCHECK );
290 OSL_VERIFY( _rValue >>= nDefaultState );
291 m_eDefaultState = (ToggleState)nDefaultState;
292 impl_resetNoBroadcast_nothrow();
294 break;
296 default:
297 OClickableImageBaseModel::setFastPropertyValue_NoBroadcast( _nHandle, _rValue );
298 break;
302 //--------------------------------------------------------------------
303 sal_Bool SAL_CALL OButtonModel::convertFastPropertyValue( Any& _rConvertedValue, Any& _rOldValue, sal_Int32 _nHandle, const Any& _rValue ) throw (IllegalArgumentException)
305 sal_Bool bModified = sal_False;
306 switch ( _nHandle )
308 case PROPERTY_ID_DEFAULT_STATE:
309 bModified = tryPropertyValue( _rConvertedValue, _rOldValue, _rValue, (sal_Int16)m_eDefaultState );
310 break;
312 default:
313 bModified = OClickableImageBaseModel::convertFastPropertyValue( _rConvertedValue, _rOldValue, _nHandle, _rValue );
314 break;
316 return bModified;
319 //--------------------------------------------------------------------
320 Any OButtonModel::getPropertyDefaultByHandle( sal_Int32 _nHandle ) const
322 Any aDefault;
323 switch ( _nHandle )
325 case PROPERTY_ID_DEFAULT_STATE:
326 aDefault <<= (sal_Int16)STATE_NOCHECK;
327 break;
329 default:
330 aDefault = OClickableImageBaseModel::getPropertyDefaultByHandle( _nHandle );
331 break;
333 return aDefault;
336 //--------------------------------------------------------------------
337 void OButtonModel::impl_resetNoBroadcast_nothrow()
341 setPropertyValue( PROPERTY_STATE, getPropertyValue( PROPERTY_DEFAULT_STATE ) );
343 catch( const Exception& )
345 DBG_UNHANDLED_EXCEPTION();
349 //==================================================================
350 // OButtonControl
351 //==================================================================
352 //------------------------------------------------------------------
353 InterfaceRef SAL_CALL OButtonControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
355 return *(new OButtonControl(_rxFactory));
358 //------------------------------------------------------------------------------
359 Sequence<Type> OButtonControl::_getTypes()
361 return ::comphelper::concatSequences(
362 OButtonControl_BASE::getTypes(),
363 OClickableImageBaseControl::_getTypes(),
364 OFormNavigationHelper::getTypes()
368 //------------------------------------------------------------------------------
369 StringSequence OButtonControl::getSupportedServiceNames() throw()
371 StringSequence aSupported = OClickableImageBaseControl::getSupportedServiceNames();
372 aSupported.realloc(aSupported.getLength() + 1);
374 ::rtl::OUString*pArray = aSupported.getArray();
375 pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_COMMANDBUTTON;
376 return aSupported;
379 //------------------------------------------------------------------------------
380 OButtonControl::OButtonControl(const Reference<XMultiServiceFactory>& _rxFactory)
381 :OClickableImageBaseControl(_rxFactory, VCL_CONTROL_COMMANDBUTTON)
382 ,OFormNavigationHelper( _rxFactory )
383 ,m_nClickEvent( 0 )
384 ,m_nTargetUrlFeatureId( -1 )
385 ,m_bEnabledByPropertyValue( sal_False )
387 increment(m_refCount);
389 // als ActionListener anmelden
390 Reference<XButton> xButton;
391 query_aggregation( m_xAggregate, xButton);
392 if (xButton.is())
393 xButton->addActionListener(this);
395 // Refcount bei 1 fuer Listener
396 decrement(m_refCount);
399 //------------------------------------------------------------------------------
400 OButtonControl::~OButtonControl()
402 if (m_nClickEvent)
403 Application::RemoveUserEvent(m_nClickEvent);
406 // UNO Anbindung
407 //------------------------------------------------------------------------------
408 Any SAL_CALL OButtonControl::queryAggregation(const Type& _rType) throw (RuntimeException)
410 // if asked for the XTypeProvider, don't let OButtonControl_BASE do this
411 Any aReturn;
412 if ( !_rType.equals( ::getCppuType( static_cast< Reference< XTypeProvider >* >( NULL ) ) ) )
413 aReturn = OButtonControl_BASE::queryInterface( _rType );
415 if ( !aReturn.hasValue() )
416 aReturn = OClickableImageBaseControl::queryAggregation( _rType );
418 if ( !aReturn.hasValue() )
419 aReturn = OFormNavigationHelper::queryInterface( _rType );
421 return aReturn;
424 //------------------------------------------------------------------------------
425 void SAL_CALL OButtonControl::disposing()
427 startOrStopModelPropertyListening( false );
429 OClickableImageBaseControl::disposing();
430 OFormNavigationHelper::dispose();
433 //------------------------------------------------------------------------------
434 void SAL_CALL OButtonControl::disposing( const EventObject& _rSource ) throw( RuntimeException )
436 OControl::disposing( _rSource );
437 OFormNavigationHelper::disposing( _rSource );
440 // ActionListener
441 //------------------------------------------------------------------------------
442 void OButtonControl::actionPerformed(const ActionEvent& /*rEvent*/) throw ( ::com::sun::star::uno::RuntimeException)
444 // Asynchron fuer starutil::URL-Button
445 sal_uInt32 n = Application::PostUserEvent( LINK(this, OButtonControl,OnClick) );
447 ::osl::MutexGuard aGuard( m_aMutex );
448 m_nClickEvent = n;
452 //------------------------------------------------------------------------------
453 IMPL_LINK( OButtonControl, OnClick, void*, EMPTYARG )
455 ::osl::ClearableMutexGuard aGuard( m_aMutex );
456 m_nClickEvent = 0;
458 if (m_aApproveActionListeners.getLength())
460 // if there are listeners, start the action in an own thread, to not allow
461 // them to block us here (we're in the application's main thread)
462 getImageProducerThread()->addEvent();
464 else
466 // Sonst nicht. Dann darf man aber auf keinen Fal die Listener
467 // benachrichtigen, auch dann nicht, wenn er spaeter hinzukommt.
468 aGuard.clear();
470 // recognize the button type
471 Reference<XPropertySet> xSet(getModel(), UNO_QUERY);
472 if (!xSet.is())
473 return 0L;
475 if (FormButtonType_PUSH == *(FormButtonType*)xSet->getPropertyValue(PROPERTY_BUTTONTYPE).getValue())
477 // notify the action listeners for a push button
478 ::cppu::OInterfaceIteratorHelper aIter(m_aActionListeners);
479 ActionEvent aEvt(static_cast<XWeak*>(this), m_aActionCommand);
480 while(aIter.hasMoreElements() )
482 // catch exceptions
483 // and catch them on a per-listener basis - if one listener fails, the others still need
484 // to get notified
485 // 97676 - 21.02.2002 - fs@openoffice.org
488 static_cast< XActionListener* >( aIter.next() )->actionPerformed(aEvt);
490 #ifdef DBG_UTIL
491 catch( const RuntimeException& )
493 // silent this
495 #endif
496 catch( const Exception& )
498 DBG_ERROR( "OButtonControl::OnClick: caught a exception other than RuntimeException!" );
502 else
503 actionPerformed_Impl( sal_False, ::com::sun::star::awt::MouseEvent() );
505 return 0L;
508 //------------------------------------------------------------------------------
509 void OButtonControl::actionPerformed_Impl( sal_Bool _bNotifyListener, const ::com::sun::star::awt::MouseEvent& _rEvt )
512 sal_Int32 nFeatureId = -1;
514 ::osl::MutexGuard aGuard( m_aMutex );
515 nFeatureId = m_nTargetUrlFeatureId;
518 if ( nFeatureId != -1 )
520 if ( !approveAction() )
521 return;
523 ::vos::OGuard aGuard( Application::GetSolarMutex() );
524 dispatch( nFeatureId );
525 return;
529 OClickableImageBaseControl::actionPerformed_Impl( _bNotifyListener, _rEvt );
532 // XButton
533 //------------------------------------------------------------------------------
534 void OButtonControl::setLabel(const ::rtl::OUString& Label) throw( RuntimeException )
536 Reference<XButton> xButton;
537 query_aggregation( m_xAggregate, xButton );
538 if (xButton.is())
539 xButton->setLabel(Label);
542 //------------------------------------------------------------------------------
543 void SAL_CALL OButtonControl::setActionCommand(const ::rtl::OUString& _rCommand) throw( RuntimeException )
546 ::osl::MutexGuard aGuard( m_aMutex );
547 m_aActionCommand = _rCommand;
550 Reference<XButton> xButton;
551 query_aggregation( m_xAggregate, xButton);
552 if (xButton.is())
553 xButton->setActionCommand(_rCommand);
556 //------------------------------------------------------------------------------
557 void SAL_CALL OButtonControl::addActionListener(const Reference<XActionListener>& _rxListener) throw( RuntimeException )
559 m_aActionListeners.addInterface(_rxListener);
562 //------------------------------------------------------------------------------
563 void SAL_CALL OButtonControl::removeActionListener(const Reference<XActionListener>& _rxListener) throw( RuntimeException )
565 m_aActionListeners.removeInterface(_rxListener);
568 //------------------------------------------------------------------------------
569 class DoPropertyListening
571 private:
572 Reference< XPropertySet > m_xProps;
573 Reference< XPropertyChangeListener > m_xListener;
574 bool m_bStartListening;
576 public:
577 DoPropertyListening(
578 const Reference< XInterface >& _rxComponent,
579 const Reference< XPropertyChangeListener >& _rxListener,
580 bool _bStart
583 void handleListening( const ::rtl::OUString& _rPropertyName );
586 //..............................................................................
587 DoPropertyListening::DoPropertyListening(
588 const Reference< XInterface >& _rxComponent, const Reference< XPropertyChangeListener >& _rxListener,
589 bool _bStart )
590 :m_xProps( _rxComponent, UNO_QUERY )
591 ,m_xListener( _rxListener )
592 ,m_bStartListening( _bStart )
594 DBG_ASSERT( m_xProps.is() || !_rxComponent.is(), "DoPropertyListening::DoPropertyListening: valid component, but no property set!" );
595 DBG_ASSERT( m_xListener.is(), "DoPropertyListening::DoPropertyListening: invalid listener!" );
598 //..............................................................................
599 void DoPropertyListening::handleListening( const ::rtl::OUString& _rPropertyName )
601 if ( m_xProps.is() )
603 if ( m_bStartListening )
604 m_xProps->addPropertyChangeListener( _rPropertyName, m_xListener );
605 else
606 m_xProps->removePropertyChangeListener( _rPropertyName, m_xListener );
610 //------------------------------------------------------------------------------
611 void OButtonControl::startOrStopModelPropertyListening( bool _bStart )
613 DoPropertyListening aListeningHandler( getModel(), this, _bStart );
614 aListeningHandler.handleListening( PROPERTY_TARGET_URL );
615 aListeningHandler.handleListening( PROPERTY_BUTTONTYPE );
616 aListeningHandler.handleListening( PROPERTY_ENABLED );
619 //------------------------------------------------------------------------------
620 sal_Bool SAL_CALL OButtonControl::setModel( const Reference< XControlModel >& _rxModel ) throw ( RuntimeException )
622 startOrStopModelPropertyListening( false );
623 sal_Bool bResult = OClickableImageBaseControl::setModel( _rxModel );
624 startOrStopModelPropertyListening( true );
626 m_bEnabledByPropertyValue = sal_True;
627 Reference< XPropertySet > xModelProps( _rxModel, UNO_QUERY );
628 if ( xModelProps.is() )
629 xModelProps->getPropertyValue( PROPERTY_ENABLED ) >>= m_bEnabledByPropertyValue;
631 modelFeatureUrlPotentiallyChanged( );
633 return bResult;
636 //------------------------------------------------------------------------------
637 void OButtonControl::modelFeatureUrlPotentiallyChanged( )
639 sal_Int32 nOldUrlFeatureId = m_nTargetUrlFeatureId;
641 // doe we have another TargetURL now? If so, we need to update our dispatches
642 m_nTargetUrlFeatureId = getModelUrlFeatureId( );
643 if ( nOldUrlFeatureId != m_nTargetUrlFeatureId )
645 invalidateSupportedFeaturesSet();
646 if ( !isDesignMode() )
647 updateDispatches( );
651 //------------------------------------------------------------------------------
652 void SAL_CALL OButtonControl::propertyChange( const PropertyChangeEvent& _rEvent ) throw ( RuntimeException )
654 if ( _rEvent.PropertyName.equals( PROPERTY_TARGET_URL )
655 || _rEvent.PropertyName.equals( PROPERTY_BUTTONTYPE )
658 modelFeatureUrlPotentiallyChanged( );
660 else if ( _rEvent.PropertyName.equals( PROPERTY_ENABLED ) )
662 _rEvent.NewValue >>= m_bEnabledByPropertyValue;
666 //------------------------------------------------------------------------------
667 namespace
669 bool isFormControllerURL( const ::rtl::OUString& _rURL )
671 const sal_Int32 nPrefixLen = URL_CONTROLLER_PREFIX.length;
672 return ( _rURL.getLength() > nPrefixLen )
673 && ( _rURL.compareToAscii( URL_CONTROLLER_PREFIX, nPrefixLen ) == 0 );
677 //------------------------------------------------------------------------------
678 sal_Int32 OButtonControl::getModelUrlFeatureId( ) const
680 sal_Int32 nFeatureId = -1;
682 // some URL related properties of the model
683 ::rtl::OUString sUrl;
684 FormButtonType eButtonType = FormButtonType_PUSH;
686 Reference< XPropertySet > xModelProps( const_cast< OButtonControl* >( this )->getModel(), UNO_QUERY );
687 if ( xModelProps.is() )
689 xModelProps->getPropertyValue( PROPERTY_TARGET_URL ) >>= sUrl;
690 xModelProps->getPropertyValue( PROPERTY_BUTTONTYPE ) >>= eButtonType;
693 // are we an URL button?
694 if ( eButtonType == FormButtonType_URL )
696 // is it a feature URL?
697 if ( isFormControllerURL( sUrl ) )
699 OFormNavigationMapper aMapper( m_aContext.getLegacyServiceFactory() );
700 nFeatureId = aMapper.getFeatureId( sUrl );
704 return nFeatureId;
707 //------------------------------------------------------------------
708 void SAL_CALL OButtonControl::setDesignMode( sal_Bool _bOn ) throw( RuntimeException )
710 OClickableImageBaseControl::setDesignMode( _bOn );
712 if ( _bOn )
713 disconnectDispatchers();
714 else
715 connectDispatchers();
716 // this will connect if not already connected and just update else
719 //------------------------------------------------------------------------------
720 void OButtonControl::getSupportedFeatures( ::std::vector< sal_Int32 >& /* [out] */ _rFeatureIds )
722 if ( -1 != m_nTargetUrlFeatureId )
723 _rFeatureIds.push_back( m_nTargetUrlFeatureId );
726 //------------------------------------------------------------------
727 void OButtonControl::featureStateChanged( sal_Int32 _nFeatureId, sal_Bool _bEnabled )
729 if ( _nFeatureId == m_nTargetUrlFeatureId )
731 // enable or disable our peer, according to the new state
732 Reference< XVclWindowPeer > xPeer( getPeer(), UNO_QUERY );
733 if ( xPeer.is() )
734 xPeer->setProperty( PROPERTY_ENABLED, makeAny( m_bEnabledByPropertyValue ? _bEnabled : sal_False ) );
735 // if we're disabled according to our model's property, then
736 // we don't care for the feature state, but *are* disabled.
737 // If the model's property states that we're enabled, then we *do*
738 // care for the feature state
741 // base class
742 OFormNavigationHelper::featureStateChanged( _nFeatureId, _bEnabled );
745 //------------------------------------------------------------------
746 void OButtonControl::allFeatureStatesChanged( )
748 if ( -1 != m_nTargetUrlFeatureId )
749 // we have only one supported feature, so simulate it has changed ...
750 featureStateChanged( m_nTargetUrlFeatureId, isEnabled( m_nTargetUrlFeatureId ) );
752 // base class
753 OFormNavigationHelper::allFeatureStatesChanged( );
756 //------------------------------------------------------------------
757 bool OButtonControl::isEnabled( sal_Int32 _nFeatureId ) const
759 if ( const_cast< OButtonControl* >( this )->isDesignMode() )
760 // TODO: the model property?
761 return true;
763 return OFormNavigationHelper::isEnabled( _nFeatureId );
766 //--------------------------------------------------------------------
767 void SAL_CALL OButtonControl::registerDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException)
769 OClickableImageBaseControl::registerDispatchProviderInterceptor( _rxInterceptor );
770 OFormNavigationHelper::registerDispatchProviderInterceptor( _rxInterceptor );
773 //--------------------------------------------------------------------
774 void SAL_CALL OButtonControl::releaseDispatchProviderInterceptor( const Reference< XDispatchProviderInterceptor >& _rxInterceptor ) throw (RuntimeException)
776 OClickableImageBaseControl::releaseDispatchProviderInterceptor( _rxInterceptor );
777 OFormNavigationHelper::releaseDispatchProviderInterceptor( _rxInterceptor );
780 //.........................................................................
781 } // namespace frm
782 //.........................................................................