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