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 
46 void 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() );
108  GetWin()->GetOutDev()->SetFillColor();
109  GetWin()->SetBackground();
110  GetWin()->GetOutDev()->SetLineColor();
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  }
131  SizeChgNotify();
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;
173  mbPaintWorks = mbEnableSmooth = true;
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 
240  mbPaintWorks = mbEnableSmooth = true;
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;
295  SwNodeIndex aIdx( *rNds.GetEndOfAutotext().StartOfSectionNode(), 1 );
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: */
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:684
Starts a section of nodes in the document model.
Definition: node.hxx:313
bool mbInEndAction
Definition: viewsh.hxx:127
OutDevType GetOutDevType() const
Base class of the Writer layout elements.
Definition: frame.hxx:315
void SetBackground()
SwViewShell(SwViewShell &, vcl::Window *pWin, OutputDevice *pOut=nullptr, tools::Long nFlags=0)
CTor for further Shells on a document.
Definition: vnew.cxx:213
bool mbEndActionByVirDev
Definition: viewsh.hxx:132
SwNode & GetEndOfAutotext() const
Section for all Flys/Header/Footers.
Definition: ndarr.hxx:154
virtual ~SwViewShell() override
Definition: vnew.cxx:278
SdrView * GetDrawView()
Definition: vnew.cxx:373
SwViewShellImp * Imp()
Definition: viewsh.hxx:182
long Long
Definition: doc.hxx:188
TElementType * Next()
Definition: calbck.hxx:365
VclPtr< OutputDevice > mpOut
Window, Printer, VirtDev, ...
Definition: viewsh.hxx:115
VclPtr< vcl::Window > mpWin
= 0 during printing or pdf export
Definition: viewsh.hxx:114
bool HasDrawView() const
Definition: vnew.cxx:358
std::unique_ptr< SwViewShellImp > mpImp
Definition: viewsh.hxx:111
static void DestroyFrame(SwFrame *const pFrame)
this is the only way to delete a SwFrame instance
Definition: ssfrm.cxx:384
#define VSHELLFLAG_SHARELAYOUT
Definition: viewsh.hxx:77
The root element of a Writer document layout.
Definition: rootfrm.hxx:82
static SwCache * GetTextCache()
Definition: txtfrm.hxx:609
std::shared_ptr< SwRootFrame > SwRootFramePtr
Definition: viewsh.hxx:78
void MakeDrawView()
Definition: viewimp.cxx:233
bool mbViewLocked
Definition: viewsh.hxx:125
static void Init(const OutputDevice *pWin)
Definition: viewopt.cxx:325
rtl::Reference< SwDoc > mxDoc
The document; never 0.
Definition: viewsh.hxx:171
void InitPrt(OutputDevice *pOutDev)
Definition: vprint.cxx:176
void Flush()
Definition: fntcache.cxx:127
void DecreaseMax(const sal_uInt16 nSub)
Definition: swcache.cxx:139
SwDoc * GetDoc() const
Definition: viewsh.hxx:282
const IDocumentDrawModelAccess & getIDocumentDrawModelAccess() const
Provides access to the document draw model interface.
Definition: viewsh.cxx:2722
bool mbInConstructor
Definition: viewsh.hxx:139
void SizeChgNotify()
Definition: viewsh.cxx:1098
bool mbPreview
Definition: viewsh.hxx:128
void SetLineColor()
void IncreaseMax(const sal_uInt16 nAdd)
Definition: swcache.cxx:128
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:133
bool IsAnimated() const
Definition: ndgrf.hxx:95
OUTDEV_PDF
const MapMode & GetMapMode() const
TElementType * First()
Definition: calbck.hxx:357
std::unique_ptr< SwAccessibilityOptions > mpAccOptions
Definition: viewsh.hxx:118
void ResetNewLayout()
Definition: rootfrm.hxx:374
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:354
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
void SetFillColor()
void DeRegisterShell(SwViewShell *pSh)
Definition: newfrm.cxx:361
Marks a node in the document model.
Definition: ndindex.hxx:32
ring_container GetRingContainer()
SwStartNode * GetStartNode()
Definition: node.hxx:593
SwFntCache * pFntCache
Definition: fntcache.cxx:66
bool mbPaintInProgress
Definition: viewsh.hxx:124
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:405
bool IsReadOnly() const
bool mbDocSizeChgd
Definition: viewsh.hxx:120
void MakeDrawView()
Definition: vnew.cxx:363
static void Remove(SwViewShell const *pSh)
Definition: vprint.cxx:134
SwDrawView * GetDrawView()
Definition: viewimp.hxx:161
void StopNumRuleAnimations(const OutputDevice *)
Definition: docnum.cxx:1159
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:424
vcl::Window * GetWin() const
Definition: viewsh.hxx:338
bool mbPaintWorks
Definition: viewsh.hxx:122
SdrView * GetDrawViewWithValidMarkList()
Definition: vnew.cxx:378
#define SAL_INFO(area, stream)
::OutputDevice const * GetOutDev() const
#define VSHELLFLAG_ISPREVIEW
Definition: viewsh.hxx:76
bool HasDrawView() const
New Interface for StarView Drawing.
Definition: viewimp.hxx:160
bool IsDragObj() const
void ValidateMarkList()
Definition: dview.hxx:110
SwRootFramePtr mpLayout
Definition: viewsh.hxx:144
Provides access to the layout of a document.
virtual void SetCurrentViewShell(SwViewShell *pNew)=0
!!!The old layout must be deleted!!!
bool mbEnableSmooth
Definition: viewsh.hxx:130
bool mbFrameView
Definition: viewsh.hxx:129
SwGrfNode * GetGrfNode()
Definition: ndgrf.hxx:154
std::unique_ptr< SwViewOption > mpOpt
Definition: viewsh.hxx:117
SAL_DLLPRIVATE void Init(const SwViewOption *pNewOpt)
Definition: vnew.cxx:46
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2122
bool HasDrawViewDrag() const
Definition: vnew.cxx:368
void SetMapMode()
sal_uInt16 mnStartAction
!= 0 if at least one Action is active.
Definition: viewsh.hxx:173