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