xref: /aoo4110/main/sw/source/core/view/viewsh.cxx (revision b1cdbd2c)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 // MARKER(update_precomp.py): autogen include statement, do not remove
23 #include "precompiled_sw.hxx"
24 
25 #define _SVX_PARAITEM_HXX
26 #define _SVX_TEXTITEM_HXX
27 
28 #include <com/sun/star/accessibility/XAccessible.hpp>
29 #include <sfx2/viewfrm.hxx>
30 #include <sfx2/progress.hxx>
31 #include <svx/srchdlg.hxx>
32 #include <svx/svdobj.hxx>
33 #include <sfx2/viewsh.hxx>
34 #include <swwait.hxx>
35 #include <swmodule.hxx>
36 #include <fesh.hxx>
37 #include <doc.hxx>
38 #include <rootfrm.hxx>
39 #include <pagefrm.hxx>
40 #include <cntfrm.hxx>
41 #include <viewimp.hxx>
42 #include <frmtool.hxx>
43 #include <viewopt.hxx>
44 #include <dview.hxx>
45 #include <swregion.hxx>
46 #include <hints.hxx>
47 #include <fmtfsize.hxx>
48 #include <docufld.hxx>
49 #include <txtfrm.hxx>
50 #include <layact.hxx>
51 #include <mdiexp.hxx>
52 #include <fntcache.hxx>
53 #include <ptqueue.hxx>
54 #include <tabfrm.hxx>
55 #include <docsh.hxx>
56 #include <pagedesc.hxx>
57 #include <ndole.hxx>
58 #include <ndindex.hxx>
59 #include <accmap.hxx>
60 #include <svtools/colorcfg.hxx>
61 #include <svtools/accessibilityoptions.hxx>
62 #include <accessibilityoptions.hxx>
63 #include <statstr.hrc>
64 #include <comcore.hrc>
65 #include <pagepreviewlayout.hxx>
66 #include <sortedobjs.hxx>
67 #include <anchoredobject.hxx>
68 #include "../../ui/inc/view.hxx"
69 #include <PostItMgr.hxx>
70 #include <vcl/virdev.hxx>
71 #include <vcl/svapp.hxx>
72 #include <svx/sdrpaintwindow.hxx>
73 #include <vcl/dibtools.hxx>
74 
75 sal_Bool ViewShell::bLstAct = sal_False;
76 ShellResource *ViewShell::pShellRes = 0;
77 Window *ViewShell::pCareWindow = 0;
78 BitmapEx* ViewShell::pErrorBmp = NULL;
79 BitmapEx* ViewShell::pReplaceBmp = NULL;
80 
81 sal_Bool bInSizeNotify = sal_False;
82 
83 DBG_NAME(LayoutIdle)
84 
85 TYPEINIT0(ViewShell);
86 
87 using namespace ::com::sun::star;
88 
89 //////////////////////////////////////////////////////////////////////////////
90 // #i72754# 2nd set of Pre/PostPaints
91 // This time it uses the lock counter mnPrePostPaintCount to allow only one activation
92 // and deactivation and mpPrePostOutDev to remember the OutDev from the BeginDrawLayers
93 // call. That way, all places where paint take place can be handled the same way, even
94 // when calling other paint methods. This is the case at the places where SW paints
95 // buffered into VDevs to avoid flicker. Tis is in general problematic and should be
96 // solved once using the BufferedOutput functionality of the DrawView.
97 
PrePaint()98 void ViewShell::PrePaint()
99 {
100     // forward PrePaint event from VCL Window to DrawingLayer
101     if(HasDrawView())
102     {
103         Imp()->GetDrawView()->PrePaint();
104     }
105 }
106 
DLPrePaint2(const Region & rRegion)107 void ViewShell::DLPrePaint2(const Region& rRegion)
108 {
109 	if(0L == mnPrePostPaintCount)
110 	{
111 		// #i75172# ensure DrawView to use DrawingLayer bufferings
112 		if ( !HasDrawView() )
113 			MakeDrawView();
114 
115 		// Prefer window; if tot available, get pOut (e.g. printer)
116 		mpPrePostOutDev = (GetWin() ? GetWin() : GetOut());
117 
118 		// #i74769# use SdrPaintWindow now direct
119 		mpTargetPaintWindow = Imp()->GetDrawView()->BeginDrawLayers(mpPrePostOutDev, rRegion);
120 		OSL_ENSURE(mpTargetPaintWindow, "BeginDrawLayers: Got no SdrPaintWindow (!)");
121 
122 		// #i74769# if prerender, save OutDev and redirect to PreRenderDevice
123 		if(mpTargetPaintWindow->GetPreRenderDevice())
124 		{
125 			mpBufferedOut = pOut;
126 			pOut = &(mpTargetPaintWindow->GetTargetOutputDevice());
127 		}
128 
129 		// remember original paint MapMode for wrapped FlyFrame paints
130 		maPrePostMapMode = pOut->GetMapMode();
131 	}
132 
133 	mnPrePostPaintCount++;
134 }
135 
DLPostPaint2(bool bPaintFormLayer)136 void ViewShell::DLPostPaint2(bool bPaintFormLayer)
137 {
138 	OSL_ENSURE(mnPrePostPaintCount > 0L, "ViewShell::DLPostPaint2: Pre/PostPaint encapsulation broken (!)");
139 	mnPrePostPaintCount--;
140 
141 	if((0L == mnPrePostPaintCount) && (0 != mpTargetPaintWindow))
142 	{
143 		// #i74769# restore buffered OutDev
144 		if(mpTargetPaintWindow->GetPreRenderDevice())
145 		{
146 			pOut = mpBufferedOut;
147 		}
148 
149 		// #i74769# use SdrPaintWindow now direct
150 		Imp()->GetDrawView()->EndDrawLayers(*mpTargetPaintWindow, bPaintFormLayer);
151 		mpTargetPaintWindow = 0;
152 	}
153 }
154 
155 //////////////////////////////////////////////////////////////////////////////
156 
157 /******************************************************************************
158 |*
159 |*	ViewShell::ImplEndAction()
160 |*
161 |*	Letzte Aenderung	MA 04. Sep. 96
162 |*
163 ******************************************************************************/
164 
ImplEndAction(const sal_Bool bIdleEnd)165 void ViewShell::ImplEndAction( const sal_Bool bIdleEnd )
166 {
167 	//Fuer den Drucker gibt es hier nichts zu tun.
168 	if ( !GetWin() || IsPreView() )
169 	{
170 		bPaintWorks = sal_True;
171 		UISizeNotify();
172 		return;
173 	}
174 
175 	bInEndAction = sal_True;
176 
177 	//Laeuft hiermit das EndAction der Letzten Shell im Ring?
178 	ViewShell::bLstAct = sal_True;
179 	ViewShell *pSh = (ViewShell*)this->GetNext();
180 	while ( pSh != this )
181 	{	if ( pSh->ActionPend() )
182 		{	ViewShell::bLstAct = sal_False;
183 			pSh = this;
184 		}
185 		else
186 			pSh = (ViewShell*)pSh->GetNext();
187 	}
188 
189     const bool bIsShellForCheckViewLayout = ( this == GetLayout()->GetCurrShell() );
190 
191 	SET_CURR_SHELL( this );
192 	if ( Imp()->HasDrawView() && !Imp()->GetDrawView()->areMarkHandlesHidden() )
193 		Imp()->StartAction();
194 
195 	if ( Imp()->GetRegion() && Imp()->GetRegion()->GetOrigin() != VisArea() )
196         Imp()->DelRegion();
197 
198 	const sal_Bool bExtraData = ::IsExtraData( GetDoc() );
199 
200 	if ( !bIdleEnd )
201 	{
202 		SwLayAction aAction( GetLayout(), Imp() );
203 		aAction.SetComplete( sal_False );
204 		if ( nLockPaint )
205 			aAction.SetPaint( sal_False );
206 		aAction.SetInputType( INPUT_KEYBOARD );
207 		aAction.Action();
208 	}
209 
210     if ( bIsShellForCheckViewLayout )
211         GetLayout()->CheckViewLayout( GetViewOptions(), &aVisArea );
212 
213 	//Wenn wir selbst keine Paints erzeugen, so warten wir auf das Paint
214 	//vom System. Dann ist das Clipping korrekt gesetzt; Beispiel: verschieben
215 	//eines DrawObjektes.
216     if ( Imp()->GetRegion()     ||
217          aInvalidRect.HasArea() ||
218          bExtraData )
219 	{
220 		if ( !nLockPaint )
221 		{
222 			sal_Bool bPaintsFromSystem = aInvalidRect.HasArea();
223 			GetWin()->Update();
224 			if ( aInvalidRect.HasArea() )
225 			{
226 				if ( bPaintsFromSystem )
227 					Imp()->AddPaintRect( aInvalidRect );
228 
229 				ResetInvalidRect();
230 				bPaintsFromSystem = sal_True;
231 			}
232 			bPaintWorks = sal_True;
233 
234 			SwRegionRects *pRegion = Imp()->GetRegion();
235 
236 			//JP 27.11.97: wer die Selection hided, muss sie aber auch
237 			//				wieder Showen. Sonst gibt es Paintfehler!
238 			//	z.B.: addional Mode, Seite vertikal hab zu sehen, in der
239 			// Mitte eine Selektion und mit einem anderen Cursor an linken
240 			// rechten Rand springen. Ohne ShowCrsr verschwindet die
241 			// Selektion
242             sal_Bool bShowCrsr = pRegion && IsA( TYPE(SwCrsrShell) );
243 			if( bShowCrsr )
244 				((SwCrsrShell*)this)->HideCrsrs();
245 
246 			if ( pRegion )
247 			{
248 				SwRootFrm* pCurrentLayout = GetLayout();
249 
250                 Imp()->pRegion = NULL;
251 
252                 //Erst Invert dann Compress, niemals andersherum!
253 				pRegion->Invert();
254 
255                 pRegion->Compress();
256 
257 				VirtualDevice *pVout = 0;
258 				while ( pRegion->Count() )
259 				{
260 					SwRect aRect( (*pRegion)[ pRegion->Count() - 1 ] );
261 					pRegion->Remove( pRegion->Count() - 1 );
262 
263 					sal_Bool bPaint = sal_True;
264 					if ( IsEndActionByVirDev() )
265 					{
266 						//virtuelles device erzeugen und einstellen.
267 						if ( !pVout )
268 							pVout = new VirtualDevice( *GetOut() );
269 						MapMode aMapMode( GetOut()->GetMapMode() );
270 						pVout->SetMapMode( aMapMode );
271 
272 						sal_Bool bSizeOK = sal_True;
273 
274 						Rectangle aTmp1( aRect.SVRect() );
275 						aTmp1 = GetOut()->LogicToPixel( aTmp1 );
276 						Rectangle aTmp2( GetOut()->PixelToLogic( aTmp1 ) );
277 						if ( aTmp2.Left() > aRect.Left() )
278 							aTmp1.Left() = Max( 0L, aTmp1.Left() - 1L );
279 						if ( aTmp2.Top() > aRect.Top() )
280 							aTmp1.Top() = Max( 0L, aTmp1.Top() - 1L );
281 						aTmp1.Right() += 1;
282 						aTmp1.Bottom() += 1;
283 						aTmp1 = GetOut()->PixelToLogic( aTmp1 );
284 						aRect = SwRect( aTmp1 );
285 
286 						const Size aTmp( pVout->GetOutputSize() );
287 						if ( aTmp.Height() < aRect.Height() ||
288 							 aTmp.Width()  < aRect.Width() )
289 						{
290 							bSizeOK = pVout->SetOutputSize( aRect.SSize() );
291 						}
292 						if ( bSizeOK )
293 						{
294 							bPaint = sal_False;
295 
296                             // --> OD 2007-07-26 #i79947#
297                             // #i72754# start Pre/PostPaint encapsulation before pOut is changed to the buffering VDev
298                             const Region aRepaintRegion(aRect.SVRect());
299                             DLPrePaint2(aRepaintRegion);
300                             // <--
301 
302                             OutputDevice  *pOld = GetOut();
303 							pVout->SetLineColor( pOld->GetLineColor() );
304 							pVout->SetFillColor( pOld->GetFillColor() );
305 							Point aOrigin( aRect.Pos() );
306 							aOrigin.X() = -aOrigin.X(); aOrigin.Y() = -aOrigin.Y();
307 							aMapMode.SetOrigin( aOrigin );
308 							pVout->SetMapMode( aMapMode );
309 
310 							pOut = pVout;
311                             if ( bPaintsFromSystem )
312                                 PaintDesktop( aRect );
313 							pCurrentLayout->Paint( aRect );
314 							pOld->DrawOutDev( aRect.Pos(), aRect.SSize(),
315 											  aRect.Pos(), aRect.SSize(), *pVout );
316 							pOut = pOld;
317 
318 							// #i72754# end Pre/PostPaint encapsulation when pOut is back and content is painted
319 							DLPostPaint2(true);
320 						}
321 					}
322 					if ( bPaint )
323                     {
324 						// #i75172# begin DrawingLayer paint
325 						// need to do begin/end DrawingLayer preparation for each single rectangle of the
326 						// repaint region. I already tried to prepare only once for the whole Region. This
327 						// seems to work (and does technically) but fails with transparent objects. Since the
328 						// region given to BeginDarwLayers() defines the clip region for DrawingLayer paint,
329 						// transparent objects in the single rectangles will indeed be painted multiple times.
330 						DLPrePaint2(Region(aRect.SVRect()));
331 
332                         if ( bPaintsFromSystem )
333                             PaintDesktop( aRect );
334 						pCurrentLayout->Paint( aRect );
335 
336 						// #i75172# end DrawingLayer paint
337 						DLPostPaint2(true);
338                     }
339 
340                     // --> OD 2009-12-03 #i107365#
341                     // Direct paint has been performed. Thus, take care of
342                     // transparent child windows.
343                     if ( GetWin() )
344                     {
345                         Window& rWindow = *(GetWin());
346                         if(rWindow.IsChildTransparentModeEnabled() && rWindow.GetChildCount())
347                         {
348                             const Rectangle aRectanglePixel(rWindow.LogicToPixel(aRect.SVRect()));
349 
350                             for ( sal_uInt16 a(0); a < rWindow.GetChildCount(); a++ )
351                             {
352                                 Window* pCandidate = rWindow.GetChild(a);
353 
354                                 if ( pCandidate && pCandidate->IsPaintTransparent() )
355                                 {
356                                     const Rectangle aCandidatePosSizePixel(
357                                                     pCandidate->GetPosPixel(),
358                                                     pCandidate->GetSizePixel());
359 
360                                     if ( aCandidatePosSizePixel.IsOver(aRectanglePixel) )
361                                     {
362                                         pCandidate->Invalidate( INVALIDATE_NOTRANSPARENT|INVALIDATE_CHILDREN );
363                                         pCandidate->Update();
364 				}
365                                 }
366                             }
367                         }
368                     }
369                     // <--
370 				}
371 
372 				delete pVout;
373                 delete pRegion;
374                 Imp()->DelRegion();
375 			}
376 			if( bShowCrsr )
377 				((SwCrsrShell*)this)->ShowCrsrs( sal_True );
378 		}
379 		else
380 		{
381             Imp()->DelRegion();
382 			bPaintWorks =  sal_True;
383 		}
384 	}
385 	else
386 		bPaintWorks = sal_True;
387 
388 	bInEndAction = sal_False;
389 	ViewShell::bLstAct = sal_False;
390 	Imp()->EndAction();
391 
392 
393 	//Damit sich die automatischen Scrollbars auch richtig anordnen k?nnen
394 	//muessen wir die Aktion hier kuenstlich beenden (EndAction loesst ein
395 	//Notify aus, und das muss Start-/EndAction rufen um die  Scrollbars
396 	//klarzubekommen.
397 	--nStartAction;
398 	UISizeNotify();
399 	++nStartAction;
400 
401 	if( Imp()->IsAccessible() )
402 		Imp()->FireAccessibleEvents();
403 }
404 
405 /******************************************************************************
406 |*
407 |*	ViewShell::ImplStartAction()
408 |*
409 |*	Ersterstellung		MA 25. Jul. 94
410 |*	Letzte Aenderung	MA 25. Jul. 94
411 |*
412 ******************************************************************************/
413 
ImplStartAction()414 void ViewShell::ImplStartAction()
415 {
416 	bPaintWorks = sal_False;
417 	Imp()->StartAction();
418 }
419 
420 
421 /******************************************************************************
422 |*
423 |*	ViewShell::ImplLockPaint(), ImplUnlockPaint()
424 |*
425 |*	Ersterstellung		MA 11. Jun. 96
426 |*	Letzte Aenderung	MA 11. Jun. 96
427 |*
428 ******************************************************************************/
429 
ImplLockPaint()430 void ViewShell::ImplLockPaint()
431 {
432 	if ( GetWin() && GetWin()->IsVisible() )
433 		GetWin()->EnablePaint( sal_False );	//Auch die Controls abklemmen.
434 	Imp()->LockPaint();
435 }
436 
437 
ImplUnlockPaint(sal_Bool bVirDev)438 void ViewShell::ImplUnlockPaint( sal_Bool bVirDev )
439 {
440 	SET_CURR_SHELL( this );
441 	if ( GetWin() && GetWin()->IsVisible() )
442 	{
443 		if ( (bInSizeNotify || bVirDev ) && VisArea().HasArea() )
444 		{
445 			//Refresh mit virtuellem Device um das Flackern zu verhindern.
446 			VirtualDevice *pVout = new VirtualDevice( *pOut );
447 			pVout->SetMapMode( pOut->GetMapMode() );
448 			Size aSize( VisArea().SSize() );
449 			aSize.Width() += 20;
450 			aSize.Height()+= 20;
451 			if( pVout->SetOutputSize( aSize ) )
452 			{
453 				GetWin()->EnablePaint( sal_True );
454 				GetWin()->Validate();
455 
456 				Imp()->UnlockPaint();
457 				pVout->SetLineColor( pOut->GetLineColor() );
458 				pVout->SetFillColor( pOut->GetFillColor() );
459 
460 				// #i72754# start Pre/PostPaint encapsulation before pOut is changed to the buffering VDev
461 				const Region aRepaintRegion(VisArea().SVRect());
462 				DLPrePaint2(aRepaintRegion);
463 
464 				OutputDevice *pOld = pOut;
465 				pOut = pVout;
466 				Paint( VisArea().SVRect() );
467 				pOut = pOld;
468 				pOut->DrawOutDev( VisArea().Pos(), aSize,
469 								  VisArea().Pos(), aSize, *pVout );
470 
471 				// #i72754# end Pre/PostPaint encapsulation when pOut is back and content is painted
472 				DLPostPaint2(true);
473 			}
474 			else
475 			{
476 				Imp()->UnlockPaint();
477 				GetWin()->EnablePaint( sal_True );
478 				GetWin()->Invalidate( INVALIDATE_CHILDREN );
479 			}
480 			delete pVout;
481 		}
482 		else
483 		{
484 			Imp()->UnlockPaint();
485 			GetWin()->EnablePaint( sal_True );
486 			GetWin()->Invalidate( INVALIDATE_CHILDREN );
487 		}
488 	}
489 	else
490 		Imp()->UnlockPaint();
491 }
492 
493 /******************************************************************************
494 |*
495 |*	ViewShell::AddPaintRect()
496 |*
497 |*	Ersterstellung		MA ??
498 |*	Letzte Aenderung	MA 09. Feb. 97
499 |*
500 ******************************************************************************/
501 
AddPaintRect(const SwRect & rRect)502 sal_Bool ViewShell::AddPaintRect( const SwRect & rRect )
503 {
504 	sal_Bool bRet = sal_False;
505 	ViewShell *pSh = this;
506 	do
507 	{
508         if( pSh->Imp() )
509         {
510 		if ( pSh->IsPreView() && pSh->GetWin() )
511 			::RepaintPagePreview( pSh, rRect );
512 		else
513                 bRet |= pSh->Imp()->AddPaintRect( rRect );//swmod 080111
514         }
515 		pSh = (ViewShell*)pSh->GetNext();
516 	} while ( pSh != this );
517 	return bRet;
518 }
519 
520 /******************************************************************************
521 |*
522 |*	ViewShell::InvalidateWindows()
523 |*
524 |*	Ersterstellung		MA ??
525 |*	Letzte Aenderung	MA 09. Feb. 97
526 |*
527 ******************************************************************************/
528 
InvalidateWindows(const SwRect & rRect)529 void ViewShell::InvalidateWindows( const SwRect &rRect )
530 {
531 	if ( !Imp()->IsCalcLayoutProgress() )
532 	{
533 		ViewShell *pSh = this;
534 		do
535 		{
536 			if ( pSh->GetWin() )
537 			{
538 				if ( pSh->IsPreView() )
539 					::RepaintPagePreview( pSh, rRect );
540 				else if ( pSh->VisArea().IsOver( rRect ) )
541 					pSh->GetWin()->Invalidate( rRect.SVRect() );
542 			}
543 			pSh = (ViewShell*)pSh->GetNext();
544 
545 		} while ( pSh != this );
546 	}
547 }
548 
549 /******************************************************************************
550 |*
551 |*	ViewShell::MakeVisible()
552 |*
553 |*	Ersterstellung		MA ??
554 |*	Letzte Aenderung	AMA 10. Okt. 95
555 |*
556 ******************************************************************************/
557 
MakeVisible(const SwRect & rRect)558 void ViewShell::MakeVisible( const SwRect &rRect )
559 {
560 	if ( !VisArea().IsInside( rRect ) || IsScrollMDI( this, rRect ) || GetCareWin(*this) )
561 	{
562 		if ( !IsViewLocked() )
563 		{
564 			if( pWin )
565 			{
566 				const SwFrm* pRoot = GetLayout();
567 				int nLoopCnt = 3;
568 				long nOldH;
569 				do{
570 					nOldH = pRoot->Frm().Height();
571 					StartAction();
572 					ScrollMDI( this, rRect, USHRT_MAX, USHRT_MAX );
573 					EndAction();
574 				} while( nOldH != pRoot->Frm().Height() && nLoopCnt-- );	//swmod 071108//swmod 071225
575 			}
576 #ifdef DBG_UTIL
577 			else
578 			{
579 				//MA: 04. Nov. 94, braucht doch keiner oder??
580 				ASSERT( !this, "MakeVisible fuer Drucker wird doch gebraucht?" );
581 			}
582 
583 #endif
584 		}
585 	}
586 }
587 
588 /******************************************************************************
589 |*
590 |*	ViewShell::CareChildWindow()
591 |*
592 |*	Ersterstellung		AMA 10. Okt. 95
593 |*	Letzte Aenderung	AMA 10. Okt. 95
594 |*
595 ******************************************************************************/
596 
CareChildWin(ViewShell & rVSh)597 Window* ViewShell::CareChildWin(ViewShell& rVSh)
598 {
599 	if(rVSh.pSfxViewShell)
600 	{
601 		const sal_uInt16 nId = SvxSearchDialogWrapper::GetChildWindowId();
602 		SfxViewFrame* pVFrame = rVSh.pSfxViewShell->GetViewFrame();
603 		const SfxChildWindow* pChWin = pVFrame->GetChildWindow( nId );
604 		Window *pWin = pChWin ? pChWin->GetWindow() : NULL;
605 		if ( pWin && pWin->IsVisible() )
606 			return pWin;
607 	}
608 	return NULL;
609 }
610 
611 /******************************************************************************
612 |*
613 |*	ViewShell::GetPagePos()
614 |*
615 |*	Ersterstellung		MA ??
616 |*	Letzte Aenderung	MA 04. Aug. 93
617 |*
618 ******************************************************************************/
619 
GetPagePos(sal_uInt16 nPageNum) const620 Point ViewShell::GetPagePos( sal_uInt16 nPageNum ) const
621 {
622 	return GetLayout()->GetPagePos( nPageNum );
623 }
624 
625 /******************************************************************************
626 |*
627 |*	ViewShell::GetNumPages()
628 |*
629 |*	Ersterstellung		MA ??
630 |*	Letzte Aenderung	MA 20. Apr. 94
631 |*
632 ******************************************************************************/
633 
GetNumPages()634 sal_uInt16 ViewShell::GetNumPages()
635 {
636 	//Es kann sein, das noch kein Layout existiert weil die Methode vom
637 	//Root-Ctor gerufen wird.
638 	return GetLayout() ? GetLayout()->GetPageNum() : 0;
639 }
640 
IsDummyPage(sal_uInt16 nPageNum) const641 sal_Bool ViewShell::IsDummyPage( sal_uInt16 nPageNum ) const
642 {
643     return GetLayout() ? GetLayout()->IsDummyPage( nPageNum ) : 0;
644 }
645 
646 /*************************************************************************
647 |*
648 |*					ViewShell::UpdateFlds()
649 |*
650 |*	  Ersterstellung	BP 04.05.92
651 |*	  Beschreibung		erzwingt ein Update fuer jedes Feld
652 |*
653 |*	UpdateFlds benachrichtigt alle Felder mit pNewHt.
654 |*	Wenn pNewHt == 0 ist (default), wird der Feldtyp verschickt.
655 |*
656 *************************************************************************/
657 
UpdateFlds(sal_Bool bCloseDB)658 void ViewShell::UpdateFlds(sal_Bool bCloseDB)
659 {
660 	SET_CURR_SHELL( this );
661 
662 	sal_Bool bCrsr = ISA(SwCrsrShell);
663 	if ( bCrsr )
664 		((SwCrsrShell*)this)->StartAction();
665 	else
666 		StartAction();
667 
668 	GetDoc()->UpdateFlds(0, bCloseDB);
669 
670 	if ( bCrsr )
671 		((SwCrsrShell*)this)->EndAction();
672 	else
673 		EndAction();
674 }
675 
676 // update all charts, for that exists any table
UpdateAllCharts()677 void ViewShell::UpdateAllCharts()
678 {
679 	SET_CURR_SHELL( this );
680 	// Start-/EndAction handled in the SwDoc-Method!
681 	GetDoc()->UpdateAllCharts();
682 }
683 
HasCharts() const684 sal_Bool ViewShell::HasCharts() const
685 {
686 	sal_Bool bRet = sal_False;
687 	const SwStartNode *pStNd;
688 	SwNodeIndex aIdx( *GetDoc()->GetNodes().GetEndOfAutotext().
689 						StartOfSectionNode(), 1 );
690 	while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
691 	{
692 		aIdx++;
693 		const SwOLENode *pNd = aIdx.GetNode().GetOLENode();
694 		if( pNd && pNd->GetChartTblName().Len() )
695 		{
696 			bRet = sal_True;
697 			break;
698 		}
699 	}
700 	return bRet;
701 }
702 
703 /*************************************************************************
704 |*
705 |*	  ViewShell::LayoutIdle()
706 |*
707 |*	  Ersterstellung	MA 26. May. 92
708 |*	  Letzte Aenderung	OG 19. Mar. 96
709 |*
710 *************************************************************************/
711 
LayoutIdle()712 void ViewShell::LayoutIdle()
713 {
714 #ifdef TCOVER
715 	//fuer TCV-Version: Ende der Startphase des Programmes
716 	TCovCall::Idle();
717 #endif
718 	if( !pOpt->IsIdle() || !GetWin() ||
719 		( Imp()->HasDrawView() && Imp()->GetDrawView()->IsDragObj() ) )
720 		return;
721 
722 	//Kein Idle wenn gerade gedruckt wird.
723 	ViewShell *pSh = this;
724 	do
725 	{	if ( !pSh->GetWin() )
726 			return;
727 		pSh = (ViewShell*)pSh->GetNext();
728 
729 	} while ( pSh != this );
730 
731 	SET_CURR_SHELL( this );
732 
733 #ifdef DBG_UTIL
734 	// Wenn Test5 gedrueckt ist, wird der IdleFormatierer abgeknipst.
735 	if( pOpt->IsTest5() )
736 		return;
737 #endif
738 
739 	{
740 		DBG_PROFSTART( LayoutIdle );
741 
742 		//Cache vorbereiten und restaurieren, damit er nicht versaut wird.
743 		SwSaveSetLRUOfst aSave( *SwTxtFrm::GetTxtCache(),
744 							 SwTxtFrm::GetTxtCache()->GetCurMax() - 50 );
745         // #125243# there are lots of stacktraces indicating that Imp() returns NULL
746         // this ViewShell seems to be invalid - but it's not clear why
747         // this return is only a workaround!
748         DBG_ASSERT(Imp(), "ViewShell already deleted?");
749         if(!Imp())
750             return;
751         SwLayIdle aIdle( GetLayout(), Imp() );
752 		DBG_PROFSTOP( LayoutIdle );
753 	}
754 }
755 
756 /*************************************************************************
757 |*
758 |*    DOCUMENT COMPATIBILITY FLAGS
759 |*
760 *************************************************************************/
761 
lcl_InvalidateAllCntnt(ViewShell & rSh,sal_uInt8 nInv)762 void lcl_InvalidateAllCntnt( ViewShell& rSh, sal_uInt8 nInv )
763 {
764     sal_Bool bCrsr = rSh.ISA(SwCrsrShell);
765     if ( bCrsr )
766         ((SwCrsrShell&)rSh).StartAction();
767     else
768         rSh.StartAction();
769     rSh.GetLayout()->InvalidateAllCntnt( nInv );
770     if ( bCrsr )
771         ((SwCrsrShell&)rSh).EndAction();
772     else
773         rSh.EndAction();
774 
775     rSh.GetDoc()->SetModified();
776 }
777 
778 /** local method to invalidate/re-calculate positions of floating screen
779     objects (Writer fly frame and drawing objects), which are anchored
780     to paragraph or to character.
781 
782     OD 2004-03-16 #i11860#
783 
784     @author OD
785 */
lcl_InvalidateAllObjPos(ViewShell & _rSh)786 void lcl_InvalidateAllObjPos( ViewShell &_rSh )
787 {
788     const bool bIsCrsrShell = _rSh.ISA(SwCrsrShell);
789     if ( bIsCrsrShell )
790         static_cast<SwCrsrShell&>(_rSh).StartAction();
791     else
792         _rSh.StartAction();
793 
794     _rSh.GetLayout()->InvalidateAllObjPos();
795 
796     if ( bIsCrsrShell )
797         static_cast<SwCrsrShell&>(_rSh).EndAction();
798     else
799         _rSh.EndAction();
800 
801     _rSh.GetDoc()->SetModified();
802 }
803 
SetParaSpaceMax(bool bNew)804 void ViewShell::SetParaSpaceMax( bool bNew )
805 {
806     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
807     if( pIDSA->get(IDocumentSettingAccess::PARA_SPACE_MAX) != bNew )
808     {
809 		SwWait aWait( *GetDoc()->GetDocShell(), true );
810         pIDSA->set(IDocumentSettingAccess::PARA_SPACE_MAX, bNew );
811         const sal_uInt8 nInv = INV_PRTAREA | INV_TABLE | INV_SECTION;
812         lcl_InvalidateAllCntnt( *this,  nInv );
813     }
814 }
815 
SetParaSpaceMaxAtPages(bool bNew)816 void ViewShell::SetParaSpaceMaxAtPages( bool bNew )
817 {
818     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
819     if( pIDSA->get(IDocumentSettingAccess::PARA_SPACE_MAX_AT_PAGES) != bNew )
820     {
821         SwWait aWait( *GetDoc()->GetDocShell(), true );
822         pIDSA->set(IDocumentSettingAccess::PARA_SPACE_MAX_AT_PAGES, bNew );
823         const sal_uInt8 nInv = INV_PRTAREA | INV_TABLE | INV_SECTION;
824         lcl_InvalidateAllCntnt( *this,  nInv );
825     }
826 }
827 
SetTabCompat(bool bNew)828 void ViewShell::SetTabCompat( bool bNew )
829 {
830     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
831     if( pIDSA->get(IDocumentSettingAccess::TAB_COMPAT) != bNew  )
832 	{
833 		SwWait aWait( *GetDoc()->GetDocShell(), true );
834         pIDSA->set(IDocumentSettingAccess::TAB_COMPAT, bNew );
835         const sal_uInt8 nInv = INV_PRTAREA | INV_SIZE | INV_TABLE | INV_SECTION;
836         lcl_InvalidateAllCntnt( *this, nInv );
837     }
838 }
839 
SetAddExtLeading(bool bNew)840 void ViewShell::SetAddExtLeading( bool bNew )
841 {
842     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
843     if ( pIDSA->get(IDocumentSettingAccess::ADD_EXT_LEADING) != bNew )
844     {
845         SwWait aWait( *GetDoc()->GetDocShell(), true );
846         pIDSA->set(IDocumentSettingAccess::ADD_EXT_LEADING, bNew );
847         SdrModel* pTmpDrawModel = getIDocumentDrawModelAccess()->GetDrawModel();
848         if ( pTmpDrawModel )
849             pTmpDrawModel->SetAddExtLeading( bNew );
850         const sal_uInt8 nInv = INV_PRTAREA | INV_SIZE | INV_TABLE | INV_SECTION;
851         lcl_InvalidateAllCntnt( *this, nInv );
852     }
853 }
854 
SetUseVirDev(bool bNewVirtual)855 void ViewShell::SetUseVirDev( bool bNewVirtual )
856 {
857     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
858     if ( pIDSA->get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE) != bNewVirtual )
859     {
860         SwWait aWait( *GetDoc()->GetDocShell(), true );
861         // this sets the flag at the document and calls PrtDataChanged
862         IDocumentDeviceAccess* pIDDA = getIDocumentDeviceAccess();
863         pIDDA->setReferenceDeviceType( bNewVirtual, true );
864     }
865 }
866 
867 // OD 2004-02-16 #106629# - control, if paragraph and table spacing is added
868 // at bottom of table cells
SetAddParaSpacingToTableCells(bool _bAddParaSpacingToTableCells)869 void ViewShell::SetAddParaSpacingToTableCells( bool _bAddParaSpacingToTableCells )
870 {
871     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
872     if ( pIDSA->get(IDocumentSettingAccess::ADD_PARA_SPACING_TO_TABLE_CELLS) != _bAddParaSpacingToTableCells )
873     {
874         SwWait aWait( *GetDoc()->GetDocShell(), true );
875         pIDSA->set(IDocumentSettingAccess::ADD_PARA_SPACING_TO_TABLE_CELLS, _bAddParaSpacingToTableCells );
876         const sal_uInt8 nInv = INV_PRTAREA;
877         lcl_InvalidateAllCntnt( *this, nInv );
878     }
879 }
880 
881 // OD 06.01.2004 #i11859# - control, if former formatting of text lines with
882 // proportional line spacing is used or not.
SetUseFormerLineSpacing(bool _bUseFormerLineSpacing)883 void ViewShell::SetUseFormerLineSpacing( bool _bUseFormerLineSpacing )
884 {
885     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
886     if ( pIDSA->get(IDocumentSettingAccess::OLD_LINE_SPACING) != _bUseFormerLineSpacing )
887     {
888         SwWait aWait( *GetDoc()->GetDocShell(), true );
889         pIDSA->set(IDocumentSettingAccess::OLD_LINE_SPACING, _bUseFormerLineSpacing );
890         const sal_uInt8 nInv = INV_PRTAREA;
891         lcl_InvalidateAllCntnt( *this, nInv );
892     }
893 }
894 
895 // OD 2004-03-12 #i11860# - control, if former object positioning is used or not.
SetUseFormerObjectPositioning(bool _bUseFormerObjPos)896 void ViewShell::SetUseFormerObjectPositioning( bool _bUseFormerObjPos )
897 {
898     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
899     if ( pIDSA->get(IDocumentSettingAccess::USE_FORMER_OBJECT_POS) != _bUseFormerObjPos )
900     {
901         SwWait aWait( *GetDoc()->GetDocShell(), true );
902         pIDSA->set(IDocumentSettingAccess::USE_FORMER_OBJECT_POS, _bUseFormerObjPos );
903         lcl_InvalidateAllObjPos( *this );
904     }
905 }
906 
907 // OD 2004-05-05 #i28701#
SetConsiderWrapOnObjPos(bool _bConsiderWrapOnObjPos)908 void ViewShell::SetConsiderWrapOnObjPos( bool _bConsiderWrapOnObjPos )
909 {
910     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
911     if ( pIDSA->get(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION) != _bConsiderWrapOnObjPos )
912     {
913         SwWait aWait( *GetDoc()->GetDocShell(), true );
914         pIDSA->set(IDocumentSettingAccess::CONSIDER_WRAP_ON_OBJECT_POSITION, _bConsiderWrapOnObjPos );
915         lcl_InvalidateAllObjPos( *this );
916     }
917 }
918 
919 // --> FME #108724#
SetUseFormerTextWrapping(bool _bUseFormerTextWrapping)920 void ViewShell::SetUseFormerTextWrapping( bool _bUseFormerTextWrapping )
921 {
922     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
923     if ( pIDSA->get(IDocumentSettingAccess::USE_FORMER_TEXT_WRAPPING) != _bUseFormerTextWrapping )
924     {
925         SwWait aWait( *GetDoc()->GetDocShell(), true );
926         pIDSA->set(IDocumentSettingAccess::USE_FORMER_TEXT_WRAPPING, _bUseFormerTextWrapping );
927         const sal_uInt8 nInv = INV_PRTAREA | INV_SIZE | INV_TABLE | INV_SECTION;
928         lcl_InvalidateAllCntnt( *this, nInv );
929     }
930 }
931 // <--
932 
933 // -> PB 2007-06-11 #i45491#
SetDoNotJustifyLinesWithManualBreak(bool _bDoNotJustifyLinesWithManualBreak)934 void ViewShell::SetDoNotJustifyLinesWithManualBreak( bool _bDoNotJustifyLinesWithManualBreak )
935 {
936     IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
937     if ( pIDSA->get(IDocumentSettingAccess::DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK) != _bDoNotJustifyLinesWithManualBreak )
938     {
939         SwWait aWait( *GetDoc()->GetDocShell(), true );
940         pIDSA->set(IDocumentSettingAccess::DO_NOT_JUSTIFY_LINES_WITH_MANUAL_BREAK, _bDoNotJustifyLinesWithManualBreak );
941         const sal_uInt8 nInv = INV_PRTAREA | INV_SIZE | INV_TABLE | INV_SECTION;
942         lcl_InvalidateAllCntnt( *this, nInv );
943     }
944 }
945 // <--
946 
947 /******************************************************************************
948 |*
949 |*	ViewShell::Reformat
950 |*
951 |*	Ersterstellung		BP ???
952 |*	Letzte Aenderung	MA 13. Feb. 98
953 |*
954 ******************************************************************************/
955 
Reformat()956 void ViewShell::Reformat()
957 {
958 	SwWait aWait( *GetDoc()->GetDocShell(), true );
959 
960 	// Wir gehen auf Nummer sicher:
961 	// Wir muessen die alten Fontinformationen wegschmeissen,
962 	// wenn die Druckeraufloesung oder der Zoomfaktor sich aendert.
963 	// Init() und Reformat() sind die sichersten Stellen.
964 #ifdef FNTMET
965 	aFntMetList.Flush();
966 #else
967 	pFntCache->Flush( );
968 #endif
969 
970     if( GetLayout()->IsCallbackActionEnabled() )
971     {
972 
973         StartAction();
974         GetLayout()->InvalidateAllCntnt( INV_SIZE | INV_POS | INV_PRTAREA );
975         EndAction();
976     }
977 }
978 
ChgNumberDigits()979  void ViewShell::ChgNumberDigits()
980  {
981      SdrModel* pTmpDrawModel = getIDocumentDrawModelAccess()->GetDrawModel();
982      if ( pTmpDrawModel )
983             pTmpDrawModel->ReformatAllTextObjects();
984 	 Reformat();
985  }
986 
987 /******************************************************************************
988 |*
989 |*	ViewShell::CalcLayout()
990 |*					Vollstaendige Formatierung von Layout und Inhalt.
991 |*
992 |*	Ersterstellung		MA 31. Jan. 94
993 |*	Letzte Aenderung	MA 08. Oct. 96
994 |*
995 ******************************************************************************/
996 
CalcLayout()997 void ViewShell::CalcLayout()
998 {
999 	SET_CURR_SHELL( this );
1000 	SwWait aWait( *GetDoc()->GetDocShell(), true );
1001 
1002 	//Cache vorbereiten und restaurieren, damit er nicht versaut wird.
1003 	SwSaveSetLRUOfst aSaveLRU( *SwTxtFrm::GetTxtCache(),
1004 						  		SwTxtFrm::GetTxtCache()->GetCurMax() - 50 );
1005 
1006 	//Progress einschalten wenn noch keiner Lauft.
1007 	const sal_Bool bEndProgress = SfxProgress::GetActiveProgress( GetDoc()->GetDocShell() ) == 0;
1008 	if ( bEndProgress )
1009 	{
1010 		sal_uInt16 nEndPage = GetLayout()->GetPageNum();
1011 		nEndPage += nEndPage * 10 / 100;
1012 		::StartProgress( STR_STATSTR_REFORMAT, 0, nEndPage, GetDoc()->GetDocShell() );
1013 	}
1014 
1015 	SwLayAction aAction( GetLayout(), Imp() );
1016 	aAction.SetPaint( sal_False );
1017 	aAction.SetStatBar( sal_True );
1018 	aAction.SetCalcLayout( sal_True );
1019 	aAction.SetReschedule( sal_True );
1020 	GetDoc()->LockExpFlds();
1021 	aAction.Action();
1022 	GetDoc()->UnlockExpFlds();
1023 
1024 	//Das SetNewFldLst() am Doc wurde unterbunden und muss nachgeholt
1025 	//werden (siehe flowfrm.cxx, txtfld.cxx)
1026 	if ( aAction.IsExpFlds() )
1027 	{
1028 		aAction.Reset();
1029 		aAction.SetPaint( sal_False );
1030 		aAction.SetStatBar( sal_True );
1031 		aAction.SetReschedule( sal_True );
1032 
1033 		SwDocPosUpdate aMsgHnt( 0 );
1034 		GetDoc()->UpdatePageFlds( &aMsgHnt );
1035 		GetDoc()->UpdateExpFlds(NULL, true);
1036 
1037 		aAction.Action();
1038 	}
1039 
1040 	if ( VisArea().HasArea() )
1041 		InvalidateWindows( VisArea() );
1042 	if ( bEndProgress )
1043 		::EndProgress( GetDoc()->GetDocShell() );
1044 }
1045 
1046 /******************************************************************************
1047 |*
1048 |*	ViewShell::SetFirstVisPageInvalid()
1049 |*
1050 |*	Ersterstellung		MA 19. May. 94
1051 |*	Letzte Aenderung	MA 19. May. 94
1052 |*
1053 ******************************************************************************/
1054 
SetFirstVisPageInvalid()1055 void ViewShell::SetFirstVisPageInvalid()
1056 {
1057 	ViewShell *pSh = this;
1058 	do
1059 	{	pSh->Imp()->SetFirstVisPageInvalid();
1060 		pSh = (ViewShell*)pSh->GetNext();
1061 
1062 	} while ( pSh != this );
1063 }
1064 
1065 /******************************************************************************
1066 |*
1067 |*	ViewShell::SizeChgNotify()
1068 |*
1069 |*	Ersterstellung		MA ??
1070 |*	Letzte Aenderung	MA 17. Sep. 96
1071 |*
1072 ******************************************************************************/
1073 
SizeChgNotify()1074 void ViewShell::SizeChgNotify()
1075 {
1076 	if ( !pWin )
1077 		bDocSizeChgd = sal_True;
1078 	else if( ActionPend() || Imp()->IsCalcLayoutProgress() || bPaintInProgress )
1079 	{
1080 		bDocSizeChgd = sal_True;
1081 
1082 		if ( !Imp()->IsCalcLayoutProgress() && ISA( SwCrsrShell ) )
1083 		{
1084 			const SwFrm *pCnt = ((SwCrsrShell*)this)->GetCurrFrm( sal_False );
1085 			const SwPageFrm *pPage;
1086 			if ( pCnt && 0 != (pPage = pCnt->FindPageFrm()) )
1087 			{
1088 				sal_uInt16 nVirtNum = pPage->GetVirtPageNum();
1089 		 		const SvxNumberType& rNum = pPage->GetPageDesc()->GetNumType();
1090 				String sDisplay = rNum.GetNumStr( nVirtNum );
1091 				PageNumNotify( this, pCnt->GetPhyPageNum(), nVirtNum, sDisplay );
1092 			}
1093 		}
1094 	}
1095 	else
1096 	{
1097 		bDocSizeChgd = sal_False;
1098 		::SizeNotify( this, GetDocSize() );
1099 	}
1100 }
1101 
1102 /******************************************************************************
1103 |*
1104 |*	ViewShell::VisPortChgd()
1105 |*
1106 |*	Ersterstellung		MA ??
1107 |*	Letzte Aenderung	MA 22. Jul. 96
1108 |*
1109 ******************************************************************************/
1110 
VisPortChgd(const SwRect & rRect)1111 void ViewShell::VisPortChgd( const SwRect &rRect)
1112 {
1113 	ASSERT( GetWin(), "VisPortChgd ohne Window." );
1114 
1115 	if ( rRect == VisArea() )
1116 		return;
1117 
1118 #ifdef DBG_UTIL
1119 	if ( bInEndAction )
1120 	{
1121 		//Da Rescheduled doch schon wieder irgendwo einer?
1122 		ASSERT( !this, "Scroll waehrend einer EndAction." );
1123 	}
1124 #endif
1125 
1126 	//Ersteinmal die alte sichtbare Seite holen, dann braucht nacher nicht
1127 	//lange gesucht werden.
1128 	const SwFrm *pOldPage = Imp()->GetFirstVisPage();
1129 
1130 	const SwRect aPrevArea( VisArea() );
1131 	const sal_Bool bFull = aPrevArea.IsEmpty();
1132 	aVisArea = rRect;
1133 	SetFirstVisPageInvalid();
1134 
1135 	//Wenn noch eine PaintRegion herumsteht und sich die VisArea geaendert hat,
1136 	//so ist die PaintRegion spaetestens jetzt obsolete. Die PaintRegion kann
1137 	//vom RootFrm::Paint erzeugt worden sein.
1138 	if ( !bInEndAction &&
1139 		 Imp()->GetRegion() && Imp()->GetRegion()->GetOrigin() != VisArea() )
1140         Imp()->DelRegion();
1141 
1142 	SET_CURR_SHELL( this );
1143 
1144 	bool bScrolled = false;
1145 
1146     SwPostItMgr* pPostItMgr = GetPostItMgr();
1147 
1148     if ( bFull )
1149 		GetWin()->Invalidate();
1150 	else
1151 	{
1152 		// Betrag ausrechnen, um den gescrolled werden muss.
1153 		const long nXDiff = aPrevArea.Left() - VisArea().Left();
1154 		const long nYDiff = aPrevArea.Top()  - VisArea().Top();
1155 
1156         if( !nXDiff && !GetViewOptions()->getBrowseMode() &&
1157 			(!Imp()->HasDrawView() || !Imp()->GetDrawView()->IsGridVisible() ) )
1158 		{
1159 			//Falls moeglich die Wiese nicht mit Scrollen.
1160 			//Also linke und rechte Kante des Scrollbereiches auf die
1161 			//Seiten begrenzen.
1162 			const SwPageFrm *pPage = (SwPageFrm*)GetLayout()->Lower();	//swmod 071108//swmod 071225
1163 			if ( pPage->Frm().Top() > pOldPage->Frm().Top() )
1164 				pPage = (SwPageFrm*)pOldPage;
1165 			SwRect aBoth( VisArea() );
1166 			aBoth.Union( aPrevArea );
1167 			const SwTwips nBottom = aBoth.Bottom();
1168             SwTwips nMinLeft = LONG_MAX;
1169 			SwTwips nMaxRight= 0;
1170 
1171             const SwTwips nSidebarWidth = pPostItMgr && pPostItMgr->ShowNotes() && pPostItMgr->HasNotes() ?
1172                                           pPostItMgr->GetSidebarWidth() + pPostItMgr->GetSidebarBorderWidth() :
1173                                           0;
1174             const bool bBookMode = GetViewOptions()->IsViewLayoutBookMode();
1175 
1176             while ( pPage && pPage->Frm().Top() <= nBottom )
1177 			{
1178                 SwRect aPageRect( pPage->Frm() );
1179                 if ( bBookMode )
1180                 {
1181                     const SwPageFrm& rFormatPage = static_cast<const SwPageFrm*>(pPage)->GetFormatPage();
1182                     aPageRect.SSize() = rFormatPage.Frm().SSize();
1183                 }
1184 
1185                 if ( aPageRect.IsOver( aBoth ) )
1186 				{
1187                     // OD 12.02.2003 #i9719#, #105645# - consider new border
1188                     // and shadow width
1189                     const SwTwips nBorderWidth =
1190                             GetOut()->PixelToLogic( Size( pPage->BorderPxWidth(), 0 ) ).Width();
1191                     const SwTwips nShadowWidth =
1192                             GetOut()->PixelToLogic( Size( pPage->ShadowPxWidth(), 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 + nShadowWidth;
1202                         }
1203                         break;
1204                         case sw::sidebarwindows::SIDEBAR_RIGHT:
1205                         {
1206                             nPageLeft =  aPageRect.Left() - nBorderWidth;
1207                             nPageRight = aPageRect.Right() + nBorderWidth + nShadowWidth + 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