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 28 #include "crsrsh.hxx" 29 #include "rootfrm.hxx" 30 #include "pagefrm.hxx" 31 #include "viewimp.hxx" 32 #include "errhdl.hxx" 33 #include "viewopt.hxx" 34 #include "flyfrm.hxx" 35 #include "frmfmt.hxx" 36 #include "layact.hxx" 37 #include "swregion.hxx" 38 #include "dflyobj.hxx" 39 #include "dview.hxx" 40 #include <tools/shl.hxx> 41 #include <swmodule.hxx> 42 #include <svx/svdpage.hxx> 43 #include <accmap.hxx> 44 45 // OD 12.12.2002 #103492# 46 #include <pagepreviewlayout.hxx> 47 48 #include <comcore.hrc> 49 #include <svx/svdundo.hxx> 50 #include <IDocumentLayoutAccess.hxx> 51 #include <IDocumentDrawModelAccess.hxx> 52 #include <IDocumentDeviceAccess.hxx> 53 #include <IDocumentSettingAccess.hxx> 54 55 /************************************************************************* 56 |* 57 |* SwViewImp::Init() 58 |* 59 |* Ersterstellung MA 25. Jul. 94 60 |* Letzte Aenderung MA 03. Nov. 95 61 |* 62 |*************************************************************************/ 63 64 void SwViewImp::Init( const SwViewOption *pNewOpt ) 65 { 66 ASSERT( pDrawView, "SwViewImp::Init without DrawView" ); 67 //Jetzt die PageView erzeugen wenn sie noch nicht existiert. 68 SwRootFrm *pRoot = pSh->GetLayout(); //swmod 071108//swmod 071225 69 if ( !pSdrPageView ) 70 { 71 IDocumentDrawModelAccess* pIDDMA = pSh->getIDocumentDrawModelAccess(); 72 if ( !pRoot->GetDrawPage() ) 73 pRoot->SetDrawPage( pIDDMA->GetDrawModel()->GetPage( 0 ) ); 74 75 if ( pRoot->GetDrawPage()->GetSize() != pRoot->Frm().SSize() ) 76 pRoot->GetDrawPage()->SetSize( pRoot->Frm().SSize() ); 77 78 pSdrPageView = pDrawView->ShowSdrPage( pRoot->GetDrawPage()); 79 // OD 26.06.2003 #108784# - notify drawing page view about invisible 80 // layers. 81 pIDDMA->NotifyInvisibleLayers( *pSdrPageView ); 82 } 83 pDrawView->SetDragStripes( pNewOpt->IsCrossHair() ); 84 pDrawView->SetGridSnap( pNewOpt->IsSnap() ); 85 pDrawView->SetGridVisible( pNewOpt->IsGridVisible() ); 86 const Size &rSz = pNewOpt->GetSnapSize(); 87 pDrawView->SetGridCoarse( rSz ); 88 const Size aFSize 89 ( rSz.Width() ? rSz.Width() /Max(short(1),pNewOpt->GetDivisionX()):0, 90 rSz.Height()? rSz.Height()/Max(short(1),pNewOpt->GetDivisionY()):0); 91 pDrawView->SetGridFine( aFSize ); 92 Fraction aSnGrWdtX(rSz.Width(), pNewOpt->GetDivisionX() + 1); 93 Fraction aSnGrWdtY(rSz.Height(), pNewOpt->GetDivisionY() + 1); 94 pDrawView->SetSnapGridWidth( aSnGrWdtX, aSnGrWdtY ); 95 96 if ( pRoot->Frm().HasArea() ) 97 pDrawView->SetWorkArea( pRoot->Frm().SVRect() ); 98 99 if ( GetShell()->IsPreView() ) 100 pDrawView->SetAnimationEnabled( sal_False ); 101 102 pDrawView->SetUseIncompatiblePathCreateInterface( sal_False ); 103 pDrawView->SetSolidMarkHdl(pNewOpt->IsSolidMarkHdl()); 104 105 // it's a JOE interface ! 106 pDrawView->SetMarkHdlSizePixel(pNewOpt->IsBigMarkHdl() ? 9 : 7); 107 } 108 109 /************************************************************************* 110 |* 111 |* SwViewImp::SwViewImp() CTor fuer die Core-Internas 112 |* 113 |* Ersterstellung MA 25. Jul. 94 114 |* Letzte Aenderung MA 06. Sep. 96 115 |* 116 |*************************************************************************/ 117 118 SwViewImp::SwViewImp( ViewShell *pParent ) : 119 pSh( pParent ), 120 pDrawView( 0 ), 121 pSdrPageView( 0 ), 122 pFirstVisPage( 0 ), 123 pRegion( 0 ), 124 pLayAct( 0 ), 125 pIdleAct( 0 ), 126 pAccMap( 0 ), 127 pSdrObjCached(NULL), 128 nRestoreActions( 0 ), 129 // OD 12.12.2002 #103492# 130 mpPgPrevwLayout( 0 ) 131 { 132 //bResetXorVisibility = 133 //HMHbShowHdlPaint = 134 bResetHdlHiddenPaint = 135 bSmoothUpdate = bStopSmooth = bStopPrt = sal_False; 136 bFirstPageInvalid = sal_True; 137 } 138 139 /****************************************************************************** 140 |* 141 |* SwViewImp::~SwViewImp() 142 |* 143 |* Ersterstellung MA 25. Jul. 94 144 |* Letzte Aenderung MA 16. Dec. 94 145 |* 146 ******************************************************************************/ 147 148 SwViewImp::~SwViewImp() 149 { 150 delete pAccMap; 151 152 // OD 12.12.2002 #103492# 153 delete mpPgPrevwLayout; 154 155 //JP 29.03.96: nach ShowSdrPage muss auch HideSdrPage gemacht werden!!! 156 if( pDrawView ) 157 pDrawView->HideSdrPage(); 158 159 delete pDrawView; 160 161 DelRegion(); 162 163 ASSERT( !pLayAct, "Have action for the rest of your life." ); 164 ASSERT( !pIdleAct,"Be idle for the rest of your life." ); 165 } 166 167 /****************************************************************************** 168 |* 169 |* SwViewImp::DelRegions() 170 |* 171 |* Ersterstellung MA 14. Apr. 94 172 |* Letzte Aenderung MA 14. Apr. 94 173 |* 174 ******************************************************************************/ 175 176 void SwViewImp::DelRegion() 177 { 178 DELETEZ(pRegion); 179 } 180 181 /****************************************************************************** 182 |* 183 |* SwViewImp::AddPaintRect() 184 |* 185 |* Ersterstellung MA ?? 186 |* Letzte Aenderung MA 27. Jul. 94 187 |* 188 ******************************************************************************/ 189 190 sal_Bool SwViewImp::AddPaintRect( const SwRect &rRect ) 191 { 192 if ( rRect.IsOver( pSh->VisArea() ) ) 193 { 194 if ( !pRegion ) 195 pRegion = new SwRegionRects( pSh->VisArea() ); 196 (*pRegion) -= rRect; 197 return sal_True; 198 } 199 return sal_False; 200 } 201 202 203 /****************************************************************************** 204 |* 205 |* ViewImp::CheckWaitCrsr() 206 |* 207 |* Ersterstellung MA 10. Aug. 94 208 |* Letzte Aenderung MA 10. Aug. 94 209 |* 210 ******************************************************************************/ 211 212 void SwViewImp::CheckWaitCrsr() 213 { 214 if ( pLayAct ) 215 pLayAct->CheckWaitCrsr(); 216 } 217 218 /****************************************************************************** 219 |* 220 |* ViewImp::IsCalcLayoutProgress() 221 |* 222 |* Ersterstellung MA 12. Aug. 94 223 |* Letzte Aenderung MA 12. Aug. 94 224 |* 225 ******************************************************************************/ 226 227 sal_Bool SwViewImp::IsCalcLayoutProgress() const 228 { 229 if ( pLayAct ) 230 return pLayAct->IsCalcLayout(); 231 return sal_False; 232 } 233 234 /****************************************************************************** 235 |* 236 |* ViewImp::IsUpdateExpFlds() 237 |* 238 |* Ersterstellung MA 28. Mar. 96 239 |* Letzte Aenderung MA 28. Mar. 96 240 |* 241 ******************************************************************************/ 242 243 sal_Bool SwViewImp::IsUpdateExpFlds() 244 { 245 if ( pLayAct && pLayAct->IsCalcLayout() ) 246 { 247 pLayAct->SetUpdateExpFlds(); 248 return sal_True; 249 } 250 return sal_False; 251 } 252 253 254 /****************************************************************************** 255 |* 256 |* SwViewImp::SetFirstVisPage(), ImplGetFirstVisPage(); 257 |* 258 |* Ersterstellung MA 21. Sep. 93 259 |* Letzte Aenderung MA 08. Mar. 94 260 |* 261 ******************************************************************************/ 262 263 void SwViewImp::SetFirstVisPage() 264 { 265 if ( pSh->bDocSizeChgd && pSh->VisArea().Top() > pSh->GetLayout()->Frm().Height() ) 266 { 267 //Wir stecken in einer Action und die VisArea sitzt wegen 268 //Loeschoperationen hinter der erste sichtbaren Seite. 269 //Damit nicht zu heftig Formatiert wird, liefern wir die letzte Seite 270 //zurueck. 271 pFirstVisPage = (SwPageFrm*)pSh->GetLayout()->Lower(); 272 while ( pFirstVisPage && pFirstVisPage->GetNext() ) 273 pFirstVisPage = (SwPageFrm*)pFirstVisPage->GetNext(); 274 } 275 else 276 { 277 const SwViewOption* pSwViewOption = GetShell()->GetViewOptions(); 278 const bool bBookMode = pSwViewOption->IsViewLayoutBookMode(); 279 280 SwPageFrm *pPage = (SwPageFrm*)pSh->GetLayout()->Lower(); 281 SwRect aPageRect = pPage->Frm(); 282 while ( pPage && !aPageRect.IsOver( pSh->VisArea() ) ) 283 { 284 pPage = (SwPageFrm*)pPage->GetNext(); 285 if ( pPage ) 286 { 287 aPageRect = pPage->Frm(); 288 if ( bBookMode && pPage->IsEmptyPage() ) 289 { 290 const SwPageFrm& rFormatPage = pPage->GetFormatPage(); 291 aPageRect.SSize() = rFormatPage.Frm().SSize(); 292 } 293 } 294 } 295 pFirstVisPage = pPage ? pPage : (SwPageFrm*)pSh->GetLayout()->Lower(); 296 } 297 bFirstPageInvalid = sal_False; 298 } 299 300 /****************************************************************************** 301 |* 302 |* SwViewImp::MakeDrawView(); 303 |* 304 |* Ersterstellung AMA 01. Nov. 95 305 |* Letzte Aenderung AMA 01. Nov. 95 306 |* 307 ******************************************************************************/ 308 309 void SwViewImp::MakeDrawView() 310 { 311 IDocumentDrawModelAccess* pIDDMA = GetShell()->getIDocumentDrawModelAccess(); 312 313 // the else here is not an error, _MakeDrawModel() calls this method again 314 // after the DrawModel is created to create DrawViews for all shells... 315 if( !pIDDMA->GetDrawModel() ) 316 { 317 pIDDMA->_MakeDrawModel(); 318 } 319 else 320 { 321 if ( !pDrawView ) 322 { 323 // #i72809# 324 // Discussed with FME, he also thinks that the getPrinter is old and not correct. When i got 325 // him right, it anyways returns GetOut() when it's a printer, but NULL when not. He suggested 326 // to use GetOut() and check the existing cases. 327 // Check worked well. Took a look at viewing, printing, PDF export and print preview with a test 328 // document which has an empty 2nd page (right page, see bug) 329 OutputDevice* pOutDevForDrawView = GetShell()->GetWin(); 330 331 if(!pOutDevForDrawView) 332 { 333 // pOutDevForDrawView = (OutputDevice*)GetShell()->getIDocumentDeviceAccess()->getPrinter( false ); 334 pOutDevForDrawView = GetShell()->GetOut(); 335 } 336 337 pDrawView = new SwDrawView( *this, pIDDMA->GetDrawModel(), pOutDevForDrawView); 338 } 339 340 GetDrawView()->SetActiveLayer( XubString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Heaven" ) ) ); 341 const SwViewOption* pSwViewOption = GetShell()->GetViewOptions(); 342 Init(pSwViewOption); 343 344 // #i68597# If document is read-only, we will not profit from overlay, 345 // so switch it off. 346 if(pDrawView && pDrawView->IsBufferedOverlayAllowed()) 347 { 348 bool bIsReadOnly(pSwViewOption->IsReadonly()); 349 350 #ifdef DBG_UTIL 351 // add test possibilities 352 static bool bAlwaysActivateForTest(false); 353 if(bAlwaysActivateForTest && bIsReadOnly) 354 { 355 bIsReadOnly = false; 356 } 357 #endif 358 359 if(bIsReadOnly) 360 { 361 pDrawView->SetBufferedOverlayAllowed(false); 362 } 363 } 364 } 365 } 366 367 /****************************************************************************** 368 |* 369 |* SwViewImp::GetRetoucheColor() 370 |* 371 |* Ersterstellung MA 24. Jun. 98 372 |* Letzte Aenderung MA 24. Jun. 98 373 |* 374 ******************************************************************************/ 375 376 Color SwViewImp::GetRetoucheColor() const 377 { 378 Color aRet( COL_TRANSPARENT ); 379 const ViewShell &rSh = *GetShell(); 380 if ( rSh.GetWin() ) 381 { 382 if ( rSh.GetViewOptions()->getBrowseMode() && 383 COL_TRANSPARENT != rSh.GetViewOptions()->GetRetoucheColor().GetColor() ) 384 aRet = rSh.GetViewOptions()->GetRetoucheColor(); 385 else if(rSh.GetViewOptions()->IsPagePreview() && 386 !SW_MOD()->GetAccessibilityOptions().GetIsForPagePreviews()) 387 aRet.SetColor(COL_WHITE); 388 else 389 aRet = SwViewOption::GetDocColor(); 390 } 391 return aRet; 392 } 393 394 /** create page preview layout 395 396 OD 12.12.2002 #103492# 397 398 @author OD 399 */ 400 void SwViewImp::InitPagePreviewLayout() 401 { 402 ASSERT( pSh->GetLayout(), "no layout - page preview layout can not be created."); 403 if ( pSh->GetLayout() ) 404 mpPgPrevwLayout = new SwPagePreviewLayout( *pSh, *(pSh->GetLayout()) ); 405 } 406 407 void SwViewImp::UpdateAccessible() 408 { 409 // We require a layout and an XModel to be accessible. 410 IDocumentLayoutAccess* pIDLA = GetShell()->getIDocumentLayoutAccess(); 411 Window *pWin = GetShell()->GetWin(); 412 ASSERT( GetShell()->GetLayout(), "no layout, no access" ); //swmod 071108//swmod 071225 413 ASSERT( pWin, "no window, no access" ); 414 415 if( IsAccessible() && pIDLA->GetCurrentViewShell() && pWin ) //swmod 071108//swmod 071225 416 GetAccessibleMap().GetDocumentView(); 417 } 418 419 void SwViewImp::DisposeAccessible( const SwFrm *pFrm, 420 const SdrObject *pObj, 421 sal_Bool bRecursive ) 422 { 423 ASSERT( !pFrm || pFrm->IsAccessibleFrm(), "frame is not accessible" ); 424 ViewShell *pVSh = GetShell(); 425 ViewShell *pTmp = pVSh; 426 do 427 { 428 if( pTmp->Imp()->IsAccessible() ) 429 pTmp->Imp()->GetAccessibleMap().Dispose( pFrm, pObj, 0, bRecursive ); 430 pTmp = (ViewShell *)pTmp->GetNext(); 431 } while ( pTmp != pVSh ); 432 } 433 434 void SwViewImp::MoveAccessible( const SwFrm *pFrm, const SdrObject *pObj, 435 const SwRect& rOldFrm ) 436 { 437 ASSERT( !pFrm || pFrm->IsAccessibleFrm(), "frame is not accessible" ); 438 ViewShell *pVSh = GetShell(); 439 ViewShell *pTmp = pVSh; 440 do 441 { 442 if( pTmp->Imp()->IsAccessible() ) 443 pTmp->Imp()->GetAccessibleMap().InvalidatePosOrSize( pFrm, pObj, 0, 444 rOldFrm ); 445 pTmp = (ViewShell *)pTmp->GetNext(); 446 } while ( pTmp != pVSh ); 447 } 448 449 void SwViewImp::FirePageChangeEvent(sal_uInt16 nOldPage, sal_uInt16 nNewPage) 450 { 451 if( IsAccessible() ) 452 GetAccessibleMap().FirePageChangeEvent( nOldPage, nNewPage); 453 } 454 455 void SwViewImp::FireSectionChangeEvent(sal_uInt16 nOldSection, sal_uInt16 nNewSection) 456 { 457 if( IsAccessible() ) 458 GetAccessibleMap().FireSectionChangeEvent(nOldSection, nNewSection); 459 } 460 void SwViewImp::FireColumnChangeEvent(sal_uInt16 nOldColumn, sal_uInt16 nNewColumn) 461 { 462 if( IsAccessible() ) 463 GetAccessibleMap().FireColumnChangeEvent(nOldColumn, nNewColumn); 464 } 465 void SwViewImp::InvalidateAccessibleFrmContent( const SwFrm *pFrm ) 466 { 467 ASSERT( pFrm->IsAccessibleFrm(), "frame is not accessible" ); 468 ViewShell *pVSh = GetShell(); 469 ViewShell *pTmp = pVSh; 470 do 471 { 472 if( pTmp->Imp()->IsAccessible() ) 473 pTmp->Imp()->GetAccessibleMap().InvalidateContent( pFrm ); 474 pTmp = (ViewShell *)pTmp->GetNext(); 475 } while ( pTmp != pVSh ); 476 } 477 478 void SwViewImp::InvalidateAccessibleCursorPosition( const SwFrm *pFrm ) 479 { 480 if( IsAccessible() ) 481 GetAccessibleMap().InvalidateCursorPosition( pFrm ); 482 } 483 484 void SwViewImp::InvalidateAccessibleEditableState( sal_Bool bAllShells, 485 const SwFrm *pFrm ) 486 { 487 if( bAllShells ) 488 { 489 ViewShell *pVSh = GetShell(); 490 ViewShell *pTmp = pVSh; 491 do 492 { 493 if( pTmp->Imp()->IsAccessible() ) 494 pTmp->Imp()->GetAccessibleMap().InvalidateStates( ACC_STATE_EDITABLE, pFrm ); 495 pTmp = (ViewShell *)pTmp->GetNext(); 496 } while ( pTmp != pVSh ); 497 } 498 else if( IsAccessible() ) 499 { 500 GetAccessibleMap().InvalidateStates( ACC_STATE_EDITABLE, pFrm ); 501 } 502 } 503 504 void SwViewImp::InvalidateAccessibleRelationSet( const SwFlyFrm *pMaster, 505 const SwFlyFrm *pFollow ) 506 { 507 ViewShell *pVSh = GetShell(); 508 ViewShell *pTmp = pVSh; 509 do 510 { 511 if( pTmp->Imp()->IsAccessible() ) 512 pTmp->Imp()->GetAccessibleMap().InvalidateRelationSet( pMaster, 513 pFollow ); 514 pTmp = (ViewShell *)pTmp->GetNext(); 515 } while ( pTmp != pVSh ); 516 } 517 518 /** invalidate CONTENT_FLOWS_FROM/_TO relation for paragraphs 519 520 OD 2005-12-01 #i27138# 521 522 @author OD 523 */ 524 void SwViewImp::_InvalidateAccessibleParaFlowRelation( const SwTxtFrm* _pFromTxtFrm, 525 const SwTxtFrm* _pToTxtFrm ) 526 { 527 if ( !_pFromTxtFrm && !_pToTxtFrm ) 528 { 529 // No text frame provided. Thus, nothing to do. 530 return; 531 } 532 533 ViewShell* pVSh = GetShell(); 534 ViewShell* pTmp = pVSh; 535 do 536 { 537 if ( pTmp->Imp()->IsAccessible() ) 538 { 539 if ( _pFromTxtFrm ) 540 { 541 pTmp->Imp()->GetAccessibleMap(). 542 InvalidateParaFlowRelation( *_pFromTxtFrm, true ); 543 } 544 if ( _pToTxtFrm ) 545 { 546 pTmp->Imp()->GetAccessibleMap(). 547 InvalidateParaFlowRelation( *_pToTxtFrm, false ); 548 } 549 } 550 pTmp = (ViewShell *)pTmp->GetNext(); 551 } while ( pTmp != pVSh ); 552 } 553 554 /** invalidate text selection for paragraphs 555 556 OD 2005-12-12 #i27301# 557 558 @author OD 559 */ 560 void SwViewImp::_InvalidateAccessibleParaTextSelection() 561 { 562 ViewShell* pVSh = GetShell(); 563 ViewShell* pTmp = pVSh; 564 do 565 { 566 if ( pTmp->Imp()->IsAccessible() ) 567 { 568 pTmp->Imp()->GetAccessibleMap().InvalidateTextSelectionOfAllParas(); 569 } 570 571 pTmp = (ViewShell *)pTmp->GetNext(); 572 } while ( pTmp != pVSh ); 573 } 574 575 /** invalidate attributes for paragraphs 576 577 OD 2009-01-06 #i88069# 578 579 @author OD 580 */ 581 void SwViewImp::_InvalidateAccessibleParaAttrs( const SwTxtFrm& rTxtFrm ) 582 { 583 ViewShell* pVSh = GetShell(); 584 ViewShell* pTmp = pVSh; 585 do 586 { 587 if ( pTmp->Imp()->IsAccessible() ) 588 { 589 pTmp->Imp()->GetAccessibleMap().InvalidateAttr( rTxtFrm ); 590 } 591 592 pTmp = (ViewShell *)pTmp->GetNext(); 593 } while ( pTmp != pVSh ); 594 } 595 596 // OD 15.01.2003 #103492# - method signature change due to new page preview functionality 597 void SwViewImp::UpdateAccessiblePreview( const std::vector<PrevwPage*>& _rPrevwPages, 598 const Fraction& _rScale, 599 const SwPageFrm* _pSelectedPageFrm, 600 const Size& _rPrevwWinSize ) 601 { 602 if( IsAccessible() ) 603 GetAccessibleMap().UpdatePreview( _rPrevwPages, _rScale, 604 _pSelectedPageFrm, _rPrevwWinSize ); 605 } 606 607 void SwViewImp::InvalidateAccessiblePreViewSelection( sal_uInt16 nSelPage ) 608 { 609 if( IsAccessible() ) 610 GetAccessibleMap().InvalidatePreViewSelection( nSelPage ); 611 } 612 613 SwAccessibleMap *SwViewImp::CreateAccessibleMap() 614 { 615 ASSERT( !pAccMap, "accessible map exists" ) 616 pAccMap = new SwAccessibleMap( GetShell() ); 617 return pAccMap; 618 } 619 620 void SwViewImp::FireAccessibleEvents() 621 { 622 if( IsAccessible() ) 623 GetAccessibleMap().FireEvents(); 624 } 625 626 IMPL_LINK(SwViewImp, SetStopPrt, void *, EMPTYARG) 627 { 628 bStopPrt = sal_True; 629 630 return 0; 631 } 632 633