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 24 #ifndef _SVX_ACCESSIBILITY_ACCESSIBLE_CONTEXT_BASE_HXX 25 #define _SVX_ACCESSIBILITY_ACCESSIBLE_CONTEXT_BASE_HXX 26 27 //#include <editeng/ChildrenManager.hxx> 28 #include <com/sun/star/accessibility/XAccessible.hpp> 29 #include <com/sun/star/accessibility/XAccessibleContext.hpp> 30 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp> 31 #include <com/sun/star/accessibility/XAccessibleStateSet.hpp> 32 #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp> 33 #include <com/sun/star/accessibility/AccessibleEventObject.hpp> 34 #include <com/sun/star/accessibility/AccessibleEventId.hpp> 35 #include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp> 36 #include <com/sun/star/uno/Reference.hxx> 37 #include <com/sun/star/lang/XComponent.hpp> 38 #include <cppuhelper/weak.hxx> 39 #include <com/sun/star/lang/XServiceInfo.hpp> 40 #include <com/sun/star/lang/XTypeProvider.hpp> 41 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> 42 #include <com/sun/star/lang/DisposedException.hpp> 43 #include <osl/mutex.hxx> 44 #include <cppuhelper/compbase4.hxx> 45 #include <editeng/editengdllapi.h> 46 47 48 namespace accessibility { 49 50 struct MutexOwner {mutable ::osl::Mutex maMutex;}; 51 52 /** @descr 53 This base class provides an implementation of the 54 <type>AccessibleContext</type> service. Apart from the 55 <type>XXAccessible<type> and <type>XAccessibleContextContext</type> 56 interfaces it supports the <type>XServiceInfo</type> interface. 57 */ 58 class EDITENG_DLLPUBLIC AccessibleContextBase 59 : public MutexOwner, 60 public cppu::WeakComponentImplHelper4< 61 ::com::sun::star::accessibility::XAccessible, 62 ::com::sun::star::accessibility::XAccessibleContext, 63 ::com::sun::star::accessibility::XAccessibleEventBroadcaster, 64 ::com::sun::star::lang::XServiceInfo 65 > 66 { 67 public: 68 69 //===== internal ======================================================== 70 71 /** The origin of the accessible name or description. 72 */ 73 enum StringOrigin { 74 ManuallySet, 75 FromShape, 76 AutomaticallyCreated, 77 NotSet 78 }; 79 80 AccessibleContextBase ( 81 const ::com::sun::star::uno::Reference< 82 ::com::sun::star::accessibility::XAccessible>& rxParent, 83 const sal_Int16 aRole); 84 virtual ~AccessibleContextBase (void); 85 86 87 /** Call all accessibility event listeners to inform them about the 88 specified event. 89 @param aEventId 90 Id of the event type. 91 @param rNewValue 92 New value of the modified attribute. Pass empty structure if 93 not applicable. 94 @param rOldValue 95 Old value of the modified attribute. Pass empty structure if 96 not applicable. 97 */ 98 void CommitChange (sal_Int16 aEventId, 99 const ::com::sun::star::uno::Any& rNewValue, 100 const ::com::sun::star::uno::Any& rOldValue); 101 102 /** Set a new description and, provided that the new name differs from 103 the old one, broadcast an accessibility event. 104 @param rsDescription 105 The new description. 106 @param eDescriptionOrigin 107 The origin of the description. This is used to determine 108 whether the given description overrules the existing one. An 109 origin with a lower numerical value overrides one with a higher 110 value. 111 */ 112 void SetAccessibleDescription ( 113 const ::rtl::OUString& rsDescription, 114 StringOrigin eDescriptionOrigin) 115 throw (::com::sun::star::uno::RuntimeException); 116 117 /** Set a new description and, provided that the new name differs from 118 the old one, broadcast an accessibility event. 119 @param rsName 120 The new name. 121 @param eNameOrigin 122 The origin of the name. This is used to determine whether the 123 given name overrules the existing one. An origin with a lower 124 numerical value overrides one with a higher value. 125 */ 126 void SetAccessibleName ( 127 const ::rtl::OUString& rsName, 128 StringOrigin eNameOrigin) 129 throw (::com::sun::star::uno::RuntimeException); 130 131 /** Set the specified state (turn it on) and send events to all 132 listeners to inform them of the change. 133 134 @param aState 135 The state to turn on. 136 137 @return 138 If the specified state changed its value due to this call 139 <TRUE/> is returned, otherwise <FALSE/>. 140 */ 141 virtual sal_Bool SetState (sal_Int16 aState); 142 143 /** Reset the specified state (turn it off) and send events to all 144 listeners to inform them of the change. 145 146 @param aState 147 The state to turn off. 148 149 @return 150 If the specified state changed its value due to this call 151 <TRUE/> is returned, otherwise <FALSE/>. 152 */ 153 virtual sal_Bool ResetState (sal_Int16 aState); 154 155 /** Return the state of the specified state. 156 157 @param aState 158 The state for which to return its value. 159 160 @return 161 A value of <TRUE/> indicates that the state is set. A <FALSE/> 162 value indicates an unset state. 163 */ 164 sal_Bool GetState (sal_Int16 aState); 165 166 /** Replace the current relation set with the specified one. Send 167 events for relations that are not in both sets. 168 169 @param rRelationSet 170 The new relation set that replaces the old one. 171 */ 172 virtual void SetRelationSet ( 173 const ::com::sun::star::uno::Reference< 174 ::com::sun::star::accessibility::XAccessibleRelationSet>& rxRelationSet) 175 throw (::com::sun::star::uno::RuntimeException); 176 177 178 //===== XAccessible ===================================================== 179 180 /// Return the XAccessibleContext. 181 virtual ::com::sun::star::uno::Reference< 182 ::com::sun::star::accessibility::XAccessibleContext> SAL_CALL 183 getAccessibleContext (void) throw (::com::sun::star::uno::RuntimeException); 184 185 186 //===== XAccessibleContext ============================================== 187 188 /// Return the number of currently visible children. 189 virtual sal_Int32 SAL_CALL 190 getAccessibleChildCount (void) throw (::com::sun::star::uno::RuntimeException); 191 192 /// Return the specified child or throw exception. 193 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL 194 getAccessibleChild (sal_Int32 nIndex) 195 throw (::com::sun::star::lang::IndexOutOfBoundsException, ::com::sun::star::uno::RuntimeException); 196 197 /// Return a reference to the parent. 198 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL 199 getAccessibleParent (void) 200 throw (::com::sun::star::uno::RuntimeException); 201 202 /// Return this objects index among the parents children. 203 virtual sal_Int32 SAL_CALL 204 getAccessibleIndexInParent (void) 205 throw (::com::sun::star::uno::RuntimeException); 206 207 /// Return this object's role. 208 virtual sal_Int16 SAL_CALL 209 getAccessibleRole (void) 210 throw (::com::sun::star::uno::RuntimeException); 211 212 /// Return this object's description. 213 virtual ::rtl::OUString SAL_CALL 214 getAccessibleDescription (void) 215 throw (::com::sun::star::uno::RuntimeException); 216 217 /// Return the object's current name. 218 virtual ::rtl::OUString SAL_CALL 219 getAccessibleName (void) 220 throw (::com::sun::star::uno::RuntimeException); 221 222 /// Return NULL to indicate that an empty relation set. 223 virtual ::com::sun::star::uno::Reference< 224 ::com::sun::star::accessibility::XAccessibleRelationSet> SAL_CALL 225 getAccessibleRelationSet (void) 226 throw (::com::sun::star::uno::RuntimeException); 227 228 /// Return the set of current states. 229 virtual ::com::sun::star::uno::Reference< 230 ::com::sun::star::accessibility::XAccessibleStateSet> SAL_CALL 231 getAccessibleStateSet (void) 232 throw (::com::sun::star::uno::RuntimeException); 233 234 /** Return the parents locale or throw exception if this object has no 235 parent yet/anymore. 236 */ 237 virtual ::com::sun::star::lang::Locale SAL_CALL 238 getLocale (void) 239 throw (::com::sun::star::uno::RuntimeException, 240 ::com::sun::star::accessibility::IllegalAccessibleComponentStateException); 241 242 //===== XComponent ======================================================== 243 244 using WeakComponentImplHelperBase::addEventListener; 245 using WeakComponentImplHelperBase::removeEventListener; 246 247 //===== XAccessibleEventBroadcaster ======================================== 248 249 virtual void SAL_CALL 250 addEventListener ( 251 const ::com::sun::star::uno::Reference< 252 ::com::sun::star::accessibility::XAccessibleEventListener >& xListener) 253 throw (::com::sun::star::uno::RuntimeException); 254 255 virtual void SAL_CALL 256 removeEventListener ( 257 const ::com::sun::star::uno::Reference< 258 ::com::sun::star::accessibility::XAccessibleEventListener >& xListener) 259 throw (::com::sun::star::uno::RuntimeException); 260 261 262 //===== XServiceInfo ==================================================== 263 264 /** Returns an identifier for the implementation of this object. 265 */ 266 virtual ::rtl::OUString SAL_CALL 267 getImplementationName (void) 268 throw (::com::sun::star::uno::RuntimeException); 269 270 /** Return whether the specified service is supported by this class. 271 */ 272 virtual sal_Bool SAL_CALL 273 supportsService (const ::rtl::OUString& sServiceName) 274 throw (::com::sun::star::uno::RuntimeException); 275 276 /** Returns a list of all supported services. In this case that is just 277 the AccessibleContext service. 278 */ 279 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL 280 getSupportedServiceNames (void) 281 throw (::com::sun::star::uno::RuntimeException); 282 283 284 //===== XTypeProvider =================================================== 285 286 /** Returns a sequence of all supported interfaces. 287 */ 288 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> SAL_CALL 289 getTypes (void) 290 throw (::com::sun::star::uno::RuntimeException); 291 292 /** Returns a implementation id. 293 */ 294 virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL 295 getImplementationId (void) 296 throw (::com::sun::star::uno::RuntimeException); 297 298 protected: 299 /** The state set. 300 */ 301 ::com::sun::star::uno::Reference< 302 ::com::sun::star::accessibility::XAccessibleStateSet> mxStateSet; 303 304 /** The relation set. Relations can be set or removed by calling the 305 <member>AddRelation</member> and <member>RemoveRelation</member> methods. 306 */ 307 ::com::sun::star::uno::Reference< 308 ::com::sun::star::accessibility::XAccessibleRelationSet> mxRelationSet; 309 310 // This method is called from the component helper base class while disposing. 311 virtual void SAL_CALL disposing (void); 312 313 /** Create the accessible object's name. This method may be called more 314 than once for a single object. 315 @return 316 The returned string is a unique (among the accessible object's 317 siblings) name. 318 */ 319 virtual ::rtl::OUString CreateAccessibleName (void) 320 throw (::com::sun::star::uno::RuntimeException); 321 322 /** Create the accessible object's descriptive string. May be called 323 more than once. 324 @return 325 Descriptive string. Not necessarily unique. 326 */ 327 virtual ::rtl::OUString 328 CreateAccessibleDescription (void) 329 throw (::com::sun::star::uno::RuntimeException); 330 331 void FireEvent (const ::com::sun::star::accessibility::AccessibleEventObject& aEvent); 332 333 /** Check whether or not the object has been disposed (or is in the 334 state of being disposed). If that is the case then 335 DisposedException is thrown to inform the (indirect) caller of the 336 foul deed. 337 */ 338 void ThrowIfDisposed (void) 339 throw (::com::sun::star::lang::DisposedException); 340 341 /** Check whether or not the object has been disposed (or is in the 342 state of being disposed). 343 344 @return TRUE, if the object is disposed or in the course 345 of being disposed. Otherwise, FALSE is returned. 346 */ 347 sal_Bool IsDisposed (void); 348 349 /** sets the role as returned by XaccessibleContext::getAccessibleRole 350 351 <p>Caution: This is only to be used in the construction phase (means within 352 the ctor or late ctor), <em>never</em> when the object is still alive and part 353 of an Accessibility hierarchy.</p> 354 */ 355 void SetAccessibleRole( sal_Int16 _nRole ); 356 357 private: 358 /// Reference to the parent object. 359 ::com::sun::star::uno::Reference< 360 ::com::sun::star::accessibility::XAccessible> mxParent; 361 362 /** Description of this object. This is not a constant because it can 363 be set from the outside. Furthermore, it changes according the the 364 draw page's display mode. 365 */ 366 ::rtl::OUString msDescription; 367 368 /** The origin of the description is used to determine whether new 369 descriptions given to the SetAccessibleDescription is ignored or 370 whether that replaces the old value in msDescription. 371 */ 372 StringOrigin meDescriptionOrigin; 373 374 /** Name of this object. It changes according to the draw page's 375 display mode. 376 */ 377 ::rtl::OUString msName; 378 379 /** The origin of the name is used to determine whether new 380 name given to the SetAccessibleName is ignored or 381 whether that replaces the old value in msName. 382 */ 383 StringOrigin meNameOrigin; 384 385 /** client id in the AccessibleEventNotifier queue 386 */ 387 sal_uInt32 mnClientId; 388 389 /** This is the role of this object. 390 */ 391 sal_Int16 maRole; 392 }; 393 394 } 395 396 #endif 397