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