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