update dev300-m58
[ooovba.git] / sw / source / core / view / viewimp.cxx
blob5eb6ba17a233d3c5dad9fa1b66e77eabd925e9ad
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: viewimp.cxx,v $
10 * $Revision: 1.41 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include "scrrect.hxx"
36 #include "crsrsh.hxx"
37 #include "rootfrm.hxx"
38 #include "pagefrm.hxx"
39 #include "viewimp.hxx"
40 #include "errhdl.hxx"
41 #include "viewopt.hxx"
42 #include "flyfrm.hxx"
43 #include "frmfmt.hxx"
44 #include "layact.hxx"
45 #include "swregion.hxx"
46 #include "dflyobj.hxx"
47 #include "dview.hxx"
48 #include <tools/shl.hxx>
49 #include <swmodule.hxx>
50 #include <svx/svdpage.hxx>
51 #include <accmap.hxx>
53 // OD 12.12.2002 #103492#
54 #include <pagepreviewlayout.hxx>
56 #include <comcore.hrc>
57 #include <svx/svdundo.hxx>
58 #include <IDocumentLayoutAccess.hxx>
59 #include <IDocumentDrawModelAccess.hxx>
60 #include <IDocumentDeviceAccess.hxx>
61 #include <IDocumentSettingAccess.hxx>
63 /*************************************************************************
65 |* SwViewImp::Init()
67 |* Ersterstellung MA 25. Jul. 94
68 |* Letzte Aenderung MA 03. Nov. 95
70 |*************************************************************************/
72 void SwViewImp::Init( const SwViewOption *pNewOpt )
74 ASSERT( pDrawView, "SwViewImp::Init without DrawView" );
75 //Jetzt die PageView erzeugen wenn sie noch nicht existiert.
76 SwRootFrm *pRoot = pSh->getIDocumentLayoutAccess()->GetRootFrm();
77 if ( !pSdrPageView )
79 IDocumentDrawModelAccess* pIDDMA = pSh->getIDocumentDrawModelAccess();
80 if ( !pRoot->GetDrawPage() )
81 pRoot->SetDrawPage( pIDDMA->GetDrawModel()->GetPage( 0 ) );
83 if ( pRoot->GetDrawPage()->GetSize() != pRoot->Frm().SSize() )
84 pRoot->GetDrawPage()->SetSize( pRoot->Frm().SSize() );
86 pSdrPageView = pDrawView->ShowSdrPage( pRoot->GetDrawPage());
87 // OD 26.06.2003 #108784# - notify drawing page view about invisible
88 // layers.
89 pIDDMA->NotifyInvisibleLayers( *pSdrPageView );
91 pDrawView->SetDragStripes( pNewOpt->IsCrossHair() );
92 pDrawView->SetGridSnap( pNewOpt->IsSnap() );
93 pDrawView->SetGridVisible( pNewOpt->IsGridVisible() );
94 const Size &rSz = pNewOpt->GetSnapSize();
95 pDrawView->SetGridCoarse( rSz );
96 const Size aFSize
97 ( rSz.Width() ? rSz.Width() /Max(short(1),pNewOpt->GetDivisionX()):0,
98 rSz.Height()? rSz.Height()/Max(short(1),pNewOpt->GetDivisionY()):0);
99 pDrawView->SetGridFine( aFSize );
100 Fraction aSnGrWdtX(rSz.Width(), pNewOpt->GetDivisionX() + 1);
101 Fraction aSnGrWdtY(rSz.Height(), pNewOpt->GetDivisionY() + 1);
102 pDrawView->SetSnapGridWidth( aSnGrWdtX, aSnGrWdtY );
104 if ( pRoot->Frm().HasArea() )
105 pDrawView->SetWorkArea( pRoot->Frm().SVRect() );
107 if ( GetShell()->IsPreView() )
108 pDrawView->SetAnimationEnabled( FALSE );
110 pDrawView->SetUseIncompatiblePathCreateInterface( FALSE );
111 pDrawView->SetSolidMarkHdl(pNewOpt->IsSolidMarkHdl());
113 // it's a JOE interface !
114 pDrawView->SetMarkHdlSizePixel(pNewOpt->IsBigMarkHdl() ? 9 : 7);
117 /*************************************************************************
119 |* SwViewImp::SwViewImp() CTor fuer die Core-Internas
121 |* Ersterstellung MA 25. Jul. 94
122 |* Letzte Aenderung MA 06. Sep. 96
124 |*************************************************************************/
126 SwViewImp::SwViewImp( ViewShell *pParent ) :
127 pSh( pParent ),
128 pDrawView( 0 ),
129 pSdrPageView( 0 ),
130 pFirstVisPage( 0 ),
131 pRegion( 0 ),
132 pScrollRects( 0 ),
133 pScrolledArea( 0 ),
134 pLayAct( 0 ),
135 pIdleAct( 0 ),
136 pAccMap( 0 ),
137 pSdrObjCached(NULL),
138 nRestoreActions( 0 ),
139 // OD 12.12.2002 #103492#
140 mpPgPrevwLayout( 0 )
142 //bResetXorVisibility =
143 //HMHbShowHdlPaint =
144 bResetHdlHiddenPaint = bScrolled =
145 bPaintInScroll = bSmoothUpdate = bStopSmooth = bStopPrt = FALSE;
146 bFirstPageInvalid = bScroll = bNextScroll = TRUE;
148 aScrollTimer.SetTimeout( 1500 );
149 aScrollTimer.SetTimeoutHdl( LINK( this, SwViewImp, RefreshScrolledHdl));
150 aScrollTimer.Stop();
153 /******************************************************************************
155 |* SwViewImp::~SwViewImp()
157 |* Ersterstellung MA 25. Jul. 94
158 |* Letzte Aenderung MA 16. Dec. 94
160 ******************************************************************************/
162 SwViewImp::~SwViewImp()
164 delete pAccMap;
166 // OD 12.12.2002 #103492#
167 delete mpPgPrevwLayout;
169 //JP 29.03.96: nach ShowSdrPage muss auch HideSdrPage gemacht werden!!!
170 if( pDrawView )
171 pDrawView->HideSdrPage();
173 delete pDrawView;
175 DelRegions();
176 delete pScrolledArea;
178 ASSERT( !pLayAct, "Have action for the rest of your life." );
179 ASSERT( !pIdleAct,"Be idle for the rest of your life." );
182 /******************************************************************************
184 |* SwViewImp::DelRegions()
186 |* Ersterstellung MA 14. Apr. 94
187 |* Letzte Aenderung MA 14. Apr. 94
189 ******************************************************************************/
191 void SwViewImp::DelRegions()
193 DELETEZ(pRegion);
194 DELETEZ(pScrollRects);
197 /******************************************************************************
199 |* SwViewImp::AddPaintRect()
201 |* Ersterstellung MA ??
202 |* Letzte Aenderung MA 27. Jul. 94
204 ******************************************************************************/
206 BOOL SwViewImp::AddPaintRect( const SwRect &rRect )
208 if ( rRect.IsOver( pSh->VisArea() ) )
210 if ( !pRegion )
211 pRegion = new SwRegionRects( pSh->VisArea() );
212 (*pRegion) -= rRect;
213 return TRUE;
215 return FALSE;
219 /******************************************************************************
221 |* ViewImp::CheckWaitCrsr()
223 |* Ersterstellung MA 10. Aug. 94
224 |* Letzte Aenderung MA 10. Aug. 94
226 ******************************************************************************/
228 void SwViewImp::CheckWaitCrsr()
230 if ( pLayAct )
231 pLayAct->CheckWaitCrsr();
234 /******************************************************************************
236 |* ViewImp::IsCalcLayoutProgress()
238 |* Ersterstellung MA 12. Aug. 94
239 |* Letzte Aenderung MA 12. Aug. 94
241 ******************************************************************************/
243 BOOL SwViewImp::IsCalcLayoutProgress() const
245 if ( pLayAct )
246 return pLayAct->IsCalcLayout();
247 return FALSE;
250 /******************************************************************************
252 |* ViewImp::IsUpdateExpFlds()
254 |* Ersterstellung MA 28. Mar. 96
255 |* Letzte Aenderung MA 28. Mar. 96
257 ******************************************************************************/
259 BOOL SwViewImp::IsUpdateExpFlds()
261 if ( pLayAct && pLayAct->IsCalcLayout() )
263 pLayAct->SetUpdateExpFlds();
264 return TRUE;
266 return FALSE;
270 /******************************************************************************
272 |* SwViewImp::SetFirstVisPage(), ImplGetFirstVisPage();
274 |* Ersterstellung MA 21. Sep. 93
275 |* Letzte Aenderung MA 08. Mar. 94
277 ******************************************************************************/
279 void SwViewImp::SetFirstVisPage()
281 if ( pSh->bDocSizeChgd && pSh->VisArea().Top() > pSh->GetLayout()->Frm().Height() )
283 //Wir stecken in einer Action und die VisArea sitzt wegen
284 //Loeschoperationen hinter der erste sichtbaren Seite.
285 //Damit nicht zu heftig Formatiert wird, liefern wir die letzte Seite
286 //zurueck.
287 pFirstVisPage = (SwPageFrm*)pSh->GetLayout()->Lower();
288 while ( pFirstVisPage && pFirstVisPage->GetNext() )
289 pFirstVisPage = (SwPageFrm*)pFirstVisPage->GetNext();
291 else
293 const SwViewOption* pSwViewOption = GetShell()->GetViewOptions();
294 const bool bBookMode = pSwViewOption->IsViewLayoutBookMode();
296 SwPageFrm *pPage = (SwPageFrm*)pSh->GetLayout()->Lower();
297 SwRect aPageRect = pPage->Frm();
298 while ( pPage && !aPageRect.IsOver( pSh->VisArea() ) )
300 pPage = (SwPageFrm*)pPage->GetNext();
301 if ( pPage )
303 aPageRect = pPage->Frm();
304 if ( bBookMode && pPage->IsEmptyPage() )
306 const SwPageFrm& rFormatPage = pPage->GetFormatPage();
307 aPageRect.SSize() = rFormatPage.Frm().SSize();
311 pFirstVisPage = pPage ? pPage : (SwPageFrm*)pSh->GetLayout()->Lower();
313 bFirstPageInvalid = FALSE;
316 /******************************************************************************
318 |* SwViewImp::MakeDrawView();
320 |* Ersterstellung AMA 01. Nov. 95
321 |* Letzte Aenderung AMA 01. Nov. 95
323 ******************************************************************************/
325 void SwViewImp::MakeDrawView()
327 IDocumentDrawModelAccess* pIDDMA = GetShell()->getIDocumentDrawModelAccess();
329 // the else here is not an error, _MakeDrawModel() calls this method again
330 // after the DrawModel is created to create DrawViews for all shells...
331 if( !pIDDMA->GetDrawModel() )
333 pIDDMA->_MakeDrawModel();
335 else
337 if ( !pDrawView )
339 // #i72809#
340 // Discussed with FME, he also thinks that the getPrinter is old and not correct. When i got
341 // him right, it anyways returns GetOut() when it's a printer, but NULL when not. He suggested
342 // to use GetOut() and check the existing cases.
343 // Check worked well. Took a look at viewing, printing, PDF export and print preview with a test
344 // document which has an empty 2nd page (right page, see bug)
345 OutputDevice* pOutDevForDrawView = GetShell()->GetWin();
347 if(!pOutDevForDrawView)
349 // pOutDevForDrawView = (OutputDevice*)GetShell()->getIDocumentDeviceAccess()->getPrinter( false );
350 pOutDevForDrawView = GetShell()->GetOut();
353 pDrawView = new SwDrawView( *this, pIDDMA->GetDrawModel(), pOutDevForDrawView);
356 GetDrawView()->SetActiveLayer( XubString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Heaven" ) ) );
357 const SwViewOption* pSwViewOption = GetShell()->GetViewOptions();
358 Init(pSwViewOption);
360 // #i68597# If document is read-only, we will not profit from overlay,
361 // so switch it off.
362 if(pDrawView && pDrawView->IsBufferedOverlayAllowed())
364 bool bIsReadOnly(pSwViewOption->IsReadonly());
366 #ifdef DBG_UTIL
367 // add test possibilities
368 static bool bAlwaysActivateForTest(false);
369 if(bAlwaysActivateForTest && bIsReadOnly)
371 bIsReadOnly = false;
373 #endif
375 if(bIsReadOnly)
377 pDrawView->SetBufferedOverlayAllowed(false);
383 /******************************************************************************
385 |* SwViewImp::GetRetoucheColor()
387 |* Ersterstellung MA 24. Jun. 98
388 |* Letzte Aenderung MA 24. Jun. 98
390 ******************************************************************************/
392 Color SwViewImp::GetRetoucheColor() const
394 Color aRet( COL_TRANSPARENT );
395 const ViewShell &rSh = *GetShell();
396 if ( rSh.GetWin() )
398 if ( rSh.getIDocumentSettingAccess()->get(IDocumentSettingAccess::BROWSE_MODE) &&
399 COL_TRANSPARENT != rSh.GetViewOptions()->GetRetoucheColor().GetColor() )
400 aRet = rSh.GetViewOptions()->GetRetoucheColor();
401 else if(rSh.GetViewOptions()->IsPagePreview() &&
402 !SW_MOD()->GetAccessibilityOptions().GetIsForPagePreviews())
403 aRet.SetColor(COL_WHITE);
404 else
405 aRet = SwViewOption::GetDocColor();
407 return aRet;
410 /** create page preview layout
412 OD 12.12.2002 #103492#
414 @author OD
416 void SwViewImp::InitPagePreviewLayout()
418 ASSERT( pSh->GetLayout(), "no layout - page preview layout can not be created.");
419 if ( pSh->GetLayout() )
420 mpPgPrevwLayout = new SwPagePreviewLayout( *pSh, *(pSh->GetLayout()) );
423 void SwViewImp::UpdateAccessible()
425 // We require a layout and an XModel to be accessible.
426 IDocumentLayoutAccess* pIDLA = GetShell()->getIDocumentLayoutAccess();
427 Window *pWin = GetShell()->GetWin();
428 ASSERT( pIDLA->GetRootFrm(), "no layout, no access" );
429 ASSERT( pWin, "no window, no access" );
431 if( IsAccessible() && pIDLA->GetRootFrm() && pWin )
432 GetAccessibleMap().GetDocumentView();
435 void SwViewImp::DisposeAccessible( const SwFrm *pFrm,
436 const SdrObject *pObj,
437 sal_Bool bRecursive )
439 ASSERT( !pFrm || pFrm->IsAccessibleFrm(), "frame is not accessible" );
440 ViewShell *pVSh = GetShell();
441 ViewShell *pTmp = pVSh;
444 if( pTmp->Imp()->IsAccessible() )
445 pTmp->Imp()->GetAccessibleMap().Dispose( pFrm, pObj, bRecursive );
446 pTmp = (ViewShell *)pTmp->GetNext();
447 } while ( pTmp != pVSh );
450 void SwViewImp::MoveAccessible( const SwFrm *pFrm, const SdrObject *pObj,
451 const SwRect& rOldFrm )
453 ASSERT( !pFrm || pFrm->IsAccessibleFrm(), "frame is not accessible" );
454 ViewShell *pVSh = GetShell();
455 ViewShell *pTmp = pVSh;
458 if( pTmp->Imp()->IsAccessible() )
459 pTmp->Imp()->GetAccessibleMap().InvalidatePosOrSize( pFrm, pObj,
460 rOldFrm );
461 pTmp = (ViewShell *)pTmp->GetNext();
462 } while ( pTmp != pVSh );
465 void SwViewImp::InvalidateAccessibleFrmContent( const SwFrm *pFrm )
467 ASSERT( pFrm->IsAccessibleFrm(), "frame is not accessible" );
468 ViewShell *pVSh = GetShell();
469 ViewShell *pTmp = pVSh;
472 if( pTmp->Imp()->IsAccessible() )
473 pTmp->Imp()->GetAccessibleMap().InvalidateContent( pFrm );
474 pTmp = (ViewShell *)pTmp->GetNext();
475 } while ( pTmp != pVSh );
478 void SwViewImp::InvalidateAccessibleCursorPosition( const SwFrm *pFrm )
480 if( IsAccessible() )
481 GetAccessibleMap().InvalidateCursorPosition( pFrm );
484 void SwViewImp::InvalidateAccessibleEditableState( sal_Bool bAllShells,
485 const SwFrm *pFrm )
487 if( bAllShells )
489 ViewShell *pVSh = GetShell();
490 ViewShell *pTmp = pVSh;
493 if( pTmp->Imp()->IsAccessible() )
494 pTmp->Imp()->GetAccessibleMap().InvalidateStates( ACC_STATE_EDITABLE, pFrm );
495 pTmp = (ViewShell *)pTmp->GetNext();
496 } while ( pTmp != pVSh );
498 else if( IsAccessible() )
500 GetAccessibleMap().InvalidateStates( ACC_STATE_EDITABLE, pFrm );
504 void SwViewImp::InvalidateAccessibleRelationSet( const SwFlyFrm *pMaster,
505 const SwFlyFrm *pFollow )
507 ViewShell *pVSh = GetShell();
508 ViewShell *pTmp = pVSh;
511 if( pTmp->Imp()->IsAccessible() )
512 pTmp->Imp()->GetAccessibleMap().InvalidateRelationSet( pMaster,
513 pFollow );
514 pTmp = (ViewShell *)pTmp->GetNext();
515 } while ( pTmp != pVSh );
518 /** invalidate CONTENT_FLOWS_FROM/_TO relation for paragraphs
520 OD 2005-12-01 #i27138#
522 @author OD
524 void SwViewImp::_InvalidateAccessibleParaFlowRelation( const SwTxtFrm* _pFromTxtFrm,
525 const SwTxtFrm* _pToTxtFrm )
527 if ( !_pFromTxtFrm && !_pToTxtFrm )
529 // No text frame provided. Thus, nothing to do.
530 return;
533 ViewShell* pVSh = GetShell();
534 ViewShell* pTmp = pVSh;
537 if ( pTmp->Imp()->IsAccessible() )
539 if ( _pFromTxtFrm )
541 pTmp->Imp()->GetAccessibleMap().
542 InvalidateParaFlowRelation( *_pFromTxtFrm, true );
544 if ( _pToTxtFrm )
546 pTmp->Imp()->GetAccessibleMap().
547 InvalidateParaFlowRelation( *_pToTxtFrm, false );
550 pTmp = (ViewShell *)pTmp->GetNext();
551 } while ( pTmp != pVSh );
554 /** invalidate text selection for paragraphs
556 OD 2005-12-12 #i27301#
558 @author OD
560 void SwViewImp::_InvalidateAccessibleParaTextSelection()
562 ViewShell* pVSh = GetShell();
563 ViewShell* pTmp = pVSh;
566 if ( pTmp->Imp()->IsAccessible() )
568 pTmp->Imp()->GetAccessibleMap().InvalidateTextSelectionOfAllParas();
571 pTmp = (ViewShell *)pTmp->GetNext();
572 } while ( pTmp != pVSh );
575 /** invalidate attributes for paragraphs
577 OD 2009-01-06 #i88069#
579 @author OD
581 void SwViewImp::_InvalidateAccessibleParaAttrs( const SwTxtFrm& rTxtFrm )
583 ViewShell* pVSh = GetShell();
584 ViewShell* pTmp = pVSh;
587 if ( pTmp->Imp()->IsAccessible() )
589 pTmp->Imp()->GetAccessibleMap().InvalidateAttr( rTxtFrm );
592 pTmp = (ViewShell *)pTmp->GetNext();
593 } while ( pTmp != pVSh );
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 )
602 if( IsAccessible() )
603 GetAccessibleMap().UpdatePreview( _rPrevwPages, _rScale,
604 _pSelectedPageFrm, _rPrevwWinSize );
607 void SwViewImp::InvalidateAccessiblePreViewSelection( sal_uInt16 nSelPage )
609 if( IsAccessible() )
610 GetAccessibleMap().InvalidatePreViewSelection( nSelPage );
613 SwAccessibleMap *SwViewImp::CreateAccessibleMap()
615 ASSERT( !pAccMap, "accessible map exists" )
616 pAccMap = new SwAccessibleMap( GetShell() );
617 return pAccMap;
620 void SwViewImp::FireAccessibleEvents()
622 if( IsAccessible() )
623 GetAccessibleMap().FireEvents();
626 IMPL_LINK(SwViewImp, SetStopPrt, void *, EMPTYARG)
628 bStopPrt = TRUE;
630 return 0;