1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: ImageButton.cxx,v $
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"
33 #include "ImageButton.hxx"
34 #include <tools/debug.hxx>
35 #include <tools/urlobj.hxx>
36 #include <vcl/svapp.hxx>
37 #include <vos/mutex.hxx>
38 #include <comphelper/basicio.hxx>
39 #include <com/sun/star/awt/MouseButton.hpp>
41 //.........................................................................
44 //.........................................................................
45 using namespace ::com::sun::star
;
46 using namespace ::com::sun::star::uno
;
47 using namespace ::com::sun::star::sdb
;
48 using namespace ::com::sun::star::sdbc
;
49 using namespace ::com::sun::star::sdbcx
;
50 using namespace ::com::sun::star::beans
;
51 using namespace ::com::sun::star::container
;
52 using namespace ::com::sun::star::form
;
53 using namespace ::com::sun::star::io
;
54 using namespace ::com::sun::star::lang
;
55 using namespace ::com::sun::star::util
;
57 //==================================================================
59 //==================================================================
60 DBG_NAME(OImageButtonModel
)
61 //------------------------------------------------------------------
62 InterfaceRef SAL_CALL
OImageButtonModel_CreateInstance(const Reference
<XMultiServiceFactory
>& _rxFactory
)
64 return *(new OImageButtonModel(_rxFactory
));
67 //------------------------------------------------------------------
68 OImageButtonModel::OImageButtonModel(const Reference
<XMultiServiceFactory
>& _rxFactory
)
69 :OClickableImageBaseModel( _rxFactory
, VCL_CONTROLMODEL_IMAGEBUTTON
, FRM_SUN_CONTROL_IMAGEBUTTON
)
70 // use the old control name for compytibility reasons
72 DBG_CTOR(OImageButtonModel
, NULL
);
73 m_nClassId
= FormComponentType::IMAGEBUTTON
;
76 //------------------------------------------------------------------
77 OImageButtonModel::OImageButtonModel( const OImageButtonModel
* _pOriginal
, const Reference
<XMultiServiceFactory
>& _rxFactory
)
78 :OClickableImageBaseModel( _pOriginal
, _rxFactory
)
80 DBG_CTOR(OImageButtonModel
, NULL
);
81 implInitializeImageURL();
84 //------------------------------------------------------------------------------
85 IMPLEMENT_DEFAULT_CLONING( OImageButtonModel
)
87 //------------------------------------------------------------------------------
88 OImageButtonModel::~OImageButtonModel()
90 DBG_DTOR(OImageButtonModel
, NULL
);
94 //------------------------------------------------------------------------------
95 StringSequence
OImageButtonModel::getSupportedServiceNames() throw()
97 StringSequence aSupported
= OClickableImageBaseModel::getSupportedServiceNames();
98 aSupported
.realloc(aSupported
.getLength() + 1);
100 ::rtl::OUString
*pArray
= aSupported
.getArray();
101 pArray
[aSupported
.getLength()-1] = FRM_SUN_COMPONENT_IMAGEBUTTON
;
105 //------------------------------------------------------------------------------
106 void OImageButtonModel::describeFixedProperties( Sequence
< Property
>& _rProps
) const
108 BEGIN_DESCRIBE_PROPERTIES( 5, OClickableImageBaseModel
)
109 DECL_PROP1(BUTTONTYPE
, FormButtonType
, BOUND
);
110 DECL_PROP1(DISPATCHURLINTERNAL
, sal_Bool
, BOUND
);
111 DECL_PROP1(TARGET_URL
, ::rtl::OUString
, BOUND
);
112 DECL_PROP1(TARGET_FRAME
, ::rtl::OUString
, BOUND
);
113 DECL_PROP1(TABINDEX
, sal_Int16
, BOUND
);
114 END_DESCRIBE_PROPERTIES();
117 //------------------------------------------------------------------------------
118 ::rtl::OUString
OImageButtonModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException
)
120 return FRM_COMPONENT_IMAGEBUTTON
; // old (non-sun) name for compatibility !
123 //------------------------------------------------------------------------------
124 void OImageButtonModel::write(const Reference
<XObjectOutputStream
>& _rxOutStream
) throw ( ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
126 OControlModel::write(_rxOutStream
);
129 _rxOutStream
->writeShort(0x0003);
130 _rxOutStream
->writeShort((sal_uInt16
)m_eButtonType
);
132 ::rtl::OUString
sTmp(INetURLObject::decode( m_sTargetURL
, '%', INetURLObject::DECODE_UNAMBIGUOUS
));
133 _rxOutStream
<< sTmp
;
134 _rxOutStream
<< m_sTargetFrame
;
135 writeHelpTextCompatibly(_rxOutStream
);
138 //------------------------------------------------------------------------------
139 void OImageButtonModel::read(const Reference
<XObjectInputStream
>& _rxInStream
) throw ( ::com::sun::star::io::IOException
, ::com::sun::star::uno::RuntimeException
)
141 OControlModel::read(_rxInStream
);
144 sal_uInt16 nVersion
= _rxInStream
->readShort();
150 m_eButtonType
= (FormButtonType
)_rxInStream
->readShort();
155 m_eButtonType
= (FormButtonType
)_rxInStream
->readShort();
156 _rxInStream
>> m_sTargetURL
;
157 _rxInStream
>> m_sTargetFrame
;
162 m_eButtonType
= (FormButtonType
)_rxInStream
->readShort();
163 _rxInStream
>> m_sTargetURL
;
164 _rxInStream
>> m_sTargetFrame
;
165 readHelpTextCompatibly(_rxInStream
);
170 DBG_ERROR("OImageButtonModel::read : unknown version !");
171 m_eButtonType
= FormButtonType_PUSH
;
172 m_sTargetURL
= ::rtl::OUString();
173 m_sTargetFrame
= ::rtl::OUString();
178 //==================================================================
179 // OImageButtonControl
180 //==================================================================
181 //------------------------------------------------------------------
182 InterfaceRef SAL_CALL
OImageButtonControl_CreateInstance(const Reference
<XMultiServiceFactory
>& _rxFactory
)
184 return *(new OImageButtonControl(_rxFactory
));
187 //------------------------------------------------------------------------------
188 Sequence
<Type
> OImageButtonControl::_getTypes()
190 static Sequence
<Type
> aTypes
;
191 if (!aTypes
.getLength())
192 aTypes
= concatSequences(OClickableImageBaseControl::_getTypes(), OImageButtonControl_BASE::getTypes());
196 //------------------------------------------------------------------------------
197 StringSequence
OImageButtonControl::getSupportedServiceNames() throw()
199 StringSequence aSupported
= OClickableImageBaseControl::getSupportedServiceNames();
200 aSupported
.realloc(aSupported
.getLength() + 1);
202 ::rtl::OUString
*pArray
= aSupported
.getArray();
203 pArray
[aSupported
.getLength()-1] = FRM_SUN_CONTROL_IMAGEBUTTON
;
207 //------------------------------------------------------------------------------
208 OImageButtonControl::OImageButtonControl(const Reference
<XMultiServiceFactory
>& _rxFactory
)
209 :OClickableImageBaseControl(_rxFactory
, VCL_CONTROL_IMAGEBUTTON
)
211 increment(m_refCount
);
213 // als MouseListener anmelden
214 Reference
< awt::XWindow
> xComp
;
215 query_aggregation( m_xAggregate
, xComp
);
217 xComp
->addMouseListener( static_cast< awt::XMouseListener
* >( this ) );
219 decrement(m_refCount
);
223 //------------------------------------------------------------------------------
224 Any SAL_CALL
OImageButtonControl::queryAggregation(const Type
& _rType
) throw (RuntimeException
)
226 Any aReturn
= OClickableImageBaseControl::queryAggregation(_rType
);
227 if (!aReturn
.hasValue())
228 aReturn
= OImageButtonControl_BASE::queryInterface(_rType
);
233 //------------------------------------------------------------------------------
234 void OImageButtonControl::mousePressed(const awt::MouseEvent
& e
) throw ( ::com::sun::star::uno::RuntimeException
)
236 ::vos::OGuard
aSolarGuard( Application::GetSolarMutex() );
238 if (e
.Buttons
!= awt::MouseButton::LEFT
)
241 ::osl::ClearableMutexGuard
aGuard( m_aMutex
);
242 if( m_aApproveActionListeners
.getLength() )
244 // if there are listeners, start the action in an own thread, to not allow
245 // them to block us here (we're in the application's main thread)
246 getImageProducerThread()->OComponentEventThread::addEvent( &e
);
250 // Sonst nicht. Dann darf man aber auf keinen Fal die Listener
251 // benachrichtigen, auch dann nicht, wenn er spaeter hinzukommt.
253 actionPerformed_Impl( sal_False
, e
);
257 //------------------------------------------------------------------------------
258 void SAL_CALL
OImageButtonControl::mouseReleased(const awt::MouseEvent
& /*e*/) throw ( RuntimeException
)
262 //------------------------------------------------------------------------------
263 void SAL_CALL
OImageButtonControl::mouseEntered(const awt::MouseEvent
& /*e*/) throw ( RuntimeException
)
267 //------------------------------------------------------------------------------
268 void SAL_CALL
OImageButtonControl::mouseExited(const awt::MouseEvent
& /*e*/) throw ( RuntimeException
)
273 //.........................................................................
275 //.........................................................................