xref: /aoo41x/main/vcl/os2/source/gdi/salprn.cxx (revision 651793b0)
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 // use this define to disable the DJP support
25cdf0e10cSrcweir // #define NO_DJP
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #define INCL_DOSMODULEMGR
28cdf0e10cSrcweir #define INCL_DEV
29cdf0e10cSrcweir #define INCL_SPL
30cdf0e10cSrcweir #define INCL_SPLERRORS
31cdf0e10cSrcweir #define INCL_SPLDOSPRINT
32cdf0e10cSrcweir #define INCL_DEVDJP
33cdf0e10cSrcweir 
34cdf0e10cSrcweir #define INCL_GPI
35cdf0e10cSrcweir #define INCL_DOSSEMAPHORES
36cdf0e10cSrcweir #define INCL_PM
37cdf0e10cSrcweir #include <svpm.h>
38cdf0e10cSrcweir #include <pmdjp.h>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir #include <string.h>
41cdf0e10cSrcweir 
42fc9fd3f1SPedro Giffuni #include <osl/module.h>
43fc9fd3f1SPedro Giffuni 
44fc9fd3f1SPedro Giffuni #include <tools/urlobj.hxx>
45fc9fd3f1SPedro Giffuni #include <tools/svwin.h>
46fc9fd3f1SPedro Giffuni #ifdef __MINGW32__
47fc9fd3f1SPedro Giffuni #include <excpt.h>
48fc9fd3f1SPedro Giffuni #endif
49fc9fd3f1SPedro Giffuni 
50fc9fd3f1SPedro Giffuni #include <os2/saldata.hxx>
51fc9fd3f1SPedro Giffuni #include <os2/salinst.h>
52fc9fd3f1SPedro Giffuni #include <os2/salgdi.h>
53fc9fd3f1SPedro Giffuni #include <os2/salframe.h>
54fc9fd3f1SPedro Giffuni #include <os2/salprn.h>
55fc9fd3f1SPedro Giffuni 
56fc9fd3f1SPedro Giffuni #include <salptype.hxx>
57fc9fd3f1SPedro Giffuni #include <print.h>
58fc9fd3f1SPedro Giffuni #include <jobset.h>
59fc9fd3f1SPedro Giffuni 
60fc9fd3f1SPedro Giffuni #include <malloc.h>
61fc9fd3f1SPedro Giffuni 
62cdf0e10cSrcweir #ifndef __H_FT2LIB
63fc9fd3f1SPedro Giffuni #include <os2/wingdi.h>
64cdf0e10cSrcweir #include <ft2lib.h>
65cdf0e10cSrcweir #endif
66cdf0e10cSrcweir 
67cdf0e10cSrcweir // =======================================================================
68cdf0e10cSrcweir 
69cdf0e10cSrcweir // -----------------------
70cdf0e10cSrcweir // - struct ImplFormInfo -
71cdf0e10cSrcweir // -----------------------
72cdf0e10cSrcweir 
73cdf0e10cSrcweir struct ImplFormInfo
74cdf0e10cSrcweir {
75cdf0e10cSrcweir 	long					mnPaperWidth;
76cdf0e10cSrcweir 	long					mnPaperHeight;
77cdf0e10cSrcweir #ifndef NO_DJP
78cdf0e10cSrcweir 	DJPT_PAPERSIZE			mnId;
79cdf0e10cSrcweir #endif
80cdf0e10cSrcweir };
81cdf0e10cSrcweir 
82cdf0e10cSrcweir // =======================================================================
83cdf0e10cSrcweir 
84cdf0e10cSrcweir // -----------------------
85cdf0e10cSrcweir // - struct ImplTrayInfo -
86cdf0e10cSrcweir // -----------------------
87cdf0e10cSrcweir 
88cdf0e10cSrcweir struct ImplTrayInfo
89cdf0e10cSrcweir {
90cdf0e10cSrcweir 	CHAR			maName[32];
91cdf0e10cSrcweir 	CHAR			maDisplayName[64];
92cdf0e10cSrcweir 	DJPT_TRAYTYPE	mnId;
93cdf0e10cSrcweir 
94cdf0e10cSrcweir 	ImplTrayInfo( const char* pTrayName,
95cdf0e10cSrcweir 				  const char* pTrayDisplayName )
96cdf0e10cSrcweir 	{
97cdf0e10cSrcweir 		strcpy( maName, pTrayName);
98cdf0e10cSrcweir 		strcpy( maDisplayName, pTrayDisplayName);
99cdf0e10cSrcweir 	}
100cdf0e10cSrcweir };
101cdf0e10cSrcweir 
102cdf0e10cSrcweir // =======================================================================
103cdf0e10cSrcweir 
104cdf0e10cSrcweir struct ImplQueueSalSysData
105cdf0e10cSrcweir {
106cdf0e10cSrcweir 	ByteString		maPrinterName;			// pszPrinters
107cdf0e10cSrcweir 	ByteString		maName; 				// pszName bzw. LogAddress
108cdf0e10cSrcweir 	ByteString		maOrgDriverName;		// pszDriverName (maDriverName.maDeviceName)
109cdf0e10cSrcweir 	ByteString		maDriverName;			// pszDriverName bis .
110cdf0e10cSrcweir 	ByteString		maDeviceName;			// pszDriverName nach .
111cdf0e10cSrcweir 	PDRIVDATA		mpDrivData;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir 					ImplQueueSalSysData( const ByteString& rPrinterName,
114cdf0e10cSrcweir 										 const ByteString& rName,
115cdf0e10cSrcweir 										 const ByteString& rDriverName,
116cdf0e10cSrcweir 										 const ByteString& rDeviceName,
117cdf0e10cSrcweir 										 const ByteString& rOrgDriverName,
118cdf0e10cSrcweir 										 PDRIVDATA pDrivData  );
119cdf0e10cSrcweir 					~ImplQueueSalSysData();
120cdf0e10cSrcweir };
121cdf0e10cSrcweir 
122cdf0e10cSrcweir // -----------------------------------------------------------------------
123cdf0e10cSrcweir 
124cdf0e10cSrcweir ImplQueueSalSysData::ImplQueueSalSysData( const ByteString& rPrinterName,
125cdf0e10cSrcweir 										  const ByteString& rName,
126cdf0e10cSrcweir 										  const ByteString& rOrgDriverName,
127cdf0e10cSrcweir 										  const ByteString& rDriverName,
128cdf0e10cSrcweir 										  const ByteString& rDeviceName,
129cdf0e10cSrcweir 										  PDRIVDATA pDrivData ) :
130cdf0e10cSrcweir 	maPrinterName( rPrinterName ),
131cdf0e10cSrcweir 	maName( rName ),
132cdf0e10cSrcweir 	maOrgDriverName( rName ),
133cdf0e10cSrcweir 	maDriverName( rDriverName ),
134cdf0e10cSrcweir 	maDeviceName( rDeviceName )
135cdf0e10cSrcweir {
136cdf0e10cSrcweir 	if ( pDrivData )
137cdf0e10cSrcweir 	{
138fc9fd3f1SPedro Giffuni 		mpDrivData = (PDRIVDATA)new PM_BYTE[pDrivData->cb];
139cdf0e10cSrcweir 		memcpy( mpDrivData, pDrivData, pDrivData->cb );
140cdf0e10cSrcweir 	}
141cdf0e10cSrcweir 	else
142cdf0e10cSrcweir 		mpDrivData = NULL;
143cdf0e10cSrcweir }
144cdf0e10cSrcweir 
145cdf0e10cSrcweir // -----------------------------------------------------------------------
146cdf0e10cSrcweir 
147cdf0e10cSrcweir ImplQueueSalSysData::~ImplQueueSalSysData()
148cdf0e10cSrcweir {
149cdf0e10cSrcweir 	delete mpDrivData;
150cdf0e10cSrcweir }
151cdf0e10cSrcweir 
152cdf0e10cSrcweir // =======================================================================
153cdf0e10cSrcweir 
154cdf0e10cSrcweir static ULONG ImplPMQueueStatusToSal( USHORT nPMStatus )
155cdf0e10cSrcweir {
156cdf0e10cSrcweir 	ULONG nStatus = 0;
157cdf0e10cSrcweir 	if ( nPMStatus & PRQ3_PAUSED )
158cdf0e10cSrcweir 		nStatus |= QUEUE_STATUS_PAUSED;
159cdf0e10cSrcweir 	if ( nPMStatus & PRQ3_PENDING )
160cdf0e10cSrcweir 		nStatus |= QUEUE_STATUS_PENDING_DELETION;
161cdf0e10cSrcweir 	if ( !nStatus )
162cdf0e10cSrcweir 		nStatus |= QUEUE_STATUS_READY;
163cdf0e10cSrcweir 	return nStatus;
164cdf0e10cSrcweir }
165cdf0e10cSrcweir 
166cdf0e10cSrcweir // -----------------------------------------------------------------------
167cdf0e10cSrcweir 
168cdf0e10cSrcweir void Os2SalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList )
169cdf0e10cSrcweir {
170cdf0e10cSrcweir 	APIRET rc;
171cdf0e10cSrcweir 	ULONG  nNeeded;
172cdf0e10cSrcweir 	ULONG  nReturned;
173cdf0e10cSrcweir 	ULONG  nTotal;
174cdf0e10cSrcweir 
175cdf0e10cSrcweir 	// query needed size of the buffer for the QueueInfo
176cdf0e10cSrcweir 	rc = SplEnumQueue( (PSZ)NULL, 3, NULL, 0, &nReturned, &nTotal, &nNeeded, NULL );
177cdf0e10cSrcweir 	if( nNeeded == 0 )
178cdf0e10cSrcweir 		return;
179cdf0e10cSrcweir 
180cdf0e10cSrcweir 	// create the buffer for the QueueInfo
181cdf0e10cSrcweir 	PCHAR pQueueData = new CHAR[nNeeded];
182cdf0e10cSrcweir 
183cdf0e10cSrcweir 	// query QueueInfos
184cdf0e10cSrcweir 	rc = SplEnumQueue( (PSZ)NULL, 3, pQueueData, nNeeded, &nReturned, &nTotal, &nNeeded, NULL );
185cdf0e10cSrcweir 
186cdf0e10cSrcweir 	PPRQINFO3 pPrqInfo = (PPRQINFO3)pQueueData;
187cdf0e10cSrcweir 	for ( int i = 0; i < nReturned; i++ )
188cdf0e10cSrcweir 	{
189cdf0e10cSrcweir 		// create entry for the QueueInfo array
190cdf0e10cSrcweir 		SalPrinterQueueInfo* pInfo = new SalPrinterQueueInfo;
191cdf0e10cSrcweir 
192cdf0e10cSrcweir 		ByteString aOrgDriverName( pPrqInfo->pszDriverName);
193cdf0e10cSrcweir 		ByteString aName( pPrqInfo->pszName);
194f98951f3SYuri Dario #if OSL_DEBUG_LEVEL>0
195f98951f3SYuri Dario 		printf("GetPrinterQueueInfo pszDriverName %s\n", pPrqInfo->pszDriverName);
196f98951f3SYuri Dario 		printf("GetPrinterQueueInfo pszName %s\n", pPrqInfo->pszDriverName);
197f98951f3SYuri Dario #endif
198cdf0e10cSrcweir 		pInfo->maDriver 	 = ::rtl::OStringToOUString (aOrgDriverName, gsl_getSystemTextEncoding());
199cdf0e10cSrcweir 		pInfo->maPrinterName = ::rtl::OStringToOUString (pPrqInfo->pszComment, gsl_getSystemTextEncoding());
200cdf0e10cSrcweir 		pInfo->maLocation	 = ::rtl::OStringToOUString (aName, gsl_getSystemTextEncoding());
201cdf0e10cSrcweir 		pInfo->mnStatus 	 = ImplPMQueueStatusToSal( pPrqInfo->fsStatus );
202cdf0e10cSrcweir 		pInfo->mnJobs		 = pPrqInfo->cJobs;
203cdf0e10cSrcweir 		// pInfo->maComment = !!!
204cdf0e10cSrcweir 
205cdf0e10cSrcweir 		// Feststellen, ob Name doppelt
206cdf0e10cSrcweir 		PPRQINFO3 pTempPrqInfo = (PPRQINFO3)pQueueData;
207cdf0e10cSrcweir 		for ( int j = 0; j < nReturned; j++ )
208cdf0e10cSrcweir 		{
209cdf0e10cSrcweir 			// Wenn Name doppelt, erweitern wir diesen um die Location
210cdf0e10cSrcweir 			if ( (j != i) &&
211cdf0e10cSrcweir 				 (strcmp( pPrqInfo->pszComment, pTempPrqInfo->pszComment ) == 0) )
212cdf0e10cSrcweir 			{
213cdf0e10cSrcweir 				pInfo->maPrinterName += ';';
214cdf0e10cSrcweir 				pInfo->maPrinterName += pInfo->maLocation;
215cdf0e10cSrcweir 			}
216cdf0e10cSrcweir 			pTempPrqInfo++;
217cdf0e10cSrcweir 		}
218cdf0e10cSrcweir 
219cdf0e10cSrcweir 		// pszDriver in DriverName (bis .) und DeviceName (nach .) aufsplitten
220cdf0e10cSrcweir 		PSZ pDriverName;
221cdf0e10cSrcweir 		PSZ pDeviceName;
222cdf0e10cSrcweir 		if ( (pDriverName = strchr( pPrqInfo->pszDriverName, '.' )) != 0 )
223cdf0e10cSrcweir 		{
224cdf0e10cSrcweir 		   *pDriverName = 0;
225cdf0e10cSrcweir 		   pDeviceName	= pDriverName + 1;
226cdf0e10cSrcweir 		}
227cdf0e10cSrcweir 		else
228cdf0e10cSrcweir 			pDeviceName = NULL;
229cdf0e10cSrcweir 
230cdf0e10cSrcweir 		// Alle Bytes hinter dem DeviceNamen auf 0 initialisieren, damit
231cdf0e10cSrcweir 		// ein memcmp vom JobSetup auch funktioniert
232cdf0e10cSrcweir 		if ( pPrqInfo->pDriverData &&
233cdf0e10cSrcweir 			 (pPrqInfo->pDriverData->cb >= sizeof( pPrqInfo->pDriverData )) )
234cdf0e10cSrcweir 		{
235cdf0e10cSrcweir 			int nDeviceNameLen = strlen( pPrqInfo->pDriverData->szDeviceName );
236cdf0e10cSrcweir 			memset( pPrqInfo->pDriverData->szDeviceName+nDeviceNameLen,
237cdf0e10cSrcweir 					0,
238cdf0e10cSrcweir 					sizeof( pPrqInfo->pDriverData->szDeviceName )-nDeviceNameLen );
239cdf0e10cSrcweir 		}
240cdf0e10cSrcweir 
241cdf0e10cSrcweir 		// save driver data and driver names
242cdf0e10cSrcweir 		ByteString aPrinterName( pPrqInfo->pszPrinters);
243cdf0e10cSrcweir 		ByteString aDriverName( pPrqInfo->pszDriverName);
244cdf0e10cSrcweir 		ByteString aDeviceName;
245cdf0e10cSrcweir 		if ( pDeviceName )
246cdf0e10cSrcweir 			aDeviceName = pDeviceName;
247cdf0e10cSrcweir 		pInfo->mpSysData = new ImplQueueSalSysData( aPrinterName, aName,
248cdf0e10cSrcweir 													aOrgDriverName,
249cdf0e10cSrcweir 													aDriverName, aDeviceName,
250cdf0e10cSrcweir 													pPrqInfo->pDriverData );
251cdf0e10cSrcweir 
252cdf0e10cSrcweir 		// add queue to the list
253cdf0e10cSrcweir 		pList->Add( pInfo );
254cdf0e10cSrcweir 
255cdf0e10cSrcweir 		// increment to next element of the QueueInfo array
256cdf0e10cSrcweir 		pPrqInfo++;
257cdf0e10cSrcweir 	}
258cdf0e10cSrcweir 
259cdf0e10cSrcweir 	delete [] pQueueData;
260cdf0e10cSrcweir }
261cdf0e10cSrcweir 
262cdf0e10cSrcweir // -----------------------------------------------------------------------
263cdf0e10cSrcweir 
264cdf0e10cSrcweir void Os2SalInstance::GetPrinterQueueState( SalPrinterQueueInfo* pInfo )
265cdf0e10cSrcweir {
266cdf0e10cSrcweir 	APIRET rc;
267cdf0e10cSrcweir 	ULONG  nNeeded;
268cdf0e10cSrcweir 	ULONG  nReturned;
269cdf0e10cSrcweir 	ULONG  nTotal;
270cdf0e10cSrcweir 
271cdf0e10cSrcweir 	// query needed size of the buffer for the QueueInfo
272cdf0e10cSrcweir 	rc = SplEnumQueue( (PSZ)NULL, 3, NULL, 0, &nReturned, &nTotal, &nNeeded, NULL );
273cdf0e10cSrcweir 	if( nNeeded == 0 )
274cdf0e10cSrcweir 		return;
275cdf0e10cSrcweir 
276cdf0e10cSrcweir 	// create the buffer for the QueueInfo
277cdf0e10cSrcweir 	PCHAR pQueueData = new CHAR[nNeeded];
278cdf0e10cSrcweir 
279cdf0e10cSrcweir 	// query QueueInfos
280cdf0e10cSrcweir 	rc = SplEnumQueue( (PSZ)NULL, 3, pQueueData, nNeeded, &nReturned, &nTotal, &nNeeded, NULL );
281cdf0e10cSrcweir 
282cdf0e10cSrcweir 	PPRQINFO3 pPrqInfo = (PPRQINFO3)pQueueData;
283cdf0e10cSrcweir 	for ( int i = 0; i < nReturned; i++ )
284cdf0e10cSrcweir 	{
285cdf0e10cSrcweir 		ImplQueueSalSysData* pSysData = (ImplQueueSalSysData*)(pInfo->mpSysData);
286cdf0e10cSrcweir 		if ( pSysData->maPrinterName.Equals( pPrqInfo->pszPrinters ) &&
287cdf0e10cSrcweir 			 pSysData->maName.Equals( pPrqInfo->pszName ) &&
288cdf0e10cSrcweir 			 pSysData->maOrgDriverName.Equals( pPrqInfo->pszDriverName ) )
289cdf0e10cSrcweir 		{
290cdf0e10cSrcweir 			pInfo->mnStatus = ImplPMQueueStatusToSal( pPrqInfo->fsStatus );
291cdf0e10cSrcweir 			pInfo->mnJobs	= pPrqInfo->cJobs;
292cdf0e10cSrcweir 			break;
293cdf0e10cSrcweir 		}
294cdf0e10cSrcweir 
295cdf0e10cSrcweir 		// increment to next element of the QueueInfo array
296cdf0e10cSrcweir 		pPrqInfo++;
297cdf0e10cSrcweir 	}
298cdf0e10cSrcweir 
299cdf0e10cSrcweir 	delete [] pQueueData;
300cdf0e10cSrcweir }
301cdf0e10cSrcweir 
302cdf0e10cSrcweir // -----------------------------------------------------------------------
303cdf0e10cSrcweir 
304cdf0e10cSrcweir void Os2SalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo )
305cdf0e10cSrcweir {
306cdf0e10cSrcweir 	delete ((ImplQueueSalSysData*)(pInfo->mpSysData));
307cdf0e10cSrcweir 	delete pInfo;
308cdf0e10cSrcweir }
309cdf0e10cSrcweir 
310cdf0e10cSrcweir // -----------------------------------------------------------------------
311cdf0e10cSrcweir 
312cdf0e10cSrcweir XubString Os2SalInstance::GetDefaultPrinter()
313cdf0e10cSrcweir {
314cdf0e10cSrcweir 	APIRET		rc;
315cdf0e10cSrcweir 	ULONG		nNeeded;
316cdf0e10cSrcweir 	ULONG		nReturned;
317cdf0e10cSrcweir 	ULONG		nTotal;
318cdf0e10cSrcweir 	char		szQueueName[255];
319cdf0e10cSrcweir 	XubString	aDefaultName;
320cdf0e10cSrcweir 
321cdf0e10cSrcweir 	// query default queue
322cdf0e10cSrcweir 	if ( !PrfQueryProfileString( HINI_PROFILE, SPL_INI_SPOOLER, "QUEUE", 0, szQueueName, sizeof( szQueueName ) ) )
323cdf0e10cSrcweir 		return aDefaultName;
324cdf0e10cSrcweir 
325cdf0e10cSrcweir 	// extract first queue name
326cdf0e10cSrcweir 	PSZ pStr;
327cdf0e10cSrcweir 	if ( (pStr = strchr( szQueueName, ';' )) != 0 )
328cdf0e10cSrcweir 		*pStr = 0;
329cdf0e10cSrcweir 
330cdf0e10cSrcweir 	// query needed size of the buffer for the QueueInfo
331cdf0e10cSrcweir 	rc = SplEnumQueue( (PSZ)NULL, 3, NULL, 0, &nReturned, &nTotal, &nNeeded, NULL );
332cdf0e10cSrcweir 	if ( nNeeded == 0 )
333cdf0e10cSrcweir 		return aDefaultName;
334cdf0e10cSrcweir 
335cdf0e10cSrcweir 	// create the buffer for the QueueInfo
336cdf0e10cSrcweir 	PCHAR pQueueData = new CHAR[ nNeeded ];
337cdf0e10cSrcweir 
338cdf0e10cSrcweir 	// query QueueInfos
339cdf0e10cSrcweir 	rc = SplEnumQueue ((PSZ)NULL, 3, pQueueData, nNeeded, &nReturned, &nTotal, &nNeeded, NULL );
340cdf0e10cSrcweir 
341cdf0e10cSrcweir 	// find printer name for default queue
342cdf0e10cSrcweir 	PPRQINFO3 pPrqInfo = (PPRQINFO3) pQueueData;
343cdf0e10cSrcweir 	for ( int i = 0; i < nReturned; i++ )
344cdf0e10cSrcweir 	{
345cdf0e10cSrcweir 		if ( strcmp( pPrqInfo->pszName, szQueueName ) == 0 )
346cdf0e10cSrcweir 		{
347cdf0e10cSrcweir 			aDefaultName = ::rtl::OStringToOUString (pPrqInfo->pszComment, gsl_getSystemTextEncoding());
348cdf0e10cSrcweir 
349cdf0e10cSrcweir 			// Feststellen, ob Name doppelt
350cdf0e10cSrcweir 			PPRQINFO3 pTempPrqInfo = (PPRQINFO3)pQueueData;
351cdf0e10cSrcweir 			for ( int j = 0; j < nReturned; j++ )
352cdf0e10cSrcweir 			{
353cdf0e10cSrcweir 				// Wenn Name doppelt, erweitern wir diesen um die Location
354cdf0e10cSrcweir 				if ( (j != i) &&
355cdf0e10cSrcweir 					 (strcmp( pPrqInfo->pszComment, pTempPrqInfo->pszComment ) == 0) )
356cdf0e10cSrcweir 				{
357cdf0e10cSrcweir 					String pszName( ::rtl::OStringToOUString (pPrqInfo->pszName, gsl_getSystemTextEncoding()));
358cdf0e10cSrcweir 					aDefaultName += ';';
359cdf0e10cSrcweir 					aDefaultName += pszName;
360cdf0e10cSrcweir 				}
361cdf0e10cSrcweir 				pTempPrqInfo++;
362cdf0e10cSrcweir 			}
363cdf0e10cSrcweir 			break;
364cdf0e10cSrcweir 		}
365cdf0e10cSrcweir 
366cdf0e10cSrcweir 		// increment to next element of the QueueInfo array
367cdf0e10cSrcweir 		pPrqInfo++;
368cdf0e10cSrcweir 	}
369cdf0e10cSrcweir 
370cdf0e10cSrcweir 	delete [] pQueueData;
371cdf0e10cSrcweir 
372cdf0e10cSrcweir 	return aDefaultName;
373cdf0e10cSrcweir }
374cdf0e10cSrcweir 
375cdf0e10cSrcweir // =======================================================================
376cdf0e10cSrcweir 
377cdf0e10cSrcweir static void* ImplAllocPrnMemory( size_t n )
378cdf0e10cSrcweir {
379cdf0e10cSrcweir 	return calloc( n, 1);
380cdf0e10cSrcweir }
381cdf0e10cSrcweir 
382cdf0e10cSrcweir // -----------------------------------------------------------------------
383cdf0e10cSrcweir 
384cdf0e10cSrcweir inline void ImplFreePrnMemory( void* p )
385cdf0e10cSrcweir {
386cdf0e10cSrcweir 	free( p );
387cdf0e10cSrcweir }
388cdf0e10cSrcweir 
389cdf0e10cSrcweir // -----------------------------------------------------------------------
390cdf0e10cSrcweir 
391cdf0e10cSrcweir static PDRIVDATA ImplPrnDrivData( const ImplJobSetup* pSetupData )
392cdf0e10cSrcweir {
393cdf0e10cSrcweir 	// Diese Funktion wird eingesetzt, damit Druckertreiber nicht auf
394cdf0e10cSrcweir 	// unseren Daten arbeiten, da es durch Konfigurationsprobleme
395cdf0e10cSrcweir 	// sein kann, das der Druckertreiber bei uns Daten ueberschreibt.
396cdf0e10cSrcweir 	// Durch diese vorgehensweise werden einige Abstuerze vermieden, bzw.
397cdf0e10cSrcweir 	// sind dadurch leichter zu finden
398cdf0e10cSrcweir 
399cdf0e10cSrcweir 	if ( !pSetupData->mpDriverData )
400cdf0e10cSrcweir 		return NULL;
401cdf0e10cSrcweir 
402cdf0e10cSrcweir 	DBG_ASSERT( ((PDRIVDATA)(pSetupData->mpDriverData))->cb == pSetupData->mnDriverDataLen,
403cdf0e10cSrcweir 				"ImplPrnDrivData() - SetupDataLen != DriverDataLen" );
404cdf0e10cSrcweir 
405cdf0e10cSrcweir 	PDRIVDATA pDrivData = (PDRIVDATA)ImplAllocPrnMemory( pSetupData->mnDriverDataLen );
406cdf0e10cSrcweir 	memcpy( pDrivData, pSetupData->mpDriverData, pSetupData->mnDriverDataLen );
407cdf0e10cSrcweir 	return pDrivData;
408cdf0e10cSrcweir }
409cdf0e10cSrcweir 
410cdf0e10cSrcweir // -----------------------------------------------------------------------
411cdf0e10cSrcweir 
412cdf0e10cSrcweir static void ImplUpdateSetupData( const PDRIVDATA pDrivData, ImplJobSetup* pSetupData )
413cdf0e10cSrcweir {
414cdf0e10cSrcweir 	// Diese Funktion wird eingesetzt, damit Druckertreiber nicht auf
415cdf0e10cSrcweir 	// unseren Daten arbeiten, da es durch Konfigurationsprobleme
416cdf0e10cSrcweir 	// sein kann, das der Druckertreiber bei uns Daten ueberschreibt.
417cdf0e10cSrcweir 	// Durch diese vorgehensweise werden einige Abstuerze vermieden, bzw.
418cdf0e10cSrcweir 	// sind dadurch leichter zu finden
419cdf0e10cSrcweir 
420cdf0e10cSrcweir 	if ( !pDrivData || !pDrivData->cb )
421cdf0e10cSrcweir 	{
422cdf0e10cSrcweir 		if ( pSetupData->mpDriverData )
423cdf0e10cSrcweir 			rtl_freeMemory( pSetupData->mpDriverData );
424cdf0e10cSrcweir 		pSetupData->mpDriverData = NULL;
425cdf0e10cSrcweir 		pSetupData->mnDriverDataLen = 0;
426cdf0e10cSrcweir 	}
427cdf0e10cSrcweir 	else
428cdf0e10cSrcweir 	{
429cdf0e10cSrcweir 		// Alle Bytes hinter dem DeviceNamen auf 0 initialisieren, damit
430cdf0e10cSrcweir 		// ein memcmp vom JobSetup auch funktioniert
431cdf0e10cSrcweir 		if ( pDrivData->cb >= sizeof( pDrivData ) )
432cdf0e10cSrcweir 		{
433cdf0e10cSrcweir 			int nDeviceNameLen = strlen( pDrivData->szDeviceName );
434cdf0e10cSrcweir 			memset( pDrivData->szDeviceName+nDeviceNameLen,
435cdf0e10cSrcweir 					0,
436cdf0e10cSrcweir 					sizeof( pDrivData->szDeviceName )-nDeviceNameLen );
437cdf0e10cSrcweir 		}
438cdf0e10cSrcweir 
439cdf0e10cSrcweir 		if ( pSetupData->mpDriverData )
440cdf0e10cSrcweir 		{
441cdf0e10cSrcweir 			if ( pSetupData->mnDriverDataLen != pDrivData->cb )
442cdf0e10cSrcweir 				rtl_freeMemory( pSetupData->mpDriverData );
443fc9fd3f1SPedro Giffuni 			pSetupData->mpDriverData = (sal_uInt8*)rtl_allocateMemory( pDrivData->cb);
444cdf0e10cSrcweir 		}
445cdf0e10cSrcweir 		else
446fc9fd3f1SPedro Giffuni 			pSetupData->mpDriverData = (sal_uInt8*)rtl_allocateMemory( pDrivData->cb);
447cdf0e10cSrcweir 		pSetupData->mnDriverDataLen = pDrivData->cb;
448cdf0e10cSrcweir 		memcpy( pSetupData->mpDriverData, pDrivData, pDrivData->cb );
449cdf0e10cSrcweir 	}
450cdf0e10cSrcweir 
451cdf0e10cSrcweir 	if ( pDrivData )
452cdf0e10cSrcweir 		ImplFreePrnMemory( pDrivData );
453cdf0e10cSrcweir }
454cdf0e10cSrcweir 
455cdf0e10cSrcweir // -----------------------------------------------------------------------
456cdf0e10cSrcweir 
457fc9fd3f1SPedro Giffuni static sal_Bool ImplPaperSizeEqual( long nPaperWidth1, long nPaperHeight1,
458cdf0e10cSrcweir 								long nPaperWidth2, long nPaperHeight2 )
459cdf0e10cSrcweir {
460cdf0e10cSrcweir 	return (((nPaperWidth1 >= nPaperWidth2-1) && (nPaperWidth1 <= nPaperWidth2+1)) &&
461cdf0e10cSrcweir 			((nPaperHeight1 >= nPaperHeight2-1) && (nPaperHeight1 <= nPaperHeight2+1)));
462cdf0e10cSrcweir }
463cdf0e10cSrcweir 
464cdf0e10cSrcweir // -----------------------------------------------------------------------
465cdf0e10cSrcweir 
466fc9fd3f1SPedro Giffuni static sal_Bool ImplIsDriverDJPEnabled( HDC hDC )
467cdf0e10cSrcweir {
468cdf0e10cSrcweir #ifdef NO_DJP
469cdf0e10cSrcweir 	return FALSE;
470cdf0e10cSrcweir #else
471cdf0e10cSrcweir 	// Ueber OS2-Ini kann DJP disablte werden
472cdf0e10cSrcweir 	if ( !PrfQueryProfileInt( HINI_PROFILE, SAL_PROFILE_APPNAME, SAL_PROFILE_USEDJP, 1 ) )
473cdf0e10cSrcweir 		return FALSE;
474cdf0e10cSrcweir 
475cdf0e10cSrcweir 	// Testen, ob DJP-Interface am Drucker vorhanden
476cdf0e10cSrcweir 	LONG   lQuery;
477cdf0e10cSrcweir 	APIRET rc;
478cdf0e10cSrcweir 
479cdf0e10cSrcweir 	lQuery = DEVESC_QUERYSIZE;
480cdf0e10cSrcweir 	rc = DevEscape( hDC,
481cdf0e10cSrcweir 					DEVESC_QUERYESCSUPPORT,
482cdf0e10cSrcweir 					sizeof( lQuery ),
483cdf0e10cSrcweir 					(PBYTE)&lQuery,
484cdf0e10cSrcweir 					0,
485cdf0e10cSrcweir 					(PBYTE)NULL );
486cdf0e10cSrcweir 	if ( DEV_OK != rc )
487cdf0e10cSrcweir 		return FALSE;
488cdf0e10cSrcweir 
489cdf0e10cSrcweir 	lQuery = DEVESC_QUERYJOBPROPERTIES;
490cdf0e10cSrcweir 	rc = DevEscape( hDC,
491cdf0e10cSrcweir 					DEVESC_QUERYESCSUPPORT,
492cdf0e10cSrcweir 					sizeof( lQuery ),
493cdf0e10cSrcweir 					(PBYTE)&lQuery,
494cdf0e10cSrcweir 					0,
495cdf0e10cSrcweir 					(PBYTE)NULL );
496cdf0e10cSrcweir 	if ( DEV_OK != rc )
497cdf0e10cSrcweir 		return FALSE;
498cdf0e10cSrcweir 
499cdf0e10cSrcweir 	lQuery = DEVESC_SETJOBPROPERTIES;
500cdf0e10cSrcweir 	rc = DevEscape( hDC,
501cdf0e10cSrcweir 					DEVESC_QUERYESCSUPPORT,
502cdf0e10cSrcweir 					sizeof( lQuery ),
503cdf0e10cSrcweir 					(PBYTE)&lQuery,
504cdf0e10cSrcweir 					0,
505cdf0e10cSrcweir 					(PBYTE)NULL );
506cdf0e10cSrcweir 	if ( DEV_OK != rc )
507cdf0e10cSrcweir 		return FALSE;
508cdf0e10cSrcweir 
509cdf0e10cSrcweir 	return TRUE;
510cdf0e10cSrcweir #endif
511cdf0e10cSrcweir }
512cdf0e10cSrcweir 
513cdf0e10cSrcweir // -----------------------------------------------------------------------
514cdf0e10cSrcweir 
515cdf0e10cSrcweir static void ImplFormatInputList( PDJP_ITEM pDJP, PQUERYTUPLE pTuple )
516cdf0e10cSrcweir {
517cdf0e10cSrcweir    // Loop through the query elements
518fc9fd3f1SPedro Giffuni    sal_Bool fContinue = TRUE;
519cdf0e10cSrcweir    do
520cdf0e10cSrcweir    {
521cdf0e10cSrcweir 	  pDJP->cb			  = sizeof (DJP_ITEM);
522cdf0e10cSrcweir 	  pDJP->ulProperty	  = pTuple->ulProperty;
523cdf0e10cSrcweir 	  pDJP->lType		  = pTuple->lType;
524cdf0e10cSrcweir 	  pDJP->ulNumReturned = 0;
525cdf0e10cSrcweir 	  pDJP->ulValue 	  = DJP_NONE;
526cdf0e10cSrcweir 
527cdf0e10cSrcweir 	  // at EOL?
528cdf0e10cSrcweir 	  fContinue = DJP_NONE != pTuple->ulProperty;
529cdf0e10cSrcweir 
530cdf0e10cSrcweir 	  // Move to next item structure and tuplet
531cdf0e10cSrcweir 	  pDJP++;
532cdf0e10cSrcweir 	  pTuple++;
533cdf0e10cSrcweir    }
534cdf0e10cSrcweir    while ( fContinue );
535cdf0e10cSrcweir }
536cdf0e10cSrcweir 
537cdf0e10cSrcweir // -----------------------------------------------------------------------
538cdf0e10cSrcweir 
539cdf0e10cSrcweir static void ImplFreeFormAndTrayList( Os2SalInfoPrinter* pOs2SalInfoPrinter )
540cdf0e10cSrcweir {
541cdf0e10cSrcweir 	if ( pOs2SalInfoPrinter->mnFormCount )
542cdf0e10cSrcweir 	{
543cdf0e10cSrcweir 		for ( USHORT i = 0; i < pOs2SalInfoPrinter->mnFormCount; i++ )
544cdf0e10cSrcweir 			delete pOs2SalInfoPrinter->mpFormArray[i];
545cdf0e10cSrcweir 		delete [] pOs2SalInfoPrinter->mpFormArray;
546cdf0e10cSrcweir 		pOs2SalInfoPrinter->mnFormCount = 0;
547cdf0e10cSrcweir 	}
548cdf0e10cSrcweir 
549cdf0e10cSrcweir 	if ( pOs2SalInfoPrinter->mnTrayCount )
550cdf0e10cSrcweir 	{
551cdf0e10cSrcweir 		for ( USHORT i = 0; i < pOs2SalInfoPrinter->mnTrayCount; i++ )
552cdf0e10cSrcweir 			delete pOs2SalInfoPrinter->mpTrayArray[i];
553cdf0e10cSrcweir 		delete [] pOs2SalInfoPrinter->mpTrayArray;
554cdf0e10cSrcweir 		pOs2SalInfoPrinter->mnTrayCount = 0;
555cdf0e10cSrcweir 	}
556cdf0e10cSrcweir }
557cdf0e10cSrcweir 
558cdf0e10cSrcweir // -----------------------------------------------------------------------
559cdf0e10cSrcweir 
560cdf0e10cSrcweir static void ImplGetFormAndTrayList( Os2SalInfoPrinter* pOs2SalInfoPrinter, const ImplJobSetup* pSetupData )
561cdf0e10cSrcweir {
562*651793b0SYuri Dario 	// if not defined, suppose default orientation is portrait
563*651793b0SYuri Dario 	Orientation orientation = ORIENTATION_PORTRAIT;
564*651793b0SYuri Dario 
565cdf0e10cSrcweir 	ImplFreeFormAndTrayList( pOs2SalInfoPrinter );
566cdf0e10cSrcweir 
567cdf0e10cSrcweir 	LONG alQuery[] =
568cdf0e10cSrcweir 	{
569cdf0e10cSrcweir 		0,					0,				// First two members of QUERYSIZE
570*651793b0SYuri Dario 		DJP_SJ_ORIENTATION, 	DJP_CURRENT,
571cdf0e10cSrcweir 		DJP_CJ_FORM,		DJP_ALL,
572cdf0e10cSrcweir 		DJP_CJ_TRAYNAME,	DJP_ALL,
573cdf0e10cSrcweir 		DJP_NONE,			DJP_NONE		// EOL marker
574cdf0e10cSrcweir 	};
575cdf0e10cSrcweir 
576cdf0e10cSrcweir 	APIRET		rc;
577cdf0e10cSrcweir 	PQUERYSIZE	pQuerySize			= (PQUERYSIZE)alQuery;
578cdf0e10cSrcweir 	PBYTE		pBuffer 			= NULL;
579cdf0e10cSrcweir 	LONG		nAlloc				= 0;
580cdf0e10cSrcweir 	PDRIVDATA	pCopyDrivData		= ImplPrnDrivData( pSetupData );
581cdf0e10cSrcweir 	LONG		nDrivDataSize		= pCopyDrivData->cb;
582cdf0e10cSrcweir 	PBYTE		pDrivData			= (PBYTE)pCopyDrivData;
583cdf0e10cSrcweir 
584cdf0e10cSrcweir 	// find out how many bytes to allocate
585cdf0e10cSrcweir 	pQuerySize->cb = sizeof( alQuery );
586cdf0e10cSrcweir 	rc = DevEscape( pOs2SalInfoPrinter->mhDC,
587cdf0e10cSrcweir 					DEVESC_QUERYSIZE,
588cdf0e10cSrcweir 					sizeof( alQuery ),
589cdf0e10cSrcweir 					(PBYTE)pQuerySize,
590cdf0e10cSrcweir 					&nDrivDataSize,
591cdf0e10cSrcweir 					pDrivData );
592cdf0e10cSrcweir 	if ( DEV_OK != rc )
593cdf0e10cSrcweir 	{
594cdf0e10cSrcweir 		ImplFreePrnMemory( pCopyDrivData );
595cdf0e10cSrcweir 		return;
596cdf0e10cSrcweir 	}
597cdf0e10cSrcweir 
598cdf0e10cSrcweir 	// allocate the memory
599cdf0e10cSrcweir 	nAlloc = pQuerySize->ulSizeNeeded;
600fc9fd3f1SPedro Giffuni 	pBuffer = (PBYTE)new PM_BYTE[nAlloc];
601cdf0e10cSrcweir 
602cdf0e10cSrcweir 	// set up the input
603cdf0e10cSrcweir 	PDJP_ITEM pDJP = (PDJP_ITEM)pBuffer;
604cdf0e10cSrcweir 	ImplFormatInputList( pDJP, pQuerySize->aTuples );
605cdf0e10cSrcweir 
606cdf0e10cSrcweir 	// do it!
607cdf0e10cSrcweir 	rc = DevEscape( pOs2SalInfoPrinter->mhDC,
608cdf0e10cSrcweir 					DEVESC_QUERYJOBPROPERTIES,
609cdf0e10cSrcweir 					nAlloc,
610cdf0e10cSrcweir 					pBuffer,
611cdf0e10cSrcweir 					&nDrivDataSize,
612cdf0e10cSrcweir 					pDrivData );
613cdf0e10cSrcweir 	ImplFreePrnMemory( pCopyDrivData );
614cdf0e10cSrcweir 
615cdf0e10cSrcweir 	if ( (DEV_OK == rc) || (DEV_WARNING == rc) )
616cdf0e10cSrcweir 	{
617cdf0e10cSrcweir 		// Loop through the query elements
618cdf0e10cSrcweir 		PQUERYTUPLE pTuple = pQuerySize->aTuples;
619cdf0e10cSrcweir 		while ( DJP_NONE != pTuple->ulProperty )
620cdf0e10cSrcweir 		{
621*651793b0SYuri Dario 			if ( pDJP->ulProperty == DJP_SJ_ORIENTATION )
622*651793b0SYuri Dario 			{
623*651793b0SYuri Dario 				if ( pDJP->ulNumReturned )
624*651793b0SYuri Dario 				{
625*651793b0SYuri Dario 					PDJPT_ORIENTATION pElm = DJP_ELEMENTP( *pDJP, DJPT_ORIENTATION );
626*651793b0SYuri Dario 					if ( (DJP_ORI_PORTRAIT == *pElm) || (DJP_ORI_REV_PORTRAIT == *pElm) )
627*651793b0SYuri Dario 						orientation = ORIENTATION_PORTRAIT;
628*651793b0SYuri Dario 					else
629*651793b0SYuri Dario 						orientation = ORIENTATION_LANDSCAPE;
630*651793b0SYuri Dario 				}
631*651793b0SYuri Dario 			}
632*651793b0SYuri Dario 			else if ( pDJP->ulProperty == DJP_CJ_FORM )
633cdf0e10cSrcweir 			{
634cdf0e10cSrcweir 				if ( pDJP->ulNumReturned )
635cdf0e10cSrcweir 				{
636cdf0e10cSrcweir 					PDJPT_FORM pElm = DJP_ELEMENTP( *pDJP, DJPT_FORM );
637cdf0e10cSrcweir 
638cdf0e10cSrcweir 					pOs2SalInfoPrinter->mnFormCount = pDJP->ulNumReturned;
639cdf0e10cSrcweir 					pOs2SalInfoPrinter->mpFormArray = new PIMPLFORMINFO[pOs2SalInfoPrinter->mnFormCount];
640cdf0e10cSrcweir 					for( int i = 0; i < pDJP->ulNumReturned; i++, pElm++ )
641cdf0e10cSrcweir 					{
642cdf0e10cSrcweir 						ImplFormInfo* pInfo 	= new ImplFormInfo;
643*651793b0SYuri Dario 						// AOO expects form size always in portrait mode
644*651793b0SYuri Dario 						if (orientation == ORIENTATION_PORTRAIT)
645*651793b0SYuri Dario 						{
646*651793b0SYuri Dario 							pInfo->mnPaperWidth 	= pElm->hcInfo.cx;
647*651793b0SYuri Dario 							pInfo->mnPaperHeight	= pElm->hcInfo.cy;
648*651793b0SYuri Dario 						}
649*651793b0SYuri Dario 						else
650*651793b0SYuri Dario 						{
651*651793b0SYuri Dario 							pInfo->mnPaperWidth 	= pElm->hcInfo.cy;
652*651793b0SYuri Dario 							pInfo->mnPaperHeight	= pElm->hcInfo.cx;
653*651793b0SYuri Dario 						}
654f98951f3SYuri Dario #if OSL_DEBUG_LEVEL>0
655*651793b0SYuri Dario 						debug_printf("ImplGetFormAndTrayList #%d: %d x %d",
656*651793b0SYuri Dario 									 i, pInfo->mnPaperWidth, pInfo->mnPaperHeight);
657f98951f3SYuri Dario #endif
658cdf0e10cSrcweir 						pInfo->mnId 			= pElm->djppsFormID;
659cdf0e10cSrcweir 						pOs2SalInfoPrinter->mpFormArray[i] = pInfo;
660cdf0e10cSrcweir 					}
661cdf0e10cSrcweir 				}
662cdf0e10cSrcweir 			}
663cdf0e10cSrcweir 			else if ( pDJP->ulProperty == DJP_CJ_TRAYNAME )
664cdf0e10cSrcweir 			{
665cdf0e10cSrcweir 				if ( pDJP->ulNumReturned )
666cdf0e10cSrcweir 				{
667cdf0e10cSrcweir 					PDJPT_TRAYNAME pElm = DJP_ELEMENTP( *pDJP, DJPT_TRAYNAME );
668cdf0e10cSrcweir 
669cdf0e10cSrcweir 					pOs2SalInfoPrinter->mnTrayCount = pDJP->ulNumReturned;
670cdf0e10cSrcweir 					pOs2SalInfoPrinter->mpTrayArray = new PIMPLTRAYINFO[pOs2SalInfoPrinter->mnTrayCount];
671cdf0e10cSrcweir 					for( int i = 0; i < pDJP->ulNumReturned; i++, pElm++ )
672cdf0e10cSrcweir 					{
673cdf0e10cSrcweir 						ImplTrayInfo* pInfo 	= new ImplTrayInfo( pElm->szTrayname, pElm->szDisplayTrayname );
674cdf0e10cSrcweir 						pInfo->mnId 			= pElm->djpttTrayID;
675cdf0e10cSrcweir 						pOs2SalInfoPrinter->mpTrayArray[i] = pInfo;
676cdf0e10cSrcweir 					}
677cdf0e10cSrcweir 				}
678cdf0e10cSrcweir 			}
679cdf0e10cSrcweir 
680cdf0e10cSrcweir 			pDJP = DJP_NEXT_STRUCTP( pDJP );
681cdf0e10cSrcweir 			pTuple++;
682cdf0e10cSrcweir 		}
683cdf0e10cSrcweir 	}
684cdf0e10cSrcweir 
685cdf0e10cSrcweir 	delete [] pBuffer;
686cdf0e10cSrcweir }
687cdf0e10cSrcweir 
688cdf0e10cSrcweir // -----------------------------------------------------------------------
689cdf0e10cSrcweir 
690fc9fd3f1SPedro Giffuni static sal_Bool ImplGetCurrentSettings( Os2SalInfoPrinter* pOs2SalInfoPrinter, ImplJobSetup* pSetupData )
691cdf0e10cSrcweir {
692cdf0e10cSrcweir 	// Um den aktuellen Tray zu ermitteln, brauchen wir auch die Listen dazu
693cdf0e10cSrcweir 	if ( !pOs2SalInfoPrinter->mnFormCount )
694cdf0e10cSrcweir 		ImplGetFormAndTrayList( pOs2SalInfoPrinter, pSetupData );
695cdf0e10cSrcweir 
696cdf0e10cSrcweir 	LONG alQuery[] =
697cdf0e10cSrcweir 	{
698cdf0e10cSrcweir 		0,						0,				// First two members of QUERYSIZE
699cdf0e10cSrcweir 		DJP_SJ_ORIENTATION, 	DJP_CURRENT,
700cdf0e10cSrcweir 		DJP_CJ_FORM,			DJP_CURRENT,
701cdf0e10cSrcweir 		DJP_NONE,				DJP_NONE		// EOL marker
702cdf0e10cSrcweir 	};
703cdf0e10cSrcweir 
704cdf0e10cSrcweir 	APIRET		rc;
705cdf0e10cSrcweir 	PQUERYSIZE	pQuerySize			= (PQUERYSIZE)alQuery;
706cdf0e10cSrcweir 	PBYTE		pBuffer 			= NULL;
707cdf0e10cSrcweir 	LONG		nAlloc				= 0;
708cdf0e10cSrcweir 	PDRIVDATA	pCopyDrivData		= ImplPrnDrivData( pSetupData );
709cdf0e10cSrcweir 	LONG		nDrivDataSize		= pCopyDrivData->cb;
710cdf0e10cSrcweir 	PBYTE		pDrivData			= (PBYTE)pCopyDrivData;
711fc9fd3f1SPedro Giffuni 	sal_Bool		bResult;
712cdf0e10cSrcweir 
713cdf0e10cSrcweir 	// find out how many bytes to allocate
714cdf0e10cSrcweir 	pQuerySize->cb = sizeof( alQuery );
715cdf0e10cSrcweir 	rc = DevEscape( pOs2SalInfoPrinter->mhDC,
716cdf0e10cSrcweir 					DEVESC_QUERYSIZE,
717cdf0e10cSrcweir 					sizeof( alQuery ),
718cdf0e10cSrcweir 					(PBYTE)pQuerySize,
719cdf0e10cSrcweir 					&nDrivDataSize,
720cdf0e10cSrcweir 					pDrivData );
721cdf0e10cSrcweir 	if ( DEV_OK != rc )
722cdf0e10cSrcweir 	{
723cdf0e10cSrcweir 		ImplFreePrnMemory( pCopyDrivData );
724cdf0e10cSrcweir 		return FALSE;
725cdf0e10cSrcweir 	}
726cdf0e10cSrcweir 
727cdf0e10cSrcweir 	// allocate the memory
728cdf0e10cSrcweir 	nAlloc = pQuerySize->ulSizeNeeded;
729fc9fd3f1SPedro Giffuni 	pBuffer = (PBYTE)new PM_BYTE[nAlloc];
730cdf0e10cSrcweir 
731cdf0e10cSrcweir 	// set up the input
732cdf0e10cSrcweir 	PDJP_ITEM pDJP = (PDJP_ITEM)pBuffer;
733cdf0e10cSrcweir 	ImplFormatInputList( pDJP, pQuerySize->aTuples );
734cdf0e10cSrcweir 
735cdf0e10cSrcweir 	rc = DevEscape( pOs2SalInfoPrinter->mhDC,
736cdf0e10cSrcweir 					DEVESC_QUERYJOBPROPERTIES,
737cdf0e10cSrcweir 					nAlloc,
738cdf0e10cSrcweir 					pBuffer,
739cdf0e10cSrcweir 					&nDrivDataSize,
740cdf0e10cSrcweir 					pDrivData );
741cdf0e10cSrcweir 	if ( (DEV_OK == rc) || (DEV_WARNING == rc) )
742cdf0e10cSrcweir 	{
743cdf0e10cSrcweir 		// aktuelle Setup-Daten uebernehmen
744cdf0e10cSrcweir 		ImplUpdateSetupData( pCopyDrivData, pSetupData );
745cdf0e10cSrcweir 
746cdf0e10cSrcweir 		// Loop through the query elements
747cdf0e10cSrcweir 		PQUERYTUPLE pTuple = pQuerySize->aTuples;
748cdf0e10cSrcweir 		while ( DJP_NONE != pTuple->ulProperty )
749cdf0e10cSrcweir 		{
750cdf0e10cSrcweir 			if ( pDJP->ulProperty == DJP_SJ_ORIENTATION )
751cdf0e10cSrcweir 			{
752cdf0e10cSrcweir 				if ( pDJP->ulNumReturned )
753cdf0e10cSrcweir 				{
754cdf0e10cSrcweir 					PDJPT_ORIENTATION pElm = DJP_ELEMENTP( *pDJP, DJPT_ORIENTATION );
755cdf0e10cSrcweir 					if ( (DJP_ORI_PORTRAIT == *pElm) || (DJP_ORI_REV_PORTRAIT == *pElm) )
756cdf0e10cSrcweir 						pSetupData->meOrientation = ORIENTATION_PORTRAIT;
757cdf0e10cSrcweir 					else
758cdf0e10cSrcweir 						pSetupData->meOrientation = ORIENTATION_LANDSCAPE;
759cdf0e10cSrcweir 				}
760cdf0e10cSrcweir 			}
761cdf0e10cSrcweir 			else if ( pDJP->ulProperty == DJP_CJ_FORM )
762cdf0e10cSrcweir 			{
763cdf0e10cSrcweir 				if ( pDJP->ulNumReturned )
764cdf0e10cSrcweir 				{
765cdf0e10cSrcweir 					PDJPT_FORM pElm = DJP_ELEMENTP( *pDJP, DJPT_FORM );
766cdf0e10cSrcweir 
767cdf0e10cSrcweir 					pSetupData->mnPaperWidth  = pElm->hcInfo.cx*100;
768cdf0e10cSrcweir 					pSetupData->mnPaperHeight = pElm->hcInfo.cy*100;
769cdf0e10cSrcweir 					switch( pElm->djppsFormID )
770cdf0e10cSrcweir 					{
771cdf0e10cSrcweir 						case DJP_PSI_A3:
772cdf0e10cSrcweir 							pSetupData->mePaperFormat = PAPER_A3;
773cdf0e10cSrcweir 							break;
774cdf0e10cSrcweir 
775cdf0e10cSrcweir 						case DJP_PSI_A4:
776cdf0e10cSrcweir 							pSetupData->mePaperFormat = PAPER_A4;
777cdf0e10cSrcweir 							break;
778cdf0e10cSrcweir 
779cdf0e10cSrcweir 						case DJP_PSI_A5:
780cdf0e10cSrcweir 							pSetupData->mePaperFormat = PAPER_A5;
781cdf0e10cSrcweir 							break;
782cdf0e10cSrcweir 
783cdf0e10cSrcweir 						case DJP_PSI_B4:
784fc9fd3f1SPedro Giffuni 							pSetupData->mePaperFormat = PAPER_B4_JIS;
785cdf0e10cSrcweir 							break;
786cdf0e10cSrcweir 
787cdf0e10cSrcweir 						case DJP_PSI_B5:
788fc9fd3f1SPedro Giffuni 							pSetupData->mePaperFormat = PAPER_B5_JIS;
789cdf0e10cSrcweir 							break;
790cdf0e10cSrcweir 
791cdf0e10cSrcweir 						case DJP_PSI_LETTER:
792cdf0e10cSrcweir 							pSetupData->mePaperFormat = PAPER_LETTER;
793cdf0e10cSrcweir 							break;
794cdf0e10cSrcweir 
795cdf0e10cSrcweir 						case DJP_PSI_LEGAL:
796cdf0e10cSrcweir 							pSetupData->mePaperFormat = PAPER_LEGAL;
797cdf0e10cSrcweir 							break;
798cdf0e10cSrcweir 
799cdf0e10cSrcweir 						case DJP_PSI_TABLOID:
800cdf0e10cSrcweir 							pSetupData->mePaperFormat = PAPER_TABLOID;
801cdf0e10cSrcweir 							break;
802cdf0e10cSrcweir 
803cdf0e10cSrcweir 						default:
804cdf0e10cSrcweir 							pSetupData->mePaperFormat = PAPER_USER;
805cdf0e10cSrcweir 							break;
806cdf0e10cSrcweir 					}
807cdf0e10cSrcweir 
808cdf0e10cSrcweir 					// Wir suchen zuerst ueber den Namen/Id und dann ueber die Id
809fc9fd3f1SPedro Giffuni 					sal_Bool	bTrayFound = FALSE;
810cdf0e10cSrcweir 					USHORT	j;
811cdf0e10cSrcweir 					for ( j = 0; j < pOs2SalInfoPrinter->mnTrayCount; j++ )
812cdf0e10cSrcweir 					{
813cdf0e10cSrcweir 						if ( (pOs2SalInfoPrinter->mpTrayArray[j]->mnId == pElm->djpttTrayID) &&
814cdf0e10cSrcweir 							 (pOs2SalInfoPrinter->mpTrayArray[j]->maName == pElm->szTrayname) )
815cdf0e10cSrcweir 						{
816cdf0e10cSrcweir 							pSetupData->mnPaperBin = j;
817cdf0e10cSrcweir 							bTrayFound = TRUE;
818cdf0e10cSrcweir 							break;
819cdf0e10cSrcweir 						}
820cdf0e10cSrcweir 					}
821cdf0e10cSrcweir 					if ( !bTrayFound )
822cdf0e10cSrcweir 					{
823cdf0e10cSrcweir 						for ( j = 0; j < pOs2SalInfoPrinter->mnTrayCount; j++ )
824cdf0e10cSrcweir 						{
825cdf0e10cSrcweir 							if ( pOs2SalInfoPrinter->mpTrayArray[j]->mnId == pElm->djpttTrayID )
826cdf0e10cSrcweir 							{
827cdf0e10cSrcweir 								pSetupData->mnPaperBin = j;
828cdf0e10cSrcweir 								bTrayFound = TRUE;
829cdf0e10cSrcweir 								break;
830cdf0e10cSrcweir 							}
831cdf0e10cSrcweir 						}
832cdf0e10cSrcweir 					}
833cdf0e10cSrcweir 					// Wenn wir Ihn immer noch nicht gefunden haben, setzen
834cdf0e10cSrcweir 					// wir ihn auf DontKnow
835cdf0e10cSrcweir 					if ( !bTrayFound )
836cdf0e10cSrcweir 						pSetupData->mnPaperBin = 0xFFFF;
837cdf0e10cSrcweir 				}
838cdf0e10cSrcweir 			}
839cdf0e10cSrcweir 
840cdf0e10cSrcweir 			pDJP = DJP_NEXT_STRUCTP( pDJP );
841cdf0e10cSrcweir 			pTuple++;
842cdf0e10cSrcweir 		}
843cdf0e10cSrcweir 
844cdf0e10cSrcweir 		bResult = TRUE;
845cdf0e10cSrcweir 	}
846cdf0e10cSrcweir 	else
847cdf0e10cSrcweir 	{
848cdf0e10cSrcweir 		ImplFreePrnMemory( pCopyDrivData );
849cdf0e10cSrcweir 		bResult = FALSE;
850cdf0e10cSrcweir 	}
851cdf0e10cSrcweir 
852cdf0e10cSrcweir 	delete [] pBuffer;
853cdf0e10cSrcweir 
854cdf0e10cSrcweir 	return bResult;
855cdf0e10cSrcweir }
856cdf0e10cSrcweir 
857cdf0e10cSrcweir // -----------------------------------------------------------------------
858cdf0e10cSrcweir 
859fc9fd3f1SPedro Giffuni static sal_Bool ImplSetOrientation( HDC hPrinterDC, PDRIVDATA pDriverData,
860cdf0e10cSrcweir 								Orientation eOrientation )
861cdf0e10cSrcweir {
862cdf0e10cSrcweir 	LONG alQuery[] =
863cdf0e10cSrcweir 	{
864cdf0e10cSrcweir 		0,						0,				// First two members of QUERYSIZE
865cdf0e10cSrcweir 		DJP_SJ_ORIENTATION, 	DJP_CURRENT,
866cdf0e10cSrcweir 		DJP_NONE,				DJP_NONE		// EOL marker
867cdf0e10cSrcweir 	};
868*651793b0SYuri Dario #if OSL_DEBUG_LEVEL>0
869*651793b0SYuri Dario 	debug_printf( "ImplSetOrientation mhDC %x, %d", hPrinterDC, eOrientation);
870*651793b0SYuri Dario #endif
871cdf0e10cSrcweir 
872cdf0e10cSrcweir 	APIRET		rc;
873cdf0e10cSrcweir 	PQUERYSIZE	pQuerySize		= (PQUERYSIZE)alQuery;
874cdf0e10cSrcweir 	PBYTE		pBuffer 		= NULL;
875cdf0e10cSrcweir 	LONG		nAlloc			= 0;
876cdf0e10cSrcweir 	LONG		nDrivDataSize	= pDriverData->cb;
877cdf0e10cSrcweir 
878cdf0e10cSrcweir 	// find out how many bytes to allocate
879cdf0e10cSrcweir 	pQuerySize->cb = sizeof( alQuery );
880cdf0e10cSrcweir 	rc = DevEscape( hPrinterDC,
881cdf0e10cSrcweir 					DEVESC_QUERYSIZE,
882cdf0e10cSrcweir 					sizeof( alQuery ),
883cdf0e10cSrcweir 					(PBYTE)pQuerySize,
884cdf0e10cSrcweir 					&nDrivDataSize,
885cdf0e10cSrcweir 					(PBYTE)pDriverData );
886cdf0e10cSrcweir 	if ( DEV_OK != rc )
887cdf0e10cSrcweir 		return FALSE;
888cdf0e10cSrcweir 
889cdf0e10cSrcweir 	// allocate the memory
890cdf0e10cSrcweir 	nAlloc = pQuerySize->ulSizeNeeded;
891fc9fd3f1SPedro Giffuni 	pBuffer = (PBYTE)new PM_BYTE[nAlloc];
892cdf0e10cSrcweir 
893cdf0e10cSrcweir 	// set up the input
894cdf0e10cSrcweir 	PDJP_ITEM pDJP = (PDJP_ITEM)pBuffer;
895cdf0e10cSrcweir 	ImplFormatInputList( pDJP, pQuerySize->aTuples );
896cdf0e10cSrcweir 
897cdf0e10cSrcweir 	pDJP->cb		 = sizeof( DJP_ITEM );
898cdf0e10cSrcweir 	pDJP->ulProperty = DJP_SJ_ORIENTATION;
899cdf0e10cSrcweir 	pDJP->lType 	 = DJP_CURRENT;
900cdf0e10cSrcweir 	pDJP->ulValue	 = (eOrientation == ORIENTATION_PORTRAIT)
901cdf0e10cSrcweir 						   ? DJP_ORI_PORTRAIT
902cdf0e10cSrcweir 						   : DJP_ORI_LANDSCAPE;
903cdf0e10cSrcweir 
904cdf0e10cSrcweir 	// do it!
905cdf0e10cSrcweir 	rc = DevEscape( hPrinterDC,
906cdf0e10cSrcweir 					DEVESC_SETJOBPROPERTIES,
907cdf0e10cSrcweir 					nAlloc,
908cdf0e10cSrcweir 					pBuffer,
909cdf0e10cSrcweir 					&nDrivDataSize,
910cdf0e10cSrcweir 					(PBYTE)pDriverData );
911cdf0e10cSrcweir 
912cdf0e10cSrcweir 	delete [] pBuffer;
913cdf0e10cSrcweir 
914cdf0e10cSrcweir 	return ((DEV_OK == rc) || (DEV_WARNING == rc));
915cdf0e10cSrcweir }
916cdf0e10cSrcweir 
917cdf0e10cSrcweir // -----------------------------------------------------------------------
918cdf0e10cSrcweir 
919fc9fd3f1SPedro Giffuni static sal_Bool ImplSetPaperSize( HDC hPrinterDC, PDRIVDATA pDriverData,
920cdf0e10cSrcweir 							  DJPT_PAPERSIZE nOS2PaperFormat )
921cdf0e10cSrcweir {
922cdf0e10cSrcweir 	LONG alQuery[] =
923cdf0e10cSrcweir 	{
924cdf0e10cSrcweir 		0,						0,				// First two members of QUERYSIZE
925cdf0e10cSrcweir 		DJP_SJ_PAPERSIZE,		DJP_CURRENT,
926cdf0e10cSrcweir 		DJP_NONE,				DJP_NONE		// EOL marker
927cdf0e10cSrcweir 	};
928cdf0e10cSrcweir 
929cdf0e10cSrcweir 	APIRET		rc;
930cdf0e10cSrcweir 	PQUERYSIZE	pQuerySize		= (PQUERYSIZE)alQuery;
931cdf0e10cSrcweir 	PBYTE		pBuffer 		= NULL;
932cdf0e10cSrcweir 	LONG		nAlloc			= 0;
933cdf0e10cSrcweir 	LONG		nDrivDataSize	= pDriverData->cb;
934cdf0e10cSrcweir 
935cdf0e10cSrcweir 	// find out how many bytes to allocate
936cdf0e10cSrcweir 	pQuerySize->cb = sizeof( alQuery );
937cdf0e10cSrcweir 	rc = DevEscape( hPrinterDC,
938cdf0e10cSrcweir 					DEVESC_QUERYSIZE,
939cdf0e10cSrcweir 					sizeof( alQuery ),
940cdf0e10cSrcweir 					(PBYTE)pQuerySize,
941cdf0e10cSrcweir 					&nDrivDataSize,
942cdf0e10cSrcweir 					(PBYTE)pDriverData );
943cdf0e10cSrcweir 	if ( DEV_OK != rc )
944cdf0e10cSrcweir 		return FALSE;
945cdf0e10cSrcweir 
946cdf0e10cSrcweir 	// allocate the memory
947cdf0e10cSrcweir 	nAlloc = pQuerySize->ulSizeNeeded;
948fc9fd3f1SPedro Giffuni 	pBuffer = (PBYTE)new PM_BYTE[nAlloc];
949cdf0e10cSrcweir 
950cdf0e10cSrcweir 	// set up the input
951cdf0e10cSrcweir 	PDJP_ITEM pDJP = (PDJP_ITEM)pBuffer;
952cdf0e10cSrcweir 	PDJP_ITEM pStartDJP = pDJP;
953cdf0e10cSrcweir 	ImplFormatInputList( pDJP, pQuerySize->aTuples );
954cdf0e10cSrcweir 
955cdf0e10cSrcweir 	// Neue Daten zuweisen
956cdf0e10cSrcweir 	pDJP->cb		 = sizeof( DJP_ITEM );
957cdf0e10cSrcweir 	pDJP->ulProperty = DJP_SJ_PAPERSIZE;
958cdf0e10cSrcweir 	pDJP->lType 	 = DJP_CURRENT;
959cdf0e10cSrcweir 	pDJP->ulValue	 = nOS2PaperFormat;
960cdf0e10cSrcweir 
961cdf0e10cSrcweir 	// und setzen
962cdf0e10cSrcweir 	rc = DevEscape( hPrinterDC,
963cdf0e10cSrcweir 					DEVESC_SETJOBPROPERTIES,
964cdf0e10cSrcweir 					nAlloc,
965cdf0e10cSrcweir 					pBuffer,
966cdf0e10cSrcweir 					&nDrivDataSize,
967cdf0e10cSrcweir 					(PBYTE)pDriverData );
968cdf0e10cSrcweir 
969cdf0e10cSrcweir 	delete [] pBuffer;
970cdf0e10cSrcweir 
971cdf0e10cSrcweir 	return ((DEV_OK == rc) || (DEV_WARNING == rc));
972cdf0e10cSrcweir }
973cdf0e10cSrcweir 
974cdf0e10cSrcweir // -----------------------------------------------------------------------
975cdf0e10cSrcweir 
976fc9fd3f1SPedro Giffuni static sal_Bool ImplSetPaperBin( HDC hPrinterDC, PDRIVDATA pDriverData,
977cdf0e10cSrcweir 							 ImplTrayInfo* pTrayInfo )
978cdf0e10cSrcweir {
979cdf0e10cSrcweir 	LONG alQuery[] =
980cdf0e10cSrcweir 	{
981cdf0e10cSrcweir 		0,						0,				// First two members of QUERYSIZE
982cdf0e10cSrcweir 		DJP_SJ_TRAYTYPE,		DJP_CURRENT,
983cdf0e10cSrcweir 		DJP_NONE,				DJP_NONE		// EOL marker
984cdf0e10cSrcweir 	};
985cdf0e10cSrcweir 
986cdf0e10cSrcweir 	APIRET		rc;
987cdf0e10cSrcweir 	PQUERYSIZE	pQuerySize		= (PQUERYSIZE)alQuery;
988cdf0e10cSrcweir 	PBYTE		pBuffer 		= NULL;
989cdf0e10cSrcweir 	LONG		nAlloc			= 0;
990cdf0e10cSrcweir 	LONG		nDrivDataSize	= pDriverData->cb;
991cdf0e10cSrcweir 
992cdf0e10cSrcweir 	// find out how many bytes to allocate
993cdf0e10cSrcweir 	pQuerySize->cb = sizeof( alQuery );
994cdf0e10cSrcweir 	rc = DevEscape( hPrinterDC,
995cdf0e10cSrcweir 					DEVESC_QUERYSIZE,
996cdf0e10cSrcweir 					sizeof( alQuery ),
997cdf0e10cSrcweir 					(PBYTE)pQuerySize,
998cdf0e10cSrcweir 					&nDrivDataSize,
999cdf0e10cSrcweir 					(PBYTE)pDriverData );
1000cdf0e10cSrcweir 	if ( DEV_OK != rc )
1001cdf0e10cSrcweir 		return FALSE;
1002cdf0e10cSrcweir 
1003cdf0e10cSrcweir 	// allocate the memory
1004cdf0e10cSrcweir 	nAlloc = pQuerySize->ulSizeNeeded;
1005fc9fd3f1SPedro Giffuni 	pBuffer = (PBYTE)new PM_BYTE[nAlloc];
1006cdf0e10cSrcweir 
1007cdf0e10cSrcweir 	// set up the input
1008cdf0e10cSrcweir 	PDJP_ITEM pDJP = (PDJP_ITEM)pBuffer;
1009cdf0e10cSrcweir 	ImplFormatInputList( pDJP, pQuerySize->aTuples );
1010cdf0e10cSrcweir 
1011cdf0e10cSrcweir 	// Neue Daten zuweisen
1012cdf0e10cSrcweir 	pDJP->cb		 = sizeof( DJP_ITEM );
1013cdf0e10cSrcweir 	pDJP->ulProperty = DJP_SJ_TRAYTYPE;
1014cdf0e10cSrcweir 	pDJP->lType 	 = DJP_CURRENT;
1015cdf0e10cSrcweir 	pDJP->ulValue	 = pTrayInfo->mnId;
1016cdf0e10cSrcweir 
1017cdf0e10cSrcweir 	// und setzen
1018cdf0e10cSrcweir 	rc = DevEscape( hPrinterDC,
1019cdf0e10cSrcweir 					DEVESC_SETJOBPROPERTIES,
1020cdf0e10cSrcweir 					nAlloc,
1021cdf0e10cSrcweir 					pBuffer,
1022cdf0e10cSrcweir 					&nDrivDataSize,
1023cdf0e10cSrcweir 					(PBYTE)pDriverData );
1024cdf0e10cSrcweir 
1025cdf0e10cSrcweir 	delete [] pBuffer;
1026cdf0e10cSrcweir 
1027cdf0e10cSrcweir 	return ((DEV_OK == rc) || (DEV_WARNING == rc));
1028cdf0e10cSrcweir }
1029cdf0e10cSrcweir 
1030cdf0e10cSrcweir // =======================================================================
1031cdf0e10cSrcweir 
1032fc9fd3f1SPedro Giffuni static sal_Bool ImplSalCreateInfoPrn( Os2SalInfoPrinter* pPrinter, PDRIVDATA pDriverData,
1033cdf0e10cSrcweir 								  HDC& rDC, HPS& rPS )
1034cdf0e10cSrcweir {
1035cdf0e10cSrcweir 	SalData* pSalData = GetSalData();
1036cdf0e10cSrcweir 
1037cdf0e10cSrcweir 	// create info context
1038cdf0e10cSrcweir 	DEVOPENSTRUC  devOpenStruc;
1039cdf0e10cSrcweir 	memset( &devOpenStruc, 0, sizeof( devOpenStruc ) );
1040cdf0e10cSrcweir 	devOpenStruc.pszLogAddress		= (char*)pPrinter->maName.GetBuffer();
1041cdf0e10cSrcweir 	devOpenStruc.pszDriverName		= (char*)pPrinter->maDriverName.GetBuffer();
1042cdf0e10cSrcweir 	devOpenStruc.pdriv				= pDriverData;
1043cdf0e10cSrcweir 	devOpenStruc.pszDataType		= "PM_Q_STD";
1044cdf0e10cSrcweir 
1045cdf0e10cSrcweir 	HDC hDC = DevOpenDC( pSalData->mhAB, OD_INFO, "*",
1046cdf0e10cSrcweir 						 4, (PDEVOPENDATA)&devOpenStruc, (HDC)NULL);
1047cdf0e10cSrcweir 	if ( !hDC )
1048cdf0e10cSrcweir 		return FALSE;
1049cdf0e10cSrcweir 
1050cdf0e10cSrcweir 	// create presentation space
1051cdf0e10cSrcweir 	SIZEL sizel;
1052cdf0e10cSrcweir 	sizel.cx = 0;
1053cdf0e10cSrcweir 	sizel.cy = 0;
1054cdf0e10cSrcweir 	HPS hPS = Ft2CreatePS( pSalData->mhAB, hDC, &sizel, GPIA_ASSOC | GPIT_MICRO | PU_PELS );
1055cdf0e10cSrcweir 	if ( !hPS )
1056cdf0e10cSrcweir 	{
1057cdf0e10cSrcweir 		DevCloseDC( hDC );
1058cdf0e10cSrcweir 		return FALSE;
1059cdf0e10cSrcweir 	}
1060cdf0e10cSrcweir 
1061cdf0e10cSrcweir 	rDC = hDC;
1062cdf0e10cSrcweir 	rPS = hPS;
1063cdf0e10cSrcweir 	return TRUE;
1064cdf0e10cSrcweir }
1065cdf0e10cSrcweir 
1066cdf0e10cSrcweir // -----------------------------------------------------------------------
1067cdf0e10cSrcweir 
1068cdf0e10cSrcweir static void ImplSalDestroyInfoPrn( Os2SalInfoPrinter* pPrinter )
1069cdf0e10cSrcweir {
1070cdf0e10cSrcweir 	ImplSalDeInitGraphics( pPrinter->mpGraphics);
1071cdf0e10cSrcweir 	Ft2Associate( pPrinter->mhPS, 0 );
1072cdf0e10cSrcweir 	Ft2DestroyPS( pPrinter->mhPS );
1073cdf0e10cSrcweir 	DevCloseDC( pPrinter->mhDC );
1074cdf0e10cSrcweir }
1075cdf0e10cSrcweir 
1076cdf0e10cSrcweir // =======================================================================
1077cdf0e10cSrcweir 
1078cdf0e10cSrcweir SalInfoPrinter* Os2SalInstance::CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo,
1079cdf0e10cSrcweir 												ImplJobSetup* pSetupData )
1080cdf0e10cSrcweir {
1081cdf0e10cSrcweir 	ImplQueueSalSysData* pSysQueueData = (ImplQueueSalSysData*)(pQueueInfo->mpSysData);
1082cdf0e10cSrcweir 	Os2SalInfoPrinter* pPrinter = new Os2SalInfoPrinter;
1083cdf0e10cSrcweir 	pPrinter->maPrinterName	= pSysQueueData->maPrinterName;
1084cdf0e10cSrcweir 	pPrinter->maName			= pSysQueueData->maName;
1085cdf0e10cSrcweir 	pPrinter->maDriverName	= pSysQueueData->maDriverName;
1086cdf0e10cSrcweir 	pPrinter->maDeviceName	= pSysQueueData->maDeviceName;
1087cdf0e10cSrcweir 
1088cdf0e10cSrcweir 	// Nur Setup-Daten uebernehmen, wenn Treiber und Laenge der Treiberdaten
1089cdf0e10cSrcweir 	// uebereinstimmt
1090cdf0e10cSrcweir 	PDRIVDATA	pDriverData;
1091fc9fd3f1SPedro Giffuni 	sal_Bool		bUpdateDriverData;
1092cdf0e10cSrcweir 	if ( pSetupData->mpDriverData && pSysQueueData->mpDrivData &&
1093cdf0e10cSrcweir 		 (pSetupData->mnSystem == JOBSETUP_SYSTEM_OS2) &&
1094cdf0e10cSrcweir 		 (pSetupData->mnDriverDataLen == pSysQueueData->mpDrivData->cb) &&
1095cdf0e10cSrcweir 		 (strcmp( ((PDRIVDATA)pSetupData->mpDriverData)->szDeviceName,
1096cdf0e10cSrcweir 				  pSysQueueData->mpDrivData->szDeviceName ) == 0) )
1097cdf0e10cSrcweir 	{
1098cdf0e10cSrcweir 		pDriverData = PDRIVDATA( pSetupData->mpDriverData );
1099cdf0e10cSrcweir 		bUpdateDriverData = FALSE;
1100cdf0e10cSrcweir 	}
1101cdf0e10cSrcweir 	else
1102cdf0e10cSrcweir 	{
1103cdf0e10cSrcweir 		pDriverData = pSysQueueData->mpDrivData;
1104cdf0e10cSrcweir 		bUpdateDriverData = TRUE;
1105cdf0e10cSrcweir 	}
1106cdf0e10cSrcweir 	if ( pDriverData )
1107cdf0e10cSrcweir 		pPrinter->maJobSetupDeviceName = pDriverData->szDeviceName;
1108cdf0e10cSrcweir 
1109cdf0e10cSrcweir 	if ( !ImplSalCreateInfoPrn( pPrinter, pDriverData,
1110cdf0e10cSrcweir 								pPrinter->mhDC,
1111cdf0e10cSrcweir 								pPrinter->mhPS ) )
1112cdf0e10cSrcweir 	{
1113cdf0e10cSrcweir 		delete pPrinter;
1114cdf0e10cSrcweir 		return NULL;
1115cdf0e10cSrcweir 	}
1116cdf0e10cSrcweir 
1117cdf0e10cSrcweir 	// create graphics object for output
1118cdf0e10cSrcweir 	Os2SalGraphics* pGraphics = new Os2SalGraphics;
1119cdf0e10cSrcweir 	pGraphics->mhDC				= pPrinter->mhDC;
1120cdf0e10cSrcweir 	pGraphics->mhPS				= pPrinter->mhPS;
1121cdf0e10cSrcweir 	pGraphics->mhWnd 			= 0;
1122cdf0e10cSrcweir 	pGraphics->mbPrinter 		= TRUE;
1123cdf0e10cSrcweir 	pGraphics->mbVirDev			= FALSE;
1124cdf0e10cSrcweir 	pGraphics->mbWindow			= FALSE;
1125cdf0e10cSrcweir 	pGraphics->mbScreen			= FALSE;
1126cdf0e10cSrcweir 
1127cdf0e10cSrcweir 	ImplSalInitGraphics( pGraphics );
1128cdf0e10cSrcweir 	pPrinter->mpGraphics			= pGraphics;
1129cdf0e10cSrcweir 
1130cdf0e10cSrcweir 	// check printer driver for DJP support
1131cdf0e10cSrcweir 	pPrinter->mbDJPSupported = ImplIsDriverDJPEnabled( pPrinter->mhDC );
1132cdf0e10cSrcweir 
1133cdf0e10cSrcweir 	if ( bUpdateDriverData )
1134cdf0e10cSrcweir 	{
1135cdf0e10cSrcweir 		if ( pSetupData->mpDriverData )
1136cdf0e10cSrcweir 			rtl_freeMemory( pSetupData->mpDriverData);
1137fc9fd3f1SPedro Giffuni 		pSetupData->mpDriverData = (sal_uInt8*)rtl_allocateMemory( pDriverData->cb);
1138cdf0e10cSrcweir 		memcpy( pSetupData->mpDriverData, pDriverData, pDriverData->cb );
1139cdf0e10cSrcweir 		pSetupData->mnDriverDataLen = pDriverData->cb;
1140cdf0e10cSrcweir 	}
1141cdf0e10cSrcweir 
1142cdf0e10cSrcweir 	// retrieve current settings from printer driver and store them to system independend data!
1143cdf0e10cSrcweir 	if ( pPrinter->mbDJPSupported )
1144cdf0e10cSrcweir 		ImplGetCurrentSettings( pPrinter, pSetupData );
1145cdf0e10cSrcweir 	pSetupData->mnSystem = JOBSETUP_SYSTEM_OS2;
1146cdf0e10cSrcweir 
1147cdf0e10cSrcweir 	return pPrinter;
1148cdf0e10cSrcweir }
1149cdf0e10cSrcweir 
1150cdf0e10cSrcweir // -----------------------------------------------------------------------
1151cdf0e10cSrcweir 
1152cdf0e10cSrcweir void Os2SalInstance::DestroyInfoPrinter( SalInfoPrinter* pPrinter )
1153cdf0e10cSrcweir {
1154cdf0e10cSrcweir 	delete pPrinter;
1155cdf0e10cSrcweir }
1156cdf0e10cSrcweir 
1157cdf0e10cSrcweir // =======================================================================
1158cdf0e10cSrcweir 
1159cdf0e10cSrcweir Os2SalInfoPrinter::Os2SalInfoPrinter()
1160cdf0e10cSrcweir {
1161cdf0e10cSrcweir 	mhDC					= 0;
1162cdf0e10cSrcweir 	mhPS					= 0;
1163cdf0e10cSrcweir 	mpGraphics			= NULL;
1164cdf0e10cSrcweir 	mbGraphics			= FALSE;
1165cdf0e10cSrcweir 	mbDJPSupported		= FALSE;
1166cdf0e10cSrcweir 	mnFormCount			= 0;
1167cdf0e10cSrcweir 	mpFormArray			= NULL;
1168cdf0e10cSrcweir 	mnTrayCount			= 0;
1169cdf0e10cSrcweir 	mpTrayArray			= NULL;
1170*651793b0SYuri Dario 	m_bPapersInit		= FALSE;
1171cdf0e10cSrcweir }
1172cdf0e10cSrcweir 
1173cdf0e10cSrcweir // -----------------------------------------------------------------------
1174cdf0e10cSrcweir 
1175cdf0e10cSrcweir Os2SalInfoPrinter::~Os2SalInfoPrinter()
1176cdf0e10cSrcweir {
1177cdf0e10cSrcweir 	if ( mpGraphics )
1178cdf0e10cSrcweir 	{
1179cdf0e10cSrcweir 		ImplSalDestroyInfoPrn( this );
1180cdf0e10cSrcweir 		delete mpGraphics;
1181cdf0e10cSrcweir 	}
1182cdf0e10cSrcweir 
1183cdf0e10cSrcweir 	ImplFreeFormAndTrayList( this );
1184cdf0e10cSrcweir }
1185cdf0e10cSrcweir 
1186cdf0e10cSrcweir // -----------------------------------------------------------------------
1187cdf0e10cSrcweir 
1188*651793b0SYuri Dario void Os2SalInfoPrinter::InitPaperFormats( const ImplJobSetup* pSetupData )
1189*651793b0SYuri Dario {
1190*651793b0SYuri Dario #if OSL_DEBUG_LEVEL>0
1191*651793b0SYuri Dario 	debug_printf( "Os2SalInfoPrinter::InitPaperFormats pSetupData %x",
1192*651793b0SYuri Dario 				  pSetupData);
1193*651793b0SYuri Dario #endif
1194*651793b0SYuri Dario 
1195*651793b0SYuri Dario 	m_aPaperFormats.clear();
1196*651793b0SYuri Dario 	m_bPapersInit = true;
1197*651793b0SYuri Dario 
1198*651793b0SYuri Dario 	// init paperbinlist if empty
1199*651793b0SYuri Dario 	if ( !mnTrayCount )
1200*651793b0SYuri Dario 		ImplGetFormAndTrayList( this, pSetupData );
1201*651793b0SYuri Dario 
1202*651793b0SYuri Dario 	for( int i = 0; i < mnFormCount; i++)
1203*651793b0SYuri Dario 	{
1204*651793b0SYuri Dario 		PaperInfo aInfo( mpFormArray[i]->mnPaperWidth * 100,
1205*651793b0SYuri Dario 						 mpFormArray[i]->mnPaperHeight * 100);
1206*651793b0SYuri Dario #if OSL_DEBUG_LEVEL>0
1207*651793b0SYuri Dario 		debug_printf( "Os2SalInfoPrinter::InitPaperFormats #%d: %d x %d",
1208*651793b0SYuri Dario 					  i, mpFormArray[i]->mnPaperWidth * 100,
1209*651793b0SYuri Dario 					  mpFormArray[i]->mnPaperHeight * 100);
1210*651793b0SYuri Dario #endif
1211*651793b0SYuri Dario 		m_aPaperFormats.push_back( aInfo );
1212*651793b0SYuri Dario 	}
1213*651793b0SYuri Dario }
1214*651793b0SYuri Dario 
1215*651793b0SYuri Dario // -----------------------------------------------------------------------
1216*651793b0SYuri Dario 
1217*651793b0SYuri Dario int Os2SalInfoPrinter::GetLandscapeAngle( const ImplJobSetup* pSetupData )
1218*651793b0SYuri Dario {
1219*651793b0SYuri Dario 	return 900;
1220*651793b0SYuri Dario }
1221*651793b0SYuri Dario 
1222*651793b0SYuri Dario // -----------------------------------------------------------------------
1223*651793b0SYuri Dario 
1224cdf0e10cSrcweir SalGraphics* Os2SalInfoPrinter::GetGraphics()
1225cdf0e10cSrcweir {
1226cdf0e10cSrcweir 	if ( mbGraphics )
1227cdf0e10cSrcweir 		return NULL;
1228cdf0e10cSrcweir 
1229cdf0e10cSrcweir 	if ( mpGraphics )
1230cdf0e10cSrcweir 		mbGraphics = TRUE;
1231cdf0e10cSrcweir 
1232cdf0e10cSrcweir 	return mpGraphics;
1233cdf0e10cSrcweir }
1234cdf0e10cSrcweir 
1235cdf0e10cSrcweir // -----------------------------------------------------------------------
1236cdf0e10cSrcweir 
1237cdf0e10cSrcweir void Os2SalInfoPrinter::ReleaseGraphics( SalGraphics* )
1238cdf0e10cSrcweir {
1239cdf0e10cSrcweir 	mbGraphics = FALSE;
1240cdf0e10cSrcweir }
1241cdf0e10cSrcweir 
1242cdf0e10cSrcweir // -----------------------------------------------------------------------
1243cdf0e10cSrcweir 
1244fc9fd3f1SPedro Giffuni sal_Bool Os2SalInfoPrinter::Setup( SalFrame* pFrame, ImplJobSetup* pSetupData )
1245cdf0e10cSrcweir {
1246cdf0e10cSrcweir 	PDRIVDATA pDrivData = ImplPrnDrivData( pSetupData );
1247cdf0e10cSrcweir 	if ( !pDrivData )
1248cdf0e10cSrcweir 		return FALSE;
1249cdf0e10cSrcweir 
1250cdf0e10cSrcweir 	APIRET rc = DevPostDeviceModes( GetSalData()->mhAB, pDrivData,
1251cdf0e10cSrcweir 									maDriverName.GetBuffer(),
1252cdf0e10cSrcweir 									maDeviceName.GetBuffer(),
1253cdf0e10cSrcweir 									maPrinterName.GetBuffer(),
1254cdf0e10cSrcweir 									DPDM_POSTJOBPROP );
1255cdf0e10cSrcweir 	if ( rc == DEV_OK )
1256cdf0e10cSrcweir 	{
1257cdf0e10cSrcweir 		ImplUpdateSetupData( pDrivData, pSetupData );
1258cdf0e10cSrcweir 
1259cdf0e10cSrcweir 		// update DC and PS
1260cdf0e10cSrcweir 		HDC hDC;
1261cdf0e10cSrcweir 		HPS hPS;
1262cdf0e10cSrcweir 		if ( !ImplSalCreateInfoPrn( this, (PDRIVDATA)(pSetupData->mpDriverData), hDC, hPS ) )
1263cdf0e10cSrcweir 			return FALSE;
1264cdf0e10cSrcweir 
1265cdf0e10cSrcweir 		// Alten Printer DC/PS zerstoeren
1266cdf0e10cSrcweir 		ImplSalDestroyInfoPrn( this );
1267cdf0e10cSrcweir 
1268cdf0e10cSrcweir 		// Neue Daten setzen und initialisieren
1269cdf0e10cSrcweir 		mhDC = hDC;
1270cdf0e10cSrcweir 		mhPS = hPS;
1271cdf0e10cSrcweir 		mpGraphics->mhDC = mhDC;
1272cdf0e10cSrcweir 		mpGraphics->mhPS = mhPS;
1273cdf0e10cSrcweir 		ImplSalInitGraphics( mpGraphics );
1274cdf0e10cSrcweir 
1275cdf0e10cSrcweir 		// retrieve current settings from printer driver and store them to system independend data!
1276cdf0e10cSrcweir 		ImplFreeFormAndTrayList( this );
1277cdf0e10cSrcweir 		if ( mbDJPSupported )
1278cdf0e10cSrcweir 			ImplGetCurrentSettings( this, pSetupData );
1279cdf0e10cSrcweir 
1280cdf0e10cSrcweir 		return TRUE;
1281cdf0e10cSrcweir 	}
1282cdf0e10cSrcweir 	else
1283cdf0e10cSrcweir 	{
1284cdf0e10cSrcweir 		ImplFreePrnMemory( pDrivData );
1285cdf0e10cSrcweir 		return FALSE;
1286cdf0e10cSrcweir 	}
1287cdf0e10cSrcweir }
1288cdf0e10cSrcweir 
1289cdf0e10cSrcweir // -----------------------------------------------------------------------
1290cdf0e10cSrcweir 
1291fc9fd3f1SPedro Giffuni sal_Bool Os2SalInfoPrinter::SetPrinterData( ImplJobSetup* pSetupData )
1292cdf0e10cSrcweir {
1293cdf0e10cSrcweir 	// Wir koennen nur Treiberdaten von OS2 setzen
1294cdf0e10cSrcweir 	if ( pSetupData->mnSystem != JOBSETUP_SYSTEM_OS2 )
1295cdf0e10cSrcweir 		return FALSE;
1296cdf0e10cSrcweir 
1297cdf0e10cSrcweir 	PDRIVDATA pNewDrivData = (PDRIVDATA)(pSetupData->mpDriverData);
1298cdf0e10cSrcweir 	if ( !pNewDrivData )
1299cdf0e10cSrcweir 		return FALSE;
1300cdf0e10cSrcweir 
1301cdf0e10cSrcweir 	// Testen, ob Printerdaten fuer den gleichen Printer uebergeben werden,
1302cdf0e10cSrcweir 	// da einige Treiber zu Abstuerzen neigen, wenn Daten von einem anderen
1303cdf0e10cSrcweir 	// Printer gesetzt werden
1304cdf0e10cSrcweir 	if ( !maJobSetupDeviceName.Equals( pNewDrivData->szDeviceName ))
1305cdf0e10cSrcweir 		return FALSE;
1306cdf0e10cSrcweir 
1307cdf0e10cSrcweir 	// update DC and PS
1308cdf0e10cSrcweir 	HDC hDC;
1309cdf0e10cSrcweir 	HPS hPS;
1310cdf0e10cSrcweir 	if ( !ImplSalCreateInfoPrn( this, pNewDrivData, hDC, hPS ) )
1311cdf0e10cSrcweir 		return FALSE;
1312cdf0e10cSrcweir 
1313cdf0e10cSrcweir 	// Alten Printer DC/PS zerstoeren
1314cdf0e10cSrcweir 	ImplSalDestroyInfoPrn( this );
1315cdf0e10cSrcweir 
1316cdf0e10cSrcweir 	// Neue Daten setzen und initialisieren
1317cdf0e10cSrcweir 	mhDC = hDC;
1318cdf0e10cSrcweir 	mhPS = hPS;
1319cdf0e10cSrcweir 	mpGraphics->mhDC = mhDC;
1320cdf0e10cSrcweir 	mpGraphics->mhPS = mhPS;
1321cdf0e10cSrcweir 	ImplSalInitGraphics( mpGraphics );
1322cdf0e10cSrcweir 
1323cdf0e10cSrcweir 	// retrieve current settings from printer driver and store them to system independend data!
1324cdf0e10cSrcweir 	ImplFreeFormAndTrayList( this );
1325cdf0e10cSrcweir 	if ( mbDJPSupported )
1326cdf0e10cSrcweir 		ImplGetCurrentSettings( this, pSetupData );
1327cdf0e10cSrcweir 
1328cdf0e10cSrcweir 	return TRUE;
1329cdf0e10cSrcweir }
1330cdf0e10cSrcweir 
1331cdf0e10cSrcweir // -----------------------------------------------------------------------
1332cdf0e10cSrcweir 
1333fc9fd3f1SPedro Giffuni sal_Bool Os2SalInfoPrinter::SetData( ULONG nFlags, ImplJobSetup* pSetupData )
1334cdf0e10cSrcweir {
1335*651793b0SYuri Dario #if OSL_DEBUG_LEVEL>0
1336*651793b0SYuri Dario 	debug_printf( "Os2SalInfoPrinter::SetData nFlags %x, pSetupData %x",
1337*651793b0SYuri Dario 				  nFlags, pSetupData);
1338*651793b0SYuri Dario #endif
1339*651793b0SYuri Dario 
1340cdf0e10cSrcweir 	// needs DJP support
1341cdf0e10cSrcweir 	if ( !mbDJPSupported )
1342cdf0e10cSrcweir 		return FALSE;
1343cdf0e10cSrcweir 
1344cdf0e10cSrcweir 	PDRIVDATA pDrivData = ImplPrnDrivData( pSetupData );
1345cdf0e10cSrcweir 
1346cdf0e10cSrcweir 	if ( !pDrivData )
1347cdf0e10cSrcweir 		return FALSE;
1348cdf0e10cSrcweir 
1349fc9fd3f1SPedro Giffuni 	sal_Bool bOK = FALSE;
1350cdf0e10cSrcweir 
1351cdf0e10cSrcweir 	// set orientation
1352cdf0e10cSrcweir 	if ( nFlags & SAL_JOBSET_ORIENTATION )
1353cdf0e10cSrcweir 	{
1354*651793b0SYuri Dario #if OSL_DEBUG_LEVEL>0
1355*651793b0SYuri Dario 		debug_printf( "Os2SalInfoPrinter::SetData meOrientation %d", pSetupData->meOrientation);
1356*651793b0SYuri Dario #endif
1357cdf0e10cSrcweir 		if ( ImplSetOrientation( mhDC, pDrivData, pSetupData->meOrientation ) )
1358cdf0e10cSrcweir 			bOK = TRUE;
1359cdf0e10cSrcweir 	}
1360cdf0e10cSrcweir 
1361cdf0e10cSrcweir 	// set paper size
1362cdf0e10cSrcweir 	if ( nFlags & SAL_JOBSET_PAPERSIZE )
1363cdf0e10cSrcweir 	{
1364cdf0e10cSrcweir 		// Papierformat ermitteln
1365cdf0e10cSrcweir 		DJPT_PAPERSIZE nOS2PaperFormat;
1366cdf0e10cSrcweir 		switch ( pSetupData->mePaperFormat )
1367cdf0e10cSrcweir 		{
1368cdf0e10cSrcweir 			case PAPER_A3:
1369cdf0e10cSrcweir 				nOS2PaperFormat = DJP_PSI_A3;
1370cdf0e10cSrcweir 				break;
1371cdf0e10cSrcweir 
1372cdf0e10cSrcweir 			case PAPER_A4:
1373cdf0e10cSrcweir 				nOS2PaperFormat = DJP_PSI_A4;
1374cdf0e10cSrcweir 				break;
1375cdf0e10cSrcweir 
1376cdf0e10cSrcweir 			case PAPER_A5:
1377cdf0e10cSrcweir 				nOS2PaperFormat = DJP_PSI_A5;
1378cdf0e10cSrcweir 				break;
1379cdf0e10cSrcweir 
1380fc9fd3f1SPedro Giffuni 			case PAPER_B4_JIS:
1381cdf0e10cSrcweir 				nOS2PaperFormat = DJP_PSI_B4;
1382cdf0e10cSrcweir 				break;
1383cdf0e10cSrcweir 
1384fc9fd3f1SPedro Giffuni 			case PAPER_B5_JIS:
1385cdf0e10cSrcweir 				nOS2PaperFormat = DJP_PSI_B5;
1386cdf0e10cSrcweir 				break;
1387cdf0e10cSrcweir 
1388cdf0e10cSrcweir 			case PAPER_LETTER:
1389cdf0e10cSrcweir 				nOS2PaperFormat = DJP_PSI_LETTER;
1390cdf0e10cSrcweir 				break;
1391cdf0e10cSrcweir 
1392cdf0e10cSrcweir 			case PAPER_LEGAL:
1393cdf0e10cSrcweir 				nOS2PaperFormat = DJP_PSI_LEGAL;
1394cdf0e10cSrcweir 				break;
1395cdf0e10cSrcweir 
1396cdf0e10cSrcweir 			case PAPER_TABLOID:
1397cdf0e10cSrcweir 				nOS2PaperFormat = DJP_PSI_TABLOID;
1398cdf0e10cSrcweir 				break;
1399cdf0e10cSrcweir 
1400cdf0e10cSrcweir 			default:
1401cdf0e10cSrcweir 				{
1402cdf0e10cSrcweir 				nOS2PaperFormat = DJP_PSI_NONE;
1403cdf0e10cSrcweir 				// OS2 rechnet in Millimetern
1404cdf0e10cSrcweir 				long nPaperWidth	 = pSetupData->mnPaperWidth  / 100;
1405cdf0e10cSrcweir 				long nPaperHeight	 = pSetupData->mnPaperHeight / 100;
1406cdf0e10cSrcweir 				// Ansonsten ueber die Papiergroesse suchen
1407cdf0e10cSrcweir 				for( int i = 0; i < mnFormCount; i++ )
1408cdf0e10cSrcweir 				{
1409cdf0e10cSrcweir 					ImplFormInfo* pFormInfo = mpFormArray[i];
1410cdf0e10cSrcweir 					if ( ImplPaperSizeEqual( nPaperWidth, nPaperHeight,
1411cdf0e10cSrcweir 											 pFormInfo->mnPaperWidth, pFormInfo->mnPaperHeight ) )
1412cdf0e10cSrcweir 					{
1413cdf0e10cSrcweir 						nOS2PaperFormat = pFormInfo->mnId;
1414cdf0e10cSrcweir 						break;
1415cdf0e10cSrcweir 					}
1416cdf0e10cSrcweir 				}
1417cdf0e10cSrcweir 				}
1418cdf0e10cSrcweir 				break;
1419cdf0e10cSrcweir 		}
1420cdf0e10cSrcweir 
1421cdf0e10cSrcweir 		if ( nOS2PaperFormat != DJP_PSI_NONE )
1422cdf0e10cSrcweir 		{
1423cdf0e10cSrcweir 			if ( ImplSetPaperSize( mhDC, pDrivData, nOS2PaperFormat ) )
1424cdf0e10cSrcweir 				bOK = TRUE;
1425cdf0e10cSrcweir 		}
1426cdf0e10cSrcweir 	}
1427cdf0e10cSrcweir 
1428cdf0e10cSrcweir 	// set paper tray
1429cdf0e10cSrcweir 	if ( (nFlags & SAL_JOBSET_PAPERBIN) && (pSetupData->mnPaperBin < mnTrayCount) )
1430cdf0e10cSrcweir 	{
1431cdf0e10cSrcweir 		if ( ImplSetPaperBin( mhDC, pDrivData,
1432cdf0e10cSrcweir 							  mpTrayArray[pSetupData->mnPaperBin] ) )
1433cdf0e10cSrcweir 			bOK = TRUE;
1434cdf0e10cSrcweir 	}
1435cdf0e10cSrcweir 
1436cdf0e10cSrcweir 	if ( bOK )
1437cdf0e10cSrcweir 	{
1438cdf0e10cSrcweir 		ImplUpdateSetupData( pDrivData, pSetupData );
1439cdf0e10cSrcweir 
1440cdf0e10cSrcweir 		// query current driver settings
1441cdf0e10cSrcweir 		ImplFreeFormAndTrayList( this );
1442cdf0e10cSrcweir 		if ( ImplGetCurrentSettings( this, pSetupData ) )
1443cdf0e10cSrcweir 		{
1444cdf0e10cSrcweir 			// update DC and PS
1445cdf0e10cSrcweir 			HDC hDC;
1446cdf0e10cSrcweir 			HPS hPS;
1447cdf0e10cSrcweir 			if ( ImplSalCreateInfoPrn( this, (PDRIVDATA)(pSetupData->mpDriverData), hDC, hPS ) )
1448cdf0e10cSrcweir 			{
1449cdf0e10cSrcweir 				// Alten Printer DC/PS zerstoeren
1450cdf0e10cSrcweir 				ImplSalDestroyInfoPrn( this );
1451cdf0e10cSrcweir 
1452cdf0e10cSrcweir 				// Neue Daten setzen und initialisieren
1453cdf0e10cSrcweir 				mhDC = hDC;
1454cdf0e10cSrcweir 				mhPS = hPS;
1455cdf0e10cSrcweir 				mpGraphics->mhDC = mhDC;
1456cdf0e10cSrcweir 				mpGraphics->mhPS = mhPS;
1457cdf0e10cSrcweir 				ImplSalInitGraphics( mpGraphics );
1458cdf0e10cSrcweir 			}
1459cdf0e10cSrcweir 			else
1460cdf0e10cSrcweir 				bOK = FALSE;
1461cdf0e10cSrcweir 		}
1462cdf0e10cSrcweir 		else
1463cdf0e10cSrcweir 			bOK = FALSE;
1464cdf0e10cSrcweir 	}
1465cdf0e10cSrcweir 
1466cdf0e10cSrcweir 	return bOK;
1467cdf0e10cSrcweir }
1468cdf0e10cSrcweir 
1469cdf0e10cSrcweir // -----------------------------------------------------------------------
1470cdf0e10cSrcweir 
1471cdf0e10cSrcweir ULONG Os2SalInfoPrinter::GetPaperBinCount( const ImplJobSetup* pJobSetup )
1472cdf0e10cSrcweir {
1473cdf0e10cSrcweir 	if ( !mbDJPSupported )
1474cdf0e10cSrcweir 		return 1;
1475cdf0e10cSrcweir 
1476cdf0e10cSrcweir 	// init paperbinlist if empty
1477cdf0e10cSrcweir 	if ( !mnTrayCount )
1478cdf0e10cSrcweir 		ImplGetFormAndTrayList( this, pJobSetup );
1479cdf0e10cSrcweir 
1480cdf0e10cSrcweir 	// Wir haben immer einen PaperTray und wenn, das eben einen ohne
1481cdf0e10cSrcweir 	// Namen
1482cdf0e10cSrcweir 	if ( !mnTrayCount )
1483cdf0e10cSrcweir 		return 1;
1484cdf0e10cSrcweir 	else
1485cdf0e10cSrcweir 		return mnTrayCount;
1486cdf0e10cSrcweir }
1487cdf0e10cSrcweir 
1488cdf0e10cSrcweir // -----------------------------------------------------------------------
1489cdf0e10cSrcweir 
1490cdf0e10cSrcweir XubString Os2SalInfoPrinter::GetPaperBinName( const ImplJobSetup* pJobSetup,
1491cdf0e10cSrcweir 										  ULONG nPaperBin )
1492cdf0e10cSrcweir {
1493cdf0e10cSrcweir 	XubString aPaperBinName;
1494cdf0e10cSrcweir 
1495cdf0e10cSrcweir 	if ( mbDJPSupported )
1496cdf0e10cSrcweir 	{
1497cdf0e10cSrcweir 		// init paperbinlist if empty
1498cdf0e10cSrcweir 		if ( !mnTrayCount )
1499cdf0e10cSrcweir 			ImplGetFormAndTrayList( this, pJobSetup );
1500cdf0e10cSrcweir 
1501cdf0e10cSrcweir 		if ( nPaperBin < mnTrayCount )
1502cdf0e10cSrcweir 			aPaperBinName = ::rtl::OStringToOUString (mpTrayArray[nPaperBin]->maDisplayName, gsl_getSystemTextEncoding());
1503cdf0e10cSrcweir 	}
1504cdf0e10cSrcweir 
1505cdf0e10cSrcweir 	return aPaperBinName;
1506cdf0e10cSrcweir }
1507cdf0e10cSrcweir 
1508cdf0e10cSrcweir // -----------------------------------------------------------------------
1509cdf0e10cSrcweir 
1510cdf0e10cSrcweir ULONG Os2SalInfoPrinter::GetCapabilities( const ImplJobSetup*, USHORT nType )
1511cdf0e10cSrcweir {
1512cdf0e10cSrcweir 	switch ( nType )
1513cdf0e10cSrcweir 	{
1514cdf0e10cSrcweir 		case PRINTER_CAPABILITIES_SUPPORTDIALOG:
1515cdf0e10cSrcweir 			return TRUE;
1516cdf0e10cSrcweir 		case PRINTER_CAPABILITIES_COPIES:
1517cdf0e10cSrcweir 			return 0xFFFF;
1518cdf0e10cSrcweir 		case PRINTER_CAPABILITIES_COLLATECOPIES:
1519cdf0e10cSrcweir 			return 0;
1520cdf0e10cSrcweir 		case PRINTER_CAPABILITIES_SETORIENTATION:
1521cdf0e10cSrcweir 		case PRINTER_CAPABILITIES_SETPAPERBIN:
1522cdf0e10cSrcweir 		case PRINTER_CAPABILITIES_SETPAPERSIZE:
1523cdf0e10cSrcweir 		case PRINTER_CAPABILITIES_SETPAPER:
1524cdf0e10cSrcweir 			return mbDJPSupported;
1525cdf0e10cSrcweir 	}
1526cdf0e10cSrcweir 
1527cdf0e10cSrcweir 	return 0;
1528cdf0e10cSrcweir }
1529cdf0e10cSrcweir 
1530cdf0e10cSrcweir // -----------------------------------------------------------------------
1531cdf0e10cSrcweir 
1532cdf0e10cSrcweir void Os2SalInfoPrinter::GetPageInfo( const ImplJobSetup*,
1533cdf0e10cSrcweir 								  long& rOutWidth, long& rOutHeight,
1534cdf0e10cSrcweir 								  long& rPageOffX, long& rPageOffY,
1535cdf0e10cSrcweir 								  long& rPageWidth, long& rPageHeight )
1536cdf0e10cSrcweir {
1537cdf0e10cSrcweir 	HDC hDC = mhDC;
1538cdf0e10cSrcweir 
1539cdf0e10cSrcweir 	// search current form
1540cdf0e10cSrcweir 	HCINFO	aInfo;
1541cdf0e10cSrcweir 	int nForms = DevQueryHardcopyCaps( hDC, 0, 0, &aInfo );
1542cdf0e10cSrcweir 	for( int i = 0; i < nForms; i++ )
1543cdf0e10cSrcweir 	{
1544cdf0e10cSrcweir 		if ( DevQueryHardcopyCaps( hDC, i, 1, &aInfo ) >= 0 )
1545cdf0e10cSrcweir 		{
1546cdf0e10cSrcweir 			if ( aInfo.flAttributes & HCAPS_CURRENT )
1547cdf0e10cSrcweir 			{
1548cdf0e10cSrcweir 				// query resolution
1549cdf0e10cSrcweir 				long nXResolution;
1550cdf0e10cSrcweir 				long nYResolution;
1551cdf0e10cSrcweir 				DevQueryCaps( hDC, CAPS_HORIZONTAL_RESOLUTION, 1, &nXResolution );
1552cdf0e10cSrcweir 				DevQueryCaps( hDC, CAPS_VERTICAL_RESOLUTION, 1, &nYResolution );
1553cdf0e10cSrcweir 				rPageOffX	= aInfo.xLeftClip * nXResolution / 1000;
1554cdf0e10cSrcweir 				rPageOffY	= (aInfo.cy-aInfo.yTopClip) * nYResolution / 1000;
1555cdf0e10cSrcweir 				rPageWidth	= aInfo.cx * nXResolution / 1000;
1556cdf0e10cSrcweir 				rPageHeight = aInfo.cy * nYResolution / 1000;
1557cdf0e10cSrcweir 				rOutWidth	= aInfo.xPels;
1558cdf0e10cSrcweir 				rOutHeight	= aInfo.yPels;
1559cdf0e10cSrcweir 				return;
1560cdf0e10cSrcweir 			}
1561cdf0e10cSrcweir 		}
1562cdf0e10cSrcweir 	}
1563cdf0e10cSrcweir 
1564cdf0e10cSrcweir 	// use device caps if no form selected/found
1565cdf0e10cSrcweir 	long lCapsWidth = 0;
1566cdf0e10cSrcweir 	long lCapsHeight = 0;
1567cdf0e10cSrcweir 	DevQueryCaps( hDC, CAPS_WIDTH, 1L, &lCapsWidth );
1568cdf0e10cSrcweir 	DevQueryCaps( hDC, CAPS_HEIGHT, 1L, &lCapsHeight );
1569cdf0e10cSrcweir 	rPageOffX	 = 0;
1570cdf0e10cSrcweir 	rPageOffY	 = 0;
1571cdf0e10cSrcweir 	rOutWidth	 = lCapsWidth;
1572cdf0e10cSrcweir 	rOutHeight	 = lCapsHeight;
1573cdf0e10cSrcweir 	rPageWidth	 = rOutWidth;
1574cdf0e10cSrcweir 	rPageHeight  = rOutHeight;
1575cdf0e10cSrcweir }
1576cdf0e10cSrcweir 
1577cdf0e10cSrcweir // =======================================================================
1578cdf0e10cSrcweir 
1579fc9fd3f1SPedro Giffuni static sal_Bool ImplIsDriverPrintDJPEnabled( HDC hDC )
1580cdf0e10cSrcweir {
1581cdf0e10cSrcweir #ifdef NO_DJP
1582cdf0e10cSrcweir 	return FALSE;
1583cdf0e10cSrcweir #else
1584cdf0e10cSrcweir 	// Ueber OS2-Ini kann DJP disablte werden
1585cdf0e10cSrcweir 	if ( !PrfQueryProfileInt( HINI_PROFILE, SAL_PROFILE_APPNAME, SAL_PROFILE_PRINTDJP, 1 ) )
1586cdf0e10cSrcweir 		return FALSE;
1587cdf0e10cSrcweir 
1588cdf0e10cSrcweir 	// Testen, ob DJP-Interface am Drucker vorhanden
1589cdf0e10cSrcweir 	LONG   lQuery;
1590cdf0e10cSrcweir 	APIRET rc;
1591cdf0e10cSrcweir 
1592cdf0e10cSrcweir 	lQuery = DEVESC_QUERYSIZE;
1593cdf0e10cSrcweir 	rc = DevEscape( hDC,
1594cdf0e10cSrcweir 					DEVESC_QUERYESCSUPPORT,
1595cdf0e10cSrcweir 					sizeof( lQuery ),
1596cdf0e10cSrcweir 					(PBYTE)&lQuery,
1597cdf0e10cSrcweir 					0,
1598cdf0e10cSrcweir 					(PBYTE)NULL );
1599cdf0e10cSrcweir 	if ( DEV_OK != rc )
1600cdf0e10cSrcweir 		return FALSE;
1601cdf0e10cSrcweir 
1602cdf0e10cSrcweir 	return TRUE;
1603cdf0e10cSrcweir #endif
1604cdf0e10cSrcweir }
1605cdf0e10cSrcweir 
1606cdf0e10cSrcweir // =======================================================================
1607cdf0e10cSrcweir 
1608cdf0e10cSrcweir SalPrinter* Os2SalInstance::CreatePrinter( SalInfoPrinter* pInfoPrinter )
1609cdf0e10cSrcweir {
1610cdf0e10cSrcweir 	Os2SalPrinter* pPrinter = new Os2SalPrinter;
1611cdf0e10cSrcweir 	pPrinter->mpInfoPrinter = static_cast<Os2SalInfoPrinter*>(pInfoPrinter);
1612cdf0e10cSrcweir 	return pPrinter;
1613cdf0e10cSrcweir }
1614cdf0e10cSrcweir 
1615cdf0e10cSrcweir // -----------------------------------------------------------------------
1616cdf0e10cSrcweir 
1617cdf0e10cSrcweir void Os2SalInstance::DestroyPrinter( SalPrinter* pPrinter )
1618cdf0e10cSrcweir {
1619cdf0e10cSrcweir 	delete pPrinter;
1620cdf0e10cSrcweir }
1621cdf0e10cSrcweir 
1622cdf0e10cSrcweir // =======================================================================
1623cdf0e10cSrcweir 
1624cdf0e10cSrcweir Os2SalPrinter::Os2SalPrinter()
1625cdf0e10cSrcweir {
1626cdf0e10cSrcweir 	mhDC					= 0;
1627cdf0e10cSrcweir 	mhPS					= 0;
1628cdf0e10cSrcweir 	mpGraphics			= NULL;
1629cdf0e10cSrcweir 	mbAbort				= FALSE;
1630cdf0e10cSrcweir 	mbPrintDJPSupported	= FALSE;
1631cdf0e10cSrcweir }
1632cdf0e10cSrcweir 
1633cdf0e10cSrcweir // -----------------------------------------------------------------------
1634cdf0e10cSrcweir 
1635cdf0e10cSrcweir Os2SalPrinter::~Os2SalPrinter()
1636cdf0e10cSrcweir {
1637cdf0e10cSrcweir }
1638cdf0e10cSrcweir 
1639cdf0e10cSrcweir // -----------------------------------------------------------------------
1640cdf0e10cSrcweir 
1641fc9fd3f1SPedro Giffuni sal_Bool Os2SalPrinter::StartJob( const XubString* pFileName,
1642cdf0e10cSrcweir 						   const XubString& rJobName,
1643cdf0e10cSrcweir 						   const XubString& rAppName,
1644cdf0e10cSrcweir 						   ULONG nCopies,
1645cdf0e10cSrcweir                            bool bCollate,
1646cdf0e10cSrcweir                            bool bDirect,
1647cdf0e10cSrcweir 						   ImplJobSetup* pSetupData )
1648cdf0e10cSrcweir {
1649cdf0e10cSrcweir 	DEVOPENSTRUC	aDevOpenStruc;
1650cdf0e10cSrcweir 	LONG			lType;
1651cdf0e10cSrcweir 	APIRET			rc;
1652cdf0e10cSrcweir 
1653cdf0e10cSrcweir 	// prepare queue information
1654cdf0e10cSrcweir 	memset( &aDevOpenStruc, 0, sizeof( aDevOpenStruc ) );
1655cdf0e10cSrcweir 	aDevOpenStruc.pszDriverName = (PSZ)(mpInfoPrinter->maDriverName.GetBuffer());
1656cdf0e10cSrcweir 
1657cdf0e10cSrcweir 	// print into file?
1658cdf0e10cSrcweir 	if ( pFileName )
1659cdf0e10cSrcweir 	{
1660cdf0e10cSrcweir 		aDevOpenStruc.pszLogAddress = (PSZ)pFileName->GetBuffer();
1661cdf0e10cSrcweir 		aDevOpenStruc.pszDataType = "PM_Q_RAW";
1662cdf0e10cSrcweir 		lType = OD_DIRECT;
1663cdf0e10cSrcweir 	}
1664cdf0e10cSrcweir 	else
1665cdf0e10cSrcweir 	{
1666cdf0e10cSrcweir 		aDevOpenStruc.pszLogAddress = (PSZ)(mpInfoPrinter->maName.GetBuffer());
1667cdf0e10cSrcweir 		if ( PrfQueryProfileInt( HINI_PROFILE, SAL_PROFILE_APPNAME, SAL_PROFILE_PRINTRAW, 0 ) )
1668cdf0e10cSrcweir 			aDevOpenStruc.pszDataType = "PM_Q_RAW";
1669cdf0e10cSrcweir 		else
1670cdf0e10cSrcweir 			aDevOpenStruc.pszDataType = "PM_Q_STD";
1671cdf0e10cSrcweir 		lType = OD_QUEUED;
1672cdf0e10cSrcweir 	}
1673cdf0e10cSrcweir 
1674cdf0e10cSrcweir #if 0 // YD FIXME
1675cdf0e10cSrcweir 	// Set comment (AppName nur bis zum 1. Space-Zeichen nehmen)
1676cdf0e10cSrcweir 	const xub_Unicode*	pComment = rAppName;
1677cdf0e10cSrcweir 	USHORT			nCommentLen = 0;
1678cdf0e10cSrcweir 	memset( maCommentBuf, 0, sizeof( maCommentBuf ) );
1679cdf0e10cSrcweir 	while ( (nCommentLen < 32) &&
1680cdf0e10cSrcweir 			(((*pComment >= 'a') && (*pComment <= 'z')) ||
1681cdf0e10cSrcweir 			 ((*pComment >= 'A') && (*pComment <= 'Z')) ||
1682cdf0e10cSrcweir 			 ((*pComment >= '0') && (*pComment <= '9')) ||
1683cdf0e10cSrcweir 			 (*pComment == '-')))
1684cdf0e10cSrcweir 	{
1685cdf0e10cSrcweir 		maCommentBuf[nCommentLen] = (char)(*pComment);
1686cdf0e10cSrcweir 		nCommentLen++;
1687cdf0e10cSrcweir 		pComment++;
1688cdf0e10cSrcweir 	}
1689cdf0e10cSrcweir 	aDevOpenStruc.pszComment = (PSZ)maCommentBuf;
1690cdf0e10cSrcweir #endif
1691cdf0e10cSrcweir 	ByteString jobName( rJobName, gsl_getSystemTextEncoding());
1692cdf0e10cSrcweir 	aDevOpenStruc.pszComment = (PSZ)jobName.GetBuffer();
1693cdf0e10cSrcweir 
1694cdf0e10cSrcweir 	// Kopien
1695cdf0e10cSrcweir 	if ( nCopies > 1 )
1696cdf0e10cSrcweir 	{
1697cdf0e10cSrcweir 		// OS2 kann maximal 999 Kopien
1698cdf0e10cSrcweir 		if ( nCopies > 999 )
1699cdf0e10cSrcweir 			nCopies = 999;
1700cdf0e10cSrcweir 		sprintf( maCopyBuf, "COP=%d", nCopies);
1701cdf0e10cSrcweir 		aDevOpenStruc.pszQueueProcParams = (PSZ)maCopyBuf;
1702cdf0e10cSrcweir 	}
1703cdf0e10cSrcweir 
1704cdf0e10cSrcweir 	// open device context
1705cdf0e10cSrcweir 	SalData*	pSalData = GetSalData();
1706cdf0e10cSrcweir 	HAB 		hAB = pSalData->mhAB;
1707cdf0e10cSrcweir 	aDevOpenStruc.pdriv = (PDRIVDATA)pSetupData->mpDriverData;
1708cdf0e10cSrcweir 	mhDC = DevOpenDC( hAB,
1709cdf0e10cSrcweir 									lType,
1710cdf0e10cSrcweir 									"*",
1711cdf0e10cSrcweir 									7,
1712cdf0e10cSrcweir 									(PDEVOPENDATA)&aDevOpenStruc,
1713cdf0e10cSrcweir 									0 );
1714cdf0e10cSrcweir 	if ( mhDC == 0 )
1715cdf0e10cSrcweir 	{
1716cdf0e10cSrcweir 		ERRORID nLastError = WinGetLastError( hAB );
1717cdf0e10cSrcweir 		if ( (nLastError & 0xFFFF) == PMERR_SPL_PRINT_ABORT )
1718cdf0e10cSrcweir 			mnError = SAL_PRINTER_ERROR_ABORT;
1719cdf0e10cSrcweir 		else
1720cdf0e10cSrcweir 			mnError = SAL_PRINTER_ERROR_GENERALERROR;
1721cdf0e10cSrcweir 		return FALSE;
1722cdf0e10cSrcweir 	}
1723cdf0e10cSrcweir 
1724cdf0e10cSrcweir 	// open presentation space
1725cdf0e10cSrcweir 	SIZEL sizel;
1726cdf0e10cSrcweir 	sizel.cx = 0;
1727cdf0e10cSrcweir 	sizel.cy = 0;
1728cdf0e10cSrcweir 	mhPS = Ft2CreatePS( hAB, mhDC, &sizel, GPIA_ASSOC | GPIT_MICRO | PU_PELS );
1729cdf0e10cSrcweir 	if ( !mhPS )
1730cdf0e10cSrcweir 	{
1731cdf0e10cSrcweir 		DevCloseDC( mhDC );
1732cdf0e10cSrcweir 		mnError = SAL_PRINTER_ERROR_GENERALERROR;
1733cdf0e10cSrcweir 		return NULL;
1734cdf0e10cSrcweir 	}
1735cdf0e10cSrcweir 
1736cdf0e10cSrcweir 	// Can we print with DJP
1737cdf0e10cSrcweir 	mbPrintDJPSupported = ImplIsDriverPrintDJPEnabled( mhDC );
1738*651793b0SYuri Dario #if OSL_DEBUG_LEVEL>0
1739*651793b0SYuri Dario 	debug_printf( "mbPrintDJPSupported %d", mbPrintDJPSupported);
1740*651793b0SYuri Dario #endif
1741cdf0e10cSrcweir 
1742cdf0e10cSrcweir 	// JobName ermitteln und Job starten
1743cdf0e10cSrcweir 	PSZ pszJobName = NULL;
1744cdf0e10cSrcweir 	int nJobNameLen = 0;
1745cdf0e10cSrcweir 	if ( jobName.Len() > 0 )
1746cdf0e10cSrcweir 	{
1747cdf0e10cSrcweir 		pszJobName = (PSZ)jobName.GetBuffer();
1748cdf0e10cSrcweir 		nJobNameLen = jobName.Len();
1749cdf0e10cSrcweir 	}
1750cdf0e10cSrcweir 	rc = DevEscape( mhDC,
1751*651793b0SYuri Dario 					mbPrintDJPSupported ? DEVESC_STARTDOC_WPROP : DEVESC_STARTDOC,
1752cdf0e10cSrcweir 					nJobNameLen, (PBYTE)pszJobName,
1753*651793b0SYuri Dario 					&((PDRIVDATA)(pSetupData->mpDriverData))->cb,
1754*651793b0SYuri Dario 					(PBYTE)(pSetupData->mpDriverData));
1755cdf0e10cSrcweir 
1756cdf0e10cSrcweir 	if ( rc != DEV_OK )
1757cdf0e10cSrcweir 	{
1758cdf0e10cSrcweir 		ERRORID nLastError = WinGetLastError( hAB );
1759cdf0e10cSrcweir 		if ( (nLastError & 0xFFFF) == PMERR_SPL_PRINT_ABORT )
1760cdf0e10cSrcweir 			mnError = SAL_PRINTER_ERROR_ABORT;
1761cdf0e10cSrcweir 		else
1762cdf0e10cSrcweir 			mnError = SAL_PRINTER_ERROR_GENERALERROR;
1763cdf0e10cSrcweir 		Ft2Associate( mhPS, NULL );
1764cdf0e10cSrcweir 		Ft2DestroyPS( mhPS );
1765cdf0e10cSrcweir 		DevCloseDC( mhDC );
1766cdf0e10cSrcweir 		return FALSE;
1767cdf0e10cSrcweir 	}
1768cdf0e10cSrcweir 
1769cdf0e10cSrcweir 	// init for first page
1770cdf0e10cSrcweir 	mbFirstPage = TRUE;
1771cdf0e10cSrcweir 	mnError = 0;
1772cdf0e10cSrcweir 
1773cdf0e10cSrcweir 	return TRUE;
1774cdf0e10cSrcweir }
1775cdf0e10cSrcweir 
1776cdf0e10cSrcweir // -----------------------------------------------------------------------
1777cdf0e10cSrcweir 
1778fc9fd3f1SPedro Giffuni sal_Bool Os2SalPrinter::EndJob()
1779cdf0e10cSrcweir {
1780cdf0e10cSrcweir 	APIRET rc;
1781cdf0e10cSrcweir 	rc = DevEscape( mhDC,
1782cdf0e10cSrcweir 					DEVESC_ENDDOC,
1783cdf0e10cSrcweir 					0, NULL,
1784cdf0e10cSrcweir 					0, NULL);
1785cdf0e10cSrcweir 
1786cdf0e10cSrcweir 	// destroy presentation space and device context
1787cdf0e10cSrcweir 	Ft2Associate( mhPS, NULL );
1788cdf0e10cSrcweir 	Ft2DestroyPS( mhPS );
1789cdf0e10cSrcweir 	DevCloseDC( mhDC );
1790cdf0e10cSrcweir 	return TRUE;
1791cdf0e10cSrcweir }
1792cdf0e10cSrcweir 
1793cdf0e10cSrcweir // -----------------------------------------------------------------------
1794cdf0e10cSrcweir 
1795fc9fd3f1SPedro Giffuni sal_Bool Os2SalPrinter::AbortJob()
1796cdf0e10cSrcweir {
1797cdf0e10cSrcweir 	APIRET rc;
1798cdf0e10cSrcweir 
1799cdf0e10cSrcweir 	rc = DevEscape( mhDC,
1800cdf0e10cSrcweir 					DEVESC_ABORTDOC,
1801cdf0e10cSrcweir 					0, NULL,
1802cdf0e10cSrcweir 					0, NULL );
1803cdf0e10cSrcweir 
1804cdf0e10cSrcweir 	// destroy SalGraphics
1805cdf0e10cSrcweir 	if ( mpGraphics )
1806cdf0e10cSrcweir 	{
1807cdf0e10cSrcweir 		ImplSalDeInitGraphics( mpGraphics );
1808cdf0e10cSrcweir 		delete mpGraphics;
1809cdf0e10cSrcweir 		mpGraphics = NULL;
1810cdf0e10cSrcweir 	}
1811cdf0e10cSrcweir 
1812cdf0e10cSrcweir 	// destroy presentation space and device context
1813cdf0e10cSrcweir 	Ft2Associate( mhPS, NULL );
1814cdf0e10cSrcweir 	Ft2DestroyPS( mhPS );
1815cdf0e10cSrcweir 	DevCloseDC( mhDC );
1816cdf0e10cSrcweir 	return TRUE;
1817cdf0e10cSrcweir }
1818cdf0e10cSrcweir 
1819cdf0e10cSrcweir // -----------------------------------------------------------------------
1820cdf0e10cSrcweir 
1821fc9fd3f1SPedro Giffuni SalGraphics* Os2SalPrinter::StartPage( ImplJobSetup* pSetupData, sal_Bool bNewJobSetup )
1822cdf0e10cSrcweir {
1823cdf0e10cSrcweir 	APIRET rc;
1824cdf0e10cSrcweir 
1825*651793b0SYuri Dario #if OSL_DEBUG_LEVEL>0
1826*651793b0SYuri Dario 	debug_printf( "Os2SalPrinter::StartPage mhDC %x, mbFirstPage %d, bNewJobSetup %d",
1827*651793b0SYuri Dario 				  mhDC, mbFirstPage, bNewJobSetup);
1828*651793b0SYuri Dario 	debug_printf( "Os2SalPrinter::StartPage pSetupData %x",
1829*651793b0SYuri Dario 				  pSetupData);
1830*651793b0SYuri Dario #endif
1831*651793b0SYuri Dario 
1832cdf0e10cSrcweir 	if ( mbFirstPage )
1833cdf0e10cSrcweir 		mbFirstPage = FALSE;
1834cdf0e10cSrcweir 	else
1835cdf0e10cSrcweir 	{
1836cdf0e10cSrcweir 		PBYTE	pJobData;
1837cdf0e10cSrcweir 		LONG	nJobDataSize;
1838cdf0e10cSrcweir 		LONG	nEscape;
1839cdf0e10cSrcweir 		if ( mbPrintDJPSupported && bNewJobSetup )
1840cdf0e10cSrcweir 		{
1841cdf0e10cSrcweir 			nEscape 		= DEVESC_NEWFRAME_WPROP;
1842cdf0e10cSrcweir 			nJobDataSize	= ((PDRIVDATA)(pSetupData->mpDriverData))->cb;
1843cdf0e10cSrcweir 			pJobData		= (PBYTE)(pSetupData->mpDriverData);
1844cdf0e10cSrcweir 		}
1845cdf0e10cSrcweir 		else
1846cdf0e10cSrcweir 		{
1847cdf0e10cSrcweir 			nEscape 		= DEVESC_NEWFRAME;
1848cdf0e10cSrcweir 			nJobDataSize	= 0;
1849cdf0e10cSrcweir 			pJobData		= NULL;
1850cdf0e10cSrcweir 		}
1851cdf0e10cSrcweir 		rc = DevEscape( mhDC,
1852cdf0e10cSrcweir 						nEscape,
1853cdf0e10cSrcweir 						0, NULL,
1854cdf0e10cSrcweir 						&nJobDataSize, pJobData );
1855cdf0e10cSrcweir 
1856cdf0e10cSrcweir 		if ( rc != DEV_OK )
1857cdf0e10cSrcweir 		{
1858cdf0e10cSrcweir 			DevEscape( mhDC, DEVESC_ENDDOC, 0, NULL, 0, NULL);
1859cdf0e10cSrcweir 			Ft2Associate( mhPS, NULL );
1860cdf0e10cSrcweir 			Ft2DestroyPS( mhPS );
1861cdf0e10cSrcweir 			DevCloseDC( mhDC );
1862cdf0e10cSrcweir 			mnError = SAL_PRINTER_ERROR_GENERALERROR;
1863cdf0e10cSrcweir 			return NULL;
1864cdf0e10cSrcweir 		}
1865cdf0e10cSrcweir 	}
1866cdf0e10cSrcweir 
1867cdf0e10cSrcweir 	// create SalGraphics with copy of hPS
1868cdf0e10cSrcweir 	Os2SalGraphics* pGraphics = new Os2SalGraphics;
1869cdf0e10cSrcweir 	pGraphics->mhDC				= mhDC;
1870cdf0e10cSrcweir 	pGraphics->mhPS				= mhPS;
1871cdf0e10cSrcweir 	pGraphics->mhWnd 			= 0;
1872cdf0e10cSrcweir 	pGraphics->mbPrinter 		= TRUE;
1873cdf0e10cSrcweir 	pGraphics->mbVirDev			= FALSE;
1874cdf0e10cSrcweir 	pGraphics->mbWindow			= FALSE;
1875cdf0e10cSrcweir 	pGraphics->mbScreen			= FALSE;
1876cdf0e10cSrcweir 	pGraphics->mnHeight			= 0;
1877cdf0e10cSrcweir 	// search current form for actual page height
1878cdf0e10cSrcweir 	HCINFO	aInfo;
1879cdf0e10cSrcweir 	int 	nForms = DevQueryHardcopyCaps( mhDC, 0, 0, &aInfo );
1880cdf0e10cSrcweir 	for( int i = 0; i < nForms; i++ )
1881cdf0e10cSrcweir 	{
1882cdf0e10cSrcweir 		if ( DevQueryHardcopyCaps( mhDC, i, 1, &aInfo ) >= 0 )
1883cdf0e10cSrcweir 		{
1884cdf0e10cSrcweir 			if ( aInfo.flAttributes & HCAPS_CURRENT )
1885cdf0e10cSrcweir 				pGraphics->mnHeight	= aInfo.yPels;
1886cdf0e10cSrcweir 		}
1887cdf0e10cSrcweir 	}
1888cdf0e10cSrcweir 	// use device caps if no form selected/found
1889cdf0e10cSrcweir 	if ( !pGraphics->mnHeight )
1890cdf0e10cSrcweir 		DevQueryCaps( mhDC, CAPS_HEIGHT, 1L, &pGraphics->mnHeight );
1891cdf0e10cSrcweir 
1892cdf0e10cSrcweir 	ImplSalInitGraphics( pGraphics );
1893cdf0e10cSrcweir 	mpGraphics = pGraphics;
1894cdf0e10cSrcweir 
1895cdf0e10cSrcweir 	return pGraphics;
1896cdf0e10cSrcweir }
1897cdf0e10cSrcweir 
1898cdf0e10cSrcweir // -----------------------------------------------------------------------
1899cdf0e10cSrcweir 
1900fc9fd3f1SPedro Giffuni sal_Bool Os2SalPrinter::EndPage()
1901cdf0e10cSrcweir {
1902*651793b0SYuri Dario #if OSL_DEBUG_LEVEL>0
1903*651793b0SYuri Dario 	debug_printf( "Os2SalPrinter::EndPage mhDC %x", mhDC);
1904*651793b0SYuri Dario #endif
1905*651793b0SYuri Dario 
1906cdf0e10cSrcweir 	if ( mpGraphics )
1907cdf0e10cSrcweir 	{
1908cdf0e10cSrcweir 		// destroy SalGraphics
1909cdf0e10cSrcweir 		ImplSalDeInitGraphics( mpGraphics );
1910cdf0e10cSrcweir 		delete mpGraphics;
1911cdf0e10cSrcweir 		mpGraphics = NULL;
1912cdf0e10cSrcweir 	}
1913cdf0e10cSrcweir 
1914cdf0e10cSrcweir 	return TRUE;
1915cdf0e10cSrcweir }
1916cdf0e10cSrcweir 
1917cdf0e10cSrcweir // -----------------------------------------------------------------------
1918cdf0e10cSrcweir 
1919cdf0e10cSrcweir ULONG Os2SalPrinter::GetErrorCode()
1920cdf0e10cSrcweir {
1921cdf0e10cSrcweir 	return mnError;
1922cdf0e10cSrcweir }
1923