1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: salprn.cxx,v $
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
34 #define INCL_DOSMODULEMGR
37 #define INCL_SPLERRORS
38 #define INCL_SPLDOSPRINT
42 #define INCL_DOSSEMAPHORES
49 #define _SV_SALPRN_CXX
50 #include <tools/debug.hxx>
51 #include <saldata.hxx>
55 #include <vcl/salptype.hxx>
57 #include <vcl/print.h>
58 #include <vcl/jobset.h>
65 // =======================================================================
67 // -----------------------
68 // - struct ImplFormInfo -
69 // -----------------------
80 // =======================================================================
82 // -----------------------
83 // - struct ImplTrayInfo -
84 // -----------------------
89 CHAR maDisplayName
[64];
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
),
130 maOrgDriverName( rName
),
131 maDriverName( rDriverName
),
132 maDeviceName( rDeviceName
)
136 mpDrivData
= (PDRIVDATA
)new BYTE
[pDrivData
->cb
];
137 memcpy( mpDrivData
, pDrivData
, pDrivData
->cb
);
143 // -----------------------------------------------------------------------
145 ImplQueueSalSysData::~ImplQueueSalSysData()
150 // =======================================================================
152 static ULONG
ImplPMQueueStatusToSal( USHORT nPMStatus
)
155 if ( nPMStatus
& PRQ3_PAUSED
)
156 nStatus
|= QUEUE_STATUS_PAUSED
;
157 if ( nPMStatus
& PRQ3_PENDING
)
158 nStatus
|= QUEUE_STATUS_PENDING_DELETION
;
160 nStatus
|= QUEUE_STATUS_READY
;
164 // -----------------------------------------------------------------------
166 void Os2SalInstance::GetPrinterQueueInfo( ImplPrnQueueList
* pList
)
173 // query needed size of the buffer for the QueueInfo
174 rc
= SplEnumQueue( (PSZ
)NULL
, 3, NULL
, 0, &nReturned
, &nTotal
, &nNeeded
, NULL
);
178 // create the buffer for the QueueInfo
179 PCHAR pQueueData
= new CHAR
[nNeeded
];
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
205 (strcmp( pPrqInfo
->pszComment
, pTempPrqInfo
->pszComment
) == 0) )
207 pInfo
->maPrinterName
+= ';';
208 pInfo
->maPrinterName
+= pInfo
->maLocation
;
213 // pszDriver in DriverName (bis .) und DeviceName (nach .) aufsplitten
216 if ( (pDriverName
= strchr( pPrqInfo
->pszDriverName
, '.' )) != 0 )
219 pDeviceName
= pDriverName
+ 1;
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
;
240 aDeviceName
= pDeviceName
;
241 pInfo
->mpSysData
= new ImplQueueSalSysData( aPrinterName
, aName
,
243 aDriverName
, aDeviceName
,
244 pPrqInfo
->pDriverData
);
246 // add queue to the list
249 // increment to next element of the QueueInfo array
253 delete [] pQueueData
;
256 // -----------------------------------------------------------------------
258 void Os2SalInstance::GetPrinterQueueState( SalPrinterQueueInfo
* pInfo
)
265 // query needed size of the buffer for the QueueInfo
266 rc
= SplEnumQueue( (PSZ
)NULL
, 3, NULL
, 0, &nReturned
, &nTotal
, &nNeeded
, NULL
);
270 // create the buffer for the QueueInfo
271 PCHAR pQueueData
= new CHAR
[nNeeded
];
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
;
289 // increment to next element of the QueueInfo array
293 delete [] pQueueData
;
296 // -----------------------------------------------------------------------
298 void Os2SalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo
* pInfo
)
300 delete ((ImplQueueSalSysData
*)(pInfo
->mpSysData
));
304 // -----------------------------------------------------------------------
306 XubString
Os2SalInstance::GetDefaultPrinter()
312 char szQueueName
[255];
313 XubString aDefaultName
;
315 // query default queue
316 if ( !PrfQueryProfileString( HINI_PROFILE
, SPL_INI_SPOOLER
, "QUEUE", 0, szQueueName
, sizeof( szQueueName
) ) )
319 // extract first queue name
321 if ( (pStr
= strchr( szQueueName
, ';' )) != 0 )
324 // query needed size of the buffer for the QueueInfo
325 rc
= SplEnumQueue( (PSZ
)NULL
, 3, NULL
, 0, &nReturned
, &nTotal
, &nNeeded
, NULL
);
329 // create the buffer for the QueueInfo
330 PCHAR pQueueData
= new CHAR
[ nNeeded
];
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
349 (strcmp( pPrqInfo
->pszComment
, pTempPrqInfo
->pszComment
) == 0) )
351 String
pszName( ::rtl::OStringToOUString (pPrqInfo
->pszName
, gsl_getSystemTextEncoding()));
353 aDefaultName
+= pszName
;
360 // increment to next element of the QueueInfo array
364 delete [] pQueueData
;
369 // =======================================================================
371 static void* ImplAllocPrnMemory( size_t n
)
373 return calloc( n
, 1);
376 // -----------------------------------------------------------------------
378 inline void ImplFreePrnMemory( void* 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
)
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
);
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;
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
);
440 pSetupData
->mpDriverData
= (BYTE
*)rtl_allocateMemory( pDrivData
->cb
);
441 pSetupData
->mnDriverDataLen
= pDrivData
->cb
;
442 memcpy( pSetupData
->mpDriverData
, pDrivData
, pDrivData
->cb
);
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
)
465 // Ueber OS2-Ini kann DJP disablte werden
466 if ( !PrfQueryProfileInt( HINI_PROFILE
, SAL_PROFILE_APPNAME
, SAL_PROFILE_USEDJP
, 1 ) )
469 // Testen, ob DJP-Interface am Drucker vorhanden
473 lQuery
= DEVESC_QUERYSIZE
;
475 DEVESC_QUERYESCSUPPORT
,
483 lQuery
= DEVESC_QUERYJOBPROPERTIES
;
485 DEVESC_QUERYESCSUPPORT
,
493 lQuery
= DEVESC_SETJOBPROPERTIES
;
495 DEVESC_QUERYESCSUPPORT
,
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
;
522 fContinue
= DJP_NONE
!= pTuple
->ulProperty
;
524 // Move to next item structure and tuplet
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
);
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
567 PQUERYSIZE pQuerySize
= (PQUERYSIZE
)alQuery
;
568 PBYTE pBuffer
= NULL
;
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
,
584 ImplFreePrnMemory( pCopyDrivData
);
588 // allocate the memory
589 nAlloc
= pQuerySize
->ulSizeNeeded
;
590 pBuffer
= (PBYTE
)new BYTE
[nAlloc
];
593 PDJP_ITEM pDJP
= (PDJP_ITEM
)pBuffer
;
594 ImplFormatInputList( pDJP
, pQuerySize
->aTuples
);
597 rc
= DevEscape( pOs2SalInfoPrinter
->mhDC
,
598 DEVESC_QUERYJOBPROPERTIES
,
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
);
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
);
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
671 PQUERYSIZE pQuerySize
= (PQUERYSIZE
)alQuery
;
672 PBYTE pBuffer
= NULL
;
674 PDRIVDATA pCopyDrivData
= ImplPrnDrivData( pSetupData
);
675 LONG nDrivDataSize
= pCopyDrivData
->cb
;
676 PBYTE pDrivData
= (PBYTE
)pCopyDrivData
;
679 // find out how many bytes to allocate
680 pQuerySize
->cb
= sizeof( alQuery
);
681 rc
= DevEscape( pOs2SalInfoPrinter
->mhDC
,
689 ImplFreePrnMemory( pCopyDrivData
);
693 // allocate the memory
694 nAlloc
= pQuerySize
->ulSizeNeeded
;
695 pBuffer
= (PBYTE
)new BYTE
[nAlloc
];
698 PDJP_ITEM pDJP
= (PDJP_ITEM
)pBuffer
;
699 ImplFormatInputList( pDJP
, pQuerySize
->aTuples
);
701 rc
= DevEscape( pOs2SalInfoPrinter
->mhDC
,
702 DEVESC_QUERYJOBPROPERTIES
,
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
;
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
)
738 pSetupData
->mePaperFormat
= PAPER_A3
;
742 pSetupData
->mePaperFormat
= PAPER_A4
;
746 pSetupData
->mePaperFormat
= PAPER_A5
;
750 pSetupData
->mePaperFormat
= PAPER_B4
;
754 pSetupData
->mePaperFormat
= PAPER_B5
;
758 pSetupData
->mePaperFormat
= PAPER_LETTER
;
762 pSetupData
->mePaperFormat
= PAPER_LEGAL
;
765 case DJP_PSI_TABLOID
:
766 pSetupData
->mePaperFormat
= PAPER_TABLOID
;
770 pSetupData
->mePaperFormat
= PAPER_USER
;
774 // Wir suchen zuerst ueber den Namen/Id und dann ueber die Id
775 BOOL bTrayFound
= FALSE
;
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
;
789 for ( j
= 0; j
< pOs2SalInfoPrinter
->mnTrayCount
; j
++ )
791 if ( pOs2SalInfoPrinter
->mpTrayArray
[j
]->mnId
== pElm
->djpttTrayID
)
793 pSetupData
->mnPaperBin
= j
;
799 // Wenn wir Ihn immer noch nicht gefunden haben, setzen
800 // wir ihn auf DontKnow
802 pSetupData
->mnPaperBin
= 0xFFFF;
806 pDJP
= DJP_NEXT_STRUCTP( pDJP
);
814 ImplFreePrnMemory( pCopyDrivData
);
823 // -----------------------------------------------------------------------
825 static BOOL
ImplSetOrientation( HDC hPrinterDC
, PDRIVDATA pDriverData
,
826 Orientation eOrientation
)
830 0, 0, // First two members of QUERYSIZE
831 DJP_SJ_ORIENTATION
, DJP_CURRENT
,
832 DJP_NONE
, DJP_NONE
// EOL marker
836 PQUERYSIZE pQuerySize
= (PQUERYSIZE
)alQuery
;
837 PBYTE pBuffer
= NULL
;
839 LONG nDrivDataSize
= pDriverData
->cb
;
841 // find out how many bytes to allocate
842 pQuerySize
->cb
= sizeof( alQuery
);
843 rc
= DevEscape( hPrinterDC
,
848 (PBYTE
)pDriverData
);
852 // allocate the memory
853 nAlloc
= pQuerySize
->ulSizeNeeded
;
854 pBuffer
= (PBYTE
)new BYTE
[nAlloc
];
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
)
868 rc
= DevEscape( hPrinterDC
,
869 DEVESC_SETJOBPROPERTIES
,
873 (PBYTE
)pDriverData
);
877 return ((DEV_OK
== rc
) || (DEV_WARNING
== rc
));
880 // -----------------------------------------------------------------------
882 static BOOL
ImplSetPaperSize( HDC hPrinterDC
, PDRIVDATA pDriverData
,
883 DJPT_PAPERSIZE nOS2PaperFormat
)
887 0, 0, // First two members of QUERYSIZE
888 DJP_SJ_PAPERSIZE
, DJP_CURRENT
,
889 DJP_NONE
, DJP_NONE
// EOL marker
893 PQUERYSIZE pQuerySize
= (PQUERYSIZE
)alQuery
;
894 PBYTE pBuffer
= NULL
;
896 LONG nDrivDataSize
= pDriverData
->cb
;
898 // find out how many bytes to allocate
899 pQuerySize
->cb
= sizeof( alQuery
);
900 rc
= DevEscape( hPrinterDC
,
905 (PBYTE
)pDriverData
);
909 // allocate the memory
910 nAlloc
= pQuerySize
->ulSizeNeeded
;
911 pBuffer
= (PBYTE
)new BYTE
[nAlloc
];
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
;
925 rc
= DevEscape( hPrinterDC
,
926 DEVESC_SETJOBPROPERTIES
,
930 (PBYTE
)pDriverData
);
934 return ((DEV_OK
== rc
) || (DEV_WARNING
== rc
));
937 // -----------------------------------------------------------------------
939 static BOOL
ImplSetPaperBin( HDC hPrinterDC
, PDRIVDATA pDriverData
,
940 ImplTrayInfo
* pTrayInfo
)
944 0, 0, // First two members of QUERYSIZE
945 DJP_SJ_TRAYTYPE
, DJP_CURRENT
,
946 DJP_NONE
, DJP_NONE
// EOL marker
950 PQUERYSIZE pQuerySize
= (PQUERYSIZE
)alQuery
;
951 PBYTE pBuffer
= NULL
;
953 LONG nDrivDataSize
= pDriverData
->cb
;
955 // find out how many bytes to allocate
956 pQuerySize
->cb
= sizeof( alQuery
);
957 rc
= DevEscape( hPrinterDC
,
962 (PBYTE
)pDriverData
);
966 // allocate the memory
967 nAlloc
= pQuerySize
->ulSizeNeeded
;
968 pBuffer
= (PBYTE
)new BYTE
[nAlloc
];
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
;
981 rc
= DevEscape( hPrinterDC
,
982 DEVESC_SETJOBPROPERTIES
,
986 (PBYTE
)pDriverData
);
990 return ((DEV_OK
== rc
) || (DEV_WARNING
== rc
));
993 // =======================================================================
995 static BOOL
ImplSalCreateInfoPrn( Os2SalInfoPrinter
* pPrinter
, PDRIVDATA pDriverData
,
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
);
1013 // create presentation space
1017 HPS hPS
= Ft2CreatePS( pSalData
->mhAB
, hDC
, &sizel
, GPIA_ASSOC
| GPIT_MICRO
| PU_PELS
);
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
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
;
1066 pDriverData
= pSysQueueData
->mpDrivData
;
1067 bUpdateDriverData
= TRUE
;
1070 pPrinter
->maJobSetupDeviceName
= pDriverData
->szDeviceName
;
1072 if ( !ImplSalCreateInfoPrn( pPrinter
, pDriverData
,
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
;
1113 // -----------------------------------------------------------------------
1115 void Os2SalInstance::DestroyInfoPrinter( SalInfoPrinter
* pPrinter
)
1120 // =======================================================================
1122 Os2SalInfoPrinter::Os2SalInfoPrinter()
1128 mbDJPSupported
= FALSE
;
1135 // -----------------------------------------------------------------------
1137 Os2SalInfoPrinter::~Os2SalInfoPrinter()
1141 ImplSalDestroyInfoPrn( this );
1145 ImplFreeFormAndTrayList( this );
1148 // -----------------------------------------------------------------------
1150 SalGraphics
* Os2SalInfoPrinter::GetGraphics()
1161 // -----------------------------------------------------------------------
1163 void Os2SalInfoPrinter::ReleaseGraphics( SalGraphics
* )
1168 // -----------------------------------------------------------------------
1170 BOOL
Os2SalInfoPrinter::Setup( SalFrame
* pFrame
, ImplJobSetup
* pSetupData
)
1172 PDRIVDATA pDrivData
= ImplPrnDrivData( pSetupData
);
1176 APIRET rc
= DevPostDeviceModes( GetSalData()->mhAB
, pDrivData
,
1177 maDriverName
.GetBuffer(),
1178 maDeviceName
.GetBuffer(),
1179 maPrinterName
.GetBuffer(),
1183 ImplUpdateSetupData( pDrivData
, pSetupData
);
1188 if ( !ImplSalCreateInfoPrn( this, (PDRIVDATA
)(pSetupData
->mpDriverData
), hDC
, hPS
) )
1191 // Alten Printer DC/PS zerstoeren
1192 ImplSalDestroyInfoPrn( this );
1194 // Neue Daten setzen und initialisieren
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
);
1210 ImplFreePrnMemory( pDrivData
);
1215 // -----------------------------------------------------------------------
1217 BOOL
Os2SalInfoPrinter::SetPrinterData( ImplJobSetup
* pSetupData
)
1219 // Wir koennen nur Treiberdaten von OS2 setzen
1220 if ( pSetupData
->mnSystem
!= JOBSETUP_SYSTEM_OS2
)
1223 PDRIVDATA pNewDrivData
= (PDRIVDATA
)(pSetupData
->mpDriverData
);
1224 if ( !pNewDrivData
)
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
))
1236 if ( !ImplSalCreateInfoPrn( this, pNewDrivData
, hDC
, hPS
) )
1239 // Alten Printer DC/PS zerstoeren
1240 ImplSalDestroyInfoPrn( this );
1242 // Neue Daten setzen und initialisieren
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
);
1257 // -----------------------------------------------------------------------
1259 BOOL
Os2SalInfoPrinter::SetData( ULONG nFlags
, ImplJobSetup
* pSetupData
)
1261 // needs DJP support
1262 if ( !mbDJPSupported
)
1265 PDRIVDATA pDrivData
= ImplPrnDrivData( pSetupData
);
1273 if ( nFlags
& SAL_JOBSET_ORIENTATION
)
1275 if ( ImplSetOrientation( mhDC
, pDrivData
, pSetupData
->meOrientation
) )
1280 if ( nFlags
& SAL_JOBSET_PAPERSIZE
)
1282 // Papierformat ermitteln
1283 DJPT_PAPERSIZE nOS2PaperFormat
;
1284 switch ( pSetupData
->mePaperFormat
)
1287 nOS2PaperFormat
= DJP_PSI_A3
;
1291 nOS2PaperFormat
= DJP_PSI_A4
;
1295 nOS2PaperFormat
= DJP_PSI_A5
;
1299 nOS2PaperFormat
= DJP_PSI_B4
;
1303 nOS2PaperFormat
= DJP_PSI_B5
;
1307 nOS2PaperFormat
= DJP_PSI_LETTER
;
1311 nOS2PaperFormat
= DJP_PSI_LEGAL
;
1315 nOS2PaperFormat
= DJP_PSI_TABLOID
;
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
;
1339 if ( nOS2PaperFormat
!= DJP_PSI_NONE
)
1341 if ( ImplSetPaperSize( mhDC
, pDrivData
, nOS2PaperFormat
) )
1347 if ( (nFlags
& SAL_JOBSET_PAPERBIN
) && (pSetupData
->mnPaperBin
< mnTrayCount
) )
1349 if ( ImplSetPaperBin( mhDC
, pDrivData
,
1350 mpTrayArray
[pSetupData
->mnPaperBin
] ) )
1356 ImplUpdateSetupData( pDrivData
, pSetupData
);
1358 // query current driver settings
1359 ImplFreeFormAndTrayList( this );
1360 if ( ImplGetCurrentSettings( this, pSetupData
) )
1365 if ( ImplSalCreateInfoPrn( this, (PDRIVDATA
)(pSetupData
->mpDriverData
), hDC
, hPS
) )
1367 // Alten Printer DC/PS zerstoeren
1368 ImplSalDestroyInfoPrn( this );
1370 // Neue Daten setzen und initialisieren
1373 mpGraphics
->mhDC
= mhDC
;
1374 mpGraphics
->mhPS
= mhPS
;
1375 ImplSalInitGraphics( mpGraphics
);
1387 // -----------------------------------------------------------------------
1389 ULONG
Os2SalInfoPrinter::GetPaperBinCount( const ImplJobSetup
* pJobSetup
)
1391 if ( !mbDJPSupported
)
1394 // init paperbinlist if empty
1396 ImplGetFormAndTrayList( this, pJobSetup
);
1398 // Wir haben immer einen PaperTray und wenn, das eben einen ohne
1406 // -----------------------------------------------------------------------
1408 XubString
Os2SalInfoPrinter::GetPaperBinName( const ImplJobSetup
* pJobSetup
,
1411 XubString aPaperBinName
;
1413 if ( mbDJPSupported
)
1415 // init paperbinlist if empty
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
)
1432 case PRINTER_CAPABILITIES_SUPPORTDIALOG
:
1434 case PRINTER_CAPABILITIES_COPIES
:
1436 case PRINTER_CAPABILITIES_COLLATECOPIES
:
1438 case PRINTER_CAPABILITIES_SETORIENTATION
:
1439 case PRINTER_CAPABILITIES_SETPAPERBIN
:
1440 case PRINTER_CAPABILITIES_SETPAPERSIZE
:
1441 case PRINTER_CAPABILITIES_SETPAPER
:
1442 return mbDJPSupported
;
1448 // -----------------------------------------------------------------------
1450 void Os2SalInfoPrinter::GetPageInfo( const ImplJobSetup
*,
1451 long& rOutWidth
, long& rOutHeight
,
1452 long& rPageOffX
, long& rPageOffY
,
1453 long& rPageWidth
, long& rPageHeight
)
1457 // search current form
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
)
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
;
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
);
1489 rOutWidth
= lCapsWidth
;
1490 rOutHeight
= lCapsHeight
;
1491 rPageWidth
= rOutWidth
;
1492 rPageHeight
= rOutHeight
;
1495 // =======================================================================
1497 static BOOL
ImplIsDriverPrintDJPEnabled( HDC hDC
)
1502 // Ueber OS2-Ini kann DJP disablte werden
1503 if ( !PrfQueryProfileInt( HINI_PROFILE
, SAL_PROFILE_APPNAME
, SAL_PROFILE_PRINTDJP
, 1 ) )
1506 // Testen, ob DJP-Interface am Drucker vorhanden
1510 lQuery
= DEVESC_QUERYSIZE
;
1511 rc
= DevEscape( hDC
,
1512 DEVESC_QUERYESCSUPPORT
,
1524 // =======================================================================
1526 SalPrinter
* Os2SalInstance::CreatePrinter( SalInfoPrinter
* pInfoPrinter
)
1528 Os2SalPrinter
* pPrinter
= new Os2SalPrinter
;
1529 pPrinter
->mpInfoPrinter
= static_cast<Os2SalInfoPrinter
*>(pInfoPrinter
);
1533 // -----------------------------------------------------------------------
1535 void Os2SalInstance::DestroyPrinter( SalPrinter
* pPrinter
)
1540 // =======================================================================
1542 Os2SalPrinter::Os2SalPrinter()
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
;
1569 // prepare queue information
1570 memset( &aDevOpenStruc
, 0, sizeof( aDevOpenStruc
) );
1571 aDevOpenStruc
.pszDriverName
= (PSZ
)(mpInfoPrinter
->maDriverName
.GetBuffer());
1576 aDevOpenStruc
.pszLogAddress
= (PSZ
)pFileName
->GetBuffer();
1577 aDevOpenStruc
.pszDataType
= "PM_Q_RAW";
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";
1586 aDevOpenStruc
.pszDataType
= "PM_Q_STD";
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
);
1605 aDevOpenStruc
.pszComment
= (PSZ
)maCommentBuf
;
1607 ByteString
jobName( rJobName
, gsl_getSystemTextEncoding());
1608 aDevOpenStruc
.pszComment
= (PSZ
)jobName
.GetBuffer();
1613 // OS2 kann maximal 999 Kopien
1614 if ( 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
,
1628 (PDEVOPENDATA
)&aDevOpenStruc
,
1632 ERRORID nLastError
= WinGetLastError( hAB
);
1633 if ( (nLastError
& 0xFFFF) == PMERR_SPL_PRINT_ABORT
)
1634 mnError
= SAL_PRINTER_ERROR_ABORT
;
1636 mnError
= SAL_PRINTER_ERROR_GENERALERROR
;
1640 // open presentation space
1644 mhPS
= Ft2CreatePS( hAB
, mhDC
, &sizel
, GPIA_ASSOC
| GPIT_MICRO
| PU_PELS
);
1648 mnError
= SAL_PRINTER_ERROR_GENERALERROR
;
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
,
1665 nJobNameLen
, (PBYTE
)pszJobName
,
1670 ERRORID nLastError
= WinGetLastError( hAB
);
1671 if ( (nLastError
& 0xFFFF) == PMERR_SPL_PRINT_ABORT
)
1672 mnError
= SAL_PRINTER_ERROR_ABORT
;
1674 mnError
= SAL_PRINTER_ERROR_GENERALERROR
;
1675 Ft2Associate( mhPS
, NULL
);
1676 Ft2DestroyPS( mhPS
);
1681 // init for first page
1688 // -----------------------------------------------------------------------
1690 BOOL
Os2SalPrinter::EndJob()
1693 rc
= DevEscape( mhDC
,
1698 // destroy presentation space and device context
1699 Ft2Associate( mhPS
, NULL
);
1700 Ft2DestroyPS( mhPS
);
1705 // -----------------------------------------------------------------------
1707 BOOL
Os2SalPrinter::AbortJob()
1711 rc
= DevEscape( mhDC
,
1716 // destroy SalGraphics
1719 ImplSalDeInitGraphics( mpGraphics
);
1724 // destroy presentation space and device context
1725 Ft2Associate( mhPS
, NULL
);
1726 Ft2DestroyPS( mhPS
);
1731 // -----------------------------------------------------------------------
1733 SalGraphics
* Os2SalPrinter::StartPage( ImplJobSetup
* pSetupData
, BOOL bNewJobSetup
)
1738 mbFirstPage
= FALSE
;
1744 if ( mbPrintDJPSupported
&& bNewJobSetup
)
1746 nEscape
= DEVESC_NEWFRAME_WPROP
;
1747 nJobDataSize
= ((PDRIVDATA
)(pSetupData
->mpDriverData
))->cb
;
1748 pJobData
= (PBYTE
)(pSetupData
->mpDriverData
);
1752 nEscape
= DEVESC_NEWFRAME
;
1756 rc
= DevEscape( mhDC
,
1759 &nJobDataSize
, pJobData
);
1763 DevEscape( mhDC
, DEVESC_ENDDOC
, 0, NULL
, 0, NULL
);
1764 Ft2Associate( mhPS
, NULL
);
1765 Ft2DestroyPS( mhPS
);
1767 mnError
= SAL_PRINTER_ERROR_GENERALERROR
;
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
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
;
1803 // -----------------------------------------------------------------------
1805 BOOL
Os2SalPrinter::EndPage()
1809 // destroy SalGraphics
1810 ImplSalDeInitGraphics( mpGraphics
);
1818 // -----------------------------------------------------------------------
1820 ULONG
Os2SalPrinter::GetErrorCode()
1825 void Os2SalInfoPrinter::InitPaperFormats( const ImplJobSetup
* pSetupData
)
1827 printf("Os2SalInfoPrinter::InitPaperFormats\n");
1829 int Os2SalInfoPrinter::GetLandscapeAngle( const ImplJobSetup
* pSetupData
)
1831 printf("Os2SalInfoPrinter::GetLandscapeAngle\n");
1834 DuplexMode
Os2SalInfoPrinter::GetDuplexMode( const ImplJobSetup
* pSetupData
)
1836 DuplexMode nRet
= DUPLEX_UNKNOWN
;
1837 printf("Os2SalInfoPrinter::GetDuplexMode\n");