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