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 25 #ifndef _SC_ACCESSIBLECONTEXTBASE_HXX 26 #define _SC_ACCESSIBLECONTEXTBASE_HXX 27 28 #include <com/sun/star/accessibility/XAccessible.hpp> 29 #include <com/sun/star/accessibility/XAccessibleComponent.hpp> 30 #include <com/sun/star/accessibility/XAccessibleContext.hpp> 31 #include <com/sun/star/accessibility/XAccessibleEventBroadcaster.hpp> 32 #ifndef _COM_SUN_STAR_ACCESSIBILITY_IllegalAccessibleComponentStateException_HPP_ 33 #include <com/sun/star/accessibility/IllegalAccessibleComponentStateException.hpp> 34 #endif 35 #include <com/sun/star/lang/DisposedException.hpp> 36 #include <com/sun/star/uno/Reference.hxx> 37 #include <cppuhelper/weak.hxx> 38 #include <com/sun/star/lang/XServiceInfo.hpp> 39 #include <com/sun/star/lang/XTypeProvider.hpp> 40 #include <com/sun/star/lang/XServiceName.hpp> 41 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> 42 #include <vos/mutex.hxx> 43 #include <cppuhelper/interfacecontainer.h> 44 45 46 #include <svl/lstner.hxx> 47 #include <cppuhelper/compbase5.hxx> 48 #include <cppuhelper/implbase1.hxx> 49 #include <comphelper/servicehelper.hxx> 50 #include <comphelper/broadcasthelper.hxx> 51 52 class Rectangle; 53 54 /** @descr 55 This base class provides an implementation of the 56 <code>AccessibleContext</code> service. 57 */ 58 59 typedef cppu::WeakAggComponentImplHelper5< 60 ::com::sun::star::accessibility::XAccessible, 61 ::com::sun::star::accessibility::XAccessibleComponent, 62 ::com::sun::star::accessibility::XAccessibleContext, 63 ::com::sun::star::accessibility::XAccessibleEventBroadcaster, 64 ::com::sun::star::lang::XServiceInfo 65 > ScAccessibleContextBaseWeakImpl; 66 67 typedef cppu::ImplHelper1< 68 ::com::sun::star::accessibility::XAccessibleEventListener 69 > ScAccessibleContextBaseImplEvent; 70 71 class ScAccessibleContextBase 72 : public comphelper::OBaseMutex, 73 public ScAccessibleContextBaseWeakImpl, 74 public ScAccessibleContextBaseImplEvent, 75 public SfxListener 76 { 77 public: 78 //===== internal ======================================================== 79 ScAccessibleContextBase( 80 const ::com::sun::star::uno::Reference< 81 ::com::sun::star::accessibility::XAccessible>& rxParent, 82 const sal_Int16 aRole); 83 84 virtual void Init(); 85 virtual void SAL_CALL disposing(); 86 protected: 87 virtual ~ScAccessibleContextBase(void); 88 public: 89 using WeakAggComponentImplHelperBase::addEventListener; 90 using WeakAggComponentImplHelperBase::removeEventListener; 91 92 ///===== SfxListener ===================================================== 93 94 virtual void Notify( SfxBroadcaster& rBC, const SfxHint& rHint ); 95 96 ///===== XInterface ===================================================== 97 98 virtual ::com::sun::star::uno::Any SAL_CALL queryInterface( 99 ::com::sun::star::uno::Type const & rType ) 100 throw (::com::sun::star::uno::RuntimeException); 101 102 virtual void SAL_CALL acquire() throw (); 103 104 virtual void SAL_CALL release() throw (); 105 106 ///===== XAccessible ===================================================== 107 108 /// Return the XAccessibleContext. 109 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext> SAL_CALL 110 getAccessibleContext(void) throw (::com::sun::star::uno::RuntimeException); 111 112 ///===== XAccessibleComponent ============================================ 113 114 virtual sal_Bool SAL_CALL containsPoint( 115 const ::com::sun::star::awt::Point& rPoint ) 116 throw (::com::sun::star::uno::RuntimeException); 117 118 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > 119 SAL_CALL getAccessibleAtPoint( 120 const ::com::sun::star::awt::Point& rPoint ) 121 throw (::com::sun::star::uno::RuntimeException); 122 123 virtual ::com::sun::star::awt::Rectangle SAL_CALL getBounds( ) 124 throw (::com::sun::star::uno::RuntimeException); 125 126 virtual ::com::sun::star::awt::Point SAL_CALL getLocation( ) 127 throw (::com::sun::star::uno::RuntimeException); 128 129 virtual ::com::sun::star::awt::Point SAL_CALL getLocationOnScreen( ) 130 throw (::com::sun::star::uno::RuntimeException); 131 132 virtual ::com::sun::star::awt::Size SAL_CALL getSize( ) 133 throw (::com::sun::star::uno::RuntimeException); 134 135 virtual sal_Bool SAL_CALL isShowing( ) 136 throw (::com::sun::star::uno::RuntimeException); 137 138 virtual sal_Bool SAL_CALL isVisible( ) 139 throw (::com::sun::star::uno::RuntimeException); 140 141 virtual void SAL_CALL grabFocus( ) 142 throw (::com::sun::star::uno::RuntimeException); 143 144 virtual sal_Int32 SAL_CALL getForeground( ) 145 throw (::com::sun::star::uno::RuntimeException); 146 147 virtual sal_Int32 SAL_CALL getBackground( ) 148 throw (::com::sun::star::uno::RuntimeException); 149 150 ///===== XAccessibleContext ============================================== 151 152 /// Return the number of currently visible children. 153 virtual sal_Int32 SAL_CALL 154 getAccessibleChildCount(void) throw (::com::sun::star::uno::RuntimeException); 155 156 /// Return the specified child or NULL if index is invalid. 157 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL 158 getAccessibleChild(sal_Int32 nIndex) 159 throw (::com::sun::star::uno::RuntimeException, 160 ::com::sun::star::lang::IndexOutOfBoundsException); 161 162 /// Return a reference to the parent. 163 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible> SAL_CALL 164 getAccessibleParent(void) 165 throw (::com::sun::star::uno::RuntimeException); 166 167 /// Return this objects index among the parents children. 168 virtual sal_Int32 SAL_CALL 169 getAccessibleIndexInParent(void) 170 throw (::com::sun::star::uno::RuntimeException); 171 172 /// Return this object's role. 173 virtual sal_Int16 SAL_CALL 174 getAccessibleRole(void) 175 throw (::com::sun::star::uno::RuntimeException); 176 177 /// Return this object's description. 178 virtual ::rtl::OUString SAL_CALL 179 getAccessibleDescription(void) 180 throw (::com::sun::star::uno::RuntimeException); 181 182 /// Return the object's current name. 183 virtual ::rtl::OUString SAL_CALL 184 getAccessibleName(void) 185 throw (::com::sun::star::uno::RuntimeException); 186 187 /// Return NULL to indicate that an empty relation set. 188 virtual ::com::sun::star::uno::Reference< 189 ::com::sun::star::accessibility::XAccessibleRelationSet> SAL_CALL 190 getAccessibleRelationSet(void) 191 throw (::com::sun::star::uno::RuntimeException); 192 193 /// Return the set of current states. 194 virtual ::com::sun::star::uno::Reference< 195 ::com::sun::star::accessibility::XAccessibleStateSet> SAL_CALL 196 getAccessibleStateSet(void) 197 throw (::com::sun::star::uno::RuntimeException); 198 199 /** Return the parents locale or throw exception if this object has no 200 parent yet/anymore. 201 */ 202 virtual ::com::sun::star::lang::Locale SAL_CALL 203 getLocale(void) 204 throw (::com::sun::star::uno::RuntimeException, 205 ::com::sun::star::accessibility::IllegalAccessibleComponentStateException); 206 207 ///===== XAccessibleEventBroadcaster ===================================== 208 209 /** Add listener that is informed of future changes of name, 210 description and so on events. 211 */ 212 virtual void SAL_CALL 213 addEventListener( 214 const ::com::sun::star::uno::Reference< 215 ::com::sun::star::accessibility::XAccessibleEventListener>& xListener) 216 throw (com::sun::star::uno::RuntimeException); 217 218 // Remove an existing event listener. 219 virtual void SAL_CALL 220 removeEventListener( 221 const ::com::sun::star::uno::Reference< 222 ::com::sun::star::accessibility::XAccessibleEventListener>& xListener) 223 throw (com::sun::star::uno::RuntimeException); 224 225 ///===== XAccessibleEventListener ======================================== 226 227 virtual void SAL_CALL 228 disposing( const ::com::sun::star::lang::EventObject& Source ) 229 throw (::com::sun::star::uno::RuntimeException); 230 231 virtual void SAL_CALL 232 notifyEvent( 233 const ::com::sun::star::accessibility::AccessibleEventObject& aEvent ) 234 throw (::com::sun::star::uno::RuntimeException); 235 236 ///===== XServiceInfo ==================================================== 237 238 /** Returns an identifier for the implementation of this object. 239 */ 240 virtual ::rtl::OUString SAL_CALL 241 getImplementationName(void) 242 throw (::com::sun::star::uno::RuntimeException); 243 244 /** Return whether the specified service is supported by this class. 245 */ 246 virtual sal_Bool SAL_CALL 247 supportsService(const ::rtl::OUString& sServiceName) 248 throw (::com::sun::star::uno::RuntimeException); 249 250 /** Returns a list of all supported services. In this case that is just 251 the AccessibleContext and Accessible service. 252 */ 253 virtual ::com::sun::star::uno::Sequence< ::rtl::OUString> SAL_CALL 254 getSupportedServiceNames(void) 255 throw (::com::sun::star::uno::RuntimeException); 256 257 ///===== XTypeProvider =================================================== 258 259 /// returns the possible types 260 virtual ::com::sun::star::uno::Sequence< ::com::sun::star::uno::Type > SAL_CALL 261 getTypes() 262 throw (::com::sun::star::uno::RuntimeException); 263 264 /** Returns a implementation id. 265 */ 266 virtual ::com::sun::star::uno::Sequence<sal_Int8> SAL_CALL 267 getImplementationId(void) 268 throw (::com::sun::star::uno::RuntimeException); 269 270 protected: 271 /// Return this object's description. 272 virtual ::rtl::OUString SAL_CALL 273 createAccessibleDescription(void) 274 throw (::com::sun::star::uno::RuntimeException); 275 276 /// Return the object's current name. 277 virtual ::rtl::OUString SAL_CALL 278 createAccessibleName(void) 279 throw (::com::sun::star::uno::RuntimeException); 280 281 /// Return the object's current bounding box relative to the desktop. 282 virtual Rectangle GetBoundingBoxOnScreen(void) const 283 throw (::com::sun::star::uno::RuntimeException); 284 285 /// Return the object's current bounding box relative to the parent object. 286 virtual Rectangle GetBoundingBox(void) const 287 throw (::com::sun::star::uno::RuntimeException); 288 289 public: 290 /// Calls all Listener to tell they the change. 291 void 292 CommitChange(const com::sun::star::accessibility::AccessibleEventObject& rEvent) const; 293 294 /// change the name and call the listener to tell they the change 295 void 296 ChangeName(); 297 298 protected: 299 /// Calls all FocusListener to tell they that the focus is gained. 300 void CommitFocusGained() const; 301 302 /// Calls all FocusListener to tell they that the focus is lost. 303 void CommitFocusLost() const; 304 IsDefunc() const305 sal_Bool IsDefunc() const { return rBHelper.bDisposed; } 306 307 virtual void IsObjectValid() const 308 throw (::com::sun::star::lang::DisposedException); 309 310 /// Use this method to set initial Name without notification SetName(const rtl::OUString & rName)311 void SetName(const rtl::OUString& rName) { msName = rName; } 312 /// Use this method to set initial Description without notification SetDescription(const rtl::OUString & rDesc)313 void SetDescription(const rtl::OUString& rDesc) { msDescription = rDesc; } 314 315 /// Reference to the parent object. 316 ::com::sun::star::uno::Reference< 317 ::com::sun::star::accessibility::XAccessible> mxParent; 318 319 private: 320 /** Description of this object. This is not a constant because it can 321 be set from the outside. Furthermore, it changes according the the 322 draw page's display mode. 323 */ 324 ::rtl::OUString msDescription; 325 326 /** Name of this object. It changes according the the draw page's 327 display mode. 328 */ 329 ::rtl::OUString msName; 330 331 /// client id in the AccessibleEventNotifier queue 332 sal_uInt32 mnClientId; 333 334 /** This is the role of this object. 335 */ 336 sal_Int16 maRole; 337 }; 338 339 340 #endif 341