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