merge the formfield patch from ooo-build
[ooovba.git] / vcl / os2 / source / gdi / salprn.cxx
blobbc333931ac9ac795f1438e57464a47df00c25cbf
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: salprn.cxx,v $
10 * $Revision: 1.6 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // use this define to disable the DJP support
32 // #define NO_DJP
34 #define INCL_DOSMODULEMGR
35 #define INCL_DEV
36 #define INCL_SPL
37 #define INCL_SPLERRORS
38 #define INCL_SPLDOSPRINT
39 #define INCL_DEVDJP
41 #define INCL_GPI
42 #define INCL_DOSSEMAPHORES
43 #define INCL_PM
44 #include <svpm.h>
45 #include <pmdjp.h>
47 #include <string.h>
49 #define _SV_SALPRN_CXX
50 #include <tools/debug.hxx>
51 #include <saldata.hxx>
52 #include <salinst.h>
53 #include <salgdi.h>
54 #include <salframe.h>
55 #include <vcl/salptype.hxx>
56 #include <salprn.h>
57 #include <vcl/print.h>
58 #include <vcl/jobset.h>
60 #ifndef __H_FT2LIB
61 #include <wingdi.h>
62 #include <ft2lib.h>
63 #endif
65 // =======================================================================
67 // -----------------------
68 // - struct ImplFormInfo -
69 // -----------------------
71 struct ImplFormInfo
73 long mnPaperWidth;
74 long mnPaperHeight;
75 #ifndef NO_DJP
76 DJPT_PAPERSIZE mnId;
77 #endif
80 // =======================================================================
82 // -----------------------
83 // - struct ImplTrayInfo -
84 // -----------------------
86 struct ImplTrayInfo
88 CHAR maName[32];
89 CHAR maDisplayName[64];
90 DJPT_TRAYTYPE mnId;
92 ImplTrayInfo( const char* pTrayName,
93 const char* pTrayDisplayName )
95 strcpy( maName, pTrayName);
96 strcpy( maDisplayName, pTrayDisplayName);
100 // =======================================================================
102 struct ImplQueueSalSysData
104 ByteString maPrinterName; // pszPrinters
105 ByteString maName; // pszName bzw. LogAddress
106 ByteString maOrgDriverName; // pszDriverName (maDriverName.maDeviceName)
107 ByteString maDriverName; // pszDriverName bis .
108 ByteString maDeviceName; // pszDriverName nach .
109 PDRIVDATA mpDrivData;
111 ImplQueueSalSysData( const ByteString& rPrinterName,
112 const ByteString& rName,
113 const ByteString& rDriverName,
114 const ByteString& rDeviceName,
115 const ByteString& rOrgDriverName,
116 PDRIVDATA pDrivData );
117 ~ImplQueueSalSysData();
120 // -----------------------------------------------------------------------
122 ImplQueueSalSysData::ImplQueueSalSysData( const ByteString& rPrinterName,
123 const ByteString& rName,
124 const ByteString& rOrgDriverName,
125 const ByteString& rDriverName,
126 const ByteString& rDeviceName,
127 PDRIVDATA pDrivData ) :
128 maPrinterName( rPrinterName ),
129 maName( rName ),
130 maOrgDriverName( rName ),
131 maDriverName( rDriverName ),
132 maDeviceName( rDeviceName )
134 if ( pDrivData )
136 mpDrivData = (PDRIVDATA)new BYTE[pDrivData->cb];
137 memcpy( mpDrivData, pDrivData, pDrivData->cb );
139 else
140 mpDrivData = NULL;
143 // -----------------------------------------------------------------------
145 ImplQueueSalSysData::~ImplQueueSalSysData()
147 delete mpDrivData;
150 // =======================================================================
152 static ULONG ImplPMQueueStatusToSal( USHORT nPMStatus )
154 ULONG nStatus = 0;
155 if ( nPMStatus & PRQ3_PAUSED )
156 nStatus |= QUEUE_STATUS_PAUSED;
157 if ( nPMStatus & PRQ3_PENDING )
158 nStatus |= QUEUE_STATUS_PENDING_DELETION;
159 if ( !nStatus )
160 nStatus |= QUEUE_STATUS_READY;
161 return nStatus;
164 // -----------------------------------------------------------------------
166 void Os2SalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList )
168 APIRET rc;
169 ULONG nNeeded;
170 ULONG nReturned;
171 ULONG nTotal;
173 // query needed size of the buffer for the QueueInfo
174 rc = SplEnumQueue( (PSZ)NULL, 3, NULL, 0, &nReturned, &nTotal, &nNeeded, NULL );
175 if( nNeeded == 0 )
176 return;
178 // create the buffer for the QueueInfo
179 PCHAR pQueueData = new CHAR[nNeeded];
181 // query QueueInfos
182 rc = SplEnumQueue( (PSZ)NULL, 3, pQueueData, nNeeded, &nReturned, &nTotal, &nNeeded, NULL );
184 PPRQINFO3 pPrqInfo = (PPRQINFO3)pQueueData;
185 for ( int i = 0; i < nReturned; i++ )
187 // create entry for the QueueInfo array
188 SalPrinterQueueInfo* pInfo = new SalPrinterQueueInfo;
190 ByteString aOrgDriverName( pPrqInfo->pszDriverName);
191 ByteString aName( pPrqInfo->pszName);
192 pInfo->maDriver = ::rtl::OStringToOUString (aOrgDriverName, gsl_getSystemTextEncoding());
193 pInfo->maPrinterName = ::rtl::OStringToOUString (pPrqInfo->pszComment, gsl_getSystemTextEncoding());
194 pInfo->maLocation = ::rtl::OStringToOUString (aName, gsl_getSystemTextEncoding());
195 pInfo->mnStatus = ImplPMQueueStatusToSal( pPrqInfo->fsStatus );
196 pInfo->mnJobs = pPrqInfo->cJobs;
197 // pInfo->maComment = !!!
199 // Feststellen, ob Name doppelt
200 PPRQINFO3 pTempPrqInfo = (PPRQINFO3)pQueueData;
201 for ( int j = 0; j < nReturned; j++ )
203 // Wenn Name doppelt, erweitern wir diesen um die Location
204 if ( (j != i) &&
205 (strcmp( pPrqInfo->pszComment, pTempPrqInfo->pszComment ) == 0) )
207 pInfo->maPrinterName += ';';
208 pInfo->maPrinterName += pInfo->maLocation;
210 pTempPrqInfo++;
213 // pszDriver in DriverName (bis .) und DeviceName (nach .) aufsplitten
214 PSZ pDriverName;
215 PSZ pDeviceName;
216 if ( (pDriverName = strchr( pPrqInfo->pszDriverName, '.' )) != 0 )
218 *pDriverName = 0;
219 pDeviceName = pDriverName + 1;
221 else
222 pDeviceName = NULL;
224 // Alle Bytes hinter dem DeviceNamen auf 0 initialisieren, damit
225 // ein memcmp vom JobSetup auch funktioniert
226 if ( pPrqInfo->pDriverData &&
227 (pPrqInfo->pDriverData->cb >= sizeof( pPrqInfo->pDriverData )) )
229 int nDeviceNameLen = strlen( pPrqInfo->pDriverData->szDeviceName );
230 memset( pPrqInfo->pDriverData->szDeviceName+nDeviceNameLen,
232 sizeof( pPrqInfo->pDriverData->szDeviceName )-nDeviceNameLen );
235 // save driver data and driver names
236 ByteString aPrinterName( pPrqInfo->pszPrinters);
237 ByteString aDriverName( pPrqInfo->pszDriverName);
238 ByteString aDeviceName;
239 if ( pDeviceName )
240 aDeviceName = pDeviceName;
241 pInfo->mpSysData = new ImplQueueSalSysData( aPrinterName, aName,
242 aOrgDriverName,
243 aDriverName, aDeviceName,
244 pPrqInfo->pDriverData );
246 // add queue to the list
247 pList->Add( pInfo );
249 // increment to next element of the QueueInfo array
250 pPrqInfo++;
253 delete [] pQueueData;
256 // -----------------------------------------------------------------------
258 void Os2SalInstance::GetPrinterQueueState( SalPrinterQueueInfo* pInfo )
260 APIRET rc;
261 ULONG nNeeded;
262 ULONG nReturned;
263 ULONG nTotal;
265 // query needed size of the buffer for the QueueInfo
266 rc = SplEnumQueue( (PSZ)NULL, 3, NULL, 0, &nReturned, &nTotal, &nNeeded, NULL );
267 if( nNeeded == 0 )
268 return;
270 // create the buffer for the QueueInfo
271 PCHAR pQueueData = new CHAR[nNeeded];
273 // query QueueInfos
274 rc = SplEnumQueue( (PSZ)NULL, 3, pQueueData, nNeeded, &nReturned, &nTotal, &nNeeded, NULL );
276 PPRQINFO3 pPrqInfo = (PPRQINFO3)pQueueData;
277 for ( int i = 0; i < nReturned; i++ )
279 ImplQueueSalSysData* pSysData = (ImplQueueSalSysData*)(pInfo->mpSysData);
280 if ( pSysData->maPrinterName.Equals( pPrqInfo->pszPrinters ) &&
281 pSysData->maName.Equals( pPrqInfo->pszName ) &&
282 pSysData->maOrgDriverName.Equals( pPrqInfo->pszDriverName ) )
284 pInfo->mnStatus = ImplPMQueueStatusToSal( pPrqInfo->fsStatus );
285 pInfo->mnJobs = pPrqInfo->cJobs;
286 break;
289 // increment to next element of the QueueInfo array
290 pPrqInfo++;
293 delete [] pQueueData;
296 // -----------------------------------------------------------------------
298 void Os2SalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo )
300 delete ((ImplQueueSalSysData*)(pInfo->mpSysData));
301 delete pInfo;
304 // -----------------------------------------------------------------------
306 XubString Os2SalInstance::GetDefaultPrinter()
308 APIRET rc;
309 ULONG nNeeded;
310 ULONG nReturned;
311 ULONG nTotal;
312 char szQueueName[255];
313 XubString aDefaultName;
315 // query default queue
316 if ( !PrfQueryProfileString( HINI_PROFILE, SPL_INI_SPOOLER, "QUEUE", 0, szQueueName, sizeof( szQueueName ) ) )
317 return aDefaultName;
319 // extract first queue name
320 PSZ pStr;
321 if ( (pStr = strchr( szQueueName, ';' )) != 0 )
322 *pStr = 0;
324 // query needed size of the buffer for the QueueInfo
325 rc = SplEnumQueue( (PSZ)NULL, 3, NULL, 0, &nReturned, &nTotal, &nNeeded, NULL );
326 if ( nNeeded == 0 )
327 return aDefaultName;
329 // create the buffer for the QueueInfo
330 PCHAR pQueueData = new CHAR[ nNeeded ];
332 // query QueueInfos
333 rc = SplEnumQueue ((PSZ)NULL, 3, pQueueData, nNeeded, &nReturned, &nTotal, &nNeeded, NULL );
335 // find printer name for default queue
336 PPRQINFO3 pPrqInfo = (PPRQINFO3) pQueueData;
337 for ( int i = 0; i < nReturned; i++ )
339 if ( strcmp( pPrqInfo->pszName, szQueueName ) == 0 )
341 aDefaultName = ::rtl::OStringToOUString (pPrqInfo->pszComment, gsl_getSystemTextEncoding());
343 // Feststellen, ob Name doppelt
344 PPRQINFO3 pTempPrqInfo = (PPRQINFO3)pQueueData;
345 for ( int j = 0; j < nReturned; j++ )
347 // Wenn Name doppelt, erweitern wir diesen um die Location
348 if ( (j != i) &&
349 (strcmp( pPrqInfo->pszComment, pTempPrqInfo->pszComment ) == 0) )
351 String pszName( ::rtl::OStringToOUString (pPrqInfo->pszName, gsl_getSystemTextEncoding()));
352 aDefaultName += ';';
353 aDefaultName += pszName;
355 pTempPrqInfo++;
357 break;
360 // increment to next element of the QueueInfo array
361 pPrqInfo++;
364 delete [] pQueueData;
366 return aDefaultName;
369 // =======================================================================
371 static void* ImplAllocPrnMemory( size_t n )
373 return calloc( n, 1);
376 // -----------------------------------------------------------------------
378 inline void ImplFreePrnMemory( void* p )
380 free( p );
383 // -----------------------------------------------------------------------
385 static PDRIVDATA ImplPrnDrivData( const ImplJobSetup* pSetupData )
387 // Diese Funktion wird eingesetzt, damit Druckertreiber nicht auf
388 // unseren Daten arbeiten, da es durch Konfigurationsprobleme
389 // sein kann, das der Druckertreiber bei uns Daten ueberschreibt.
390 // Durch diese vorgehensweise werden einige Abstuerze vermieden, bzw.
391 // sind dadurch leichter zu finden
393 if ( !pSetupData->mpDriverData )
394 return NULL;
396 DBG_ASSERT( ((PDRIVDATA)(pSetupData->mpDriverData))->cb == pSetupData->mnDriverDataLen,
397 "ImplPrnDrivData() - SetupDataLen != DriverDataLen" );
399 PDRIVDATA pDrivData = (PDRIVDATA)ImplAllocPrnMemory( pSetupData->mnDriverDataLen );
400 memcpy( pDrivData, pSetupData->mpDriverData, pSetupData->mnDriverDataLen );
401 return pDrivData;
404 // -----------------------------------------------------------------------
406 static void ImplUpdateSetupData( const PDRIVDATA pDrivData, ImplJobSetup* pSetupData )
408 // Diese Funktion wird eingesetzt, damit Druckertreiber nicht auf
409 // unseren Daten arbeiten, da es durch Konfigurationsprobleme
410 // sein kann, das der Druckertreiber bei uns Daten ueberschreibt.
411 // Durch diese vorgehensweise werden einige Abstuerze vermieden, bzw.
412 // sind dadurch leichter zu finden
414 if ( !pDrivData || !pDrivData->cb )
416 if ( pSetupData->mpDriverData )
417 rtl_freeMemory( pSetupData->mpDriverData );
418 pSetupData->mpDriverData = NULL;
419 pSetupData->mnDriverDataLen = 0;
421 else
423 // Alle Bytes hinter dem DeviceNamen auf 0 initialisieren, damit
424 // ein memcmp vom JobSetup auch funktioniert
425 if ( pDrivData->cb >= sizeof( pDrivData ) )
427 int nDeviceNameLen = strlen( pDrivData->szDeviceName );
428 memset( pDrivData->szDeviceName+nDeviceNameLen,
430 sizeof( pDrivData->szDeviceName )-nDeviceNameLen );
433 if ( pSetupData->mpDriverData )
435 if ( pSetupData->mnDriverDataLen != pDrivData->cb )
436 rtl_freeMemory( pSetupData->mpDriverData );
437 pSetupData->mpDriverData = (BYTE*)rtl_allocateMemory( pDrivData->cb);
439 else
440 pSetupData->mpDriverData = (BYTE*)rtl_allocateMemory( pDrivData->cb);
441 pSetupData->mnDriverDataLen = pDrivData->cb;
442 memcpy( pSetupData->mpDriverData, pDrivData, pDrivData->cb );
445 if ( pDrivData )
446 ImplFreePrnMemory( pDrivData );
449 // -----------------------------------------------------------------------
451 static BOOL ImplPaperSizeEqual( long nPaperWidth1, long nPaperHeight1,
452 long nPaperWidth2, long nPaperHeight2 )
454 return (((nPaperWidth1 >= nPaperWidth2-1) && (nPaperWidth1 <= nPaperWidth2+1)) &&
455 ((nPaperHeight1 >= nPaperHeight2-1) && (nPaperHeight1 <= nPaperHeight2+1)));
458 // -----------------------------------------------------------------------
460 static BOOL ImplIsDriverDJPEnabled( HDC hDC )
462 #ifdef NO_DJP
463 return FALSE;
464 #else
465 // Ueber OS2-Ini kann DJP disablte werden
466 if ( !PrfQueryProfileInt( HINI_PROFILE, SAL_PROFILE_APPNAME, SAL_PROFILE_USEDJP, 1 ) )
467 return FALSE;
469 // Testen, ob DJP-Interface am Drucker vorhanden
470 LONG lQuery;
471 APIRET rc;
473 lQuery = DEVESC_QUERYSIZE;
474 rc = DevEscape( hDC,
475 DEVESC_QUERYESCSUPPORT,
476 sizeof( lQuery ),
477 (PBYTE)&lQuery,
479 (PBYTE)NULL );
480 if ( DEV_OK != rc )
481 return FALSE;
483 lQuery = DEVESC_QUERYJOBPROPERTIES;
484 rc = DevEscape( hDC,
485 DEVESC_QUERYESCSUPPORT,
486 sizeof( lQuery ),
487 (PBYTE)&lQuery,
489 (PBYTE)NULL );
490 if ( DEV_OK != rc )
491 return FALSE;
493 lQuery = DEVESC_SETJOBPROPERTIES;
494 rc = DevEscape( hDC,
495 DEVESC_QUERYESCSUPPORT,
496 sizeof( lQuery ),
497 (PBYTE)&lQuery,
499 (PBYTE)NULL );
500 if ( DEV_OK != rc )
501 return FALSE;
503 return TRUE;
504 #endif
507 // -----------------------------------------------------------------------
509 static void ImplFormatInputList( PDJP_ITEM pDJP, PQUERYTUPLE pTuple )
511 // Loop through the query elements
512 BOOL fContinue = TRUE;
515 pDJP->cb = sizeof (DJP_ITEM);
516 pDJP->ulProperty = pTuple->ulProperty;
517 pDJP->lType = pTuple->lType;
518 pDJP->ulNumReturned = 0;
519 pDJP->ulValue = DJP_NONE;
521 // at EOL?
522 fContinue = DJP_NONE != pTuple->ulProperty;
524 // Move to next item structure and tuplet
525 pDJP++;
526 pTuple++;
528 while ( fContinue );
531 // -----------------------------------------------------------------------
533 static void ImplFreeFormAndTrayList( Os2SalInfoPrinter* pOs2SalInfoPrinter )
535 if ( pOs2SalInfoPrinter->mnFormCount )
537 for ( USHORT i = 0; i < pOs2SalInfoPrinter->mnFormCount; i++ )
538 delete pOs2SalInfoPrinter->mpFormArray[i];
539 delete [] pOs2SalInfoPrinter->mpFormArray;
540 pOs2SalInfoPrinter->mnFormCount = 0;
543 if ( pOs2SalInfoPrinter->mnTrayCount )
545 for ( USHORT i = 0; i < pOs2SalInfoPrinter->mnTrayCount; i++ )
546 delete pOs2SalInfoPrinter->mpTrayArray[i];
547 delete [] pOs2SalInfoPrinter->mpTrayArray;
548 pOs2SalInfoPrinter->mnTrayCount = 0;
552 // -----------------------------------------------------------------------
554 static void ImplGetFormAndTrayList( Os2SalInfoPrinter* pOs2SalInfoPrinter, const ImplJobSetup* pSetupData )
556 ImplFreeFormAndTrayList( pOs2SalInfoPrinter );
558 LONG alQuery[] =
560 0, 0, // First two members of QUERYSIZE
561 DJP_CJ_FORM, DJP_ALL,
562 DJP_CJ_TRAYNAME, DJP_ALL,
563 DJP_NONE, DJP_NONE // EOL marker
566 APIRET rc;
567 PQUERYSIZE pQuerySize = (PQUERYSIZE)alQuery;
568 PBYTE pBuffer = NULL;
569 LONG nAlloc = 0;
570 PDRIVDATA pCopyDrivData = ImplPrnDrivData( pSetupData );
571 LONG nDrivDataSize = pCopyDrivData->cb;
572 PBYTE pDrivData = (PBYTE)pCopyDrivData;
574 // find out how many bytes to allocate
575 pQuerySize->cb = sizeof( alQuery );
576 rc = DevEscape( pOs2SalInfoPrinter->mhDC,
577 DEVESC_QUERYSIZE,
578 sizeof( alQuery ),
579 (PBYTE)pQuerySize,
580 &nDrivDataSize,
581 pDrivData );
582 if ( DEV_OK != rc )
584 ImplFreePrnMemory( pCopyDrivData );
585 return;
588 // allocate the memory
589 nAlloc = pQuerySize->ulSizeNeeded;
590 pBuffer = (PBYTE)new BYTE[nAlloc];
592 // set up the input
593 PDJP_ITEM pDJP = (PDJP_ITEM)pBuffer;
594 ImplFormatInputList( pDJP, pQuerySize->aTuples );
596 // do it!
597 rc = DevEscape( pOs2SalInfoPrinter->mhDC,
598 DEVESC_QUERYJOBPROPERTIES,
599 nAlloc,
600 pBuffer,
601 &nDrivDataSize,
602 pDrivData );
603 ImplFreePrnMemory( pCopyDrivData );
605 if ( (DEV_OK == rc) || (DEV_WARNING == rc) )
607 // Loop through the query elements
608 PQUERYTUPLE pTuple = pQuerySize->aTuples;
609 while ( DJP_NONE != pTuple->ulProperty )
611 if ( pDJP->ulProperty == DJP_CJ_FORM )
613 if ( pDJP->ulNumReturned )
615 PDJPT_FORM pElm = DJP_ELEMENTP( *pDJP, DJPT_FORM );
617 pOs2SalInfoPrinter->mnFormCount = pDJP->ulNumReturned;
618 pOs2SalInfoPrinter->mpFormArray = new PIMPLFORMINFO[pOs2SalInfoPrinter->mnFormCount];
619 for( int i = 0; i < pDJP->ulNumReturned; i++, pElm++ )
621 ImplFormInfo* pInfo = new ImplFormInfo;
622 pInfo->mnPaperWidth = pElm->hcInfo.cx;
623 pInfo->mnPaperHeight = pElm->hcInfo.cy;
624 pInfo->mnId = pElm->djppsFormID;
625 pOs2SalInfoPrinter->mpFormArray[i] = pInfo;
629 else if ( pDJP->ulProperty == DJP_CJ_TRAYNAME )
631 if ( pDJP->ulNumReturned )
633 PDJPT_TRAYNAME pElm = DJP_ELEMENTP( *pDJP, DJPT_TRAYNAME );
635 pOs2SalInfoPrinter->mnTrayCount = pDJP->ulNumReturned;
636 pOs2SalInfoPrinter->mpTrayArray = new PIMPLTRAYINFO[pOs2SalInfoPrinter->mnTrayCount];
637 for( int i = 0; i < pDJP->ulNumReturned; i++, pElm++ )
639 ImplTrayInfo* pInfo = new ImplTrayInfo( pElm->szTrayname, pElm->szDisplayTrayname );
640 pInfo->mnId = pElm->djpttTrayID;
641 pOs2SalInfoPrinter->mpTrayArray[i] = pInfo;
646 pDJP = DJP_NEXT_STRUCTP( pDJP );
647 pTuple++;
651 delete [] pBuffer;
654 // -----------------------------------------------------------------------
656 static BOOL ImplGetCurrentSettings( Os2SalInfoPrinter* pOs2SalInfoPrinter, ImplJobSetup* pSetupData )
658 // Um den aktuellen Tray zu ermitteln, brauchen wir auch die Listen dazu
659 if ( !pOs2SalInfoPrinter->mnFormCount )
660 ImplGetFormAndTrayList( pOs2SalInfoPrinter, pSetupData );
662 LONG alQuery[] =
664 0, 0, // First two members of QUERYSIZE
665 DJP_SJ_ORIENTATION, DJP_CURRENT,
666 DJP_CJ_FORM, DJP_CURRENT,
667 DJP_NONE, DJP_NONE // EOL marker
670 APIRET rc;
671 PQUERYSIZE pQuerySize = (PQUERYSIZE)alQuery;
672 PBYTE pBuffer = NULL;
673 LONG nAlloc = 0;
674 PDRIVDATA pCopyDrivData = ImplPrnDrivData( pSetupData );
675 LONG nDrivDataSize = pCopyDrivData->cb;
676 PBYTE pDrivData = (PBYTE)pCopyDrivData;
677 BOOL bResult;
679 // find out how many bytes to allocate
680 pQuerySize->cb = sizeof( alQuery );
681 rc = DevEscape( pOs2SalInfoPrinter->mhDC,
682 DEVESC_QUERYSIZE,
683 sizeof( alQuery ),
684 (PBYTE)pQuerySize,
685 &nDrivDataSize,
686 pDrivData );
687 if ( DEV_OK != rc )
689 ImplFreePrnMemory( pCopyDrivData );
690 return FALSE;
693 // allocate the memory
694 nAlloc = pQuerySize->ulSizeNeeded;
695 pBuffer = (PBYTE)new BYTE[nAlloc];
697 // set up the input
698 PDJP_ITEM pDJP = (PDJP_ITEM)pBuffer;
699 ImplFormatInputList( pDJP, pQuerySize->aTuples );
701 rc = DevEscape( pOs2SalInfoPrinter->mhDC,
702 DEVESC_QUERYJOBPROPERTIES,
703 nAlloc,
704 pBuffer,
705 &nDrivDataSize,
706 pDrivData );
707 if ( (DEV_OK == rc) || (DEV_WARNING == rc) )
709 // aktuelle Setup-Daten uebernehmen
710 ImplUpdateSetupData( pCopyDrivData, pSetupData );
712 // Loop through the query elements
713 PQUERYTUPLE pTuple = pQuerySize->aTuples;
714 while ( DJP_NONE != pTuple->ulProperty )
716 if ( pDJP->ulProperty == DJP_SJ_ORIENTATION )
718 if ( pDJP->ulNumReturned )
720 PDJPT_ORIENTATION pElm = DJP_ELEMENTP( *pDJP, DJPT_ORIENTATION );
721 if ( (DJP_ORI_PORTRAIT == *pElm) || (DJP_ORI_REV_PORTRAIT == *pElm) )
722 pSetupData->meOrientation = ORIENTATION_PORTRAIT;
723 else
724 pSetupData->meOrientation = ORIENTATION_LANDSCAPE;
727 else if ( pDJP->ulProperty == DJP_CJ_FORM )
729 if ( pDJP->ulNumReturned )
731 PDJPT_FORM pElm = DJP_ELEMENTP( *pDJP, DJPT_FORM );
733 pSetupData->mnPaperWidth = pElm->hcInfo.cx*100;
734 pSetupData->mnPaperHeight = pElm->hcInfo.cy*100;
735 switch( pElm->djppsFormID )
737 case DJP_PSI_A3:
738 pSetupData->mePaperFormat = PAPER_A3;
739 break;
741 case DJP_PSI_A4:
742 pSetupData->mePaperFormat = PAPER_A4;
743 break;
745 case DJP_PSI_A5:
746 pSetupData->mePaperFormat = PAPER_A5;
747 break;
749 case DJP_PSI_B4:
750 pSetupData->mePaperFormat = PAPER_B4;
751 break;
753 case DJP_PSI_B5:
754 pSetupData->mePaperFormat = PAPER_B5;
755 break;
757 case DJP_PSI_LETTER:
758 pSetupData->mePaperFormat = PAPER_LETTER;
759 break;
761 case DJP_PSI_LEGAL:
762 pSetupData->mePaperFormat = PAPER_LEGAL;
763 break;
765 case DJP_PSI_TABLOID:
766 pSetupData->mePaperFormat = PAPER_TABLOID;
767 break;
769 default:
770 pSetupData->mePaperFormat = PAPER_USER;
771 break;
774 // Wir suchen zuerst ueber den Namen/Id und dann ueber die Id
775 BOOL bTrayFound = FALSE;
776 USHORT j;
777 for ( j = 0; j < pOs2SalInfoPrinter->mnTrayCount; j++ )
779 if ( (pOs2SalInfoPrinter->mpTrayArray[j]->mnId == pElm->djpttTrayID) &&
780 (pOs2SalInfoPrinter->mpTrayArray[j]->maName == pElm->szTrayname) )
782 pSetupData->mnPaperBin = j;
783 bTrayFound = TRUE;
784 break;
787 if ( !bTrayFound )
789 for ( j = 0; j < pOs2SalInfoPrinter->mnTrayCount; j++ )
791 if ( pOs2SalInfoPrinter->mpTrayArray[j]->mnId == pElm->djpttTrayID )
793 pSetupData->mnPaperBin = j;
794 bTrayFound = TRUE;
795 break;
799 // Wenn wir Ihn immer noch nicht gefunden haben, setzen
800 // wir ihn auf DontKnow
801 if ( !bTrayFound )
802 pSetupData->mnPaperBin = 0xFFFF;
806 pDJP = DJP_NEXT_STRUCTP( pDJP );
807 pTuple++;
810 bResult = TRUE;
812 else
814 ImplFreePrnMemory( pCopyDrivData );
815 bResult = FALSE;
818 delete [] pBuffer;
820 return bResult;
823 // -----------------------------------------------------------------------
825 static BOOL ImplSetOrientation( HDC hPrinterDC, PDRIVDATA pDriverData,
826 Orientation eOrientation )
828 LONG alQuery[] =
830 0, 0, // First two members of QUERYSIZE
831 DJP_SJ_ORIENTATION, DJP_CURRENT,
832 DJP_NONE, DJP_NONE // EOL marker
835 APIRET rc;
836 PQUERYSIZE pQuerySize = (PQUERYSIZE)alQuery;
837 PBYTE pBuffer = NULL;
838 LONG nAlloc = 0;
839 LONG nDrivDataSize = pDriverData->cb;
841 // find out how many bytes to allocate
842 pQuerySize->cb = sizeof( alQuery );
843 rc = DevEscape( hPrinterDC,
844 DEVESC_QUERYSIZE,
845 sizeof( alQuery ),
846 (PBYTE)pQuerySize,
847 &nDrivDataSize,
848 (PBYTE)pDriverData );
849 if ( DEV_OK != rc )
850 return FALSE;
852 // allocate the memory
853 nAlloc = pQuerySize->ulSizeNeeded;
854 pBuffer = (PBYTE)new BYTE[nAlloc];
856 // set up the input
857 PDJP_ITEM pDJP = (PDJP_ITEM)pBuffer;
858 ImplFormatInputList( pDJP, pQuerySize->aTuples );
860 pDJP->cb = sizeof( DJP_ITEM );
861 pDJP->ulProperty = DJP_SJ_ORIENTATION;
862 pDJP->lType = DJP_CURRENT;
863 pDJP->ulValue = (eOrientation == ORIENTATION_PORTRAIT)
864 ? DJP_ORI_PORTRAIT
865 : DJP_ORI_LANDSCAPE;
867 // do it!
868 rc = DevEscape( hPrinterDC,
869 DEVESC_SETJOBPROPERTIES,
870 nAlloc,
871 pBuffer,
872 &nDrivDataSize,
873 (PBYTE)pDriverData );
875 delete [] pBuffer;
877 return ((DEV_OK == rc) || (DEV_WARNING == rc));
880 // -----------------------------------------------------------------------
882 static BOOL ImplSetPaperSize( HDC hPrinterDC, PDRIVDATA pDriverData,
883 DJPT_PAPERSIZE nOS2PaperFormat )
885 LONG alQuery[] =
887 0, 0, // First two members of QUERYSIZE
888 DJP_SJ_PAPERSIZE, DJP_CURRENT,
889 DJP_NONE, DJP_NONE // EOL marker
892 APIRET rc;
893 PQUERYSIZE pQuerySize = (PQUERYSIZE)alQuery;
894 PBYTE pBuffer = NULL;
895 LONG nAlloc = 0;
896 LONG nDrivDataSize = pDriverData->cb;
898 // find out how many bytes to allocate
899 pQuerySize->cb = sizeof( alQuery );
900 rc = DevEscape( hPrinterDC,
901 DEVESC_QUERYSIZE,
902 sizeof( alQuery ),
903 (PBYTE)pQuerySize,
904 &nDrivDataSize,
905 (PBYTE)pDriverData );
906 if ( DEV_OK != rc )
907 return FALSE;
909 // allocate the memory
910 nAlloc = pQuerySize->ulSizeNeeded;
911 pBuffer = (PBYTE)new BYTE[nAlloc];
913 // set up the input
914 PDJP_ITEM pDJP = (PDJP_ITEM)pBuffer;
915 PDJP_ITEM pStartDJP = pDJP;
916 ImplFormatInputList( pDJP, pQuerySize->aTuples );
918 // Neue Daten zuweisen
919 pDJP->cb = sizeof( DJP_ITEM );
920 pDJP->ulProperty = DJP_SJ_PAPERSIZE;
921 pDJP->lType = DJP_CURRENT;
922 pDJP->ulValue = nOS2PaperFormat;
924 // und setzen
925 rc = DevEscape( hPrinterDC,
926 DEVESC_SETJOBPROPERTIES,
927 nAlloc,
928 pBuffer,
929 &nDrivDataSize,
930 (PBYTE)pDriverData );
932 delete [] pBuffer;
934 return ((DEV_OK == rc) || (DEV_WARNING == rc));
937 // -----------------------------------------------------------------------
939 static BOOL ImplSetPaperBin( HDC hPrinterDC, PDRIVDATA pDriverData,
940 ImplTrayInfo* pTrayInfo )
942 LONG alQuery[] =
944 0, 0, // First two members of QUERYSIZE
945 DJP_SJ_TRAYTYPE, DJP_CURRENT,
946 DJP_NONE, DJP_NONE // EOL marker
949 APIRET rc;
950 PQUERYSIZE pQuerySize = (PQUERYSIZE)alQuery;
951 PBYTE pBuffer = NULL;
952 LONG nAlloc = 0;
953 LONG nDrivDataSize = pDriverData->cb;
955 // find out how many bytes to allocate
956 pQuerySize->cb = sizeof( alQuery );
957 rc = DevEscape( hPrinterDC,
958 DEVESC_QUERYSIZE,
959 sizeof( alQuery ),
960 (PBYTE)pQuerySize,
961 &nDrivDataSize,
962 (PBYTE)pDriverData );
963 if ( DEV_OK != rc )
964 return FALSE;
966 // allocate the memory
967 nAlloc = pQuerySize->ulSizeNeeded;
968 pBuffer = (PBYTE)new BYTE[nAlloc];
970 // set up the input
971 PDJP_ITEM pDJP = (PDJP_ITEM)pBuffer;
972 ImplFormatInputList( pDJP, pQuerySize->aTuples );
974 // Neue Daten zuweisen
975 pDJP->cb = sizeof( DJP_ITEM );
976 pDJP->ulProperty = DJP_SJ_TRAYTYPE;
977 pDJP->lType = DJP_CURRENT;
978 pDJP->ulValue = pTrayInfo->mnId;
980 // und setzen
981 rc = DevEscape( hPrinterDC,
982 DEVESC_SETJOBPROPERTIES,
983 nAlloc,
984 pBuffer,
985 &nDrivDataSize,
986 (PBYTE)pDriverData );
988 delete [] pBuffer;
990 return ((DEV_OK == rc) || (DEV_WARNING == rc));
993 // =======================================================================
995 static BOOL ImplSalCreateInfoPrn( Os2SalInfoPrinter* pPrinter, PDRIVDATA pDriverData,
996 HDC& rDC, HPS& rPS )
998 SalData* pSalData = GetSalData();
1000 // create info context
1001 DEVOPENSTRUC devOpenStruc;
1002 memset( &devOpenStruc, 0, sizeof( devOpenStruc ) );
1003 devOpenStruc.pszLogAddress = (char*)pPrinter->maName.GetBuffer();
1004 devOpenStruc.pszDriverName = (char*)pPrinter->maDriverName.GetBuffer();
1005 devOpenStruc.pdriv = pDriverData;
1006 devOpenStruc.pszDataType = "PM_Q_STD";
1008 HDC hDC = DevOpenDC( pSalData->mhAB, OD_INFO, "*",
1009 4, (PDEVOPENDATA)&devOpenStruc, (HDC)NULL);
1010 if ( !hDC )
1011 return FALSE;
1013 // create presentation space
1014 SIZEL sizel;
1015 sizel.cx = 0;
1016 sizel.cy = 0;
1017 HPS hPS = Ft2CreatePS( pSalData->mhAB, hDC, &sizel, GPIA_ASSOC | GPIT_MICRO | PU_PELS );
1018 if ( !hPS )
1020 DevCloseDC( hDC );
1021 return FALSE;
1024 rDC = hDC;
1025 rPS = hPS;
1026 return TRUE;
1029 // -----------------------------------------------------------------------
1031 static void ImplSalDestroyInfoPrn( Os2SalInfoPrinter* pPrinter )
1033 ImplSalDeInitGraphics( pPrinter->mpGraphics);
1034 Ft2Associate( pPrinter->mhPS, 0 );
1035 Ft2DestroyPS( pPrinter->mhPS );
1036 DevCloseDC( pPrinter->mhDC );
1039 // =======================================================================
1041 SalInfoPrinter* Os2SalInstance::CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo,
1042 ImplJobSetup* pSetupData )
1044 ImplQueueSalSysData* pSysQueueData = (ImplQueueSalSysData*)(pQueueInfo->mpSysData);
1045 Os2SalInfoPrinter* pPrinter = new Os2SalInfoPrinter;
1046 pPrinter->maPrinterName = pSysQueueData->maPrinterName;
1047 pPrinter->maName = pSysQueueData->maName;
1048 pPrinter->maDriverName = pSysQueueData->maDriverName;
1049 pPrinter->maDeviceName = pSysQueueData->maDeviceName;
1051 // Nur Setup-Daten uebernehmen, wenn Treiber und Laenge der Treiberdaten
1052 // uebereinstimmt
1053 PDRIVDATA pDriverData;
1054 BOOL bUpdateDriverData;
1055 if ( pSetupData->mpDriverData && pSysQueueData->mpDrivData &&
1056 (pSetupData->mnSystem == JOBSETUP_SYSTEM_OS2) &&
1057 (pSetupData->mnDriverDataLen == pSysQueueData->mpDrivData->cb) &&
1058 (strcmp( ((PDRIVDATA)pSetupData->mpDriverData)->szDeviceName,
1059 pSysQueueData->mpDrivData->szDeviceName ) == 0) )
1061 pDriverData = PDRIVDATA( pSetupData->mpDriverData );
1062 bUpdateDriverData = FALSE;
1064 else
1066 pDriverData = pSysQueueData->mpDrivData;
1067 bUpdateDriverData = TRUE;
1069 if ( pDriverData )
1070 pPrinter->maJobSetupDeviceName = pDriverData->szDeviceName;
1072 if ( !ImplSalCreateInfoPrn( pPrinter, pDriverData,
1073 pPrinter->mhDC,
1074 pPrinter->mhPS ) )
1076 delete pPrinter;
1077 return NULL;
1080 // create graphics object for output
1081 Os2SalGraphics* pGraphics = new Os2SalGraphics;
1082 pGraphics->mhDC = pPrinter->mhDC;
1083 pGraphics->mhPS = pPrinter->mhPS;
1084 pGraphics->mhWnd = 0;
1085 pGraphics->mbPrinter = TRUE;
1086 pGraphics->mbVirDev = FALSE;
1087 pGraphics->mbWindow = FALSE;
1088 pGraphics->mbScreen = FALSE;
1090 ImplSalInitGraphics( pGraphics );
1091 pPrinter->mpGraphics = pGraphics;
1093 // check printer driver for DJP support
1094 pPrinter->mbDJPSupported = ImplIsDriverDJPEnabled( pPrinter->mhDC );
1096 if ( bUpdateDriverData )
1098 if ( pSetupData->mpDriverData )
1099 rtl_freeMemory( pSetupData->mpDriverData);
1100 pSetupData->mpDriverData = (BYTE*)rtl_allocateMemory( pDriverData->cb);
1101 memcpy( pSetupData->mpDriverData, pDriverData, pDriverData->cb );
1102 pSetupData->mnDriverDataLen = pDriverData->cb;
1105 // retrieve current settings from printer driver and store them to system independend data!
1106 if ( pPrinter->mbDJPSupported )
1107 ImplGetCurrentSettings( pPrinter, pSetupData );
1108 pSetupData->mnSystem = JOBSETUP_SYSTEM_OS2;
1110 return pPrinter;
1113 // -----------------------------------------------------------------------
1115 void Os2SalInstance::DestroyInfoPrinter( SalInfoPrinter* pPrinter )
1117 delete pPrinter;
1120 // =======================================================================
1122 Os2SalInfoPrinter::Os2SalInfoPrinter()
1124 mhDC = 0;
1125 mhPS = 0;
1126 mpGraphics = NULL;
1127 mbGraphics = FALSE;
1128 mbDJPSupported = FALSE;
1129 mnFormCount = 0;
1130 mpFormArray = NULL;
1131 mnTrayCount = 0;
1132 mpTrayArray = NULL;
1135 // -----------------------------------------------------------------------
1137 Os2SalInfoPrinter::~Os2SalInfoPrinter()
1139 if ( mpGraphics )
1141 ImplSalDestroyInfoPrn( this );
1142 delete mpGraphics;
1145 ImplFreeFormAndTrayList( this );
1148 // -----------------------------------------------------------------------
1150 SalGraphics* Os2SalInfoPrinter::GetGraphics()
1152 if ( mbGraphics )
1153 return NULL;
1155 if ( mpGraphics )
1156 mbGraphics = TRUE;
1158 return mpGraphics;
1161 // -----------------------------------------------------------------------
1163 void Os2SalInfoPrinter::ReleaseGraphics( SalGraphics* )
1165 mbGraphics = FALSE;
1168 // -----------------------------------------------------------------------
1170 BOOL Os2SalInfoPrinter::Setup( SalFrame* pFrame, ImplJobSetup* pSetupData )
1172 PDRIVDATA pDrivData = ImplPrnDrivData( pSetupData );
1173 if ( !pDrivData )
1174 return FALSE;
1176 APIRET rc = DevPostDeviceModes( GetSalData()->mhAB, pDrivData,
1177 maDriverName.GetBuffer(),
1178 maDeviceName.GetBuffer(),
1179 maPrinterName.GetBuffer(),
1180 DPDM_POSTJOBPROP );
1181 if ( rc == DEV_OK )
1183 ImplUpdateSetupData( pDrivData, pSetupData );
1185 // update DC and PS
1186 HDC hDC;
1187 HPS hPS;
1188 if ( !ImplSalCreateInfoPrn( this, (PDRIVDATA)(pSetupData->mpDriverData), hDC, hPS ) )
1189 return FALSE;
1191 // Alten Printer DC/PS zerstoeren
1192 ImplSalDestroyInfoPrn( this );
1194 // Neue Daten setzen und initialisieren
1195 mhDC = hDC;
1196 mhPS = hPS;
1197 mpGraphics->mhDC = mhDC;
1198 mpGraphics->mhPS = mhPS;
1199 ImplSalInitGraphics( mpGraphics );
1201 // retrieve current settings from printer driver and store them to system independend data!
1202 ImplFreeFormAndTrayList( this );
1203 if ( mbDJPSupported )
1204 ImplGetCurrentSettings( this, pSetupData );
1206 return TRUE;
1208 else
1210 ImplFreePrnMemory( pDrivData );
1211 return FALSE;
1215 // -----------------------------------------------------------------------
1217 BOOL Os2SalInfoPrinter::SetPrinterData( ImplJobSetup* pSetupData )
1219 // Wir koennen nur Treiberdaten von OS2 setzen
1220 if ( pSetupData->mnSystem != JOBSETUP_SYSTEM_OS2 )
1221 return FALSE;
1223 PDRIVDATA pNewDrivData = (PDRIVDATA)(pSetupData->mpDriverData);
1224 if ( !pNewDrivData )
1225 return FALSE;
1227 // Testen, ob Printerdaten fuer den gleichen Printer uebergeben werden,
1228 // da einige Treiber zu Abstuerzen neigen, wenn Daten von einem anderen
1229 // Printer gesetzt werden
1230 if ( !maJobSetupDeviceName.Equals( pNewDrivData->szDeviceName ))
1231 return FALSE;
1233 // update DC and PS
1234 HDC hDC;
1235 HPS hPS;
1236 if ( !ImplSalCreateInfoPrn( this, pNewDrivData, hDC, hPS ) )
1237 return FALSE;
1239 // Alten Printer DC/PS zerstoeren
1240 ImplSalDestroyInfoPrn( this );
1242 // Neue Daten setzen und initialisieren
1243 mhDC = hDC;
1244 mhPS = hPS;
1245 mpGraphics->mhDC = mhDC;
1246 mpGraphics->mhPS = mhPS;
1247 ImplSalInitGraphics( mpGraphics );
1249 // retrieve current settings from printer driver and store them to system independend data!
1250 ImplFreeFormAndTrayList( this );
1251 if ( mbDJPSupported )
1252 ImplGetCurrentSettings( this, pSetupData );
1254 return TRUE;
1257 // -----------------------------------------------------------------------
1259 BOOL Os2SalInfoPrinter::SetData( ULONG nFlags, ImplJobSetup* pSetupData )
1261 // needs DJP support
1262 if ( !mbDJPSupported )
1263 return FALSE;
1265 PDRIVDATA pDrivData = ImplPrnDrivData( pSetupData );
1267 if ( !pDrivData )
1268 return FALSE;
1270 BOOL bOK = FALSE;
1272 // set orientation
1273 if ( nFlags & SAL_JOBSET_ORIENTATION )
1275 if ( ImplSetOrientation( mhDC, pDrivData, pSetupData->meOrientation ) )
1276 bOK = TRUE;
1279 // set paper size
1280 if ( nFlags & SAL_JOBSET_PAPERSIZE )
1282 // Papierformat ermitteln
1283 DJPT_PAPERSIZE nOS2PaperFormat;
1284 switch ( pSetupData->mePaperFormat )
1286 case PAPER_A3:
1287 nOS2PaperFormat = DJP_PSI_A3;
1288 break;
1290 case PAPER_A4:
1291 nOS2PaperFormat = DJP_PSI_A4;
1292 break;
1294 case PAPER_A5:
1295 nOS2PaperFormat = DJP_PSI_A5;
1296 break;
1298 case PAPER_B4:
1299 nOS2PaperFormat = DJP_PSI_B4;
1300 break;
1302 case PAPER_B5:
1303 nOS2PaperFormat = DJP_PSI_B5;
1304 break;
1306 case PAPER_LETTER:
1307 nOS2PaperFormat = DJP_PSI_LETTER;
1308 break;
1310 case PAPER_LEGAL:
1311 nOS2PaperFormat = DJP_PSI_LEGAL;
1312 break;
1314 case PAPER_TABLOID:
1315 nOS2PaperFormat = DJP_PSI_TABLOID;
1316 break;
1318 default:
1320 nOS2PaperFormat = DJP_PSI_NONE;
1321 // OS2 rechnet in Millimetern
1322 long nPaperWidth = pSetupData->mnPaperWidth / 100;
1323 long nPaperHeight = pSetupData->mnPaperHeight / 100;
1324 // Ansonsten ueber die Papiergroesse suchen
1325 for( int i = 0; i < mnFormCount; i++ )
1327 ImplFormInfo* pFormInfo = mpFormArray[i];
1328 if ( ImplPaperSizeEqual( nPaperWidth, nPaperHeight,
1329 pFormInfo->mnPaperWidth, pFormInfo->mnPaperHeight ) )
1331 nOS2PaperFormat = pFormInfo->mnId;
1332 break;
1336 break;
1339 if ( nOS2PaperFormat != DJP_PSI_NONE )
1341 if ( ImplSetPaperSize( mhDC, pDrivData, nOS2PaperFormat ) )
1342 bOK = TRUE;
1346 // set paper tray
1347 if ( (nFlags & SAL_JOBSET_PAPERBIN) && (pSetupData->mnPaperBin < mnTrayCount) )
1349 if ( ImplSetPaperBin( mhDC, pDrivData,
1350 mpTrayArray[pSetupData->mnPaperBin] ) )
1351 bOK = TRUE;
1354 if ( bOK )
1356 ImplUpdateSetupData( pDrivData, pSetupData );
1358 // query current driver settings
1359 ImplFreeFormAndTrayList( this );
1360 if ( ImplGetCurrentSettings( this, pSetupData ) )
1362 // update DC and PS
1363 HDC hDC;
1364 HPS hPS;
1365 if ( ImplSalCreateInfoPrn( this, (PDRIVDATA)(pSetupData->mpDriverData), hDC, hPS ) )
1367 // Alten Printer DC/PS zerstoeren
1368 ImplSalDestroyInfoPrn( this );
1370 // Neue Daten setzen und initialisieren
1371 mhDC = hDC;
1372 mhPS = hPS;
1373 mpGraphics->mhDC = mhDC;
1374 mpGraphics->mhPS = mhPS;
1375 ImplSalInitGraphics( mpGraphics );
1377 else
1378 bOK = FALSE;
1380 else
1381 bOK = FALSE;
1384 return bOK;
1387 // -----------------------------------------------------------------------
1389 ULONG Os2SalInfoPrinter::GetPaperBinCount( const ImplJobSetup* pJobSetup )
1391 if ( !mbDJPSupported )
1392 return 1;
1394 // init paperbinlist if empty
1395 if ( !mnTrayCount )
1396 ImplGetFormAndTrayList( this, pJobSetup );
1398 // Wir haben immer einen PaperTray und wenn, das eben einen ohne
1399 // Namen
1400 if ( !mnTrayCount )
1401 return 1;
1402 else
1403 return mnTrayCount;
1406 // -----------------------------------------------------------------------
1408 XubString Os2SalInfoPrinter::GetPaperBinName( const ImplJobSetup* pJobSetup,
1409 ULONG nPaperBin )
1411 XubString aPaperBinName;
1413 if ( mbDJPSupported )
1415 // init paperbinlist if empty
1416 if ( !mnTrayCount )
1417 ImplGetFormAndTrayList( this, pJobSetup );
1419 if ( nPaperBin < mnTrayCount )
1420 aPaperBinName = ::rtl::OStringToOUString (mpTrayArray[nPaperBin]->maDisplayName, gsl_getSystemTextEncoding());
1423 return aPaperBinName;
1426 // -----------------------------------------------------------------------
1428 ULONG Os2SalInfoPrinter::GetCapabilities( const ImplJobSetup*, USHORT nType )
1430 switch ( nType )
1432 case PRINTER_CAPABILITIES_SUPPORTDIALOG:
1433 return TRUE;
1434 case PRINTER_CAPABILITIES_COPIES:
1435 return 0xFFFF;
1436 case PRINTER_CAPABILITIES_COLLATECOPIES:
1437 return 0;
1438 case PRINTER_CAPABILITIES_SETORIENTATION:
1439 case PRINTER_CAPABILITIES_SETPAPERBIN:
1440 case PRINTER_CAPABILITIES_SETPAPERSIZE:
1441 case PRINTER_CAPABILITIES_SETPAPER:
1442 return mbDJPSupported;
1445 return 0;
1448 // -----------------------------------------------------------------------
1450 void Os2SalInfoPrinter::GetPageInfo( const ImplJobSetup*,
1451 long& rOutWidth, long& rOutHeight,
1452 long& rPageOffX, long& rPageOffY,
1453 long& rPageWidth, long& rPageHeight )
1455 HDC hDC = mhDC;
1457 // search current form
1458 HCINFO aInfo;
1459 int nForms = DevQueryHardcopyCaps( hDC, 0, 0, &aInfo );
1460 for( int i = 0; i < nForms; i++ )
1462 if ( DevQueryHardcopyCaps( hDC, i, 1, &aInfo ) >= 0 )
1464 if ( aInfo.flAttributes & HCAPS_CURRENT )
1466 // query resolution
1467 long nXResolution;
1468 long nYResolution;
1469 DevQueryCaps( hDC, CAPS_HORIZONTAL_RESOLUTION, 1, &nXResolution );
1470 DevQueryCaps( hDC, CAPS_VERTICAL_RESOLUTION, 1, &nYResolution );
1471 rPageOffX = aInfo.xLeftClip * nXResolution / 1000;
1472 rPageOffY = (aInfo.cy-aInfo.yTopClip) * nYResolution / 1000;
1473 rPageWidth = aInfo.cx * nXResolution / 1000;
1474 rPageHeight = aInfo.cy * nYResolution / 1000;
1475 rOutWidth = aInfo.xPels;
1476 rOutHeight = aInfo.yPels;
1477 return;
1482 // use device caps if no form selected/found
1483 long lCapsWidth = 0;
1484 long lCapsHeight = 0;
1485 DevQueryCaps( hDC, CAPS_WIDTH, 1L, &lCapsWidth );
1486 DevQueryCaps( hDC, CAPS_HEIGHT, 1L, &lCapsHeight );
1487 rPageOffX = 0;
1488 rPageOffY = 0;
1489 rOutWidth = lCapsWidth;
1490 rOutHeight = lCapsHeight;
1491 rPageWidth = rOutWidth;
1492 rPageHeight = rOutHeight;
1495 // =======================================================================
1497 static BOOL ImplIsDriverPrintDJPEnabled( HDC hDC )
1499 #ifdef NO_DJP
1500 return FALSE;
1501 #else
1502 // Ueber OS2-Ini kann DJP disablte werden
1503 if ( !PrfQueryProfileInt( HINI_PROFILE, SAL_PROFILE_APPNAME, SAL_PROFILE_PRINTDJP, 1 ) )
1504 return FALSE;
1506 // Testen, ob DJP-Interface am Drucker vorhanden
1507 LONG lQuery;
1508 APIRET rc;
1510 lQuery = DEVESC_QUERYSIZE;
1511 rc = DevEscape( hDC,
1512 DEVESC_QUERYESCSUPPORT,
1513 sizeof( lQuery ),
1514 (PBYTE)&lQuery,
1516 (PBYTE)NULL );
1517 if ( DEV_OK != rc )
1518 return FALSE;
1520 return TRUE;
1521 #endif
1524 // =======================================================================
1526 SalPrinter* Os2SalInstance::CreatePrinter( SalInfoPrinter* pInfoPrinter )
1528 Os2SalPrinter* pPrinter = new Os2SalPrinter;
1529 pPrinter->mpInfoPrinter = static_cast<Os2SalInfoPrinter*>(pInfoPrinter);
1530 return pPrinter;
1533 // -----------------------------------------------------------------------
1535 void Os2SalInstance::DestroyPrinter( SalPrinter* pPrinter )
1537 delete pPrinter;
1540 // =======================================================================
1542 Os2SalPrinter::Os2SalPrinter()
1544 mhDC = 0;
1545 mhPS = 0;
1546 mpGraphics = NULL;
1547 mbAbort = FALSE;
1548 mbPrintDJPSupported = FALSE;
1551 // -----------------------------------------------------------------------
1553 Os2SalPrinter::~Os2SalPrinter()
1557 // -----------------------------------------------------------------------
1559 BOOL Os2SalPrinter::StartJob( const XubString* pFileName,
1560 const XubString& rJobName,
1561 const XubString& rAppName,
1562 ULONG nCopies, BOOL bCollate,
1563 ImplJobSetup* pSetupData )
1565 DEVOPENSTRUC aDevOpenStruc;
1566 LONG lType;
1567 APIRET rc;
1569 // prepare queue information
1570 memset( &aDevOpenStruc, 0, sizeof( aDevOpenStruc ) );
1571 aDevOpenStruc.pszDriverName = (PSZ)(mpInfoPrinter->maDriverName.GetBuffer());
1573 // print into file?
1574 if ( pFileName )
1576 aDevOpenStruc.pszLogAddress = (PSZ)pFileName->GetBuffer();
1577 aDevOpenStruc.pszDataType = "PM_Q_RAW";
1578 lType = OD_DIRECT;
1580 else
1582 aDevOpenStruc.pszLogAddress = (PSZ)(mpInfoPrinter->maName.GetBuffer());
1583 if ( PrfQueryProfileInt( HINI_PROFILE, SAL_PROFILE_APPNAME, SAL_PROFILE_PRINTRAW, 0 ) )
1584 aDevOpenStruc.pszDataType = "PM_Q_RAW";
1585 else
1586 aDevOpenStruc.pszDataType = "PM_Q_STD";
1587 lType = OD_QUEUED;
1590 #if 0 // YD FIXME
1591 // Set comment (AppName nur bis zum 1. Space-Zeichen nehmen)
1592 const xub_Unicode* pComment = rAppName;
1593 USHORT nCommentLen = 0;
1594 memset( maCommentBuf, 0, sizeof( maCommentBuf ) );
1595 while ( (nCommentLen < 32) &&
1596 (((*pComment >= 'a') && (*pComment <= 'z')) ||
1597 ((*pComment >= 'A') && (*pComment <= 'Z')) ||
1598 ((*pComment >= '0') && (*pComment <= '9')) ||
1599 (*pComment == '-')))
1601 maCommentBuf[nCommentLen] = (char)(*pComment);
1602 nCommentLen++;
1603 pComment++;
1605 aDevOpenStruc.pszComment = (PSZ)maCommentBuf;
1606 #endif
1607 ByteString jobName( rJobName, gsl_getSystemTextEncoding());
1608 aDevOpenStruc.pszComment = (PSZ)jobName.GetBuffer();
1610 // Kopien
1611 if ( nCopies > 1 )
1613 // OS2 kann maximal 999 Kopien
1614 if ( nCopies > 999 )
1615 nCopies = 999;
1616 sprintf( maCopyBuf, "COP=%d", nCopies);
1617 aDevOpenStruc.pszQueueProcParams = (PSZ)maCopyBuf;
1620 // open device context
1621 SalData* pSalData = GetSalData();
1622 HAB hAB = pSalData->mhAB;
1623 aDevOpenStruc.pdriv = (PDRIVDATA)pSetupData->mpDriverData;
1624 mhDC = DevOpenDC( hAB,
1625 lType,
1626 "*",
1628 (PDEVOPENDATA)&aDevOpenStruc,
1629 0 );
1630 if ( mhDC == 0 )
1632 ERRORID nLastError = WinGetLastError( hAB );
1633 if ( (nLastError & 0xFFFF) == PMERR_SPL_PRINT_ABORT )
1634 mnError = SAL_PRINTER_ERROR_ABORT;
1635 else
1636 mnError = SAL_PRINTER_ERROR_GENERALERROR;
1637 return FALSE;
1640 // open presentation space
1641 SIZEL sizel;
1642 sizel.cx = 0;
1643 sizel.cy = 0;
1644 mhPS = Ft2CreatePS( hAB, mhDC, &sizel, GPIA_ASSOC | GPIT_MICRO | PU_PELS );
1645 if ( !mhPS )
1647 DevCloseDC( mhDC );
1648 mnError = SAL_PRINTER_ERROR_GENERALERROR;
1649 return NULL;
1652 // Can we print with DJP
1653 mbPrintDJPSupported = ImplIsDriverPrintDJPEnabled( mhDC );
1655 // JobName ermitteln und Job starten
1656 PSZ pszJobName = NULL;
1657 int nJobNameLen = 0;
1658 if ( jobName.Len() > 0 )
1660 pszJobName = (PSZ)jobName.GetBuffer();
1661 nJobNameLen = jobName.Len();
1663 rc = DevEscape( mhDC,
1664 DEVESC_STARTDOC,
1665 nJobNameLen, (PBYTE)pszJobName,
1666 0, (PBYTE)NULL );
1668 if ( rc != DEV_OK )
1670 ERRORID nLastError = WinGetLastError( hAB );
1671 if ( (nLastError & 0xFFFF) == PMERR_SPL_PRINT_ABORT )
1672 mnError = SAL_PRINTER_ERROR_ABORT;
1673 else
1674 mnError = SAL_PRINTER_ERROR_GENERALERROR;
1675 Ft2Associate( mhPS, NULL );
1676 Ft2DestroyPS( mhPS );
1677 DevCloseDC( mhDC );
1678 return FALSE;
1681 // init for first page
1682 mbFirstPage = TRUE;
1683 mnError = 0;
1685 return TRUE;
1688 // -----------------------------------------------------------------------
1690 BOOL Os2SalPrinter::EndJob()
1692 APIRET rc;
1693 rc = DevEscape( mhDC,
1694 DEVESC_ENDDOC,
1695 0, NULL,
1696 0, NULL);
1698 // destroy presentation space and device context
1699 Ft2Associate( mhPS, NULL );
1700 Ft2DestroyPS( mhPS );
1701 DevCloseDC( mhDC );
1702 return TRUE;
1705 // -----------------------------------------------------------------------
1707 BOOL Os2SalPrinter::AbortJob()
1709 APIRET rc;
1711 rc = DevEscape( mhDC,
1712 DEVESC_ABORTDOC,
1713 0, NULL,
1714 0, NULL );
1716 // destroy SalGraphics
1717 if ( mpGraphics )
1719 ImplSalDeInitGraphics( mpGraphics );
1720 delete mpGraphics;
1721 mpGraphics = NULL;
1724 // destroy presentation space and device context
1725 Ft2Associate( mhPS, NULL );
1726 Ft2DestroyPS( mhPS );
1727 DevCloseDC( mhDC );
1728 return TRUE;
1731 // -----------------------------------------------------------------------
1733 SalGraphics* Os2SalPrinter::StartPage( ImplJobSetup* pSetupData, BOOL bNewJobSetup )
1735 APIRET rc;
1737 if ( mbFirstPage )
1738 mbFirstPage = FALSE;
1739 else
1741 PBYTE pJobData;
1742 LONG nJobDataSize;
1743 LONG nEscape;
1744 if ( mbPrintDJPSupported && bNewJobSetup )
1746 nEscape = DEVESC_NEWFRAME_WPROP;
1747 nJobDataSize = ((PDRIVDATA)(pSetupData->mpDriverData))->cb;
1748 pJobData = (PBYTE)(pSetupData->mpDriverData);
1750 else
1752 nEscape = DEVESC_NEWFRAME;
1753 nJobDataSize = 0;
1754 pJobData = NULL;
1756 rc = DevEscape( mhDC,
1757 nEscape,
1758 0, NULL,
1759 &nJobDataSize, pJobData );
1761 if ( rc != DEV_OK )
1763 DevEscape( mhDC, DEVESC_ENDDOC, 0, NULL, 0, NULL);
1764 Ft2Associate( mhPS, NULL );
1765 Ft2DestroyPS( mhPS );
1766 DevCloseDC( mhDC );
1767 mnError = SAL_PRINTER_ERROR_GENERALERROR;
1768 return NULL;
1772 // create SalGraphics with copy of hPS
1773 Os2SalGraphics* pGraphics = new Os2SalGraphics;
1774 pGraphics->mhDC = mhDC;
1775 pGraphics->mhPS = mhPS;
1776 pGraphics->mhWnd = 0;
1777 pGraphics->mbPrinter = TRUE;
1778 pGraphics->mbVirDev = FALSE;
1779 pGraphics->mbWindow = FALSE;
1780 pGraphics->mbScreen = FALSE;
1781 pGraphics->mnHeight = 0;
1782 // search current form for actual page height
1783 HCINFO aInfo;
1784 int nForms = DevQueryHardcopyCaps( mhDC, 0, 0, &aInfo );
1785 for( int i = 0; i < nForms; i++ )
1787 if ( DevQueryHardcopyCaps( mhDC, i, 1, &aInfo ) >= 0 )
1789 if ( aInfo.flAttributes & HCAPS_CURRENT )
1790 pGraphics->mnHeight = aInfo.yPels;
1793 // use device caps if no form selected/found
1794 if ( !pGraphics->mnHeight )
1795 DevQueryCaps( mhDC, CAPS_HEIGHT, 1L, &pGraphics->mnHeight );
1797 ImplSalInitGraphics( pGraphics );
1798 mpGraphics = pGraphics;
1800 return pGraphics;
1803 // -----------------------------------------------------------------------
1805 BOOL Os2SalPrinter::EndPage()
1807 if ( mpGraphics )
1809 // destroy SalGraphics
1810 ImplSalDeInitGraphics( mpGraphics );
1811 delete mpGraphics;
1812 mpGraphics = NULL;
1815 return TRUE;
1818 // -----------------------------------------------------------------------
1820 ULONG Os2SalPrinter::GetErrorCode()
1822 return mnError;
1825 void Os2SalInfoPrinter::InitPaperFormats( const ImplJobSetup* pSetupData )
1827 printf("Os2SalInfoPrinter::InitPaperFormats\n");
1829 int Os2SalInfoPrinter::GetLandscapeAngle( const ImplJobSetup* pSetupData )
1831 printf("Os2SalInfoPrinter::GetLandscapeAngle\n");
1832 return 0;
1834 DuplexMode Os2SalInfoPrinter::GetDuplexMode( const ImplJobSetup* pSetupData )
1836 DuplexMode nRet = DUPLEX_UNKNOWN;
1837 printf("Os2SalInfoPrinter::GetDuplexMode\n");
1838 return nRet;