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