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