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 // MARKER(update_precomp.py): autogen include statement, do not remove 25 #include "precompiled_sw.hxx" 26 27 #include <com/sun/star/accessibility/XAccessibleContext.hpp> 28 #include <rtl/uuid.h> 29 #include <vos/mutex.hxx> 30 #include <vcl/svapp.hxx> 31 #include <com/sun/star/accessibility/AccessibleRole.hpp> 32 #include <com/sun/star/accessibility/AccessibleStateType.hpp> 33 #include <com/sun/star/accessibility/AccessibleRelation.hpp> 34 #include <com/sun/star/accessibility/AccessibleRelationType.hpp> 35 #include <com/sun/star/accessibility/XAccessibleRelationSet.hpp> 36 #include <com/sun/star/accessibility/AccessibleEventId.hpp> 37 #include <unotools/accessiblestatesethelper.hxx> 38 #include <frmfmt.hxx> 39 #include <flyfrm.hxx> 40 #include <accmap.hxx> 41 #include <unotools/accessiblerelationsethelper.hxx> 42 // --> OD 2009-07-14 #i73249# 43 #include <hints.hxx> 44 // <-- 45 #include "acctextframe.hxx" 46 47 //IAccessibility2 Implementation 2009----- 48 #ifndef _DOC_HXX 49 #include <doc.hxx> 50 #endif 51 //-----IAccessibility2 Implementation 2009 52 using namespace ::com::sun::star; 53 using namespace ::com::sun::star::accessibility; 54 using ::rtl::OUString; 55 56 using utl::AccessibleRelationSetHelper; 57 using ::com::sun::star::accessibility::XAccessibleContext; 58 59 const sal_Char sServiceName[] = "com.sun.star.text.AccessibleTextFrameView"; 60 const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessibleTextFrameView"; 61 62 SwAccessibleTextFrame::SwAccessibleTextFrame( 63 SwAccessibleMap* pInitMap, 64 const SwFlyFrm* pFlyFrm ) : 65 SwAccessibleFrameBase( pInitMap, AccessibleRole::TEXT_FRAME, pFlyFrm ), 66 msTitle(), 67 msDesc() 68 { 69 if ( pFlyFrm ) 70 { 71 const SwFlyFrmFmt* pFlyFrmFmt = 72 dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() ); 73 msTitle = pFlyFrmFmt->GetObjTitle(); 74 75 msDesc = pFlyFrmFmt->GetObjDescription(); 76 if ( msDesc.getLength() == 0 && 77 msTitle != GetName() ) 78 { 79 msDesc = msTitle; 80 } 81 } 82 } 83 84 SwAccessibleTextFrame::~SwAccessibleTextFrame() 85 { 86 } 87 88 void SwAccessibleTextFrame::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) 89 { 90 const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ; 91 // --> OD 2009-07-14 #i73249# 92 // suppress handling of RES_NAME_CHANGED in case that attribute Title is 93 // used as the accessible name. 94 if ( nWhich != RES_NAME_CHANGED || 95 msTitle.getLength() == 0 ) 96 { 97 SwAccessibleFrameBase::Modify( pOld, pNew ); 98 } 99 100 const SwFlyFrm *pFlyFrm = static_cast< const SwFlyFrm * >( GetFrm() ); 101 switch( nWhich ) 102 { 103 // --> OD 2009-07-14 #i73249# 104 case RES_TITLE_CHANGED: 105 { 106 const String& sOldTitle( 107 dynamic_cast<const SwStringMsgPoolItem*>(pOld)->GetString() ); 108 const String& sNewTitle( 109 dynamic_cast<const SwStringMsgPoolItem*>(pNew)->GetString() ); 110 if ( sOldTitle == sNewTitle ) 111 { 112 break; 113 } 114 msTitle = sNewTitle; 115 AccessibleEventObject aEvent; 116 aEvent.EventId = AccessibleEventId::NAME_CHANGED; 117 aEvent.OldValue <<= OUString( sOldTitle ); 118 aEvent.NewValue <<= msTitle; 119 FireAccessibleEvent( aEvent ); 120 121 const SwFlyFrmFmt* pFlyFrmFmt = 122 dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() ); 123 if ( pFlyFrmFmt->GetObjDescription().Len() != 0 ) 124 { 125 break; 126 } 127 } 128 // intentional no break here 129 case RES_DESCRIPTION_CHANGED: 130 { 131 if ( pFlyFrm ) 132 { 133 const OUString sOldDesc( msDesc ); 134 135 const SwFlyFrmFmt* pFlyFrmFmt = 136 dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() ); 137 const String& rDesc = pFlyFrmFmt->GetObjDescription(); 138 msDesc = rDesc; 139 if ( msDesc.getLength() == 0 && 140 msTitle != GetName() ) 141 { 142 msDesc = msTitle; 143 } 144 145 if ( msDesc != sOldDesc ) 146 { 147 AccessibleEventObject aEvent; 148 aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED; 149 aEvent.OldValue <<= sOldDesc; 150 aEvent.NewValue <<= msDesc; 151 FireAccessibleEvent( aEvent ); 152 } 153 } 154 } 155 break; 156 // <-- 157 } 158 } 159 160 //IAccessibility2 Implementation 2009----- 161 //===== XInterface ========================================================== 162 163 com::sun::star::uno::Any SAL_CALL 164 SwAccessibleTextFrame::queryInterface (const com::sun::star::uno::Type & rType) 165 throw (::com::sun::star::uno::RuntimeException) 166 { 167 ::com::sun::star::uno::Any aReturn = SwAccessibleContext::queryInterface (rType); 168 if ( ! aReturn.hasValue()) 169 aReturn = ::cppu::queryInterface (rType, 170 static_cast< ::com::sun::star::accessibility::XAccessibleSelection* >(this) 171 ); 172 return aReturn; 173 } 174 175 176 177 178 void SAL_CALL 179 SwAccessibleTextFrame::acquire (void) 180 throw () 181 { 182 SwAccessibleContext::acquire (); 183 } 184 185 void SAL_CALL 186 SwAccessibleTextFrame::release (void) 187 throw () 188 { 189 SwAccessibleContext::release (); 190 } 191 192 // added by qiuhd, 193 // 194 //===== XAccessibleSelection ============================================ 195 // 196 197 //-------------------------------------------------------------------------------- 198 void SAL_CALL SwAccessibleTextFrame::selectAccessibleChild( sal_Int32 ) 199 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException ) 200 { 201 DBG_ASSERT( false, "<SwAccessibleTextFrame::selectAccessibleChild( sal_Int32 )> - missing implementation" ); 202 } 203 204 //---------------------------------------------------------------------------------- 205 sal_Bool SAL_CALL SwAccessibleTextFrame::isAccessibleChildSelected( sal_Int32 nChildIndex ) 206 throw (lang::IndexOutOfBoundsException, uno::RuntimeException ) 207 { 208 uno::Reference<XAccessible> xAcc = getAccessibleChild( nChildIndex ); 209 uno::Reference<XAccessibleContext> xContext; 210 if( xAcc.is() ) 211 xContext = xAcc->getAccessibleContext(); 212 213 if( xContext.is() ) 214 { 215 if( xContext->getAccessibleRole() == AccessibleRole::PARAGRAPH ) 216 { 217 uno::Reference< ::com::sun::star::accessibility::XAccessibleText > 218 xText(xAcc, uno::UNO_QUERY); 219 if( xText.is() ) 220 { 221 if( xText->getSelectionStart() >= 0 ) return sal_True; 222 } 223 } 224 } 225 226 return sal_False; 227 } 228 229 //--------------------------------------------------------------------- 230 void SAL_CALL SwAccessibleTextFrame::clearAccessibleSelection( ) 231 throw ( uno::RuntimeException ) 232 { 233 DBG_ASSERT( false, "<SwAccessibleTextFrame::clearAccessibleSelection( )> - missing implementation" ); 234 } 235 236 //------------------------------------------------------------------------- 237 void SAL_CALL SwAccessibleTextFrame::selectAllAccessibleChildren( ) 238 throw ( uno::RuntimeException ) 239 { 240 DBG_ASSERT( false, "<SwAccessibleTextFrame::selectAllAccessibleChildren( )> - missing implementation" ); 241 } 242 243 //---------------------------------------------------------------------------- 244 sal_Int32 SAL_CALL SwAccessibleTextFrame::getSelectedAccessibleChildCount() 245 throw ( uno::RuntimeException ) 246 { 247 sal_Int32 nCount = 0; 248 sal_Int32 TotalCount = getAccessibleChildCount(); 249 for( sal_Int32 i = 0; i < TotalCount; i++ ) 250 if( isAccessibleChildSelected(i) ) nCount++; 251 252 return nCount; 253 } 254 255 //-------------------------------------------------------------------------------------- 256 uno::Reference<XAccessible> SAL_CALL SwAccessibleTextFrame::getSelectedAccessibleChild( sal_Int32 nSelectedChildIndex ) 257 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException) 258 { 259 if ( nSelectedChildIndex > getSelectedAccessibleChildCount() ) 260 throw lang::IndexOutOfBoundsException(); 261 sal_Int32 i1, i2; 262 for( i1 = 0, i2 = 0; i1 < getAccessibleChildCount(); i1++ ) 263 if( isAccessibleChildSelected(i1) ) 264 { 265 if( i2 == nSelectedChildIndex ) 266 return getAccessibleChild( i1 ); 267 i2++; 268 } 269 return uno::Reference<XAccessible>(); 270 } 271 272 //---------------------------------------------------------------------------------- 273 void SAL_CALL SwAccessibleTextFrame::deselectAccessibleChild( sal_Int32 ) 274 throw ( lang::IndexOutOfBoundsException, uno::RuntimeException ) 275 { 276 DBG_ASSERT( false, "<SwAccessibleTextFrame::selectAllAccessibleChildren( sal_Int32 )> - missing implementation" ); 277 } 278 //-----IAccessibility2 Implementation 2009 279 280 // --> OD 2009-07-14 #i73249# 281 OUString SAL_CALL SwAccessibleTextFrame::getAccessibleName (void) 282 throw (uno::RuntimeException) 283 { 284 vos::OGuard aGuard(Application::GetSolarMutex()); 285 286 CHECK_FOR_DEFUNC( XAccessibleContext ) 287 288 if ( msTitle.getLength() != 0 ) 289 { 290 return msTitle; 291 } 292 293 return SwAccessibleFrameBase::getAccessibleName(); 294 } 295 // <-- 296 297 OUString SAL_CALL SwAccessibleTextFrame::getAccessibleDescription (void) 298 throw (uno::RuntimeException) 299 { 300 vos::OGuard aGuard(Application::GetSolarMutex()); 301 302 CHECK_FOR_DEFUNC( XAccessibleContext ) 303 /* MT: I guess msDesc is correct noadays? 304 //IAccessibility2 Implementation 2009----- 305 OUString longDesc; 306 const SwFlyFrmFmt* pFlyFmt = GetShell()->GetDoc()->FindFlyByName( GetName(), 0); 307 if( pFlyFmt ) 308 { 309 longDesc = OUString( pFlyFmt->GetDescription() ); 310 } 311 if( longDesc.getLength() > 0 ) 312 return GetName() + OUString(' ') + longDesc; 313 else 314 return GetName(); 315 //-----IAccessibility2 Implementation 2009 316 */ 317 318 return msDesc; 319 } 320 321 OUString SAL_CALL SwAccessibleTextFrame::getImplementationName() 322 throw( uno::RuntimeException ) 323 { 324 return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationName)); 325 } 326 327 sal_Bool SAL_CALL SwAccessibleTextFrame::supportsService( 328 const OUString& sTestServiceName) 329 throw (uno::RuntimeException) 330 { 331 return sTestServiceName.equalsAsciiL( sServiceName, 332 sizeof(sServiceName)-1 ) || 333 sTestServiceName.equalsAsciiL( sAccessibleServiceName, 334 sizeof(sAccessibleServiceName)-1 ); 335 } 336 337 uno::Sequence< OUString > SAL_CALL SwAccessibleTextFrame::getSupportedServiceNames() 338 throw( uno::RuntimeException ) 339 { 340 uno::Sequence< OUString > aRet(2); 341 OUString* pArray = aRet.getArray(); 342 pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceName) ); 343 pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) ); 344 return aRet; 345 } 346 347 uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleTextFrame::getImplementationId() 348 throw(uno::RuntimeException) 349 { 350 vos::OGuard aGuard(Application::GetSolarMutex()); 351 static uno::Sequence< sal_Int8 > aId( 16 ); 352 static sal_Bool bInit = sal_False; 353 if(!bInit) 354 { 355 rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True ); 356 bInit = sal_True; 357 } 358 return aId; 359 } 360 361 362 // 363 // XAccessibleRelationSet 364 // 365 366 367 SwFlyFrm* SwAccessibleTextFrame::getFlyFrm() const 368 { 369 SwFlyFrm* pFlyFrm = NULL; 370 371 const SwFrm* pFrm = GetFrm(); 372 DBG_ASSERT( pFrm != NULL, "frame expected" ); 373 if( pFrm->IsFlyFrm() ) 374 { 375 pFlyFrm = static_cast<SwFlyFrm*>( const_cast<SwFrm*>( pFrm ) ); 376 } 377 378 return pFlyFrm; 379 } 380 381 AccessibleRelation SwAccessibleTextFrame::makeRelation( sal_Int16 nType, const SwFlyFrm* pFrm ) 382 { 383 uno::Sequence<uno::Reference<XInterface> > aSequence(1); 384 aSequence[0] = GetMap()->GetContext( pFrm ); 385 return AccessibleRelation( nType, aSequence ); 386 } 387 388 389 uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleTextFrame::getAccessibleRelationSet( ) 390 throw ( uno::RuntimeException ) 391 { 392 vos::OGuard aGuard(Application::GetSolarMutex()); 393 CHECK_FOR_DEFUNC( XAccessibleContext ); 394 395 // get the frame, and insert prev/next relations into helper 396 397 AccessibleRelationSetHelper* pHelper = new AccessibleRelationSetHelper(); 398 399 SwFlyFrm* pFlyFrm = getFlyFrm(); 400 DBG_ASSERT( pFlyFrm != NULL, "fly frame expected" ); 401 402 const SwFlyFrm* pPrevFrm = pFlyFrm->GetPrevLink(); 403 if( pPrevFrm != NULL ) 404 pHelper->AddRelation( makeRelation( 405 AccessibleRelationType::CONTENT_FLOWS_FROM, pPrevFrm ) ); 406 407 const SwFlyFrm* pNextFrm = pFlyFrm->GetNextLink(); 408 if( pNextFrm != NULL ) 409 pHelper->AddRelation( makeRelation( 410 AccessibleRelationType::CONTENT_FLOWS_TO, pNextFrm ) ); 411 412 return pHelper; 413 } 414