xref: /aoo42x/main/sw/source/ui/uiview/viewport.cxx (revision efeef26f)
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 
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 
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 
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 
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 
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 
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 
169 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 
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 
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 
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 
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 
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 
427 sal_Bool SwView::IsScroll( const Rectangle &rRect ) const
428 {
429 	return bCenterCrsr || bTopCrsr || !aVisArea.IsInside(rRect);
430 }
431 
432 
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 
560 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 
575 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 
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 
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 
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 
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 
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 
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 
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 		Point aPos( aVisArea.TopLeft() );
721 		lcl_GetPos(this, aPos, pScrollbar, IsDocumentBorder());
722 
723 		sal_uInt16 nPhNum = 1;
724 		sal_uInt16 nVirtNum = 1;
725 
726 		String sDisplay;
727 		if(pWrtShell->GetPageNumber( aPos.Y(), sal_False, nPhNum, nVirtNum, sDisplay ))
728 		{
729 			// JP 21.07.00: the end scrollhandler invalidate the FN_STAT_PAGE,
730 			// 				so we dont must do it agin.
731 //          if(!GetViewFrame()->GetFrame().IsInPlace())
732 //				S F X_BINDINGS().Update(FN_STAT_PAGE);
733 
734 			//QuickHelp:
735             if( pWrtShell->GetPageCnt() > 1 && Help::IsQuickHelpEnabled() )
736 			{
737 				if( !nPgNum || nPgNum != nPhNum )
738 				{
739 					Rectangle aRect;
740 					aRect.Left() = pScrollbar->GetParent()->OutputToScreenPixel(
741 										pScrollbar->GetPosPixel() ).X() -8;
742 					aRect.Top() = pScrollbar->OutputToScreenPixel(
743 									pScrollbar->GetPointerPosPixel() ).Y();
744 					aRect.Right() 	= aRect.Left();
745 					aRect.Bottom()	= aRect.Top();
746 
747 					String sPageStr( GetPageStr( nPhNum, nVirtNum, sDisplay ));
748 					SwContentAtPos aCnt( SwContentAtPos::SW_OUTLINE );
749 					pWrtShell->GetContentAtPos( aPos, aCnt );
750 					if( aCnt.sStr.Len() )
751 					{
752 						sPageStr += String::CreateFromAscii(
753 										RTL_CONSTASCII_STRINGPARAM( "  - " ));
754 						sPageStr.Insert( aCnt.sStr, 0, 80 );
755 						sPageStr.SearchAndReplaceAll( '\t', ' ' );
756                         sPageStr.SearchAndReplaceAll( 0x0a, ' ' );
757                     }
758 
759 					Help::ShowQuickHelp( pScrollbar, aRect, sPageStr,
760 									QUICKHELP_RIGHT|QUICKHELP_VCENTER);
761 				}
762 				nPgNum = nPhNum;
763 			}
764 		}
765 	}
766 	else
767 		EndScrollHdl(pScrollbar);
768 
769 	if ( pScrollbar->GetType() == SCROLL_DRAG )
770 		pWrtShell->EnableSmooth( sal_True );
771 
772 	return 0;
773 }
774 /*------------------------------------------------------------------------
775  Beschreibung:	Handler der Scrollbars
776 ------------------------------------------------------------------------*/
777 
778 IMPL_LINK( SwView, EndScrollHdl, SwScrollbar *, pScrollbar )
779 {
780 	if ( !GetWrtShell().ActionPend() )
781 	{
782 		if(nPgNum)
783 		{
784 			nPgNum = 0;
785 			Help::ShowQuickHelp(pScrollbar, Rectangle(), aEmptyStr, 0);
786 		}
787 		Point aPos( aVisArea.TopLeft() );
788 		sal_Bool bBorder = IsDocumentBorder();
789 		lcl_GetPos(this, aPos, pScrollbar, bBorder);
790 		if ( bBorder && aPos == aVisArea.TopLeft() )
791 			UpdateScrollbars();
792 		else
793 			SetVisArea( aPos, sal_False );
794 
795 		GetViewFrame()->GetBindings().Update(FN_STAT_PAGE);
796 	}
797 	return 0;
798 }
799 
800 /*--------------------------------------------------------------------
801 	Beschreibung:
802 
803 		berechnet die Groesse von aVisArea abhaengig von der Groesse
804 		des EditWin auf dem Schirm.
805 
806  --------------------------------------------------------------------*/
807 
808 void SwView::CalcVisArea( const Size &rOutPixel )
809 {
810 	Point aTopLeft;
811 	Rectangle aRect( aTopLeft, rOutPixel );
812 	aTopLeft = GetEditWin().PixelToLogic( aTopLeft );
813 	Point aBottomRight( GetEditWin().PixelToLogic( aRect.BottomRight() ) );
814 
815 	aRect.Left() = aTopLeft.X();
816 	aRect.Top() = aTopLeft.Y();
817 	aRect.Right() = aBottomRight.X();
818 	aRect.Bottom() = aBottomRight.Y();
819 
820 	//Die Verschiebungen nach rechts und/oder unten koennen jetzt falsch
821 	//sein (z.B. Zoom aendern, Viewgroesse aendern.
822 	const long lBorder = IsDocumentBorder() ? DOCUMENTBORDER : DOCUMENTBORDER*2;
823 	if ( aRect.Left() )
824 	{
825 		const long lWidth = GetWrtShell().GetDocSize().Width() + lBorder;
826 		if ( aRect.Right() > lWidth )
827 		{
828 			long lDelta    = aRect.Right() - lWidth;
829 			aRect.Left()  -= lDelta;
830 			aRect.Right() -= lDelta;
831 		}
832 	}
833 	if ( aRect.Top() )
834 	{
835 		const long lHeight = GetWrtShell().GetDocSize().Height() + lBorder;
836 		if ( aRect.Bottom() > lHeight )
837 		{
838 			long lDelta		= aRect.Bottom() - lHeight;
839 			aRect.Top()	   -= lDelta;
840 			aRect.Bottom() -= lDelta;
841 		}
842 	}
843 	SetVisArea( aRect );
844 	GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOM );
845     GetViewFrame()->GetBindings().Invalidate( SID_ATTR_ZOOMSLIDER ); // for snapping points
846 }
847 
848 /*--------------------------------------------------------------------
849 	Beschreibung:	Bedienelemente neu anordnen
850  --------------------------------------------------------------------*/
851 
852 
853 void SwView::CalcAndSetBorderPixel( SvBorder &rToFill, sal_Bool /*bInner*/ )
854 {
855 	sal_Bool bRightVRuler = pWrtShell->GetViewOptions()->IsVRulerRight();
856     if ( pVRuler->IsVisible() )
857 	{
858         long nWidth = pVRuler->GetSizePixel().Width();
859 		if(bRightVRuler)
860             rToFill.Right() = nWidth;
861 		else
862 			rToFill.Left() = nWidth;
863 	}
864 
865     DBG_ASSERT(pHRuler, "warum ist das Lineal nicht da?");
866     if ( pHRuler->IsVisible() )
867         rToFill.Top() = pHRuler->GetSizePixel().Height();
868 
869 	const StyleSettings &rSet = GetEditWin().GetSettings().GetStyleSettings();
870 	const long nTmp = rSet.GetScrollBarSize();
871     if( pVScrollbar->IsVisible(sal_False) )
872 	{
873 		if(bRightVRuler)
874             rToFill.Left() = nTmp;
875 		else
876 			rToFill.Right()  = nTmp;
877 	}
878     //#i32913# in browse mode the visibility of the horizontal scrollbar
879     // depends on the content (fixed width tables may require a scrollbar)
880     if ( pHScrollbar->IsVisible(pWrtShell->GetViewOptions()->getBrowseMode()) )
881 		rToFill.Bottom() = nTmp;
882 
883 	SetBorderPixel( rToFill );
884 }
885 
886 
887 void ViewResizePixel( const Window &rRef,
888 					const Point &rOfst,
889 					const Size &rSize,
890 					const Size &rEditSz,
891 					const sal_Bool /*bInner*/,
892                     SwScrollbar& rVScrollbar,
893                     SwScrollbar& rHScrollbar,
894 					ImageButton* pPageUpBtn,
895 					ImageButton* pPageDownBtn,
896 					ImageButton* pNaviBtn,
897                     Window& rScrollBarBox,
898 					SvxRuler* pVLineal,
899 					SvxRuler* pHLineal,
900                     sal_Bool bWebView,
901                     sal_Bool bVRulerRight )
902 {
903 // ViewResizePixel wird auch von der PreView benutzt!!!
904 
905 	const sal_Bool bHLineal = pHLineal && pHLineal->IsVisible();
906 	const long nHLinSzHeight = bHLineal ?
907 						pHLineal->GetSizePixel().Height() : 0;
908     const sal_Bool bVLineal = pVLineal && pVLineal->IsVisible();
909     const long nVLinSzWidth = bVLineal ?
910 						pVLineal->GetSizePixel().Width() : 0;
911     long nHBSzHeight2= rHScrollbar.IsVisible( sal_False ) || !rHScrollbar.IsAuto() ?
912 					   rRef.GetSettings().GetStyleSettings().GetScrollBarSize() : 0;
913     long nHBSzHeight =
914 				rHScrollbar.IsVisible(sal_True) ||  (rHScrollbar.IsVisible( sal_False ) && !rHScrollbar.IsAuto()) ?
915 								nHBSzHeight2:0;
916     long nVBSzWidth = rVScrollbar.IsVisible(sal_True) ||  (rVScrollbar.IsVisible( sal_False ) && !rVScrollbar.IsAuto()) ?
917                          rRef.GetSettings().GetStyleSettings().GetScrollBarSize() : 0;
918 
919     if(pVLineal)
920     {
921         WinBits nStyle = pVLineal->GetStyle()&~WB_RIGHT_ALIGNED;
922         Point aPos( rOfst.X(), rOfst.Y()+nHLinSzHeight );
923 		if(bVRulerRight)
924 		{
925             aPos.X() += rSize.Width() - nVLinSzWidth;
926             nStyle |= WB_RIGHT_ALIGNED;
927         }
928         Size  aSize( nVLinSzWidth, rEditSz.Height() );
929 		if(!aSize.Width())
930 			aSize.Width() = pVLineal->GetSizePixel().Width();
931         pVLineal->SetStyle(nStyle);
932         pVLineal->SetPosSizePixel( aPos, aSize );
933         if(!pVLineal->IsVisible())
934             pVLineal->Resize();
935     }
936 //  Lineal braucht ein Resize, sonst funktioniert es nicht im unischtbaren Zustand
937     if(pHLineal)
938     {
939 		Size aSize( rSize.Width(), nHLinSzHeight );
940         if ( nVBSzWidth && !bVRulerRight)
941 			aSize.Width() -= nVBSzWidth;
942 		if(!aSize.Height())
943 			aSize.Height() = pHLineal->GetSizePixel().Height();
944 		pHLineal->SetPosSizePixel( rOfst, aSize );
945 //		#46802 VCL ruft an unsichtbaren Fenstern kein Resize
946 //      fuer das Lineal ist das aber keine gute Idee
947 		if(!pHLineal->IsVisible())
948 			pHLineal->Resize();
949 	}
950 
951 	// Scrollbars und SizeBox anordnen
952 	Point aScrollFillPos;
953 	{
954 		Point aPos( rOfst.X(),
955 					rOfst.Y()+rSize.Height()-nHBSzHeight );
956         if(bVRulerRight)
957         {
958             aPos.X() += nVBSzWidth;
959         }
960 
961 		Size  aSize( rSize.Width(), nHBSzHeight2 );
962 		if ( nVBSzWidth )
963 			aSize.Width() -= nVBSzWidth;
964         rHScrollbar.SetPosSizePixel( aPos, aSize );
965 		aScrollFillPos.Y() = aPos.Y();
966 	}
967 	{
968 		Point aPos( rOfst.X()+rSize.Width()-nVBSzWidth,
969 					rOfst.Y() );
970         Size  aSize( nVBSzWidth, rSize.Height() );
971         if(bVRulerRight)
972 		{
973 			aPos.X() = rOfst.X();
974             if(bHLineal)
975             {
976                 aPos.Y() += nHLinSzHeight;
977                 aSize.Height() -= nHLinSzHeight;
978             }
979 		}
980 
981         Size  aImgSz( nVBSzWidth, nVBSzWidth );
982 
983 		//#55949#  wenn der Platz fuer Scrollbar und Page-Buttons zu klein wird, dann
984 		// werden die Buttons versteckt
985 		sal_uInt16 nCnt = pNaviBtn ? 3 : 2;
986 		long nSubSize = (aImgSz.Width() * nCnt );
987 		//
988 		sal_Bool bHidePageButtons = aSize.Height() < ((bWebView ? 3 : 2) * nSubSize);
989 		if(!bHidePageButtons)
990 			aSize.Height() -= nSubSize;
991 		else
992 			aImgSz.Width() = 0;	// kein Hide, weil das im Update Scrollbar missverstanden wird
993 
994 		if ( nHBSzHeight )
995 			aSize.Height() -= nHBSzHeight;
996         rVScrollbar.SetPosSizePixel( aPos, aSize );
997 
998 		aPos.Y() += aSize.Height();
999 		pPageUpBtn->SetPosSizePixel( aPos, aImgSz );
1000 		if(pNaviBtn)
1001 		{
1002 			aPos.Y() += aImgSz.Height();
1003 			pNaviBtn->SetPosSizePixel(aPos, aImgSz);
1004 		}
1005 
1006 		aPos.Y() += aImgSz.Height();
1007 		pPageDownBtn->SetPosSizePixel( aPos, aImgSz );
1008 
1009 
1010         if( rHScrollbar.IsVisible( sal_False ) )
1011 		{
1012 			aScrollFillPos.X() = aPos.X();
1013 
1014             rScrollBarBox.SetPosSizePixel( aScrollFillPos,
1015 										 Size( nHBSzHeight,	nVBSzWidth) );
1016         }
1017 	}
1018 }
1019 
1020 
1021 void SwView::ShowAtResize()
1022 {
1023 	bShowAtResize = sal_False;
1024     if ( pWrtShell->GetViewOptions()->IsViewHRuler() )
1025         pHRuler->Show();
1026 }
1027 
1028 
1029 void SwView::InnerResizePixel( const Point &rOfst, const Size &rSize )
1030 {
1031     Size aObjSize = GetObjectShell()->GetVisArea().GetSize();
1032     if ( aObjSize.Width() > 0 && aObjSize.Height() > 0 )
1033     {
1034         SvBorder aBorder( GetBorderPixel() );
1035         Size aSize( rSize );
1036         aSize.Width() -= (aBorder.Left() + aBorder.Right());
1037         aSize.Height() -= (aBorder.Top() + aBorder.Bottom());
1038         Size aObjSizePixel = GetWindow()->LogicToPixel( aObjSize, MAP_TWIP );
1039         SfxViewShell::SetZoomFactor( Fraction( aSize.Width(), aObjSizePixel.Width() ),
1040                         Fraction( aSize.Height(), aObjSizePixel.Height() ) );
1041     }
1042 
1043     bInInnerResizePixel = sal_True;
1044     const sal_Bool bHScrollVisible = pHScrollbar->IsVisible(sal_True);
1045     const sal_Bool bVScrollVisible = pVScrollbar->IsVisible(sal_True);
1046 	sal_Bool bRepeat = sal_False;
1047 	do
1048 	{
1049 		Size aSz( rSize );
1050         SvBorder aBorder;
1051         CalcAndSetBorderPixel( aBorder, sal_True );
1052         if ( GetViewFrame()->GetFrame().IsInPlace() )
1053         {
1054             Size aViewSize( aSz );
1055             Point aViewPos( rOfst );
1056             aViewSize.Height() -= (aBorder.Top() + aBorder.Bottom());
1057             aViewSize.Width()  -= (aBorder.Left() + aBorder.Right());
1058             aViewPos.X() += aBorder.Left();
1059             aViewPos.Y() += aBorder.Top();
1060             GetEditWin().SetPosSizePixel( aViewPos, aViewSize );
1061         }
1062         else
1063         {
1064             aSz.Height() += aBorder.Top()  + aBorder.Bottom();
1065             aSz.Width()  += aBorder.Left() + aBorder.Right();
1066         }
1067 
1068 		Size aEditSz( GetEditWin().GetOutputSizePixel() );
1069 		ViewResizePixel( GetEditWin(), rOfst, aSz, aEditSz, sal_True, *pVScrollbar,
1070                             *pHScrollbar, pPageUpBtn, pPageDownBtn,
1071 							pNaviBtn,
1072                             *pScrollFill, pVRuler, pHRuler,
1073                             0 != PTR_CAST(SwWebView, this),
1074                             pWrtShell->GetViewOptions()->IsVRulerRight());
1075 		if ( bShowAtResize )
1076 			ShowAtResize();
1077 
1078 		if( pHRuler->IsVisible() || pVRuler->IsVisible() )
1079 		{
1080 			const Fraction& rFrac = GetEditWin().GetMapMode().GetScaleX();
1081             sal_uInt16 nZoom = 100;
1082             if (0 != rFrac.GetDenominator())
1083                 nZoom = sal_uInt16(rFrac.GetNumerator() * 100L / rFrac.GetDenominator());
1084 
1085 			const Fraction aFrac( nZoom, 100 );
1086 			pVRuler->SetZoom( aFrac );
1087 			pHRuler->SetZoom( aFrac );
1088 			InvalidateRulerPos();	//Inhalt invalidieren.
1089 		}
1090 		//CursorStack zuruecksetzen, da die Cursorpositionen fuer PageUp/-Down
1091 		//nicht mehr zum aktuell sichtbaren Bereich passen
1092 		pWrtShell->ResetCursorStack();
1093 
1094 		//EditWin niemals einstellen!
1095 
1096 		//VisArea einstellen, aber dort nicht das SetVisArea der DocShell rufen!
1097 		bProtectDocShellVisArea = sal_True;
1098 		CalcVisArea( aEditSz );
1099 		//visibility changes of the automatic horizontal scrollbar
1100 		//require to repeat the ViewResizePixel() call - but only once!
1101 		if(bRepeat)
1102 			bRepeat = sal_False;
1103 		else if(bHScrollVisible != pHScrollbar->IsVisible(sal_True) ||
1104 				bVScrollVisible != pVScrollbar->IsVisible(sal_True))
1105 			bRepeat = sal_True;
1106 	}while( bRepeat );
1107 	bProtectDocShellVisArea = sal_False;
1108     bInInnerResizePixel = sal_False;
1109 }
1110 
1111 
1112 void SwView::OuterResizePixel( const Point &rOfst, const Size &rSize )
1113 {
1114     // FME 22.08.2003 #i16909# - return, if no size (caused by minimize window).
1115     if ( bInOuterResizePixel || ( !rSize.Width() && !rSize.Height() ) )
1116 		return;
1117 	bInOuterResizePixel	= sal_True;
1118 
1119 // feststellen, ob Scrollbars angezeigt werden duerfen
1120 	sal_Bool bBrowse = pWrtShell->GetViewOptions()->getBrowseMode();
1121 	sal_Bool bShowH = sal_False,
1122 		 bShowV = sal_False,
1123 		 bAuto  = sal_False,
1124 		 bHAuto = bBrowse;
1125 	switch( GetScrollingMode() )
1126 	{
1127 	case SCROLLING_DEFAULT:
1128 		{
1129 			const SwViewOption *pVOpt = pWrtShell->GetViewOptions();
1130 			if ( !pVOpt->IsReadonly() || pVOpt->IsStarOneSetting() )
1131 			{
1132 				bShowH = pVOpt->IsViewHScrollBar();
1133 				bShowV = pVOpt->IsViewVScrollBar();
1134 				break;
1135 			}
1136 		}
1137 		/* kein break hier */
1138 	case SCROLLING_AUTO:
1139 		bAuto = bHAuto = sal_True;
1140 		bShowH = bShowV = sal_True;
1141 		break;
1142 	case SCROLLING_YES:
1143 		bShowH = bShowV = sal_True;
1144 		break;
1145 	case SCROLLING_NO:
1146 		bShowH = bShowV = bHAuto = sal_False;
1147 		break;
1148 	}
1149     SwDocShell* pDocSh = GetDocShell();
1150     sal_Bool bIsPreview = pDocSh->IsPreview();
1151     if( bIsPreview )
1152     {
1153         bShowH = bShowV = bHAuto = bAuto = sal_False;
1154     }
1155     if(pHScrollbar->IsVisible(sal_False) != bShowH)
1156         ShowHScrollbar(bShowH);
1157     pHScrollbar->SetAuto( bHAuto );
1158     if(pVScrollbar->IsVisible(sal_False) != bShowV)
1159         ShowVScrollbar(bShowV);
1160     pVScrollbar->SetAuto(bAuto);
1161 
1162 	SET_CURR_SHELL( pWrtShell );
1163 	sal_Bool bRepeat = sal_False;
1164 	long nCnt = 0;
1165 
1166 	sal_Bool bUnLockView = !pWrtShell->IsViewLocked();
1167 	pWrtShell->LockView( sal_True );
1168 	pWrtShell->LockPaint();
1169 
1170 	do {
1171 		++nCnt;
1172         const sal_Bool bScroll1 = pVScrollbar->IsVisible(sal_True);
1173         const sal_Bool bScroll2 = pHScrollbar->IsVisible(sal_True);
1174 		SvBorder aBorder;
1175 		CalcAndSetBorderPixel( aBorder, sal_False );
1176 		const Size aEditSz( GetEditWin().GetOutputSizePixel() );
1177         ViewResizePixel( GetEditWin(), rOfst, rSize, aEditSz, sal_False, *pVScrollbar,
1178                                 *pHScrollbar, pPageUpBtn, pPageDownBtn,
1179 								pNaviBtn,
1180                                 *pScrollFill, pVRuler, pHRuler,
1181                                 0 != PTR_CAST(SwWebView, this),
1182                                 pWrtShell->GetViewOptions()->IsVRulerRight() );
1183 		if ( bShowAtResize )
1184 			ShowAtResize();
1185 
1186         if( pHRuler->IsVisible() || pVRuler->IsVisible() )
1187 			InvalidateRulerPos();	//Inhalt invalidieren.
1188 
1189 		//CursorStack zuruecksetzen, da die Cursorpositionen fuer PageUp/-Down
1190 		//nicht mehr zum aktuell sichtbaren Bereich passen
1191 		pWrtShell->ResetCursorStack();
1192 
1193         ASSERT( !GetEditWin().IsVisible() ||
1194                     (( aEditSz.Width() > 0 && aEditSz.Height() > 0 )
1195                         || !aVisArea.IsEmpty()), "Small world, isn't it?" );
1196 
1197 		//EditWin niemals einstellen!
1198 
1199 		//Die VisArea muss aber natuerlich eingestellt werden.
1200 		//jetzt ist auch der richtige Zeitpunkt den Zoom neu zu berechnen wenn
1201 		//es kein einfacher Faktor ist.
1202 		pWrtShell->StartAction();
1203 		CalcVisArea( aEditSz );
1204 
1205 		//Damit auch beim outplace editing die Seitenbreite sofort
1206 		//angepasst wird.
1207         //TODO/LATER: is that still necessary?!
1208         /*
1209         if ( pDocSh->GetCreateMode() == SFX_CREATE_MODE_EMBEDDED )
1210             pDocSh->SetVisArea(
1211                             pDocSh->SfxInPlaceObject::GetVisArea() );*/
1212 		if ( pWrtShell->GetViewOptions()->GetZoomType() != SVX_ZOOM_PERCENT &&
1213 			 !pWrtShell->GetViewOptions()->getBrowseMode() )
1214 			_SetZoom( aEditSz, (SvxZoomType)pWrtShell->GetViewOptions()->GetZoomType(), 100, sal_True );
1215 		pWrtShell->EndAction();
1216 
1217         bRepeat = bScroll1 != pVScrollbar->IsVisible(sal_True);
1218 		if ( !bRepeat )
1219             bRepeat = bScroll2 != pHScrollbar->IsVisible(sal_True);
1220 
1221 		//Nicht endlosschleifen. Moeglichst dann stoppen wenn die
1222 		//(Auto-)Scrollbars sichtbar sind.
1223 		if ( bRepeat &&
1224              ( nCnt > 10 || ( nCnt > 3 && bHAuto && bAuto ) )
1225            )
1226 		{
1227 			bRepeat = sal_False;
1228 		}
1229 
1230 	}while ( bRepeat );
1231 
1232 	if( pVScrollbar->IsVisible(sal_False) || pVScrollbar->IsAuto())
1233 	{
1234 		sal_Bool bShowButtons = pVScrollbar->IsVisible(sal_True);
1235 		if(pPageUpBtn && pPageUpBtn->IsVisible() != bShowButtons)
1236 		{
1237 			pPageUpBtn->Show(bShowButtons);
1238 			if(pPageDownBtn)
1239 				pPageDownBtn->Show(bShowButtons);
1240 			if(pNaviBtn)
1241 				pNaviBtn->Show(bShowButtons);
1242 		}
1243 	}
1244 
1245 	pWrtShell->UnlockPaint();
1246 	if( bUnLockView )
1247 		pWrtShell->LockView( sal_False );
1248 
1249     bInOuterResizePixel = sal_False;
1250 
1251 	if ( mpPostItMgr )
1252 	{
1253 		mpPostItMgr->CalcRects();
1254 		mpPostItMgr->LayoutPostIts();
1255 	}
1256 }
1257 
1258 
1259 void SwView::SetZoomFactor( const Fraction &rX, const Fraction &rY )
1260 {
1261 	const Fraction &rFrac = rX < rY ? rX : rY;
1262 	SetZoom( SVX_ZOOM_PERCENT, (short) long(rFrac * Fraction( 100, 1 )) );
1263 
1264 	//Um Rundungsfehler zu minimieren lassen wir von der Basisklasse ggf.
1265 	//auch die krummen Werte einstellen
1266 	SfxViewShell::SetZoomFactor( rX, rY );
1267 }
1268 
1269 
1270 Size SwView::GetOptimalSizePixel() const
1271 {
1272 	Size aPgSize;
1273 	if ( pWrtShell->GetViewOptions()->getBrowseMode() )
1274 		aPgSize = SvxPaperInfo::GetPaperSize(PAPER_A4);
1275 	else
1276 	{
1277         aPgSize = GetWrtShell().GetAnyCurRect(RECT_PAGE).SSize();
1278         aPgSize.Width() += DOCUMENTBORDER * 2;
1279 
1280         const SwPageDesc &rDesc = pWrtShell->GetPageDesc( pWrtShell->GetCurPageDesc() );
1281         if( nsUseOnPage::PD_MIRROR == rDesc.GetUseOn() )
1282 		{
1283             const SvxLRSpaceItem &rLRSpace = rDesc.GetMaster().GetLRSpace();
1284             const SvxLRSpaceItem &rLeftLRSpace = rDesc.GetLeft().GetLRSpace();
1285             aPgSize.Width() += Abs( long(rLeftLRSpace.GetLeft()) - long(rLRSpace.GetLeft()) );
1286 		}
1287     }
1288 	return GetEditWin().LogicToPixel( aPgSize );
1289 }
1290 
1291 
1292 sal_Bool SwView::UpdateScrollbars()
1293 {
1294     sal_Bool bRet = sal_False;
1295     if ( !aVisArea.IsEmpty() )
1296 	{
1297 		const sal_Bool bBorder = IsDocumentBorder();
1298 		Rectangle aTmpRect( aVisArea );
1299 		if ( bBorder )
1300 		{
1301 			Point aPt( DOCUMENTBORDER, DOCUMENTBORDER );
1302 			aPt = AlignToPixel( aPt );
1303 			aTmpRect.Move( -aPt.X(), -aPt.Y() );
1304 		}
1305 
1306 		Size aTmpSz( aDocSz );
1307 		const long lOfst = bBorder ? 0 : DOCUMENTBORDER * 2L;
1308 		aTmpSz.Width() += lOfst; aTmpSz.Height() += lOfst;
1309 
1310         {
1311             const sal_Bool bVScrollVisible = pVScrollbar->IsVisible(sal_True);
1312             pVScrollbar->DocSzChgd( aTmpSz );
1313             pVScrollbar->ViewPortChgd( aTmpRect );
1314 
1315             sal_Bool bShowButtons = pVScrollbar->IsVisible(sal_True);
1316             if(pPageUpBtn && pPageUpBtn->IsVisible() != bShowButtons)
1317             {
1318                 pPageUpBtn->Show(bShowButtons);
1319                 if(pPageDownBtn)
1320                     pPageDownBtn->Show(bShowButtons);
1321                 if(pNaviBtn)
1322                     pNaviBtn->Show(bShowButtons);
1323             }
1324 
1325             if ( bVScrollVisible != pVScrollbar->IsVisible(sal_True) )
1326                 bRet = sal_True;
1327         }
1328         {
1329             const sal_Bool bHScrollVisible = pHScrollbar->IsVisible(sal_True);
1330             pHScrollbar->DocSzChgd( aTmpSz );
1331             pHScrollbar->ViewPortChgd( aTmpRect );
1332             if ( bHScrollVisible != pHScrollbar->IsVisible(sal_True) )
1333                 bRet = sal_True;
1334             pScrollFill->Show(pHScrollbar->IsVisible(sal_True) && pVScrollbar->IsVisible(sal_True) );
1335         }
1336 	}
1337     return bRet;
1338 }
1339 
1340 
1341 void SwView::Move()
1342 {
1343 	if ( GetWrtShell().IsInSelect() )
1344 		GetWrtShell().EndSelect();	//#32427#
1345 	SfxViewShell::Move();
1346 }
1347 
1348 sal_Bool SwView::HandleWheelCommands( const CommandEvent& rCEvt )
1349 {
1350 	sal_Bool bOk = sal_False;
1351 	const CommandWheelData* pWData = rCEvt.GetWheelData();
1352 	if( pWData && COMMAND_WHEEL_ZOOM == pWData->GetMode() )
1353 	{
1354 		sal_uInt16 nFact = pWrtShell->GetViewOptions()->GetZoom();
1355 		if( 0L > pWData->GetDelta() )
1356             nFact = static_cast< sal_uInt16 >(Max( 20, nFact - 10 ));
1357 		else
1358             nFact = static_cast< sal_uInt16 >(Min( 600, nFact + 10 ));
1359 
1360 		SetZoom( SVX_ZOOM_PERCENT, nFact );
1361 		bOk = sal_True;
1362 	}
1363 	else
1364 	{
1365 		if (pWData && (COMMAND_WHEEL_SCROLL==pWData->GetMode()) && (((sal_uLong)0xFFFFFFFF) == pWData->GetScrollLines()))
1366         	{
1367                         if (pWData->GetDelta()<0)
1368                                 PhyPageDown();
1369                         else
1370                                 PhyPageUp();
1371                         bOk = sal_True;
1372                 }
1373 		else
1374 			bOk = pEditWin->HandleScrollCommand( rCEvt,
1375                     		pHScrollbar, pVScrollbar);
1376 	}
1377 	return bOk;
1378 }
1379 
1380 
1381