1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef _ACCBASE_HXX 28 #define _ACCBASE_HXX 29 #include <accframe.hxx> 30 #include <accmap.hxx> 31 #include <com/sun/star/accessibility/XAccessibleComponent.hpp> 32 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp> 33 #include <com/sun/star/lang/DisposedException.hpp> 34 #include <com/sun/star/lang/XServiceInfo.hpp> 35 #include <cppuhelper/implbase5.hxx> 36 #include <cppuhelper/interfacecontainer.hxx> 37 38 class Window; 39 class SwAccessibleMap; 40 class SwCrsrShell; 41 class SdrObject; 42 class SwPaM; 43 namespace utl { 44 class AccessibleStateSetHelper; 45 } 46 namespace accessibility { 47 class AccessibleShape; 48 } 49 class SwFmtFld; 50 class SwAccessibleChildContainer; 51 52 const sal_Char sAccessibleServiceName[] = "com.sun.star.accessibility.Accessible"; 53 54 class SwAccessibleContext : 55 public ::cppu::WeakImplHelper5< 56 ::com::sun::star::accessibility::XAccessible, 57 ::com::sun::star::accessibility::XAccessibleContext, 58 ::com::sun::star::accessibility::XAccessibleComponent, 59 ::com::sun::star::accessibility::XAccessibleEventBroadcaster, 60 ::com::sun::star::lang::XServiceInfo 61 >, 62 public SwAccessibleFrame 63 { 64 // The implements for the XAccessibleSelection interface has been 65 // 'externalized' and wants access to the protected members like 66 // GetMap, GetChild, GetParent, and GetFrm. 67 friend class SwAccessibleSelectionHelper; 68 69 70 protected: 71 72 mutable ::osl::Mutex aListenerMutex; 73 mutable ::vos::OMutex aMutex; 74 75 private: 76 77 ::rtl::OUString sName; // immutable outside constructor 78 79 // The parent if it has been retrieved. This is always an 80 // SwAccessibleContext. (protected by Mutex) 81 ::com::sun::star::uno::WeakReference < 82 ::com::sun::star::accessibility::XAccessible > xWeakParent; 83 84 SwAccessibleMap *pMap; // must be protected by solar mutex 85 86 sal_uInt32 nClientId; // client id in the AccessibleEventNotifier queue 87 sal_Int16 nRole; // immutable outside constructor 88 89 // The current states (protected by mutex) 90 sal_Bool bIsShowingState : 1; 91 sal_Bool bIsEditableState : 1; 92 sal_Bool bIsOpaqueState : 1; 93 sal_Bool bIsDefuncState : 1; 94 95 // Are we currently disposing that object (protected by solar mutex)? 96 sal_Bool bDisposing : 1; 97 98 // --> OD 2008-03-10 #i85634# 99 // boolean, indicating if the accessible context is in general registered at 100 // the accessible map. 101 bool bRegisteredAtAccessibleMap; 102 // <-- 103 104 void InitStates(); 105 106 protected: 107 void SetName( const ::rtl::OUString& rName ) { sName = rName; } 108 inline sal_Int16 GetRole() const 109 { 110 return nRole; 111 } 112 113 void SetParent( SwAccessibleContext *pParent ); 114 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> GetWeakParent() const; 115 116 sal_Bool IsDisposing() const { return bDisposing; } 117 118 Window *GetWindow(); 119 SwAccessibleMap *GetMap() { return pMap; } 120 const SwAccessibleMap *GetMap() const { return pMap; } 121 122 /** convenience method to get the SwViewShell through accessibility map */ 123 inline ViewShell* GetShell() 124 { 125 return GetMap()->GetShell(); 126 } 127 inline const ViewShell* GetShell() const 128 { 129 return GetMap()->GetShell(); 130 } 131 132 /** convenience method to get SwCrsrShell through accessibility map 133 * @returns SwCrsrShell, or NULL if none is found */ 134 SwCrsrShell* GetCrsrShell(); 135 const SwCrsrShell* GetCrsrShell() const; 136 137 // Notify all children that the vis araea has changed. 138 // The SwFrm might belong to the current object or to any other child or 139 // grandchild. 140 void ChildrenScrolled( const SwFrm *pFrm, const SwRect& rOldVisArea ); 141 142 // The context's showing state changed. May only be called for context that 143 // exist even if they aren't visible. 144 void Scrolled( const SwRect& rOldVisArea ); 145 146 // A child has been moved while setting the vis area 147 void ScrolledWithin( const SwRect& rOldVisArea ); 148 149 // The has been added while setting the vis area 150 void ScrolledIn(); 151 152 // The context has to be removed while setting the vis area 153 void ScrolledOut( const SwRect& rOldVisArea ); 154 155 // Invalidate the states of all children of the specified SwFrm. The 156 // SwFrm might belong the the current object or to any child or grandchild! 157 // --> OD 2005-12-12 #i27301# - use new type definition for <_nStates> 158 void InvalidateChildrenStates( const SwFrm* _pFrm, 159 tAccessibleStates _nStates ); 160 // <-- 161 162 // Dispose children of the specified SwFrm. The SwFrm might belong to 163 // the current object or to any other child or grandchild. 164 void DisposeChildren( const SwFrm *pFrm, 165 sal_Bool bRecursive ); 166 167 void DisposeShape( const SdrObject *pObj, 168 ::accessibility::AccessibleShape *pAccImpl ); 169 void ScrolledInShape( const SdrObject *pObj, 170 ::accessibility::AccessibleShape *pAccImpl ); 171 172 virtual void _InvalidateContent( sal_Bool bVisibleDataFired ); 173 174 virtual void _InvalidateCursorPos(); 175 virtual void _InvalidateFocus(); 176 177 public: 178 179 void FireAccessibleEvent( ::com::sun::star::accessibility::AccessibleEventObject& rEvent ); 180 181 protected: 182 183 // broadcast visual data event 184 void FireVisibleDataEvent(); 185 186 // broadcast state change event 187 void FireStateChangedEvent( sal_Int16 nState, sal_Bool bNewState ); 188 189 // Set states for getAccessibleStateSet. 190 // This base class sets DEFUNC(0/1), EDITABLE(0/1), ENABLED(1), 191 // SHOWING(0/1), OPAQUE(0/1) and VISIBLE(1). 192 virtual void GetStates( ::utl::AccessibleStateSetHelper& rStateSet ); 193 194 sal_Bool IsEditableState(); 195 196 virtual ::com::sun::star::awt::Rectangle SAL_CALL 197 getBoundsImpl(sal_Bool bRelative) 198 throw (::com::sun::star::uno::RuntimeException); 199 200 // --> OD 2008-03-10 #i85634# 201 inline void NotRegisteredAtAccessibleMap() 202 { 203 bRegisteredAtAccessibleMap = false; 204 } 205 void RemoveFrmFromAccessibleMap(); 206 // <-- 207 208 virtual ~SwAccessibleContext(); 209 210 public: 211 212 SwAccessibleContext( SwAccessibleMap *pMap, sal_Int16 nRole, 213 const SwFrm *pFrm ); 214 215 //===== XAccessible ===================================================== 216 217 /// Return the XAccessibleContext. 218 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext> SAL_CALL 219 getAccessibleContext (void) throw (com::sun::star::uno::RuntimeException); 220 221 //===== XAccessibleContext ============================================== 222 223 /// Return the number of currently visible children. 224 virtual sal_Int32 SAL_CALL getAccessibleChildCount (void) 225 throw (::com::sun::star::uno::RuntimeException); 226 227 /// Return the specified child or NULL if index is invalid. 228 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL 229 getAccessibleChild (sal_Int32 nIndex) 230 throw (::com::sun::star::uno::RuntimeException, 231 ::com::sun::star::lang::IndexOutOfBoundsException); 232 233 /// Return a reference to the parent. 234 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL 235 getAccessibleParent (void) 236 throw (::com::sun::star::uno::RuntimeException); 237 238 /// Return this objects index among the parents children. 239 virtual sal_Int32 SAL_CALL 240 getAccessibleIndexInParent (void) 241 throw (::com::sun::star::uno::RuntimeException); 242 243 /// Return this object's role. 244 virtual sal_Int16 SAL_CALL 245 getAccessibleRole (void) 246 throw (::com::sun::star::uno::RuntimeException); 247 248 /// Return this object's description. 249 virtual ::rtl::OUString SAL_CALL 250 getAccessibleDescription (void) 251 throw (::com::sun::star::uno::RuntimeException); 252 253 /// Return the object's current name. 254 virtual ::rtl::OUString SAL_CALL 255 getAccessibleName (void) 256 throw (::com::sun::star::uno::RuntimeException); 257 258 /// Return NULL to indicate that an empty relation set. 259 virtual ::com::sun::star::uno::Reference< 260 ::com::sun::star::accessibility::XAccessibleRelationSet> SAL_CALL 261 getAccessibleRelationSet (void) 262 throw (::com::sun::star::uno::RuntimeException); 263 264 /// Return the set of current states. 265 virtual ::com::sun::star::uno::Reference< 266 ::com::sun::star::accessibility::XAccessibleStateSet> SAL_CALL 267 getAccessibleStateSet (void) 268 throw (::com::sun::star::uno::RuntimeException); 269 270 /** Return the parents locale or throw exception if this object has no 271 parent yet/anymore. 272 */ 273 virtual ::com::sun::star::lang::Locale SAL_CALL 274 getLocale (void) 275 throw (::com::sun::star::accessibility::IllegalAccessibleComponentStateException, ::com::sun::star::uno::RuntimeException); 276 277 //===== XAccessibleEventBroadcaster ===================================== 278 279 virtual void SAL_CALL addEventListener( 280 const ::com::sun::star::uno::Reference< 281 ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) 282 throw (::com::sun::star::uno::RuntimeException); 283 virtual void SAL_CALL removeEventListener( 284 const ::com::sun::star::uno::Reference< 285 ::com::sun::star::accessibility::XAccessibleEventListener >& xListener ) 286 throw (::com::sun::star::uno::RuntimeException); 287 288 //===== XAccessibleComponent ============================================ 289 virtual sal_Bool SAL_CALL containsPoint( 290 const ::com::sun::star::awt::Point& aPoint ) 291 throw (::com::sun::star::uno::RuntimeException); 292 293 virtual ::com::sun::star::uno::Reference< 294 ::com::sun::star::accessibility::XAccessible > SAL_CALL getAccessibleAtPoint( 295 const ::com::sun::star::awt::Point& aPoint ) 296 throw (::com::sun::star::uno::RuntimeException); 297 298 virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds() 299 throw (::com::sun::star::uno::RuntimeException); 300 301 virtual ::com::sun::star::awt::Point SAL_CALL getLocation() 302 throw (::com::sun::star::uno::RuntimeException); 303 304 virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen() 305 throw (::com::sun::star::uno::RuntimeException); 306 307 virtual ::com::sun::star::awt::Size SAL_CALL getSize() 308 throw (::com::sun::star::uno::RuntimeException); 309 310 virtual void SAL_CALL grabFocus() 311 throw (::com::sun::star::uno::RuntimeException); 312 313 virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding() 314 throw (::com::sun::star::uno::RuntimeException); 315 virtual sal_Int32 SAL_CALL getForeground() 316 throw (::com::sun::star::uno::RuntimeException); 317 virtual sal_Int32 SAL_CALL getBackground() 318 throw (::com::sun::star::uno::RuntimeException); 319 320 321 //===== XServiceInfo ==================================================== 322 323 /** Returns an identifier for the implementation of this object. 324 */ 325 virtual ::rtl::OUString SAL_CALL 326 getImplementationName (void) 327 throw (::com::sun::star::uno::RuntimeException); 328 329 /** Return whether the specified service is supported by this class. 330 */ 331 virtual sal_Bool SAL_CALL 332 supportsService (const ::rtl::OUString& sServiceName) 333 throw (::com::sun::star::uno::RuntimeException); 334 335 /** Returns a list of all supported services. In this case that is just 336 the AccessibleContext service. 337 */ 338 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL 339 getSupportedServiceNames (void) 340 throw (::com::sun::star::uno::RuntimeException); 341 342 //====== thread safe C++ interface ======================================== 343 344 // The object is not visible an longer and should be destroyed 345 virtual void Dispose( sal_Bool bRecursive = sal_False ); 346 347 // The child object is not visible an longer and should be destroyed 348 virtual void DisposeChild( const sw::access::SwAccessibleChild& rFrmOrObj, sal_Bool bRecursive ); 349 350 // The object has been moved by the layout 351 virtual void InvalidatePosOrSize( const SwRect& rFrm ); 352 353 // The vhild object has been moved by the layout 354 virtual void InvalidateChildPosOrSize( const sw::access::SwAccessibleChild& rFrmOrObj, 355 const SwRect& rFrm ); 356 357 // The content may have changed (but it hasn't tohave changed) 358 void InvalidateContent(); 359 360 // The caretPos has changed 361 void InvalidateCursorPos(); 362 363 // The Focus state has changed 364 void InvalidateFocus(); 365 366 // Check states 367 // --> OD 2005-12-12 #i27301# - use new type definition for <_nStates> 368 void InvalidateStates( tAccessibleStates _nStates ); 369 // <-- 370 371 // the XAccessibleRelationSet may have changed 372 void InvalidateRelation( sal_uInt16 nType ); 373 374 /** text selection has changed 375 376 OD 2005-12-14 #i27301# 377 378 @author OD 379 */ 380 void InvalidateTextSelection(); 381 382 /** attributes has changed 383 384 OD 2009-01-06 #i88069# 385 386 @author OD 387 */ 388 void InvalidateAttr(); 389 390 bool HasAdditionalAccessibleChildren(); 391 392 /** get additional child by index 393 394 OD 2010-01-27 #i88070# 395 396 @author OD 397 */ 398 Window* GetAdditionalAccessibleChild( const sal_Int32 nIndex ); 399 400 /** get all additional accessible children 401 402 OD 2010-01-27 #i88070# 403 404 @author OD 405 */ 406 void GetAdditionalAccessibleChildren( std::vector< Window* >* pChildren ); 407 408 409 const ::rtl::OUString& GetName() const { return sName; } 410 411 virtual sal_Bool HasCursor(); // required by map to remember that object 412 413 sal_Bool Select( SwPaM *pPaM, SdrObject *pObj, sal_Bool bAdd ); 414 inline sal_Bool Select( SwPaM& rPaM ) 415 { 416 return Select( &rPaM, 0, sal_False ); 417 } 418 inline sal_Bool Select( SdrObject *pObj, sal_Bool bAdd ) 419 { 420 return Select( 0, pObj, bAdd ); 421 } 422 423 static ::rtl::OUString GetResource( sal_uInt16 nResId, 424 const ::rtl::OUString *pArg1 = 0, 425 const ::rtl::OUString *pArg2 = 0 ); 426 427 428 }; 429 430 // some heaviliy used exception support 431 const sal_Char sDefunc[] = "object is defunctional"; 432 const sal_Char sMissingWindow[] = "window is missing"; 433 434 #define THROW_RUNTIME_EXCEPTION( ifc, msg ) \ 435 ::com::sun::star::uno::Reference < ifc > xThis( this ); \ 436 ::com::sun::star::uno::RuntimeException aExcept( \ 437 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(msg) ), xThis ); \ 438 throw aExcept; 439 440 #define CHECK_FOR_DEFUNC_THIS( ifc, ths ) \ 441 if( !(GetFrm() && GetMap()) ) \ 442 { \ 443 ::com::sun::star::uno::Reference < ifc > xThis( ths ); \ 444 ::com::sun::star::lang::DisposedException aExcept( \ 445 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(sDefunc) ), \ 446 xThis ); \ 447 throw aExcept; \ 448 } 449 450 #define CHECK_FOR_DEFUNC( ifc ) \ 451 CHECK_FOR_DEFUNC_THIS( ifc, this ) 452 453 #define CHECK_FOR_WINDOW( i, w ) \ 454 if( !(w) ) \ 455 { \ 456 THROW_RUNTIME_EXCEPTION( i, sMissingWindow ); \ 457 } 458 #endif 459 460