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