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 #include <calbck.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  {
108  GetWin()->SetFillColor();
109  GetWin()->SetBackground();
110  GetWin()->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  long nFlags )
147  :
148  maBrowseBorder(),
149  mpSfxViewShell( nullptr ),
150  mpImp( new SwViewShellImp( this ) ),
151  mpWin( pWindow ),
152  mpOut( pOutput ? pOutput
153  : pWindow ? static_cast<OutputDevice*>(pWindow)
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  maPrePostMapMode()
168 {
169  // in order to suppress event handling in
170  // <SwDrawContact::Changed> during construction of <SwViewShell> instance
171  mbInConstructor = true;
172 
174  mbEndActionByVirDev = false;
175  mbPaintWorks = mbEnableSmooth = true;
176  mbPreview = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
177 
178  // i#38810 Do not reset modified state of document,
179  // if it's already been modified.
180  const bool bIsDocModified( mxDoc->getIDocumentState().IsModified() );
181  OutputDevice* pOrigOut = mpOut;
182  Init( pNewOpt ); // may change the Outdev (InitPrt())
183  mpOut = pOrigOut;
184 
185  // initialize print preview layout after layout
186  // is created in <SwViewShell::Init(..)> - called above.
187  if ( mbPreview )
188  {
189  // init page preview layout
190  mpImp->InitPagePreviewLayout();
191  }
192 
193  SET_CURR_SHELL( this );
194 
195  static_cast<SwHiddenTextFieldType*>(mxDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::HiddenText ))->
196  SetHiddenFlag( !mpOpt->IsShowHiddenField() );
197 
198  // In Init a standard FrameFormat is created.
199  if ( !mxDoc->GetIDocumentUndoRedo().IsUndoNoResetModified()
200  && !bIsDocModified )
201  {
202  mxDoc->getIDocumentState().ResetModified();
203  }
204 
205  // extend format cache.
206  if ( SwTextFrame::GetTextCache()->GetCurMax() < 2550 )
208  if( mpOpt->IsGridVisible() || getIDocumentDrawModelAccess().GetDrawModel() )
209  Imp()->MakeDrawView();
210 
211  mbInConstructor = false;
212 }
213 
216  OutputDevice * pOutput, long const nFlags)
217  : Ring( &rShell ) ,
218  maBrowseBorder( rShell.maBrowseBorder ),
219  mpSfxViewShell( nullptr ),
220  mpImp( new SwViewShellImp( this ) ),
221  mpWin( pWindow ),
222  mpOut( pOutput ? pOutput
223  : pWindow ? static_cast<OutputDevice*>(pWindow)
224  : static_cast<OutputDevice*>(rShell.GetDoc()->getIDocumentDeviceAccess().getPrinter( true ))),
225  mpAccOptions( new SwAccessibilityOptions ),
226  mbShowHeaderSeparator( false ),
227  mbShowFooterSeparator( false ),
228  mbHeaderFooterEdit( false ),
229  mpTargetPaintWindow(nullptr),
230  mpBufferedOut(nullptr),
231  mxDoc( rShell.GetDoc() ),
232  mnStartAction( 0 ),
233  mnLockPaint( 0 ),
234  mbSelectAll(false),
235  mbOutputToWindow(false),
236  mpPrePostOutDev(nullptr),
237  maPrePostMapMode()
238 {
239  // in order to suppress event handling in
240  // <SwDrawContact::Changed> during construction of <SwViewShell> instance
241  mbInConstructor = true;
242 
243  mbPaintWorks = mbEnableSmooth = true;
245  mbEndActionByVirDev = false;
246  mbPreview = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
247 
248  if( nFlags & VSHELLFLAG_SHARELAYOUT )
249  mpLayout = rShell.mpLayout;
250 
251  SET_CURR_SHELL( this );
252 
253  bool bModified = mxDoc->getIDocumentState().IsModified();
254 
255  OutputDevice* pOrigOut = mpOut;
256  Init( rShell.GetViewOptions() ); // might change Outdev (InitPrt())
257  mpOut = pOrigOut;
258 
259  if ( mbPreview )
260  mpImp->InitPagePreviewLayout();
261 
262  static_cast<SwHiddenTextFieldType*>(mxDoc->getIDocumentFieldsAccess().GetSysFieldType( SwFieldIds::HiddenText ))->
263  SetHiddenFlag( !mpOpt->IsShowHiddenField() );
264 
265  // In Init a standard FrameFormat is created.
266  if( !bModified && !mxDoc->GetIDocumentUndoRedo().IsUndoNoResetModified() )
267  {
268  mxDoc->getIDocumentState().ResetModified();
269  }
270 
271  // extend format cache.
272  if ( SwTextFrame::GetTextCache()->GetCurMax() < 2550 )
274  if( mpOpt->IsGridVisible() || getIDocumentDrawModelAccess().GetDrawModel() )
275  Imp()->MakeDrawView();
276 
277  mbInConstructor = false;
278 
279 }
280 
282 {
283  IDocumentLayoutAccess* const pLayoutAccess
284  = mxDoc ? &mxDoc->getIDocumentLayoutAccess() : nullptr;
285 
286  {
287  SET_CURR_SHELL( this );
288  mbPaintWorks = false;
289 
290  // i#9684 Stopping the animated graphics is not
291  // necessary during printing or pdf export, because the animation
292  // has not been started in this case.
293  if( mxDoc.get() && GetWin() )
294  {
295  SwNodes& rNds = mxDoc->GetNodes();
296 
297  SwStartNode *pStNd;
298  SwNodeIndex aIdx( *rNds.GetEndOfAutotext().StartOfSectionNode(), 1 );
299  while ( nullptr != (pStNd = aIdx.GetNode().GetStartNode()) )
300  {
301  ++aIdx;
302  SwGrfNode *pGNd = aIdx.GetNode().GetGrfNode();
303  if ( nullptr != pGNd )
304  {
305  if( pGNd->IsAnimated() )
306  {
307  SwIterator<SwFrame,SwGrfNode> aIter( *pGNd );
308  for( SwFrame* pFrame = aIter.First(); pFrame; pFrame = aIter.Next() )
309  {
310  OSL_ENSURE( pFrame->IsNoTextFrame(), "GraphicNode with Text?" );
311  static_cast<SwNoTextFrame*>(pFrame)->StopAnimation( mpOut );
312  }
313  }
314  }
315  aIdx.Assign( *pStNd->EndOfSectionNode(), +1 );
316  }
317 
319  }
320 
321  mpImp.reset();
322 
323  if (mxDoc)
324  {
325  if( mxDoc->getReferenceCount() > 1 )
327  }
328 
329  mpOpt.reset();
330 
331  // resize format cache.
332  if ( SwTextFrame::GetTextCache()->GetCurMax() > 250 )
334 
335  // Remove from PaintQueue if necessary
336  SwPaintQueue::Remove( this );
337 
338  OSL_ENSURE( !mnStartAction, "EndAction() pending." );
339  }
340 
341  if ( pLayoutAccess )
342  {
343  GetLayout()->DeRegisterShell( this );
344  if(pLayoutAccess->GetCurrentViewShell()==this)
345  {
346  pLayoutAccess->SetCurrentViewShell(nullptr);
347  for(SwViewShell& rShell : GetRingContainer())
348  {
349  if(&rShell != this)
350  {
351  pLayoutAccess->SetCurrentViewShell(&rShell);
352  break;
353  }
354  }
355  }
356  }
357 
358  mpAccOptions.reset();
359 }
360 
362 {
363  return Imp() && Imp()->HasDrawView();
364 }
365 
367 {
368  Imp()->MakeDrawView( );
369 }
370 
372 {
373  return Imp()->HasDrawView() && Imp()->GetDrawView()->IsDragObj();
374 }
375 
377 {
378  return Imp()->GetDrawView();
379 }
380 
382 {
383  SwDrawView* pDView = Imp()->GetDrawView();
384  pDView->ValidateMarkList();
385  return pDView;
386 }
387 
388 /* 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:281
SdrView * GetDrawView()
Definition: vnew.cxx:376
SwViewShellImp * Imp()
Definition: viewsh.hxx:185
void StopNumRuleAnimations(OutputDevice *)
Definition: docnum.cxx:1153
Definition: doc.hxx:185
TElementType * Next()
Definition: calbck.hxx:376
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:361
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:166
void DecreaseMax(const sal_uInt16 nSub)
Definition: swcache.cxx:141
SwDoc * GetDoc() const
Definition: viewsh.hxx:284
const IDocumentDrawModelAccess & getIDocumentDrawModelAccess() const
Provides access to the document draw model interface.
Definition: viewsh.cxx:2594
bool mbInConstructor
Definition: viewsh.hxx:141
void SizeChgNotify()
Definition: viewsh.cxx:1044
bool mbPreview
Definition: viewsh.hxx:130
void SetLineColor()
void IncreaseMax(const sal_uInt16 nAdd)
Definition: swcache.cxx:130
const SwStartNode * StartOfSectionNode() const
Definition: node.hxx:131
bool IsAnimated() const
Definition: ndgrf.hxx:96
OUTDEV_PDF
TElementType * First()
Definition: calbck.hxx:345
std::unique_ptr< SwAccessibilityOptions > mpAccOptions
Definition: viewsh.hxx:120
void ResetNewLayout()
Definition: rootfrm.hxx:368
sal_uInt16 GetHtmlMode(const SwDocShell *pShell)
Definition: viewopt.cxx:339
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:67
bool mbPaintInProgress
Definition: viewsh.hxx:126
IDocumentLayoutAccess const & getIDocumentLayoutAccess() const
Definition: doc.cxx:437
bool IsReadOnly() const
static void Init(vcl::Window const *pWin)
Definition: viewopt.cxx:310
SwViewShell(SwViewShell &, vcl::Window *pWin, OutputDevice *pOut=nullptr, long nFlags=0)
CTor for further Shells on a document.
Definition: vnew.cxx:215
bool mbDocSizeChgd
Definition: viewsh.hxx:122
void MakeDrawView()
Definition: vnew.cxx:366
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:381
#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:46
SwRootFrame * GetLayout() const
Definition: viewsh.cxx:2072
bool HasDrawViewDrag() const
Definition: vnew.cxx:371
sal_uInt16 mnStartAction
!= 0 if at least one Action is active.
Definition: viewsh.hxx:176