1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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>
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
52 #include <ndindex.hxx>
53 #include <accessibilityoptions.hxx>
56 /*************************************************************************
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" );
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.
76 // ViewOptions werden dynamisch angelegt
79 pOpt
= new SwViewOption
;
81 // Ein ApplyViewOptions braucht nicht gerufen zu werden
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() )
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
);
123 InitPrt( pPrinter
, pPDFOut
);
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)
130 pDoc
->CheckDefaultPageFmt();
134 RTL_LOGFILE_CONTEXT_TRACE( aLog
, "View::Init - after InitPrt" );
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();
147 GetDoc()->SetRootFrm( pRoot
= new SwRootFrm( pDoc
->GetDfltFrmFmt(), this ) );
152 // XForms mode: initialize XForms mode, based on design mode (draw view)
153 // MakeDrawView() requires layout
154 if( GetDoc()->isXForms() )
156 if( ! HasDrawView() )
158 pOpt
->SetFormView( ! GetDrawView()->IsDesignMode() );
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
,
177 pImp( new SwViewImp( this ) ),
179 pOut( pOutput
? pOutput
180 : pWindow
? (OutputDevice
*)pWindow
181 : (OutputDevice
*)rDocument
.getPrinter( true )),
184 pAccOptions( new SwAccessibilityOptions
),
185 mpTargetPaintWindow(0), // #i74769#
186 mpBufferedOut(0), // #i74769#
190 mnPrePostPaintCount(0L), // #i72754#
191 mpPrePostOutDev(0), // #i72754#
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() );
211 Init( pNewOpt
); //verstellt ggf. das Outdev (InitPrt())
214 // OD 28.03.2003 #108470# - initialize print preview layout after layout
215 // is created in <ViewShell::Init(..)> - called above.
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
)
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
) :
256 aBrowseBorder( rShell
.aBrowseBorder
),
258 pImp( new SwViewImp( this ) ),
260 pOut( pOutput
? pOutput
261 : pWindow
? (OutputDevice
*)pWindow
262 : (OutputDevice
*)rShell
.GetDoc()->getPrinter( true )),
265 pAccOptions( new SwAccessibilityOptions
),
266 mpTargetPaintWindow(0), // #i74769#
267 mpBufferedOut(0), // #i74769#
268 pDoc( rShell
.GetDoc() ),
271 mnPrePostPaintCount(0L), // #i72754#
272 mpPrePostOutDev(0), // #i72754#
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#
287 pImp
->InitPagePreviewLayout();
289 SET_CURR_SHELL( this );
292 BOOL bModified
= pDoc
->IsModified();
295 Init( rShell
.GetViewOptions() ); //verstellt ggf. das Outdev (InitPrt())
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 );
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();
340 SwNodeIndex
aIdx( *rNds
.GetEndOfAutotext().StartOfSectionNode(), 1 );
341 while ( 0 != (pStNd
= aIdx
.GetNode().GetStartNode()) )
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.
368 if( !pDoc
->release() )
369 delete pDoc
, pDoc
= 0;
371 pDoc
->GetRootFrm()->ResetNewLayout();
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." );
387 GetLayout()->DeRegisterShell( this );
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();