update dev300-m58
[ooovba.git] / sw / source / core / view / vnew.cxx
blobafae44310b49857505684f4031466cef5f1ea5e3
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: vnew.cxx,v $
10 * $Revision: 1.31.210.2 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <sfx2/printer.hxx>
36 #include <rtl/logfile.hxx>
37 #include <doc.hxx>
38 #ifndef _DOCSH_HXX
39 #include <docsh.hxx>
40 #endif
41 #include <viewsh.hxx>
42 #include <rootfrm.hxx>
43 #include <viewimp.hxx>
44 #include <viewopt.hxx>
45 #include <txtfrm.hxx> // Zugriff auf TxtCache
46 #include <notxtfrm.hxx>
47 #include <fntcache.hxx>
48 #include <docufld.hxx>
49 #include <ptqueue.hxx>
50 #include <dview.hxx> // SdrView
51 #include <ndgrf.hxx>
52 #include <ndindex.hxx>
53 #include <accessibilityoptions.hxx>
56 /*************************************************************************
58 |* ViewShell::Init()
60 |* Letzte Aenderung MA 14. Jun. 96
62 |*************************************************************************/
64 void ViewShell::Init( const SwViewOption *pNewOpt )
66 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "ViewShell::Init" );
68 bDocSizeChgd = FALSE;
70 // Wir gehen auf Nummer sicher:
71 // Wir muessen die alten Fontinformationen wegschmeissen,
72 // wenn die Druckeraufloesung oder der Zoomfaktor sich aendert.
73 // Init() und Reformat() sind die sichersten Stellen.
74 pFntCache->Flush( );
76 // ViewOptions werden dynamisch angelegt
77 if( !pOpt )
79 pOpt = new SwViewOption;
81 // Ein ApplyViewOptions braucht nicht gerufen zu werden
82 if( pNewOpt )
84 *pOpt = *pNewOpt;
85 // Der Zoomfaktor muss eingestellt werden, weil in der CTOR-
86 // phase aus Performancegruenden kein ApplyViewOptions gerufen wird.
87 if( GetWin() && 100 != pOpt->GetZoom() )
89 MapMode aMode( pWin->GetMapMode() );
90 const Fraction aNewFactor( pOpt->GetZoom(), 100 );
91 aMode.SetScaleX( aNewFactor );
92 aMode.SetScaleY( aNewFactor );
93 pWin->SetMapMode( aMode );
98 SwDocShell* pDShell = pDoc->GetDocShell();
99 pDoc->set(IDocumentSettingAccess::HTML_MODE, 0 != ::GetHtmlMode( pDShell ) );
101 // JP 02.02.99: Bug 61335 - Readonly-Flag an den ViewOptions setzen,
102 // bevor das Layout angelegt wird. Ansonsten muesste man
103 // nochmals durchformatieren!!
104 if( pDShell && pDShell->IsReadOnly() )
105 pOpt->SetReadonly( TRUE );
107 RTL_LOGFILE_CONTEXT_TRACE( aLog, "View::Init - before InitPrt" );
109 // --> FME 2007-11-06 #i82967#
110 OutputDevice* pPDFOut = 0;
111 if ( pOut && pOut->GetPDFWriter() )
112 pPDFOut = pOut;
113 // <--
115 // --> FME 2005-01-21 #i41075#
116 // Only setup the printer if we need one:
117 const IDocumentSettingAccess* pIDSA = getIDocumentSettingAccess();
118 const bool bBrowseMode = pIDSA->get(IDocumentSettingAccess::BROWSE_MODE);
119 const bool bCreatePrinter = !bBrowseMode &&
120 !pIDSA->get(IDocumentSettingAccess::USE_VIRTUAL_DEVICE);
121 SfxPrinter* pPrinter = getIDocumentDeviceAccess()->getPrinter( bCreatePrinter );
122 if( pPrinter )
123 InitPrt( pPrinter, pPDFOut );
124 // <--
126 // --> FME 2005-03-16 #i44963# Good occasion to check if page sizes in
127 // page descriptions are still set to (LONG_MAX, LONG_MAX) (html import)
128 if ( !bBrowseMode )
130 pDoc->CheckDefaultPageFmt();
132 // <--
134 RTL_LOGFILE_CONTEXT_TRACE( aLog, "View::Init - after InitPrt" );
136 if( GetWin() )
138 pOpt->Init( GetWin() );
139 GetWin()->SetFillColor();
140 GetWin()->SetBackground();
141 GetWin()->SetLineColor();
144 //Layout erzeugen wenn es noch nicht vorhanden ist.
145 SwRootFrm* pRoot = GetDoc()->GetRootFrm();
146 if( !pRoot )
147 GetDoc()->SetRootFrm( pRoot = new SwRootFrm( pDoc->GetDfltFrmFmt(), this ) );
149 SizeChgNotify();
151 // --> #i31958#
152 // XForms mode: initialize XForms mode, based on design mode (draw view)
153 // MakeDrawView() requires layout
154 if( GetDoc()->isXForms() )
156 if( ! HasDrawView() )
157 MakeDrawView();
158 pOpt->SetFormView( ! GetDrawView()->IsDesignMode() );
160 // <-- #i31958#
163 /*************************************************************************
165 |* ViewShell::ViewShell() CTor fuer die erste Shell.
167 |* Letzte Aenderung MA 29. Aug. 95
169 |*************************************************************************/
171 ViewShell::ViewShell( SwDoc& rDocument, Window *pWindow,
172 const SwViewOption *pNewOpt, OutputDevice *pOutput,
173 long nFlags )
175 aBrowseBorder(),
176 pSfxViewShell( 0 ),
177 pImp( new SwViewImp( this ) ),
178 pWin( pWindow ),
179 pOut( pOutput ? pOutput
180 : pWindow ? (OutputDevice*)pWindow
181 : (OutputDevice*)rDocument.getPrinter( true )),
182 mpTmpRef( 0 ),
183 pOpt( 0 ),
184 pAccOptions( new SwAccessibilityOptions ),
185 mpTargetPaintWindow(0), // #i74769#
186 mpBufferedOut(0), // #i74769#
187 pDoc( &rDocument ),
188 nStartAction( 0 ),
189 nLockPaint( 0 ),
190 mnPrePostPaintCount(0L), // #i72754#
191 mpPrePostOutDev(0), // #i72754#
192 maPrePostMapMode()
194 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "ViewShell::SwViewShell" );
196 // OD 2004-06-01 #i26791# - in order to suppress event handling in
197 // <SwDrawContact::Changed> during contruction of <ViewShell> instance
198 mbInConstructor = true;
200 bPaintInProgress = bViewLocked = bInEndAction = bFrameView =
201 bEndActionByVirDev = FALSE;
202 bPaintWorks = bEnableSmooth = TRUE;
203 bPreView = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
205 // --> OD 2005-02-11 #i38810# - Do not reset modified state of document,
206 // if it's already been modified.
207 const bool bIsDocModified( pDoc->IsModified() );
208 // <--
209 pDoc->acquire();
210 pOutput = pOut;
211 Init( pNewOpt ); //verstellt ggf. das Outdev (InitPrt())
212 pOut = pOutput;
214 // OD 28.03.2003 #108470# - initialize print preview layout after layout
215 // is created in <ViewShell::Init(..)> - called above.
216 if ( bPreView )
218 // OD 12.12.2002 #103492# - init page preview layout
219 pImp->InitPagePreviewLayout();
222 SET_CURR_SHELL( this );
224 ((SwHiddenTxtFieldType*)pDoc->GetSysFldType( RES_HIDDENTXTFLD ))->
225 SetHiddenFlag( !pOpt->IsShowHiddenField() );
227 //In Init wird ein Standard-FrmFmt angelegt.
228 // --> OD 2005-02-11 #i38810#
229 if ( !pDoc->IsUndoNoResetModified() && !bIsDocModified )
230 // <--
232 pDoc->ResetModified();
235 //Format-Cache erweitern.
236 if ( SwTxtFrm::GetTxtCache()->GetCurMax() < 2550 )
237 SwTxtFrm::GetTxtCache()->IncreaseMax( 100 );
238 if( pOpt->IsGridVisible() || getIDocumentDrawModelAccess()->GetDrawModel() )
239 Imp()->MakeDrawView();
241 // OD 2004-06-01 #i26791#
242 mbInConstructor = false;
245 /*************************************************************************
247 |* ViewShell::ViewShell() CTor fuer weitere Shells auf ein Dokument.
249 |* Letzte Aenderung MA 29. Aug. 95
251 |*************************************************************************/
253 ViewShell::ViewShell( ViewShell& rShell, Window *pWindow,
254 OutputDevice *pOutput, long nFlags ) :
255 Ring( &rShell ),
256 aBrowseBorder( rShell.aBrowseBorder ),
257 pSfxViewShell( 0 ),
258 pImp( new SwViewImp( this ) ),
259 pWin( pWindow ),
260 pOut( pOutput ? pOutput
261 : pWindow ? (OutputDevice*)pWindow
262 : (OutputDevice*)rShell.GetDoc()->getPrinter( true )),
263 mpTmpRef( 0 ),
264 pOpt( 0 ),
265 pAccOptions( new SwAccessibilityOptions ),
266 mpTargetPaintWindow(0), // #i74769#
267 mpBufferedOut(0), // #i74769#
268 pDoc( rShell.GetDoc() ),
269 nStartAction( 0 ),
270 nLockPaint( 0 ),
271 mnPrePostPaintCount(0L), // #i72754#
272 mpPrePostOutDev(0), // #i72754#
273 maPrePostMapMode()
275 RTL_LOGFILE_CONTEXT_AUTHOR( aLog, "SW", "JP93722", "ViewShell::SwViewShell" );
277 // OD 2004-06-01 #i26791# - in order to suppress event handling in
278 // <SwDrawContact::Changed> during contruction of <ViewShell> instance
279 mbInConstructor = true;
281 bPaintWorks = bEnableSmooth = TRUE;
282 bPaintInProgress = bViewLocked = bInEndAction = bFrameView =
283 bEndActionByVirDev = FALSE;
284 bPreView = 0 !=( VSHELLFLAG_ISPREVIEW & nFlags );
285 // OD 12.12.2002 #103492#
286 if ( bPreView )
287 pImp->InitPagePreviewLayout();
289 SET_CURR_SHELL( this );
291 pDoc->acquire();
292 BOOL bModified = pDoc->IsModified();
294 pOutput = pOut;
295 Init( rShell.GetViewOptions() ); //verstellt ggf. das Outdev (InitPrt())
296 pOut = pOutput;
298 ((SwHiddenTxtFieldType*)pDoc->GetSysFldType( RES_HIDDENTXTFLD ))->
299 SetHiddenFlag( !pOpt->IsShowHiddenField() );
301 // in Init wird ein Standard-FrmFmt angelegt
302 if( !bModified && !pDoc->IsUndoNoResetModified() )
303 pDoc->ResetModified();
305 //Format-Cache erweitern.
306 if ( SwTxtFrm::GetTxtCache()->GetCurMax() < 2550 )
307 SwTxtFrm::GetTxtCache()->IncreaseMax( 100 );
308 if( pOpt->IsGridVisible() || getIDocumentDrawModelAccess()->GetDrawModel() )
309 Imp()->MakeDrawView();
311 // OD 2004-06-01 #i26791#
312 mbInConstructor = false;
316 /******************************************************************************
318 |* ViewShell::~ViewShell()
320 |* Ersterstellung MA ??
321 |* Letzte Aenderung MA 10. May. 95
323 ******************************************************************************/
325 ViewShell::~ViewShell()
328 SET_CURR_SHELL( this );
329 bPaintWorks = FALSE;
331 // FME 2004-06-21 #i9684# Stopping the animated graphics is not
332 // necessary during printing or pdf export, because the animation
333 // has not been started in this case.
334 if( pDoc && GetWin() )
336 SwNodes& rNds = pDoc->GetNodes();
337 SwGrfNode *pGNd;
339 SwStartNode *pStNd;
340 SwNodeIndex aIdx( *rNds.GetEndOfAutotext().StartOfSectionNode(), 1 );
341 while ( 0 != (pStNd = aIdx.GetNode().GetStartNode()) )
343 aIdx++;
344 if ( 0 != ( pGNd = aIdx.GetNode().GetGrfNode() ) )
346 if( pGNd->IsAnimated() )
348 SwClientIter aIter( *pGNd );
349 for( SwFrm* pFrm = (SwFrm*)aIter.First( TYPE(SwFrm) );
350 pFrm; pFrm = (SwFrm*)aIter.Next() )
352 ASSERT( pFrm->IsNoTxtFrm(), "GraphicNode with Text?" );
353 ((SwNoTxtFrm*)pFrm)->StopAnimation( pOut );
357 aIdx.Assign( *pStNd->EndOfSectionNode(), +1 );
360 GetDoc()->StopNumRuleAnimations( pOut );
363 delete pImp; //Erst loeschen, damit die LayoutViews vernichtet werden.
364 pImp = 0; // Set to zero, because ~SwFrm relies on it.
366 if ( pDoc )
368 if( !pDoc->release() )
369 delete pDoc, pDoc = 0;
370 else
371 pDoc->GetRootFrm()->ResetNewLayout();
374 delete pOpt;
376 //Format-Cache zurueckschrauben.
377 if ( SwTxtFrm::GetTxtCache()->GetCurMax() > 250 )
378 SwTxtFrm::GetTxtCache()->DecreaseMax( 100 );
380 //Ggf. aus der PaintQueue entfernen lassen
381 SwPaintQueue::Remove( this );
383 ASSERT( !nStartAction, "EndAction() pending." );
386 if ( pDoc )
387 GetLayout()->DeRegisterShell( this );
389 delete mpTmpRef;
390 delete pAccOptions;
393 BOOL ViewShell::HasDrawView() const
395 return Imp()->HasDrawView();
398 void ViewShell::MakeDrawView()
400 Imp()->MakeDrawView( );
403 SdrView* ViewShell::GetDrawView()
405 return Imp()->GetDrawView();
408 SdrView* ViewShell::GetDrawViewWithValidMarkList()
410 SwDrawView* pDView = Imp()->GetDrawView();
411 pDView->ValidateMarkList();
412 return pDView;