xref: /aoo41x/main/sw/source/core/access/accfield.cxx (revision 0deba7fb)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright IBM Corporation 2010.
6  * Copyright 2000, 2010 Oracle and/or its affiliates.
7  *
8  * OpenOffice.org - a multi-platform office productivity suite
9  *
10  * This file is part of OpenOffice.org.
11  *
12  * OpenOffice.org is free software: you can redistribute it and/or modify
13  * it under the terms of the GNU Lesser General Public License version 3
14  * only, as published by the Free Software Foundation.
15  *
16  * OpenOffice.org is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU Lesser General Public License version 3 for more details
20  * (a copy is included in the LICENSE file that accompanied this code).
21  *
22  * You should have received a copy of the GNU Lesser General Public License
23  * version 3 along with OpenOffice.org.  If not, see
24  * <http://www.openoffice.org/license.html>
25  * for a copy of the LGPLv3 License.
26  *
27  ************************************************************************/
28 
29 // MARKER(update_precomp.py): autogen include statement, do not remove
30 #include "precompiled_sw.hxx"
31 
32 #ifndef COMPHELPER_ACCESSIBLE_KEYBINDING_HELPER_HXX
33 #include <comphelper/accessiblekeybindinghelper.hxx>
34 #endif
35 #ifndef _SWURL_HXX //autogen
36 #include <swurl.hxx>
37 #endif
38 #ifndef _VOS_MUTEX_HXX_ //autogen
39 #include <vos/mutex.hxx>
40 #endif
41 #ifndef _SV_SVAPP_HXX //autogen
42 #include <vcl/svapp.hxx>
43 #endif
44 #ifndef _NDTXT_HXX
45 #include <ndtxt.hxx>
46 #endif
47 #ifndef _TXTINET_HXX
48 #include <txtinet.hxx>
49 #endif
50 
51 #ifndef _ACCPARA_HXX
52 #include <accpara.hxx>
53 #endif
54 #ifndef _ACCFIELD_HXX
55 #include <accfield.hxx>
56 #endif
57 
58 #include <comphelper/processfactory.hxx>
59 
60 #ifndef _COM_SUN_STAR_FRAME_XDESKTOP_HPP_
61 #include <com/sun/star/frame/XDesktop.hpp>
62 #endif
63 #ifndef _COM_SUN_STAR_FRAME_XCOMPONENTLOADER_HPP_
64 #include <com/sun/star/frame/XComponentLoader.hpp>
65 #endif
66 #ifndef _COM_SUN_STAR_DOCUMENT_XLINKTARGETSUPPLIER_HPP_
67 #include <com/sun/star/document/XLinkTargetSupplier.hpp>
68 #endif
69 #ifndef COMPHELPER_ACCESSIBLE_EVENT_NOTIFIER
70 #include <comphelper/accessibleeventnotifier.hxx>
71 #endif
72 
73 //Add end
74 
75 using namespace ::com::sun::star;
76 using namespace ::com::sun::star::beans;
77 using namespace ::com::sun::star::lang;
78 using namespace ::com::sun::star::uno;
79 using namespace ::com::sun::star::accessibility;
80 // using namespace ::rtl;
81 
82 SwAccessibleField::SwAccessibleField( SwField *pSwFld,SwAccessibleParagraph *p,sal_Int16 nRole) :
83 	m_xPara( p ),m_pSwField(pSwFld),m_nRole(nRole)
84 {
85 	m_nClientId=0;
86 }
87 
88 uno::Reference< XAccessibleContext > SAL_CALL
89 	SwAccessibleField::getAccessibleContext( void )
90         throw (::com::sun::star::uno::RuntimeException)
91 {
92 	uno::Reference < XAccessibleContext > xRet( this );
93 	return xRet;
94 }
95 
96 sal_Int32 SAL_CALL SwAccessibleField::getAccessibleChildCount( void )
97         throw (::com::sun::star::uno::RuntimeException)
98 {
99 	vos::OGuard aGuard(Application::GetSolarMutex());
100 	return 0;
101 }
102 
103 uno::Reference< XAccessible> SAL_CALL
104 	SwAccessibleField::getAccessibleChild( long )
105         throw (::com::sun::star::uno::RuntimeException,
106 				::com::sun::star::lang::IndexOutOfBoundsException)
107 {
108 	vos::OGuard aGuard(Application::GetSolarMutex());
109 	return uno::Reference< XAccessible >();
110 }
111 
112 uno::Reference< XAccessible> SAL_CALL SwAccessibleField::getAccessibleParent (void)
113         throw (::com::sun::star::uno::RuntimeException)
114 {
115 	vos::OGuard aGuard(Application::GetSolarMutex());
116 
117 	uno::Reference< XAccessible > xParent(static_cast<XAccessible*>(m_xPara.getBodyPtr()),UNO_QUERY);
118 	return xParent;
119 }
120 
121 sal_Int32 SAL_CALL SwAccessibleField::getAccessibleIndexInParent (void)
122         throw (::com::sun::star::uno::RuntimeException)
123 {
124 	vos::OGuard aGuard(Application::GetSolarMutex());
125 	return 0;
126 }
127 
128 sal_Int16 SAL_CALL SwAccessibleField::getAccessibleRole (void)
129         throw (::com::sun::star::uno::RuntimeException)
130 {
131 	return m_nRole;
132 }
133 
134 rtl::OUString SAL_CALL SwAccessibleField::getAccessibleDescription (void)
135         throw (::com::sun::star::uno::RuntimeException)
136 {
137 	ASSERT( !this, "description needs to be overloaded" );
138 	//THROW_RUNTIME_EXCEPTION( XAccessibleContext, "internal error (method must be overloaded)" );
139 	return rtl::OUString();
140 }
141 
142 rtl::OUString SAL_CALL SwAccessibleField::getAccessibleName (void)
143         throw (::com::sun::star::uno::RuntimeException)
144 {
145 	return rtl::OUString();
146 }
147 
148 uno::Reference< XAccessibleRelationSet> SAL_CALL
149 	SwAccessibleField::getAccessibleRelationSet (void)
150         throw (::com::sun::star::uno::RuntimeException)
151 {
152 	return NULL;
153 }
154 
155 uno::Reference<XAccessibleStateSet> SAL_CALL
156 	SwAccessibleField::getAccessibleStateSet (void)
157         throw (::com::sun::star::uno::RuntimeException)
158 {
159 	vos::OGuard aGuard(Application::GetSolarMutex());
160 	return uno::Reference<XAccessibleStateSet>();
161 }
162 
163 com::sun::star::lang::Locale SAL_CALL SwAccessibleField::getLocale (void)
164 		throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException)
165 {
166 	vos::OGuard aGuard(Application::GetSolarMutex());
167 
168 	com::sun::star::lang::Locale aLoc( Application::GetSettings().GetLocale() );
169 	return aLoc;
170 }
171 
172 static sal_Bool lcl_PointInRectangle(const awt::Point & aPoint,
173                                      const awt::Rectangle & aRect)
174 {
175     long nDiffX = aPoint.X - aRect.X;
176     long nDiffY = aPoint.Y - aRect.Y;
177 
178     return
179         nDiffX >= 0 && nDiffX < aRect.Width && nDiffY >= 0 &&
180         nDiffY < aRect.Height;
181 
182 }
183 
184 sal_Bool SAL_CALL SwAccessibleField::containsPoint(
185 			const ::com::sun::star::awt::Point& aPoint )
186 		throw (RuntimeException)
187 {
188     awt::Rectangle aPixBounds = getBoundsImpl(sal_True);
189     aPixBounds.X = 0;
190     aPixBounds.Y = 0;
191 
192     return lcl_PointInRectangle(aPoint, aPixBounds);
193 }
194 
195 uno::Reference< XAccessible > SAL_CALL SwAccessibleField::getAccessibleAtPoint(
196 				const awt::Point& aPoint )
197 		throw (RuntimeException)
198 {
199 	vos::OGuard aGuard(Application::GetSolarMutex());
200 
201 	uno::Reference< XAccessible > xAcc;
202 	awt::Rectangle rc = getBounds();
203 	if(aPoint.X >= rc.X && aPoint.X <= rc.X + rc.Width &&
204 		aPoint.Y >= rc.Y && aPoint.Y <= rc.Y + rc.Height )
205 	{
206 		xAcc =this;
207 	}
208 	return xAcc;
209 }
210 
211 
212 /**
213    Get bounding box.
214 
215    There are two modes.
216 
217    - realative
218 
219      Return bounding box relative to parent if parent is no root
220      frame. Otherwise return the absolute bounding box.
221 
222    - absolute
223 
224      Return the absolute bounding box.
225 
226    @param bRelative
227    true: Use relative mode.
228    false: Use absolute mode.
229 */
230 awt::Rectangle SAL_CALL SwAccessibleField::getBoundsImpl( sal_Bool )
231 		throw (RuntimeException)
232 {
233 	vos::OGuard aGuard(Application::GetSolarMutex());
234 	return awt::Rectangle();
235 }
236 
237 awt::Rectangle SAL_CALL SwAccessibleField::getBounds()
238 		throw (RuntimeException)
239 {
240     return getBoundsImpl(sal_True);
241 }
242 
243 awt::Point SAL_CALL SwAccessibleField::getLocation()
244     throw (RuntimeException)
245 {
246     awt::Rectangle aRect = getBoundsImpl(sal_True);
247     awt::Point aPoint(aRect.X, aRect.Y);
248 
249     return aPoint;
250 }
251 
252 
253 awt::Point SAL_CALL SwAccessibleField::getLocationOnScreen()
254 		throw (RuntimeException)
255 {
256     awt::Rectangle aRect = getBoundsImpl(sal_False);
257     //Point aPixPos = m_xPara->getLocationOnScreen();
258     return awt::Point( aRect.X,aRect.Y);//aPixPos.X() + aRect.nLeft , aPixPos.Y() + + aRect.nRight );
259 }
260 
261 
262 awt::Size SAL_CALL SwAccessibleField::getSize()
263 		throw (RuntimeException)
264 {
265     awt::Rectangle aRect = getBoundsImpl(sal_False);
266 	awt::Size aSize( aRect.Width, aRect.Height );
267 
268 	return aSize;
269 }
270 
271 void SAL_CALL SwAccessibleField::grabFocus()
272 		throw (RuntimeException)
273 {
274 	vos::OGuard aGuard(Application::GetSolarMutex());
275 	return;
276 }
277 
278 
279 sal_Int32 SAL_CALL SwAccessibleField::getForeground()
280 		throw (::com::sun::star::uno::RuntimeException)
281 {
282 	return 0;
283 }
284 
285 sal_Int32 SAL_CALL SwAccessibleField::getBackground()
286 		throw (::com::sun::star::uno::RuntimeException)
287 {
288 	return 0xffffff;
289 }
290 ::com::sun::star::uno::Any SAL_CALL SwAccessibleField::queryInterface(
291         const ::com::sun::star::uno::Type& rType )
292         throw (::com::sun::star::uno::RuntimeException)
293 {
294 	Any aRet;
295     if ( rType == ::getCppuType((uno::Reference<XAccessibleContext> *)0) )
296     {
297         Reference<XAccessibleContext> aAccContext = (XAccessibleContext *) this; // resolve ambiguity
298         aRet <<= aAccContext;
299     }
300     else if ( rType == ::getCppuType((Reference<XAccessibleComponent> *)0) )
301     {
302         Reference<XAccessibleComponent> aAccEditComponent = this;
303         aRet <<= aAccEditComponent;
304     }
305 	if (rType == ::getCppuType((Reference<XAccessibleEventBroadcaster> *)0))
306 	{
307         Reference<XAccessibleEventBroadcaster> aAccBroadcaster= this;
308         aRet <<= aAccBroadcaster;
309 	}
310 	return aRet;
311 }
312 
313 void SAL_CALL SwAccessibleField::acquire(  ) throw ()
314 {
315 }
316 void SAL_CALL SwAccessibleField::release(  ) throw ()
317 {
318 }
319 
320 void SAL_CALL SwAccessibleField::addEventListener(
321 			const Reference< XAccessibleEventListener >& xListener )
322 		throw (::com::sun::star::uno::RuntimeException)
323 {
324 	//DBG_MSG( "accessible event listener added" )
325 
326 	if (xListener.is())
327     {
328     	vos::OGuard aGuard(Application::GetSolarMutex());
329 		if (!m_nClientId)
330             m_nClientId = comphelper::AccessibleEventNotifier::registerClient( );
331 		comphelper::AccessibleEventNotifier::addEventListener( m_nClientId, xListener );
332     }
333 }
334 
335 void SAL_CALL SwAccessibleField::removeEventListener(
336 			const Reference< XAccessibleEventListener >& xListener )
337 		throw (::com::sun::star::uno::RuntimeException)
338 {
339 	//DBG_MSG( "accessible event listener removed" )
340 
341 	if (xListener.is())
342 	{
343     	vos::OGuard aGuard(Application::GetSolarMutex());
344 		sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( m_nClientId, xListener );
345 		if ( !nListenerCount )
346 		{
347 			// no listeners anymore
348 			// -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
349 			// and at least to us not firing any events anymore, in case somebody calls
350 			// NotifyAccessibleEvent, again
351 			comphelper::AccessibleEventNotifier::revokeClient( m_nClientId );
352 			m_nClientId = 0;
353 		}
354 	}
355 }
356