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 <com/sun/star/uno/Sequence.hxx>
21 : #include <com/sun/star/uno/Any.hxx>
22 : #include <com/sun/star/view/XRenderable.hpp>
23 :
24 : #include <hintids.hxx>
25 : #include <rtl/ustring.hxx>
26 : #include <sfx2/app.hxx>
27 : #include <sfx2/objsh.hxx>
28 : #include <sfx2/prnmon.hxx>
29 : #include <svl/languageoptions.hxx>
30 : #include <editeng/paperinf.hxx>
31 : #include <editeng/pbinitem.hxx>
32 : #include <svx/svdview.hxx>
33 : #include <toolkit/awt/vclxdevice.hxx>
34 : #include <unotools/localedatawrapper.hxx>
35 : #include <unotools/moduleoptions.hxx>
36 : #include <unotools/syslocale.hxx>
37 : #include <vcl/oldprintadaptor.hxx>
38 :
39 : #include <unotxdoc.hxx>
40 : #include <docsh.hxx>
41 : #include <txtfld.hxx>
42 : #include <fmtfld.hxx>
43 : #include <fmtfsize.hxx>
44 : #include <frmatr.hxx>
45 : #include <rootfrm.hxx>
46 : #include <pagefrm.hxx>
47 : #include <cntfrm.hxx>
48 : #include <doc.hxx>
49 : #include <IDocumentUndoRedo.hxx>
50 : #include <wdocsh.hxx>
51 : #include <fesh.hxx>
52 : #include <pam.hxx>
53 : #include <viewimp.hxx> // Imp->SetFirstVisPageInvalid()
54 : #include <layact.hxx>
55 : #include <ndtxt.hxx>
56 : #include <fldbas.hxx>
57 : #include <docfld.hxx> // _SetGetExpFld
58 : #include <docufld.hxx> // PostItFld /-Type
59 : #include <shellres.hxx>
60 : #include <viewopt.hxx>
61 : #include <printdata.hxx> // SwPrintData
62 : #include <pagedesc.hxx>
63 : #include <poolfmt.hxx> // fuer RES_POOLPAGE_JAKET
64 : #include <mdiexp.hxx> // Ansteuern der Statusleiste
65 : #include <statstr.hrc> // -- " --
66 : #include <ptqueue.hxx>
67 : #include <tabfrm.hxx>
68 : #include <txtfrm.hxx> // MinPrtLine
69 : #include <viscrs.hxx> // SwShellCrsr
70 : #include <fmtpdsc.hxx> // SwFmtPageDesc
71 : #include <globals.hrc>
72 :
73 :
74 : using namespace ::com::sun::star;
75 :
76 : //--------------------------------------------------------------------
77 : //Klasse zum Puffern von Paints
78 : class SwQueuedPaint
79 : {
80 : public:
81 : SwQueuedPaint *pNext;
82 : ViewShell *pSh;
83 : SwRect aRect;
84 :
85 0 : SwQueuedPaint( ViewShell *pNew, const SwRect &rRect ) :
86 : pNext( 0 ),
87 : pSh( pNew ),
88 0 : aRect( rRect )
89 0 : {}
90 : };
91 :
92 : SwQueuedPaint *SwPaintQueue::pQueue = 0;
93 :
94 : // saves some settings from the draw view
95 : class SwDrawViewSave
96 : {
97 : String sLayerNm;
98 : SdrView* pDV;
99 : sal_Bool bPrintControls;
100 : public:
101 : SwDrawViewSave( SdrView* pSdrView );
102 : ~SwDrawViewSave();
103 : };
104 :
105 :
106 0 : void SwPaintQueue::Add( ViewShell *pNew, const SwRect &rNew )
107 : {
108 : SwQueuedPaint *pPt;
109 0 : if ( 0 != (pPt = pQueue) )
110 : {
111 0 : while ( pPt->pSh != pNew && pPt->pNext )
112 0 : pPt = pPt->pNext;
113 0 : if ( pPt->pSh == pNew )
114 : {
115 0 : pPt->aRect.Union( rNew );
116 0 : return;
117 : }
118 : }
119 0 : SwQueuedPaint *pNQ = new SwQueuedPaint( pNew, rNew );
120 0 : if ( pPt )
121 0 : pPt->pNext = pNQ;
122 : else
123 0 : pQueue = pNQ;
124 : }
125 :
126 :
127 :
128 0 : void SwPaintQueue::Repaint()
129 : {
130 0 : if ( !SwRootFrm::IsInPaint() && pQueue )
131 : {
132 0 : SwQueuedPaint *pPt = pQueue;
133 0 : do
134 0 : { ViewShell *pSh = pPt->pSh;
135 0 : SET_CURR_SHELL( pSh );
136 0 : if ( pSh->IsPreView() )
137 : {
138 0 : if ( pSh->GetWin() )
139 : {
140 : //Fuer PreView aussenherum, weil im PaintHdl (UI) die
141 : //Zeilen/Spalten bekannt sind.
142 0 : pSh->GetWin()->Invalidate();
143 0 : pSh->GetWin()->Update();
144 : }
145 : }
146 : else
147 0 : pSh->Paint( pPt->aRect.SVRect() );
148 0 : pPt = pPt->pNext;
149 : } while ( pPt );
150 :
151 0 : do
152 0 : { pPt = pQueue;
153 0 : pQueue = pQueue->pNext;
154 0 : delete pPt;
155 : } while ( pQueue );
156 : }
157 0 : }
158 :
159 :
160 :
161 65 : void SwPaintQueue::Remove( ViewShell *pSh )
162 : {
163 : SwQueuedPaint *pPt;
164 65 : if ( 0 != (pPt = pQueue) )
165 : {
166 0 : SwQueuedPaint *pPrev = 0;
167 0 : while ( pPt && pPt->pSh != pSh )
168 : {
169 0 : pPrev = pPt;
170 0 : pPt = pPt->pNext;
171 : }
172 0 : if ( pPt )
173 : {
174 0 : if ( pPrev )
175 0 : pPrev->pNext = pPt->pNext;
176 0 : else if ( pPt == pQueue )
177 0 : pQueue = 0;
178 0 : delete pPt;
179 : }
180 : }
181 65 : }
182 :
183 : /******************************************************************************
184 : * Methode : void SetSwVisArea( ViewShell *pSh, Point aPrtOffset, ...
185 : * Beschreibung:
186 : * Erstellt : OK 04.11.94 16:27
187 : * Aenderung :
188 : ******************************************************************************/
189 :
190 0 : void SetSwVisArea( ViewShell *pSh, const SwRect &rRect, sal_Bool /*bPDFExport*/ )
191 : {
192 : OSL_ENSURE( !pSh->GetWin(), "Drucken mit Window?" );
193 0 : pSh->aVisArea = rRect;
194 0 : pSh->Imp()->SetFirstVisPageInvalid();
195 0 : Point aPt( rRect.Pos() );
196 :
197 : // calculate an offset for the rectangle of the n-th page to
198 : // move the start point of the output operation to a position
199 : // such that in the output device all pages will be painted
200 : // at the same position
201 0 : aPt.X() = -aPt.X(); aPt.Y() = -aPt.Y();
202 :
203 0 : OutputDevice *pOut = pSh->GetOut();
204 :
205 0 : MapMode aMapMode( pOut->GetMapMode() );
206 0 : aMapMode.SetOrigin( aPt );
207 0 : pOut->SetMapMode( aMapMode );
208 0 : }
209 :
210 : /******************************************************************************/
211 :
212 0 : void ViewShell::InitPrt( OutputDevice *pOutDev )
213 : {
214 : //Fuer den Printer merken wir uns einen negativen Offset, der
215 : //genau dem Offset de OutputSize entspricht. Das ist notwendig,
216 : //weil unser Ursprung der linken ober Ecke der physikalischen
217 : //Seite ist, die Ausgaben (SV) aber den Outputoffset als Urstprung
218 : //betrachten.
219 0 : if ( pOutDev )
220 : {
221 0 : aPrtOffst = Point();
222 :
223 0 : aPrtOffst += pOutDev->GetMapMode().GetOrigin();
224 0 : MapMode aMapMode( pOutDev->GetMapMode() );
225 0 : aMapMode.SetMapUnit( MAP_TWIP );
226 0 : pOutDev->SetMapMode( aMapMode );
227 0 : pOutDev->SetLineColor();
228 0 : pOutDev->SetFillColor();
229 : }
230 : else
231 0 : aPrtOffst.X() = aPrtOffst.Y() = 0;
232 :
233 0 : if ( !pWin )
234 0 : pOut = pOutDev; //Oder was sonst?
235 0 : }
236 :
237 : /******************************************************************************
238 : * Methode : void ViewShell::ChgAllPageOrientation
239 : * Erstellt : MA 08. Aug. 95
240 : * Aenderung :
241 : ******************************************************************************/
242 :
243 :
244 0 : void ViewShell::ChgAllPageOrientation( sal_uInt16 eOri )
245 : {
246 : OSL_ENSURE( nStartAction, "missing an Action" );
247 0 : SET_CURR_SHELL( this );
248 :
249 0 : sal_uInt16 nAll = GetDoc()->GetPageDescCnt();
250 0 : sal_Bool bNewOri = Orientation(eOri) == ORIENTATION_PORTRAIT ? sal_False : sal_True;
251 :
252 0 : for( sal_uInt16 i = 0; i < nAll; ++ i )
253 : {
254 0 : const SwPageDesc& rOld = GetDoc()->GetPageDesc( i );
255 :
256 0 : if( rOld.GetLandscape() != bNewOri )
257 : {
258 0 : SwPageDesc aNew( rOld );
259 : {
260 0 : ::sw::UndoGuard const ug(GetDoc()->GetIDocumentUndoRedo());
261 0 : GetDoc()->CopyPageDesc(rOld, aNew);
262 : }
263 0 : aNew.SetLandscape( bNewOri );
264 0 : SwFrmFmt& rFmt = aNew.GetMaster();
265 0 : SwFmtFrmSize aSz( rFmt.GetFrmSize() );
266 : // Groesse anpassen.
267 : // PORTRAIT -> Hoeher als Breit
268 : // LANDSCAPE -> Breiter als Hoch
269 : // Hoehe ist die VarSize, Breite ist die FixSize (per Def.)
270 0 : if( bNewOri ? aSz.GetHeight() > aSz.GetWidth()
271 0 : : aSz.GetHeight() < aSz.GetWidth() )
272 : {
273 0 : SwTwips aTmp = aSz.GetHeight();
274 0 : aSz.SetHeight( aSz.GetWidth() );
275 0 : aSz.SetWidth( aTmp );
276 0 : rFmt.SetFmtAttr( aSz );
277 : }
278 0 : GetDoc()->ChgPageDesc( i, aNew );
279 : }
280 0 : }
281 0 : }
282 :
283 : /******************************************************************************
284 : * Methode : void ViewShell::ChgAllPageOrientation
285 : * Erstellt : MA 08. Aug. 95
286 : * Aenderung :
287 : ******************************************************************************/
288 :
289 :
290 0 : void ViewShell::ChgAllPageSize( Size &rSz )
291 : {
292 : OSL_ENSURE( nStartAction, "missing an Action" );
293 0 : SET_CURR_SHELL( this );
294 :
295 0 : SwDoc* pMyDoc = GetDoc();
296 0 : sal_uInt16 nAll = pMyDoc->GetPageDescCnt();
297 :
298 0 : for( sal_uInt16 i = 0; i < nAll; ++i )
299 : {
300 0 : const SwPageDesc &rOld = pMyDoc->GetPageDesc( i );
301 0 : SwPageDesc aNew( rOld );
302 : {
303 0 : ::sw::UndoGuard const ug(GetDoc()->GetIDocumentUndoRedo());
304 0 : GetDoc()->CopyPageDesc( rOld, aNew );
305 : }
306 0 : SwFrmFmt& rPgFmt = aNew.GetMaster();
307 0 : Size aSz( rSz );
308 0 : const sal_Bool bOri = aNew.GetLandscape();
309 0 : if( bOri ? aSz.Height() > aSz.Width()
310 0 : : aSz.Height() < aSz.Width() )
311 : {
312 0 : SwTwips aTmp = aSz.Height();
313 0 : aSz.Height() = aSz.Width();
314 0 : aSz.Width() = aTmp;
315 : }
316 :
317 0 : SwFmtFrmSize aFrmSz( rPgFmt.GetFrmSize() );
318 0 : aFrmSz.SetSize( aSz );
319 0 : rPgFmt.SetFmtAttr( aFrmSz );
320 0 : pMyDoc->ChgPageDesc( i, aNew );
321 0 : }
322 0 : }
323 :
324 :
325 0 : void ViewShell::CalcPagesForPrint( sal_uInt16 nMax )
326 : {
327 0 : SET_CURR_SHELL( this );
328 :
329 0 : SwRootFrm* pMyLayout = GetLayout();
330 : // ULONG nStatMax = pLayout->GetPageNum();
331 :
332 0 : const SwFrm *pPage = pMyLayout->Lower();
333 0 : SwLayAction aAction( pMyLayout, Imp() );
334 :
335 0 : pMyLayout->StartAllAction();
336 0 : for ( sal_uInt16 i = 1; pPage && i <= nMax; pPage = pPage->GetNext(), ++i )
337 : {
338 0 : pPage->Calc();
339 0 : SwRect aOldVis( VisArea() );
340 0 : aVisArea = pPage->Frm();
341 0 : Imp()->SetFirstVisPageInvalid();
342 0 : aAction.Reset();
343 0 : aAction.SetPaint( sal_False );
344 0 : aAction.SetWaitAllowed( sal_False );
345 0 : aAction.SetReschedule( sal_True );
346 :
347 0 : aAction.Action();
348 :
349 0 : aVisArea = aOldVis; //Zuruecksetzen wg. der Paints!
350 0 : Imp()->SetFirstVisPageInvalid();
351 : // SwPaintQueue::Repaint();
352 : }
353 :
354 0 : pMyLayout->EndAllAction();
355 0 : }
356 :
357 : /******************************************************************************/
358 :
359 0 : SwDoc * ViewShell::FillPrtDoc( SwDoc *pPrtDoc, const SfxPrinter* pPrt)
360 : {
361 : OSL_ENSURE( this->IsA( TYPE(SwFEShell) ),"ViewShell::Prt for FEShell only");
362 0 : SwFEShell* pFESh = (SwFEShell*)this;
363 : // Wir bauen uns ein neues Dokument
364 : // SwDoc *pPrtDoc = new SwDoc;
365 : // pPrtDoc->acquire();
366 : // pPrtDoc->SetRefForDocShell( (SvEmbeddedObjectRef*)&(long&)rDocShellRef );
367 0 : pPrtDoc->LockExpFlds();
368 :
369 : // Der Drucker wird uebernommen
370 : //! Make a copy of it since it gets destroyed with the temporary document
371 : //! used for PDF export
372 0 : if (pPrt)
373 0 : pPrtDoc->setPrinter( new SfxPrinter(*pPrt), true, true );
374 :
375 : const SfxPoolItem* pCpyItem;
376 0 : const SfxItemPool& rPool = GetAttrPool();
377 0 : for( sal_uInt16 nWh = POOLATTR_BEGIN; nWh < POOLATTR_END; ++nWh )
378 0 : if( 0 != ( pCpyItem = rPool.GetPoolDefaultItem( nWh ) ) )
379 0 : pPrtDoc->GetAttrPool().SetPoolDefaultItem( *pCpyItem );
380 :
381 : // JP 29.07.99 - Bug 67951 - set all Styles from the SourceDoc into
382 : // the PrintDoc - will be replaced!
383 0 : pPrtDoc->ReplaceStyles( *GetDoc() );
384 :
385 0 : SwShellCrsr *pActCrsr = pFESh->_GetCrsr();
386 0 : SwShellCrsr *pFirstCrsr = dynamic_cast<SwShellCrsr*>(pActCrsr->GetNext());
387 0 : if( !pActCrsr->HasMark() ) // bei Multiselektion kann der aktuelle Cursor leer sein
388 : {
389 0 : pActCrsr = dynamic_cast<SwShellCrsr*>(pActCrsr->GetPrev());
390 : }
391 :
392 : // Die Y-Position der ersten Selektion
393 0 : Point aSelPoint;
394 0 : if( pFESh->IsTableMode() )
395 : {
396 0 : SwShellTableCrsr* pShellTblCrsr = pFESh->GetTableCrsr();
397 :
398 0 : const SwCntntNode* pCntntNode = pShellTblCrsr->GetNode()->GetCntntNode();
399 0 : const SwCntntFrm *pCntntFrm = pCntntNode ? pCntntNode->getLayoutFrm( GetLayout(), 0, pShellTblCrsr->Start() ) : 0;
400 0 : if( pCntntFrm )
401 : {
402 0 : SwRect aCharRect;
403 0 : SwCrsrMoveState aTmpState( MV_NONE );
404 0 : pCntntFrm->GetCharRect( aCharRect, *pShellTblCrsr->Start(), &aTmpState );
405 0 : aSelPoint = Point( aCharRect.Left(), aCharRect.Top() );
406 : }
407 : }
408 : else
409 : {
410 0 : aSelPoint = pFirstCrsr->GetSttPos();
411 : }
412 :
413 0 : const SwPageFrm* pPage = GetLayout()->GetPageAtPos( aSelPoint );
414 : OSL_ENSURE( pPage, "no page found!" );
415 :
416 : // get page descriptor - fall back to the first one if pPage could not be found
417 : const SwPageDesc* pPageDesc = pPage ? pPrtDoc->FindPageDescByName(
418 0 : pPage->GetPageDesc()->GetName() ) : &pPrtDoc->GetPageDesc( (sal_uInt16)0 );
419 :
420 0 : if( !pFESh->IsTableMode() && pActCrsr->HasMark() )
421 : { // Am letzten Absatz die Absatzattribute richten:
422 0 : SwNodeIndex aNodeIdx( *pPrtDoc->GetNodes().GetEndOfContent().StartOfSectionNode() );
423 0 : SwTxtNode* pTxtNd = pPrtDoc->GetNodes().GoNext( &aNodeIdx )->GetTxtNode();
424 : SwCntntNode *pLastNd =
425 0 : pActCrsr->GetCntntNode( (*pActCrsr->GetMark()) <= (*pActCrsr->GetPoint()) );
426 : // Hier werden die Absatzattribute des ersten Absatzes uebertragen
427 0 : if( pLastNd && pLastNd->IsTxtNode() )
428 0 : ((SwTxtNode*)pLastNd)->CopyCollFmt( *pTxtNd );
429 : }
430 :
431 : // es wurde in der CORE eine neu angelegt (OLE-Objekte kopiert!)
432 : // if( aDocShellRef.Is() )
433 : // SwDataExchange::InitOle( aDocShellRef, pPrtDoc );
434 : // und fuellen es mit dem selektierten Bereich
435 0 : pFESh->Copy( pPrtDoc );
436 :
437 : //Jetzt noch am ersten Absatz die Seitenvorlage setzen
438 : {
439 0 : SwNodeIndex aNodeIdx( *pPrtDoc->GetNodes().GetEndOfContent().StartOfSectionNode() );
440 0 : SwCntntNode* pCNd = pPrtDoc->GetNodes().GoNext( &aNodeIdx ); // gehe zum 1. ContentNode
441 0 : if( pFESh->IsTableMode() )
442 : {
443 0 : SwTableNode* pTNd = pCNd->FindTableNode();
444 0 : if( pTNd )
445 0 : pTNd->GetTable().GetFrmFmt()->SetFmtAttr( SwFmtPageDesc( pPageDesc ) );
446 : }
447 : else
448 : {
449 0 : pCNd->SetAttr( SwFmtPageDesc( pPageDesc ) );
450 0 : if( pFirstCrsr->HasMark() )
451 : {
452 0 : SwTxtNode *pTxtNd = pCNd->GetTxtNode();
453 0 : if( pTxtNd )
454 : {
455 : SwCntntNode *pFirstNd =
456 0 : pFirstCrsr->GetCntntNode( (*pFirstCrsr->GetMark()) > (*pFirstCrsr->GetPoint()) );
457 : // Hier werden die Absatzattribute des ersten Absatzes uebertragen
458 0 : if( pFirstNd && pFirstNd->IsTxtNode() )
459 0 : ((SwTxtNode*)pFirstNd)->CopyCollFmt( *pTxtNd );
460 : }
461 : }
462 0 : }
463 : }
464 0 : return pPrtDoc;
465 : }
466 :
467 : // TODO: there is already a GetPageByPageNum, but it checks some physical page
468 : // number; unsure if we want that here, should find out what that is...
469 : SwPageFrm const*
470 0 : sw_getPage(SwRootFrm const& rLayout, sal_Int32 const nPage)
471 : {
472 : // yes this is O(n^2) but at least it does not crash...
473 0 : SwPageFrm const* pPage = dynamic_cast<const SwPageFrm*>(rLayout.Lower());
474 0 : for (sal_Int32 i = nPage; pPage && (i > 0); --i)
475 : {
476 0 : if (1 == i) { // note: nPage is 1-based, i.e. 0 is invalid!
477 0 : return pPage;
478 : }
479 0 : pPage = dynamic_cast<SwPageFrm const*>(pPage->GetNext());
480 : }
481 : OSL_ENSURE(pPage, "ERROR: SwPageFrm expected");
482 : OSL_FAIL("non-existent page requested");
483 0 : return 0;
484 : }
485 :
486 0 : sal_Bool ViewShell::PrintOrPDFExport(
487 : OutputDevice *pOutDev,
488 : SwPrintData const& rPrintData,
489 : sal_Int32 nRenderer /* the index in the vector of pages to be printed */ )
490 : {
491 : //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
492 : //Immer die Druckroutinen in viewpg.cxx (PrintProspect) mitpflegen!!
493 : //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
494 :
495 0 : const sal_Int32 nMaxRenderer = rPrintData.GetRenderData().GetPagesToPrint().size() - 1;
496 : OSL_ENSURE( 0 <= nRenderer && nRenderer <= nMaxRenderer, "nRenderer out of bounds");
497 0 : if (!pOutDev || nMaxRenderer < 0 || nRenderer < 0 || nRenderer > nMaxRenderer)
498 0 : return sal_False;
499 :
500 : // save settings of OutputDevice (should be done always since the
501 : // output device is now provided by a call from outside the Writer)
502 0 : pOutDev->Push();
503 :
504 : // Print/PDF export for (multi-)selection has already generated a
505 : // temporary document with the selected text.
506 : // (see XRenderable implementation in unotxdoc.cxx)
507 : // It is implemented this way because PDF export calls this Prt function
508 : // once per page and we do not like to always have the temporary document
509 : // to be created that often here.
510 0 : ViewShell *pShell = new ViewShell( *this, 0, pOutDev );
511 :
512 0 : SdrView *pDrawView = pShell->GetDrawView();
513 0 : if (pDrawView)
514 : {
515 0 : pDrawView->SetBufferedOutputAllowed( false );
516 0 : pDrawView->SetBufferedOverlayAllowed( false );
517 : }
518 :
519 : { //Zusaetzlicher Scope, damit die CurrShell vor dem zerstoeren der
520 : //Shell zurueckgesetzt wird.
521 :
522 0 : SET_CURR_SHELL( pShell );
523 :
524 : //JP 01.02.99: das ReadOnly Flag wird NIE mitkopiert; Bug 61335
525 0 : if( pOpt->IsReadonly() )
526 0 : pShell->pOpt->SetReadonly( sal_True );
527 :
528 : // save options at draw view:
529 0 : SwDrawViewSave aDrawViewSave( pShell->GetDrawView() );
530 :
531 0 : pShell->PrepareForPrint( rPrintData );
532 :
533 0 : const sal_Int32 nPage = rPrintData.GetRenderData().GetPagesToPrint()[ nRenderer ];
534 : OSL_ENSURE( nPage < 0 ||
535 : rPrintData.GetRenderData().GetValidPagesSet().count( nPage ) == 1,
536 : "ViewShell::PrintOrPDFExport: nPage not valid" );
537 : ViewShell *const pViewSh2 = (nPage < 0)
538 0 : ? rPrintData.GetRenderData().m_pPostItShell.get()// post-it page
539 0 : : pShell; // a 'regular' page, not one from the post-it doc
540 :
541 : SwPageFrm const*const pStPage =
542 0 : sw_getPage(*pViewSh2->GetLayout(), abs(nPage));
543 : OSL_ENSURE( pStPage, "failed to get start page" );
544 0 : if (!pStPage)
545 : {
546 0 : return sal_False;
547 : }
548 :
549 : //!! applying view options and formatting the document should now only be done in getRendererCount!
550 :
551 0 : ::SetSwVisArea( pViewSh2, pStPage->Frm() );
552 :
553 : // FIXME disabled because rPrintData.aOffset is always (0,0)
554 : #if 0
555 : // wenn wir einen Umschlag drucken wird ein Offset beachtet
556 : if( pStPage->GetFmt()->GetPoolFmtId() == RES_POOLPAGE_JAKET )
557 : {
558 : Point aNewOrigin = pOutDev->GetMapMode().GetOrigin();
559 : aNewOrigin += rPrintData.aOffset;
560 : MapMode aTmp( pOutDev->GetMapMode() );
561 : aTmp.SetOrigin( aNewOrigin );
562 : pOutDev->SetMapMode( aTmp );
563 : }
564 : #endif
565 :
566 0 : pShell->InitPrt( pOutDev );
567 :
568 0 : ::SetSwVisArea( pViewSh2, pStPage->Frm() );
569 :
570 0 : pStPage->GetUpper()->Paint( pStPage->Frm(), &rPrintData );
571 :
572 0 : SwPaintQueue::Repaint();
573 : } //Zus. Scope wg. CurShell!
574 :
575 0 : delete pShell;
576 :
577 : // restore settings of OutputDevice (should be done always now since the
578 : // output device is now provided by a call from outside the Writer)
579 0 : pOutDev->Pop();
580 :
581 0 : return sal_True;
582 : }
583 :
584 : /******************************************************************************
585 : * Methode : PrtOle2()
586 : * Beschreibung:
587 : * Erstellt : PK 07.12.94
588 : * Aenderung : MA 16. Feb. 95
589 : ******************************************************************************/
590 :
591 :
592 :
593 2 : void ViewShell::PrtOle2( SwDoc *pDoc, const SwViewOption *pOpt, const SwPrintData& rOptions,
594 : OutputDevice* pOleOut, const Rectangle& rRect )
595 : {
596 : //Wir brauchen eine Shell fuer das Drucken. Entweder hat das Doc schon
597 : //eine, dann legen wir uns eine neue Sicht an, oder das Doc hat noch
598 : //keine, dann erzeugen wir die erste Sicht.
599 : ViewShell *pSh;
600 2 : if( pDoc->GetCurrentViewShell() )
601 2 : pSh = new ViewShell( *pDoc->GetCurrentViewShell(), 0, pOleOut,VSHELLFLAG_SHARELAYOUT );//swmod 080129
602 : else //swmod 071108//swmod 071225
603 0 : pSh = new ViewShell( *pDoc, 0, pOpt, pOleOut);//swmod 080129
604 :
605 : {
606 2 : SET_CURR_SHELL( pSh );
607 2 : pSh->PrepareForPrint( rOptions );
608 2 : pSh->SetPrtFormatOption( sal_True );
609 :
610 2 : SwRect aSwRect( rRect );
611 2 : pSh->aVisArea = aSwRect;
612 :
613 2 : if ( pSh->GetViewOptions()->getBrowseMode() &&
614 0 : pSh->GetNext() == pSh )
615 : {
616 0 : pSh->CheckBrowseView( sal_False );
617 0 : pSh->GetLayout()->Lower()->InvalidateSize();
618 : }
619 :
620 : // CalcPagesForPrint() should not be necessary here. The pages in the
621 : // visible area will be formatted in SwRootFrm::Paint().
622 : // Removing this gives us a performance gain during saving the
623 : // document because the thumbnail creation will not trigger a complete
624 : // formatting of the document.
625 : // Seiten fuers Drucken formatieren
626 : // pSh->CalcPagesForPrint( SHRT_MAX );
627 : //#39275# jetzt will der Meyer doch ein Clipping
628 2 : pOleOut->Push( PUSH_CLIPREGION );
629 2 : pOleOut->IntersectClipRegion( aSwRect.SVRect() );
630 2 : pSh->GetLayout()->Paint( aSwRect );
631 : // SFX_APP()->SpoilDemoOutput( *pOleOut, rRect );
632 :
633 2 : pOleOut->Pop();
634 : // erst muss das CurrShell Object zerstoert werden!!
635 : }
636 2 : delete pSh;
637 2 : }
638 :
639 : /******************************************************************************
640 : * Methode : IsAnyFieldInDoc()
641 : * Beschreibung: Stellt fest, ob im DocNodesArray Felder verankert sind
642 : * Erstellt : JP 27.07.95
643 : * Aenderung : JP 10.12.97
644 : ******************************************************************************/
645 :
646 :
647 :
648 0 : sal_Bool ViewShell::IsAnyFieldInDoc() const
649 : {
650 : const SfxPoolItem* pItem;
651 0 : sal_uInt32 nMaxItems = pDoc->GetAttrPool().GetItemCount2( RES_TXTATR_FIELD );
652 0 : for( sal_uInt32 n = 0; n < nMaxItems; ++n )
653 0 : if( 0 != (pItem = pDoc->GetAttrPool().GetItem2( RES_TXTATR_FIELD, n )))
654 : {
655 0 : const SwFmtFld* pFmtFld = (SwFmtFld*)pItem;
656 0 : const SwTxtFld* pTxtFld = pFmtFld->GetTxtFld();
657 : //#i101026# mod: do not include postits in field check
658 0 : const SwField* pFld = pFmtFld->GetFld();
659 0 : if( pTxtFld && pTxtFld->GetTxtNode().GetNodes().IsDocNodes() && (pFld->Which() != RES_POSTITFLD))
660 0 : return sal_True;
661 : }
662 0 : return sal_False;
663 : }
664 :
665 :
666 :
667 : /******************************************************************************
668 : * SwDrawViewSave
669 : *
670 : * Saves some settings at the draw view
671 : ******************************************************************************/
672 :
673 0 : SwDrawViewSave::SwDrawViewSave( SdrView* pSdrView )
674 0 : : pDV( pSdrView )
675 : {
676 0 : if ( pDV )
677 : {
678 0 : sLayerNm.AssignAscii( RTL_CONSTASCII_STRINGPARAM("Controls" ) );
679 0 : bPrintControls = pDV->IsLayerPrintable( sLayerNm );
680 : }
681 0 : }
682 :
683 0 : SwDrawViewSave::~SwDrawViewSave()
684 : {
685 0 : if ( pDV )
686 : {
687 0 : pDV->SetLayerPrintable( sLayerNm, bPrintControls );
688 : }
689 0 : }
690 :
691 :
692 : // OD 09.01.2003 #i6467# - method also called for page preview
693 2 : void ViewShell::PrepareForPrint( const SwPrintData &rOptions )
694 : {
695 2 : pOpt->SetGraphic ( sal_True == rOptions.bPrintGraphic );
696 2 : pOpt->SetTable ( sal_True == rOptions.bPrintTable );
697 2 : pOpt->SetDraw ( sal_True == rOptions.bPrintDraw );
698 2 : pOpt->SetControl ( sal_True == rOptions.bPrintControl );
699 2 : pOpt->SetPageBack( sal_True == rOptions.bPrintPageBackground );
700 2 : pOpt->SetBlackFont( sal_True == rOptions.bPrintBlackFont );
701 :
702 2 : if ( HasDrawView() )
703 : {
704 2 : SdrView *pDrawView = GetDrawView();
705 2 : String sLayerNm;
706 2 : sLayerNm.AssignAscii(RTL_CONSTASCII_STRINGPARAM("Controls" ));
707 : // OD 09.01.2003 #i6467# - consider, if view shell belongs to page preview
708 2 : if ( !IsPreView() )
709 : {
710 2 : pDrawView->SetLayerPrintable( sLayerNm, rOptions.bPrintControl );
711 : }
712 : else
713 : {
714 0 : pDrawView->SetLayerVisible( sLayerNm, rOptions.bPrintControl );
715 2 : }
716 : }
717 2 : }
718 :
719 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|