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
16 #include "wine/wingdi16.h"
18 #include "wine/winuser16.h"
23 #include "debugtools.h"
29 DEFAULT_DEBUG_CHANNEL(commdlg);
34 /* This PRINTDLGA internal structure stores
35 * pointers to several throughout useful structures.
41 LPPRINTDLGA lpPrintDlg;
42 LPPRINTER_INFO_2A lpPrinterInfo;
44 HICON hCollateIcon; /* PrintDlg only */
45 HICON hNoCollateIcon; /* PrintDlg only */
46 HICON hPortraitIcon; /* PrintSetupDlg only */
47 HICON hLandscapeIcon; /* PrintSetupDlg only */
51 static struct pd_flags {
55 {PD_SELECTION, "PD_SELECTION "},
56 {PD_PAGENUMS, "PD_PAGENUMS "},
57 {PD_NOSELECTION, "PD_NOSELECTION "},
58 {PD_NOPAGENUMS, "PD_NOPAGENUMS "},
59 {PD_COLLATE, "PD_COLLATE "},
60 {PD_PRINTTOFILE, "PD_PRINTTOFILE "},
61 {PD_PRINTSETUP, "PD_PRINTSETUP "},
62 {PD_NOWARNING, "PD_NOWARNING "},
63 {PD_RETURNDC, "PD_RETURNDC "},
64 {PD_RETURNIC, "PD_RETURNIC "},
65 {PD_RETURNDEFAULT, "PD_RETURNDEFAULT "},
66 {PD_SHOWHELP, "PD_SHOWHELP "},
67 {PD_ENABLEPRINTHOOK, "PD_ENABLEPRINTHOOK "},
68 {PD_ENABLESETUPHOOK, "PD_ENABLESETUPHOOK "},
69 {PD_ENABLEPRINTTEMPLATE, "PD_ENABLEPRINTTEMPLATE "},
70 {PD_ENABLESETUPTEMPLATE, "PD_ENABLESETUPTEMPLATE "},
71 {PD_ENABLEPRINTTEMPLATEHANDLE, "PD_ENABLEPRINTTEMPLATEHANDLE "},
72 {PD_ENABLESETUPTEMPLATEHANDLE, "PD_ENABLESETUPTEMPLATEHANDLE "},
73 {PD_USEDEVMODECOPIES, "PD_USEDEVMODECOPIES[ANDCOLLATE] "},
74 {PD_DISABLEPRINTTOFILE, "PD_DISABLEPRINTTOFILE "},
75 {PD_HIDEPRINTTOFILE, "PD_HIDEPRINTTOFILE "},
76 {PD_NONETWORKBUTTON, "PD_NONETWORKBUTTON "},
81 /***********************************************************************
82 * PRINTDLG_GetDefaultPrinterName
84 * Returns the default printer name in buf.
85 * Even under WinNT/2000 default printer is retrieved via GetProfileString -
86 * these entries are mapped somewhere in the registry rather than win.ini.
88 * Returns TRUE on success else FALSE
90 static BOOL PRINTDLG_GetDefaultPrinterName(LPSTR buf, DWORD len)
94 if(!GetProfileStringA("windows", "device", "", buf, len))
96 if((ptr = strchr(buf, ',')) == NULL)
102 /***********************************************************************
103 * PRINTDLG_OpenDefaultPrinter
105 * Returns a winspool printer handle to the default printer in *hprn
106 * Caller must call ClosePrinter on the handle
108 * Returns TRUE on success else FALSE
110 static BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
113 if(!PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf)))
115 return OpenPrinterA(buf, hprn, NULL);
118 /***********************************************************************
119 * PRINTDLG_SetUpPrinterListCombo
121 * Initializes printer list combox.
122 * hDlg: HWND of dialog
123 * id: Control id of combo
124 * name: Name of printer to select
126 * Initializes combo with list of available printers. Selects printer 'name'
127 * If name is NULL or does not exist select the default printer.
129 * Returns number of printers added to list.
131 static INT PRINTDLG_SetUpPrinterListCombo(HWND hDlg, UINT id, LPCSTR name)
135 LPPRINTER_INFO_2A pi;
136 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
137 pi = HeapAlloc(GetProcessHeap(), 0, needed);
138 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
141 for(i = 0; i < num; i++) {
142 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
143 (LPARAM)pi[i].pPrinterName );
145 HeapFree(GetProcessHeap(), 0, pi);
147 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
148 (LPARAM)name)) == CB_ERR) {
151 TRACE("Can't find '%s' in printer list so trying to find default\n",
153 if(!PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf)))
155 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
157 TRACE("Can't find default printer in printer list\n");
159 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
163 /***********************************************************************
164 * PRINTDLG_CreateDevNames [internal]
167 * creates a DevNames structure.
169 * (NB. when we handle unicode the offsets will be in wchars).
171 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, char* DeviceDriverName,
172 char* DeviceName, char* OutputPort)
175 char* pDevNamesSpace;
177 LPDEVNAMES lpDevNames;
180 size = strlen(DeviceDriverName) + 1
181 + strlen(DeviceName) + 1
182 + strlen(OutputPort) + 1
186 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
188 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
192 pDevNamesSpace = GlobalLock(*hmem);
193 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
195 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
196 strcpy(pTempPtr, DeviceDriverName);
197 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
199 pTempPtr += strlen(DeviceDriverName) + 1;
200 strcpy(pTempPtr, DeviceName);
201 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
203 pTempPtr += strlen(DeviceName) + 1;
204 strcpy(pTempPtr, OutputPort);
205 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
207 PRINTDLG_GetDefaultPrinterName(buf, sizeof(buf));
208 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
213 /***********************************************************************
214 * PRINTDLG_UpdatePrintDlg [internal]
217 * updates the PrintDlg structure for returnvalues.
220 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
223 static BOOL PRINTDLG_UpdatePrintDlg(HWND hDlg,
224 PRINT_PTRA* PrintStructures)
226 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
227 PDEVMODEA lpdm = PrintStructures->lpDevMode;
228 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
231 if(!lpdm) return FALSE;
234 if(!(lppd->Flags & PD_PRINTSETUP)) {
235 /* check whether nFromPage and nToPage are within range defined by
236 * nMinPage and nMaxPage
238 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
241 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
242 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
243 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
244 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
245 char resourcestr[256];
247 LoadStringA(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
249 sprintf(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
250 LoadStringA(COMDLG32_hInstance, PD32_PRINT_TITLE,
252 MessageBoxA(hDlg, resultstr, resourcestr,
253 MB_OK | MB_ICONWARNING);
256 lppd->nFromPage = nFromPage;
257 lppd->nToPage = nToPage;
260 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
261 lppd->Flags |= PD_PRINTTOFILE;
262 pi->pPortName = "FILE:";
265 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
266 FIXME("Collate lppd not yet implemented as output\n");
269 /* set PD_Collate and nCopies */
270 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
271 /* The application doesn't support multiple copies or collate...
273 lppd->Flags &= ~PD_COLLATE;
275 /* if the printer driver supports it... store info there
276 * otherwise no collate & multiple copies !
278 if (lpdm->dmFields & DM_COLLATE)
280 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
281 if (lpdm->dmFields & DM_COPIES)
282 lpdm->dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
284 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
285 lppd->Flags |= PD_COLLATE;
287 lppd->Flags &= ~PD_COLLATE;
288 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
295 /************************************************************************
296 * PRINTDLG_SetUpPaperComboBox
298 * Initialize either the papersize or inputslot combos of the Printer Setup
299 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
300 * We also try to re-select the old selection.
302 static BOOL PRINTDLG_SetUpPaperComboBox(HWND hDlg,
315 int fwCapability_Names;
316 int fwCapability_Words;
318 TRACE(" Printer: %s, ComboID: %d\n",PrinterName,nIDComboBox);
320 /* query the dialog box for the current selected value */
321 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
323 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, Sel,
327 if (nIDComboBox == cmb2) {
329 fwCapability_Names = DC_PAPERNAMES;
330 fwCapability_Words = DC_PAPERS;
334 fwCapability_Names = DC_BINNAMES;
335 fwCapability_Words = DC_BINS;
338 /* for some printer drivers, DeviceCapabilities calls a VXD to obtain the
339 * paper settings. As Wine doesn't allow VXDs, this results in a crash.
341 WARN(" if your printer driver uses VXDs, expect a crash now!\n");
342 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
343 fwCapability_Names, NULL, dm);
344 if (NrOfEntries == 0)
345 WARN("no Name Entries found!\n");
347 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
349 ERR("Number of caps is different\n");
353 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*NamesSize);
354 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
355 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
356 fwCapability_Names, Names, dm);
357 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
358 fwCapability_Words, (LPSTR)Words, dm);
360 /* reset any current content in the combobox */
361 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
363 /* store new content */
364 for (i = 0; i < NrOfEntries; i++) {
365 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
366 (LPARAM)(&Names[i*NamesSize]) );
367 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
371 /* Look for old selection - can't do this is previous loop since
372 item order will change as more items are added */
374 for (i = 0; i < NrOfEntries; i++) {
375 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
381 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
383 HeapFree(GetProcessHeap(),0,Words);
384 HeapFree(GetProcessHeap(),0,Names);
388 /***********************************************************************
389 * PRINTDLG_UpdatePrinterInfoTexts [internal]
391 static void PRINTDLG_UpdatePrinterInfoTexts(HWND hDlg, LPPRINTER_INFO_2A pi)
394 char ResourceString[256];
400 /* add all status messages */
401 for (i = 0; i < 25; i++) {
402 if (pi->Status & (1<<i)) {
403 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
404 ResourceString, 255);
405 strcat(StatusMsg,ResourceString);
409 /* FIXME: status==ready must only be appended if really so.
410 but how to detect? */
411 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
412 ResourceString, 255);
413 strcat(StatusMsg,ResourceString);
415 SendDlgItemMessageA(hDlg, stc12, WM_SETTEXT, 0, (LPARAM)StatusMsg);
417 /* set all other printer info texts */
418 SendDlgItemMessageA(hDlg, stc11, WM_SETTEXT, 0, (LPARAM)pi->pDriverName);
419 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
420 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pLocation);
422 SendDlgItemMessageA(hDlg, stc14, WM_SETTEXT, 0,(LPARAM)pi->pPortName);
423 SendDlgItemMessageA(hDlg, stc13, WM_SETTEXT, 0, (LPARAM)pi->pComment);
427 /*******************************************************************
429 * PRINTDLG_ChangePrinter
432 static BOOL PRINTDLG_ChangePrinter(HWND hDlg, char *name,
433 PRINT_PTRA *PrintStructures)
435 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
436 LPDEVMODEA lpdm = NULL;
441 if(PrintStructures->lpPrinterInfo)
442 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
443 if(!OpenPrinterA(name, &hprn, NULL)) {
444 ERR("Can't open printer %s\n", name);
447 GetPrinterA(hprn, 2, NULL, 0, &needed);
448 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
449 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
453 PRINTDLG_UpdatePrinterInfoTexts(hDlg, PrintStructures->lpPrinterInfo);
455 if(PrintStructures->lpDevMode) {
456 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
457 PrintStructures->lpDevMode = NULL;
460 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
462 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
465 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
466 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
468 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
469 !strcmp(lpdm->dmDeviceName,
470 PrintStructures->lpDevMode->dmDeviceName)) {
471 /* Supplied devicemode matches current printer so try to use it */
472 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
473 DM_OUT_BUFFER | DM_IN_BUFFER);
476 GlobalUnlock(lppd->hDevMode);
478 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
480 if(!(lppd->Flags & PD_PRINTSETUP)) {
481 /* Print range (All/Range/Selection) */
482 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
483 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
484 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
485 if (lppd->Flags & PD_NOSELECTION)
486 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
488 if (lppd->Flags & PD_SELECTION)
489 CheckRadioButton(hDlg, rad1, rad3, rad2);
490 if (lppd->Flags & PD_NOPAGENUMS) {
491 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
492 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
493 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
494 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
495 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
497 if (lppd->Flags & PD_PAGENUMS)
498 CheckRadioButton(hDlg, rad1, rad3, rad3);
500 /* "All xxx pages"... */
502 char resourcestr[64];
504 LoadStringA(COMDLG32_hInstance, PD32_PRINT_ALL_X_PAGES,
506 sprintf(result,resourcestr,lppd->nMaxPage - lppd->nMinPage + 1);
507 SendDlgItemMessageA(hDlg, rad1, WM_SETTEXT, 0, (LPARAM) result);
512 * FIXME: The ico3 is not displayed for some reason. I don't know why.
514 if (lppd->Flags & PD_COLLATE) {
515 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
516 (LPARAM)PrintStructures->hCollateIcon);
517 CheckDlgButton(hDlg, chx2, 1);
519 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
520 (LPARAM)PrintStructures->hNoCollateIcon);
521 CheckDlgButton(hDlg, chx2, 0);
524 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
525 /* if printer doesn't support it: no Collate */
526 if (!(lpdm->dmFields & DM_COLLATE)) {
527 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
528 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
533 if (lppd->hDevMode == 0)
534 SetDlgItemInt(hDlg, edt3, lppd->nCopies, FALSE);
536 SetDlgItemInt(hDlg, edt3, lpdm->dmCopies, FALSE);
538 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
539 /* if printer doesn't support it: no nCopies */
540 if (!(lpdm->dmFields & DM_COPIES)) {
541 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
542 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
547 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
548 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
549 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
550 if (lppd->Flags & PD_HIDEPRINTTOFILE)
551 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
553 } else { /* PD_PRINTSETUP */
554 PRINTDLG_SetUpPaperComboBox(hDlg, cmb2,
555 PrintStructures->lpPrinterInfo->pPrinterName,
556 PrintStructures->lpPrinterInfo->pPortName,
558 PRINTDLG_SetUpPaperComboBox(hDlg, cmb3,
559 PrintStructures->lpPrinterInfo->pPrinterName,
560 PrintStructures->lpPrinterInfo->pPortName,
562 CheckRadioButton(hDlg, rad1, rad2,
563 (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT) ?
568 if ((lppd->Flags & PD_SHOWHELP)==0) {
569 /* hide if PD_SHOWHELP not specified */
570 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
576 /***********************************************************************
577 * PRINTDLG_WMInitDialog [internal]
579 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
580 PRINT_PTRA* PrintStructures)
582 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
586 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
588 /* load Collate ICONs */
589 PrintStructures->hCollateIcon =
590 LoadIconA(COMDLG32_hInstance, "PD32_COLLATE");
591 PrintStructures->hNoCollateIcon =
592 LoadIconA(COMDLG32_hInstance, "PD32_NOCOLLATE");
593 if(PrintStructures->hCollateIcon == 0 ||
594 PrintStructures->hNoCollateIcon == 0) {
595 ERR("no icon in resourcefile\n");
596 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
597 EndDialog(hDlg, FALSE);
600 /* load Paper Orientation ICON */
601 /* FIXME: not implemented yet */
604 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
605 * must be registered and the Help button must be shown.
607 if (lppd->Flags & PD_SHOWHELP) {
608 if((PrintStructures->HelpMessageID =
609 RegisterWindowMessageA(HELPMSGSTRING)) == 0) {
610 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
614 PrintStructures->HelpMessageID = 0;
616 /* FIXME: I allow more freedom than either Win95 or WinNT,
617 * which do not agree to what errors should be thrown or not
618 * in case nToPage or nFromPage is out-of-range.
620 if (lppd->nMaxPage < lppd->nMinPage)
621 lppd->nMaxPage = lppd->nMinPage;
622 if (lppd->nMinPage == lppd->nMaxPage)
623 lppd->Flags |= PD_NOPAGENUMS;
624 if (lppd->nToPage < lppd->nMinPage)
625 lppd->nToPage = lppd->nMinPage;
626 if (lppd->nToPage > lppd->nMaxPage)
627 lppd->nToPage = lppd->nMaxPage;
628 if (lppd->nFromPage < lppd->nMinPage)
629 lppd->nFromPage = lppd->nMinPage;
630 if (lppd->nFromPage > lppd->nMaxPage)
631 lppd->nFromPage = lppd->nMaxPage;
635 pdn = GlobalLock(lppd->hDevNames);
636 pdm = GlobalLock(lppd->hDevMode);
638 name = (char*)pdn + pdn->wDeviceOffset;
640 name = pdm->dmDeviceName;
641 PRINTDLG_SetUpPrinterListCombo(hDlg, comboID, name);
642 if(pdm) GlobalUnlock(lppd->hDevMode);
643 if(pdn) GlobalUnlock(lppd->hDevNames);
645 /* Now find selected printer and update rest of dlg */
646 name = HeapAlloc(GetProcessHeap(),0,256);
647 GetDlgItemTextA(hDlg, comboID, name, 255);
648 PRINTDLG_ChangePrinter(hDlg, name, PrintStructures);
649 HeapFree(GetProcessHeap(),0,name);
654 /***********************************************************************
655 * PRINTDLG_WMCommand [internal]
657 static LRESULT PRINTDLG_WMCommand(HWND hDlg, WPARAM wParam,
658 LPARAM lParam, PRINT_PTRA* PrintStructures)
660 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
661 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
662 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
664 switch (LOWORD(wParam)) {
666 TRACE(" OK button was hit\n");
667 if (PRINTDLG_UpdatePrintDlg(hDlg, PrintStructures)!=TRUE)
669 EndDialog(hDlg, TRUE);
673 TRACE(" CANCEL button was hit\n");
674 EndDialog(hDlg, FALSE);
678 TRACE(" HELP button was hit\n");
679 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
680 (WPARAM) hDlg, (LPARAM) lppd);
683 case chx2: /* collate pages checkbox */
684 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
685 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
686 (LPARAM)PrintStructures->hCollateIcon);
688 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
689 (LPARAM)PrintStructures->hNoCollateIcon);
691 case edt1: /* from page nr editbox */
692 case edt2: /* to page nr editbox */
693 if (HIWORD(wParam)==EN_CHANGE) {
696 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
697 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
698 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
699 CheckRadioButton(hDlg, rad1, rad3, rad3);
702 case psh2: /* Properties button */
705 char PrinterName[256];
707 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
708 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
709 WARN(" Call to OpenPrinter did not succeed!\n");
712 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
713 PrintStructures->lpDevMode,
714 PrintStructures->lpDevMode,
715 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
716 ClosePrinter(hPrinter);
721 case cmb4: /* Printer combobox */
722 if (HIWORD(wParam)==CBN_SELCHANGE) {
723 char PrinterName[256];
724 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
725 PRINTDLG_ChangePrinter(hDlg, PrinterName, PrintStructures);
729 case cmb2: /* Papersize */
731 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
733 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
741 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
743 lpdm->dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
752 /***********************************************************************
753 * PrintDlgProcA [internal]
755 BOOL WINAPI PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
758 PRINT_PTRA* PrintStructures;
761 if (uMsg!=WM_INITDIALOG) {
762 PrintStructures = (PRINT_PTRA*) GetWindowLongA(hDlg, DWL_USER);
763 if (!PrintStructures)
766 PrintStructures = (PRINT_PTRA*) lParam;
767 SetWindowLongA(hDlg, DWL_USER, lParam);
768 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
770 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
771 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg,
773 (LPARAM)PrintStructures->lpPrintDlg);
778 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
779 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam,
786 return PRINTDLG_WMCommand(hDlg, wParam, lParam, PrintStructures);
789 DestroyIcon(PrintStructures->hCollateIcon);
790 DestroyIcon(PrintStructures->hNoCollateIcon);
791 /* FIXME: don't forget to delete the paper orientation icons here! */
798 /************************************************************
800 * PRINTDLG_GetDlgTemplate
803 static HGLOBAL PRINTDLG_GetDlgTemplate(PRINTDLGA *lppd)
805 HGLOBAL hDlgTmpl, hResInfo;
807 if (lppd->Flags & PD_PRINTSETUP) {
808 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
809 hDlgTmpl = lppd->hSetupTemplate;
810 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
811 hResInfo = FindResourceA(lppd->hInstance,
812 lppd->lpSetupTemplateName, RT_DIALOGA);
813 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
815 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
817 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
820 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
821 hDlgTmpl = lppd->hPrintTemplate;
822 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
823 hResInfo = FindResourceA(lppd->hInstance,
824 lppd->lpPrintTemplateName,
826 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
828 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
830 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
836 /***********************************************************************
841 static BOOL PRINTDLG_CreateDC(LPPRINTDLGA lppd)
843 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
844 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
846 if(lppd->Flags & PD_RETURNDC) {
847 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
848 (char*)pdn + pdn->wDeviceOffset,
849 (char*)pdn + pdn->wOutputOffset,
851 } else if(lppd->Flags & PD_RETURNIC) {
852 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
853 (char*)pdn + pdn->wDeviceOffset,
854 (char*)pdn + pdn->wOutputOffset,
857 GlobalUnlock(lppd->hDevNames);
858 GlobalUnlock(lppd->hDevMode);
859 return lppd->hDC ? TRUE : FALSE;
862 /***********************************************************************
863 * PrintDlgA (COMDLG32.17)
865 * Displays the the PRINT dialog box, which enables the user to specify
866 * specific properties of the print job.
869 * nonzero if the user pressed the OK button
870 * zero if the user cancelled the window or an error occurred
874 * * The Collate Icons do not display, even though they are in the code.
875 * * The Properties Button(s) should call DocumentPropertiesA().
877 * * The Paper Orientation Icons are not implemented yet.
878 * * The Properties Button(s) should call DocumentPropertiesA().
879 * * Settings are not yet taken from a provided DevMode or
880 * default printer settings.
882 BOOL WINAPI PrintDlgA(
883 LPPRINTDLGA lppd /* ptr to PRINTDLG32 struct */
888 HINSTANCE hInst = GetWindowLongA( lppd->hwndOwner, GWL_HINSTANCE );
890 if(TRACE_ON(commdlg)) {
891 char flagstr[1000] = "";
892 struct pd_flags *pflag = pd_flags;
893 for( ; pflag->name; pflag++) {
894 if(lppd->Flags & pflag->flag)
895 strcat(flagstr, pflag->name);
897 TRACE("(%p): hwndOwner = %08x, hDevMode = %08x, hDevNames = %08x\n"
898 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %08x\n"
899 "flags %08lx (%s)\n",
900 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
901 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
902 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
905 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
906 WARN("structure size failure !!!\n");
907 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
911 if(lppd->Flags & PD_RETURNDEFAULT) {
912 PRINTER_INFO_2A *pbuf;
916 if(lppd->hDevMode || lppd->hDevNames) {
917 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
918 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
921 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
922 WARN("Can't find default printer\n");
923 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
927 GetPrinterA(hprn, 2, NULL, 0, &needed);
928 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
929 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
931 PRINTDLG_CreateDevNames(&(lppd->hDevNames), "winspool",
932 pbuf->pDevMode->dmDeviceName,
934 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
935 pbuf->pDevMode->dmDriverExtra);
936 ptr = GlobalLock(lppd->hDevMode);
937 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
938 pbuf->pDevMode->dmDriverExtra);
939 GlobalUnlock(lppd->hDevMode);
940 HeapFree(GetProcessHeap(), 0, pbuf);
944 PRINT_PTRA *PrintStructures;
946 /* load Dialog resources,
947 * depending on Flags indicates Print32 or Print32_setup dialog
949 hDlgTmpl = PRINTDLG_GetDlgTemplate(lppd);
950 if (!(hDlgTmpl) || !(ptr = LockResource( hDlgTmpl ))) {
951 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
954 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
956 PrintStructures->lpPrintDlg = lppd;
958 /* and create & process the dialog
960 bRet = DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
962 (LPARAM)PrintStructures);
965 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
966 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
968 if (lppd->hDevMode == 0) {
969 TRACE(" No hDevMode yet... Need to create my own\n");
970 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
971 lpdm->dmSize + lpdm->dmDriverExtra);
974 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
975 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
977 GlobalUnlock(lppd->hDevMode);
978 TRACE("Now got %d locks\n", locks);
981 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
982 lpdm->dmSize + lpdm->dmDriverExtra,
985 lpdmReturn = GlobalLock(lppd->hDevMode);
986 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
988 if (lppd->hDevNames != 0) {
990 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
991 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
993 GlobalUnlock(lppd->hDevNames);
996 PRINTDLG_CreateDevNames(&(lppd->hDevNames), "winspool",
997 lpdmReturn->dmDeviceName, pi->pPortName);
998 GlobalUnlock(lppd->hDevMode);
1000 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1001 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
1002 HeapFree(GetProcessHeap(), 0, PrintStructures);
1004 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
1005 bRet = PRINTDLG_CreateDC(lppd);
1007 TRACE("exit! (%d)\n", bRet);
1013 /***********************************************************************
1014 * PrintDlgW (COMDLG32.18)
1016 BOOL WINAPI PrintDlgW( LPPRINTDLGW printdlg )
1018 FIXME("A really empty stub\n" );
1022 /***********************************************************************
1027 /***********************************************************************
1028 * PageSetupDlgA (COMDLG32.15)
1030 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
1031 FIXME("(%p), stub!\n",setupdlg);
1034 /***********************************************************************
1035 * PageSetupDlgW (COMDLG32.16)
1037 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
1038 FIXME("(%p), stub!\n",setupdlg);
1042 /**********************************************************************
1047 /***********************************************************************
1048 * PrintDlgProc16 (COMMDLG.21)
1050 LRESULT WINAPI PrintDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1056 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
1057 ShowWindow16(hWnd, SW_SHOWNORMAL);
1063 EndDialog(hWnd, TRUE);
1066 EndDialog(hWnd, FALSE);
1075 /***********************************************************************
1076 * PrintSetupDlgProc16 (COMMDLG.22)
1078 LRESULT WINAPI PrintSetupDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
1084 TRACE("WM_INITDIALOG lParam=%08lX\n", lParam);
1085 ShowWindow16(hWnd, SW_SHOWNORMAL);
1090 EndDialog(hWnd, TRUE);
1093 EndDialog(hWnd, FALSE);
1102 /***********************************************************************
1103 * PrintDlg16 (COMMDLG.20)
1105 * Displays the the PRINT dialog box, which enables the user to specify
1106 * specific properties of the print job.
1109 * nonzero if the user pressed the OK button
1110 * zero if the user cancelled the window or an error occurred
1113 * * calls up to the 32-bit versions of the Dialogs, which look different
1114 * * Customizing is *not* implemented.
1116 BOOL16 WINAPI PrintDlg16( LPPRINTDLG16 lpPrint )
1123 memset(&Print32, 0, sizeof(Print32));
1124 Print32.lStructSize = sizeof(Print32);
1125 Print32.hwndOwner = lpPrint->hwndOwner;
1126 if(lpPrint->hDevMode) {
1127 size = GlobalSize16(lpPrint->hDevMode);
1128 Print32.hDevMode = GlobalAlloc(GMEM_MOVEABLE, size);
1129 ptr = GlobalLock(Print32.hDevMode);
1130 ptr16 = GlobalLock16(lpPrint->hDevMode);
1131 memcpy(ptr, ptr16, size);
1132 GlobalFree16(lpPrint->hDevMode);
1133 GlobalUnlock(Print32.hDevMode);
1135 Print32.hDevMode = 0;
1136 if(lpPrint->hDevNames) {
1137 size = GlobalSize16(lpPrint->hDevNames);
1138 Print32.hDevNames = GlobalAlloc(GMEM_MOVEABLE, size);
1139 ptr = GlobalLock(Print32.hDevNames);
1140 ptr16 = GlobalLock16(lpPrint->hDevNames);
1141 memcpy(ptr, ptr16, size);
1142 GlobalFree16(lpPrint->hDevNames);
1143 GlobalUnlock(Print32.hDevNames);
1145 Print32.hDevNames = 0;
1146 Print32.Flags = lpPrint->Flags;
1147 Print32.nFromPage = lpPrint->nFromPage;
1148 Print32.nToPage = lpPrint->nToPage;
1149 Print32.nMinPage = lpPrint->nMinPage;
1150 Print32.nMaxPage = lpPrint->nMaxPage;
1151 Print32.nCopies = lpPrint->nCopies;
1152 Print32.hInstance = lpPrint->hInstance;
1153 Print32.lCustData = lpPrint->lCustData;
1154 if(lpPrint->lpfnPrintHook) {
1155 FIXME("Need to allocate thunk\n");
1156 /* Print32.lpfnPrintHook = lpPrint->lpfnPrintHook;*/
1158 if(lpPrint->lpfnSetupHook) {
1159 FIXME("Need to allocate thunk\n");
1160 /* Print32.lpfnSetupHook = lpPrint->lpfnSetupHook;*/
1162 Print32.lpPrintTemplateName = PTR_SEG_TO_LIN(lpPrint->lpPrintTemplateName);
1163 Print32.lpSetupTemplateName = PTR_SEG_TO_LIN(lpPrint->lpSetupTemplateName);
1164 Print32.hPrintTemplate = lpPrint->hPrintTemplate;
1165 Print32.hSetupTemplate = lpPrint->hSetupTemplate;
1167 ret = PrintDlgA(&Print32);
1169 if(Print32.hDevMode) {
1170 size = GlobalSize(Print32.hDevMode);
1171 lpPrint->hDevMode = GlobalAlloc16(GMEM_MOVEABLE, size);
1172 ptr16 = GlobalLock16(lpPrint->hDevMode);
1173 ptr = GlobalLock(Print32.hDevMode);
1174 memcpy(ptr16, ptr, size);
1175 GlobalFree(Print32.hDevMode);
1176 GlobalUnlock16(lpPrint->hDevMode);
1178 lpPrint->hDevMode = 0;
1179 if(Print32.hDevNames) {
1180 size = GlobalSize(Print32.hDevNames);
1181 lpPrint->hDevNames = GlobalAlloc16(GMEM_MOVEABLE, size);
1182 ptr16 = GlobalLock16(lpPrint->hDevNames);
1183 ptr = GlobalLock(Print32.hDevNames);
1184 memcpy(ptr16, ptr, size);
1185 GlobalFree(Print32.hDevNames);
1186 GlobalUnlock16(lpPrint->hDevNames);
1188 lpPrint->hDevNames = 0;
1189 lpPrint->hDC = Print32.hDC;
1190 lpPrint->Flags = Print32.Flags;
1191 lpPrint->nFromPage = Print32.nFromPage;
1192 lpPrint->nToPage = Print32.nToPage;
1193 lpPrint->nCopies = Print32.nCopies;