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