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
14 #include "debugtools.h"
20 DEFAULT_DEBUG_CHANNEL(psdrv);
23 /************************************************************************
27 * Updates dm1 with some fields from dm2
30 void PSDRV_MergeDevmodes(PSDRV_DEVMODEA *dm1, PSDRV_DEVMODEA *dm2,
33 /* some sanity checks here on dm2 */
35 if(dm2->dmPublic.dmFields & DM_ORIENTATION)
36 dm1->dmPublic.u1.s1.dmOrientation = dm2->dmPublic.u1.s1.dmOrientation;
38 /* NB PaperWidth is always < PaperLength */
40 if(dm2->dmPublic.dmFields & DM_PAPERSIZE) {
43 for(page = pi->ppd->PageSizes; page; page = page->next) {
44 if(page->WinPage == dm2->dmPublic.u1.s1.dmPaperSize)
48 dm1->dmPublic.u1.s1.dmPaperSize = dm2->dmPublic.u1.s1.dmPaperSize;
49 dm1->dmPublic.u1.s1.dmPaperWidth = page->PaperDimension->x *
51 dm1->dmPublic.u1.s1.dmPaperLength = page->PaperDimension->y *
53 TRACE("Changing page to %s %d x %d\n", page->FullName,
54 dm1->dmPublic.u1.s1.dmPaperWidth,
55 dm1->dmPublic.u1.s1.dmPaperLength );
57 TRACE("Trying to change to unsupported pagesize %d\n",
58 dm2->dmPublic.u1.s1.dmPaperSize);
62 if(dm2->dmPublic.dmFields & DM_PAPERLENGTH) {
63 dm1->dmPublic.u1.s1.dmPaperLength = dm2->dmPublic.u1.s1.dmPaperLength;
64 TRACE("Changing PaperLength to %d\n",
65 dm2->dmPublic.u1.s1.dmPaperLength);
66 FIXME("Changing PaperLength. Do we adjust PaperSize?\n");
69 if(dm2->dmPublic.dmFields & DM_PAPERWIDTH) {
70 dm1->dmPublic.u1.s1.dmPaperWidth = dm2->dmPublic.u1.s1.dmPaperWidth;
71 TRACE("Changing PaperWidth to %d\n",
72 dm2->dmPublic.u1.s1.dmPaperWidth);
73 FIXME("Changing PaperWidth. Do we adjust PaperSize?\n");
76 if(dm2->dmPublic.dmFields & DM_SCALE) {
77 dm1->dmPublic.dmScale = dm2->dmPublic.dmScale;
78 TRACE("Changing Scale to %d\n", dm2->dmPublic.dmScale);
81 if(dm2->dmPublic.dmFields & DM_COPIES) {
82 dm1->dmPublic.dmCopies = dm2->dmPublic.dmCopies;
83 TRACE("Changing Copies to %d\n", dm2->dmPublic.dmCopies);
86 if(dm2->dmPublic.dmFields & DM_DEFAULTSOURCE) {
89 for(slot = pi->ppd->InputSlots; slot; slot = slot->next) {
90 if(slot->WinBin == dm2->dmPublic.dmDefaultSource)
94 dm1->dmPublic.dmDefaultSource = dm2->dmPublic.dmDefaultSource;
95 TRACE("Changing bin to '%s'\n", slot->FullName);
97 TRACE("Trying to change to unsupported bin %d\n",
98 dm2->dmPublic.dmDefaultSource);
102 if (dm2->dmPublic.dmFields & DM_DEFAULTSOURCE )
103 dm1->dmPublic.dmDefaultSource = dm2->dmPublic.dmDefaultSource;
104 if (dm2->dmPublic.dmFields & DM_PRINTQUALITY )
105 dm1->dmPublic.dmPrintQuality = dm2->dmPublic.dmPrintQuality;
106 if (dm2->dmPublic.dmFields & DM_COLOR )
107 dm1->dmPublic.dmColor = dm2->dmPublic.dmColor;
108 if (dm2->dmPublic.dmFields & DM_DUPLEX )
109 dm1->dmPublic.dmDuplex = dm2->dmPublic.dmDuplex;
110 if (dm2->dmPublic.dmFields & DM_YRESOLUTION )
111 dm1->dmPublic.dmYResolution = dm2->dmPublic.dmYResolution;
112 if (dm2->dmPublic.dmFields & DM_TTOPTION )
113 dm1->dmPublic.dmTTOption = dm2->dmPublic.dmTTOption;
114 if (dm2->dmPublic.dmFields & DM_COLLATE )
115 dm1->dmPublic.dmCollate = dm2->dmPublic.dmCollate;
116 if (dm2->dmPublic.dmFields & DM_FORMNAME )
117 lstrcpynA(dm1->dmPublic.dmFormName, dm2->dmPublic.dmFormName, CCHFORMNAME);
118 if (dm2->dmPublic.dmFields & DM_BITSPERPEL )
119 dm1->dmPublic.dmBitsPerPel = dm2->dmPublic.dmBitsPerPel;
120 if (dm2->dmPublic.dmFields & DM_PELSWIDTH )
121 dm1->dmPublic.dmPelsWidth = dm2->dmPublic.dmPelsWidth;
122 if (dm2->dmPublic.dmFields & DM_PELSHEIGHT )
123 dm1->dmPublic.dmPelsHeight = dm2->dmPublic.dmPelsHeight;
124 if (dm2->dmPublic.dmFields & DM_DISPLAYFLAGS )
125 dm1->dmPublic.dmDisplayFlags = dm2->dmPublic.dmDisplayFlags;
126 if (dm2->dmPublic.dmFields & DM_DISPLAYFREQUENCY )
127 dm1->dmPublic.dmDisplayFrequency = dm2->dmPublic.dmDisplayFrequency;
128 if (dm2->dmPublic.dmFields & DM_POSITION )
129 dm1->dmPublic.u1.dmPosition = dm2->dmPublic.u1.dmPosition;
130 if (dm2->dmPublic.dmFields & DM_LOGPIXELS )
131 dm1->dmPublic.dmLogPixels = dm2->dmPublic.dmLogPixels;
132 if (dm2->dmPublic.dmFields & DM_ICMMETHOD )
133 dm1->dmPublic.dmICMMethod = dm2->dmPublic.dmICMMethod;
134 if (dm2->dmPublic.dmFields & DM_ICMINTENT )
135 dm1->dmPublic.dmICMIntent = dm2->dmPublic.dmICMIntent;
136 if (dm2->dmPublic.dmFields & DM_MEDIATYPE )
137 dm1->dmPublic.dmMediaType = dm2->dmPublic.dmMediaType;
138 if (dm2->dmPublic.dmFields & DM_DITHERTYPE )
139 dm1->dmPublic.dmDitherType = dm2->dmPublic.dmDitherType;
140 if (dm2->dmPublic.dmFields & DM_PANNINGWIDTH )
141 dm1->dmPublic.dmPanningWidth = dm2->dmPublic.dmPanningWidth;
142 if (dm2->dmPublic.dmFields & DM_PANNINGHEIGHT )
143 dm1->dmPublic.dmPanningHeight = dm2->dmPublic.dmPanningHeight;
149 /**************************************************************
151 * PSDRV_AdvancedSetupDialog16 [WINEPS.93]
154 WORD WINAPI PSDRV_AdvancedSetupDialog16(HWND16 hwnd, HANDLE16 hDriver,
155 LPDEVMODEA devin, LPDEVMODEA devout)
158 TRACE("hwnd = %04x, hDriver = %04x devin=%p devout=%p\n", hwnd,
159 hDriver, devin, devout);
163 /****************************************************************
166 * Dialog proc for 'Paper' propsheet
168 BOOL WINAPI PSDRV_PaperDlgProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM
178 di = (PSDRV_DLGINFO*)((PROPSHEETPAGEA*)lParam)->lParam;
179 SetWindowLongA(hwnd, DWL_USER, (LONG)di);
181 for(ps = di->pi->ppd->PageSizes, i = 0; ps; ps = ps->next, i++) {
182 SendDlgItemMessageA(hwnd, IDD_PAPERS, LB_INSERTSTRING, i,
183 (LPARAM)ps->FullName);
184 if(di->pi->Devmode->dmPublic.u1.s1.dmPaperSize == ps->WinPage)
187 SendDlgItemMessageA(hwnd, IDD_PAPERS, LB_SETCURSEL, Cursel, 0);
189 CheckRadioButton(hwnd, IDD_ORIENT_PORTRAIT, IDD_ORIENT_LANDSCAPE,
190 di->pi->Devmode->dmPublic.u1.s1.dmOrientation ==
191 DMORIENT_PORTRAIT ? IDD_ORIENT_PORTRAIT :
192 IDD_ORIENT_LANDSCAPE);
196 di = (PSDRV_DLGINFO *)GetWindowLongA(hwnd, DWL_USER);
197 switch(LOWORD(wParam)) {
199 if(HIWORD(wParam) == LBN_SELCHANGE) {
200 Cursel = SendDlgItemMessageA(hwnd, LOWORD(wParam), LB_GETCURSEL, 0, 0);
201 for(i = 0, ps = di->pi->ppd->PageSizes; i < Cursel; i++, ps = ps->next)
203 TRACE("Setting pagesize to item %d Winpage = %d\n", Cursel,
205 di->dlgdm->dmPublic.u1.s1.dmPaperSize = ps->WinPage;
208 case IDD_ORIENT_PORTRAIT:
209 case IDD_ORIENT_LANDSCAPE:
210 TRACE("Setting orientation to %s\n", wParam == IDD_ORIENT_PORTRAIT ?
211 "portrait" : "landscape");
212 di->dlgdm->dmPublic.u1.s1.dmOrientation = wParam == IDD_ORIENT_PORTRAIT ?
213 DMORIENT_PORTRAIT : DMORIENT_LANDSCAPE;
220 NMHDR *nmhdr = (NMHDR *)lParam;
221 di = (PSDRV_DLGINFO *)GetWindowLongA(hwnd, DWL_USER);
222 switch(nmhdr->code) {
224 memcpy(di->pi->Devmode, di->dlgdm, sizeof(PSDRV_DEVMODEA));
225 SetWindowLongA(hwnd, DWL_MSGRESULT, PSNRET_NOERROR);
243 static void (WINAPI* pInitCommonControls) (void);
244 static HPROPSHEETPAGE (WINAPI* pCreatePropertySheetPage) (LPCPROPSHEETPAGEA);
245 static int (WINAPI* pPropertySheet) (LPCPROPSHEETHEADERA);
247 /***************************************************************
249 * PSDRV_ExtDeviceMode16 [WINEPS.90]
251 * Just returns default devmode at the moment
253 INT16 WINAPI PSDRV_ExtDeviceMode16(HWND16 hwnd, HANDLE16 hDriver,
254 LPDEVMODEA lpdmOutput, LPSTR lpszDevice,
255 LPSTR lpszPort, LPDEVMODEA lpdmInput,
256 LPSTR lpszProfile, WORD fwMode)
258 PRINTERINFO *pi = PSDRV_FindPrinterInfo(lpszDevice);
261 TRACE("(hwnd=%04x, hDriver=%04x, devOut=%p, Device='%s', Port='%s', devIn=%p, Profile='%s', Mode=%04x)\n",
262 hwnd, hDriver, lpdmOutput, lpszDevice, lpszPort, lpdmInput, lpszProfile,
266 return sizeof(DEVMODEA); /* Just copy dmPublic bit of PSDRV_DEVMODE */
268 if((fwMode & DM_MODIFY) && lpdmInput) {
269 TRACE("DM_MODIFY set. devIn->dmFields = %08lx\n", lpdmInput->dmFields);
270 PSDRV_MergeDevmodes(pi->Devmode, (PSDRV_DEVMODEA *)lpdmInput, pi);
273 if(fwMode & DM_PROMPT) {
274 HINSTANCE hinstComctl32, hinstWineps32 = LoadLibraryA("WINEPS");
275 HPROPSHEETPAGE hpsp[1];
277 PROPSHEETHEADERA psh;
279 PSDRV_DEVMODEA *dlgdm;
281 hinstComctl32 = LoadLibraryA("comctl32.dll");
282 pInitCommonControls = (void*)GetProcAddress(hinstComctl32,
283 "InitCommonControls");
284 pCreatePropertySheetPage = (void*)GetProcAddress(hinstComctl32,
285 "CreatePropertySheetPage");
286 pPropertySheet = (void*)GetProcAddress(hinstComctl32, "PropertySheet");
287 memset(&psp,0,sizeof(psp));
288 dlgdm = HeapAlloc( PSDRV_Heap, 0, sizeof(*dlgdm) );
289 memcpy(dlgdm, pi->Devmode, sizeof(*dlgdm));
290 di = HeapAlloc( PSDRV_Heap, 0, sizeof(*di) );
293 psp.dwSize = sizeof(psp);
294 psp.hInstance = hinstWineps32;
295 psp.u.pszTemplate = "PAPER";
296 psp.u2.pszIcon = NULL;
297 psp.pfnDlgProc = PSDRV_PaperDlgProc;
298 psp.lParam = (LPARAM)di;
299 hpsp[0] = pCreatePropertySheetPage(&psp);
301 memset(&psh, 0, sizeof(psh));
302 psh.dwSize = sizeof(psh);
303 psh.pszCaption = "Setup";
305 psh.hwndParent = hwnd;
306 psh.u3.phpage = hpsp;
308 pPropertySheet(&psh);
311 if(fwMode & DM_UPDATE)
312 FIXME("Mode DM_UPDATE. Just do the same as DM_COPY\n");
314 if((fwMode & DM_COPY) || (fwMode & DM_UPDATE)) {
315 memcpy(lpdmOutput, pi->Devmode, sizeof(DEVMODEA));
320 /**************************************************************
322 * PSDRV_ExtDeviceMode
324 INT PSDRV_ExtDeviceMode(LPSTR lpszDriver, HWND hwnd, LPDEVMODEA lpdmOutput,
325 LPSTR lpszDevice, LPSTR lpszPort, LPDEVMODEA lpdmInput,
326 LPSTR lpszProfile, DWORD dwMode)
328 return PSDRV_ExtDeviceMode16(hwnd, 0, lpdmOutput, lpszDevice, lpszPort,
329 lpdmInput, lpszProfile, dwMode);
332 /***********************************************************************
334 * PSDRV_DeviceCapabilities16 [WINEPS.91]
337 DWORD WINAPI PSDRV_DeviceCapabilities16(LPCSTR lpszDevice, LPCSTR lpszPort,
338 WORD fwCapability, LPSTR lpszOutput,
339 LPDEVMODEA lpDevMode)
343 pi = PSDRV_FindPrinterInfo(lpszDevice);
345 TRACE("Cap=%d. Got PrinterInfo = %p\n", fwCapability, pi);
349 ERR("no printerinfo for %s, return 0!\n",lpszDevice);
354 lpdm = lpDevMode ? lpDevMode : (DEVMODEA *)pi->Devmode;
356 switch(fwCapability) {
361 WORD *wp = (WORD *)lpszOutput;
364 for(ps = pi->ppd->PageSizes; ps; ps = ps->next, i++)
365 if(lpszOutput != NULL)
373 POINT16 *pt = (POINT16 *)lpszOutput;
376 for(ps = pi->ppd->PageSizes; ps; ps = ps->next, i++)
377 if(lpszOutput != NULL) {
378 pt->x = ps->PaperDimension->x * 254.0 / 72.0;
379 pt->y = ps->PaperDimension->y * 254.0 / 72.0;
388 char *cp = lpszOutput;
391 for(ps = pi->ppd->PageSizes; ps; ps = ps->next, i++)
392 if(lpszOutput != NULL) {
393 lstrcpynA(cp, ps->FullName, 64);
400 return pi->ppd->LandscapeOrientation ? pi->ppd->LandscapeOrientation : 90;
405 WORD *wp = (WORD *)lpszOutput;
408 for(slot = pi->ppd->InputSlots; slot; slot = slot->next, i++)
409 if(lpszOutput != NULL)
410 *wp++ = slot->WinBin;
417 char *cp = lpszOutput;
420 for(slot = pi->ppd->InputSlots; slot; slot = slot->next, i++)
421 if(lpszOutput != NULL) {
422 lstrcpynA(cp, slot->FullName, 24);
429 FIXME("DC_BINADJUST: stub.\n");
430 return DCBA_FACEUPNONE;
432 case DC_ENUMRESOLUTIONS:
434 LONG *lp = (LONG*)lpszOutput;
436 if(lpszOutput != NULL) {
437 lp[0] = (LONG)pi->ppd->DefaultResolution;
438 lp[1] = (LONG)pi->ppd->DefaultResolution;
444 FIXME("DC_COPIES: returning %d. Is this correct?\n", lpdm->dmCopies);
445 return lpdm->dmCopies;
448 return lpdm->dmDriverVersion;
450 case DC_DATATYPE_PRODUCED:
451 FIXME("DATA_TYPE_PRODUCED: stub.\n");
452 return -1; /* simulate that the driver supports 'RAW' */
455 FIXME("DC_DUPLEX: returning %d. Is this correct?\n", lpdm->dmDuplex);
456 return lpdm->dmDuplex;
458 case DC_EMF_COMPLIANT:
459 FIXME("DC_EMF_COMPLIANT: stub.\n");
460 return -1; /* simulate that the driver do not support EMF */
463 return lpdm->dmDriverExtra;
466 return lpdm->dmFields;
468 case DC_FILEDEPENDENCIES:
469 FIXME("DC_FILEDEPENDENCIES: stub.\n");
477 ptMax.x = ptMax.y = 0;
479 if(lpszOutput == NULL)
483 for(ps = pi->ppd->PageSizes; ps; ps = ps->next, i++) {
484 if(ps->PaperDimension->x > ptMax.x)
485 ptMax.x = ps->PaperDimension->x;
486 if(ps->PaperDimension->y > ptMax.y)
487 ptMax.y = ps->PaperDimension->y;
489 *((POINT*)lpszOutput) = ptMax;
498 ptMax.x = ptMax.y = 0;
500 if(lpszOutput == NULL)
504 for(ps = pi->ppd->PageSizes; ps; ps = ps->next, i++) {
505 if(ps->PaperDimension->x > ptMax.x)
506 ptMax.x = ps->PaperDimension->x;
507 if(ps->PaperDimension->y > ptMax.y)
508 ptMax.y = ps->PaperDimension->y;
510 *((POINT*)lpszOutput) = ptMax;
518 FIXME("DC_TRUETYPE: stub\n");
522 return lpdm->dmSpecVersion;
525 FIXME("Unsupported capability %d\n", fwCapability);
530 /**************************************************************
532 * PSDRV_DeviceCapabilities
534 DWORD PSDRV_DeviceCapabilities(LPSTR lpszDriver, LPCSTR lpszDevice,
535 LPCSTR lpszPort, WORD fwCapability,
536 LPSTR lpszOutput, LPDEVMODEA lpdm)
538 return PSDRV_DeviceCapabilities16(lpszDevice, lpszPort, fwCapability,
542 /***************************************************************
544 * PSDRV_DeviceMode16 [WINEPS.13]
547 void WINAPI PSDRV_DeviceMode16(HWND16 hwnd, HANDLE16 hDriver,
548 LPSTR lpszDevice, LPSTR lpszPort)
550 PSDRV_ExtDeviceMode16( hwnd, hDriver, NULL, lpszDevice, lpszPort, NULL,
559 HPROPSHEETPAGE hPages[10];
562 INT PSDRV_ExtDeviceModePropSheet(HWND hwnd, LPSTR lpszDevice, LPSTR lpszPort,
565 EDMPS *ps = pPropSheet;
568 psp->dwSize = sizeof(psp);
569 psp->hInstance = 0x1234;