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