xref: /trunk/main/sw/source/core/view/viewimp.cxx (revision ca62e2c2083b5d0995f1245bad6c2edfb455fbec)
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 //IAccessibility2 Implementation 2009-----
450 void SwViewImp::FirePageChangeEvent(sal_uInt16 nOldPage, sal_uInt16 nNewPage)
451 {
452     if( IsAccessible() )
453         GetAccessibleMap().FirePageChangeEvent( nOldPage, nNewPage);
454 }
455 
456 void SwViewImp::FireSectionChangeEvent(sal_uInt16 nOldSection, sal_uInt16 nNewSection)
457 {
458     if( IsAccessible() )
459         GetAccessibleMap().FireSectionChangeEvent(nOldSection, nNewSection);
460 }
461 void SwViewImp::FireColumnChangeEvent(sal_uInt16 nOldColumn, sal_uInt16 nNewColumn)
462 {
463     if( IsAccessible() )
464         GetAccessibleMap().FireColumnChangeEvent(nOldColumn,  nNewColumn);
465 }
466 //-----IAccessibility2 Implementation 2009
467 void SwViewImp::InvalidateAccessibleFrmContent( const SwFrm *pFrm )
468 {
469     ASSERT( pFrm->IsAccessibleFrm(), "frame is not accessible" );
470     ViewShell *pVSh = GetShell();
471     ViewShell *pTmp = pVSh;
472     do
473     {
474         if( pTmp->Imp()->IsAccessible() )
475             pTmp->Imp()->GetAccessibleMap().InvalidateContent( pFrm );
476         pTmp = (ViewShell *)pTmp->GetNext();
477     } while ( pTmp != pVSh );
478 }
479 
480 void SwViewImp::InvalidateAccessibleCursorPosition( const SwFrm *pFrm )
481 {
482     if( IsAccessible() )
483         GetAccessibleMap().InvalidateCursorPosition( pFrm );
484 }
485 
486 void SwViewImp::InvalidateAccessibleEditableState( sal_Bool bAllShells,
487                                                    const SwFrm *pFrm    )
488 {
489     if( bAllShells )
490     {
491         ViewShell *pVSh = GetShell();
492         ViewShell *pTmp = pVSh;
493         do
494         {
495             if( pTmp->Imp()->IsAccessible() )
496                 pTmp->Imp()->GetAccessibleMap().InvalidateStates( ACC_STATE_EDITABLE, pFrm );
497             pTmp = (ViewShell *)pTmp->GetNext();
498         } while ( pTmp != pVSh );
499     }
500     else if( IsAccessible() )
501     {
502         GetAccessibleMap().InvalidateStates( ACC_STATE_EDITABLE, pFrm );
503     }
504 }
505 
506 void SwViewImp::InvalidateAccessibleRelationSet( const SwFlyFrm *pMaster,
507                                                  const SwFlyFrm *pFollow )
508 {
509     ViewShell *pVSh = GetShell();
510     ViewShell *pTmp = pVSh;
511     do
512     {
513         if( pTmp->Imp()->IsAccessible() )
514             pTmp->Imp()->GetAccessibleMap().InvalidateRelationSet( pMaster,
515                                                                    pFollow );
516         pTmp = (ViewShell *)pTmp->GetNext();
517     } while ( pTmp != pVSh );
518 }
519 
520  /** invalidate CONTENT_FLOWS_FROM/_TO relation for paragraphs
521 
522     OD 2005-12-01 #i27138#
523 
524     @author OD
525 */
526 void SwViewImp::_InvalidateAccessibleParaFlowRelation( const SwTxtFrm* _pFromTxtFrm,
527                                                        const SwTxtFrm* _pToTxtFrm )
528 {
529     if ( !_pFromTxtFrm && !_pToTxtFrm )
530     {
531         // No text frame provided. Thus, nothing to do.
532         return;
533     }
534 
535     ViewShell* pVSh = GetShell();
536     ViewShell* pTmp = pVSh;
537     do
538     {
539         if ( pTmp->Imp()->IsAccessible() )
540         {
541             if ( _pFromTxtFrm )
542             {
543                 pTmp->Imp()->GetAccessibleMap().
544                             InvalidateParaFlowRelation( *_pFromTxtFrm, true );
545             }
546             if ( _pToTxtFrm )
547             {
548                 pTmp->Imp()->GetAccessibleMap().
549                             InvalidateParaFlowRelation( *_pToTxtFrm, false );
550             }
551         }
552         pTmp = (ViewShell *)pTmp->GetNext();
553     } while ( pTmp != pVSh );
554 }
555 
556 /** invalidate text selection for paragraphs
557 
558     OD 2005-12-12 #i27301#
559 
560     @author OD
561 */
562 void SwViewImp::_InvalidateAccessibleParaTextSelection()
563 {
564     ViewShell* pVSh = GetShell();
565     ViewShell* pTmp = pVSh;
566     do
567     {
568         if ( pTmp->Imp()->IsAccessible() )
569         {
570             pTmp->Imp()->GetAccessibleMap().InvalidateTextSelectionOfAllParas();
571         }
572 
573         pTmp = (ViewShell *)pTmp->GetNext();
574     } while ( pTmp != pVSh );
575 }
576 
577 /** invalidate attributes for paragraphs
578 
579     OD 2009-01-06 #i88069#
580 
581     @author OD
582 */
583 void SwViewImp::_InvalidateAccessibleParaAttrs( const SwTxtFrm& rTxtFrm )
584 {
585     ViewShell* pVSh = GetShell();
586     ViewShell* pTmp = pVSh;
587     do
588     {
589         if ( pTmp->Imp()->IsAccessible() )
590         {
591             pTmp->Imp()->GetAccessibleMap().InvalidateAttr( rTxtFrm );
592         }
593 
594         pTmp = (ViewShell *)pTmp->GetNext();
595     } while ( pTmp != pVSh );
596 }
597 
598 // OD 15.01.2003 #103492# - method signature change due to new page preview functionality
599 void SwViewImp::UpdateAccessiblePreview( const std::vector<PrevwPage*>& _rPrevwPages,
600                                          const Fraction&  _rScale,
601                                          const SwPageFrm* _pSelectedPageFrm,
602                                          const Size&      _rPrevwWinSize )
603 {
604     if( IsAccessible() )
605         GetAccessibleMap().UpdatePreview( _rPrevwPages, _rScale,
606                                           _pSelectedPageFrm, _rPrevwWinSize );
607 }
608 
609 void SwViewImp::InvalidateAccessiblePreViewSelection( sal_uInt16 nSelPage )
610 {
611     if( IsAccessible() )
612         GetAccessibleMap().InvalidatePreViewSelection( nSelPage );
613 }
614 
615 SwAccessibleMap *SwViewImp::CreateAccessibleMap()
616 {
617     ASSERT( !pAccMap, "accessible map exists" )
618     pAccMap = new SwAccessibleMap( GetShell() );
619     return pAccMap;
620 }
621 
622 void SwViewImp::FireAccessibleEvents()
623 {
624     if( IsAccessible() )
625         GetAccessibleMap().FireEvents();
626 }
627 
628 IMPL_LINK(SwViewImp, SetStopPrt, void *, EMPTYARG)
629 {
630     bStopPrt = sal_True;
631 
632     return 0;
633 }
634 
635