xref: /haiku/src/add-ons/print/drivers/preview/PrinterDriver.h (revision 51978af14a173e7fae0563b562be5603bc652aeb)
1 /*
2 
3 Preview printer driver.
4 
5 Copyright (c) 2001 OpenBeOS.
6 
7 Authors:
8 	Philippe Houdoin
9 	Simon Gauvin
10 	Michael Pfeiffer
11 
12 Permission is hereby granted, free of charge, to any person obtaining a copy of
13 this software and associated documentation files (the "Software"), to deal in
14 the Software without restriction, including without limitation the rights to
15 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
16 of the Software, and to permit persons to whom the Software is furnished to do
17 so, subject to the following conditions:
18 
19 The above copyright notice and this permission notice shall be included in all
20 copies or substantial portions of the Software.
21 
22 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 THE SOFTWARE.
29 
30 */
31 
32 #ifndef PRINTERDRIVER_H
33 #define PRINTERDRIVER_H
34 
35 #include <AppKit.h>
36 #include <InterfaceKit.h>
37 #include "InterfaceUtils.h"
38 
39 #ifndef ROUND_UP
40 	#define ROUND_UP(x, y) (((x) + (y) - 1) & ~((y) - 1))
41 #endif
42 
43 #define MAX_INT32 ((int32)0x7fffffffL)
44 
45 /* copied from PDFlib.h: */
46 #define a0_width	 (float) 2380.0
47 #define a0_height	 (float) 3368.0
48 #define a1_width	 (float) 1684.0
49 #define a1_height	 (float) 2380.0
50 #define a2_width	 (float) 1190.0
51 #define a2_height	 (float) 1684.0
52 #define a3_width	 (float) 842.0
53 #define a3_height	 (float) 1190.0
54 #define a4_width	 (float) 595.0
55 #define a4_height	 (float) 842.0
56 #define a5_width	 (float) 421.0
57 #define a5_height	 (float) 595.0
58 #define a6_width	 (float) 297.0
59 #define a6_height	 (float) 421.0
60 #define b5_width	 (float) 501.0
61 #define b5_height	 (float) 709.0
62 #define letter_width	 (float) 612.0
63 #define letter_height	 (float) 792.0
64 #define legal_width 	 (float) 612.0
65 #define legal_height 	 (float) 1008.0
66 #define ledger_width	 (float) 1224.0
67 #define ledger_height	 (float) 792.0
68 #define p11x17_width	 (float) 792.0
69 #define p11x17_height	 (float) 1224.0
70 
71 // transport add-on calls definition
72 extern "C" {
73 	typedef BDataIO *(*init_transport_proc)(BMessage *);
74 	typedef void 	(*exit_transport_proc)(void);
75 };
76 
77 
78 /**
79  * Class PrinterDriver
80  */
81 class PrinterDriver
82 {
83 public:
84 	// constructors / destructor
85 							PrinterDriver(BNode* printerNode);
86 	virtual					~PrinterDriver();
87 
88 	void StopPrinting();
89 
90 	virtual status_t 		PrintJob(BFile *jobFile, BMessage *jobMsg);
91 	virtual status_t        BeginJob();
92 	virtual status_t		PrintPage(int32 pageNumber, int32 pageCount);
93 	virtual status_t        EndJob();
94 
95 	// configuration window getters
96 	virtual BlockingWindow* NewPrinterSetupWindow(char* printerName);
97 	virtual BlockingWindow* NewPageSetupWindow(BMessage *setupMsg, const char *printerName);
98 	virtual BlockingWindow* NewJobSetupWindow(BMessage *setupMsg, const char *printerName);
99 
100 	// configuration default methods
101 	virtual status_t 		PrinterSetup(char *printerName);
102 	virtual status_t 		PageSetup(BMessage *msg, const char *printerName = NULL);
103 	virtual status_t 		JobSetup(BMessage *msg, const char *printerName = NULL);
104 	virtual BMessage*       GetDefaultSettings();
105 
106 	// transport-related methods
107 	status_t				OpenTransport();
108 	status_t				CloseTransport();
109 	bool                    PrintToFileCanceled();
110 
111 	// accessors
112 	inline BFile			*JobFile()		{ return fJobFile; }
113 	inline BNode			*PrinterNode()	{ return fPrinterNode; }
114 	inline BMessage			*JobMsg()		{ return fJobMsg; }
115 	inline BDataIO			*Transport()	{ return fTransport; }
116 	inline int32            Pass() const    { return fPass; }
117 
118 	// publics status code
119 	typedef enum {
120 		PORTRAIT_ORIENTATION,
121 		LANDSCAPE_ORIENTATION
122 	} Orientation;
123 
124 
125 private:
126 	status_t Go(BlockingWindow* w);
127 
128 	BFile					*fJobFile;
129 	BNode					*fPrinterNode;
130 	BMessage				*fJobMsg;
131 
132 	volatile Orientation	fOrientation;
133 
134 	bool					fPrinting;
135 	int32                   fPass;
136 
137 	// transport-related
138 	BDataIO					*fTransport;
139 	image_id				fTransportAddOn;
140 	init_transport_proc		fTransportInitProc;
141 	exit_transport_proc		fTransportExitProc;
142 };
143 
144 #endif // #ifndef PRINTERDRIVER_H
145 
146