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