xref: /trunk/main/sw/source/ui/uiview/viewport.cxx (revision ffd38472365e95f6a578737bc9a5eb0fac624a86)
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 #include "hintids.hxx"
26 #include <vcl/help.hxx>
27 #include <svx/ruler.hxx>
28 #include <editeng/paperinf.hxx>
29 #include <editeng/lrspitem.hxx>
30 #include <sfx2/bindings.hxx>
31 #ifndef _VIEW_HXX
32 #include <view.hxx>
33 #endif
34 #include <wrtsh.hxx>
35 #include <swmodule.hxx>
36 #include <viewopt.hxx>
37 #include <frmatr.hxx>
38 #ifndef _DOCSH_HXX
39 #include <docsh.hxx>
40 #endif
41 #ifndef _CMDID_H
42 #include <cmdid.h>
43 #endif
44 #include <edtwin.hxx>
45 #include <scroll.hxx>
46 #ifndef _WVIEW_HXX
47 #include <wview.hxx>
48 #endif
49 #include <usrpref.hxx>
50 #include <pagedesc.hxx>
51 #include <workctrl.hxx>
52 #include <crsskip.hxx>
53 
54 #include <PostItMgr.hxx>
55 
56 #include <IDocumentSettingAccess.hxx>
57 
58 //Das SetVisArea der DocShell darf nicht vom InnerResizePixel gerufen werden.
59 //Unsere Einstellungen muessen aber stattfinden.
60 #ifndef WB_RIGHT_ALIGNED
61 #define WB_RIGHT_ALIGNED    ((WinBits)0x00008000)
62 #endif
63 
64 static sal_Bool bProtectDocShellVisArea = sal_False;
65 
66 static sal_uInt16 nPgNum = 0;
67 
68 sal_Bool SwView::IsDocumentBorder()
69 {
70     return GetDocShell()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ||
71            pWrtShell->GetViewOptions()->getBrowseMode() ||
72            SVX_ZOOM_PAGEWIDTH_NOBORDER == (SvxZoomType)pWrtShell->GetViewOptions()->GetZoomType();
73 }
74 
75 inline long GetLeftMargin( SwView &rView )
76 {
77     SvxZoomType eType = (SvxZoomType)rView.GetWrtShell().GetViewOptions()->GetZoomType();
78     long lRet = rView.GetWrtShell().GetAnyCurRect(RECT_PAGE_PRT).Left();
79     return eType == SVX_ZOOM_PERCENT   ? lRet + DOCUMENTBORDER :
80            eType == SVX_ZOOM_PAGEWIDTH || eType == SVX_ZOOM_PAGEWIDTH_NOBORDER ? 0 :
81                                          lRet + DOCUMENTBORDER + nLeftOfst;
82 }
83 
84 //-------------------------------------------------------------------------
85 
86 void lcl_GetPos(SwView* pView,
87                 Point& rPos,
88                 SwScrollbar* pScrollbar,
89                 sal_Bool bBorder)
90 {
91     SwWrtShell &rSh = pView->GetWrtShell();
92     const Size aDocSz( rSh.GetDocSize() );
93 
94     const long lBorder = bBorder ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
95     sal_Bool bHori = pScrollbar->IsHoriScroll();
96 
97     const long lPos = pScrollbar->GetThumbPos() + (bBorder ? DOCUMENTBORDER : 0);
98     long Point:: *pPt = bHori ? &Point::nA : &Point::nB;
99     long Size::  *pSz = bHori ? &Size::nA  : &Size::nB;
100 
101     long lDelta = lPos - rSh.VisArea().Pos().*pPt;
102     const long lSize = aDocSz.*pSz + lBorder;
103     // Bug 11693: sollte rechts oder unten zuviel Wiese sein, dann muss
104     //            diese von der VisArea herausgerechnet werden!
105     long nTmp = pView->GetVisArea().Right()+lDelta;
106     if ( bHori && nTmp > lSize )
107         lDelta -= nTmp - lSize;
108     nTmp = pView->GetVisArea().Bottom()+lDelta;
109     if ( !bHori && nTmp > lSize )
110         lDelta -= nTmp - lSize;
111 
112     rPos.*pPt += lDelta;
113     if ( bBorder && rPos.*pPt < DOCUMENTBORDER )
114         rPos.*pPt = DOCUMENTBORDER;
115 }
116 
117 /*--------------------------------------------------------------------
118     Beschreibung:   Nullpunkt Ruler setzen
119  --------------------------------------------------------------------*/
120 
121 void SwView::InvalidateRulerPos()
122 {
123     static sal_uInt16 __READONLY_DATA aInval[] =
124     {
125         SID_ATTR_PARA_LRSPACE, SID_RULER_BORDERS, SID_RULER_PAGE_POS,
126         SID_RULER_LR_MIN_MAX, SID_ATTR_LONG_ULSPACE, SID_ATTR_LONG_LRSPACE,
127         SID_RULER_BORDER_DISTANCE,
128         SID_ATTR_PARA_LRSPACE_VERTICAL, SID_RULER_BORDERS_VERTICAL,
129         SID_RULER_TEXT_RIGHT_TO_LEFT,
130         SID_RULER_ROWS, SID_RULER_ROWS_VERTICAL, FN_STAT_PAGE,
131         0
132     };
133 
134     GetViewFrame()->GetBindings().Invalidate(aInval);
135 
136     DBG_ASSERT(pHRuler, "Why is there no Ruler?");
137     pHRuler->ForceUpdate();
138     pVRuler->ForceUpdate();
139 }
140 
141 /*--------------------------------------------------------------------
142     Beschreibung:   begrenzt das Scrollen soweit, dass jeweils nur einen
143                     viertel Bildschirm bis vor das Ende des Dokumentes
144                     gescrollt werden kann.
145  --------------------------------------------------------------------*/
146 
147 long SwView::SetHScrollMax( long lMax )
148 {
149     const long lBorder = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
150     const long lSize = GetDocSz().Width() + lBorder - aVisArea.GetWidth();
151 
152     // bei negativen Werten ist das Dokument vollstaendig sichtbar;
153     // in diesem Fall kein Scrollen
154     return Max( Min( lMax, lSize ), 0L );
155 }
156 
157 
158 long SwView::SetVScrollMax( long lMax )
159 {
160     const long lBorder = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
161     long lSize = GetDocSz().Height() + lBorder - aVisArea.GetHeight();
162     return Max( Min( lMax, lSize), 0L );        // siehe horz.
163 }
164 
165 
166 Point SwView::AlignToPixel(const Point &rPt) const
167 {
168     return GetEditWin().PixelToLogic( GetEditWin().LogicToPixel( rPt ) );
169 }
170 
171 /*--------------------------------------------------------------------
172     Beschreibung:   Dokumentgroesse hat sich geaendert
173  --------------------------------------------------------------------*/
174 
175 void SwView::DocSzChgd(const Size &rSz)
176 {
177 
178 extern int bDocSzUpdated;
179 
180 
181 aDocSz = rSz;
182 
183     if( !pWrtShell || aVisArea.IsEmpty() )      // keine Shell -> keine Aenderung
184     {
185         bDocSzUpdated = sal_False;
186         return;
187     }
188 
189     //Wenn Text geloescht worden ist, kann es sein, dass die VisArea hinter
190     //den sichtbaren Bereich verweist
191     Rectangle aNewVisArea( aVisArea );
192     bool bModified = false;
193     SwTwips lGreenOffset = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
194     SwTwips lTmp = aDocSz.Width() + lGreenOffset;
195 
196     if ( aNewVisArea.Right() >= lTmp  )
197     {
198         lTmp = aNewVisArea.Right() - lTmp;
199         aNewVisArea.Right() -= lTmp;
200         aNewVisArea.Left() -= lTmp;
201         bModified = true;
202     }
203 
204     lTmp = aDocSz.Height() + lGreenOffset;
205     if ( aNewVisArea.Bottom() >= lTmp )
206     {
207         lTmp = aNewVisArea.Bottom() - lTmp;
208         aNewVisArea.Bottom() -= lTmp;
209         aNewVisArea.Top() -= lTmp;
210         bModified = true;
211     }
212 
213     if ( bModified )
214         SetVisArea( aNewVisArea, sal_False );
215 
216     if ( UpdateScrollbars() && !bInOuterResizePixel && !bInInnerResizePixel &&
217             !GetViewFrame()->GetFrame().IsInPlace())
218         OuterResizePixel( Point(),
219                           GetViewFrame()->GetWindow().GetOutputSizePixel() );
220 }
221 
222 /*--------------------------------------------------------------------
223     Beschreibung:   Visarea neu setzen
224  --------------------------------------------------------------------*/
225 
226 void SwView::SetVisArea( const Rectangle &rRect, sal_Bool bUpdateScrollbar )
227 {
228     const Size aOldSz( aVisArea.GetSize() );
229 
230     const Point aTopLeft(     AlignToPixel( rRect.TopLeft() ));
231     const Point aBottomRight( AlignToPixel( rRect.BottomRight() ));
232     Rectangle aLR( aTopLeft, aBottomRight );
233 
234     if( aLR == aVisArea )
235         return;
236 
237     const SwTwips lMin = IsDocumentBorder() ? DOCUMENTBORDER : 0;
238 
239     // keine negative Position, keine neg. Groesse
240     if( aLR.Top() < lMin )
241     {
242         aLR.Bottom() += lMin - aLR.Top();
243         aLR.Top() = lMin;
244     }
245     if( aLR.Left() < lMin )
246     {
247         aLR.Right() += lMin - aLR.Left();
248         aLR.Left() = lMin;
249     }
250     if( aLR.Right() < 0 )
251         aLR.Right() = 0;
252     if( aLR.Bottom() < 0 )
253         aLR.Bottom() = 0;
254 
255     if( aLR == aVisArea )
256         return;
257 
258     const Size aSize( aLR.GetSize() );
259     if( aSize.Width() < 0 || aSize.Height() < 0 )
260         return;
261 
262     //Bevor die Daten veraendert werden ggf. ein Update rufen. Dadurch wird
263     //sichergestellt, da? anliegende Paints korrekt in Dokumentkoordinaten
264     //umgerechnet werden.
265     //Vorsichtshalber tun wir das nur wenn an der Shell eine Action laeuft,
266     //denn dann wir nicht wirklich gepaintet sondern die Rechtecke werden
267     //lediglich (in Dokumentkoordinaten) vorgemerkt.
268     if ( pWrtShell && pWrtShell->ActionPend() )
269         pWrtShell->GetWin()->Update();
270 
271     aVisArea = aLR;
272 
273     const sal_Bool bOuterResize = bUpdateScrollbar && UpdateScrollbars();
274 
275     if ( pWrtShell )
276     {
277         pWrtShell->VisPortChgd( aVisArea );
278         if ( aOldSz != pWrtShell->VisArea().SSize() &&
279              ( Abs(aOldSz.Width() - pWrtShell->VisArea().Width()) > 2 ||
280                 Abs(aOldSz.Height() - pWrtShell->VisArea().Height()) > 2 ) )
281             pWrtShell->CheckBrowseView( sal_False );
282     }
283 
284     if ( !bProtectDocShellVisArea )
285     {
286         //Wenn die Groesse der VisArea unveraendert ist, reichen wir die
287         //Groesse der VisArea vom InternalObject weiter. Damit soll der
288         //Transport von Fehlern vermieden werden.
289         Rectangle aVis( aVisArea );
290         if ( aVis.GetSize() == aOldSz )
291             aVis.SetSize( GetDocShell()->SfxObjectShell::GetVisArea(ASPECT_CONTENT).GetSize() );
292                     // TODO/LATER: why casting?!
293                     //GetDocShell()->SfxInPlaceObject::GetVisArea().GetSize() );
294 
295         //Bei embedded immer mit Modify...
296         // TODO/LATER: why casting?!
297         GetDocShell()->SfxObjectShell::SetVisArea( aVis );
298         /*
299         if ( GetDocShell()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
300             GetDocShell()->SfxInPlaceObject::SetVisArea( aVis );
301         else
302             GetDocShell()->SvEmbeddedObject::SetVisArea( aVis );*/
303     }
304 
305     SfxViewShell::VisAreaChanged( aVisArea );
306 
307     InvalidateRulerPos();
308 
309     SwEditWin::ClearTip();
310 
311     if ( bOuterResize && !bInOuterResizePixel && !bInInnerResizePixel)
312             OuterResizePixel( Point(),
313                 GetViewFrame()->GetWindow().GetOutputSizePixel() );
314 }
315 
316 /*--------------------------------------------------------------------
317     Beschreibung:   Pos VisArea setzen
318  --------------------------------------------------------------------*/
319 
320 void SwView::SetVisArea( const Point &rPt, sal_Bool bUpdateScrollbar )
321 {
322     //einmal alignen, damit Brushes korrekt angesetzt werden.
323     //MA 31. May. 96: Das geht in der BrowseView schief, weil evlt.
324     //nicht das ganze Dokument sichtbar wird. Da der Inhalt in Frames
325     //passgenau ist, kann nicht aligned werden (bessere Idee?!?!)
326     //MA 29. Oct. 96 (fix: Bild.de, 200%) ganz ohne Alignment geht es nicht
327     //mal sehen wie weit wir mit der halben BrushSize kommen.
328     //TODO: why BRUSH_SIZE?
329     Point aPt( rPt );
330 //  const long nTmp = GetWrtShell().IsFrameView() ? BRUSH_SIZE/2 : BRUSH_SIZE;
331     const long nTmp = GetWrtShell().IsFrameView() ? 4 : 8;
332     aPt = GetEditWin().LogicToPixel( aPt );
333     aPt.X() -= aPt.X() % nTmp;
334     aPt.Y() -= aPt.Y() % nTmp;
335     aPt = GetEditWin().PixelToLogic( aPt );
336 
337     if ( aPt == aVisArea.TopLeft() )
338         return;
339 
340     const long lXDiff = aVisArea.Left() - aPt.X();
341     const long lYDiff = aVisArea.Top()  - aPt.Y();
342     SetVisArea( Rectangle( aPt,
343             Point( aVisArea.Right() - lXDiff, aVisArea.Bottom() - lYDiff ) ),
344             bUpdateScrollbar);
345 }
346 
347 
348 void SwView::CheckVisArea()
349 {
350     pHScrollbar->SetAuto( pWrtShell->GetViewOptions()->getBrowseMode() &&
351                               !GetViewFrame()->GetFrame().IsInPlace() );
352     if ( IsDocumentBorder() )
353     {
354         if ( aVisArea.Left() != DOCUMENTBORDER ||
355              aVisArea.Top()  != DOCUMENTBORDER )
356         {
357             Rectangle aNewVisArea( aVisArea );
358             aNewVisArea.Move( DOCUMENTBORDER - aVisArea.Left(),
359                               DOCUMENTBORDER - aVisArea.Top() );
360             SetVisArea( aNewVisArea, sal_True );
361         }
362     }
363 }
364 
365 /*--------------------------------------------------------------------
366     Beschreibung:   Sichtbaren Bereich berechnen
367 
368     OUT Point *pPt:             neue Position des sichtbaren
369                                 Bereiches
370     IN  Rectangle &rRect:       Rechteck, das sich innerhalb des neuen
371                                 sichtbaren Bereiches befinden soll
372         sal_uInt16 nRange           optional exakte Angabe des Bereiches,
373                                 um den ggfs. gescrollt werden soll
374  --------------------------------------------------------------------*/
375 
376 void SwView::CalcPt( Point *pPt, const Rectangle &rRect,
377                      sal_uInt16 nRangeX, sal_uInt16 nRangeY)
378 {
379 
380     const SwTwips lMin = IsDocumentBorder() ? DOCUMENTBORDER : 0;
381 
382     long nYScroll = GetYScroll();
383     long nDesHeight = rRect.GetHeight();
384     long nCurHeight = aVisArea.GetHeight();
385     nYScroll = Min(nYScroll, nCurHeight - nDesHeight); // wird es knapp, dann nicht zuviel scrollen
386     if(nDesHeight > nCurHeight) // die Hoehe reicht nicht aus, dann interessiert nYScroll nicht mehr
387     {
388         pPt->Y() = rRect.Top();
389         pPt->Y() = Max( lMin, pPt->Y() );
390     }
391     else if ( rRect.Top() < aVisArea.Top() )                //Verschiebung nach oben
392     {
393         pPt->Y() = rRect.Top() - (nRangeY != USHRT_MAX ? nRangeY : nYScroll);
394         pPt->Y() = Max( lMin, pPt->Y() );
395     }
396     else if( rRect.Bottom() > aVisArea.Bottom() )   //Verschiebung nach unten
397     {
398         pPt->Y() = rRect.Bottom() -
399                     (aVisArea.GetHeight()) + ( nRangeY != USHRT_MAX ?
400             nRangeY : nYScroll );
401         pPt->Y() = SetVScrollMax( pPt->Y() );
402     }
403     long nXScroll = GetXScroll();
404     if ( rRect.Right() > aVisArea.Right() )         //Verschiebung nach rechts
405     {
406         pPt->X() = rRect.Right()  -
407                     (aVisArea.GetWidth()) +
408                     (nRangeX != USHRT_MAX ? nRangeX : nXScroll);
409         pPt->X() = SetHScrollMax( pPt->X() );
410     }
411     else if ( rRect.Left() < aVisArea.Left() )      //Verschiebung nach links
412     {
413         pPt->X() = rRect.Left() - (nRangeX != USHRT_MAX ? nRangeX : nXScroll);
414         pPt->X() = Max( ::GetLeftMargin( *this ) + nLeftOfst, pPt->X() );
415         pPt->X() = Min( rRect.Left() - nScrollX, pPt->X() );
416         pPt->X() = Max( 0L, pPt->X() );
417     }
418 }
419 
420 /*--------------------------------------------------------------------
421     Beschreibung:   Scrolling
422  --------------------------------------------------------------------*/
423 
424 sal_Bool SwView::IsScroll( const Rectangle &rRect ) const
425 {
426     return bCenterCrsr || bTopCrsr || !aVisArea.IsInside(rRect);
427 }
428 
429 
430 void SwView::Scroll( const Rectangle &rRect, sal_uInt16 nRangeX, sal_uInt16 nRangeY )
431 {
432     if ( aVisArea.IsEmpty() )
433         return;
434 
435     Rectangle aOldVisArea( aVisArea );
436     long nDiffY = 0;
437 
438     Window* pCareWn = ViewShell::GetCareWin(GetWrtShell());
439     if ( pCareWn )
440     {
441         Rectangle aDlgRect( GetEditWin().PixelToLogic(
442                 pCareWn->GetWindowExtentsRelative( &GetEditWin() ) ) );
443         // Nur, wenn der Dialog nicht rechts oder links der VisArea liegt:
444         if ( aDlgRect.Left() < aVisArea.Right() &&
445              aDlgRect.Right() > aVisArea.Left() )
446         {
447             // Falls wir nicht zentriert werden sollen, in der VisArea liegen
448             // und nicht vom Dialog ueberdeckt werden ...
449             if ( !bCenterCrsr && aOldVisArea.IsInside( rRect )
450                  && ( rRect.Left() > aDlgRect.Right()
451                       || rRect.Right() < aDlgRect.Left()
452                       || rRect.Top() > aDlgRect.Bottom()
453                       || rRect.Bottom() < aDlgRect.Top() ) )
454                 return;
455 
456             // Ist oberhalb oder unterhalb der Dialogs mehr Platz?
457             long nTopDiff = aDlgRect.Top() - aVisArea.Top();
458             long nBottomDiff = aVisArea.Bottom() - aDlgRect.Bottom();
459             if ( nTopDiff < nBottomDiff )
460             {
461                 if ( nBottomDiff > 0 ) // Ist unterhalb ueberhaupt Platz?
462                 {   // dann verschieben wir die Oberkante und merken uns dies
463                     nDiffY = aDlgRect.Bottom() - aVisArea.Top();
464                     aVisArea.Top() += nDiffY;
465                 }
466             }
467             else
468             {
469                 if ( nTopDiff > 0 ) // Ist oberhalb ueberhaupt Platz?
470                     aVisArea.Bottom() = aDlgRect.Top(); // Unterkante aendern
471             }
472         }
473     }
474 
475     //s.o. !IsScroll()
476     if( !(bCenterCrsr || bTopCrsr) && aVisArea.IsInside( rRect ) )
477     {
478         aVisArea = aOldVisArea;
479         return;
480     }
481     //falls das Rechteck groesser als der sichtbare Bereich -->
482     //obere linke Ecke
483     Size aSize( rRect.GetSize() );
484     const Size aVisSize( aVisArea.GetSize() );
485     if( !aVisArea.IsEmpty() && (
486         aSize.Width() + GetXScroll() > aVisSize.Width() ||
487         aSize.Height()+ GetYScroll() > aVisSize.Height() ))
488     {
489         Point aPt( aVisArea.TopLeft() );
490         aSize.Width() = Min( aSize.Width(), aVisSize.Width() );
491         aSize.Height()= Min( aSize.Height(),aVisSize.Height());
492 
493         CalcPt( &aPt, Rectangle( rRect.TopLeft(), aSize ),
494                 static_cast< sal_uInt16 >((aVisSize.Width() - aSize.Width()) / 2),
495                 static_cast< sal_uInt16 >((aVisSize.Height()- aSize.Height())/ 2) );
496 
497         if( bTopCrsr )
498         {
499             const long nBorder = IsDocumentBorder() ? DOCUMENTBORDER : 0;
500             aPt.Y() = Min( Max( nBorder, rRect.Top() ),
501                                 aDocSz.Height() + nBorder -
502                                     aVisArea.GetHeight() );
503         }
504         aPt.Y() -= nDiffY;
505         aVisArea = aOldVisArea;
506         SetVisArea( aPt );
507         return;
508     }
509     if( !bCenterCrsr )
510     {
511         Point aPt( aVisArea.TopLeft() );
512         CalcPt( &aPt, rRect, nRangeX, nRangeY );
513 
514         if( bTopCrsr )
515         {
516             const long nBorder = IsDocumentBorder() ? DOCUMENTBORDER : 0;
517             aPt.Y() = Min( Max( nBorder, rRect.Top() ),
518                                 aDocSz.Height() + nBorder -
519                                     aVisArea.GetHeight() );
520         }
521 
522         aPt.Y() -= nDiffY;
523         aVisArea = aOldVisArea;
524         SetVisArea( aPt );
525         return;
526     }
527 
528     //Cursor zentrieren
529     Point aPnt( aVisArea.TopLeft() );
530     // ... in Y-Richtung auf jeden Fall
531     aPnt.Y() += ( rRect.Top() + rRect.Bottom()
532                   - aVisArea.Top() - aVisArea.Bottom() ) / 2 - nDiffY;
533     // ... in X-Richtung nur, wenn das Rechteck rechts oder links aus der
534     //     VisArea hinausragt.
535     if ( rRect.Right() > aVisArea.Right() || rRect.Left() < aVisArea.Left() )
536     {
537         aPnt.X() += ( rRect.Left() + rRect.Right()
538                   - aVisArea.Left() - aVisArea.Right() ) / 2;
539         aPnt.X() = SetHScrollMax( aPnt.X() );
540         const SwTwips lMin = IsDocumentBorder() ? DOCUMENTBORDER : 0;
541         aPnt.X() = Max( (GetLeftMargin( *this ) - lMin) + nLeftOfst, aPnt.X() );
542     }
543     aVisArea = aOldVisArea;
544     if( pCareWn )
545     {   // Wenn wir nur einem Dialog ausweichen wollen, wollen wir nicht ueber
546         // das Ende des Dokument hinausgehen.
547         aPnt.Y() = SetVScrollMax( aPnt.Y() );
548     }
549     SetVisArea( aPnt );
550 }
551 
552 /*--------------------------------------------------------------------
553     Beschreibung:   Seitenweises Scrollen
554     Liefern den Wert, um den bei PageUp / -Down gescrollt werden soll
555  --------------------------------------------------------------------*/
556 
557 sal_Bool SwView::GetPageScrollUpOffset( SwTwips &rOff ) const
558 {
559     if ( !aVisArea.Top() || !aVisArea.GetHeight() )
560         return sal_False;
561     long nYScrl = GetYScroll() / 2;
562     rOff = -(aVisArea.GetHeight() - nYScrl);
563     //nicht vor den Dokumentanfang scrollen
564     if( aVisArea.Top() - rOff < 0 )
565         rOff = rOff - aVisArea.Top();
566     else if( GetWrtShell().GetCharRect().Top() < (aVisArea.Top() + nYScrl))
567         rOff += nYScrl;
568     return sal_True;
569 }
570 
571 
572 sal_Bool SwView::GetPageScrollDownOffset( SwTwips &rOff ) const
573 {
574     if ( !aVisArea.GetHeight() ||
575          (aVisArea.GetHeight() > aDocSz.Height()) )
576         return sal_False;
577     long nYScrl = GetYScroll() / 2;
578     rOff = aVisArea.GetHeight() - nYScrl;
579     //nicht hinter das Dokumentende scrollen
580     if ( aVisArea.Top() + rOff > aDocSz.Height() )
581         rOff = aDocSz.Height() - aVisArea.Bottom();
582     else if( GetWrtShell().GetCharRect().Bottom() >
583                                             ( aVisArea.Bottom() - nYScrl ))
584         rOff -= nYScrl;
585     return rOff > 0;
586 }
587 
588 // Seitenweises Blaettern
589 
590 long SwView::PageUp()
591 {
592     if (!aVisArea.GetHeight())
593         return 0;
594 
595     Point aPos(aVisArea.TopLeft());
596     aPos.Y() -= aVisArea.GetHeight() - (GetYScroll() / 2);
597     aPos.Y() = Max(0L, aPos.Y());
598     SetVisArea( aPos );
599     return 1;
600 }
601 
602 
603 long SwView::PageDown()
604 {
605     if ( !aVisArea.GetHeight() )
606         return 0;
607     Point aPos( aVisArea.TopLeft() );
608     aPos.Y() += aVisArea.GetHeight() - (GetYScroll() / 2);
609     aPos.Y() = SetVScrollMax( aPos.Y() );
610     SetVisArea( aPos );
611     return 1;
612 }
613 
614 
615 long SwView::PhyPageUp()
616 {
617     //aktuell sichtbare Seite erfragen, nicht formatieren
618     sal_uInt16 nActPage = pWrtShell->GetNextPrevPageNum( sal_False );
619 
620     if( USHRT_MAX != nActPage )
621     {
622         const Point aPt( aVisArea.Left(),
623                          pWrtShell->GetPagePos( nActPage ).Y() );
624         Point aAlPt( AlignToPixel( aPt ) );
625         // falls ein Unterschied besteht, wurde abgeschnitten --> dann
626         // einen Pixel addieren, damit kein Rest der Vorgaengerseite
627         // sichtbar ist
628         if( aPt.Y() != aAlPt.Y() )
629             aAlPt.Y() += 3 * GetEditWin().PixelToLogic( Size( 0, 1 ) ).Height();
630         SetVisArea( aAlPt );
631     }
632     return 1;
633 }
634 
635 
636 long SwView::PhyPageDown()
637 {
638     //aktuell sichtbare Seite erfragen, nicht formatieren
639     sal_uInt16 nActPage = pWrtShell->GetNextPrevPageNum( sal_True );
640     // falls die letzte Dokumentseite sichtbar ist, nichts tun
641     if( USHRT_MAX != nActPage )
642     {
643         const Point aPt( aVisArea.Left(),
644                          pWrtShell->GetPagePos( nActPage ).Y() );
645         Point aAlPt( AlignToPixel( aPt ) );
646         // falls ein Unterschied besteht, wurde abgeschnitten --> dann
647         // einen Pixel addieren, damit kein Rest der Vorgaengerseite sichtbar ist
648         if( aPt.Y() != aAlPt.Y() )
649             aAlPt.Y() += 3 * GetEditWin().PixelToLogic( Size( 0, 1 ) ).Height();
650         SetVisArea( aAlPt );
651     }
652     return 1;
653 }
654 
655 
656 long SwView::PageUpCrsr( sal_Bool bSelect )
657 {
658     if ( !bSelect )
659     {
660         const sal_uInt16 eType = pWrtShell->GetFrmType(0,sal_True);
661         if ( eType & FRMTYPE_FOOTNOTE )
662         {
663             pWrtShell->MoveCrsr();
664             pWrtShell->GotoFtnAnchor();
665             pWrtShell->Right(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
666             return 1;
667         }
668     }
669 
670     SwTwips lOff = 0;
671     if ( GetPageScrollUpOffset( lOff ) &&
672          (pWrtShell->IsCrsrReadonly() ||
673           !pWrtShell->PageCrsr( lOff, bSelect )) &&
674          PageUp() )
675     {
676         pWrtShell->ResetCursorStack();
677         return sal_True;
678     }
679     return sal_False;
680 }
681 
682 
683 long SwView::PageDownCrsr(sal_Bool bSelect)
684 {
685     SwTwips lOff = 0;
686     if ( GetPageScrollDownOffset( lOff ) &&
687          (pWrtShell->IsCrsrReadonly() ||
688           !pWrtShell->PageCrsr( lOff, bSelect )) &&
689          PageDown() )
690     {
691         pWrtShell->ResetCursorStack();
692         return sal_True;
693     }
694     return sal_False;
695 }
696 
697 /*------------------------------------------------------------------------
698  Beschreibung:  Handler der Scrollbars
699 ------------------------------------------------------------------------*/
700 
701 IMPL_LINK( SwView, ScrollHdl, SwScrollbar *, pScrollbar )
702 {
703     if ( GetWrtShell().ActionPend() )
704         return 0;
705 
706     if ( pScrollbar->GetType() == SCROLL_DRAG )
707         pWrtShell->EnableSmooth( sal_False );
708 
709     if(!pWrtShell->GetViewOptions()->getBrowseMode() &&
710         pScrollbar->GetType() == SCROLL_DRAG)
711     {
712         //Hier wieder auskommentieren wenn das mitscrollen nicht gewuenscht ist.
713         // JP 21.07.00: the end scrollhandler invalidate the FN_STAT_PAGE,
714         //              so we dont must do it again.
715         EndScrollHdl(pScrollbar);
716 
717         if ( Help::IsQuickHelpEnabled() &&
718              pWrtShell->GetViewOptions()->IsShowScrollBarTips())
719         {
720             Point aPos( aVisArea.TopLeft() );
721             lcl_GetPos(this, aPos, pScrollbar, IsDocumentBorder());
722 
723             sal_uInt16 nPhNum = 1;
724             sal_uInt16 nVirtNum = 1;
725 
726             String sDisplay;
727             if(pWrtShell->GetPageNumber( aPos.Y(), sal_False, nPhNum, nVirtNum, sDisplay ))
728             {
729                 // JP 21.07.00: the end scrollhandler invalidate the FN_STAT_PAGE,
730                 //                 so we dont must do it again.
731     //          if(!GetViewFrame()->GetFrame().IsInPlace())
732     //                S F X_BINDINGS().Update(FN_STAT_PAGE);
733 
734                 //QuickHelp:
735                 if( pWrtShell->GetPageCnt() > 1 )
736                 {
737                     if( !nPgNum || nPgNum != nPhNum )
738                     {
739                         Rectangle aRect;
740                         aRect.Left() = pScrollbar->GetParent()->OutputToScreenPixel(
741                                             pScrollbar->GetPosPixel() ).X() -8;
742                         aRect.Top() = pScrollbar->OutputToScreenPixel(
743                                         pScrollbar->GetPointerPosPixel() ).Y();
744                         aRect.Right()     = aRect.Left();
745                         aRect.Bottom()    = aRect.Top();
746 
747                         String sPageStr( GetPageStr( nPhNum, nVirtNum, sDisplay ));
748                         SwContentAtPos aCnt( SwContentAtPos::SW_OUTLINE );
749                         pWrtShell->GetContentAtPos( aPos, aCnt );
750                         if( aCnt.sStr.Len() )
751                         {
752                             sPageStr += String::CreateFromAscii(
753                                             RTL_CONSTASCII_STRINGPARAM( "  - " ));
754                             sPageStr.Insert( aCnt.sStr, 0, 80 );
755                             sPageStr.SearchAndReplaceAll( '\t', ' ' );
756                             sPageStr.SearchAndReplaceAll( 0x0a, ' ' );
757                         }
758 
759                         Help::ShowQuickHelp( pScrollbar, aRect, sPageStr,
760                                         QUICKHELP_RIGHT|QUICKHELP_VCENTER);
761                     }
762                     nPgNum = nPhNum;
763                 }
764             }
765         }
766     }
767     else
768         EndScrollHdl(pScrollbar);
769 
770     if ( pScrollbar->GetType() == SCROLL_DRAG )
771         pWrtShell->EnableSmooth( sal_True );
772 
773     return 0;
774 }
775 /*------------------------------------------------------------------------
776  Beschreibung:  Handler der Scrollbars
777 ------------------------------------------------------------------------*/
778 
779 IMPL_LINK( SwView, EndScrollHdl, SwScrollbar *, pScrollbar )
780 {
781     if ( !GetWrtShell().ActionPend() )
782     {
783         if(nPgNum)
784         {
785             nPgNum = 0;
786             Help::ShowQuickHelp(pScrollbar, Rectangle(), aEmptyStr, 0);
787         }
788         Point aPos( aVisArea.TopLeft() );
789         sal_Bool bBorder = IsDocumentBorder();
790         lcl_GetPos(this, aPos, pScrollbar, bBorder);
791         if ( bBorder && aPos == aVisArea.TopLeft() )
792             UpdateScrollbars();
793         else
794             SetVisArea( aPos, sal_False );
795 
796         GetViewFrame()->GetBindings().Update(FN_STAT_PAGE);
797     }
798     return 0;
799 }
800 
801 /*--------------------------------------------------------------------
802     Beschreibung:
803 
804         berechnet die Groesse von aVisArea abhaengig von der Groesse
805         des EditWin auf dem Schirm.
806 
807  --------------------------------------------------------------------*/
808 
809 void SwView::CalcVisArea( const Size &rOutPixel )
810 {
811     Point aTopLeft;
812     Rectangle aRect( aTopLeft, rOutPixel );
813     aTopLeft = GetEditWin().PixelToLogic( aTopLeft );
814     Point aBottomRight( GetEditWin().PixelToLogic( aRect.BottomRight() ) );
815 
816     aRect.Left() = aTopLeft.X();
817     aRect.Top() = aTopLeft.Y();
818     aRect.Right() = aBottomRight.X();
819     aRect.Bottom() = aBottomRight.Y();
820 
821     //Die Verschiebungen nach rechts und/oder unten koennen jetzt falsch
822     //sein (z.B. Zoom aendern, Viewgroesse aendern.
823     const long lBorder = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER*2;
824     if ( aRect.Left() )
825     {
826         const long lWidth = GetWrtShell().GetDocSize().Width() + lBorder;
827         if ( aRect.Right() > lWidth )
828         {
829             long lDelta    = aRect.Right() - lWidth;
830             aRect.Left()  -= lDelta;
831             aRect.Right() -= lDelta;
832         }
833     }
834     if ( aRect.Top() )
835     {
836         const long lHeight = GetWrtShell().GetDocSize().Height() + lBorder;
837         if ( aRect.Bottom() > lHeight )
838         {
839             long lDelta     = aRect.Bottom() - lHeight;
840             aRect.Top()    -= lDelta;
841             aRect.Bottom() -= lDelta;
842         }
843     }
844     SetVisArea( aRect );
845     GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOM );
846     GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER ); // for snapping points
847 }
848 
849 /*--------------------------------------------------------------------
850     Beschreibung:   Bedienelemente neu anordnen
851  --------------------------------------------------------------------*/
852 
853 
854 void SwView::CalcAndSetBorderPixel( SvBorder &rToFill, sal_Bool /*bInner*/ )
855 {
856     sal_Bool bRightVRuler = pWrtShell->GetViewOptions()->IsVRulerRight();
857     if ( pVRuler->IsVisible() )
858     {
859         long nWidth = pVRuler->GetSizePixel().Width();
860         if(bRightVRuler)
861             rToFill.Right() = nWidth;
862         else
863             rToFill.Left() = nWidth;
864     }
865 
866     DBG_ASSERT(pHRuler, "Why is there no Ruler?");
867     if ( pHRuler->IsVisible() )
868         rToFill.Top() = pHRuler->GetSizePixel().Height();
869 
870     const StyleSettings &rSet = GetEditWin().GetSettings().GetStyleSettings();
871     const long nTmp = rSet.GetScrollBarSize();
872     if( pVScrollbar->IsVisible(sal_False) )
873     {
874         if(bRightVRuler)
875             rToFill.Left() = nTmp;
876         else
877             rToFill.Right()  = nTmp;
878     }
879     //#i32913# in browse mode the visibility of the horizontal scrollbar
880     // depends on the content (fixed width tables may require a scrollbar)
881     if ( pHScrollbar->IsVisible(pWrtShell->GetViewOptions()->getBrowseMode()) )
882         rToFill.Bottom() = nTmp;
883 
884     SetBorderPixel( rToFill );
885 }
886 
887 
888 void ViewResizePixel( const Window &rRef,
889                     const Point &rOfst,
890                     const Size &rSize,
891                     const Size &rEditSz,
892                     const sal_Bool /*bInner*/,
893                     SwScrollbar& rVScrollbar,
894                     SwScrollbar& rHScrollbar,
895                     ImageButton* pPageUpBtn,
896                     ImageButton* pPageDownBtn,
897                     ImageButton* pNaviBtn,
898                     Window& rScrollBarBox,
899                     SvxRuler* pVRuler,
900                     SvxRuler* pHRuler,
901                     sal_Bool bWebView,
902                     sal_Bool bVRulerRight )
903 {
904 // ViewResizePixel wird auch von der PreView benutzt!!!
905 
906     const sal_Bool bHRuler = pHRuler && pHRuler->IsVisible();
907     const long nHLinSzHeight = bHRuler ?
908                         pHRuler->GetSizePixel().Height() : 0;
909     const sal_Bool bVRuler = pVRuler && pVRuler->IsVisible();
910     const long nVLinSzWidth = bVRuler ?
911                         pVRuler->GetSizePixel().Width() : 0;
912     long nHBSzHeight2= rHScrollbar.IsVisible( sal_False ) || !rHScrollbar.IsAuto() ?
913                        rRef.GetSettings().GetStyleSettings().GetScrollBarSize() : 0;
914     long nHBSzHeight =
915                 rHScrollbar.IsVisible(sal_True) ||  (rHScrollbar.IsVisible( sal_False ) && !rHScrollbar.IsAuto()) ?
916                                 nHBSzHeight2:0;
917     long nVBSzWidth = rVScrollbar.IsVisible(sal_True) ||  (rVScrollbar.IsVisible( sal_False ) && !rVScrollbar.IsAuto()) ?
918                          rRef.GetSettings().GetStyleSettings().GetScrollBarSize() : 0;
919 
920     if(pVRuler)
921     {
922         WinBits nStyle = pVRuler->GetStyle()&~WB_RIGHT_ALIGNED;
923         Point aPos( rOfst.X(), rOfst.Y()+nHLinSzHeight );
924         if(bVRulerRight)
925         {
926             aPos.X() += rSize.Width() - nVLinSzWidth;
927             nStyle |= WB_RIGHT_ALIGNED;
928         }
929         Size  aSize( nVLinSzWidth, rEditSz.Height() );
930         if(!aSize.Width())
931             aSize.Width() = pVRuler->GetSizePixel().Width();
932         pVRuler->SetStyle(nStyle);
933         pVRuler->SetPosSizePixel( aPos, aSize );
934         if(!pVRuler->IsVisible())
935             pVRuler->Resize();
936     }
937 //  Ruler braucht ein Resize, sonst funktioniert es nicht im unischtbaren Zustand
938     if(pHRuler)
939     {
940         Size aSize( rSize.Width(), nHLinSzHeight );
941         if ( nVBSzWidth && !bVRulerRight)
942             aSize.Width() -= nVBSzWidth;
943         if(!aSize.Height())
944             aSize.Height() = pHRuler->GetSizePixel().Height();
945         pHRuler->SetPosSizePixel( rOfst, aSize );
946 //      #46802 VCL ruft an unsichtbaren Fenstern kein Resize
947 //      für den Ruler ist das aber keine gute Idee
948         if(!pHRuler->IsVisible())
949             pHRuler->Resize();
950     }
951 
952     // Scrollbars und SizeBox anordnen
953     Point aScrollFillPos;
954     {
955         Point aPos( rOfst.X(),
956                     rOfst.Y()+rSize.Height()-nHBSzHeight );
957         if(bVRulerRight)
958         {
959             aPos.X() += nVBSzWidth;
960         }
961 
962         Size  aSize( rSize.Width(), nHBSzHeight2 );
963         if ( nVBSzWidth )
964             aSize.Width() -= nVBSzWidth;
965         rHScrollbar.SetPosSizePixel( aPos, aSize );
966         aScrollFillPos.Y() = aPos.Y();
967     }
968     {
969         Point aPos( rOfst.X()+rSize.Width()-nVBSzWidth,
970                     rOfst.Y() );
971         Size  aSize( nVBSzWidth, rSize.Height() );
972         if(bVRulerRight)
973         {
974             aPos.X() = rOfst.X();
975             if(bHRuler)
976             {
977                 aPos.Y() += nHLinSzHeight;
978                 aSize.Height() -= nHLinSzHeight;
979             }
980         }
981 
982         Size  aImgSz( nVBSzWidth, nVBSzWidth );
983 
984         //#55949#  wenn der Platz fuer Scrollbar und Page-Buttons zu klein wird, dann
985         // werden die Buttons versteckt
986         sal_uInt16 nCnt = pNaviBtn ? 3 : 2;
987         long nSubSize = (aImgSz.Width() * nCnt );
988         //
989         sal_Bool bHidePageButtons = aSize.Height() < ((bWebView ? 3 : 2) * nSubSize);
990         if(!bHidePageButtons)
991             aSize.Height() -= nSubSize;
992         else
993             aImgSz.Width() = 0; // kein Hide, weil das im Update Scrollbar missverstanden wird
994 
995         if ( nHBSzHeight )
996             aSize.Height() -= nHBSzHeight;
997         rVScrollbar.SetPosSizePixel( aPos, aSize );
998 
999         aPos.Y() += aSize.Height();
1000         pPageUpBtn->SetPosSizePixel( aPos, aImgSz );
1001         if(pNaviBtn)
1002         {
1003             aPos.Y() += aImgSz.Height();
1004             pNaviBtn->SetPosSizePixel(aPos, aImgSz);
1005         }
1006 
1007         aPos.Y() += aImgSz.Height();
1008         pPageDownBtn->SetPosSizePixel( aPos, aImgSz );
1009 
1010 
1011         if( rHScrollbar.IsVisible( sal_False ) )
1012         {
1013             aScrollFillPos.X() = aPos.X();
1014 
1015             rScrollBarBox.SetPosSizePixel( aScrollFillPos,
1016                                          Size( nHBSzHeight, nVBSzWidth) );
1017         }
1018     }
1019 }
1020 
1021 
1022 void SwView::ShowAtResize()
1023 {
1024     bShowAtResize = sal_False;
1025     if ( pWrtShell->GetViewOptions()->IsViewHRuler() )
1026         pHRuler->Show();
1027 }
1028 
1029 
1030 void SwView::InnerResizePixel( const Point &rOfst, const Size &rSize )
1031 {
1032     Size aObjSize = GetObjectShell()->GetVisArea().GetSize();
1033     if ( aObjSize.Width() > 0 && aObjSize.Height() > 0 )
1034     {
1035         SvBorder aBorder( GetBorderPixel() );
1036         Size aSize( rSize );
1037         aSize.Width() -= (aBorder.Left() + aBorder.Right());
1038         aSize.Height() -= (aBorder.Top() + aBorder.Bottom());
1039         Size aObjSizePixel = GetWindow()->LogicToPixel( aObjSize, MAP_TWIP );
1040         SfxViewShell::SetZoomFactor( Fraction( aSize.Width(), aObjSizePixel.Width() ),
1041                         Fraction( aSize.Height(), aObjSizePixel.Height() ) );
1042     }
1043 
1044     bInInnerResizePixel = sal_True;
1045     const sal_Bool bHScrollVisible = pHScrollbar->IsVisible(sal_True);
1046     const sal_Bool bVScrollVisible = pVScrollbar->IsVisible(sal_True);
1047     sal_Bool bRepeat = sal_False;
1048     do
1049     {
1050         Size aSz( rSize );
1051         SvBorder aBorder;
1052         CalcAndSetBorderPixel( aBorder, sal_True );
1053         if ( GetViewFrame()->GetFrame().IsInPlace() )
1054         {
1055             Size aViewSize( aSz );
1056             Point aViewPos( rOfst );
1057             aViewSize.Height() -= (aBorder.Top() + aBorder.Bottom());
1058             aViewSize.Width()  -= (aBorder.Left() + aBorder.Right());
1059             aViewPos.X() += aBorder.Left();
1060             aViewPos.Y() += aBorder.Top();
1061             GetEditWin().SetPosSizePixel( aViewPos, aViewSize );
1062         }
1063         else
1064         {
1065             aSz.Height() += aBorder.Top()  + aBorder.Bottom();
1066             aSz.Width()  += aBorder.Left() + aBorder.Right();
1067         }
1068 
1069         Size aEditSz( GetEditWin().GetOutputSizePixel() );
1070         ViewResizePixel( GetEditWin(), rOfst, aSz, aEditSz, sal_True, *pVScrollbar,
1071                             *pHScrollbar, pPageUpBtn, pPageDownBtn,
1072                             pNaviBtn,
1073                             *pScrollFill, pVRuler, pHRuler,
1074                             0 != PTR_CAST(SwWebView, this),
1075                             pWrtShell->GetViewOptions()->IsVRulerRight());
1076         if ( bShowAtResize )
1077             ShowAtResize();
1078 
1079         if( pHRuler->IsVisible() || pVRuler->IsVisible() )
1080         {
1081             const Fraction& rFrac = GetEditWin().GetMapMode().GetScaleX();
1082             sal_uInt16 nZoom = 100;
1083             if (0 != rFrac.GetDenominator())
1084                 nZoom = sal_uInt16(rFrac.GetNumerator() * 100L / rFrac.GetDenominator());
1085 
1086             const Fraction aFrac( nZoom, 100 );
1087             pVRuler->SetZoom( aFrac );
1088             pHRuler->SetZoom( aFrac );
1089             InvalidateRulerPos();   //Inhalt invalidieren.
1090         }
1091         //CursorStack zuruecksetzen, da die Cursorpositionen fuer PageUp/-Down
1092         //nicht mehr zum aktuell sichtbaren Bereich passen
1093         pWrtShell->ResetCursorStack();
1094 
1095         //EditWin niemals einstellen!
1096 
1097         //VisArea einstellen, aber dort nicht das SetVisArea der DocShell rufen!
1098         bProtectDocShellVisArea = sal_True;
1099         CalcVisArea( aEditSz );
1100         //visibility changes of the automatic horizontal scrollbar
1101         //require to repeat the ViewResizePixel() call - but only once!
1102         if(bRepeat)
1103             bRepeat = sal_False;
1104         else if(bHScrollVisible != pHScrollbar->IsVisible(sal_True) ||
1105                 bVScrollVisible != pVScrollbar->IsVisible(sal_True))
1106             bRepeat = sal_True;
1107     }while( bRepeat );
1108     bProtectDocShellVisArea = sal_False;
1109     bInInnerResizePixel = sal_False;
1110 }
1111 
1112 
1113 void SwView::OuterResizePixel( const Point &rOfst, const Size &rSize )
1114 {
1115     // FME 22.08.2003 #i16909# - return, if no size (caused by minimize window).
1116     if ( bInOuterResizePixel || ( !rSize.Width() && !rSize.Height() ) )
1117         return;
1118     bInOuterResizePixel = sal_True;
1119 
1120 // feststellen, ob Scrollbars angezeigt werden duerfen
1121     sal_Bool bBrowse = pWrtShell->GetViewOptions()->getBrowseMode();
1122     sal_Bool bShowH = sal_False,
1123          bShowV = sal_False,
1124          bAuto  = sal_False,
1125          bHAuto = bBrowse;
1126     switch( GetScrollingMode() )
1127     {
1128     case SCROLLING_DEFAULT:
1129         {
1130             const SwViewOption *pVOpt = pWrtShell->GetViewOptions();
1131             if ( !pVOpt->IsReadonly() || pVOpt->IsStarOneSetting() )
1132             {
1133                 bShowH = pVOpt->IsViewHScrollBar();
1134                 bShowV = pVOpt->IsViewVScrollBar();
1135                 break;
1136             }
1137         }
1138         /* kein break hier */
1139     case SCROLLING_AUTO:
1140         bAuto = bHAuto = sal_True;
1141         bShowH = bShowV = sal_True;
1142         break;
1143     case SCROLLING_YES:
1144         bShowH = bShowV = sal_True;
1145         break;
1146     case SCROLLING_NO:
1147         bShowH = bShowV = bHAuto = sal_False;
1148         break;
1149     }
1150     SwDocShell* pDocSh = GetDocShell();
1151     sal_Bool bIsPreview = pDocSh->IsPreview();
1152     if( bIsPreview )
1153     {
1154         bShowH = bShowV = bHAuto = bAuto = sal_False;
1155     }
1156     if(pHScrollbar->IsVisible(sal_False) != bShowH)
1157         ShowHScrollbar(bShowH);
1158     pHScrollbar->SetAuto( bHAuto );
1159     if(pVScrollbar->IsVisible(sal_False) != bShowV)
1160         ShowVScrollbar(bShowV);
1161     pVScrollbar->SetAuto(bAuto);
1162 
1163     SET_CURR_SHELL( pWrtShell );
1164     sal_Bool bRepeat = sal_False;
1165     long nCnt = 0;
1166 
1167     sal_Bool bUnLockView = !pWrtShell->IsViewLocked();
1168     pWrtShell->LockView( sal_True );
1169     pWrtShell->LockPaint();
1170 
1171     do {
1172         ++nCnt;
1173         const sal_Bool bScroll1 = pVScrollbar->IsVisible(sal_True);
1174         const sal_Bool bScroll2 = pHScrollbar->IsVisible(sal_True);
1175         SvBorder aBorder;
1176         CalcAndSetBorderPixel( aBorder, sal_False );
1177         const Size aEditSz( GetEditWin().GetOutputSizePixel() );
1178         ViewResizePixel( GetEditWin(), rOfst, rSize, aEditSz, sal_False, *pVScrollbar,
1179                                 *pHScrollbar, pPageUpBtn, pPageDownBtn,
1180                                 pNaviBtn,
1181                                 *pScrollFill, pVRuler, pHRuler,
1182                                 0 != PTR_CAST(SwWebView, this),
1183                                 pWrtShell->GetViewOptions()->IsVRulerRight() );
1184         if ( bShowAtResize )
1185             ShowAtResize();
1186 
1187         if( pHRuler->IsVisible() || pVRuler->IsVisible() )
1188             InvalidateRulerPos();   //Inhalt invalidieren.
1189 
1190         //CursorStack zuruecksetzen, da die Cursorpositionen fuer PageUp/-Down
1191         //nicht mehr zum aktuell sichtbaren Bereich passen
1192         pWrtShell->ResetCursorStack();
1193 
1194         ASSERT( !GetEditWin().IsVisible() ||
1195                     (( aEditSz.Width() > 0 && aEditSz.Height() > 0 )
1196                         || !aVisArea.IsEmpty()), "Small world, isn't it?" );
1197 
1198         //EditWin niemals einstellen!
1199 
1200         //Die VisArea muss aber natuerlich eingestellt werden.
1201         //jetzt ist auch der richtige Zeitpunkt den Zoom neu zu berechnen wenn
1202         //es kein einfacher Faktor ist.
1203         pWrtShell->StartAction();
1204         CalcVisArea( aEditSz );
1205 
1206         //Damit auch beim outplace editing die Seitenbreite sofort
1207         //angepasst wird.
1208         //TODO/LATER: is that still necessary?!
1209         /*
1210         if ( pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1211             pDocSh->SetVisArea(
1212                             pDocSh->SfxInPlaceObject::GetVisArea() );*/
1213         if ( pWrtShell->GetViewOptions()->GetZoomType() != SVX_ZOOM_PERCENT &&
1214              !pWrtShell->GetViewOptions()->getBrowseMode() )
1215             _SetZoom( aEditSz, (SvxZoomType)pWrtShell->GetViewOptions()->GetZoomType(), 100, sal_True );
1216         pWrtShell->EndAction();
1217 
1218         bRepeat = bScroll1 != pVScrollbar->IsVisible(sal_True);
1219         if ( !bRepeat )
1220             bRepeat = bScroll2 != pHScrollbar->IsVisible(sal_True);
1221 
1222         //Nicht endlosschleifen. Moeglichst dann stoppen wenn die
1223         //(Auto-)Scrollbars sichtbar sind.
1224         if ( bRepeat &&
1225              ( nCnt > 10 || ( nCnt > 3 && bHAuto && bAuto ) )
1226            )
1227         {
1228             bRepeat = sal_False;
1229         }
1230 
1231     }while ( bRepeat );
1232 
1233     if( pVScrollbar->IsVisible(sal_False) || pVScrollbar->IsAuto())
1234     {
1235         sal_Bool bShowButtons = pVScrollbar->IsVisible(sal_True);
1236         if(pPageUpBtn && pPageUpBtn->IsVisible() != bShowButtons)
1237         {
1238             pPageUpBtn->Show(bShowButtons);
1239             if(pPageDownBtn)
1240                 pPageDownBtn->Show(bShowButtons);
1241             if(pNaviBtn)
1242                 pNaviBtn->Show(bShowButtons);
1243         }
1244     }
1245 
1246     pWrtShell->UnlockPaint();
1247     if( bUnLockView )
1248         pWrtShell->LockView( sal_False );
1249 
1250     bInOuterResizePixel = sal_False;
1251 
1252     if ( mpPostItMgr )
1253     {
1254         mpPostItMgr->CalcRects();
1255         mpPostItMgr->LayoutPostIts();
1256     }
1257 }
1258 
1259 
1260 void SwView::SetZoomFactor( const Fraction &rX, const Fraction &rY )
1261 {
1262     const Fraction &rFrac = rX < rY ? rX : rY;
1263     SetZoom( SVX_ZOOM_PERCENT, (short) long(rFrac * Fraction( 100, 1 )) );
1264 
1265     //Um Rundungsfehler zu minimieren lassen wir von der Basisklasse ggf.
1266     //auch die krummen Werte einstellen
1267     SfxViewShell::SetZoomFactor( rX, rY );
1268 }
1269 
1270 
1271 Size SwView::GetOptimalSizePixel() const
1272 {
1273     Size aPgSize;
1274     if ( pWrtShell->GetViewOptions()->getBrowseMode() )
1275         aPgSize = SvxPaperInfo::GetPaperSize(PAPER_A4);
1276     else
1277     {
1278         aPgSize = GetWrtShell().GetAnyCurRect(RECT_PAGE).SSize();
1279         aPgSize.Width() += DOCUMENTBORDER * 2;
1280 
1281         const SwPageDesc &rDesc = pWrtShell->GetPageDesc( pWrtShell->GetCurPageDesc() );
1282         if( nsUseOnPage::PD_MIRROR == rDesc.GetUseOn() )
1283         {
1284             const SvxLRSpaceItem &rLRSpace = rDesc.GetMaster().GetLRSpace();
1285             const SvxLRSpaceItem &rLeftLRSpace = rDesc.GetLeft().GetLRSpace();
1286             aPgSize.Width() += Abs( long(rLeftLRSpace.GetLeft()) - long(rLRSpace.GetLeft()) );
1287         }
1288     }
1289     return GetEditWin().LogicToPixel( aPgSize );
1290 }
1291 
1292 
1293 sal_Bool SwView::UpdateScrollbars()
1294 {
1295     sal_Bool bRet = sal_False;
1296     if ( !aVisArea.IsEmpty() )
1297     {
1298         const sal_Bool bBorder = IsDocumentBorder();
1299         Rectangle aTmpRect( aVisArea );
1300         if ( bBorder )
1301         {
1302             Point aPt( DOCUMENTBORDER, DOCUMENTBORDER );
1303             aPt = AlignToPixel( aPt );
1304             aTmpRect.Move( -aPt.X(), -aPt.Y() );
1305         }
1306 
1307         Size aTmpSz( aDocSz );
1308         const long lOfst = bBorder ? 0 : DOCUMENTBORDER * 2L;
1309         aTmpSz.Width() += lOfst; aTmpSz.Height() += lOfst;
1310 
1311         {
1312             const sal_Bool bVScrollVisible = pVScrollbar->IsVisible(sal_True);
1313             pVScrollbar->DocSzChgd( aTmpSz );
1314             pVScrollbar->ViewPortChgd( aTmpRect );
1315 
1316             sal_Bool bShowButtons = pVScrollbar->IsVisible(sal_True);
1317             if(pPageUpBtn && pPageUpBtn->IsVisible() != bShowButtons)
1318             {
1319                 pPageUpBtn->Show(bShowButtons);
1320                 if(pPageDownBtn)
1321                     pPageDownBtn->Show(bShowButtons);
1322                 if(pNaviBtn)
1323                     pNaviBtn->Show(bShowButtons);
1324             }
1325 
1326             if ( bVScrollVisible != pVScrollbar->IsVisible(sal_True) )
1327                 bRet = sal_True;
1328         }
1329         {
1330             const sal_Bool bHScrollVisible = pHScrollbar->IsVisible(sal_True);
1331             pHScrollbar->DocSzChgd( aTmpSz );
1332             pHScrollbar->ViewPortChgd( aTmpRect );
1333             if ( bHScrollVisible != pHScrollbar->IsVisible(sal_True) )
1334                 bRet = sal_True;
1335             pScrollFill->Show(pHScrollbar->IsVisible(sal_True) && pVScrollbar->IsVisible(sal_True) );
1336         }
1337     }
1338     return bRet;
1339 }
1340 
1341 
1342 void SwView::Move()
1343 {
1344     if ( GetWrtShell().IsInSelect() )
1345         GetWrtShell().EndSelect();  //#32427#
1346     SfxViewShell::Move();
1347 }
1348 
1349 sal_Bool SwView::HandleWheelCommands( const CommandEvent& rCEvt )
1350 {
1351     sal_Bool bOk = sal_False;
1352     const CommandWheelData* pWData = rCEvt.GetWheelData();
1353     if( pWData && COMMAND_WHEEL_ZOOM == pWData->GetMode() )
1354     {
1355         sal_uInt16 nFact = pWrtShell->GetViewOptions()->GetZoom();
1356         if( 0L > pWData->GetDelta() )
1357             nFact = static_cast< sal_uInt16 >(Max( 20, nFact - 10 ));
1358         else
1359             nFact = static_cast< sal_uInt16 >(Min( 600, nFact + 10 ));
1360 
1361         SetZoom( SVX_ZOOM_PERCENT, nFact );
1362         bOk = sal_True;
1363     }
1364     else
1365     {
1366         if (pWData && (COMMAND_WHEEL_SCROLL==pWData->GetMode()) && (((sal_uLong)0xFFFFFFFF) == pWData->GetScrollLines()))
1367             {
1368                         if (pWData->GetDelta()<0)
1369                                 PhyPageDown();
1370                         else
1371                                 PhyPageUp();
1372                         bOk = sal_True;
1373                 }
1374         else
1375             bOk = pEditWin->HandleScrollCommand( rCEvt,
1376                             pHScrollbar, pVScrollbar);
1377     }
1378     return bOk;
1379 }
1380 
1381 /* vim: set noet sw=4 ts=4: */
1382