LibreOffice Module sw (master) 1
vnew.cxx
Go to the documentation of this file.
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 <sfx2/printer.hxx>
21#include <sal/log.hxx>
22#include <osl/diagnose.h>
23#include <doc.hxx>
25#include <IDocumentUndoRedo.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>
45#include <comphelper/lok.hxx>
46
47void SwViewShell::Init( const SwViewOption *pNewOpt )
48{
49 mbDocSizeChgd = false;
50
51 // We play it safe: Remove old font information whenever the printer
52 // resolution or the zoom factor changes. For that, Init() and Reformat()
53 // are the most secure places.
54 pFntCache->Flush( );
55
56 // ViewOptions are created dynamically
57
58 if( !mpOpt )
59 {
60 mpOpt.reset(new SwViewOption);
61
62 // ApplyViewOptions() does not need to be called
63 if( pNewOpt )
64 {
65 *mpOpt = *pNewOpt;
66 // Zoom factor needs to be set because there is no call to ApplyViewOptions() during
67 // CTOR for performance reasons.
68 if( GetWin() && 100 != mpOpt->GetZoom() )
69 {
70 MapMode aMode( mpWin->GetMapMode() );
71 const Fraction aNewFactor( mpOpt->GetZoom(), 100 );
72 aMode.SetScaleX( aNewFactor );
73 aMode.SetScaleY( aNewFactor );
74 mpWin->SetMapMode( aMode );
75 }
76 }
77 }
78
79 SwDocShell* pDShell = mxDoc->GetDocShell();
80 mxDoc->GetDocumentSettingManager().set(DocumentSettingId::HTML_MODE, 0 != ::GetHtmlMode( pDShell ) );
81 // set readonly flag at ViewOptions before creating layout. Otherwise,
82 // one would have to reformat again.
83
84 if( pDShell && pDShell->IsReadOnly() )
85 mpOpt->SetReadonly( true );
86
87 SAL_INFO( "sw.core", "View::Init - before InitPrt" );
88 OutputDevice* pPDFOut = nullptr;
89
90 if (mpOut && (OUTDEV_PDF == mpOut->GetOutDevType()))
91 pPDFOut = mpOut;
92
93 // Only setup the printer if we need one:
94 const bool bBrowseMode = mpOpt->getBrowseMode();
95 if( pPDFOut )
96 InitPrt( pPDFOut );
97
98 // i#44963 Good occasion to check if page sizes in
99 // page descriptions are still set to (LONG_MAX, LONG_MAX) (html import)
100 if ( !bBrowseMode )
101 {
102 mxDoc->CheckDefaultPageFormat();
103 }
104
105 SAL_INFO( "sw.core", "View::Init - after InitPrt" );
106 if( GetWin() )
107 {
108 SwViewOption::Init( GetWin()->GetOutDev() );
112 }
113
114 // Create a new layout, if there is no one available
115 if( !mpLayout )
116 {
117 // Here's the code which disables the usage of "multiple" layouts at the moment
118 // If the problems with controls and groups objects are solved,
119 // this code can be removed...
121 if( pCurrShell )
122 mpLayout = pCurrShell->mpLayout;
123 // end of "disable multiple layouts"
124 if( !mpLayout )
125 {
126 // switched to two step construction because creating the layout in SwRootFrame needs a valid pLayout set
127 mpLayout = SwRootFramePtr(new SwRootFrame(mxDoc->GetDfltFrameFormat(), this),
129 mpLayout->Init( mxDoc->GetDfltFrameFormat() );
130 }
131 }
133
134 // XForms mode: initialize XForms mode, based on design mode (draw view)
135 // MakeDrawView() requires layout
136 if( GetDoc()->isXForms() )
137 {
138 if( ! HasDrawView() )
139 MakeDrawView();
140 mpOpt->SetFormView( ! GetDrawView()->IsDesignMode() );
141 }
142}
143
146 const SwViewOption *pNewOpt, OutputDevice *pOutput,
147 tools::Long nFlags )
148 :
149 mpSfxViewShell( nullptr ),
150 mpImp( new SwViewShellImp( this ) ),
151 mpWin( pWindow ),
152 mpOut( pOutput ? pOutput
153 : pWindow ? pWindow->GetOutDev()
154 : static_cast<OutputDevice*>(rDocument.getIDocumentDeviceAccess().getPrinter( true ))),
155 mpAccOptions( new SwAccessibilityOptions ),
156 mbShowHeaderSeparator( false ),
157 mbShowFooterSeparator( false ),
158 mbHeaderFooterEdit( false ),
159 mpTargetPaintWindow(nullptr),
160 mpBufferedOut(nullptr),
161 mxDoc( &rDocument ),
162 mnStartAction( 0 ),
163 mnLockPaint( 0 ),
164 mbSelectAll(false),
165 mbOutputToWindow(false),
166 mpPrePostOutDev(nullptr)
167{
168 // in order to suppress event handling in
169 // <SwDrawContact::Changed> during construction of <SwViewShell> instance
170 mbInConstructor = true;
171
174 mbPreview = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
175
176 // i#38810 Do not reset modified state of document,
177 // if it's already been modified.
178 const bool bIsDocModified( mxDoc->getIDocumentState().IsModified() );
179 OutputDevice* pOrigOut = mpOut;
180 Init( pNewOpt ); // may change the Outdev (InitPrt())
181 mpOut = pOrigOut;
182
183 // initialize print preview layout after layout
184 // is created in <SwViewShell::Init(..)> - called above.
185 if ( mbPreview )
186 {
187 // init page preview layout
188 mpImp->InitPagePreviewLayout();
189 }
190
191 CurrShell aCurr( this );
192
193 static_cast<SwHiddenTextFieldType*>(mxDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::HiddenText ))->
194 SetHiddenFlag( !mpOpt->IsShowHiddenField() );
195
196 // In Init a standard FrameFormat is created.
197 if ( !mxDoc->GetIDocumentUndoRedo().IsUndoNoResetModified()
198 && !bIsDocModified )
199 {
200 mxDoc->getIDocumentState().ResetModified();
201 }
202
203 // extend format cache.
204 if ( SwTextFrame::GetTextCache()->GetCurMax() < 2550 )
206 if( mpOpt->IsGridVisible() || getIDocumentDrawModelAccess().GetDrawModel() )
207 Imp()->MakeDrawView();
208
209 mbInConstructor = false;
210}
211
214 OutputDevice * pOutput, tools::Long const nFlags)
215 : Ring( &rShell ) ,
216 maBrowseBorder( rShell.maBrowseBorder ),
217 mpSfxViewShell( nullptr ),
218 mpImp( new SwViewShellImp( this ) ),
219 mpWin( pWindow ),
220 mpOut( pOutput ? pOutput
221 : pWindow ? pWindow->GetOutDev()
222 : static_cast<OutputDevice*>(rShell.GetDoc()->getIDocumentDeviceAccess().getPrinter( true ))),
223 mpAccOptions( new SwAccessibilityOptions ),
224 mbShowHeaderSeparator( false ),
225 mbShowFooterSeparator( false ),
226 mbHeaderFooterEdit( false ),
227 mpTargetPaintWindow(nullptr),
228 mpBufferedOut(nullptr),
229 mxDoc( rShell.GetDoc() ),
230 mnStartAction( 0 ),
231 mnLockPaint( 0 ),
232 mbSelectAll(false),
233 mbOutputToWindow(false),
234 mpPrePostOutDev(nullptr)
235{
236 // in order to suppress event handling in
237 // <SwDrawContact::Changed> during construction of <SwViewShell> instance
238 mbInConstructor = true;
239
242 mbPreview = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
243
244 if( nFlags & VSHELLFLAG_SHARELAYOUT )
245 mpLayout = rShell.mpLayout;
246
247 CurrShell aCurr( this );
248
249 bool bModified = mxDoc->getIDocumentState().IsModified();
250
251 OutputDevice* pOrigOut = mpOut;
252
253 SwViewOption aNewOpt;
254
255 if ( rShell.GetViewOptions() )
256 {
257 aNewOpt = *rShell.GetViewOptions();
258 }
259
261 {
262 // Do not copy the color config in tiled rendering
263 aNewOpt.SetThemeName("Default");
264 }
265
266 Init( &aNewOpt ); // might change Outdev (InitPrt())
267 mpOut = pOrigOut;
268
269 if ( mbPreview )
270 mpImp->InitPagePreviewLayout();
271
272 static_cast<SwHiddenTextFieldType*>(mxDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::HiddenText ))->
273 SetHiddenFlag( !mpOpt->IsShowHiddenField() );
274
275 // In Init a standard FrameFormat is created.
276 if( !bModified && !mxDoc->GetIDocumentUndoRedo().IsUndoNoResetModified() )
277 {
278 mxDoc->getIDocumentState().ResetModified();
279 }
280
281 // extend format cache.
282 if ( SwTextFrame::GetTextCache()->GetCurMax() < 2550 )
284 if( mpOpt->IsGridVisible() || getIDocumentDrawModelAccess().GetDrawModel() )
285 Imp()->MakeDrawView();
286
287 mbInConstructor = false;
288
289}
290
292{
293 IDocumentLayoutAccess* const pLayoutAccess
294 = mxDoc ? &mxDoc->getIDocumentLayoutAccess() : nullptr;
295
296 {
297 CurrShell aCurr( this );
298 mbPaintWorks = false;
299
300 // i#9684 Stopping the animated graphics is not
301 // necessary during printing or pdf export, because the animation
302 // has not been started in this case.
303 if( mxDoc && GetWin() )
304 {
305 SwNodes& rNds = mxDoc->GetNodes();
306
307 SwStartNode *pStNd;
309 while ( nullptr != (pStNd = aIdx.GetNode().GetStartNode()) )
310 {
311 ++aIdx;
312 SwGrfNode *pGNd = aIdx.GetNode().GetGrfNode();
313 if ( nullptr != pGNd )
314 {
315 if( pGNd->IsAnimated() )
316 {
317 SwIterator<SwFrame,SwGrfNode> aIter( *pGNd );
318 for( SwFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next() )
319 {
320 OSL_ENSURE( pFrame->IsNoTextFrame(), "GraphicNode with Text?" );
321 static_cast<SwNoTextFrame*>(pFrame)->StopAnimation( mpOut );
322 }
323 }
324 }
325 aIdx.Assign( *pStNd->EndOfSectionNode(), +1 );
326 }
327
329 }
330
331 mpImp.reset();
332
333 if (mxDoc)
334 {
335 if( mxDoc->getReferenceCount() > 1 )
337 }
338
339 mpOpt.reset();
340
341 // resize format cache.
342 if ( SwTextFrame::GetTextCache()->GetCurMax() > 250 )
344
345 // Remove from PaintQueue if necessary
346 SwPaintQueue::Remove( this );
347
348 OSL_ENSURE( !mnStartAction, "EndAction() pending." );
349 }
350
351 if ( pLayoutAccess )
352 {
353 GetLayout()->DeRegisterShell( this );
354 if(pLayoutAccess->GetCurrentViewShell()==this)
355 {
356 pLayoutAccess->SetCurrentViewShell(nullptr);
357 for(SwViewShell& rShell : GetRingContainer())
358 {
359 if(&rShell != this)
360 {
361 pLayoutAccess->SetCurrentViewShell(&rShell);
362 break;
363 }
364 }
365 }
366 }
367
368 mpAccOptions.reset();
369}
370
372{
373 return Imp() && Imp()->HasDrawView();
374}
375
377{
378 Imp()->MakeDrawView( );
379}
380
382{
383 return Imp()->HasDrawView() && Imp()->GetDrawView()->IsDragObj();
384}
385
387{
388 return Imp()->GetDrawView();
389}
390
392{
393 SwDrawView* pDView = Imp()->GetDrawView();
394 pDView->ValidateMarkList();
395 return pDView;
396}
397
398/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
Provides access to the layout of a document.
virtual void SetCurrentViewShell(SwViewShell *pNew)=0
!!!The old layout must be deleted!!!
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
void SetScaleY(const Fraction &rScaleY)
void SetScaleX(const Fraction &rScaleX)
void SetLineColor()
void SetFillColor()
bool IsDragObj() const
bool IsReadOnly() const
sal_uInt16 GetCurMax() const
Definition: swcache.hxx:116
void IncreaseMax(const sal_uInt16 nAdd)
Definition: swcache.cxx:128
void DecreaseMax(const sal_uInt16 nSub)
Definition: swcache.cxx:139
Definition: doc.hxx:197
void StopNumRuleAnimations(const OutputDevice *)
Definition: docnum.cxx:1155
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:419
void ValidateMarkList()
Definition: dview.hxx:110
void Flush()
Definition: fntcache.cxx:76
Base class of the Writer layout elements.
Definition: frame.hxx:315
static void DestroyFrame(SwFrame *const pFrame)
this is the only way to delete a SwFrame instance
Definition: ssfrm.cxx:390
bool IsAnimated() const
Definition: ndgrf.hxx:91
TElementType * Next()
Definition: calbck.hxx:380
TElementType * First()
Definition: calbck.hxx:372
Marks a node in the document model.
Definition: ndindex.hxx:31
SwNode & GetNode() const
Definition: ndindex.hxx:123
SwNodeIndex & Assign(SwNodes const &rNds, SwNodeOffset nIdx)
Definition: ndindex.hxx:114
SwStartNode * GetStartNode()
Definition: node.hxx:642
SwGrfNode * GetGrfNode()
Definition: ndgrf.hxx:150
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:153
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:695
SwNode & GetEndOfAutotext() const
Section for all Flys/Header/Footers.
Definition: ndarr.hxx:158
static void Remove(SwViewShell const *pSh)
Definition: vprint.cxx:135
The root element of a Writer document layout.
Definition: rootfrm.hxx:85
void DeRegisterShell(SwViewShell *pSh)
Definition: newfrm.cxx:362
void ResetNewLayout()
Definition: rootfrm.hxx:382
Starts a section of nodes in the document model.
Definition: node.hxx:348
static SwCache * GetTextCache()
Definition: txtfrm.hxx:626
static void Init(const OutputDevice *pWin)
Definition: viewopt.cxx:394
void SetThemeName(const OUString &rThemeName)
Definition: viewopt.hxx:316
void MakeDrawView()
Definition: viewimp.cxx:240
bool HasDrawView() const
New Interface for StarView Drawing.
Definition: viewimp.hxx:163
SwDrawView * GetDrawView()
Definition: viewimp.hxx:164
bool mbInEndAction
Definition: viewsh.hxx:154
VclPtr< vcl::Window > mpWin
= 0 during printing or pdf export
Definition: viewsh.hxx:141
void SizeChgNotify()
Definition: viewsh.cxx:1135
bool HasDrawView() const
Definition: vnew.cxx:371
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:452
VclPtr< OutputDevice > mpOut
Window, Printer, VirtDev, ...
Definition: viewsh.hxx:142
rtl::Reference< SwDoc > mxDoc
The document; never 0.
Definition: viewsh.hxx:199
bool mbDocSizeChgd
Definition: viewsh.hxx:147
SwViewShell(SwViewShell &, vcl::Window *pWin, OutputDevice *pOut=nullptr, tools::Long nFlags=0)
CTor for further Shells on a document.
Definition: vnew.cxx:213
SwViewShellImp * Imp()
Definition: viewsh.hxx:211
std::unique_ptr< SwViewOption > mpOpt
Definition: viewsh.hxx:144
bool HasDrawViewDrag() const
Definition: vnew.cxx:381
bool mbPreview
Definition: viewsh.hxx:155
SwRootFramePtr mpLayout
Definition: viewsh.hxx:168
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2163
bool mbEnableSmooth
Definition: viewsh.hxx:156
std::unique_ptr< SwAccessibilityOptions > mpAccOptions
Definition: viewsh.hxx:145
SdrView * GetDrawViewWithValidMarkList()
Definition: vnew.cxx:391
vcl::Window * GetWin() const
Definition: viewsh.hxx:364
const IDocumentDrawModelAccess & getIDocumentDrawModelAccess() const
Provides access to the document draw model interface.
Definition: viewsh.cxx:2823
void MakeDrawView()
Definition: vnew.cxx:376
bool mbPaintWorks
Definition: viewsh.hxx:149
std::unique_ptr< SwViewShellImp > mpImp
Definition: viewsh.hxx:138
sal_uInt16 mnStartAction
!= 0 if at least one Action is active.
Definition: viewsh.hxx:201
virtual ~SwViewShell() override
Definition: vnew.cxx:291
SwDoc * GetDoc() const
Definition: viewsh.hxx:308
SAL_DLLPRIVATE void Init(const SwViewOption *pNewOpt)
Definition: vnew.cxx:47
bool mbPaintInProgress
Definition: viewsh.hxx:151
bool mbInConstructor
Definition: viewsh.hxx:163
bool mbViewLocked
Definition: viewsh.hxx:152
void InitPrt(OutputDevice *pOutDev)
Definition: vprint.cxx:177
SdrView * GetDrawView()
Definition: vnew.cxx:386
ring_container GetRingContainer()
Definition: ring.hxx:240
::OutputDevice const * GetOutDev() const
void SetBackground()
SwFntCache * pFntCache
Definition: fntcache.cxx:66
#define SAL_INFO(area, stream)
long Long
OUTDEV_PDF
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:415
#define VSHELLFLAG_SHARELAYOUT
Definition: viewsh.hxx:96
#define VSHELLFLAG_ISPREVIEW
Definition: viewsh.hxx:95
std::shared_ptr< SwRootFrame > SwRootFramePtr
Definition: viewsh.hxx:97