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