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