1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: 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"
44 #include "drawdoc.hxx"
45 #include "drawview.hxx"
46 #include "ViewShellBase.hxx"
47 #include "DrawViewShell.hxx"
48 #include "OutlineViewShell.hxx"
49 #include "Outliner.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"
74 #include <svtools/intitem.hxx>
75 #include <svx/paperinf.hxx>
76 #include <svx/xlnclit.hxx>
77 #include "printdialog.hxx"
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
88 ViewShell
& rViewShell
,
90 SfxProgress
& rProgress
,
91 const MultiSelection
& rSelPages
,
92 const String
& rTimeDateStr
,
93 const Font
& rTimeDateFont
,
94 const SdOptionsPrintItem
* pPrintOpts
,
97 USHORT nProgressOffset
,
99 : mrViewShell(rViewShell
),
101 mrProgress(rProgress
),
102 mrSelPages(rSelPages
),
103 mrTimeDateStr(rTimeDateStr
),
104 mrTimeDateFont(rTimeDateFont
),
105 mpPrintOpts(pPrintOpts
),
108 mnProgressOffset(nProgressOffset
),
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
;
121 USHORT mnProgressOffset
;
126 PrintManager::PrintManager (ViewShellBase
& 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
,
164 SfxPrinter
* pOld
= mrBase
.GetDocShell()->GetPrinter( FALSE
);
165 if ( pOld
&& pOld
->IsPrinting() )
166 return SFX_PRINTERROR_BUSY
;
168 mrBase
.GetDocShell()->SetPrinter(pNewPrinter
);
170 if ( (nDiffFlags
& SFX_PRINTER_CHG_ORIENTATION
||
171 nDiffFlags
& SFX_PRINTER_CHG_SIZE
) && pNewPrinter
)
173 MapMode aMap
= pNewPrinter
->GetMapMode();
174 aMap
.SetMapUnit(MAP_100TH_MM
);
175 MapMode aOldMap
= pNewPrinter
->GetMapMode();
176 pNewPrinter
->SetMapMode(aMap
);
177 Size aNewSize
= pNewPrinter
->GetOutputSize();
179 BOOL bScaleAll
= FALSE
;
182 WarningBox
aWarnBox (
184 (WinBits
)(WB_YES_NO
| WB_DEF_YES
),
185 String(SdResId(STR_SCALE_OBJS_TO_PAGE
)));
186 bScaleAll
= (aWarnBox
.Execute() == RET_YES
);
189 ViewShell
* pShell
= mrBase
.GetMainViewShell().get();
190 if (pShell
!= NULL
&& pShell
->ISA(DrawViewShell
))
192 SdPage
* pPage
= mrBase
.GetDocument()->GetSdPage(
194 pShell
->SetPageSizeAndBorder (
195 static_cast<DrawViewShell
*>(pShell
)->GetPageKind(),
199 pNewPrinter
->GetOrientation(),
200 pPage
->GetPaperBin(),
201 pPage
->IsBackgroundFullSize());
204 pNewPrinter
->SetMapMode(aOldMap
);
213 PrintDialog
* PrintManager::CreatePrintDialog (::Window
*pParent
)
215 const bool bImpress
= mrBase
.GetDocument()->GetDocumentType() == DOCUMENT_TYPE_IMPRESS
;
217 SdPrintDialog
* pDlg
= SdPrintDialog::Create(pParent
,bImpress
);
219 ViewShell
* pShell
= mrBase
.GetMainViewShell().get();
220 if (pShell
!=NULL
&& ! pShell
->ISA(OutlineViewShell
))
223 if (pShell
->ISA(DrawViewShell
))
225 pDlg
->SetRangeText(UniString::CreateFromInt32(
226 static_cast<DrawViewShell
*>(pShell
)->GetCurPageId()));
228 /* else if(pShell->ISA(::sd::slidesorter::SlideSorterViewShell))
231 dynamic_cast<sd::slidesorter::SlideSorterViewShell*>(pShell)->GetPageRangeString());
232 if( aStrRange.Len() )
234 pDlg->SetRangeText( aStrRange );
235 // According #79749 always check PRINTDIALOG_ALL
236 // pDlg->CheckRange( PRINTDIALOG_RANGE );
244 static_cast<OutlineViewShell
*>(pShell
)->GetPageRangeString());
245 if( aStrRange
.Len() )
247 pDlg
->SetRangeText( aStrRange
);
248 // According #79749 always check PRINTDIALOG_ALL
249 // pDlg->CheckRange( PRINTDIALOG_RANGE );
252 pDlg
->EnableRange( PRINTDIALOG_RANGE
);
253 pDlg
->EnableRange( PRINTDIALOG_ALL
);
254 pDlg
->EnableCollate();
256 if (pShell
->ISA(DrawViewShell
) && pShell
->GetView()->AreObjectsMarked())
258 pDlg
->EnableRange( PRINTDIALOG_SELECTION
);
259 // According #79749 always check PRINTDIALOG_ALL
260 // pDlg->CheckRange( PRINTDIALOG_SELECTION );
265 const SdOptionsPrintItem
* pPrintOpts
= 0;
267 SfxPrinter
* pPrinter
= mrBase
.GetPrinter(FALSE
);
270 const SfxPoolItem
* pPoolItem
= 0;
271 if(pPrinter
->GetOptions().GetItemState(ATTR_OPTIONS_PRINT
, FALSE
, &pPoolItem
) == SFX_ITEM_SET
)
272 pPrintOpts
= dynamic_cast< const SdOptionsPrintItem
* >( pPoolItem
);
274 pDlg
->Init( pPrintOpts
);
280 SfxTabPage
* PrintManager::CreatePrintOptionsPage( ::Window
*pParent
, const SfxItemSet
&rOptions
)
282 SfxTabPage
* pPage
= 0;
283 DocumentType eDocType
= mrBase
.GetDocument()->GetDocumentType();
284 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
285 ::CreateTabPage fnCreatePage
= pFact
? pFact
->GetSdPrintOptionsTabPageCreatorFunc() : 0;
288 pPage
= (*fnCreatePage
)( pParent
, rOptions
);
289 if( eDocType
== DOCUMENT_TYPE_DRAW
)
291 SfxAllItemSet
aSet(*(rOptions
.GetPool()));
292 aSet
.Put (SfxUInt32Item(SID_SDMODE_FLAG
,SD_DRAW_MODE
));
293 pPage
->PageCreated(aSet
);
302 USHORT
PrintManager::Print (SfxProgress
& rProgress
, BOOL bIsAPI
, PrintDialog
* pDlg
)
304 SfxPrinter
* pPrinter
= mrBase
.GetPrinter(TRUE
);
305 ViewShell
* pShell
= mrBase
.GetMainViewShell().get();
307 if (pPrinter
!=NULL
&& pShell
!=NULL
)
309 const PrinterOptions
aOldPrinterOptions( pPrinter
->GetPrinterOptions() );
310 MapMode
aMap( pPrinter
->GetMapMode() );
311 const MapMode
aOldMap( aMap
);
312 USHORT nOldPaperBin
= pPrinter
->GetPaperBin();
314 aMap
.SetMapUnit(MAP_100TH_MM
);
315 pPrinter
->SetMapMode(aMap
);
317 ::Outliner
& rOutliner
= mrBase
.GetDocument()->GetDrawOutliner();
318 ULONG nOldCntrl
= rOutliner
.GetControlWord();
319 ULONG nCntrl
= nOldCntrl
;
320 nCntrl
&= ~EE_CNTRL_MARKFIELDS
;
321 nCntrl
&= ~EE_CNTRL_ONLINESPELLING
;
322 rOutliner
.SetControlWord( nCntrl
);
324 // old place of FitPageToPrinterWithDialog().
325 SdOptionsPrintItem
* pPrintOpts
= 0;
327 const SfxPoolItem
* pPoolItem
= 0;
328 if (pPrinter
->GetOptions().GetItemState( ATTR_OPTIONS_PRINT
, FALSE
, &pPoolItem
) == SFX_ITEM_SET
)
329 pPrintOpts
= dynamic_cast< SdOptionsPrintItem
* >( const_cast< SfxPoolItem
* >( pPoolItem
) ) ;
331 if( dynamic_cast<SdPrintDialog
*>(pDlg
) && static_cast<SdPrintDialog
*>(pDlg
)->Fill( pPrintOpts
) )
333 SfxItemSet
aNewOptions( pPrinter
->GetOptions() );
334 aNewOptions
.Put( *pPrintOpts
);
335 pPrinter
->SetOptions( aNewOptions
);
336 pPrintOpts
= dynamic_cast< SdOptionsPrintItem
* >( const_cast< SfxPoolItem
* >( pPrinter
->GetOptions().GetItem( ATTR_OPTIONS_PRINT
) ) );
339 // Wenn wir im Gliederungsmodus sind, muss das Model auf Stand gebracht werden
340 if (pShell
->ISA(OutlineViewShell
))
341 static_cast<OutlineViewShell
*>(pShell
)->PrepareClose (FALSE
, FALSE
);
343 // Basisklasse rufen, um Basic anzusprechen
344 mrBase
.SfxViewShell::Print( rProgress
, bIsAPI
, pDlg
);
346 // Setzen des Textes des Druckmonitors
347 rProgress
.SetText( String( SdResId( STR_STATSTR_PRINT
) ) );
349 PrintDialogRange eOption
;
350 MultiSelection aPrintSelection
;
352 Font
aTimeDateFont(FAMILY_SWISS
, Size(0, 423));
353 PageKind ePageKind
= PK_STANDARD
;
354 USHORT nPage
, nPageMax
;
355 USHORT nTotal
, nCopies
;
356 USHORT nPrintCount
= 0;
357 USHORT nProgressOffset
= 0;
358 USHORT nCollateCopies
= 1;
359 BOOL bPrintMarkedOnly
= FALSE
;
360 BOOL bPrintOutline
= FALSE
;
361 BOOL bPrintHandout
= FALSE
;
362 BOOL bPrintDraw
= FALSE
;
363 BOOL bPrintNotes
= FALSE
;
364 BOOL bHandoutHorizontal
= TRUE
;
365 USHORT nSlidesPerHandout
= 6;
367 Orientation eOldOrientation
= pPrinter
->GetOrientation();
371 SfxMiscCfg
* pMisc
= SFX_APP()->GetMiscConfig();
373 if( pPrintOpts
->GetOptionsPrint().IsDate() )
375 aTimeDateStr
+= GetSdrGlobalData().GetLocaleData()->getDate( Date() );
376 aTimeDateStr
+= (sal_Unicode
)' ';
379 if( pPrintOpts
->GetOptionsPrint().IsTime() )
380 aTimeDateStr
+= GetSdrGlobalData().GetLocaleData()->getTime( Time(), FALSE
, FALSE
);
382 if( pPrintOpts
->GetOptionsPrint().IsOutline() )
383 bPrintOutline
= TRUE
;
385 if( pPrintOpts
->GetOptionsPrint().IsHandout() )
387 bPrintHandout
= TRUE
;
388 bHandoutHorizontal
= pPrintOpts
->GetOptionsPrint().IsHandoutHorizontal();
389 nSlidesPerHandout
= pPrintOpts
->GetOptionsPrint().GetHandoutPages();
392 if( pPrintOpts
->GetOptionsPrint().IsDraw() )
395 if( pPrintOpts
->GetOptionsPrint().IsNotes() )
398 ePageKind
= PK_NOTES
;
401 pPrintOpts
->GetOptionsPrint().SetWarningPrinter( pMisc
->IsNotFoundWarning() );
402 pPrintOpts
->GetOptionsPrint().SetWarningSize( pMisc
->IsPaperSizeWarning() );
403 pPrintOpts
->GetOptionsPrint().SetWarningOrientation( pMisc
->IsPaperOrientationWarning() );
405 UINT16 nQuality
= pPrintOpts
->GetOptionsPrint().GetOutputQuality();
406 ULONG nMode
= DRAWMODE_DEFAULT
;
409 nMode
= DRAWMODE_GRAYLINE
| DRAWMODE_GRAYFILL
| DRAWMODE_BLACKTEXT
| DRAWMODE_GRAYBITMAP
| DRAWMODE_GRAYGRADIENT
;
410 else if( nQuality
== 2 )
411 nMode
= DRAWMODE_BLACKLINE
| DRAWMODE_BLACKTEXT
| DRAWMODE_WHITEFILL
| DRAWMODE_GRAYBITMAP
| DRAWMODE_WHITEGRADIENT
;
413 pPrinter
->SetDrawMode( nMode
);
420 eOption
= pDlg
->GetCheckedRange();
422 if( eOption
== PRINTDIALOG_SELECTION
)
423 bPrintMarkedOnly
= TRUE
;
426 // Bei PrintDirect wird gesamtes Dokument gedruckt
427 eOption
= PRINTDIALOG_ALL
;
429 // #72527 If we are in PrintDirect and any objects
430 // are selected, then a dialog (see ViewShell::DoPrint)
431 // ask whether the total document should be printed
432 // or only the selected objects. If only the selected
433 // object, then the flag bPrintDirectSelected is TRUE
434 if (mbPrintDirectSelected
)
436 eOption
= PRINTDIALOG_SELECTION
;
437 bPrintMarkedOnly
= TRUE
;
440 nPageMax
= mrBase
.GetDocument()->GetSdPageCount( ePageKind
);
441 aPrintSelection
.SetTotalRange( Range( 1, nPageMax
) );
445 case PRINTDIALOG_ALL
:
446 aPrintSelection
.Select(Range(1, nPageMax
));
449 case PRINTDIALOG_RANGE
:
450 aPrintSelection
= MultiSelection(pDlg
->GetRangeText());
455 if (pShell
->ISA(DrawViewShell
))
456 aPrintSelection
.Select (
457 static_cast<DrawViewShell
*>(pShell
)->GetCurPageId());
460 if( msPageRange
.Len() )
461 aPrintSelection
= MultiSelection( msPageRange
);
463 aPrintSelection
.Select(Range(1, nPageMax
));
469 nPage
= Min(nPageMax
, (USHORT
) aPrintSelection
.FirstSelected());
474 nPageMax
= Min(nPageMax
, (USHORT
) aPrintSelection
.LastSelected());
488 nCopies
= (pDlg
? pDlg
->GetCopyCount() : 1);
490 USHORT nSelectCount
= (USHORT
) aPrintSelection
.GetSelectCount();
491 nTotal
= nSelectCount
* nCopies
* nPrintCount
;
493 if( pDlg
&& pDlg
->IsCollateEnabled() && pDlg
->IsCollateChecked() )
494 nCollateCopies
= nCopies
;
496 // check if selected range of pages contains transparent objects
497 BOOL bContainsTransparency
= FALSE
;
498 BOOL bPrintExcluded
= TRUE
;
500 if( bPrintNotes
|| bPrintDraw
|| bPrintHandout
)
503 bPrintExcluded
= pPrintOpts
->GetOptionsPrint().IsHiddenPages();
505 for( USHORT j
= nPage
; ( j
< nPageMax
&& !bContainsTransparency
); j
++ )
507 if( aPrintSelection
.IsSelected( j
+ 1 ) )
509 SdPage
* pPage
= mrBase
.GetDocument()->GetSdPage(
512 if( pPage
&& ( !pPage
->IsExcluded() || bPrintExcluded
) )
514 bContainsTransparency
= (BOOL
)pPage
->HasTransparentObjects();
515 if( !bContainsTransparency
)
517 if(pPage
->TRG_HasMasterPage())
519 bContainsTransparency
= (BOOL
)pPage
->TRG_GetMasterPage().HasTransparentObjects();
527 if (pPrinter
->InitJob (mrBase
.GetWindow(), !bIsAPI
&& bContainsTransparency
))
538 nCollateCopies
> 1 ? 1 : nCopies
,
543 InitHandoutTemplate( aInfo
, nSlidesPerHandout
, bHandoutHorizontal
);
545 for( USHORT n
= 1; n
<= nCollateCopies
; n
++ )
549 // siehe unten in PrintOutline()
550 pPrinter
->SetPaperBin( nOldPaperBin
);
552 PrintOutline(aInfo
, nPage
);
553 aInfo
.mnProgressOffset
+= (nSelectCount
* ( nCollateCopies
> 1 ? 1 : nCopies
));
558 PrintHandout(aInfo
, nPage
);
559 aInfo
.mnProgressOffset
+= (nSelectCount
* ( nCollateCopies
> 1 ? 1 : nCopies
));
563 PrintStdOrNotes(aInfo
, nPage
, PK_STANDARD
, bPrintMarkedOnly
);
564 aInfo
.mnProgressOffset
+= (nSelectCount
* ( nCollateCopies
> 1 ? 1 : nCopies
));
568 PrintStdOrNotes(aInfo
, nPage
, PK_NOTES
, FALSE
);
569 aInfo
.mnProgressOffset
+= (nSelectCount
* ( nCollateCopies
> 1 ? 1 : nCopies
));
572 // When in duplex mode then add an empty page after printing
573 // an odd number of pages. This is to avoid the first page
574 // of the next run being printed on the backside of the
576 if (nCollateCopies
> 1
578 && (pPrinter
->GetCurPage()%2)==0
579 && (pPrinter
->GetDuplexMode()==DUPLEX_ON
))
581 pPrinter
->StartPage();
587 pPrinter
->SetOrientation( eOldOrientation
);
588 pPrinter
->SetPrinterOptions( aOldPrinterOptions
);
589 pPrinter
->SetMapMode( aOldMap
);
591 rOutliner
.SetControlWord(nOldCntrl
);
593 // Druckerschach wieder zuruecksetzen
594 pPrinter
->SetPaperBin( nOldPaperBin
);
604 ErrCode
PrintManager::DoPrint (
605 SfxPrinter
* pPrinter
,
606 PrintDialog
* pPrintDialog
,
607 BOOL bSilent
, BOOL bIsAPI
)
609 ErrCode nResult
= ERRCODE_NONE
;
613 ViewShell
* pShell
= mrBase
.GetMainViewShell().get();
617 if ( ! FitPageToPrinterWithDialog(pPrinter
, bSilent
))
620 const SdrMarkList
& rMarkList
= pShell
->GetView()->GetMarkedObjectList();
622 // Retrieve the range of marked pages.
623 String
sNewPageRange (msPageRange
);
625 RestrictPrintingToSelection (FALSE
);
627 // #105477# Don't show query dialog if print dialog has been shown
629 && !bSilent
&& !bIsAPI
630 && (rMarkList
.GetMarkCount() || sNewPageRange
.Len()) )
632 SvxPrtQryBox
aQuery (mrBase
.GetWindow());
634 switch (aQuery
.Execute())
637 nResult
= ERRCODE_IO_ABORT
;
641 RestrictPrintingToSelection (TRUE
);
642 SetPrintingPageRange (sNewPageRange
);
647 if (nResult
== ERRCODE_NONE
)
649 // Tell the printer which digit language to use.
650 WindowUpdater
* pWindowUpdater
= pShell
->GetWindowUpdater();
651 if (pWindowUpdater
!= NULL
)
652 pWindowUpdater
->Update (pPrinter
, mrBase
.GetDocument());
654 // Forward the call to SfxViewShell::DoPrint() which
655 // eventually calls Print() (after StartJob etc.)
656 nResult
= mrBase
.SfxViewShell::DoPrint (
657 pPrinter
, pPrintDialog
, bSilent
, bIsAPI
);
659 RestrictPrintingToSelection (FALSE
);
670 void PrintManager::PreparePrint (PrintDialog
* )
672 SfxPrinter
* pPrinter
= GetPrinter(TRUE
);
677 const SfxItemSet
& rOptions
= pPrinter
->GetOptions();
678 SdOptionsPrintItem
* pPrintOpts
= NULL
;
680 if (rOptions
.GetItemState( ATTR_OPTIONS_PRINT
, FALSE
,
681 (const SfxPoolItem
**) &pPrintOpts
) != SFX_ITEM_SET
)
686 // Einstellungen der ersten zu druckenden Seite setzen
690 if ( pPrintOpts
->GetOptionsPrint().IsHandout() )
693 SdPage
* pPage
= mrBase
.GetDocument()->GetSdPage(0, PK_HANDOUT
);
696 if (!pPrintOpts
->GetOptionsPrint().IsPaperbin()) // Drucken NICHT aus Druckereinstellung
698 pPrinter
->SetPaperBin(pPage
->GetPaperBin());
701 pPrinter
->SetOrientation(pPage
->TRG_GetMasterPage().GetOrientation());
703 else if ( pPrintOpts
->GetOptionsPrint().IsDraw() || pPrintOpts
->GetOptionsPrint().IsNotes() )
705 // Standard- oder Notizseiten
706 if( !pPrintOpts
->GetOptionsPrint().IsPaperbin() ) // Drucken NICHT aus Druckereinstellung
708 PageKind ePageKind
= PK_NOTES
;
710 if (pPrintOpts
->GetOptionsPrint().IsDraw())
712 ePageKind
= PK_STANDARD
;
715 SdPage
* pPage
= mrBase
.GetDocument()->GetSdPage(0, ePageKind
);
716 pPrinter
->SetPaperBin(pPage
->GetPaperBin());
718 Orientation eOrientation
= ORIENTATION_PORTRAIT
;
720 if ( !pPrintOpts
->GetOptionsPrint().IsBooklet() )
722 eOrientation
= pPage
->GetOrientation();
726 Size
aPageSize(pPage
->GetSize());
728 if( aPageSize
.Width() < aPageSize
.Height() )
729 eOrientation
= ORIENTATION_LANDSCAPE
;
732 pPrinter
->SetOrientation(eOrientation
);
741 void PrintManager::RestrictPrintingToSelection (bool bFlag
)
743 mbPrintDirectSelected
= bFlag
? TRUE
: FALSE
;
749 void PrintManager::SetPrintingPageRange (const String
& rsPageRange
)
751 msPageRange
= rsPageRange
;
757 bool PrintManager::FitPageToPrinterWithDialog (
758 SfxPrinter
* pPrinter
,
761 bool bContinuePrinting
= true;
763 if (pPrinter
!= NULL
)
765 // Remember old printer values so that they can be restored when
766 // printing is aborted by the user.
767 const PrinterOptions
aOldPrinterOptions (pPrinter
->GetPrinterOptions());
768 const MapMode
aOldMap (pPrinter
->GetMapMode());
770 // Get values from the priner in order to decide whether to show a
772 const SfxItemSet
& rOptions
= pPrinter
->GetOptions();
773 SdOptionsPrintItem
* pPrintOpts
= NULL
;
774 BOOL bScalePage
= TRUE
;
775 BOOL bTilePage
= FALSE
;
776 BOOL bNotesPage
= FALSE
;
777 BOOL bPrintBooklet
= FALSE
;
779 if( rOptions
.GetItemState( ATTR_OPTIONS_PRINT
, FALSE
, (const SfxPoolItem
**) &pPrintOpts
) == SFX_ITEM_SET
)
781 bScalePage
= pPrintOpts
->GetOptionsPrint().IsPagesize();
782 bPrintBooklet
= pPrintOpts
->GetOptionsPrint().IsBooklet();
783 bNotesPage
= pPrintOpts
->GetOptionsPrint().IsNotes();
784 pPrintOpts
->GetOptionsPrint().SetCutPage( FALSE
);
789 SdPage
* pPage
= mrBase
.GetDocument()->GetSdPage( 0, PK_STANDARD
);
790 Size
aPageSize( pPage
->GetSize() );
791 Size
aPrintSize( pPrinter
->GetOutputSize() );
792 long nPageWidth
= aPageSize
.Width() - pPage
->GetLftBorder() - pPage
->GetRgtBorder();
793 long nPageHeight
= aPageSize
.Height() - pPage
->GetUppBorder() - pPage
->GetLwrBorder();
794 long nNotesPageWidth
, nNotesPageHeight
;
795 long nPrintWidth
= aPrintSize
.Width();
796 long nPrintHeight
= aPrintSize
.Height();
797 USHORT nRet
= RET_OK
;
800 SdPage
* pNotesPage
= mrBase
.GetDocument()->GetSdPage( 0, PK_NOTES
);
801 Size aNotesPageSize
= Size( pNotesPage
->GetSize () );
802 nNotesPageWidth
= aNotesPageSize
.Width() - pNotesPage
->GetLftBorder() - pNotesPage
->GetRgtBorder();
803 nNotesPageHeight
= aNotesPageSize
.Height() - pNotesPage
->GetUppBorder() - pNotesPage
->GetLwrBorder();
806 // When necessary then show a dialog that asks the user how to fit
807 // the pages to be printed to the (smaller) printer pages.
811 && ( ( ( nPageWidth
> nPrintWidth
|| nPageHeight
> nPrintHeight
)
812 && ( nPageWidth
> nPrintHeight
|| nPageHeight
> nPrintWidth
)
815 && ( nNotesPageWidth
> nPrintWidth
|| nNotesPageHeight
> nPrintHeight
)
816 && ( nNotesPageWidth
> nPrintHeight
|| nNotesPageHeight
> nPrintWidth
) )
820 if (IsScreenFormat())
822 // For the screen format the page content is always scaled
823 // to the printable area of the printer pages.
824 pPrintOpts
->GetOptionsPrint().SetPagesize();
829 SdAbstractDialogFactory
* pFact
= SdAbstractDialogFactory::Create();
830 AbstractSdPrintDlg
* pDlg
= pFact
? pFact
->CreateSdPrintDlg(mrBase
.GetWindow() ) : 0;
831 // Do not show the dialog when the bSilent flag is set. We
832 // do create the dialog anyway so that we can extract the
833 // default method of mapping internal pages to printer pages
835 if( ! bSilent
&& pDlg
)
836 nRet
= pDlg
->Execute();
839 switch (pDlg
->GetAttr())
842 pPrintOpts
->GetOptionsPrint().SetPagesize();
846 // Tiling is the default behaviour in
847 // ViewShell::PrintStdOrNotes(). The poperty of
848 // pPrintOpts is ignored there so setting it
849 // here may only lead to unwanted side effects.
853 pPrintOpts
->GetOptionsPrint().SetCutPage();
856 bContinuePrinting
= true;
862 // The user has pressed the 'Cancel' button. Restore the old values and
863 // return a flag to tell the caller to abort printing.
864 if( nRet
== RET_CANCEL
)
866 pPrinter
->SetPrinterOptions( aOldPrinterOptions
);
867 pPrinter
->SetMapMode( aOldMap
);
868 bContinuePrinting
= false;
872 return bContinuePrinting
;
878 void PrintManager::PrintOutline (
883 // Seiteneinstellungen koennen nicht fuer die Gliederung gemacht werden
884 // (also auch nicht der Druckerschacht), deswegen wird der Druckerschacht
885 // von der Seite PK_STANDARD genommen.
887 if( pPrintOpts && !pPrintOpts->GetOptionsPrint().IsPaperbin() ) // Drucken NICHT aus Druckereinstellung
889 USHORT nPaperBin = GetDoc()->GetSdPage(nPage, PK_STANDARD)->GetPaperBin();
890 rPrinter.SetPaperBin( nPaperBin );
892 // Es wird jetzt (vorlaeufig ?) der Druckerschacht vom Drucker genommen
894 const MapMode
aOldMap( rInfo
.mrPrinter
.GetMapMode() );
895 MapMode
aMap( aOldMap
);
896 const Orientation eOldOrient
= rInfo
.mrPrinter
.GetOrientation();
897 Point
aPageOfs( rInfo
.mrPrinter
.GetPageOffset() );
898 Fraction
aScale(1, 2);
899 BOOL bPrintExcluded
= TRUE
;
901 aMap
.SetOrigin(Point() - aPageOfs
);
902 aMap
.SetScaleX(aScale
);
903 aMap
.SetScaleY(aScale
);
904 rInfo
.mrPrinter
.SetMapMode(aMap
);
905 rInfo
.mrPrinter
.SetOrientation(ORIENTATION_PORTRAIT
);
907 if ( rInfo
.mpPrintOpts
)
908 bPrintExcluded
= rInfo
.mpPrintOpts
->GetOptionsPrint().IsHiddenPages();
910 Rectangle
aOutRect(aPageOfs
, rInfo
.mrPrinter
.GetOutputSize());
913 Outliner
* pOutliner
= rInfo
.mrViewShell
.GetDoc()->GetInternalOutliner();
914 pOutliner
->Init( OUTLINERMODE_OUTLINEVIEW
);
915 USHORT nOutlMode
= pOutliner
->GetMode();
916 BOOL bOldUpdateMode
= pOutliner
->GetUpdateMode();
918 Size aPaperSize
= pOutliner
->GetPaperSize();
919 pOutliner
->SetPaperSize(aOutRect
.GetSize());
920 pOutliner
->SetUpdateMode(TRUE
);
922 long nPageH
= aOutRect
.GetHeight();
924 USHORT nPageCount
= rInfo
.mnProgressOffset
;
926 while ( nPage
< rInfo
.mnPageMax
)
928 Paragraph
* pPara
= NULL
;
932 pOutliner
->SetFirstPageNumber(nPage
+1);
934 while ( nH
< nPageH
&& nPage
< rInfo
.mnPageMax
)
936 if ( rInfo
.mrSelPages
.IsSelected(nPage
+1) )
938 //rProgress.SetState( nPageCount, nTotal );
939 //rProgress.SetStateText( nPageCount, nPage+1, nTotal );
941 String aTmp
= UniString::CreateFromInt32( nPage
+1 );
942 aTmp
+= String( SdResId( STR_PRINT_OUTLINE
) );
943 rInfo
.mrProgress
.SetStateText(nPageCount
, aTmp
, rInfo
.mnTotal
);
945 nPageCount
= nPageCount
+ rInfo
.mnCopies
;
947 SdPage
* pPage
= (SdPage
*)rInfo
.mrViewShell
.GetDoc()->GetSdPage(nPage
, PK_STANDARD
);
948 SdrTextObj
* pTextObj
= NULL
;
951 if ( !pPage
->IsExcluded() || bPrintExcluded
)
953 while ( !pTextObj
&& nObj
< pPage
->GetObjCount() )
955 SdrObject
* pObj
= pPage
->GetObj(nObj
++);
956 if ( pObj
->GetObjInventor() == SdrInventor
&&
957 pObj
->GetObjIdentifier() == OBJ_TITLETEXT
)
958 pTextObj
= (SdrTextObj
*) pObj
;
961 pPara
= pOutliner
->GetParagraph( pOutliner
->GetParagraphCount() - 1 );
963 if ( pTextObj
&& !pTextObj
->IsEmptyPresObj() &&
964 pTextObj
->GetOutlinerParaObject() )
965 pOutliner
->AddText( *(pTextObj
->GetOutlinerParaObject()) );
967 pOutliner
->Insert(String());
972 while ( !pTextObj
&& nObj
< pPage
->GetObjCount() )
974 SdrObject
* pObj
= pPage
->GetObj(nObj
++);
975 if ( pObj
->GetObjInventor() == SdrInventor
&&
976 pObj
->GetObjIdentifier() == OBJ_OUTLINETEXT
)
977 pTextObj
= (SdrTextObj
*) pObj
;
980 BOOL bSubTitle
= FALSE
;
984 pTextObj
= (SdrTextObj
*) pPage
->GetPresObj(PRESOBJ_TEXT
); // Untertitel vorhanden?
987 ULONG nParaCount1
= pOutliner
->GetParagraphCount();
989 if ( pTextObj
&& !pTextObj
->IsEmptyPresObj() &&
990 pTextObj
->GetOutlinerParaObject() )
991 pOutliner
->AddText( *(pTextObj
->GetOutlinerParaObject()) );
995 ULONG nParaCount2
= pOutliner
->GetParagraphCount();
996 for (ULONG nPara
= nParaCount1
; nPara
< nParaCount2
; nPara
++)
998 Paragraph
* pP
= pOutliner
->GetParagraph(nPara
);
999 if(pP
&& pOutliner
->GetDepth( (USHORT
) nPara
) > 0 )
1000 pOutliner
->SetDepth(pP
, 0);
1004 nH
= pOutliner
->GetTextHeight();
1010 if ( nH
> nPageH
&& pPara
)
1012 ULONG nCnt
= pOutliner
->GetAbsPos( pOutliner
->GetParagraph( pOutliner
->GetParagraphCount() - 1 ) );
1013 ULONG nParaPos
= pOutliner
->GetAbsPos( pPara
);
1015 pPara
= pOutliner
->GetParagraph( ++nParaPos
);
1016 if ( nCnt
&& pPara
)
1018 pOutliner
->Remove(pPara
, nCnt
);
1023 rInfo
.mrPrinter
.StartPage();
1024 pOutliner
->Draw(&rInfo
.mrPrinter
, aOutRect
);
1026 if ( rInfo
.mrTimeDateStr
.Len() )
1028 Font aOldFont
= rInfo
.mrPrinter
.OutputDevice::GetFont();
1029 rInfo
.mrPrinter
.SetFont(rInfo
.mrTimeDateFont
);
1030 rInfo
.mrPrinter
.DrawText(aPageOfs
, rInfo
.mrTimeDateStr
);
1031 rInfo
.mrPrinter
.SetFont(aOldFont
);
1033 rInfo
.mrPrinter
.EndPage();
1035 pOutliner
->SetUpdateMode(bOldUpdateMode
);
1036 pOutliner
->SetPaperSize(aPaperSize
);
1037 pOutliner
->Init( nOutlMode
);
1039 rInfo
.mrPrinter
.SetOrientation(eOldOrient
);
1040 rInfo
.mrPrinter
.SetMapMode( aOldMap
);
1046 void PrintManager::PrintHandout( PrintInfo
& rInfo
, USHORT nPage
)
1048 SdPage
* pPage
= rInfo
.mrViewShell
.GetDoc()->GetSdPage(0, PK_HANDOUT
);
1049 SdPage
& rMaster
= (SdPage
&)pPage
->TRG_GetMasterPage();
1050 SdDrawDocument
* pDocument
= rInfo
.mrViewShell
.GetDoc();
1052 BOOL bScalePage
= TRUE
;
1053 if ( rInfo
.mpPrintOpts
)
1055 bScalePage
= rInfo
.mpPrintOpts
->GetOptionsPrint().IsPagesize();
1059 if( rInfo
.mpPrintOpts
&& !rInfo
.mpPrintOpts
->GetOptionsPrint().IsPaperbin() ) // Drucken NICHT aus Druckereinstellung
1061 USHORT nPaperBin
= pPage
->GetPaperBin();
1062 rInfo
.mrPrinter
.SetPaperBin( nPaperBin
);
1065 // Hoch/Querformat aendern?
1066 Orientation eOrientation
= rMaster
.GetOrientation();
1068 short nDlgResult
= RET_OK
;
1070 if ( !rInfo
.mrPrinter
.SetOrientation(eOrientation
) &&
1071 (!rInfo
.mpPrintOpts
|| rInfo
.mpPrintOpts
->GetOptionsPrint().IsWarningOrientation()) )
1073 // eine Warnung anzeigen
1074 WarningBox
aWarnBox(rInfo
.mrViewShell
.GetActiveWindow(),(WinBits
)(WB_OK_CANCEL
| WB_DEF_CANCEL
),
1075 String(SdResId(STR_WARN_PRINTFORMAT_FAILURE
)));
1076 nDlgResult
= aWarnBox
.Execute();
1079 if ( nDlgResult
== RET_OK
)
1081 const MapMode
aOldMap( rInfo
.mrPrinter
.GetMapMode() );
1082 MapMode
aMap( aOldMap
);
1083 Point
aPageOfs( rInfo
.mrPrinter
.GetPageOffset() );
1084 DrawView
* pPrintView
;
1085 BOOL bPrintExcluded
= TRUE
;
1087 aMap
.SetOrigin(Point() - aPageOfs
);
1091 Size
aPageSize(pPage
->GetSize());
1092 Size
aPrintSize( rInfo
.mrPrinter
.GetOutputSize() );
1094 double fHorz
= (double) aPrintSize
.Width() / aPageSize
.Width();
1095 double fVert
= (double) aPrintSize
.Height() / aPageSize
.Height();
1098 if ( fHorz
< fVert
)
1099 aFract
= Fraction(aPrintSize
.Width(), aPageSize
.Width());
1101 aFract
= Fraction(aPrintSize
.Height(), aPageSize
.Height());
1103 aMap
.SetScaleX(aFract
);
1104 aMap
.SetScaleY(aFract
);
1105 aMap
.SetOrigin(Point());
1108 rInfo
.mrPrinter
.SetMapMode(aMap
);
1110 if (rInfo
.mrViewShell
.ISA(DrawViewShell
))
1111 pPrintView
= new DrawView (rInfo
.mrViewShell
.GetDocSh(), &rInfo
.mrPrinter
,
1112 static_cast<DrawViewShell
*>(&rInfo
.mrViewShell
));
1114 pPrintView
= new DrawView (rInfo
.mrViewShell
.GetDocSh(), &rInfo
.mrPrinter
, NULL
);
1116 USHORT nPageCount
= rInfo
.mnProgressOffset
;
1118 rInfo
.mrViewShell
.WriteFrameViewData();
1120 rInfo
.mrViewShell
.SetPrintedHandoutPageNum(0);
1122 if ( rInfo
.mpPrintOpts
)
1123 bPrintExcluded
= rInfo
.mpPrintOpts
->GetOptionsPrint().IsHiddenPages();
1125 std::vector
< SdPage
* > aPagesVector
;
1126 while ( nPage
< rInfo
.mnPageMax
)
1129 if( rInfo
.mrSelPages
.IsSelected(nPage
) )
1131 SdPage
* pTemp
= pDocument
->GetSdPage(nPage
-1, PK_STANDARD
);
1132 if( !pTemp
->IsExcluded() || bPrintExcluded
)
1133 aPagesVector
.push_back( pTemp
);
1137 std::vector
< SdrPageObj
* > aPageObjVector
;
1138 SdrObjListIter
aShapeIter( *pPage
);
1139 while( aShapeIter
.IsMore() )
1141 SdrPageObj
* pPageObj
= dynamic_cast< SdrPageObj
* >(aShapeIter
.Next());
1143 aPageObjVector
.push_back( pPageObj
);
1146 if( aPageObjVector
.empty() )
1149 rInfo
.mrViewShell
.SetPrintedHandoutPageCount( (USHORT
)((aPagesVector
.size() + aPageObjVector
.size() - 1) / aPageObjVector
.size()) );
1152 sal_Int32 nHandoutPageCount = aPagesVector.size() / aPageObjVector.size();
1153 sal_Int32 nHandoutPage = 0;
1155 std::vector
< SdPage
* >::iterator
aPageIter( aPagesVector
.begin() );
1156 while( aPageIter
!= aPagesVector
.end() )
1158 std::vector
< SdrPageObj
* >::iterator
aPageObjIter( aPageObjVector
.begin() );
1160 while( (aPageObjIter
!= aPageObjVector
.end()) && (aPageIter
!= aPagesVector
.end()) )
1162 SdrPageObj
* pPageObj
= (*aPageObjIter
++);
1163 pPageObj
->SetReferencedPage( (*aPageIter
++) );
1166 // if there are more page objects than pages left, set the rest to invisible
1167 int nHangoverCount
= 0;
1168 while(aPageObjIter
!= aPageObjVector
.end())
1170 (*aPageObjIter
++)->SetReferencedPage(0L);
1174 if( nHangoverCount
)
1176 int nSkip
= aPageObjVector
.size() - nHangoverCount
;
1178 while( aShapeIter
.IsMore() )
1180 SdrPathObj
* pPathObj
= dynamic_cast< SdrPathObj
* >( aShapeIter
.Next() );
1189 pPathObj
->SetMergedItem( XLineStyleItem(XLINE_NONE
) );
1196 String aTmp
= UniString::CreateFromInt32( nPage
);
1197 aTmp
+= String( SdResId( STR_PRINT_HANDOUT
) );
1198 rInfo
.mrProgress
.SetStateText( nPageCount
, aTmp
, rInfo
.mnTotal
);
1200 rInfo
.mrViewShell
.SetPrintedHandoutPageNum(rInfo
.mrViewShell
.GetPrintedHandoutPageNum() + 1);
1202 rInfo
.mrPrinter
.StartPage();
1203 pPrintView
->ShowSdrPage(pPage
); // , Point());
1205 SdrPageView
* pPageView
= pPrintView
->GetSdrPageView(); // pPage);
1206 pPageView
->SetVisibleLayers(rInfo
.mrViewShell
.GetFrameView()->GetVisibleLayers() );
1207 pPageView
->SetPrintableLayers(rInfo
.mrViewShell
.GetFrameView()->GetPrintableLayers() );
1209 pPrintView
->CompleteRedraw(&rInfo
.mrPrinter
, Rectangle(Point(0,0), pPage
->GetSize()));
1211 if ( rInfo
.mrTimeDateStr
.Len() )
1213 Font aOldFont
= rInfo
.mrPrinter
.OutputDevice::GetFont();
1214 rInfo
.mrPrinter
.SetFont(rInfo
.mrTimeDateFont
);
1215 rInfo
.mrPrinter
.DrawText(aPageOfs
, rInfo
.mrTimeDateStr
);
1216 rInfo
.mrPrinter
.SetFont(aOldFont
);
1218 rInfo
.mrPrinter
.EndPage();
1219 pPrintView
->HideSdrPage(); // pPrintView->GetPageView(pPage));
1221 if( nHangoverCount
)
1224 while( aShapeIter
.IsMore() )
1226 SdrPathObj
* pPathObj
= dynamic_cast< SdrPathObj
* >( aShapeIter
.Next() );
1228 pPathObj
->SetMergedItem( XLineStyleItem(XLINE_SOLID
) );
1234 rInfo
.mrViewShell
.SetPrintedHandoutPageNum(1);
1235 rInfo
.mrViewShell
.SetPrintedHandoutPageCount(0);
1237 rInfo
.mrPrinter
.SetMapMode(aOldMap
);
1244 void PrintManager::PrintStdOrNotes (
1248 BOOL bPrintMarkedOnly
)
1251 BOOL bScalePage
= TRUE
;
1252 BOOL bTilePage
= FALSE
;
1253 BOOL bPrintExcluded
= TRUE
;
1254 BOOL bPrintPageName
= TRUE
;
1255 BOOL bPrintBooklet
= FALSE
;
1256 BOOL bPrintFrontPage
= FALSE
;
1257 BOOL bPrintBackPage
= FALSE
;
1258 SdDrawDocument
* pDocument
= rInfo
.mrViewShell
.GetDoc();
1260 SdPage
* pRefPage
= pDocument
->GetSdPage(nPage
, ePageKind
);
1262 if ( rInfo
.mpPrintOpts
)
1264 bScalePage
= rInfo
.mpPrintOpts
->GetOptionsPrint().IsPagesize();
1265 bTilePage
= rInfo
.mpPrintOpts
->GetOptionsPrint().IsPagetile();
1266 bPrintPageName
= rInfo
.mpPrintOpts
->GetOptionsPrint().IsPagename();
1267 bPrintExcluded
= rInfo
.mpPrintOpts
->GetOptionsPrint().IsHiddenPages();
1268 bPrintBooklet
= rInfo
.mpPrintOpts
->GetOptionsPrint().IsBooklet();
1269 bPrintFrontPage
= rInfo
.mpPrintOpts
->GetOptionsPrint().IsFrontPage();
1270 bPrintBackPage
= rInfo
.mpPrintOpts
->GetOptionsPrint().IsBackPage();
1273 if( !rInfo
.mpPrintOpts
->GetOptionsPrint().IsPaperbin() ) // Drucken NICHT aus Druckereinstellung
1275 USHORT nPaperBin
= pDocument
->GetSdPage(nPage
, ePageKind
)->GetPaperBin();
1276 rInfo
.mrPrinter
.SetPaperBin( nPaperBin
);
1281 // Hoch/Querformat aendern?
1282 Size
aPageSize(pRefPage
->GetSize());
1283 Orientation eOrientation
= ORIENTATION_PORTRAIT
;
1285 short nDlgResult
= RET_OK
;
1287 if( !bPrintBooklet
)
1289 eOrientation
= pRefPage
->GetOrientation();
1291 else if( aPageSize
.Width() < aPageSize
.Height() )
1292 eOrientation
= ORIENTATION_LANDSCAPE
;
1294 if ( !rInfo
.mrPrinter
.SetOrientation(eOrientation
) &&
1295 (!rInfo
.mpPrintOpts
|| rInfo
.mpPrintOpts
->GetOptionsPrint().IsWarningOrientation()) )
1297 // eine Warnung anzeigen
1298 WarningBox
aWarnBox(
1299 rInfo
.mrViewShell
.GetActiveWindow(),
1300 (WinBits
)(WB_OK_CANCEL
| WB_DEF_CANCEL
),
1301 String(SdResId(STR_WARN_PRINTFORMAT_FAILURE
)));
1302 nDlgResult
= aWarnBox
.Execute();
1305 if ( nDlgResult
== RET_OK
)
1307 const MapMode
aOldMap( rInfo
.mrPrinter
.GetMapMode() );
1308 MapMode
aMap( aOldMap
);
1309 Point
aPageOfs( rInfo
.mrPrinter
.GetPageOffset() );
1310 DrawView
* pPrintView
;
1312 aMap
.SetOrigin(Point() - aPageOfs
);
1313 rInfo
.mrPrinter
.SetMapMode(aMap
);
1314 Size
aPrintSize( rInfo
.mrPrinter
.GetOutputSize() );
1316 if (rInfo
.mrViewShell
.ISA(DrawViewShell
))
1317 pPrintView
= new DrawView (rInfo
.mrViewShell
.GetDocSh(), &rInfo
.mrPrinter
,
1318 static_cast<DrawViewShell
*>(&rInfo
.mrViewShell
));
1320 pPrintView
= new DrawView (rInfo
.mrViewShell
.GetDocSh(), &rInfo
.mrPrinter
, NULL
);
1322 USHORT nPageCount
= rInfo
.mnProgressOffset
;
1324 // Als Broschuere drucken ?
1327 MapMode
aStdMap( rInfo
.mrPrinter
.GetMapMode() );
1328 ::std::vector
< USHORT
> aPageVector
;
1329 ::std::vector
< ::std::pair
< USHORT
, USHORT
> > aPairVector
;
1331 Size
aPrintSize_2( aPrintSize
);
1332 Size
aPageSize_2( aPageSize
);
1334 if( eOrientation
== ORIENTATION_LANDSCAPE
)
1335 aPrintSize_2
.Width() >>= 1;
1337 aPrintSize_2
.Height() >>= 1;
1339 const double fPageWH
= (double) aPageSize_2
.Width() / aPageSize_2
.Height();
1340 const double fPrintWH
= (double) aPrintSize_2
.Width() / aPrintSize_2
.Height();
1342 if( fPageWH
< fPrintWH
)
1344 aPageSize_2
.Width() = (long) ( aPrintSize_2
.Height() * fPageWH
);
1345 aPageSize_2
.Height()= aPrintSize_2
.Height();
1349 aPageSize_2
.Width() = aPrintSize_2
.Width();
1350 aPageSize_2
.Height() = (long) ( aPrintSize_2
.Width() / fPageWH
);
1353 aMap
.SetScaleX( Fraction( aPageSize_2
.Width(), aPageSize
.Width() ) );
1354 aMap
.SetScaleY( Fraction( aPageSize_2
.Height(), aPageSize
.Height() ) );
1356 // calculate adjusted print size
1357 aPrintSize
= OutputDevice::LogicToLogic( aPrintSize
, aStdMap
, aMap
);
1359 if( eOrientation
== ORIENTATION_LANDSCAPE
)
1361 aOffset
.X() = ( ( aPrintSize
.Width() >> 1 ) - aPageSize
.Width() ) >> 1;
1362 aOffset
.Y() = ( aPrintSize
.Height() - aPageSize
.Height() ) >> 1;
1366 aOffset
.X() = ( aPrintSize
.Width() - aPageSize
.Width() ) >> 1;
1367 aOffset
.Y() = ( ( aPrintSize
.Height() >> 1 ) - aPageSize
.Height() ) >> 1;
1370 // create vector of pages to print
1371 while( nPage
< rInfo
.mnPageMax
)
1373 if( rInfo
.mrSelPages
.IsSelected( nPage
+ 1 ) )
1375 SdPage
* pP
= pDocument
->GetSdPage( nPage
, ePageKind
);
1377 if( pP
&& ( !pP
->IsExcluded() || bPrintExcluded
) )
1378 aPageVector
.push_back( nPage
);
1384 // create pairs of pages to print on each page
1385 if( aPageVector
.size() )
1387 sal_uInt32 nFirstIndex
= 0, nLastIndex
= aPageVector
.size() - 1;
1389 if( aPageVector
.size() & 1 )
1390 aPairVector
.push_back( ::std::make_pair( (USHORT
) 65535, aPageVector
[ nFirstIndex
++ ] ) );
1392 aPairVector
.push_back( ::std::make_pair( aPageVector
[ nLastIndex
-- ], aPageVector
[ nFirstIndex
++ ] ) );
1394 while( nFirstIndex
< nLastIndex
)
1396 if( nFirstIndex
& 1 )
1397 aPairVector
.push_back( ::std::make_pair( aPageVector
[ nFirstIndex
++ ], aPageVector
[ nLastIndex
-- ] ) );
1399 aPairVector
.push_back( ::std::make_pair( aPageVector
[ nLastIndex
-- ], aPageVector
[ nFirstIndex
++ ] ) );
1403 for( sal_uInt32 i
= 0; i
< aPairVector
.size(); i
++ )
1405 if( ( !( i
& 1 ) && bPrintFrontPage
) || ( ( i
& 1 ) && bPrintBackPage
) )
1407 const ::std::pair
< USHORT
, USHORT
> aPair( aPairVector
[ i
] );
1409 rInfo
.mrPrinter
.StartPage();
1411 SdPage
* pPageToPrint
= pDocument
->GetSdPage( aPair
.first
, ePageKind
);
1415 aMap
.SetOrigin( aOffset
);
1416 rInfo
.mrPrinter
.SetMapMode( aMap
);
1417 PrintPage(rInfo
, pPrintView
, pPageToPrint
, bPrintMarkedOnly
);
1420 pPageToPrint
= pDocument
->GetSdPage( aPair
.second
, ePageKind
);
1424 Point
aSecondOffset( aOffset
);
1426 if( eOrientation
== ORIENTATION_LANDSCAPE
)
1427 aSecondOffset
.X() += ( aPrintSize
.Width() >> 1 );
1429 aSecondOffset
.Y() += ( aPrintSize
.Height() >> 1 );
1431 aMap
.SetOrigin( aSecondOffset
);
1432 rInfo
.mrPrinter
.SetMapMode( aMap
);
1433 PrintPage(rInfo
, pPrintView
, pPageToPrint
, bPrintMarkedOnly
);
1436 rInfo
.mrPrinter
.EndPage();
1440 rInfo
.mrPrinter
.SetMapMode( aStdMap
);
1444 rInfo
.mrViewShell
.WriteFrameViewData();
1447 while ( nPage
< rInfo
.mnPageMax
)
1449 if (rInfo
.mrSelPages
.IsSelected(nPage
+1) )
1451 SdPage
* pPage
= pDocument
->GetSdPage(nPage
, ePageKind
);
1452 // Kann sich die Seitengroesse geaendert haben?
1453 aPageSize
= pPage
->GetSize();
1455 rInfo
.mrProgress
.SetState( nPageCount
, rInfo
.mnTotal
);
1456 nPageCount
= nPageCount
+ rInfo
.mnCopies
;
1460 double fHorz
= (double) aPrintSize
.Width() / aPageSize
.Width();
1461 double fVert
= (double) aPrintSize
.Height() / aPageSize
.Height();
1463 if ( fHorz
< fVert
)
1464 aFract
= Fraction(aPrintSize
.Width(), aPageSize
.Width());
1466 aFract
= Fraction(aPrintSize
.Height(), aPageSize
.Height());
1468 aMap
.SetScaleX(aFract
);
1469 aMap
.SetScaleY(aFract
);
1470 aMap
.SetOrigin(Point());
1473 if ( !pPage
->IsExcluded() || bPrintExcluded
)
1475 String aTmp
= UniString::CreateFromInt32( nPage
+1 );
1477 if(ePageKind
== PK_NOTES
)
1478 aTmp
+= String( SdResId( STR_PRINT_NOTES
) );
1480 aTmp
+= String( SdResId( STR_PRINT_DRAWING
) );
1481 rInfo
.mrProgress
.SetStateText( nPageCount
, aTmp
, rInfo
.mnTotal
);
1484 if ( bPrintPageName
)
1486 aPageStr
= pPage
->GetName();
1487 aPageStr
+= (sal_Unicode
)' ';
1489 aPageStr
+= rInfo
.mrTimeDateStr
;
1491 MapMode aStdMap
= rInfo
.mrPrinter
.GetMapMode();
1492 rInfo
.mrPrinter
.SetMapMode(aMap
);
1497 long aPageWidth
= aPageSize
.Width() - pPage
->GetLftBorder() - pPage
->GetRgtBorder();
1498 long aPageHeight
= aPageSize
.Height() - pPage
->GetUppBorder() - pPage
->GetLwrBorder();
1499 long aPrintWidth
= aPrintSize
.Width();
1500 long aPrintHeight
= aPrintSize
.Height();
1503 // Falls implizit umgestellt wurde (Landscape/Portrait)
1504 // wird dies beim Kacheln, bzw. aufteilen (Poster) beruecksichtigt
1505 BOOL bSwitchPageSize
= FALSE
;
1506 if( ( aPrintWidth
> aPrintHeight
&& aPageWidth
< aPageHeight
) ||
1507 ( aPrintWidth
< aPrintHeight
&& aPageWidth
> aPageHeight
) )
1509 bSwitchPageSize
= TRUE
;
1510 aPrintWidth
= aPrintSize
.Height();
1511 aPrintHeight
= aPrintSize
.Width();
1514 // Eine (kleine) Seite, die gekachelt ausgegeben werden soll
1516 aPageWidth
< aPrintWidth
&&
1517 aPageHeight
< aPrintHeight
)
1523 rInfo
.mrPrinter
.StartPage();
1524 pPrintView
->ShowSdrPage( pPage
);
1526 SdrPageView
* pPageView
= pPrintView
->GetSdrPageView(); // pPage);
1527 pPageView
->SetVisibleLayers(rInfo
.mrViewShell
.GetFrameView()->GetVisibleLayers() );
1528 pPageView
->SetPrintableLayers(rInfo
.mrViewShell
.GetFrameView()->GetPrintableLayers() );
1530 long nPagesPrinted
= 0; // Fuer Bedingung s.u.
1531 BOOL bPrintPage
; // Fuer Bedingung s.u.
1535 BOOL bWidth
= aPageWidth
< aPrintWidth
;
1536 BOOL bHeight
= aPageHeight
< aPrintHeight
;
1537 if( !bWidth
&& !bHeight
)
1540 // Etwas umstaendliche Abfrage, die ausdrueckt, ob eine Seite
1541 // beim Kacheln abgeschnitten oder gar nicht dargestellt werden
1542 // soll. Die Bedingung ist, dass eine 2. Seite (horz. oder vert.)
1543 // immer gedruck wird, waehrend eine dritte Seite (oder hoeher)
1544 // nur noch gedruckt wird, wenn diese auch noch vollstaendig
1545 // aufs Papier passt.
1546 if( nPagesPrinted
< 4 && !( !bWidth
&& nPagesPrinted
== 2 ) )
1552 if( ( bWidth
&& bHeight
) || bPrintPage
)
1554 aStdMap
.SetOrigin( aPrintOrigin
);
1555 rInfo
.mrPrinter
.SetMapMode( aStdMap
);
1557 if (rInfo
.mrViewShell
.ISA(DrawViewShell
) && bPrintMarkedOnly
)
1559 rInfo
.mrViewShell
.GetView()->DrawMarkedObj(rInfo
.mrPrinter
);
1562 pPrintView
->CompleteRedraw( &rInfo
.mrPrinter
, Rectangle( aPtZero
, aPageSize
) );
1566 aPrintOrigin
.X() += aPageWidth
;
1567 aPrintWidth
-= aPageWidth
;
1571 aPrintOrigin
.X() = 0;
1572 aPrintWidth
= bSwitchPageSize
? aPrintSize
.Height() : aPrintSize
.Width();
1573 aPrintOrigin
.Y() += aPageHeight
;
1574 aPrintHeight
-= aPageHeight
;
1578 if ( aPageStr
.Len() )
1580 Font aOldFont
= rInfo
.mrPrinter
.OutputDevice::GetFont();
1581 rInfo
.mrPrinter
.SetFont(rInfo
.mrTimeDateFont
);
1582 rInfo
.mrPrinter
.DrawText(aPageOfs
, aPageStr
);
1583 rInfo
.mrPrinter
.SetFont(aOldFont
);
1585 rInfo
.mrPrinter
.EndPage();
1586 pPrintView
->HideSdrPage(); // pPrintView->GetPageView(pPage));
1591 // For pages larger then the printable area there
1592 // are three options:
1593 // 1. Scale down to the page to the printable area.
1594 // 2. Print only the upper left part of the page
1595 // (without the unprintable borders).
1596 // 3. Split the page into parts of the size of the
1600 const bool bCutPage (rInfo
.mpPrintOpts
&& rInfo
.mpPrintOpts
->GetOptionsPrint().IsCutPage());
1601 if (bScalePage
|| bCutPage
)
1605 // if CutPage is set then do not move
1606 // it, otherwise move the scaled page
1607 // to printable area
1613 bCutPage
? Point(-aPageOfs
.X(), -aPageOfs
.Y()) : Point(0,0),
1622 // if the printable area is bigger than page size, center the page
1623 if( aPageSize
.Width() < aPrintWidth
)
1624 aOrigin
.X() = ( aPrintWidth
- aPageSize
.Width() )/2;
1625 if( aPageSize
.Height() < aPrintHeight
)
1626 aOrigin
.Y() = ( aPrintHeight
- aPageSize
.Height() )/2;
1628 // Handle 3. Print parts of the page in the
1629 // size of the printable area until the
1630 // whole page is covered.
1632 for (aPageOrigin
= aOrigin
;
1633 -aPageOrigin
.Y()<aPageHeight
;
1634 aPageOrigin
.Y() -= aPrintHeight
)
1636 for (aPageOrigin
.X()=aOrigin
.X();
1637 -aPageOrigin
.X()<aPageWidth
;
1638 aPageOrigin
.X() -= aPrintWidth
)
1659 rInfo
.mrPrinter
.SetMapMode( aOldMap
);
1666 void PrintManager::PrintPagePart (
1669 DrawView
& rPrintView
,
1670 const Point
& rPageOrigin
,
1671 BOOL bPrintMarkedOnly
,
1672 const String
& rsPageString
,
1673 const Point
& rStringOffset
)
1675 rInfo
.mrPrinter
.StartPage();
1676 rPrintView
.ShowSdrPage(pPage
); // , Point(0,0));
1678 // Set origin of the map mode so that the next part of the page is
1680 MapMode aOriginalMapMode
= rInfo
.mrPrinter
.GetMapMode();
1681 MapMode aMapMode
= rInfo
.mrPrinter
.GetMapMode();
1682 aMapMode
.SetOrigin(rPageOrigin
);
1683 rInfo
.mrPrinter
.SetMapMode(aMapMode
);
1685 SdrPageView
* pPageView
= rPrintView
.GetSdrPageView(); // pPage);
1686 pPageView
->SetVisibleLayers(rInfo
.mrViewShell
.GetFrameView()->GetVisibleLayers() );
1687 pPageView
->SetPrintableLayers(rInfo
.mrViewShell
.GetFrameView()->GetPrintableLayers() );
1689 if (rInfo
.mrViewShell
.ISA(DrawViewShell
) && bPrintMarkedOnly
)
1690 rInfo
.mrViewShell
.GetView()->DrawMarkedObj(rInfo
.mrPrinter
);
1692 rPrintView
.CompleteRedraw(&rInfo
.mrPrinter
, Rectangle(Point(0,0), pPage
->GetSize()));
1693 rInfo
.mrPrinter
.SetMapMode(aOriginalMapMode
);
1695 if (rsPageString
.Len())
1697 Font aOldFont
= rInfo
.mrPrinter
.OutputDevice::GetFont();
1698 rInfo
.mrPrinter
.SetFont(rInfo
.mrTimeDateFont
);
1699 rInfo
.mrPrinter
.DrawText(rStringOffset
, rsPageString
);
1700 rInfo
.mrPrinter
.SetFont(aOldFont
);
1702 rInfo
.mrPrinter
.EndPage();
1703 rPrintView
.HideSdrPage(); // rPrintView.GetPageView(pPage));
1710 void PrintManager::PrintPage (
1712 ::sd::View
* pPrintView
,
1714 BOOL bPrintMarkedOnly
)
1717 pPrintView
->ShowSdrPage( pPage
); // , aPtZero );
1719 SdrPageView
* pPageView
= pPrintView
->GetSdrPageView(); // pPage );
1720 pPageView
->SetVisibleLayers(rInfo
.mrViewShell
.GetFrameView()->GetVisibleLayers() );
1721 pPageView
->SetPrintableLayers(rInfo
.mrViewShell
.GetFrameView()->GetPrintableLayers() );
1723 if (rInfo
.mrViewShell
.ISA(DrawViewShell
) && bPrintMarkedOnly
)
1724 rInfo
.mrViewShell
.GetView()->DrawMarkedObj(rInfo
.mrPrinter
);
1726 pPrintView
->CompleteRedraw(&rInfo
.mrPrinter
, Rectangle(Point(0,0), pPage
->GetSize()));
1728 pPrintView
->HideSdrPage(); // pPrintView->GetPageView( pPage ) );
1734 bool PrintManager::IsScreenFormat (void)
1736 // Determine the page size.
1737 SdPage
* pPage
= mrBase
.GetDocument()->GetSdPage(0, PK_STANDARD
);
1738 Size
aPaperSize (pPage
->GetSize());
1740 // Take Orientation into account.
1741 if (pPage
->GetOrientation() == ORIENTATION_LANDSCAPE
)
1744 // Check whether paper size is 'Screen'
1745 Paper
ePaper(SvxPaperInfo::GetSvxPaper(aPaperSize
, MAP_100TH_MM
, TRUE
));
1746 return (ePaper
== PAPER_SCREEN
);
1750 void PrintManager::InitHandoutTemplate( PrintInfo
& /*rInfo*/, USHORT nSlidesPerHandout
, BOOL bHandoutHorizontal
)
1752 AutoLayout eLayout
= AUTOLAYOUT_HANDOUT6
;
1753 switch( nSlidesPerHandout
)
1755 case 1: eLayout
= AUTOLAYOUT_HANDOUT1
; break;
1756 case 2: eLayout
= AUTOLAYOUT_HANDOUT2
; break;
1757 case 3: eLayout
= AUTOLAYOUT_HANDOUT3
; break;
1758 case 4: eLayout
= AUTOLAYOUT_HANDOUT4
; break;
1759 case 9: eLayout
= AUTOLAYOUT_HANDOUT9
; break;
1762 if( !mrBase
.GetDocument() )
1765 SdDrawDocument
& rModel
= *mrBase
.GetDocument();
1767 // first, prepare handout page (not handout master)
1769 SdPage
* pHandout
= rModel
.GetSdPage(0, PK_HANDOUT
);
1773 // delete all previous shapes from handout page
1774 while( pHandout
->GetObjCount() )
1776 SdrObject
* pObj
= pHandout
->NbcRemoveObject(0);
1778 SdrObject::Free( pObj
);
1781 const bool bDrawLines
= eLayout
== AUTOLAYOUT_HANDOUT3
;
1783 std::vector
< Rectangle
> aAreas
;
1784 SdPage::CalculateHandoutAreas( rModel
, eLayout
, bHandoutHorizontal
, aAreas
);
1786 std::vector
< Rectangle
>::iterator
iter( aAreas
.begin() );
1787 while( iter
!= aAreas
.end() )
1789 pHandout
->NbcInsertObject( new SdrPageObj((*iter
++)) );
1791 if( bDrawLines
&& (iter
!= aAreas
.end()) )
1793 Rectangle
aRect( (*iter
++) );
1795 basegfx::B2DPolygon aPoly
;
1796 aPoly
.insert(0, basegfx::B2DPoint( aRect
.Left(), aRect
.Top() ) );
1797 aPoly
.insert(1, basegfx::B2DPoint( aRect
.Right(), aRect
.Top() ) );
1799 basegfx::B2DHomMatrix aMatrix
;
1800 aMatrix
.translate( 0.0, static_cast< double >( aRect
.GetHeight() / 7 ) );
1802 basegfx::B2DPolyPolygon aPathPoly
;
1803 for( sal_uInt16 nLine
= 0; nLine
< 7; nLine
++ )
1805 aPoly
.transform( aMatrix
);
1806 aPathPoly
.append( aPoly
);
1809 SdrPathObj
* pPathObj
= new SdrPathObj(OBJ_PATHLINE
, aPathPoly
);
1810 pPathObj
->SetMergedItem( XLineStyleItem(XLINE_SOLID
) );
1811 pPathObj
->SetMergedItem( XLineColorItem(String(), Color(COL_BLACK
)));
1813 pHandout
->NbcInsertObject( pPathObj
);
1818 } // end of namespace sd