Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 : #include <comphelper/accessiblekeybindinghelper.hxx>
20 : #include <swurl.hxx>
21 : #include <vcl/svapp.hxx>
22 : #include <vcl/settings.hxx>
23 : #include <ndtxt.hxx>
24 : #include <txtinet.hxx>
25 :
26 : #include <accpara.hxx>
27 : #include <accfield.hxx>
28 :
29 : #include <comphelper/processfactory.hxx>
30 :
31 : #include <com/sun/star/frame/XDesktop.hpp>
32 : #include <com/sun/star/frame/XComponentLoader.hpp>
33 : #include <com/sun/star/document/XLinkTargetSupplier.hpp>
34 : #include <comphelper/accessibleeventnotifier.hxx>
35 :
36 : //Add end
37 :
38 : using namespace ::com::sun::star;
39 : using namespace ::com::sun::star::beans;
40 : using namespace ::com::sun::star::lang;
41 : using namespace ::com::sun::star::uno;
42 : using namespace ::com::sun::star::accessibility;
43 :
44 0 : SwAccessibleField::SwAccessibleField( SwField *pSwFld,SwAccessibleParagraph *p,sal_Int16 nRole) :
45 0 : m_xPara( p ),m_pSwField(pSwFld),m_nRole(nRole)
46 : {
47 0 : m_nClientId=0;
48 0 : }
49 :
50 : uno::Reference< XAccessibleContext > SAL_CALL
51 0 : SwAccessibleField::getAccessibleContext( void )
52 : throw (::com::sun::star::uno::RuntimeException, std::exception)
53 : {
54 0 : uno::Reference < XAccessibleContext > xRet( this );
55 0 : return xRet;
56 : }
57 :
58 0 : sal_Int32 SAL_CALL SwAccessibleField::getAccessibleChildCount( void )
59 : throw (::com::sun::star::uno::RuntimeException, std::exception)
60 : {
61 0 : SolarMutexGuard aGuard;
62 0 : return 0;
63 : }
64 :
65 : uno::Reference< XAccessible> SAL_CALL
66 0 : SwAccessibleField::getAccessibleChild( sal_Int32 )
67 : throw (::com::sun::star::uno::RuntimeException,
68 : ::com::sun::star::lang::IndexOutOfBoundsException, std::exception)
69 : {
70 0 : SolarMutexGuard aGuard;
71 0 : return uno::Reference< XAccessible >();
72 : }
73 :
74 0 : uno::Reference< XAccessible> SAL_CALL SwAccessibleField::getAccessibleParent (void)
75 : throw (::com::sun::star::uno::RuntimeException, std::exception)
76 : {
77 0 : SolarMutexGuard aGuard;
78 :
79 0 : uno::Reference< XAccessible > xParent(static_cast<XAccessible*>(m_xPara.get()),UNO_QUERY);
80 0 : return xParent;
81 : }
82 :
83 0 : sal_Int32 SAL_CALL SwAccessibleField::getAccessibleIndexInParent (void)
84 : throw (::com::sun::star::uno::RuntimeException, std::exception)
85 : {
86 0 : SolarMutexGuard aGuard;
87 0 : return 0;
88 : }
89 :
90 0 : sal_Int16 SAL_CALL SwAccessibleField::getAccessibleRole (void)
91 : throw (::com::sun::star::uno::RuntimeException, std::exception)
92 : {
93 0 : SolarMutexGuard g;
94 0 : return m_nRole;
95 : }
96 :
97 0 : OUString SAL_CALL SwAccessibleField::getAccessibleDescription (void)
98 : throw (::com::sun::star::uno::RuntimeException, std::exception)
99 : {
100 : OSL_ENSURE( !this, "description needs to be overloaded" );
101 0 : return OUString();
102 : }
103 :
104 0 : OUString SAL_CALL SwAccessibleField::getAccessibleName (void)
105 : throw (::com::sun::star::uno::RuntimeException, std::exception)
106 : {
107 0 : return OUString();
108 : }
109 :
110 : uno::Reference< XAccessibleRelationSet> SAL_CALL
111 0 : SwAccessibleField::getAccessibleRelationSet (void)
112 : throw (::com::sun::star::uno::RuntimeException, std::exception)
113 : {
114 0 : return NULL;
115 : }
116 :
117 : uno::Reference<XAccessibleStateSet> SAL_CALL
118 0 : SwAccessibleField::getAccessibleStateSet (void)
119 : throw (::com::sun::star::uno::RuntimeException, std::exception)
120 : {
121 0 : SolarMutexGuard aGuard;
122 0 : return uno::Reference<XAccessibleStateSet>();
123 : }
124 :
125 0 : com::sun::star::lang::Locale SAL_CALL SwAccessibleField::getLocale (void)
126 : throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException, std::exception)
127 : {
128 0 : SolarMutexGuard aGuard;
129 :
130 0 : com::sun::star::lang::Locale aLoc( Application::GetSettings().GetLanguageTag().getLocale() );
131 0 : return aLoc;
132 : }
133 :
134 0 : static sal_Bool lcl_PointInRectangle(const awt::Point & aPoint,
135 : const awt::Rectangle & aRect)
136 : {
137 0 : long nDiffX = aPoint.X - aRect.X;
138 0 : long nDiffY = aPoint.Y - aRect.Y;
139 :
140 : return
141 0 : nDiffX >= 0 && nDiffX < aRect.Width && nDiffY >= 0 &&
142 0 : nDiffY < aRect.Height;
143 :
144 : }
145 :
146 0 : sal_Bool SAL_CALL SwAccessibleField::containsPoint(
147 : const ::com::sun::star::awt::Point& aPoint )
148 : throw (RuntimeException, std::exception)
149 : {
150 0 : awt::Rectangle aPixBounds = getBoundsImpl(sal_True);
151 0 : aPixBounds.X = 0;
152 0 : aPixBounds.Y = 0;
153 :
154 0 : return lcl_PointInRectangle(aPoint, aPixBounds);
155 : }
156 :
157 0 : uno::Reference< XAccessible > SAL_CALL SwAccessibleField::getAccessibleAtPoint(
158 : const awt::Point& aPoint )
159 : throw (RuntimeException, std::exception)
160 : {
161 0 : SolarMutexGuard aGuard;
162 :
163 0 : uno::Reference< XAccessible > xAcc;
164 0 : awt::Rectangle rc = getBounds();
165 0 : if(aPoint.X >= rc.X && aPoint.X <= rc.X + rc.Width &&
166 0 : aPoint.Y >= rc.Y && aPoint.Y <= rc.Y + rc.Height )
167 : {
168 0 : xAcc =this;
169 : }
170 0 : return xAcc;
171 : }
172 :
173 : /**
174 : Get bounding box.
175 :
176 : There are two modes.
177 :
178 : - realative
179 :
180 : Return bounding box relative to parent if parent is no root
181 : frame. Otherwise return the absolute bounding box.
182 :
183 : - absolute
184 :
185 : Return the absolute bounding box.
186 :
187 : @param bRelative
188 : true: Use relative mode.
189 : false: Use absolute mode.
190 : */
191 0 : awt::Rectangle SAL_CALL SwAccessibleField::getBoundsImpl( sal_Bool )
192 : throw (RuntimeException)
193 : {
194 0 : SolarMutexGuard aGuard;
195 0 : return awt::Rectangle();
196 : }
197 :
198 0 : awt::Rectangle SAL_CALL SwAccessibleField::getBounds()
199 : throw (RuntimeException, std::exception)
200 : {
201 0 : return getBoundsImpl(sal_True);
202 : }
203 :
204 0 : awt::Point SAL_CALL SwAccessibleField::getLocation()
205 : throw (RuntimeException, std::exception)
206 : {
207 0 : awt::Rectangle aRect = getBoundsImpl(sal_True);
208 0 : awt::Point aPoint(aRect.X, aRect.Y);
209 :
210 0 : return aPoint;
211 : }
212 :
213 0 : awt::Point SAL_CALL SwAccessibleField::getLocationOnScreen()
214 : throw (RuntimeException, std::exception)
215 : {
216 0 : awt::Rectangle aRect = getBoundsImpl(sal_False);
217 : //Point aPixPos = m_xPara->getLocationOnScreen();
218 0 : return awt::Point( aRect.X,aRect.Y);//aPixPos.X() + aRect.nLeft , aPixPos.Y() + + aRect.nRight );
219 : }
220 :
221 0 : awt::Size SAL_CALL SwAccessibleField::getSize()
222 : throw (RuntimeException, std::exception)
223 : {
224 0 : awt::Rectangle aRect = getBoundsImpl(sal_False);
225 0 : awt::Size aSize( aRect.Width, aRect.Height );
226 :
227 0 : return aSize;
228 : }
229 :
230 0 : void SAL_CALL SwAccessibleField::grabFocus()
231 : throw (RuntimeException, std::exception)
232 : {
233 0 : SolarMutexGuard aGuard;
234 0 : return;
235 : }
236 :
237 0 : sal_Int32 SAL_CALL SwAccessibleField::getForeground()
238 : throw (::com::sun::star::uno::RuntimeException, std::exception)
239 : {
240 0 : return 0;
241 : }
242 :
243 0 : sal_Int32 SAL_CALL SwAccessibleField::getBackground()
244 : throw (::com::sun::star::uno::RuntimeException, std::exception)
245 : {
246 0 : return 0xffffff;
247 : }
248 0 : ::com::sun::star::uno::Any SAL_CALL SwAccessibleField::queryInterface(
249 : const ::com::sun::star::uno::Type& rType )
250 : throw (::com::sun::star::uno::RuntimeException, std::exception)
251 : {
252 0 : Any aRet;
253 0 : if ( rType == ::getCppuType((uno::Reference<XAccessibleContext> *)0) )
254 : {
255 0 : Reference<XAccessibleContext> aAccContext = (XAccessibleContext *) this; // resolve ambiguity
256 0 : aRet <<= aAccContext;
257 : }
258 0 : else if ( rType == ::getCppuType((Reference<XAccessibleComponent> *)0) )
259 : {
260 0 : Reference<XAccessibleComponent> aAccEditComponent = this;
261 0 : aRet <<= aAccEditComponent;
262 : }
263 0 : if (rType == ::getCppuType((Reference<XAccessibleEventBroadcaster> *)0))
264 : {
265 0 : Reference<XAccessibleEventBroadcaster> aAccBroadcaster= this;
266 0 : aRet <<= aAccBroadcaster;
267 : }
268 0 : return aRet;
269 : }
270 :
271 0 : void SAL_CALL SwAccessibleField::acquire( ) throw ()
272 : {
273 0 : }
274 0 : void SAL_CALL SwAccessibleField::release( ) throw ()
275 : {
276 0 : }
277 :
278 0 : void SAL_CALL SwAccessibleField::addEventListener(
279 : const Reference< XAccessibleEventListener >& xListener )
280 : throw (::com::sun::star::uno::RuntimeException)
281 : {
282 : //DBG_MSG( "accessible event listener added" )
283 :
284 0 : if (xListener.is())
285 : {
286 0 : SolarMutexGuard aGuard;
287 0 : if (!m_nClientId)
288 0 : m_nClientId = comphelper::AccessibleEventNotifier::registerClient( );
289 0 : comphelper::AccessibleEventNotifier::addEventListener( m_nClientId, xListener );
290 : }
291 0 : }
292 :
293 0 : void SAL_CALL SwAccessibleField::removeEventListener(
294 : const Reference< XAccessibleEventListener >& xListener )
295 : throw (::com::sun::star::uno::RuntimeException)
296 : {
297 : //DBG_MSG( "accessible event listener removed" )
298 :
299 0 : if (xListener.is())
300 : {
301 0 : SolarMutexGuard aGuard;
302 0 : sal_Int32 nListenerCount = comphelper::AccessibleEventNotifier::removeEventListener( m_nClientId, xListener );
303 0 : if ( !nListenerCount )
304 : {
305 : // no listeners anymore
306 : // -> revoke ourself. This may lead to the notifier thread dying (if we were the last client),
307 : // and at least to us not firing any events anymore, in case somebody calls
308 : // NotifyAccessibleEvent, again
309 0 : comphelper::AccessibleEventNotifier::revokeClient( m_nClientId );
310 0 : m_nClientId = 0;
311 0 : }
312 : }
313 0 : }
314 :
315 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|