update dev300-m58
[ooovba.git] / sd / source / ui / view / PrintManager.cxx
bloba0ec7e1c2d810be9d6ccf1ae1ebc2615a7345eeb
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: PrintManager.cxx,v $
10 * $Revision: 1.24.8.1 $
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_sd.hxx"
34 #include <basegfx/polygon/b2dpolygon.hxx>
35 #include <basegfx/polygon/b2dpolypolygon.hxx>
36 #include <basegfx/matrix/b2dhommatrix.hxx>
38 #include "PrintManager.hxx"
40 #include <svx/editstat.hxx>
41 #include "optsitem.hxx"
42 #include "sdattr.hxx"
43 #include "sdpage.hxx"
44 #include "drawdoc.hxx"
45 #include "drawview.hxx"
46 #include "ViewShellBase.hxx"
47 #include "DrawViewShell.hxx"
48 #include "OutlineViewShell.hxx"
49 #include "Outliner.hxx"
50 #include "Window.hxx"
51 #include "FrameView.hxx"
52 #include <sfx2/progress.hxx>
53 #include <svtools/printdlg.hxx>
54 #include <tools/multisel.hxx>
55 #include <svtools/misccfg.hxx>
56 #include <unotools/localedatawrapper.hxx>
57 #include <svx/prtqry.hxx>
58 #include "WindowUpdater.hxx"
59 #include <sfx2/printer.hxx>
60 #include <svx/svdoutl.hxx>
61 #include "sdresid.hxx"
62 #include <svx/svdetc.hxx>
63 #include <svx/svdopage.hxx>
64 #include <svx/svdpagv.hxx>
65 #include <svx/svditer.hxx>
67 #include "strings.hrc"
69 #include <svx/svdopath.hxx>
70 #include "sdabstdlg.hxx"
71 #include "printdlg.hrc"
72 #include "prntopts.hrc"
73 #include "app.hrc"
74 #include <svtools/intitem.hxx>
75 #include <svx/paperinf.hxx>
76 #include <svx/xlnclit.hxx>
77 #include "printdialog.hxx"
79 namespace sd {
81 /** This simple container reduces the number of arguments that have to be
82 passed around and makes it easier to modify the set of arguments.
84 class PrintManager::PrintInfo
86 public:
87 PrintInfo (
88 ViewShell& rViewShell,
89 SfxPrinter& rPrinter,
90 SfxProgress& rProgress,
91 const MultiSelection& rSelPages,
92 const String& rTimeDateStr,
93 const Font& rTimeDateFont,
94 const SdOptionsPrintItem* pPrintOpts,
95 USHORT nPageMax,
96 USHORT nCopies,
97 USHORT nProgressOffset,
98 USHORT nTotal)
99 : mrViewShell(rViewShell),
100 mrPrinter(rPrinter),
101 mrProgress(rProgress),
102 mrSelPages(rSelPages),
103 mrTimeDateStr(rTimeDateStr),
104 mrTimeDateFont(rTimeDateFont),
105 mpPrintOpts(pPrintOpts),
106 mnPageMax(nPageMax),
107 mnCopies(nCopies),
108 mnProgressOffset(nProgressOffset),
109 mnTotal(nTotal)
112 ViewShell& mrViewShell;
113 SfxPrinter& mrPrinter;
114 SfxProgress& mrProgress;
115 const MultiSelection& mrSelPages;
116 const String& mrTimeDateStr;
117 const Font& mrTimeDateFont;
118 const SdOptionsPrintItem* mpPrintOpts;
119 USHORT mnPageMax;
120 USHORT mnCopies;
121 USHORT mnProgressOffset;
122 USHORT mnTotal;
126 PrintManager::PrintManager (ViewShellBase& rBase)
127 : mrBase (rBase)
134 PrintManager::~PrintManager (void)
141 SfxPrinter* PrintManager::GetPrinter (BOOL bCreate)
143 return mrBase.GetDocShell()->GetPrinter (bCreate);
149 USHORT PrintManager::SetPrinter (
150 SfxPrinter* pNewPrinter,
151 USHORT nDiffFlags,bool bIsAPI)
153 return SetPrinterOptDlg (pNewPrinter,nDiffFlags,!bIsAPI);
159 USHORT PrintManager::SetPrinterOptDlg (
160 SfxPrinter* pNewPrinter,
161 USHORT nDiffFlags,
162 BOOL _bShowDialog)
164 mrBase.GetDocShell()->SetPrinter(pNewPrinter);
166 if ( (nDiffFlags & SFX_PRINTER_CHG_ORIENTATION ||
167 nDiffFlags & SFX_PRINTER_CHG_SIZE) && pNewPrinter )
169 MapMode aMap = pNewPrinter->GetMapMode();
170 aMap.SetMapUnit(MAP_100TH_MM);
171 MapMode aOldMap = pNewPrinter->GetMapMode();
172 pNewPrinter->SetMapMode(aMap);
173 Size aNewSize = pNewPrinter->GetOutputSize();
175 BOOL bScaleAll = FALSE;
176 if ( _bShowDialog )
178 WarningBox aWarnBox (
179 mrBase.GetWindow(),
180 (WinBits)(WB_YES_NO | WB_DEF_YES),
181 String(SdResId(STR_SCALE_OBJS_TO_PAGE)));
182 bScaleAll = (aWarnBox.Execute() == RET_YES);
185 ViewShell* pShell = mrBase.GetMainViewShell().get();
186 if (pShell != NULL && pShell->ISA(DrawViewShell))
188 SdPage* pPage = mrBase.GetDocument()->GetSdPage(
189 0, PK_STANDARD );
190 pShell->SetPageSizeAndBorder (
191 static_cast<DrawViewShell*>(pShell)->GetPageKind(),
192 aNewSize,
193 -1,-1,-1,-1,
194 bScaleAll,
195 pNewPrinter->GetOrientation(),
196 pPage->GetPaperBin(),
197 pPage->IsBackgroundFullSize());
200 pNewPrinter->SetMapMode(aOldMap);
203 return 0;
209 PrintDialog* PrintManager::CreatePrintDialog (::Window *pParent)
211 const bool bImpress = mrBase.GetDocument()->GetDocumentType() == DOCUMENT_TYPE_IMPRESS;
213 SdPrintDialog* pDlg = SdPrintDialog::Create(pParent,bImpress);
215 ViewShell* pShell = mrBase.GetMainViewShell().get();
216 if (pShell!=NULL && ! pShell->ISA(OutlineViewShell))
219 if (pShell->ISA(DrawViewShell))
221 pDlg->SetRangeText(UniString::CreateFromInt32(
222 static_cast<DrawViewShell*>(pShell)->GetCurPageId()));
224 /* else if(pShell->ISA(::sd::slidesorter::SlideSorterViewShell))
226 String aStrRange(
227 dynamic_cast<sd::slidesorter::SlideSorterViewShell*>(pShell)->GetPageRangeString());
228 if( aStrRange.Len() )
230 pDlg->SetRangeText( aStrRange );
231 // According #79749 always check PRINTDIALOG_ALL
232 // pDlg->CheckRange( PRINTDIALOG_RANGE );
237 else
239 String aStrRange(
240 static_cast<OutlineViewShell*>(pShell)->GetPageRangeString());
241 if( aStrRange.Len() )
243 pDlg->SetRangeText( aStrRange );
244 // According #79749 always check PRINTDIALOG_ALL
245 // pDlg->CheckRange( PRINTDIALOG_RANGE );
248 pDlg->EnableRange( PRINTDIALOG_RANGE );
249 pDlg->EnableRange( PRINTDIALOG_ALL );
250 pDlg->EnableCollate();
252 if (pShell->ISA(DrawViewShell) && pShell->GetView()->AreObjectsMarked())
254 pDlg->EnableRange( PRINTDIALOG_SELECTION );
255 // According #79749 always check PRINTDIALOG_ALL
256 // pDlg->CheckRange( PRINTDIALOG_SELECTION );
259 if( bImpress )
261 const SdOptionsPrintItem* pPrintOpts = 0;
263 SfxPrinter* pPrinter = mrBase.GetPrinter(FALSE);
264 if( pPrinter )
266 const SfxPoolItem* pPoolItem = 0;
267 if(pPrinter->GetOptions().GetItemState(ATTR_OPTIONS_PRINT, FALSE, &pPoolItem ) == SFX_ITEM_SET )
268 pPrintOpts = dynamic_cast< const SdOptionsPrintItem* >( pPoolItem );
270 pDlg->Init( pPrintOpts );
273 return pDlg;
276 SfxTabPage* PrintManager::CreatePrintOptionsPage( ::Window *pParent, const SfxItemSet &rOptions)
278 SfxTabPage* pPage = 0;
279 DocumentType eDocType = mrBase.GetDocument()->GetDocumentType();
280 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
281 ::CreateTabPage fnCreatePage = pFact ? pFact->GetSdPrintOptionsTabPageCreatorFunc() : 0;
282 if( fnCreatePage )
284 pPage = (*fnCreatePage)( pParent, rOptions );
285 if( eDocType == DOCUMENT_TYPE_DRAW )
287 SfxAllItemSet aSet(*(rOptions.GetPool()));
288 aSet.Put (SfxUInt32Item(SID_SDMODE_FLAG,SD_DRAW_MODE));
289 pPage->PageCreated(aSet);
292 return pPage;
298 USHORT PrintManager::Print (SfxProgress& rProgress, BOOL bIsAPI, PrintDialog* pDlg)
300 SfxPrinter* pPrinter = mrBase.GetPrinter(TRUE);
301 ViewShell* pShell = mrBase.GetMainViewShell().get();
303 if (pPrinter!=NULL && pShell!=NULL)
305 const PrinterOptions aOldPrinterOptions( pPrinter->GetPrinterOptions() );
306 MapMode aMap( pPrinter->GetMapMode() );
307 const MapMode aOldMap( aMap );
308 USHORT nOldPaperBin = pPrinter->GetPaperBin();
310 aMap.SetMapUnit(MAP_100TH_MM);
311 pPrinter->SetMapMode(aMap);
313 ::Outliner& rOutliner = mrBase.GetDocument()->GetDrawOutliner();
314 ULONG nOldCntrl = rOutliner.GetControlWord();
315 ULONG nCntrl = nOldCntrl;
316 nCntrl &= ~EE_CNTRL_MARKFIELDS;
317 nCntrl &= ~EE_CNTRL_ONLINESPELLING;
318 rOutliner.SetControlWord( nCntrl );
320 // old place of FitPageToPrinterWithDialog().
321 SdOptionsPrintItem* pPrintOpts = 0;
323 const SfxPoolItem* pPoolItem = 0;
324 if (pPrinter->GetOptions().GetItemState( ATTR_OPTIONS_PRINT, FALSE, &pPoolItem ) == SFX_ITEM_SET )
325 pPrintOpts = dynamic_cast< SdOptionsPrintItem* >( const_cast< SfxPoolItem* >( pPoolItem ) ) ;
327 if( dynamic_cast<SdPrintDialog*>(pDlg) && static_cast<SdPrintDialog*>(pDlg)->Fill( pPrintOpts ) )
329 SfxItemSet aNewOptions( pPrinter->GetOptions() );
330 aNewOptions.Put( *pPrintOpts );
331 pPrinter->SetOptions( aNewOptions );
332 pPrintOpts = dynamic_cast< SdOptionsPrintItem* >( const_cast< SfxPoolItem* >( pPrinter->GetOptions().GetItem( ATTR_OPTIONS_PRINT ) ) );
335 // Wenn wir im Gliederungsmodus sind, muss das Model auf Stand gebracht werden
336 if (pShell->ISA(OutlineViewShell))
337 static_cast<OutlineViewShell*>(pShell)->PrepareClose (FALSE, FALSE);
339 // Basisklasse rufen, um Basic anzusprechen
340 mrBase.SfxViewShell::Print( rProgress, bIsAPI, pDlg );
342 // Setzen des Textes des Druckmonitors
343 rProgress.SetText( String( SdResId( STR_STATSTR_PRINT ) ) );
345 PrintDialogRange eOption;
346 MultiSelection aPrintSelection;
347 String aTimeDateStr;
348 Font aTimeDateFont(FAMILY_SWISS, Size(0, 423));
349 PageKind ePageKind = PK_STANDARD;
350 USHORT nPage, nPageMax;
351 USHORT nTotal, nCopies;
352 USHORT nPrintCount = 0;
353 USHORT nProgressOffset = 0;
354 USHORT nCollateCopies = 1;
355 BOOL bPrintMarkedOnly = FALSE;
356 BOOL bPrintOutline = FALSE;
357 BOOL bPrintHandout = FALSE;
358 BOOL bPrintDraw = FALSE;
359 BOOL bPrintNotes = FALSE;
360 BOOL bHandoutHorizontal = TRUE;
361 USHORT nSlidesPerHandout = 6;
363 Orientation eOldOrientation = pPrinter->GetOrientation();
365 if( pPrintOpts )
367 SfxMiscCfg* pMisc = SFX_APP()->GetMiscConfig();
369 if( pPrintOpts->GetOptionsPrint().IsDate() )
371 aTimeDateStr += GetSdrGlobalData().GetLocaleData()->getDate( Date() );
372 aTimeDateStr += (sal_Unicode)' ';
375 if( pPrintOpts->GetOptionsPrint().IsTime() )
376 aTimeDateStr += GetSdrGlobalData().GetLocaleData()->getTime( Time(), FALSE, FALSE );
378 if( pPrintOpts->GetOptionsPrint().IsOutline() )
379 bPrintOutline = TRUE;
381 if( pPrintOpts->GetOptionsPrint().IsHandout() )
383 bPrintHandout = TRUE;
384 bHandoutHorizontal = pPrintOpts->GetOptionsPrint().IsHandoutHorizontal();
385 nSlidesPerHandout = pPrintOpts->GetOptionsPrint().GetHandoutPages();
388 if( pPrintOpts->GetOptionsPrint().IsDraw() )
389 bPrintDraw = TRUE;
391 if( pPrintOpts->GetOptionsPrint().IsNotes() )
393 bPrintNotes = TRUE;
394 ePageKind = PK_NOTES;
397 pPrintOpts->GetOptionsPrint().SetWarningPrinter( pMisc->IsNotFoundWarning() );
398 pPrintOpts->GetOptionsPrint().SetWarningSize( pMisc->IsPaperSizeWarning() );
399 pPrintOpts->GetOptionsPrint().SetWarningOrientation( pMisc->IsPaperOrientationWarning() );
401 UINT16 nQuality = pPrintOpts->GetOptionsPrint().GetOutputQuality();
402 ULONG nMode = DRAWMODE_DEFAULT;
404 if( nQuality == 1 )
405 nMode = DRAWMODE_GRAYLINE | DRAWMODE_GRAYFILL | DRAWMODE_BLACKTEXT | DRAWMODE_GRAYBITMAP | DRAWMODE_GRAYGRADIENT;
406 else if( nQuality == 2 )
407 nMode = DRAWMODE_BLACKLINE | DRAWMODE_BLACKTEXT | DRAWMODE_WHITEFILL | DRAWMODE_GRAYBITMAP | DRAWMODE_WHITEGRADIENT;
409 pPrinter->SetDrawMode( nMode );
411 else
412 bPrintDraw = TRUE;
414 if( pDlg )
416 eOption = pDlg->GetCheckedRange();
418 if( eOption == PRINTDIALOG_SELECTION )
419 bPrintMarkedOnly = TRUE;
421 else
422 // Bei PrintDirect wird gesamtes Dokument gedruckt
423 eOption = PRINTDIALOG_ALL;
425 // #72527 If we are in PrintDirect and any objects
426 // are selected, then a dialog (see ViewShell::DoPrint)
427 // ask whether the total document should be printed
428 // or only the selected objects. If only the selected
429 // object, then the flag bPrintDirectSelected is TRUE
430 if (mbPrintDirectSelected)
432 eOption = PRINTDIALOG_SELECTION;
433 bPrintMarkedOnly = TRUE;
436 nPageMax = mrBase.GetDocument()->GetSdPageCount( ePageKind );
437 aPrintSelection.SetTotalRange( Range( 1, nPageMax ) );
439 switch( eOption )
441 case PRINTDIALOG_ALL:
442 aPrintSelection.Select(Range(1, nPageMax));
443 break;
445 case PRINTDIALOG_RANGE:
446 aPrintSelection = MultiSelection(pDlg->GetRangeText());
447 break;
449 default:
451 if (pShell->ISA(DrawViewShell))
452 aPrintSelection.Select (
453 static_cast<DrawViewShell*>(pShell)->GetCurPageId());
454 else
456 if( msPageRange.Len() )
457 aPrintSelection = MultiSelection( msPageRange );
458 else
459 aPrintSelection.Select(Range(1, nPageMax));
462 break;
465 nPage = Min(nPageMax, (USHORT) aPrintSelection.FirstSelected());
467 if ( nPage > 0 )
468 nPage--;
470 nPageMax = Min(nPageMax, (USHORT) aPrintSelection.LastSelected());
472 if( bPrintOutline )
473 nPrintCount++;
475 if( bPrintHandout )
476 nPrintCount++;
478 if( bPrintDraw )
479 nPrintCount++;
481 if( bPrintNotes )
482 nPrintCount++;
484 nCopies = (pDlg ? pDlg->GetCopyCount() : 1);
486 USHORT nSelectCount = (USHORT) aPrintSelection.GetSelectCount();
487 nTotal = nSelectCount * nCopies * nPrintCount;
489 if( pDlg && pDlg->IsCollateEnabled() && pDlg->IsCollateChecked() )
490 nCollateCopies = nCopies;
492 // check if selected range of pages contains transparent objects
493 BOOL bContainsTransparency = FALSE;
494 BOOL bPrintExcluded = TRUE;
496 if( bPrintNotes || bPrintDraw || bPrintHandout )
498 if( pPrintOpts )
499 bPrintExcluded = pPrintOpts->GetOptionsPrint().IsHiddenPages();
501 for( USHORT j = nPage; ( j < nPageMax && !bContainsTransparency ); j++ )
503 if( aPrintSelection.IsSelected( j + 1 ) )
505 SdPage* pPage = mrBase.GetDocument()->GetSdPage(
506 j, PK_STANDARD );
508 if( pPage && ( !pPage->IsExcluded() || bPrintExcluded ) )
510 bContainsTransparency = (BOOL)pPage->HasTransparentObjects();
511 if( !bContainsTransparency )
513 if(pPage->TRG_HasMasterPage())
515 bContainsTransparency = (BOOL)pPage->TRG_GetMasterPage().HasTransparentObjects();
523 if (pPrinter->InitJob (mrBase.GetWindow(), !bIsAPI && bContainsTransparency))
525 PrintInfo aInfo(
526 *pShell,
527 *pPrinter,
528 rProgress,
529 aPrintSelection,
530 aTimeDateStr,
531 aTimeDateFont,
532 pPrintOpts,
533 nPageMax,
534 nCollateCopies > 1 ? 1 : nCopies,
535 nProgressOffset,
536 nTotal);
538 if( bPrintHandout )
539 InitHandoutTemplate( aInfo, nSlidesPerHandout, bHandoutHorizontal );
541 for( USHORT n = 1; n <= nCollateCopies; n++ )
543 if ( bPrintOutline )
545 // siehe unten in PrintOutline()
546 pPrinter->SetPaperBin( nOldPaperBin );
548 PrintOutline(aInfo, nPage);
549 aInfo.mnProgressOffset += (nSelectCount * ( nCollateCopies > 1 ? 1 : nCopies));
552 if ( bPrintHandout )
554 PrintHandout(aInfo, nPage );
555 aInfo.mnProgressOffset += (nSelectCount * ( nCollateCopies > 1 ? 1 : nCopies));
557 if( bPrintDraw )
559 PrintStdOrNotes(aInfo, nPage, PK_STANDARD, bPrintMarkedOnly);
560 aInfo.mnProgressOffset += (nSelectCount * ( nCollateCopies > 1 ? 1 : nCopies));
562 if( bPrintNotes )
564 PrintStdOrNotes(aInfo, nPage, PK_NOTES, FALSE);
565 aInfo.mnProgressOffset += (nSelectCount * ( nCollateCopies > 1 ? 1 : nCopies));
568 // When in duplex mode then add an empty page after printing
569 // an odd number of pages. This is to avoid the first page
570 // of the next run being printed on the backside of the
571 // current page.
572 if (nCollateCopies > 1
573 && n<nCollateCopies
574 && (pPrinter->GetCurPage()%2)==0
575 && (pPrinter->GetDuplexMode()==DUPLEX_ON))
577 pPrinter->StartPage();
578 pPrinter->EndPage();
583 pPrinter->SetOrientation( eOldOrientation );
584 pPrinter->SetPrinterOptions( aOldPrinterOptions );
585 pPrinter->SetMapMode( aOldMap );
587 rOutliner.SetControlWord(nOldCntrl);
589 // Druckerschach wieder zuruecksetzen
590 pPrinter->SetPaperBin( nOldPaperBin );
593 return 0;
600 ErrCode PrintManager::DoPrint (
601 SfxPrinter* pPrinter,
602 PrintDialog* pPrintDialog,
603 BOOL bSilent, BOOL bIsAPI )
605 ErrCode nResult = ERRCODE_NONE;
609 ViewShell* pShell = mrBase.GetMainViewShell().get();
610 if (pShell == NULL)
611 break;
613 if ( ! FitPageToPrinterWithDialog(pPrinter, bSilent))
614 break;
616 const SdrMarkList& rMarkList = pShell->GetView()->GetMarkedObjectList();
618 // Retrieve the range of marked pages.
619 String sNewPageRange (msPageRange);
621 RestrictPrintingToSelection (FALSE);
623 // #105477# Don't show query dialog if print dialog has been shown
624 if ( !pPrintDialog
625 && !bSilent && !bIsAPI
626 && (rMarkList.GetMarkCount() || sNewPageRange.Len()) )
628 SvxPrtQryBox aQuery (mrBase.GetWindow());
630 switch (aQuery.Execute())
632 case RET_CANCEL:
633 nResult = ERRCODE_IO_ABORT;
634 break;
636 case RET_OK:
637 RestrictPrintingToSelection (TRUE);
638 SetPrintingPageRange (sNewPageRange);
639 break;
643 if (nResult == ERRCODE_NONE)
645 // Tell the printer which digit language to use.
646 WindowUpdater* pWindowUpdater = pShell->GetWindowUpdater();
647 if (pWindowUpdater != NULL)
648 pWindowUpdater->Update (pPrinter, mrBase.GetDocument());
650 // Forward the call to SfxViewShell::DoPrint() which
651 // eventually calls Print() (after StartJob etc.)
652 nResult = mrBase.SfxViewShell::DoPrint (
653 pPrinter, pPrintDialog, bSilent, bIsAPI );
655 RestrictPrintingToSelection (FALSE);
658 while(false);
660 return nResult;
666 void PrintManager::PreparePrint (PrintDialog* )
668 SfxPrinter* pPrinter = GetPrinter(TRUE);
670 if (!pPrinter)
671 return;
673 const SfxItemSet& rOptions = pPrinter->GetOptions();
674 SdOptionsPrintItem* pPrintOpts = NULL;
676 if (rOptions.GetItemState( ATTR_OPTIONS_PRINT, FALSE,
677 (const SfxPoolItem**) &pPrintOpts) != SFX_ITEM_SET)
679 pPrintOpts = NULL;
682 // Einstellungen der ersten zu druckenden Seite setzen
684 if (pPrintOpts)
686 if ( pPrintOpts->GetOptionsPrint().IsHandout() )
688 // Handzettel
689 SdPage* pPage = mrBase.GetDocument()->GetSdPage(0, PK_HANDOUT);
691 // Papierschacht
692 if (!pPrintOpts->GetOptionsPrint().IsPaperbin()) // Drucken NICHT aus Druckereinstellung
694 pPrinter->SetPaperBin(pPage->GetPaperBin());
697 pPrinter->SetOrientation(pPage->TRG_GetMasterPage().GetOrientation());
699 else if ( pPrintOpts->GetOptionsPrint().IsDraw() || pPrintOpts->GetOptionsPrint().IsNotes() )
701 // Standard- oder Notizseiten
702 if( !pPrintOpts->GetOptionsPrint().IsPaperbin() ) // Drucken NICHT aus Druckereinstellung
704 PageKind ePageKind = PK_NOTES;
706 if (pPrintOpts->GetOptionsPrint().IsDraw())
708 ePageKind = PK_STANDARD;
711 SdPage* pPage = mrBase.GetDocument()->GetSdPage(0, ePageKind);
712 pPrinter->SetPaperBin(pPage->GetPaperBin());
714 Orientation eOrientation = ORIENTATION_PORTRAIT;
716 if ( !pPrintOpts->GetOptionsPrint().IsBooklet() )
718 eOrientation = pPage->GetOrientation();
720 else
722 Size aPageSize(pPage->GetSize());
724 if( aPageSize.Width() < aPageSize.Height() )
725 eOrientation = ORIENTATION_LANDSCAPE;
728 pPrinter->SetOrientation(eOrientation);
737 void PrintManager::RestrictPrintingToSelection (bool bFlag)
739 mbPrintDirectSelected = bFlag ? TRUE : FALSE;
745 void PrintManager::SetPrintingPageRange (const String& rsPageRange)
747 msPageRange = rsPageRange;
753 bool PrintManager::FitPageToPrinterWithDialog (
754 SfxPrinter* pPrinter,
755 bool bSilent)
757 bool bContinuePrinting = true;
759 if (pPrinter != NULL)
761 // Remember old printer values so that they can be restored when
762 // printing is aborted by the user.
763 const PrinterOptions aOldPrinterOptions (pPrinter->GetPrinterOptions());
764 const MapMode aOldMap (pPrinter->GetMapMode());
766 // Get values from the priner in order to decide whether to show a
767 // dialog.
768 const SfxItemSet& rOptions = pPrinter->GetOptions();
769 SdOptionsPrintItem* pPrintOpts = NULL;
770 BOOL bScalePage = TRUE;
771 BOOL bTilePage = FALSE;
772 BOOL bNotesPage = FALSE;
773 BOOL bPrintBooklet = FALSE;
775 if( rOptions.GetItemState( ATTR_OPTIONS_PRINT, FALSE, (const SfxPoolItem**) &pPrintOpts ) == SFX_ITEM_SET )
777 bScalePage = pPrintOpts->GetOptionsPrint().IsPagesize();
778 bPrintBooklet = pPrintOpts->GetOptionsPrint().IsBooklet();
779 bNotesPage = pPrintOpts->GetOptionsPrint().IsNotes();
780 pPrintOpts->GetOptionsPrint().SetCutPage( FALSE );
782 else
783 pPrintOpts = NULL;
785 SdPage* pPage = mrBase.GetDocument()->GetSdPage( 0, PK_STANDARD );
786 Size aPageSize( pPage->GetSize() );
787 Size aPrintSize( pPrinter->GetOutputSize() );
788 long nPageWidth = aPageSize.Width() - pPage->GetLftBorder() - pPage->GetRgtBorder();
789 long nPageHeight = aPageSize.Height() - pPage->GetUppBorder() - pPage->GetLwrBorder();
790 long nNotesPageWidth, nNotesPageHeight;
791 long nPrintWidth = aPrintSize.Width();
792 long nPrintHeight = aPrintSize.Height();
793 USHORT nRet = RET_OK;
795 if( bNotesPage ) {
796 SdPage* pNotesPage = mrBase.GetDocument()->GetSdPage( 0, PK_NOTES );
797 Size aNotesPageSize = Size( pNotesPage->GetSize () );
798 nNotesPageWidth = aNotesPageSize.Width() - pNotesPage->GetLftBorder() - pNotesPage->GetRgtBorder();
799 nNotesPageHeight = aNotesPageSize.Height() - pNotesPage->GetUppBorder() - pNotesPage->GetLwrBorder();
802 // When necessary then show a dialog that asks the user how to fit
803 // the pages to be printed to the (smaller) printer pages.
804 if ( !bScalePage
805 && !bTilePage
806 && !bPrintBooklet
807 && ( ( ( nPageWidth > nPrintWidth || nPageHeight > nPrintHeight )
808 && ( nPageWidth > nPrintHeight || nPageHeight > nPrintWidth )
809 ) ||
810 ( bNotesPage
811 && ( nNotesPageWidth > nPrintWidth || nNotesPageHeight > nPrintHeight )
812 && ( nNotesPageWidth > nPrintHeight || nNotesPageHeight > nPrintWidth ) )
816 if (IsScreenFormat())
818 // For the screen format the page content is always scaled
819 // to the printable area of the printer pages.
820 pPrintOpts->GetOptionsPrint().SetPagesize();
822 else
825 SdAbstractDialogFactory* pFact = SdAbstractDialogFactory::Create();
826 AbstractSdPrintDlg* pDlg = pFact ? pFact->CreateSdPrintDlg(mrBase.GetWindow() ) : 0;
827 // Do not show the dialog when the bSilent flag is set. We
828 // do create the dialog anyway so that we can extract the
829 // default method of mapping internal pages to printer pages
830 // from it.
831 if( ! bSilent && pDlg )
832 nRet = pDlg->Execute();
833 if( nRet == RET_OK )
835 switch (pDlg->GetAttr())
837 case 1:
838 pPrintOpts->GetOptionsPrint().SetPagesize();
839 break;
841 case 2:
842 // Tiling is the default behaviour in
843 // ViewShell::PrintStdOrNotes(). The poperty of
844 // pPrintOpts is ignored there so setting it
845 // here may only lead to unwanted side effects.
846 break;
848 case 3:
849 pPrintOpts->GetOptionsPrint().SetCutPage();
850 break;
852 bContinuePrinting = true;
854 delete pDlg;
858 // The user has pressed the 'Cancel' button. Restore the old values and
859 // return a flag to tell the caller to abort printing.
860 if( nRet == RET_CANCEL )
862 pPrinter->SetPrinterOptions( aOldPrinterOptions );
863 pPrinter->SetMapMode( aOldMap );
864 bContinuePrinting = false;
868 return bContinuePrinting;
874 void PrintManager::PrintOutline (
875 PrintInfo& rInfo,
876 USHORT nPage)
878 // Papierschacht
879 // Seiteneinstellungen koennen nicht fuer die Gliederung gemacht werden
880 // (also auch nicht der Druckerschacht), deswegen wird der Druckerschacht
881 // von der Seite PK_STANDARD genommen.
883 if( pPrintOpts && !pPrintOpts->GetOptionsPrint().IsPaperbin() ) // Drucken NICHT aus Druckereinstellung
885 USHORT nPaperBin = GetDoc()->GetSdPage(nPage, PK_STANDARD)->GetPaperBin();
886 rPrinter.SetPaperBin( nPaperBin );
887 } */
888 // Es wird jetzt (vorlaeufig ?) der Druckerschacht vom Drucker genommen
890 const MapMode aOldMap( rInfo.mrPrinter.GetMapMode() );
891 MapMode aMap( aOldMap );
892 const Orientation eOldOrient = rInfo.mrPrinter.GetOrientation();
893 Point aPageOfs( rInfo.mrPrinter.GetPageOffset() );
894 Fraction aScale(1, 2);
895 BOOL bPrintExcluded = TRUE;
897 aMap.SetOrigin(Point() - aPageOfs);
898 aMap.SetScaleX(aScale);
899 aMap.SetScaleY(aScale);
900 rInfo.mrPrinter.SetMapMode(aMap);
901 rInfo.mrPrinter.SetOrientation(ORIENTATION_PORTRAIT);
903 if ( rInfo.mpPrintOpts )
904 bPrintExcluded = rInfo.mpPrintOpts->GetOptionsPrint().IsHiddenPages();
906 Rectangle aOutRect(aPageOfs, rInfo.mrPrinter.GetOutputSize());
908 Link aOldLink;
909 Outliner* pOutliner = rInfo.mrViewShell.GetDoc()->GetInternalOutliner();
910 pOutliner->Init( OUTLINERMODE_OUTLINEVIEW );
911 USHORT nOutlMode = pOutliner->GetMode();
912 BOOL bOldUpdateMode = pOutliner->GetUpdateMode();
914 Size aPaperSize = pOutliner->GetPaperSize();
915 pOutliner->SetPaperSize(aOutRect.GetSize());
916 pOutliner->SetUpdateMode(TRUE);
918 long nPageH = aOutRect.GetHeight();
920 USHORT nPageCount = rInfo.mnProgressOffset;
922 while ( nPage < rInfo.mnPageMax )
924 Paragraph* pPara = NULL;
925 long nH = 0;
927 pOutliner->Clear();
928 pOutliner->SetFirstPageNumber(nPage+1);
930 while ( nH < nPageH && nPage < rInfo.mnPageMax )
932 if ( rInfo.mrSelPages.IsSelected(nPage+1) )
934 //rProgress.SetState( nPageCount, nTotal );
935 //rProgress.SetStateText( nPageCount, nPage+1, nTotal );
937 String aTmp = UniString::CreateFromInt32( nPage+1 );
938 aTmp += String( SdResId( STR_PRINT_OUTLINE ) );
939 rInfo.mrProgress.SetStateText(nPageCount, aTmp, rInfo.mnTotal );
941 nPageCount = nPageCount + rInfo.mnCopies;
943 SdPage* pPage = (SdPage*)rInfo.mrViewShell.GetDoc()->GetSdPage(nPage, PK_STANDARD);
944 SdrTextObj* pTextObj = NULL;
945 ULONG nObj = 0;
947 if ( !pPage->IsExcluded() || bPrintExcluded )
949 while ( !pTextObj && nObj < pPage->GetObjCount() )
951 SdrObject* pObj = pPage->GetObj(nObj++);
952 if ( pObj->GetObjInventor() == SdrInventor &&
953 pObj->GetObjIdentifier() == OBJ_TITLETEXT )
954 pTextObj = (SdrTextObj*) pObj;
957 pPara = pOutliner->GetParagraph( pOutliner->GetParagraphCount() - 1 );
959 if ( pTextObj && !pTextObj->IsEmptyPresObj() &&
960 pTextObj->GetOutlinerParaObject() )
961 pOutliner->AddText( *(pTextObj->GetOutlinerParaObject()) );
962 else
963 pOutliner->Insert(String());
965 pTextObj = NULL;
966 nObj = 0;
968 while ( !pTextObj && nObj < pPage->GetObjCount() )
970 SdrObject* pObj = pPage->GetObj(nObj++);
971 if ( pObj->GetObjInventor() == SdrInventor &&
972 pObj->GetObjIdentifier() == OBJ_OUTLINETEXT )
973 pTextObj = (SdrTextObj*) pObj;
976 BOOL bSubTitle = FALSE;
977 if (!pTextObj)
979 bSubTitle = TRUE;
980 pTextObj = (SdrTextObj*) pPage->GetPresObj(PRESOBJ_TEXT); // Untertitel vorhanden?
983 ULONG nParaCount1 = pOutliner->GetParagraphCount();
985 if ( pTextObj && !pTextObj->IsEmptyPresObj() &&
986 pTextObj->GetOutlinerParaObject() )
987 pOutliner->AddText( *(pTextObj->GetOutlinerParaObject()) );
989 if ( bSubTitle )
991 ULONG nParaCount2 = pOutliner->GetParagraphCount();
992 for (ULONG nPara = nParaCount1; nPara < nParaCount2; nPara++)
994 Paragraph* pP = pOutliner->GetParagraph(nPara);
995 if(pP && pOutliner->GetDepth( (USHORT) nPara ) > 0 )
996 pOutliner->SetDepth(pP, 0);
1000 nH = pOutliner->GetTextHeight();
1003 nPage++;
1006 if ( nH > nPageH && pPara )
1008 ULONG nCnt = pOutliner->GetAbsPos( pOutliner->GetParagraph( pOutliner->GetParagraphCount() - 1 ) );
1009 ULONG nParaPos = pOutliner->GetAbsPos( pPara );
1010 nCnt -= nParaPos;
1011 pPara = pOutliner->GetParagraph( ++nParaPos );
1012 if ( nCnt && pPara )
1014 pOutliner->Remove(pPara, nCnt);
1015 nPage--;
1019 rInfo.mrPrinter.StartPage();
1020 pOutliner->Draw(&rInfo.mrPrinter, aOutRect);
1022 if ( rInfo.mrTimeDateStr.Len() )
1024 Font aOldFont = rInfo.mrPrinter.OutputDevice::GetFont();
1025 rInfo.mrPrinter.SetFont(rInfo.mrTimeDateFont);
1026 rInfo.mrPrinter.DrawText(aPageOfs, rInfo.mrTimeDateStr);
1027 rInfo.mrPrinter.SetFont(aOldFont);
1029 rInfo.mrPrinter.EndPage();
1031 pOutliner->SetUpdateMode(bOldUpdateMode);
1032 pOutliner->SetPaperSize(aPaperSize);
1033 pOutliner->Init( nOutlMode );
1035 rInfo.mrPrinter.SetOrientation(eOldOrient);
1036 rInfo.mrPrinter.SetMapMode( aOldMap );
1042 void PrintManager::PrintHandout( PrintInfo& rInfo, USHORT nPage )
1044 SdPage* pPage = rInfo.mrViewShell.GetDoc()->GetSdPage(0, PK_HANDOUT);
1045 SdPage& rMaster = (SdPage&)pPage->TRG_GetMasterPage();
1046 SdDrawDocument* pDocument = rInfo.mrViewShell.GetDoc();
1048 BOOL bScalePage = TRUE;
1049 if ( rInfo.mpPrintOpts )
1051 bScalePage = rInfo.mpPrintOpts->GetOptionsPrint().IsPagesize();
1054 // Papierschacht
1055 if( rInfo.mpPrintOpts && !rInfo.mpPrintOpts->GetOptionsPrint().IsPaperbin() ) // Drucken NICHT aus Druckereinstellung
1057 USHORT nPaperBin = pPage->GetPaperBin();
1058 rInfo.mrPrinter.SetPaperBin( nPaperBin );
1061 // Hoch/Querformat aendern?
1062 Orientation eOrientation = rMaster.GetOrientation();
1064 short nDlgResult = RET_OK;
1066 if ( !rInfo.mrPrinter.SetOrientation(eOrientation) &&
1067 (!rInfo.mpPrintOpts || rInfo.mpPrintOpts->GetOptionsPrint().IsWarningOrientation()) )
1069 // eine Warnung anzeigen
1070 WarningBox aWarnBox(rInfo.mrViewShell.GetActiveWindow(),(WinBits)(WB_OK_CANCEL | WB_DEF_CANCEL),
1071 String(SdResId(STR_WARN_PRINTFORMAT_FAILURE)));
1072 nDlgResult = aWarnBox.Execute();
1075 if ( nDlgResult == RET_OK )
1077 const MapMode aOldMap( rInfo.mrPrinter.GetMapMode() );
1078 MapMode aMap( aOldMap );
1079 Point aPageOfs( rInfo.mrPrinter.GetPageOffset() );
1080 DrawView* pPrintView;
1081 BOOL bPrintExcluded = TRUE;
1083 aMap.SetOrigin(Point() - aPageOfs);
1085 if ( bScalePage )
1087 Size aPageSize(pPage->GetSize());
1088 Size aPrintSize( rInfo.mrPrinter.GetOutputSize() );
1090 double fHorz = (double) aPrintSize.Width() / aPageSize.Width();
1091 double fVert = (double) aPrintSize.Height() / aPageSize.Height();
1093 Fraction aFract;
1094 if ( fHorz < fVert )
1095 aFract = Fraction(aPrintSize.Width(), aPageSize.Width());
1096 else
1097 aFract = Fraction(aPrintSize.Height(), aPageSize.Height());
1099 aMap.SetScaleX(aFract);
1100 aMap.SetScaleY(aFract);
1101 aMap.SetOrigin(Point());
1104 rInfo.mrPrinter.SetMapMode(aMap);
1106 if (rInfo.mrViewShell.ISA(DrawViewShell))
1107 pPrintView = new DrawView (rInfo.mrViewShell.GetDocSh(), &rInfo.mrPrinter,
1108 static_cast<DrawViewShell*>(&rInfo.mrViewShell));
1109 else
1110 pPrintView = new DrawView (rInfo.mrViewShell.GetDocSh(), &rInfo.mrPrinter, NULL);
1112 USHORT nPageCount = rInfo.mnProgressOffset;
1114 rInfo.mrViewShell.WriteFrameViewData();
1116 rInfo.mrViewShell.SetPrintedHandoutPageNum(0);
1118 if ( rInfo.mpPrintOpts )
1119 bPrintExcluded = rInfo.mpPrintOpts->GetOptionsPrint().IsHiddenPages();
1121 std::vector< SdPage* > aPagesVector;
1122 while ( nPage < rInfo.mnPageMax )
1124 nPage++;
1125 if( rInfo.mrSelPages.IsSelected(nPage) )
1127 SdPage* pTemp = pDocument->GetSdPage(nPage-1, PK_STANDARD);
1128 if( !pTemp->IsExcluded() || bPrintExcluded )
1129 aPagesVector.push_back( pTemp );
1133 std::vector< SdrPageObj* > aPageObjVector;
1134 SdrObjListIter aShapeIter( *pPage );
1135 while( aShapeIter.IsMore() )
1137 SdrPageObj* pPageObj = dynamic_cast< SdrPageObj* >(aShapeIter.Next());
1138 if( pPageObj )
1139 aPageObjVector.push_back( pPageObj );
1142 if( aPageObjVector.empty() )
1143 return;
1145 rInfo.mrViewShell.SetPrintedHandoutPageCount( (USHORT)((aPagesVector.size() + aPageObjVector.size() - 1) / aPageObjVector.size()) );
1148 sal_Int32 nHandoutPageCount = aPagesVector.size() / aPageObjVector.size();
1149 sal_Int32 nHandoutPage = 0;
1151 std::vector< SdPage* >::iterator aPageIter( aPagesVector.begin() );
1152 while( aPageIter != aPagesVector.end() )
1154 std::vector< SdrPageObj* >::iterator aPageObjIter( aPageObjVector.begin() );
1156 while( (aPageObjIter != aPageObjVector.end()) && (aPageIter != aPagesVector.end()) )
1158 SdrPageObj* pPageObj = (*aPageObjIter++);
1159 pPageObj->SetReferencedPage( (*aPageIter++) );
1162 // if there are more page objects than pages left, set the rest to invisible
1163 int nHangoverCount = 0;
1164 while(aPageObjIter != aPageObjVector.end())
1166 (*aPageObjIter++)->SetReferencedPage(0L);
1167 nHangoverCount++;
1170 if( nHangoverCount )
1172 int nSkip = aPageObjVector.size() - nHangoverCount;
1173 aShapeIter.Reset();
1174 while( aShapeIter.IsMore() )
1176 SdrPathObj* pPathObj = dynamic_cast< SdrPathObj* >( aShapeIter.Next() );
1177 if( pPathObj )
1179 if( nSkip )
1181 nSkip--;
1183 else
1185 pPathObj->SetMergedItem( XLineStyleItem(XLINE_NONE) );
1191 // todo progress
1192 String aTmp = UniString::CreateFromInt32( nPage );
1193 aTmp += String( SdResId( STR_PRINT_HANDOUT ) );
1194 rInfo.mrProgress.SetStateText( nPageCount, aTmp, rInfo.mnTotal );
1196 rInfo.mrViewShell.SetPrintedHandoutPageNum(rInfo.mrViewShell.GetPrintedHandoutPageNum() + 1);
1198 rInfo.mrPrinter.StartPage();
1199 pPrintView->ShowSdrPage(pPage); // , Point());
1201 SdrPageView* pPageView = pPrintView->GetSdrPageView(); // pPage);
1202 pPageView->SetVisibleLayers(rInfo.mrViewShell.GetFrameView()->GetVisibleLayers() );
1203 pPageView->SetPrintableLayers(rInfo.mrViewShell.GetFrameView()->GetPrintableLayers() );
1205 pPrintView->CompleteRedraw(&rInfo.mrPrinter, Rectangle(Point(0,0), pPage->GetSize()));
1207 if ( rInfo.mrTimeDateStr.Len() )
1209 Font aOldFont = rInfo.mrPrinter.OutputDevice::GetFont();
1210 rInfo.mrPrinter.SetFont(rInfo.mrTimeDateFont);
1211 rInfo.mrPrinter.DrawText(aPageOfs, rInfo.mrTimeDateStr);
1212 rInfo.mrPrinter.SetFont(aOldFont);
1214 rInfo.mrPrinter.EndPage();
1215 pPrintView->HideSdrPage(); // pPrintView->GetPageView(pPage));
1217 if( nHangoverCount )
1219 aShapeIter.Reset();
1220 while( aShapeIter.IsMore() )
1222 SdrPathObj* pPathObj = dynamic_cast< SdrPathObj* >( aShapeIter.Next() );
1223 if( pPathObj )
1224 pPathObj->SetMergedItem( XLineStyleItem(XLINE_SOLID) );
1230 rInfo.mrViewShell.SetPrintedHandoutPageNum(1);
1231 rInfo.mrViewShell.SetPrintedHandoutPageCount(0);
1232 delete pPrintView;
1233 rInfo.mrPrinter.SetMapMode(aOldMap);
1240 void PrintManager::PrintStdOrNotes (
1241 PrintInfo& rInfo,
1242 USHORT nPage,
1243 PageKind ePageKind,
1244 BOOL bPrintMarkedOnly)
1246 Fraction aFract;
1247 BOOL bScalePage = TRUE;
1248 BOOL bTilePage = FALSE;
1249 BOOL bPrintExcluded = TRUE;
1250 BOOL bPrintPageName = TRUE;
1251 BOOL bPrintBooklet = FALSE;
1252 BOOL bPrintFrontPage = FALSE;
1253 BOOL bPrintBackPage = FALSE;
1254 SdDrawDocument* pDocument = rInfo.mrViewShell.GetDoc();
1256 SdPage* pRefPage = pDocument->GetSdPage(nPage, ePageKind);
1258 if ( rInfo.mpPrintOpts )
1260 bScalePage = rInfo.mpPrintOpts->GetOptionsPrint().IsPagesize();
1261 bTilePage = rInfo.mpPrintOpts->GetOptionsPrint().IsPagetile();
1262 bPrintPageName = rInfo.mpPrintOpts->GetOptionsPrint().IsPagename();
1263 bPrintExcluded = rInfo.mpPrintOpts->GetOptionsPrint().IsHiddenPages();
1264 bPrintBooklet = rInfo.mpPrintOpts->GetOptionsPrint().IsBooklet();
1265 bPrintFrontPage = rInfo.mpPrintOpts->GetOptionsPrint().IsFrontPage();
1266 bPrintBackPage = rInfo.mpPrintOpts->GetOptionsPrint().IsBackPage();
1268 // Papierschacht
1269 if( !rInfo.mpPrintOpts->GetOptionsPrint().IsPaperbin() ) // Drucken NICHT aus Druckereinstellung
1271 USHORT nPaperBin = pDocument->GetSdPage(nPage, ePageKind)->GetPaperBin();
1272 rInfo.mrPrinter.SetPaperBin( nPaperBin );
1277 // Hoch/Querformat aendern?
1278 Size aPageSize(pRefPage->GetSize());
1279 Orientation eOrientation = ORIENTATION_PORTRAIT;
1281 short nDlgResult = RET_OK;
1283 if( !bPrintBooklet )
1285 eOrientation = pRefPage->GetOrientation();
1287 else if( aPageSize.Width() < aPageSize.Height() )
1288 eOrientation = ORIENTATION_LANDSCAPE;
1290 if ( !rInfo.mrPrinter.SetOrientation(eOrientation) &&
1291 (!rInfo.mpPrintOpts || rInfo.mpPrintOpts->GetOptionsPrint().IsWarningOrientation()) )
1293 // eine Warnung anzeigen
1294 WarningBox aWarnBox(
1295 rInfo.mrViewShell.GetActiveWindow(),
1296 (WinBits)(WB_OK_CANCEL | WB_DEF_CANCEL),
1297 String(SdResId(STR_WARN_PRINTFORMAT_FAILURE)));
1298 nDlgResult = aWarnBox.Execute();
1301 if ( nDlgResult == RET_OK )
1303 const MapMode aOldMap( rInfo.mrPrinter.GetMapMode() );
1304 MapMode aMap( aOldMap );
1305 Point aPageOfs( rInfo.mrPrinter.GetPageOffset() );
1306 DrawView* pPrintView;
1308 aMap.SetOrigin(Point() - aPageOfs);
1309 rInfo.mrPrinter.SetMapMode(aMap);
1310 Size aPrintSize( rInfo.mrPrinter.GetOutputSize() );
1312 if (rInfo.mrViewShell.ISA(DrawViewShell))
1313 pPrintView = new DrawView (rInfo.mrViewShell.GetDocSh(), &rInfo.mrPrinter,
1314 static_cast<DrawViewShell*>(&rInfo.mrViewShell));
1315 else
1316 pPrintView = new DrawView (rInfo.mrViewShell.GetDocSh(), &rInfo.mrPrinter, NULL);
1318 USHORT nPageCount = rInfo.mnProgressOffset;
1320 // Als Broschuere drucken ?
1321 if( bPrintBooklet )
1323 MapMode aStdMap( rInfo.mrPrinter.GetMapMode() );
1324 ::std::vector< USHORT > aPageVector;
1325 ::std::vector< ::std::pair< USHORT, USHORT > > aPairVector;
1326 Point aOffset;
1327 Size aPrintSize_2( aPrintSize );
1328 Size aPageSize_2( aPageSize );
1330 if( eOrientation == ORIENTATION_LANDSCAPE )
1331 aPrintSize_2.Width() >>= 1;
1332 else
1333 aPrintSize_2.Height() >>= 1;
1335 const double fPageWH = (double) aPageSize_2.Width() / aPageSize_2.Height();
1336 const double fPrintWH = (double) aPrintSize_2.Width() / aPrintSize_2.Height();
1338 if( fPageWH < fPrintWH )
1340 aPageSize_2.Width() = (long) ( aPrintSize_2.Height() * fPageWH );
1341 aPageSize_2.Height()= aPrintSize_2.Height();
1343 else
1345 aPageSize_2.Width() = aPrintSize_2.Width();
1346 aPageSize_2.Height() = (long) ( aPrintSize_2.Width() / fPageWH );
1349 aMap.SetScaleX( Fraction( aPageSize_2.Width(), aPageSize.Width() ) );
1350 aMap.SetScaleY( Fraction( aPageSize_2.Height(), aPageSize.Height() ) );
1352 // calculate adjusted print size
1353 aPrintSize = OutputDevice::LogicToLogic( aPrintSize, aStdMap, aMap );
1355 if( eOrientation == ORIENTATION_LANDSCAPE )
1357 aOffset.X() = ( ( aPrintSize.Width() >> 1 ) - aPageSize.Width() ) >> 1;
1358 aOffset.Y() = ( aPrintSize.Height() - aPageSize.Height() ) >> 1;
1360 else
1362 aOffset.X() = ( aPrintSize.Width() - aPageSize.Width() ) >> 1;
1363 aOffset.Y() = ( ( aPrintSize.Height() >> 1 ) - aPageSize.Height() ) >> 1;
1366 // create vector of pages to print
1367 while( nPage < rInfo.mnPageMax )
1369 if( rInfo.mrSelPages.IsSelected( nPage + 1 ) )
1371 SdPage* pP = pDocument->GetSdPage( nPage, ePageKind );
1373 if( pP && ( !pP->IsExcluded() || bPrintExcluded ) )
1374 aPageVector.push_back( nPage );
1377 nPage++;
1380 // create pairs of pages to print on each page
1381 if( aPageVector.size() )
1383 sal_uInt32 nFirstIndex = 0, nLastIndex = aPageVector.size() - 1;
1385 if( aPageVector.size() & 1 )
1386 aPairVector.push_back( ::std::make_pair( (USHORT) 65535, aPageVector[ nFirstIndex++ ] ) );
1387 else
1388 aPairVector.push_back( ::std::make_pair( aPageVector[ nLastIndex-- ], aPageVector[ nFirstIndex++ ] ) );
1390 while( nFirstIndex < nLastIndex )
1392 if( nFirstIndex & 1 )
1393 aPairVector.push_back( ::std::make_pair( aPageVector[ nFirstIndex++ ], aPageVector[ nLastIndex-- ] ) );
1394 else
1395 aPairVector.push_back( ::std::make_pair( aPageVector[ nLastIndex-- ], aPageVector[ nFirstIndex++ ] ) );
1399 for( sal_uInt32 i = 0; i < aPairVector.size(); i++ )
1401 if( ( !( i & 1 ) && bPrintFrontPage ) || ( ( i & 1 ) && bPrintBackPage ) )
1403 const ::std::pair< USHORT, USHORT > aPair( aPairVector[ i ] );
1405 rInfo.mrPrinter.StartPage();
1407 SdPage* pPageToPrint = pDocument->GetSdPage( aPair.first, ePageKind );
1409 if( pPageToPrint )
1411 aMap.SetOrigin( aOffset );
1412 rInfo.mrPrinter.SetMapMode( aMap );
1413 PrintPage(rInfo, pPrintView, pPageToPrint, bPrintMarkedOnly );
1416 pPageToPrint = pDocument->GetSdPage( aPair.second, ePageKind );
1418 if( pPageToPrint )
1420 Point aSecondOffset( aOffset );
1422 if( eOrientation == ORIENTATION_LANDSCAPE )
1423 aSecondOffset.X() += ( aPrintSize.Width() >> 1 );
1424 else
1425 aSecondOffset.Y() += ( aPrintSize.Height() >> 1 );
1427 aMap.SetOrigin( aSecondOffset );
1428 rInfo.mrPrinter.SetMapMode( aMap );
1429 PrintPage(rInfo, pPrintView, pPageToPrint, bPrintMarkedOnly );
1432 rInfo.mrPrinter.EndPage();
1436 rInfo.mrPrinter.SetMapMode( aStdMap );
1438 else
1440 rInfo.mrViewShell.WriteFrameViewData();
1441 Point aPtZero;
1443 while ( nPage < rInfo.mnPageMax )
1445 if (rInfo.mrSelPages.IsSelected(nPage+1) )
1447 SdPage* pPage = pDocument->GetSdPage(nPage, ePageKind);
1448 // Kann sich die Seitengroesse geaendert haben?
1449 aPageSize = pPage->GetSize();
1451 rInfo.mrProgress.SetState( nPageCount, rInfo.mnTotal );
1452 nPageCount = nPageCount + rInfo.mnCopies;
1454 if ( bScalePage )
1456 double fHorz = (double) aPrintSize.Width() / aPageSize.Width();
1457 double fVert = (double) aPrintSize.Height() / aPageSize.Height();
1459 if ( fHorz < fVert )
1460 aFract = Fraction(aPrintSize.Width(), aPageSize.Width());
1461 else
1462 aFract = Fraction(aPrintSize.Height(), aPageSize.Height());
1464 aMap.SetScaleX(aFract);
1465 aMap.SetScaleY(aFract);
1466 aMap.SetOrigin(Point());
1469 if ( !pPage->IsExcluded() || bPrintExcluded )
1471 String aTmp = UniString::CreateFromInt32( nPage+1 );
1473 if(ePageKind == PK_NOTES)
1474 aTmp += String( SdResId( STR_PRINT_NOTES ) );
1475 else
1476 aTmp += String( SdResId( STR_PRINT_DRAWING ) );
1477 rInfo.mrProgress.SetStateText( nPageCount, aTmp, rInfo.mnTotal );
1479 String aPageStr;
1480 if ( bPrintPageName )
1482 aPageStr = pPage->GetName();
1483 aPageStr += (sal_Unicode)' ';
1485 aPageStr += rInfo.mrTimeDateStr;
1487 MapMode aStdMap = rInfo.mrPrinter.GetMapMode();
1488 rInfo.mrPrinter.SetMapMode(aMap);
1491 BOOL bPrint = TRUE;
1492 Point aPageOrigin;
1493 long aPageWidth = aPageSize.Width() - pPage->GetLftBorder() - pPage->GetRgtBorder();
1494 long aPageHeight = aPageSize.Height() - pPage->GetUppBorder() - pPage->GetLwrBorder();
1495 long aPrintWidth = aPrintSize.Width();
1496 long aPrintHeight = aPrintSize.Height();
1498 // Bugfix zu 44530:
1499 // Falls implizit umgestellt wurde (Landscape/Portrait)
1500 // wird dies beim Kacheln, bzw. aufteilen (Poster) beruecksichtigt
1501 BOOL bSwitchPageSize = FALSE;
1502 if( ( aPrintWidth > aPrintHeight && aPageWidth < aPageHeight ) ||
1503 ( aPrintWidth < aPrintHeight && aPageWidth > aPageHeight ) )
1505 bSwitchPageSize = TRUE;
1506 aPrintWidth = aPrintSize.Height();
1507 aPrintHeight = aPrintSize.Width();
1510 // Eine (kleine) Seite, die gekachelt ausgegeben werden soll
1511 if( bTilePage &&
1512 aPageWidth < aPrintWidth &&
1513 aPageHeight < aPrintHeight )
1515 aPageWidth += 500;
1516 aPageHeight += 500;
1517 Point aPrintOrigin;
1519 rInfo.mrPrinter.StartPage();
1520 pPrintView->ShowSdrPage( pPage );
1522 SdrPageView* pPageView = pPrintView->GetSdrPageView(); // pPage);
1523 pPageView->SetVisibleLayers(rInfo.mrViewShell.GetFrameView()->GetVisibleLayers() );
1524 pPageView->SetPrintableLayers(rInfo.mrViewShell.GetFrameView()->GetPrintableLayers() );
1526 long nPagesPrinted = 0; // Fuer Bedingung s.u.
1527 BOOL bPrintPage; // Fuer Bedingung s.u.
1529 while( bPrint )
1531 BOOL bWidth = aPageWidth < aPrintWidth;
1532 BOOL bHeight = aPageHeight < aPrintHeight;
1533 if( !bWidth && !bHeight )
1534 bPrint = FALSE;
1536 // Etwas umstaendliche Abfrage, die ausdrueckt, ob eine Seite
1537 // beim Kacheln abgeschnitten oder gar nicht dargestellt werden
1538 // soll. Die Bedingung ist, dass eine 2. Seite (horz. oder vert.)
1539 // immer gedruck wird, waehrend eine dritte Seite (oder hoeher)
1540 // nur noch gedruckt wird, wenn diese auch noch vollstaendig
1541 // aufs Papier passt.
1542 if( nPagesPrinted < 4 && !( !bWidth && nPagesPrinted == 2 ) )
1543 bPrintPage = TRUE;
1544 else
1545 bPrintPage = FALSE;
1546 nPagesPrinted++;
1548 if( ( bWidth && bHeight ) || bPrintPage )
1550 aStdMap.SetOrigin( aPrintOrigin );
1551 rInfo.mrPrinter.SetMapMode( aStdMap );
1553 if (rInfo.mrViewShell.ISA(DrawViewShell) && bPrintMarkedOnly )
1555 rInfo.mrViewShell.GetView()->DrawMarkedObj(rInfo.mrPrinter);
1557 else
1558 pPrintView->CompleteRedraw( &rInfo.mrPrinter, Rectangle( aPtZero, aPageSize ) );
1560 if( bWidth )
1562 aPrintOrigin.X() += aPageWidth;
1563 aPrintWidth -= aPageWidth;
1565 else if( bHeight )
1567 aPrintOrigin.X() = 0;
1568 aPrintWidth = bSwitchPageSize ? aPrintSize.Height() : aPrintSize.Width();
1569 aPrintOrigin.Y() += aPageHeight;
1570 aPrintHeight -= aPageHeight;
1574 if ( aPageStr.Len() )
1576 Font aOldFont = rInfo.mrPrinter.OutputDevice::GetFont();
1577 rInfo.mrPrinter.SetFont(rInfo.mrTimeDateFont);
1578 rInfo.mrPrinter.DrawText(aPageOfs, aPageStr);
1579 rInfo.mrPrinter.SetFont(aOldFont);
1581 rInfo.mrPrinter.EndPage();
1582 pPrintView->HideSdrPage(); // pPrintView->GetPageView(pPage));
1584 bPrint = FALSE;
1587 // For pages larger then the printable area there
1588 // are three options:
1589 // 1. Scale down to the page to the printable area.
1590 // 2. Print only the upper left part of the page
1591 // (without the unprintable borders).
1592 // 3. Split the page into parts of the size of the
1593 // printable area.
1594 if (bPrint)
1596 const bool bCutPage (rInfo.mpPrintOpts && rInfo.mpPrintOpts->GetOptionsPrint().IsCutPage());
1597 if (bScalePage || bCutPage)
1599 // Handle 1 and 2.
1601 // if CutPage is set then do not move
1602 // it, otherwise move the scaled page
1603 // to printable area
1605 PrintPagePart(
1606 rInfo,
1607 pPage,
1608 *pPrintView,
1609 bCutPage ? Point(-aPageOfs.X(), -aPageOfs.Y()) : Point(0,0),
1610 bPrintMarkedOnly,
1611 aPageStr,
1612 aPageOfs);
1614 else
1616 Point aOrigin;
1618 // if the printable area is bigger than page size, center the page
1619 if( aPageSize.Width() < aPrintWidth )
1620 aOrigin.X() = ( aPrintWidth - aPageSize.Width() )/2;
1621 if( aPageSize.Height() < aPrintHeight )
1622 aOrigin.Y() = ( aPrintHeight - aPageSize.Height() )/2;
1624 // Handle 3. Print parts of the page in the
1625 // size of the printable area until the
1626 // whole page is covered.
1628 for (aPageOrigin = aOrigin;
1629 -aPageOrigin.Y()<aPageHeight;
1630 aPageOrigin.Y() -= aPrintHeight)
1632 for (aPageOrigin.X()=aOrigin.X();
1633 -aPageOrigin.X()<aPageWidth;
1634 aPageOrigin.X() -= aPrintWidth)
1636 PrintPagePart(
1637 rInfo,
1638 pPage,
1639 *pPrintView,
1640 aPageOrigin,
1641 bPrintMarkedOnly,
1642 aPageStr,
1643 aPageOfs);
1650 nPage++;
1654 delete pPrintView;
1655 rInfo.mrPrinter.SetMapMode( aOldMap );
1662 void PrintManager::PrintPagePart (
1663 PrintInfo& rInfo,
1664 SdPage* pPage,
1665 DrawView& rPrintView,
1666 const Point& rPageOrigin,
1667 BOOL bPrintMarkedOnly,
1668 const String& rsPageString,
1669 const Point& rStringOffset)
1671 rInfo.mrPrinter.StartPage();
1672 rPrintView.ShowSdrPage(pPage); // , Point(0,0));
1674 // Set origin of the map mode so that the next part of the page is
1675 // printed.
1676 MapMode aOriginalMapMode = rInfo.mrPrinter.GetMapMode();
1677 MapMode aMapMode = rInfo.mrPrinter.GetMapMode();
1678 aMapMode.SetOrigin(rPageOrigin);
1679 rInfo.mrPrinter.SetMapMode(aMapMode);
1681 SdrPageView* pPageView = rPrintView.GetSdrPageView(); // pPage);
1682 pPageView->SetVisibleLayers(rInfo.mrViewShell.GetFrameView()->GetVisibleLayers() );
1683 pPageView->SetPrintableLayers(rInfo.mrViewShell.GetFrameView()->GetPrintableLayers() );
1685 if (rInfo.mrViewShell.ISA(DrawViewShell) && bPrintMarkedOnly)
1686 rInfo.mrViewShell.GetView()->DrawMarkedObj(rInfo.mrPrinter);
1687 else
1688 rPrintView.CompleteRedraw(&rInfo.mrPrinter, Rectangle(Point(0,0), pPage->GetSize()));
1689 rInfo.mrPrinter.SetMapMode(aOriginalMapMode);
1691 if (rsPageString.Len())
1693 Font aOldFont = rInfo.mrPrinter.OutputDevice::GetFont();
1694 rInfo.mrPrinter.SetFont(rInfo.mrTimeDateFont);
1695 rInfo.mrPrinter.DrawText(rStringOffset, rsPageString);
1696 rInfo.mrPrinter.SetFont(aOldFont);
1698 rInfo.mrPrinter.EndPage();
1699 rPrintView.HideSdrPage(); // rPrintView.GetPageView(pPage));
1706 void PrintManager::PrintPage (
1707 PrintInfo& rInfo,
1708 ::sd::View* pPrintView,
1709 SdPage* pPage,
1710 BOOL bPrintMarkedOnly)
1712 Point aPtZero;
1713 pPrintView->ShowSdrPage( pPage ); // , aPtZero );
1715 SdrPageView* pPageView = pPrintView->GetSdrPageView(); // pPage );
1716 pPageView->SetVisibleLayers(rInfo.mrViewShell.GetFrameView()->GetVisibleLayers() );
1717 pPageView->SetPrintableLayers(rInfo.mrViewShell.GetFrameView()->GetPrintableLayers() );
1719 if (rInfo.mrViewShell.ISA(DrawViewShell) && bPrintMarkedOnly)
1720 rInfo.mrViewShell.GetView()->DrawMarkedObj(rInfo.mrPrinter);
1721 else
1722 pPrintView->CompleteRedraw(&rInfo.mrPrinter, Rectangle(Point(0,0), pPage->GetSize()));
1724 pPrintView->HideSdrPage(); // pPrintView->GetPageView( pPage ) );
1730 bool PrintManager::IsScreenFormat (void)
1732 // Determine the page size.
1733 SdPage* pPage = mrBase.GetDocument()->GetSdPage(0, PK_STANDARD);
1734 Size aPaperSize (pPage->GetSize());
1736 // Take Orientation into account.
1737 if (pPage->GetOrientation() == ORIENTATION_LANDSCAPE)
1738 Swap(aPaperSize);
1740 // Check whether paper size is 'Screen'
1741 Paper ePaper(SvxPaperInfo::GetSvxPaper(aPaperSize, MAP_100TH_MM, TRUE));
1742 return (ePaper == PAPER_SCREEN);
1746 void PrintManager::InitHandoutTemplate( PrintInfo& /*rInfo*/, USHORT nSlidesPerHandout, BOOL bHandoutHorizontal )
1748 AutoLayout eLayout = AUTOLAYOUT_HANDOUT6;
1749 switch( nSlidesPerHandout )
1751 case 1: eLayout = AUTOLAYOUT_HANDOUT1; break;
1752 case 2: eLayout = AUTOLAYOUT_HANDOUT2; break;
1753 case 3: eLayout = AUTOLAYOUT_HANDOUT3; break;
1754 case 4: eLayout = AUTOLAYOUT_HANDOUT4; break;
1755 case 9: eLayout = AUTOLAYOUT_HANDOUT9; break;
1758 if( !mrBase.GetDocument() )
1759 return;
1761 SdDrawDocument& rModel = *mrBase.GetDocument();
1763 // first, prepare handout page (not handout master)
1765 SdPage* pHandout = rModel.GetSdPage(0, PK_HANDOUT);
1766 if( !pHandout )
1767 return;
1769 // delete all previous shapes from handout page
1770 while( pHandout->GetObjCount() )
1772 SdrObject* pObj = pHandout->NbcRemoveObject(0);
1773 if( pObj )
1774 SdrObject::Free( pObj );
1777 const bool bDrawLines = eLayout == AUTOLAYOUT_HANDOUT3;
1779 std::vector< Rectangle > aAreas;
1780 SdPage::CalculateHandoutAreas( rModel, eLayout, bHandoutHorizontal, aAreas );
1782 std::vector< Rectangle >::iterator iter( aAreas.begin() );
1783 while( iter != aAreas.end() )
1785 pHandout->NbcInsertObject( new SdrPageObj((*iter++)) );
1787 if( bDrawLines && (iter != aAreas.end()) )
1789 Rectangle aRect( (*iter++) );
1791 basegfx::B2DPolygon aPoly;
1792 aPoly.insert(0, basegfx::B2DPoint( aRect.Left(), aRect.Top() ) );
1793 aPoly.insert(1, basegfx::B2DPoint( aRect.Right(), aRect.Top() ) );
1795 basegfx::B2DHomMatrix aMatrix;
1796 aMatrix.translate( 0.0, static_cast< double >( aRect.GetHeight() / 7 ) );
1798 basegfx::B2DPolyPolygon aPathPoly;
1799 for( sal_uInt16 nLine = 0; nLine < 7; nLine++ )
1801 aPoly.transform( aMatrix );
1802 aPathPoly.append( aPoly );
1805 SdrPathObj* pPathObj = new SdrPathObj(OBJ_PATHLINE, aPathPoly );
1806 pPathObj->SetMergedItem( XLineStyleItem(XLINE_SOLID) );
1807 pPathObj->SetMergedItem( XLineColorItem(String(), Color(COL_BLACK)));
1809 pHandout->NbcInsertObject( pPathObj );
1814 } // end of namespace sd