Version 7.6.3.2-android, tag libreoffice-7.6.3.2-android
[LibreOffice.git] / sw / source / core / view / vnew.cxx
blob0d097f0a94752550df578ca3462fea6e9944688e
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sfx2/printer.hxx>
21 #include <sal/log.hxx>
22 #include <osl/diagnose.h>
23 #include <doc.hxx>
24 #include <IDocumentDrawModelAccess.hxx>
25 #include <IDocumentUndoRedo.hxx>
26 #include <DocumentSettingManager.hxx>
27 #include <IDocumentDeviceAccess.hxx>
28 #include <IDocumentLayoutAccess.hxx>
29 #include <IDocumentFieldsAccess.hxx>
30 #include <IDocumentState.hxx>
31 #include <docsh.hxx>
32 #include <viewsh.hxx>
33 #include <rootfrm.hxx>
34 #include <viewimp.hxx>
35 #include <viewopt.hxx>
36 #include <txtfrm.hxx>
37 #include <notxtfrm.hxx>
38 #include <fntcache.hxx>
39 #include <docufld.hxx>
40 #include <ptqueue.hxx>
41 #include <dview.hxx>
42 #include <ndgrf.hxx>
43 #include <ndindex.hxx>
44 #include <accessibilityoptions.hxx>
46 void SwViewShell::Init( const SwViewOption *pNewOpt )
48 mbDocSizeChgd = false;
50 // We play it safe: Remove old font information whenever the printer
51 // resolution or the zoom factor changes. For that, Init() and Reformat()
52 // are the most secure places.
53 pFntCache->Flush( );
55 // ViewOptions are created dynamically
57 if( !mpOpt )
59 mpOpt.reset(new SwViewOption);
61 // ApplyViewOptions() does not need to be called
62 if( pNewOpt )
64 *mpOpt = *pNewOpt;
65 // Zoom factor needs to be set because there is no call to ApplyViewOptions() during
66 // CTOR for performance reasons.
67 if( GetWin() && 100 != mpOpt->GetZoom() )
69 MapMode aMode( mpWin->GetMapMode() );
70 const Fraction aNewFactor( mpOpt->GetZoom(), 100 );
71 aMode.SetScaleX( aNewFactor );
72 aMode.SetScaleY( aNewFactor );
73 mpWin->SetMapMode( aMode );
78 SwDocShell* pDShell = mxDoc->GetDocShell();
79 mxDoc->GetDocumentSettingManager().set(DocumentSettingId::HTML_MODE, 0 != ::GetHtmlMode( pDShell ) );
80 // set readonly flag at ViewOptions before creating layout. Otherwise,
81 // one would have to reformat again.
83 if( pDShell && pDShell->IsReadOnly() )
84 mpOpt->SetReadonly( true );
86 SAL_INFO( "sw.core", "View::Init - before InitPrt" );
87 OutputDevice* pPDFOut = nullptr;
89 if (mpOut && (OUTDEV_PDF == mpOut->GetOutDevType()))
90 pPDFOut = mpOut;
92 // Only setup the printer if we need one:
93 const bool bBrowseMode = mpOpt->getBrowseMode();
94 if( pPDFOut )
95 InitPrt( pPDFOut );
97 // i#44963 Good occasion to check if page sizes in
98 // page descriptions are still set to (LONG_MAX, LONG_MAX) (html import)
99 if ( !bBrowseMode )
101 mxDoc->CheckDefaultPageFormat();
104 SAL_INFO( "sw.core", "View::Init - after InitPrt" );
105 if( GetWin() )
107 SwViewOption::Init( GetWin()->GetOutDev() );
108 GetWin()->GetOutDev()->SetFillColor();
109 GetWin()->SetBackground();
110 GetWin()->GetOutDev()->SetLineColor();
113 // Create a new layout, if there is no one available
114 if( !mpLayout )
116 // Here's the code which disables the usage of "multiple" layouts at the moment
117 // If the problems with controls and groups objects are solved,
118 // this code can be removed...
119 SwViewShell *pCurrShell = GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
120 if( pCurrShell )
121 mpLayout = pCurrShell->mpLayout;
122 // end of "disable multiple layouts"
123 if( !mpLayout )
125 // switched to two step construction because creating the layout in SwRootFrame needs a valid pLayout set
126 mpLayout = SwRootFramePtr(new SwRootFrame(mxDoc->GetDfltFrameFormat(), this),
127 &SwFrame::DestroyFrame);
128 mpLayout->Init( mxDoc->GetDfltFrameFormat() );
131 SizeChgNotify();
133 // XForms mode: initialize XForms mode, based on design mode (draw view)
134 // MakeDrawView() requires layout
135 if( GetDoc()->isXForms() )
137 if( ! HasDrawView() )
138 MakeDrawView();
139 mpOpt->SetFormView( ! GetDrawView()->IsDesignMode() );
143 /// CTor for the first Shell.
144 SwViewShell::SwViewShell( SwDoc& rDocument, vcl::Window *pWindow,
145 const SwViewOption *pNewOpt, OutputDevice *pOutput,
146 tools::Long nFlags )
148 mpSfxViewShell( nullptr ),
149 mpImp( new SwViewShellImp( this ) ),
150 mpWin( pWindow ),
151 mpOut( pOutput ? pOutput
152 : pWindow ? pWindow->GetOutDev()
153 : static_cast<OutputDevice*>(rDocument.getIDocumentDeviceAccess().getPrinter( true ))),
154 mpAccOptions( new SwAccessibilityOptions ),
155 mbShowHeaderSeparator( false ),
156 mbShowFooterSeparator( false ),
157 mbHeaderFooterEdit( false ),
158 mpTargetPaintWindow(nullptr),
159 mpBufferedOut(nullptr),
160 mxDoc( &rDocument ),
161 mnStartAction( 0 ),
162 mnLockPaint( 0 ),
163 mbSelectAll(false),
164 mbOutputToWindow(false),
165 mpPrePostOutDev(nullptr)
167 // in order to suppress event handling in
168 // <SwDrawContact::Changed> during construction of <SwViewShell> instance
169 mbInConstructor = true;
171 mbPaintInProgress = mbViewLocked = mbInEndAction = mbFrameView = false;
172 mbPaintWorks = mbEnableSmooth = true;
173 mbPreview = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
175 // i#38810 Do not reset modified state of document,
176 // if it's already been modified.
177 const bool bIsDocModified( mxDoc->getIDocumentState().IsModified() );
178 OutputDevice* pOrigOut = mpOut;
179 Init( pNewOpt ); // may change the Outdev (InitPrt())
180 mpOut = pOrigOut;
182 // initialize print preview layout after layout
183 // is created in <SwViewShell::Init(..)> - called above.
184 if ( mbPreview )
186 // init page preview layout
187 mpImp->InitPagePreviewLayout();
190 CurrShell aCurr( this );
192 static_cast<SwHiddenTextFieldType*>(mxDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::HiddenText ))->
193 SetHiddenFlag( !mpOpt->IsShowHiddenField() );
195 // In Init a standard FrameFormat is created.
196 if ( !mxDoc->GetIDocumentUndoRedo().IsUndoNoResetModified()
197 && !bIsDocModified )
199 mxDoc->getIDocumentState().ResetModified();
202 // extend format cache.
203 if ( SwTextFrame::GetTextCache()->GetCurMax() < 2550 )
204 SwTextFrame::GetTextCache()->IncreaseMax( 100 );
205 if( mpOpt->IsGridVisible() || getIDocumentDrawModelAccess().GetDrawModel() )
206 Imp()->MakeDrawView();
208 mbInConstructor = false;
211 /// CTor for further Shells on a document.
212 SwViewShell::SwViewShell( SwViewShell& rShell, vcl::Window *pWindow,
213 OutputDevice * pOutput, tools::Long const nFlags)
214 : Ring( &rShell ) ,
215 maBrowseBorder( rShell.maBrowseBorder ),
216 mpSfxViewShell( nullptr ),
217 mpImp( new SwViewShellImp( this ) ),
218 mpWin( pWindow ),
219 mpOut( pOutput ? pOutput
220 : pWindow ? pWindow->GetOutDev()
221 : static_cast<OutputDevice*>(rShell.GetDoc()->getIDocumentDeviceAccess().getPrinter( true ))),
222 mpAccOptions( new SwAccessibilityOptions ),
223 mbShowHeaderSeparator( false ),
224 mbShowFooterSeparator( false ),
225 mbHeaderFooterEdit( false ),
226 mpTargetPaintWindow(nullptr),
227 mpBufferedOut(nullptr),
228 mxDoc( rShell.GetDoc() ),
229 mnStartAction( 0 ),
230 mnLockPaint( 0 ),
231 mbSelectAll(false),
232 mbOutputToWindow(false),
233 mpPrePostOutDev(nullptr)
235 // in order to suppress event handling in
236 // <SwDrawContact::Changed> during construction of <SwViewShell> instance
237 mbInConstructor = true;
239 mbPaintWorks = mbEnableSmooth = true;
240 mbPaintInProgress = mbViewLocked = mbInEndAction = mbFrameView = false;
241 mbPreview = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
243 if( nFlags & VSHELLFLAG_SHARELAYOUT )
244 mpLayout = rShell.mpLayout;
246 CurrShell aCurr( this );
248 bool bModified = mxDoc->getIDocumentState().IsModified();
250 OutputDevice* pOrigOut = mpOut;
251 Init( rShell.GetViewOptions() ); // might change Outdev (InitPrt())
252 mpOut = pOrigOut;
254 if ( mbPreview )
255 mpImp->InitPagePreviewLayout();
257 static_cast<SwHiddenTextFieldType*>(mxDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::HiddenText ))->
258 SetHiddenFlag( !mpOpt->IsShowHiddenField() );
260 // In Init a standard FrameFormat is created.
261 if( !bModified && !mxDoc->GetIDocumentUndoRedo().IsUndoNoResetModified() )
263 mxDoc->getIDocumentState().ResetModified();
266 // extend format cache.
267 if ( SwTextFrame::GetTextCache()->GetCurMax() < 2550 )
268 SwTextFrame::GetTextCache()->IncreaseMax( 100 );
269 if( mpOpt->IsGridVisible() || getIDocumentDrawModelAccess().GetDrawModel() )
270 Imp()->MakeDrawView();
272 mbInConstructor = false;
276 SwViewShell::~SwViewShell()
278 IDocumentLayoutAccess* const pLayoutAccess
279 = mxDoc ? &mxDoc->getIDocumentLayoutAccess() : nullptr;
282 CurrShell aCurr( this );
283 mbPaintWorks = false;
285 // i#9684 Stopping the animated graphics is not
286 // necessary during printing or pdf export, because the animation
287 // has not been started in this case.
288 if( mxDoc && GetWin() )
290 SwNodes& rNds = mxDoc->GetNodes();
292 SwStartNode *pStNd;
293 SwNodeIndex aIdx( *rNds.GetEndOfAutotext().StartOfSectionNode(), 1 );
294 while ( nullptr != (pStNd = aIdx.GetNode().GetStartNode()) )
296 ++aIdx;
297 SwGrfNode *pGNd = aIdx.GetNode().GetGrfNode();
298 if ( nullptr != pGNd )
300 if( pGNd->IsAnimated() )
302 SwIterator<SwFrame,SwGrfNode> aIter( *pGNd );
303 for( SwFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next() )
305 OSL_ENSURE( pFrame->IsNoTextFrame(), "GraphicNode with Text?" );
306 static_cast<SwNoTextFrame*>(pFrame)->StopAnimation( mpOut );
310 aIdx.Assign( *pStNd->EndOfSectionNode(), +1 );
313 GetDoc()->StopNumRuleAnimations( mpOut );
316 mpImp.reset();
318 if (mxDoc)
320 if( mxDoc->getReferenceCount() > 1 )
321 GetLayout()->ResetNewLayout();
324 mpOpt.reset();
326 // resize format cache.
327 if ( SwTextFrame::GetTextCache()->GetCurMax() > 250 )
328 SwTextFrame::GetTextCache()->DecreaseMax( 100 );
330 // Remove from PaintQueue if necessary
331 SwPaintQueue::Remove( this );
333 OSL_ENSURE( !mnStartAction, "EndAction() pending." );
336 if ( pLayoutAccess )
338 GetLayout()->DeRegisterShell( this );
339 if(pLayoutAccess->GetCurrentViewShell()==this)
341 pLayoutAccess->SetCurrentViewShell(nullptr);
342 for(SwViewShell& rShell : GetRingContainer())
344 if(&rShell != this)
346 pLayoutAccess->SetCurrentViewShell(&rShell);
347 break;
353 mpAccOptions.reset();
356 bool SwViewShell::HasDrawView() const
358 return Imp() && Imp()->HasDrawView();
361 void SwViewShell::MakeDrawView()
363 Imp()->MakeDrawView( );
366 bool SwViewShell::HasDrawViewDrag() const
368 return Imp()->HasDrawView() && Imp()->GetDrawView()->IsDragObj();
371 SdrView* SwViewShell::GetDrawView()
373 return Imp()->GetDrawView();
376 SdrView* SwViewShell::GetDrawViewWithValidMarkList()
378 SwDrawView* pDView = Imp()->GetDrawView();
379 pDView->ValidateMarkList();
380 return pDView;
383 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */