xref: /aoo41x/main/vcl/source/gdi/oldprintadaptor.cxx (revision 9f62ea84)
1*9f62ea84SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*9f62ea84SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*9f62ea84SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*9f62ea84SAndrew Rist  * distributed with this work for additional information
6*9f62ea84SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*9f62ea84SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*9f62ea84SAndrew Rist  * "License"); you may not use this file except in compliance
9*9f62ea84SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*9f62ea84SAndrew Rist  *
11*9f62ea84SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*9f62ea84SAndrew Rist  *
13*9f62ea84SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*9f62ea84SAndrew Rist  * software distributed under the License is distributed on an
15*9f62ea84SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*9f62ea84SAndrew Rist  * KIND, either express or implied.  See the License for the
17*9f62ea84SAndrew Rist  * specific language governing permissions and limitations
18*9f62ea84SAndrew Rist  * under the License.
19*9f62ea84SAndrew Rist  *
20*9f62ea84SAndrew Rist  *************************************************************/
21*9f62ea84SAndrew Rist 
22*9f62ea84SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #include "precompiled_vcl.hxx"
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "vcl/oldprintadaptor.hxx"
27cdf0e10cSrcweir #include "vcl/gdimtf.hxx"
28cdf0e10cSrcweir 
29cdf0e10cSrcweir #include "com/sun/star/awt/Size.hpp"
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <vector>
32cdf0e10cSrcweir 
33cdf0e10cSrcweir namespace vcl
34cdf0e10cSrcweir {
35cdf0e10cSrcweir     struct AdaptorPage
36cdf0e10cSrcweir     {
37cdf0e10cSrcweir         GDIMetaFile                     maPage;
38cdf0e10cSrcweir         com::sun::star::awt::Size       maPageSize;
39cdf0e10cSrcweir     };
40cdf0e10cSrcweir 
41cdf0e10cSrcweir     struct ImplOldStyleAdaptorData
42cdf0e10cSrcweir     {
43cdf0e10cSrcweir         std::vector< AdaptorPage >  maPages;
44cdf0e10cSrcweir     };
45cdf0e10cSrcweir }
46cdf0e10cSrcweir 
47cdf0e10cSrcweir using namespace vcl;
48cdf0e10cSrcweir using namespace cppu;
49cdf0e10cSrcweir using namespace com::sun::star;
50cdf0e10cSrcweir using namespace com::sun::star::uno;
51cdf0e10cSrcweir using namespace com::sun::star::beans;
52cdf0e10cSrcweir 
OldStylePrintAdaptor(const boost::shared_ptr<Printer> & i_pPrinter)53cdf0e10cSrcweir OldStylePrintAdaptor::OldStylePrintAdaptor( const boost::shared_ptr< Printer >& i_pPrinter )
54cdf0e10cSrcweir     : PrinterController( i_pPrinter )
55cdf0e10cSrcweir     , mpData( new ImplOldStyleAdaptorData() )
56cdf0e10cSrcweir {
57cdf0e10cSrcweir }
58cdf0e10cSrcweir 
~OldStylePrintAdaptor()59cdf0e10cSrcweir OldStylePrintAdaptor::~OldStylePrintAdaptor()
60cdf0e10cSrcweir {
61cdf0e10cSrcweir }
62cdf0e10cSrcweir 
StartPage()63cdf0e10cSrcweir void OldStylePrintAdaptor::StartPage()
64cdf0e10cSrcweir {
65cdf0e10cSrcweir     Size aPaperSize( getPrinter()->PixelToLogic( getPrinter()->GetPaperSizePixel(), MapMode( MAP_100TH_MM ) ) );
66cdf0e10cSrcweir     mpData->maPages.push_back( AdaptorPage() );
67cdf0e10cSrcweir     mpData->maPages.back().maPageSize.Width = aPaperSize.getWidth();
68cdf0e10cSrcweir     mpData->maPages.back().maPageSize.Height = aPaperSize.getHeight();
69cdf0e10cSrcweir     getPrinter()->SetConnectMetaFile( &mpData->maPages.back().maPage );
70cdf0e10cSrcweir 
71cdf0e10cSrcweir     // copy state into metafile
72cdf0e10cSrcweir     boost::shared_ptr<Printer> pPrinter( getPrinter() );
73cdf0e10cSrcweir     pPrinter->SetMapMode( pPrinter->GetMapMode() );
74cdf0e10cSrcweir     pPrinter->SetFont( pPrinter->GetFont() );
75cdf0e10cSrcweir     pPrinter->SetDrawMode( pPrinter->GetDrawMode() );
76cdf0e10cSrcweir     pPrinter->SetLineColor( pPrinter->GetLineColor() );
77cdf0e10cSrcweir     pPrinter->SetFillColor( pPrinter->GetFillColor() );
78cdf0e10cSrcweir }
79cdf0e10cSrcweir 
EndPage()80cdf0e10cSrcweir void OldStylePrintAdaptor::EndPage()
81cdf0e10cSrcweir {
82cdf0e10cSrcweir     getPrinter()->SetConnectMetaFile( NULL );
83cdf0e10cSrcweir     mpData->maPages.back().maPage.WindStart();
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
getPageCount() const86cdf0e10cSrcweir int  OldStylePrintAdaptor::getPageCount() const
87cdf0e10cSrcweir {
88cdf0e10cSrcweir     return int(mpData->maPages.size());
89cdf0e10cSrcweir }
90cdf0e10cSrcweir 
getPageParameters(int i_nPage) const91cdf0e10cSrcweir Sequence< PropertyValue > OldStylePrintAdaptor::getPageParameters( int i_nPage ) const
92cdf0e10cSrcweir {
93cdf0e10cSrcweir     Sequence< PropertyValue > aRet( 1 );
94cdf0e10cSrcweir     aRet[0].Name = rtl::OUString( RTL_CONSTASCII_USTRINGPARAM("PageSize") );
95cdf0e10cSrcweir     if( i_nPage < int(mpData->maPages.size() ) )
96cdf0e10cSrcweir         aRet[0].Value = makeAny( mpData->maPages[i_nPage].maPageSize );
97cdf0e10cSrcweir     else
98cdf0e10cSrcweir     {
99cdf0e10cSrcweir         awt::Size aEmpty( 0, 0  );
100cdf0e10cSrcweir         aRet[0].Value = makeAny( aEmpty );
101cdf0e10cSrcweir     }
102cdf0e10cSrcweir     return aRet;
103cdf0e10cSrcweir }
104cdf0e10cSrcweir 
printPage(int i_nPage) const105cdf0e10cSrcweir void OldStylePrintAdaptor::printPage( int i_nPage ) const
106cdf0e10cSrcweir {
107cdf0e10cSrcweir     if( i_nPage < int(mpData->maPages.size()) )
108cdf0e10cSrcweir    {
109cdf0e10cSrcweir        mpData->maPages[ i_nPage ].maPage.WindStart();
110cdf0e10cSrcweir        mpData->maPages[ i_nPage ].maPage.Play( getPrinter().get() );
111cdf0e10cSrcweir    }
112cdf0e10cSrcweir }
113cdf0e10cSrcweir 
114