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 using namespace ::com::sun::star; 48 using namespace ::com::sun::star::accessibility; 49 using ::rtl::OUString; 50 51 using utl::AccessibleRelationSetHelper; 52 using ::com::sun::star::accessibility::XAccessibleContext; 53 54 const sal_Char sServiceName[] = "com.sun.star.text.AccessibleTextFrameView"; 55 const sal_Char sImplementationName[] = "com.sun.star.comp.Writer.SwAccessibleTextFrameView"; 56 57 SwAccessibleTextFrame::SwAccessibleTextFrame( 58 SwAccessibleMap* pInitMap, 59 const SwFlyFrm* pFlyFrm ) : 60 SwAccessibleFrameBase( pInitMap, AccessibleRole::TEXT_FRAME, pFlyFrm ), 61 msTitle(), 62 msDesc() 63 { 64 if ( pFlyFrm ) 65 { 66 const SwFlyFrmFmt* pFlyFrmFmt = 67 dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() ); 68 msTitle = pFlyFrmFmt->GetObjTitle(); 69 70 msDesc = pFlyFrmFmt->GetObjDescription(); 71 if ( msDesc.getLength() == 0 && 72 msTitle != GetName() ) 73 { 74 msDesc = msTitle; 75 } 76 } 77 } 78 79 SwAccessibleTextFrame::~SwAccessibleTextFrame() 80 { 81 } 82 83 void SwAccessibleTextFrame::Modify( const SfxPoolItem* pOld, const SfxPoolItem *pNew) 84 { 85 const sal_uInt16 nWhich = pOld ? pOld->Which() : pNew ? pNew->Which() : 0 ; 86 // --> OD 2009-07-14 #i73249# 87 // suppress handling of RES_NAME_CHANGED in case that attribute Title is 88 // used as the accessible name. 89 if ( nWhich != RES_NAME_CHANGED || 90 msTitle.getLength() == 0 ) 91 { 92 SwAccessibleFrameBase::Modify( pOld, pNew ); 93 } 94 95 const SwFlyFrm *pFlyFrm = static_cast< const SwFlyFrm * >( GetFrm() ); 96 switch( nWhich ) 97 { 98 // --> OD 2009-07-14 #i73249# 99 case RES_TITLE_CHANGED: 100 { 101 const String& sOldTitle( 102 dynamic_cast<const SwStringMsgPoolItem*>(pOld)->GetString() ); 103 const String& sNewTitle( 104 dynamic_cast<const SwStringMsgPoolItem*>(pNew)->GetString() ); 105 if ( sOldTitle == sNewTitle ) 106 { 107 break; 108 } 109 msTitle = sNewTitle; 110 AccessibleEventObject aEvent; 111 aEvent.EventId = AccessibleEventId::NAME_CHANGED; 112 aEvent.OldValue <<= OUString( sOldTitle ); 113 aEvent.NewValue <<= msTitle; 114 FireAccessibleEvent( aEvent ); 115 116 const SwFlyFrmFmt* pFlyFrmFmt = 117 dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() ); 118 if ( pFlyFrmFmt->GetObjDescription().Len() != 0 ) 119 { 120 break; 121 } 122 } 123 // intentional no break here 124 case RES_DESCRIPTION_CHANGED: 125 { 126 if ( pFlyFrm ) 127 { 128 const OUString sOldDesc( msDesc ); 129 130 const SwFlyFrmFmt* pFlyFrmFmt = 131 dynamic_cast<const SwFlyFrmFmt*>( pFlyFrm->GetFmt() ); 132 const String& rDesc = pFlyFrmFmt->GetObjDescription(); 133 msDesc = rDesc; 134 if ( msDesc.getLength() == 0 && 135 msTitle != GetName() ) 136 { 137 msDesc = msTitle; 138 } 139 140 if ( msDesc != sOldDesc ) 141 { 142 AccessibleEventObject aEvent; 143 aEvent.EventId = AccessibleEventId::DESCRIPTION_CHANGED; 144 aEvent.OldValue <<= sOldDesc; 145 aEvent.NewValue <<= msDesc; 146 FireAccessibleEvent( aEvent ); 147 } 148 } 149 } 150 break; 151 // <-- 152 } 153 } 154 155 // --> OD 2009-07-14 #i73249# 156 OUString SAL_CALL SwAccessibleTextFrame::getAccessibleName (void) 157 throw (uno::RuntimeException) 158 { 159 vos::OGuard aGuard(Application::GetSolarMutex()); 160 161 CHECK_FOR_DEFUNC( XAccessibleContext ) 162 163 if ( msTitle.getLength() != 0 ) 164 { 165 return msTitle; 166 } 167 168 return SwAccessibleFrameBase::getAccessibleName(); 169 } 170 // <-- 171 OUString SAL_CALL SwAccessibleTextFrame::getAccessibleDescription (void) 172 throw (uno::RuntimeException) 173 { 174 vos::OGuard aGuard(Application::GetSolarMutex()); 175 176 CHECK_FOR_DEFUNC( XAccessibleContext ) 177 178 return msDesc; 179 180 } 181 182 OUString SAL_CALL SwAccessibleTextFrame::getImplementationName() 183 throw( uno::RuntimeException ) 184 { 185 return OUString(RTL_CONSTASCII_USTRINGPARAM(sImplementationName)); 186 } 187 188 sal_Bool SAL_CALL SwAccessibleTextFrame::supportsService( 189 const OUString& sTestServiceName) 190 throw (uno::RuntimeException) 191 { 192 return sTestServiceName.equalsAsciiL( sServiceName, 193 sizeof(sServiceName)-1 ) || 194 sTestServiceName.equalsAsciiL( sAccessibleServiceName, 195 sizeof(sAccessibleServiceName)-1 ); 196 } 197 198 uno::Sequence< OUString > SAL_CALL SwAccessibleTextFrame::getSupportedServiceNames() 199 throw( uno::RuntimeException ) 200 { 201 uno::Sequence< OUString > aRet(2); 202 OUString* pArray = aRet.getArray(); 203 pArray[0] = OUString( RTL_CONSTASCII_USTRINGPARAM(sServiceName) ); 204 pArray[1] = OUString( RTL_CONSTASCII_USTRINGPARAM(sAccessibleServiceName) ); 205 return aRet; 206 } 207 208 uno::Sequence< sal_Int8 > SAL_CALL SwAccessibleTextFrame::getImplementationId() 209 throw(uno::RuntimeException) 210 { 211 vos::OGuard aGuard(Application::GetSolarMutex()); 212 static uno::Sequence< sal_Int8 > aId( 16 ); 213 static sal_Bool bInit = sal_False; 214 if(!bInit) 215 { 216 rtl_createUuid( (sal_uInt8 *)(aId.getArray() ), 0, sal_True ); 217 bInit = sal_True; 218 } 219 return aId; 220 } 221 222 223 // 224 // XAccessibleRelationSet 225 // 226 227 228 SwFlyFrm* SwAccessibleTextFrame::getFlyFrm() const 229 { 230 SwFlyFrm* pFlyFrm = NULL; 231 232 const SwFrm* pFrm = GetFrm(); 233 DBG_ASSERT( pFrm != NULL, "frame expected" ); 234 if( pFrm->IsFlyFrm() ) 235 { 236 pFlyFrm = static_cast<SwFlyFrm*>( const_cast<SwFrm*>( pFrm ) ); 237 } 238 239 return pFlyFrm; 240 } 241 242 AccessibleRelation SwAccessibleTextFrame::makeRelation( sal_Int16 nType, const SwFlyFrm* pFrm ) 243 { 244 uno::Sequence<uno::Reference<XInterface> > aSequence(1); 245 aSequence[0] = GetMap()->GetContext( pFrm ); 246 return AccessibleRelation( nType, aSequence ); 247 } 248 249 250 uno::Reference<XAccessibleRelationSet> SAL_CALL SwAccessibleTextFrame::getAccessibleRelationSet( ) 251 throw ( uno::RuntimeException ) 252 { 253 vos::OGuard aGuard(Application::GetSolarMutex()); 254 CHECK_FOR_DEFUNC( XAccessibleContext ); 255 256 // get the frame, and insert prev/next relations into helper 257 258 AccessibleRelationSetHelper* pHelper = new AccessibleRelationSetHelper(); 259 260 SwFlyFrm* pFlyFrm = getFlyFrm(); 261 DBG_ASSERT( pFlyFrm != NULL, "fly frame expected" ); 262 263 const SwFlyFrm* pPrevFrm = pFlyFrm->GetPrevLink(); 264 if( pPrevFrm != NULL ) 265 pHelper->AddRelation( makeRelation( 266 AccessibleRelationType::CONTENT_FLOWS_FROM, pPrevFrm ) ); 267 268 const SwFlyFrm* pNextFrm = pFlyFrm->GetNextLink(); 269 if( pNextFrm != NULL ) 270 pHelper->AddRelation( makeRelation( 271 AccessibleRelationType::CONTENT_FLOWS_TO, pNextFrm ) ); 272 273 return pHelper; 274 } 275