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