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
46void SwViewShell::Init( const SwViewOption *pNewOpt )
47{
48 mbDocSizeChgd = false;
49
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( );
54
55 // ViewOptions are created dynamically
56
57 if( !mpOpt )
58 {
59 mpOpt.reset(new SwViewOption);
60
61 // ApplyViewOptions() does not need to be called
62 if( pNewOpt )
63 {
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() )
68 {
69 MapMode aMode( mpWin->GetMapMode() );
70 const Fraction aNewFactor( mpOpt->GetZoom(), 100 );
71 aMode.SetScaleX( aNewFactor );
72 aMode.SetScaleY( aNewFactor );
73 mpWin->SetMapMode( aMode );
74 }
75 }
76 }
77
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.
82
83 if( pDShell && pDShell->IsReadOnly() )
84 mpOpt->SetReadonly( true );
85
86 SAL_INFO( "sw.core", "View::Init - before InitPrt" );
87 OutputDevice* pPDFOut = nullptr;
88
89 if (mpOut && (OUTDEV_PDF == mpOut->GetOutDevType()))
90 pPDFOut = mpOut;
91
92 // Only setup the printer if we need one:
93 const bool bBrowseMode = mpOpt->getBrowseMode();
94 if( pPDFOut )
95 InitPrt( pPDFOut );
96
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 )
100 {
101 mxDoc->CheckDefaultPageFormat();
102 }
103
104 SAL_INFO( "sw.core", "View::Init - after InitPrt" );
105 if( GetWin() )
106 {
107 SwViewOption::Init( GetWin()->GetOutDev() );
111 }
112
113 // Create a new layout, if there is no one available
114 if( !mpLayout )
115 {
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...
120 if( pCurrShell )
121 mpLayout = pCurrShell->mpLayout;
122 // end of "disable multiple layouts"
123 if( !mpLayout )
124 {
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),
128 mpLayout->Init( mxDoc->GetDfltFrameFormat() );
129 }
130 }
132
133 // XForms mode: initialize XForms mode, based on design mode (draw view)
134 // MakeDrawView() requires layout
135 if( GetDoc()->isXForms() )
136 {
137 if( ! HasDrawView() )
138 MakeDrawView();
139 mpOpt->SetFormView( ! GetDrawView()->IsDesignMode() );
140 }
141}
142
145 const SwViewOption *pNewOpt, OutputDevice *pOutput,
146 tools::Long nFlags )
147 :
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)
166{
167 // in order to suppress event handling in
168 // <SwDrawContact::Changed> during construction of <SwViewShell> instance
169 mbInConstructor = true;
170
172 mbEndActionByVirDev = false;
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 mbEndActionByVirDev = false;
243 mbPreview = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
244
245 if( nFlags & VSHELLFLAG_SHARELAYOUT )
246 mpLayout = rShell.mpLayout;
247
248 CurrShell aCurr( this );
249
250 bool bModified = mxDoc->getIDocumentState().IsModified();
251
252 OutputDevice* pOrigOut = mpOut;
253 Init( rShell.GetViewOptions() ); // might change Outdev (InitPrt())
254 mpOut = pOrigOut;
255
256 if ( mbPreview )
257 mpImp->InitPagePreviewLayout();
258
259 static_cast<SwHiddenTextFieldType*>(mxDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::HiddenText ))->
260 SetHiddenFlag( !mpOpt->IsShowHiddenField() );
261
262 // In Init a standard FrameFormat is created.
263 if( !bModified && !mxDoc->GetIDocumentUndoRedo().IsUndoNoResetModified() )
264 {
265 mxDoc->getIDocumentState().ResetModified();
266 }
267
268 // extend format cache.
269 if ( SwTextFrame::GetTextCache()->GetCurMax() < 2550 )
271 if( mpOpt->IsGridVisible() || getIDocumentDrawModelAccess().GetDrawModel() )
272 Imp()->MakeDrawView();
273
274 mbInConstructor = false;
275
276}
277
279{
280 IDocumentLayoutAccess* const pLayoutAccess
281 = mxDoc ? &mxDoc->getIDocumentLayoutAccess() : nullptr;
282
283 {
284 CurrShell aCurr( this );
285 mbPaintWorks = false;
286
287 // i#9684 Stopping the animated graphics is not
288 // necessary during printing or pdf export, because the animation
289 // has not been started in this case.
290 if( mxDoc && GetWin() )
291 {
292 SwNodes& rNds = mxDoc->GetNodes();
293
294 SwStartNode *pStNd;
296 while ( nullptr != (pStNd = aIdx.GetNode().GetStartNode()) )
297 {
298 ++aIdx;
299 SwGrfNode *pGNd = aIdx.GetNode().GetGrfNode();
300 if ( nullptr != pGNd )
301 {
302 if( pGNd->IsAnimated() )
303 {
304 SwIterator<SwFrame,SwGrfNode> aIter( *pGNd );
305 for( SwFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next() )
306 {
307 OSL_ENSURE( pFrame->IsNoTextFrame(), "GraphicNode with Text?" );
308 static_cast<SwNoTextFrame*>(pFrame)->StopAnimation( mpOut );
309 }
310 }
311 }
312 aIdx.Assign( *pStNd->EndOfSectionNode(), +1 );
313 }
314
316 }
317
318 mpImp.reset();
319
320 if (mxDoc)
321 {
322 if( mxDoc->getReferenceCount() > 1 )
324 }
325
326 mpOpt.reset();
327
328 // resize format cache.
329 if ( SwTextFrame::GetTextCache()->GetCurMax() > 250 )
331
332 // Remove from PaintQueue if necessary
333 SwPaintQueue::Remove( this );
334
335 OSL_ENSURE( !mnStartAction, "EndAction() pending." );
336 }
337
338 if ( pLayoutAccess )
339 {
340 GetLayout()->DeRegisterShell( this );
341 if(pLayoutAccess->GetCurrentViewShell()==this)
342 {
343 pLayoutAccess->SetCurrentViewShell(nullptr);
344 for(SwViewShell& rShell : GetRingContainer())
345 {
346 if(&rShell != this)
347 {
348 pLayoutAccess->SetCurrentViewShell(&rShell);
349 break;
350 }
351 }
352 }
353 }
354
355 mpAccOptions.reset();
356}
357
359{
360 return Imp() && Imp()->HasDrawView();
361}
362
364{
365 Imp()->MakeDrawView( );
366}
367
369{
370 return Imp()->HasDrawView() && Imp()->GetDrawView()->IsDragObj();
371}
372
374{
375 return Imp()->GetDrawView();
376}
377
379{
380 SwDrawView* pDView = Imp()->GetDrawView();
381 pDView->ValidateMarkList();
382 return pDView;
383}
384
385/* 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:195
void StopNumRuleAnimations(const OutputDevice *)
Definition: docnum.cxx:1155
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:413
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:95
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:154
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:153
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:733
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:618
static void Init(const OutputDevice *pWin)
Definition: viewopt.cxx:394
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:135
VclPtr< vcl::Window > mpWin
= 0 during printing or pdf export
Definition: viewsh.hxx:122
void SizeChgNotify()
Definition: viewsh.cxx:1130
bool HasDrawView() const
Definition: vnew.cxx:358
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:434
VclPtr< OutputDevice > mpOut
Window, Printer, VirtDev, ...
Definition: viewsh.hxx:123
rtl::Reference< SwDoc > mxDoc
The document; never 0.
Definition: viewsh.hxx:179
bool mbDocSizeChgd
Definition: viewsh.hxx:128
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:190
std::unique_ptr< SwViewOption > mpOpt
Definition: viewsh.hxx:125
bool mbFrameView
Definition: viewsh.hxx:137
bool HasDrawViewDrag() const
Definition: vnew.cxx:368
bool mbPreview
Definition: viewsh.hxx:136
SwRootFramePtr mpLayout
Definition: viewsh.hxx:152
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2159
bool mbEnableSmooth
Definition: viewsh.hxx:138
std::unique_ptr< SwAccessibilityOptions > mpAccOptions
Definition: viewsh.hxx:126
SdrView * GetDrawViewWithValidMarkList()
Definition: vnew.cxx:378
vcl::Window * GetWin() const
Definition: viewsh.hxx:346
const IDocumentDrawModelAccess & getIDocumentDrawModelAccess() const
Provides access to the document draw model interface.
Definition: viewsh.cxx:2815
void MakeDrawView()
Definition: vnew.cxx:363
bool mbPaintWorks
Definition: viewsh.hxx:130
std::unique_ptr< SwViewShellImp > mpImp
Definition: viewsh.hxx:119
sal_uInt16 mnStartAction
!= 0 if at least one Action is active.
Definition: viewsh.hxx:181
virtual ~SwViewShell() override
Definition: vnew.cxx:278
SwDoc * GetDoc() const
Definition: viewsh.hxx:290
SAL_DLLPRIVATE void Init(const SwViewOption *pNewOpt)
Definition: vnew.cxx:46
bool mbPaintInProgress
Definition: viewsh.hxx:132
bool mbInConstructor
Definition: viewsh.hxx:147
bool mbViewLocked
Definition: viewsh.hxx:133
void InitPrt(OutputDevice *pOutDev)
Definition: vprint.cxx:177
SdrView * GetDrawView()
Definition: vnew.cxx:373
bool mbEndActionByVirDev
Definition: viewsh.hxx:140
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:77
#define VSHELLFLAG_ISPREVIEW
Definition: viewsh.hxx:76
std::shared_ptr< SwRootFrame > SwRootFramePtr
Definition: viewsh.hxx:78