xref: /trunk/main/sw/source/core/view/vnew.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 // MARKER(update_precomp.py): autogen include statement, do not remove
29 #include "precompiled_sw.hxx"
30 
31 
32 #include <sfx2/printer.hxx>
33 #include <rtl/logfile.hxx>
34 #include <doc.hxx>
35 #include <IDocumentUndoRedo.hxx>
36 #include <docsh.hxx>
37 #include <viewsh.hxx>
38 #include <rootfrm.hxx>
39 #include <viewimp.hxx>
40 #include <viewopt.hxx>
41 #include <txtfrm.hxx>		// Zugriff auf TxtCache
42 #include <notxtfrm.hxx>
43 #include <fntcache.hxx>
44 #include <docufld.hxx>
45 #include <ptqueue.hxx>
46 #include <dview.hxx>		// SdrView
47 #include <ndgrf.hxx>
48 #include <ndindex.hxx>
49 #include <accessibilityoptions.hxx>
50 #include <switerator.hxx>
51 
52 /*************************************************************************
53 |*
54 |*	ViewShell::Init()
55 |*************************************************************************/
56 
57 void ViewShell::Init( const SwViewOption *pNewOpt )
58 {
59 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "ViewShell::Init" );
60 
61 	bDocSizeChgd = sal_False;
62 
63 	// Wir gehen auf Nummer sicher:
64 	// Wir muessen die alten Fontinformationen wegschmeissen,
65 	// wenn die Druckeraufloesung oder der Zoomfaktor sich aendert.
66 	// Init() und Reformat() sind die sichersten Stellen.
67 	pFntCache->Flush( );
68 
69 	// ViewOptions werden dynamisch angelegt
70 	if( !pOpt )
71 	{
72 		pOpt = new SwViewOption;
73 
74 		// Ein ApplyViewOptions braucht nicht gerufen zu werden
75 		if( pNewOpt )
76 		{
77 			*pOpt = *pNewOpt;
78 			// Der Zoomfaktor muss eingestellt werden, weil in der CTOR-
79 			// phase aus Performancegruenden kein ApplyViewOptions gerufen wird.
80 			if( GetWin() && 100 != pOpt->GetZoom() )
81 			{
82 				MapMode aMode( pWin->GetMapMode() );
83 				const Fraction aNewFactor( pOpt->GetZoom(), 100 );
84 				aMode.SetScaleX( aNewFactor );
85 				aMode.SetScaleY( aNewFactor );
86 				pWin->SetMapMode( aMode );
87 			}
88 		}
89 	}
90 
91 	SwDocShell* pDShell = pDoc->GetDocShell();
92 	pDoc->set(IDocumentSettingAccess::HTML_MODE, 0 != ::GetHtmlMode( pDShell ) );
93 
94 	// JP 02.02.99: Bug 61335 - Readonly-Flag an den ViewOptions setzen,
95 	//				bevor das Layout angelegt wird. Ansonsten muesste man
96 	//				nochmals durchformatieren!!
97 	if( pDShell && pDShell->IsReadOnly() )
98 		pOpt->SetReadonly( sal_True );
99 
100 	RTL_LOGFILE_CONTEXT_TRACE( aLog, "View::Init - before InitPrt" );
101 
102     // --> FME 2007-11-06 #i82967#
103     OutputDevice* pPDFOut = 0;
104     if ( pOut && pOut->GetPDFWriter() )
105         pPDFOut = pOut;
106     // <--
107 
108     // --> FME 2005-01-21 #i41075#
109     // Only setup the printer if we need one:
110     const bool bBrowseMode = pOpt->getBrowseMode();
111     if( pPDFOut )
112         InitPrt( pPDFOut );
113     // <--
114 
115     // --> FME 2005-03-16 #i44963# Good occasion to check if page sizes in
116     // page descriptions are still set to (LONG_MAX, LONG_MAX) (html import)
117     if ( !bBrowseMode )
118     {
119         pDoc->CheckDefaultPageFmt();
120     }
121     // <--
122 
123 	RTL_LOGFILE_CONTEXT_TRACE( aLog, "View::Init - after InitPrt" );
124 
125 	if( GetWin() )
126 	{
127 		pOpt->Init( GetWin() );
128 		GetWin()->SetFillColor();
129 		GetWin()->SetBackground();
130 		GetWin()->SetLineColor();
131 	}
132 
133     // Create a new layout, if there is no one available
134 	if( !pLayout )
135     {
136         // Here's the code which disables the usage of "multiple" layouts at the moment
137         // If the problems with controls and groups objects are solved,
138         // this code can be removed...
139         ViewShell *pCurrShell = GetDoc()->GetCurrentViewShell();
140         if( pCurrShell )
141             pLayout = pCurrShell->pLayout;
142         // end of "disable multiple layouts"
143         if( !pLayout )
144 		{
145 			// switched to two step construction because creating the layout in SwRootFrm needs a valid pLayout set
146             pLayout = SwRootFrmPtr(new SwRootFrm( pDoc->GetDfltFrmFmt(), this ));//swmod081016
147             pLayout->Init( pDoc->GetDfltFrmFmt() );
148         }
149     }
150 	SizeChgNotify();	//swmod 071108
151 
152     // --> #i31958#
153     // XForms mode: initialize XForms mode, based on design mode (draw view)
154     //   MakeDrawView() requires layout
155     if( GetDoc()->isXForms() )
156     {
157         if( ! HasDrawView() )
158             MakeDrawView();
159         pOpt->SetFormView( ! GetDrawView()->IsDesignMode() );
160     }
161     // <-- #i31958#
162 }
163 
164 /*************************************************************************
165 |*
166 |*	ViewShell::ViewShell()	CTor fuer die erste Shell.
167 |*************************************************************************/
168 
169 ViewShell::ViewShell( SwDoc& rDocument, Window *pWindow,
170 						const SwViewOption *pNewOpt, OutputDevice *pOutput,
171 						long nFlags )
172     :
173 	aBrowseBorder(),
174     pSfxViewShell( 0 ),
175     pImp( new SwViewImp( this ) ),
176     pWin( pWindow ),
177     pOut( pOutput ? pOutput
178                   : pWindow ? (OutputDevice*)pWindow
179                             : (OutputDevice*)rDocument.getPrinter( true )),
180     mpTmpRef( 0 ),
181     pOpt( 0 ),
182     pAccOptions( new SwAccessibilityOptions ),
183 	mpTargetPaintWindow(0), // #i74769#
184 	mpBufferedOut(0), // #i74769#
185     pDoc( &rDocument ),
186     nStartAction( 0 ),
187 	nLockPaint( 0 ),
188 	mnPrePostPaintCount(0L), // #i72754#
189 	mpPrePostOutDev(0), // #i72754#
190 	maPrePostMapMode()
191 {
192 	RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "ViewShell::SwViewShell" );
193 
194     // OD 2004-06-01 #i26791# - in order to suppress event handling in
195     // <SwDrawContact::Changed> during contruction of <ViewShell> instance
196     mbInConstructor = true;
197 
198 	bPaintInProgress = bViewLocked = bInEndAction = bFrameView =
199 	bEndActionByVirDev = sal_False;
200 	bPaintWorks = bEnableSmooth = sal_True;
201 	bPreView = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
202 
203     // --> OD 2005-02-11 #i38810# - Do not reset modified state of document,
204     // if it's already been modified.
205     const bool bIsDocModified( pDoc->IsModified() );
206     // <--
207 	pDoc->acquire();
208 	pOutput = pOut;
209 	Init( pNewOpt );	//verstellt ggf. das Outdev (InitPrt())
210 	pOut = pOutput;
211 
212     // OD 28.03.2003 #108470# - initialize print preview layout after layout
213     // is created in <ViewShell::Init(..)> - called above.
214     if ( bPreView )
215     {
216         // OD 12.12.2002 #103492# - init page preview layout
217         pImp->InitPagePreviewLayout();
218     }
219 
220 	SET_CURR_SHELL( this );
221 
222 	((SwHiddenTxtFieldType*)pDoc->GetSysFldType( RES_HIDDENTXTFLD ))->
223         SetHiddenFlag( !pOpt->IsShowHiddenField() );
224 
225 	//In Init wird ein Standard-FrmFmt angelegt.
226     // --> OD 2005-02-11 #i38810#
227     if (   !pDoc->GetIDocumentUndoRedo().IsUndoNoResetModified()
228         && !bIsDocModified )
229     // <--
230     {
231 		pDoc->ResetModified();
232     }
233 
234 	//Format-Cache erweitern.
235 	if ( SwTxtFrm::GetTxtCache()->GetCurMax() < 2550 )
236 		SwTxtFrm::GetTxtCache()->IncreaseMax( 100 );
237     if( pOpt->IsGridVisible() || getIDocumentDrawModelAccess()->GetDrawModel() )
238 		Imp()->MakeDrawView();
239 
240     // OD 2004-06-01 #i26791#
241     mbInConstructor = false;
242 }
243 
244 /*************************************************************************
245 |*
246 |*	ViewShell::ViewShell()	CTor fuer weitere Shells auf ein Dokument.
247 |*************************************************************************/
248 
249 ViewShell::ViewShell( ViewShell& rShell, Window *pWindow,
250 						OutputDevice *pOutput, long nFlags ) :
251 	Ring( &rShell ),
252     aBrowseBorder( rShell.aBrowseBorder ),
253     pSfxViewShell( 0 ),
254     pImp( new SwViewImp( this ) ),
255     pWin( pWindow ),
256 	pOut( pOutput ? pOutput
257 				  : pWindow ? (OutputDevice*)pWindow
258                             : (OutputDevice*)rShell.GetDoc()->getPrinter( true )),
259     mpTmpRef( 0 ),
260 	pOpt( 0 ),
261     pAccOptions( new SwAccessibilityOptions ),
262 	mpTargetPaintWindow(0), // #i74769#
263 	mpBufferedOut(0), // #i74769#
264     pDoc( rShell.GetDoc() ),
265     nStartAction( 0 ),
266 	nLockPaint( 0 ),
267 	mnPrePostPaintCount(0L), // #i72754#
268 	mpPrePostOutDev(0), // #i72754#
269 	maPrePostMapMode()
270 {
271     RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722",  "ViewShell::SwViewShell" );
272 
273     // OD 2004-06-01 #i26791# - in order to suppress event handling in
274     // <SwDrawContact::Changed> during contruction of <ViewShell> instance
275     mbInConstructor = true;
276 
277     bPaintWorks = bEnableSmooth = sal_True;
278 	bPaintInProgress = bViewLocked = bInEndAction = bFrameView =
279 	bEndActionByVirDev = sal_False;
280 	bPreView = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
281 	if( nFlags & VSHELLFLAG_SHARELAYOUT ) //swmod 080125
282 		pLayout = rShell.pLayout;//swmod 080125
283 
284 	SET_CURR_SHELL( this );
285 
286 	pDoc->acquire();
287 	sal_Bool bModified = pDoc->IsModified();
288 
289 	pOutput = pOut;
290 	Init( rShell.GetViewOptions() );	//verstellt ggf. das Outdev (InitPrt())
291 	pOut = pOutput;
292 
293     // OD 12.12.2002 #103492#
294     if ( bPreView )
295         pImp->InitPagePreviewLayout();
296 
297 	((SwHiddenTxtFieldType*)pDoc->GetSysFldType( RES_HIDDENTXTFLD ))->
298             SetHiddenFlag( !pOpt->IsShowHiddenField() );
299 
300 	// in Init wird ein Standard-FrmFmt angelegt
301     if( !bModified && !pDoc->GetIDocumentUndoRedo().IsUndoNoResetModified() )
302     {
303 		pDoc->ResetModified();
304     }
305 
306 	//Format-Cache erweitern.
307 	if ( SwTxtFrm::GetTxtCache()->GetCurMax() < 2550 )
308 		SwTxtFrm::GetTxtCache()->IncreaseMax( 100 );
309     if( pOpt->IsGridVisible() || getIDocumentDrawModelAccess()->GetDrawModel() )
310         Imp()->MakeDrawView();
311 
312     // OD 2004-06-01 #i26791#
313     mbInConstructor = false;
314 
315 }
316 
317 /******************************************************************************
318 |*
319 |*	ViewShell::~ViewShell()
320 |*
321 ******************************************************************************/
322 
323 ViewShell::~ViewShell()
324 {
325 	{
326 		SET_CURR_SHELL( this );
327 		bPaintWorks = sal_False;
328 
329         // FME 2004-06-21 #i9684# Stopping the animated graphics is not
330         // necessary during printing or pdf export, because the animation
331         // has not been started in this case.
332         if( pDoc && GetWin() )
333 		{
334 			SwNodes& rNds = pDoc->GetNodes();
335 			SwGrfNode *pGNd;
336 
337 			SwStartNode *pStNd;
338 			SwNodeIndex aIdx( *rNds.GetEndOfAutotext().StartOfSectionNode(), 1 );
339 			while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
340 			{
341 				aIdx++;
342 				if ( 0 != ( pGNd = aIdx.GetNode().GetGrfNode() ) )
343 				{
344 					if( pGNd->IsAnimated() )
345 					{
346 						SwIterator<SwFrm,SwGrfNode> aIter( *pGNd );
347 						for( SwFrm* pFrm = aIter.First(); pFrm; pFrm = aIter.Next() )
348 						{
349 							ASSERT( pFrm->IsNoTxtFrm(), "GraphicNode with Text?" );
350 							((SwNoTxtFrm*)pFrm)->StopAnimation( pOut );
351 						}
352 					}
353 				}
354 				aIdx.Assign( *pStNd->EndOfSectionNode(), +1 );
355 			}
356 
357 			GetDoc()->StopNumRuleAnimations( pOut );
358 		}
359 
360 		delete pImp; //Erst loeschen, damit die LayoutViews vernichtet werden.
361 		pImp = 0;	// Set to zero, because ~SwFrm relies on it.
362 
363 		if ( pDoc )
364 		{
365 			if( !pDoc->release() )
366 				delete pDoc, pDoc = 0;
367 			else
368 				GetLayout()->ResetNewLayout();
369 		}//swmod 080317
370 
371 		delete pOpt;
372 
373 		//Format-Cache zurueckschrauben.
374 		if ( SwTxtFrm::GetTxtCache()->GetCurMax() > 250 )
375 			SwTxtFrm::GetTxtCache()->DecreaseMax( 100 );
376 
377 		//Ggf. aus der PaintQueue entfernen lassen
378 		SwPaintQueue::Remove( this );
379 
380 		ASSERT( !nStartAction, "EndAction() pending." );
381 	}
382 
383 	if ( pDoc )
384 	{
385 		GetLayout()->DeRegisterShell( this );
386 		if(pDoc->GetCurrentViewShell()==this)
387 			pDoc->SetCurrentViewShell( this->GetNext()!=this ?
388 			(ViewShell*)this->GetNext() : NULL );
389 	}
390 
391     delete mpTmpRef;
392     delete pAccOptions;
393 }
394 
395 sal_Bool ViewShell::HasDrawView() const
396 {
397 	return Imp() ? Imp()->HasDrawView() : 0;
398 }
399 
400 void ViewShell::MakeDrawView()
401 {
402 	Imp()->MakeDrawView( );
403 }
404 
405 SdrView* ViewShell::GetDrawView()
406 {
407 	return Imp()->GetDrawView();
408 }
409 
410 SdrView* ViewShell::GetDrawViewWithValidMarkList()
411 {
412 	SwDrawView* pDView = Imp()->GetDrawView();
413 	pDView->ValidateMarkList();
414 	return pDView;
415 }
416