Line data Source code
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 <doc.hxx>
22 : #include <IDocumentUndoRedo.hxx>
23 : #include <DocumentSettingManager.hxx>
24 : #include <IDocumentDeviceAccess.hxx>
25 : #include <IDocumentLayoutAccess.hxx>
26 : #include <IDocumentFieldsAccess.hxx>
27 : #include <IDocumentState.hxx>
28 : #include <docsh.hxx>
29 : #include <viewsh.hxx>
30 : #include <rootfrm.hxx>
31 : #include <viewimp.hxx>
32 : #include <viewopt.hxx>
33 : #include <txtfrm.hxx>
34 : #include <notxtfrm.hxx>
35 : #include <fntcache.hxx>
36 : #include <docufld.hxx>
37 : #include <ptqueue.hxx>
38 : #include <dview.hxx>
39 : #include <ndgrf.hxx>
40 : #include <ndindex.hxx>
41 : #include <accessibilityoptions.hxx>
42 : #include <calbck.hxx>
43 :
44 3109 : void SwViewShell::Init( const SwViewOption *pNewOpt )
45 : {
46 3109 : mbDocSizeChgd = false;
47 :
48 : // We play it save: Remove old font information whenever the printer
49 : // resolution or the zoom factor changes. For that, Init() and Reformat()
50 : // are the most secure places.
51 3109 : pFntCache->Flush( );
52 :
53 : // ViewOptions are created dynamically
54 :
55 3109 : if( !mpOpt )
56 : {
57 3109 : mpOpt = new SwViewOption;
58 :
59 : // ApplyViewOptions() does not need to be called
60 3109 : if( pNewOpt )
61 : {
62 3109 : *mpOpt = *pNewOpt;
63 : // Zoom factor needs to be set because there is no call to ApplyViewOptions() during
64 : // CTOR for performance reasons.
65 3109 : if( GetWin() && 100 != mpOpt->GetZoom() )
66 : {
67 0 : MapMode aMode( mpWin->GetMapMode() );
68 0 : const Fraction aNewFactor( mpOpt->GetZoom(), 100 );
69 0 : aMode.SetScaleX( aNewFactor );
70 0 : aMode.SetScaleY( aNewFactor );
71 0 : mpWin->SetMapMode( aMode );
72 : }
73 : }
74 : }
75 :
76 3109 : SwDocShell* pDShell = mpDoc->GetDocShell();
77 3109 : mpDoc->GetDocumentSettingManager().set(DocumentSettingId::HTML_MODE, 0 != ::GetHtmlMode( pDShell ) );
78 : // JP 02.02.99: Bug 61335 - set readonly flag at ViewOptions before creating layout. Otherwise,
79 : // one would have to reformat again.
80 :
81 3109 : if( pDShell && pDShell->IsReadOnly() )
82 1 : mpOpt->SetReadonly( true );
83 :
84 : SAL_INFO( "sw.core", "View::Init - before InitPrt" );
85 : // --> FME 2007-11-06 #i82967#
86 3109 : OutputDevice* pPDFOut = 0;
87 :
88 3109 : if ( mpOut && mpOut->GetPDFWriter() )
89 0 : pPDFOut = mpOut;
90 : // <--
91 :
92 : // --> FME 2005-01-21 #i41075#
93 : // Only setup the printer if we need one:
94 3109 : const bool bBrowseMode = mpOpt->getBrowseMode();
95 3109 : if( pPDFOut )
96 0 : InitPrt( pPDFOut );
97 : // <--
98 :
99 : // --> FME 2005-03-16 #i44963# Good occasion to check if page sizes in
100 : // page descriptions are still set to (LONG_MAX, LONG_MAX) (html import)
101 3109 : if ( !bBrowseMode )
102 : {
103 3106 : mpDoc->CheckDefaultPageFormat();
104 : }
105 : // <--
106 :
107 : SAL_INFO( "sw.core", "View::Init - after InitPrt" );
108 3109 : if( GetWin() )
109 : {
110 2761 : SwViewOption::Init( GetWin() );
111 2761 : GetWin()->SetFillColor();
112 2761 : GetWin()->SetBackground();
113 2761 : GetWin()->SetLineColor();
114 : }
115 :
116 : // Create a new layout, if there is no one available
117 3109 : if( !mpLayout )
118 : {
119 : // Here's the code which disables the usage of "multiple" layouts at the moment
120 : // If the problems with controls and groups objects are solved,
121 : // this code can be removed...
122 3043 : SwViewShell *pCurrShell = GetDoc()->getIDocumentLayoutAccess().GetCurrentViewShell();
123 3043 : if( pCurrShell )
124 1 : mpLayout = pCurrShell->mpLayout;
125 : // end of "disable multiple layouts"
126 3043 : if( !mpLayout )
127 : {
128 : // switched to two step construction because creating the layout in SwRootFrm needs a valid pLayout set
129 6084 : mpLayout = SwRootFrmPtr(new SwRootFrm(mpDoc->GetDfltFrameFormat(), this),
130 3042 : &SwFrm::DestroyFrm);
131 3042 : mpLayout->Init( mpDoc->GetDfltFrameFormat() );
132 : }
133 : }
134 3109 : SizeChgNotify();
135 :
136 : // --> #i31958#
137 : // XForms mode: initialize XForms mode, based on design mode (draw view)
138 : // MakeDrawView() requires layout
139 3109 : if( GetDoc()->isXForms() )
140 : {
141 0 : if( ! HasDrawView() )
142 0 : MakeDrawView();
143 0 : mpOpt->SetFormView( ! GetDrawView()->IsDesignMode() );
144 : }
145 : // <-- #i31958#
146 3109 : }
147 :
148 : /// CTor for the first Shell.
149 3042 : SwViewShell::SwViewShell( SwDoc& rDocument, vcl::Window *pWindow,
150 : const SwViewOption *pNewOpt, OutputDevice *pOutput,
151 : long nFlags )
152 : :
153 : maBrowseBorder(),
154 : mpSfxViewShell( 0 ),
155 3042 : mpImp( new SwViewShellImp( this ) ),
156 : mpWin( pWindow ),
157 : mpOut( pOutput ? pOutput
158 : : pWindow ? static_cast<OutputDevice*>(pWindow)
159 0 : : static_cast<OutputDevice*>(rDocument.getIDocumentDeviceAccess().getPrinter( true ))),
160 : mpTmpRef( 0 ),
161 : mpOpt( 0 ),
162 3042 : mpAccOptions( new SwAccessibilityOptions ),
163 : mbShowHeaderSeparator( false ),
164 : mbShowFooterSeparator( false ),
165 : mbHeaderFooterEdit( false ),
166 : mpTargetPaintWindow(0), // #i74769#
167 : mpBufferedOut(0), // #i74769#
168 : mpDoc( &rDocument ),
169 : mnStartAction( 0 ),
170 : mnLockPaint( 0 ),
171 : mbSelectAll(false),
172 : mbInLibreOfficeKitCallback(false),
173 : mpPrePostOutDev(0), // #i72754#
174 9126 : maPrePostMapMode()
175 : {
176 : // OD 2004-06-01 #i26791# - in order to suppress event handling in
177 : // <SwDrawContact::Changed> during construction of <SwViewShell> instance
178 3042 : mbInConstructor = true;
179 :
180 : mbPaintInProgress = mbViewLocked = mbInEndAction = mbFrameView =
181 3042 : mbEndActionByVirDev = false;
182 3042 : mbPaintWorks = mbEnableSmooth = true;
183 3042 : mbPreview = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
184 :
185 : // --> OD 2005-02-11 #i38810# - Do not reset modified state of document,
186 : // if it's already been modified.
187 3042 : const bool bIsDocModified( mpDoc->getIDocumentState().IsModified() );
188 3042 : mpDoc->acquire();
189 3042 : pOutput = mpOut;
190 3042 : Init( pNewOpt ); // may change the Outdev (InitPrt())
191 3042 : mpOut = pOutput;
192 :
193 : // OD 28.03.2003 #108470# - initialize print preview layout after layout
194 : // is created in <SwViewShell::Init(..)> - called above.
195 3042 : if ( mbPreview )
196 : {
197 : // OD 12.12.2002 #103492# - init page preview layout
198 0 : mpImp->InitPagePreviewLayout();
199 : }
200 :
201 3042 : SET_CURR_SHELL( this );
202 :
203 3042 : static_cast<SwHiddenTextFieldType*>(mpDoc->getIDocumentFieldsAccess().GetSysFieldType( RES_HIDDENTXTFLD ))->
204 6084 : SetHiddenFlag( !mpOpt->IsShowHiddenField() );
205 :
206 : // In Init a standard FrameFormat is created.
207 : // --> OD 2005-02-11 #i38810#
208 6084 : if ( !mpDoc->GetIDocumentUndoRedo().IsUndoNoResetModified()
209 3042 : && !bIsDocModified )
210 : // <--
211 : {
212 2725 : mpDoc->getIDocumentState().ResetModified();
213 : }
214 :
215 : // extend format cache.
216 3042 : if ( SwTextFrm::GetTextCache()->GetCurMax() < 2550 )
217 3042 : SwTextFrm::GetTextCache()->IncreaseMax( 100 );
218 3042 : if( mpOpt->IsGridVisible() || getIDocumentDrawModelAccess()->GetDrawModel() )
219 3042 : Imp()->MakeDrawView();
220 :
221 : // OD 2004-06-01 #i26791#
222 3042 : mbInConstructor = false;
223 3042 : }
224 :
225 : /// CTor for further Shells on a document.
226 67 : SwViewShell::SwViewShell( SwViewShell& rShell, vcl::Window *pWindow,
227 : OutputDevice *pOutput, long nFlags ) :
228 : Ring( &rShell ),
229 : maBrowseBorder( rShell.maBrowseBorder ),
230 : mpSfxViewShell( 0 ),
231 67 : mpImp( new SwViewShellImp( this ) ),
232 : mpWin( pWindow ),
233 : mpOut( pOutput ? pOutput
234 : : pWindow ? static_cast<OutputDevice*>(pWindow)
235 0 : : static_cast<OutputDevice*>(rShell.GetDoc()->getIDocumentDeviceAccess().getPrinter( true ))),
236 : mpTmpRef( 0 ),
237 : mpOpt( 0 ),
238 67 : mpAccOptions( new SwAccessibilityOptions ),
239 : mbShowHeaderSeparator( false ),
240 : mbShowFooterSeparator( false ),
241 : mbHeaderFooterEdit( false ),
242 : mpTargetPaintWindow(0), // #i74769#
243 : mpBufferedOut(0), // #i74769#
244 67 : mpDoc( rShell.GetDoc() ),
245 : mnStartAction( 0 ),
246 : mnLockPaint( 0 ),
247 : mbSelectAll(false),
248 : mbInLibreOfficeKitCallback(false),
249 : mpPrePostOutDev(0), // #i72754#
250 268 : maPrePostMapMode()
251 : {
252 : // OD 2004-06-01 #i26791# - in order to suppress event handling in
253 : // <SwDrawContact::Changed> during construction of <SwViewShell> instance
254 67 : mbInConstructor = true;
255 :
256 67 : mbPaintWorks = mbEnableSmooth = true;
257 : mbPaintInProgress = mbViewLocked = mbInEndAction = mbFrameView =
258 67 : mbEndActionByVirDev = false;
259 67 : mbPreview = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
260 : // OD 12.12.2002 #103492#
261 67 : if( nFlags & VSHELLFLAG_SHARELAYOUT )
262 66 : mpLayout = rShell.mpLayout;
263 :
264 67 : SET_CURR_SHELL( this );
265 :
266 67 : mpDoc->acquire();
267 67 : bool bModified = mpDoc->getIDocumentState().IsModified();
268 :
269 67 : pOutput = mpOut;
270 67 : Init( rShell.GetViewOptions() ); // might change Outdev (InitPrt())
271 67 : mpOut = pOutput;
272 :
273 : // OD 12.12.2002 #103492#
274 67 : if ( mbPreview )
275 0 : mpImp->InitPagePreviewLayout();
276 :
277 67 : static_cast<SwHiddenTextFieldType*>(mpDoc->getIDocumentFieldsAccess().GetSysFieldType( RES_HIDDENTXTFLD ))->
278 134 : SetHiddenFlag( !mpOpt->IsShowHiddenField() );
279 :
280 : // In Init a standard FrameFormat is created.
281 67 : if( !bModified && !mpDoc->GetIDocumentUndoRedo().IsUndoNoResetModified() )
282 : {
283 39 : mpDoc->getIDocumentState().ResetModified();
284 : }
285 :
286 : // extend format cache.
287 67 : if ( SwTextFrm::GetTextCache()->GetCurMax() < 2550 )
288 67 : SwTextFrm::GetTextCache()->IncreaseMax( 100 );
289 67 : if( mpOpt->IsGridVisible() || getIDocumentDrawModelAccess()->GetDrawModel() )
290 67 : Imp()->MakeDrawView();
291 :
292 : // OD 2004-06-01 #i26791#
293 67 : mbInConstructor = false;
294 :
295 67 : }
296 :
297 6558 : SwViewShell::~SwViewShell()
298 : {
299 : {
300 3105 : SET_CURR_SHELL( this );
301 3105 : mbPaintWorks = false;
302 :
303 : // FME 2004-06-21 #i9684# Stopping the animated graphics is not
304 : // necessary during printing or pdf export, because the animation
305 : // has not been started in this case.
306 3105 : if( mpDoc && GetWin() )
307 : {
308 2757 : SwNodes& rNds = mpDoc->GetNodes();
309 :
310 : SwStartNode *pStNd;
311 2757 : SwNodeIndex aIdx( *rNds.GetEndOfAutotext().StartOfSectionNode(), 1 );
312 8700 : while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
313 : {
314 3186 : ++aIdx;
315 3186 : SwGrfNode *pGNd = aIdx.GetNode().GetGrfNode();
316 3186 : if ( 0 != pGNd )
317 : {
318 463 : if( pGNd->IsAnimated() )
319 : {
320 0 : SwIterator<SwFrm,SwGrfNode> aIter( *pGNd );
321 0 : for( SwFrm* pFrm = aIter.First(); pFrm; pFrm = aIter.Next() )
322 : {
323 : OSL_ENSURE( pFrm->IsNoTextFrm(), "GraphicNode with Text?" );
324 0 : static_cast<SwNoTextFrm*>(pFrm)->StopAnimation( mpOut );
325 0 : }
326 : }
327 : }
328 3186 : aIdx.Assign( *pStNd->EndOfSectionNode(), +1 );
329 : }
330 :
331 2757 : GetDoc()->StopNumRuleAnimations( mpOut );
332 : }
333 :
334 3105 : delete mpImp; // Delete first, so that the LayoutViews are destroyed.
335 3105 : mpImp = 0; // Set to zero, because ~SwFrm relies on it.
336 :
337 3105 : if ( mpDoc )
338 : {
339 3105 : if( !mpDoc->release() )
340 0 : delete mpDoc, mpDoc = 0;
341 : else
342 3105 : GetLayout()->ResetNewLayout();
343 : }
344 :
345 3105 : delete mpOpt;
346 :
347 : // resize format cache.
348 3105 : if ( SwTextFrm::GetTextCache()->GetCurMax() > 250 )
349 3105 : SwTextFrm::GetTextCache()->DecreaseMax( 100 );
350 :
351 : // Remove from PaintQueue if necessary
352 3105 : SwPaintQueue::Remove( this );
353 :
354 3105 : OSL_ENSURE( !mnStartAction, "EndAction() pending." );
355 : }
356 :
357 3105 : if ( mpDoc )
358 : {
359 3105 : GetLayout()->DeRegisterShell( this );
360 3105 : auto& rLayoutAccess(mpDoc->getIDocumentLayoutAccess());
361 3105 : if(rLayoutAccess.GetCurrentViewShell()==this)
362 : {
363 3038 : rLayoutAccess.SetCurrentViewShell(nullptr);
364 6076 : for(SwViewShell& rShell : GetRingContainer())
365 : {
366 3038 : if(&rShell != this)
367 : {
368 0 : rLayoutAccess.SetCurrentViewShell(&rShell);
369 0 : break;
370 : }
371 : }
372 : }
373 : }
374 :
375 3105 : mpTmpRef.disposeAndClear();
376 3105 : delete mpAccOptions;
377 3453 : }
378 :
379 63147 : bool SwViewShell::HasDrawView() const
380 : {
381 63147 : return Imp() && Imp()->HasDrawView();
382 : }
383 :
384 0 : void SwViewShell::MakeDrawView()
385 : {
386 0 : Imp()->MakeDrawView( );
387 0 : }
388 :
389 215571 : SdrView* SwViewShell::GetDrawView()
390 : {
391 215571 : return Imp()->GetDrawView();
392 : }
393 :
394 0 : SdrView* SwViewShell::GetDrawViewWithValidMarkList()
395 : {
396 0 : SwDrawView* pDView = Imp()->GetDrawView();
397 0 : pDView->ValidateMarkList();
398 0 : return pDView;
399 177 : }
400 :
401 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|