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