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 #include "ImageButton.hxx"
27cdf0e10cSrcweir #include <tools/debug.hxx>
28cdf0e10cSrcweir #include <tools/urlobj.hxx>
29cdf0e10cSrcweir #include <vcl/svapp.hxx>
30cdf0e10cSrcweir #include <vos/mutex.hxx>
31cdf0e10cSrcweir #include <comphelper/basicio.hxx>
32cdf0e10cSrcweir #include <com/sun/star/awt/MouseButton.hpp>
33cdf0e10cSrcweir 
34cdf0e10cSrcweir //.........................................................................
35cdf0e10cSrcweir namespace frm
36cdf0e10cSrcweir {
37cdf0e10cSrcweir //.........................................................................
38cdf0e10cSrcweir using namespace ::com::sun::star;
39cdf0e10cSrcweir using namespace ::com::sun::star::uno;
40cdf0e10cSrcweir using namespace ::com::sun::star::sdb;
41cdf0e10cSrcweir using namespace ::com::sun::star::sdbc;
42cdf0e10cSrcweir using namespace ::com::sun::star::sdbcx;
43cdf0e10cSrcweir using namespace ::com::sun::star::beans;
44cdf0e10cSrcweir using namespace ::com::sun::star::container;
45cdf0e10cSrcweir using namespace ::com::sun::star::form;
46cdf0e10cSrcweir using namespace ::com::sun::star::io;
47cdf0e10cSrcweir using namespace ::com::sun::star::lang;
48cdf0e10cSrcweir using namespace ::com::sun::star::util;
49cdf0e10cSrcweir 
50cdf0e10cSrcweir //==================================================================
51cdf0e10cSrcweir //= OImageButtonModel
52cdf0e10cSrcweir //==================================================================
DBG_NAME(OImageButtonModel)53cdf0e10cSrcweir DBG_NAME(OImageButtonModel)
54cdf0e10cSrcweir //------------------------------------------------------------------
55cdf0e10cSrcweir InterfaceRef SAL_CALL OImageButtonModel_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
56cdf0e10cSrcweir {
57cdf0e10cSrcweir  	return *(new OImageButtonModel(_rxFactory));
58cdf0e10cSrcweir }
59cdf0e10cSrcweir 
60cdf0e10cSrcweir //------------------------------------------------------------------
OImageButtonModel(const Reference<XMultiServiceFactory> & _rxFactory)61cdf0e10cSrcweir OImageButtonModel::OImageButtonModel(const Reference<XMultiServiceFactory>& _rxFactory)
62cdf0e10cSrcweir 					:OClickableImageBaseModel( _rxFactory, VCL_CONTROLMODEL_IMAGEBUTTON, FRM_SUN_CONTROL_IMAGEBUTTON )
63cdf0e10cSrcweir 									// use the old control name for compytibility reasons
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 	DBG_CTOR(OImageButtonModel, NULL);
66cdf0e10cSrcweir 	m_nClassId = FormComponentType::IMAGEBUTTON;
67cdf0e10cSrcweir }
68cdf0e10cSrcweir 
69cdf0e10cSrcweir //------------------------------------------------------------------
OImageButtonModel(const OImageButtonModel * _pOriginal,const Reference<XMultiServiceFactory> & _rxFactory)70cdf0e10cSrcweir OImageButtonModel::OImageButtonModel( const OImageButtonModel* _pOriginal, const Reference<XMultiServiceFactory>& _rxFactory)
71cdf0e10cSrcweir 	:OClickableImageBaseModel( _pOriginal, _rxFactory )
72cdf0e10cSrcweir {
73cdf0e10cSrcweir 	DBG_CTOR(OImageButtonModel, NULL);
74cdf0e10cSrcweir     implInitializeImageURL();
75cdf0e10cSrcweir }
76cdf0e10cSrcweir 
77cdf0e10cSrcweir //------------------------------------------------------------------------------
IMPLEMENT_DEFAULT_CLONING(OImageButtonModel)78cdf0e10cSrcweir IMPLEMENT_DEFAULT_CLONING( OImageButtonModel )
79cdf0e10cSrcweir 
80cdf0e10cSrcweir //------------------------------------------------------------------------------
81cdf0e10cSrcweir OImageButtonModel::~OImageButtonModel()
82cdf0e10cSrcweir {
83cdf0e10cSrcweir 	DBG_DTOR(OImageButtonModel, NULL);
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
86cdf0e10cSrcweir // XServiceInfo
87cdf0e10cSrcweir //------------------------------------------------------------------------------
getSupportedServiceNames()88cdf0e10cSrcweir StringSequence	OImageButtonModel::getSupportedServiceNames() throw()
89cdf0e10cSrcweir {
90cdf0e10cSrcweir 	StringSequence aSupported = OClickableImageBaseModel::getSupportedServiceNames();
91cdf0e10cSrcweir 	aSupported.realloc(aSupported.getLength() + 1);
92cdf0e10cSrcweir 
93cdf0e10cSrcweir 	::rtl::OUString*pArray = aSupported.getArray();
94cdf0e10cSrcweir 	pArray[aSupported.getLength()-1] = FRM_SUN_COMPONENT_IMAGEBUTTON;
95cdf0e10cSrcweir 	return aSupported;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir 
98cdf0e10cSrcweir //------------------------------------------------------------------------------
describeFixedProperties(Sequence<Property> & _rProps) const99cdf0e10cSrcweir void OImageButtonModel::describeFixedProperties( Sequence< Property >& _rProps ) const
100cdf0e10cSrcweir {
101cdf0e10cSrcweir 	BEGIN_DESCRIBE_PROPERTIES( 5, OClickableImageBaseModel )
102cdf0e10cSrcweir         DECL_PROP1(BUTTONTYPE,          FormButtonType,     BOUND);
103cdf0e10cSrcweir         DECL_PROP1(DISPATCHURLINTERNAL, sal_Bool,           BOUND);
104cdf0e10cSrcweir         DECL_PROP1(TARGET_URL,          ::rtl::OUString,    BOUND);
105cdf0e10cSrcweir         DECL_PROP1(TARGET_FRAME,        ::rtl::OUString,    BOUND);
106cdf0e10cSrcweir         DECL_PROP1(TABINDEX,            sal_Int16,          BOUND);
107cdf0e10cSrcweir 	END_DESCRIBE_PROPERTIES();
108cdf0e10cSrcweir }
109cdf0e10cSrcweir 
110cdf0e10cSrcweir //------------------------------------------------------------------------------
getServiceName()111cdf0e10cSrcweir ::rtl::OUString OImageButtonModel::getServiceName() throw ( ::com::sun::star::uno::RuntimeException)
112cdf0e10cSrcweir {
113cdf0e10cSrcweir 	return FRM_COMPONENT_IMAGEBUTTON;	// old (non-sun) name for compatibility !
114cdf0e10cSrcweir }
115cdf0e10cSrcweir 
116cdf0e10cSrcweir //------------------------------------------------------------------------------
write(const Reference<XObjectOutputStream> & _rxOutStream)117cdf0e10cSrcweir void OImageButtonModel::write(const Reference<XObjectOutputStream>& _rxOutStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
118cdf0e10cSrcweir {
119cdf0e10cSrcweir 	OControlModel::write(_rxOutStream);
120cdf0e10cSrcweir 
121cdf0e10cSrcweir 	// Version
122cdf0e10cSrcweir 	_rxOutStream->writeShort(0x0003);
123cdf0e10cSrcweir 	_rxOutStream->writeShort((sal_uInt16)m_eButtonType);
124cdf0e10cSrcweir 
125cdf0e10cSrcweir 	::rtl::OUString sTmp(INetURLObject::decode( m_sTargetURL, '%', INetURLObject::DECODE_UNAMBIGUOUS));
126cdf0e10cSrcweir 	_rxOutStream << sTmp;
127cdf0e10cSrcweir 	_rxOutStream << m_sTargetFrame;
128cdf0e10cSrcweir 	writeHelpTextCompatibly(_rxOutStream);
129cdf0e10cSrcweir }
130cdf0e10cSrcweir 
131cdf0e10cSrcweir //------------------------------------------------------------------------------
read(const Reference<XObjectInputStream> & _rxInStream)132cdf0e10cSrcweir void OImageButtonModel::read(const Reference<XObjectInputStream>& _rxInStream) throw ( ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException)
133cdf0e10cSrcweir {
134cdf0e10cSrcweir 	OControlModel::read(_rxInStream);
135cdf0e10cSrcweir 
136cdf0e10cSrcweir 	// Version
137cdf0e10cSrcweir 	sal_uInt16 nVersion = _rxInStream->readShort();
138cdf0e10cSrcweir 
139cdf0e10cSrcweir 	switch (nVersion)
140cdf0e10cSrcweir 	{
141cdf0e10cSrcweir 		case 0x0001:
142cdf0e10cSrcweir 		{
143cdf0e10cSrcweir 			m_eButtonType = (FormButtonType)_rxInStream->readShort();
144cdf0e10cSrcweir 		}
145cdf0e10cSrcweir 		break;
146cdf0e10cSrcweir 		case 0x0002:
147cdf0e10cSrcweir 		{
148cdf0e10cSrcweir 			m_eButtonType = (FormButtonType)_rxInStream->readShort();
149cdf0e10cSrcweir 			_rxInStream >> m_sTargetURL;
150cdf0e10cSrcweir 			_rxInStream >> m_sTargetFrame;
151cdf0e10cSrcweir 		}
152cdf0e10cSrcweir 		break;
153cdf0e10cSrcweir 		case 0x0003:
154cdf0e10cSrcweir 		{
155cdf0e10cSrcweir 			m_eButtonType = (FormButtonType)_rxInStream->readShort();
156cdf0e10cSrcweir 			_rxInStream >> m_sTargetURL;
157cdf0e10cSrcweir 			_rxInStream >> m_sTargetFrame;
158cdf0e10cSrcweir 			readHelpTextCompatibly(_rxInStream);
159cdf0e10cSrcweir 		}
160cdf0e10cSrcweir 		break;
161cdf0e10cSrcweir 
162cdf0e10cSrcweir 		default :
163cdf0e10cSrcweir 			DBG_ERROR("OImageButtonModel::read : unknown version !");
164cdf0e10cSrcweir 			m_eButtonType = FormButtonType_PUSH;
165cdf0e10cSrcweir 			m_sTargetURL = ::rtl::OUString();
166cdf0e10cSrcweir 			m_sTargetFrame = ::rtl::OUString();
167cdf0e10cSrcweir 			break;
168cdf0e10cSrcweir 	}
169cdf0e10cSrcweir }
170cdf0e10cSrcweir 
171cdf0e10cSrcweir //==================================================================
172cdf0e10cSrcweir // OImageButtonControl
173cdf0e10cSrcweir //==================================================================
174cdf0e10cSrcweir //------------------------------------------------------------------
OImageButtonControl_CreateInstance(const Reference<XMultiServiceFactory> & _rxFactory)175cdf0e10cSrcweir InterfaceRef SAL_CALL OImageButtonControl_CreateInstance(const Reference<XMultiServiceFactory>& _rxFactory)
176cdf0e10cSrcweir {
177cdf0e10cSrcweir 	return *(new OImageButtonControl(_rxFactory));
178cdf0e10cSrcweir }
179cdf0e10cSrcweir 
180cdf0e10cSrcweir //------------------------------------------------------------------------------
_getTypes()181cdf0e10cSrcweir Sequence<Type> OImageButtonControl::_getTypes()
182cdf0e10cSrcweir {
183cdf0e10cSrcweir 	static Sequence<Type> aTypes;
184cdf0e10cSrcweir 	if (!aTypes.getLength())
185cdf0e10cSrcweir 		aTypes = concatSequences(OClickableImageBaseControl::_getTypes(), OImageButtonControl_BASE::getTypes());
186cdf0e10cSrcweir 	return aTypes;
187cdf0e10cSrcweir }
188cdf0e10cSrcweir 
189cdf0e10cSrcweir //------------------------------------------------------------------------------
getSupportedServiceNames()190cdf0e10cSrcweir StringSequence	OImageButtonControl::getSupportedServiceNames() throw()
191cdf0e10cSrcweir {
192cdf0e10cSrcweir 	StringSequence aSupported = OClickableImageBaseControl::getSupportedServiceNames();
193cdf0e10cSrcweir 	aSupported.realloc(aSupported.getLength() + 1);
194cdf0e10cSrcweir 
195cdf0e10cSrcweir 	::rtl::OUString*pArray = aSupported.getArray();
196cdf0e10cSrcweir 	pArray[aSupported.getLength()-1] = FRM_SUN_CONTROL_IMAGEBUTTON;
197cdf0e10cSrcweir 	return aSupported;
198cdf0e10cSrcweir }
199cdf0e10cSrcweir 
200cdf0e10cSrcweir //------------------------------------------------------------------------------
OImageButtonControl(const Reference<XMultiServiceFactory> & _rxFactory)201cdf0e10cSrcweir OImageButtonControl::OImageButtonControl(const Reference<XMultiServiceFactory>& _rxFactory)
202cdf0e10cSrcweir 			:OClickableImageBaseControl(_rxFactory, VCL_CONTROL_IMAGEBUTTON)
203cdf0e10cSrcweir {
204cdf0e10cSrcweir 	increment(m_refCount);
205cdf0e10cSrcweir 	{
206cdf0e10cSrcweir 		// als MouseListener anmelden
207cdf0e10cSrcweir         Reference< awt::XWindow >  xComp;
208cdf0e10cSrcweir 		query_aggregation( m_xAggregate, xComp);
209cdf0e10cSrcweir 		if (xComp.is())
210cdf0e10cSrcweir             xComp->addMouseListener( static_cast< awt::XMouseListener* >( this ) );
211cdf0e10cSrcweir 	}
212cdf0e10cSrcweir 	decrement(m_refCount);
213cdf0e10cSrcweir }
214cdf0e10cSrcweir 
215cdf0e10cSrcweir // UNO Anbindung
216cdf0e10cSrcweir //------------------------------------------------------------------------------
queryAggregation(const Type & _rType)217cdf0e10cSrcweir Any SAL_CALL OImageButtonControl::queryAggregation(const Type& _rType) throw (RuntimeException)
218cdf0e10cSrcweir {
219cdf0e10cSrcweir 	Any aReturn = OClickableImageBaseControl::queryAggregation(_rType);
220cdf0e10cSrcweir 	if (!aReturn.hasValue())
221cdf0e10cSrcweir 		aReturn = OImageButtonControl_BASE::queryInterface(_rType);
222cdf0e10cSrcweir 
223cdf0e10cSrcweir 	return aReturn;
224cdf0e10cSrcweir }
225cdf0e10cSrcweir 
226cdf0e10cSrcweir //------------------------------------------------------------------------------
mousePressed(const awt::MouseEvent & e)227cdf0e10cSrcweir void OImageButtonControl::mousePressed(const awt::MouseEvent& e) throw ( ::com::sun::star::uno::RuntimeException)
228cdf0e10cSrcweir {
229cdf0e10cSrcweir     ::vos::OGuard aSolarGuard( Application::GetSolarMutex() );
230cdf0e10cSrcweir 
231cdf0e10cSrcweir     if (e.Buttons != awt::MouseButton::LEFT)
232cdf0e10cSrcweir 		return;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir 	::osl::ClearableMutexGuard aGuard( m_aMutex );
235cdf0e10cSrcweir 	if( m_aApproveActionListeners.getLength() )
236cdf0e10cSrcweir 	{
237cdf0e10cSrcweir 		// if there are listeners, start the action in an own thread, to not allow
238cdf0e10cSrcweir         // them to block us here (we're in the application's main thread)
239cdf0e10cSrcweir         getImageProducerThread()->OComponentEventThread::addEvent( &e );
240cdf0e10cSrcweir 	}
241cdf0e10cSrcweir 	else
242cdf0e10cSrcweir 	{
243cdf0e10cSrcweir 		// Sonst nicht. Dann darf man aber auf keinen Fal die Listener
244cdf0e10cSrcweir 		// benachrichtigen, auch dann nicht, wenn er spaeter hinzukommt.
245cdf0e10cSrcweir 		aGuard.clear();
246cdf0e10cSrcweir 		actionPerformed_Impl( sal_False, e );
247cdf0e10cSrcweir 	}
248cdf0e10cSrcweir }
249cdf0e10cSrcweir 
250cdf0e10cSrcweir //------------------------------------------------------------------------------
mouseReleased(const awt::MouseEvent &)251cdf0e10cSrcweir void SAL_CALL OImageButtonControl::mouseReleased(const awt::MouseEvent& /*e*/) throw ( RuntimeException)
252cdf0e10cSrcweir {
253cdf0e10cSrcweir }
254cdf0e10cSrcweir 
255cdf0e10cSrcweir //------------------------------------------------------------------------------
mouseEntered(const awt::MouseEvent &)256cdf0e10cSrcweir void SAL_CALL OImageButtonControl::mouseEntered(const awt::MouseEvent& /*e*/) throw ( RuntimeException)
257cdf0e10cSrcweir {
258cdf0e10cSrcweir }
259cdf0e10cSrcweir 
260cdf0e10cSrcweir //------------------------------------------------------------------------------
mouseExited(const awt::MouseEvent &)261cdf0e10cSrcweir void SAL_CALL OImageButtonControl::mouseExited(const awt::MouseEvent& /*e*/) throw ( RuntimeException)
262cdf0e10cSrcweir {
263cdf0e10cSrcweir }
264cdf0e10cSrcweir 
265cdf0e10cSrcweir 
266cdf0e10cSrcweir //.........................................................................
267cdf0e10cSrcweir }	// namespace frm
268cdf0e10cSrcweir //.........................................................................
269cdf0e10cSrcweir 
270