xref: /aoo41x/main/vcl/source/gdi/oldprintadaptor.cxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 
28 #include "precompiled_vcl.hxx"
29 
30 #include "vcl/oldprintadaptor.hxx"
31 #include "vcl/gdimtf.hxx"
32 
33 #include "com/sun/star/awt/Size.hpp"
34 
35 #include <vector>
36 
37 namespace vcl
38 {
39     struct AdaptorPage
40     {
41         GDIMetaFile                     maPage;
42         com::sun::star::awt::Size       maPageSize;
43     };
44 
45     struct ImplOldStyleAdaptorData
46     {
47         std::vector< AdaptorPage >  maPages;
48     };
49 }
50 
51 using namespace vcl;
52 using namespace cppu;
53 using namespace com::sun::star;
54 using namespace com::sun::star::uno;
55 using namespace com::sun::star::beans;
56 
57 OldStylePrintAdaptor::OldStylePrintAdaptor( const boost::shared_ptr< Printer >& i_pPrinter )
58     : PrinterController( i_pPrinter )
59     , mpData( new ImplOldStyleAdaptorData() )
60 {
61 }
62 
63 OldStylePrintAdaptor::~OldStylePrintAdaptor()
64 {
65 }
66 
67 void OldStylePrintAdaptor::StartPage()
68 {
69     Size aPaperSize( getPrinter()->PixelToLogic( getPrinter()->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) ) );
70     mpData->maPages.push_back( AdaptorPage() );
71     mpData->maPages.back().maPageSize.Width = aPaperSize.getWidth();
72     mpData->maPages.back().maPageSize.Height = aPaperSize.getHeight();
73     getPrinter()->SetConnectMetaFile( &mpData->maPages.back().maPage );
74 
75     // copy state into metafile
76     boost::shared_ptr<Printer> pPrinter( getPrinter() );
77     pPrinter->SetMapMode( pPrinter->GetMapMode() );
78     pPrinter->SetFont( pPrinter->GetFont() );
79     pPrinter->SetDrawMode( pPrinter->GetDrawMode() );
80     pPrinter->SetLineColor( pPrinter->GetLineColor() );
81     pPrinter->SetFillColor( pPrinter->GetFillColor() );
82 }
83 
84 void OldStylePrintAdaptor::EndPage()
85 {
86     getPrinter()->SetConnectMetaFile( NULL );
87     mpData->maPages.back().maPage.WindStart();
88 }
89 
90 int  OldStylePrintAdaptor::getPageCount() const
91 {
92     return int(mpData->maPages.size());
93 }
94 
95 Sequence< PropertyValue > OldStylePrintAdaptor::getPageParameters( int i_nPage ) const
96 {
97     Sequence< PropertyValue > aRet( 1 );
98     aRet[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageSize") );
99     if( i_nPage < int(mpData->maPages.size() ) )
100         aRet[0].Value = makeAny( mpData->maPages[i_nPage].maPageSize );
101     else
102     {
103         awt::Size aEmpty( 0, 0  );
104         aRet[0].Value = makeAny( aEmpty );
105     }
106     return aRet;
107 }
108 
109 void OldStylePrintAdaptor::printPage( int i_nPage ) const
110 {
111     if( i_nPage < int(mpData->maPages.size()) )
112    {
113        mpData->maPages[ i_nPage ].maPage.WindStart();
114        mpData->maPages[ i_nPage ].maPage.Play( getPrinter().get() );
115    }
116 }
117 
118