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 116 /** Set a new description and, provided that the new name differs from 117 the old one, broadcast an accessibility event. 118 @param rsName 119 The new name. 120 @param eNameOrigin 121 The origin of the name. This is used to determine whether the 122 given name overrules the existing one. An origin with a lower 123 numerical value overrides one with a higher value. 124 */ 125 void SetAccessibleName ( 126 const ::rtl::OUString& rsName, 127 StringOrigin eNameOrigin); 128 129 /** Set the specified state (turn it on) and send events to all 130 listeners to inform them of the change. 131 132 @param aState 133 The state to turn on. 134 135 @return 136 If the specified state changed its value due to this call 137 <TRUE/> is returned, otherwise <FALSE/>. 138 */ 139 virtual sal_Bool SetState (sal_Int16 aState); 140 141 /** Reset the specified state (turn it off) and send events to all 142 listeners to inform them of the change. 143 144 @param aState 145 The state to turn off. 146 147 @return 148 If the specified state changed its value due to this call 149 <TRUE/> is returned, otherwise <FALSE/>. 150 */ 151 virtual sal_Bool ResetState (sal_Int16 aState); 152 153 /** Return the state of the specified state. 154 155 @param aState 156 The state for which to return its value. 157 158 @return 159 A value of <TRUE/> indicates that the state is set. A <FALSE/> 160 value indicates an unset state. 161 */ 162 sal_Bool GetState (sal_Int16 aState); 163 164 /** Replace the current relation set with the specified one. Send 165 events for relations that are not in both sets. 166 167 @param rRelationSet 168 The new relation set that replaces the old one. 169 */ 170 virtual void SetRelationSet ( 171 const ::com::sun::star::uno::Reference< 172 ::com::sun::star::accessibility::XAccessibleRelationSet>& rxRelationSet); 173 174 175 //===== XAccessible ===================================================== 176 177 /// Return the XAccessibleContext. 178 virtual ::com::sun::star::uno::Reference< 179 ::com::sun::star::accessibility::XAccessibleContext> SAL_CALL 180 getAccessibleContext (void); 181 182 183 //===== XAccessibleContext ============================================== 184 185 /// Return the number of currently visible children. 186 virtual sal_Int32 SAL_CALL 187 getAccessibleChildCount (void); 188 189 /// Return the specified child or throw exception. 190 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL 191 getAccessibleChild (sal_Int32 nIndex); 192 193 /// Return a reference to the parent. 194 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL 195 getAccessibleParent (void); 196 197 /// Return this objects index among the parents children. 198 virtual sal_Int32 SAL_CALL 199 getAccessibleIndexInParent (void); 200 201 /// Return this object's role. 202 virtual sal_Int16 SAL_CALL 203 getAccessibleRole (void); 204 205 /// Return this object's description. 206 virtual ::rtl::OUString SAL_CALL 207 getAccessibleDescription (void); 208 209 /// Return the object's current name. 210 virtual ::rtl::OUString SAL_CALL 211 getAccessibleName (void); 212 213 /// Return NULL to indicate that an empty relation set. 214 virtual ::com::sun::star::uno::Reference< 215 ::com::sun::star::accessibility::XAccessibleRelationSet> SAL_CALL 216 getAccessibleRelationSet (void); 217 218 /// Return the set of current states. 219 virtual ::com::sun::star::uno::Reference< 220 ::com::sun::star::accessibility::XAccessibleStateSet> SAL_CALL 221 getAccessibleStateSet (void); 222 223 /** Return the parents locale or throw exception if this object has no 224 parent yet/anymore. 225 */ 226 virtual ::com::sun::star::lang::Locale SAL_CALL 227 getLocale (void); 228 229 //===== XComponent ======================================================== 230 231 using WeakComponentImplHelperBase::addEventListener; 232 using WeakComponentImplHelperBase::removeEventListener; 233 234 //===== XAccessibleEventBroadcaster ======================================== 235 236 virtual void SAL_CALL 237 addEventListener ( 238 const ::com::sun::star::uno::Reference< 239 ::com::sun::star::accessibility::XAccessibleEventListener >& xListener); 240 241 virtual void SAL_CALL 242 removeEventListener ( 243 const ::com::sun::star::uno::Reference< 244 ::com::sun::star::accessibility::XAccessibleEventListener >& xListener); 245 246 247 //===== XServiceInfo ==================================================== 248 249 /** Returns an identifier for the implementation of this object. 250 */ 251 virtual ::rtl::OUString SAL_CALL 252 getImplementationName (void); 253 254 /** Return whether the specified service is supported by this class. 255 */ 256 virtual sal_Bool SAL_CALL 257 supportsService (const ::rtl::OUString& sServiceName); 258 259 /** Returns a list of all supported services. In this case that is just 260 the AccessibleContext service. 261 */ 262 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL 263 getSupportedServiceNames (void); 264 265 266 //===== XTypeProvider =================================================== 267 268 /** Returns a sequence of all supported interfaces. 269 */ 270 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type> SAL_CALL 271 getTypes (void); 272 273 /** Returns a implementation id. 274 */ 275 virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL 276 getImplementationId (void); 277 278 protected: 279 /** The state set. 280 */ 281 ::com::sun::star::uno::Reference< 282 ::com::sun::star::accessibility::XAccessibleStateSet> mxStateSet; 283 284 /** The relation set. Relations can be set or removed by calling the 285 <member>AddRelation</member> and <member>RemoveRelation</member> methods. 286 */ 287 ::com::sun::star::uno::Reference< 288 ::com::sun::star::accessibility::XAccessibleRelationSet> mxRelationSet; 289 290 // This method is called from the component helper base class while disposing. 291 virtual void SAL_CALL disposing (void); 292 293 /** Create the accessible object's name. This method may be called more 294 than once for a single object. 295 @return 296 The returned string is a unique (among the accessible object's 297 siblings) name. 298 */ 299 virtual ::rtl::OUString CreateAccessibleName (void); 300 301 /** Create the accessible object's descriptive string. May be called 302 more than once. 303 @return 304 Descriptive string. Not necessarily unique. 305 */ 306 virtual ::rtl::OUString 307 CreateAccessibleDescription (void); 308 309 void FireEvent (const ::com::sun::star::accessibility::AccessibleEventObject& aEvent); 310 311 /** Check whether or not the object has been disposed (or is in the 312 state of being disposed). If that is the case then 313 DisposedException is thrown to inform the (indirect) caller of the 314 foul deed. 315 */ 316 void ThrowIfDisposed (void); 317 318 /** Check whether or not the object has been disposed (or is in the 319 state of being disposed). 320 321 @return TRUE, if the object is disposed or in the course 322 of being disposed. Otherwise, FALSE is returned. 323 */ 324 sal_Bool IsDisposed (void); 325 326 /** sets the role as returned by XaccessibleContext::getAccessibleRole 327 328 <p>Caution: This is only to be used in the construction phase (means within 329 the ctor or late ctor), <em>never</em> when the object is still alive and part 330 of an Accessibility hierarchy.</p> 331 */ 332 void SetAccessibleRole( sal_Int16 _nRole ); 333 334 private: 335 /// Reference to the parent object. 336 ::com::sun::star::uno::Reference< 337 ::com::sun::star::accessibility::XAccessible> mxParent; 338 339 /** Description of this object. This is not a constant because it can 340 be set from the outside. Furthermore, it changes according to the 341 draw page's display mode. 342 */ 343 ::rtl::OUString msDescription; 344 345 /** The origin of the description is used to determine whether new 346 descriptions given to the SetAccessibleDescription is ignored or 347 whether that replaces the old value in msDescription. 348 */ 349 StringOrigin meDescriptionOrigin; 350 351 /** Name of this object. It changes according to the draw page's 352 display mode. 353 */ 354 ::rtl::OUString msName; 355 356 /** The origin of the name is used to determine whether new 357 name given to the SetAccessibleName is ignored or 358 whether that replaces the old value in msName. 359 */ 360 StringOrigin meNameOrigin; 361 362 /** client id in the AccessibleEventNotifier queue 363 */ 364 sal_uInt32 mnClientId; 365 366 /** This is the role of this object. 367 */ 368 sal_Int16 maRole; 369 }; 370 371 } 372 373 #endif 374