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