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 <doc.hxx>
24 #include <IDocumentUndoRedo.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>
44 
45 void SwViewShell::Init( const SwViewOption *pNewOpt )
46 {
47  mbDocSizeChgd = false;
48 
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( );
53 
54  // ViewOptions are created dynamically
55 
56  if( !mpOpt )
57  {
58  mpOpt.reset(new SwViewOption);
59 
60  // ApplyViewOptions() does not need to be called
61  if( pNewOpt )
62  {
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() )
67  {
68  MapMode aMode( mpWin->GetMapMode() );
69  const Fraction aNewFactor( mpOpt->GetZoom(), 100 );
70  aMode.SetScaleX( aNewFactor );
71  aMode.SetScaleY( aNewFactor );
72  mpWin->SetMapMode( aMode );
73  }
74  }
75  }
76 
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.
81 
82  if( pDShell && pDShell->IsReadOnly() )
83  mpOpt->SetReadonly( true );
84 
85  SAL_INFO( "sw.core", "View::Init - before InitPrt" );
86  OutputDevice* pPDFOut = nullptr;
87 
88  if (mpOut && (OUTDEV_PDF == mpOut->GetOutDevType()))
89  pPDFOut = mpOut;
90 
91  // Only setup the printer if we need one:
92  const bool bBrowseMode = mpOpt->getBrowseMode();
93  if( pPDFOut )
94  InitPrt( pPDFOut );
95 
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 )
99  {
100  mxDoc->CheckDefaultPageFormat();
101  }
102 
103  SAL_INFO( "sw.core", "View::Init - after InitPrt" );
104  if( GetWin() )
105  {
107  GetWin()->SetFillColor();
108  GetWin()->SetBackground();
109  GetWin()->SetLineColor();
110  }
111 
112  // Create a new layout, if there is no one available
113  if( !mpLayout )
114  {
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...
119  if( pCurrShell )
120  mpLayout = pCurrShell->mpLayout;
121  // end of "disable multiple layouts"
122  if( !mpLayout )
123  {
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),
127  mpLayout->Init( mxDoc->GetDfltFrameFormat() );
128  }
129  }
130  SizeChgNotify();
131 
132  // XForms mode: initialize XForms mode, based on design mode (draw view)
133  // MakeDrawView() requires layout
134  if( GetDoc()->isXForms() )
135  {
136  if( ! HasDrawView() )
137  MakeDrawView();
138  mpOpt->SetFormView( ! GetDrawView()->IsDesignMode() );
139  }
140 }
141 
144  const SwViewOption *pNewOpt, OutputDevice *pOutput,
145  long nFlags )
146  :
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()
167 {
168  // in order to suppress event handling in
169  // <SwDrawContact::Changed> during construction of <SwViewShell> instance
170  mbInConstructor = true;
171 
173  mbEndActionByVirDev = false;
174  mbPaintWorks = mbEnableSmooth = true;
175  mbPreview = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
176 
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;
183 
184  // initialize print preview layout after layout
185  // is created in <SwViewShell::Init(..)> - called above.
186  if ( mbPreview )
187  {
188  // init page preview layout
189  mpImp->InitPagePreviewLayout();
190  }
191 
192  SET_CURR_SHELL( this );
193 
194  static_cast<SwHiddenTextFieldType*>(mxDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::HiddenText ))->
195  SetHiddenFlag( !mpOpt->IsShowHiddenField() );
196 
197  // In Init a standard FrameFormat is created.
198  if ( !mxDoc->GetIDocumentUndoRedo().IsUndoNoResetModified()
199  && !bIsDocModified )
200  {
201  mxDoc->getIDocumentState().ResetModified();
202  }
203 
204  // extend format cache.
205  if ( SwTextFrame::GetTextCache()->GetCurMax() < 2550 )
207  if( mpOpt->IsGridVisible() || getIDocumentDrawModelAccess().GetDrawModel() )
208  Imp()->MakeDrawView();
209 
210  mbInConstructor = false;
211 }
212 
215  OutputDevice * pOutput, 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()
237 {
238  // in order to suppress event handling in
239  // <SwDrawContact::Changed> during construction of <SwViewShell> instance
240  mbInConstructor = true;
241 
242  mbPaintWorks = mbEnableSmooth = true;
244  mbEndActionByVirDev = false;
245  mbPreview = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
246 
247  if( nFlags & VSHELLFLAG_SHARELAYOUT )
248  mpLayout = rShell.mpLayout;
249 
250  SET_CURR_SHELL( this );
251 
252  bool bModified = mxDoc->getIDocumentState().IsModified();
253 
254  OutputDevice* pOrigOut = mpOut;
255  Init( rShell.GetViewOptions() ); // might change Outdev (InitPrt())
256  mpOut = pOrigOut;
257 
258  if ( mbPreview )
259  mpImp->InitPagePreviewLayout();
260 
261  static_cast<SwHiddenTextFieldType*>(mxDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::HiddenText ))->
262  SetHiddenFlag( !mpOpt->IsShowHiddenField() );
263 
264  // In Init a standard FrameFormat is created.
265  if( !bModified && !mxDoc->GetIDocumentUndoRedo().IsUndoNoResetModified() )
266  {
267  mxDoc->getIDocumentState().ResetModified();
268  }
269 
270  // extend format cache.
271  if ( SwTextFrame::GetTextCache()->GetCurMax() < 2550 )
273  if( mpOpt->IsGridVisible() || getIDocumentDrawModelAccess().GetDrawModel() )
274  Imp()->MakeDrawView();
275 
276  mbInConstructor = false;
277 
278 }
279 
281 {
282  IDocumentLayoutAccess* const pLayoutAccess
283  = mxDoc ? &mxDoc->getIDocumentLayoutAccess() : nullptr;
284 
285  {
286  SET_CURR_SHELL( this );
287  mbPaintWorks = false;
288 
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.get() && GetWin() )
293  {
294  SwNodes& rNds = mxDoc->GetNodes();
295 
296  SwStartNode *pStNd;
297  SwNodeIndex aIdx( *rNds.GetEndOfAutotext().StartOfSectionNode(), 1 );
298  while ( nullptr != (pStNd = aIdx.GetNode().GetStartNode()) )
299  {
300  ++aIdx;
301  SwGrfNode *pGNd = aIdx.GetNode().GetGrfNode();
302  if ( nullptr != pGNd )
303  {
304  if( pGNd->IsAnimated() )
305  {
306  SwIterator<SwFrame,SwGrfNode> aIter( *pGNd );
307  for( SwFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next() )
308  {
309  OSL_ENSURE( pFrame->IsNoTextFrame(), "GraphicNode with Text?" );
310  static_cast<SwNoTextFrame*>(pFrame)->StopAnimation( mpOut );
311  }
312  }
313  }
314  aIdx.Assign( *pStNd->EndOfSectionNode(), +1 );
315  }
316 
318  }
319 
320  mpImp.reset();
321 
322  if (mxDoc)
323  {
324  if( mxDoc->getReferenceCount() > 1 )
326  }
327 
328  mpOpt.reset();
329 
330  // resize format cache.
331  if ( SwTextFrame::GetTextCache()->GetCurMax() > 250 )
333 
334  // Remove from PaintQueue if necessary
335  SwPaintQueue::Remove( this );
336 
337  OSL_ENSURE( !mnStartAction, "EndAction() pending." );
338  }
339 
340  if ( pLayoutAccess )
341  {
342  GetLayout()->DeRegisterShell( this );
343  if(pLayoutAccess->GetCurrentViewShell()==this)
344  {
345  pLayoutAccess->SetCurrentViewShell(nullptr);
346  for(SwViewShell& rShell : GetRingContainer())
347  {
348  if(&rShell != this)
349  {
350  pLayoutAccess->SetCurrentViewShell(&rShell);
351  break;
352  }
353  }
354  }
355  }
356 
357  mpAccOptions.reset();
358 }
359 
361 {
362  return Imp() && Imp()->HasDrawView();
363 }
364 
366 {
367  Imp()->MakeDrawView( );
368 }
369 
371 {
372  return Imp()->HasDrawView() && Imp()->GetDrawView()->IsDragObj();
373 }
374 
376 {
377  return Imp()->GetDrawView();
378 }
379 
381 {
382  SwDrawView* pDView = Imp()->GetDrawView();
383  pDView->ValidateMarkList();
384  return pDView;
385 }
386 
387 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
const SwEndNode * EndOfSectionNode() const
Definition: node.hxx:682
Starts a section of nodes in the document model.
Definition: node.hxx:303
bool mbInEndAction
Definition: viewsh.hxx:129
OutDevType GetOutDevType() const
Base class of the Writer layout elements.
Definition: frame.hxx:295
bool mbEndActionByVirDev
Definition: viewsh.hxx:134
SwNode & GetEndOfAutotext() const
Section for all Flys/Header/Footers.
Definition: ndarr.hxx:157
virtual ~SwViewShell() override
Definition: vnew.cxx:280
SdrView * GetDrawView()
Definition: vnew.cxx:375
SwViewShellImp * Imp()
Definition: viewsh.hxx:185
void StopNumRuleAnimations(OutputDevice *)
Definition: docnum.cxx:1144
Definition: doc.hxx:185
TElementType * Next()
Definition: calbck.hxx:373
VclPtr< OutputDevice > mpOut
Window, Printer, VirtDev, ...
Definition: viewsh.hxx:117
VclPtr< vcl::Window > mpWin
= 0 during printing or pdf export
Definition: viewsh.hxx:116
bool HasDrawView() const
Definition: vnew.cxx:360
const MapMode & GetMapMode() const
std::unique_ptr< SwViewShellImp > mpImp
Definition: viewsh.hxx:113
static void DestroyFrame(SwFrame *const pFrame)
this is the only way to delete a SwFrame instance
Definition: ssfrm.cxx:382
#define VSHELLFLAG_SHARELAYOUT
Definition: viewsh.hxx:79
The root element of a Writer document layout.
Definition: rootfrm.hxx:79
void SetMapMode()
static SwCache * GetTextCache()
Definition: txtfrm.hxx:597
std::shared_ptr< SwRootFrame > SwRootFramePtr
Definition: viewsh.hxx:80
void MakeDrawView()
Definition: viewimp.cxx:203
bool mbViewLocked
Definition: viewsh.hxx:127
void SetBackground()
rtl::Reference< SwDoc > mxDoc
The document; never 0.
Definition: viewsh.hxx:174
void InitPrt(OutputDevice *pOutDev)
Definition: vprint.cxx:196
void Flush()
Definition: fntcache.cxx:165
void DecreaseMax(const sal_uInt16 nSub)
Definition: swcache.cxx:140
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
const IDocumentDrawModelAccess & getIDocumentDrawModelAccess() const
Provides access to the document draw model interface.
Definition: viewsh.cxx:2597
bool mbInConstructor
Definition: viewsh.hxx:141
void SizeChgNotify()
Definition: viewsh.cxx:1045
bool mbPreview
Definition: viewsh.hxx:130
void SetLineColor()
void IncreaseMax(const sal_uInt16 nAdd)
Definition: swcache.cxx:129
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:131
bool IsAnimated() const
Definition: ndgrf.hxx:96
OUTDEV_PDF
TElementType * First()
Definition: calbck.hxx:342
std::unique_ptr< SwAccessibilityOptions > mpAccOptions
Definition: viewsh.hxx:120
void ResetNewLayout()
Definition: rootfrm.hxx:368
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:340
virtual const SwDrawModel * GetDrawModel() const =0
Draw Model and id accessors.
void SetFillColor()
void DeRegisterShell(SwViewShell *pSh)
Definition: newfrm.cxx:363
#define SET_CURR_SHELL(shell)
Definition: swtypes.hxx:101
Marks a node in the document model.
Definition: ndindex.hxx:31
ring_container GetRingContainer()
SwStartNode * GetStartNode()
Definition: node.hxx:591
SwFntCache * pFntCache
Definition: fntcache.cxx:68
bool mbPaintInProgress
Definition: viewsh.hxx:126
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:404
bool IsReadOnly() const
static void Init(vcl::Window const *pWin)
Definition: viewopt.cxx:311
SwViewShell(SwViewShell &, vcl::Window *pWin, OutputDevice *pOut=nullptr, long nFlags=0)
CTor for further Shells on a document.
Definition: vnew.cxx:214
bool mbDocSizeChgd
Definition: viewsh.hxx:122
void MakeDrawView()
Definition: vnew.cxx:365
static void Remove(SwViewShell const *pSh)
Definition: vprint.cxx:154
SwDrawView * GetDrawView()
Definition: viewimp.hxx:156
virtual const SwViewShell * GetCurrentViewShell() const =0
Returns the layout set at the document.
const SwViewOption * GetViewOptions() const
Definition: viewsh.hxx:426
vcl::Window * GetWin() const
Definition: viewsh.hxx:340
bool mbPaintWorks
Definition: viewsh.hxx:124
SdrView * GetDrawViewWithValidMarkList()
Definition: vnew.cxx:380
#define SAL_INFO(area, stream)
#define VSHELLFLAG_ISPREVIEW
Definition: viewsh.hxx:78
bool HasDrawView() const
New Interface for StarView Drawing.
Definition: viewimp.hxx:155
bool IsDragObj() const
void ValidateMarkList()
Definition: dview.hxx:111
SwRootFramePtr mpLayout
Definition: viewsh.hxx:146
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:132
bool mbFrameView
Definition: viewsh.hxx:131
SwGrfNode * GetGrfNode()
Definition: ndgrf.hxx:155
std::unique_ptr< SwViewOption > mpOpt
Definition: viewsh.hxx:119
SAL_DLLPRIVATE void Init(const SwViewOption *pNewOpt)
Definition: vnew.cxx:45
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2075
bool HasDrawViewDrag() const
Definition: vnew.cxx:370
sal_uInt16 mnStartAction
!= 0 if at least one Action is active.
Definition: viewsh.hxx:176