xref: /haiku/src/add-ons/print/drivers/preview/PrinterDriver.h (revision 93aeb8c3bc3f13cb1f282e3e749258a23790d947)
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 "PrintTransport.h"
38 #include "InterfaceUtils.h"
39 
40 #ifndef ROUND_UP
41 	#define ROUND_UP(x, y) (((x) + (y) - 1) & ~((y) - 1))
42 #endif
43 
44 #define MAX_INT32 ((int32)0x7fffffffL)
45 
46 /* copied from PDFlib.h: */
47 #define a0_width	 (float) 2380.0
48 #define a0_height	 (float) 3368.0
49 #define a1_width	 (float) 1684.0
50 #define a1_height	 (float) 2380.0
51 #define a2_width	 (float) 1190.0
52 #define a2_height	 (float) 1684.0
53 #define a3_width	 (float) 842.0
54 #define a3_height	 (float) 1190.0
55 #define a4_width	 (float) 595.0
56 #define a4_height	 (float) 842.0
57 #define a5_width	 (float) 421.0
58 #define a5_height	 (float) 595.0
59 #define a6_width	 (float) 297.0
60 #define a6_height	 (float) 421.0
61 #define b5_width	 (float) 501.0
62 #define b5_height	 (float) 709.0
63 #define letter_width	 (float) 612.0
64 #define letter_height	 (float) 792.0
65 #define legal_width 	 (float) 612.0
66 #define legal_height 	 (float) 1008.0
67 #define ledger_width	 (float) 1224.0
68 #define ledger_height	 (float) 792.0
69 #define p11x17_width	 (float) 792.0
70 #define p11x17_height	 (float) 1224.0
71 
72 
73 /**
74  * Class PrinterDriver
75  */
76 class PrinterDriver
77 {
78 public:
79 	// constructors / destructor
80 							PrinterDriver(BNode* printerNode);
81 	virtual					~PrinterDriver();
82 
83 	void StopPrinting();
84 
85 	virtual status_t 		PrintJob(BFile *jobFile, BMessage *jobMsg);
86 	virtual status_t        BeginJob();
87 	virtual status_t		PrintPage(int32 pageNumber, int32 pageCount);
88 	virtual status_t        EndJob();
89 
90 	// configuration window getters
91 	virtual BlockingWindow* NewPrinterSetupWindow(char* printerName);
92 	virtual BlockingWindow* NewPageSetupWindow(BMessage *setupMsg, const char *printerName);
93 	virtual BlockingWindow* NewJobSetupWindow(BMessage *setupMsg, const char *printerName);
94 
95 	// configuration default methods
96 	virtual status_t 		PrinterSetup(char *printerName);
97 	virtual status_t 		PageSetup(BMessage *msg, const char *printerName = NULL);
98 	virtual status_t 		JobSetup(BMessage *msg, const char *printerName = NULL);
99 	virtual BMessage*       GetDefaultSettings();
100 
101 	// accessors
102 	inline BFile			*JobFile()		{ return fJobFile; }
103 	inline BNode			*PrinterNode()	{ return fPrinterNode; }
104 	inline BMessage			*JobMsg()		{ return fJobMsg; }
105 	inline BDataIO			*Transport()	{ return fPrintTransport.GetDataIO(); }
106 	inline int32            Pass() const    { return fPass; }
107 
108 	// publics status code
109 	typedef enum {
110 		PORTRAIT_ORIENTATION,
111 		LANDSCAPE_ORIENTATION
112 	} Orientation;
113 
114 
115 private:
116 	status_t Go(BlockingWindow* w);
117 
118 	BFile					*fJobFile;
119 	BNode					*fPrinterNode;
120 	BMessage				*fJobMsg;
121 
122 	volatile Orientation	fOrientation;
123 
124 	bool					fPrinting;
125 	int32                   fPass;
126 
127 	// transport-related
128 	PrintTransport          fPrintTransport;
129 };
130 
131 #endif // #ifndef PRINTERDRIVER_H
132 
133