save old text color during a call of DrawCaptionTempW
[wine/kumbayo.git] / dlls / comdlg32 / printdlg.c
blob6b8ed15aaa1bf849a42440438ee30cb2892fc285
1 /*
2 * COMMDLG - Print Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1999 Klaas van Gend
7 * Copyright 2000 Huw D M Davies
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
23 #include <ctype.h>
24 #include <stdlib.h>
25 #include <stdarg.h>
26 #include <stdio.h>
27 #include <string.h>
29 #define NONAMELESSUNION
30 #define NONAMELESSSTRUCT
31 #include "windef.h"
32 #include "winbase.h"
33 #include "wingdi.h"
34 #include "winuser.h"
35 #include "winspool.h"
36 #include "winerror.h"
38 #include "wine/debug.h"
40 #include "commdlg.h"
41 #include "dlgs.h"
42 #include "cderr.h"
44 WINE_DEFAULT_DEBUG_CHANNEL(commdlg);
46 #include "cdlg.h"
47 #include "printdlg.h"
49 /* Yes these constants are the same, but we're just copying win98 */
50 #define UPDOWN_ID 0x270f
51 #define MAX_COPIES 9999
53 /* Debugging info */
54 static const struct pd_flags psd_flags[] = {
55 {PSD_MINMARGINS,"PSD_MINMARGINS"},
56 {PSD_MARGINS,"PSD_MARGINS"},
57 {PSD_INTHOUSANDTHSOFINCHES,"PSD_INTHOUSANDTHSOFINCHES"},
58 {PSD_INHUNDREDTHSOFMILLIMETERS,"PSD_INHUNDREDTHSOFMILLIMETERS"},
59 {PSD_DISABLEMARGINS,"PSD_DISABLEMARGINS"},
60 {PSD_DISABLEPRINTER,"PSD_DISABLEPRINTER"},
61 {PSD_NOWARNING,"PSD_NOWARNING"},
62 {PSD_DISABLEORIENTATION,"PSD_DISABLEORIENTATION"},
63 {PSD_RETURNDEFAULT,"PSD_RETURNDEFAULT"},
64 {PSD_DISABLEPAPER,"PSD_DISABLEPAPER"},
65 {PSD_SHOWHELP,"PSD_SHOWHELP"},
66 {PSD_ENABLEPAGESETUPHOOK,"PSD_ENABLEPAGESETUPHOOK"},
67 {PSD_ENABLEPAGESETUPTEMPLATE,"PSD_ENABLEPAGESETUPTEMPLATE"},
68 {PSD_ENABLEPAGESETUPTEMPLATEHANDLE,"PSD_ENABLEPAGESETUPTEMPLATEHANDLE"},
69 {PSD_ENABLEPAGEPAINTHOOK,"PSD_ENABLEPAGEPAINTHOOK"},
70 {PSD_DISABLEPAGEPAINTING,"PSD_DISABLEPAGEPAINTING"},
71 {-1, NULL}
74 /* address of wndproc for subclassed Static control */
75 static WNDPROC lpfnStaticWndProc;
76 /* the text of the fake document to render for the Page Setup dialog */
77 static WCHAR wszFakeDocumentText[1024];
79 /***********************************************************************
80 * PRINTDLG_OpenDefaultPrinter
82 * Returns a winspool printer handle to the default printer in *hprn
83 * Caller must call ClosePrinter on the handle
85 * Returns TRUE on success else FALSE
87 BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
89 WCHAR buf[260];
90 DWORD dwBufLen = sizeof(buf) / sizeof(buf[0]);
91 BOOL res;
92 if(!GetDefaultPrinterW(buf, &dwBufLen))
93 return FALSE;
94 res = OpenPrinterW(buf, hprn, NULL);
95 if (!res)
96 WARN("Could not open printer %s\n", debugstr_w(buf));
97 return res;
100 /***********************************************************************
101 * PRINTDLG_SetUpPrinterListCombo
103 * Initializes printer list combox.
104 * hDlg: HWND of dialog
105 * id: Control id of combo
106 * name: Name of printer to select
108 * Initializes combo with list of available printers. Selects printer 'name'
109 * If name is NULL or does not exist select the default printer.
111 * Returns number of printers added to list.
113 INT PRINTDLG_SetUpPrinterListComboA(HWND hDlg, UINT id, LPCSTR name)
115 DWORD needed, num;
116 INT i;
117 LPPRINTER_INFO_2A pi;
118 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
119 pi = HeapAlloc(GetProcessHeap(), 0, needed);
120 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
121 &num);
123 SendDlgItemMessageA(hDlg, id, CB_RESETCONTENT, 0, 0);
125 for(i = 0; i < num; i++) {
126 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
127 (LPARAM)pi[i].pPrinterName );
129 HeapFree(GetProcessHeap(), 0, pi);
130 if(!name ||
131 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
132 (LPARAM)name)) == CB_ERR) {
134 char buf[260];
135 DWORD dwBufLen = sizeof(buf);
136 if (name != NULL)
137 WARN("Can't find %s in printer list so trying to find default\n",
138 debugstr_a(name));
139 if(!GetDefaultPrinterA(buf, &dwBufLen))
140 return num;
141 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
142 if(i == CB_ERR)
143 FIXME("Can't find default printer in printer list\n");
145 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
146 return num;
149 static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
151 DWORD needed, num;
152 INT i;
153 LPPRINTER_INFO_2W pi;
154 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
155 pi = HeapAlloc(GetProcessHeap(), 0, needed);
156 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
157 &num);
159 for(i = 0; i < num; i++) {
160 SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
161 (LPARAM)pi[i].pPrinterName );
163 HeapFree(GetProcessHeap(), 0, pi);
164 if(!name ||
165 (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
166 (LPARAM)name)) == CB_ERR) {
167 WCHAR buf[260];
168 DWORD dwBufLen = sizeof(buf)/sizeof(buf[0]);
169 if (name != NULL)
170 WARN("Can't find %s in printer list so trying to find default\n",
171 debugstr_w(name));
172 if(!GetDefaultPrinterW(buf, &dwBufLen))
173 return num;
174 i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
175 if(i == CB_ERR)
176 TRACE("Can't find default printer in printer list\n");
178 SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
179 return num;
182 /***********************************************************************
183 * PRINTDLG_CreateDevNames [internal]
186 * creates a DevNames structure.
188 * (NB. when we handle unicode the offsets will be in wchars).
190 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, const char* DeviceDriverName,
191 const char* DeviceName, const char* OutputPort)
193 long size;
194 char* pDevNamesSpace;
195 char* pTempPtr;
196 LPDEVNAMES lpDevNames;
197 char buf[260];
198 DWORD dwBufLen = sizeof(buf);
200 size = strlen(DeviceDriverName) + 1
201 + strlen(DeviceName) + 1
202 + strlen(OutputPort) + 1
203 + sizeof(DEVNAMES);
205 if(*hmem)
206 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
207 else
208 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
209 if (*hmem == 0)
210 return FALSE;
212 pDevNamesSpace = GlobalLock(*hmem);
213 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
215 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
216 strcpy(pTempPtr, DeviceDriverName);
217 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
219 pTempPtr += strlen(DeviceDriverName) + 1;
220 strcpy(pTempPtr, DeviceName);
221 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
223 pTempPtr += strlen(DeviceName) + 1;
224 strcpy(pTempPtr, OutputPort);
225 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
227 GetDefaultPrinterA(buf, &dwBufLen);
228 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
229 GlobalUnlock(*hmem);
230 return TRUE;
233 static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
234 LPCWSTR DeviceName, LPCWSTR OutputPort)
236 long size;
237 LPWSTR pDevNamesSpace;
238 LPWSTR pTempPtr;
239 LPDEVNAMES lpDevNames;
240 WCHAR bufW[260];
241 DWORD dwBufLen = sizeof(bufW) / sizeof(WCHAR);
243 size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
244 + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
245 + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
246 + sizeof(DEVNAMES);
248 if(*hmem)
249 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
250 else
251 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
252 if (*hmem == 0)
253 return FALSE;
255 pDevNamesSpace = GlobalLock(*hmem);
256 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
258 pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
259 lstrcpyW(pTempPtr, DeviceDriverName);
260 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
262 pTempPtr += lstrlenW(DeviceDriverName) + 1;
263 lstrcpyW(pTempPtr, DeviceName);
264 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
266 pTempPtr += lstrlenW(DeviceName) + 1;
267 lstrcpyW(pTempPtr, OutputPort);
268 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
270 GetDefaultPrinterW(bufW, &dwBufLen);
271 lpDevNames->wDefault = (lstrcmpW(bufW, DeviceName) == 0) ? 1 : 0;
272 GlobalUnlock(*hmem);
273 return TRUE;
276 /***********************************************************************
277 * PRINTDLG_UpdatePrintDlg [internal]
280 * updates the PrintDlg structure for return values.
282 * RETURNS
283 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
284 * TRUE if successful.
286 static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
287 PRINT_PTRA* PrintStructures)
289 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
290 PDEVMODEA lpdm = PrintStructures->lpDevMode;
291 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
294 if(!lpdm) {
295 FIXME("No lpdm ptr?\n");
296 return FALSE;
300 if(!(lppd->Flags & PD_PRINTSETUP)) {
301 /* check whether nFromPage and nToPage are within range defined by
302 * nMinPage and nMaxPage
304 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
305 WORD nToPage;
306 WORD nFromPage;
307 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
308 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
309 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
310 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
311 char resourcestr[256];
312 char resultstr[256];
313 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
314 resourcestr, 255);
315 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
316 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
317 resourcestr, 255);
318 MessageBoxA(hDlg, resultstr, resourcestr,
319 MB_OK | MB_ICONWARNING);
320 return FALSE;
322 lppd->nFromPage = nFromPage;
323 lppd->nToPage = nToPage;
324 lppd->Flags |= PD_PAGENUMS;
326 else
327 lppd->Flags &= ~PD_PAGENUMS;
329 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) /* Selection */
330 lppd->Flags |= PD_SELECTION;
331 else
332 lppd->Flags &= ~PD_SELECTION;
334 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
335 static char file[] = "FILE:";
336 lppd->Flags |= PD_PRINTTOFILE;
337 pi->pPortName = file;
340 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
341 FIXME("Collate lppd not yet implemented as output\n");
344 /* set PD_Collate and nCopies */
345 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
346 /* The application doesn't support multiple copies or collate...
348 lppd->Flags &= ~PD_COLLATE;
349 lppd->nCopies = 1;
350 /* if the printer driver supports it... store info there
351 * otherwise no collate & multiple copies !
353 if (lpdm->dmFields & DM_COLLATE)
354 lpdm->dmCollate =
355 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
356 if (lpdm->dmFields & DM_COPIES)
357 lpdm->u1.s1.dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
358 } else {
359 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
360 lppd->Flags |= PD_COLLATE;
361 else
362 lppd->Flags &= ~PD_COLLATE;
363 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
366 return TRUE;
369 static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
370 PRINT_PTRW* PrintStructures)
372 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
373 PDEVMODEW lpdm = PrintStructures->lpDevMode;
374 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
377 if(!lpdm) {
378 FIXME("No lpdm ptr?\n");
379 return FALSE;
383 if(!(lppd->Flags & PD_PRINTSETUP)) {
384 /* check whether nFromPage and nToPage are within range defined by
385 * nMinPage and nMaxPage
387 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
388 WORD nToPage;
389 WORD nFromPage;
390 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
391 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
392 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
393 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
394 WCHAR resourcestr[256];
395 WCHAR resultstr[256];
396 LoadStringW(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
397 resourcestr, 255);
398 wsprintfW(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
399 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,
400 resourcestr, 255);
401 MessageBoxW(hDlg, resultstr, resourcestr,
402 MB_OK | MB_ICONWARNING);
403 return FALSE;
405 lppd->nFromPage = nFromPage;
406 lppd->nToPage = nToPage;
407 lppd->Flags |= PD_PAGENUMS;
409 else
410 lppd->Flags &= ~PD_PAGENUMS;
412 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) /* Selection */
413 lppd->Flags |= PD_SELECTION;
414 else
415 lppd->Flags &= ~PD_SELECTION;
417 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
418 static WCHAR file[] = {'F','I','L','E',':',0};
419 lppd->Flags |= PD_PRINTTOFILE;
420 pi->pPortName = file;
423 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
424 FIXME("Collate lppd not yet implemented as output\n");
427 /* set PD_Collate and nCopies */
428 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
429 /* The application doesn't support multiple copies or collate...
431 lppd->Flags &= ~PD_COLLATE;
432 lppd->nCopies = 1;
433 /* if the printer driver supports it... store info there
434 * otherwise no collate & multiple copies !
436 if (lpdm->dmFields & DM_COLLATE)
437 lpdm->dmCollate =
438 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
439 if (lpdm->dmFields & DM_COPIES)
440 lpdm->u1.s1.dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
441 } else {
442 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
443 lppd->Flags |= PD_COLLATE;
444 else
445 lppd->Flags &= ~PD_COLLATE;
446 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
449 return TRUE;
452 static BOOL PRINTDLG_PaperSizeA(
453 PRINTDLGA *pdlga,const WORD PaperSize,LPPOINT size
455 DEVNAMES *dn;
456 DEVMODEA *dm;
457 LPSTR devname,portname;
458 int i;
459 INT NrOfEntries,ret;
460 WORD *Words = NULL;
461 POINT *points = NULL;
462 BOOL retval = FALSE;
464 dn = GlobalLock(pdlga->hDevNames);
465 dm = GlobalLock(pdlga->hDevMode);
466 devname = ((char*)dn)+dn->wDeviceOffset;
467 portname = ((char*)dn)+dn->wOutputOffset;
470 NrOfEntries = DeviceCapabilitiesA(devname,portname,DC_PAPERNAMES,NULL,dm);
471 if (!NrOfEntries) {
472 FIXME("No papernames found for %s/%s\n",devname,portname);
473 goto out;
475 if (NrOfEntries == -1) {
476 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
477 goto out;
480 Words = HeapAlloc(GetProcessHeap(),0,NrOfEntries*sizeof(WORD));
481 if (NrOfEntries != (ret=DeviceCapabilitiesA(devname,portname,DC_PAPERS,(LPSTR)Words,dm))) {
482 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
483 goto out;
485 for (i=0;i<NrOfEntries;i++)
486 if (Words[i] == PaperSize)
487 break;
488 HeapFree(GetProcessHeap(),0,Words);
489 if (i == NrOfEntries) {
490 FIXME("Papersize %d not found in list?\n",PaperSize);
491 goto out;
493 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
494 if (NrOfEntries!=(ret=DeviceCapabilitiesA(devname,portname,DC_PAPERSIZE,(LPSTR)points,dm))) {
495 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
496 goto out;
498 /* this is _10ths_ of a millimeter */
499 size->x=points[i].x;
500 size->y=points[i].y;
501 retval = TRUE;
502 out:
503 GlobalUnlock(pdlga->hDevNames);
504 GlobalUnlock(pdlga->hDevMode);
505 HeapFree(GetProcessHeap(),0,Words);
506 HeapFree(GetProcessHeap(),0,points);
507 return retval;
510 static BOOL PRINTDLG_PaperSizeW(
511 PRINTDLGW *pdlga,const WCHAR *PaperSize,LPPOINT size
513 DEVNAMES *dn;
514 DEVMODEW *dm;
515 LPWSTR devname,portname;
516 int i;
517 INT NrOfEntries,ret;
518 WCHAR *Names = NULL;
519 POINT *points = NULL;
520 BOOL retval = FALSE;
522 dn = GlobalLock(pdlga->hDevNames);
523 dm = GlobalLock(pdlga->hDevMode);
524 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
525 portname = ((WCHAR*)dn)+dn->wOutputOffset;
528 NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
529 if (!NrOfEntries) {
530 FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
531 goto out;
533 if (NrOfEntries == -1) {
534 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
535 goto out;
538 Names = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
539 if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
540 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
541 goto out;
543 for (i=0;i<NrOfEntries;i++)
544 if (!lstrcmpW(PaperSize,Names+(64*i)))
545 break;
546 HeapFree(GetProcessHeap(),0,Names);
547 if (i==NrOfEntries) {
548 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
549 goto out;
551 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
552 if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
553 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
554 goto out;
556 /* this is _10ths_ of a millimeter */
557 size->x=points[i].x;
558 size->y=points[i].y;
559 retval = TRUE;
560 out:
561 GlobalUnlock(pdlga->hDevNames);
562 GlobalUnlock(pdlga->hDevMode);
563 HeapFree(GetProcessHeap(),0,Names);
564 HeapFree(GetProcessHeap(),0,points);
565 return retval;
569 /************************************************************************
570 * PRINTDLG_SetUpPaperComboBox
572 * Initialize either the papersize or inputslot combos of the Printer Setup
573 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
574 * We also try to re-select the old selection.
576 static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
577 int nIDComboBox,
578 char* PrinterName,
579 char* PortName,
580 LPDEVMODEA dm)
582 int i;
583 int NrOfEntries;
584 char* Names;
585 WORD* Words;
586 DWORD Sel;
587 WORD oldWord = 0;
588 int NamesSize;
589 int fwCapability_Names;
590 int fwCapability_Words;
592 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
594 /* query the dialog box for the current selected value */
595 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
596 if(Sel != CB_ERR) {
597 /* we enter here only if a different printer is selected after
598 * the Print Setup dialog is opened. The current settings are
599 * stored into the newly selected printer.
601 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
602 Sel, 0);
603 if (dm) {
604 if (nIDComboBox == cmb2)
605 dm->u1.s1.dmPaperSize = oldWord;
606 else
607 dm->u1.s1.dmDefaultSource = oldWord;
610 else {
611 /* we enter here only when the Print setup dialog is initially
612 * opened. In this case the settings are restored from when
613 * the dialog was last closed.
615 if (dm) {
616 if (nIDComboBox == cmb2)
617 oldWord = dm->u1.s1.dmPaperSize;
618 else
619 oldWord = dm->u1.s1.dmDefaultSource;
623 if (nIDComboBox == cmb2) {
624 NamesSize = 64;
625 fwCapability_Names = DC_PAPERNAMES;
626 fwCapability_Words = DC_PAPERS;
627 } else {
628 nIDComboBox = cmb3;
629 NamesSize = 24;
630 fwCapability_Names = DC_BINNAMES;
631 fwCapability_Words = DC_BINS;
634 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
635 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
637 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
638 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
639 fwCapability_Names, NULL, dm);
640 if (NrOfEntries == 0)
641 WARN("no Name Entries found!\n");
642 else if (NrOfEntries < 0)
643 return FALSE;
645 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
646 != NrOfEntries) {
647 ERR("Number of caps is different\n");
648 NrOfEntries = 0;
651 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
652 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
653 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
654 fwCapability_Names, Names, dm);
655 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
656 fwCapability_Words, (LPSTR)Words, dm);
658 /* reset any current content in the combobox */
659 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
661 /* store new content */
662 for (i = 0; i < NrOfEntries; i++) {
663 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
664 (LPARAM)(&Names[i*NamesSize]) );
665 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
666 Words[i]);
669 /* Look for old selection - can't do this is previous loop since
670 item order will change as more items are added */
671 Sel = 0;
672 for (i = 0; i < NrOfEntries; i++) {
673 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
674 oldWord) {
675 Sel = i;
676 break;
679 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
681 HeapFree(GetProcessHeap(),0,Words);
682 HeapFree(GetProcessHeap(),0,Names);
683 return TRUE;
686 static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
687 int nIDComboBox,
688 const WCHAR* PrinterName,
689 const WCHAR* PortName,
690 LPDEVMODEW dm)
692 int i;
693 int NrOfEntries;
694 WCHAR* Names;
695 WORD* Words;
696 DWORD Sel;
697 WORD oldWord = 0;
698 int NamesSize;
699 int fwCapability_Names;
700 int fwCapability_Words;
702 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
704 /* query the dialog box for the current selected value */
705 Sel = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
706 if(Sel != CB_ERR) {
707 /* we enter here only if a different printer is selected after
708 * the Print Setup dialog is opened. The current settings are
709 * stored into the newly selected printer.
711 oldWord = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA,
712 Sel, 0);
713 if (dm) {
714 if (nIDComboBox == cmb2)
715 dm->u1.s1.dmPaperSize = oldWord;
716 else
717 dm->u1.s1.dmDefaultSource = oldWord;
720 else {
721 /* we enter here only when the Print setup dialog is initially
722 * opened. In this case the settings are restored from when
723 * the dialog was last closed.
725 if (dm) {
726 if (nIDComboBox == cmb2)
727 oldWord = dm->u1.s1.dmPaperSize;
728 else
729 oldWord = dm->u1.s1.dmDefaultSource;
733 if (nIDComboBox == cmb2) {
734 NamesSize = 64;
735 fwCapability_Names = DC_PAPERNAMES;
736 fwCapability_Words = DC_PAPERS;
737 } else {
738 nIDComboBox = cmb3;
739 NamesSize = 24;
740 fwCapability_Names = DC_BINNAMES;
741 fwCapability_Words = DC_BINS;
744 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
745 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
747 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
748 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
749 fwCapability_Names, NULL, dm);
750 if (NrOfEntries == 0)
751 WARN("no Name Entries found!\n");
752 else if (NrOfEntries < 0)
753 return FALSE;
755 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
756 != NrOfEntries) {
757 ERR("Number of caps is different\n");
758 NrOfEntries = 0;
761 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
762 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
763 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
764 fwCapability_Names, Names, dm);
765 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
766 fwCapability_Words, (LPWSTR)Words, dm);
768 /* reset any current content in the combobox */
769 SendDlgItemMessageW(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
771 /* store new content */
772 for (i = 0; i < NrOfEntries; i++) {
773 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
774 (LPARAM)(&Names[i*NamesSize]) );
775 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
776 Words[i]);
779 /* Look for old selection - can't do this is previous loop since
780 item order will change as more items are added */
781 Sel = 0;
782 for (i = 0; i < NrOfEntries; i++) {
783 if(SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
784 oldWord) {
785 Sel = i;
786 break;
789 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
791 HeapFree(GetProcessHeap(),0,Words);
792 HeapFree(GetProcessHeap(),0,Names);
793 return TRUE;
797 /***********************************************************************
798 * PRINTDLG_UpdatePrinterInfoTexts [internal]
800 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, const PRINTER_INFO_2A *pi)
802 char StatusMsg[256];
803 char ResourceString[256];
804 int i;
806 /* Status Message */
807 StatusMsg[0]='\0';
809 /* add all status messages */
810 for (i = 0; i < 25; i++) {
811 if (pi->Status & (1<<i)) {
812 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
813 ResourceString, 255);
814 strcat(StatusMsg,ResourceString);
817 /* append "ready" */
818 /* FIXME: status==ready must only be appended if really so.
819 but how to detect? */
820 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
821 ResourceString, 255);
822 strcat(StatusMsg,ResourceString);
823 SetDlgItemTextA(hDlg, stc12, StatusMsg);
825 /* set all other printer info texts */
826 SetDlgItemTextA(hDlg, stc11, pi->pDriverName);
828 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
829 SetDlgItemTextA(hDlg, stc14, pi->pLocation);
830 else
831 SetDlgItemTextA(hDlg, stc14, pi->pPortName);
832 SetDlgItemTextA(hDlg, stc13, pi->pComment ? pi->pComment : "");
833 return;
836 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, const PRINTER_INFO_2W *pi)
838 WCHAR StatusMsg[256];
839 WCHAR ResourceString[256];
840 static const WCHAR emptyW[] = {0};
841 int i;
843 /* Status Message */
844 StatusMsg[0]='\0';
846 /* add all status messages */
847 for (i = 0; i < 25; i++) {
848 if (pi->Status & (1<<i)) {
849 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
850 ResourceString, 255);
851 lstrcatW(StatusMsg,ResourceString);
854 /* append "ready" */
855 /* FIXME: status==ready must only be appended if really so.
856 but how to detect? */
857 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
858 ResourceString, 255);
859 lstrcatW(StatusMsg,ResourceString);
860 SetDlgItemTextW(hDlg, stc12, StatusMsg);
862 /* set all other printer info texts */
863 SetDlgItemTextW(hDlg, stc11, pi->pDriverName);
864 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
865 SetDlgItemTextW(hDlg, stc14, pi->pLocation);
866 else
867 SetDlgItemTextW(hDlg, stc14, pi->pPortName);
868 SetDlgItemTextW(hDlg, stc13, pi->pComment ? pi->pComment : emptyW);
872 /*******************************************************************
874 * PRINTDLG_ChangePrinter
877 BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
878 PRINT_PTRA *PrintStructures)
880 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
881 LPDEVMODEA lpdm = NULL;
882 LONG dmSize;
883 DWORD needed;
884 HANDLE hprn;
886 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
887 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
888 if(!OpenPrinterA(name, &hprn, NULL)) {
889 ERR("Can't open printer %s\n", name);
890 return FALSE;
892 GetPrinterA(hprn, 2, NULL, 0, &needed);
893 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
894 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
895 &needed);
896 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
897 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
898 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
899 needed, &needed)) {
900 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
901 return FALSE;
903 ClosePrinter(hprn);
905 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
907 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
908 PrintStructures->lpDevMode = NULL;
910 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
911 if(dmSize == -1) {
912 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
913 return FALSE;
915 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
916 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
917 DM_OUT_BUFFER);
918 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
919 !lstrcmpA( (LPSTR) lpdm->dmDeviceName,
920 (LPSTR) PrintStructures->lpDevMode->dmDeviceName)) {
921 /* Supplied devicemode matches current printer so try to use it */
922 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
923 DM_OUT_BUFFER | DM_IN_BUFFER);
925 if(lpdm)
926 GlobalUnlock(lppd->hDevMode);
928 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
930 if(!(lppd->Flags & PD_PRINTSETUP)) {
931 /* Print range (All/Range/Selection) */
932 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
933 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
934 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
935 if (lppd->Flags & PD_NOSELECTION)
936 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
937 else
938 if (lppd->Flags & PD_SELECTION)
939 CheckRadioButton(hDlg, rad1, rad3, rad2);
940 if (lppd->Flags & PD_NOPAGENUMS) {
941 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
942 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
943 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
944 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
945 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
946 } else {
947 if (lppd->Flags & PD_PAGENUMS)
948 CheckRadioButton(hDlg, rad1, rad3, rad3);
951 /* Collate pages
953 * FIXME: The ico3 is not displayed for some reason. I don't know why.
955 if (lppd->Flags & PD_COLLATE) {
956 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
957 (LPARAM)PrintStructures->hCollateIcon);
958 CheckDlgButton(hDlg, chx2, 1);
959 } else {
960 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
961 (LPARAM)PrintStructures->hNoCollateIcon);
962 CheckDlgButton(hDlg, chx2, 0);
965 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
966 /* if printer doesn't support it: no Collate */
967 if (!(lpdm->dmFields & DM_COLLATE)) {
968 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
969 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
973 /* nCopies */
975 INT copies;
976 if (lppd->hDevMode == 0)
977 copies = lppd->nCopies;
978 else
979 copies = lpdm->u1.s1.dmCopies;
980 if(copies == 0) copies = 1;
981 else if(copies < 0) copies = MAX_COPIES;
982 SetDlgItemInt(hDlg, edt3, copies, FALSE);
985 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
986 /* if printer doesn't support it: no nCopies */
987 if (!(lpdm->dmFields & DM_COPIES)) {
988 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
989 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
993 /* print to file */
994 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
995 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
996 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
997 if (lppd->Flags & PD_HIDEPRINTTOFILE)
998 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1000 } else { /* PD_PRINTSETUP */
1001 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1003 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
1004 PrintStructures->lpPrinterInfo->pPrinterName,
1005 PrintStructures->lpPrinterInfo->pPortName,
1006 lpdm);
1007 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
1008 PrintStructures->lpPrinterInfo->pPrinterName,
1009 PrintStructures->lpPrinterInfo->pPortName,
1010 lpdm);
1011 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1012 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1013 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1014 PrintStructures->hLandscapeIcon));
1018 /* help button */
1019 if ((lppd->Flags & PD_SHOWHELP)==0) {
1020 /* hide if PD_SHOWHELP not specified */
1021 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1023 return TRUE;
1026 static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1027 PRINT_PTRW *PrintStructures)
1029 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1030 LPDEVMODEW lpdm = NULL;
1031 LONG dmSize;
1032 DWORD needed;
1033 HANDLE hprn;
1035 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1036 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1037 if(!OpenPrinterW(name, &hprn, NULL)) {
1038 ERR("Can't open printer %s\n", debugstr_w(name));
1039 return FALSE;
1041 GetPrinterW(hprn, 2, NULL, 0, &needed);
1042 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1043 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1044 &needed);
1045 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1046 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
1047 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1048 needed, &needed)) {
1049 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1050 return FALSE;
1052 ClosePrinter(hprn);
1054 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1056 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1057 PrintStructures->lpDevMode = NULL;
1059 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1060 if(dmSize == -1) {
1061 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1062 return FALSE;
1064 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1065 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1066 DM_OUT_BUFFER);
1067 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1068 !lstrcmpW(lpdm->dmDeviceName,
1069 PrintStructures->lpDevMode->dmDeviceName)) {
1070 /* Supplied devicemode matches current printer so try to use it */
1071 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1072 DM_OUT_BUFFER | DM_IN_BUFFER);
1074 if(lpdm)
1075 GlobalUnlock(lppd->hDevMode);
1077 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1079 if(!(lppd->Flags & PD_PRINTSETUP)) {
1080 /* Print range (All/Range/Selection) */
1081 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1082 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1083 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1084 if (lppd->Flags & PD_NOSELECTION)
1085 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1086 else
1087 if (lppd->Flags & PD_SELECTION)
1088 CheckRadioButton(hDlg, rad1, rad3, rad2);
1089 if (lppd->Flags & PD_NOPAGENUMS) {
1090 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1091 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1092 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1093 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1094 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1095 } else {
1096 if (lppd->Flags & PD_PAGENUMS)
1097 CheckRadioButton(hDlg, rad1, rad3, rad3);
1100 /* Collate pages
1102 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1104 if (lppd->Flags & PD_COLLATE) {
1105 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1106 (LPARAM)PrintStructures->hCollateIcon);
1107 CheckDlgButton(hDlg, chx2, 1);
1108 } else {
1109 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1110 (LPARAM)PrintStructures->hNoCollateIcon);
1111 CheckDlgButton(hDlg, chx2, 0);
1114 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1115 /* if printer doesn't support it: no Collate */
1116 if (!(lpdm->dmFields & DM_COLLATE)) {
1117 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1118 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1122 /* nCopies */
1124 INT copies;
1125 if (lppd->hDevMode == 0)
1126 copies = lppd->nCopies;
1127 else
1128 copies = lpdm->u1.s1.dmCopies;
1129 if(copies == 0) copies = 1;
1130 else if(copies < 0) copies = MAX_COPIES;
1131 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1134 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1135 /* if printer doesn't support it: no nCopies */
1136 if (!(lpdm->dmFields & DM_COPIES)) {
1137 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1138 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1142 /* print to file */
1143 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1144 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1145 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1146 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1147 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1149 } else { /* PD_PRINTSETUP */
1150 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1152 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1153 PrintStructures->lpPrinterInfo->pPrinterName,
1154 PrintStructures->lpPrinterInfo->pPortName,
1155 lpdm);
1156 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1157 PrintStructures->lpPrinterInfo->pPrinterName,
1158 PrintStructures->lpPrinterInfo->pPortName,
1159 lpdm);
1160 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1161 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1162 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1163 PrintStructures->hLandscapeIcon));
1167 /* help button */
1168 if ((lppd->Flags & PD_SHOWHELP)==0) {
1169 /* hide if PD_SHOWHELP not specified */
1170 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1172 return TRUE;
1175 /***********************************************************************
1176 * check_printer_setup [internal]
1178 static LRESULT check_printer_setup(HWND hDlg)
1180 DWORD needed,num;
1181 WCHAR resourcestr[256],resultstr[256];
1182 int res;
1184 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
1185 if(needed == 0)
1187 EnumPrintersW(PRINTER_ENUM_CONNECTIONS, NULL, 2, NULL, 0, &needed, &num);
1189 if(needed > 0)
1190 return TRUE;
1191 else
1193 LoadStringW(COMDLG32_hInstance, PD32_NO_DEVICES,resultstr, 255);
1194 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,resourcestr, 255);
1195 res = MessageBoxW(hDlg, resultstr, resourcestr,MB_OK | MB_ICONWARNING);
1196 return FALSE;
1200 /***********************************************************************
1201 * PRINTDLG_WMInitDialog [internal]
1203 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1204 PRINT_PTRA* PrintStructures)
1206 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1207 DEVNAMES *pdn;
1208 DEVMODEA *pdm;
1209 char *name = NULL;
1210 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1212 /* load Collate ICONs */
1213 /* We load these with LoadImage because they are not a standard
1214 size and we don't want them rescaled */
1215 PrintStructures->hCollateIcon =
1216 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1217 PrintStructures->hNoCollateIcon =
1218 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1220 /* These can be done with LoadIcon */
1221 PrintStructures->hPortraitIcon =
1222 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1223 PrintStructures->hLandscapeIcon =
1224 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1226 /* display the collate/no_collate icon */
1227 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1228 (LPARAM)PrintStructures->hNoCollateIcon);
1230 if(PrintStructures->hCollateIcon == 0 ||
1231 PrintStructures->hNoCollateIcon == 0 ||
1232 PrintStructures->hPortraitIcon == 0 ||
1233 PrintStructures->hLandscapeIcon == 0) {
1234 ERR("no icon in resourcefile\n");
1235 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1236 EndDialog(hDlg, FALSE);
1240 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1241 * must be registered and the Help button must be shown.
1243 if (lppd->Flags & PD_SHOWHELP) {
1244 if((PrintStructures->HelpMessageID =
1245 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1246 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1247 return FALSE;
1249 } else
1250 PrintStructures->HelpMessageID = 0;
1252 if(!(lppd->Flags &PD_PRINTSETUP)) {
1253 PrintStructures->hwndUpDown =
1254 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1255 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1256 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1257 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1258 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1261 /* FIXME: I allow more freedom than either Win95 or WinNT,
1262 * which do not agree to what errors should be thrown or not
1263 * in case nToPage or nFromPage is out-of-range.
1265 if (lppd->nMaxPage < lppd->nMinPage)
1266 lppd->nMaxPage = lppd->nMinPage;
1267 if (lppd->nMinPage == lppd->nMaxPage)
1268 lppd->Flags |= PD_NOPAGENUMS;
1269 if (lppd->nToPage < lppd->nMinPage)
1270 lppd->nToPage = lppd->nMinPage;
1271 if (lppd->nToPage > lppd->nMaxPage)
1272 lppd->nToPage = lppd->nMaxPage;
1273 if (lppd->nFromPage < lppd->nMinPage)
1274 lppd->nFromPage = lppd->nMinPage;
1275 if (lppd->nFromPage > lppd->nMaxPage)
1276 lppd->nFromPage = lppd->nMaxPage;
1278 /* if we have the combo box, fill it */
1279 if (GetDlgItem(hDlg,comboID)) {
1280 /* Fill Combobox
1282 pdn = GlobalLock(lppd->hDevNames);
1283 pdm = GlobalLock(lppd->hDevMode);
1284 if(pdn)
1285 name = (char*)pdn + pdn->wDeviceOffset;
1286 else if(pdm)
1287 name = (char*)pdm->dmDeviceName;
1288 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1289 if(pdm) GlobalUnlock(lppd->hDevMode);
1290 if(pdn) GlobalUnlock(lppd->hDevNames);
1292 /* Now find selected printer and update rest of dlg */
1293 name = HeapAlloc(GetProcessHeap(),0,256);
1294 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1295 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1296 HeapFree(GetProcessHeap(),0,name);
1297 } else {
1298 /* else use default printer */
1299 char name[200];
1300 DWORD dwBufLen = sizeof(name);
1301 BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
1303 if (ret)
1304 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1305 else
1306 FIXME("No default printer found, expect problems!\n");
1308 return TRUE;
1311 static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1312 PRINT_PTRW* PrintStructures)
1314 static const WCHAR PD32_COLLATE[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1315 static const WCHAR PD32_NOCOLLATE[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
1316 static const WCHAR PD32_PORTRAIT[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
1317 static const WCHAR PD32_LANDSCAPE[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
1318 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1319 DEVNAMES *pdn;
1320 DEVMODEW *pdm;
1321 WCHAR *name = NULL;
1322 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1324 /* load Collate ICONs */
1325 /* We load these with LoadImage because they are not a standard
1326 size and we don't want them rescaled */
1327 PrintStructures->hCollateIcon =
1328 LoadImageW(COMDLG32_hInstance, PD32_COLLATE, IMAGE_ICON, 0, 0, 0);
1329 PrintStructures->hNoCollateIcon =
1330 LoadImageW(COMDLG32_hInstance, PD32_NOCOLLATE, IMAGE_ICON, 0, 0, 0);
1332 /* These can be done with LoadIcon */
1333 PrintStructures->hPortraitIcon =
1334 LoadIconW(COMDLG32_hInstance, PD32_PORTRAIT);
1335 PrintStructures->hLandscapeIcon =
1336 LoadIconW(COMDLG32_hInstance, PD32_LANDSCAPE);
1338 /* display the collate/no_collate icon */
1339 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1340 (LPARAM)PrintStructures->hNoCollateIcon);
1342 if(PrintStructures->hCollateIcon == 0 ||
1343 PrintStructures->hNoCollateIcon == 0 ||
1344 PrintStructures->hPortraitIcon == 0 ||
1345 PrintStructures->hLandscapeIcon == 0) {
1346 ERR("no icon in resourcefile\n");
1347 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1348 EndDialog(hDlg, FALSE);
1352 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1353 * must be registered and the Help button must be shown.
1355 if (lppd->Flags & PD_SHOWHELP) {
1356 if((PrintStructures->HelpMessageID =
1357 RegisterWindowMessageW(HELPMSGSTRINGW)) == 0) {
1358 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1359 return FALSE;
1361 } else
1362 PrintStructures->HelpMessageID = 0;
1364 if(!(lppd->Flags &PD_PRINTSETUP)) {
1365 PrintStructures->hwndUpDown =
1366 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1367 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1368 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1369 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1370 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1373 /* FIXME: I allow more freedom than either Win95 or WinNT,
1374 * which do not agree to what errors should be thrown or not
1375 * in case nToPage or nFromPage is out-of-range.
1377 if (lppd->nMaxPage < lppd->nMinPage)
1378 lppd->nMaxPage = lppd->nMinPage;
1379 if (lppd->nMinPage == lppd->nMaxPage)
1380 lppd->Flags |= PD_NOPAGENUMS;
1381 if (lppd->nToPage < lppd->nMinPage)
1382 lppd->nToPage = lppd->nMinPage;
1383 if (lppd->nToPage > lppd->nMaxPage)
1384 lppd->nToPage = lppd->nMaxPage;
1385 if (lppd->nFromPage < lppd->nMinPage)
1386 lppd->nFromPage = lppd->nMinPage;
1387 if (lppd->nFromPage > lppd->nMaxPage)
1388 lppd->nFromPage = lppd->nMaxPage;
1390 /* if we have the combo box, fill it */
1391 if (GetDlgItem(hDlg,comboID)) {
1392 /* Fill Combobox
1394 pdn = GlobalLock(lppd->hDevNames);
1395 pdm = GlobalLock(lppd->hDevMode);
1396 if(pdn)
1397 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1398 else if(pdm)
1399 name = pdm->dmDeviceName;
1400 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1401 if(pdm) GlobalUnlock(lppd->hDevMode);
1402 if(pdn) GlobalUnlock(lppd->hDevNames);
1404 /* Now find selected printer and update rest of dlg */
1405 /* ansi is ok here */
1406 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1407 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1408 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1409 HeapFree(GetProcessHeap(),0,name);
1410 } else {
1411 /* else use default printer */
1412 WCHAR name[200];
1413 DWORD dwBufLen = sizeof(name) / sizeof(WCHAR);
1414 BOOL ret = GetDefaultPrinterW(name, &dwBufLen);
1416 if (ret)
1417 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1418 else
1419 FIXME("No default printer found, expect problems!\n");
1421 return TRUE;
1424 /***********************************************************************
1425 * PRINTDLG_WMCommand [internal]
1427 LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1428 LPARAM lParam, PRINT_PTRA* PrintStructures)
1430 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1431 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1432 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1434 switch (LOWORD(wParam)) {
1435 case IDOK:
1436 TRACE(" OK button was hit\n");
1437 if (!PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)) {
1438 FIXME("Update printdlg was not successful!\n");
1439 return(FALSE);
1441 EndDialog(hDlg, TRUE);
1442 return(TRUE);
1444 case IDCANCEL:
1445 TRACE(" CANCEL button was hit\n");
1446 EndDialog(hDlg, FALSE);
1447 return(FALSE);
1449 case pshHelp:
1450 TRACE(" HELP button was hit\n");
1451 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1452 (WPARAM) hDlg, (LPARAM) lppd);
1453 break;
1455 case chx2: /* collate pages checkbox */
1456 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1457 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1458 (LPARAM)PrintStructures->hCollateIcon);
1459 else
1460 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1461 (LPARAM)PrintStructures->hNoCollateIcon);
1462 break;
1463 case edt1: /* from page nr editbox */
1464 case edt2: /* to page nr editbox */
1465 if (HIWORD(wParam)==EN_CHANGE) {
1466 WORD nToPage;
1467 WORD nFromPage;
1468 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1469 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1470 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1471 CheckRadioButton(hDlg, rad1, rad3, rad3);
1473 break;
1475 case edt3:
1476 if(HIWORD(wParam) == EN_CHANGE) {
1477 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1478 if(copies <= 1)
1479 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1480 else
1481 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1483 break;
1485 #if 0
1486 case psh1: /* Print Setup */
1488 PRINTDLG16 pdlg;
1490 if (!PrintStructures->dlg.lpPrintDlg16) {
1491 FIXME("The 32bit print dialog does not have this button!?\n");
1492 break;
1495 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1496 pdlg.Flags |= PD_PRINTSETUP;
1497 pdlg.hwndOwner = HWND_16(hDlg);
1498 if (!PrintDlg16(&pdlg))
1499 break;
1501 break;
1502 #endif
1503 case psh2: /* Properties button */
1505 HANDLE hPrinter;
1506 char PrinterName[256];
1508 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1509 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1510 FIXME(" Call to OpenPrinter did not succeed!\n");
1511 break;
1513 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1514 PrintStructures->lpDevMode,
1515 PrintStructures->lpDevMode,
1516 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1517 ClosePrinter(hPrinter);
1518 break;
1521 case rad1: /* Paperorientation */
1522 if (lppd->Flags & PD_PRINTSETUP)
1524 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1525 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1526 (LPARAM)(PrintStructures->hPortraitIcon));
1528 break;
1530 case rad2: /* Paperorientation */
1531 if (lppd->Flags & PD_PRINTSETUP)
1533 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1534 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1535 (LPARAM)(PrintStructures->hLandscapeIcon));
1537 break;
1539 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1540 if (PrinterComboID != LOWORD(wParam)) {
1541 FIXME("No handling for print quality combo box yet.\n");
1542 break;
1544 /* FALLTHROUGH */
1545 case cmb4: /* Printer combobox */
1546 if (HIWORD(wParam)==CBN_SELCHANGE) {
1547 char PrinterName[256];
1548 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1549 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1551 break;
1553 case cmb2: /* Papersize */
1555 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1556 if(Sel != CB_ERR)
1557 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1558 CB_GETITEMDATA,
1559 Sel, 0);
1561 break;
1563 case cmb3: /* Bin */
1565 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1566 if(Sel != CB_ERR)
1567 lpdm->u1.s1.dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1568 CB_GETITEMDATA, Sel,
1571 break;
1573 if(lppd->Flags & PD_PRINTSETUP) {
1574 switch (LOWORD(wParam)) {
1575 case rad1: /* orientation */
1576 case rad2:
1577 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1578 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1579 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1580 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1581 (WPARAM)IMAGE_ICON,
1582 (LPARAM)PrintStructures->hPortraitIcon);
1583 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1584 (WPARAM)IMAGE_ICON,
1585 (LPARAM)PrintStructures->hPortraitIcon);
1587 } else {
1588 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1589 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1590 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1591 (WPARAM)IMAGE_ICON,
1592 (LPARAM)PrintStructures->hLandscapeIcon);
1593 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1594 (WPARAM)IMAGE_ICON,
1595 (LPARAM)PrintStructures->hLandscapeIcon);
1598 break;
1601 return FALSE;
1604 static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1605 LPARAM lParam, PRINT_PTRW* PrintStructures)
1607 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1608 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1609 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1611 switch (LOWORD(wParam)) {
1612 case IDOK:
1613 TRACE(" OK button was hit\n");
1614 if (!PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)) {
1615 FIXME("Update printdlg was not successful!\n");
1616 return(FALSE);
1618 EndDialog(hDlg, TRUE);
1619 return(TRUE);
1621 case IDCANCEL:
1622 TRACE(" CANCEL button was hit\n");
1623 EndDialog(hDlg, FALSE);
1624 return(FALSE);
1626 case pshHelp:
1627 TRACE(" HELP button was hit\n");
1628 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1629 (WPARAM) hDlg, (LPARAM) lppd);
1630 break;
1632 case chx2: /* collate pages checkbox */
1633 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1634 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1635 (LPARAM)PrintStructures->hCollateIcon);
1636 else
1637 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1638 (LPARAM)PrintStructures->hNoCollateIcon);
1639 break;
1640 case edt1: /* from page nr editbox */
1641 case edt2: /* to page nr editbox */
1642 if (HIWORD(wParam)==EN_CHANGE) {
1643 WORD nToPage;
1644 WORD nFromPage;
1645 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1646 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1647 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1648 CheckRadioButton(hDlg, rad1, rad3, rad3);
1650 break;
1652 case edt3:
1653 if(HIWORD(wParam) == EN_CHANGE) {
1654 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1655 if(copies <= 1)
1656 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1657 else
1658 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1660 break;
1662 case psh1: /* Print Setup */
1664 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1666 break;
1667 case psh2: /* Properties button */
1669 HANDLE hPrinter;
1670 WCHAR PrinterName[256];
1672 if (!GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255)) break;
1673 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1674 FIXME(" Call to OpenPrinter did not succeed!\n");
1675 break;
1677 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1678 PrintStructures->lpDevMode,
1679 PrintStructures->lpDevMode,
1680 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1681 ClosePrinter(hPrinter);
1682 break;
1685 case rad1: /* Paperorientation */
1686 if (lppd->Flags & PD_PRINTSETUP)
1688 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1689 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1690 (LPARAM)(PrintStructures->hPortraitIcon));
1692 break;
1694 case rad2: /* Paperorientation */
1695 if (lppd->Flags & PD_PRINTSETUP)
1697 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1698 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1699 (LPARAM)(PrintStructures->hLandscapeIcon));
1701 break;
1703 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT */
1704 if (PrinterComboID != LOWORD(wParam)) {
1705 FIXME("No handling for print quality combo box yet.\n");
1706 break;
1708 /* FALLTHROUGH */
1709 case cmb4: /* Printer combobox */
1710 if (HIWORD(wParam)==CBN_SELCHANGE) {
1711 WCHAR PrinterName[256];
1712 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1713 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1715 break;
1717 case cmb2: /* Papersize */
1719 DWORD Sel = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1720 if(Sel != CB_ERR)
1721 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageW(hDlg, cmb2,
1722 CB_GETITEMDATA,
1723 Sel, 0);
1725 break;
1727 case cmb3: /* Bin */
1729 DWORD Sel = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1730 if(Sel != CB_ERR)
1731 lpdm->u1.s1.dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1732 CB_GETITEMDATA, Sel,
1735 break;
1737 if(lppd->Flags & PD_PRINTSETUP) {
1738 switch (LOWORD(wParam)) {
1739 case rad1: /* orientation */
1740 case rad2:
1741 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1742 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1743 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1744 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1745 (WPARAM)IMAGE_ICON,
1746 (LPARAM)PrintStructures->hPortraitIcon);
1747 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1748 (WPARAM)IMAGE_ICON,
1749 (LPARAM)PrintStructures->hPortraitIcon);
1751 } else {
1752 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1753 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1754 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1755 (WPARAM)IMAGE_ICON,
1756 (LPARAM)PrintStructures->hLandscapeIcon);
1757 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1758 (WPARAM)IMAGE_ICON,
1759 (LPARAM)PrintStructures->hLandscapeIcon);
1762 break;
1765 return FALSE;
1768 /***********************************************************************
1769 * PrintDlgProcA [internal]
1771 static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1772 LPARAM lParam)
1774 PRINT_PTRA* PrintStructures;
1775 INT_PTR res = FALSE;
1777 if (uMsg!=WM_INITDIALOG) {
1778 PrintStructures = (PRINT_PTRA*)GetPropA(hDlg,"__WINE_PRINTDLGDATA");
1779 if (!PrintStructures)
1780 return FALSE;
1781 } else {
1782 PrintStructures = (PRINT_PTRA*) lParam;
1783 SetPropA(hDlg,"__WINE_PRINTDLGDATA",PrintStructures);
1784 if(!check_printer_setup(hDlg))
1786 EndDialog(hDlg,FALSE);
1787 return FALSE;
1789 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
1791 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1792 res = PrintStructures->lpPrintDlg->lpfnPrintHook(
1793 hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg
1795 return res;
1798 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1799 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
1800 lParam);
1801 if(res) return res;
1804 switch (uMsg) {
1805 case WM_COMMAND:
1806 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
1808 case WM_DESTROY:
1809 DestroyIcon(PrintStructures->hCollateIcon);
1810 DestroyIcon(PrintStructures->hNoCollateIcon);
1811 DestroyIcon(PrintStructures->hPortraitIcon);
1812 DestroyIcon(PrintStructures->hLandscapeIcon);
1813 if(PrintStructures->hwndUpDown)
1814 DestroyWindow(PrintStructures->hwndUpDown);
1815 return FALSE;
1817 return res;
1820 static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1821 LPARAM lParam)
1823 static const WCHAR propW[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
1824 PRINT_PTRW* PrintStructures;
1825 INT_PTR res = FALSE;
1827 if (uMsg!=WM_INITDIALOG) {
1828 PrintStructures = (PRINT_PTRW*) GetPropW(hDlg, propW);
1829 if (!PrintStructures)
1830 return FALSE;
1831 } else {
1832 PrintStructures = (PRINT_PTRW*) lParam;
1833 SetPropW(hDlg, propW, PrintStructures);
1834 if(!check_printer_setup(hDlg))
1836 EndDialog(hDlg,FALSE);
1837 return FALSE;
1839 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
1841 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1842 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg);
1843 return res;
1846 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1847 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, lParam);
1848 if(res) return res;
1851 switch (uMsg) {
1852 case WM_COMMAND:
1853 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
1855 case WM_DESTROY:
1856 DestroyIcon(PrintStructures->hCollateIcon);
1857 DestroyIcon(PrintStructures->hNoCollateIcon);
1858 DestroyIcon(PrintStructures->hPortraitIcon);
1859 DestroyIcon(PrintStructures->hLandscapeIcon);
1860 if(PrintStructures->hwndUpDown)
1861 DestroyWindow(PrintStructures->hwndUpDown);
1862 return FALSE;
1864 return res;
1867 /************************************************************
1869 * PRINTDLG_GetDlgTemplate
1872 static HGLOBAL PRINTDLG_GetDlgTemplateA(const PRINTDLGA *lppd)
1874 HRSRC hResInfo;
1875 HGLOBAL hDlgTmpl;
1877 if (lppd->Flags & PD_PRINTSETUP) {
1878 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1879 hDlgTmpl = lppd->hSetupTemplate;
1880 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1881 hResInfo = FindResourceA(lppd->hInstance,
1882 lppd->lpSetupTemplateName, (LPSTR)RT_DIALOG);
1883 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1884 } else {
1885 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
1886 (LPSTR)RT_DIALOG);
1887 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1889 } else {
1890 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1891 hDlgTmpl = lppd->hPrintTemplate;
1892 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1893 hResInfo = FindResourceA(lppd->hInstance,
1894 lppd->lpPrintTemplateName,
1895 (LPSTR)RT_DIALOG);
1896 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1897 } else {
1898 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
1899 (LPSTR)RT_DIALOG);
1900 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1903 return hDlgTmpl;
1906 static HGLOBAL PRINTDLG_GetDlgTemplateW(const PRINTDLGW *lppd)
1908 HRSRC hResInfo;
1909 HGLOBAL hDlgTmpl;
1910 static const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1911 static const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
1913 if (lppd->Flags & PD_PRINTSETUP) {
1914 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1915 hDlgTmpl = lppd->hSetupTemplate;
1916 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1917 hResInfo = FindResourceW(lppd->hInstance,
1918 lppd->lpSetupTemplateName, (LPWSTR)RT_DIALOG);
1919 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1920 } else {
1921 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, (LPWSTR)RT_DIALOG);
1922 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1924 } else {
1925 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1926 hDlgTmpl = lppd->hPrintTemplate;
1927 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1928 hResInfo = FindResourceW(lppd->hInstance,
1929 lppd->lpPrintTemplateName,
1930 (LPWSTR)RT_DIALOG);
1931 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1932 } else {
1933 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, (LPWSTR)RT_DIALOG);
1934 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1937 return hDlgTmpl;
1940 /***********************************************************************
1942 * PRINTDLG_CreateDC
1945 static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
1947 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1948 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
1950 if(lppd->Flags & PD_RETURNDC) {
1951 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
1952 (char*)pdn + pdn->wDeviceOffset,
1953 (char*)pdn + pdn->wOutputOffset,
1954 pdm );
1955 } else if(lppd->Flags & PD_RETURNIC) {
1956 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
1957 (char*)pdn + pdn->wDeviceOffset,
1958 (char*)pdn + pdn->wOutputOffset,
1959 pdm );
1961 GlobalUnlock(lppd->hDevNames);
1962 GlobalUnlock(lppd->hDevMode);
1963 return lppd->hDC ? TRUE : FALSE;
1966 static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
1968 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1969 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
1971 if(lppd->Flags & PD_RETURNDC) {
1972 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
1973 (WCHAR*)pdn + pdn->wDeviceOffset,
1974 (WCHAR*)pdn + pdn->wOutputOffset,
1975 pdm );
1976 } else if(lppd->Flags & PD_RETURNIC) {
1977 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
1978 (WCHAR*)pdn + pdn->wDeviceOffset,
1979 (WCHAR*)pdn + pdn->wOutputOffset,
1980 pdm );
1982 GlobalUnlock(lppd->hDevNames);
1983 GlobalUnlock(lppd->hDevMode);
1984 return lppd->hDC ? TRUE : FALSE;
1987 /***********************************************************************
1988 * PrintDlgA (COMDLG32.@)
1990 * Displays the PRINT dialog box, which enables the user to specify
1991 * specific properties of the print job.
1993 * PARAMS
1994 * lppd [IO] ptr to PRINTDLG32 struct
1996 * RETURNS
1997 * nonzero if the user pressed the OK button
1998 * zero if the user cancelled the window or an error occurred
2000 * BUGS
2001 * PrintDlg:
2002 * * The Collate Icons do not display, even though they are in the code.
2003 * * The Properties Button(s) should call DocumentPropertiesA().
2006 BOOL WINAPI PrintDlgA(LPPRINTDLGA lppd)
2008 BOOL bRet = FALSE;
2009 LPVOID ptr;
2010 HINSTANCE hInst;
2012 if (!lppd)
2014 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
2015 return FALSE;
2018 hInst = (HINSTANCE)GetWindowLongPtrA( lppd->hwndOwner, GWLP_HINSTANCE );
2019 if(TRACE_ON(commdlg)) {
2020 char flagstr[1000] = "";
2021 const struct pd_flags *pflag = pd_flags;
2022 for( ; pflag->name; pflag++) {
2023 if(lppd->Flags & pflag->flag)
2024 strcat(flagstr, pflag->name);
2026 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2027 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2028 "flags %08x (%s)\n",
2029 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2030 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2031 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2034 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
2035 WARN("structure size failure !!!\n");
2036 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2037 return FALSE;
2040 if(lppd->Flags & PD_RETURNDEFAULT) {
2041 PRINTER_INFO_2A *pbuf;
2042 DRIVER_INFO_3A *dbuf;
2043 HANDLE hprn;
2044 DWORD needed;
2046 if(lppd->hDevMode || lppd->hDevNames) {
2047 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2048 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2049 return FALSE;
2051 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2052 WARN("Can't find default printer\n");
2053 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2054 return FALSE;
2057 GetPrinterA(hprn, 2, NULL, 0, &needed);
2058 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2059 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2061 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2062 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2063 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2064 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2065 GetLastError(),pbuf->pPrinterName);
2066 HeapFree(GetProcessHeap(), 0, dbuf);
2067 HeapFree(GetProcessHeap(), 0, pbuf);
2068 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2069 return FALSE;
2071 ClosePrinter(hprn);
2073 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2074 dbuf->pDriverPath,
2075 pbuf->pPrinterName,
2076 pbuf->pPortName);
2077 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2078 pbuf->pDevMode->dmDriverExtra);
2079 ptr = GlobalLock(lppd->hDevMode);
2080 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2081 pbuf->pDevMode->dmDriverExtra);
2082 GlobalUnlock(lppd->hDevMode);
2083 HeapFree(GetProcessHeap(), 0, pbuf);
2084 HeapFree(GetProcessHeap(), 0, dbuf);
2085 bRet = TRUE;
2086 } else {
2087 HGLOBAL hDlgTmpl;
2088 PRINT_PTRA *PrintStructures;
2090 /* load Dialog resources,
2091 * depending on Flags indicates Print32 or Print32_setup dialog
2093 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2094 if (!hDlgTmpl) {
2095 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2096 return FALSE;
2098 ptr = LockResource( hDlgTmpl );
2099 if (!ptr) {
2100 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2101 return FALSE;
2104 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2105 sizeof(PRINT_PTRA));
2106 PrintStructures->lpPrintDlg = lppd;
2108 /* and create & process the dialog .
2109 * -1 is failure, 0 is broken hwnd, everything else is ok.
2111 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2112 PrintDlgProcA,
2113 (LPARAM)PrintStructures));
2115 if(bRet) {
2116 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2117 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2118 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2120 if (lppd->hDevMode == 0) {
2121 TRACE(" No hDevMode yet... Need to create my own\n");
2122 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2123 lpdm->dmSize + lpdm->dmDriverExtra);
2124 } else {
2125 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2126 lpdm->dmSize + lpdm->dmDriverExtra,
2127 GMEM_MOVEABLE);
2129 lpdmReturn = GlobalLock(lppd->hDevMode);
2130 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2132 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2133 di->pDriverPath,
2134 pi->pPrinterName,
2135 pi->pPortName
2137 GlobalUnlock(lppd->hDevMode);
2139 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2140 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2141 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2142 HeapFree(GetProcessHeap(), 0, PrintStructures);
2144 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2145 bRet = PRINTDLG_CreateDCA(lppd);
2147 TRACE("exit! (%d)\n", bRet);
2148 return bRet;
2151 /***********************************************************************
2152 * PrintDlgW (COMDLG32.@)
2154 * See PrintDlgA.
2156 BOOL WINAPI PrintDlgW(LPPRINTDLGW lppd)
2158 BOOL bRet = FALSE;
2159 LPVOID ptr;
2160 HINSTANCE hInst;
2162 if (!lppd)
2164 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
2165 return FALSE;
2168 hInst = (HINSTANCE)GetWindowLongPtrW( lppd->hwndOwner, GWLP_HINSTANCE );
2169 if(TRACE_ON(commdlg)) {
2170 char flagstr[1000] = "";
2171 const struct pd_flags *pflag = pd_flags;
2172 for( ; pflag->name; pflag++) {
2173 if(lppd->Flags & pflag->flag)
2174 strcat(flagstr, pflag->name);
2176 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2177 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2178 "flags %08x (%s)\n",
2179 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2180 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2181 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2184 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2185 WARN("structure size failure !!!\n");
2186 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2187 return FALSE;
2190 if(lppd->Flags & PD_RETURNDEFAULT) {
2191 PRINTER_INFO_2W *pbuf;
2192 DRIVER_INFO_3W *dbuf;
2193 HANDLE hprn;
2194 DWORD needed;
2196 if(lppd->hDevMode || lppd->hDevNames) {
2197 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2198 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2199 return FALSE;
2201 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2202 WARN("Can't find default printer\n");
2203 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2204 return FALSE;
2207 GetPrinterW(hprn, 2, NULL, 0, &needed);
2208 pbuf = HeapAlloc(GetProcessHeap(), 0, sizeof(WCHAR)*needed);
2209 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2211 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2212 dbuf = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*needed);
2213 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2214 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2215 GetLastError(),debugstr_w(pbuf->pPrinterName));
2216 HeapFree(GetProcessHeap(), 0, dbuf);
2217 HeapFree(GetProcessHeap(), 0, pbuf);
2218 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2219 return FALSE;
2221 ClosePrinter(hprn);
2223 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2224 dbuf->pDriverPath,
2225 pbuf->pPrinterName,
2226 pbuf->pPortName);
2227 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2228 pbuf->pDevMode->dmDriverExtra);
2229 ptr = GlobalLock(lppd->hDevMode);
2230 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2231 pbuf->pDevMode->dmDriverExtra);
2232 GlobalUnlock(lppd->hDevMode);
2233 HeapFree(GetProcessHeap(), 0, pbuf);
2234 HeapFree(GetProcessHeap(), 0, dbuf);
2235 bRet = TRUE;
2236 } else {
2237 HGLOBAL hDlgTmpl;
2238 PRINT_PTRW *PrintStructures;
2240 /* load Dialog resources,
2241 * depending on Flags indicates Print32 or Print32_setup dialog
2243 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2244 if (!hDlgTmpl) {
2245 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2246 return FALSE;
2248 ptr = LockResource( hDlgTmpl );
2249 if (!ptr) {
2250 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2251 return FALSE;
2254 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2255 sizeof(PRINT_PTRW));
2256 PrintStructures->lpPrintDlg = lppd;
2258 /* and create & process the dialog .
2259 * -1 is failure, 0 is broken hwnd, everything else is ok.
2261 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2262 PrintDlgProcW,
2263 (LPARAM)PrintStructures));
2265 if(bRet) {
2266 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2267 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2268 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2270 if (lppd->hDevMode == 0) {
2271 TRACE(" No hDevMode yet... Need to create my own\n");
2272 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2273 lpdm->dmSize + lpdm->dmDriverExtra);
2274 } else {
2275 WORD locks;
2276 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2277 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2278 while(locks--) {
2279 GlobalUnlock(lppd->hDevMode);
2280 TRACE("Now got %d locks\n", locks);
2283 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2284 lpdm->dmSize + lpdm->dmDriverExtra,
2285 GMEM_MOVEABLE);
2287 lpdmReturn = GlobalLock(lppd->hDevMode);
2288 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2290 if (lppd->hDevNames != 0) {
2291 WORD locks;
2292 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2293 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2294 while(locks--)
2295 GlobalUnlock(lppd->hDevNames);
2298 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2299 di->pDriverPath,
2300 pi->pPrinterName,
2301 pi->pPortName
2303 GlobalUnlock(lppd->hDevMode);
2305 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2306 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2307 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2308 HeapFree(GetProcessHeap(), 0, PrintStructures);
2310 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2311 bRet = PRINTDLG_CreateDCW(lppd);
2313 TRACE("exit! (%d)\n", bRet);
2314 return bRet;
2317 /***********************************************************************
2319 * PageSetupDlg
2320 * rad1 - portrait
2321 * rad2 - landscape
2322 * cmb1 - printer select (not in standard dialog template)
2323 * cmb2 - paper size
2324 * cmb3 - source (tray?)
2325 * edt4 - border left
2326 * edt5 - border top
2327 * edt6 - border right
2328 * edt7 - border bottom
2329 * psh3 - "Printer..."
2332 typedef struct {
2333 LPPAGESETUPDLGA dlga; /* Handler to user defined struct */
2334 PRINTDLGA pdlg;
2335 HWND hDlg; /* Page Setup dialog handler */
2336 PAGESETUPDLGA curdlg; /* Stores the current dialog state */
2337 RECT rtDrawRect; /* Drawing rect for page */
2338 } PageSetupDataA;
2340 typedef struct {
2341 LPPAGESETUPDLGW dlga;
2342 PRINTDLGW pdlg;
2343 PAGESETUPDLGW curdlg; /* Current dialog state */
2344 } PageSetupDataW;
2347 static HGLOBAL PRINTDLG_GetPGSTemplateA(const PAGESETUPDLGA *lppd)
2349 HRSRC hResInfo;
2350 HGLOBAL hDlgTmpl;
2352 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2353 hDlgTmpl = lppd->hPageSetupTemplate;
2354 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2355 hResInfo = FindResourceA(lppd->hInstance,
2356 lppd->lpPageSetupTemplateName, (LPSTR)RT_DIALOG);
2357 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2358 } else {
2359 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,(LPSTR)RT_DIALOG);
2360 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2362 return hDlgTmpl;
2365 static HGLOBAL PRINTDLG_GetPGSTemplateW(const PAGESETUPDLGW *lppd)
2367 HRSRC hResInfo;
2368 HGLOBAL hDlgTmpl;
2370 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2371 hDlgTmpl = lppd->hPageSetupTemplate;
2372 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2373 hResInfo = FindResourceW(lppd->hInstance,
2374 lppd->lpPageSetupTemplateName, (LPWSTR)RT_DIALOG);
2375 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2376 } else {
2377 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,(LPWSTR)RT_DIALOG);
2378 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2380 return hDlgTmpl;
2383 static DWORD
2384 _c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
2385 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2386 return 10*size*100/254;
2387 /* If we don't have a flag, we can choose one. Use millimeters
2388 * to avoid confusing me
2390 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2391 return 10*size;
2395 static DWORD
2396 _c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
2397 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2398 return size;
2399 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2400 return (size*254)/100;
2401 /* if we don't have a flag, we can choose one. Use millimeters
2402 * to avoid confusing me
2404 dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2405 return (size*254)/100;
2408 static void
2409 _c_size2strA(PageSetupDataA *pda,DWORD size,LPSTR strout) {
2410 strcpy(strout,"<undef>");
2411 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2412 sprintf(strout,"%d",(size)/100);
2413 return;
2415 if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2416 sprintf(strout,"%din",(size)/1000);
2417 return;
2419 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2420 sprintf(strout,"%d",(size)/100);
2421 return;
2423 static void
2424 _c_size2strW(PageSetupDataW *pda,DWORD size,LPWSTR strout) {
2425 static const char mm_fmt[] = "%.2f mm";
2426 static const char in_fmt[] = "%.2f in";
2427 char buf[20];
2428 if (pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2429 sprintf(buf, mm_fmt, (size * 1.0) / 100.0);
2430 } else if (pda->dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2431 sprintf(buf, in_fmt, (size * 1.0) / 1000.0);
2432 } else {
2433 pda->dlga->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2434 sprintf(buf, mm_fmt, (size * 1.0) / 100.0);
2437 MultiByteToWideChar(CP_ACP, 0, buf, -1, strout, 20);
2440 static DWORD
2441 _c_str2sizeA(const PAGESETUPDLGA *dlga, LPCSTR strin) {
2442 float val;
2443 char rest[200];
2445 rest[0]='\0';
2446 if (!sscanf(strin,"%f%s",&val,rest))
2447 return 0;
2449 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
2450 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2451 return 1000*val;
2452 else
2453 return val*25.4*100;
2455 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
2456 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
2458 if (!strcmp(rest,"mm")) {
2459 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2460 return 100*val;
2461 else
2462 return 1000.0*val/25.4;
2464 if (rest[0]=='\0') {
2465 /* use application supplied default */
2466 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2467 /* 100*mm */
2468 return 100.0*val;
2470 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2471 /* 1000*inch */
2472 return 1000.0*val;
2475 ERR("Did not find a conversion for type '%s'!\n",rest);
2476 return 0;
2480 static DWORD
2481 _c_str2sizeW(const PAGESETUPDLGW *dlga, LPCWSTR strin) {
2482 char buf[200];
2484 /* this W -> A transition is OK */
2485 /* we need a unicode version of sscanf to avoid it */
2486 WideCharToMultiByte(CP_ACP, 0, strin, -1, buf, sizeof(buf), NULL, NULL);
2487 return _c_str2sizeA((const PAGESETUPDLGA *)dlga, buf);
2491 /****************************************************************************
2492 * PRINTDLG_PS_UpdateDlgStructA
2494 * Updates pda->dlga structure
2495 * Function calls when user presses OK button
2497 * PARAMS
2498 * hDlg [in] main window dialog HANDLE
2499 * pda [in/out] ptr to PageSetupDataA structure
2501 * RETURNS
2502 * TRUE
2504 static BOOL
2505 PRINTDLG_PS_UpdateDlgStructA(HWND hDlg, PageSetupDataA *pda) {
2506 DEVNAMES *dn;
2507 DEVMODEA *dm;
2508 DWORD paperword;
2510 memcpy(pda->dlga, &pda->curdlg, sizeof(pda->curdlg));
2511 pda->dlga->hDevMode = pda->pdlg.hDevMode;
2512 pda->dlga->hDevNames = pda->pdlg.hDevNames;
2514 dn = GlobalLock(pda->pdlg.hDevNames);
2515 dm = GlobalLock(pda->pdlg.hDevMode);
2517 /* Save paper orientation into device context */
2518 if(pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y)
2519 dm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2520 else
2521 dm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2523 /* Save paper size into the device context */
2524 paperword = SendDlgItemMessageA(hDlg,cmb2,CB_GETITEMDATA,
2525 SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0), 0);
2526 if (paperword != CB_ERR)
2527 dm->u1.s1.dmPaperSize = paperword;
2528 else
2529 FIXME("could not get dialog text for papersize cmbbox?\n");
2531 /* Save paper source into the device context */
2532 paperword = SendDlgItemMessageA(hDlg,cmb1,CB_GETITEMDATA,
2533 SendDlgItemMessageA(hDlg, cmb1, CB_GETCURSEL, 0, 0), 0);
2534 if (paperword != CB_ERR)
2535 dm->u1.s1.dmDefaultSource = paperword;
2536 else
2537 FIXME("could not get dialog text for papersize cmbbox?\n");
2539 GlobalUnlock(pda->pdlg.hDevNames);
2540 GlobalUnlock(pda->pdlg.hDevMode);
2542 return TRUE;
2545 static BOOL
2546 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pda) {
2547 DEVNAMES *dn;
2548 DEVMODEW *dm;
2549 LPWSTR devname,portname;
2550 WCHAR papername[64];
2551 WCHAR buf[200];
2553 dn = GlobalLock(pda->pdlg.hDevNames);
2554 dm = GlobalLock(pda->pdlg.hDevMode);
2555 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2556 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2558 /* Save paper size into device context */
2559 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2560 /* Save paper source into device context */
2561 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2563 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername))>0) {
2564 PRINTDLG_PaperSizeW(&(pda->pdlg),papername,&(pda->dlga->ptPaperSize));
2565 pda->dlga->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.x);
2566 pda->dlga->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga,pda->dlga->ptPaperSize.y);
2567 } else
2568 FIXME("could not get dialog text for papersize cmbbox?\n");
2569 #define GETVAL(id,val) if (GetDlgItemTextW(hDlg,id,buf,sizeof(buf)/sizeof(buf[0]))>0) { val = _c_str2sizeW(pda->dlga,buf); } else { FIXME("could not get dlgitemtextw for %x\n",id); }
2570 GETVAL(edt4,pda->dlga->rtMargin.left);
2571 GETVAL(edt5,pda->dlga->rtMargin.top);
2572 GETVAL(edt6,pda->dlga->rtMargin.right);
2573 GETVAL(edt7,pda->dlga->rtMargin.bottom);
2574 #undef GETVAL
2576 /* If we are in landscape, swap x and y of page size */
2577 if (IsDlgButtonChecked(hDlg, rad2)) {
2578 DWORD tmp;
2579 tmp = pda->dlga->ptPaperSize.x;
2580 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
2581 pda->dlga->ptPaperSize.y = tmp;
2584 /* Save orientation */
2585 if (pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y)
2586 dm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2587 else
2588 dm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2590 GlobalUnlock(pda->pdlg.hDevNames);
2591 GlobalUnlock(pda->pdlg.hDevMode);
2592 return TRUE;
2595 /**********************************************************************************************
2596 * PRINTDLG_PS_ChangeActivePrinerA
2598 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2600 * PARAMS
2601 * name [in] Name of a printer for activation
2602 * pda [in/out] ptr to PageSetupDataA structure
2604 * RETURN
2605 * TRUE if success
2606 * FALSE if fail
2608 static BOOL
2609 PRINTDLG_PS_ChangeActivePrinterA(LPSTR name, PageSetupDataA *pda){
2610 HANDLE hprn;
2611 DWORD needed;
2612 LPPRINTER_INFO_2A lpPrinterInfo;
2613 LPDRIVER_INFO_3A lpDriverInfo;
2614 DEVMODEA *pDevMode, *dm;
2616 if(!OpenPrinterA(name, &hprn, NULL)){
2617 ERR("Can't open printer %s\n", name);
2618 return FALSE;
2620 GetPrinterA(hprn, 2, NULL, 0, &needed);
2621 lpPrinterInfo = HeapAlloc(GetProcessHeap(), 0, needed);
2622 GetPrinterA(hprn, 2, (LPBYTE)lpPrinterInfo, needed, &needed);
2623 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2624 lpDriverInfo = HeapAlloc(GetProcessHeap(), 0, needed);
2625 if(!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)lpDriverInfo, needed, &needed)) {
2626 ERR("GetPrinterDriverA failed for %s, fix your config!\n", lpPrinterInfo->pPrinterName);
2627 HeapFree(GetProcessHeap(), 0, lpDriverInfo);
2628 HeapFree(GetProcessHeap(), 0, lpPrinterInfo);
2629 return FALSE;
2631 ClosePrinter(hprn);
2633 needed = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
2634 if(needed == -1) {
2635 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
2636 HeapFree(GetProcessHeap(), 0, lpDriverInfo);
2637 HeapFree(GetProcessHeap(), 0, lpPrinterInfo);
2638 return FALSE;
2640 pDevMode = HeapAlloc(GetProcessHeap(), 0, needed);
2641 DocumentPropertiesA(0, 0, name, pDevMode, NULL, DM_OUT_BUFFER);
2643 pda->pdlg.hDevMode = GlobalReAlloc(pda->pdlg.hDevMode,
2644 pDevMode->dmSize + pDevMode->dmDriverExtra,
2645 GMEM_MOVEABLE);
2646 dm = GlobalLock(pda->pdlg.hDevMode);
2647 memcpy(dm, pDevMode, pDevMode->dmSize + pDevMode->dmDriverExtra);
2649 PRINTDLG_CreateDevNames(&(pda->pdlg.hDevNames),
2650 lpDriverInfo->pDriverPath,
2651 lpPrinterInfo->pPrinterName,
2652 lpPrinterInfo->pPortName);
2654 GlobalUnlock(pda->pdlg.hDevMode);
2655 HeapFree(GetProcessHeap(), 0, pDevMode);
2656 HeapFree(GetProcessHeap(), 0, lpPrinterInfo);
2657 HeapFree(GetProcessHeap(), 0, lpDriverInfo);
2658 return TRUE;
2661 /****************************************************************************************
2662 * PRINTDLG_PS_ChangePrinterA
2664 * Fills Printers, Paper and Source combo
2666 * RETURNS
2667 * TRUE
2669 static BOOL
2670 PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
2671 DEVNAMES *dn;
2672 DEVMODEA *dm;
2673 LPSTR devname,portname;
2675 dn = GlobalLock(pda->pdlg.hDevNames);
2676 dm = GlobalLock(pda->pdlg.hDevMode);
2677 devname = ((char*)dn)+dn->wDeviceOffset;
2678 portname = ((char*)dn)+dn->wOutputOffset;
2679 PRINTDLG_SetUpPrinterListComboA(hDlg, cmb1, devname);
2680 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
2681 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
2682 GlobalUnlock(pda->pdlg.hDevNames);
2683 GlobalUnlock(pda->pdlg.hDevMode);
2684 return TRUE;
2687 static void PRINTDLG_PS_SetOrientationW(HWND hDlg, PageSetupDataW* pda)
2689 WCHAR PaperName[64];
2691 GetDlgItemTextW(hDlg, cmb2, PaperName, sizeof(PaperName)/sizeof(WCHAR));
2692 PRINTDLG_PaperSizeW(&pda->pdlg, PaperName, &pda->curdlg.ptPaperSize);
2693 pda->curdlg.ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga, pda->curdlg.ptPaperSize.x);
2694 pda->curdlg.ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pda->dlga, pda->curdlg.ptPaperSize.y);
2696 if(IsDlgButtonChecked(hDlg, rad2))
2698 DWORD tmp = pda->curdlg.ptPaperSize.x;
2699 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2700 pda->curdlg.ptPaperSize.y = tmp;
2704 static BOOL
2705 PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pda) {
2706 DEVNAMES *dn;
2707 DEVMODEW *dm;
2708 LPWSTR devname,portname;
2710 dn = GlobalLock(pda->pdlg.hDevNames);
2711 dm = GlobalLock(pda->pdlg.hDevMode);
2712 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2713 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2714 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2715 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2717 /* Landscape orientation */
2718 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE)
2719 CheckRadioButton(hDlg, rad1, rad2, rad2);
2720 else /* this is default if papersize is not set */
2721 CheckRadioButton(hDlg, rad1, rad2, rad1);
2723 GlobalUnlock(pda->pdlg.hDevNames);
2724 GlobalUnlock(pda->pdlg.hDevMode);
2726 PRINTDLG_PS_SetOrientationW(hDlg, pda);
2728 return TRUE;
2731 /******************************************************************************************
2732 * PRINTDLG_PS_ChangePaperPrev
2734 * Changes paper preview size / position
2736 * PARAMS:
2737 * pda [i] Pointer for current PageSetupDataA structure
2739 * RETURNS:
2740 * always - TRUE
2742 static BOOL
2743 PRINTDLG_PS_ChangePaperPrev(const PageSetupDataA *pda)
2745 LONG width, height, x, y;
2746 RECT rtTmp;
2748 if(pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y) {
2749 width = pda->rtDrawRect.right - pda->rtDrawRect.left;
2750 height = pda->curdlg.ptPaperSize.y * width / pda->curdlg.ptPaperSize.x;
2751 } else {
2752 height = pda->rtDrawRect.bottom - pda->rtDrawRect.top;
2753 width = pda->curdlg.ptPaperSize.x * height / pda->curdlg.ptPaperSize.y;
2755 x = (pda->rtDrawRect.right + pda->rtDrawRect.left - width) / 2;
2756 y = (pda->rtDrawRect.bottom + pda->rtDrawRect.top - height) / 2;
2757 TRACE("rtDrawRect(%d, %d, %d, %d) x=%d, y=%d, w=%d, h=%d\n",
2758 pda->rtDrawRect.left, pda->rtDrawRect.top, pda->rtDrawRect.right, pda->rtDrawRect.bottom,
2759 x, y, width, height);
2761 #define SHADOW 4
2762 MoveWindow(GetDlgItem(pda->hDlg, rct2), x+width, y+SHADOW, SHADOW, height, FALSE);
2763 MoveWindow(GetDlgItem(pda->hDlg, rct3), x+SHADOW, y+height, width, SHADOW, FALSE);
2764 MoveWindow(GetDlgItem(pda->hDlg, rct1), x, y, width, height, FALSE);
2765 memcpy(&rtTmp, &pda->rtDrawRect, sizeof(RECT));
2766 rtTmp.right += SHADOW;
2767 rtTmp.bottom += SHADOW;
2768 #undef SHADOW
2770 InvalidateRect(pda->hDlg, &rtTmp, TRUE);
2771 return TRUE;
2774 #define GETVAL(idc,val) \
2775 if(msg == EN_CHANGE){ \
2776 if (GetDlgItemTextA(hDlg,idc,buf,sizeof(buf)) > 0)\
2777 val = _c_str2sizeA(pda->dlga,buf); \
2778 else\
2779 FIXME("could not get dlgitemtexta for %x\n",id); \
2782 /********************************************************************************
2783 * PRINTDLG_PS_WMCommandA
2784 * process WM_COMMAND message for PageSetupDlgA
2786 * PARAMS
2787 * hDlg [in] Main dialog HANDLE
2788 * wParam [in] WM_COMMAND wParam
2789 * lParam [in] WM_COMMAND lParam
2790 * pda [in/out] ptr to PageSetupDataA
2793 static BOOL
2794 PRINTDLG_PS_WMCommandA(
2795 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
2797 WORD msg = HIWORD(wParam);
2798 WORD id = LOWORD(wParam);
2799 char buf[200];
2801 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
2802 LOWORD(lParam),wParam,lParam);
2803 switch (id) {
2804 case IDOK:
2805 if (!PRINTDLG_PS_UpdateDlgStructA(hDlg, pda))
2806 return(FALSE);
2807 EndDialog(hDlg, TRUE);
2808 return TRUE ;
2810 case IDCANCEL:
2811 EndDialog(hDlg, FALSE);
2812 return FALSE ;
2814 case psh3: {
2815 pda->pdlg.Flags = 0;
2816 pda->pdlg.hwndOwner = hDlg;
2817 if (PrintDlgA(&(pda->pdlg)))
2818 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
2820 return TRUE;
2821 case rad1:
2822 case rad2:
2823 if((id == rad1 && pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y) ||
2824 (id == rad2 && pda->curdlg.ptPaperSize.y > pda->curdlg.ptPaperSize.x))
2826 char TmpText[25];
2827 char TmpText2[25];
2828 DWORD tmp = pda->curdlg.ptPaperSize.x;
2830 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2831 pda->curdlg.ptPaperSize.y = tmp;
2833 GetDlgItemTextA(hDlg, edt4, TmpText, sizeof(TmpText));
2834 GetDlgItemTextA(hDlg, edt5, TmpText2, sizeof(TmpText2));
2835 SetDlgItemTextA(hDlg, edt5, TmpText);
2836 SetDlgItemTextA(hDlg, edt4, TmpText2);
2838 GetDlgItemTextA(hDlg, edt6, TmpText, sizeof(TmpText));
2839 GetDlgItemTextA(hDlg, edt7, TmpText2, sizeof(TmpText2));
2840 SetDlgItemTextA(hDlg, edt7, TmpText);
2841 SetDlgItemTextA(hDlg, edt6, TmpText2);
2843 PRINTDLG_PS_ChangePaperPrev(pda);
2845 break;
2846 case cmb1: /* Printer combo */
2847 if(msg == CBN_SELCHANGE){
2848 char crPrinterName[256];
2849 GetDlgItemTextA(hDlg, id, crPrinterName, 255);
2850 PRINTDLG_PS_ChangeActivePrinterA(crPrinterName, pda);
2851 PRINTDLG_PS_ChangePrinterA(hDlg, pda);
2853 break;
2854 case cmb2: /* Paper combo */
2855 if(msg == CBN_SELCHANGE){
2856 DWORD paperword = SendDlgItemMessageA(hDlg,cmb2,CB_GETITEMDATA,
2857 SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0), 0);
2858 if (paperword != CB_ERR) {
2859 PRINTDLG_PaperSizeA(&(pda->pdlg), paperword,&(pda->curdlg.ptPaperSize));
2860 pda->curdlg.ptPaperSize.x = _c_10mm2size(pda->dlga,pda->curdlg.ptPaperSize.x);
2861 pda->curdlg.ptPaperSize.y = _c_10mm2size(pda->dlga,pda->curdlg.ptPaperSize.y);
2863 if (IsDlgButtonChecked(hDlg, rad2)) {
2864 DWORD tmp = pda->curdlg.ptPaperSize.x;
2865 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2866 pda->curdlg.ptPaperSize.y = tmp;
2868 PRINTDLG_PS_ChangePaperPrev(pda);
2869 } else
2870 FIXME("could not get dialog text for papersize cmbbox?\n");
2872 break;
2873 case cmb3:
2874 if(msg == CBN_SELCHANGE){
2875 DEVMODEA *dm = GlobalLock(pda->pdlg.hDevMode);
2876 dm->u1.s1.dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,CB_GETITEMDATA,
2877 SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0), 0);
2878 GlobalUnlock(pda->pdlg.hDevMode);
2880 break;
2881 case psh2: /* Printer Properties button */
2883 HANDLE hPrinter;
2884 char PrinterName[256];
2885 DEVMODEA *dm;
2886 LRESULT count;
2887 int i;
2889 GetDlgItemTextA(hDlg, cmb1, PrinterName, 255);
2890 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
2891 FIXME("Call to OpenPrinter did not succeed!\n");
2892 break;
2894 dm = GlobalLock(pda->pdlg.hDevMode);
2895 DocumentPropertiesA(hDlg, hPrinter, PrinterName, dm, dm,
2896 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
2897 ClosePrinter(hPrinter);
2898 /* Changing paper */
2899 PRINTDLG_PaperSizeA(&(pda->pdlg), dm->u1.s1.dmPaperSize, &(pda->curdlg.ptPaperSize));
2900 pda->curdlg.ptPaperSize.x = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.x);
2901 pda->curdlg.ptPaperSize.y = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.y);
2902 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE){
2903 DWORD tmp = pda->curdlg.ptPaperSize.x;
2904 pda->curdlg.ptPaperSize.x = pda->curdlg.ptPaperSize.y;
2905 pda->curdlg.ptPaperSize.y = tmp;
2906 CheckRadioButton(hDlg, rad1, rad2, rad2);
2908 else
2909 CheckRadioButton(hDlg, rad1, rad2, rad1);
2910 /* Changing paper preview */
2911 PRINTDLG_PS_ChangePaperPrev(pda);
2912 /* Selecting paper in combo */
2913 count = SendDlgItemMessageA(hDlg, cmb2, CB_GETCOUNT, 0, 0);
2914 if(count != CB_ERR){
2915 for(i=0; i<count; ++i){
2916 if(SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0) == dm->u1.s1.dmPaperSize) {
2917 SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
2918 break;
2923 GlobalUnlock(pda->pdlg.hDevMode);
2924 break;
2926 case edt4:
2927 GETVAL(id, pda->curdlg.rtMargin.left);
2928 break;
2929 case edt5:
2930 GETVAL(id, pda->curdlg.rtMargin.top);
2931 break;
2932 case edt6:
2933 GETVAL(id, pda->curdlg.rtMargin.right);
2934 break;
2935 case edt7:
2936 GETVAL(id, pda->curdlg.rtMargin.bottom);
2937 break;
2939 InvalidateRect(GetDlgItem(hDlg, rct1), NULL, TRUE);
2940 return FALSE;
2942 #undef GETVAL
2944 static BOOL
2945 PRINTDLG_PS_WMCommandW(
2946 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pda
2948 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
2949 LOWORD(lParam),wParam,lParam);
2950 switch (LOWORD(wParam)) {
2951 case IDOK:
2952 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pda))
2953 return(FALSE);
2954 EndDialog(hDlg, TRUE);
2955 return TRUE ;
2957 case IDCANCEL:
2958 EndDialog(hDlg, FALSE);
2959 return FALSE ;
2961 case rad1:
2962 case rad2:
2963 if((LOWORD(wParam) == rad1 && pda->curdlg.ptPaperSize.x > pda->curdlg.ptPaperSize.y) ||
2964 (LOWORD(wParam) == rad2 && pda->curdlg.ptPaperSize.y > pda->curdlg.ptPaperSize.x))
2966 WCHAR tmpText[25];
2967 WCHAR tmpText2[25];
2968 DWORD tmp = pda->curdlg.ptPaperSize.y;
2970 pda->curdlg.ptPaperSize.y = pda->curdlg.ptPaperSize.x;
2971 pda->curdlg.ptPaperSize.x = tmp;
2973 GetDlgItemTextW(hDlg, edt4, tmpText, sizeof(tmpText)/sizeof(WCHAR));
2974 GetDlgItemTextW(hDlg, edt5, tmpText2, sizeof(tmpText2)/sizeof(WCHAR));
2975 SetDlgItemTextW(hDlg, edt5, tmpText);
2976 SetDlgItemTextW(hDlg, edt4, tmpText2);
2978 GetDlgItemTextW(hDlg, edt6, tmpText, sizeof(tmpText)/sizeof(WCHAR));
2979 GetDlgItemTextW(hDlg, edt7, tmpText2, sizeof(tmpText2)/sizeof(WCHAR));
2980 SetDlgItemTextW(hDlg, edt7, tmpText);
2981 SetDlgItemTextW(hDlg, edt6, tmpText2);
2983 break;
2985 case psh3: {
2986 pda->pdlg.Flags = 0;
2987 pda->pdlg.hwndOwner = hDlg;
2988 if (PrintDlgW(&(pda->pdlg)))
2989 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
2990 return TRUE;
2993 return FALSE;
2997 /***********************************************************************
2998 * DefaultPagePaintHook
2999 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3000 * whenever the sample page is redrawn.
3003 static UINT_PTR
3004 PRINTDLG_DefaultPagePaintHook(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam,
3005 const PageSetupDataA *pda)
3007 LPRECT lprc = (LPRECT) lParam;
3008 HDC hdc = (HDC) wParam;
3009 HPEN hpen, holdpen;
3010 LOGFONTW lf;
3011 HFONT hfont, holdfont;
3012 INT oldbkmode;
3013 TRACE("uMsg: WM_USER+%d\n",uMsg-WM_USER);
3014 /* Call user paint hook if enable */
3015 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK)
3016 if (pda->dlga->lpfnPagePaintHook(hwndDlg, uMsg, wParam, lParam))
3017 return TRUE;
3019 switch (uMsg) {
3020 /* LPPAGESETUPDLG in lParam */
3021 case WM_PSD_PAGESETUPDLG:
3022 /* Inform about the sample page rectangle */
3023 case WM_PSD_FULLPAGERECT:
3024 /* Inform about the margin rectangle */
3025 case WM_PSD_MINMARGINRECT:
3026 return FALSE;
3028 /* Draw dashed rectangle showing margins */
3029 case WM_PSD_MARGINRECT:
3030 hpen = CreatePen(PS_DASH, 1, GetSysColor(COLOR_3DSHADOW));
3031 holdpen = SelectObject(hdc, hpen);
3032 Rectangle(hdc, lprc->left, lprc->top, lprc->right, lprc->bottom);
3033 DeleteObject(SelectObject(hdc, holdpen));
3034 return TRUE;
3035 /* Draw the fake document */
3036 case WM_PSD_GREEKTEXTRECT:
3037 /* select a nice scalable font, because we want the text really small */
3038 SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);
3039 lf.lfHeight = 6; /* value chosen based on visual effect */
3040 hfont = CreateFontIndirectW(&lf);
3041 holdfont = SelectObject(hdc, hfont);
3043 /* if text not loaded, then do so now */
3044 if (wszFakeDocumentText[0] == '\0')
3045 LoadStringW(COMDLG32_hInstance,
3046 IDS_FAKEDOCTEXT,
3047 wszFakeDocumentText,
3048 sizeof(wszFakeDocumentText)/sizeof(wszFakeDocumentText[0]));
3050 oldbkmode = SetBkMode(hdc, TRANSPARENT);
3051 DrawTextW(hdc, wszFakeDocumentText, -1, lprc, DT_TOP|DT_LEFT|DT_NOPREFIX|DT_WORDBREAK);
3052 SetBkMode(hdc, oldbkmode);
3054 DeleteObject(SelectObject(hdc, holdfont));
3055 return TRUE;
3057 /* Envelope stamp */
3058 case WM_PSD_ENVSTAMPRECT:
3059 /* Return address */
3060 case WM_PSD_YAFULLPAGERECT:
3061 FIXME("envelope/stamp is not implemented\n");
3062 return FALSE;
3063 default:
3064 FIXME("Unknown message %x\n",uMsg);
3065 return FALSE;
3067 return TRUE;
3070 /***********************************************************************
3071 * PagePaintProc
3072 * The main paint procedure for the PageSetupDlg function.
3073 * The Page Setup dialog box includes an image of a sample page that shows how
3074 * the user's selections affect the appearance of the printed output.
3075 * The image consists of a rectangle that represents the selected paper
3076 * or envelope type, with a dotted-line rectangle representing
3077 * the current margins, and partial (Greek text) characters
3078 * to show how text looks on the printed page.
3080 * The following messages in the order sends to user hook procedure:
3081 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3082 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3083 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3084 * WM_PSD_MARGINRECT Draw the margin rectangle
3085 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3086 * If any of first three messages returns TRUE, painting done.
3088 * PARAMS:
3089 * hWnd [in] Handle to the Page Setup dialog box
3090 * uMsg [in] Received message
3092 * TODO:
3093 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3094 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3096 * RETURNS:
3097 * FALSE if all done correctly
3102 static LRESULT CALLBACK
3103 PRINTDLG_PagePaintProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3105 PAINTSTRUCT ps;
3106 RECT rcClient, rcMargin;
3107 HPEN hpen, holdpen;
3108 HDC hdc;
3109 HBRUSH hbrush, holdbrush;
3110 PageSetupDataA *pda;
3111 int papersize=0, orientation=0; /* FIXME: set this values for user paint hook */
3112 double scalx, scaly;
3113 #define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, pda)
3115 if (uMsg != WM_PAINT)
3116 return CallWindowProcA(lpfnStaticWndProc, hWnd, uMsg, wParam, lParam);
3118 /* Processing WM_PAINT message */
3119 pda = (PageSetupDataA*)GetPropA(hWnd, "__WINE_PAGESETUPDLGDATA");
3120 if (!pda) {
3121 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3122 return FALSE;
3124 if (PRINTDLG_DefaultPagePaintHook(hWnd, WM_PSD_PAGESETUPDLG, MAKELONG(papersize, orientation), (LPARAM)pda->dlga, pda))
3125 return FALSE;
3127 hdc = BeginPaint(hWnd, &ps);
3128 GetClientRect(hWnd, &rcClient);
3130 scalx = rcClient.right / (double)pda->curdlg.ptPaperSize.x;
3131 scaly = rcClient.bottom / (double)pda->curdlg.ptPaperSize.y;
3132 rcMargin = rcClient;
3134 rcMargin.left += pda->curdlg.rtMargin.left * scalx;
3135 rcMargin.top += pda->curdlg.rtMargin.top * scalx;
3136 rcMargin.right -= pda->curdlg.rtMargin.right * scaly;
3137 rcMargin.bottom -= pda->curdlg.rtMargin.bottom * scaly;
3139 /* if the space is too small then we make sure to not draw anything */
3140 rcMargin.left = min(rcMargin.left, rcMargin.right);
3141 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3143 if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT, &rcClient) &&
3144 !CALLPAINTHOOK(WM_PSD_MINMARGINRECT, &rcMargin) )
3146 /* fill background */
3147 hbrush = GetSysColorBrush(COLOR_3DHIGHLIGHT);
3148 FillRect(hdc, &rcClient, hbrush);
3149 holdbrush = SelectObject(hdc, hbrush);
3151 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
3152 holdpen = SelectObject(hdc, hpen);
3154 /* paint left edge */
3155 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3156 LineTo(hdc, rcClient.left, rcClient.bottom-1);
3158 /* paint top edge */
3159 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3160 LineTo(hdc, rcClient.right, rcClient.top);
3162 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW));
3163 DeleteObject(SelectObject(hdc, hpen));
3165 /* paint right edge */
3166 MoveToEx(hdc, rcClient.right-1, rcClient.top, NULL);
3167 LineTo(hdc, rcClient.right-1, rcClient.bottom);
3169 /* paint bottom edge */
3170 MoveToEx(hdc, rcClient.left, rcClient.bottom-1, NULL);
3171 LineTo(hdc, rcClient.right, rcClient.bottom-1);
3173 DeleteObject(SelectObject(hdc, holdpen));
3174 DeleteObject(SelectObject(hdc, holdbrush));
3176 CALLPAINTHOOK(WM_PSD_MARGINRECT, &rcMargin);
3178 /* give text a bit of a space from the frame */
3179 rcMargin.left += 2;
3180 rcMargin.top += 2;
3181 rcMargin.right -= 2;
3182 rcMargin.bottom -= 2;
3184 /* if the space is too small then we make sure to not draw anything */
3185 rcMargin.left = min(rcMargin.left, rcMargin.right);
3186 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3188 CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT, &rcMargin);
3191 EndPaint(hWnd, &ps);
3192 return FALSE;
3193 #undef CALLPAINTHOOK
3196 /***********************************************************************
3197 * PRINTDLG_PageDlgProcA
3198 * Message handler for PageSetupDlgA
3200 static INT_PTR CALLBACK
3201 PRINTDLG_PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3203 DEVMODEA *dm;
3204 PageSetupDataA *pda;
3205 INT_PTR res = FALSE;
3206 HWND hDrawWnd;
3208 if (uMsg == WM_INITDIALOG) { /*Init dialog*/
3209 pda = (PageSetupDataA*)lParam;
3210 pda->hDlg = hDlg; /* saving handle to main window to PageSetupDataA structure */
3211 memcpy(&pda->curdlg, pda->dlga, sizeof(pda->curdlg));
3213 hDrawWnd = GetDlgItem(hDlg, rct1);
3214 TRACE("set property to %p\n", pda);
3215 SetPropA(hDlg, "__WINE_PAGESETUPDLGDATA", pda);
3216 SetPropA(hDrawWnd, "__WINE_PAGESETUPDLGDATA", pda);
3217 GetWindowRect(hDrawWnd, &pda->rtDrawRect); /* Calculating rect in client coordinates where paper draws */
3218 ScreenToClient(hDlg, (LPPOINT)&pda->rtDrawRect);
3219 ScreenToClient(hDlg, (LPPOINT)(&pda->rtDrawRect.right));
3220 lpfnStaticWndProc = (WNDPROC)SetWindowLongPtrW(
3221 hDrawWnd,
3222 GWLP_WNDPROC,
3223 (ULONG_PTR)PRINTDLG_PagePaintProc);
3225 /* FIXME: Paint hook. Must it be at begin of initializtion or at end? */
3226 res = TRUE;
3227 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3228 if (!pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga))
3229 FIXME("Setup page hook failed?\n");
3232 /* if printer button disabled */
3233 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3234 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3235 /* if margin edit boxes disabled */
3236 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3237 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3238 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3239 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3240 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3242 /* Set orientation radiobutton properly */
3243 if(pda->dlga->hDevMode)
3245 dm = GlobalLock(pda->dlga->hDevMode);
3246 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE)
3247 CheckRadioButton(hDlg, rad1, rad2, rad2);
3248 else /* this is default if papersize is not set */
3249 CheckRadioButton(hDlg, rad1, rad2, rad1);
3250 GlobalUnlock(pda->dlga->hDevMode);
3253 /* if orientation disabled */
3254 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3255 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3256 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3258 /* We fill them out enabled or not */
3259 if (pda->dlga->Flags & PSD_MARGINS) {
3260 char str[100];
3261 _c_size2strA(pda,pda->dlga->rtMargin.left,str);
3262 SetDlgItemTextA(hDlg,edt4,str);
3263 _c_size2strA(pda,pda->dlga->rtMargin.top,str);
3264 SetDlgItemTextA(hDlg,edt5,str);
3265 _c_size2strA(pda,pda->dlga->rtMargin.right,str);
3266 SetDlgItemTextA(hDlg,edt6,str);
3267 _c_size2strA(pda,pda->dlga->rtMargin.bottom,str);
3268 SetDlgItemTextA(hDlg,edt7,str);
3269 } else {
3270 /* default is 1 inch */
3271 DWORD size = _c_inch2size(pda->dlga,1000);
3272 char str[20];
3273 _c_size2strA(pda,size,str);
3274 SetDlgItemTextA(hDlg,edt4,str);
3275 SetDlgItemTextA(hDlg,edt5,str);
3276 SetDlgItemTextA(hDlg,edt6,str);
3277 SetDlgItemTextA(hDlg,edt7,str);
3278 pda->curdlg.rtMargin.left = size;
3279 pda->curdlg.rtMargin.top = size;
3280 pda->curdlg.rtMargin.right = size;
3281 pda->curdlg.rtMargin.bottom = size;
3283 /* if paper disabled */
3284 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3285 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3286 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3288 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3289 PRINTDLG_PS_ChangePrinterA(hDlg, pda);
3290 dm = GlobalLock(pda->pdlg.hDevMode);
3291 if(dm){
3292 dm->u1.s1.dmDefaultSource = 15; /*FIXME: Automatic select. Does it always 15 at start? */
3293 PRINTDLG_PaperSizeA(&(pda->pdlg), dm->u1.s1.dmPaperSize, &pda->curdlg.ptPaperSize);
3294 GlobalUnlock(pda->pdlg.hDevMode);
3295 pda->curdlg.ptPaperSize.x = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.x);
3296 pda->curdlg.ptPaperSize.y = _c_10mm2size(pda->dlga, pda->curdlg.ptPaperSize.y);
3297 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) { /* Landscape orientation */
3298 DWORD tmp = pda->curdlg.ptPaperSize.y;
3299 pda->curdlg.ptPaperSize.y = pda->curdlg.ptPaperSize.x;
3300 pda->curdlg.ptPaperSize.x = tmp;
3302 } else
3303 WARN("GlobalLock(pda->pdlg.hDevMode) fail? hDevMode=%p\n", pda->pdlg.hDevMode);
3304 /* Drawing paper prev */
3305 PRINTDLG_PS_ChangePaperPrev(pda);
3306 return TRUE;
3307 } else {
3308 pda = (PageSetupDataA*)GetPropA(hDlg,"__WINE_PAGESETUPDLGDATA");
3309 if (!pda) {
3310 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3311 return FALSE;
3313 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3314 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3315 if (res) return res;
3318 switch (uMsg) {
3319 case WM_COMMAND:
3320 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
3322 return FALSE;
3325 static INT_PTR CALLBACK
3326 PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3328 static const WCHAR __WINE_PAGESETUPDLGDATA[] =
3329 { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
3330 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
3331 PageSetupDataW *pda;
3332 BOOL res = FALSE;
3334 if (uMsg==WM_INITDIALOG) {
3335 res = TRUE;
3336 pda = (PageSetupDataW*)lParam;
3337 memcpy(&pda->curdlg, pda, sizeof(pda->curdlg));
3338 SetPropW(hDlg, __WINE_PAGESETUPDLGDATA, pda);
3339 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3340 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga);
3341 if (!res) {
3342 FIXME("Setup page hook failed?\n");
3343 res = TRUE;
3347 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3348 FIXME("PagePaintHook not yet implemented!\n");
3350 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3351 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3352 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3353 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3354 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3355 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3356 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3359 PRINTDLG_PS_ChangePrinterW(hDlg,pda);
3361 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3362 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3363 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3365 /* We fill them out enabled or not */
3366 if (pda->dlga->Flags & PSD_MARGINS) {
3367 WCHAR str[100];
3368 _c_size2strW(pda,pda->dlga->rtMargin.left,str);
3369 SetDlgItemTextW(hDlg,edt4,str);
3370 _c_size2strW(pda,pda->dlga->rtMargin.top,str);
3371 SetDlgItemTextW(hDlg,edt5,str);
3372 _c_size2strW(pda,pda->dlga->rtMargin.right,str);
3373 SetDlgItemTextW(hDlg,edt6,str);
3374 _c_size2strW(pda,pda->dlga->rtMargin.bottom,str);
3375 SetDlgItemTextW(hDlg,edt7,str);
3376 } else {
3377 /* default is 1 inch */
3378 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pda->dlga,1000);
3379 WCHAR str[20];
3380 _c_size2strW(pda,size,str);
3381 SetDlgItemTextW(hDlg,edt4,str);
3382 SetDlgItemTextW(hDlg,edt5,str);
3383 SetDlgItemTextW(hDlg,edt6,str);
3384 SetDlgItemTextW(hDlg,edt7,str);
3387 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3388 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3389 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3392 return TRUE;
3393 } else {
3394 pda = (PageSetupDataW*)GetPropW(hDlg, __WINE_PAGESETUPDLGDATA);
3395 if (!pda) {
3396 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3397 return FALSE;
3399 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3400 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3401 if (res) return res;
3404 switch (uMsg) {
3405 case WM_COMMAND:
3406 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pda);
3408 return FALSE;
3411 /***********************************************************************
3412 * PageSetupDlgA (COMDLG32.@)
3414 * Displays the PAGE SETUP dialog box, which enables the user to specify
3415 * specific properties of a printed page such as
3416 * size, source, orientation and the width of the page margins.
3418 * PARAMS
3419 * setupdlg [IO] PAGESETUPDLGA struct
3421 * RETURNS
3422 * TRUE if the user pressed the OK button
3423 * FALSE if the user cancelled the window or an error occurred
3425 * NOTES
3426 * The values of hDevMode and hDevNames are filled on output and can be
3427 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3431 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
3432 HGLOBAL hDlgTmpl;
3433 LPVOID ptr;
3434 BOOL bRet;
3435 PageSetupDataA *pda;
3436 PRINTDLGA pdlg;
3438 if (setupdlg == NULL) {
3439 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
3440 return FALSE;
3443 /* TRACE */
3444 if(TRACE_ON(commdlg)) {
3445 char flagstr[1000] = "";
3446 const struct pd_flags *pflag = psd_flags;
3447 for( ; pflag->name; pflag++) {
3448 if(setupdlg->Flags & pflag->flag) {
3449 strcat(flagstr, pflag->name);
3450 strcat(flagstr, "|");
3453 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3454 "hinst %p, flags %08x (%s)\n",
3455 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3456 setupdlg->hDevNames,
3457 setupdlg->hInstance, setupdlg->Flags, flagstr);
3460 /* Checking setupdlg structure */
3461 if(setupdlg->lStructSize != sizeof(PAGESETUPDLGA)) {
3462 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
3463 return FALSE;
3465 if ((setupdlg->Flags & PSD_ENABLEPAGEPAINTHOOK) &&
3466 (setupdlg->lpfnPagePaintHook == NULL)) {
3467 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK);
3468 return FALSE;
3471 /* Initialize default printer struct. If no printer device info is specified
3472 retrieve the default printer data. */
3473 memset(&pdlg,0,sizeof(pdlg));
3474 pdlg.lStructSize = sizeof(pdlg);
3475 if (setupdlg->hDevMode && setupdlg->hDevNames) {
3476 pdlg.hDevMode = setupdlg->hDevMode;
3477 pdlg.hDevNames = setupdlg->hDevNames;
3478 } else {
3479 pdlg.Flags = PD_RETURNDEFAULT;
3480 bRet = PrintDlgA(&pdlg);
3481 if (!bRet){
3482 if (!(setupdlg->Flags & PSD_NOWARNING)) {
3483 char errstr[256];
3484 LoadStringA(COMDLG32_hInstance, PD32_NO_DEFAULT_PRINTER, errstr, 255);
3485 MessageBoxA(setupdlg->hwndOwner, errstr, 0, MB_OK | MB_ICONERROR);
3487 return FALSE;
3491 /* short cut exit, just return default values */
3492 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3493 DEVMODEA *dm;
3495 setupdlg->hDevMode = pdlg.hDevMode;
3496 setupdlg->hDevNames = pdlg.hDevNames;
3497 dm = GlobalLock(pdlg.hDevMode);
3498 PRINTDLG_PaperSizeA(&pdlg, dm->u1.s1.dmPaperSize, &setupdlg->ptPaperSize);
3499 GlobalUnlock(pdlg.hDevMode);
3500 setupdlg->ptPaperSize.x=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.x);
3501 setupdlg->ptPaperSize.y=_c_10mm2size(setupdlg,setupdlg->ptPaperSize.y);
3502 return TRUE;
3505 /* get dialog template */
3506 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
3507 if (!hDlgTmpl) {
3508 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3509 return FALSE;
3511 ptr = LockResource( hDlgTmpl );
3512 if (!ptr) {
3513 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3514 return FALSE;
3517 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
3518 pda->dlga = setupdlg;
3519 memcpy(&pda->pdlg,&pdlg,sizeof(pdlg));
3521 bRet = (0<DialogBoxIndirectParamA(
3522 setupdlg->hInstance,
3523 ptr,
3524 setupdlg->hwndOwner,
3525 PRINTDLG_PageDlgProcA,
3526 (LPARAM)pda)
3529 HeapFree(GetProcessHeap(),0,pda);
3530 return bRet;
3532 /***********************************************************************
3533 * PageSetupDlgW (COMDLG32.@)
3535 * See PageSetupDlgA.
3537 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
3538 HGLOBAL hDlgTmpl;
3539 LPVOID ptr;
3540 BOOL bRet;
3541 PageSetupDataW *pdw;
3542 PRINTDLGW pdlg;
3544 FIXME("Unicode implementation is not done yet\n");
3546 if (setupdlg == NULL) {
3547 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
3548 return FALSE;
3551 if(TRACE_ON(commdlg)) {
3552 char flagstr[1000] = "";
3553 const struct pd_flags *pflag = psd_flags;
3554 for( ; pflag->name; pflag++) {
3555 if(setupdlg->Flags & pflag->flag) {
3556 strcat(flagstr, pflag->name);
3557 strcat(flagstr, "|");
3560 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3561 "hinst %p, flags %08x (%s)\n",
3562 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3563 setupdlg->hDevNames,
3564 setupdlg->hInstance, setupdlg->Flags, flagstr);
3567 /* Initialize default printer struct. If no printer device info is specified
3568 retrieve the default printer data. */
3569 memset(&pdlg,0,sizeof(pdlg));
3570 pdlg.lStructSize = sizeof(pdlg);
3571 if (setupdlg->hDevMode && setupdlg->hDevNames) {
3572 pdlg.hDevMode = setupdlg->hDevMode;
3573 pdlg.hDevNames = setupdlg->hDevNames;
3574 } else {
3575 pdlg.Flags = PD_RETURNDEFAULT;
3576 bRet = PrintDlgW(&pdlg);
3577 if (!bRet){
3578 if (!(setupdlg->Flags & PSD_NOWARNING)) {
3579 WCHAR errstr[256];
3580 LoadStringW(COMDLG32_hInstance, PD32_NO_DEFAULT_PRINTER, errstr, 255);
3581 MessageBoxW(setupdlg->hwndOwner, errstr, 0, MB_OK | MB_ICONERROR);
3583 return FALSE;
3587 /* short cut exit, just return default values */
3588 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3589 static const WCHAR a4[] = {'A','4',0};
3590 setupdlg->hDevMode = pdlg.hDevMode;
3591 setupdlg->hDevNames = pdlg.hDevNames;
3592 /* FIXME: Just return "A4" for now. */
3593 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
3594 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
3595 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
3596 return TRUE;
3598 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
3599 if (!hDlgTmpl) {
3600 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3601 return FALSE;
3603 ptr = LockResource( hDlgTmpl );
3604 if (!ptr) {
3605 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3606 return FALSE;
3608 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
3609 pdw->dlga = setupdlg;
3610 memcpy(&pdw->pdlg,&pdlg,sizeof(pdlg));
3612 bRet = (0<DialogBoxIndirectParamW(
3613 setupdlg->hInstance,
3614 ptr,
3615 setupdlg->hwndOwner,
3616 PageDlgProcW,
3617 (LPARAM)pdw)
3619 return bRet;
3622 /***********************************************************************
3623 * PrintDlgExA (COMDLG32.@)
3625 * See PrintDlgExW.
3627 * BUGS
3628 * Only a Stub
3631 HRESULT WINAPI PrintDlgExA(LPPRINTDLGEXA lppd)
3634 FIXME("(%p) stub\n", lppd);
3635 if ((lppd == NULL) || (lppd->lStructSize != sizeof(PRINTDLGEXA))) {
3636 return E_INVALIDARG;
3639 if (!IsWindow(lppd->hwndOwner)) {
3640 return E_HANDLE;
3643 return E_NOTIMPL;
3646 /***********************************************************************
3647 * PrintDlgExW (COMDLG32.@)
3649 * Display the property sheet style PRINT dialog box
3651 * PARAMS
3652 * lppd [IO] ptr to PRINTDLGEX struct
3654 * RETURNS
3655 * Success: S_OK
3656 * Failure: One of the following COM error codes:
3657 * E_OUTOFMEMORY Insufficient memory.
3658 * E_INVALIDARG One or more arguments are invalid.
3659 * E_POINTER Invalid pointer.
3660 * E_HANDLE Invalid handle.
3661 * E_FAIL Unspecified error.
3663 * NOTES
3664 * This Dialog enables the user to specify specific properties of the print job.
3665 * The property sheet can also have additional application-specific and
3666 * driver-specific property pages.
3668 * BUGS
3669 * Only a Stub
3672 HRESULT WINAPI PrintDlgExW(LPPRINTDLGEXW lppd)
3675 FIXME("(%p) stub\n", lppd);
3676 if ((lppd == NULL) || (lppd->lStructSize != sizeof(PRINTDLGEXW))) {
3677 return E_INVALIDARG;
3680 if (!IsWindow(lppd->hwndOwner)) {
3681 return E_HANDLE;
3684 return E_NOTIMPL;