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