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