xref: /aoo42x/main/vcl/inc/aqua/salprn.h (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 #ifndef _SV_SALPRN_H
29*cdf0e10cSrcweir #define _SV_SALPRN_H
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include "aqua/aquavcltypes.h"
32*cdf0e10cSrcweir 
33*cdf0e10cSrcweir #include "salprn.hxx"
34*cdf0e10cSrcweir 
35*cdf0e10cSrcweir #include <boost/shared_array.hpp>
36*cdf0e10cSrcweir 
37*cdf0e10cSrcweir 
38*cdf0e10cSrcweir // ---------------------
39*cdf0e10cSrcweir // - AquaSalInfoPrinter -
40*cdf0e10cSrcweir // ---------------------
41*cdf0e10cSrcweir 
42*cdf0e10cSrcweir class AquaSalGraphics;
43*cdf0e10cSrcweir 
44*cdf0e10cSrcweir class AquaSalInfoPrinter : public SalInfoPrinter
45*cdf0e10cSrcweir {
46*cdf0e10cSrcweir     /// Printer graphics
47*cdf0e10cSrcweir 	AquaSalGraphics*		mpGraphics;
48*cdf0e10cSrcweir     /// is Graphics used
49*cdf0e10cSrcweir 	bool					mbGraphics;
50*cdf0e10cSrcweir     /// job active ?
51*cdf0e10cSrcweir     bool                    mbJob;
52*cdf0e10cSrcweir 
53*cdf0e10cSrcweir     /// cocoa printer object
54*cdf0e10cSrcweir     NSPrinter*              mpPrinter;
55*cdf0e10cSrcweir     /// cocoa print info object
56*cdf0e10cSrcweir     NSPrintInfo*            mpPrintInfo;
57*cdf0e10cSrcweir 
58*cdf0e10cSrcweir     /// FIXME: get real printer context for infoprinter if possible
59*cdf0e10cSrcweir     /// fake context for info printer
60*cdf0e10cSrcweir     /// graphics context for Quartz 2D
61*cdf0e10cSrcweir 	CGContextRef		                    mrContext;
62*cdf0e10cSrcweir     /// memory for graphics bitmap context for querying metrics
63*cdf0e10cSrcweir     boost::shared_array< sal_uInt8 >        maContextMemory;
64*cdf0e10cSrcweir 
65*cdf0e10cSrcweir     // since changes to NSPrintInfo during a job are ignored
66*cdf0e10cSrcweir     // we have to care for some settings ourselves
67*cdf0e10cSrcweir     // currently we do this for orientation;
68*cdf0e10cSrcweir     // really needed however is a solution for paper formats
69*cdf0e10cSrcweir     Orientation               mePageOrientation;
70*cdf0e10cSrcweir 
71*cdf0e10cSrcweir     int                       mnStartPageOffsetX;
72*cdf0e10cSrcweir     int                       mnStartPageOffsetY;
73*cdf0e10cSrcweir     sal_Int32                 mnCurPageRangeStart;
74*cdf0e10cSrcweir     sal_Int32                 mnCurPageRangeCount;
75*cdf0e10cSrcweir 
76*cdf0e10cSrcweir     public:
77*cdf0e10cSrcweir     AquaSalInfoPrinter( const SalPrinterQueueInfo& pInfo );
78*cdf0e10cSrcweir     virtual ~AquaSalInfoPrinter();
79*cdf0e10cSrcweir 
80*cdf0e10cSrcweir     void                        SetupPrinterGraphics( CGContextRef i_xContext ) const;
81*cdf0e10cSrcweir 
82*cdf0e10cSrcweir 	virtual SalGraphics*		GetGraphics();
83*cdf0e10cSrcweir 	virtual void				ReleaseGraphics( SalGraphics* i_pGraphics );
84*cdf0e10cSrcweir 	virtual sal_Bool				Setup( SalFrame* i_pFrame, ImplJobSetup* i_pSetupData );
85*cdf0e10cSrcweir 	virtual sal_Bool				SetPrinterData( ImplJobSetup* pSetupData );
86*cdf0e10cSrcweir 	virtual sal_Bool				SetData( sal_uLong i_nFlags, ImplJobSetup* i_pSetupData );
87*cdf0e10cSrcweir 	virtual void				GetPageInfo( const ImplJobSetup* i_pSetupData,
88*cdf0e10cSrcweir                                              long& o_rOutWidth, long& o_rOutHeight,
89*cdf0e10cSrcweir                                              long& o_rPageOffX, long& o_rPageOffY,
90*cdf0e10cSrcweir                                              long& o_rPageWidth, long& o_rPageHeight );
91*cdf0e10cSrcweir 	virtual sal_uLong				GetCapabilities( const ImplJobSetup* i_pSetupData, sal_uInt16 i_nType );
92*cdf0e10cSrcweir 	virtual sal_uLong				GetPaperBinCount( const ImplJobSetup* i_pSetupData );
93*cdf0e10cSrcweir 	virtual String				GetPaperBinName( const ImplJobSetup* i_pSetupData, sal_uLong i_nPaperBin );
94*cdf0e10cSrcweir     virtual void				InitPaperFormats( const ImplJobSetup* i_pSetupData );
95*cdf0e10cSrcweir     virtual int					GetLandscapeAngle( const ImplJobSetup* i_pSetupData );
96*cdf0e10cSrcweir 
97*cdf0e10cSrcweir     // the artificial separation between InfoPrinter and Printer
98*cdf0e10cSrcweir     // is not really useful for us
99*cdf0e10cSrcweir     // so let's make AquaSalPrinter just a forwarder to AquaSalInfoPrinter
100*cdf0e10cSrcweir     // and concentrate the real work in one class
101*cdf0e10cSrcweir     // implement pull model print system
102*cdf0e10cSrcweir     sal_Bool                        StartJob( const String* i_pFileName,
103*cdf0e10cSrcweir                                           const String& rJobName,
104*cdf0e10cSrcweir                                           const String& i_rAppName,
105*cdf0e10cSrcweir                                           ImplJobSetup* i_pSetupData,
106*cdf0e10cSrcweir                                           vcl::PrinterController& i_rController );
107*cdf0e10cSrcweir     sal_Bool					    EndJob();
108*cdf0e10cSrcweir 	sal_Bool    					AbortJob();
109*cdf0e10cSrcweir 	SalGraphics*    			StartPage( ImplJobSetup* i_pSetupData, sal_Bool i_bNewJobData );
110*cdf0e10cSrcweir 	sal_Bool    					EndPage();
111*cdf0e10cSrcweir 	sal_uLong	    				GetErrorCode() const;
112*cdf0e10cSrcweir 
113*cdf0e10cSrcweir     NSPrintInfo* getPrintInfo() const { return mpPrintInfo; }
114*cdf0e10cSrcweir     void setStartPageOffset( int nOffsetX, int nOffsetY ) { mnStartPageOffsetX = nOffsetX; mnStartPageOffsetY = nOffsetY; }
115*cdf0e10cSrcweir     sal_Int32 getCurPageRangeStart() const { return mnCurPageRangeStart; }
116*cdf0e10cSrcweir     sal_Int32 getCurPageRangeCount() const { return mnCurPageRangeCount; }
117*cdf0e10cSrcweir 
118*cdf0e10cSrcweir     // match width/height against known paper formats, possibly switching orientation
119*cdf0e10cSrcweir     const PaperInfo* matchPaper( long i_nWidth, long i_nHeight, Orientation& o_rOrientation ) const;
120*cdf0e10cSrcweir     void setPaperSize( long i_nWidth, long i_nHeight, Orientation i_eSetOrientation );
121*cdf0e10cSrcweir 
122*cdf0e10cSrcweir     private:
123*cdf0e10cSrcweir     AquaSalInfoPrinter( const AquaSalInfoPrinter& );
124*cdf0e10cSrcweir     AquaSalInfoPrinter& operator=(const AquaSalInfoPrinter&);
125*cdf0e10cSrcweir };
126*cdf0e10cSrcweir 
127*cdf0e10cSrcweir // -----------------
128*cdf0e10cSrcweir // - AquaSalPrinter -
129*cdf0e10cSrcweir // -----------------
130*cdf0e10cSrcweir 
131*cdf0e10cSrcweir class AquaSalPrinter : public SalPrinter
132*cdf0e10cSrcweir {
133*cdf0e10cSrcweir 	AquaSalInfoPrinter* 		mpInfoPrinter;			// pointer to the compatible InfoPrinter
134*cdf0e10cSrcweir     public:
135*cdf0e10cSrcweir     AquaSalPrinter( AquaSalInfoPrinter* i_pInfoPrinter );
136*cdf0e10cSrcweir     virtual ~AquaSalPrinter();
137*cdf0e10cSrcweir 
138*cdf0e10cSrcweir 	virtual sal_Bool					StartJob( const XubString* i_pFileName,
139*cdf0e10cSrcweir                                               const XubString& i_rJobName,
140*cdf0e10cSrcweir                                               const XubString& i_rAppName,
141*cdf0e10cSrcweir                                               sal_uLong i_nCopies,
142*cdf0e10cSrcweir                                               bool i_bCollate,
143*cdf0e10cSrcweir                                               bool i_bDirect,
144*cdf0e10cSrcweir                                               ImplJobSetup* i_pSetupData );
145*cdf0e10cSrcweir     // implement pull model print system
146*cdf0e10cSrcweir     virtual sal_Bool                    StartJob( const String* i_pFileName,
147*cdf0e10cSrcweir                                               const String& rJobName,
148*cdf0e10cSrcweir                                               const String& i_rAppName,
149*cdf0e10cSrcweir                                               ImplJobSetup* i_pSetupData,
150*cdf0e10cSrcweir                                               vcl::PrinterController& i_rListener );
151*cdf0e10cSrcweir 
152*cdf0e10cSrcweir 	virtual sal_Bool					EndJob();
153*cdf0e10cSrcweir 	virtual sal_Bool					AbortJob();
154*cdf0e10cSrcweir 	virtual SalGraphics*			StartPage( ImplJobSetup* i_pSetupData, sal_Bool i_bNewJobData );
155*cdf0e10cSrcweir 	virtual sal_Bool					EndPage();
156*cdf0e10cSrcweir 	virtual sal_uLong					GetErrorCode();
157*cdf0e10cSrcweir 
158*cdf0e10cSrcweir     private:
159*cdf0e10cSrcweir     AquaSalPrinter( const AquaSalPrinter& );
160*cdf0e10cSrcweir     AquaSalPrinter& operator=(const AquaSalPrinter&);
161*cdf0e10cSrcweir };
162*cdf0e10cSrcweir 
163*cdf0e10cSrcweir const double fPtTo100thMM = 35.27777778;
164*cdf0e10cSrcweir 
165*cdf0e10cSrcweir inline int PtTo10Mu( double nPoints ) { return (int)(((nPoints)*fPtTo100thMM)+0.5); }
166*cdf0e10cSrcweir 
167*cdf0e10cSrcweir inline double TenMuToPt( double nUnits ) { return floor(((nUnits)/fPtTo100thMM)+0.5); }
168*cdf0e10cSrcweir 
169*cdf0e10cSrcweir 
170*cdf0e10cSrcweir 
171*cdf0e10cSrcweir #endif // _SV_SALPRN_H
172