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 10*9f62ea84SAndrew Rist * 11*9f62ea84SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0 12*9f62ea84SAndrew Rist * 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. 19*9f62ea84SAndrew Rist * 20*9f62ea84SAndrew Rist *************************************************************/ 21*9f62ea84SAndrew Rist 22*9f62ea84SAndrew Rist 23cdf0e10cSrcweir 24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove 25cdf0e10cSrcweir #include "precompiled_vcl.hxx" 26cdf0e10cSrcweir 27cdf0e10cSrcweir #include <string.h> 28cdf0e10cSrcweir 29cdf0e10cSrcweir #include <osl/module.h> 30cdf0e10cSrcweir 31cdf0e10cSrcweir #include <tools/urlobj.hxx> 32cdf0e10cSrcweir #include <tools/svwin.h> 33cdf0e10cSrcweir #ifdef __MINGW32__ 34cdf0e10cSrcweir #include <excpt.h> 35cdf0e10cSrcweir #endif 36cdf0e10cSrcweir 37cdf0e10cSrcweir #include <win/wincomp.hxx> 38cdf0e10cSrcweir #include <win/saldata.hxx> 39cdf0e10cSrcweir #include <win/salinst.h> 40cdf0e10cSrcweir #include <win/salgdi.h> 41cdf0e10cSrcweir #include <win/salframe.h> 42cdf0e10cSrcweir #include <win/salprn.h> 43cdf0e10cSrcweir 44cdf0e10cSrcweir #include <salptype.hxx> 45cdf0e10cSrcweir #include <print.h> 46cdf0e10cSrcweir #include <jobset.h> 47cdf0e10cSrcweir 48cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> 49cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/ExecutableDialogResults.hpp> 50cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilePicker.hpp> 51cdf0e10cSrcweir #include <com/sun/star/ui/dialogs/XFilterManager.hpp> 52cdf0e10cSrcweir #include <com/sun/star/lang/XMultiServiceFactory.hpp> 53cdf0e10cSrcweir #include <com/sun/star/lang/XInitialization.hpp> 54cdf0e10cSrcweir #include <comphelper/processfactory.hxx> 55cdf0e10cSrcweir 56cdf0e10cSrcweir #include <malloc.h> 57cdf0e10cSrcweir 58cdf0e10cSrcweir #ifdef __MINGW32__ 59cdf0e10cSrcweir #define CATCH_DRIVER_EX_BEGIN \ 60cdf0e10cSrcweir jmp_buf jmpbuf; \ 61cdf0e10cSrcweir __SEHandler han; \ 62cdf0e10cSrcweir if (__builtin_setjmp(jmpbuf) == 0) \ 63cdf0e10cSrcweir { \ 64cdf0e10cSrcweir han.Set(jmpbuf, NULL, (__SEHandler::PF)EXCEPTION_EXECUTE_HANDLER) 65cdf0e10cSrcweir 66cdf0e10cSrcweir #define CATCH_DRIVER_EX_END(mes, p) \ 67cdf0e10cSrcweir } \ 68cdf0e10cSrcweir han.Reset() 69cdf0e10cSrcweir #define CATCH_DRIVER_EX_END_2(mes) \ 70cdf0e10cSrcweir } \ 71cdf0e10cSrcweir han.Reset() 72cdf0e10cSrcweir #else 73cdf0e10cSrcweir #define CATCH_DRIVER_EX_BEGIN \ 74cdf0e10cSrcweir __try \ 75cdf0e10cSrcweir { 76cdf0e10cSrcweir #define CATCH_DRIVER_EX_END(mes, p) \ 77cdf0e10cSrcweir } \ 78cdf0e10cSrcweir __except(WinSalInstance::WorkaroundExceptionHandlingInUSER32Lib(GetExceptionCode(), GetExceptionInformation()))\ 79cdf0e10cSrcweir { \ 80cdf0e10cSrcweir DBG_ERROR( mes ); \ 81cdf0e10cSrcweir p->markInvalid(); \ 82cdf0e10cSrcweir } 83cdf0e10cSrcweir #define CATCH_DRIVER_EX_END_2(mes) \ 84cdf0e10cSrcweir } \ 85cdf0e10cSrcweir __except(WinSalInstance::WorkaroundExceptionHandlingInUSER32Lib(GetExceptionCode(), GetExceptionInformation()))\ 86cdf0e10cSrcweir { \ 87cdf0e10cSrcweir DBG_ERROR( mes ); \ 88cdf0e10cSrcweir } 89cdf0e10cSrcweir #endif 90cdf0e10cSrcweir 91cdf0e10cSrcweir 92cdf0e10cSrcweir using namespace com::sun::star; 93cdf0e10cSrcweir using namespace com::sun::star::uno; 94cdf0e10cSrcweir using namespace com::sun::star::lang; 95cdf0e10cSrcweir using namespace com::sun::star::ui::dialogs; 96cdf0e10cSrcweir using namespace rtl; 97cdf0e10cSrcweir 98cdf0e10cSrcweir // ======================================================================= 99cdf0e10cSrcweir 100cdf0e10cSrcweir static char aImplWindows[] = "windows"; 101cdf0e10cSrcweir static char aImplDevices[] = "devices"; 102cdf0e10cSrcweir static char aImplDevice[] = "device"; 103cdf0e10cSrcweir 104cdf0e10cSrcweir static LPDEVMODEA SAL_DEVMODE_A( const ImplJobSetup* pSetupData ) 105cdf0e10cSrcweir { 106cdf0e10cSrcweir LPDEVMODEA pRet = NULL; 107cdf0e10cSrcweir SalDriverData* pDrv = (SalDriverData*)pSetupData->mpDriverData; 108cdf0e10cSrcweir if( pDrv->mnVersion == SAL_DRIVERDATA_VERSION_A && 109cdf0e10cSrcweir pSetupData->mnDriverDataLen >= sizeof(DEVMODEA)+sizeof(SalDriverData)-1 110cdf0e10cSrcweir ) 111cdf0e10cSrcweir pRet = ((LPDEVMODEA)((pSetupData->mpDriverData) + (pDrv->mnDriverOffset))); 112cdf0e10cSrcweir return pRet; 113cdf0e10cSrcweir } 114cdf0e10cSrcweir 115cdf0e10cSrcweir static LPDEVMODEW SAL_DEVMODE_W( const ImplJobSetup* pSetupData ) 116cdf0e10cSrcweir { 117cdf0e10cSrcweir LPDEVMODEW pRet = NULL; 118cdf0e10cSrcweir SalDriverData* pDrv = (SalDriverData*)pSetupData->mpDriverData; 119cdf0e10cSrcweir if( pDrv->mnVersion == SAL_DRIVERDATA_VERSION_W && 120cdf0e10cSrcweir pSetupData->mnDriverDataLen >= sizeof(DEVMODEW)+sizeof(SalDriverData)-1 121cdf0e10cSrcweir ) 122cdf0e10cSrcweir pRet = ((LPDEVMODEW)((pSetupData->mpDriverData) + (pDrv->mnDriverOffset))); 123cdf0e10cSrcweir return pRet; 124cdf0e10cSrcweir } 125cdf0e10cSrcweir 126cdf0e10cSrcweir // ======================================================================= 127cdf0e10cSrcweir 128cdf0e10cSrcweir static sal_uLong ImplWinQueueStatusToSal( DWORD nWinStatus ) 129cdf0e10cSrcweir { 130cdf0e10cSrcweir sal_uLong nStatus = 0; 131cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_PAUSED ) 132cdf0e10cSrcweir nStatus |= QUEUE_STATUS_PAUSED; 133cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_ERROR ) 134cdf0e10cSrcweir nStatus |= QUEUE_STATUS_ERROR; 135cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_PENDING_DELETION ) 136cdf0e10cSrcweir nStatus |= QUEUE_STATUS_PENDING_DELETION; 137cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_PAPER_JAM ) 138cdf0e10cSrcweir nStatus |= QUEUE_STATUS_PAPER_JAM; 139cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_PAPER_OUT ) 140cdf0e10cSrcweir nStatus |= QUEUE_STATUS_PAPER_OUT; 141cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_MANUAL_FEED ) 142cdf0e10cSrcweir nStatus |= QUEUE_STATUS_MANUAL_FEED; 143cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_PAPER_PROBLEM ) 144cdf0e10cSrcweir nStatus |= QUEUE_STATUS_PAPER_PROBLEM; 145cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_OFFLINE ) 146cdf0e10cSrcweir nStatus |= QUEUE_STATUS_OFFLINE; 147cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_IO_ACTIVE ) 148cdf0e10cSrcweir nStatus |= QUEUE_STATUS_IO_ACTIVE; 149cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_BUSY ) 150cdf0e10cSrcweir nStatus |= QUEUE_STATUS_BUSY; 151cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_PRINTING ) 152cdf0e10cSrcweir nStatus |= QUEUE_STATUS_PRINTING; 153cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_OUTPUT_BIN_FULL ) 154cdf0e10cSrcweir nStatus |= QUEUE_STATUS_OUTPUT_BIN_FULL; 155cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_WAITING ) 156cdf0e10cSrcweir nStatus |= QUEUE_STATUS_WAITING; 157cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_PROCESSING ) 158cdf0e10cSrcweir nStatus |= QUEUE_STATUS_PROCESSING; 159cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_INITIALIZING ) 160cdf0e10cSrcweir nStatus |= QUEUE_STATUS_INITIALIZING; 161cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_WARMING_UP ) 162cdf0e10cSrcweir nStatus |= QUEUE_STATUS_WARMING_UP; 163cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_TONER_LOW ) 164cdf0e10cSrcweir nStatus |= QUEUE_STATUS_TONER_LOW; 165cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_NO_TONER ) 166cdf0e10cSrcweir nStatus |= QUEUE_STATUS_NO_TONER; 167cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_PAGE_PUNT ) 168cdf0e10cSrcweir nStatus |= QUEUE_STATUS_PAGE_PUNT; 169cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_USER_INTERVENTION ) 170cdf0e10cSrcweir nStatus |= QUEUE_STATUS_USER_INTERVENTION; 171cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_OUT_OF_MEMORY ) 172cdf0e10cSrcweir nStatus |= QUEUE_STATUS_OUT_OF_MEMORY; 173cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_DOOR_OPEN ) 174cdf0e10cSrcweir nStatus |= QUEUE_STATUS_DOOR_OPEN; 175cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_SERVER_UNKNOWN ) 176cdf0e10cSrcweir nStatus |= QUEUE_STATUS_SERVER_UNKNOWN; 177cdf0e10cSrcweir if ( nWinStatus & PRINTER_STATUS_POWER_SAVE ) 178cdf0e10cSrcweir nStatus |= QUEUE_STATUS_POWER_SAVE; 179cdf0e10cSrcweir if ( !nStatus && !(nWinStatus & PRINTER_STATUS_NOT_AVAILABLE) ) 180cdf0e10cSrcweir nStatus |= QUEUE_STATUS_READY; 181cdf0e10cSrcweir return nStatus; 182cdf0e10cSrcweir } 183cdf0e10cSrcweir 184cdf0e10cSrcweir // ----------------------------------------------------------------------- 185cdf0e10cSrcweir 186cdf0e10cSrcweir static void getPrinterQueueInfoOldStyle( ImplPrnQueueList* pList ) 187cdf0e10cSrcweir { 188cdf0e10cSrcweir DWORD i; 189cdf0e10cSrcweir DWORD n; 190cdf0e10cSrcweir DWORD nBytes = 0; 191cdf0e10cSrcweir DWORD nInfoPrn2; 192cdf0e10cSrcweir sal_Bool bFound = FALSE; 193cdf0e10cSrcweir PRINTER_INFO_2* pWinInfo2 = NULL; 194cdf0e10cSrcweir PRINTER_INFO_2* pGetInfo2; 195cdf0e10cSrcweir EnumPrintersA( PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &nBytes, &nInfoPrn2 ); 196cdf0e10cSrcweir if ( nBytes ) 197cdf0e10cSrcweir { 198cdf0e10cSrcweir pWinInfo2 = (PRINTER_INFO_2*) rtl_allocateMemory( nBytes ); 199cdf0e10cSrcweir if ( EnumPrintersA( PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pWinInfo2, nBytes, &nBytes, &nInfoPrn2 ) ) 200cdf0e10cSrcweir { 201cdf0e10cSrcweir pGetInfo2 = pWinInfo2; 202cdf0e10cSrcweir for ( i = 0; i < nInfoPrn2; i++ ) 203cdf0e10cSrcweir { 204cdf0e10cSrcweir SalPrinterQueueInfo* pInfo = new SalPrinterQueueInfo; 205cdf0e10cSrcweir pInfo->maPrinterName = ImplSalGetUniString( pGetInfo2->pPrinterName ); 206cdf0e10cSrcweir pInfo->maDriver = ImplSalGetUniString( pGetInfo2->pDriverName ); 207cdf0e10cSrcweir XubString aPortName; 208cdf0e10cSrcweir if ( pGetInfo2->pPortName ) 209cdf0e10cSrcweir aPortName = ImplSalGetUniString( pGetInfo2->pPortName ); 210cdf0e10cSrcweir // pLocation can be 0 (the Windows docu doesn't describe this) 211cdf0e10cSrcweir if ( pGetInfo2->pLocation && strlen( pGetInfo2->pLocation ) ) 212cdf0e10cSrcweir pInfo->maLocation = ImplSalGetUniString( pGetInfo2->pLocation ); 213cdf0e10cSrcweir else 214cdf0e10cSrcweir pInfo->maLocation = aPortName; 215cdf0e10cSrcweir // pComment can be 0 (the Windows docu doesn't describe this) 216cdf0e10cSrcweir if ( pGetInfo2->pComment ) 217cdf0e10cSrcweir pInfo->maComment = ImplSalGetUniString( pGetInfo2->pComment ); 218cdf0e10cSrcweir pInfo->mnStatus = ImplWinQueueStatusToSal( pGetInfo2->Status ); 219cdf0e10cSrcweir pInfo->mnJobs = pGetInfo2->cJobs; 220cdf0e10cSrcweir pInfo->mpSysData = new XubString( aPortName ); 221cdf0e10cSrcweir pList->Add( pInfo ); 222cdf0e10cSrcweir pGetInfo2++; 223cdf0e10cSrcweir } 224cdf0e10cSrcweir 225cdf0e10cSrcweir bFound = TRUE; 226cdf0e10cSrcweir } 227cdf0e10cSrcweir } 228cdf0e10cSrcweir 229cdf0e10cSrcweir // read printers from win.ini 230cdf0e10cSrcweir // TODO: MSDN: GetProfileString() should not be called from server 231cdf0e10cSrcweir // code because it is just there for WIN16 compatibility 232cdf0e10cSrcweir UINT nSize = 4096; 233cdf0e10cSrcweir char* pBuf = new char[nSize]; 234cdf0e10cSrcweir UINT nRead = GetProfileStringA( aImplDevices, NULL, "", pBuf, nSize ); 235cdf0e10cSrcweir while ( nRead >= nSize-2 ) 236cdf0e10cSrcweir { 237cdf0e10cSrcweir nSize += 2048; 238cdf0e10cSrcweir delete []pBuf; 239cdf0e10cSrcweir pBuf = new char[nSize]; 240cdf0e10cSrcweir nRead = GetProfileStringA( aImplDevices, NULL, "", pBuf, nSize ); 241cdf0e10cSrcweir } 242cdf0e10cSrcweir 243cdf0e10cSrcweir // extract printer names from buffer and fill list 244cdf0e10cSrcweir char* pName = pBuf; 245cdf0e10cSrcweir while ( *pName ) 246cdf0e10cSrcweir { 247cdf0e10cSrcweir char* pPortName; 248cdf0e10cSrcweir char* pTmp; 249cdf0e10cSrcweir char aPortBuf[256]; 250cdf0e10cSrcweir GetProfileStringA( aImplDevices, pName, "", aPortBuf, sizeof( aPortBuf ) ); 251cdf0e10cSrcweir 252cdf0e10cSrcweir pPortName = aPortBuf; 253cdf0e10cSrcweir 254cdf0e10cSrcweir // create name 255cdf0e10cSrcweir xub_StrLen nNameLen = sal::static_int_cast<xub_StrLen>(strlen( pName )); 256cdf0e10cSrcweir XubString aName( ImplSalGetUniString( pName, nNameLen ) ); 257cdf0e10cSrcweir 258cdf0e10cSrcweir // get driver name 259cdf0e10cSrcweir pTmp = pPortName; 260cdf0e10cSrcweir while ( *pTmp != ',' ) 261cdf0e10cSrcweir pTmp++; 262cdf0e10cSrcweir XubString aDriver( ImplSalGetUniString( pPortName, (sal_uInt16)(pTmp-pPortName) ) ); 263cdf0e10cSrcweir pPortName = pTmp; 264cdf0e10cSrcweir 265cdf0e10cSrcweir // get port names 266cdf0e10cSrcweir do 267cdf0e10cSrcweir { 268cdf0e10cSrcweir pPortName++; 269cdf0e10cSrcweir pTmp = pPortName; 270cdf0e10cSrcweir while ( *pTmp && (*pTmp != ',') ) 271cdf0e10cSrcweir pTmp++; 272cdf0e10cSrcweir 273cdf0e10cSrcweir String aPortName( ImplSalGetUniString( pPortName, (sal_uInt16)(pTmp-pPortName) ) ); 274cdf0e10cSrcweir 275cdf0e10cSrcweir // create new entry 276cdf0e10cSrcweir // look up if printer was already found in first loop 277cdf0e10cSrcweir sal_Bool bAdd = TRUE; 278cdf0e10cSrcweir if ( pWinInfo2 ) 279cdf0e10cSrcweir { 280cdf0e10cSrcweir pGetInfo2 = pWinInfo2; 281cdf0e10cSrcweir for ( n = 0; n < nInfoPrn2; n++ ) 282cdf0e10cSrcweir { 283cdf0e10cSrcweir if ( aName.EqualsIgnoreCaseAscii( pGetInfo2->pPrinterName ) ) 284cdf0e10cSrcweir { 285cdf0e10cSrcweir bAdd = FALSE; 286cdf0e10cSrcweir break; 287cdf0e10cSrcweir } 288cdf0e10cSrcweir pGetInfo2++; 289cdf0e10cSrcweir } 290cdf0e10cSrcweir } 291cdf0e10cSrcweir // if it's a new printer, add it 292cdf0e10cSrcweir if ( bAdd ) 293cdf0e10cSrcweir { 294cdf0e10cSrcweir SalPrinterQueueInfo* pInfo = new SalPrinterQueueInfo; 295cdf0e10cSrcweir pInfo->maPrinterName = aName; 296cdf0e10cSrcweir pInfo->maDriver = aDriver; 297cdf0e10cSrcweir pInfo->maLocation = aPortName; 298cdf0e10cSrcweir pInfo->mnStatus = 0; 299cdf0e10cSrcweir pInfo->mnJobs = QUEUE_JOBS_DONTKNOW; 300cdf0e10cSrcweir pInfo->mpSysData = new XubString( aPortName ); 301cdf0e10cSrcweir pList->Add( pInfo ); 302cdf0e10cSrcweir } 303cdf0e10cSrcweir } 304cdf0e10cSrcweir while ( *pTmp == ',' ); 305cdf0e10cSrcweir 306cdf0e10cSrcweir pName += nNameLen + 1; 307cdf0e10cSrcweir } 308cdf0e10cSrcweir 309cdf0e10cSrcweir delete []pBuf; 310cdf0e10cSrcweir rtl_freeMemory( pWinInfo2 ); 311cdf0e10cSrcweir } 312cdf0e10cSrcweir 313cdf0e10cSrcweir void WinSalInstance::GetPrinterQueueInfo( ImplPrnQueueList* pList ) 314cdf0e10cSrcweir { 315cdf0e10cSrcweir if( ! aSalShlData.mbWPrinter ) 316cdf0e10cSrcweir { 317cdf0e10cSrcweir getPrinterQueueInfoOldStyle( pList ); 318cdf0e10cSrcweir return; 319cdf0e10cSrcweir } 320cdf0e10cSrcweir DWORD i; 321cdf0e10cSrcweir DWORD nBytes = 0; 322cdf0e10cSrcweir DWORD nInfoPrn4 = 0; 323cdf0e10cSrcweir PRINTER_INFO_4W* pWinInfo4 = NULL; 324cdf0e10cSrcweir EnumPrintersW( PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, NULL, 0, &nBytes, &nInfoPrn4 ); 325cdf0e10cSrcweir if ( nBytes ) 326cdf0e10cSrcweir { 327cdf0e10cSrcweir pWinInfo4 = (PRINTER_INFO_4W*) rtl_allocateMemory( nBytes ); 328cdf0e10cSrcweir if ( EnumPrintersW( PRINTER_ENUM_LOCAL | PRINTER_ENUM_CONNECTIONS, NULL, 4, (LPBYTE)pWinInfo4, nBytes, &nBytes, &nInfoPrn4 ) ) 329cdf0e10cSrcweir { 330cdf0e10cSrcweir for ( i = 0; i < nInfoPrn4; i++ ) 331cdf0e10cSrcweir { 332cdf0e10cSrcweir SalPrinterQueueInfo* pInfo = new SalPrinterQueueInfo; 333cdf0e10cSrcweir pInfo->maPrinterName = UniString( reinterpret_cast< const sal_Unicode* >(pWinInfo4[i].pPrinterName) ); 334cdf0e10cSrcweir pInfo->mnStatus = 0; 335cdf0e10cSrcweir pInfo->mnJobs = 0; 336cdf0e10cSrcweir pInfo->mpSysData = NULL; 337cdf0e10cSrcweir pList->Add( pInfo ); 338cdf0e10cSrcweir } 339cdf0e10cSrcweir } 340cdf0e10cSrcweir rtl_freeMemory( pWinInfo4 ); 341cdf0e10cSrcweir } 342cdf0e10cSrcweir } 343cdf0e10cSrcweir 344cdf0e10cSrcweir // ----------------------------------------------------------------------- 345cdf0e10cSrcweir 346cdf0e10cSrcweir static void getPrinterQueueStateOldStyle( SalPrinterQueueInfo* pInfo ) 347cdf0e10cSrcweir { 348cdf0e10cSrcweir DWORD nBytes = 0; 349cdf0e10cSrcweir DWORD nInfoRet; 350cdf0e10cSrcweir PRINTER_INFO_2* pWinInfo2; 351cdf0e10cSrcweir EnumPrintersA( PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &nBytes, &nInfoRet ); 352cdf0e10cSrcweir if ( nBytes ) 353cdf0e10cSrcweir { 354cdf0e10cSrcweir pWinInfo2 = (PRINTER_INFO_2*) rtl_allocateMemory( nBytes ); 355cdf0e10cSrcweir if ( EnumPrintersA( PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pWinInfo2, nBytes, &nBytes, &nInfoRet ) ) 356cdf0e10cSrcweir { 357cdf0e10cSrcweir PRINTER_INFO_2* pGetInfo2 = pWinInfo2; 358cdf0e10cSrcweir for ( DWORD i = 0; i < nInfoRet; i++ ) 359cdf0e10cSrcweir { 360cdf0e10cSrcweir if ( pInfo->maPrinterName.EqualsAscii( pGetInfo2->pPrinterName ) && 361cdf0e10cSrcweir ( pInfo->maDriver.Len() == 0 || 362cdf0e10cSrcweir pInfo->maDriver.EqualsAscii( pGetInfo2->pDriverName ) ) 363cdf0e10cSrcweir ) 364cdf0e10cSrcweir { 365cdf0e10cSrcweir XubString aPortName; 366cdf0e10cSrcweir if ( pGetInfo2->pPortName ) 367cdf0e10cSrcweir aPortName = ImplSalGetUniString( pGetInfo2->pPortName ); 368cdf0e10cSrcweir // pLocation can be 0 (the Windows docu doesn't describe this) 369cdf0e10cSrcweir if ( pGetInfo2->pLocation && strlen( pGetInfo2->pLocation ) ) 370cdf0e10cSrcweir pInfo->maLocation = ImplSalGetUniString( pGetInfo2->pLocation ); 371cdf0e10cSrcweir else 372cdf0e10cSrcweir pInfo->maLocation = aPortName; 373cdf0e10cSrcweir // pComment can be 0 (the Windows docu doesn't describe this) 374cdf0e10cSrcweir if ( pGetInfo2->pComment ) 375cdf0e10cSrcweir pInfo->maComment = ImplSalGetUniString( pGetInfo2->pComment ); 376cdf0e10cSrcweir pInfo->mnStatus = ImplWinQueueStatusToSal( pGetInfo2->Status ); 377cdf0e10cSrcweir pInfo->mnJobs = pGetInfo2->cJobs; 378cdf0e10cSrcweir if( ! pInfo->mpSysData ) 379cdf0e10cSrcweir pInfo->mpSysData = new XubString( aPortName ); 380cdf0e10cSrcweir break; 381cdf0e10cSrcweir } 382cdf0e10cSrcweir 383cdf0e10cSrcweir pGetInfo2++; 384cdf0e10cSrcweir } 385cdf0e10cSrcweir } 386cdf0e10cSrcweir 387cdf0e10cSrcweir rtl_freeMemory( pWinInfo2 ); 388cdf0e10cSrcweir } 389cdf0e10cSrcweir } 390cdf0e10cSrcweir 391cdf0e10cSrcweir void WinSalInstance::GetPrinterQueueState( SalPrinterQueueInfo* pInfo ) 392cdf0e10cSrcweir { 393cdf0e10cSrcweir if( ! aSalShlData.mbWPrinter ) 394cdf0e10cSrcweir { 395cdf0e10cSrcweir getPrinterQueueStateOldStyle( pInfo ); 396cdf0e10cSrcweir return; 397cdf0e10cSrcweir } 398cdf0e10cSrcweir 399cdf0e10cSrcweir HANDLE hPrinter = 0; 400cdf0e10cSrcweir LPWSTR pPrnName = reinterpret_cast<LPWSTR>(const_cast<sal_Unicode*>(pInfo->maPrinterName.GetBuffer())); 401cdf0e10cSrcweir if( OpenPrinterW( pPrnName, &hPrinter, NULL ) ) 402cdf0e10cSrcweir { 403cdf0e10cSrcweir DWORD nBytes = 0; 404cdf0e10cSrcweir GetPrinterW( hPrinter, 2, NULL, 0, &nBytes ); 405cdf0e10cSrcweir if( nBytes ) 406cdf0e10cSrcweir { 407cdf0e10cSrcweir PRINTER_INFO_2W* pWinInfo2 = (PRINTER_INFO_2W*)rtl_allocateMemory(nBytes); 408cdf0e10cSrcweir if( GetPrinterW( hPrinter, 2, (LPBYTE)pWinInfo2, nBytes, &nBytes ) ) 409cdf0e10cSrcweir { 410cdf0e10cSrcweir if( pWinInfo2->pDriverName ) 411cdf0e10cSrcweir pInfo->maDriver = String( reinterpret_cast< const sal_Unicode* >(pWinInfo2->pDriverName) ); 412cdf0e10cSrcweir XubString aPortName; 413cdf0e10cSrcweir if ( pWinInfo2->pPortName ) 414cdf0e10cSrcweir aPortName = String( reinterpret_cast< const sal_Unicode* >(pWinInfo2->pPortName) ); 415cdf0e10cSrcweir // pLocation can be 0 (the Windows docu doesn't describe this) 416cdf0e10cSrcweir if ( pWinInfo2->pLocation && *pWinInfo2->pLocation ) 417cdf0e10cSrcweir pInfo->maLocation = String( reinterpret_cast< const sal_Unicode* >(pWinInfo2->pLocation) ); 418cdf0e10cSrcweir else 419cdf0e10cSrcweir pInfo->maLocation = aPortName; 420cdf0e10cSrcweir // pComment can be 0 (the Windows docu doesn't describe this) 421cdf0e10cSrcweir if ( pWinInfo2->pComment ) 422cdf0e10cSrcweir pInfo->maComment = String( reinterpret_cast< const sal_Unicode* >(pWinInfo2->pComment) ); 423cdf0e10cSrcweir pInfo->mnStatus = ImplWinQueueStatusToSal( pWinInfo2->Status ); 424cdf0e10cSrcweir pInfo->mnJobs = pWinInfo2->cJobs; 425cdf0e10cSrcweir if( ! pInfo->mpSysData ) 426cdf0e10cSrcweir pInfo->mpSysData = new XubString( aPortName ); 427cdf0e10cSrcweir } 428cdf0e10cSrcweir rtl_freeMemory(pWinInfo2); 429cdf0e10cSrcweir } 430cdf0e10cSrcweir ClosePrinter( hPrinter ); 431cdf0e10cSrcweir } 432cdf0e10cSrcweir } 433cdf0e10cSrcweir 434cdf0e10cSrcweir // ----------------------------------------------------------------------- 435cdf0e10cSrcweir 436cdf0e10cSrcweir void WinSalInstance::DeletePrinterQueueInfo( SalPrinterQueueInfo* pInfo ) 437cdf0e10cSrcweir { 438cdf0e10cSrcweir delete (String*)(pInfo->mpSysData); 439cdf0e10cSrcweir delete pInfo; 440cdf0e10cSrcweir } 441cdf0e10cSrcweir 442cdf0e10cSrcweir // ----------------------------------------------------------------------- 443cdf0e10cSrcweir XubString WinSalInstance::GetDefaultPrinter() 444cdf0e10cSrcweir { 445cdf0e10cSrcweir static bool bGetDefPrtAPI = true; 446cdf0e10cSrcweir static sal_Bool(WINAPI*pGetDefaultPrinter)(LPWSTR,LPDWORD) = NULL; 447cdf0e10cSrcweir // try to use GetDefaultPrinter API (not available prior to W2000) 448cdf0e10cSrcweir if( bGetDefPrtAPI ) 449cdf0e10cSrcweir { 450cdf0e10cSrcweir bGetDefPrtAPI = false; 451cdf0e10cSrcweir // check for W2k and XP 452cdf0e10cSrcweir if( aSalShlData.maVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT && aSalShlData.maVersionInfo.dwMajorVersion >= 5 ) 453cdf0e10cSrcweir { 454cdf0e10cSrcweir OUString aLibraryName( RTL_CONSTASCII_USTRINGPARAM( "winspool.drv" ) ); 455cdf0e10cSrcweir oslModule pLib = osl_loadModule( aLibraryName.pData, SAL_LOADMODULE_DEFAULT ); 456cdf0e10cSrcweir oslGenericFunction pFunc = NULL; 457cdf0e10cSrcweir if( pLib ) 458cdf0e10cSrcweir { 459cdf0e10cSrcweir OUString queryFuncName( RTL_CONSTASCII_USTRINGPARAM( "GetDefaultPrinterW" ) ); 460cdf0e10cSrcweir pFunc = osl_getFunctionSymbol( pLib, queryFuncName.pData ); 461cdf0e10cSrcweir } 462cdf0e10cSrcweir 463cdf0e10cSrcweir pGetDefaultPrinter = (sal_Bool(WINAPI*)(LPWSTR,LPDWORD)) pFunc; 464cdf0e10cSrcweir } 465cdf0e10cSrcweir } 466cdf0e10cSrcweir if( pGetDefaultPrinter ) 467cdf0e10cSrcweir { 468cdf0e10cSrcweir DWORD nChars = 0; 469cdf0e10cSrcweir pGetDefaultPrinter( NULL, &nChars ); 470cdf0e10cSrcweir if( nChars ) 471cdf0e10cSrcweir { 472cdf0e10cSrcweir LPWSTR pStr = (LPWSTR)rtl_allocateMemory(nChars*sizeof(WCHAR)); 473cdf0e10cSrcweir XubString aDefPrt; 474cdf0e10cSrcweir if( pGetDefaultPrinter( pStr, &nChars ) ) 475cdf0e10cSrcweir { 476cdf0e10cSrcweir aDefPrt = reinterpret_cast<sal_Unicode* >(pStr); 477cdf0e10cSrcweir } 478cdf0e10cSrcweir rtl_freeMemory( pStr ); 479cdf0e10cSrcweir if( aDefPrt.Len() ) 480cdf0e10cSrcweir return aDefPrt; 481cdf0e10cSrcweir } 482cdf0e10cSrcweir } 483cdf0e10cSrcweir 484cdf0e10cSrcweir // get default printer from win.ini 485cdf0e10cSrcweir char szBuffer[256]; 486cdf0e10cSrcweir GetProfileStringA( aImplWindows, aImplDevice, "", szBuffer, sizeof( szBuffer ) ); 487cdf0e10cSrcweir if ( szBuffer[0] ) 488cdf0e10cSrcweir { 489cdf0e10cSrcweir // Printername suchen 490cdf0e10cSrcweir char* pBuf = szBuffer; 491cdf0e10cSrcweir char* pTmp = pBuf; 492cdf0e10cSrcweir while ( *pTmp && (*pTmp != ',') ) 493cdf0e10cSrcweir pTmp++; 494cdf0e10cSrcweir return ImplSalGetUniString( pBuf, (xub_StrLen)(pTmp-pBuf) ); 495cdf0e10cSrcweir } 496cdf0e10cSrcweir else 497cdf0e10cSrcweir return XubString(); 498cdf0e10cSrcweir } 499cdf0e10cSrcweir 500cdf0e10cSrcweir // ======================================================================= 501cdf0e10cSrcweir 502cdf0e10cSrcweir static DWORD ImplDeviceCaps( WinSalInfoPrinter* pPrinter, WORD nCaps, 503cdf0e10cSrcweir BYTE* pOutput, const ImplJobSetup* pSetupData ) 504cdf0e10cSrcweir { 505cdf0e10cSrcweir if( aSalShlData.mbWPrinter ) 506cdf0e10cSrcweir { 507cdf0e10cSrcweir DEVMODEW* pDevMode; 508cdf0e10cSrcweir if ( !pSetupData || !pSetupData->mpDriverData ) 509cdf0e10cSrcweir pDevMode = NULL; 510cdf0e10cSrcweir else 511cdf0e10cSrcweir pDevMode = SAL_DEVMODE_W( pSetupData ); 512cdf0e10cSrcweir 513cdf0e10cSrcweir return DeviceCapabilitiesW( reinterpret_cast<LPCWSTR>(pPrinter->maDeviceName.GetBuffer()), 514cdf0e10cSrcweir reinterpret_cast<LPCWSTR>(pPrinter->maPortName.GetBuffer()), 515cdf0e10cSrcweir nCaps, (LPWSTR)pOutput, pDevMode ); 516cdf0e10cSrcweir } 517cdf0e10cSrcweir else 518cdf0e10cSrcweir { 519cdf0e10cSrcweir DEVMODEA* pDevMode; 520cdf0e10cSrcweir if ( !pSetupData || !pSetupData->mpDriverData ) 521cdf0e10cSrcweir pDevMode = NULL; 522cdf0e10cSrcweir else 523cdf0e10cSrcweir pDevMode = SAL_DEVMODE_A( pSetupData ); 524cdf0e10cSrcweir 525cdf0e10cSrcweir return DeviceCapabilitiesA( ImplSalGetWinAnsiString( pPrinter->maDeviceName, TRUE ).GetBuffer(), 526cdf0e10cSrcweir ImplSalGetWinAnsiString( pPrinter->maPortName, TRUE ).GetBuffer(), 527cdf0e10cSrcweir nCaps, (LPSTR)pOutput, pDevMode ); 528cdf0e10cSrcweir } 529cdf0e10cSrcweir } 530cdf0e10cSrcweir 531cdf0e10cSrcweir // ----------------------------------------------------------------------- 532cdf0e10cSrcweir 533cdf0e10cSrcweir static sal_Bool ImplTestSalJobSetup( WinSalInfoPrinter* pPrinter, 534cdf0e10cSrcweir ImplJobSetup* pSetupData, sal_Bool bDelete ) 535cdf0e10cSrcweir { 536cdf0e10cSrcweir if ( pSetupData && pSetupData->mpDriverData ) 537cdf0e10cSrcweir { 538cdf0e10cSrcweir // signature and size must fit to avoid using 539cdf0e10cSrcweir // JobSetups from a wrong system 540cdf0e10cSrcweir 541cdf0e10cSrcweir // initialize versions from jobsetup 542cdf0e10cSrcweir // those will be overwritten with driver's version 543cdf0e10cSrcweir DEVMODEA* pDevModeA = NULL; 544cdf0e10cSrcweir DEVMODEW* pDevModeW = NULL; 545cdf0e10cSrcweir LONG dmSpecVersion = -1; 546cdf0e10cSrcweir LONG dmDriverVersion = -1; 547cdf0e10cSrcweir SalDriverData* pSalDriverData = (SalDriverData*)pSetupData->mpDriverData; 548cdf0e10cSrcweir BYTE* pDriverData = ((BYTE*)pSalDriverData) + pSalDriverData->mnDriverOffset; 549cdf0e10cSrcweir if( pSalDriverData->mnVersion == SAL_DRIVERDATA_VERSION_W ) 550cdf0e10cSrcweir { 551cdf0e10cSrcweir if( aSalShlData.mbWPrinter ) 552cdf0e10cSrcweir pDevModeW = (DEVMODEW*)pDriverData; 553cdf0e10cSrcweir } 554cdf0e10cSrcweir else if( pSalDriverData->mnVersion == SAL_DRIVERDATA_VERSION_A ) 555cdf0e10cSrcweir { 556cdf0e10cSrcweir if( ! aSalShlData.mbWPrinter ) 557cdf0e10cSrcweir pDevModeA = (DEVMODEA*)pDriverData; 558cdf0e10cSrcweir } 559cdf0e10cSrcweir 560cdf0e10cSrcweir long nSysJobSize = -1; 561cdf0e10cSrcweir if( pPrinter && ( pDevModeA || pDevModeW ) ) 562cdf0e10cSrcweir { 563cdf0e10cSrcweir // just too many driver crashes in that area -> check the dmSpecVersion and dmDriverVersion fields always !!! 564cdf0e10cSrcweir // this prevents using the jobsetup between different Windows versions (eg from XP to 9x) but we 565cdf0e10cSrcweir // can avoid potential driver crashes as their jobsetups are often not compatible 566cdf0e10cSrcweir // #110800#, #111151#, #112381#, #i16580#, #i14173# and perhaps #112375# 567cdf0e10cSrcweir ByteString aPrinterNameA= ImplSalGetWinAnsiString( pPrinter->maDeviceName, TRUE ); 568cdf0e10cSrcweir HANDLE hPrn; 569cdf0e10cSrcweir LPWSTR pPrinterNameW = reinterpret_cast<LPWSTR>(const_cast<sal_Unicode*>(pPrinter->maDeviceName.GetBuffer())); 570cdf0e10cSrcweir if ( ! aSalShlData.mbWPrinter ) 571cdf0e10cSrcweir { 572cdf0e10cSrcweir if ( !OpenPrinterA( (LPSTR)aPrinterNameA.GetBuffer(), &hPrn, NULL ) ) 573cdf0e10cSrcweir return FALSE; 574cdf0e10cSrcweir } 575cdf0e10cSrcweir else 576cdf0e10cSrcweir if ( !OpenPrinterW( pPrinterNameW, &hPrn, NULL ) ) 577cdf0e10cSrcweir return FALSE; 578cdf0e10cSrcweir 579cdf0e10cSrcweir // #131642# hPrn==HGDI_ERROR even though OpenPrinter() succeeded! 580cdf0e10cSrcweir if( hPrn == HGDI_ERROR ) 581cdf0e10cSrcweir return FALSE; 582cdf0e10cSrcweir 583cdf0e10cSrcweir if( aSalShlData.mbWPrinter ) 584cdf0e10cSrcweir { 585cdf0e10cSrcweir nSysJobSize = DocumentPropertiesW( 0, hPrn, 586cdf0e10cSrcweir pPrinterNameW, 587cdf0e10cSrcweir NULL, NULL, 0 ); 588cdf0e10cSrcweir } 589cdf0e10cSrcweir else 590cdf0e10cSrcweir { 591cdf0e10cSrcweir nSysJobSize = DocumentPropertiesA( 0, hPrn, 592cdf0e10cSrcweir (LPSTR)aPrinterNameA.GetBuffer(), 593cdf0e10cSrcweir NULL, NULL, 0 ); 594cdf0e10cSrcweir } 595cdf0e10cSrcweir 596cdf0e10cSrcweir if( nSysJobSize < 0 ) 597cdf0e10cSrcweir { 598cdf0e10cSrcweir ClosePrinter( hPrn ); 599cdf0e10cSrcweir return FALSE; 600cdf0e10cSrcweir } 601cdf0e10cSrcweir BYTE *pBuffer = (BYTE*)_alloca( nSysJobSize ); 602cdf0e10cSrcweir LONG nRet = -1; 603cdf0e10cSrcweir if( aSalShlData.mbWPrinter ) 604cdf0e10cSrcweir { 605cdf0e10cSrcweir nRet = DocumentPropertiesW( 0, hPrn, 606cdf0e10cSrcweir pPrinterNameW, 607cdf0e10cSrcweir (LPDEVMODEW)pBuffer, NULL, DM_OUT_BUFFER ); 608cdf0e10cSrcweir } 609cdf0e10cSrcweir else 610cdf0e10cSrcweir { 611cdf0e10cSrcweir nRet = DocumentPropertiesA( 0, hPrn, 612cdf0e10cSrcweir (LPSTR)aPrinterNameA.GetBuffer(), 613cdf0e10cSrcweir (LPDEVMODEA)pBuffer, NULL, DM_OUT_BUFFER ); 614cdf0e10cSrcweir } 615cdf0e10cSrcweir if( nRet < 0 ) 616cdf0e10cSrcweir { 617cdf0e10cSrcweir ClosePrinter( hPrn ); 618cdf0e10cSrcweir return FALSE; 619cdf0e10cSrcweir } 620cdf0e10cSrcweir 621cdf0e10cSrcweir // the spec version differs between the windows platforms, ie 98,NT,2000/XP 622cdf0e10cSrcweir // this allows us to throw away printer settings from other platforms that might crash a buggy driver 623cdf0e10cSrcweir // we check the driver version as well 624cdf0e10cSrcweir dmSpecVersion = aSalShlData.mbWPrinter ? ((DEVMODEW*)pBuffer)->dmSpecVersion : ((DEVMODEA*)pBuffer)->dmSpecVersion; 625cdf0e10cSrcweir dmDriverVersion = aSalShlData.mbWPrinter ? ((DEVMODEW*)pBuffer)->dmDriverVersion : ((DEVMODEA*)pBuffer)->dmDriverVersion; 626cdf0e10cSrcweir 627cdf0e10cSrcweir ClosePrinter( hPrn ); 628cdf0e10cSrcweir } 629cdf0e10cSrcweir SalDriverData* pSetupDriverData = (SalDriverData*)(pSetupData->mpDriverData); 630cdf0e10cSrcweir if ( (pSetupData->mnSystem == JOBSETUP_SYSTEM_WINDOWS) && 631cdf0e10cSrcweir (pPrinter->maDriverName == pSetupData->maDriver) && 632cdf0e10cSrcweir (pSetupData->mnDriverDataLen > sizeof( SalDriverData )) && 633cdf0e10cSrcweir (long)(pSetupData->mnDriverDataLen - pSetupDriverData->mnDriverOffset) == nSysJobSize && 634cdf0e10cSrcweir pSetupDriverData->mnSysSignature == SAL_DRIVERDATA_SYSSIGN ) 635cdf0e10cSrcweir { 636cdf0e10cSrcweir if( pDevModeA && 637cdf0e10cSrcweir (dmSpecVersion == pDevModeA->dmSpecVersion) && 638cdf0e10cSrcweir (dmDriverVersion == pDevModeA->dmDriverVersion) ) 639cdf0e10cSrcweir return TRUE; 640cdf0e10cSrcweir if( pDevModeW && 641cdf0e10cSrcweir (dmSpecVersion == pDevModeW->dmSpecVersion) && 642cdf0e10cSrcweir (dmDriverVersion == pDevModeW->dmDriverVersion) ) 643cdf0e10cSrcweir return TRUE; 644cdf0e10cSrcweir } 645cdf0e10cSrcweir if ( bDelete ) 646cdf0e10cSrcweir { 647cdf0e10cSrcweir rtl_freeMemory( pSetupData->mpDriverData ); 648cdf0e10cSrcweir pSetupData->mpDriverData = NULL; 649cdf0e10cSrcweir pSetupData->mnDriverDataLen = 0; 650cdf0e10cSrcweir } 651cdf0e10cSrcweir } 652cdf0e10cSrcweir 653cdf0e10cSrcweir return FALSE; 654cdf0e10cSrcweir } 655cdf0e10cSrcweir 656cdf0e10cSrcweir // ----------------------------------------------------------------------- 657cdf0e10cSrcweir 658cdf0e10cSrcweir static sal_Bool ImplUpdateSalJobSetup( WinSalInfoPrinter* pPrinter, ImplJobSetup* pSetupData, 659cdf0e10cSrcweir sal_Bool bIn, WinSalFrame* pVisibleDlgParent ) 660cdf0e10cSrcweir { 661cdf0e10cSrcweir ByteString aPrinterNameA = ImplSalGetWinAnsiString( pPrinter->maDeviceName, TRUE ); 662cdf0e10cSrcweir HANDLE hPrn; 663cdf0e10cSrcweir LPWSTR pPrinterNameW = reinterpret_cast<LPWSTR>(const_cast<sal_Unicode*>(pPrinter->maDeviceName.GetBuffer())); 664cdf0e10cSrcweir if( aSalShlData.mbWPrinter ) 665cdf0e10cSrcweir { 666cdf0e10cSrcweir if ( !OpenPrinterW( pPrinterNameW, &hPrn, NULL ) ) 667cdf0e10cSrcweir return FALSE; 668cdf0e10cSrcweir } 669cdf0e10cSrcweir else 670cdf0e10cSrcweir { 671cdf0e10cSrcweir if ( !OpenPrinterA( (LPSTR)aPrinterNameA.GetBuffer(), &hPrn, NULL ) ) 672cdf0e10cSrcweir return FALSE; 673cdf0e10cSrcweir } 674cdf0e10cSrcweir // #131642# hPrn==HGDI_ERROR even though OpenPrinter() succeeded! 675cdf0e10cSrcweir if( hPrn == HGDI_ERROR ) 676cdf0e10cSrcweir return FALSE; 677cdf0e10cSrcweir 678cdf0e10cSrcweir LONG nRet; 679cdf0e10cSrcweir LONG nSysJobSize = -1; 680cdf0e10cSrcweir HWND hWnd = 0; 681cdf0e10cSrcweir DWORD nMode = DM_OUT_BUFFER; 682cdf0e10cSrcweir sal_uLong nDriverDataLen = 0; 683cdf0e10cSrcweir SalDriverData* pOutBuffer = NULL; 684cdf0e10cSrcweir BYTE* pInBuffer = NULL; 685cdf0e10cSrcweir 686cdf0e10cSrcweir if( aSalShlData.mbWPrinter ) 687cdf0e10cSrcweir { 688cdf0e10cSrcweir nSysJobSize = DocumentPropertiesW( hWnd, hPrn, 689cdf0e10cSrcweir pPrinterNameW, 690cdf0e10cSrcweir NULL, NULL, 0 ); 691cdf0e10cSrcweir } 692cdf0e10cSrcweir else 693cdf0e10cSrcweir nSysJobSize = DocumentPropertiesA( hWnd, hPrn, 694cdf0e10cSrcweir (LPSTR)ImplSalGetWinAnsiString( pPrinter->maDeviceName, TRUE ).GetBuffer(), 695cdf0e10cSrcweir NULL, NULL, 0 ); 696cdf0e10cSrcweir if ( nSysJobSize < 0 ) 697cdf0e10cSrcweir { 698cdf0e10cSrcweir ClosePrinter( hPrn ); 699cdf0e10cSrcweir return FALSE; 700cdf0e10cSrcweir } 701cdf0e10cSrcweir 702cdf0e10cSrcweir // Outputbuffer anlegen 703cdf0e10cSrcweir nDriverDataLen = sizeof(SalDriverData) + nSysJobSize-1; 704cdf0e10cSrcweir pOutBuffer = (SalDriverData*)rtl_allocateZeroMemory( nDriverDataLen ); 705cdf0e10cSrcweir pOutBuffer->mnSysSignature = SAL_DRIVERDATA_SYSSIGN; 706cdf0e10cSrcweir pOutBuffer->mnVersion = aSalShlData.mbWPrinter ? SAL_DRIVERDATA_VERSION_W : SAL_DRIVERDATA_VERSION_A; 707cdf0e10cSrcweir // calculate driver data offset including structure padding 708cdf0e10cSrcweir pOutBuffer->mnDriverOffset = sal::static_int_cast<sal_uInt16>( 709cdf0e10cSrcweir (char*)pOutBuffer->maDriverData - 710cdf0e10cSrcweir (char*)pOutBuffer ); 711cdf0e10cSrcweir 712cdf0e10cSrcweir // Testen, ob wir einen geeigneten Inputbuffer haben 713cdf0e10cSrcweir if ( bIn && ImplTestSalJobSetup( pPrinter, pSetupData, FALSE ) ) 714cdf0e10cSrcweir { 715cdf0e10cSrcweir pInBuffer = (BYTE*)pSetupData->mpDriverData + ((SalDriverData*)pSetupData->mpDriverData)->mnDriverOffset; 716cdf0e10cSrcweir nMode |= DM_IN_BUFFER; 717cdf0e10cSrcweir } 718cdf0e10cSrcweir 719cdf0e10cSrcweir // Testen, ob Dialog angezeigt werden soll 720cdf0e10cSrcweir if ( pVisibleDlgParent ) 721cdf0e10cSrcweir { 722cdf0e10cSrcweir hWnd = pVisibleDlgParent->mhWnd; 723cdf0e10cSrcweir nMode |= DM_IN_PROMPT; 724cdf0e10cSrcweir } 725cdf0e10cSrcweir 726cdf0e10cSrcweir // Release mutex, in the other case we don't get paints and so on 727cdf0e10cSrcweir sal_uLong nMutexCount=0; 728cdf0e10cSrcweir if ( pVisibleDlgParent ) 729cdf0e10cSrcweir nMutexCount = ImplSalReleaseYieldMutex(); 730cdf0e10cSrcweir 731cdf0e10cSrcweir BYTE* pOutDevMode = (((BYTE*)pOutBuffer) + pOutBuffer->mnDriverOffset); 732cdf0e10cSrcweir if( aSalShlData.mbWPrinter ) 733cdf0e10cSrcweir { 734cdf0e10cSrcweir nRet = DocumentPropertiesW( hWnd, hPrn, 735cdf0e10cSrcweir pPrinterNameW, 736cdf0e10cSrcweir (LPDEVMODEW)pOutDevMode, (LPDEVMODEW)pInBuffer, nMode ); 737cdf0e10cSrcweir } 738cdf0e10cSrcweir else 739cdf0e10cSrcweir { 740cdf0e10cSrcweir nRet = DocumentPropertiesA( hWnd, hPrn, 741cdf0e10cSrcweir (LPSTR)ImplSalGetWinAnsiString( pPrinter->maDeviceName, TRUE ).GetBuffer(), 742cdf0e10cSrcweir (LPDEVMODEA)pOutDevMode, (LPDEVMODEA)pInBuffer, nMode ); 743cdf0e10cSrcweir } 744cdf0e10cSrcweir if ( pVisibleDlgParent ) 745cdf0e10cSrcweir ImplSalAcquireYieldMutex( nMutexCount ); 746cdf0e10cSrcweir ClosePrinter( hPrn ); 747cdf0e10cSrcweir 748cdf0e10cSrcweir if( (nRet < 0) || (pVisibleDlgParent && (nRet == IDCANCEL)) ) 749cdf0e10cSrcweir { 750cdf0e10cSrcweir rtl_freeMemory( pOutBuffer ); 751cdf0e10cSrcweir return FALSE; 752cdf0e10cSrcweir } 753cdf0e10cSrcweir 754cdf0e10cSrcweir // fill up string buffers with 0 so they do not influence a JobSetup's memcmp 755cdf0e10cSrcweir if( aSalShlData.mbWPrinter ) 756cdf0e10cSrcweir { 757cdf0e10cSrcweir if( ((LPDEVMODEW)pOutDevMode)->dmSize >= 64 ) 758cdf0e10cSrcweir { 759cdf0e10cSrcweir sal_Int32 nLen = rtl_ustr_getLength( (const sal_Unicode*)((LPDEVMODEW)pOutDevMode)->dmDeviceName ); 760cdf0e10cSrcweir if ( nLen < sizeof( ((LPDEVMODEW)pOutDevMode)->dmDeviceName )/sizeof(sal_Unicode) ) 761cdf0e10cSrcweir memset( ((LPDEVMODEW)pOutDevMode)->dmDeviceName+nLen, 0, sizeof( ((LPDEVMODEW)pOutDevMode)->dmDeviceName )-(nLen*sizeof(sal_Unicode)) ); 762cdf0e10cSrcweir } 763cdf0e10cSrcweir if( ((LPDEVMODEW)pOutDevMode)->dmSize >= 166 ) 764cdf0e10cSrcweir { 765cdf0e10cSrcweir sal_Int32 nLen = rtl_ustr_getLength( (const sal_Unicode*)((LPDEVMODEW)pOutDevMode)->dmFormName ); 766cdf0e10cSrcweir if ( nLen < sizeof( ((LPDEVMODEW)pOutDevMode)->dmFormName )/sizeof(sal_Unicode) ) 767cdf0e10cSrcweir memset( ((LPDEVMODEW)pOutDevMode)->dmFormName+nLen, 0, sizeof( ((LPDEVMODEW)pOutDevMode)->dmFormName )-(nLen*sizeof(sal_Unicode)) ); 768cdf0e10cSrcweir } 769cdf0e10cSrcweir } 770cdf0e10cSrcweir else 771cdf0e10cSrcweir { 772cdf0e10cSrcweir if( ((LPDEVMODEA)pOutDevMode)->dmSize >= 32 ) 773cdf0e10cSrcweir { 774cdf0e10cSrcweir sal_Int32 nLen = strlen( (const char*)((LPDEVMODEA)pOutDevMode)->dmDeviceName ); 775cdf0e10cSrcweir if ( nLen < sizeof( ((LPDEVMODEA)pOutDevMode)->dmDeviceName ) ) 776cdf0e10cSrcweir memset( ((LPDEVMODEA)pOutDevMode)->dmDeviceName+nLen, 0, sizeof( ((LPDEVMODEA)pOutDevMode)->dmDeviceName )-nLen ); 777cdf0e10cSrcweir } 778cdf0e10cSrcweir if( ((LPDEVMODEA)pOutDevMode)->dmSize >= 102 ) 779cdf0e10cSrcweir { 780cdf0e10cSrcweir sal_Int32 nLen = strlen( (const char*)((LPDEVMODEA)pOutDevMode)->dmFormName ); 781cdf0e10cSrcweir if ( nLen < sizeof( ((LPDEVMODEA)pOutDevMode)->dmFormName ) ) 782cdf0e10cSrcweir memset( ((LPDEVMODEA)pOutDevMode)->dmFormName+nLen, 0, sizeof( ((LPDEVMODEA)pOutDevMode)->dmFormName )-nLen ); 783cdf0e10cSrcweir } 784cdf0e10cSrcweir } 785cdf0e10cSrcweir 786cdf0e10cSrcweir // update data 787cdf0e10cSrcweir if ( pSetupData->mpDriverData ) 788cdf0e10cSrcweir rtl_freeMemory( pSetupData->mpDriverData ); 789cdf0e10cSrcweir pSetupData->mnDriverDataLen = nDriverDataLen; 790cdf0e10cSrcweir pSetupData->mpDriverData = (BYTE*)pOutBuffer; 791cdf0e10cSrcweir pSetupData->mnSystem = JOBSETUP_SYSTEM_WINDOWS; 792cdf0e10cSrcweir 793cdf0e10cSrcweir return TRUE; 794cdf0e10cSrcweir } 795cdf0e10cSrcweir 796cdf0e10cSrcweir // ----------------------------------------------------------------------- 797cdf0e10cSrcweir 798cdf0e10cSrcweir #define DECLARE_DEVMODE( i )\ 799cdf0e10cSrcweir DEVMODEA* pDevModeA = SAL_DEVMODE_A(i);\ 800cdf0e10cSrcweir DEVMODEW* pDevModeW = SAL_DEVMODE_W(i);\ 801cdf0e10cSrcweir if( pDevModeA == NULL && pDevModeW == NULL )\ 802cdf0e10cSrcweir return 803cdf0e10cSrcweir 804cdf0e10cSrcweir #define CHOOSE_DEVMODE(i)\ 805cdf0e10cSrcweir (pDevModeW ? pDevModeW->i : pDevModeA->i) 806cdf0e10cSrcweir 807cdf0e10cSrcweir static void ImplDevModeToJobSetup( WinSalInfoPrinter* pPrinter, ImplJobSetup* pSetupData, sal_uLong nFlags ) 808cdf0e10cSrcweir { 809cdf0e10cSrcweir if ( !pSetupData || !pSetupData->mpDriverData ) 810cdf0e10cSrcweir return; 811cdf0e10cSrcweir 812cdf0e10cSrcweir DECLARE_DEVMODE( pSetupData ); 813cdf0e10cSrcweir 814cdf0e10cSrcweir // Orientation 815cdf0e10cSrcweir if ( nFlags & SAL_JOBSET_ORIENTATION ) 816cdf0e10cSrcweir { 817cdf0e10cSrcweir if ( CHOOSE_DEVMODE(dmOrientation) == DMORIENT_PORTRAIT ) 818cdf0e10cSrcweir pSetupData->meOrientation = ORIENTATION_PORTRAIT; 819cdf0e10cSrcweir else if ( CHOOSE_DEVMODE(dmOrientation) == DMORIENT_LANDSCAPE ) 820cdf0e10cSrcweir pSetupData->meOrientation = ORIENTATION_LANDSCAPE; 821cdf0e10cSrcweir } 822cdf0e10cSrcweir 823cdf0e10cSrcweir // PaperBin 824cdf0e10cSrcweir if ( nFlags & SAL_JOBSET_PAPERBIN ) 825cdf0e10cSrcweir { 826cdf0e10cSrcweir sal_uLong nCount = ImplDeviceCaps( pPrinter, DC_BINS, NULL, pSetupData ); 827cdf0e10cSrcweir 828cdf0e10cSrcweir if ( nCount && (nCount != GDI_ERROR) ) 829cdf0e10cSrcweir { 830cdf0e10cSrcweir WORD* pBins = (WORD*)rtl_allocateZeroMemory( nCount*sizeof(WORD) ); 831cdf0e10cSrcweir ImplDeviceCaps( pPrinter, DC_BINS, (BYTE*)pBins, pSetupData ); 832cdf0e10cSrcweir pSetupData->mnPaperBin = 0; 833cdf0e10cSrcweir 834cdf0e10cSrcweir // search the right bin and assign index to mnPaperBin 835cdf0e10cSrcweir for( sal_uLong i = 0; i < nCount; i++ ) 836cdf0e10cSrcweir { 837cdf0e10cSrcweir if( CHOOSE_DEVMODE(dmDefaultSource) == pBins[ i ] ) 838cdf0e10cSrcweir { 839cdf0e10cSrcweir pSetupData->mnPaperBin = (sal_uInt16)i; 840cdf0e10cSrcweir break; 841cdf0e10cSrcweir } 842cdf0e10cSrcweir } 843cdf0e10cSrcweir 844cdf0e10cSrcweir rtl_freeMemory( pBins ); 845cdf0e10cSrcweir } 846cdf0e10cSrcweir } 847cdf0e10cSrcweir 848cdf0e10cSrcweir // PaperSize 849cdf0e10cSrcweir if ( nFlags & SAL_JOBSET_PAPERSIZE ) 850cdf0e10cSrcweir { 851cdf0e10cSrcweir if( (CHOOSE_DEVMODE(dmFields) & (DM_PAPERWIDTH|DM_PAPERLENGTH)) == (DM_PAPERWIDTH|DM_PAPERLENGTH) ) 852cdf0e10cSrcweir { 853cdf0e10cSrcweir pSetupData->mnPaperWidth = CHOOSE_DEVMODE(dmPaperWidth)*10; 854cdf0e10cSrcweir pSetupData->mnPaperHeight = CHOOSE_DEVMODE(dmPaperLength)*10; 855cdf0e10cSrcweir } 856cdf0e10cSrcweir else 857cdf0e10cSrcweir { 858cdf0e10cSrcweir sal_uLong nPaperCount = ImplDeviceCaps( pPrinter, DC_PAPERS, NULL, pSetupData ); 859cdf0e10cSrcweir WORD* pPapers = NULL; 860cdf0e10cSrcweir sal_uLong nPaperSizeCount = ImplDeviceCaps( pPrinter, DC_PAPERSIZE, NULL, pSetupData ); 861cdf0e10cSrcweir POINT* pPaperSizes = NULL; 862cdf0e10cSrcweir if ( nPaperCount && (nPaperCount != GDI_ERROR) ) 863cdf0e10cSrcweir { 864cdf0e10cSrcweir pPapers = (WORD*)rtl_allocateZeroMemory(nPaperCount*sizeof(WORD)); 865cdf0e10cSrcweir ImplDeviceCaps( pPrinter, DC_PAPERS, (BYTE*)pPapers, pSetupData ); 866cdf0e10cSrcweir } 867cdf0e10cSrcweir if ( nPaperSizeCount && (nPaperSizeCount != GDI_ERROR) ) 868cdf0e10cSrcweir { 869cdf0e10cSrcweir pPaperSizes = (POINT*)rtl_allocateZeroMemory(nPaperSizeCount*sizeof(POINT)); 870cdf0e10cSrcweir ImplDeviceCaps( pPrinter, DC_PAPERSIZE, (BYTE*)pPaperSizes, pSetupData ); 871cdf0e10cSrcweir } 872cdf0e10cSrcweir if( nPaperSizeCount == nPaperCount && pPaperSizes && pPapers ) 873cdf0e10cSrcweir { 874cdf0e10cSrcweir for( sal_uLong i = 0; i < nPaperCount; i++ ) 875cdf0e10cSrcweir { 876cdf0e10cSrcweir if( pPapers[ i ] == CHOOSE_DEVMODE(dmPaperSize) ) 877cdf0e10cSrcweir { 878cdf0e10cSrcweir pSetupData->mnPaperWidth = pPaperSizes[ i ].x*10; 879cdf0e10cSrcweir pSetupData->mnPaperHeight = pPaperSizes[ i ].y*10; 880cdf0e10cSrcweir break; 881cdf0e10cSrcweir } 882cdf0e10cSrcweir } 883cdf0e10cSrcweir } 884cdf0e10cSrcweir if( pPapers ) 885cdf0e10cSrcweir rtl_freeMemory( pPapers ); 886cdf0e10cSrcweir if( pPaperSizes ) 887cdf0e10cSrcweir rtl_freeMemory( pPaperSizes ); 888cdf0e10cSrcweir } 889cdf0e10cSrcweir switch( CHOOSE_DEVMODE(dmPaperSize) ) 890cdf0e10cSrcweir { 891cdf0e10cSrcweir case( DMPAPER_LETTER ): 892cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_LETTER; 893cdf0e10cSrcweir break; 894cdf0e10cSrcweir case( DMPAPER_TABLOID ): 895cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_TABLOID; 896cdf0e10cSrcweir break; 897cdf0e10cSrcweir case( DMPAPER_LEDGER ): 898cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_LEDGER; 899cdf0e10cSrcweir break; 900cdf0e10cSrcweir case( DMPAPER_LEGAL ): 901cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_LEGAL; 902cdf0e10cSrcweir break; 903cdf0e10cSrcweir case( DMPAPER_STATEMENT ): 904cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_STATEMENT; 905cdf0e10cSrcweir break; 906cdf0e10cSrcweir case( DMPAPER_EXECUTIVE ): 907cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_EXECUTIVE; 908cdf0e10cSrcweir break; 909cdf0e10cSrcweir case( DMPAPER_A3 ): 910cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_A3; 911cdf0e10cSrcweir break; 912cdf0e10cSrcweir case( DMPAPER_A4 ): 913cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_A4; 914cdf0e10cSrcweir break; 915cdf0e10cSrcweir case( DMPAPER_A5 ): 916cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_A5; 917cdf0e10cSrcweir break; 918cdf0e10cSrcweir //See http://wiki.services.openoffice.org/wiki/DefaultPaperSize 919cdf0e10cSrcweir //i.e. 920cdf0e10cSrcweir //http://msdn.microsoft.com/en-us/library/dd319099(VS.85).aspx 921cdf0e10cSrcweir //DMPAPER_B4 12 B4 (JIS) 257 x 364 mm 922cdf0e10cSrcweir //http://partners.adobe.com/public/developer/en/ps/5003.PPD_Spec_v4.3.pdf 923cdf0e10cSrcweir //also says that the MS DMPAPER_B4 is JIS, which makes most sense. And 924cdf0e10cSrcweir //matches our Excel filter's belief about the matching XlPaperSize 925cdf0e10cSrcweir //enumeration. 926cdf0e10cSrcweir // 927cdf0e10cSrcweir //http://msdn.microsoft.com/en-us/library/ms776398(VS.85).aspx said 928cdf0e10cSrcweir ////"DMPAPER_B4 12 B4 (JIS) 250 x 354" 929cdf0e10cSrcweir //which is bogus as it's either JIS 257 × 364 or ISO 250 × 353 930cdf0e10cSrcweir //(cmc) 931cdf0e10cSrcweir case( DMPAPER_B4 ): 932cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_B4_JIS; 933cdf0e10cSrcweir break; 934cdf0e10cSrcweir case( DMPAPER_B5 ): 935cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_B5_JIS; 936cdf0e10cSrcweir break; 937cdf0e10cSrcweir case( DMPAPER_QUARTO ): 938cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_QUARTO; 939cdf0e10cSrcweir break; 940cdf0e10cSrcweir case( DMPAPER_10X14 ): 941cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_10x14; 942cdf0e10cSrcweir break; 943cdf0e10cSrcweir case( DMPAPER_NOTE ): 944cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_LETTER; 945cdf0e10cSrcweir break; 946cdf0e10cSrcweir case( DMPAPER_ENV_9 ): 947cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_ENV_9; 948cdf0e10cSrcweir break; 949cdf0e10cSrcweir case( DMPAPER_ENV_10 ): 950cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_ENV_10; 951cdf0e10cSrcweir break; 952cdf0e10cSrcweir case( DMPAPER_ENV_11 ): 953cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_ENV_11; 954cdf0e10cSrcweir break; 955cdf0e10cSrcweir case( DMPAPER_ENV_12 ): 956cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_ENV_12; 957cdf0e10cSrcweir break; 958cdf0e10cSrcweir case( DMPAPER_ENV_14 ): 959cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_ENV_14; 960cdf0e10cSrcweir break; 961cdf0e10cSrcweir case( DMPAPER_CSHEET ): 962cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_C; 963cdf0e10cSrcweir break; 964cdf0e10cSrcweir case( DMPAPER_DSHEET ): 965cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_D; 966cdf0e10cSrcweir break; 967cdf0e10cSrcweir case( DMPAPER_ESHEET ): 968cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_E; 969cdf0e10cSrcweir break; 970cdf0e10cSrcweir case( DMPAPER_ENV_DL): 971cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_ENV_DL; 972cdf0e10cSrcweir break; 973cdf0e10cSrcweir case( DMPAPER_ENV_C5): 974cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_ENV_C5; 975cdf0e10cSrcweir break; 976cdf0e10cSrcweir case( DMPAPER_ENV_C3): 977cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_ENV_C3; 978cdf0e10cSrcweir break; 979cdf0e10cSrcweir case( DMPAPER_ENV_C4): 980cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_ENV_C4; 981cdf0e10cSrcweir break; 982cdf0e10cSrcweir case( DMPAPER_ENV_C6): 983cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_ENV_C6; 984cdf0e10cSrcweir break; 985cdf0e10cSrcweir case( DMPAPER_ENV_C65): 986cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_ENV_C65; 987cdf0e10cSrcweir break; 988cdf0e10cSrcweir case( DMPAPER_ENV_ITALY ): 989cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_ENV_ITALY; 990cdf0e10cSrcweir break; 991cdf0e10cSrcweir case( DMPAPER_ENV_MONARCH ): 992cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_ENV_MONARCH; 993cdf0e10cSrcweir break; 994cdf0e10cSrcweir case( DMPAPER_ENV_PERSONAL ): 995cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_ENV_PERSONAL; 996cdf0e10cSrcweir break; 997cdf0e10cSrcweir case( DMPAPER_FANFOLD_US ): 998cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_FANFOLD_US; 999cdf0e10cSrcweir break; 1000cdf0e10cSrcweir case( DMPAPER_FANFOLD_STD_GERMAN ): 1001cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_FANFOLD_DE; 1002cdf0e10cSrcweir break; 1003cdf0e10cSrcweir case( DMPAPER_FANFOLD_LGL_GERMAN ): 1004cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_FANFOLD_LEGAL_DE; 1005cdf0e10cSrcweir break; 1006cdf0e10cSrcweir case( DMPAPER_ISO_B4 ): 1007cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_B4_ISO; 1008cdf0e10cSrcweir break; 1009cdf0e10cSrcweir case( DMPAPER_JAPANESE_POSTCARD ): 1010cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_POSTCARD_JP; 1011cdf0e10cSrcweir break; 1012cdf0e10cSrcweir case( DMPAPER_9X11 ): 1013cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_9x11; 1014cdf0e10cSrcweir break; 1015cdf0e10cSrcweir case( DMPAPER_10X11 ): 1016cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_10x11; 1017cdf0e10cSrcweir break; 1018cdf0e10cSrcweir case( DMPAPER_15X11 ): 1019cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_15x11; 1020cdf0e10cSrcweir break; 1021cdf0e10cSrcweir case( DMPAPER_ENV_INVITE ): 1022cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_ENV_INVITE; 1023cdf0e10cSrcweir break; 1024cdf0e10cSrcweir case( DMPAPER_A_PLUS ): 1025cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_A_PLUS; 1026cdf0e10cSrcweir break; 1027cdf0e10cSrcweir case( DMPAPER_B_PLUS ): 1028cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_B_PLUS; 1029cdf0e10cSrcweir break; 1030cdf0e10cSrcweir case( DMPAPER_LETTER_PLUS ): 1031cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_LETTER_PLUS; 1032cdf0e10cSrcweir break; 1033cdf0e10cSrcweir case( DMPAPER_A4_PLUS ): 1034cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_A4_PLUS; 1035cdf0e10cSrcweir break; 1036cdf0e10cSrcweir case( DMPAPER_A2 ): 1037cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_A2; 1038cdf0e10cSrcweir break; 1039cdf0e10cSrcweir case( DMPAPER_DBL_JAPANESE_POSTCARD ): 1040cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_DOUBLEPOSTCARD_JP; 1041cdf0e10cSrcweir break; 1042cdf0e10cSrcweir case( DMPAPER_A6 ): 1043cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_A6; 1044cdf0e10cSrcweir break; 1045cdf0e10cSrcweir case( DMPAPER_B6_JIS ): 1046cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_B6_JIS; 1047cdf0e10cSrcweir break; 1048cdf0e10cSrcweir case( DMPAPER_12X11 ): 1049cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_12x11; 1050cdf0e10cSrcweir break; 1051cdf0e10cSrcweir default: 1052cdf0e10cSrcweir pSetupData->mePaperFormat = PAPER_USER; 1053cdf0e10cSrcweir break; 1054cdf0e10cSrcweir } 1055cdf0e10cSrcweir } 1056cdf0e10cSrcweir 1057cdf0e10cSrcweir if( nFlags & SAL_JOBSET_DUPLEXMODE ) 1058cdf0e10cSrcweir { 1059cdf0e10cSrcweir DuplexMode eDuplex = DUPLEX_UNKNOWN; 1060cdf0e10cSrcweir if( (CHOOSE_DEVMODE(dmFields) & DM_DUPLEX) ) 1061cdf0e10cSrcweir { 1062cdf0e10cSrcweir if( CHOOSE_DEVMODE(dmDuplex) == DMDUP_SIMPLEX ) 1063cdf0e10cSrcweir eDuplex = DUPLEX_OFF; 1064cdf0e10cSrcweir else if( CHOOSE_DEVMODE(dmDuplex) == DMDUP_VERTICAL ) 1065cdf0e10cSrcweir eDuplex = DUPLEX_LONGEDGE; 1066cdf0e10cSrcweir else if( CHOOSE_DEVMODE(dmDuplex) == DMDUP_HORIZONTAL ) 1067cdf0e10cSrcweir eDuplex = DUPLEX_SHORTEDGE; 1068cdf0e10cSrcweir } 1069cdf0e10cSrcweir pSetupData->meDuplexMode = eDuplex; 1070cdf0e10cSrcweir } 1071cdf0e10cSrcweir } 1072cdf0e10cSrcweir 1073cdf0e10cSrcweir // ----------------------------------------------------------------------- 1074cdf0e10cSrcweir 1075cdf0e10cSrcweir static void ImplJobSetupToDevMode( WinSalInfoPrinter* pPrinter, ImplJobSetup* pSetupData, sal_uLong nFlags ) 1076cdf0e10cSrcweir { 1077cdf0e10cSrcweir if ( !pSetupData || !pSetupData->mpDriverData ) 1078cdf0e10cSrcweir return; 1079cdf0e10cSrcweir 1080cdf0e10cSrcweir DECLARE_DEVMODE( pSetupData ); 1081cdf0e10cSrcweir 1082cdf0e10cSrcweir // Orientation 1083cdf0e10cSrcweir if ( nFlags & SAL_JOBSET_ORIENTATION ) 1084cdf0e10cSrcweir { 1085cdf0e10cSrcweir CHOOSE_DEVMODE(dmFields) |= DM_ORIENTATION; 1086cdf0e10cSrcweir if ( pSetupData->meOrientation == ORIENTATION_PORTRAIT ) 1087cdf0e10cSrcweir CHOOSE_DEVMODE(dmOrientation) = DMORIENT_PORTRAIT; 1088cdf0e10cSrcweir else 1089cdf0e10cSrcweir CHOOSE_DEVMODE(dmOrientation) = DMORIENT_LANDSCAPE; 1090cdf0e10cSrcweir } 1091cdf0e10cSrcweir 1092cdf0e10cSrcweir // PaperBin 1093cdf0e10cSrcweir if ( nFlags & SAL_JOBSET_PAPERBIN ) 1094cdf0e10cSrcweir { 1095cdf0e10cSrcweir sal_uLong nCount = ImplDeviceCaps( pPrinter, DC_BINS, NULL, pSetupData ); 1096cdf0e10cSrcweir 1097cdf0e10cSrcweir if ( nCount && (nCount != GDI_ERROR) ) 1098cdf0e10cSrcweir { 1099cdf0e10cSrcweir WORD* pBins = (WORD*)rtl_allocateZeroMemory(nCount*sizeof(WORD)); 1100cdf0e10cSrcweir ImplDeviceCaps( pPrinter, DC_BINS, (BYTE*)pBins, pSetupData ); 1101cdf0e10cSrcweir CHOOSE_DEVMODE(dmFields) |= DM_DEFAULTSOURCE; 1102cdf0e10cSrcweir CHOOSE_DEVMODE(dmDefaultSource) = pBins[ pSetupData->mnPaperBin ]; 1103cdf0e10cSrcweir rtl_freeMemory( pBins ); 1104cdf0e10cSrcweir } 1105cdf0e10cSrcweir } 1106cdf0e10cSrcweir 1107cdf0e10cSrcweir // PaperSize 1108cdf0e10cSrcweir if ( nFlags & SAL_JOBSET_PAPERSIZE ) 1109cdf0e10cSrcweir { 1110cdf0e10cSrcweir CHOOSE_DEVMODE(dmFields) |= DM_PAPERSIZE; 1111cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperWidth) = 0; 1112cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperLength) = 0; 1113cdf0e10cSrcweir 1114cdf0e10cSrcweir switch( pSetupData->mePaperFormat ) 1115cdf0e10cSrcweir { 1116cdf0e10cSrcweir case( PAPER_A2 ): 1117cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_A2; 1118cdf0e10cSrcweir break; 1119cdf0e10cSrcweir case( PAPER_A3 ): 1120cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_A3; 1121cdf0e10cSrcweir break; 1122cdf0e10cSrcweir case( PAPER_A4 ): 1123cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_A4; 1124cdf0e10cSrcweir break; 1125cdf0e10cSrcweir case( PAPER_A5 ): 1126cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_A5; 1127cdf0e10cSrcweir break; 1128cdf0e10cSrcweir case( PAPER_B4_ISO): 1129cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ISO_B4; 1130cdf0e10cSrcweir break; 1131cdf0e10cSrcweir case( PAPER_LETTER ): 1132cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_LETTER; 1133cdf0e10cSrcweir break; 1134cdf0e10cSrcweir case( PAPER_LEGAL ): 1135cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_LEGAL; 1136cdf0e10cSrcweir break; 1137cdf0e10cSrcweir case( PAPER_TABLOID ): 1138cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_TABLOID; 1139cdf0e10cSrcweir break; 1140cdf0e10cSrcweir #if 0 1141cdf0e10cSrcweir //http://msdn.microsoft.com/en-us/library/ms776398(VS.85).aspx 1142cdf0e10cSrcweir //DMPAPER_ENV_B6 is documented as: 1143cdf0e10cSrcweir //"DMPAPER_ENV_B6 35 Envelope B6 176 x 125 mm" 1144cdf0e10cSrcweir //which is the wrong way around, it is surely 125 x 176, i.e. 1145cdf0e10cSrcweir //compare DMPAPER_ENV_B4 and DMPAPER_ENV_B4 as 1146cdf0e10cSrcweir //DMPAPER_ENV_B4 33 Envelope B4 250 x 353 mm 1147cdf0e10cSrcweir //DMPAPER_ENV_B5 34 Envelope B5 176 x 250 mm 1148cdf0e10cSrcweir case( PAPER_B6_ISO ): 1149cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_B6; 1150cdf0e10cSrcweir break; 1151cdf0e10cSrcweir #endif 1152cdf0e10cSrcweir case( PAPER_ENV_C4 ): 1153cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_C4; 1154cdf0e10cSrcweir break; 1155cdf0e10cSrcweir case( PAPER_ENV_C5 ): 1156cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_C5; 1157cdf0e10cSrcweir break; 1158cdf0e10cSrcweir case( PAPER_ENV_C6 ): 1159cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_C6; 1160cdf0e10cSrcweir break; 1161cdf0e10cSrcweir case( PAPER_ENV_C65 ): 1162cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_C65; 1163cdf0e10cSrcweir break; 1164cdf0e10cSrcweir case( PAPER_ENV_DL ): 1165cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_DL; 1166cdf0e10cSrcweir break; 1167cdf0e10cSrcweir case( PAPER_C ): 1168cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_CSHEET; 1169cdf0e10cSrcweir break; 1170cdf0e10cSrcweir case( PAPER_D ): 1171cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_DSHEET; 1172cdf0e10cSrcweir break; 1173cdf0e10cSrcweir case( PAPER_E ): 1174cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ESHEET; 1175cdf0e10cSrcweir break; 1176cdf0e10cSrcweir case( PAPER_EXECUTIVE ): 1177cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_EXECUTIVE; 1178cdf0e10cSrcweir break; 1179cdf0e10cSrcweir case( PAPER_FANFOLD_LEGAL_DE ): 1180cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_FANFOLD_LGL_GERMAN; 1181cdf0e10cSrcweir break; 1182cdf0e10cSrcweir case( PAPER_ENV_MONARCH ): 1183cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_MONARCH; 1184cdf0e10cSrcweir break; 1185cdf0e10cSrcweir case( PAPER_ENV_PERSONAL ): 1186cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_PERSONAL; 1187cdf0e10cSrcweir break; 1188cdf0e10cSrcweir case( PAPER_ENV_9 ): 1189cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_9; 1190cdf0e10cSrcweir break; 1191cdf0e10cSrcweir case( PAPER_ENV_10 ): 1192cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_10; 1193cdf0e10cSrcweir break; 1194cdf0e10cSrcweir case( PAPER_ENV_11 ): 1195cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_11; 1196cdf0e10cSrcweir break; 1197cdf0e10cSrcweir case( PAPER_ENV_12 ): 1198cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_12; 1199cdf0e10cSrcweir break; 1200cdf0e10cSrcweir //See the comments on DMPAPER_B4 above 1201cdf0e10cSrcweir case( PAPER_B4_JIS ): 1202cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_B4; 1203cdf0e10cSrcweir break; 1204cdf0e10cSrcweir case( PAPER_B5_JIS ): 1205cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_B5; 1206cdf0e10cSrcweir break; 1207cdf0e10cSrcweir case( PAPER_B6_JIS ): 1208cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_B6_JIS; 1209cdf0e10cSrcweir break; 1210cdf0e10cSrcweir case( PAPER_LEDGER ): 1211cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_LEDGER; 1212cdf0e10cSrcweir break; 1213cdf0e10cSrcweir case( PAPER_STATEMENT ): 1214cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_STATEMENT; 1215cdf0e10cSrcweir break; 1216cdf0e10cSrcweir case( PAPER_10x14 ): 1217cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_10X14; 1218cdf0e10cSrcweir break; 1219cdf0e10cSrcweir case( PAPER_ENV_14 ): 1220cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_14; 1221cdf0e10cSrcweir break; 1222cdf0e10cSrcweir case( PAPER_ENV_C3 ): 1223cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_C3; 1224cdf0e10cSrcweir break; 1225cdf0e10cSrcweir case( PAPER_ENV_ITALY ): 1226cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_ITALY; 1227cdf0e10cSrcweir break; 1228cdf0e10cSrcweir case( PAPER_FANFOLD_US ): 1229cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_FANFOLD_US; 1230cdf0e10cSrcweir break; 1231cdf0e10cSrcweir case( PAPER_FANFOLD_DE ): 1232cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_FANFOLD_STD_GERMAN; 1233cdf0e10cSrcweir break; 1234cdf0e10cSrcweir case( PAPER_POSTCARD_JP ): 1235cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_JAPANESE_POSTCARD; 1236cdf0e10cSrcweir break; 1237cdf0e10cSrcweir case( PAPER_9x11 ): 1238cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_9X11; 1239cdf0e10cSrcweir break; 1240cdf0e10cSrcweir case( PAPER_10x11 ): 1241cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_10X11; 1242cdf0e10cSrcweir break; 1243cdf0e10cSrcweir case( PAPER_15x11 ): 1244cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_15X11; 1245cdf0e10cSrcweir break; 1246cdf0e10cSrcweir case( PAPER_ENV_INVITE ): 1247cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_ENV_INVITE; 1248cdf0e10cSrcweir break; 1249cdf0e10cSrcweir case( PAPER_A_PLUS ): 1250cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_A_PLUS; 1251cdf0e10cSrcweir break; 1252cdf0e10cSrcweir case( PAPER_B_PLUS ): 1253cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_B_PLUS; 1254cdf0e10cSrcweir break; 1255cdf0e10cSrcweir case( PAPER_LETTER_PLUS ): 1256cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_LETTER_PLUS; 1257cdf0e10cSrcweir break; 1258cdf0e10cSrcweir case( PAPER_A4_PLUS ): 1259cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_A4_PLUS; 1260cdf0e10cSrcweir break; 1261cdf0e10cSrcweir case( PAPER_DOUBLEPOSTCARD_JP ): 1262cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_DBL_JAPANESE_POSTCARD; 1263cdf0e10cSrcweir break; 1264cdf0e10cSrcweir case( PAPER_A6 ): 1265cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_A6; 1266cdf0e10cSrcweir break; 1267cdf0e10cSrcweir case( PAPER_12x11 ): 1268cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_12X11; 1269cdf0e10cSrcweir break; 1270cdf0e10cSrcweir default: 1271cdf0e10cSrcweir { 1272cdf0e10cSrcweir short nPaper = 0; 1273cdf0e10cSrcweir sal_uLong nPaperCount = ImplDeviceCaps( pPrinter, DC_PAPERS, NULL, pSetupData ); 1274cdf0e10cSrcweir WORD* pPapers = NULL; 1275cdf0e10cSrcweir sal_uLong nPaperSizeCount = ImplDeviceCaps( pPrinter, DC_PAPERSIZE, NULL, pSetupData ); 1276cdf0e10cSrcweir POINT* pPaperSizes = NULL; 1277cdf0e10cSrcweir DWORD nLandscapeAngle = ImplDeviceCaps( pPrinter, DC_ORIENTATION, NULL, pSetupData ); 1278cdf0e10cSrcweir if ( nPaperCount && (nPaperCount != GDI_ERROR) ) 1279cdf0e10cSrcweir { 1280cdf0e10cSrcweir pPapers = (WORD*)rtl_allocateZeroMemory(nPaperCount*sizeof(WORD)); 1281cdf0e10cSrcweir ImplDeviceCaps( pPrinter, DC_PAPERS, (BYTE*)pPapers, pSetupData ); 1282cdf0e10cSrcweir } 1283cdf0e10cSrcweir if ( nPaperSizeCount && (nPaperSizeCount != GDI_ERROR) ) 1284cdf0e10cSrcweir { 1285cdf0e10cSrcweir pPaperSizes = (POINT*)rtl_allocateZeroMemory(nPaperSizeCount*sizeof(POINT)); 1286cdf0e10cSrcweir ImplDeviceCaps( pPrinter, DC_PAPERSIZE, (BYTE*)pPaperSizes, pSetupData ); 1287cdf0e10cSrcweir } 1288cdf0e10cSrcweir if ( (nPaperSizeCount == nPaperCount) && pPapers && pPaperSizes ) 1289cdf0e10cSrcweir { 1290cdf0e10cSrcweir PaperInfo aInfo(pSetupData->mnPaperWidth, pSetupData->mnPaperHeight); 1291cdf0e10cSrcweir // compare paper formats and select a good match 1292cdf0e10cSrcweir for ( sal_uLong i = 0; i < nPaperCount; i++ ) 1293cdf0e10cSrcweir { 1294cdf0e10cSrcweir if ( aInfo.sloppyEqual(PaperInfo(pPaperSizes[i].x*10, pPaperSizes[i].y*10))) 1295cdf0e10cSrcweir { 1296cdf0e10cSrcweir nPaper = pPapers[i]; 1297cdf0e10cSrcweir break; 1298cdf0e10cSrcweir } 1299cdf0e10cSrcweir } 1300cdf0e10cSrcweir 1301cdf0e10cSrcweir // If the printer supports landscape orientation, check paper sizes again 1302cdf0e10cSrcweir // with landscape orientation. This is necessary as a printer driver provides 1303cdf0e10cSrcweir // all paper sizes with portrait orientation only!! 1304cdf0e10cSrcweir if ( !nPaper && nLandscapeAngle != 0 ) 1305cdf0e10cSrcweir { 1306cdf0e10cSrcweir PaperInfo aRotatedInfo(pSetupData->mnPaperHeight, pSetupData->mnPaperWidth); 1307cdf0e10cSrcweir for ( sal_uLong i = 0; i < nPaperCount; i++ ) 1308cdf0e10cSrcweir { 1309cdf0e10cSrcweir if ( aRotatedInfo.sloppyEqual(PaperInfo(pPaperSizes[i].x*10, pPaperSizes[i].y*10)) ) 1310cdf0e10cSrcweir { 1311cdf0e10cSrcweir nPaper = pPapers[i]; 1312cdf0e10cSrcweir break; 1313cdf0e10cSrcweir } 1314cdf0e10cSrcweir } 1315cdf0e10cSrcweir } 1316cdf0e10cSrcweir 1317cdf0e10cSrcweir if ( nPaper ) 1318cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = nPaper; 1319cdf0e10cSrcweir } 1320cdf0e10cSrcweir 1321cdf0e10cSrcweir if ( !nPaper ) 1322cdf0e10cSrcweir { 1323cdf0e10cSrcweir CHOOSE_DEVMODE(dmFields) |= DM_PAPERLENGTH | DM_PAPERWIDTH; 1324cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperSize) = DMPAPER_USER; 1325cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperWidth) = (short)(pSetupData->mnPaperWidth/10); 1326cdf0e10cSrcweir CHOOSE_DEVMODE(dmPaperLength) = (short)(pSetupData->mnPaperHeight/10); 1327cdf0e10cSrcweir } 1328cdf0e10cSrcweir 1329cdf0e10cSrcweir if ( pPapers ) 1330cdf0e10cSrcweir rtl_freeMemory(pPapers); 1331cdf0e10cSrcweir if ( pPaperSizes ) 1332cdf0e10cSrcweir rtl_freeMemory(pPaperSizes); 1333cdf0e10cSrcweir 1334cdf0e10cSrcweir break; 1335cdf0e10cSrcweir } 1336cdf0e10cSrcweir } 1337cdf0e10cSrcweir } 1338cdf0e10cSrcweir if( (nFlags & SAL_JOBSET_DUPLEXMODE) ) 1339cdf0e10cSrcweir { 1340cdf0e10cSrcweir switch( pSetupData->meDuplexMode ) 1341cdf0e10cSrcweir { 1342cdf0e10cSrcweir case DUPLEX_OFF: 1343cdf0e10cSrcweir CHOOSE_DEVMODE(dmFields) |= DM_DUPLEX; 1344cdf0e10cSrcweir CHOOSE_DEVMODE(dmDuplex) = DMDUP_SIMPLEX; 1345cdf0e10cSrcweir break; 1346cdf0e10cSrcweir case DUPLEX_SHORTEDGE: 1347cdf0e10cSrcweir CHOOSE_DEVMODE(dmFields) |= DM_DUPLEX; 1348cdf0e10cSrcweir CHOOSE_DEVMODE(dmDuplex) = DMDUP_HORIZONTAL; 1349cdf0e10cSrcweir break; 1350cdf0e10cSrcweir case DUPLEX_LONGEDGE: 1351cdf0e10cSrcweir CHOOSE_DEVMODE(dmFields) |= DM_DUPLEX; 1352cdf0e10cSrcweir CHOOSE_DEVMODE(dmDuplex) = DMDUP_VERTICAL; 1353cdf0e10cSrcweir break; 1354cdf0e10cSrcweir case DUPLEX_UNKNOWN: 1355cdf0e10cSrcweir break; 1356cdf0e10cSrcweir } 1357cdf0e10cSrcweir } 1358cdf0e10cSrcweir } 1359cdf0e10cSrcweir 1360cdf0e10cSrcweir // ----------------------------------------------------------------------- 1361cdf0e10cSrcweir 1362cdf0e10cSrcweir static HDC ImplCreateICW_WithCatch( LPWSTR pDriver, 1363cdf0e10cSrcweir LPCWSTR pDevice, 1364cdf0e10cSrcweir LPDEVMODEW pDevMode ) 1365cdf0e10cSrcweir { 1366cdf0e10cSrcweir HDC hDC = 0; 1367cdf0e10cSrcweir CATCH_DRIVER_EX_BEGIN; 1368cdf0e10cSrcweir hDC = CreateICW( pDriver, pDevice, 0, pDevMode ); 1369cdf0e10cSrcweir CATCH_DRIVER_EX_END_2( "exception in CreateICW" ); 1370cdf0e10cSrcweir return hDC; 1371cdf0e10cSrcweir } 1372cdf0e10cSrcweir 1373cdf0e10cSrcweir static HDC ImplCreateICA_WithCatch( char* pDriver, 1374cdf0e10cSrcweir char* pDevice, 1375cdf0e10cSrcweir LPDEVMODEA pDevMode ) 1376cdf0e10cSrcweir { 1377cdf0e10cSrcweir HDC hDC = 0; 1378cdf0e10cSrcweir CATCH_DRIVER_EX_BEGIN; 1379cdf0e10cSrcweir hDC = CreateICA( pDriver, pDevice, 0, pDevMode ); 1380cdf0e10cSrcweir CATCH_DRIVER_EX_END_2( "exception in CreateICW" ); 1381cdf0e10cSrcweir return hDC; 1382cdf0e10cSrcweir } 1383cdf0e10cSrcweir 1384cdf0e10cSrcweir 1385cdf0e10cSrcweir static HDC ImplCreateSalPrnIC( WinSalInfoPrinter* pPrinter, ImplJobSetup* pSetupData ) 1386cdf0e10cSrcweir { 1387cdf0e10cSrcweir HDC hDC = 0; 1388cdf0e10cSrcweir if( aSalShlData.mbWPrinter ) 1389cdf0e10cSrcweir { 1390cdf0e10cSrcweir LPDEVMODEW pDevMode; 1391cdf0e10cSrcweir if ( pSetupData && pSetupData->mpDriverData ) 1392cdf0e10cSrcweir pDevMode = SAL_DEVMODE_W( pSetupData ); 1393cdf0e10cSrcweir else 1394cdf0e10cSrcweir pDevMode = NULL; 1395cdf0e10cSrcweir // #95347 some buggy drivers (eg, OKI) write to those buffers in CreateIC, although declared const - so provide some space 1396cdf0e10cSrcweir // pl: does this hold true for Unicode functions ? 1397cdf0e10cSrcweir if( pPrinter->maDriverName.Len() > 2048 || pPrinter->maDeviceName.Len() > 2048 ) 1398cdf0e10cSrcweir return 0; 1399cdf0e10cSrcweir sal_Unicode pDriverName[ 4096 ]; 1400cdf0e10cSrcweir sal_Unicode pDeviceName[ 4096 ]; 1401cdf0e10cSrcweir rtl_copyMemory( pDriverName, pPrinter->maDriverName.GetBuffer(), pPrinter->maDriverName.Len()*sizeof(sal_Unicode)); 1402cdf0e10cSrcweir memset( pDriverName+pPrinter->maDriverName.Len(), 0, 32 ); 1403cdf0e10cSrcweir rtl_copyMemory( pDeviceName, pPrinter->maDeviceName.GetBuffer(), pPrinter->maDeviceName.Len()*sizeof(sal_Unicode)); 1404cdf0e10cSrcweir memset( pDeviceName+pPrinter->maDeviceName.Len(), 0, 32 ); 1405cdf0e10cSrcweir hDC = ImplCreateICW_WithCatch( reinterpret_cast< LPWSTR >(pDriverName), 1406cdf0e10cSrcweir reinterpret_cast< LPCWSTR >(pDeviceName), 1407cdf0e10cSrcweir pDevMode ); 1408cdf0e10cSrcweir } 1409cdf0e10cSrcweir else 1410cdf0e10cSrcweir { 1411cdf0e10cSrcweir LPDEVMODEA pDevMode; 1412cdf0e10cSrcweir if ( pSetupData && pSetupData->mpDriverData ) 1413cdf0e10cSrcweir pDevMode = SAL_DEVMODE_A( pSetupData ); 1414cdf0e10cSrcweir else 1415cdf0e10cSrcweir pDevMode = NULL; 1416cdf0e10cSrcweir // #95347 some buggy drivers (eg, OKI) write to those buffers in CreateIC, although declared const - so provide some space 1417cdf0e10cSrcweir ByteString aDriver ( ImplSalGetWinAnsiString( pPrinter->maDriverName, TRUE ) ); 1418cdf0e10cSrcweir ByteString aDevice ( ImplSalGetWinAnsiString( pPrinter->maDeviceName, TRUE ) ); 1419cdf0e10cSrcweir int n = aDriver.Len() > aDevice.Len() ? aDriver.Len() : aDevice.Len(); 1420cdf0e10cSrcweir // #125813# under some circumstances many printer drivers really 1421cdf0e10cSrcweir // seem to have a problem with the names and their conversions. 1422cdf0e10cSrcweir // We need to get on to of this, but haven't been able to reproduce 1423cdf0e10cSrcweir // the problem yet. Put the names on the stack so we get them 1424cdf0e10cSrcweir // with an eventual crash report. 1425cdf0e10cSrcweir if( n >= 2048 ) 1426cdf0e10cSrcweir return 0; 1427cdf0e10cSrcweir n += 2048; 1428cdf0e10cSrcweir char lpszDriverName[ 4096 ]; 1429cdf0e10cSrcweir char lpszDeviceName[ 4096 ]; 1430cdf0e10cSrcweir strncpy( lpszDriverName, aDriver.GetBuffer(), n ); 1431cdf0e10cSrcweir strncpy( lpszDeviceName, aDevice.GetBuffer(), n ); 1432cdf0e10cSrcweir // HDU: the crashes usually happen in a MBCS to unicode conversion, 1433cdf0e10cSrcweir // so I suspect the MBCS string's end is not properly recognized. 1434cdf0e10cSrcweir // The longest MBCS encoding I'm aware of has six bytes per code 1435cdf0e10cSrcweir // => add a couple of zeroes... 1436cdf0e10cSrcweir memset( lpszDriverName+aDriver.Len(), 0, 16 ); 1437cdf0e10cSrcweir memset( lpszDeviceName+aDevice.Len(), 0, 16 ); 1438cdf0e10cSrcweir hDC = ImplCreateICA_WithCatch( lpszDriverName, 1439cdf0e10cSrcweir lpszDeviceName, 1440cdf0e10cSrcweir pDevMode ); 1441cdf0e10cSrcweir } 1442cdf0e10cSrcweir return hDC; 1443cdf0e10cSrcweir } 1444cdf0e10cSrcweir 1445cdf0e10cSrcweir // ----------------------------------------------------------------------- 1446cdf0e10cSrcweir 1447cdf0e10cSrcweir static WinSalGraphics* ImplCreateSalPrnGraphics( HDC hDC ) 1448cdf0e10cSrcweir { 1449cdf0e10cSrcweir WinSalGraphics* pGraphics = new WinSalGraphics; 1450cdf0e10cSrcweir pGraphics->SetLayout( 0 ); 1451cdf0e10cSrcweir pGraphics->mhDC = hDC; 1452cdf0e10cSrcweir pGraphics->mhWnd = 0; 1453cdf0e10cSrcweir pGraphics->mbPrinter = TRUE; 1454cdf0e10cSrcweir pGraphics->mbVirDev = FALSE; 1455cdf0e10cSrcweir pGraphics->mbWindow = FALSE; 1456cdf0e10cSrcweir pGraphics->mbScreen = FALSE; 1457cdf0e10cSrcweir ImplSalInitGraphics( pGraphics ); 1458cdf0e10cSrcweir return pGraphics; 1459cdf0e10cSrcweir } 1460cdf0e10cSrcweir 1461cdf0e10cSrcweir // ----------------------------------------------------------------------- 1462cdf0e10cSrcweir 1463cdf0e10cSrcweir static sal_Bool ImplUpdateSalPrnIC( WinSalInfoPrinter* pPrinter, ImplJobSetup* pSetupData ) 1464cdf0e10cSrcweir { 1465cdf0e10cSrcweir HDC hNewDC = ImplCreateSalPrnIC( pPrinter, pSetupData ); 1466cdf0e10cSrcweir if ( !hNewDC ) 1467cdf0e10cSrcweir return FALSE; 1468cdf0e10cSrcweir 1469cdf0e10cSrcweir if ( pPrinter->mpGraphics ) 1470cdf0e10cSrcweir { 1471cdf0e10cSrcweir ImplSalDeInitGraphics( pPrinter->mpGraphics ); 1472cdf0e10cSrcweir DeleteDC( pPrinter->mpGraphics->mhDC ); 1473cdf0e10cSrcweir delete pPrinter->mpGraphics; 1474cdf0e10cSrcweir } 1475cdf0e10cSrcweir 1476cdf0e10cSrcweir pPrinter->mpGraphics = ImplCreateSalPrnGraphics( hNewDC ); 1477cdf0e10cSrcweir pPrinter->mhDC = hNewDC; 1478cdf0e10cSrcweir 1479cdf0e10cSrcweir return TRUE; 1480cdf0e10cSrcweir } 1481cdf0e10cSrcweir 1482cdf0e10cSrcweir // ======================================================================= 1483cdf0e10cSrcweir 1484cdf0e10cSrcweir SalInfoPrinter* WinSalInstance::CreateInfoPrinter( SalPrinterQueueInfo* pQueueInfo, 1485cdf0e10cSrcweir ImplJobSetup* pSetupData ) 1486cdf0e10cSrcweir { 1487cdf0e10cSrcweir WinSalInfoPrinter* pPrinter = new WinSalInfoPrinter; 1488cdf0e10cSrcweir if( ! pQueueInfo->mpSysData ) 1489cdf0e10cSrcweir GetPrinterQueueState( pQueueInfo ); 1490cdf0e10cSrcweir pPrinter->maDriverName = pQueueInfo->maDriver; 1491cdf0e10cSrcweir pPrinter->maDeviceName = pQueueInfo->maPrinterName; 1492cdf0e10cSrcweir pPrinter->maPortName = pQueueInfo->mpSysData ? 1493cdf0e10cSrcweir *(String*)(pQueueInfo->mpSysData) 1494cdf0e10cSrcweir : String(); 1495cdf0e10cSrcweir 1496cdf0e10cSrcweir // check if the provided setup data match the actual printer 1497cdf0e10cSrcweir ImplTestSalJobSetup( pPrinter, pSetupData, TRUE ); 1498cdf0e10cSrcweir 1499cdf0e10cSrcweir HDC hDC = ImplCreateSalPrnIC( pPrinter, pSetupData ); 1500cdf0e10cSrcweir if ( !hDC ) 1501cdf0e10cSrcweir { 1502cdf0e10cSrcweir delete pPrinter; 1503cdf0e10cSrcweir return NULL; 1504cdf0e10cSrcweir } 1505cdf0e10cSrcweir 1506cdf0e10cSrcweir pPrinter->mpGraphics = ImplCreateSalPrnGraphics( hDC ); 1507cdf0e10cSrcweir pPrinter->mhDC = hDC; 1508cdf0e10cSrcweir if ( !pSetupData->mpDriverData ) 1509cdf0e10cSrcweir ImplUpdateSalJobSetup( pPrinter, pSetupData, FALSE, NULL ); 1510cdf0e10cSrcweir ImplDevModeToJobSetup( pPrinter, pSetupData, SAL_JOBSET_ALL ); 1511cdf0e10cSrcweir pSetupData->mnSystem = JOBSETUP_SYSTEM_WINDOWS; 1512cdf0e10cSrcweir 1513cdf0e10cSrcweir return pPrinter; 1514cdf0e10cSrcweir } 1515cdf0e10cSrcweir 1516cdf0e10cSrcweir // ----------------------------------------------------------------------- 1517cdf0e10cSrcweir 1518cdf0e10cSrcweir void WinSalInstance::DestroyInfoPrinter( SalInfoPrinter* pPrinter ) 1519cdf0e10cSrcweir { 1520cdf0e10cSrcweir delete pPrinter; 1521cdf0e10cSrcweir } 1522cdf0e10cSrcweir 1523cdf0e10cSrcweir // ======================================================================= 1524cdf0e10cSrcweir 1525cdf0e10cSrcweir WinSalInfoPrinter::WinSalInfoPrinter() : 1526cdf0e10cSrcweir mpGraphics( NULL ), 1527cdf0e10cSrcweir mhDC( 0 ), 1528cdf0e10cSrcweir mbGraphics( FALSE ) 1529cdf0e10cSrcweir { 1530cdf0e10cSrcweir m_bPapersInit = FALSE; 1531cdf0e10cSrcweir } 1532cdf0e10cSrcweir 1533cdf0e10cSrcweir // ----------------------------------------------------------------------- 1534cdf0e10cSrcweir 1535cdf0e10cSrcweir WinSalInfoPrinter::~WinSalInfoPrinter() 1536cdf0e10cSrcweir { 1537cdf0e10cSrcweir if ( mpGraphics ) 1538cdf0e10cSrcweir { 1539cdf0e10cSrcweir ImplSalDeInitGraphics( mpGraphics ); 1540cdf0e10cSrcweir DeleteDC( mpGraphics->mhDC ); 1541cdf0e10cSrcweir delete mpGraphics; 1542cdf0e10cSrcweir } 1543cdf0e10cSrcweir } 1544cdf0e10cSrcweir 1545cdf0e10cSrcweir // ----------------------------------------------------------------------- 1546cdf0e10cSrcweir 1547cdf0e10cSrcweir void WinSalInfoPrinter::InitPaperFormats( const ImplJobSetup* pSetupData ) 1548cdf0e10cSrcweir { 1549cdf0e10cSrcweir m_aPaperFormats.clear(); 1550cdf0e10cSrcweir 1551cdf0e10cSrcweir DWORD nCount = ImplDeviceCaps( this, DC_PAPERSIZE, NULL, pSetupData ); 1552cdf0e10cSrcweir if( nCount == GDI_ERROR ) 1553cdf0e10cSrcweir nCount = 0; 1554cdf0e10cSrcweir 1555cdf0e10cSrcweir POINT* pPaperSizes = NULL; 1556cdf0e10cSrcweir if( nCount ) 1557cdf0e10cSrcweir { 1558cdf0e10cSrcweir pPaperSizes = (POINT*)rtl_allocateZeroMemory(nCount*sizeof(POINT)); 1559cdf0e10cSrcweir ImplDeviceCaps( this, DC_PAPERSIZE, (BYTE*)pPaperSizes, pSetupData ); 1560cdf0e10cSrcweir 1561cdf0e10cSrcweir if( aSalShlData.mbWPrinter ) 1562cdf0e10cSrcweir { 1563cdf0e10cSrcweir sal_Unicode* pNamesBuffer = (sal_Unicode*)rtl_allocateMemory(nCount*64*sizeof(sal_Unicode)); 1564cdf0e10cSrcweir ImplDeviceCaps( this, DC_PAPERNAMES, (BYTE*)pNamesBuffer, pSetupData ); 1565cdf0e10cSrcweir for( DWORD i = 0; i < nCount; ++i ) 1566cdf0e10cSrcweir { 1567cdf0e10cSrcweir PaperInfo aInfo(pPaperSizes[i].x * 10, pPaperSizes[i].y * 10); 1568cdf0e10cSrcweir m_aPaperFormats.push_back( aInfo ); 1569cdf0e10cSrcweir } 1570cdf0e10cSrcweir rtl_freeMemory( pNamesBuffer ); 1571cdf0e10cSrcweir } 1572cdf0e10cSrcweir else 1573cdf0e10cSrcweir { 1574cdf0e10cSrcweir char* pNamesBuffer = (char*)rtl_allocateMemory(nCount*64); 1575cdf0e10cSrcweir ImplDeviceCaps( this, DC_PAPERNAMES, (BYTE*)pNamesBuffer, pSetupData ); 1576cdf0e10cSrcweir for( DWORD i = 0; i < nCount; ++i ) 1577cdf0e10cSrcweir { 1578cdf0e10cSrcweir PaperInfo aInfo(pPaperSizes[i].x * 10, pPaperSizes[i].y * 10); 1579cdf0e10cSrcweir m_aPaperFormats.push_back( aInfo ); 1580cdf0e10cSrcweir } 1581cdf0e10cSrcweir rtl_freeMemory( pNamesBuffer ); 1582cdf0e10cSrcweir } 1583cdf0e10cSrcweir rtl_freeMemory( pPaperSizes ); 1584cdf0e10cSrcweir } 1585cdf0e10cSrcweir 1586cdf0e10cSrcweir m_bPapersInit = true; 1587cdf0e10cSrcweir } 1588cdf0e10cSrcweir 1589cdf0e10cSrcweir // ----------------------------------------------------------------------- 1590cdf0e10cSrcweir 1591cdf0e10cSrcweir int WinSalInfoPrinter::GetLandscapeAngle( const ImplJobSetup* pSetupData ) 1592cdf0e10cSrcweir { 1593cdf0e10cSrcweir int nRet = ImplDeviceCaps( this, DC_ORIENTATION, NULL, pSetupData ); 1594cdf0e10cSrcweir 1595cdf0e10cSrcweir if( nRet != GDI_ERROR ) 1596cdf0e10cSrcweir return nRet * 10; 1597cdf0e10cSrcweir else 1598cdf0e10cSrcweir return 900; // guess 1599cdf0e10cSrcweir } 1600cdf0e10cSrcweir 1601cdf0e10cSrcweir // ----------------------------------------------------------------------- 1602cdf0e10cSrcweir 1603cdf0e10cSrcweir SalGraphics* WinSalInfoPrinter::GetGraphics() 1604cdf0e10cSrcweir { 1605cdf0e10cSrcweir if ( mbGraphics ) 1606cdf0e10cSrcweir return NULL; 1607cdf0e10cSrcweir 1608cdf0e10cSrcweir if ( mpGraphics ) 1609cdf0e10cSrcweir mbGraphics = TRUE; 1610cdf0e10cSrcweir 1611cdf0e10cSrcweir return mpGraphics; 1612cdf0e10cSrcweir } 1613cdf0e10cSrcweir 1614cdf0e10cSrcweir // ----------------------------------------------------------------------- 1615cdf0e10cSrcweir 1616cdf0e10cSrcweir void WinSalInfoPrinter::ReleaseGraphics( SalGraphics* ) 1617cdf0e10cSrcweir { 1618cdf0e10cSrcweir mbGraphics = FALSE; 1619cdf0e10cSrcweir } 1620cdf0e10cSrcweir 1621cdf0e10cSrcweir // ----------------------------------------------------------------------- 1622cdf0e10cSrcweir 1623cdf0e10cSrcweir sal_Bool WinSalInfoPrinter::Setup( SalFrame* pFrame, ImplJobSetup* pSetupData ) 1624cdf0e10cSrcweir { 1625cdf0e10cSrcweir if ( ImplUpdateSalJobSetup( this, pSetupData, TRUE, static_cast<WinSalFrame*>(pFrame) ) ) 1626cdf0e10cSrcweir { 1627cdf0e10cSrcweir ImplDevModeToJobSetup( this, pSetupData, SAL_JOBSET_ALL ); 1628cdf0e10cSrcweir return ImplUpdateSalPrnIC( this, pSetupData ); 1629cdf0e10cSrcweir } 1630cdf0e10cSrcweir 1631cdf0e10cSrcweir return FALSE; 1632cdf0e10cSrcweir } 1633cdf0e10cSrcweir 1634cdf0e10cSrcweir // ----------------------------------------------------------------------- 1635cdf0e10cSrcweir 1636cdf0e10cSrcweir sal_Bool WinSalInfoPrinter::SetPrinterData( ImplJobSetup* pSetupData ) 1637cdf0e10cSrcweir { 1638cdf0e10cSrcweir if ( !ImplTestSalJobSetup( this, pSetupData, FALSE ) ) 1639cdf0e10cSrcweir return FALSE; 1640cdf0e10cSrcweir return ImplUpdateSalPrnIC( this, pSetupData ); 1641cdf0e10cSrcweir } 1642cdf0e10cSrcweir 1643cdf0e10cSrcweir // ----------------------------------------------------------------------- 1644cdf0e10cSrcweir 1645cdf0e10cSrcweir sal_Bool WinSalInfoPrinter::SetData( sal_uLong nFlags, ImplJobSetup* pSetupData ) 1646cdf0e10cSrcweir { 1647cdf0e10cSrcweir ImplJobSetupToDevMode( this, pSetupData, nFlags ); 1648cdf0e10cSrcweir if ( ImplUpdateSalJobSetup( this, pSetupData, TRUE, NULL ) ) 1649cdf0e10cSrcweir { 1650cdf0e10cSrcweir ImplDevModeToJobSetup( this, pSetupData, nFlags ); 1651cdf0e10cSrcweir return ImplUpdateSalPrnIC( this, pSetupData ); 1652cdf0e10cSrcweir } 1653cdf0e10cSrcweir 1654cdf0e10cSrcweir return FALSE; 1655cdf0e10cSrcweir } 1656cdf0e10cSrcweir 1657cdf0e10cSrcweir // ----------------------------------------------------------------------- 1658cdf0e10cSrcweir 1659cdf0e10cSrcweir sal_uLong WinSalInfoPrinter::GetPaperBinCount( const ImplJobSetup* pSetupData ) 1660cdf0e10cSrcweir { 1661cdf0e10cSrcweir DWORD nRet = ImplDeviceCaps( this, DC_BINS, NULL, pSetupData ); 1662cdf0e10cSrcweir if ( nRet && (nRet != GDI_ERROR) ) 1663cdf0e10cSrcweir return nRet; 1664cdf0e10cSrcweir else 1665cdf0e10cSrcweir return 0; 1666cdf0e10cSrcweir } 1667cdf0e10cSrcweir 1668cdf0e10cSrcweir // ----------------------------------------------------------------------- 1669cdf0e10cSrcweir 1670cdf0e10cSrcweir XubString WinSalInfoPrinter::GetPaperBinName( const ImplJobSetup* pSetupData, sal_uLong nPaperBin ) 1671cdf0e10cSrcweir { 1672cdf0e10cSrcweir XubString aPaperBinName; 1673cdf0e10cSrcweir 1674cdf0e10cSrcweir DWORD nBins = ImplDeviceCaps( this, DC_BINNAMES, NULL, pSetupData ); 1675cdf0e10cSrcweir if ( (nPaperBin < nBins) && (nBins != GDI_ERROR) ) 1676cdf0e10cSrcweir { 1677cdf0e10cSrcweir if( aSalShlData.mbWPrinter ) 1678cdf0e10cSrcweir { 1679cdf0e10cSrcweir sal_Unicode* pBuffer = new sal_Unicode[nBins*24]; 1680cdf0e10cSrcweir DWORD nRet = ImplDeviceCaps( this, DC_BINNAMES, (BYTE*)pBuffer, pSetupData ); 1681cdf0e10cSrcweir if ( nRet && (nRet != GDI_ERROR) ) 1682cdf0e10cSrcweir aPaperBinName = pBuffer + (nPaperBin*24); 1683cdf0e10cSrcweir delete [] pBuffer; 1684cdf0e10cSrcweir } 1685cdf0e10cSrcweir else 1686cdf0e10cSrcweir { 1687cdf0e10cSrcweir char* pBuffer = new char[nBins*24]; 1688cdf0e10cSrcweir DWORD nRet = ImplDeviceCaps( this, DC_BINNAMES, (BYTE*)pBuffer, pSetupData ); 1689cdf0e10cSrcweir if ( nRet && (nRet != GDI_ERROR) ) 1690cdf0e10cSrcweir aPaperBinName = ImplSalGetUniString( (const char*)(pBuffer + (nPaperBin*24)) ); 1691cdf0e10cSrcweir delete [] pBuffer; 1692cdf0e10cSrcweir } 1693cdf0e10cSrcweir } 1694cdf0e10cSrcweir 1695cdf0e10cSrcweir return aPaperBinName; 1696cdf0e10cSrcweir } 1697cdf0e10cSrcweir 1698cdf0e10cSrcweir // ----------------------------------------------------------------------- 1699cdf0e10cSrcweir 1700cdf0e10cSrcweir sal_uLong WinSalInfoPrinter::GetCapabilities( const ImplJobSetup* pSetupData, sal_uInt16 nType ) 1701cdf0e10cSrcweir { 1702cdf0e10cSrcweir DWORD nRet; 1703cdf0e10cSrcweir 1704cdf0e10cSrcweir switch ( nType ) 1705cdf0e10cSrcweir { 1706cdf0e10cSrcweir case PRINTER_CAPABILITIES_SUPPORTDIALOG: 1707cdf0e10cSrcweir return TRUE; 1708cdf0e10cSrcweir case PRINTER_CAPABILITIES_COPIES: 1709cdf0e10cSrcweir nRet = ImplDeviceCaps( this, DC_COPIES, NULL, pSetupData ); 1710cdf0e10cSrcweir if ( nRet && (nRet != GDI_ERROR) ) 1711cdf0e10cSrcweir return nRet; 1712cdf0e10cSrcweir return 0; 1713cdf0e10cSrcweir case PRINTER_CAPABILITIES_COLLATECOPIES: 1714cdf0e10cSrcweir if ( aSalShlData.mbW40 ) 1715cdf0e10cSrcweir { 1716cdf0e10cSrcweir nRet = ImplDeviceCaps( this, DC_COLLATE, NULL, pSetupData ); 1717cdf0e10cSrcweir if ( nRet && (nRet != GDI_ERROR) ) 1718cdf0e10cSrcweir { 1719cdf0e10cSrcweir nRet = ImplDeviceCaps( this, DC_COPIES, NULL, pSetupData ); 1720cdf0e10cSrcweir if ( nRet && (nRet != GDI_ERROR) ) 1721cdf0e10cSrcweir return nRet; 1722cdf0e10cSrcweir } 1723cdf0e10cSrcweir } 1724cdf0e10cSrcweir return 0; 1725cdf0e10cSrcweir 1726cdf0e10cSrcweir case PRINTER_CAPABILITIES_SETORIENTATION: 1727cdf0e10cSrcweir nRet = ImplDeviceCaps( this, DC_ORIENTATION, NULL, pSetupData ); 1728cdf0e10cSrcweir if ( nRet && (nRet != GDI_ERROR) ) 1729cdf0e10cSrcweir return TRUE; 1730cdf0e10cSrcweir return FALSE; 1731cdf0e10cSrcweir 1732cdf0e10cSrcweir case PRINTER_CAPABILITIES_SETPAPERBIN: 1733cdf0e10cSrcweir nRet = ImplDeviceCaps( this, DC_BINS, NULL, pSetupData ); 1734cdf0e10cSrcweir if ( nRet && (nRet != GDI_ERROR) ) 1735cdf0e10cSrcweir return TRUE; 1736cdf0e10cSrcweir return FALSE; 1737cdf0e10cSrcweir 1738cdf0e10cSrcweir case PRINTER_CAPABILITIES_SETPAPERSIZE: 1739cdf0e10cSrcweir case PRINTER_CAPABILITIES_SETPAPER: 1740cdf0e10cSrcweir nRet = ImplDeviceCaps( this, DC_PAPERS, NULL, pSetupData ); 1741cdf0e10cSrcweir if ( nRet && (nRet != GDI_ERROR) ) 1742cdf0e10cSrcweir return TRUE; 1743cdf0e10cSrcweir return FALSE; 1744cdf0e10cSrcweir } 1745cdf0e10cSrcweir 1746cdf0e10cSrcweir return 0; 1747cdf0e10cSrcweir } 1748cdf0e10cSrcweir 1749cdf0e10cSrcweir // ----------------------------------------------------------------------- 1750cdf0e10cSrcweir 1751cdf0e10cSrcweir void WinSalInfoPrinter::GetPageInfo( const ImplJobSetup*, 1752cdf0e10cSrcweir long& rOutWidth, long& rOutHeight, 1753cdf0e10cSrcweir long& rPageOffX, long& rPageOffY, 1754cdf0e10cSrcweir long& rPageWidth, long& rPageHeight ) 1755cdf0e10cSrcweir { 1756cdf0e10cSrcweir HDC hDC = mhDC; 1757cdf0e10cSrcweir 1758cdf0e10cSrcweir rOutWidth = GetDeviceCaps( hDC, HORZRES ); 1759cdf0e10cSrcweir rOutHeight = GetDeviceCaps( hDC, VERTRES ); 1760cdf0e10cSrcweir 1761cdf0e10cSrcweir rPageOffX = GetDeviceCaps( hDC, PHYSICALOFFSETX ); 1762cdf0e10cSrcweir rPageOffY = GetDeviceCaps( hDC, PHYSICALOFFSETY ); 1763cdf0e10cSrcweir rPageWidth = GetDeviceCaps( hDC, PHYSICALWIDTH ); 1764cdf0e10cSrcweir rPageHeight = GetDeviceCaps( hDC, PHYSICALHEIGHT ); 1765cdf0e10cSrcweir } 1766cdf0e10cSrcweir 1767cdf0e10cSrcweir // ======================================================================= 1768cdf0e10cSrcweir 1769cdf0e10cSrcweir SalPrinter* WinSalInstance::CreatePrinter( SalInfoPrinter* pInfoPrinter ) 1770cdf0e10cSrcweir { 1771cdf0e10cSrcweir WinSalPrinter* pPrinter = new WinSalPrinter; 1772cdf0e10cSrcweir pPrinter->mpInfoPrinter = static_cast<WinSalInfoPrinter*>(pInfoPrinter); 1773cdf0e10cSrcweir return pPrinter; 1774cdf0e10cSrcweir } 1775cdf0e10cSrcweir 1776cdf0e10cSrcweir // ----------------------------------------------------------------------- 1777cdf0e10cSrcweir 1778cdf0e10cSrcweir void WinSalInstance::DestroyPrinter( SalPrinter* pPrinter ) 1779cdf0e10cSrcweir { 1780cdf0e10cSrcweir delete pPrinter; 1781cdf0e10cSrcweir } 1782cdf0e10cSrcweir 1783cdf0e10cSrcweir // ======================================================================= 1784cdf0e10cSrcweir 1785cdf0e10cSrcweir BOOL CALLBACK SalPrintAbortProc( HDC hPrnDC, int /* nError */ ) 1786cdf0e10cSrcweir { 1787cdf0e10cSrcweir SalData* pSalData = GetSalData(); 1788cdf0e10cSrcweir WinSalPrinter* pPrinter; 1789cdf0e10cSrcweir sal_Bool bWhile = TRUE; 1790cdf0e10cSrcweir int i = 0; 1791cdf0e10cSrcweir 1792cdf0e10cSrcweir do 1793cdf0e10cSrcweir { 1794cdf0e10cSrcweir // Messages verarbeiten 1795cdf0e10cSrcweir MSG aMsg; 1796cdf0e10cSrcweir if ( ImplPeekMessage( &aMsg, 0, 0, 0, PM_REMOVE ) ) 1797cdf0e10cSrcweir { 1798cdf0e10cSrcweir if ( !ImplInterceptChildWindowKeyDown( aMsg ) ) 1799cdf0e10cSrcweir { 1800cdf0e10cSrcweir TranslateMessage( &aMsg ); 1801cdf0e10cSrcweir ImplDispatchMessage( &aMsg ); 1802cdf0e10cSrcweir } 1803cdf0e10cSrcweir i++; 1804cdf0e10cSrcweir if ( i > 15 ) 1805cdf0e10cSrcweir bWhile = FALSE; 1806cdf0e10cSrcweir } 1807cdf0e10cSrcweir else 1808cdf0e10cSrcweir bWhile = FALSE; 1809cdf0e10cSrcweir 1810cdf0e10cSrcweir pPrinter = pSalData->mpFirstPrinter; 1811cdf0e10cSrcweir while ( pPrinter ) 1812cdf0e10cSrcweir { 1813cdf0e10cSrcweir if( pPrinter->mhDC == hPrnDC ) 1814cdf0e10cSrcweir break; 1815cdf0e10cSrcweir 1816cdf0e10cSrcweir pPrinter = pPrinter->mpNextPrinter; 1817cdf0e10cSrcweir } 1818cdf0e10cSrcweir 1819cdf0e10cSrcweir if ( !pPrinter || pPrinter->mbAbort ) 1820cdf0e10cSrcweir return FALSE; 1821cdf0e10cSrcweir } 1822cdf0e10cSrcweir while ( bWhile ); 1823cdf0e10cSrcweir 1824cdf0e10cSrcweir return TRUE; 1825cdf0e10cSrcweir } 1826cdf0e10cSrcweir 1827cdf0e10cSrcweir // ----------------------------------------------------------------------- 1828cdf0e10cSrcweir 1829cdf0e10cSrcweir static LPDEVMODEA ImplSalSetCopies( LPDEVMODEA pDevMode, sal_uLong nCopies, sal_Bool bCollate ) 1830cdf0e10cSrcweir { 1831cdf0e10cSrcweir LPDEVMODEA pNewDevMode = pDevMode; 1832cdf0e10cSrcweir if ( pDevMode && (nCopies > 1) ) 1833cdf0e10cSrcweir { 1834cdf0e10cSrcweir if ( nCopies > 32765 ) 1835cdf0e10cSrcweir nCopies = 32765; 1836cdf0e10cSrcweir sal_uLong nDevSize = pDevMode->dmSize+pDevMode->dmDriverExtra; 1837cdf0e10cSrcweir pNewDevMode = (LPDEVMODEA)rtl_allocateMemory( nDevSize ); 1838cdf0e10cSrcweir memcpy( pNewDevMode, pDevMode, nDevSize ); 1839cdf0e10cSrcweir pDevMode = pNewDevMode; 1840cdf0e10cSrcweir pDevMode->dmFields |= DM_COPIES; 1841cdf0e10cSrcweir pDevMode->dmCopies = (short)(sal_uInt16)nCopies; 1842cdf0e10cSrcweir if ( aSalShlData.mbW40 ) 1843cdf0e10cSrcweir { 1844cdf0e10cSrcweir pDevMode->dmFields |= DM_COLLATE; 1845cdf0e10cSrcweir if ( bCollate ) 1846cdf0e10cSrcweir pDevMode->dmCollate = DMCOLLATE_TRUE; 1847cdf0e10cSrcweir else 1848cdf0e10cSrcweir pDevMode->dmCollate = DMCOLLATE_FALSE; 1849cdf0e10cSrcweir } 1850cdf0e10cSrcweir } 1851cdf0e10cSrcweir 1852cdf0e10cSrcweir return pNewDevMode; 1853cdf0e10cSrcweir } 1854cdf0e10cSrcweir 1855cdf0e10cSrcweir static LPDEVMODEW ImplSalSetCopies( LPDEVMODEW pDevMode, sal_uLong nCopies, sal_Bool bCollate ) 1856cdf0e10cSrcweir { 1857cdf0e10cSrcweir LPDEVMODEW pNewDevMode = pDevMode; 1858cdf0e10cSrcweir if ( pDevMode && (nCopies > 1) ) 1859cdf0e10cSrcweir { 1860cdf0e10cSrcweir if ( nCopies > 32765 ) 1861cdf0e10cSrcweir nCopies = 32765; 1862cdf0e10cSrcweir sal_uLong nDevSize = pDevMode->dmSize+pDevMode->dmDriverExtra; 1863cdf0e10cSrcweir pNewDevMode = (LPDEVMODEW)rtl_allocateMemory( nDevSize ); 1864cdf0e10cSrcweir memcpy( pNewDevMode, pDevMode, nDevSize ); 1865cdf0e10cSrcweir pDevMode = pNewDevMode; 1866cdf0e10cSrcweir pDevMode->dmFields |= DM_COPIES; 1867cdf0e10cSrcweir pDevMode->dmCopies = (short)(sal_uInt16)nCopies; 1868cdf0e10cSrcweir if ( aSalShlData.mbW40 ) 1869cdf0e10cSrcweir { 1870cdf0e10cSrcweir pDevMode->dmFields |= DM_COLLATE; 1871cdf0e10cSrcweir if ( bCollate ) 1872cdf0e10cSrcweir pDevMode->dmCollate = DMCOLLATE_TRUE; 1873cdf0e10cSrcweir else 1874cdf0e10cSrcweir pDevMode->dmCollate = DMCOLLATE_FALSE; 1875cdf0e10cSrcweir } 1876cdf0e10cSrcweir } 1877cdf0e10cSrcweir 1878cdf0e10cSrcweir return pNewDevMode; 1879cdf0e10cSrcweir } 1880cdf0e10cSrcweir 1881cdf0e10cSrcweir // ----------------------------------------------------------------------- 1882cdf0e10cSrcweir 1883cdf0e10cSrcweir WinSalPrinter::WinSalPrinter() : 1884cdf0e10cSrcweir mpGraphics( NULL ), 1885cdf0e10cSrcweir mpInfoPrinter( NULL ), 1886cdf0e10cSrcweir mpNextPrinter( NULL ), 1887cdf0e10cSrcweir mhDC( 0 ), 1888cdf0e10cSrcweir mnError( 0 ), 1889cdf0e10cSrcweir mnCopies( 0 ), 1890cdf0e10cSrcweir mbCollate( FALSE ), 1891cdf0e10cSrcweir mbAbort( FALSE ), 1892cdf0e10cSrcweir mbValid( true ) 1893cdf0e10cSrcweir { 1894cdf0e10cSrcweir SalData* pSalData = GetSalData(); 1895cdf0e10cSrcweir // insert printer in printerlist 1896cdf0e10cSrcweir mpNextPrinter = pSalData->mpFirstPrinter; 1897cdf0e10cSrcweir pSalData->mpFirstPrinter = this; 1898cdf0e10cSrcweir } 1899cdf0e10cSrcweir 1900cdf0e10cSrcweir // ----------------------------------------------------------------------- 1901cdf0e10cSrcweir 1902cdf0e10cSrcweir WinSalPrinter::~WinSalPrinter() 1903cdf0e10cSrcweir { 1904cdf0e10cSrcweir SalData* pSalData = GetSalData(); 1905cdf0e10cSrcweir 1906cdf0e10cSrcweir // release DC if there is one still around because of AbortJob 1907cdf0e10cSrcweir HDC hDC = mhDC; 1908cdf0e10cSrcweir if ( hDC ) 1909cdf0e10cSrcweir { 1910cdf0e10cSrcweir if ( mpGraphics ) 1911cdf0e10cSrcweir { 1912cdf0e10cSrcweir ImplSalDeInitGraphics( mpGraphics ); 1913cdf0e10cSrcweir delete mpGraphics; 1914cdf0e10cSrcweir } 1915cdf0e10cSrcweir 1916cdf0e10cSrcweir DeleteDC( hDC ); 1917cdf0e10cSrcweir } 1918cdf0e10cSrcweir 1919cdf0e10cSrcweir // remove printer from printerlist 1920cdf0e10cSrcweir if ( this == pSalData->mpFirstPrinter ) 1921cdf0e10cSrcweir pSalData->mpFirstPrinter = mpNextPrinter; 1922cdf0e10cSrcweir else 1923cdf0e10cSrcweir { 1924cdf0e10cSrcweir WinSalPrinter* pTempPrinter = pSalData->mpFirstPrinter; 1925cdf0e10cSrcweir 1926cdf0e10cSrcweir while( pTempPrinter->mpNextPrinter != this ) 1927cdf0e10cSrcweir pTempPrinter = pTempPrinter->mpNextPrinter; 1928cdf0e10cSrcweir 1929cdf0e10cSrcweir pTempPrinter->mpNextPrinter = mpNextPrinter; 1930cdf0e10cSrcweir } 1931cdf0e10cSrcweir mbValid = false; 1932cdf0e10cSrcweir } 1933cdf0e10cSrcweir 1934cdf0e10cSrcweir // ----------------------------------------------------------------------- 1935cdf0e10cSrcweir 1936cdf0e10cSrcweir void WinSalPrinter::markInvalid() 1937cdf0e10cSrcweir { 1938cdf0e10cSrcweir mbValid = false; 1939cdf0e10cSrcweir } 1940cdf0e10cSrcweir 1941cdf0e10cSrcweir // ----------------------------------------------------------------------- 1942cdf0e10cSrcweir 1943cdf0e10cSrcweir // need wrappers for StarTocW/A to use structured exception handling 1944cdf0e10cSrcweir // since SEH does not mix with standard exception handling's cleanup 1945cdf0e10cSrcweir static int lcl_StartDocW( HDC hDC, DOCINFOW* pInfo, WinSalPrinter* pPrt ) 1946cdf0e10cSrcweir { 1947cdf0e10cSrcweir int nRet = 0; 1948cdf0e10cSrcweir CATCH_DRIVER_EX_BEGIN; 1949cdf0e10cSrcweir nRet = ::StartDocW( hDC, pInfo ); 1950cdf0e10cSrcweir CATCH_DRIVER_EX_END( "exception in StartDocW", pPrt ); 1951cdf0e10cSrcweir return nRet; 1952cdf0e10cSrcweir } 1953cdf0e10cSrcweir 1954cdf0e10cSrcweir static int lcl_StartDocA( HDC hDC, DOCINFOA* pInfo, WinSalPrinter* pPrt ) 1955cdf0e10cSrcweir { 1956cdf0e10cSrcweir int nRet = 0; 1957cdf0e10cSrcweir CATCH_DRIVER_EX_BEGIN; 1958cdf0e10cSrcweir nRet = ::StartDocA( hDC, pInfo ); 1959cdf0e10cSrcweir CATCH_DRIVER_EX_END( "exception in StartDocW", pPrt ); 1960cdf0e10cSrcweir return nRet; 1961cdf0e10cSrcweir } 1962cdf0e10cSrcweir 1963cdf0e10cSrcweir sal_Bool WinSalPrinter::StartJob( const XubString* pFileName, 1964cdf0e10cSrcweir const XubString& rJobName, 1965cdf0e10cSrcweir const XubString&, 1966cdf0e10cSrcweir sal_uLong nCopies, 1967cdf0e10cSrcweir bool bCollate, 1968cdf0e10cSrcweir bool /*bDirect*/, 1969cdf0e10cSrcweir ImplJobSetup* pSetupData ) 1970cdf0e10cSrcweir { 1971cdf0e10cSrcweir mnError = 0; 1972cdf0e10cSrcweir mbAbort = FALSE; 1973cdf0e10cSrcweir mnCopies = nCopies; 1974cdf0e10cSrcweir mbCollate = bCollate; 1975cdf0e10cSrcweir 1976cdf0e10cSrcweir LPDEVMODEA pOrgDevModeA = NULL; 1977cdf0e10cSrcweir LPDEVMODEA pDevModeA = NULL; 1978cdf0e10cSrcweir LPDEVMODEW pOrgDevModeW = NULL; 1979cdf0e10cSrcweir LPDEVMODEW pDevModeW = NULL; 1980cdf0e10cSrcweir HDC hDC = 0; 1981cdf0e10cSrcweir if( aSalShlData.mbWPrinter ) 1982cdf0e10cSrcweir { 1983cdf0e10cSrcweir if ( pSetupData && pSetupData->mpDriverData ) 1984cdf0e10cSrcweir { 1985cdf0e10cSrcweir pOrgDevModeW = SAL_DEVMODE_W( pSetupData ); 1986cdf0e10cSrcweir pDevModeW = ImplSalSetCopies( pOrgDevModeW, nCopies, bCollate ); 1987cdf0e10cSrcweir } 1988cdf0e10cSrcweir else 1989cdf0e10cSrcweir pDevModeW = NULL; 1990cdf0e10cSrcweir 1991cdf0e10cSrcweir // #95347 some buggy drivers (eg, OKI) write to those buffers in CreateDC, although declared const - so provide some space 1992cdf0e10cSrcweir sal_Unicode aDrvBuf[4096]; 1993cdf0e10cSrcweir sal_Unicode aDevBuf[4096]; 1994cdf0e10cSrcweir rtl_copyMemory( aDrvBuf, mpInfoPrinter->maDriverName.GetBuffer(), (mpInfoPrinter->maDriverName.Len()+1)*sizeof(sal_Unicode)); 1995cdf0e10cSrcweir rtl_copyMemory( aDevBuf, mpInfoPrinter->maDeviceName.GetBuffer(), (mpInfoPrinter->maDeviceName.Len()+1)*sizeof(sal_Unicode)); 1996cdf0e10cSrcweir hDC = CreateDCW( reinterpret_cast<LPCWSTR>(aDrvBuf), 1997cdf0e10cSrcweir reinterpret_cast<LPCWSTR>(aDevBuf), 1998cdf0e10cSrcweir NULL, 1999cdf0e10cSrcweir pDevModeW ); 2000cdf0e10cSrcweir 2001cdf0e10cSrcweir if ( pDevModeW != pOrgDevModeW ) 2002cdf0e10cSrcweir rtl_freeMemory( pDevModeW ); 2003cdf0e10cSrcweir } 2004cdf0e10cSrcweir else 2005cdf0e10cSrcweir { 2006cdf0e10cSrcweir if ( pSetupData && pSetupData->mpDriverData ) 2007cdf0e10cSrcweir { 2008cdf0e10cSrcweir pOrgDevModeA = SAL_DEVMODE_A( pSetupData ); 2009cdf0e10cSrcweir pDevModeA = ImplSalSetCopies( pOrgDevModeA, nCopies, bCollate ); 2010cdf0e10cSrcweir } 2011cdf0e10cSrcweir else 2012cdf0e10cSrcweir pDevModeA = NULL; 2013cdf0e10cSrcweir 2014cdf0e10cSrcweir // #95347 some buggy drivers (eg, OKI) write to those buffers in CreateDC, although declared const - so provide some space 2015cdf0e10cSrcweir ByteString aDriver ( ImplSalGetWinAnsiString( mpInfoPrinter->maDriverName, TRUE ) ); 2016cdf0e10cSrcweir ByteString aDevice ( ImplSalGetWinAnsiString( mpInfoPrinter->maDeviceName, TRUE ) ); 2017cdf0e10cSrcweir int n = aDriver.Len() > aDevice.Len() ? aDriver.Len() : aDevice.Len(); 2018cdf0e10cSrcweir n += 2048; 2019cdf0e10cSrcweir char *lpszDriverName = new char[n]; 2020cdf0e10cSrcweir char *lpszDeviceName = new char[n]; 2021cdf0e10cSrcweir strncpy( lpszDriverName, aDriver.GetBuffer(), n ); 2022cdf0e10cSrcweir strncpy( lpszDeviceName, aDevice.GetBuffer(), n ); 2023cdf0e10cSrcweir hDC = CreateDCA( lpszDriverName, 2024cdf0e10cSrcweir lpszDeviceName, 2025cdf0e10cSrcweir NULL, 2026cdf0e10cSrcweir pDevModeA ); 2027cdf0e10cSrcweir 2028cdf0e10cSrcweir delete [] lpszDriverName; 2029cdf0e10cSrcweir delete [] lpszDeviceName; 2030cdf0e10cSrcweir 2031cdf0e10cSrcweir if ( pDevModeA != pOrgDevModeA ) 2032cdf0e10cSrcweir rtl_freeMemory( pDevModeA ); 2033cdf0e10cSrcweir } 2034cdf0e10cSrcweir 2035cdf0e10cSrcweir if ( !hDC ) 2036cdf0e10cSrcweir { 2037cdf0e10cSrcweir mnError = SAL_PRINTER_ERROR_GENERALERROR; 2038cdf0e10cSrcweir return FALSE; 2039cdf0e10cSrcweir } 2040cdf0e10cSrcweir 2041cdf0e10cSrcweir // make sure mhDC is set before the printer driver may call our abortproc 2042cdf0e10cSrcweir mhDC = hDC; 2043cdf0e10cSrcweir if ( SetAbortProc( hDC, SalPrintAbortProc ) <= 0 ) 2044cdf0e10cSrcweir { 2045cdf0e10cSrcweir mnError = SAL_PRINTER_ERROR_GENERALERROR; 2046cdf0e10cSrcweir return FALSE; 2047cdf0e10cSrcweir } 2048cdf0e10cSrcweir 2049cdf0e10cSrcweir mnError = 0; 2050cdf0e10cSrcweir mbAbort = FALSE; 2051cdf0e10cSrcweir 2052cdf0e10cSrcweir // Wegen Telocom Balloon Fax-Treiber, der uns unsere Messages 2053cdf0e10cSrcweir // ansonsten oefters schickt, versuchen wir vorher alle 2054cdf0e10cSrcweir // zu verarbeiten und dann eine Dummy-Message reinstellen 2055cdf0e10cSrcweir sal_Bool bWhile = TRUE; 2056cdf0e10cSrcweir int i = 0; 2057cdf0e10cSrcweir do 2058cdf0e10cSrcweir { 2059cdf0e10cSrcweir // Messages verarbeiten 2060cdf0e10cSrcweir MSG aMsg; 2061cdf0e10cSrcweir if ( ImplPeekMessage( &aMsg, 0, 0, 0, PM_REMOVE ) ) 2062cdf0e10cSrcweir { 2063cdf0e10cSrcweir if ( !ImplInterceptChildWindowKeyDown( aMsg ) ) 2064cdf0e10cSrcweir { 2065cdf0e10cSrcweir TranslateMessage( &aMsg ); 2066cdf0e10cSrcweir ImplDispatchMessage( &aMsg ); 2067cdf0e10cSrcweir } 2068cdf0e10cSrcweir 2069cdf0e10cSrcweir i++; 2070cdf0e10cSrcweir if ( i > 15 ) 2071cdf0e10cSrcweir bWhile = FALSE; 2072cdf0e10cSrcweir } 2073cdf0e10cSrcweir else 2074cdf0e10cSrcweir bWhile = FALSE; 2075cdf0e10cSrcweir } 2076cdf0e10cSrcweir while ( bWhile ); 2077cdf0e10cSrcweir ImplPostMessage( GetSalData()->mpFirstInstance->mhComWnd, SAL_MSG_DUMMY, 0, 0 ); 2078cdf0e10cSrcweir 2079cdf0e10cSrcweir // bring up a file choser if printing to file port but no file name given 2080cdf0e10cSrcweir OUString aOutFileName; 2081cdf0e10cSrcweir if( mpInfoPrinter->maPortName.EqualsIgnoreCaseAscii( "FILE:" ) && !(pFileName && pFileName->Len()) ) 2082cdf0e10cSrcweir { 2083cdf0e10cSrcweir 2084cdf0e10cSrcweir uno::Reference< lang::XMultiServiceFactory > xFactory( ::comphelper::getProcessServiceFactory() ); 2085cdf0e10cSrcweir if( xFactory.is() ) 2086cdf0e10cSrcweir { 2087cdf0e10cSrcweir uno::Reference< XFilePicker > xFilePicker( xFactory->createInstance( 2088cdf0e10cSrcweir OUString( RTL_CONSTASCII_USTRINGPARAM( "com.sun.star.ui.dialogs.FilePicker" ) ) ), 2089cdf0e10cSrcweir UNO_QUERY ); 2090cdf0e10cSrcweir DBG_ASSERT( xFilePicker.is(), "could not get FilePicker service" ); 2091cdf0e10cSrcweir 2092cdf0e10cSrcweir uno::Reference< XInitialization > xInit( xFilePicker, UNO_QUERY ); 2093cdf0e10cSrcweir uno::Reference< XFilterManager > xFilterMgr( xFilePicker, UNO_QUERY ); 2094cdf0e10cSrcweir if( xInit.is() && xFilePicker.is() && xFilterMgr.is() ) 2095cdf0e10cSrcweir { 2096cdf0e10cSrcweir Sequence< Any > aServiceType( 1 ); 2097cdf0e10cSrcweir aServiceType[0] <<= TemplateDescription::FILESAVE_SIMPLE; 2098cdf0e10cSrcweir xInit->initialize( aServiceType ); 2099cdf0e10cSrcweir if( xFilePicker->execute() == ExecutableDialogResults::OK ) 2100cdf0e10cSrcweir { 2101cdf0e10cSrcweir Sequence< OUString > aPathSeq( xFilePicker->getFiles() ); 2102cdf0e10cSrcweir INetURLObject aObj( aPathSeq[0] ); 2103cdf0e10cSrcweir // we're using ansi calls (StartDocA) so convert the string 2104cdf0e10cSrcweir aOutFileName = aObj.PathToFileName(); 2105cdf0e10cSrcweir } 2106cdf0e10cSrcweir else 2107cdf0e10cSrcweir { 2108cdf0e10cSrcweir mnError = SAL_PRINTER_ERROR_ABORT; 2109cdf0e10cSrcweir return FALSE; 2110cdf0e10cSrcweir } 2111cdf0e10cSrcweir } 2112cdf0e10cSrcweir } 2113cdf0e10cSrcweir } 2114cdf0e10cSrcweir 2115cdf0e10cSrcweir if( aSalShlData.mbWPrinter ) 2116cdf0e10cSrcweir { 2117cdf0e10cSrcweir DOCINFOW aInfo; 2118cdf0e10cSrcweir memset( &aInfo, 0, sizeof( DOCINFOW ) ); 2119cdf0e10cSrcweir aInfo.cbSize = sizeof( aInfo ); 2120cdf0e10cSrcweir aInfo.lpszDocName = (LPWSTR)rJobName.GetBuffer(); 2121cdf0e10cSrcweir if ( pFileName || aOutFileName.getLength() ) 2122cdf0e10cSrcweir { 2123cdf0e10cSrcweir if ( (pFileName && pFileName->Len()) || aOutFileName.getLength() ) 2124cdf0e10cSrcweir { 2125cdf0e10cSrcweir aInfo.lpszOutput = (LPWSTR)( (pFileName && pFileName->Len()) ? pFileName->GetBuffer() : aOutFileName.getStr()); 2126cdf0e10cSrcweir } 2127cdf0e10cSrcweir else 2128cdf0e10cSrcweir aInfo.lpszOutput = L"FILE:"; 2129cdf0e10cSrcweir } 2130cdf0e10cSrcweir else 2131cdf0e10cSrcweir aInfo.lpszOutput = NULL; 2132cdf0e10cSrcweir 2133cdf0e10cSrcweir // start Job 2134cdf0e10cSrcweir int nRet = lcl_StartDocW( hDC, &aInfo, this ); 2135cdf0e10cSrcweir 2136cdf0e10cSrcweir if ( nRet <= 0 ) 2137cdf0e10cSrcweir { 2138cdf0e10cSrcweir long nError = GetLastError(); 2139cdf0e10cSrcweir if ( (nRet == SP_USERABORT) || (nRet == SP_APPABORT) || (nError == ERROR_PRINT_CANCELLED) || (nError == ERROR_CANCELLED) ) 2140cdf0e10cSrcweir mnError = SAL_PRINTER_ERROR_ABORT; 2141cdf0e10cSrcweir else 2142cdf0e10cSrcweir mnError = SAL_PRINTER_ERROR_GENERALERROR; 2143cdf0e10cSrcweir return FALSE; 2144cdf0e10cSrcweir } 2145cdf0e10cSrcweir } 2146cdf0e10cSrcweir else 2147cdf0e10cSrcweir { 2148cdf0e10cSrcweir // Both strings must exist, if StartJob() is called 2149cdf0e10cSrcweir ByteString aJobName( ImplSalGetWinAnsiString( rJobName, TRUE ) ); 2150cdf0e10cSrcweir ByteString aFileName; 2151cdf0e10cSrcweir 2152cdf0e10cSrcweir DOCINFOA aInfo; 2153cdf0e10cSrcweir memset( &aInfo, 0, sizeof( DOCINFOA ) ); 2154cdf0e10cSrcweir aInfo.cbSize = sizeof( aInfo ); 2155cdf0e10cSrcweir aInfo.lpszDocName = (LPCSTR)aJobName.GetBuffer(); 2156cdf0e10cSrcweir if ( pFileName || aOutFileName.getLength() ) 2157cdf0e10cSrcweir { 2158cdf0e10cSrcweir if ( pFileName->Len() || aOutFileName.getLength() ) 2159cdf0e10cSrcweir { 2160cdf0e10cSrcweir aFileName = ImplSalGetWinAnsiString( pFileName ? *pFileName : static_cast<const XubString>(aOutFileName), TRUE ); 2161cdf0e10cSrcweir aInfo.lpszOutput = (LPCSTR)aFileName.GetBuffer(); 2162cdf0e10cSrcweir } 2163cdf0e10cSrcweir else 2164cdf0e10cSrcweir aInfo.lpszOutput = "FILE:"; 2165cdf0e10cSrcweir } 2166cdf0e10cSrcweir else 2167cdf0e10cSrcweir aInfo.lpszOutput = NULL; 2168cdf0e10cSrcweir 2169cdf0e10cSrcweir // start Job 2170cdf0e10cSrcweir int nRet = lcl_StartDocA( hDC, &aInfo, this ); 2171cdf0e10cSrcweir if ( nRet <= 0 ) 2172cdf0e10cSrcweir { 2173cdf0e10cSrcweir long nError = GetLastError(); 2174cdf0e10cSrcweir if ( (nRet == SP_USERABORT) || (nRet == SP_APPABORT) || (nError == ERROR_PRINT_CANCELLED) || (nError == ERROR_CANCELLED) ) 2175cdf0e10cSrcweir mnError = SAL_PRINTER_ERROR_ABORT; 2176cdf0e10cSrcweir else 2177cdf0e10cSrcweir mnError = SAL_PRINTER_ERROR_GENERALERROR; 2178cdf0e10cSrcweir return FALSE; 2179cdf0e10cSrcweir } 2180cdf0e10cSrcweir } 2181cdf0e10cSrcweir 2182cdf0e10cSrcweir return TRUE; 2183cdf0e10cSrcweir } 2184cdf0e10cSrcweir 2185cdf0e10cSrcweir // ----------------------------------------------------------------------- 2186cdf0e10cSrcweir 2187cdf0e10cSrcweir sal_Bool WinSalPrinter::EndJob() 2188cdf0e10cSrcweir { 2189cdf0e10cSrcweir DWORD err = 0; 2190cdf0e10cSrcweir HDC hDC = mhDC; 2191cdf0e10cSrcweir if ( isValid() && hDC ) 2192cdf0e10cSrcweir { 2193cdf0e10cSrcweir if ( mpGraphics ) 2194cdf0e10cSrcweir { 2195cdf0e10cSrcweir ImplSalDeInitGraphics( mpGraphics ); 2196cdf0e10cSrcweir delete mpGraphics; 2197cdf0e10cSrcweir mpGraphics = NULL; 2198cdf0e10cSrcweir } 2199cdf0e10cSrcweir 2200cdf0e10cSrcweir // #i54419# Windows fax printer brings up a dialog in EndDoc 2201cdf0e10cSrcweir // which text previously copied in soffice process can be 2202cdf0e10cSrcweir // pasted to -> deadlock due to mutex not released. 2203cdf0e10cSrcweir // it should be safe to release the yield mutex over the EndDoc 2204cdf0e10cSrcweir // call, however the real solution is supposed to be the threading 2205cdf0e10cSrcweir // framework yet to come. 2206cdf0e10cSrcweir SalData* pSalData = GetSalData(); 2207cdf0e10cSrcweir sal_uLong nAcquire = pSalData->mpFirstInstance->ReleaseYieldMutex(); 2208cdf0e10cSrcweir CATCH_DRIVER_EX_BEGIN; 2209cdf0e10cSrcweir if( ::EndDoc( hDC ) <= 0 ) 2210cdf0e10cSrcweir err = GetLastError(); 2211cdf0e10cSrcweir CATCH_DRIVER_EX_END( "exception in EndDoc", this ); 2212cdf0e10cSrcweir 2213cdf0e10cSrcweir pSalData->mpFirstInstance->AcquireYieldMutex( nAcquire ); 2214cdf0e10cSrcweir DeleteDC( hDC ); 2215cdf0e10cSrcweir mhDC = 0; 2216cdf0e10cSrcweir } 2217cdf0e10cSrcweir 2218cdf0e10cSrcweir return TRUE; 2219cdf0e10cSrcweir } 2220cdf0e10cSrcweir 2221cdf0e10cSrcweir // ----------------------------------------------------------------------- 2222cdf0e10cSrcweir 2223cdf0e10cSrcweir sal_Bool WinSalPrinter::AbortJob() 2224cdf0e10cSrcweir { 2225cdf0e10cSrcweir mbAbort = TRUE; 2226cdf0e10cSrcweir 2227cdf0e10cSrcweir // Abort asyncron ausloesen 2228cdf0e10cSrcweir HDC hDC = mhDC; 2229cdf0e10cSrcweir if ( hDC ) 2230cdf0e10cSrcweir { 2231cdf0e10cSrcweir SalData* pSalData = GetSalData(); 2232cdf0e10cSrcweir ImplPostMessage( pSalData->mpFirstInstance->mhComWnd, 2233cdf0e10cSrcweir SAL_MSG_PRINTABORTJOB, (WPARAM)hDC, 0 ); 2234cdf0e10cSrcweir } 2235cdf0e10cSrcweir 2236cdf0e10cSrcweir return TRUE; 2237cdf0e10cSrcweir } 2238cdf0e10cSrcweir 2239cdf0e10cSrcweir // ----------------------------------------------------------------------- 2240cdf0e10cSrcweir 2241cdf0e10cSrcweir void ImplSalPrinterAbortJobAsync( HDC hPrnDC ) 2242cdf0e10cSrcweir { 2243cdf0e10cSrcweir SalData* pSalData = GetSalData(); 2244cdf0e10cSrcweir WinSalPrinter* pPrinter = pSalData->mpFirstPrinter; 2245cdf0e10cSrcweir 2246cdf0e10cSrcweir // Feststellen, ob Printer noch existiert 2247cdf0e10cSrcweir while ( pPrinter ) 2248cdf0e10cSrcweir { 2249cdf0e10cSrcweir if ( pPrinter->mhDC == hPrnDC ) 2250cdf0e10cSrcweir break; 2251cdf0e10cSrcweir 2252cdf0e10cSrcweir pPrinter = pPrinter->mpNextPrinter; 2253cdf0e10cSrcweir } 2254cdf0e10cSrcweir 2255cdf0e10cSrcweir // Wenn Printer noch existiert, dann den Job abbrechen 2256cdf0e10cSrcweir if ( pPrinter ) 2257cdf0e10cSrcweir { 2258cdf0e10cSrcweir HDC hDC = pPrinter->mhDC; 2259cdf0e10cSrcweir if ( hDC ) 2260cdf0e10cSrcweir { 2261cdf0e10cSrcweir if ( pPrinter->mpGraphics ) 2262cdf0e10cSrcweir { 2263cdf0e10cSrcweir ImplSalDeInitGraphics( pPrinter->mpGraphics ); 2264cdf0e10cSrcweir delete pPrinter->mpGraphics; 2265cdf0e10cSrcweir pPrinter->mpGraphics = NULL; 2266cdf0e10cSrcweir } 2267cdf0e10cSrcweir 2268cdf0e10cSrcweir CATCH_DRIVER_EX_BEGIN; 2269cdf0e10cSrcweir ::AbortDoc( hDC ); 2270cdf0e10cSrcweir CATCH_DRIVER_EX_END( "exception in AbortDoc", pPrinter ); 2271cdf0e10cSrcweir 2272cdf0e10cSrcweir DeleteDC( hDC ); 2273cdf0e10cSrcweir pPrinter->mhDC = 0; 2274cdf0e10cSrcweir } 2275cdf0e10cSrcweir } 2276cdf0e10cSrcweir } 2277cdf0e10cSrcweir 2278cdf0e10cSrcweir // ----------------------------------------------------------------------- 2279cdf0e10cSrcweir 2280cdf0e10cSrcweir SalGraphics* WinSalPrinter::StartPage( ImplJobSetup* pSetupData, sal_Bool bNewJobData ) 2281cdf0e10cSrcweir { 2282cdf0e10cSrcweir if( ! isValid() || mhDC == 0 ) 2283cdf0e10cSrcweir return NULL; 2284cdf0e10cSrcweir 2285cdf0e10cSrcweir HDC hDC = mhDC; 2286cdf0e10cSrcweir if ( pSetupData && pSetupData->mpDriverData && bNewJobData ) 2287cdf0e10cSrcweir { 2288cdf0e10cSrcweir if( aSalShlData.mbWPrinter ) 2289cdf0e10cSrcweir { 2290cdf0e10cSrcweir LPDEVMODEW pOrgDevModeW; 2291cdf0e10cSrcweir LPDEVMODEW pDevModeW; 2292cdf0e10cSrcweir pOrgDevModeW = SAL_DEVMODE_W( pSetupData ); 2293cdf0e10cSrcweir pDevModeW = ImplSalSetCopies( pOrgDevModeW, mnCopies, mbCollate ); 2294cdf0e10cSrcweir ResetDCW( hDC, pDevModeW ); 2295cdf0e10cSrcweir if ( pDevModeW != pOrgDevModeW ) 2296cdf0e10cSrcweir rtl_freeMemory( pDevModeW ); 2297cdf0e10cSrcweir } 2298cdf0e10cSrcweir else 2299cdf0e10cSrcweir { 2300cdf0e10cSrcweir LPDEVMODEA pOrgDevModeA; 2301cdf0e10cSrcweir LPDEVMODEA pDevModeA; 2302cdf0e10cSrcweir pOrgDevModeA = SAL_DEVMODE_A( pSetupData ); 2303cdf0e10cSrcweir pDevModeA = ImplSalSetCopies( pOrgDevModeA, mnCopies, mbCollate ); 2304cdf0e10cSrcweir ResetDCA( hDC, pDevModeA ); 2305cdf0e10cSrcweir if ( pDevModeA != pOrgDevModeA ) 2306cdf0e10cSrcweir rtl_freeMemory( pDevModeA ); 2307cdf0e10cSrcweir } 2308cdf0e10cSrcweir } 2309cdf0e10cSrcweir int nRet = 0; 2310cdf0e10cSrcweir CATCH_DRIVER_EX_BEGIN; 2311cdf0e10cSrcweir nRet = ::StartPage( hDC ); 2312cdf0e10cSrcweir CATCH_DRIVER_EX_END( "exception in StartPage", this ); 2313cdf0e10cSrcweir 2314cdf0e10cSrcweir if ( nRet <= 0 ) 2315cdf0e10cSrcweir { 2316cdf0e10cSrcweir GetLastError(); 2317cdf0e10cSrcweir mnError = SAL_PRINTER_ERROR_GENERALERROR; 2318cdf0e10cSrcweir return NULL; 2319cdf0e10cSrcweir } 2320cdf0e10cSrcweir 2321cdf0e10cSrcweir // Hack to work around old PostScript printer drivers optimizing away empty pages 2322cdf0e10cSrcweir // TODO: move into ImplCreateSalPrnGraphics()? 2323cdf0e10cSrcweir HPEN hTempPen = SelectPen( hDC, GetStockPen( NULL_PEN ) ); 2324cdf0e10cSrcweir HBRUSH hTempBrush = SelectBrush( hDC, GetStockBrush( NULL_BRUSH ) ); 2325cdf0e10cSrcweir WIN_Rectangle( hDC, -8000, -8000, -7999, -7999 ); 2326cdf0e10cSrcweir SelectPen( hDC, hTempPen ); 2327cdf0e10cSrcweir SelectBrush( hDC, hTempBrush ); 2328cdf0e10cSrcweir 2329cdf0e10cSrcweir mpGraphics = ImplCreateSalPrnGraphics( hDC ); 2330cdf0e10cSrcweir return mpGraphics; 2331cdf0e10cSrcweir } 2332cdf0e10cSrcweir 2333cdf0e10cSrcweir // ----------------------------------------------------------------------- 2334cdf0e10cSrcweir 2335cdf0e10cSrcweir sal_Bool WinSalPrinter::EndPage() 2336cdf0e10cSrcweir { 2337cdf0e10cSrcweir HDC hDC = mhDC; 2338cdf0e10cSrcweir if ( hDC && mpGraphics ) 2339cdf0e10cSrcweir { 2340cdf0e10cSrcweir ImplSalDeInitGraphics( mpGraphics ); 2341cdf0e10cSrcweir delete mpGraphics; 2342cdf0e10cSrcweir mpGraphics = NULL; 2343cdf0e10cSrcweir } 2344cdf0e10cSrcweir 2345cdf0e10cSrcweir if( ! isValid() ) 2346cdf0e10cSrcweir return FALSE; 2347cdf0e10cSrcweir 2348cdf0e10cSrcweir int nRet = 0; 2349cdf0e10cSrcweir CATCH_DRIVER_EX_BEGIN; 2350cdf0e10cSrcweir nRet = ::EndPage( hDC ); 2351cdf0e10cSrcweir CATCH_DRIVER_EX_END( "exception in EndPage", this ); 2352cdf0e10cSrcweir 2353cdf0e10cSrcweir if ( nRet > 0 ) 2354cdf0e10cSrcweir return TRUE; 2355cdf0e10cSrcweir else 2356cdf0e10cSrcweir { 2357cdf0e10cSrcweir GetLastError(); 2358cdf0e10cSrcweir mnError = SAL_PRINTER_ERROR_GENERALERROR; 2359cdf0e10cSrcweir return FALSE; 2360cdf0e10cSrcweir } 2361cdf0e10cSrcweir } 2362cdf0e10cSrcweir 2363cdf0e10cSrcweir // ----------------------------------------------------------------------- 2364cdf0e10cSrcweir 2365cdf0e10cSrcweir sal_uLong WinSalPrinter::GetErrorCode() 2366cdf0e10cSrcweir { 2367cdf0e10cSrcweir return mnError; 2368cdf0e10cSrcweir } 2369