xref: /aoo41x/main/sw/source/core/view/viewsh.cxx (revision efeef26f)
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 #define _SVX_PARAITEM_HXX
29 #define _SVX_TEXTITEM_HXX
30 
31 #include <com/sun/star/accessibility/XAccessible.hpp>
32 
33 #include <sfx2/viewfrm.hxx>
34 #include <sfx2/progress.hxx>
35 #include <svx/srchdlg.hxx>
36 #include <svx/svdobj.hxx>
37 #include <sfx2/viewsh.hxx>
38 #ifndef _SHL_HXX
39 //#include <tools/shl.hxx>
40 #endif
41 #include <swwait.hxx>
42 #include <swmodule.hxx>
43 #include <fesh.hxx>
44 #include <doc.hxx>
45 #include <rootfrm.hxx>
46 #include <pagefrm.hxx>
47 #include <cntfrm.hxx>
48 #include <viewimp.hxx>
49 #include <frmtool.hxx>
50 #include <viewopt.hxx>
51 #include <dview.hxx>
52 #include <swregion.hxx>
53 #include <hints.hxx>
54 #include <fmtfsize.hxx>
55 #include <docufld.hxx>
56 #include <txtfrm.hxx>
57 #include <layact.hxx>
58 #include <mdiexp.hxx>
59 #include <fntcache.hxx>
60 #include <ptqueue.hxx>
61 #include <tabfrm.hxx>
62 #ifndef _DOCSH_HXX
63 #include <docsh.hxx>
64 #endif
65 #include <pagedesc.hxx>
66 #include <ndole.hxx>
67 #include <ndindex.hxx>
68 #include <accmap.hxx>
69 #include <svtools/colorcfg.hxx>
70 #include <svtools/accessibilityoptions.hxx>
71 #include <accessibilityoptions.hxx>
72 #ifndef _STATSTR_HRC
73 #include <statstr.hrc>
74 #endif
75 #ifndef _COMCORE_HRC
76 #include <comcore.hrc>
77 #endif
78 // OD 14.01.2003 #103492#
79 #include <pagepreviewlayout.hxx>
80 // --> OD 2004-05-24 #i28701#
81 #include <sortedobjs.hxx>
82 #include <anchoredobject.hxx>
83 // <--
84 
85 #include "../../ui/inc/view.hxx"
86 #include <PostItMgr.hxx>
87 #include <vcl/virdev.hxx>
88 
89 #include <vcl/svapp.hxx>
90 
91 // #i74769#
92 #include <svx/sdrpaintwindow.hxx>
93 
94 sal_Bool ViewShell::bLstAct = sal_False;
95 ShellResource *ViewShell::pShellRes = 0;
96 Window *ViewShell::pCareWindow = 0;
97 BitmapEx* ViewShell::pErrorBmp = NULL;
98 BitmapEx* ViewShell::pReplaceBmp = NULL;
99 
100 sal_Bool bInSizeNotify = sal_False;
101 
102 DBG_NAME(LayoutIdle)
103 
104 TYPEINIT0(ViewShell);
105 
106 using namespace ::com::sun::star;
107 
108 //////////////////////////////////////////////////////////////////////////////
109 // #i72754# 2nd set of Pre/PostPaints
110 // This time it uses the lock counter mnPrePostPaintCount to allow only one activation
111 // and deactivation and mpPrePostOutDev to remember the OutDev from the BeginDrawLayers
112 // call. That way, all places where paint take place can be handled the same way, even
113 // when calling other paint methods. This is the case at the places where SW paints
114 // buffered into VDevs to avoid flicker. Tis is in general problematic and should be
115 // solved once using the BufferedOutput functionality of the DrawView.
116 
117 void ViewShell::PrePaint()
118 {
119     // forward PrePaint event from VCL Window to DrawingLayer
120     if(HasDrawView())
121     {
122         Imp()->GetDrawView()->PrePaint();
123     }
124 }
125 
126 void ViewShell::DLPrePaint2(const Region& rRegion)
127 {
128 	if(0L == mnPrePostPaintCount)
129 	{
130 		// #i75172# ensure DrawView to use DrawingLayer bufferings
131 		if ( !HasDrawView() )
132 			MakeDrawView();
133 
134 		// Prefer window; if tot available, get pOut (e.g. printer)
135 		mpPrePostOutDev = (GetWin() ? GetWin() : GetOut());
136 
137 		// #i74769# use SdrPaintWindow now direct
138 		mpTargetPaintWindow = Imp()->GetDrawView()->BeginDrawLayers(mpPrePostOutDev, rRegion);
139 		OSL_ENSURE(mpTargetPaintWindow, "BeginDrawLayers: Got no SdrPaintWindow (!)");
140 
141 		// #i74769# if prerender, save OutDev and redirect to PreRenderDevice
142 		if(mpTargetPaintWindow->GetPreRenderDevice())
143 		{
144 			mpBufferedOut = pOut;
145 			pOut = &(mpTargetPaintWindow->GetTargetOutputDevice());
146 		}
147 
148 		// remember original paint MapMode for wrapped FlyFrame paints
149 		maPrePostMapMode = pOut->GetMapMode();
150 	}
151 
152 	mnPrePostPaintCount++;
153 }
154 
155 void ViewShell::DLPostPaint2(bool bPaintFormLayer)
156 {
157 	OSL_ENSURE(mnPrePostPaintCount > 0L, "ViewShell::DLPostPaint2: Pre/PostPaint encapsulation broken (!)");
158 	mnPrePostPaintCount--;
159 
160 	if((0L == mnPrePostPaintCount) && (0 != mpTargetPaintWindow))
161 	{
162 		// #i74769# restore buffered OutDev
163 		if(mpTargetPaintWindow->GetPreRenderDevice())
164 		{
165 			pOut = mpBufferedOut;
166 		}
167 
168 		// #i74769# use SdrPaintWindow now direct
169 		Imp()->GetDrawView()->EndDrawLayers(*mpTargetPaintWindow, bPaintFormLayer);
170 		mpTargetPaintWindow = 0;
171 	}
172 }
173 
174 //////////////////////////////////////////////////////////////////////////////
175 
176 /******************************************************************************
177 |*
178 |*	ViewShell::ImplEndAction()
179 |*
180 |*	Letzte Aenderung	MA 04. Sep. 96
181 |*
182 ******************************************************************************/
183 
184 void ViewShell::ImplEndAction( const sal_Bool bIdleEnd )
185 {
186 	//Fuer den Drucker gibt es hier nichts zu tun.
187 	if ( !GetWin() || IsPreView() )
188 	{
189 		bPaintWorks = sal_True;
190 		UISizeNotify();
191 		return;
192 	}
193 
194 	bInEndAction = sal_True;
195 
196 	//Laeuft hiermit das EndAction der Letzten Shell im Ring?
197 	ViewShell::bLstAct = sal_True;
198 	ViewShell *pSh = (ViewShell*)this->GetNext();
199 	while ( pSh != this )
200 	{	if ( pSh->ActionPend() )
201 		{	ViewShell::bLstAct = sal_False;
202 			pSh = this;
203 		}
204 		else
205 			pSh = (ViewShell*)pSh->GetNext();
206 	}
207 
208     const bool bIsShellForCheckViewLayout = ( this == GetLayout()->GetCurrShell() );
209 
210 	SET_CURR_SHELL( this );
211 	if ( Imp()->HasDrawView() && !Imp()->GetDrawView()->areMarkHandlesHidden() )
212 		Imp()->StartAction();
213 
214 	if ( Imp()->GetRegion() && Imp()->GetRegion()->GetOrigin() != VisArea() )
215         Imp()->DelRegion();
216 
217 	const sal_Bool bExtraData = ::IsExtraData( GetDoc() );
218 
219 	if ( !bIdleEnd )
220 	{
221 		SwLayAction aAction( GetLayout(), Imp() );
222 		aAction.SetComplete( sal_False );
223 		if ( nLockPaint )
224 			aAction.SetPaint( sal_False );
225 		aAction.SetInputType( INPUT_KEYBOARD );
226 		aAction.Action();
227 	}
228 
229     if ( bIsShellForCheckViewLayout )
230         GetLayout()->CheckViewLayout( GetViewOptions(), &aVisArea );
231 
232 	//Wenn wir selbst keine Paints erzeugen, so warten wir auf das Paint
233 	//vom System. Dann ist das Clipping korrekt gesetzt; Beispiel: verschieben
234 	//eines DrawObjektes.
235     if ( Imp()->GetRegion()     ||
236          aInvalidRect.HasArea() ||
237          bExtraData )
238 	{
239 		if ( !nLockPaint )
240 		{
241 			sal_Bool bPaintsFromSystem = aInvalidRect.HasArea();
242 			GetWin()->Update();
243 			if ( aInvalidRect.HasArea() )
244 			{
245 				if ( bPaintsFromSystem )
246 					Imp()->AddPaintRect( aInvalidRect );
247 
248 				ResetInvalidRect();
249 				bPaintsFromSystem = sal_True;
250 			}
251 			bPaintWorks = sal_True;
252 
253 			SwRegionRects *pRegion = Imp()->GetRegion();
254 
255 			//JP 27.11.97: wer die Selection hided, muss sie aber auch
256 			//				wieder Showen. Sonst gibt es Paintfehler!
257 			//	z.B.: addional Mode, Seite vertikal hab zu sehen, in der
258 			// Mitte eine Selektion und mit einem anderen Cursor an linken
259 			// rechten Rand springen. Ohne ShowCrsr verschwindet die
260 			// Selektion
261             sal_Bool bShowCrsr = pRegion && IsA( TYPE(SwCrsrShell) );
262 			if( bShowCrsr )
263 				((SwCrsrShell*)this)->HideCrsrs();
264 
265 			if ( pRegion )
266 			{
267 				SwRootFrm* pCurrentLayout = GetLayout();
268 
269                 Imp()->pRegion = NULL;
270 
271                 //Erst Invert dann Compress, niemals andersherum!
272 				pRegion->Invert();
273 
274                 pRegion->Compress();
275 
276 				VirtualDevice *pVout = 0;
277 				while ( pRegion->Count() )
278 				{
279 					SwRect aRect( (*pRegion)[ pRegion->Count() - 1 ] );
280 					pRegion->Remove( pRegion->Count() - 1 );
281 
282 					sal_Bool bPaint = sal_True;
283 					if ( IsEndActionByVirDev() )
284 					{
285 						//virtuelles device erzeugen und einstellen.
286 						if ( !pVout )
287 							pVout = new VirtualDevice( *GetOut() );
288 						MapMode aMapMode( GetOut()->GetMapMode() );
289 						pVout->SetMapMode( aMapMode );
290 
291 						sal_Bool bSizeOK = sal_True;
292 
293 						Rectangle aTmp1( aRect.SVRect() );
294 						aTmp1 = GetOut()->LogicToPixel( aTmp1 );
295 						Rectangle aTmp2( GetOut()->PixelToLogic( aTmp1 ) );
296 						if ( aTmp2.Left() > aRect.Left() )
297 							aTmp1.Left() = Max( 0L, aTmp1.Left() - 1L );
298 						if ( aTmp2.Top() > aRect.Top() )
299 							aTmp1.Top() = Max( 0L, aTmp1.Top() - 1L );
300 						aTmp1.Right() += 1;
301 						aTmp1.Bottom() += 1;
302 						aTmp1 = GetOut()->PixelToLogic( aTmp1 );
303 						aRect = SwRect( aTmp1 );
304 
305 						const Size aTmp( pVout->GetOutputSize() );
306 						if ( aTmp.Height() < aRect.Height() ||
307 							 aTmp.Width()  < aRect.Width() )
308 						{
309 							bSizeOK = pVout->SetOutputSize( aRect.SSize() );
310 						}
311 						if ( bSizeOK )
312 						{
313 							bPaint = sal_False;
314 
315                             // --> OD 2007-07-26 #i79947#
316                             // #i72754# start Pre/PostPaint encapsulation before pOut is changed to the buffering VDev
317                             const Region aRepaintRegion(aRect.SVRect());
318                             DLPrePaint2(aRepaintRegion);
319                             // <--
320 
321                             OutputDevice  *pOld = GetOut();
322 							pVout->SetLineColor( pOld->GetLineColor() );
323 							pVout->SetFillColor( pOld->GetFillColor() );
324 							Point aOrigin( aRect.Pos() );
325 							aOrigin.X() = -aOrigin.X(); aOrigin.Y() = -aOrigin.Y();
326 							aMapMode.SetOrigin( aOrigin );
327 							pVout->SetMapMode( aMapMode );
328 
329 							pOut = pVout;
330                             if ( bPaintsFromSystem )
331                                 PaintDesktop( aRect );
332 							pCurrentLayout->Paint( aRect );
333 							pOld->DrawOutDev( aRect.Pos(), aRect.SSize(),
334 											  aRect.Pos(), aRect.SSize(), *pVout );
335 							pOut = pOld;
336 
337 							// #i72754# end Pre/PostPaint encapsulation when pOut is back and content is painted
338 							DLPostPaint2(true);
339 						}
340 					}
341 					if ( bPaint )
342                     {
343 						// #i75172# begin DrawingLayer paint
344 						// need to do begin/end DrawingLayer preparation for each single rectangle of the
345 						// repaint region. I already tried to prepare only once for the whole Region. This
346 						// seems to work (and does technically) but fails with transparent objects. Since the
347 						// region given to BeginDarwLayers() defines the clip region for DrawingLayer paint,
348 						// transparent objects in the single rectangles will indeed be painted multiple times.
349 						DLPrePaint2(Region(aRect.SVRect()));
350 
351                         if ( bPaintsFromSystem )
352                             PaintDesktop( aRect );
353 						pCurrentLayout->Paint( aRect );
354 
355 						// #i75172# end DrawingLayer paint
356 						DLPostPaint2(true);
357                     }
358 
359                     // --> OD 2009-12-03 #i107365#
360                     // Direct paint has been performed. Thus, take care of
361                     // transparent child windows.
362                     if ( GetWin() )
363                     {
364                         Window& rWindow = *(GetWin());
365                         if(rWindow.IsChildTransparentModeEnabled() && rWindow.GetChildCount())
366                         {
367                             const Rectangle aRectanglePixel(rWindow.LogicToPixel(aRect.SVRect()));
368 
369                             for ( sal_uInt16 a(0); a < rWindow.GetChildCount(); a++ )
370                             {
371                                 Window* pCandidate = rWindow.GetChild(a);
372 
373                                 if ( pCandidate && pCandidate->IsPaintTransparent() )
374                                 {
375                                     const Rectangle aCandidatePosSizePixel(
376                                                     pCandidate->GetPosPixel(),
377                                                     pCandidate->GetSizePixel());
378 
379                                     if ( aCandidatePosSizePixel.IsOver(aRectanglePixel) )
380                                     {
381                                         pCandidate->Invalidate( INVALIDATE_NOTRANSPARENT|INVALIDATE_CHILDREN );
382                                         pCandidate->Update();
383 				}
384                                 }
385                             }
386                         }
387                     }
388                     // <--
389 				}
390 
391 				delete pVout;
392                 delete pRegion;
393                 Imp()->DelRegion();
394 			}
395 			if( bShowCrsr )
396 				((SwCrsrShell*)this)->ShowCrsrs( sal_True );
397 		}
398 		else
399 		{
400             Imp()->DelRegion();
401 			bPaintWorks =  sal_True;
402 		}
403 	}
404 	else
405 		bPaintWorks = sal_True;
406 
407 	bInEndAction = sal_False;
408 	ViewShell::bLstAct = sal_False;
409 	Imp()->EndAction();
410 
411 
412 	//Damit sich die automatischen Scrollbars auch richtig anordnen k?nnen
413 	//muessen wir die Aktion hier kuenstlich beenden (EndAction loesst ein
414 	//Notify aus, und das muss Start-/EndAction rufen um die  Scrollbars
415 	//klarzubekommen.
416 	--nStartAction;
417 	UISizeNotify();
418 	++nStartAction;
419 
420 	if( Imp()->IsAccessible() )
421 		Imp()->FireAccessibleEvents();
422 }
423 
424 /******************************************************************************
425 |*
426 |*	ViewShell::ImplStartAction()
427 |*
428 |*	Ersterstellung		MA 25. Jul. 94
429 |*	Letzte Aenderung	MA 25. Jul. 94
430 |*
431 ******************************************************************************/
432 
433 void ViewShell::ImplStartAction()
434 {
435 	bPaintWorks = sal_False;
436 	Imp()->StartAction();
437 }
438 
439 
440 /******************************************************************************
441 |*
442 |*	ViewShell::ImplLockPaint(), ImplUnlockPaint()
443 |*
444 |*	Ersterstellung		MA 11. Jun. 96
445 |*	Letzte Aenderung	MA 11. Jun. 96
446 |*
447 ******************************************************************************/
448 
449 void ViewShell::ImplLockPaint()
450 {
451 	if ( GetWin() && GetWin()->IsVisible() )
452 		GetWin()->EnablePaint( sal_False );	//Auch die Controls abklemmen.
453 	Imp()->LockPaint();
454 }
455 
456 
457 void ViewShell::ImplUnlockPaint( sal_Bool bVirDev )
458 {
459 	SET_CURR_SHELL( this );
460 	if ( GetWin() && GetWin()->IsVisible() )
461 	{
462 		if ( (bInSizeNotify || bVirDev ) && VisArea().HasArea() )
463 		{
464 			//Refresh mit virtuellem Device um das Flackern zu verhindern.
465 			VirtualDevice *pVout = new VirtualDevice( *pOut );
466 			pVout->SetMapMode( pOut->GetMapMode() );
467 			Size aSize( VisArea().SSize() );
468 			aSize.Width() += 20;
469 			aSize.Height()+= 20;
470 			if( pVout->SetOutputSize( aSize ) )
471 			{
472 				GetWin()->EnablePaint( sal_True );
473 				GetWin()->Validate();
474 
475 				Imp()->UnlockPaint();
476 				pVout->SetLineColor( pOut->GetLineColor() );
477 				pVout->SetFillColor( pOut->GetFillColor() );
478 
479 				// #i72754# start Pre/PostPaint encapsulation before pOut is changed to the buffering VDev
480 				const Region aRepaintRegion(VisArea().SVRect());
481 				DLPrePaint2(aRepaintRegion);
482 
483 				OutputDevice *pOld = pOut;
484 				pOut = pVout;
485 				Paint( VisArea().SVRect() );
486 				pOut = pOld;
487 				pOut->DrawOutDev( VisArea().Pos(), aSize,
488 								  VisArea().Pos(), aSize, *pVout );
489 
490 				// #i72754# end Pre/PostPaint encapsulation when pOut is back and content is painted
491 				DLPostPaint2(true);
492 			}
493 			else
494 			{
495 				Imp()->UnlockPaint();
496 				GetWin()->EnablePaint( sal_True );
497 				GetWin()->Invalidate( INVALIDATE_CHILDREN );
498 			}
499 			delete pVout;
500 		}
501 		else
502 		{
503 			Imp()->UnlockPaint();
504 			GetWin()->EnablePaint( sal_True );
505 			GetWin()->Invalidate( INVALIDATE_CHILDREN );
506 		}
507 	}
508 	else
509 		Imp()->UnlockPaint();
510 }
511 
512 /******************************************************************************
513 |*
514 |*	ViewShell::AddPaintRect()
515 |*
516 |*	Ersterstellung		MA ??
517 |*	Letzte Aenderung	MA 09. Feb. 97
518 |*
519 ******************************************************************************/
520 
521 sal_Bool ViewShell::AddPaintRect( const SwRect & rRect )
522 {
523 	sal_Bool bRet = sal_False;
524 	ViewShell *pSh = this;
525 	do
526 	{
527         if( pSh->Imp() )
528         {
529 		if ( pSh->IsPreView() && pSh->GetWin() )
530 			::RepaintPagePreview( pSh, rRect );
531 		else
532                 bRet |= pSh->Imp()->AddPaintRect( rRect );//swmod 080111
533         }
534 		pSh = (ViewShell*)pSh->GetNext();
535 	} while ( pSh != this );
536 	return bRet;
537 }
538 
539 /******************************************************************************
540 |*
541 |*	ViewShell::InvalidateWindows()
542 |*
543 |*	Ersterstellung		MA ??
544 |*	Letzte Aenderung	MA 09. Feb. 97
545 |*
546 ******************************************************************************/
547 
548 void ViewShell::InvalidateWindows( const SwRect &rRect )
549 {
550 	if ( !Imp()->IsCalcLayoutProgress() )
551 	{
552 		ViewShell *pSh = this;
553 		do
554 		{
555 			if ( pSh->GetWin() )
556 			{
557 				if ( pSh->IsPreView() )
558 					::RepaintPagePreview( pSh, rRect );
559 				else if ( pSh->VisArea().IsOver( rRect ) )
560 					pSh->GetWin()->Invalidate( rRect.SVRect() );
561 			}
562 			pSh = (ViewShell*)pSh->GetNext();
563 
564 		} while ( pSh != this );
565 	}
566 }
567 
568 /******************************************************************************
569 |*
570 |*	ViewShell::MakeVisible()
571 |*
572 |*	Ersterstellung		MA ??
573 |*	Letzte Aenderung	AMA 10. Okt. 95
574 |*
575 ******************************************************************************/
576 
577 void ViewShell::MakeVisible( const SwRect &rRect )
578 {
579 	if ( !VisArea().IsInside( rRect ) || IsScrollMDI( this, rRect ) || GetCareWin(*this) )
580 	{
581 		if ( !IsViewLocked() )
582 		{
583 			if( pWin )
584 			{
585 				const SwFrm* pRoot = GetLayout();
586 				int nLoopCnt = 3;
587 				long nOldH;
588 				do{
589 					nOldH = pRoot->Frm().Height();
590 					StartAction();
591 					ScrollMDI( this, rRect, USHRT_MAX, USHRT_MAX );
592 					EndAction();
593 				} while( nOldH != pRoot->Frm().Height() && nLoopCnt-- );	//swmod 071108//swmod 071225
594 			}
595 #ifdef DBG_UTIL
596 			else
597 			{
598 				//MA: 04. Nov. 94, braucht doch keiner oder??
599 				ASSERT( !this, "MakeVisible fuer Drucker wird doch gebraucht?" );
600 			}
601 
602 #endif
603 		}
604 	}
605 }
606 
607 /******************************************************************************
608 |*
609 |*	ViewShell::CareChildWindow()
610 |*
611 |*	Ersterstellung		AMA 10. Okt. 95
612 |*	Letzte Aenderung	AMA 10. Okt. 95
613 |*
614 ******************************************************************************/
615 
616 Window* ViewShell::CareChildWin(ViewShell& rVSh)
617 {
618 	if(rVSh.pSfxViewShell)
619 	{
620 		const sal_uInt16 nId = SvxSearchDialogWrapper::GetChildWindowId();
621 		SfxViewFrame* pVFrame = rVSh.pSfxViewShell->GetViewFrame();
622 		const SfxChildWindow* pChWin = pVFrame->GetChildWindow( nId );
623 		Window *pWin = pChWin ? pChWin->GetWindow() : NULL;
624 		if ( pWin && pWin->IsVisible() )
625 			return pWin;
626 	}
627 	return NULL;
628 }
629 
630 /******************************************************************************
631 |*
632 |*	ViewShell::GetPagePos()
633 |*
634 |*	Ersterstellung		MA ??
635 |*	Letzte Aenderung	MA 04. Aug. 93
636 |*
637 ******************************************************************************/
638 
639 Point ViewShell::GetPagePos( sal_uInt16 nPageNum ) const
640 {
641 	return GetLayout()->GetPagePos( nPageNum );
642 }
643 
644 /******************************************************************************
645 |*
646 |*	ViewShell::GetNumPages()
647 |*
648 |*	Ersterstellung		MA ??
649 |*	Letzte Aenderung	MA 20. Apr. 94
650 |*
651 ******************************************************************************/
652 
653 sal_uInt16 ViewShell::GetNumPages()
654 {
655 	//Es kann sein, das noch kein Layout existiert weil die Methode vom
656 	//Root-Ctor gerufen wird.
657 	return GetLayout() ? GetLayout()->GetPageNum() : 0;
658 }
659 
660 sal_Bool ViewShell::IsDummyPage( sal_uInt16 nPageNum ) const
661 {
662     return GetLayout() ? GetLayout()->IsDummyPage( nPageNum ) : 0;
663 }
664 
665 /*************************************************************************
666 |*
667 |*					ViewShell::UpdateFlds()
668 |*
669 |*	  Ersterstellung	BP 04.05.92
670 |*	  Beschreibung		erzwingt ein Update fuer jedes Feld
671 |*
672 |*	UpdateFlds benachrichtigt alle Felder mit pNewHt.
673 |*	Wenn pNewHt == 0 ist (default), wird der Feldtyp verschickt.
674 |*
675 *************************************************************************/
676 
677 void ViewShell::UpdateFlds(sal_Bool bCloseDB)
678 {
679 	SET_CURR_SHELL( this );
680 
681 	sal_Bool bCrsr = ISA(SwCrsrShell);
682 	if ( bCrsr )
683 		((SwCrsrShell*)this)->StartAction();
684 	else
685 		StartAction();
686 
687 	GetDoc()->UpdateFlds(0, bCloseDB);
688 
689 	if ( bCrsr )
690 		((SwCrsrShell*)this)->EndAction();
691 	else
692 		EndAction();
693 }
694 
695 // update all charts, for that exists any table
696 void ViewShell::UpdateAllCharts()
697 {
698 	SET_CURR_SHELL( this );
699 	// Start-/EndAction handled in the SwDoc-Method!
700 	GetDoc()->UpdateAllCharts();
701 }
702 
703 sal_Bool ViewShell::HasCharts() const
704 {
705 	sal_Bool bRet = sal_False;
706 	const SwStartNode *pStNd;
707 	SwNodeIndex aIdx( *GetDoc()->GetNodes().GetEndOfAutotext().
708 						StartOfSectionNode(), 1 );
709 	while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
710 	{
711 		aIdx++;
712 		const SwOLENode *pNd = aIdx.GetNode().GetOLENode();
713 		if( pNd && pNd->GetChartTblName().Len() )
714 		{
715 			bRet = sal_True;
716 			break;
717 		}
718 	}
719 	return bRet;
720 }
721 
722 /*************************************************************************
723 |*
724 |*	  ViewShell::LayoutIdle()
725 |*
726 |*	  Ersterstellung	MA 26. May. 92
727 |*	  Letzte Aenderung	OG 19. Mar. 96
728 |*
729 *************************************************************************/
730 
731 void ViewShell::LayoutIdle()
732 {
733 #ifdef TCOVER
734 	//fuer TCV-Version: Ende der Startphase des Programmes
735 	TCovCall::Idle();
736 #endif
737 	if( !pOpt->IsIdle() || !GetWin() ||
738 		( Imp()->HasDrawView() && Imp()->GetDrawView()->IsDragObj() ) )
739 		return;
740 
741 	//Kein Idle wenn gerade gedruckt wird.
742 	ViewShell *pSh = this;
743 	do
744 	{	if ( !pSh->GetWin() )
745 			return;
746 		pSh = (ViewShell*)pSh->GetNext();
747 
748 	} while ( pSh != this );
749 
750 	SET_CURR_SHELL( this );
751 
752 #ifdef DBG_UTIL
753 	// Wenn Test5 gedrueckt ist, wird der IdleFormatierer abgeknipst.
754 	if( pOpt->IsTest5() )
755 		return;
756 #endif
757 
758 	{
759 		DBG_PROFSTART( LayoutIdle );
760 
761 		//Cache vorbereiten und restaurieren, damit er nicht versaut wird.
762 		SwSaveSetLRUOfst aSave( *SwTxtFrm::GetTxtCache(),
763 							 SwTxtFrm::GetTxtCache()->GetCurMax() - 50 );
764         // #125243# there are lots of stacktraces indicating that Imp() returns NULL
765         // this ViewShell seems to be invalid - but it's not clear why
766         // this return is only a workaround!
767         DBG_ASSERT(Imp(), "ViewShell already deleted?");
768         if(!Imp())
769             return;
770         SwLayIdle aIdle( GetLayout(), Imp() );
771 		DBG_PROFSTOP( LayoutIdle );
772 	}
773 }
774 
775 /*************************************************************************
776 |*
777 |*    DOCUMENT COMPATIBILITY FLAGS
778 |*
779 *************************************************************************/
780 
781 void lcl_InvalidateAllCntnt( ViewShell& rSh, sal_uInt8 nInv )
782 {
783     sal_Bool bCrsr = rSh.ISA(SwCrsrShell);
784     if ( bCrsr )
785         ((SwCrsrShell&)rSh).StartAction();
786     else
787         rSh.StartAction();
788     rSh.GetLayout()->InvalidateAllCntnt( nInv );
789     if ( bCrsr )
790         ((SwCrsrShell&)rSh).EndAction();
791     else
792         rSh.EndAction();
793 
794     rSh.GetDoc()->SetModified();
795 }
796 
797 /** local method to invalidate/re-calculate positions of floating screen
798     objects (Writer fly frame and drawing objects), which are anchored
799     to paragraph or to character.
800 
801     OD 2004-03-16 #i11860#
802 
803     @author OD
804 */
805 void lcl_InvalidateAllObjPos( ViewShell &_rSh )
806 {
807     const bool bIsCrsrShell = _rSh.ISA(SwCrsrShell);
808     if ( bIsCrsrShell )
809         static_cast<SwCrsrShell&>(_rSh).StartAction();
810     else
811         _rSh.StartAction();
812 
813     _rSh.GetLayout()->InvalidateAllObjPos();
814 
815     if ( bIsCrsrShell )
816         static_cast<SwCrsrShell&>(_rSh).EndAction();
817     else
818         _rSh.EndAction();
819 
820     _rSh.GetDoc()->SetModified();
821 }
822 
823 void ViewShell::SetParaSpaceMax( bool bNew )
824 {
825     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
826     if( pIDSA->get(IDocumentSettingAccess::PARA_SPACE_MAX) != bNew )
827     {
828 		SwWait aWait( *GetDoc()->GetDocShell(), sal_True );
829         pIDSA->set(IDocumentSettingAccess::PARA_SPACE_MAX, bNew );
830         const sal_uInt8 nInv = INV_PRTAREA | INV_TABLE | INV_SECTION;
831         lcl_InvalidateAllCntnt( *this,  nInv );
832     }
833 }
834 
835 void ViewShell::SetParaSpaceMaxAtPages( bool bNew )
836 {
837     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
838     if( pIDSA->get(IDocumentSettingAccess::PARA_SPACE_MAX_AT_PAGES) != bNew )
839     {
840         SwWait aWait( *GetDoc()->GetDocShell(), sal_True );
841         pIDSA->set(IDocumentSettingAccess::PARA_SPACE_MAX_AT_PAGES, bNew );
842         const sal_uInt8 nInv = INV_PRTAREA | INV_TABLE | INV_SECTION;
843         lcl_InvalidateAllCntnt( *this,  nInv );
844     }
845 }
846 
847 void ViewShell::SetTabCompat( bool bNew )
848 {
849     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
850     if( pIDSA->get(IDocumentSettingAccess::TAB_COMPAT) != bNew  )
851 	{
852 		SwWait aWait( *GetDoc()->GetDocShell(), sal_True );
853         pIDSA->set(IDocumentSettingAccess::TAB_COMPAT, bNew );
854         const sal_uInt8 nInv = INV_PRTAREA | INV_SIZE | INV_TABLE | INV_SECTION;
855         lcl_InvalidateAllCntnt( *this, nInv );
856     }
857 }
858 
859 void ViewShell::SetAddExtLeading( bool bNew )
860 {
861     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
862     if ( pIDSA->get(IDocumentSettingAccess::ADD_EXT_LEADING) != bNew )
863     {
864         SwWait aWait( *GetDoc()->GetDocShell(), sal_True );
865         pIDSA->set(IDocumentSettingAccess::ADD_EXT_LEADING, bNew );
866         SdrModel* pTmpDrawModel = getIDocumentDrawModelAccess()->GetDrawModel();
867         if ( pTmpDrawModel )
868             pTmpDrawModel->SetAddExtLeading( bNew );
869         const sal_uInt8 nInv = INV_PRTAREA | INV_SIZE | INV_TABLE | INV_SECTION;
870         lcl_InvalidateAllCntnt( *this, nInv );
871     }
872 }
873 
874 void ViewShell::SetUseVirDev( bool bNewVirtual )
875 {
876     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
877     if ( pIDSA->get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) != bNewVirtual )
878     {
879         SwWait aWait( *GetDoc()->GetDocShell(), sal_True );
880         // this sets the flag at the document and calls PrtDataChanged
881         IDocumentDeviceAccess* pIDDA = getIDocumentDeviceAccess();
882         pIDDA->setReferenceDeviceType( bNewVirtual, true );
883     }
884 }
885 
886 // OD 2004-02-16 #106629# - control, if paragraph and table spacing is added
887 // at bottom of table cells
888 void ViewShell::SetAddParaSpacingToTableCells( bool _bAddParaSpacingToTableCells )
889 {
890     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
891     if ( pIDSA->get(IDocumentSettingAccess::ADD_PARA_SPACING_TO_TABLE_CELLS) != _bAddParaSpacingToTableCells )
892     {
893         SwWait aWait( *GetDoc()->GetDocShell(), sal_True );
894         pIDSA->set(IDocumentSettingAccess::ADD_PARA_SPACING_TO_TABLE_CELLS, _bAddParaSpacingToTableCells );
895         const sal_uInt8 nInv = INV_PRTAREA;
896         lcl_InvalidateAllCntnt( *this, nInv );
897     }
898 }
899 
900 // OD 06.01.2004 #i11859# - control, if former formatting of text lines with
901 // proportional line spacing is used or not.
902 void ViewShell::SetUseFormerLineSpacing( bool _bUseFormerLineSpacing )
903 {
904     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
905     if ( pIDSA->get(IDocumentSettingAccess::OLD_LINE_SPACING) != _bUseFormerLineSpacing )
906     {
907         SwWait aWait( *GetDoc()->GetDocShell(), sal_True );
908         pIDSA->set(IDocumentSettingAccess::OLD_LINE_SPACING, _bUseFormerLineSpacing );
909         const sal_uInt8 nInv = INV_PRTAREA;
910         lcl_InvalidateAllCntnt( *this, nInv );
911     }
912 }
913 
914 // OD 2004-03-12 #i11860# - control, if former object positioning is used or not.
915 void ViewShell::SetUseFormerObjectPositioning( bool _bUseFormerObjPos )
916 {
917     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
918     if ( pIDSA->get(IDocumentSettingAccess::USE_FORMER_OBJECT_POS) != _bUseFormerObjPos )
919     {
920         SwWait aWait( *GetDoc()->GetDocShell(), sal_True );
921         pIDSA->set(IDocumentSettingAccess::USE_FORMER_OBJECT_POS, _bUseFormerObjPos );
922         lcl_InvalidateAllObjPos( *this );
923     }
924 }
925 
926 // OD 2004-05-05 #i28701#
927 void ViewShell::SetConsiderWrapOnObjPos( bool _bConsiderWrapOnObjPos )
928 {
929     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
930     if ( pIDSA->get(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION) != _bConsiderWrapOnObjPos )
931     {
932         SwWait aWait( *GetDoc()->GetDocShell(), sal_True );
933         pIDSA->set(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION, _bConsiderWrapOnObjPos );
934         lcl_InvalidateAllObjPos( *this );
935     }
936 }
937 
938 // --> FME #108724#
939 void ViewShell::SetUseFormerTextWrapping( bool _bUseFormerTextWrapping )
940 {
941     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
942     if ( pIDSA->get(IDocumentSettingAccess::USE_FORMER_TEXT_WRAPPING) != _bUseFormerTextWrapping )
943     {
944         SwWait aWait( *GetDoc()->GetDocShell(), sal_True );
945         pIDSA->set(IDocumentSettingAccess::USE_FORMER_TEXT_WRAPPING, _bUseFormerTextWrapping );
946         const sal_uInt8 nInv = INV_PRTAREA | INV_SIZE | INV_TABLE | INV_SECTION;
947         lcl_InvalidateAllCntnt( *this, nInv );
948     }
949 }
950 // <--
951 
952 // -> PB 2007-06-11 #i45491#
953 void ViewShell::SetDoNotJustifyLinesWithManualBreak( bool _bDoNotJustifyLinesWithManualBreak )
954 {
955     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
956     if ( pIDSA->get(IDocumentSettingAccess::DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK) != _bDoNotJustifyLinesWithManualBreak )
957     {
958         SwWait aWait( *GetDoc()->GetDocShell(), sal_True );
959         pIDSA->set(IDocumentSettingAccess::DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK, _bDoNotJustifyLinesWithManualBreak );
960         const sal_uInt8 nInv = INV_PRTAREA | INV_SIZE | INV_TABLE | INV_SECTION;
961         lcl_InvalidateAllCntnt( *this, nInv );
962     }
963 }
964 // <--
965 
966 /******************************************************************************
967 |*
968 |*	ViewShell::Reformat
969 |*
970 |*	Ersterstellung		BP ???
971 |*	Letzte Aenderung	MA 13. Feb. 98
972 |*
973 ******************************************************************************/
974 
975 void ViewShell::Reformat()
976 {
977 	SwWait aWait( *GetDoc()->GetDocShell(), sal_True );
978 
979 	// Wir gehen auf Nummer sicher:
980 	// Wir muessen die alten Fontinformationen wegschmeissen,
981 	// wenn die Druckeraufloesung oder der Zoomfaktor sich aendert.
982 	// Init() und Reformat() sind die sichersten Stellen.
983 #ifdef FNTMET
984 	aFntMetList.Flush();
985 #else
986 	pFntCache->Flush( );
987 #endif
988 
989     if( GetLayout()->IsCallbackActionEnabled() )
990     {
991 
992         StartAction();
993         GetLayout()->InvalidateAllCntnt( INV_SIZE | INV_POS | INV_PRTAREA );
994         EndAction();
995     }
996 }
997 
998  void ViewShell::ChgNumberDigits()
999  {
1000      SdrModel* pTmpDrawModel = getIDocumentDrawModelAccess()->GetDrawModel();
1001      if ( pTmpDrawModel )
1002             pTmpDrawModel->ReformatAllTextObjects();
1003 	 Reformat();
1004  }
1005 
1006 /******************************************************************************
1007 |*
1008 |*	ViewShell::CalcLayout()
1009 |*					Vollstaendige Formatierung von Layout und Inhalt.
1010 |*
1011 |*	Ersterstellung		MA 31. Jan. 94
1012 |*	Letzte Aenderung	MA 08. Oct. 96
1013 |*
1014 ******************************************************************************/
1015 
1016 void ViewShell::CalcLayout()
1017 {
1018 	SET_CURR_SHELL( this );
1019 	SwWait aWait( *GetDoc()->GetDocShell(), sal_True );
1020 
1021 	//Cache vorbereiten und restaurieren, damit er nicht versaut wird.
1022 	SwSaveSetLRUOfst aSaveLRU( *SwTxtFrm::GetTxtCache(),
1023 						  		SwTxtFrm::GetTxtCache()->GetCurMax() - 50 );
1024 
1025 	//Progress einschalten wenn noch keiner Lauft.
1026 	const sal_Bool bEndProgress = SfxProgress::GetActiveProgress( GetDoc()->GetDocShell() ) == 0;
1027 	if ( bEndProgress )
1028 	{
1029 		sal_uInt16 nEndPage = GetLayout()->GetPageNum();
1030 		nEndPage += nEndPage * 10 / 100;
1031 		::StartProgress( STR_STATSTR_REFORMAT, 0, nEndPage, GetDoc()->GetDocShell() );
1032 	}
1033 
1034 	SwLayAction aAction( GetLayout(), Imp() );
1035 	aAction.SetPaint( sal_False );
1036 	aAction.SetStatBar( sal_True );
1037 	aAction.SetCalcLayout( sal_True );
1038 	aAction.SetReschedule( sal_True );
1039 	GetDoc()->LockExpFlds();
1040 	aAction.Action();
1041 	GetDoc()->UnlockExpFlds();
1042 
1043 	//Das SetNewFldLst() am Doc wurde unterbunden und muss nachgeholt
1044 	//werden (siehe flowfrm.cxx, txtfld.cxx)
1045 	if ( aAction.IsExpFlds() )
1046 	{
1047 		aAction.Reset();
1048 		aAction.SetPaint( sal_False );
1049 		aAction.SetStatBar( sal_True );
1050 		aAction.SetReschedule( sal_True );
1051 
1052 		SwDocPosUpdate aMsgHnt( 0 );
1053 		GetDoc()->UpdatePageFlds( &aMsgHnt );
1054 		GetDoc()->UpdateExpFlds(NULL, true);
1055 
1056 		aAction.Action();
1057 	}
1058 
1059 	if ( VisArea().HasArea() )
1060 		InvalidateWindows( VisArea() );
1061 	if ( bEndProgress )
1062 		::EndProgress( GetDoc()->GetDocShell() );
1063 }
1064 
1065 /******************************************************************************
1066 |*
1067 |*	ViewShell::SetFirstVisPageInvalid()
1068 |*
1069 |*	Ersterstellung		MA 19. May. 94
1070 |*	Letzte Aenderung	MA 19. May. 94
1071 |*
1072 ******************************************************************************/
1073 
1074 void ViewShell::SetFirstVisPageInvalid()
1075 {
1076 	ViewShell *pSh = this;
1077 	do
1078 	{	pSh->Imp()->SetFirstVisPageInvalid();
1079 		pSh = (ViewShell*)pSh->GetNext();
1080 
1081 	} while ( pSh != this );
1082 }
1083 
1084 /******************************************************************************
1085 |*
1086 |*	ViewShell::SizeChgNotify()
1087 |*
1088 |*	Ersterstellung		MA ??
1089 |*	Letzte Aenderung	MA 17. Sep. 96
1090 |*
1091 ******************************************************************************/
1092 
1093 void ViewShell::SizeChgNotify()
1094 {
1095 	if ( !pWin )
1096 		bDocSizeChgd = sal_True;
1097 	else if( ActionPend() || Imp()->IsCalcLayoutProgress() || bPaintInProgress )
1098 	{
1099 		bDocSizeChgd = sal_True;
1100 
1101 		if ( !Imp()->IsCalcLayoutProgress() && ISA( SwCrsrShell ) )
1102 		{
1103 			const SwFrm *pCnt = ((SwCrsrShell*)this)->GetCurrFrm( sal_False );
1104 			const SwPageFrm *pPage;
1105 			if ( pCnt && 0 != (pPage = pCnt->FindPageFrm()) )
1106 			{
1107 				sal_uInt16 nVirtNum = pPage->GetVirtPageNum();
1108 		 		const SvxNumberType& rNum = pPage->GetPageDesc()->GetNumType();
1109 				String sDisplay = rNum.GetNumStr( nVirtNum );
1110 				PageNumNotify( this, pCnt->GetPhyPageNum(), nVirtNum, sDisplay );
1111 			}
1112 		}
1113 	}
1114 	else
1115 	{
1116 		bDocSizeChgd = sal_False;
1117 		::SizeNotify( this, GetDocSize() );
1118 	}
1119 }
1120 
1121 /******************************************************************************
1122 |*
1123 |*	ViewShell::VisPortChgd()
1124 |*
1125 |*	Ersterstellung		MA ??
1126 |*	Letzte Aenderung	MA 22. Jul. 96
1127 |*
1128 ******************************************************************************/
1129 
1130 void ViewShell::VisPortChgd( const SwRect &rRect)
1131 {
1132 	ASSERT( GetWin(), "VisPortChgd ohne Window." );
1133 
1134 	if ( rRect == VisArea() )
1135 		return;
1136 
1137 #ifdef DBG_UTIL
1138 	if ( bInEndAction )
1139 	{
1140 		//Da Rescheduled doch schon wieder irgendwo einer?
1141 		ASSERT( !this, "Scroll waehrend einer EndAction." );
1142 	}
1143 #endif
1144 
1145 	//Ersteinmal die alte sichtbare Seite holen, dann braucht nacher nicht
1146 	//lange gesucht werden.
1147 	const SwFrm *pOldPage = Imp()->GetFirstVisPage();
1148 
1149 	const SwRect aPrevArea( VisArea() );
1150 	const sal_Bool bFull = aPrevArea.IsEmpty();
1151 	aVisArea = rRect;
1152 	SetFirstVisPageInvalid();
1153 
1154 	//Wenn noch eine PaintRegion herumsteht und sich die VisArea geaendert hat,
1155 	//so ist die PaintRegion spaetestens jetzt obsolete. Die PaintRegion kann
1156 	//vom RootFrm::Paint erzeugt worden sein.
1157 	if ( !bInEndAction &&
1158 		 Imp()->GetRegion() && Imp()->GetRegion()->GetOrigin() != VisArea() )
1159         Imp()->DelRegion();
1160 
1161 	SET_CURR_SHELL( this );
1162 
1163 	bool bScrolled = false;
1164 
1165     SwPostItMgr* pPostItMgr = GetPostItMgr();
1166 
1167     if ( bFull )
1168 		GetWin()->Invalidate();
1169 	else
1170 	{
1171 		// Betrag ausrechnen, um den gescrolled werden muss.
1172 		const long nXDiff = aPrevArea.Left() - VisArea().Left();
1173 		const long nYDiff = aPrevArea.Top()  - VisArea().Top();
1174 
1175         if( !nXDiff && !GetViewOptions()->getBrowseMode() &&
1176 			(!Imp()->HasDrawView() || !Imp()->GetDrawView()->IsGridVisible() ) )
1177 		{
1178 			//Falls moeglich die Wiese nicht mit Scrollen.
1179 			//Also linke und rechte Kante des Scrollbereiches auf die
1180 			//Seiten begrenzen.
1181 			const SwPageFrm *pPage = (SwPageFrm*)GetLayout()->Lower();	//swmod 071108//swmod 071225
1182 			if ( pPage->Frm().Top() > pOldPage->Frm().Top() )
1183 				pPage = (SwPageFrm*)pOldPage;
1184 			SwRect aBoth( VisArea() );
1185 			aBoth.Union( aPrevArea );
1186 			const SwTwips nBottom = aBoth.Bottom();
1187             SwTwips nMinLeft = LONG_MAX;
1188 			SwTwips nMaxRight= 0;
1189 
1190             const SwTwips nSidebarWidth = pPostItMgr && pPostItMgr->ShowNotes() && pPostItMgr->HasNotes() ?
1191                                           pPostItMgr->GetSidebarWidth() + pPostItMgr->GetSidebarBorderWidth() :
1192                                           0;
1193             const bool bBookMode = GetViewOptions()->IsViewLayoutBookMode();
1194 
1195             while ( pPage && pPage->Frm().Top() <= nBottom )
1196 			{
1197                 SwRect aPageRect( pPage->Frm() );
1198                 if ( bBookMode )
1199                 {
1200                     const SwPageFrm& rFormatPage = static_cast<const SwPageFrm*>(pPage)->GetFormatPage();
1201                     aPageRect.SSize() = rFormatPage.Frm().SSize();
1202                 }
1203 
1204                 if ( aPageRect.IsOver( aBoth ) )
1205 				{
1206                     // OD 12.02.2003 #i9719#, #105645# - consider new border
1207                     // and shadow width
1208                     const SwTwips nBorderWidth =
1209                             GetOut()->PixelToLogic( Size( pPage->BorderPxWidth(), 0 ) ).Width();
1210                     const SwTwips nShadowWidth =
1211                             GetOut()->PixelToLogic( Size( pPage->ShadowPxWidth(), 0 ) ).Width();
1212 
1213                     SwTwips nPageLeft = 0;
1214 					SwTwips nPageRight = 0;
1215                     switch ( pPage->SidebarPosition() )
1216                     {
1217                         case sw::sidebarwindows::SIDEBAR_LEFT:
1218                         {
1219                             nPageLeft =  aPageRect.Left() - nBorderWidth - nSidebarWidth;
1220                             nPageRight = aPageRect.Right() + nBorderWidth + nShadowWidth;
1221                         }
1222                         break;
1223                         case sw::sidebarwindows::SIDEBAR_RIGHT:
1224                         {
1225                             nPageLeft =  aPageRect.Left() - nBorderWidth;
1226                             nPageRight = aPageRect.Right() + nBorderWidth + nShadowWidth + nSidebarWidth;
1227                         }
1228                         break;
1229                         case sw::sidebarwindows::SIDEBAR_NONE:
1230                             // nothing to do
1231                         break;
1232                     }
1233 					if( nPageLeft < nMinLeft )
1234                         nMinLeft = nPageLeft;
1235 					if( nPageRight > nMaxRight )
1236                         nMaxRight = nPageRight;
1237 					//Zus. auf die Zeichenobjekte abgleichen.
1238 					//Einen Ofst beruecksichtigen, weil die Objekte u.U.
1239 					//selektiert sind und die Henkel dann hinausstehen.
1240 					if ( pPage->GetSortedObjs() )
1241 					{
1242 						const long nOfst = GetOut()->PixelToLogic(
1243 							Size(Imp()->GetDrawView()->GetMarkHdlSizePixel()/2,0)).Width();
1244                         for ( sal_uInt16 i = 0;
1245 							  i < pPage->GetSortedObjs()->Count(); ++i )
1246 						{
1247                             SwAnchoredObject* pObj = (*pPage->GetSortedObjs())[i];
1248                             const Rectangle &rBound = pObj->GetObjRect().SVRect();
1249                             // OD 03.03.2003 #107927# - use correct datatype
1250                             const SwTwips nL = Max( 0L, rBound.Left() - nOfst );
1251 							if ( nL < nMinLeft )
1252 								nMinLeft = nL;
1253 							if( rBound.Right() + nOfst > nMaxRight )
1254 								nMaxRight = rBound.Right() + nOfst;
1255 						}
1256 					}
1257 				}
1258 				pPage = (SwPageFrm*)pPage->GetNext();
1259 			}
1260 			Rectangle aRect( aPrevArea.SVRect() );
1261 			aRect.Left()  = nMinLeft;
1262 			aRect.Right() = nMaxRight;
1263 			if( VisArea().IsOver( aPrevArea ) && !nLockPaint )
1264 			{
1265 				bScrolled = true;
1266 				aVisArea.Pos() = aPrevArea.Pos();
1267 				if ( SmoothScroll( nXDiff, nYDiff, &aRect ) )
1268 					return;
1269 				aVisArea.Pos() = rRect.Pos();
1270 			}
1271 			else
1272 				GetWin()->Invalidate( aRect );
1273 		}
1274 		else if ( !nLockPaint ) //Wird im UnLock erledigt
1275 		{
1276 			if( VisArea().IsOver( aPrevArea ) )
1277 			{
1278 				bScrolled = true;
1279 				aVisArea.Pos() = aPrevArea.Pos();
1280 				if ( SmoothScroll( nXDiff, nYDiff, 0 ) )
1281 					return;
1282 				aVisArea.Pos() = rRect.Pos();
1283 			}
1284 			else
1285 				GetWin()->Invalidate();
1286 		}
1287 	}
1288 
1289 	Point aPt( VisArea().Pos() );
1290 	aPt.X() = -aPt.X(); aPt.Y() = -aPt.Y();
1291 	MapMode aMapMode( GetWin()->GetMapMode() );
1292 	aMapMode.SetOrigin( aPt );
1293 	GetWin()->SetMapMode( aMapMode );
1294 	if ( HasDrawView() )
1295 	{
1296 		Imp()->GetDrawView()->VisAreaChanged( GetWin() );
1297 		Imp()->GetDrawView()->SetActualWin( GetWin() );
1298 	}
1299 	GetWin()->Update();
1300 
1301     // --> OD 2010-02-11 #i88070#
1302     if ( pPostItMgr )
1303     {
1304         pPostItMgr->Rescale();
1305         pPostItMgr->CalcRects();
1306         pPostItMgr->LayoutPostIts();
1307     }
1308     // <--
1309 
1310     if ( !bScrolled && pPostItMgr && pPostItMgr->HasNotes() && pPostItMgr->ShowNotes() )
1311 		pPostItMgr->CorrectPositions();
1312 
1313 	if( Imp()->IsAccessible() )
1314 		Imp()->UpdateAccessible();
1315 
1316 }
1317 
1318 /******************************************************************************
1319 |*
1320 |*	ViewShell::SmoothScroll()
1321 |*
1322 |*	Ersterstellung		MA 04. Jul. 96
1323 |*	Letzte Aenderung	MA 25. Mar. 97
1324 |*
1325 ******************************************************************************/
1326 
1327 sal_Bool ViewShell::SmoothScroll( long lXDiff, long lYDiff, const Rectangle *pRect )
1328 {
1329 	const sal_uLong nColCnt = pOut->GetColorCount();
1330 	long lMult = 1, lMax = LONG_MAX;
1331 	if ( nColCnt == 65536 )
1332 	{
1333 		lMax = 7000;
1334 		lMult = 2;
1335 	}
1336 	if ( nColCnt == 16777216 )
1337 	{
1338 		lMax = 5000;
1339 		lMult = 6;
1340 	}
1341 	else if ( nColCnt == 1 )
1342 	{
1343 		lMax = 3000;
1344 		lMult = 12;
1345 	}
1346 
1347 	// #i75172# isolated static conditions
1348 	const bool bOnlyYScroll(!lXDiff && Abs(lYDiff) != 0 && Abs(lYDiff) < lMax);
1349 	const bool bAllowedWithChildWindows(GetWin()->GetWindowClipRegionPixel(WINDOW_GETCLIPREGION_NOCHILDREN|WINDOW_GETCLIPREGION_NULL).IsNull());
1350 // --> OD 2009-08-12 #i98766# - disable smooth scrolling for Mac port builds
1351 #ifdef QUARTZ
1352     const bool bSmoothScrollAllowed(false);
1353     (void) bOnlyYScroll;
1354     (void) bAllowedWithChildWindows;
1355 #else
1356     const bool bSmoothScrollAllowed(bOnlyYScroll && bEnableSmooth && GetViewOptions()->IsSmoothScroll() &&  bAllowedWithChildWindows);
1357 #endif
1358 // <-
1359 	const bool bIAmCursorShell(ISA(SwCrsrShell));
1360     (void) bIAmCursorShell;
1361 
1362 	// #i75172# with selection on overlay, smooth scroll should be allowed with it
1363 	const bool bAllowedForSelection(true || (bIAmCursorShell && !((SwCrsrShell*)this)->HasSelection()));
1364 
1365 	// #i75172# with cursors on overlay, smooth scroll should be allowed with it
1366 	const bool bAllowedForMultipleCursors(true || (bIAmCursorShell && ((SwCrsrShell*)this)->GetCrsrCnt() < 2));
1367 
1368 	if(bSmoothScrollAllowed  && bAllowedForSelection && bAllowedForMultipleCursors)
1369 	{
1370 		Imp()->bStopSmooth = sal_False;
1371 
1372 		const SwRect aOldVis( VisArea() );
1373 
1374 		//Virtuelles Device erzeugen und einstellen.
1375 		const Size aPixSz = GetWin()->PixelToLogic(Size(1,1));
1376 		VirtualDevice *pVout = new VirtualDevice( *GetWin() );
1377 		pVout->SetLineColor( GetWin()->GetLineColor() );
1378 		pVout->SetFillColor( GetWin()->GetFillColor() );
1379 		MapMode aMapMode( GetWin()->GetMapMode() );
1380 		pVout->SetMapMode( aMapMode );
1381 		Size aSize( aVisArea.Width()+2*aPixSz.Width(), Abs(lYDiff)+(2*aPixSz.Height()) );
1382 		if ( pRect )
1383 			aSize.Width() = Min(aSize.Width(), pRect->GetWidth()+2*aPixSz.Width());
1384 		if ( pVout->SetOutputSize( aSize ) )
1385 		{
1386 			nLockPaint++;
1387 
1388 			//Ersteinmal alles neue in das VirDev Painten.
1389 			SwRect aRect( VisArea() );
1390 			aRect.Height( aSize.Height() );
1391 			if ( pRect )
1392 			{
1393 				aRect.Pos().X() = Max(aRect.Left(),pRect->Left()-aPixSz.Width());
1394 				aRect.Right( Min(aRect.Right()+2*aPixSz.Width(), pRect->Right()+aPixSz.Width()));
1395 			}
1396 			else
1397 				aRect.SSize().Width() += 2*aPixSz.Width();
1398 			aRect.Pos().Y() = lYDiff < 0 ? aOldVis.Bottom() - aPixSz.Height()
1399 										 : aRect.Top() - aSize.Height() + aPixSz.Height();
1400 			aRect.Pos().X() = Max( 0L, aRect.Left()-aPixSz.Width() );
1401 			aRect.Pos()  = GetWin()->PixelToLogic( GetWin()->LogicToPixel( aRect.Pos()));
1402 			aRect.SSize()= GetWin()->PixelToLogic( GetWin()->LogicToPixel( aRect.SSize()));
1403 			aVisArea = aRect;
1404 			const Point aPt( -aRect.Left(), -aRect.Top() );
1405 			aMapMode.SetOrigin( aPt );
1406 			pVout->SetMapMode( aMapMode );
1407 			OutputDevice *pOld = pOut;
1408 			pOut = pVout;
1409 
1410 			{
1411 				// #i75172# To get a clean repaint, a new ObjectContact is needed here. Without, the
1412 				// repaint would not be correct since it would use the wrong DrawPage visible region.
1413 				// This repaint IS about painting something currently outside the visible part (!).
1414 				// For that purpose, AddWindowToPaintView is used which creates a new SdrPageViewWindow
1415 				// and all the necessary stuff. It's not cheap, but necessary here. Alone because repaint
1416 				// target really is NOT the current window.
1417 				// Also will automatically NOT use PreRendering and overlay (since target is VirtualDevice)
1418 				if(!HasDrawView())
1419 					MakeDrawView();
1420 				SdrView* pDrawView = GetDrawView();
1421 				pDrawView->AddWindowToPaintView(pVout);
1422 
1423 				// clear pWin during DLPrePaint2 to get paint preparation for pOut, but set it again
1424 				// immediately afterwards. There are many decisions in SW which imply that Printing
1425 				// is used when pWin == 0 (wrong but widely used).
1426 				Window* pOldWin = pWin;
1427 				pWin = 0;
1428 				DLPrePaint2(Region(aRect.SVRect()));
1429 				pWin = pOldWin;
1430 
1431 				// SW paint stuff
1432 				PaintDesktop( aRect );
1433 				ViewShell::bLstAct = sal_True;
1434 				GetLayout()->Paint( aRect );
1435 				ViewShell::bLstAct = sal_False;
1436 
1437 				// end paint and destroy ObjectContact again
1438 				DLPostPaint2(true);
1439 				pDrawView->DeleteWindowFromPaintView(pVout);
1440 
1441 				// temporary debug paint checking...
1442 				static bool bDoSaveForVisualControl(false);
1443 				if(bDoSaveForVisualControl)
1444 				{
1445 					const bool bMapModeWasEnabledVDev(pVout->IsMapModeEnabled());
1446 					pVout->EnableMapMode(false);
1447 					const Bitmap aBitmap(pVout->GetBitmap(Point(), pVout->GetOutputSizePixel()));
1448                     const String aTmpString(ByteString( "c:\\test.bmp" ), RTL_TEXTENCODING_UTF8);
1449                     SvFileStream aNew(aTmpString, STREAM_WRITE|STREAM_TRUNC);
1450 					aNew << aBitmap;
1451 					pVout->EnableMapMode(bMapModeWasEnabledVDev);
1452 				}
1453 			}
1454 
1455 			pOut = pOld;
1456 			aVisArea = aOldVis;
1457 
1458 			//Jetzt Stueckchenweise schieben und die neuen Pixel aus dem
1459 			//VirDev  kopieren.
1460 
1461 			// ??????????????????????
1462 			// or is it better to get the scrollfactor from the User
1463 			// as option?
1464 			// ??????????????????????
1465 			long lMaDelta = aPixSz.Height();
1466 			if ( Abs(lYDiff) > ( aVisArea.Height() / 3 ) )
1467 				lMaDelta *= 6;
1468 			else
1469 				lMaDelta *= 2;
1470 
1471 			lMaDelta *= lMult;
1472 
1473 			if ( lYDiff < 0 )
1474 				lMaDelta = -lMaDelta;
1475 
1476 			long lDiff = lYDiff;
1477 			while ( lDiff )
1478 			{
1479 				long lScroll;
1480 				if ( Imp()->bStopSmooth || Abs(lDiff) <= Abs(lMaDelta) )
1481 				{
1482 					lScroll = lDiff;
1483 					lDiff = 0;
1484 				}
1485 				else
1486 				{
1487 					lScroll = lMaDelta;
1488 					lDiff -= lMaDelta;
1489 				}
1490 
1491                 const SwRect aTmpOldVis = VisArea();
1492 				aVisArea.Pos().Y() -= lScroll;
1493 				aVisArea.Pos() = GetWin()->PixelToLogic( GetWin()->LogicToPixel( VisArea().Pos()));
1494                 lScroll = aTmpOldVis.Top() - VisArea().Top();
1495 				if ( pRect )
1496 				{
1497                     Rectangle aTmp( aTmpOldVis.SVRect() );
1498 					aTmp.Left() = pRect->Left();
1499 					aTmp.Right()= pRect->Right();
1500 					GetWin()->Scroll( 0, lScroll, aTmp, SCROLL_CHILDREN);
1501 				}
1502 				else
1503 					GetWin()->Scroll( 0, lScroll, SCROLL_CHILDREN );
1504 
1505                 const Point aTmpPt( -VisArea().Left(), -VisArea().Top() );
1506                 MapMode aTmpMapMode( GetWin()->GetMapMode() );
1507                 aTmpMapMode.SetOrigin( aTmpPt );
1508                 GetWin()->SetMapMode( aTmpMapMode );
1509 
1510 				if ( Imp()->HasDrawView() )
1511 					Imp()->GetDrawView()->VisAreaChanged( GetWin() );
1512 
1513 				SetFirstVisPageInvalid();
1514 				if ( !Imp()->bStopSmooth )
1515 				{
1516 					const bool bScrollDirectionIsUp(lScroll > 0);
1517 					Imp()->aSmoothRect = VisArea();
1518 
1519 					if(bScrollDirectionIsUp)
1520 					{
1521 						Imp()->aSmoothRect.Bottom( VisArea().Top() + lScroll + aPixSz.Height());
1522 					}
1523 					else
1524 					{
1525 						Imp()->aSmoothRect.Top( VisArea().Bottom() + lScroll - aPixSz.Height());
1526 					}
1527 
1528 					Imp()->bSmoothUpdate = sal_True;
1529 					GetWin()->Update();
1530 					Imp()->bSmoothUpdate = sal_False;
1531 
1532 					if(!Imp()->bStopSmooth)
1533 					{
1534 						static bool bDoItOnPixels(true);
1535 						if(bDoItOnPixels)
1536 						{
1537 							// start paint on logic base
1538 							const Rectangle aTargetLogic(Imp()->aSmoothRect.SVRect());
1539 							DLPrePaint2(Region(aTargetLogic));
1540 
1541 							// get target rectangle in discrete pixels
1542 							OutputDevice& rTargetDevice = mpTargetPaintWindow->GetTargetOutputDevice();
1543 							const Rectangle aTargetPixel(rTargetDevice.LogicToPixel(aTargetLogic));
1544 
1545 							// get source top-left in discrete pixels
1546 							const Point aSourceTopLeft(pVout->LogicToPixel(aTargetLogic.TopLeft()));
1547 
1548 							// switch off MapModes
1549 							const bool bMapModeWasEnabledDest(rTargetDevice.IsMapModeEnabled());
1550 							const bool bMapModeWasEnabledSource(pVout->IsMapModeEnabled());
1551 							rTargetDevice.EnableMapMode(false);
1552 							pVout->EnableMapMode(false);
1553 
1554 							// copy content
1555 							static bool bTestDirectToWindowPaint(false);
1556 							if(bTestDirectToWindowPaint)
1557 							{
1558 								const bool bMapModeWasEnabledWin(GetWin()->IsMapModeEnabled());
1559 								GetWin()->EnableMapMode(false);
1560 
1561 								GetWin()->DrawOutDev(
1562 									aTargetPixel.TopLeft(), aTargetPixel.GetSize(), // dest
1563 									aSourceTopLeft, aTargetPixel.GetSize(), // source
1564 									*pVout);
1565 
1566 								GetWin()->EnableMapMode(bMapModeWasEnabledWin);
1567 							}
1568 
1569 							rTargetDevice.DrawOutDev(
1570 								aTargetPixel.TopLeft(), aTargetPixel.GetSize(), // dest
1571 								aSourceTopLeft, aTargetPixel.GetSize(), // source
1572 								*pVout);
1573 
1574 							// restore MapModes
1575 							rTargetDevice.EnableMapMode(bMapModeWasEnabledDest);
1576 							pVout->EnableMapMode(bMapModeWasEnabledSource);
1577 
1578 							// end paint on logoc base
1579 							DLPostPaint2(true);
1580 						}
1581 						else
1582 						{
1583 							Rectangle aRectangle(Imp()->aSmoothRect.SVRect());
1584 							aRectangle.Left() -= aPixSz.Width();
1585 							aRectangle.Right() += aPixSz.Width();
1586 							aRectangle.Top() -= aPixSz.Height();
1587 							aRectangle.Bottom() += aPixSz.Height();
1588 							const Point aUpdateTopLeft(aRectangle.TopLeft());
1589 							const Size aUpdateSize(aRectangle.GetSize());
1590 
1591 							// #i75172# the part getting visible needs to be handled like a repaint.
1592 							// For that, start with DLPrePaint2 and the correct Rectangle
1593 							DLPrePaint2(Region(aRectangle));
1594 
1595 							static bool bTestDirectToWindowPaint(false);
1596 							if(bTestDirectToWindowPaint)
1597 							{
1598 								GetWin()->DrawOutDev(aUpdateTopLeft, aUpdateSize, aUpdateTopLeft, aUpdateSize, *pVout);
1599 							}
1600 
1601 							mpTargetPaintWindow->GetTargetOutputDevice().DrawOutDev(aUpdateTopLeft, aUpdateSize, aUpdateTopLeft, aUpdateSize, *pVout);
1602 
1603 							// #i75172# Corret repaint end
1604 							// Note: This also correcty creates the overlay, thus smooth scroll will
1605 							// also be allowed now wth selection (see big IF above)
1606 							DLPostPaint2(true);
1607 						}
1608 					}
1609 					else
1610 						--nLockPaint;
1611 				}
1612 			}
1613 			delete pVout;
1614 			GetWin()->Update();
1615 			if ( !Imp()->bStopSmooth )
1616 				--nLockPaint;
1617 			SetFirstVisPageInvalid();
1618 			return sal_True;
1619 		}
1620 		delete pVout;
1621 	}
1622 
1623     aVisArea.Pos().X() -= lXDiff;
1624 	aVisArea.Pos().Y() -= lYDiff;
1625 	if ( pRect )
1626 		GetWin()->Scroll( lXDiff, lYDiff, *pRect, SCROLL_CHILDREN);
1627 	else
1628 		GetWin()->Scroll( lXDiff, lYDiff, SCROLL_CHILDREN);
1629 	return sal_False;
1630 }
1631 
1632 /******************************************************************************
1633 |*
1634 |*	ViewShell::PaintDesktop()
1635 |*
1636 |*	Ersterstellung		MA 16. Dec. 93
1637 |*	Letzte Aenderung	MA 30. Nov. 95
1638 |*
1639 ******************************************************************************/
1640 
1641 void ViewShell::PaintDesktop( const SwRect &rRect )
1642 {
1643 	if ( !GetWin() && !GetOut()->GetConnectMetaFile() )
1644 		return;						//Fuer den Drucker tun wir hier nix
1645 
1646 	//Sonderfaelle abfangen, damit es nicht gar so ueberraschend aussieht.
1647 	//Kann z.B. waehrend des Idle'ns zwischenzeitlich auftreten.
1648 	//Die Rechtecke neben den Seiten muessen wir leider auf jedenfall Painten,
1649 	//den diese werden spaeter beim VisPortChgd ausgespart.
1650 	sal_Bool bBorderOnly = sal_False;
1651 	const SwRootFrm *pRoot = GetLayout();//swmod 080305
1652 	if ( rRect.Top() > pRoot->Frm().Bottom() )
1653 	{
1654 		const SwFrm *pPg = pRoot->Lower();
1655 		while ( pPg && pPg->GetNext() )
1656 			pPg = pPg->GetNext();
1657 		if ( !pPg || !pPg->Frm().IsOver( VisArea() ) )
1658 			bBorderOnly = sal_True;
1659 	}
1660 
1661     const bool bBookMode = GetViewOptions()->IsViewLayoutBookMode();
1662 
1663     SwRegionRects aRegion( rRect );
1664 
1665 	//mod #i6193: remove sidebar area to avoid flickering
1666     const SwPostItMgr* pPostItMgr = GetPostItMgr();
1667     const SwTwips nSidebarWidth = pPostItMgr && pPostItMgr->HasNotes() && pPostItMgr->ShowNotes() ?
1668                                   pPostItMgr->GetSidebarWidth() + pPostItMgr->GetSidebarBorderWidth() :
1669                                   0;
1670 
1671     if ( bBorderOnly )
1672 	{
1673 		const SwFrm *pPage =pRoot->Lower();	//swmod 071108//swmod 071225
1674 		SwRect aLeft( rRect ), aRight( rRect );
1675 		while ( pPage )
1676 		{
1677 			long nTmp = pPage->Frm().Left();
1678 			if ( nTmp < aLeft.Right() )
1679 				aLeft.Right( nTmp );
1680 			nTmp = pPage->Frm().Right();
1681 			if ( nTmp > aRight.Left() )
1682 			{
1683                 aRight.Left( nTmp + nSidebarWidth );
1684             }
1685 			pPage = pPage->GetNext();
1686 		}
1687 		aRegion.Remove( 0, aRegion.Count() );
1688 		if ( aLeft.HasArea() )
1689 			aRegion.Insert( aLeft, 0 );
1690 		if ( aRight.HasArea() )
1691 			aRegion.Insert( aRight, 1 );
1692 	}
1693 	else
1694 	{
1695 		const SwFrm *pPage = Imp()->GetFirstVisPage();
1696 		const SwTwips nBottom = rRect.Bottom();
1697         //const SwTwips nRight  = rRect.Right();
1698 		while ( pPage && aRegion.Count() &&
1699 				(pPage->Frm().Top() <= nBottom) ) // PAGES01 && (pPage->Frm().Left() <= nRight))
1700 		{
1701             SwRect aPageRect( pPage->Frm() );
1702             if ( bBookMode )
1703             {
1704                 const SwPageFrm& rFormatPage = static_cast<const SwPageFrm*>(pPage)->GetFormatPage();
1705                 aPageRect.SSize() = rFormatPage.Frm().SSize();
1706             }
1707 
1708             const bool bSidebarRight =
1709                 static_cast<const SwPageFrm*>(pPage)->SidebarPosition() == sw::sidebarwindows::SIDEBAR_RIGHT;
1710             aPageRect.Pos().X() -= bSidebarRight ? 0 : nSidebarWidth;
1711             aPageRect.SSize().Width() += nSidebarWidth;
1712 
1713             if ( aPageRect.IsOver( rRect ) )
1714                 aRegion -= aPageRect;
1715 
1716             pPage = pPage->GetNext();
1717 		}
1718 	}
1719 	if ( aRegion.Count() )
1720 		_PaintDesktop( aRegion );
1721 }
1722 
1723 
1724 // PaintDesktop gesplittet, dieser Teil wird auch von PreViewPage benutzt
1725 void ViewShell::_PaintDesktop( const SwRegionRects &rRegion )
1726 {
1727     // OD 2004-04-23 #116347#
1728     GetOut()->Push( PUSH_FILLCOLOR|PUSH_LINECOLOR );
1729     GetOut()->SetLineColor();
1730 
1731 	for ( sal_uInt16 i = 0; i < rRegion.Count(); ++i )
1732 	{
1733 		const Rectangle aRectangle(rRegion[i].SVRect());
1734 
1735         // #i93170#
1736         // Here we have a real Problem. On the one hand we have the buffering for paint
1737         // and overlay which needs an embracing pair of DLPrePaint2/DLPostPaint2 calls,
1738         // on the other hand the MapMode is not set correctly when this code is executed.
1739         // This is done in the users of this method, for each SWpage before painting it.
1740         // Since the MapMode is not correct here, the call to DLPostPaint2 will paint
1741         // existing FormControls due to the current MapMode.
1742         //
1743         // There are basically three solutions for this:
1744         //
1745         // (1) Set the MapMode correct, move the background painting to the users of
1746         //     this code
1747         //
1748         // (2) Do no DLPrePaint2/DLPostPaint2 here; no SdrObjects are allowed to lie in
1749         //     the desktop region. Disadvantage: the desktop will not be part of the
1750         //     buffers, e.g. overlay. Thus, as soon as overlay will be used over the
1751         //     desktop, it will not work.
1752         //
1753         // (3) expand DLPostPaint2 with a flag to signal if FormControl paints shall
1754         //     be done or not
1755         //
1756         // Currently, (3) will be the best possible solution. It will keep overlay and
1757 		// buffering intact and work without MapMode for single pages. In the medium
1758 		// to long run, (1) will need to be used and the bool bPaintFormLayer needs
1759 		// to be removed again
1760 
1761 		// #i68597# inform Drawinglayer about display change
1762 		DLPrePaint2(Region(aRectangle));
1763 
1764 		// #i75172# needed to move line/Fill color setters into loop since DLPrePaint2
1765 		// may exchange GetOut(), that's it's purpose. This happens e.g. at print preview.
1766 		GetOut()->SetFillColor( SwViewOption::GetAppBackgroundColor());
1767 		GetOut()->SetLineColor();
1768 		GetOut()->DrawRect(aRectangle);
1769 
1770 		DLPostPaint2(false);
1771 	}
1772 
1773 	GetOut()->Pop();
1774 }
1775 
1776 /******************************************************************************
1777 |*
1778 |*	ViewShell::CheckInvalidForPaint()
1779 |*
1780 |*	Ersterstellung		MA 19. May. 94
1781 |*	Letzte Aenderung	MA 09. Jun. 94
1782 |*
1783 ******************************************************************************/
1784 
1785 sal_Bool ViewShell::CheckInvalidForPaint( const SwRect &rRect )
1786 {
1787 	if ( !GetWin() )
1788 		return sal_False;
1789 
1790 	const SwPageFrm *pPage = Imp()->GetFirstVisPage();
1791 	const SwTwips nBottom = VisArea().Bottom();
1792 	const SwTwips nRight  = VisArea().Right();
1793 	sal_Bool bRet = sal_False;
1794 	while ( !bRet && pPage && !((pPage->Frm().Top()  > nBottom) ||
1795 					   			(pPage->Frm().Left() > nRight)))
1796 	{
1797 		if ( pPage->IsInvalid() || pPage->IsInvalidFly() )
1798 			bRet = sal_True;
1799 		pPage = (SwPageFrm*)pPage->GetNext();
1800 	}
1801 
1802 	if ( bRet )
1803 	{
1804 		//Start/EndAction wuerden hier leider nix helfen, weil das Paint vom
1805 		//GUI 'reinkam und somit ein Clipping gesetzt ist gegen das wir nicht
1806 		//nicht ankommen.
1807 		//Ergo: Alles selbst machen (siehe ImplEndAction())
1808 		if ( Imp()->GetRegion() && Imp()->GetRegion()->GetOrigin() != VisArea())
1809              Imp()->DelRegion();
1810 
1811 		SwLayAction aAction( GetLayout(), Imp() );
1812 		aAction.SetComplete( sal_False );
1813         // We increment the action counter to avoid a recursive call of actions
1814         // e.g. from a SwFEShell::RequestObjectResize(..) in bug 95829.
1815         // A recursive call of actions is no good idea because the inner action
1816         // can't format frames which are locked by the outer action. This may
1817         // cause and endless loop.
1818         ++nStartAction;
1819 		aAction.Action();
1820         --nStartAction;
1821 
1822 		SwRegionRects *pRegion = Imp()->GetRegion();
1823 		if ( pRegion && aAction.IsBrowseActionStop() )
1824 		{
1825 			//Nur dann interessant, wenn sich im sichtbaren Bereich etwas
1826 			//veraendert hat.
1827 			sal_Bool bStop = sal_True;
1828 			for ( sal_uInt16 i = 0; i < pRegion->Count(); ++i )
1829 			{
1830 				const SwRect &rTmp = (*pRegion)[i];
1831 				if ( sal_False == (bStop = rTmp.IsOver( VisArea() )) )
1832 					break;
1833 			}
1834 			if ( bStop )
1835 			{
1836                 Imp()->DelRegion();
1837 				pRegion = 0;
1838 			}
1839 		}
1840 
1841 		if ( pRegion )
1842 		{
1843 			//Erst Invert dann Compress, niemals andersherum!
1844 			pRegion->Invert();
1845 			pRegion->Compress();
1846 			bRet = sal_False;
1847 			if ( pRegion->Count() )
1848 			{
1849 				SwRegionRects aRegion( rRect );
1850 				for ( sal_uInt16 i = 0; i < pRegion->Count(); ++i )
1851 				{	const SwRect &rTmp = (*pRegion)[i];
1852 					if ( !rRect.IsInside( rTmp ) )
1853 					{
1854 						InvalidateWindows( rTmp );
1855 						if ( rTmp.IsOver( VisArea() ) )
1856 						{	aRegion -= rTmp;
1857 							bRet = sal_True;
1858 						}
1859 					}
1860 				}
1861 				if ( bRet )
1862 				{
1863 					for ( sal_uInt16 i = 0; i < aRegion.Count(); ++i )
1864 						GetWin()->Invalidate( aRegion[i].SVRect() );
1865 
1866 					if ( rRect != VisArea() )
1867 					{
1868 						//rRect == VisArea ist der spezialfall fuer neu bzw.
1869 						//Shift-Ctrl-R, dafuer sollte es nicht notwendig sein
1870 						//das Rechteck nocheinmal in Dokumentkoordinaten v
1871 						//vorzuhalten.
1872 						if ( aInvalidRect.IsEmpty() )
1873 							aInvalidRect = rRect;
1874 						else
1875 							aInvalidRect.Union( rRect );
1876 					}
1877 				}
1878 			}
1879 			else
1880 				bRet = sal_False;
1881             Imp()->DelRegion();
1882 		}
1883 		else
1884 			bRet = sal_False;
1885 	}
1886 	return bRet;
1887 }
1888 
1889 /******************************************************************************
1890 |*
1891 |*	ViewShell::Paint()
1892 |*
1893 |*	Ersterstellung		MA ??
1894 |*	Letzte Aenderung	MA 17. Sep. 96
1895 |*
1896 ******************************************************************************/
1897 
1898 void ViewShell::Paint(const Rectangle &rRect)
1899 {
1900 	if ( nLockPaint )
1901 	{
1902 		if ( Imp()->bSmoothUpdate )
1903 		{
1904 			SwRect aTmp( rRect );
1905 			if ( !Imp()->aSmoothRect.IsInside( aTmp ) )
1906 				Imp()->bStopSmooth = sal_True;
1907 			else
1908 			{
1909 				Imp()->aSmoothRect = aTmp;
1910 				return;
1911 			}
1912 		}
1913 		else
1914 			return;
1915 	}
1916 
1917 	if ( SwRootFrm::IsInPaint() )
1918 	{
1919 		//Waehrend der Ausgabe einer Seite beim Druckvorgang wird das
1920 		//Paint gepuffert.
1921 		SwPaintQueue::Add( this, SwRect( rRect ) );
1922 		return;
1923 	}
1924 
1925 	//MA 30. Jul. 95: fix(16787): mit !nStartAction versuche ich mal mich gegen
1926 	//fehlerhaften Code an anderen Stellen zu wehren. Hoffentlich fuehrt das
1927 	//nicht zu Problemen!?
1928 	if ( bPaintWorks && !nStartAction )
1929 	{
1930 		if( GetWin() && GetWin()->IsVisible() )
1931 		{
1932 			SwRect aRect( rRect );
1933 			if ( bPaintInProgress ) //Schutz gegen doppelte Paints!
1934 			{
1935 				GetWin()->Invalidate( rRect );
1936 				return;
1937 			}
1938 
1939 			bPaintInProgress = sal_True;
1940 			SET_CURR_SHELL( this );
1941 			SwRootFrm::SetNoVirDev( sal_True );
1942 
1943 			//Wir wollen nicht staendig hin und her Clippen, wir verlassen
1944 			//uns darauf, das sich alle auf das Rechteck beschraeken und
1945 			//brauchen das Clipping hier nur einmalig einkalkulieren. Das
1946 			//ClipRect wird hier einmal entfernt und nicht Restauriert, denn
1947 			//von aussen braucht es sowieso keiner mehr.
1948 			//Nicht wenn wir ein MetaFile aufzeichnen.
1949 			if( !GetOut()->GetConnectMetaFile() && GetOut()->IsClipRegion())
1950 				GetOut()->SetClipRegion();
1951 
1952 			if ( IsPreView() )
1953 			{
1954 				//Falls sinnvoll gleich das alte InvalidRect verarbeiten bzw.
1955 				//vernichten.
1956 				if ( aRect.IsInside( aInvalidRect ) )
1957 					ResetInvalidRect();
1958 				ViewShell::bLstAct = sal_True;
1959 				GetLayout()->Paint( aRect );
1960 				ViewShell::bLstAct = sal_False;
1961 			}
1962 			else
1963 			{
1964 				//SwSaveHdl *pSaveHdl = 0;
1965 				//if ( Imp()->HasDrawView() )
1966 				//	pSaveHdl = new SwSaveHdl( Imp() );
1967 
1968 				//Wenn eine der sichtbaren Seiten noch irgendetwas zum Repaint
1969 				//angemeldet hat, so muessen Repaints ausgeloest werden.
1970 				if ( !CheckInvalidForPaint( aRect ) )
1971 				{
1972                     // --> OD 2009-08-12 #i101192#
1973                     // start Pre/PostPaint encapsulation to avoid screen blinking
1974                     const Region aRepaintRegion(aRect.SVRect());
1975                     DLPrePaint2(aRepaintRegion);
1976                     // <--
1977 					PaintDesktop( aRect );
1978 					//Falls sinnvoll gleich das alte InvalidRect verarbeiten bzw.
1979 					//vernichten.
1980 					if ( aRect.IsInside( aInvalidRect ) )
1981 						ResetInvalidRect();
1982 					ViewShell::bLstAct = sal_True;
1983 					GetLayout()->Paint( aRect );
1984 					ViewShell::bLstAct = sal_False;
1985                     // --> OD 2009-08-12 #i101192#
1986                     // end Pre/PostPaint encapsulation
1987                     DLPostPaint2(true);
1988                     // <--
1989                 }
1990 
1991 				//delete pSaveHdl;
1992 			}
1993 			SwRootFrm::SetNoVirDev( sal_False );
1994 			bPaintInProgress = sal_False;
1995 			UISizeNotify();
1996 		}
1997 	}
1998 	else
1999 	{
2000 		if ( aInvalidRect.IsEmpty() )
2001 			aInvalidRect = SwRect( rRect );
2002 		else
2003 			aInvalidRect.Union( SwRect( rRect ) );
2004 
2005 		if ( bInEndAction && GetWin() )
2006 		{
2007 			Region aRegion( GetWin()->GetPaintRegion() );
2008 			RegionHandle hHdl( aRegion.BeginEnumRects() );
2009 			Rectangle aRect;
2010 			while ( aRegion.GetNextEnumRect( hHdl, aRect ) )
2011 				Imp()->AddPaintRect( aRect );
2012 			aRegion.EndEnumRects( hHdl );
2013 		}
2014 		else if ( SfxProgress::GetActiveProgress( GetDoc()->GetDocShell() ) &&
2015 				  GetOut() == GetWin() )
2016 		{
2017 			// #i68597#
2018 			const Region aDLRegion(rRect);
2019 			DLPrePaint2(aDLRegion);
2020 
2021 			// OD 2004-04-23 #116347#
2022             pOut->Push( PUSH_FILLCOLOR|PUSH_LINECOLOR );
2023 			pOut->SetFillColor( Imp()->GetRetoucheColor() );
2024             pOut->SetLineColor();
2025 			pOut->DrawRect( rRect );
2026 			pOut->Pop();
2027 
2028 			// #i68597#
2029 			DLPostPaint2(true);
2030 		}
2031 	}
2032 }
2033 
2034 /******************************************************************************
2035 |*
2036 |*	ViewShell::SetBrowseBorder()
2037 |*
2038 |*	Ersterstellung		AMA 20. Aug. 96
2039 |*	Letzte Aenderung	AMA 20. Aug. 96
2040 |*
2041 ******************************************************************************/
2042 
2043 void ViewShell::SetBrowseBorder( const Size& rNew )
2044 {
2045 	if( rNew != aBrowseBorder )
2046 	{
2047 		aBrowseBorder = rNew;
2048 		if ( aVisArea.HasArea() )
2049 			CheckBrowseView( sal_False );
2050 	}
2051 }
2052 
2053 const Size& ViewShell::GetBrowseBorder() const
2054 {
2055 	return aBrowseBorder;
2056 }
2057 
2058 sal_Int32 ViewShell::GetBrowseWidth() const
2059 {
2060     const SwPostItMgr* pPostItMgr = GetPostItMgr();
2061 	if ( pPostItMgr && pPostItMgr->HasNotes() && pPostItMgr->ShowNotes() )
2062 	{
2063 		Size aBorder( aBrowseBorder );
2064 		aBorder.Width() += aBrowseBorder.Width();
2065 		aBorder.Width() += pPostItMgr->GetSidebarWidth(true) + pPostItMgr->GetSidebarBorderWidth(true);
2066 		return aVisArea.Width() - GetOut()->PixelToLogic(aBorder).Width();
2067 	}
2068 	else
2069 		return aVisArea.Width() - 2 * GetOut()->PixelToLogic(aBrowseBorder).Width();
2070 }
2071 
2072 /******************************************************************************
2073 |*
2074 |*	ViewShell::CheckBrowseView()
2075 |*
2076 |*	Ersterstellung		MA 04. Mar. 96
2077 |*	Letzte Aenderung	MA 04. Jul. 96
2078 |*
2079 ******************************************************************************/
2080 
2081 void ViewShell::CheckBrowseView( sal_Bool bBrowseChgd )
2082 {
2083     if ( !bBrowseChgd && !GetViewOptions()->getBrowseMode() )
2084 		return;
2085 
2086 	SET_CURR_SHELL( this );
2087 
2088 	ASSERT( GetLayout(), "Layout not ready" );
2089 
2090 	// Wenn das Layout noch nicht einmal eine Hoehe hat,
2091 	// ist sowieso nichts formatiert.
2092 	// Dann eruebrigt sich die Invalidierung
2093 	// Falsch, z.B. beim Anlegen einer neuen View wird der Inhalt eingef?gt
2094 	// und formatiert (trotz einer leeren VisArea). Hier muessen deshalb
2095 	// die Seiten zur Formatierung angeregt werden.
2096 	if( !GetLayout()->Frm().Height() )
2097 	{
2098 		SwFrm* pPage = GetLayout()->Lower();
2099 		while( pPage )
2100 		{
2101 			pPage->_InvalidateSize();
2102 			pPage = pPage->GetNext();
2103 		}
2104 		return;
2105 	}
2106 
2107     LockPaint();
2108 	StartAction();
2109 
2110 	SwPageFrm *pPg = (SwPageFrm*)GetLayout()->Lower();
2111 	do
2112 	{	pPg->InvalidateSize();
2113 		pPg->_InvalidatePrt();
2114 		pPg->InvaPercentLowers();
2115 		if ( bBrowseChgd )
2116 		{
2117 			pPg->PrepareHeader();
2118 			pPg->PrepareFooter();
2119 		}
2120 		pPg = (SwPageFrm*)pPg->GetNext();
2121 	} while ( pPg );
2122 
2123 	// Wenn sich die Groessenverhaeltnise im BrowseModus aendern,
2124 	// muss die Position und PrtArea der Cntnt- und Tab-Frames invalidiert werden.
2125 	sal_uInt8 nInv = INV_PRTAREA | INV_TABLE | INV_POS;
2126 	// Beim BrowseModus-Wechsel benoetigen die CntntFrms
2127 	// wg. der Drucker/Bildschirmformatierung eine Size-Invalidierung
2128 	if( bBrowseChgd )
2129         nInv |= INV_SIZE | INV_DIRECTION;
2130 
2131 	GetLayout()->InvalidateAllCntnt( nInv );
2132 
2133 	SwFrm::CheckPageDescs( (SwPageFrm*)GetLayout()->Lower() );
2134 
2135 	EndAction();
2136 	UnlockPaint();
2137 }
2138 
2139 /*************************************************************************
2140 |*
2141 |* 	  ViewShell::GetLayout()
2142 |*	  ViewShell::GetNodes()
2143 |*
2144 |*	  Ersterstellung	OK 26. May. 92
2145 |*	  Letzte Aenderung	MA 16. Sep. 93
2146 |*
2147 *************************************************************************/
2148 
2149 SwRootFrm *ViewShell::GetLayout() const
2150 {
2151 	return pLayout.get();	//swmod 080116
2152 }
2153 /***********************************************************************/
2154 
2155 OutputDevice& ViewShell::GetRefDev() const
2156 {
2157     OutputDevice* pTmpOut = 0;
2158     if (  GetWin() &&
2159           GetViewOptions()->getBrowseMode() &&
2160          !GetViewOptions()->IsPrtFormat() )
2161         pTmpOut = GetWin();
2162     else if ( 0 != mpTmpRef )
2163         pTmpOut = mpTmpRef;
2164     else
2165         pTmpOut = GetDoc()->getReferenceDevice( true );
2166 
2167     return *pTmpOut;
2168 }
2169 
2170 const SwNodes& ViewShell::GetNodes() const
2171 {
2172     return pDoc->GetNodes();
2173 }
2174 
2175 
2176 void ViewShell::DrawSelChanged()
2177 {
2178 }
2179 
2180 
2181 Size ViewShell::GetDocSize() const
2182 {
2183 	Size aSz;
2184 	const SwRootFrm* pRoot = GetLayout();
2185 	if( pRoot )
2186 		aSz = pRoot->Frm().SSize();
2187 
2188 	return aSz;
2189 }
2190 
2191 
2192 SfxItemPool& ViewShell::GetAttrPool()
2193 {
2194 	return GetDoc()->GetAttrPool();
2195 }
2196 
2197 /******************************************************************************
2198 |*
2199 |*	ViewShell::ApplyViewOptions(), ImplApplyViewOptions()
2200 |*
2201 |*	Ersterstellung		??
2202 |*	Letzte Aenderung	MA 03. Mar. 98
2203 |*
2204 ******************************************************************************/
2205 
2206 void ViewShell::ApplyViewOptions( const SwViewOption &rOpt )
2207 {
2208 
2209 	ViewShell *pSh = this;
2210 	do
2211 	{	pSh->StartAction();
2212 		pSh = (ViewShell*)pSh->GetNext();
2213 	} while ( pSh != this );
2214 
2215 	ImplApplyViewOptions( rOpt );
2216 
2217     // swmod 080115
2218 	// With one layout per view it is not longer necessary
2219     // to sync these "layout related" view options
2220     // But as long as we have to disable "multiple layout"
2221 	pSh = (ViewShell*)this->GetNext();
2222 	while ( pSh != this )
2223 	{
2224 		SwViewOption aOpt( *pSh->GetViewOptions() );
2225 		aOpt.SetFldName( rOpt.IsFldName() );
2226         	aOpt.SetShowHiddenField( rOpt.IsShowHiddenField() );
2227 		aOpt.SetShowHiddenPara( rOpt.IsShowHiddenPara() );
2228         	aOpt.SetShowHiddenChar( rOpt.IsShowHiddenChar() );
2229         	aOpt.SetViewLayoutBookMode( rOpt.IsViewLayoutBookMode() );
2230         	aOpt.SetViewLayoutColumns( rOpt.GetViewLayoutColumns() );
2231 		aOpt.SetPostIts(rOpt.IsPostIts());
2232 		if ( !(aOpt == *pSh->GetViewOptions()) )
2233 			pSh->ImplApplyViewOptions( aOpt );
2234 		pSh = (ViewShell*)pSh->GetNext();
2235 	}
2236     // End of disabled multiple window
2237 
2238 	pSh = this;
2239 	do
2240 	{	pSh->EndAction();
2241 		pSh = (ViewShell*)pSh->GetNext();
2242 	} while ( pSh != this );
2243 
2244 }
2245 
2246 void ViewShell::ImplApplyViewOptions( const SwViewOption &rOpt )
2247 {
2248     if (*pOpt == rOpt)
2249         return;
2250 
2251     Window *pMyWin = GetWin();
2252     if( !pMyWin )
2253 	{
2254         ASSERT( pMyWin, "ViewShell::ApplyViewOptions: no window" );
2255 		return;
2256 	}
2257 
2258 	SET_CURR_SHELL( this );
2259 
2260 	sal_Bool bReformat	 = sal_False;
2261 
2262     if( pOpt->IsShowHiddenField() != rOpt.IsShowHiddenField() )
2263 	{
2264 		((SwHiddenTxtFieldType*)pDoc->GetSysFldType( RES_HIDDENTXTFLD ))->
2265                                             SetHiddenFlag( !rOpt.IsShowHiddenField() );
2266 		bReformat = sal_True;
2267 	}
2268     if ( pOpt->IsShowHiddenPara() != rOpt.IsShowHiddenPara() )
2269 	{
2270 		SwHiddenParaFieldType* pFldType = (SwHiddenParaFieldType*)GetDoc()->
2271 										  GetSysFldType(RES_HIDDENPARAFLD);
2272 		if( pFldType && pFldType->GetDepends() )
2273 		{
2274 			SwMsgPoolItem aHnt( RES_HIDDENPARA_PRINT );
2275 			pFldType->ModifyNotification( &aHnt, 0);
2276 		}
2277 		bReformat = sal_True;
2278 	}
2279     if ( !bReformat && pOpt->IsShowHiddenChar() != rOpt.IsShowHiddenChar() )
2280     {
2281         bReformat = GetDoc()->ContainsHiddenChars();
2282     }
2283 
2284 	// bReformat wird sal_True, wenn ...
2285 	// - Feldnamen anzeigen oder nicht ...
2286 	// ( - SwEndPortion muessen _nicht_ mehr generiert werden. )
2287 	// - Das Window ist natuerlich was ganz anderes als der Drucker...
2288     bReformat = bReformat || pOpt->IsFldName() != rOpt.IsFldName();
2289 
2290 	// Der Mapmode wird veraendert, Minima/Maxima werden von der UI beachtet
2291 	if( pOpt->GetZoom() != rOpt.GetZoom() && !IsPreView() )
2292 	{
2293         MapMode aMode( pMyWin->GetMapMode() );
2294 		Fraction aNewFactor( rOpt.GetZoom(), 100 );
2295 		aMode.SetScaleX( aNewFactor );
2296 		aMode.SetScaleY( aNewFactor );
2297         pMyWin->SetMapMode( aMode );
2298 		// Wenn kein ReferenzDevice (Drucker) zum Formatieren benutzt wird,
2299 		// sondern der Bildschirm, muss bei Zoomfaktoraenderung neu formatiert
2300 		// werden.
2301         if( pOpt->getBrowseMode() )
2302 			bReformat = sal_True;
2303     }
2304 
2305     bool bBrowseModeChanged = false;
2306     if( pOpt->getBrowseMode() != rOpt.getBrowseMode() )
2307     {
2308         bBrowseModeChanged = true;
2309         bReformat = sal_True;
2310     }
2311     else if( pOpt->getBrowseMode() && pOpt->IsPrtFormat() != rOpt.IsPrtFormat() )
2312         bReformat = sal_True;
2313 
2314 	if ( HasDrawView() || rOpt.IsGridVisible() )
2315 	{
2316 		if ( !HasDrawView() )
2317 			MakeDrawView();
2318 
2319 		SwDrawView *pDView = Imp()->GetDrawView();
2320 		if ( pDView->IsDragStripes() != rOpt.IsCrossHair() )
2321 			pDView->SetDragStripes( rOpt.IsCrossHair() );
2322 
2323 		if ( pDView->IsGridSnap() != rOpt.IsSnap() )
2324 			pDView->SetGridSnap( rOpt.IsSnap() );
2325 
2326 		if ( pDView->IsGridVisible() != rOpt.IsGridVisible() )
2327 			pDView->SetGridVisible( rOpt.IsGridVisible() );
2328 
2329 		const Size &rSz = rOpt.GetSnapSize();
2330 		pDView->SetGridCoarse( rSz );
2331 
2332 		const Size aFSize
2333 			( rSz.Width() ? rSz.Width() / (rOpt.GetDivisionX()+1) : 0,
2334 			  rSz.Height()? rSz.Height()/ (rOpt.GetDivisionY()+1) : 0);
2335 		pDView->SetGridFine( aFSize );
2336 		Fraction aSnGrWdtX(rSz.Width(), rOpt.GetDivisionX() + 1);
2337 		Fraction aSnGrWdtY(rSz.Height(), rOpt.GetDivisionY() + 1);
2338 		pDView->SetSnapGridWidth( aSnGrWdtX, aSnGrWdtY );
2339 
2340 		if ( pOpt->IsSolidMarkHdl() != rOpt.IsSolidMarkHdl() )
2341 			pDView->SetSolidMarkHdl( rOpt.IsSolidMarkHdl() );
2342 
2343 			// it's a JOE interface !
2344 		if ( pOpt->IsBigMarkHdl() != rOpt.IsBigMarkHdl() )
2345 			pDView->SetMarkHdlSizePixel(rOpt.IsBigMarkHdl() ? 9 : 7);
2346 	}
2347 
2348 	sal_Bool bOnlineSpellChgd = pOpt->IsOnlineSpell() != rOpt.IsOnlineSpell();
2349 
2350 	*pOpt = rOpt;	// Erst jetzt werden die Options uebernommen.
2351 	pOpt->SetUIOptions(rOpt);
2352 
2353 	pDoc->set(IDocumentSettingAccess::HTML_MODE, 0 != ::GetHtmlMode(pDoc->GetDocShell()));
2354 
2355     if( bBrowseModeChanged )
2356     {
2357         // --> FME 2005-03-16 #i44963# Good occasion to check if page sizes in
2358         // page descriptions are still set to (LONG_MAX, LONG_MAX) (html import)
2359         pDoc->CheckDefaultPageFmt();
2360         // <--
2361         CheckBrowseView( sal_True );
2362     }
2363 
2364     pMyWin->Invalidate();
2365 	if ( bReformat )
2366 	{
2367 		// Es hilft alles nichts, wir muessen an alle CntntFrms ein
2368 		// Prepare verschicken, wir formatieren neu:
2369 		StartAction();
2370 		Reformat();
2371 		EndAction();
2372 	}
2373 
2374 	if( bOnlineSpellChgd )
2375 	{
2376 		ViewShell *pSh = (ViewShell*)this->GetNext();
2377 		sal_Bool bOnlineSpl = rOpt.IsOnlineSpell();
2378 		while( pSh != this )
2379 		{	pSh->pOpt->SetOnlineSpell( bOnlineSpl );
2380 			Window *pTmpWin = pSh->GetWin();
2381 			if( pTmpWin )
2382 				pTmpWin->Invalidate();
2383 			pSh = (ViewShell*)pSh->GetNext();
2384 		}
2385 	}
2386 
2387 }
2388 
2389 /******************************************************************************
2390 |*
2391 |*	ViewShell::SetUIOptions()
2392 |*
2393 |*	Ersterstellung		OS 29.07.96
2394 |*	Letzte Aenderung	OS 29.07.96
2395 |*
2396 ******************************************************************************/
2397 
2398 void ViewShell::SetUIOptions( const SwViewOption &rOpt )
2399 {
2400 	pOpt->SetUIOptions(rOpt);
2401 	//the API-Flag of the view options is set but never reset
2402 	//it is required to set scroll bars in readonly documents
2403 	if(rOpt.IsStarOneSetting())
2404 		pOpt->SetStarOneSetting(sal_True);
2405 
2406 	pOpt->SetSymbolFont(rOpt.GetSymbolFont());
2407 }
2408 
2409 /******************************************************************************
2410 |*
2411 |*	ViewShell::SetReadonly()
2412 |*
2413 |*	Ersterstellung		OS 05.09.96
2414 |*	Letzte Aenderung	MA 12. Feb. 97
2415 |*
2416 ******************************************************************************/
2417 
2418 void ViewShell::SetReadonlyOption(sal_Bool bSet)
2419 {
2420 	//JP 01.02.99: bei ReadOnly Flag richtig abfragen und ggfs. neu
2421 	//				formatieren; Bug 61335
2422 
2423 	// Schalten wir gerade von Readonly auf Bearbeiten um?
2424 	if( bSet != pOpt->IsReadonly() )
2425 	{
2426 		// damit die Flags richtig erfragt werden koennen.
2427 		pOpt->SetReadonly( sal_False );
2428 
2429 		sal_Bool bReformat = pOpt->IsFldName();
2430 
2431 		pOpt->SetReadonly( bSet );
2432 
2433 		if( bReformat )
2434 		{
2435 			StartAction();
2436 			Reformat();
2437 			if ( GetWin() )
2438 				GetWin()->Invalidate();
2439 			EndAction();
2440 		}
2441 		else if ( GetWin() )
2442 			GetWin()->Invalidate();
2443 		if( Imp()->IsAccessible() )
2444 			Imp()->InvalidateAccessibleEditableState( sal_False );
2445 	}
2446 }
2447 /* -----------------28.08.2003 15:45-----------------
2448 
2449  --------------------------------------------------*/
2450 void  ViewShell::SetPDFExportOption(sal_Bool bSet)
2451 {
2452     if( bSet != pOpt->IsPDFExport() )
2453     {
2454         if( bSet && pOpt->getBrowseMode() )
2455             pOpt->SetPrtFormat( sal_True );
2456         pOpt->SetPDFExport(bSet);
2457     }
2458 }
2459 /* -----------------------------2002/07/31 17:06------------------------------
2460 
2461  ---------------------------------------------------------------------------*/
2462 void  ViewShell::SetReadonlySelectionOption(sal_Bool bSet)
2463 {
2464     if( bSet != pOpt->IsSelectionInReadonly() )
2465     {
2466         pOpt->SetSelectionInReadonly(bSet);
2467     }
2468 }
2469 /******************************************************************************
2470 |*
2471 |*	ViewShell::SetPrtFormatOption()
2472 |*
2473 |*	Ersterstellung		AMA 10. Sep. 97
2474 |*	Letzte Aenderung	AMA 10. Sep. 97
2475 |*
2476 ******************************************************************************/
2477 
2478 void ViewShell::SetPrtFormatOption( sal_Bool bSet )
2479 {
2480 	pOpt->SetPrtFormat( bSet );
2481 }
2482 
2483 /******************************************************************************
2484 |*
2485 |*	ViewShell::UISizeNotify()
2486 |*
2487 |*	Ersterstellung		MA 14. Jan. 97
2488 |*	Letzte Aenderung	MA 14. Jan. 97
2489 |*
2490 ******************************************************************************/
2491 
2492 
2493 void ViewShell::UISizeNotify()
2494 {
2495 	if ( bDocSizeChgd )
2496 	{
2497 		bDocSizeChgd = sal_False;
2498 		sal_Bool bOld = bInSizeNotify;
2499 		bInSizeNotify = sal_True;
2500 		::SizeNotify( this, GetDocSize() );
2501 		bInSizeNotify = bOld;
2502 	}
2503 }
2504 
2505 
2506 void    ViewShell::SetRestoreActions(sal_uInt16 nSet)
2507 {
2508 	DBG_ASSERT(!GetRestoreActions()||!nSet, "mehrfaches Restore der Actions ?");
2509 	Imp()->SetRestoreActions(nSet);
2510 }
2511 sal_uInt16 	ViewShell::GetRestoreActions() const
2512 {
2513 	return Imp()->GetRestoreActions();
2514 }
2515 
2516 sal_Bool ViewShell::IsNewLayout() const
2517 {
2518 	return GetLayout()->IsNewLayout();
2519 }
2520 
2521 uno::Reference< ::com::sun::star::accessibility::XAccessible > ViewShell::CreateAccessible()
2522 {
2523     uno::Reference< ::com::sun::star::accessibility::XAccessible > xAcc;
2524 
2525 	// We require a layout and an XModel to be accessible.
2526     ASSERT( pLayout, "no layout, no access" );
2527 	ASSERT( GetWin(), "no window, no access" );
2528 
2529 	if( pDoc->GetCurrentViewShell() && GetWin() )	//swmod 071108
2530 		xAcc = Imp()->GetAccessibleMap().GetDocumentView();
2531 
2532 	return xAcc;
2533 }
2534 
2535 uno::Reference< ::com::sun::star::accessibility::XAccessible >
2536 ViewShell::CreateAccessiblePreview()
2537 {
2538     DBG_ASSERT( IsPreView(),
2539                 "Can't create accessible preview for non-preview ViewShell" );
2540 
2541 	// We require a layout and an XModel to be accessible.
2542 	ASSERT( pLayout, "no layout, no access" );
2543 	ASSERT( GetWin(), "no window, no access" );
2544 
2545     // OD 15.01.2003 #103492# - add condition <IsPreView()>
2546     if ( IsPreView() && GetLayout()&& GetWin() )
2547     {
2548         // OD 14.01.2003 #103492# - adjustment for new method signature
2549         return Imp()->GetAccessibleMap().GetDocumentPreview(
2550                     PagePreviewLayout()->maPrevwPages,
2551                     GetWin()->GetMapMode().GetScaleX(),
2552                     GetLayout()->GetPageByPageNum( PagePreviewLayout()->mnSelectedPageNum ),
2553                     PagePreviewLayout()->maWinSize );	//swmod 080305
2554     }
2555 	return NULL;
2556 }
2557 
2558 void ViewShell::InvalidateAccessibleFocus()
2559 {
2560 	if( Imp()->IsAccessible() )
2561 		Imp()->GetAccessibleMap().InvalidateFocus();
2562 }
2563 
2564 /** invalidate CONTENT_FLOWS_FROM/_TO relation for paragraphs
2565 
2566     OD 2005-12-01 #i27138#
2567 
2568     @author OD
2569 */
2570 void ViewShell::InvalidateAccessibleParaFlowRelation( const SwTxtFrm* _pFromTxtFrm,
2571                                                       const SwTxtFrm* _pToTxtFrm )
2572 {
2573     if ( GetLayout() && GetLayout()->IsAnyShellAccessible() )
2574     {
2575         Imp()->_InvalidateAccessibleParaFlowRelation( _pFromTxtFrm, _pToTxtFrm );
2576     }
2577 }
2578 
2579 /** invalidate text selection for paragraphs
2580 
2581     OD 2005-12-12 #i27301#
2582 
2583     @author OD
2584 */
2585 void ViewShell::InvalidateAccessibleParaTextSelection()
2586 {
2587     if ( GetLayout() && GetLayout()->IsAnyShellAccessible() )
2588     {
2589         Imp()->_InvalidateAccessibleParaTextSelection();
2590     }
2591 }
2592 
2593 /** invalidate attributes for paragraphs
2594 
2595     OD 2009-01-06 #i88069#
2596 
2597     @author OD
2598 */
2599 void ViewShell::InvalidateAccessibleParaAttrs( const SwTxtFrm& rTxtFrm )
2600 {
2601     if ( GetLayout() && GetLayout()->IsAnyShellAccessible() )
2602     {
2603         Imp()->_InvalidateAccessibleParaAttrs( rTxtFrm );
2604     }
2605 }
2606 
2607 SwAccessibleMap* ViewShell::GetAccessibleMap()
2608 {
2609     if ( Imp()->IsAccessible() )
2610     {
2611         return &(Imp()->GetAccessibleMap());
2612     }
2613 
2614     return 0;
2615 }
2616 /* -----------------------------06.05.2002 13:23------------------------------
2617 
2618  ---------------------------------------------------------------------------*/
2619 void ViewShell::ApplyAccessiblityOptions(SvtAccessibilityOptions& rAccessibilityOptions)
2620 {
2621     if(pOpt->IsPagePreview() && !rAccessibilityOptions.GetIsForPagePreviews())
2622     {
2623         pAccOptions->SetAlwaysAutoColor(sal_False);
2624         pAccOptions->SetStopAnimatedGraphics(sal_False);
2625         pAccOptions->SetStopAnimatedText(sal_False);
2626     }
2627     else
2628     {
2629         pAccOptions->SetAlwaysAutoColor(rAccessibilityOptions.GetIsAutomaticFontColor());
2630         pAccOptions->SetStopAnimatedGraphics(! rAccessibilityOptions.GetIsAllowAnimatedGraphics());
2631         pAccOptions->SetStopAnimatedText(! rAccessibilityOptions.GetIsAllowAnimatedText());
2632 
2633         // --> FME 2004-06-29 #114856# Formular view
2634         // Always set this option, not only if document is read-only:
2635         pOpt->SetSelectionInReadonly(rAccessibilityOptions.IsSelectionInReadonly());
2636     }
2637 }
2638 
2639 ShellResource* ViewShell::GetShellRes()
2640 {
2641 	return pShellRes;
2642 }
2643 
2644 void ViewShell::SetCareWin( Window* pNew )
2645 {
2646 	pCareWindow = pNew;
2647 }
2648 
2649 sal_uInt16 ViewShell::GetPageCount() const
2650 {
2651     return GetLayout() ? GetLayout()->GetPageNum() : 1;
2652 }
2653 
2654 const Size ViewShell::GetPageSize( sal_uInt16 nPageNum, bool bSkipEmptyPages ) const
2655 {
2656     Size aSize;
2657 	const SwRootFrm* pTmpRoot = GetLayout();
2658     if( pTmpRoot && nPageNum )
2659     {
2660         const SwPageFrm* pPage = static_cast<const SwPageFrm*>
2661                                  (pTmpRoot->Lower());
2662 
2663         while( --nPageNum && pPage->GetNext() )
2664             pPage = static_cast<const SwPageFrm*>( pPage->GetNext() );
2665 
2666         if( !bSkipEmptyPages && pPage->IsEmptyPage() && pPage->GetNext() )
2667             pPage = static_cast<const SwPageFrm*>( pPage->GetNext() );
2668 
2669         aSize = pPage->Frm().SSize();
2670     }
2671     return aSize;
2672 }
2673 
2674 // --> FME 2004-06-15 #i12836# enhanced pdf export
2675 sal_Int32 ViewShell::GetPageNumAndSetOffsetForPDF( OutputDevice& rOut, const SwRect& rRect ) const
2676 {
2677     ASSERT( GetLayout(), "GetPageNumAndSetOffsetForPDF assumes presence of layout" )
2678 
2679     sal_Int32 nRet = -1;
2680 
2681     // --> FME 2005-01-07 #i40059# Position out of bounds:
2682     SwRect aRect( rRect );
2683     aRect.Pos().X() = Max( aRect.Left(), GetLayout()->Frm().Left() );
2684     // <--
2685 
2686     const SwPageFrm* pPage = GetLayout()->GetPageAtPos( aRect.Center() );
2687     if ( pPage )
2688     {
2689         ASSERT( pPage, "GetPageNumAndSetOffsetForPDF: No page found" )
2690 
2691         Point aOffset( pPage->Frm().Pos() );
2692         aOffset.X() = -aOffset.X();
2693         aOffset.Y() = -aOffset.Y();
2694 
2695         MapMode aMapMode( rOut.GetMapMode() );
2696         aMapMode.SetOrigin( aOffset );
2697         rOut.SetMapMode( aMapMode );
2698 
2699         nRet = pPage->GetPhyPageNum() - 1;
2700     }
2701 
2702     return nRet;
2703 }
2704 // <--
2705 
2706 // --> PB 2007-05-30 #146850#
2707 const BitmapEx& ViewShell::GetReplacementBitmap( bool bIsErrorState )
2708 {
2709     BitmapEx** ppRet;
2710     sal_uInt16 nResId = 0, nHCResId = 0;
2711     if( bIsErrorState )
2712     {
2713         ppRet = &pErrorBmp;
2714         nResId = RID_GRAPHIC_ERRORBMP;
2715         nHCResId = RID_GRAPHIC_ERRORBMP_HC;
2716     }
2717     else
2718     {
2719         ppRet = &pReplaceBmp;
2720         nResId = RID_GRAPHIC_REPLACEBMP;
2721         nHCResId = RID_GRAPHIC_REPLACEBMP_HC;
2722     }
2723 
2724     if( !*ppRet )
2725     {
2726         sal_uInt16 nBmpResId =
2727             Application::GetSettings().GetStyleSettings().GetHighContrastMode()
2728                 ? nHCResId : nResId;
2729         *ppRet = new BitmapEx( SW_RES( nBmpResId ) );
2730     }
2731     return **ppRet;
2732 }
2733 
2734 void ViewShell::DeleteReplacementBitmaps()
2735 {
2736     DELETEZ( pErrorBmp );
2737     DELETEZ( pReplaceBmp );
2738 }
2739 // <--
2740 
2741 SwPostItMgr* ViewShell::GetPostItMgr()
2742 {
2743     SwView* pView =  GetDoc()->GetDocShell() ? GetDoc()->GetDocShell()->GetView() : 0;
2744     if ( pView )
2745         return pView->GetPostItMgr();
2746 
2747     return 0;
2748 }
2749 
2750 /*
2751  * Document Interface Access
2752  */
2753 const IDocumentSettingAccess* ViewShell::getIDocumentSettingAccess() const { return pDoc; }
2754 IDocumentSettingAccess* ViewShell::getIDocumentSettingAccess() { return pDoc; }
2755 const IDocumentDeviceAccess* ViewShell::getIDocumentDeviceAccess() const { return pDoc; }
2756 IDocumentDeviceAccess* ViewShell::getIDocumentDeviceAccess() { return pDoc; }
2757 const IDocumentMarkAccess* ViewShell::getIDocumentMarkAccess() const { return pDoc->getIDocumentMarkAccess(); }
2758 IDocumentMarkAccess* ViewShell::getIDocumentMarkAccess() { return pDoc->getIDocumentMarkAccess(); }
2759 const IDocumentDrawModelAccess* ViewShell::getIDocumentDrawModelAccess() const { return pDoc; }
2760 IDocumentDrawModelAccess* ViewShell::getIDocumentDrawModelAccess() { return pDoc; }
2761 const IDocumentRedlineAccess* ViewShell::getIDocumentRedlineAccess() const { return pDoc; }
2762 IDocumentRedlineAccess* ViewShell::getIDocumentRedlineAccess() { return pDoc; }
2763 const IDocumentLayoutAccess* ViewShell::getIDocumentLayoutAccess() const { return pDoc; }
2764 IDocumentLayoutAccess* ViewShell::getIDocumentLayoutAccess() { return pDoc; }
2765 const IDocumentFieldsAccess* ViewShell::getIDocumentFieldsAccess() const { return pDoc; }
2766 IDocumentContentOperations* ViewShell::getIDocumentContentOperations() { return pDoc; }
2767 IDocumentStylePoolAccess* ViewShell::getIDocumentStylePoolAccess() { return pDoc; }
2768 const IDocumentStatistics* ViewShell::getIDocumentStatistics() const { return pDoc; }
2769 
2770 IDocumentUndoRedo      & ViewShell::GetIDocumentUndoRedo()
2771 { return pDoc->GetIDocumentUndoRedo(); }
2772 IDocumentUndoRedo const& ViewShell::GetIDocumentUndoRedo() const
2773 { return pDoc->GetIDocumentUndoRedo(); }
2774 
2775 // --> OD 2007-11-14 #i83479#
2776 const IDocumentListItems* ViewShell::getIDocumentListItemsAccess() const
2777 {
2778     return pDoc;
2779 }
2780 const IDocumentOutlineNodes* ViewShell::getIDocumentOutlineNodesAccess() const
2781 {
2782     return pDoc;
2783 }
2784 // <--
2785