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 ACCESSIBILITY_EXT_ACCESSIBLEGRIDCONTROL_HXX 26 #define ACCESSIBILITY_EXT_ACCESSIBLEGRIDCONTROL_HXX 27 28 #include <accessibility/extended/AccessibleGridControlBase.hxx> 29 #include <accessibility/extended/AccessibleGridControlTable.hxx> 30 #include <cppuhelper/weakref.hxx> 31 #include <svtools/accessibletable.hxx> 32 33 #include <memory> 34 35 using namespace ::svt::table; 36 37 // ============================================================================ 38 39 namespace accessibility { 40 41 class AccessibleGridControl_Impl; 42 43 // ============================================================================ 44 45 /** This class represents the complete accessible Grid Control object. */ 46 class AccessibleGridControl : public AccessibleGridControlBase 47 { 48 friend class AccessibleGridControlAccess; 49 50 protected: 51 AccessibleGridControl( 52 const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxParent, 53 const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxCreator, 54 ::svt::table::IAccessibleTable& _rTable 55 ); 56 57 virtual ~AccessibleGridControl(); 58 59 /** Cleans up members. */ 60 using AccessibleGridControlBase::disposing; 61 virtual void SAL_CALL disposing(); 62 63 protected: 64 // XAccessibleContext ----------------------------------------------------- 65 66 /** @return The count of visible children. */ 67 virtual sal_Int32 SAL_CALL getAccessibleChildCount() 68 throw ( ::com::sun::star::uno::RuntimeException ); 69 70 /** @return The XAccessible interface of the specified child. */ 71 virtual ::com::sun::star::uno::Reference< 72 ::com::sun::star::accessibility::XAccessible > SAL_CALL 73 getAccessibleChild( sal_Int32 nChildIndex ) 74 throw ( ::com::sun::star::lang::IndexOutOfBoundsException, 75 ::com::sun::star::uno::RuntimeException ); 76 77 /** @return The role of this object (a table). */ 78 virtual sal_Int16 SAL_CALL getAccessibleRole() 79 throw ( ::com::sun::star::uno::RuntimeException ); 80 81 // XAccessibleComponent --------------------------------------------------- 82 83 /** @return 84 The accessible child rendered under the given point. 85 */ 86 virtual ::com::sun::star::uno::Reference< 87 ::com::sun::star::accessibility::XAccessible > SAL_CALL 88 getAccessibleAtPoint( const ::com::sun::star::awt::Point& rPoint ) 89 throw ( ::com::sun::star::uno::RuntimeException ); 90 91 /** Grabs the focus to the Grid Control. */ 92 virtual void SAL_CALL grabFocus() 93 throw ( ::com::sun::star::uno::RuntimeException ); 94 95 /** @return The key bindings associated with this object. */ 96 virtual ::com::sun::star::uno::Any SAL_CALL getAccessibleKeyBinding() 97 throw ( ::com::sun::star::uno::RuntimeException ); 98 99 // XServiceInfo ----------------------------------------------------------- 100 101 /** @return 102 The name of this class. 103 */ 104 virtual ::rtl::OUString SAL_CALL getImplementationName() 105 throw ( ::com::sun::star::uno::RuntimeException ); 106 107 public: 108 // helper functions 109 110 /** commitCellEvent commit the event at all listeners of the table 111 @param nEventId 112 the event id 113 @param rNewValue 114 the new value 115 @param rOldValue 116 the old value 117 */ 118 void commitCellEvent(sal_Int16 nEventId, const ::com::sun::star::uno::Any& rNewValue, 119 const ::com::sun::star::uno::Any& rOldValue); 120 121 /** commitTableEvent commit the event at all listeners of the table 122 @param nEventId 123 the event id 124 @param rNewValue 125 the new value 126 @param rOldValue 127 the old value 128 */ 129 void commitTableEvent(sal_Int16 nEventId, const ::com::sun::star::uno::Any& rNewValue, 130 const ::com::sun::star::uno::Any& rOldValue); 131 /** returns the accessible object for the row or the column header bar 132 */ 133 inline ::com::sun::star::uno::Reference< 134 ::com::sun::star::accessibility::XAccessible > getHeaderBar(::svt::table::AccessibleTableControlObjType _eObjType)135 getHeaderBar( ::svt::table::AccessibleTableControlObjType _eObjType ) 136 { 137 return implGetHeaderBar(_eObjType); 138 } 139 140 /** returns the accessible object for the table representation 141 */ 142 inline ::com::sun::star::uno::Reference< 143 ::com::sun::star::accessibility::XAccessible > getTable()144 getTable( ) 145 { 146 return implGetTable(); 147 } 148 149 protected: 150 // internal virtual methods ----------------------------------------------- 151 152 /** @attention This method requires locked mutex's and a living object. 153 @return The bounding box (VCL rect.) relative to the parent window. */ 154 virtual Rectangle implGetBoundingBox(); 155 /** @attention This method requires locked mutex's and a living object. 156 @return The bounding box (VCL rect.) in screen coordinates. */ 157 virtual Rectangle implGetBoundingBoxOnScreen(); 158 159 // internal helper methods ------------------------------------------------ 160 161 /** This method creates (once) and returns the accessible data table child. 162 @attention This method requires locked mutex's and a living object. 163 @return The XAccessible interface of the data table. */ 164 virtual ::com::sun::star::uno::Reference< 165 ::com::sun::star::accessibility::XAccessible > implGetTable(); 166 167 /** This method creates (once) and returns the specified header bar. 168 @attention This method requires locked mutex's and a living object. 169 @return The XAccessible interface of the header bar. */ 170 ::com::sun::star::uno::Reference< 171 ::com::sun::star::accessibility::XAccessible > 172 implGetHeaderBar( ::svt::table::AccessibleTableControlObjType eObjType ); 173 174 /** This method returns one of the children that are always present: 175 Data table, row and column header bar or corner control. 176 @attention This method requires locked mutex's and a living object. 177 @return The XAccessible interface of the specified child. */ 178 ::com::sun::star::uno::Reference< 179 ::com::sun::star::accessibility::XAccessible > 180 implGetFixedChild( sal_Int32 nChildIndex ); 181 182 /** This method creates and returns an accessible table. 183 @return An AccessibleGridControlTable. */ 184 virtual AccessibleGridControlTable* createAccessibleTable(); 185 186 private: 187 // members ---------------------------------------------------------------- 188 ::std::auto_ptr< AccessibleGridControl_Impl > m_pImpl; 189 }; 190 191 // ============================================================================ 192 /** the XAccessible which creates/returns an AccessibleGridControl 193 194 <p>The instance holds it's XAccessibleContext with a hard reference, while 195 the contxt holds this instance weak.</p> 196 */ 197 typedef ::cppu::WeakImplHelper1 < ::com::sun::star::accessibility::XAccessible > AccessibleGridControlAccess_Base; 198 199 class AccessibleGridControlAccess :public AccessibleGridControlAccess_Base 200 ,public ::svt::table::IAccessibleTableControl 201 { 202 private: 203 ::osl::Mutex m_aMutex; 204 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > 205 m_xParent; 206 ::svt::table::IAccessibleTable& m_rTable; 207 208 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > 209 m_xContext; 210 AccessibleGridControl* m_pContext; 211 // note that this pointer is valid as long as m_xContext is valid! 212 213 public: 214 AccessibleGridControlAccess( 215 const ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible >& _rxParent, 216 ::svt::table::IAccessibleTable& _rTable 217 ); 218 219 /// checks whether the accessible context is still alive 220 bool isContextAlive() const; 221 222 /// returns the AccessibleContext belonging to this Accessible getContext()223 inline AccessibleGridControl* getContext() { return m_pContext; } getContext() const224 inline const AccessibleGridControl* getContext() const { return m_pContext; } 225 226 protected: 227 virtual ~AccessibleGridControlAccess(); 228 229 // XAccessible 230 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessibleContext > 231 SAL_CALL getAccessibleContext() throw ( ::com::sun::star::uno::RuntimeException ); 232 233 // IAccessibleTable 234 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > getMyself()235 getMyself() 236 { 237 return this; 238 } 239 void dispose(); isAlive() const240 virtual sal_Bool isAlive() const 241 { 242 return isContextAlive(); 243 } 244 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > getTableHeader(::svt::table::AccessibleTableControlObjType _eObjType)245 getTableHeader( ::svt::table::AccessibleTableControlObjType _eObjType ) 246 { 247 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAccessible; 248 AccessibleGridControl* pContext( getContext() ); 249 if ( pContext ) 250 xAccessible = pContext->getHeaderBar( _eObjType ); 251 return xAccessible; 252 } 253 virtual ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > getTable()254 getTable() 255 { 256 ::com::sun::star::uno::Reference< ::com::sun::star::accessibility::XAccessible > xAccessible; 257 AccessibleGridControl* pContext( getContext() ); 258 if ( pContext ) 259 xAccessible = pContext->getTable(); 260 return xAccessible; 261 } commitCellEvent(sal_Int16 nEventId,const::com::sun::star::uno::Any & rNewValue,const::com::sun::star::uno::Any & rOldValue)262 virtual void commitCellEvent( sal_Int16 nEventId, 263 const ::com::sun::star::uno::Any& rNewValue, const ::com::sun::star::uno::Any& rOldValue ) 264 { 265 AccessibleGridControl* pContext( getContext() ); 266 if ( pContext ) 267 pContext->commitCellEvent( nEventId, rNewValue, rOldValue ); 268 } commitTableEvent(sal_Int16 nEventId,const::com::sun::star::uno::Any & rNewValue,const::com::sun::star::uno::Any & rOldValue)269 virtual void commitTableEvent( sal_Int16 nEventId, 270 const ::com::sun::star::uno::Any& rNewValue, const ::com::sun::star::uno::Any& rOldValue ) 271 { 272 AccessibleGridControl* pContext( getContext() ); 273 if ( pContext ) 274 pContext->commitTableEvent( nEventId, rNewValue, rOldValue ); 275 } commitEvent(sal_Int16 nEventId,const::com::sun::star::uno::Any & rNewValue,const::com::sun::star::uno::Any & rOldValue)276 virtual void commitEvent( sal_Int16 nEventId, 277 const ::com::sun::star::uno::Any& rNewValue, const ::com::sun::star::uno::Any& rOldValue ) 278 { 279 AccessibleGridControl* pContext( getContext() ); 280 if ( pContext ) 281 pContext->commitEvent( nEventId, rNewValue, rOldValue ); 282 } 283 284 private: 285 AccessibleGridControlAccess(); // never implemented 286 AccessibleGridControlAccess( const AccessibleGridControlAccess& ); // never implemented 287 AccessibleGridControlAccess& operator=( const AccessibleGridControlAccess& ); // never implemented 288 }; 289 290 // ============================================================================ 291 } // namespace accessibility 292 293 // ============================================================================ 294 295 #endif 296 297