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 <accfrmobj.hxx> 28 29 #include <accmap.hxx> 30 #include <acccontext.hxx> 31 32 #include <viewsh.hxx> 33 #include <rootfrm.hxx> 34 #include <flyfrm.hxx> 35 #include <pagefrm.hxx> 36 #include <cellfrm.hxx> 37 #include <swtable.hxx> 38 #include <dflyobj.hxx> 39 #include <frmfmt.hxx> 40 #include <fmtanchr.hxx> 41 #include <dcontact.hxx> 42 43 //IAccessibility2 Implementation 2009----- 44 #include <pam.hxx> 45 //-----IAccessibility2 Implementation 2009 46 47 #include <vcl/window.hxx> 48 49 namespace css = ::com::sun::star; 50 51 namespace sw { namespace access { 52 53 SwAccessibleChild::SwAccessibleChild() 54 : mpFrm( 0 ) 55 , mpDrawObj( 0 ) 56 , mpWindow( 0 ) 57 {} 58 59 SwAccessibleChild::SwAccessibleChild( const SdrObject* pDrawObj ) 60 : mpFrm( 0 ) 61 , mpDrawObj( 0 ) 62 , mpWindow( 0 ) 63 { 64 Init( pDrawObj ); 65 } 66 67 SwAccessibleChild::SwAccessibleChild( const SwFrm* pFrm ) 68 : mpFrm( 0 ) 69 , mpDrawObj( 0 ) 70 , mpWindow( 0 ) 71 { 72 Init( pFrm ); 73 } 74 75 SwAccessibleChild::SwAccessibleChild( Window* pWindow ) 76 : mpFrm( 0 ) 77 , mpDrawObj( 0 ) 78 , mpWindow( 0 ) 79 { 80 Init( pWindow ); 81 } 82 83 84 SwAccessibleChild::SwAccessibleChild( const SwFrm* pFrm, 85 const SdrObject* pDrawObj, 86 Window* pWindow ) 87 { 88 if ( pFrm ) 89 { 90 Init( pFrm ); 91 } 92 else if ( pDrawObj ) 93 { 94 Init( pDrawObj ); 95 } 96 else if ( pWindow ) 97 { 98 Init( pWindow ); 99 } 100 ASSERT( (!pFrm || pFrm == mpFrm) && 101 (!pDrawObj || pDrawObj == mpDrawObj) && 102 (!pWindow || pWindow == mpWindow), 103 "invalid frame/object/window combination" ); 104 105 } 106 107 void SwAccessibleChild::Init( const SdrObject* pDrawObj ) 108 { 109 mpDrawObj = pDrawObj; 110 mpFrm = mpDrawObj && mpDrawObj->ISA(SwVirtFlyDrawObj) 111 ? static_cast < const SwVirtFlyDrawObj * >( mpDrawObj )->GetFlyFrm() 112 : 0; 113 mpWindow = 0; 114 } 115 116 void SwAccessibleChild::Init( const SwFrm* pFrm ) 117 { 118 mpFrm = pFrm; 119 mpDrawObj = mpFrm && mpFrm->IsFlyFrm() 120 ? static_cast < const SwFlyFrm * >( mpFrm )->GetVirtDrawObj() 121 : 0; 122 mpWindow = 0; 123 } 124 125 void SwAccessibleChild::Init( Window* pWindow ) 126 { 127 mpWindow = pWindow; 128 mpFrm = 0; 129 mpDrawObj = 0; 130 } 131 132 bool SwAccessibleChild::IsAccessible( sal_Bool bPagePreview ) const 133 { 134 bool bRet( false ); 135 136 if ( mpFrm ) 137 { 138 bRet = mpFrm->IsAccessibleFrm() && 139 ( !mpFrm->IsCellFrm() || 140 static_cast<const SwCellFrm *>( mpFrm )->GetTabBox()->GetSttNd() != 0 ) && 141 !mpFrm->IsInCoveredCell() && 142 ( bPagePreview || 143 !mpFrm->IsPageFrm() ); 144 } 145 else if ( mpDrawObj ) 146 { 147 bRet = true; 148 } 149 else if ( mpWindow ) 150 { 151 bRet = true; 152 } 153 154 return bRet; 155 } 156 157 bool SwAccessibleChild::IsBoundAsChar() const 158 { 159 bool bRet( false ); 160 161 if ( mpFrm ) 162 { 163 bRet = mpFrm->IsFlyFrm() && 164 static_cast< const SwFlyFrm *>(mpFrm)->IsFlyInCntFrm(); 165 } 166 else if ( mpDrawObj ) 167 { 168 const SwFrmFmt* mpFrmFmt = ::FindFrmFmt( mpDrawObj ); 169 bRet = mpFrmFmt 170 ? (FLY_AS_CHAR == mpFrmFmt->GetAnchor().GetAnchorId()) 171 : false; 172 } 173 else if ( mpWindow ) 174 { 175 bRet = false; 176 } 177 178 return bRet; 179 } 180 181 //IAccessibility2 Implementation 2009----- 182 sal_uInt32 SwAccessibleChild::GetAnchorPosition() const 183 { 184 if( mpDrawObj ) 185 { 186 const SwFrmFmt *pFrmFmt = ::FindFrmFmt( mpDrawObj ); 187 if ( pFrmFmt ) 188 { 189 const SwPosition *pPos = pFrmFmt->GetAnchor().GetCntntAnchor(); 190 if ( pPos ) 191 { 192 return pPos->nContent.GetIndex(); 193 } 194 } 195 } 196 return 0; 197 } 198 //-----IAccessibility2 Implementation 2009 199 200 SwAccessibleChild::SwAccessibleChild( const SwAccessibleChild& r ) 201 : mpFrm( r.mpFrm ) 202 , mpDrawObj( r.mpDrawObj ) 203 , mpWindow( r.mpWindow ) 204 {} 205 206 SwAccessibleChild& SwAccessibleChild::operator=( const SwAccessibleChild& r ) 207 { 208 mpDrawObj = r.mpDrawObj; 209 mpFrm = r.mpFrm; 210 mpWindow = r.mpWindow; 211 212 return *this; 213 } 214 215 SwAccessibleChild& SwAccessibleChild::operator=( const SdrObject* pDrawObj ) 216 { 217 Init( pDrawObj ); 218 return *this; 219 } 220 221 SwAccessibleChild& SwAccessibleChild::operator=( const SwFrm* pFrm ) 222 { 223 Init( pFrm ); 224 return *this; 225 } 226 227 SwAccessibleChild& SwAccessibleChild::operator=( Window* pWindow ) 228 { 229 Init( pWindow ); 230 return *this; 231 } 232 233 bool SwAccessibleChild::operator==( const SwAccessibleChild& r ) const 234 { 235 return mpFrm == r.mpFrm && 236 mpDrawObj == r.mpDrawObj && 237 mpWindow == r.mpWindow; 238 } 239 240 bool SwAccessibleChild::IsValid() const 241 { 242 return mpFrm != 0 || 243 mpDrawObj != 0 || 244 mpWindow != 0; 245 } 246 247 const SdrObject* SwAccessibleChild::GetDrawObject() const 248 { 249 return mpDrawObj; 250 } 251 252 const SwFrm *SwAccessibleChild::GetSwFrm() const 253 { 254 return mpFrm; 255 } 256 257 Window* SwAccessibleChild::GetWindow() const 258 { 259 return mpWindow; 260 } 261 262 bool SwAccessibleChild::IsVisibleChildrenOnly() const 263 { 264 bool bRet( false ); 265 266 if ( !mpFrm ) 267 { 268 bRet = true; 269 } 270 else 271 { 272 bRet = mpFrm->IsRootFrm() || 273 !( mpFrm->IsTabFrm() || 274 mpFrm->IsInTab() || 275 ( IsBoundAsChar() && 276 static_cast<const SwFlyFrm*>(mpFrm)->GetAnchorFrm()->IsInTab() ) ); 277 } 278 279 return bRet; 280 } 281 282 SwRect SwAccessibleChild::GetBox( const SwAccessibleMap& rAccMap ) const 283 { 284 SwRect aBox; 285 286 if ( mpFrm ) 287 { 288 if ( mpFrm->IsPageFrm() && 289 static_cast< const SwPageFrm * >( mpFrm )->IsEmptyPage() ) 290 { 291 aBox = SwRect( mpFrm->Frm().Left(), mpFrm->Frm().Top()-1, 1, 1 ); 292 } 293 else if ( mpFrm->IsTabFrm() ) 294 { 295 aBox = SwRect( mpFrm->Frm() ); 296 aBox.Intersection( mpFrm->GetUpper()->Frm() ); 297 } 298 else 299 { 300 aBox = mpFrm->Frm(); 301 } 302 } 303 else if( mpDrawObj ) 304 { 305 aBox = SwRect( mpDrawObj->GetCurrentBoundRect() ); 306 } 307 else if ( mpWindow ) 308 { 309 aBox = SwRect( rAccMap.GetShell()->GetWin()->PixelToLogic( 310 Rectangle( mpWindow->GetPosPixel(), 311 mpWindow->GetSizePixel() ) ) ); 312 } 313 314 return aBox; 315 } 316 317 SwRect SwAccessibleChild::GetBounds( const SwAccessibleMap& rAccMap ) const 318 { 319 SwRect aBound; 320 321 if( mpFrm ) 322 { 323 if( mpFrm->IsPageFrm() && 324 static_cast< const SwPageFrm * >( mpFrm )->IsEmptyPage() ) 325 { 326 aBound = SwRect( mpFrm->Frm().Left(), mpFrm->Frm().Top()-1, 0, 0 ); 327 } 328 else 329 aBound = mpFrm->PaintArea(); 330 } 331 else if( mpDrawObj ) 332 { 333 aBound = GetBox( rAccMap ); 334 } 335 else if ( mpWindow ) 336 { 337 aBound = GetBox( rAccMap ); 338 } 339 340 return aBound; 341 } 342 343 bool SwAccessibleChild::AlwaysIncludeAsChild() const 344 { 345 bool bAlwaysIncludedAsChild( false ); 346 347 if ( mpWindow ) 348 { 349 bAlwaysIncludedAsChild = true; 350 } 351 352 return bAlwaysIncludedAsChild; 353 } 354 355 const SwFrm* SwAccessibleChild::GetParent( const sal_Bool bInPagePreview ) const 356 { 357 const SwFrm* pParent( 0 ); 358 359 if ( mpFrm ) 360 { 361 if( mpFrm->IsFlyFrm() ) 362 { 363 const SwFlyFrm* pFly = static_cast< const SwFlyFrm *>( mpFrm ); 364 if( pFly->IsFlyInCntFrm() ) 365 { 366 // For FLY_AS_CHAR the parent is the anchor 367 pParent = pFly->GetAnchorFrm(); 368 ASSERT( SwAccessibleChild( pParent ).IsAccessible( bInPagePreview ), 369 "parent is not accessible" ); 370 } 371 else 372 { 373 // In any other case the parent is the root frm 374 // (in page preview, the page frame) 375 if( bInPagePreview ) 376 pParent = pFly->FindPageFrm(); 377 else 378 pParent = pFly->getRootFrm(); 379 } 380 } 381 else 382 { 383 SwAccessibleChild aUpper( mpFrm->GetUpper() ); 384 while( aUpper.GetSwFrm() && !aUpper.IsAccessible(bInPagePreview) ) 385 { 386 aUpper = aUpper.GetSwFrm()->GetUpper(); 387 } 388 pParent = aUpper.GetSwFrm(); 389 } 390 } 391 else if( mpDrawObj ) 392 { 393 const SwDrawContact *pContact = 394 static_cast< const SwDrawContact* >( GetUserCall( mpDrawObj ) ); 395 ASSERT( pContact, "sdr contact is missing" ); 396 if( pContact ) 397 { 398 const SwFrmFmt *pFrmFmt = pContact->GetFmt(); 399 ASSERT( pFrmFmt, "frame format is missing" ); 400 if( pFrmFmt && FLY_AS_CHAR == pFrmFmt->GetAnchor().GetAnchorId() ) 401 { 402 // For FLY_AS_CHAR the parent is the anchor 403 pParent = pContact->GetAnchorFrm(); 404 ASSERT( SwAccessibleChild( pParent ).IsAccessible( bInPagePreview ), 405 "parent is not accessible" ); 406 407 } 408 else 409 { 410 // In any other case the parent is the root frm 411 if( bInPagePreview ) 412 pParent = pContact->GetAnchorFrm()->FindPageFrm(); 413 else 414 pParent = pContact->GetAnchorFrm()->getRootFrm(); 415 } 416 } 417 } 418 else if ( mpWindow ) 419 { 420 css::uno::Reference < css::accessibility::XAccessible > xAcc = 421 mpWindow->GetAccessible(); 422 if ( xAcc.is() ) 423 { 424 css::uno::Reference < css::accessibility::XAccessibleContext > xAccContext = 425 xAcc->getAccessibleContext(); 426 if ( xAccContext.is() ) 427 { 428 css::uno::Reference < css::accessibility::XAccessible > xAccParent = 429 xAccContext->getAccessibleParent(); 430 if ( xAccParent.is() ) 431 { 432 SwAccessibleContext* pAccParentImpl = 433 dynamic_cast< SwAccessibleContext *>( xAccParent.get() ); 434 if ( pAccParentImpl ) 435 { 436 pParent = pAccParentImpl->GetFrm(); 437 } 438 } 439 } 440 } 441 } 442 443 return pParent; 444 } 445 446 } } // eof of namespace sw::access 447 448