Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #include "crsrsh.hxx"
21 : #include "rootfrm.hxx"
22 : #include "pagefrm.hxx"
23 : #include "viewimp.hxx"
24 : #include "viewopt.hxx"
25 : #include "flyfrm.hxx"
26 : #include "frmfmt.hxx"
27 : #include "layact.hxx"
28 : #include "swregion.hxx"
29 : #include "dflyobj.hxx"
30 : #include "dview.hxx"
31 : #include <swmodule.hxx>
32 : #include <svx/svdpage.hxx>
33 : #include <accmap.hxx>
34 :
35 : #include <pagepreviewlayout.hxx>
36 : #include <comcore.hrc>
37 : #include <svx/svdundo.hxx>
38 : #include <IDocumentLayoutAccess.hxx>
39 : #include <IDocumentDrawModelAccess.hxx>
40 : #include <IDocumentDeviceAccess.hxx>
41 : #include <IDocumentSettingAccess.hxx>
42 : #include <drawdoc.hxx>
43 :
44 3109 : void SwViewShellImp::Init( const SwViewOption *pNewOpt )
45 : {
46 : OSL_ENSURE( pDrawView, "SwViewShellImp::Init without DrawView" );
47 : //Create PageView if it doesn't exist
48 3109 : SwRootFrm *pRoot = pSh->GetLayout();
49 3109 : if ( !pSdrPageView )
50 : {
51 3109 : IDocumentDrawModelAccess* pIDDMA = pSh->getIDocumentDrawModelAccess();
52 3109 : if ( !pRoot->GetDrawPage() )
53 0 : pRoot->SetDrawPage( pIDDMA->GetDrawModel()->GetPage( 0 ) );
54 :
55 3109 : if ( pRoot->GetDrawPage()->GetSize() != pRoot->Frm().SSize() )
56 3042 : pRoot->GetDrawPage()->SetSize( pRoot->Frm().SSize() );
57 :
58 3109 : pSdrPageView = pDrawView->ShowSdrPage( pRoot->GetDrawPage());
59 : // OD 26.06.2003 #108784# - notify drawing page view about invisible
60 : // layers.
61 3109 : pIDDMA->NotifyInvisibleLayers( *pSdrPageView );
62 : }
63 3109 : pDrawView->SetDragStripes( pNewOpt->IsCrossHair() );
64 3109 : pDrawView->SetGridSnap( pNewOpt->IsSnap() );
65 3109 : pDrawView->SetGridVisible( pNewOpt->IsGridVisible() );
66 3109 : const Size &rSz = pNewOpt->GetSnapSize();
67 3109 : pDrawView->SetGridCoarse( rSz );
68 : const Size aFSize
69 15545 : ( rSz.Width() ? rSz.Width() /std::max(short(1),pNewOpt->GetDivisionX()):0,
70 18654 : rSz.Height()? rSz.Height()/std::max(short(1),pNewOpt->GetDivisionY()):0);
71 3109 : pDrawView->SetGridFine( aFSize );
72 3109 : Fraction aSnGrWdtX(rSz.Width(), pNewOpt->GetDivisionX() + 1);
73 6218 : Fraction aSnGrWdtY(rSz.Height(), pNewOpt->GetDivisionY() + 1);
74 3109 : pDrawView->SetSnapGridWidth( aSnGrWdtX, aSnGrWdtY );
75 :
76 3109 : if ( pRoot->Frm().HasArea() )
77 3106 : pDrawView->SetWorkArea( pRoot->Frm().SVRect() );
78 :
79 3109 : if ( GetShell()->IsPreview() )
80 0 : pDrawView->SetAnimationEnabled( false );
81 :
82 3109 : pDrawView->SetUseIncompatiblePathCreateInterface( false );
83 :
84 : // set handle size to 9 pixels, always
85 6218 : pDrawView->SetMarkHdlSizePixel(9);
86 3109 : }
87 :
88 : /// CTor for the core internals
89 3109 : SwViewShellImp::SwViewShellImp( SwViewShell *pParent ) :
90 : pSh( pParent ),
91 : pDrawView( 0 ),
92 : pSdrPageView( 0 ),
93 : pFirstVisPage( 0 ),
94 : pRegion( 0 ),
95 : pLayAct( 0 ),
96 : pIdleAct( 0 ),
97 : pAccMap( 0 ),
98 : pSdrObjCached(NULL),
99 : bFirstPageInvalid( true ),
100 : bResetHdlHiddenPaint( false ),
101 : bSmoothUpdate( false ),
102 : bStopSmooth( false ),
103 : nRestoreActions( 0 ),
104 : // OD 12.12.2002 #103492#
105 3109 : mpPgPreviewLayout( 0 )
106 : {
107 3109 : }
108 :
109 6210 : SwViewShellImp::~SwViewShellImp()
110 : {
111 3105 : delete pAccMap;
112 :
113 : // OD 12.12.2002 #103492#
114 3105 : delete mpPgPreviewLayout;
115 :
116 : //JP 29.03.96: after ShowSdrPage HideSdrPage must also be executed!!!
117 3105 : if( pDrawView )
118 3105 : pDrawView->HideSdrPage();
119 :
120 3105 : delete pDrawView;
121 :
122 3105 : DelRegion();
123 :
124 : OSL_ENSURE( !pLayAct, "Have action for the rest of your life." );
125 : OSL_ENSURE( !pIdleAct,"Be idle for the rest of your life." );
126 3105 : }
127 :
128 7887 : void SwViewShellImp::DelRegion()
129 : {
130 7887 : DELETEZ(pRegion);
131 7887 : }
132 :
133 27255 : bool SwViewShellImp::AddPaintRect( const SwRect &rRect )
134 : {
135 : // In case of tiled rendering the visual area is the last painted tile -> not interesting.
136 27255 : if ( rRect.IsOver( pSh->VisArea() ) || pSh->isTiledRendering() )
137 : {
138 14703 : if ( !pRegion )
139 : {
140 : // In case of normal rendering, this makes sure only visible rectangles are painted.
141 : // Otherwise get the rectangle of the full document, so all paint rectangles are invalidated.
142 4093 : const SwRect& rArea = pSh->isTiledRendering() ? pSh->GetLayout()->Frm() : pSh->VisArea();
143 4093 : pRegion = new SwRegionRects( rArea );
144 : }
145 14703 : (*pRegion) -= rRect;
146 14703 : return true;
147 : }
148 12552 : return false;
149 : }
150 :
151 915 : void SwViewShellImp::CheckWaitCrsr()
152 : {
153 915 : if ( pLayAct )
154 728 : pLayAct->CheckWaitCrsr();
155 915 : }
156 :
157 22307 : bool SwViewShellImp::IsCalcLayoutProgress() const
158 : {
159 22307 : return pLayAct && pLayAct->IsCalcLayout();
160 : }
161 :
162 13371 : bool SwViewShellImp::IsUpdateExpFields()
163 : {
164 13371 : if ( pLayAct && pLayAct->IsCalcLayout() )
165 : {
166 6412 : pLayAct->SetUpdateExpFields();
167 6412 : return true;
168 : }
169 6959 : return false;
170 : }
171 :
172 16556 : void SwViewShellImp::SetFirstVisPage()
173 : {
174 16556 : if ( pSh->mbDocSizeChgd && pSh->VisArea().Top() > pSh->GetLayout()->Frm().Height() )
175 : {
176 : //We are in an action and because of erase actions the VisArea is
177 : //after the first visible page.
178 : //To avoid excessive formatting, hand back the last page.
179 2 : pFirstVisPage = static_cast<SwPageFrm*>(pSh->GetLayout()->Lower());
180 8 : while ( pFirstVisPage && pFirstVisPage->GetNext() )
181 4 : pFirstVisPage = static_cast<SwPageFrm*>(pFirstVisPage->GetNext());
182 : }
183 : else
184 : {
185 16554 : const SwViewOption* pSwViewOption = GetShell()->GetViewOptions();
186 16554 : const bool bBookMode = pSwViewOption->IsViewLayoutBookMode();
187 :
188 16554 : SwPageFrm *pPage = static_cast<SwPageFrm*>(pSh->GetLayout()->Lower());
189 16554 : SwRect aPageRect = pPage->GetBoundRect();
190 16554 : float fAmount = pSh->VisArea().Height() * 0.43;
191 33682 : while ( pPage && aPageRect.Bottom() < pSh->VisArea().Top() + fAmount )
192 : {
193 574 : pPage = static_cast<SwPageFrm*>(pPage->GetNext());
194 574 : if ( pPage )
195 : {
196 567 : aPageRect = pPage->GetBoundRect();
197 567 : if ( bBookMode && pPage->IsEmptyPage() )
198 : {
199 0 : const SwPageFrm& rFormatPage = pPage->GetFormatPage();
200 0 : aPageRect.SSize() = rFormatPage.GetBoundRect().SSize();
201 : }
202 : }
203 : }
204 16554 : pFirstVisPage = pPage ? pPage : static_cast<SwPageFrm*>(pSh->GetLayout()->Lower());
205 : }
206 16556 : bFirstPageInvalid = false;
207 16556 : }
208 :
209 3109 : void SwViewShellImp::MakeDrawView()
210 : {
211 3109 : IDocumentDrawModelAccess* pIDDMA = GetShell()->getIDocumentDrawModelAccess();
212 :
213 : // the else here is not an error, _MakeDrawModel() calls this method again
214 : // after the DrawModel is created to create DrawViews for all shells...
215 3109 : if( !pIDDMA->GetDrawModel() )
216 : {
217 0 : pIDDMA->_MakeDrawModel();
218 : }
219 : else
220 : {
221 3109 : if ( !pDrawView )
222 : {
223 : // #i72809#
224 : // Discussed with FME, he also thinks that the getPrinter is old and not correct. When i got
225 : // him right, it anyways returns GetOut() when it's a printer, but NULL when not. He suggested
226 : // to use GetOut() and check the existing cases.
227 : // Check worked well. Took a look at viewing, printing, PDF export and print preview with a test
228 : // document which has an empty 2nd page (right page, see bug)
229 3109 : OutputDevice* pOutDevForDrawView = GetShell()->GetWin();
230 :
231 3109 : if(!pOutDevForDrawView)
232 : {
233 348 : pOutDevForDrawView = GetShell()->GetOut();
234 : }
235 :
236 3109 : pDrawView = new SwDrawView( *this, pIDDMA->GetDrawModel(), pOutDevForDrawView);
237 : }
238 :
239 3109 : GetDrawView()->SetActiveLayer("Heaven");
240 3109 : const SwViewOption* pSwViewOption = GetShell()->GetViewOptions();
241 3109 : Init(pSwViewOption);
242 :
243 : // #i68597# If document is read-only, we will not profit from overlay,
244 : // so switch it off.
245 3109 : if (pDrawView->IsBufferedOverlayAllowed())
246 : {
247 3109 : if(pSwViewOption->IsReadonly())
248 : {
249 1 : pDrawView->SetBufferedOverlayAllowed(false);
250 : }
251 : }
252 : }
253 3109 : }
254 :
255 9435 : Color SwViewShellImp::GetRetoucheColor() const
256 : {
257 9435 : Color aRet( COL_TRANSPARENT );
258 9435 : const SwViewShell &rSh = *GetShell();
259 9435 : if ( rSh.GetWin() )
260 : {
261 9176 : if ( rSh.GetViewOptions()->getBrowseMode() &&
262 89 : COL_TRANSPARENT != rSh.GetViewOptions()->GetRetoucheColor().GetColor() )
263 0 : aRet = rSh.GetViewOptions()->GetRetoucheColor();
264 9087 : else if(rSh.GetViewOptions()->IsPagePreview() &&
265 0 : !SW_MOD()->GetAccessibilityOptions().GetIsForPagePreviews())
266 0 : aRet.SetColor(COL_WHITE);
267 : else
268 9087 : aRet = SwViewOption::GetDocColor();
269 : }
270 9435 : return aRet;
271 : }
272 :
273 : // create page preview layout
274 0 : void SwViewShellImp::InitPagePreviewLayout()
275 : {
276 : OSL_ENSURE( pSh->GetLayout(), "no layout - page preview layout can not be created.");
277 0 : if ( pSh->GetLayout() )
278 0 : mpPgPreviewLayout = new SwPagePreviewLayout( *pSh, *(pSh->GetLayout()) );
279 0 : }
280 :
281 25 : void SwViewShellImp::UpdateAccessible()
282 : {
283 : // We require a layout and an XModel to be accessible.
284 25 : IDocumentLayoutAccess* pIDLA = GetShell()->getIDocumentLayoutAccess();
285 25 : vcl::Window *pWin = GetShell()->GetWin();
286 : OSL_ENSURE( GetShell()->GetLayout(), "no layout, no access" );
287 : OSL_ENSURE( pWin, "no window, no access" );
288 :
289 25 : if( IsAccessible() && pIDLA->GetCurrentViewShell() && pWin )
290 25 : GetAccessibleMap().GetDocumentView();
291 25 : }
292 :
293 0 : void SwViewShellImp::DisposeAccessible( const SwFrm *pFrm,
294 : const SdrObject *pObj,
295 : bool bRecursive )
296 : {
297 : OSL_ENSURE( !pFrm || pFrm->IsAccessibleFrm(), "frame is not accessible" );
298 0 : for(SwViewShell& rTmp : GetShell()->GetRingContainer())
299 : {
300 0 : if( rTmp.Imp()->IsAccessible() )
301 0 : rTmp.Imp()->GetAccessibleMap().Dispose( pFrm, pObj, 0, bRecursive );
302 : }
303 0 : }
304 :
305 58 : void SwViewShellImp::MoveAccessible( const SwFrm *pFrm, const SdrObject *pObj,
306 : const SwRect& rOldFrm )
307 : {
308 : OSL_ENSURE( !pFrm || pFrm->IsAccessibleFrm(), "frame is not accessible" );
309 116 : for(SwViewShell& rTmp : GetShell()->GetRingContainer())
310 : {
311 58 : if( rTmp.Imp()->IsAccessible() )
312 58 : rTmp.Imp()->GetAccessibleMap().InvalidatePosOrSize( pFrm, pObj, 0,
313 58 : rOldFrm );
314 : }
315 58 : }
316 :
317 0 : void SwViewShellImp::InvalidateAccessibleFrmContent( const SwFrm *pFrm )
318 : {
319 : OSL_ENSURE( pFrm->IsAccessibleFrm(), "frame is not accessible" );
320 0 : for(SwViewShell& rTmp : GetShell()->GetRingContainer())
321 : {
322 0 : if( rTmp.Imp()->IsAccessible() )
323 0 : rTmp.Imp()->GetAccessibleMap().InvalidateContent( pFrm );
324 : }
325 0 : }
326 :
327 83 : void SwViewShellImp::InvalidateAccessibleCursorPosition( const SwFrm *pFrm )
328 : {
329 83 : if( IsAccessible() )
330 83 : GetAccessibleMap().InvalidateCursorPosition( pFrm );
331 83 : }
332 :
333 0 : void SwViewShellImp::InvalidateAccessibleEditableState( bool bAllShells,
334 : const SwFrm *pFrm )
335 : {
336 0 : if( bAllShells )
337 : {
338 0 : for(SwViewShell& rTmp : GetShell()->GetRingContainer())
339 : {
340 0 : if( rTmp.Imp()->IsAccessible() )
341 0 : rTmp.Imp()->GetAccessibleMap().InvalidateStates( AccessibleStates::EDITABLE, pFrm );
342 : }
343 : }
344 0 : else if( IsAccessible() )
345 : {
346 0 : GetAccessibleMap().InvalidateStates( AccessibleStates::EDITABLE, pFrm );
347 : }
348 0 : }
349 :
350 0 : void SwViewShellImp::InvalidateAccessibleRelationSet( const SwFlyFrm *pMaster,
351 : const SwFlyFrm *pFollow )
352 : {
353 0 : for(SwViewShell& rTmp : GetShell()->GetRingContainer())
354 : {
355 0 : if( rTmp.Imp()->IsAccessible() )
356 0 : rTmp.Imp()->GetAccessibleMap().InvalidateRelationSet( pMaster,
357 0 : pFollow );
358 : }
359 0 : }
360 :
361 : /// invalidate CONTENT_FLOWS_FROM/_TO relation for paragraphs
362 0 : void SwViewShellImp::_InvalidateAccessibleParaFlowRelation( const SwTextFrm* _pFromTextFrm,
363 : const SwTextFrm* _pToTextFrm )
364 : {
365 0 : if ( !_pFromTextFrm && !_pToTextFrm )
366 : {
367 : // No text frame provided. Thus, nothing to do.
368 0 : return;
369 : }
370 :
371 0 : for(SwViewShell& rTmp : GetShell()->GetRingContainer())
372 : {
373 0 : if ( rTmp.Imp()->IsAccessible() )
374 : {
375 0 : if ( _pFromTextFrm )
376 : {
377 0 : rTmp.Imp()->GetAccessibleMap().
378 0 : InvalidateParaFlowRelation( *_pFromTextFrm, true );
379 : }
380 0 : if ( _pToTextFrm )
381 : {
382 0 : rTmp.Imp()->GetAccessibleMap().
383 0 : InvalidateParaFlowRelation( *_pToTextFrm, false );
384 : }
385 : }
386 : }
387 : }
388 :
389 : /// invalidate text selection for paragraphs
390 83 : void SwViewShellImp::_InvalidateAccessibleParaTextSelection()
391 : {
392 166 : for(SwViewShell& rTmp : GetShell()->GetRingContainer())
393 : {
394 83 : if ( rTmp.Imp()->IsAccessible() )
395 : {
396 83 : rTmp.Imp()->GetAccessibleMap().InvalidateTextSelectionOfAllParas();
397 : }
398 : }
399 83 : }
400 :
401 : /// invalidate attributes for paragraphs
402 0 : void SwViewShellImp::_InvalidateAccessibleParaAttrs( const SwTextFrm& rTextFrm )
403 : {
404 0 : for(SwViewShell& rTmp : GetShell()->GetRingContainer())
405 : {
406 0 : if ( rTmp.Imp()->IsAccessible() )
407 : {
408 0 : rTmp.Imp()->GetAccessibleMap().InvalidateAttr( rTextFrm );
409 : }
410 : }
411 0 : }
412 :
413 : // OD 15.01.2003 #103492# - method signature change due to new page preview functionality
414 0 : void SwViewShellImp::UpdateAccessiblePreview( const std::vector<PreviewPage*>& _rPreviewPages,
415 : const Fraction& _rScale,
416 : const SwPageFrm* _pSelectedPageFrm,
417 : const Size& _rPreviewWinSize )
418 : {
419 0 : if( IsAccessible() )
420 0 : GetAccessibleMap().UpdatePreview( _rPreviewPages, _rScale,
421 0 : _pSelectedPageFrm, _rPreviewWinSize );
422 0 : }
423 :
424 0 : void SwViewShellImp::InvalidateAccessiblePreviewSelection( sal_uInt16 nSelPage )
425 : {
426 0 : if( IsAccessible() )
427 0 : GetAccessibleMap().InvalidatePreviewSelection( nSelPage );
428 0 : }
429 :
430 12 : SwAccessibleMap *SwViewShellImp::CreateAccessibleMap()
431 : {
432 : OSL_ENSURE( !pAccMap, "accessible map exists" );
433 12 : pAccMap = new SwAccessibleMap( GetShell() );
434 12 : return pAccMap;
435 : }
436 :
437 5377073 : void SwViewShellImp::FireAccessibleEvents()
438 : {
439 5377073 : if( IsAccessible() )
440 5377073 : GetAccessibleMap().FireEvents();
441 5377250 : }
442 :
443 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|