xref: /aoo42x/main/sw/source/core/view/viewimp.cxx (revision efeef26f)
1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 
23 
24 // MARKER(update_precomp.py): autogen include statement, do not remove
25 #include "precompiled_sw.hxx"
26 
27 
28 #include "crsrsh.hxx"
29 #include "rootfrm.hxx"
30 #include "pagefrm.hxx"
31 #include "viewimp.hxx"
32 #include "errhdl.hxx"
33 #include "viewopt.hxx"
34 #include "flyfrm.hxx"
35 #include "frmfmt.hxx"
36 #include "layact.hxx"
37 #include "swregion.hxx"
38 #include "dflyobj.hxx"
39 #include "dview.hxx"
40 #include <tools/shl.hxx>
41 #include <swmodule.hxx>
42 #include <svx/svdpage.hxx>
43 #include <accmap.hxx>
44 
45 // OD 12.12.2002 #103492#
46 #include <pagepreviewlayout.hxx>
47 
48 #include <comcore.hrc>
49 #include <svx/svdundo.hxx>
50 #include <IDocumentLayoutAccess.hxx>
51 #include <IDocumentDrawModelAccess.hxx>
52 #include <IDocumentDeviceAccess.hxx>
53 #include <IDocumentSettingAccess.hxx>
54 
55 /*************************************************************************
56 |*
57 |*	SwViewImp::Init()
58 |*
59 |*	Ersterstellung		MA 25. Jul. 94
60 |*	Letzte Aenderung	MA 03. Nov. 95
61 |*
62 |*************************************************************************/
63 
64 void SwViewImp::Init( const SwViewOption *pNewOpt )
65 {
66 	ASSERT( pDrawView, "SwViewImp::Init without DrawView" );
67 	//Jetzt die PageView erzeugen wenn sie noch nicht existiert.
68     SwRootFrm *pRoot = pSh->GetLayout();	//swmod 071108//swmod 071225
69 	if ( !pSdrPageView )
70 	{
71         IDocumentDrawModelAccess* pIDDMA = pSh->getIDocumentDrawModelAccess();
72 		if ( !pRoot->GetDrawPage() )
73             pRoot->SetDrawPage( pIDDMA->GetDrawModel()->GetPage( 0 ) );
74 
75 		if ( pRoot->GetDrawPage()->GetSize() != pRoot->Frm().SSize() )
76             pRoot->GetDrawPage()->SetSize( pRoot->Frm().SSize() );
77 
78         pSdrPageView = pDrawView->ShowSdrPage( pRoot->GetDrawPage());
79         // OD 26.06.2003 #108784# - notify drawing page view about invisible
80         // layers.
81         pIDDMA->NotifyInvisibleLayers( *pSdrPageView );
82 	}
83 	pDrawView->SetDragStripes( pNewOpt->IsCrossHair() );
84 	pDrawView->SetGridSnap( pNewOpt->IsSnap() );
85 	pDrawView->SetGridVisible( pNewOpt->IsGridVisible() );
86 	const Size &rSz = pNewOpt->GetSnapSize();
87 	pDrawView->SetGridCoarse( rSz );
88 	const Size aFSize
89 			( rSz.Width() ? rSz.Width() /Max(short(1),pNewOpt->GetDivisionX()):0,
90 			  rSz.Height()? rSz.Height()/Max(short(1),pNewOpt->GetDivisionY()):0);
91  	pDrawView->SetGridFine( aFSize );
92 	Fraction aSnGrWdtX(rSz.Width(), pNewOpt->GetDivisionX() + 1);
93 	Fraction aSnGrWdtY(rSz.Height(), pNewOpt->GetDivisionY() + 1);
94 	pDrawView->SetSnapGridWidth( aSnGrWdtX, aSnGrWdtY );
95 
96 	if ( pRoot->Frm().HasArea() )
97 		pDrawView->SetWorkArea( pRoot->Frm().SVRect() );
98 
99 	if ( GetShell()->IsPreView() )
100 		pDrawView->SetAnimationEnabled( sal_False );
101 
102 	pDrawView->SetUseIncompatiblePathCreateInterface( sal_False );
103 	pDrawView->SetSolidMarkHdl(pNewOpt->IsSolidMarkHdl());
104 
105 	// it's a JOE interface !
106 	pDrawView->SetMarkHdlSizePixel(pNewOpt->IsBigMarkHdl() ? 9 : 7);
107 }
108 
109 /*************************************************************************
110 |*
111 |*	SwViewImp::SwViewImp()	CTor fuer die Core-Internas
112 |*
113 |*	Ersterstellung		MA 25. Jul. 94
114 |*	Letzte Aenderung	MA 06. Sep. 96
115 |*
116 |*************************************************************************/
117 
118 SwViewImp::SwViewImp( ViewShell *pParent ) :
119 	pSh( pParent ),
120     pDrawView( 0 ),
121     pSdrPageView( 0 ),
122     pFirstVisPage( 0 ),
123 	pRegion( 0 ),
124 	pLayAct( 0 ),
125 	pIdleAct( 0 ),
126     pAccMap( 0 ),
127     pSdrObjCached(NULL),
128     nRestoreActions( 0 ),
129     // OD 12.12.2002 #103492#
130     mpPgPrevwLayout( 0 )
131 {
132 	//bResetXorVisibility =
133 	//HMHbShowHdlPaint =
134     bResetHdlHiddenPaint =
135     bSmoothUpdate = bStopSmooth = bStopPrt = sal_False;
136     bFirstPageInvalid = sal_True;
137 }
138 
139 /******************************************************************************
140 |*
141 |*	SwViewImp::~SwViewImp()
142 |*
143 |*	Ersterstellung		MA 25. Jul. 94
144 |*	Letzte Aenderung	MA 16. Dec. 94
145 |*
146 ******************************************************************************/
147 
148 SwViewImp::~SwViewImp()
149 {
150 	delete pAccMap;
151 
152     // OD 12.12.2002 #103492#
153     delete mpPgPrevwLayout;
154 
155     //JP 29.03.96: nach ShowSdrPage muss auch HideSdrPage gemacht werden!!!
156 	if( pDrawView )
157  		pDrawView->HideSdrPage();
158 
159 	delete pDrawView;
160 
161     DelRegion();
162 
163 	ASSERT( !pLayAct, "Have action for the rest of your life." );
164 	ASSERT( !pIdleAct,"Be idle for the rest of your life." );
165 }
166 
167 /******************************************************************************
168 |*
169 |*	SwViewImp::DelRegions()
170 |*
171 |*	Ersterstellung		MA 14. Apr. 94
172 |*	Letzte Aenderung	MA 14. Apr. 94
173 |*
174 ******************************************************************************/
175 
176 void SwViewImp::DelRegion()
177 {
178 	DELETEZ(pRegion);
179 }
180 
181 /******************************************************************************
182 |*
183 |*	SwViewImp::AddPaintRect()
184 |*
185 |*	Ersterstellung		MA ??
186 |*	Letzte Aenderung	MA 27. Jul. 94
187 |*
188 ******************************************************************************/
189 
190 sal_Bool SwViewImp::AddPaintRect( const SwRect &rRect )
191 {
192 	if ( rRect.IsOver( pSh->VisArea() ) )
193 	{
194 		if ( !pRegion )
195 			pRegion = new SwRegionRects( pSh->VisArea() );
196 		(*pRegion) -= rRect;
197 		return sal_True;
198 	}
199 	return sal_False;
200 }
201 
202 
203 /******************************************************************************
204 |*
205 |*	ViewImp::CheckWaitCrsr()
206 |*
207 |*	Ersterstellung		MA 10. Aug. 94
208 |*	Letzte Aenderung	MA 10. Aug. 94
209 |*
210 ******************************************************************************/
211 
212 void SwViewImp::CheckWaitCrsr()
213 {
214 	if ( pLayAct )
215 		pLayAct->CheckWaitCrsr();
216 }
217 
218 /******************************************************************************
219 |*
220 |*	ViewImp::IsCalcLayoutProgress()
221 |*
222 |*	Ersterstellung		MA 12. Aug. 94
223 |*	Letzte Aenderung	MA 12. Aug. 94
224 |*
225 ******************************************************************************/
226 
227 sal_Bool SwViewImp::IsCalcLayoutProgress() const
228 {
229 	if ( pLayAct )
230 		return pLayAct->IsCalcLayout();
231 	return sal_False;
232 }
233 
234 /******************************************************************************
235 |*
236 |*	ViewImp::IsUpdateExpFlds()
237 |*
238 |*	Ersterstellung		MA 28. Mar. 96
239 |*	Letzte Aenderung	MA 28. Mar. 96
240 |*
241 ******************************************************************************/
242 
243 sal_Bool SwViewImp::IsUpdateExpFlds()
244 {
245 	if ( pLayAct && pLayAct->IsCalcLayout() )
246 	{
247 		pLayAct->SetUpdateExpFlds();
248 		return sal_True;
249 	}
250  	return sal_False;
251 }
252 
253 
254 /******************************************************************************
255 |*
256 |*	SwViewImp::SetFirstVisPage(), ImplGetFirstVisPage();
257 |*
258 |*	Ersterstellung		MA 21. Sep. 93
259 |*	Letzte Aenderung	MA 08. Mar. 94
260 |*
261 ******************************************************************************/
262 
263 void SwViewImp::SetFirstVisPage()
264 {
265 	if ( pSh->bDocSizeChgd && pSh->VisArea().Top() > pSh->GetLayout()->Frm().Height() )
266 	{
267 		//Wir stecken in einer Action und die VisArea sitzt wegen
268 		//Loeschoperationen hinter der erste sichtbaren Seite.
269 		//Damit nicht zu heftig Formatiert wird, liefern wir die letzte Seite
270 		//zurueck.
271 		pFirstVisPage = (SwPageFrm*)pSh->GetLayout()->Lower();
272 		while ( pFirstVisPage && pFirstVisPage->GetNext() )
273 			pFirstVisPage = (SwPageFrm*)pFirstVisPage->GetNext();
274 	}
275 	else
276 	{
277         const SwViewOption* pSwViewOption = GetShell()->GetViewOptions();
278         const bool bBookMode = pSwViewOption->IsViewLayoutBookMode();
279 
280         SwPageFrm *pPage = (SwPageFrm*)pSh->GetLayout()->Lower();
281         SwRect aPageRect = pPage->Frm();
282 		while ( pPage && !aPageRect.IsOver( pSh->VisArea() ) )
283         {
284 			pPage = (SwPageFrm*)pPage->GetNext();
285             if ( pPage )
286             {
287                 aPageRect = pPage->Frm();
288                 if ( bBookMode && pPage->IsEmptyPage() )
289                 {
290                     const SwPageFrm& rFormatPage = pPage->GetFormatPage();
291                     aPageRect.SSize() = rFormatPage.Frm().SSize();
292                 }
293             }
294         }
295 		pFirstVisPage = pPage ? pPage : (SwPageFrm*)pSh->GetLayout()->Lower();
296 	}
297 	bFirstPageInvalid = sal_False;
298 }
299 
300 /******************************************************************************
301 |*
302 |*	SwViewImp::MakeDrawView();
303 |*
304 |*	Ersterstellung		AMA 01. Nov. 95
305 |*	Letzte Aenderung	AMA 01. Nov. 95
306 |*
307 ******************************************************************************/
308 
309 void SwViewImp::MakeDrawView()
310 {
311     IDocumentDrawModelAccess* pIDDMA = GetShell()->getIDocumentDrawModelAccess();
312 
313 	// the else here is not an error, _MakeDrawModel() calls this method again
314 	// after the DrawModel is created to create DrawViews for all shells...
315 	if( !pIDDMA->GetDrawModel() )
316 	{
317         pIDDMA->_MakeDrawModel();
318 	}
319 	else
320 	{
321 		if ( !pDrawView )
322 		{
323 			// #i72809#
324 			// Discussed with FME, he also thinks that the getPrinter is old and not correct. When i got
325 			// him right, it anyways returns GetOut() when it's a printer, but NULL when not. He suggested
326 			// to use GetOut() and check the existing cases.
327 			// Check worked well. Took a look at viewing, printing, PDF export and print preview with a test
328 			// document which has an empty 2nd page (right page, see bug)
329 			OutputDevice* pOutDevForDrawView = GetShell()->GetWin();
330 
331 			if(!pOutDevForDrawView)
332 			{
333 				// pOutDevForDrawView = (OutputDevice*)GetShell()->getIDocumentDeviceAccess()->getPrinter( false );
334 				pOutDevForDrawView = GetShell()->GetOut();
335 			}
336 
337 			pDrawView = new SwDrawView( *this, pIDDMA->GetDrawModel(), pOutDevForDrawView);
338 		}
339 
340 		GetDrawView()->SetActiveLayer( XubString::CreateFromAscii( RTL_CONSTASCII_STRINGPARAM( "Heaven" ) ) );
341 		const SwViewOption* pSwViewOption = GetShell()->GetViewOptions();
342 		Init(pSwViewOption);
343 
344 		// #i68597# If document is read-only, we will not profit from overlay,
345 		// so switch it off.
346 		if(pDrawView && pDrawView->IsBufferedOverlayAllowed())
347 		{
348 			bool bIsReadOnly(pSwViewOption->IsReadonly());
349 
350 #ifdef DBG_UTIL
351 			// add test possibilities
352 			static bool bAlwaysActivateForTest(false);
353 			if(bAlwaysActivateForTest && bIsReadOnly)
354 			{
355 				bIsReadOnly = false;
356 			}
357 #endif
358 
359 			if(bIsReadOnly)
360 			{
361 				pDrawView->SetBufferedOverlayAllowed(false);
362 			}
363 		}
364 	}
365 }
366 
367 /******************************************************************************
368 |*
369 |*	SwViewImp::GetRetoucheColor()
370 |*
371 |*	Ersterstellung		MA 24. Jun. 98
372 |*	Letzte Aenderung	MA 24. Jun. 98
373 |*
374 ******************************************************************************/
375 
376 Color SwViewImp::GetRetoucheColor() const
377 {
378     Color aRet( COL_TRANSPARENT );
379 	const ViewShell &rSh = *GetShell();
380 	if ( rSh.GetWin() )
381 	{
382         if ( rSh.GetViewOptions()->getBrowseMode() &&
383 			 COL_TRANSPARENT != rSh.GetViewOptions()->GetRetoucheColor().GetColor() )
384 			aRet = rSh.GetViewOptions()->GetRetoucheColor();
385         else if(rSh.GetViewOptions()->IsPagePreview()  &&
386                     !SW_MOD()->GetAccessibilityOptions().GetIsForPagePreviews())
387             aRet.SetColor(COL_WHITE);
388         else
389             aRet = SwViewOption::GetDocColor();
390     }
391 	return aRet;
392 }
393 
394 /** create page preview layout
395 
396     OD 12.12.2002 #103492#
397 
398     @author OD
399 */
400 void SwViewImp::InitPagePreviewLayout()
401 {
402     ASSERT( pSh->GetLayout(), "no layout - page preview layout can not be created.");
403     if ( pSh->GetLayout() )
404         mpPgPrevwLayout = new SwPagePreviewLayout( *pSh, *(pSh->GetLayout()) );
405 }
406 
407 void SwViewImp::UpdateAccessible()
408 {
409 	// We require a layout and an XModel to be accessible.
410     IDocumentLayoutAccess* pIDLA = GetShell()->getIDocumentLayoutAccess();
411 	Window *pWin = GetShell()->GetWin();
412     ASSERT( GetShell()->GetLayout(), "no layout, no access" );	//swmod 071108//swmod 071225
413 	ASSERT( pWin, "no window, no access" );
414 
415     if( IsAccessible() && pIDLA->GetCurrentViewShell() && pWin )	//swmod 071108//swmod 071225
416 		GetAccessibleMap().GetDocumentView();
417 }
418 
419 void SwViewImp::DisposeAccessible( const SwFrm *pFrm,
420 								   const SdrObject *pObj,
421 								   sal_Bool bRecursive )
422 {
423 	ASSERT( !pFrm || pFrm->IsAccessibleFrm(), "frame is not accessible" );
424 	ViewShell *pVSh = GetShell();
425 	ViewShell *pTmp = pVSh;
426 	do
427 	{
428 		if( pTmp->Imp()->IsAccessible() )
429             pTmp->Imp()->GetAccessibleMap().Dispose( pFrm, pObj, 0, bRecursive );
430 		pTmp = (ViewShell *)pTmp->GetNext();
431 	} while ( pTmp != pVSh );
432 }
433 
434 void SwViewImp::MoveAccessible( const SwFrm *pFrm, const SdrObject *pObj,
435 								const SwRect& rOldFrm )
436 {
437 	ASSERT( !pFrm || pFrm->IsAccessibleFrm(), "frame is not accessible" );
438 	ViewShell *pVSh = GetShell();
439 	ViewShell *pTmp = pVSh;
440 	do
441 	{
442 		if( pTmp->Imp()->IsAccessible() )
443             pTmp->Imp()->GetAccessibleMap().InvalidatePosOrSize( pFrm, pObj, 0,
444 																 rOldFrm );
445 		pTmp = (ViewShell *)pTmp->GetNext();
446 	} while ( pTmp != pVSh );
447 }
448 
449 void SwViewImp::InvalidateAccessibleFrmContent( const SwFrm *pFrm )
450 {
451 	ASSERT( pFrm->IsAccessibleFrm(), "frame is not accessible" );
452 	ViewShell *pVSh = GetShell();
453 	ViewShell *pTmp = pVSh;
454 	do
455 	{
456 		if( pTmp->Imp()->IsAccessible() )
457 			pTmp->Imp()->GetAccessibleMap().InvalidateContent( pFrm );
458 		pTmp = (ViewShell *)pTmp->GetNext();
459 	} while ( pTmp != pVSh );
460 }
461 
462 void SwViewImp::InvalidateAccessibleCursorPosition( const SwFrm *pFrm )
463 {
464 	if( IsAccessible() )
465 		GetAccessibleMap().InvalidateCursorPosition( pFrm );
466 }
467 
468 void SwViewImp::InvalidateAccessibleEditableState( sal_Bool bAllShells,
469 	   											   const SwFrm *pFrm	)
470 {
471 	if( bAllShells )
472 	{
473 		ViewShell *pVSh = GetShell();
474 		ViewShell *pTmp = pVSh;
475 		do
476 		{
477 			if( pTmp->Imp()->IsAccessible() )
478 				pTmp->Imp()->GetAccessibleMap().InvalidateStates( ACC_STATE_EDITABLE, pFrm );
479 			pTmp = (ViewShell *)pTmp->GetNext();
480 		} while ( pTmp != pVSh );
481 	}
482 	else if( IsAccessible() )
483 	{
484 		GetAccessibleMap().InvalidateStates( ACC_STATE_EDITABLE, pFrm );
485 	}
486 }
487 
488 void SwViewImp::InvalidateAccessibleRelationSet( const SwFlyFrm *pMaster,
489                                                  const SwFlyFrm *pFollow )
490 {
491 	ViewShell *pVSh = GetShell();
492 	ViewShell *pTmp = pVSh;
493 	do
494 	{
495 		if( pTmp->Imp()->IsAccessible() )
496 			pTmp->Imp()->GetAccessibleMap().InvalidateRelationSet( pMaster,
497                                                                    pFollow );
498 		pTmp = (ViewShell *)pTmp->GetNext();
499 	} while ( pTmp != pVSh );
500 }
501 
502  /** invalidate CONTENT_FLOWS_FROM/_TO relation for paragraphs
503 
504     OD 2005-12-01 #i27138#
505 
506     @author OD
507 */
508 void SwViewImp::_InvalidateAccessibleParaFlowRelation( const SwTxtFrm* _pFromTxtFrm,
509                                                        const SwTxtFrm* _pToTxtFrm )
510 {
511     if ( !_pFromTxtFrm && !_pToTxtFrm )
512     {
513         // No text frame provided. Thus, nothing to do.
514         return;
515     }
516 
517     ViewShell* pVSh = GetShell();
518     ViewShell* pTmp = pVSh;
519     do
520     {
521         if ( pTmp->Imp()->IsAccessible() )
522         {
523             if ( _pFromTxtFrm )
524             {
525                 pTmp->Imp()->GetAccessibleMap().
526                             InvalidateParaFlowRelation( *_pFromTxtFrm, true );
527             }
528             if ( _pToTxtFrm )
529             {
530                 pTmp->Imp()->GetAccessibleMap().
531                             InvalidateParaFlowRelation( *_pToTxtFrm, false );
532             }
533         }
534         pTmp = (ViewShell *)pTmp->GetNext();
535     } while ( pTmp != pVSh );
536 }
537 
538 /** invalidate text selection for paragraphs
539 
540     OD 2005-12-12 #i27301#
541 
542     @author OD
543 */
544 void SwViewImp::_InvalidateAccessibleParaTextSelection()
545 {
546     ViewShell* pVSh = GetShell();
547     ViewShell* pTmp = pVSh;
548     do
549     {
550         if ( pTmp->Imp()->IsAccessible() )
551         {
552             pTmp->Imp()->GetAccessibleMap().InvalidateTextSelectionOfAllParas();
553         }
554 
555         pTmp = (ViewShell *)pTmp->GetNext();
556     } while ( pTmp != pVSh );
557 }
558 
559 /** invalidate attributes for paragraphs
560 
561     OD 2009-01-06 #i88069#
562 
563     @author OD
564 */
565 void SwViewImp::_InvalidateAccessibleParaAttrs( const SwTxtFrm& rTxtFrm )
566 {
567     ViewShell* pVSh = GetShell();
568     ViewShell* pTmp = pVSh;
569     do
570     {
571         if ( pTmp->Imp()->IsAccessible() )
572         {
573             pTmp->Imp()->GetAccessibleMap().InvalidateAttr( rTxtFrm );
574         }
575 
576         pTmp = (ViewShell *)pTmp->GetNext();
577     } while ( pTmp != pVSh );
578 }
579 
580 // OD 15.01.2003 #103492# - method signature change due to new page preview functionality
581 void SwViewImp::UpdateAccessiblePreview( const std::vector<PrevwPage*>& _rPrevwPages,
582                                          const Fraction&  _rScale,
583                                          const SwPageFrm* _pSelectedPageFrm,
584                                          const Size&      _rPrevwWinSize )
585 {
586     if( IsAccessible() )
587         GetAccessibleMap().UpdatePreview( _rPrevwPages, _rScale,
588                                           _pSelectedPageFrm, _rPrevwWinSize );
589 }
590 
591 void SwViewImp::InvalidateAccessiblePreViewSelection( sal_uInt16 nSelPage )
592 {
593     if( IsAccessible() )
594         GetAccessibleMap().InvalidatePreViewSelection( nSelPage );
595 }
596 
597 SwAccessibleMap *SwViewImp::CreateAccessibleMap()
598 {
599 	ASSERT( !pAccMap, "accessible map exists" )
600 	pAccMap = new SwAccessibleMap( GetShell() );
601 	return pAccMap;
602 }
603 
604 void SwViewImp::FireAccessibleEvents()
605 {
606 	if( IsAccessible() )
607 		GetAccessibleMap().FireEvents();
608 }
609 
610 IMPL_LINK(SwViewImp, SetStopPrt, void *, EMPTYARG)
611 {
612 	bStopPrt = sal_True;
613 
614 	return 0;
615 }
616 
617