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