nss: upgrade to release 3.73
[LibreOffice.git] / sw / source / core / view / vnew.cxx
blob44e632c5d4d00aa394b45e520b0822d75ec89d4a
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 <doc.hxx>
23 #include <IDocumentDrawModelAccess.hxx>
24 #include <IDocumentUndoRedo.hxx>
25 #include <DocumentSettingManager.hxx>
26 #include <IDocumentDeviceAccess.hxx>
27 #include <IDocumentLayoutAccess.hxx>
28 #include <IDocumentFieldsAccess.hxx>
29 #include <IDocumentState.hxx>
30 #include <docsh.hxx>
31 #include <viewsh.hxx>
32 #include <rootfrm.hxx>
33 #include <viewimp.hxx>
34 #include <viewopt.hxx>
35 #include <txtfrm.hxx>
36 #include <notxtfrm.hxx>
37 #include <fntcache.hxx>
38 #include <docufld.hxx>
39 #include <ptqueue.hxx>
40 #include <dview.hxx>
41 #include <ndgrf.hxx>
42 #include <ndindex.hxx>
43 #include <accessibilityoptions.hxx>
45 void SwViewShell::Init( const SwViewOption *pNewOpt )
47 mbDocSizeChgd = false;
49 // We play it safe: Remove old font information whenever the printer
50 // resolution or the zoom factor changes. For that, Init() and Reformat()
51 // are the most secure places.
52 pFntCache->Flush( );
54 // ViewOptions are created dynamically
56 if( !mpOpt )
58 mpOpt.reset(new SwViewOption);
60 // ApplyViewOptions() does not need to be called
61 if( pNewOpt )
63 *mpOpt = *pNewOpt;
64 // Zoom factor needs to be set because there is no call to ApplyViewOptions() during
65 // CTOR for performance reasons.
66 if( GetWin() && 100 != mpOpt->GetZoom() )
68 MapMode aMode( mpWin->GetMapMode() );
69 const Fraction aNewFactor( mpOpt->GetZoom(), 100 );
70 aMode.SetScaleX( aNewFactor );
71 aMode.SetScaleY( aNewFactor );
72 mpWin->SetMapMode( aMode );
77 SwDocShell* pDShell = mxDoc->GetDocShell();
78 mxDoc->GetDocumentSettingManager().set(DocumentSettingId::HTML_MODE, 0 != ::GetHtmlMode( pDShell ) );
79 // set readonly flag at ViewOptions before creating layout. Otherwise,
80 // one would have to reformat again.
82 if( pDShell && pDShell->IsReadOnly() )
83 mpOpt->SetReadonly( true );
85 SAL_INFO( "sw.core", "View::Init - before InitPrt" );
86 OutputDevice* pPDFOut = nullptr;
88 if (mpOut && (OUTDEV_PDF == mpOut->GetOutDevType()))
89 pPDFOut = mpOut;
91 // Only setup the printer if we need one:
92 const bool bBrowseMode = mpOpt->getBrowseMode();
93 if( pPDFOut )
94 InitPrt( pPDFOut );
96 // i#44963 Good occasion to check if page sizes in
97 // page descriptions are still set to (LONG_MAX, LONG_MAX) (html import)
98 if ( !bBrowseMode )
100 mxDoc->CheckDefaultPageFormat();
103 SAL_INFO( "sw.core", "View::Init - after InitPrt" );
104 if( GetWin() )
106 SwViewOption::Init( GetWin() );
107 GetWin()->SetFillColor();
108 GetWin()->SetBackground();
109 GetWin()->SetLineColor();
112 // Create a new layout, if there is no one available
113 if( !mpLayout )
115 // Here's the code which disables the usage of "multiple" layouts at the moment
116 // If the problems with controls and groups objects are solved,
117 // this code can be removed...
118 SwViewShell *pCurrShell = GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
119 if( pCurrShell )
120 mpLayout = pCurrShell->mpLayout;
121 // end of "disable multiple layouts"
122 if( !mpLayout )
124 // switched to two step construction because creating the layout in SwRootFrame needs a valid pLayout set
125 mpLayout = SwRootFramePtr(new SwRootFrame(mxDoc->GetDfltFrameFormat(), this),
126 &SwFrame::DestroyFrame);
127 mpLayout->Init( mxDoc->GetDfltFrameFormat() );
130 SizeChgNotify();
132 // XForms mode: initialize XForms mode, based on design mode (draw view)
133 // MakeDrawView() requires layout
134 if( GetDoc()->isXForms() )
136 if( ! HasDrawView() )
137 MakeDrawView();
138 mpOpt->SetFormView( ! GetDrawView()->IsDesignMode() );
142 /// CTor for the first Shell.
143 SwViewShell::SwViewShell( SwDoc& rDocument, vcl::Window *pWindow,
144 const SwViewOption *pNewOpt, OutputDevice *pOutput,
145 tools::Long nFlags )
147 maBrowseBorder(),
148 mpSfxViewShell( nullptr ),
149 mpImp( new SwViewShellImp( this ) ),
150 mpWin( pWindow ),
151 mpOut( pOutput ? pOutput
152 : pWindow ? static_cast<OutputDevice*>(pWindow)
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),
166 maPrePostMapMode()
168 // in order to suppress event handling in
169 // <SwDrawContact::Changed> during construction of <SwViewShell> instance
170 mbInConstructor = true;
172 mbPaintInProgress = mbViewLocked = mbInEndAction = mbFrameView =
173 mbEndActionByVirDev = false;
174 mbPaintWorks = mbEnableSmooth = true;
175 mbPreview = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
177 // i#38810 Do not reset modified state of document,
178 // if it's already been modified.
179 const bool bIsDocModified( mxDoc->getIDocumentState().IsModified() );
180 OutputDevice* pOrigOut = mpOut;
181 Init( pNewOpt ); // may change the Outdev (InitPrt())
182 mpOut = pOrigOut;
184 // initialize print preview layout after layout
185 // is created in <SwViewShell::Init(..)> - called above.
186 if ( mbPreview )
188 // init page preview layout
189 mpImp->InitPagePreviewLayout();
192 CurrShell aCurr( this );
194 static_cast<SwHiddenTextFieldType*>(mxDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::HiddenText ))->
195 SetHiddenFlag( !mpOpt->IsShowHiddenField() );
197 // In Init a standard FrameFormat is created.
198 if ( !mxDoc->GetIDocumentUndoRedo().IsUndoNoResetModified()
199 && !bIsDocModified )
201 mxDoc->getIDocumentState().ResetModified();
204 // extend format cache.
205 if ( SwTextFrame::GetTextCache()->GetCurMax() < 2550 )
206 SwTextFrame::GetTextCache()->IncreaseMax( 100 );
207 if( mpOpt->IsGridVisible() || getIDocumentDrawModelAccess().GetDrawModel() )
208 Imp()->MakeDrawView();
210 mbInConstructor = false;
213 /// CTor for further Shells on a document.
214 SwViewShell::SwViewShell( SwViewShell& rShell, vcl::Window *pWindow,
215 OutputDevice * pOutput, tools::Long const nFlags)
216 : Ring( &rShell ) ,
217 maBrowseBorder( rShell.maBrowseBorder ),
218 mpSfxViewShell( nullptr ),
219 mpImp( new SwViewShellImp( this ) ),
220 mpWin( pWindow ),
221 mpOut( pOutput ? pOutput
222 : pWindow ? static_cast<OutputDevice*>(pWindow)
223 : static_cast<OutputDevice*>(rShell.GetDoc()->getIDocumentDeviceAccess().getPrinter( true ))),
224 mpAccOptions( new SwAccessibilityOptions ),
225 mbShowHeaderSeparator( false ),
226 mbShowFooterSeparator( false ),
227 mbHeaderFooterEdit( false ),
228 mpTargetPaintWindow(nullptr),
229 mpBufferedOut(nullptr),
230 mxDoc( rShell.GetDoc() ),
231 mnStartAction( 0 ),
232 mnLockPaint( 0 ),
233 mbSelectAll(false),
234 mbOutputToWindow(false),
235 mpPrePostOutDev(nullptr),
236 maPrePostMapMode()
238 // in order to suppress event handling in
239 // <SwDrawContact::Changed> during construction of <SwViewShell> instance
240 mbInConstructor = true;
242 mbPaintWorks = mbEnableSmooth = true;
243 mbPaintInProgress = mbViewLocked = mbInEndAction = mbFrameView =
244 mbEndActionByVirDev = false;
245 mbPreview = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
247 if( nFlags & VSHELLFLAG_SHARELAYOUT )
248 mpLayout = rShell.mpLayout;
250 CurrShell aCurr( this );
252 bool bModified = mxDoc->getIDocumentState().IsModified();
254 OutputDevice* pOrigOut = mpOut;
255 Init( rShell.GetViewOptions() ); // might change Outdev (InitPrt())
256 mpOut = pOrigOut;
258 if ( mbPreview )
259 mpImp->InitPagePreviewLayout();
261 static_cast<SwHiddenTextFieldType*>(mxDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::HiddenText ))->
262 SetHiddenFlag( !mpOpt->IsShowHiddenField() );
264 // In Init a standard FrameFormat is created.
265 if( !bModified && !mxDoc->GetIDocumentUndoRedo().IsUndoNoResetModified() )
267 mxDoc->getIDocumentState().ResetModified();
270 // extend format cache.
271 if ( SwTextFrame::GetTextCache()->GetCurMax() < 2550 )
272 SwTextFrame::GetTextCache()->IncreaseMax( 100 );
273 if( mpOpt->IsGridVisible() || getIDocumentDrawModelAccess().GetDrawModel() )
274 Imp()->MakeDrawView();
276 mbInConstructor = false;
280 SwViewShell::~SwViewShell()
282 IDocumentLayoutAccess* const pLayoutAccess
283 = mxDoc ? &mxDoc->getIDocumentLayoutAccess() : nullptr;
286 CurrShell aCurr( this );
287 mbPaintWorks = false;
289 // i#9684 Stopping the animated graphics is not
290 // necessary during printing or pdf export, because the animation
291 // has not been started in this case.
292 if( mxDoc && GetWin() )
294 SwNodes& rNds = mxDoc->GetNodes();
296 SwStartNode *pStNd;
297 SwNodeIndex aIdx( *rNds.GetEndOfAutotext().StartOfSectionNode(), 1 );
298 while ( nullptr != (pStNd = aIdx.GetNode().GetStartNode()) )
300 ++aIdx;
301 SwGrfNode *pGNd = aIdx.GetNode().GetGrfNode();
302 if ( nullptr != pGNd )
304 if( pGNd->IsAnimated() )
306 SwIterator<SwFrame,SwGrfNode> aIter( *pGNd );
307 for( SwFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next() )
309 OSL_ENSURE( pFrame->IsNoTextFrame(), "GraphicNode with Text?" );
310 static_cast<SwNoTextFrame*>(pFrame)->StopAnimation( mpOut );
314 aIdx.Assign( *pStNd->EndOfSectionNode(), +1 );
317 GetDoc()->StopNumRuleAnimations( mpOut );
320 mpImp.reset();
322 if (mxDoc)
324 if( mxDoc->getReferenceCount() > 1 )
325 GetLayout()->ResetNewLayout();
328 mpOpt.reset();
330 // resize format cache.
331 if ( SwTextFrame::GetTextCache()->GetCurMax() > 250 )
332 SwTextFrame::GetTextCache()->DecreaseMax( 100 );
334 // Remove from PaintQueue if necessary
335 SwPaintQueue::Remove( this );
337 OSL_ENSURE( !mnStartAction, "EndAction() pending." );
340 if ( pLayoutAccess )
342 GetLayout()->DeRegisterShell( this );
343 if(pLayoutAccess->GetCurrentViewShell()==this)
345 pLayoutAccess->SetCurrentViewShell(nullptr);
346 for(SwViewShell& rShell : GetRingContainer())
348 if(&rShell != this)
350 pLayoutAccess->SetCurrentViewShell(&rShell);
351 break;
357 mpAccOptions.reset();
360 bool SwViewShell::HasDrawView() const
362 return Imp() && Imp()->HasDrawView();
365 void SwViewShell::MakeDrawView()
367 Imp()->MakeDrawView( );
370 bool SwViewShell::HasDrawViewDrag() const
372 return Imp()->HasDrawView() && Imp()->GetDrawView()->IsDragObj();
375 SdrView* SwViewShell::GetDrawView()
377 return Imp()->GetDrawView();
380 SdrView* SwViewShell::GetDrawViewWithValidMarkList()
382 SwDrawView* pDView = Imp()->GetDrawView();
383 pDView->ValidateMarkList();
384 return pDView;
387 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */