2 * Exported functions from the PostScript driver.
4 * [Ext]DeviceMode, DeviceCapabilities, AdvancedSetupDialog.
6 * Will need ExtTextOut for winword6 (urgh!)
8 * Copyright 1998 Huw D M Davies
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27 #include "wine/debug.h"
33 WINE_DEFAULT_DEBUG_CHANNEL(psdrv);
36 /************************************************************************
40 * Updates dm1 with some fields from dm2
43 void PSDRV_MergeDevmodes(PSDRV_DEVMODEA *dm1, PSDRV_DEVMODEA *dm2,
46 /* some sanity checks here on dm2 */
48 if(dm2->dmPublic.dmFields & DM_ORIENTATION)
49 dm1->dmPublic.u1.s1.dmOrientation = dm2->dmPublic.u1.s1.dmOrientation;
51 /* NB PaperWidth is always < PaperLength */
53 if(dm2->dmPublic.dmFields & DM_PAPERSIZE) {
56 for(page = pi->ppd->PageSizes; page; page = page->next) {
57 if(page->WinPage == dm2->dmPublic.u1.s1.dmPaperSize)
61 dm1->dmPublic.u1.s1.dmPaperSize = dm2->dmPublic.u1.s1.dmPaperSize;
62 dm1->dmPublic.u1.s1.dmPaperWidth = page->PaperDimension->x *
64 dm1->dmPublic.u1.s1.dmPaperLength = page->PaperDimension->y *
66 TRACE("Changing page to %s %d x %d\n", page->FullName,
67 dm1->dmPublic.u1.s1.dmPaperWidth,
68 dm1->dmPublic.u1.s1.dmPaperLength );
70 TRACE("Trying to change to unsupported pagesize %d\n",
71 dm2->dmPublic.u1.s1.dmPaperSize);
75 if(dm2->dmPublic.dmFields & DM_PAPERLENGTH) {
76 dm1->dmPublic.u1.s1.dmPaperLength = dm2->dmPublic.u1.s1.dmPaperLength;
77 TRACE("Changing PaperLength to %d\n",
78 dm2->dmPublic.u1.s1.dmPaperLength);
79 FIXME("Changing PaperLength. Do we adjust PaperSize?\n");
82 if(dm2->dmPublic.dmFields & DM_PAPERWIDTH) {
83 dm1->dmPublic.u1.s1.dmPaperWidth = dm2->dmPublic.u1.s1.dmPaperWidth;
84 TRACE("Changing PaperWidth to %d\n",
85 dm2->dmPublic.u1.s1.dmPaperWidth);
86 FIXME("Changing PaperWidth. Do we adjust PaperSize?\n");
89 if(dm2->dmPublic.dmFields & DM_SCALE) {
90 dm1->dmPublic.dmScale = dm2->dmPublic.dmScale;
91 TRACE("Changing Scale to %d\n", dm2->dmPublic.dmScale);
94 if(dm2->dmPublic.dmFields & DM_COPIES) {
95 dm1->dmPublic.dmCopies = dm2->dmPublic.dmCopies;
96 TRACE("Changing Copies to %d\n", dm2->dmPublic.dmCopies);
99 if(dm2->dmPublic.dmFields & DM_DEFAULTSOURCE) {
102 for(slot = pi->ppd->InputSlots; slot; slot = slot->next) {
103 if(slot->WinBin == dm2->dmPublic.dmDefaultSource)
107 dm1->dmPublic.dmDefaultSource = dm2->dmPublic.dmDefaultSource;
108 TRACE("Changing bin to '%s'\n", slot->FullName);
110 TRACE("Trying to change to unsupported bin %d\n",
111 dm2->dmPublic.dmDefaultSource);
115 if (dm2->dmPublic.dmFields & DM_DEFAULTSOURCE )
116 dm1->dmPublic.dmDefaultSource = dm2->dmPublic.dmDefaultSource;
117 if (dm2->dmPublic.dmFields & DM_PRINTQUALITY )
118 dm1->dmPublic.dmPrintQuality = dm2->dmPublic.dmPrintQuality;
119 if (dm2->dmPublic.dmFields & DM_COLOR )
120 dm1->dmPublic.dmColor = dm2->dmPublic.dmColor;
121 if (dm2->dmPublic.dmFields & DM_DUPLEX )
122 dm1->dmPublic.dmDuplex = dm2->dmPublic.dmDuplex;
123 if (dm2->dmPublic.dmFields & DM_YRESOLUTION )
124 dm1->dmPublic.dmYResolution = dm2->dmPublic.dmYResolution;
125 if (dm2->dmPublic.dmFields & DM_TTOPTION )
126 dm1->dmPublic.dmTTOption = dm2->dmPublic.dmTTOption;
127 if (dm2->dmPublic.dmFields & DM_COLLATE )
128 dm1->dmPublic.dmCollate = dm2->dmPublic.dmCollate;
129 if (dm2->dmPublic.dmFields & DM_FORMNAME )
130 lstrcpynA(dm1->dmPublic.dmFormName, dm2->dmPublic.dmFormName, CCHFORMNAME);
131 if (dm2->dmPublic.dmFields & DM_BITSPERPEL )
132 dm1->dmPublic.dmBitsPerPel = dm2->dmPublic.dmBitsPerPel;
133 if (dm2->dmPublic.dmFields & DM_PELSWIDTH )
134 dm1->dmPublic.dmPelsWidth = dm2->dmPublic.dmPelsWidth;
135 if (dm2->dmPublic.dmFields & DM_PELSHEIGHT )
136 dm1->dmPublic.dmPelsHeight = dm2->dmPublic.dmPelsHeight;
137 if (dm2->dmPublic.dmFields & DM_DISPLAYFLAGS )
138 dm1->dmPublic.dmDisplayFlags = dm2->dmPublic.dmDisplayFlags;
139 if (dm2->dmPublic.dmFields & DM_DISPLAYFREQUENCY )
140 dm1->dmPublic.dmDisplayFrequency = dm2->dmPublic.dmDisplayFrequency;
141 if (dm2->dmPublic.dmFields & DM_POSITION )
142 dm1->dmPublic.u1.dmPosition = dm2->dmPublic.u1.dmPosition;
143 if (dm2->dmPublic.dmFields & DM_LOGPIXELS )
144 dm1->dmPublic.dmLogPixels = dm2->dmPublic.dmLogPixels;
145 if (dm2->dmPublic.dmFields & DM_ICMMETHOD )
146 dm1->dmPublic.dmICMMethod = dm2->dmPublic.dmICMMethod;
147 if (dm2->dmPublic.dmFields & DM_ICMINTENT )
148 dm1->dmPublic.dmICMIntent = dm2->dmPublic.dmICMIntent;
149 if (dm2->dmPublic.dmFields & DM_MEDIATYPE )
150 dm1->dmPublic.dmMediaType = dm2->dmPublic.dmMediaType;
151 if (dm2->dmPublic.dmFields & DM_DITHERTYPE )
152 dm1->dmPublic.dmDitherType = dm2->dmPublic.dmDitherType;
153 if (dm2->dmPublic.dmFields & DM_PANNINGWIDTH )
154 dm1->dmPublic.dmPanningWidth = dm2->dmPublic.dmPanningWidth;
155 if (dm2->dmPublic.dmFields & DM_PANNINGHEIGHT )
156 dm1->dmPublic.dmPanningHeight = dm2->dmPublic.dmPanningHeight;
162 /**************************************************************
163 * AdvancedSetupDialog [WINEPS16.93]
166 WORD WINAPI PSDRV_AdvancedSetupDialog16(HWND16 hwnd, HANDLE16 hDriver,
167 LPDEVMODEA devin, LPDEVMODEA devout)
170 TRACE("hwnd = %04x, hDriver = %04x devin=%p devout=%p\n", hwnd,
171 hDriver, devin, devout);
175 /****************************************************************
178 * Dialog proc for 'Paper' propsheet
180 BOOL WINAPI PSDRV_PaperDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
190 di = (PSDRV_DLGINFO*)((PROPSHEETPAGEA*)lParam)->lParam;
191 SetWindowLongA(hwnd, DWL_USER, (LONG)di);
193 for(ps = di->pi->ppd->PageSizes, i = 0; ps; ps = ps->next, i++) {
194 SendDlgItemMessageA(hwnd, IDD_PAPERS, LB_INSERTSTRING, i,
195 (LPARAM)ps->FullName);
196 if(di->pi->Devmode->dmPublic.u1.s1.dmPaperSize == ps->WinPage)
199 SendDlgItemMessageA(hwnd, IDD_PAPERS, LB_SETCURSEL, Cursel, 0);
201 CheckRadioButton(hwnd, IDD_ORIENT_PORTRAIT, IDD_ORIENT_LANDSCAPE,
202 di->pi->Devmode->dmPublic.u1.s1.dmOrientation ==
203 DMORIENT_PORTRAIT ? IDD_ORIENT_PORTRAIT :
204 IDD_ORIENT_LANDSCAPE);
208 di = (PSDRV_DLGINFO *)GetWindowLongA(hwnd, DWL_USER);
209 switch(LOWORD(wParam)) {
211 if(HIWORD(wParam) == LBN_SELCHANGE) {
212 Cursel = SendDlgItemMessageA(hwnd, LOWORD(wParam), LB_GETCURSEL, 0, 0);
213 for(i = 0, ps = di->pi->ppd->PageSizes; i < Cursel; i++, ps = ps->next)
215 TRACE("Setting pagesize to item %d Winpage = %d\n", Cursel,
217 di->dlgdm->dmPublic.u1.s1.dmPaperSize = ps->WinPage;
220 case IDD_ORIENT_PORTRAIT:
221 case IDD_ORIENT_LANDSCAPE:
222 TRACE("Setting orientation to %s\n", wParam == IDD_ORIENT_PORTRAIT ?
223 "portrait" : "landscape");
224 di->dlgdm->dmPublic.u1.s1.dmOrientation = wParam == IDD_ORIENT_PORTRAIT ?
225 DMORIENT_PORTRAIT : DMORIENT_LANDSCAPE;
232 NMHDR *nmhdr = (NMHDR *)lParam;
233 di = (PSDRV_DLGINFO *)GetWindowLongA(hwnd, DWL_USER);
234 switch(nmhdr->code) {
236 memcpy(di->pi->Devmode, di->dlgdm, sizeof(PSDRV_DEVMODEA));
237 SetWindowLongA(hwnd, DWL_MSGRESULT, PSNRET_NOERROR);
255 static void (WINAPI *pInitCommonControls) (void);
256 static HPROPSHEETPAGE (WINAPI *pCreatePropertySheetPage) (LPCPROPSHEETPAGEW);
257 static int (WINAPI *pPropertySheet) (LPCPROPSHEETHEADERW);
259 /***************************************************************
260 * ExtDeviceMode [WINEPS16.90]
262 * Just returns default devmode at the moment
264 INT16 WINAPI PSDRV_ExtDeviceMode16(HWND16 hwnd, HANDLE16 hDriver,
265 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
266 LPSTR lpszPort, LPDEVMODEA lpdmInput,
267 LPSTR lpszProfile, WORD fwMode)
269 PRINTERINFO *pi = PSDRV_FindPrinterInfo(lpszDevice);
272 TRACE("(hwnd=%04x, hDriver=%04x, devOut=%p, Device='%s', Port='%s', devIn=%p, Profile='%s', Mode=%04x)\n",
273 hwnd, hDriver, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile,
277 return sizeof(DEVMODEA); /* Just copy dmPublic bit of PSDRV_DEVMODE */
279 if((fwMode & DM_MODIFY) && lpdmInput) {
280 TRACE("DM_MODIFY set. devIn->dmFields = %08lx\n", lpdmInput->dmFields);
281 PSDRV_MergeDevmodes(pi->Devmode, (PSDRV_DEVMODEA *)lpdmInput, pi);
284 if(fwMode & DM_PROMPT) {
285 HINSTANCE hinstComctl32, hinstWineps32 = LoadLibraryA("WINEPS");
286 HPROPSHEETPAGE hpsp[1];
288 PROPSHEETHEADERW psh;
290 PSDRV_DEVMODEA *dlgdm;
291 static const WCHAR PAPERW[] = {'P','A','P','E','R','\0'};
292 static const WCHAR SetupW[] = {'S','e','t','u','p','\0'};
294 hinstComctl32 = LoadLibraryA("comctl32.dll");
295 pInitCommonControls = (void*)GetProcAddress(hinstComctl32,
296 "InitCommonControls");
297 pCreatePropertySheetPage = (void*)GetProcAddress(hinstComctl32,
298 "CreatePropertySheetPageW");
299 pPropertySheet = (void*)GetProcAddress(hinstComctl32, "PropertySheetW");
300 memset(&psp,0,sizeof(psp));
301 dlgdm = HeapAlloc( PSDRV_Heap, 0, sizeof(*dlgdm) );
302 memcpy(dlgdm, pi->Devmode, sizeof(*dlgdm));
303 di = HeapAlloc( PSDRV_Heap, 0, sizeof(*di) );
306 psp.dwSize = sizeof(psp);
307 psp.hInstance = hinstWineps32;
308 psp.u.pszTemplate = PAPERW;
309 psp.u2.pszIcon = NULL;
310 psp.pfnDlgProc = PSDRV_PaperDlgProc;
311 psp.lParam = (LPARAM)di;
312 hpsp[0] = pCreatePropertySheetPage(&psp);
314 memset(&psh, 0, sizeof(psh));
315 psh.dwSize = sizeof(psh);
316 psh.pszCaption = SetupW;
318 psh.hwndParent = hwnd;
319 psh.u3.phpage = hpsp;
321 pPropertySheet(&psh);
324 if(fwMode & DM_UPDATE)
325 FIXME("Mode DM_UPDATE. Just do the same as DM_COPY\n");
327 if((fwMode & DM_COPY) || (fwMode & DM_UPDATE)) {
328 memcpy(lpdmOutput, pi->Devmode, sizeof(DEVMODEA));
333 /**************************************************************
335 * PSDRV_ExtDeviceMode
337 INT PSDRV_ExtDeviceMode(LPSTR lpszDriver, HWND hwnd, LPDEVMODEA lpdmOutput,
338 LPSTR lpszDevice, LPSTR lpszPort, LPDEVMODEA lpdmInput,
339 LPSTR lpszProfile, DWORD dwMode)
341 return PSDRV_ExtDeviceMode16(hwnd, 0, lpdmOutput, lpszDevice, lpszPort,
342 lpdmInput, lpszProfile, dwMode);
345 /***********************************************************************
346 * DeviceCapabilities [WINEPS16.91]
349 DWORD WINAPI PSDRV_DeviceCapabilities16(LPCSTR lpszDevice, LPCSTR lpszPort,
350 WORD fwCapability, LPSTR lpszOutput,
351 LPDEVMODEA lpDevMode)
355 pi = PSDRV_FindPrinterInfo(lpszDevice);
357 TRACE("Cap=%d. Got PrinterInfo = %p\n", fwCapability, pi);
361 ERR("no printerinfo for %s, return 0!\n",lpszDevice);
366 lpdm = lpDevMode ? lpDevMode : (DEVMODEA *)pi->Devmode;
368 switch(fwCapability) {
373 WORD *wp = (WORD *)lpszOutput;
376 for(ps = pi->ppd->PageSizes; ps; ps = ps->next, i++)
377 if(lpszOutput != NULL)
385 POINT16 *pt = (POINT16 *)lpszOutput;
388 for(ps = pi->ppd->PageSizes; ps; ps = ps->next, i++)
389 if(lpszOutput != NULL) {
390 pt->x = ps->PaperDimension->x * 254.0 / 72.0;
391 pt->y = ps->PaperDimension->y * 254.0 / 72.0;
400 char *cp = lpszOutput;
403 for(ps = pi->ppd->PageSizes; ps; ps = ps->next, i++)
404 if(lpszOutput != NULL) {
405 lstrcpynA(cp, ps->FullName, 64);
412 return pi->ppd->LandscapeOrientation ? pi->ppd->LandscapeOrientation : 90;
417 WORD *wp = (WORD *)lpszOutput;
420 /* We explicitly list DMBIN_AUTO first; actually while win9x does this
421 win2000 lists DMBIN_FORMSOURCE instead. */
423 if(lpszOutput != NULL)
426 for(slot = pi->ppd->InputSlots; slot; slot = slot->next, i++)
427 if(lpszOutput != NULL)
428 *wp++ = slot->WinBin;
435 char *cp = lpszOutput;
438 /* Add an entry corresponding to DMBIN_AUTO, see DC_BINS */
440 if(lpszOutput != NULL) {
441 strcpy(cp, "Automatically Select");
445 for(slot = pi->ppd->InputSlots; slot; slot = slot->next, i++)
446 if(lpszOutput != NULL) {
447 lstrcpynA(cp, slot->FullName, 24);
454 FIXME("DC_BINADJUST: stub.\n");
455 return DCBA_FACEUPNONE;
457 case DC_ENUMRESOLUTIONS:
459 LONG *lp = (LONG*)lpszOutput;
461 if(lpszOutput != NULL) {
462 lp[0] = (LONG)pi->ppd->DefaultResolution;
463 lp[1] = (LONG)pi->ppd->DefaultResolution;
469 FIXME("DC_COPIES: returning %d. Is this correct?\n", lpdm->dmCopies);
470 return lpdm->dmCopies;
473 return lpdm->dmDriverVersion;
475 case DC_DATATYPE_PRODUCED:
476 FIXME("DATA_TYPE_PRODUCED: stub.\n");
477 return -1; /* simulate that the driver supports 'RAW' */
480 FIXME("DC_DUPLEX: returning %d. Is this correct?\n", lpdm->dmDuplex);
481 return lpdm->dmDuplex;
483 case DC_EMF_COMPLIANT:
484 FIXME("DC_EMF_COMPLIANT: stub.\n");
485 return -1; /* simulate that the driver do not support EMF */
488 return lpdm->dmDriverExtra;
491 return lpdm->dmFields;
493 case DC_FILEDEPENDENCIES:
494 FIXME("DC_FILEDEPENDENCIES: stub.\n");
502 ptMax.x = ptMax.y = 0;
504 if(lpszOutput == NULL)
508 for(ps = pi->ppd->PageSizes; ps; ps = ps->next, i++) {
509 if(ps->PaperDimension->x > ptMax.x)
510 ptMax.x = ps->PaperDimension->x;
511 if(ps->PaperDimension->y > ptMax.y)
512 ptMax.y = ps->PaperDimension->y;
514 *((POINT*)lpszOutput) = ptMax;
523 ptMax.x = ptMax.y = 0;
525 if(lpszOutput == NULL)
529 for(ps = pi->ppd->PageSizes; ps; ps = ps->next, i++) {
530 if(ps->PaperDimension->x > ptMax.x)
531 ptMax.x = ps->PaperDimension->x;
532 if(ps->PaperDimension->y > ptMax.y)
533 ptMax.y = ps->PaperDimension->y;
535 *((POINT*)lpszOutput) = ptMax;
543 FIXME("DC_TRUETYPE: stub\n");
547 return lpdm->dmSpecVersion;
550 FIXME("Unsupported capability %d\n", fwCapability);
555 /**************************************************************
557 * PSDRV_DeviceCapabilities
559 DWORD PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice,
560 LPCSTR lpszPort, WORD fwCapability,
561 LPSTR lpszOutput, LPDEVMODEA lpdm)
563 return PSDRV_DeviceCapabilities16(lpszDevice, lpszPort, fwCapability,
567 /***************************************************************
568 * DeviceMode [WINEPS16.13]
571 void WINAPI PSDRV_DeviceMode16(HWND16 hwnd, HANDLE16 hDriver,
572 LPSTR lpszDevice, LPSTR lpszPort)
574 PSDRV_ExtDeviceMode16( hwnd, hDriver, NULL, lpszDevice, lpszPort, NULL,
583 HPROPSHEETPAGE hPages[10];
586 INT PSDRV_ExtDeviceModePropSheet(HWND hwnd, LPSTR lpszDevice, LPSTR lpszPort,
589 EDMPS *ps = pPropSheet;
592 psp->dwSize = sizeof(psp);
593 psp->hInstance = 0x1234;