xref: /aoo42x/main/vcl/aqua/source/gdi/salprn.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_vcl.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <boost/bind.hpp>
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "vcl/print.hxx"
34*cdf0e10cSrcweir #include "vcl/unohelp.hxx"
35*cdf0e10cSrcweir 
36*cdf0e10cSrcweir #include "aqua/salinst.h"
37*cdf0e10cSrcweir #include "aqua/salprn.h"
38*cdf0e10cSrcweir #include "aqua/aquaprintview.h"
39*cdf0e10cSrcweir #include "aqua/salgdi.h"
40*cdf0e10cSrcweir #include "aqua/saldata.hxx"
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir #include "jobset.h"
43*cdf0e10cSrcweir #include "salptype.hxx"
44*cdf0e10cSrcweir 
45*cdf0e10cSrcweir #include "com/sun/star/lang/XMultiServiceFactory.hpp"
46*cdf0e10cSrcweir #include "com/sun/star/container/XNameAccess.hpp"
47*cdf0e10cSrcweir #include "com/sun/star/beans/PropertyValue.hpp"
48*cdf0e10cSrcweir #include "com/sun/star/awt/Size.hpp"
49*cdf0e10cSrcweir 
50*cdf0e10cSrcweir #include <algorithm>
51*cdf0e10cSrcweir 
52*cdf0e10cSrcweir using namespace rtl;
53*cdf0e10cSrcweir using namespace vcl;
54*cdf0e10cSrcweir using namespace com::sun::star;
55*cdf0e10cSrcweir using namespace com::sun::star::uno;
56*cdf0e10cSrcweir using namespace com::sun::star::lang;
57*cdf0e10cSrcweir using namespace com::sun::star::beans;
58*cdf0e10cSrcweir using namespace com::sun::star::container;
59*cdf0e10cSrcweir 
60*cdf0e10cSrcweir // =======================================================================
61*cdf0e10cSrcweir 
62*cdf0e10cSrcweir AquaSalInfoPrinter::AquaSalInfoPrinter( const SalPrinterQueueInfo& i_rQueue ) :
63*cdf0e10cSrcweir     mpGraphics( 0 ),
64*cdf0e10cSrcweir     mbGraphics( false ),
65*cdf0e10cSrcweir     mbJob( false ),
66*cdf0e10cSrcweir     mpPrinter( nil ),
67*cdf0e10cSrcweir     mpPrintInfo( nil ),
68*cdf0e10cSrcweir     mePageOrientation( ORIENTATION_PORTRAIT ),
69*cdf0e10cSrcweir     mnStartPageOffsetX( 0 ),
70*cdf0e10cSrcweir     mnStartPageOffsetY( 0 ),
71*cdf0e10cSrcweir     mnCurPageRangeStart( 0 ),
72*cdf0e10cSrcweir     mnCurPageRangeCount( 0 )
73*cdf0e10cSrcweir {
74*cdf0e10cSrcweir     NSString* pStr = CreateNSString( i_rQueue.maPrinterName );
75*cdf0e10cSrcweir     mpPrinter = [NSPrinter printerWithName: pStr];
76*cdf0e10cSrcweir     [pStr release];
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir     NSPrintInfo* pShared = [NSPrintInfo sharedPrintInfo];
79*cdf0e10cSrcweir     if( pShared )
80*cdf0e10cSrcweir     {
81*cdf0e10cSrcweir         mpPrintInfo = [pShared copy];
82*cdf0e10cSrcweir         [mpPrintInfo setPrinter: mpPrinter];
83*cdf0e10cSrcweir         mePageOrientation = ([mpPrintInfo orientation] == NSLandscapeOrientation) ? ORIENTATION_LANDSCAPE : ORIENTATION_PORTRAIT;
84*cdf0e10cSrcweir         [mpPrintInfo setOrientation: NSPortraitOrientation];
85*cdf0e10cSrcweir     }
86*cdf0e10cSrcweir 
87*cdf0e10cSrcweir     mpGraphics = new AquaSalGraphics();
88*cdf0e10cSrcweir 
89*cdf0e10cSrcweir     const int nWidth = 100, nHeight = 100;
90*cdf0e10cSrcweir     maContextMemory.reset( reinterpret_cast<sal_uInt8*>( rtl_allocateMemory( nWidth * 4 * nHeight ) ),
91*cdf0e10cSrcweir                            boost::bind( rtl_freeMemory, _1 ) );
92*cdf0e10cSrcweir 
93*cdf0e10cSrcweir     if( maContextMemory )
94*cdf0e10cSrcweir     {
95*cdf0e10cSrcweir         mrContext = CGBitmapContextCreate( maContextMemory.get(), nWidth, nHeight, 8, nWidth * 4, GetSalData()->mxRGBSpace, kCGImageAlphaNoneSkipFirst );
96*cdf0e10cSrcweir         if( mrContext )
97*cdf0e10cSrcweir             SetupPrinterGraphics( mrContext );
98*cdf0e10cSrcweir     }
99*cdf0e10cSrcweir }
100*cdf0e10cSrcweir 
101*cdf0e10cSrcweir // -----------------------------------------------------------------------
102*cdf0e10cSrcweir 
103*cdf0e10cSrcweir AquaSalInfoPrinter::~AquaSalInfoPrinter()
104*cdf0e10cSrcweir {
105*cdf0e10cSrcweir     delete mpGraphics;
106*cdf0e10cSrcweir     if( mpPrintInfo )
107*cdf0e10cSrcweir         [mpPrintInfo release];
108*cdf0e10cSrcweir     #if 0
109*cdf0e10cSrcweir     // FIXME: verify that NSPrintInfo releases the printer
110*cdf0e10cSrcweir     // else we have a leak here
111*cdf0e10cSrcweir     if( mpPrinter )
112*cdf0e10cSrcweir         [mpPrinter release];
113*cdf0e10cSrcweir     #endif
114*cdf0e10cSrcweir     if( mrContext )
115*cdf0e10cSrcweir         CFRelease( mrContext );
116*cdf0e10cSrcweir }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir // -----------------------------------------------------------------------
119*cdf0e10cSrcweir 
120*cdf0e10cSrcweir void AquaSalInfoPrinter::SetupPrinterGraphics( CGContextRef i_rContext ) const
121*cdf0e10cSrcweir {
122*cdf0e10cSrcweir     if( mpGraphics )
123*cdf0e10cSrcweir     {
124*cdf0e10cSrcweir         if( mpPrintInfo )
125*cdf0e10cSrcweir         {
126*cdf0e10cSrcweir             // FIXME: get printer resolution
127*cdf0e10cSrcweir             long nDPIX = 720, nDPIY = 720;
128*cdf0e10cSrcweir             NSSize aPaperSize = [mpPrintInfo paperSize];
129*cdf0e10cSrcweir 
130*cdf0e10cSrcweir             NSRect aImageRect = [mpPrintInfo imageablePageBounds];
131*cdf0e10cSrcweir             if( mePageOrientation == ORIENTATION_PORTRAIT )
132*cdf0e10cSrcweir             {
133*cdf0e10cSrcweir                 // move mirrored CTM back into paper
134*cdf0e10cSrcweir                 double dX = 0, dY = aPaperSize.height;
135*cdf0e10cSrcweir                 // move CTM to reflect imageable area
136*cdf0e10cSrcweir                 dX += aImageRect.origin.x;
137*cdf0e10cSrcweir                 dY -= aPaperSize.height - aImageRect.size.height - aImageRect.origin.y;
138*cdf0e10cSrcweir                 CGContextTranslateCTM( i_rContext, dX + mnStartPageOffsetX, dY - mnStartPageOffsetY );
139*cdf0e10cSrcweir                 // scale to be top/down and reflect our "virtual" DPI
140*cdf0e10cSrcweir                 CGContextScaleCTM( i_rContext, 72.0/double(nDPIX), -(72.0/double(nDPIY)) );
141*cdf0e10cSrcweir             }
142*cdf0e10cSrcweir             else
143*cdf0e10cSrcweir             {
144*cdf0e10cSrcweir                 // move CTM to reflect imageable area
145*cdf0e10cSrcweir                 double dX = aImageRect.origin.x, dY = aPaperSize.height - aImageRect.size.height - aImageRect.origin.y;
146*cdf0e10cSrcweir                 CGContextTranslateCTM( i_rContext, -dX, -dY );
147*cdf0e10cSrcweir                 // turn by 90 degree
148*cdf0e10cSrcweir                 CGContextRotateCTM( i_rContext, M_PI/2 );
149*cdf0e10cSrcweir                 // move turned CTM back into paper
150*cdf0e10cSrcweir                 dX = aPaperSize.height;
151*cdf0e10cSrcweir                 dY = -aPaperSize.width;
152*cdf0e10cSrcweir                 CGContextTranslateCTM( i_rContext, dX + mnStartPageOffsetY, dY - mnStartPageOffsetX );
153*cdf0e10cSrcweir                 // scale to be top/down and reflect our "virtual" DPI
154*cdf0e10cSrcweir                 CGContextScaleCTM( i_rContext, -(72.0/double(nDPIY)), (72.0/double(nDPIX)) );
155*cdf0e10cSrcweir             }
156*cdf0e10cSrcweir             mpGraphics->SetPrinterGraphics( i_rContext, nDPIX, nDPIY, 1.0 );
157*cdf0e10cSrcweir         }
158*cdf0e10cSrcweir         else
159*cdf0e10cSrcweir             DBG_ERROR( "no print info in SetupPrinterGraphics" );
160*cdf0e10cSrcweir     }
161*cdf0e10cSrcweir }
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir // -----------------------------------------------------------------------
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir SalGraphics* AquaSalInfoPrinter::GetGraphics()
166*cdf0e10cSrcweir {
167*cdf0e10cSrcweir     SalGraphics* pGraphics = mbGraphics ? NULL : mpGraphics;
168*cdf0e10cSrcweir     mbGraphics = true;
169*cdf0e10cSrcweir 	return pGraphics;
170*cdf0e10cSrcweir }
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir // -----------------------------------------------------------------------
173*cdf0e10cSrcweir 
174*cdf0e10cSrcweir void AquaSalInfoPrinter::ReleaseGraphics( SalGraphics* )
175*cdf0e10cSrcweir {
176*cdf0e10cSrcweir     mbGraphics = false;
177*cdf0e10cSrcweir }
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir // -----------------------------------------------------------------------
180*cdf0e10cSrcweir 
181*cdf0e10cSrcweir sal_Bool AquaSalInfoPrinter::Setup( SalFrame*, ImplJobSetup* )
182*cdf0e10cSrcweir {
183*cdf0e10cSrcweir 	return sal_False;
184*cdf0e10cSrcweir }
185*cdf0e10cSrcweir 
186*cdf0e10cSrcweir // -----------------------------------------------------------------------
187*cdf0e10cSrcweir 
188*cdf0e10cSrcweir static struct PaperSizeEntry
189*cdf0e10cSrcweir {
190*cdf0e10cSrcweir     double fWidth;
191*cdf0e10cSrcweir     double fHeight;
192*cdf0e10cSrcweir     Paper        nPaper;
193*cdf0e10cSrcweir } aPaperSizes[] =
194*cdf0e10cSrcweir {
195*cdf0e10cSrcweir     { 842, 1191, PAPER_A3 },
196*cdf0e10cSrcweir     { 595,  842, PAPER_A4 },
197*cdf0e10cSrcweir     { 420,  595, PAPER_A5 },
198*cdf0e10cSrcweir     { 612,  792, PAPER_LETTER },
199*cdf0e10cSrcweir     { 612, 1008, PAPER_LEGAL },
200*cdf0e10cSrcweir     { 728, 1032, PAPER_B4_JIS },
201*cdf0e10cSrcweir     { 516,  729, PAPER_B5_JIS },
202*cdf0e10cSrcweir     { 792, 1224, PAPER_TABLOID }
203*cdf0e10cSrcweir };
204*cdf0e10cSrcweir 
205*cdf0e10cSrcweir static bool getPaperSize( double& o_fWidth, double& o_fHeight, const Paper i_ePaper )
206*cdf0e10cSrcweir {
207*cdf0e10cSrcweir     for(unsigned int i = 0; i < sizeof(aPaperSizes)/sizeof(aPaperSizes[0]); i++ )
208*cdf0e10cSrcweir     {
209*cdf0e10cSrcweir         if( aPaperSizes[i].nPaper == i_ePaper )
210*cdf0e10cSrcweir         {
211*cdf0e10cSrcweir             o_fWidth = aPaperSizes[i].fWidth;
212*cdf0e10cSrcweir             o_fHeight = aPaperSizes[i].fHeight;
213*cdf0e10cSrcweir             return true;
214*cdf0e10cSrcweir         }
215*cdf0e10cSrcweir     }
216*cdf0e10cSrcweir     return false;
217*cdf0e10cSrcweir }
218*cdf0e10cSrcweir 
219*cdf0e10cSrcweir static Paper recognizePaper( double i_fWidth, double i_fHeight )
220*cdf0e10cSrcweir {
221*cdf0e10cSrcweir     Paper aPaper = PAPER_USER;
222*cdf0e10cSrcweir     sal_uInt64 nPaperDesc = 1000000*sal_uInt64(i_fWidth) + sal_uInt64(i_fHeight);
223*cdf0e10cSrcweir     switch( nPaperDesc )
224*cdf0e10cSrcweir     {
225*cdf0e10cSrcweir     case 842001191: aPaper = PAPER_A3;      break;
226*cdf0e10cSrcweir     case 595000842: aPaper = PAPER_A4;      break;
227*cdf0e10cSrcweir     case 420000595: aPaper = PAPER_A5;      break;
228*cdf0e10cSrcweir     case 612000792: aPaper = PAPER_LETTER;  break;
229*cdf0e10cSrcweir     case 728001032: aPaper = PAPER_B4_JIS;  break;
230*cdf0e10cSrcweir     case 516000729: aPaper = PAPER_B5_JIS;  break;
231*cdf0e10cSrcweir     case 612001008: aPaper = PAPER_LEGAL;   break;
232*cdf0e10cSrcweir     case 792001224: aPaper = PAPER_TABLOID; break;
233*cdf0e10cSrcweir     default:
234*cdf0e10cSrcweir         aPaper = PAPER_USER;
235*cdf0e10cSrcweir         break;
236*cdf0e10cSrcweir     }
237*cdf0e10cSrcweir 
238*cdf0e10cSrcweir     if( aPaper == PAPER_USER )
239*cdf0e10cSrcweir     {
240*cdf0e10cSrcweir         // search with fuzz factor
241*cdf0e10cSrcweir         for( unsigned int i = 0; i < sizeof(aPaperSizes)/sizeof(aPaperSizes[0]); i++ )
242*cdf0e10cSrcweir         {
243*cdf0e10cSrcweir             double w = (i_fWidth > aPaperSizes[i].fWidth) ? i_fWidth - aPaperSizes[i].fWidth : aPaperSizes[i].fWidth - i_fWidth;
244*cdf0e10cSrcweir             double h = (i_fHeight > aPaperSizes[i].fHeight) ? i_fHeight - aPaperSizes[i].fHeight : aPaperSizes[i].fHeight - i_fHeight;
245*cdf0e10cSrcweir             if( w < 3 && h < 3 )
246*cdf0e10cSrcweir             {
247*cdf0e10cSrcweir                 aPaper = aPaperSizes[i].nPaper;
248*cdf0e10cSrcweir                 break;
249*cdf0e10cSrcweir             }
250*cdf0e10cSrcweir         }
251*cdf0e10cSrcweir     }
252*cdf0e10cSrcweir 
253*cdf0e10cSrcweir     return aPaper;
254*cdf0e10cSrcweir }
255*cdf0e10cSrcweir 
256*cdf0e10cSrcweir sal_Bool AquaSalInfoPrinter::SetPrinterData( ImplJobSetup* io_pSetupData )
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir     // FIXME: implement driver data
259*cdf0e10cSrcweir     if( io_pSetupData && io_pSetupData->mpDriverData )
260*cdf0e10cSrcweir         return SetData( ~0, io_pSetupData );
261*cdf0e10cSrcweir 
262*cdf0e10cSrcweir 
263*cdf0e10cSrcweir     sal_Bool bSuccess = sal_True;
264*cdf0e10cSrcweir 
265*cdf0e10cSrcweir     // set system type
266*cdf0e10cSrcweir     io_pSetupData->mnSystem = JOBSETUP_SYSTEM_MAC;
267*cdf0e10cSrcweir 
268*cdf0e10cSrcweir     // get paper format
269*cdf0e10cSrcweir     if( mpPrintInfo )
270*cdf0e10cSrcweir     {
271*cdf0e10cSrcweir         NSSize aPaperSize = [mpPrintInfo paperSize];
272*cdf0e10cSrcweir         double width = aPaperSize.width, height = aPaperSize.height;
273*cdf0e10cSrcweir         // set paper
274*cdf0e10cSrcweir         io_pSetupData->mePaperFormat = recognizePaper( width, height );
275*cdf0e10cSrcweir         if( io_pSetupData->mePaperFormat == PAPER_USER )
276*cdf0e10cSrcweir         {
277*cdf0e10cSrcweir             io_pSetupData->mnPaperWidth = PtTo10Mu( width );
278*cdf0e10cSrcweir             io_pSetupData->mnPaperHeight = PtTo10Mu( height );
279*cdf0e10cSrcweir         }
280*cdf0e10cSrcweir         else
281*cdf0e10cSrcweir         {
282*cdf0e10cSrcweir             io_pSetupData->mnPaperWidth = 0;
283*cdf0e10cSrcweir             io_pSetupData->mnPaperHeight = 0;
284*cdf0e10cSrcweir         }
285*cdf0e10cSrcweir 
286*cdf0e10cSrcweir         // set orientation
287*cdf0e10cSrcweir         io_pSetupData->meOrientation = mePageOrientation;
288*cdf0e10cSrcweir 
289*cdf0e10cSrcweir         io_pSetupData->mnPaperBin = 0;
290*cdf0e10cSrcweir         io_pSetupData->mpDriverData = reinterpret_cast<sal_uInt8*>(rtl_allocateMemory( 4 ));
291*cdf0e10cSrcweir         io_pSetupData->mnDriverDataLen = 4;
292*cdf0e10cSrcweir     }
293*cdf0e10cSrcweir     else
294*cdf0e10cSrcweir         bSuccess = sal_False;
295*cdf0e10cSrcweir 
296*cdf0e10cSrcweir 
297*cdf0e10cSrcweir 	return bSuccess;
298*cdf0e10cSrcweir }
299*cdf0e10cSrcweir 
300*cdf0e10cSrcweir // -----------------------------------------------------------------------
301*cdf0e10cSrcweir 
302*cdf0e10cSrcweir void AquaSalInfoPrinter::setPaperSize( long i_nWidth, long i_nHeight, Orientation i_eSetOrientation )
303*cdf0e10cSrcweir {
304*cdf0e10cSrcweir 
305*cdf0e10cSrcweir     Orientation ePaperOrientation = ORIENTATION_PORTRAIT;
306*cdf0e10cSrcweir     const PaperInfo* pPaper = matchPaper( i_nWidth, i_nHeight, ePaperOrientation );
307*cdf0e10cSrcweir 
308*cdf0e10cSrcweir     if( pPaper )
309*cdf0e10cSrcweir     {
310*cdf0e10cSrcweir         NSString* pPaperName = [CreateNSString( rtl::OStringToOUString(PaperInfo::toPSName(pPaper->getPaper()), RTL_TEXTENCODING_ASCII_US) ) autorelease];
311*cdf0e10cSrcweir         [mpPrintInfo setPaperName: pPaperName];
312*cdf0e10cSrcweir     }
313*cdf0e10cSrcweir     else if( i_nWidth > 0 && i_nHeight > 0 )
314*cdf0e10cSrcweir     {
315*cdf0e10cSrcweir         NSSize aPaperSize = { TenMuToPt(i_nWidth), TenMuToPt(i_nHeight) };
316*cdf0e10cSrcweir         [mpPrintInfo setPaperSize: aPaperSize];
317*cdf0e10cSrcweir     }
318*cdf0e10cSrcweir     // this seems counterintuitive
319*cdf0e10cSrcweir     mePageOrientation = i_eSetOrientation;
320*cdf0e10cSrcweir }
321*cdf0e10cSrcweir 
322*cdf0e10cSrcweir // -----------------------------------------------------------------------
323*cdf0e10cSrcweir 
324*cdf0e10cSrcweir sal_Bool AquaSalInfoPrinter::SetData( sal_uLong i_nFlags, ImplJobSetup* io_pSetupData )
325*cdf0e10cSrcweir {
326*cdf0e10cSrcweir     if( ! io_pSetupData || io_pSetupData->mnSystem != JOBSETUP_SYSTEM_MAC )
327*cdf0e10cSrcweir         return sal_False;
328*cdf0e10cSrcweir 
329*cdf0e10cSrcweir 
330*cdf0e10cSrcweir     if( mpPrintInfo )
331*cdf0e10cSrcweir     {
332*cdf0e10cSrcweir         if( (i_nFlags & SAL_JOBSET_ORIENTATION) != 0 )
333*cdf0e10cSrcweir             mePageOrientation = io_pSetupData->meOrientation;
334*cdf0e10cSrcweir 
335*cdf0e10cSrcweir         if( (i_nFlags & SAL_JOBSET_PAPERSIZE) !=  0)
336*cdf0e10cSrcweir         {
337*cdf0e10cSrcweir             // set paper format
338*cdf0e10cSrcweir             long width = 21000, height = 29700;
339*cdf0e10cSrcweir             if( io_pSetupData->mePaperFormat == PAPER_USER )
340*cdf0e10cSrcweir             {
341*cdf0e10cSrcweir                 // #i101108# sanity check
342*cdf0e10cSrcweir                 if( io_pSetupData->mnPaperWidth && io_pSetupData->mnPaperHeight )
343*cdf0e10cSrcweir                 {
344*cdf0e10cSrcweir                     width = io_pSetupData->mnPaperWidth;
345*cdf0e10cSrcweir                     height = io_pSetupData->mnPaperHeight;
346*cdf0e10cSrcweir                 }
347*cdf0e10cSrcweir             }
348*cdf0e10cSrcweir             else
349*cdf0e10cSrcweir             {
350*cdf0e10cSrcweir                 double w = 595,  h = 842;
351*cdf0e10cSrcweir                 getPaperSize( w, h, io_pSetupData->mePaperFormat );
352*cdf0e10cSrcweir                 width = static_cast<long>(PtTo10Mu( w ));
353*cdf0e10cSrcweir                 height = static_cast<long>(PtTo10Mu( h ));
354*cdf0e10cSrcweir             }
355*cdf0e10cSrcweir 
356*cdf0e10cSrcweir             setPaperSize( width, height, mePageOrientation );
357*cdf0e10cSrcweir         }
358*cdf0e10cSrcweir     }
359*cdf0e10cSrcweir 
360*cdf0e10cSrcweir 	return mpPrintInfo != nil;
361*cdf0e10cSrcweir }
362*cdf0e10cSrcweir 
363*cdf0e10cSrcweir // -----------------------------------------------------------------------
364*cdf0e10cSrcweir 
365*cdf0e10cSrcweir sal_uLong AquaSalInfoPrinter::GetPaperBinCount( const ImplJobSetup* )
366*cdf0e10cSrcweir {
367*cdf0e10cSrcweir 	return 0;
368*cdf0e10cSrcweir }
369*cdf0e10cSrcweir 
370*cdf0e10cSrcweir // -----------------------------------------------------------------------
371*cdf0e10cSrcweir 
372*cdf0e10cSrcweir XubString AquaSalInfoPrinter::GetPaperBinName( const ImplJobSetup*, sal_uLong )
373*cdf0e10cSrcweir {
374*cdf0e10cSrcweir 	return XubString();
375*cdf0e10cSrcweir }
376*cdf0e10cSrcweir 
377*cdf0e10cSrcweir // -----------------------------------------------------------------------
378*cdf0e10cSrcweir 
379*cdf0e10cSrcweir static bool getUseNativeDialog()
380*cdf0e10cSrcweir {
381*cdf0e10cSrcweir     bool bNative = true;
382*cdf0e10cSrcweir     try
383*cdf0e10cSrcweir     {
384*cdf0e10cSrcweir         // get service provider
385*cdf0e10cSrcweir         uno::Reference< XMultiServiceFactory > xSMgr( unohelper::GetMultiServiceFactory() );
386*cdf0e10cSrcweir         // create configuration hierachical access name
387*cdf0e10cSrcweir         if( xSMgr.is() )
388*cdf0e10cSrcweir         {
389*cdf0e10cSrcweir             try
390*cdf0e10cSrcweir             {
391*cdf0e10cSrcweir                 uno::Reference< XMultiServiceFactory > xConfigProvider(
392*cdf0e10cSrcweir                    uno::Reference< XMultiServiceFactory >(
393*cdf0e10cSrcweir                         xSMgr->createInstance( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
394*cdf0e10cSrcweir                                         "com.sun.star.configuration.ConfigurationProvider" ))),
395*cdf0e10cSrcweir                         UNO_QUERY )
396*cdf0e10cSrcweir                     );
397*cdf0e10cSrcweir                 if( xConfigProvider.is() )
398*cdf0e10cSrcweir                 {
399*cdf0e10cSrcweir                     Sequence< Any > aArgs(1);
400*cdf0e10cSrcweir                     PropertyValue aVal;
401*cdf0e10cSrcweir                     aVal.Name = OUString( RTL_CONSTASCII_USTRINGPARAM( "nodepath" ) );
402*cdf0e10cSrcweir                     aVal.Value <<= OUString( RTL_CONSTASCII_USTRINGPARAM( "/org.openoffice.Office.Common/Misc" ) );
403*cdf0e10cSrcweir                     aArgs.getArray()[0] <<= aVal;
404*cdf0e10cSrcweir                     uno::Reference< XNameAccess > xConfigAccess(
405*cdf0e10cSrcweir                         uno::Reference< XNameAccess >(
406*cdf0e10cSrcweir                             xConfigProvider->createInstanceWithArguments( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
407*cdf0e10cSrcweir                                                 "com.sun.star.configuration.ConfigurationAccess" )),
408*cdf0e10cSrcweir                                                                             aArgs ),
409*cdf0e10cSrcweir                             UNO_QUERY )
410*cdf0e10cSrcweir                         );
411*cdf0e10cSrcweir                     if( xConfigAccess.is() )
412*cdf0e10cSrcweir                     {
413*cdf0e10cSrcweir                         try
414*cdf0e10cSrcweir                         {
415*cdf0e10cSrcweir                             sal_Bool bValue = sal_False;
416*cdf0e10cSrcweir                             Any aAny = xConfigAccess->getByName( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "UseSystemPrintDialog" ) ) );
417*cdf0e10cSrcweir                             if( aAny >>= bValue )
418*cdf0e10cSrcweir                                 bNative = bValue;
419*cdf0e10cSrcweir                         }
420*cdf0e10cSrcweir                         catch( NoSuchElementException& )
421*cdf0e10cSrcweir                         {
422*cdf0e10cSrcweir                         }
423*cdf0e10cSrcweir                         catch( WrappedTargetException& )
424*cdf0e10cSrcweir                         {
425*cdf0e10cSrcweir                         }
426*cdf0e10cSrcweir                     }
427*cdf0e10cSrcweir                 }
428*cdf0e10cSrcweir             }
429*cdf0e10cSrcweir             catch( Exception& )
430*cdf0e10cSrcweir             {
431*cdf0e10cSrcweir             }
432*cdf0e10cSrcweir         }
433*cdf0e10cSrcweir     }
434*cdf0e10cSrcweir     catch( WrappedTargetException& )
435*cdf0e10cSrcweir     {
436*cdf0e10cSrcweir     }
437*cdf0e10cSrcweir 
438*cdf0e10cSrcweir     return bNative;
439*cdf0e10cSrcweir }
440*cdf0e10cSrcweir 
441*cdf0e10cSrcweir sal_uLong AquaSalInfoPrinter::GetCapabilities( const ImplJobSetup*, sal_uInt16 i_nType )
442*cdf0e10cSrcweir {
443*cdf0e10cSrcweir 	switch( i_nType )
444*cdf0e10cSrcweir 	{
445*cdf0e10cSrcweir 		case PRINTER_CAPABILITIES_SUPPORTDIALOG:
446*cdf0e10cSrcweir 			return 0;
447*cdf0e10cSrcweir 		case PRINTER_CAPABILITIES_COPIES:
448*cdf0e10cSrcweir 			return 0xffff;
449*cdf0e10cSrcweir 		case PRINTER_CAPABILITIES_COLLATECOPIES:
450*cdf0e10cSrcweir 			return 0xffff;
451*cdf0e10cSrcweir 		case PRINTER_CAPABILITIES_SETORIENTATION:
452*cdf0e10cSrcweir 			return 1;
453*cdf0e10cSrcweir 		case PRINTER_CAPABILITIES_SETDUPLEX:
454*cdf0e10cSrcweir 			return 0;
455*cdf0e10cSrcweir 		case PRINTER_CAPABILITIES_SETPAPERBIN:
456*cdf0e10cSrcweir 			return 0;
457*cdf0e10cSrcweir 		case PRINTER_CAPABILITIES_SETPAPERSIZE:
458*cdf0e10cSrcweir 			return 1;
459*cdf0e10cSrcweir 		case PRINTER_CAPABILITIES_SETPAPER:
460*cdf0e10cSrcweir 			return 1;
461*cdf0e10cSrcweir         case PRINTER_CAPABILITIES_EXTERNALDIALOG:
462*cdf0e10cSrcweir             return getUseNativeDialog() ? 1 : 0;
463*cdf0e10cSrcweir         case PRINTER_CAPABILITIES_PDF:
464*cdf0e10cSrcweir             return 1;
465*cdf0e10cSrcweir         case PRINTER_CAPABILITIES_USEPULLMODEL:
466*cdf0e10cSrcweir             return 1;
467*cdf0e10cSrcweir 		default: break;
468*cdf0e10cSrcweir 	};
469*cdf0e10cSrcweir 	return 0;
470*cdf0e10cSrcweir }
471*cdf0e10cSrcweir 
472*cdf0e10cSrcweir // -----------------------------------------------------------------------
473*cdf0e10cSrcweir 
474*cdf0e10cSrcweir void AquaSalInfoPrinter::GetPageInfo( const ImplJobSetup*,
475*cdf0e10cSrcweir 								  long& o_rOutWidth, long& o_rOutHeight,
476*cdf0e10cSrcweir 								  long& o_rPageOffX, long& o_rPageOffY,
477*cdf0e10cSrcweir 								  long& o_rPageWidth, long& o_rPageHeight )
478*cdf0e10cSrcweir {
479*cdf0e10cSrcweir     if( mpPrintInfo )
480*cdf0e10cSrcweir     {
481*cdf0e10cSrcweir         long nDPIX = 72, nDPIY = 72;
482*cdf0e10cSrcweir         mpGraphics->GetResolution( nDPIX, nDPIY );
483*cdf0e10cSrcweir         const double fXScaling = static_cast<double>(nDPIX)/72.0,
484*cdf0e10cSrcweir                      fYScaling = static_cast<double>(nDPIY)/72.0;
485*cdf0e10cSrcweir 
486*cdf0e10cSrcweir         NSSize aPaperSize = [mpPrintInfo paperSize];
487*cdf0e10cSrcweir         o_rPageWidth  = static_cast<long>( double(aPaperSize.width) * fXScaling );
488*cdf0e10cSrcweir         o_rPageHeight = static_cast<long>( double(aPaperSize.height) * fYScaling );
489*cdf0e10cSrcweir 
490*cdf0e10cSrcweir         NSRect aImageRect = [mpPrintInfo imageablePageBounds];
491*cdf0e10cSrcweir         o_rPageOffX   = static_cast<long>( aImageRect.origin.x * fXScaling );
492*cdf0e10cSrcweir         o_rPageOffY   = static_cast<long>( (aPaperSize.height - aImageRect.size.height - aImageRect.origin.y) * fYScaling );
493*cdf0e10cSrcweir         o_rOutWidth   = static_cast<long>( aImageRect.size.width * fXScaling );
494*cdf0e10cSrcweir         o_rOutHeight  = static_cast<long>( aImageRect.size.height * fYScaling );
495*cdf0e10cSrcweir 
496*cdf0e10cSrcweir         if( mePageOrientation == ORIENTATION_LANDSCAPE )
497*cdf0e10cSrcweir         {
498*cdf0e10cSrcweir             std::swap( o_rOutWidth, o_rOutHeight );
499*cdf0e10cSrcweir             std::swap( o_rPageWidth, o_rPageHeight );
500*cdf0e10cSrcweir             std::swap( o_rPageOffX, o_rPageOffY );
501*cdf0e10cSrcweir         }
502*cdf0e10cSrcweir     }
503*cdf0e10cSrcweir }
504*cdf0e10cSrcweir 
505*cdf0e10cSrcweir static Size getPageSize( vcl::PrinterController& i_rController, sal_Int32 i_nPage )
506*cdf0e10cSrcweir {
507*cdf0e10cSrcweir     Size aPageSize;
508*cdf0e10cSrcweir     Sequence< PropertyValue > aPageParms( i_rController.getPageParameters( i_nPage ) );
509*cdf0e10cSrcweir     for( sal_Int32 nProperty = 0, nPropertyCount = aPageParms.getLength(); nProperty < nPropertyCount; ++nProperty )
510*cdf0e10cSrcweir     {
511*cdf0e10cSrcweir         if( aPageParms[ nProperty ].Name.equalsAscii( "PageSize" ) )
512*cdf0e10cSrcweir         {
513*cdf0e10cSrcweir             awt::Size aSize;
514*cdf0e10cSrcweir             aPageParms[ nProperty].Value >>= aSize;
515*cdf0e10cSrcweir             aPageSize.Width() = aSize.Width;
516*cdf0e10cSrcweir             aPageSize.Height() = aSize.Height;
517*cdf0e10cSrcweir             break;
518*cdf0e10cSrcweir         }
519*cdf0e10cSrcweir     }
520*cdf0e10cSrcweir     return aPageSize;
521*cdf0e10cSrcweir }
522*cdf0e10cSrcweir 
523*cdf0e10cSrcweir sal_Bool AquaSalInfoPrinter::StartJob( const String* i_pFileName,
524*cdf0e10cSrcweir                                    const String& i_rJobName,
525*cdf0e10cSrcweir                                    const String& /*i_rAppName*/,
526*cdf0e10cSrcweir                                    ImplJobSetup* i_pSetupData,
527*cdf0e10cSrcweir                                    vcl::PrinterController& i_rController
528*cdf0e10cSrcweir                                    )
529*cdf0e10cSrcweir {
530*cdf0e10cSrcweir     if( mbJob )
531*cdf0e10cSrcweir         return sal_False;
532*cdf0e10cSrcweir 
533*cdf0e10cSrcweir     sal_Bool bSuccess = sal_False;
534*cdf0e10cSrcweir     bool bWasAborted = false;
535*cdf0e10cSrcweir     AquaSalInstance* pInst = GetSalData()->mpFirstInstance;
536*cdf0e10cSrcweir     PrintAccessoryViewState aAccViewState;
537*cdf0e10cSrcweir     sal_Int32 nAllPages = 0;
538*cdf0e10cSrcweir 
539*cdf0e10cSrcweir     // reset IsLastPage
540*cdf0e10cSrcweir     i_rController.setLastPage( sal_False );
541*cdf0e10cSrcweir 
542*cdf0e10cSrcweir     // update job data
543*cdf0e10cSrcweir     if( i_pSetupData )
544*cdf0e10cSrcweir         SetData( ~0, i_pSetupData );
545*cdf0e10cSrcweir 
546*cdf0e10cSrcweir     // do we want a progress panel ?
547*cdf0e10cSrcweir     sal_Bool bShowProgressPanel = sal_True;
548*cdf0e10cSrcweir     beans::PropertyValue* pMonitor = i_rController.getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "MonitorVisible" ) ) );
549*cdf0e10cSrcweir     if( pMonitor )
550*cdf0e10cSrcweir         pMonitor->Value >>= bShowProgressPanel;
551*cdf0e10cSrcweir     if( ! i_rController.isShowDialogs() )
552*cdf0e10cSrcweir         bShowProgressPanel = sal_False;
553*cdf0e10cSrcweir 
554*cdf0e10cSrcweir     // possibly create one job for collated output
555*cdf0e10cSrcweir     sal_Bool bSinglePrintJobs = sal_False;
556*cdf0e10cSrcweir     beans::PropertyValue* pSingleValue = i_rController.getValue( rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "PrintCollateAsSingleJobs" ) ) );
557*cdf0e10cSrcweir     if( pSingleValue )
558*cdf0e10cSrcweir     {
559*cdf0e10cSrcweir         pSingleValue->Value >>= bSinglePrintJobs;
560*cdf0e10cSrcweir     }
561*cdf0e10cSrcweir 
562*cdf0e10cSrcweir     // FIXME: jobStarted() should be done after the print dialog has ended (if there is one)
563*cdf0e10cSrcweir     // how do I know when that might be ?
564*cdf0e10cSrcweir     i_rController.jobStarted();
565*cdf0e10cSrcweir 
566*cdf0e10cSrcweir 
567*cdf0e10cSrcweir     int nCopies = i_rController.getPrinter()->GetCopyCount();
568*cdf0e10cSrcweir     int nJobs = 1;
569*cdf0e10cSrcweir     if( bSinglePrintJobs )
570*cdf0e10cSrcweir     {
571*cdf0e10cSrcweir         nJobs = nCopies;
572*cdf0e10cSrcweir         nCopies = 1;
573*cdf0e10cSrcweir     }
574*cdf0e10cSrcweir 
575*cdf0e10cSrcweir     for( int nCurJob = 0; nCurJob < nJobs; nCurJob++ )
576*cdf0e10cSrcweir     {
577*cdf0e10cSrcweir         aAccViewState.bNeedRestart = true;
578*cdf0e10cSrcweir         do
579*cdf0e10cSrcweir         {
580*cdf0e10cSrcweir             if( aAccViewState.bNeedRestart )
581*cdf0e10cSrcweir             {
582*cdf0e10cSrcweir                 mnCurPageRangeStart = 0;
583*cdf0e10cSrcweir                 mnCurPageRangeCount = 0;
584*cdf0e10cSrcweir                 nAllPages = i_rController.getFilteredPageCount();
585*cdf0e10cSrcweir             }
586*cdf0e10cSrcweir 
587*cdf0e10cSrcweir             aAccViewState.bNeedRestart = false;
588*cdf0e10cSrcweir 
589*cdf0e10cSrcweir             Size aCurSize( 21000, 29700 );
590*cdf0e10cSrcweir             if( nAllPages > 0 )
591*cdf0e10cSrcweir             {
592*cdf0e10cSrcweir                 mnCurPageRangeCount = 1;
593*cdf0e10cSrcweir                 aCurSize = getPageSize( i_rController, mnCurPageRangeStart );
594*cdf0e10cSrcweir                 Size aNextSize( aCurSize );
595*cdf0e10cSrcweir 
596*cdf0e10cSrcweir                 // print pages up to a different size
597*cdf0e10cSrcweir                 while( mnCurPageRangeCount + mnCurPageRangeStart < nAllPages )
598*cdf0e10cSrcweir                 {
599*cdf0e10cSrcweir                     aNextSize = getPageSize( i_rController, mnCurPageRangeStart + mnCurPageRangeCount );
600*cdf0e10cSrcweir                     if( aCurSize == aNextSize // same page size
601*cdf0e10cSrcweir                         ||
602*cdf0e10cSrcweir                         (aCurSize.Width() == aNextSize.Height() && aCurSize.Height() == aNextSize.Width()) // same size, but different orientation
603*cdf0e10cSrcweir                         )
604*cdf0e10cSrcweir                     {
605*cdf0e10cSrcweir                         mnCurPageRangeCount++;
606*cdf0e10cSrcweir                     }
607*cdf0e10cSrcweir                     else
608*cdf0e10cSrcweir                         break;
609*cdf0e10cSrcweir                 }
610*cdf0e10cSrcweir             }
611*cdf0e10cSrcweir             else
612*cdf0e10cSrcweir                 mnCurPageRangeCount = 0;
613*cdf0e10cSrcweir 
614*cdf0e10cSrcweir             // now for the current run
615*cdf0e10cSrcweir             mnStartPageOffsetX = mnStartPageOffsetY = 0;
616*cdf0e10cSrcweir             // setup the paper size and orientation
617*cdf0e10cSrcweir             // do this on our associated Printer object, since that is
618*cdf0e10cSrcweir             // out interface to the applications which occasionally rely on the paper
619*cdf0e10cSrcweir             // information (e.g. brochure printing scales to the found paper size)
620*cdf0e10cSrcweir             // also SetPaperSizeUser has the advantage that we can share a
621*cdf0e10cSrcweir             // platform independent paper matching algorithm
622*cdf0e10cSrcweir             boost::shared_ptr<Printer> pPrinter( i_rController.getPrinter() );
623*cdf0e10cSrcweir             pPrinter->SetMapMode( MapMode( MAP_100TH_MM ) );
624*cdf0e10cSrcweir             pPrinter->SetPaperSizeUser( aCurSize, true );
625*cdf0e10cSrcweir 
626*cdf0e10cSrcweir             // create view
627*cdf0e10cSrcweir             NSView* pPrintView = [[AquaPrintView alloc] initWithController: &i_rController withInfoPrinter: this];
628*cdf0e10cSrcweir 
629*cdf0e10cSrcweir             NSMutableDictionary* pPrintDict = [mpPrintInfo dictionary];
630*cdf0e10cSrcweir 
631*cdf0e10cSrcweir             // set filename
632*cdf0e10cSrcweir             if( i_pFileName )
633*cdf0e10cSrcweir             {
634*cdf0e10cSrcweir                 [mpPrintInfo setJobDisposition: NSPrintSaveJob];
635*cdf0e10cSrcweir                 NSString* pPath = CreateNSString( *i_pFileName );
636*cdf0e10cSrcweir                 [pPrintDict setObject: pPath forKey: NSPrintSavePath];
637*cdf0e10cSrcweir                 [pPath release];
638*cdf0e10cSrcweir             }
639*cdf0e10cSrcweir 
640*cdf0e10cSrcweir             [pPrintDict setObject: [[NSNumber numberWithInt: nCopies] autorelease] forKey: NSPrintCopies];
641*cdf0e10cSrcweir             if( nCopies > 1 )
642*cdf0e10cSrcweir                 [pPrintDict setObject: [[NSNumber numberWithBool: pPrinter->IsCollateCopy()] autorelease] forKey: NSPrintMustCollate];
643*cdf0e10cSrcweir             [pPrintDict setObject: [[NSNumber numberWithBool: YES] autorelease] forKey: NSPrintDetailedErrorReporting];
644*cdf0e10cSrcweir             [pPrintDict setObject: [[NSNumber numberWithInt: 1] autorelease] forKey: NSPrintFirstPage];
645*cdf0e10cSrcweir             // #i103253# weird: for some reason, autoreleasing the value below like the others above
646*cdf0e10cSrcweir             // leads do a double free malloc error. Why this value should behave differently from all the others
647*cdf0e10cSrcweir             // is a mystery.
648*cdf0e10cSrcweir             [pPrintDict setObject: [NSNumber numberWithInt: mnCurPageRangeCount] forKey: NSPrintLastPage];
649*cdf0e10cSrcweir 
650*cdf0e10cSrcweir 
651*cdf0e10cSrcweir             // create print operation
652*cdf0e10cSrcweir             NSPrintOperation* pPrintOperation = [NSPrintOperation printOperationWithView: pPrintView printInfo: mpPrintInfo];
653*cdf0e10cSrcweir 
654*cdf0e10cSrcweir             if( pPrintOperation )
655*cdf0e10cSrcweir             {
656*cdf0e10cSrcweir                 NSObject* pReleaseAfterUse = nil;
657*cdf0e10cSrcweir                 bool bShowPanel = (! i_rController.isDirectPrint() && getUseNativeDialog() && i_rController.isShowDialogs() );
658*cdf0e10cSrcweir                 [pPrintOperation setShowsPrintPanel: bShowPanel ? YES : NO ];
659*cdf0e10cSrcweir                 [pPrintOperation setShowsProgressPanel: bShowProgressPanel ? YES : NO];
660*cdf0e10cSrcweir 
661*cdf0e10cSrcweir                 // set job title (since MacOSX 10.5)
662*cdf0e10cSrcweir                 if( [pPrintOperation respondsToSelector: @selector(setJobTitle:)] )
663*cdf0e10cSrcweir                     [pPrintOperation performSelector: @selector(setJobTitle:) withObject: [CreateNSString( i_rJobName ) autorelease]];
664*cdf0e10cSrcweir 
665*cdf0e10cSrcweir                 if( bShowPanel && mnCurPageRangeStart == 0 && nCurJob == 0) // only the first range of pages (in the first job) gets the accesory view
666*cdf0e10cSrcweir                     pReleaseAfterUse = [AquaPrintAccessoryView setupPrinterPanel: pPrintOperation withController: &i_rController withState: &aAccViewState];
667*cdf0e10cSrcweir 
668*cdf0e10cSrcweir                 bSuccess = sal_True;
669*cdf0e10cSrcweir                 mbJob = true;
670*cdf0e10cSrcweir                 pInst->startedPrintJob();
671*cdf0e10cSrcweir                 [pPrintOperation runOperation];
672*cdf0e10cSrcweir                 pInst->endedPrintJob();
673*cdf0e10cSrcweir                 bWasAborted = [[[pPrintOperation printInfo] jobDisposition] compare: NSPrintCancelJob] == NSOrderedSame;
674*cdf0e10cSrcweir                 mbJob = false;
675*cdf0e10cSrcweir                 if( pReleaseAfterUse )
676*cdf0e10cSrcweir                     [pReleaseAfterUse release];
677*cdf0e10cSrcweir             }
678*cdf0e10cSrcweir 
679*cdf0e10cSrcweir             mnCurPageRangeStart += mnCurPageRangeCount;
680*cdf0e10cSrcweir             mnCurPageRangeCount = 1;
681*cdf0e10cSrcweir         } while( aAccViewState.bNeedRestart || mnCurPageRangeStart + mnCurPageRangeCount < nAllPages );
682*cdf0e10cSrcweir     }
683*cdf0e10cSrcweir 
684*cdf0e10cSrcweir     // inform application that it can release its data
685*cdf0e10cSrcweir     // this is awkward, but the XRenderable interface has no method for this,
686*cdf0e10cSrcweir     // so we need to call XRenderadble::render one last time with IsLastPage = sal_True
687*cdf0e10cSrcweir     i_rController.setLastPage( sal_True );
688*cdf0e10cSrcweir     GDIMetaFile aPageFile;
689*cdf0e10cSrcweir     if( mrContext )
690*cdf0e10cSrcweir         SetupPrinterGraphics( mrContext );
691*cdf0e10cSrcweir     i_rController.getFilteredPageFile( 0, aPageFile );
692*cdf0e10cSrcweir 
693*cdf0e10cSrcweir     i_rController.setJobState( bWasAborted
694*cdf0e10cSrcweir                              ? view::PrintableState_JOB_ABORTED
695*cdf0e10cSrcweir                              : view::PrintableState_JOB_SPOOLED );
696*cdf0e10cSrcweir 
697*cdf0e10cSrcweir     mnCurPageRangeStart = mnCurPageRangeCount = 0;
698*cdf0e10cSrcweir 
699*cdf0e10cSrcweir     return bSuccess;
700*cdf0e10cSrcweir }
701*cdf0e10cSrcweir 
702*cdf0e10cSrcweir // -----------------------------------------------------------------------
703*cdf0e10cSrcweir 
704*cdf0e10cSrcweir sal_Bool AquaSalInfoPrinter::EndJob()
705*cdf0e10cSrcweir {
706*cdf0e10cSrcweir     mnStartPageOffsetX = mnStartPageOffsetY = 0;
707*cdf0e10cSrcweir     mbJob = false;
708*cdf0e10cSrcweir     return sal_True;
709*cdf0e10cSrcweir }
710*cdf0e10cSrcweir 
711*cdf0e10cSrcweir // -----------------------------------------------------------------------
712*cdf0e10cSrcweir 
713*cdf0e10cSrcweir sal_Bool AquaSalInfoPrinter::AbortJob()
714*cdf0e10cSrcweir {
715*cdf0e10cSrcweir     mbJob = false;
716*cdf0e10cSrcweir 
717*cdf0e10cSrcweir     // FIXME: implementation
718*cdf0e10cSrcweir 	return sal_False;
719*cdf0e10cSrcweir }
720*cdf0e10cSrcweir 
721*cdf0e10cSrcweir // -----------------------------------------------------------------------
722*cdf0e10cSrcweir 
723*cdf0e10cSrcweir SalGraphics* AquaSalInfoPrinter::StartPage( ImplJobSetup* i_pSetupData, sal_Bool i_bNewJobData )
724*cdf0e10cSrcweir {
725*cdf0e10cSrcweir     if( i_bNewJobData && i_pSetupData )
726*cdf0e10cSrcweir         SetPrinterData( i_pSetupData );
727*cdf0e10cSrcweir 
728*cdf0e10cSrcweir     CGContextRef rContext = reinterpret_cast<CGContextRef>([[NSGraphicsContext currentContext] graphicsPort]);
729*cdf0e10cSrcweir 
730*cdf0e10cSrcweir     SetupPrinterGraphics( rContext );
731*cdf0e10cSrcweir 
732*cdf0e10cSrcweir 	return mpGraphics;
733*cdf0e10cSrcweir }
734*cdf0e10cSrcweir 
735*cdf0e10cSrcweir // -----------------------------------------------------------------------
736*cdf0e10cSrcweir 
737*cdf0e10cSrcweir sal_Bool AquaSalInfoPrinter::EndPage()
738*cdf0e10cSrcweir {
739*cdf0e10cSrcweir     mpGraphics->InvalidateContext();
740*cdf0e10cSrcweir 	return sal_True;
741*cdf0e10cSrcweir }
742*cdf0e10cSrcweir 
743*cdf0e10cSrcweir // -----------------------------------------------------------------------
744*cdf0e10cSrcweir 
745*cdf0e10cSrcweir sal_uLong AquaSalInfoPrinter::GetErrorCode() const
746*cdf0e10cSrcweir {
747*cdf0e10cSrcweir 	return 0;
748*cdf0e10cSrcweir }
749*cdf0e10cSrcweir 
750*cdf0e10cSrcweir // =======================================================================
751*cdf0e10cSrcweir 
752*cdf0e10cSrcweir AquaSalPrinter::AquaSalPrinter( AquaSalInfoPrinter* i_pInfoPrinter ) :
753*cdf0e10cSrcweir     mpInfoPrinter( i_pInfoPrinter )
754*cdf0e10cSrcweir {
755*cdf0e10cSrcweir }
756*cdf0e10cSrcweir 
757*cdf0e10cSrcweir // -----------------------------------------------------------------------
758*cdf0e10cSrcweir 
759*cdf0e10cSrcweir AquaSalPrinter::~AquaSalPrinter()
760*cdf0e10cSrcweir {
761*cdf0e10cSrcweir }
762*cdf0e10cSrcweir 
763*cdf0e10cSrcweir // -----------------------------------------------------------------------
764*cdf0e10cSrcweir 
765*cdf0e10cSrcweir sal_Bool AquaSalPrinter::StartJob( const String* i_pFileName,
766*cdf0e10cSrcweir                                const String& i_rJobName,
767*cdf0e10cSrcweir                                const String& i_rAppName,
768*cdf0e10cSrcweir                                ImplJobSetup* i_pSetupData,
769*cdf0e10cSrcweir                                vcl::PrinterController& i_rController )
770*cdf0e10cSrcweir {
771*cdf0e10cSrcweir     return mpInfoPrinter->StartJob( i_pFileName, i_rJobName, i_rAppName, i_pSetupData, i_rController );
772*cdf0e10cSrcweir }
773*cdf0e10cSrcweir 
774*cdf0e10cSrcweir // -----------------------------------------------------------------------
775*cdf0e10cSrcweir 
776*cdf0e10cSrcweir sal_Bool AquaSalPrinter::StartJob( const XubString* /*i_pFileName*/,
777*cdf0e10cSrcweir                                const XubString& /*i_rJobName*/,
778*cdf0e10cSrcweir                                const XubString& /*i_rAppName*/,
779*cdf0e10cSrcweir                                sal_uLong /*i_nCopies*/,
780*cdf0e10cSrcweir                                bool /*i_bCollate*/,
781*cdf0e10cSrcweir                                bool /*i_bDirect*/,
782*cdf0e10cSrcweir                                ImplJobSetup* )
783*cdf0e10cSrcweir {
784*cdf0e10cSrcweir     DBG_ERROR( "should never be called" );
785*cdf0e10cSrcweir     return sal_False;
786*cdf0e10cSrcweir }
787*cdf0e10cSrcweir 
788*cdf0e10cSrcweir // -----------------------------------------------------------------------
789*cdf0e10cSrcweir 
790*cdf0e10cSrcweir sal_Bool AquaSalPrinter::EndJob()
791*cdf0e10cSrcweir {
792*cdf0e10cSrcweir 	return mpInfoPrinter->EndJob();
793*cdf0e10cSrcweir }
794*cdf0e10cSrcweir 
795*cdf0e10cSrcweir // -----------------------------------------------------------------------
796*cdf0e10cSrcweir 
797*cdf0e10cSrcweir sal_Bool AquaSalPrinter::AbortJob()
798*cdf0e10cSrcweir {
799*cdf0e10cSrcweir 	return mpInfoPrinter->AbortJob();
800*cdf0e10cSrcweir }
801*cdf0e10cSrcweir 
802*cdf0e10cSrcweir // -----------------------------------------------------------------------
803*cdf0e10cSrcweir 
804*cdf0e10cSrcweir SalGraphics* AquaSalPrinter::StartPage( ImplJobSetup* i_pSetupData, sal_Bool i_bNewJobData )
805*cdf0e10cSrcweir {
806*cdf0e10cSrcweir 	return mpInfoPrinter->StartPage( i_pSetupData, i_bNewJobData );
807*cdf0e10cSrcweir }
808*cdf0e10cSrcweir 
809*cdf0e10cSrcweir // -----------------------------------------------------------------------
810*cdf0e10cSrcweir 
811*cdf0e10cSrcweir sal_Bool AquaSalPrinter::EndPage()
812*cdf0e10cSrcweir {
813*cdf0e10cSrcweir 	return mpInfoPrinter->EndPage();
814*cdf0e10cSrcweir }
815*cdf0e10cSrcweir 
816*cdf0e10cSrcweir // -----------------------------------------------------------------------
817*cdf0e10cSrcweir 
818*cdf0e10cSrcweir sal_uLong AquaSalPrinter::GetErrorCode()
819*cdf0e10cSrcweir {
820*cdf0e10cSrcweir 	return mpInfoPrinter->GetErrorCode();
821*cdf0e10cSrcweir }
822*cdf0e10cSrcweir 
823*cdf0e10cSrcweir void AquaSalInfoPrinter::InitPaperFormats( const ImplJobSetup* )
824*cdf0e10cSrcweir {
825*cdf0e10cSrcweir     m_aPaperFormats.clear();
826*cdf0e10cSrcweir     m_bPapersInit = true;
827*cdf0e10cSrcweir 
828*cdf0e10cSrcweir     if( mpPrinter )
829*cdf0e10cSrcweir     {
830*cdf0e10cSrcweir         if( [mpPrinter statusForTable: @"PPD"] == NSPrinterTableOK )
831*cdf0e10cSrcweir         {
832*cdf0e10cSrcweir             NSArray* pPaperNames = [mpPrinter stringListForKey: @"PageSize" inTable: @"PPD"];
833*cdf0e10cSrcweir             if( pPaperNames )
834*cdf0e10cSrcweir             {
835*cdf0e10cSrcweir                 unsigned int nPapers = [pPaperNames count];
836*cdf0e10cSrcweir                 for( unsigned int i = 0; i < nPapers; i++ )
837*cdf0e10cSrcweir                 {
838*cdf0e10cSrcweir                     NSString* pPaper = [pPaperNames objectAtIndex: i];
839*cdf0e10cSrcweir                     // first try to match the name
840*cdf0e10cSrcweir                     rtl::OString aPaperName( [pPaper UTF8String] );
841*cdf0e10cSrcweir                     Paper ePaper = PaperInfo::fromPSName( aPaperName );
842*cdf0e10cSrcweir                     if( ePaper != PAPER_USER )
843*cdf0e10cSrcweir                     {
844*cdf0e10cSrcweir                         m_aPaperFormats.push_back( PaperInfo( ePaper ) );
845*cdf0e10cSrcweir                     }
846*cdf0e10cSrcweir                     else
847*cdf0e10cSrcweir                     {
848*cdf0e10cSrcweir                         NSSize aPaperSize = [mpPrinter pageSizeForPaper: pPaper];
849*cdf0e10cSrcweir                         if( aPaperSize.width > 0 && aPaperSize.height > 0 )
850*cdf0e10cSrcweir                         {
851*cdf0e10cSrcweir                             PaperInfo aInfo( PtTo10Mu( aPaperSize.width ),
852*cdf0e10cSrcweir                                              PtTo10Mu( aPaperSize.height ) );
853*cdf0e10cSrcweir                             if( aInfo.getPaper() == PAPER_USER )
854*cdf0e10cSrcweir                                 aInfo.doSloppyFit();
855*cdf0e10cSrcweir                             m_aPaperFormats.push_back( aInfo );
856*cdf0e10cSrcweir                         }
857*cdf0e10cSrcweir                     }
858*cdf0e10cSrcweir                 }
859*cdf0e10cSrcweir             }
860*cdf0e10cSrcweir         }
861*cdf0e10cSrcweir     }
862*cdf0e10cSrcweir }
863*cdf0e10cSrcweir 
864*cdf0e10cSrcweir const PaperInfo* AquaSalInfoPrinter::matchPaper( long i_nWidth, long i_nHeight, Orientation& o_rOrientation ) const
865*cdf0e10cSrcweir {
866*cdf0e10cSrcweir     if( ! m_bPapersInit )
867*cdf0e10cSrcweir         const_cast<AquaSalInfoPrinter*>(this)->InitPaperFormats( NULL );
868*cdf0e10cSrcweir 
869*cdf0e10cSrcweir     const PaperInfo* pMatch = NULL;
870*cdf0e10cSrcweir     o_rOrientation = ORIENTATION_PORTRAIT;
871*cdf0e10cSrcweir     for( int n = 0; n < 2 ; n++ )
872*cdf0e10cSrcweir     {
873*cdf0e10cSrcweir         for( size_t i = 0; i < m_aPaperFormats.size(); i++ )
874*cdf0e10cSrcweir         {
875*cdf0e10cSrcweir             if( abs( m_aPaperFormats[i].getWidth() - i_nWidth ) < 50 &&
876*cdf0e10cSrcweir                 abs( m_aPaperFormats[i].getHeight() - i_nHeight ) < 50 )
877*cdf0e10cSrcweir             {
878*cdf0e10cSrcweir                 pMatch = &m_aPaperFormats[i];
879*cdf0e10cSrcweir                 return pMatch;
880*cdf0e10cSrcweir             }
881*cdf0e10cSrcweir         }
882*cdf0e10cSrcweir         o_rOrientation = ORIENTATION_LANDSCAPE;
883*cdf0e10cSrcweir         std::swap( i_nWidth, i_nHeight );
884*cdf0e10cSrcweir     }
885*cdf0e10cSrcweir     return pMatch;
886*cdf0e10cSrcweir }
887*cdf0e10cSrcweir 
888*cdf0e10cSrcweir int AquaSalInfoPrinter::GetLandscapeAngle( const ImplJobSetup* )
889*cdf0e10cSrcweir {
890*cdf0e10cSrcweir     return 900;
891*cdf0e10cSrcweir }
892*cdf0e10cSrcweir 
893*cdf0e10cSrcweir 
894