xref: /aoo42x/main/sw/source/ui/uiview/viewport.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include "hintids.hxx"
33 #include <vcl/help.hxx>
34 #include <svx/ruler.hxx>
35 #include <editeng/paperinf.hxx>
36 #include <editeng/lrspitem.hxx>
37 #include <sfx2/bindings.hxx>
38 #ifndef _VIEW_HXX
39 #include <view.hxx>
40 #endif
41 #include <wrtsh.hxx>
42 #include <swmodule.hxx>
43 #include <viewopt.hxx>
44 #include <frmatr.hxx>
45 #ifndef _DOCSH_HXX
46 #include <docsh.hxx>
47 #endif
48 #ifndef _CMDID_H
49 #include <cmdid.h>
50 #endif
51 #include <edtwin.hxx>
52 #include <scroll.hxx>
53 #ifndef _WVIEW_HXX
54 #include <wview.hxx>
55 #endif
56 #include <usrpref.hxx>
57 #include <pagedesc.hxx>
58 #include <workctrl.hxx>
59 #include <crsskip.hxx>
60 
61 #include <PostItMgr.hxx>
62 
63 #include <IDocumentSettingAccess.hxx>
64 
65 //Das SetVisArea der DocShell darf nicht vom InnerResizePixel gerufen werden.
66 //Unsere Einstellungen muessen aber stattfinden.
67 #ifndef WB_RIGHT_ALIGNED
68 #define WB_RIGHT_ALIGNED    ((WinBits)0x00008000)
69 #endif
70 
71 static sal_Bool bProtectDocShellVisArea = sal_False;
72 
73 static sal_uInt16 nPgNum = 0;
74 
75 sal_Bool SwView::IsDocumentBorder()
76 {
77     return GetDocShell()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED ||
78            pWrtShell->GetViewOptions()->getBrowseMode() ||
79            SVX_ZOOM_PAGEWIDTH_NOBORDER == (SvxZoomType)pWrtShell->GetViewOptions()->GetZoomType();
80 }
81 
82 inline long GetLeftMargin( SwView &rView )
83 {
84     SvxZoomType eType = (SvxZoomType)rView.GetWrtShell().GetViewOptions()->GetZoomType();
85 	long lRet = rView.GetWrtShell().GetAnyCurRect(RECT_PAGE_PRT).Left();
86 	return eType == SVX_ZOOM_PERCENT   ? lRet + DOCUMENTBORDER :
87            eType == SVX_ZOOM_PAGEWIDTH || eType == SVX_ZOOM_PAGEWIDTH_NOBORDER ? 0 :
88 										 lRet + DOCUMENTBORDER + nLeftOfst;
89 }
90 
91 //-------------------------------------------------------------------------
92 
93 void lcl_GetPos(SwView* pView,
94 				Point& rPos,
95 				SwScrollbar* pScrollbar,
96 				sal_Bool bBorder)
97 {
98 	SwWrtShell &rSh = pView->GetWrtShell();
99 	const Size aDocSz( rSh.GetDocSize() );
100 
101 	const long lBorder = bBorder ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
102 	sal_Bool bHori = pScrollbar->IsHoriScroll();
103 
104 	const long lPos = pScrollbar->GetThumbPos() + (bBorder ? DOCUMENTBORDER : 0);
105 	long Point:: *pPt = bHori ? &Point::nA : &Point::nB;
106 	long Size::  *pSz = bHori ? &Size::nA  : &Size::nB;
107 
108 	long lDelta = lPos - rSh.VisArea().Pos().*pPt;
109 	const long lSize = aDocSz.*pSz + lBorder;
110 	// Bug 11693: sollte rechts oder unten zuviel Wiese sein, dann muss
111 	// 			  diese von der VisArea herausgerechnet werden!
112 	long nTmp = pView->GetVisArea().Right()+lDelta;
113 	if ( bHori && nTmp > lSize )
114 		lDelta -= nTmp - lSize;
115 	nTmp = pView->GetVisArea().Bottom()+lDelta;
116 	if ( !bHori && nTmp > lSize )
117 		lDelta -= nTmp - lSize;
118 
119 	rPos.*pPt += lDelta;
120 	if ( bBorder && rPos.*pPt < DOCUMENTBORDER )
121 		rPos.*pPt = DOCUMENTBORDER;
122 }
123 
124 /*--------------------------------------------------------------------
125 	Beschreibung:	Nullpunkt Lineal setzen
126  --------------------------------------------------------------------*/
127 
128 void SwView::InvalidateRulerPos()
129 {
130 	static sal_uInt16 __READONLY_DATA aInval[] =
131 	{
132 		SID_ATTR_PARA_LRSPACE, SID_RULER_BORDERS, SID_RULER_PAGE_POS,
133 		SID_RULER_LR_MIN_MAX, SID_ATTR_LONG_ULSPACE, SID_ATTR_LONG_LRSPACE,
134         SID_RULER_BORDER_DISTANCE,
135         SID_ATTR_PARA_LRSPACE_VERTICAL, SID_RULER_BORDERS_VERTICAL,
136         SID_RULER_TEXT_RIGHT_TO_LEFT,
137         SID_RULER_ROWS, SID_RULER_ROWS_VERTICAL, FN_STAT_PAGE,
138         0
139 	};
140 
141 	GetViewFrame()->GetBindings().Invalidate(aInval);
142 
143     DBG_ASSERT(pHRuler, "warum ist das Lineal nicht da?");
144     pHRuler->ForceUpdate();
145     pVRuler->ForceUpdate();
146 }
147 
148 /*--------------------------------------------------------------------
149 	Beschreibung:	begrenzt das Scrollen soweit, dass jeweils nur einen
150 					viertel Bildschirm bis vor das Ende des Dokumentes
151 					gescrollt werden kann.
152  --------------------------------------------------------------------*/
153 
154 long SwView::SetHScrollMax( long lMax )
155 {
156 	const long lBorder = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
157 	const long lSize = GetDocSz().Width() + lBorder - aVisArea.GetWidth();
158 
159 	// bei negativen Werten ist das Dokument vollstaendig sichtbar;
160 	// in diesem Fall kein Scrollen
161 	return Max( Min( lMax, lSize ), 0L );
162 }
163 
164 
165 long SwView::SetVScrollMax( long lMax )
166 {
167 	const long lBorder = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
168 	long lSize = GetDocSz().Height() + lBorder - aVisArea.GetHeight();
169 	return Max( Min( lMax, lSize), 0L );		// siehe horz.
170 }
171 
172 
173 Point SwView::AlignToPixel(const Point &rPt) const
174 {
175 	return GetEditWin().PixelToLogic( GetEditWin().LogicToPixel( rPt ) );
176 }
177 
178 /*--------------------------------------------------------------------
179 	Beschreibung:	Dokumentgroesse hat sich geaendert
180  --------------------------------------------------------------------*/
181 
182 void SwView::DocSzChgd(const Size &rSz)
183 {
184 
185 extern int bDocSzUpdated;
186 
187 
188 aDocSz = rSz;
189 
190 	if( !pWrtShell || aVisArea.IsEmpty() )		// keine Shell -> keine Aenderung
191 	{
192 		bDocSzUpdated = sal_False;
193 		return;
194 	}
195 
196 	//Wenn Text geloescht worden ist, kann es sein, dass die VisArea hinter
197 	//den sichtbaren Bereich verweist
198 	Rectangle aNewVisArea( aVisArea );
199 	bool bModified = false;
200 	SwTwips lGreenOffset = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER * 2;
201 	SwTwips lTmp = aDocSz.Width() + lGreenOffset;
202 
203 	if ( aNewVisArea.Right() >= lTmp  )
204 	{
205 		lTmp = aNewVisArea.Right() - lTmp;
206 		aNewVisArea.Right() -= lTmp;
207 		aNewVisArea.Left() -= lTmp;
208         bModified = true;
209 	}
210 
211 	lTmp = aDocSz.Height() + lGreenOffset;
212 	if ( aNewVisArea.Bottom() >= lTmp )
213 	{
214 		lTmp = aNewVisArea.Bottom() - lTmp;
215 		aNewVisArea.Bottom() -= lTmp;
216 		aNewVisArea.Top() -= lTmp;
217 		bModified = true;
218 	}
219 
220 	if ( bModified )
221 		SetVisArea( aNewVisArea, sal_False );
222 
223     if ( UpdateScrollbars() && !bInOuterResizePixel && !bInInnerResizePixel &&
224             !GetViewFrame()->GetFrame().IsInPlace())
225         OuterResizePixel( Point(),
226 						  GetViewFrame()->GetWindow().GetOutputSizePixel() );
227 }
228 
229 /*--------------------------------------------------------------------
230 	Beschreibung:	Visarea neu setzen
231  --------------------------------------------------------------------*/
232 
233 void SwView::SetVisArea( const Rectangle &rRect, sal_Bool bUpdateScrollbar )
234 {
235 	const Size aOldSz( aVisArea.GetSize() );
236 
237 	const Point aTopLeft(	  AlignToPixel( rRect.TopLeft() ));
238 	const Point aBottomRight( AlignToPixel( rRect.BottomRight() ));
239 	Rectangle aLR( aTopLeft, aBottomRight );
240 
241 	if( aLR == aVisArea )
242 		return;
243 
244 	const SwTwips lMin = IsDocumentBorder() ? DOCUMENTBORDER : 0;
245 
246 	// keine negative Position, keine neg. Groesse
247 	if( aLR.Top() < lMin )
248 	{
249 		aLR.Bottom() += lMin - aLR.Top();
250 		aLR.Top() = lMin;
251 	}
252     if( aLR.Left() < lMin )
253 	{
254 		aLR.Right() += lMin - aLR.Left();
255 		aLR.Left() = lMin;
256 	}
257 	if( aLR.Right() < 0 )
258 		aLR.Right() = 0;
259 	if( aLR.Bottom() < 0 )
260 		aLR.Bottom() = 0;
261 
262 	if( aLR == aVisArea )
263 		return;
264 
265 	const Size aSize( aLR.GetSize() );
266 	if( aSize.Width() < 0 || aSize.Height() < 0 )
267 		return;
268 
269 	//Bevor die Daten veraendert werden ggf. ein Update rufen. Dadurch wird
270 	//sichergestellt, da? anliegende Paints korrekt in Dokumentkoordinaten
271 	//umgerechnet werden.
272 	//Vorsichtshalber tun wir das nur wenn an der Shell eine Action laeuft,
273 	//denn dann wir nicht wirklich gepaintet sondern die Rechtecke werden
274 	//lediglich (in Dokumentkoordinaten) vorgemerkt.
275 	if ( pWrtShell && pWrtShell->ActionPend() )
276 		pWrtShell->GetWin()->Update();
277 
278 	aVisArea = aLR;
279 
280     const sal_Bool bOuterResize = bUpdateScrollbar && UpdateScrollbars();
281 
282 	if ( pWrtShell )
283 	{
284 		pWrtShell->VisPortChgd( aVisArea );
285 		if ( aOldSz != pWrtShell->VisArea().SSize() &&
286 			 ( Abs(aOldSz.Width() - pWrtShell->VisArea().Width()) > 2 ||
287 				Abs(aOldSz.Height() - pWrtShell->VisArea().Height()) > 2 ) )
288 			pWrtShell->CheckBrowseView( sal_False );
289 	}
290 
291 	if ( !bProtectDocShellVisArea )
292 	{
293 		//Wenn die Groesse der VisArea unveraendert ist, reichen wir die
294 		//Groesse der VisArea vom InternalObject weiter. Damit soll der
295 		//Transport von Fehlern vermieden werden.
296 		Rectangle aVis( aVisArea );
297 		if ( aVis.GetSize() == aOldSz )
298             aVis.SetSize( GetDocShell()->SfxObjectShell::GetVisArea(ASPECT_CONTENT).GetSize() );
299                     // TODO/LATER: why casting?!
300                     //GetDocShell()->SfxInPlaceObject::GetVisArea().GetSize() );
301 
302 		//Bei embedded immer mit Modify...
303         // TODO/LATER: why casting?!
304         GetDocShell()->SfxObjectShell::SetVisArea( aVis );
305         /*
306 		if ( GetDocShell()->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
307 			GetDocShell()->SfxInPlaceObject::SetVisArea( aVis );
308 		else
309             GetDocShell()->SvEmbeddedObject::SetVisArea( aVis );*/
310 	}
311 
312 	SfxViewShell::VisAreaChanged( aVisArea );
313 
314 	InvalidateRulerPos();
315 
316 	SwEditWin::ClearTip();
317 
318     if ( bOuterResize && !bInOuterResizePixel && !bInInnerResizePixel)
319             OuterResizePixel( Point(),
320 				GetViewFrame()->GetWindow().GetOutputSizePixel() );
321 }
322 
323 /*--------------------------------------------------------------------
324 	Beschreibung:	Pos VisArea setzen
325  --------------------------------------------------------------------*/
326 
327 void SwView::SetVisArea( const Point &rPt, sal_Bool bUpdateScrollbar )
328 {
329 	//einmal alignen, damit Brushes korrekt angesetzt werden.
330 	//MA 31. May. 96: Das geht in der BrowseView schief, weil evlt.
331 	//nicht das ganze Dokument sichtbar wird. Da der Inhalt in Frames
332 	//passgenau ist, kann nicht aligned werden (bessere Idee?!?!)
333 	//MA 29. Oct. 96 (fix: Bild.de, 200%) ganz ohne Alignment geht es nicht
334 	//mal sehen wie weit wir mit der halben BrushSize kommen.
335 	//TODO: why BRUSH_SIZE?
336 	Point aPt( rPt );
337 //	const long nTmp = GetWrtShell().IsFrameView() ? BRUSH_SIZE/2 : BRUSH_SIZE;
338 	const long nTmp = GetWrtShell().IsFrameView() ? 4 : 8;
339 	aPt = GetEditWin().LogicToPixel( aPt );
340 	aPt.X() -= aPt.X() % nTmp;
341 	aPt.Y() -= aPt.Y() % nTmp;
342 	aPt = GetEditWin().PixelToLogic( aPt );
343 
344 	if ( aPt == aVisArea.TopLeft() )
345 		return;
346 
347 	const long lXDiff = aVisArea.Left() - aPt.X();
348 	const long lYDiff = aVisArea.Top()	- aPt.Y();
349 	SetVisArea( Rectangle( aPt,
350 			Point( aVisArea.Right() - lXDiff, aVisArea.Bottom() - lYDiff ) ),
351 			bUpdateScrollbar);
352 }
353 
354 
355 void SwView::CheckVisArea()
356 {
357     pHScrollbar->SetAuto( pWrtShell->GetViewOptions()->getBrowseMode() &&
358                               !GetViewFrame()->GetFrame().IsInPlace() );
359 	if ( IsDocumentBorder() )
360 	{
361 		if ( aVisArea.Left() != DOCUMENTBORDER ||
362 			 aVisArea.Top()  != DOCUMENTBORDER )
363 		{
364 			Rectangle aNewVisArea( aVisArea );
365 			aNewVisArea.Move( DOCUMENTBORDER - aVisArea.Left(),
366 							  DOCUMENTBORDER - aVisArea.Top() );
367 			SetVisArea( aNewVisArea, sal_True );
368 		}
369 	}
370 }
371 
372 /*--------------------------------------------------------------------
373 	Beschreibung:	Sichtbaren Bereich berechnen
374 
375 	OUT Point *pPt:				neue Position des sichtbaren
376 								Bereiches
377 	IN	Rectangle &rRect:		Rechteck, das sich innerhalb des neuen
378 								sichtbaren Bereiches befinden soll
379 		sal_uInt16 nRange			optional exakte Angabe des Bereiches,
380 								um den ggfs. gescrollt werden soll
381  --------------------------------------------------------------------*/
382 
383 void SwView::CalcPt( Point *pPt, const Rectangle &rRect,
384 					 sal_uInt16 nRangeX, sal_uInt16 nRangeY)
385 {
386 
387 	const SwTwips lMin = IsDocumentBorder() ? DOCUMENTBORDER : 0;
388 
389 	long nYScroll = GetYScroll();
390 	long nDesHeight = rRect.GetHeight();
391 	long nCurHeight = aVisArea.GetHeight();
392 	nYScroll = Min(nYScroll, nCurHeight - nDesHeight); // wird es knapp, dann nicht zuviel scrollen
393 	if(nDesHeight > nCurHeight) // die Hoehe reicht nicht aus, dann interessiert nYScroll nicht mehr
394 	{
395 		pPt->Y() = rRect.Top();
396 		pPt->Y() = Max( lMin, pPt->Y() );
397 	}
398 	else if ( rRect.Top() < aVisArea.Top() )				//Verschiebung nach oben
399 	{
400 		pPt->Y() = rRect.Top() - (nRangeY != USHRT_MAX ? nRangeY : nYScroll);
401 		pPt->Y() = Max( lMin, pPt->Y() );
402 	}
403 	else if( rRect.Bottom() > aVisArea.Bottom() )	//Verschiebung nach unten
404 	{
405 		pPt->Y() = rRect.Bottom() -
406 					(aVisArea.GetHeight()) + ( nRangeY != USHRT_MAX ?
407 			nRangeY : nYScroll );
408 		pPt->Y() = SetVScrollMax( pPt->Y() );
409 	}
410 	long nXScroll = GetXScroll();
411 	if ( rRect.Right() > aVisArea.Right() )			//Verschiebung nach rechts
412 	{
413 		pPt->X() = rRect.Right()  -
414 					(aVisArea.GetWidth()) +
415 					(nRangeX != USHRT_MAX ? nRangeX : nXScroll);
416 		pPt->X() = SetHScrollMax( pPt->X() );
417 	}
418 	else if ( rRect.Left() < aVisArea.Left() )		//Verschiebung nach links
419 	{
420 		pPt->X() = rRect.Left() - (nRangeX != USHRT_MAX ? nRangeX : nXScroll);
421 		pPt->X() = Max( ::GetLeftMargin( *this ) + nLeftOfst, pPt->X() );
422 		pPt->X() = Min( rRect.Left() - nScrollX, pPt->X() );
423 		pPt->X() = Max( 0L, pPt->X() );
424 	}
425 }
426 
427 /*--------------------------------------------------------------------
428 	Beschreibung:	Scrolling
429  --------------------------------------------------------------------*/
430 
431 sal_Bool SwView::IsScroll( const Rectangle &rRect ) const
432 {
433 	return bCenterCrsr || bTopCrsr || !aVisArea.IsInside(rRect);
434 }
435 
436 
437 void SwView::Scroll( const Rectangle &rRect, sal_uInt16 nRangeX, sal_uInt16 nRangeY )
438 {
439 	if ( aVisArea.IsEmpty() )
440 		return;
441 
442 	Rectangle aOldVisArea( aVisArea );
443 	long nDiffY = 0;
444 
445 	Window* pCareWn = ViewShell::GetCareWin(GetWrtShell());
446 	if ( pCareWn )
447 	{
448         Rectangle aDlgRect( GetEditWin().PixelToLogic(
449                 pCareWn->GetWindowExtentsRelative( &GetEditWin() ) ) );
450 		// Nur, wenn der Dialog nicht rechts oder links der VisArea liegt:
451 		if ( aDlgRect.Left() < aVisArea.Right() &&
452 			 aDlgRect.Right() > aVisArea.Left() )
453 		{
454 			// Falls wir nicht zentriert werden sollen, in der VisArea liegen
455 			// und nicht vom Dialog ueberdeckt werden ...
456 			if ( !bCenterCrsr && aOldVisArea.IsInside( rRect )
457 				 && ( rRect.Left() > aDlgRect.Right()
458 					  || rRect.Right() < aDlgRect.Left()
459 					  || rRect.Top() > aDlgRect.Bottom()
460 					  || rRect.Bottom() < aDlgRect.Top() ) )
461 				return;
462 
463 			// Ist oberhalb oder unterhalb der Dialogs mehr Platz?
464 			long nTopDiff = aDlgRect.Top() - aVisArea.Top();
465 			long nBottomDiff = aVisArea.Bottom() - aDlgRect.Bottom();
466 			if ( nTopDiff < nBottomDiff )
467 			{
468 				if ( nBottomDiff > 0 ) // Ist unterhalb ueberhaupt Platz?
469 				{	// dann verschieben wir die Oberkante und merken uns dies
470 					nDiffY = aDlgRect.Bottom() - aVisArea.Top();
471 					aVisArea.Top() += nDiffY;
472 				}
473 			}
474 			else
475 			{
476 				if ( nTopDiff > 0 ) // Ist oberhalb ueberhaupt Platz?
477 					aVisArea.Bottom() = aDlgRect.Top(); // Unterkante aendern
478 			}
479 		}
480 	}
481 
482 	//s.o. !IsScroll()
483 	if( !(bCenterCrsr || bTopCrsr) && aVisArea.IsInside( rRect ) )
484 	{
485 		aVisArea = aOldVisArea;
486 		return;
487 	}
488 	//falls das Rechteck groesser als der sichtbare Bereich -->
489 	//obere linke Ecke
490 	Size aSize( rRect.GetSize() );
491 	const Size aVisSize( aVisArea.GetSize() );
492 	if( !aVisArea.IsEmpty() && (
493 		aSize.Width() + GetXScroll() > aVisSize.Width() ||
494 		aSize.Height()+ GetYScroll() > aVisSize.Height() ))
495 	{
496 		Point aPt( aVisArea.TopLeft() );
497 		aSize.Width() = Min( aSize.Width(), aVisSize.Width() );
498 		aSize.Height()= Min( aSize.Height(),aVisSize.Height());
499 
500 		CalcPt( &aPt, Rectangle( rRect.TopLeft(), aSize ),
501                 static_cast< sal_uInt16 >((aVisSize.Width() - aSize.Width()) / 2),
502                 static_cast< sal_uInt16 >((aVisSize.Height()- aSize.Height())/ 2) );
503 
504 		if( bTopCrsr )
505 		{
506 			const long nBorder = IsDocumentBorder() ? DOCUMENTBORDER : 0;
507 			aPt.Y() = Min( Max( nBorder, rRect.Top() ),
508 								aDocSz.Height() + nBorder -
509 									aVisArea.GetHeight() );
510 		}
511 		aPt.Y() -= nDiffY;
512 		aVisArea = aOldVisArea;
513 		SetVisArea( aPt );
514 		return;
515 	}
516 	if( !bCenterCrsr )
517 	{
518 		Point aPt( aVisArea.TopLeft() );
519 		CalcPt( &aPt, rRect, nRangeX, nRangeY );
520 
521 		if( bTopCrsr )
522 		{
523 			const long nBorder = IsDocumentBorder() ? DOCUMENTBORDER : 0;
524 			aPt.Y() = Min( Max( nBorder, rRect.Top() ),
525 								aDocSz.Height() + nBorder -
526 									aVisArea.GetHeight() );
527 		}
528 
529 		aPt.Y() -= nDiffY;
530 		aVisArea = aOldVisArea;
531 		SetVisArea( aPt );
532 		return;
533 	}
534 
535 	//Cursor zentrieren
536 	Point aPnt( aVisArea.TopLeft() );
537 	// ... in Y-Richtung auf jeden Fall
538 	aPnt.Y() += ( rRect.Top() + rRect.Bottom()
539 				  - aVisArea.Top() - aVisArea.Bottom() ) / 2 - nDiffY;
540 	// ... in X-Richtung nur, wenn das Rechteck rechts oder links aus der
541 	//	   VisArea hinausragt.
542 	if ( rRect.Right() > aVisArea.Right() || rRect.Left() < aVisArea.Left() )
543 	{
544 		aPnt.X() += ( rRect.Left() + rRect.Right()
545 				  - aVisArea.Left() - aVisArea.Right() ) / 2;
546 		aPnt.X() = SetHScrollMax( aPnt.X() );
547 		const SwTwips lMin = IsDocumentBorder() ? DOCUMENTBORDER : 0;
548 		aPnt.X() = Max( (GetLeftMargin( *this ) - lMin) + nLeftOfst, aPnt.X() );
549 	}
550 	aVisArea = aOldVisArea;
551 	if( pCareWn )
552 	{   // Wenn wir nur einem Dialog ausweichen wollen, wollen wir nicht ueber
553 		// das Ende des Dokument hinausgehen.
554 		aPnt.Y() = SetVScrollMax( aPnt.Y() );
555 	}
556 	SetVisArea( aPnt );
557 }
558 
559 /*--------------------------------------------------------------------
560 	Beschreibung:	Seitenweises Scrollen
561 	Liefern den Wert, um den bei PageUp / -Down gescrollt werden soll
562  --------------------------------------------------------------------*/
563 
564 sal_Bool SwView::GetPageScrollUpOffset( SwTwips &rOff ) const
565 {
566 	if ( !aVisArea.Top() || !aVisArea.GetHeight() )
567 		return sal_False;
568 	long nYScrl = GetYScroll() / 2;
569 	rOff = -(aVisArea.GetHeight() - nYScrl);
570 	//nicht vor den Dokumentanfang scrollen
571 	if( aVisArea.Top() - rOff < 0 )
572 		rOff = rOff - aVisArea.Top();
573 	else if( GetWrtShell().GetCharRect().Top() < (aVisArea.Top() + nYScrl))
574 		rOff += nYScrl;
575 	return sal_True;
576 }
577 
578 
579 sal_Bool SwView::GetPageScrollDownOffset( SwTwips &rOff ) const
580 {
581 	if ( !aVisArea.GetHeight() ||
582 		 (aVisArea.GetHeight() > aDocSz.Height()) )
583 		return sal_False;
584 	long nYScrl = GetYScroll() / 2;
585 	rOff = aVisArea.GetHeight() - nYScrl;
586 	//nicht hinter das Dokumentende scrollen
587 	if ( aVisArea.Top() + rOff > aDocSz.Height() )
588 		rOff = aDocSz.Height() - aVisArea.Bottom();
589 	else if( GetWrtShell().GetCharRect().Bottom() >
590 											( aVisArea.Bottom() - nYScrl ))
591 		rOff -= nYScrl;
592 	return rOff > 0;
593 }
594 
595 // Seitenweises Blaettern
596 
597 long SwView::PageUp()
598 {
599 	if (!aVisArea.GetHeight())
600 		return 0;
601 
602 	Point aPos(aVisArea.TopLeft());
603 	aPos.Y() -= aVisArea.GetHeight() - (GetYScroll() / 2);
604 	aPos.Y() = Max(0L, aPos.Y());
605 	SetVisArea( aPos );
606 	return 1;
607 }
608 
609 
610 long SwView::PageDown()
611 {
612 	if ( !aVisArea.GetHeight() )
613 		return 0;
614 	Point aPos( aVisArea.TopLeft() );
615 	aPos.Y() += aVisArea.GetHeight() - (GetYScroll() / 2);
616 	aPos.Y() = SetVScrollMax( aPos.Y() );
617 	SetVisArea( aPos );
618 	return 1;
619 }
620 
621 
622 long SwView::PhyPageUp()
623 {
624 	//aktuell sichtbare Seite erfragen, nicht formatieren
625 	sal_uInt16 nActPage = pWrtShell->GetNextPrevPageNum( sal_False );
626 
627 	if( USHRT_MAX != nActPage )
628 	{
629 		const Point aPt( aVisArea.Left(),
630 						 pWrtShell->GetPagePos( nActPage ).Y() );
631 		Point aAlPt( AlignToPixel( aPt ) );
632 		// falls ein Unterschied besteht, wurde abgeschnitten --> dann
633 		// einen Pixel addieren, damit kein Rest der Vorgaengerseite
634 		// sichtbar ist
635 		if( aPt.Y() != aAlPt.Y() )
636 			aAlPt.Y() += 3 * GetEditWin().PixelToLogic( Size( 0, 1 ) ).Height();
637 		SetVisArea( aAlPt );
638 	}
639 	return 1;
640 }
641 
642 
643 long SwView::PhyPageDown()
644 {
645 	//aktuell sichtbare Seite erfragen, nicht formatieren
646 	sal_uInt16 nActPage = pWrtShell->GetNextPrevPageNum( sal_True );
647 	// falls die letzte Dokumentseite sichtbar ist, nichts tun
648 	if( USHRT_MAX != nActPage )
649 	{
650 		const Point aPt( aVisArea.Left(),
651 						 pWrtShell->GetPagePos( nActPage ).Y() );
652 		Point aAlPt( AlignToPixel( aPt ) );
653 		// falls ein Unterschied besteht, wurde abgeschnitten --> dann
654 		// einen Pixel addieren, damit kein Rest der Vorgaengerseite sichtbar ist
655 		if( aPt.Y() != aAlPt.Y() )
656 			aAlPt.Y() += 3 * GetEditWin().PixelToLogic( Size( 0, 1 ) ).Height();
657 		SetVisArea( aAlPt );
658 	}
659 	return 1;
660 }
661 
662 
663 long SwView::PageUpCrsr( sal_Bool bSelect )
664 {
665 	if ( !bSelect )
666 	{
667 		const sal_uInt16 eType = pWrtShell->GetFrmType(0,sal_True);
668 		if ( eType & FRMTYPE_FOOTNOTE )
669 		{
670 			pWrtShell->MoveCrsr();
671 			pWrtShell->GotoFtnAnchor();
672 			pWrtShell->Right(CRSR_SKIP_CHARS, sal_False, 1, sal_False );
673 			return 1;
674 		}
675 	}
676 
677 	SwTwips lOff = 0;
678 	if ( GetPageScrollUpOffset( lOff ) &&
679 		 (pWrtShell->IsCrsrReadonly() ||
680 		  !pWrtShell->PageCrsr( lOff, bSelect )) &&
681 		 PageUp() )
682 	{
683 		pWrtShell->ResetCursorStack();
684 		return sal_True;
685 	}
686 	return sal_False;
687 }
688 
689 
690 long SwView::PageDownCrsr(sal_Bool bSelect)
691 {
692 	SwTwips lOff = 0;
693 	if ( GetPageScrollDownOffset( lOff ) &&
694 		 (pWrtShell->IsCrsrReadonly() ||
695 		  !pWrtShell->PageCrsr( lOff, bSelect )) &&
696 		 PageDown() )
697 	{
698 		pWrtShell->ResetCursorStack();
699 		return sal_True;
700 	}
701 	return sal_False;
702 }
703 
704 /*------------------------------------------------------------------------
705  Beschreibung:	Handler der Scrollbars
706 ------------------------------------------------------------------------*/
707 
708 IMPL_LINK( SwView, ScrollHdl, SwScrollbar *, pScrollbar )
709 {
710 	if ( GetWrtShell().ActionPend() )
711 		return 0;
712 
713 	if ( pScrollbar->GetType() == SCROLL_DRAG )
714 		pWrtShell->EnableSmooth( sal_False );
715 
716 	if(!pWrtShell->GetViewOptions()->getBrowseMode() &&
717 		pScrollbar->GetType() == SCROLL_DRAG)
718 	{
719 		//Hier wieder auskommentieren wenn das mitscrollen nicht gewuenscht ist.
720 		// JP 21.07.00: the end scrollhandler invalidate the FN_STAT_PAGE,
721 		// 				so we dont must do it agin.
722 		EndScrollHdl(pScrollbar);
723 
724 		Point aPos( aVisArea.TopLeft() );
725 		lcl_GetPos(this, aPos, pScrollbar, IsDocumentBorder());
726 
727 		sal_uInt16 nPhNum = 1;
728 		sal_uInt16 nVirtNum = 1;
729 
730 		String sDisplay;
731 		if(pWrtShell->GetPageNumber( aPos.Y(), sal_False, nPhNum, nVirtNum, sDisplay ))
732 		{
733 			// JP 21.07.00: the end scrollhandler invalidate the FN_STAT_PAGE,
734 			// 				so we dont must do it agin.
735 //          if(!GetViewFrame()->GetFrame().IsInPlace())
736 //				S F X_BINDINGS().Update(FN_STAT_PAGE);
737 
738 			//QuickHelp:
739             if( pWrtShell->GetPageCnt() > 1 && Help::IsQuickHelpEnabled() )
740 			{
741 				if( !nPgNum || nPgNum != nPhNum )
742 				{
743 					Rectangle aRect;
744 					aRect.Left() = pScrollbar->GetParent()->OutputToScreenPixel(
745 										pScrollbar->GetPosPixel() ).X() -8;
746 					aRect.Top() = pScrollbar->OutputToScreenPixel(
747 									pScrollbar->GetPointerPosPixel() ).Y();
748 					aRect.Right() 	= aRect.Left();
749 					aRect.Bottom()	= aRect.Top();
750 
751 					String sPageStr( GetPageStr( nPhNum, nVirtNum, sDisplay ));
752 					SwContentAtPos aCnt( SwContentAtPos::SW_OUTLINE );
753 					pWrtShell->GetContentAtPos( aPos, aCnt );
754 					if( aCnt.sStr.Len() )
755 					{
756 						sPageStr += String::CreateFromAscii(
757 										RTL_CONSTASCII_STRINGPARAM( "  - " ));
758 						sPageStr.Insert( aCnt.sStr, 0, 80 );
759 						sPageStr.SearchAndReplaceAll( '\t', ' ' );
760                         sPageStr.SearchAndReplaceAll( 0x0a, ' ' );
761                     }
762 
763 					Help::ShowQuickHelp( pScrollbar, aRect, sPageStr,
764 									QUICKHELP_RIGHT|QUICKHELP_VCENTER);
765 				}
766 				nPgNum = nPhNum;
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 
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 
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 
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 
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 
1025 void SwView::ShowAtResize()
1026 {
1027 	bShowAtResize = sal_False;
1028     if ( pWrtShell->GetViewOptions()->IsViewHRuler() )
1029         pHRuler->Show();
1030 }
1031 
1032 
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 
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 
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 
1274 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 
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 
1345 void SwView::Move()
1346 {
1347 	if ( GetWrtShell().IsInSelect() )
1348 		GetWrtShell().EndSelect();	//#32427#
1349 	SfxViewShell::Move();
1350 }
1351 
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