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