push c6fcfc519a04d046be60ec60e33d075a2146cc03
[wine/hacks.git] / dlls / comdlg32 / printdlg.c
blob47c3b348f149929e153cc6bcd5762bd3e609690b
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];
78 static const WCHAR pd32_collateW[] = { 'P', 'D', '3', '2', '_', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
79 static const WCHAR pd32_nocollateW[] = { 'P', 'D', '3', '2', '_', 'N', 'O', 'C', 'O', 'L', 'L', 'A', 'T', 'E', 0 };
80 static const WCHAR pd32_portraitW[] = { 'P', 'D', '3', '2', '_', 'P', 'O', 'R', 'T', 'R', 'A', 'I', 'T', 0 };
81 static const WCHAR pd32_landscapeW[] = { 'P', 'D', '3', '2', '_', 'L', 'A', 'N', 'D', 'S', 'C', 'A', 'P', 'E', 0 };
82 static const WCHAR printdlg_prop[] = {'_','_','W','I','N','E','_','P','R','I','N','T','D','L','G','D','A','T','A',0};
83 static const WCHAR pagesetupdlg_prop[] = { '_', '_', 'W', 'I', 'N', 'E', '_', 'P', 'A', 'G', 'E',
84 'S', 'E', 'T', 'U', 'P', 'D', 'L', 'G', 'D', 'A', 'T', 'A', 0 };
86 /***********************************************************************
87 * PRINTDLG_OpenDefaultPrinter
89 * Returns a winspool printer handle to the default printer in *hprn
90 * Caller must call ClosePrinter on the handle
92 * Returns TRUE on success else FALSE
94 BOOL PRINTDLG_OpenDefaultPrinter(HANDLE *hprn)
96 WCHAR buf[260];
97 DWORD dwBufLen = sizeof(buf) / sizeof(buf[0]);
98 BOOL res;
99 if(!GetDefaultPrinterW(buf, &dwBufLen))
100 return FALSE;
101 res = OpenPrinterW(buf, hprn, NULL);
102 if (!res)
103 WARN("Could not open printer %s\n", debugstr_w(buf));
104 return res;
107 /***********************************************************************
108 * PRINTDLG_SetUpPrinterListCombo
110 * Initializes printer list combox.
111 * hDlg: HWND of dialog
112 * id: Control id of combo
113 * name: Name of printer to select
115 * Initializes combo with list of available printers. Selects printer 'name'
116 * If name is NULL or does not exist select the default printer.
118 * Returns number of printers added to list.
120 INT PRINTDLG_SetUpPrinterListComboA(HWND hDlg, UINT id, LPCSTR name)
122 DWORD needed, num;
123 INT i;
124 LPPRINTER_INFO_2A pi;
125 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
126 pi = HeapAlloc(GetProcessHeap(), 0, needed);
127 EnumPrintersA(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
128 &num);
130 SendDlgItemMessageA(hDlg, id, CB_RESETCONTENT, 0, 0);
132 for(i = 0; i < num; i++) {
133 SendDlgItemMessageA(hDlg, id, CB_ADDSTRING, 0,
134 (LPARAM)pi[i].pPrinterName );
136 HeapFree(GetProcessHeap(), 0, pi);
137 if(!name ||
138 (i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1,
139 (LPARAM)name)) == CB_ERR) {
141 char buf[260];
142 DWORD dwBufLen = sizeof(buf);
143 if (name != NULL)
144 WARN("Can't find %s in printer list so trying to find default\n",
145 debugstr_a(name));
146 if(!GetDefaultPrinterA(buf, &dwBufLen))
147 return num;
148 i = SendDlgItemMessageA(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
149 if(i == CB_ERR)
150 FIXME("Can't find default printer in printer list\n");
152 SendDlgItemMessageA(hDlg, id, CB_SETCURSEL, i, 0);
153 return num;
156 static INT PRINTDLG_SetUpPrinterListComboW(HWND hDlg, UINT id, LPCWSTR name)
158 DWORD needed, num;
159 INT i;
160 LPPRINTER_INFO_2W pi;
161 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
162 pi = HeapAlloc(GetProcessHeap(), 0, needed);
163 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, (LPBYTE)pi, needed, &needed,
164 &num);
166 for(i = 0; i < num; i++) {
167 SendDlgItemMessageW(hDlg, id, CB_ADDSTRING, 0,
168 (LPARAM)pi[i].pPrinterName );
170 HeapFree(GetProcessHeap(), 0, pi);
171 if(!name ||
172 (i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1,
173 (LPARAM)name)) == CB_ERR) {
174 WCHAR buf[260];
175 DWORD dwBufLen = sizeof(buf)/sizeof(buf[0]);
176 if (name != NULL)
177 WARN("Can't find %s in printer list so trying to find default\n",
178 debugstr_w(name));
179 if(!GetDefaultPrinterW(buf, &dwBufLen))
180 return num;
181 i = SendDlgItemMessageW(hDlg, id, CB_FINDSTRINGEXACT, -1, (LPARAM)buf);
182 if(i == CB_ERR)
183 TRACE("Can't find default printer in printer list\n");
185 SendDlgItemMessageW(hDlg, id, CB_SETCURSEL, i, 0);
186 return num;
189 /***********************************************************************
190 * PRINTDLG_CreateDevNames [internal]
193 * creates a DevNames structure.
195 * (NB. when we handle unicode the offsets will be in wchars).
197 static BOOL PRINTDLG_CreateDevNames(HGLOBAL *hmem, const char* DeviceDriverName,
198 const char* DeviceName, const char* OutputPort)
200 long size;
201 char* pDevNamesSpace;
202 char* pTempPtr;
203 LPDEVNAMES lpDevNames;
204 char buf[260];
205 DWORD dwBufLen = sizeof(buf);
207 size = strlen(DeviceDriverName) + 1
208 + strlen(DeviceName) + 1
209 + strlen(OutputPort) + 1
210 + sizeof(DEVNAMES);
212 if(*hmem)
213 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
214 else
215 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
216 if (*hmem == 0)
217 return FALSE;
219 pDevNamesSpace = GlobalLock(*hmem);
220 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
222 pTempPtr = pDevNamesSpace + sizeof(DEVNAMES);
223 strcpy(pTempPtr, DeviceDriverName);
224 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
226 pTempPtr += strlen(DeviceDriverName) + 1;
227 strcpy(pTempPtr, DeviceName);
228 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
230 pTempPtr += strlen(DeviceName) + 1;
231 strcpy(pTempPtr, OutputPort);
232 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
234 GetDefaultPrinterA(buf, &dwBufLen);
235 lpDevNames->wDefault = (strcmp(buf, DeviceName) == 0) ? 1 : 0;
236 GlobalUnlock(*hmem);
237 return TRUE;
240 static BOOL PRINTDLG_CreateDevNamesW(HGLOBAL *hmem, LPCWSTR DeviceDriverName,
241 LPCWSTR DeviceName, LPCWSTR OutputPort)
243 long size;
244 LPWSTR pDevNamesSpace;
245 LPWSTR pTempPtr;
246 LPDEVNAMES lpDevNames;
247 WCHAR bufW[260];
248 DWORD dwBufLen = sizeof(bufW) / sizeof(WCHAR);
250 size = sizeof(WCHAR)*lstrlenW(DeviceDriverName) + 2
251 + sizeof(WCHAR)*lstrlenW(DeviceName) + 2
252 + sizeof(WCHAR)*lstrlenW(OutputPort) + 2
253 + sizeof(DEVNAMES);
255 if(*hmem)
256 *hmem = GlobalReAlloc(*hmem, size, GMEM_MOVEABLE);
257 else
258 *hmem = GlobalAlloc(GMEM_MOVEABLE, size);
259 if (*hmem == 0)
260 return FALSE;
262 pDevNamesSpace = GlobalLock(*hmem);
263 lpDevNames = (LPDEVNAMES) pDevNamesSpace;
265 pTempPtr = (LPWSTR)((LPDEVNAMES)pDevNamesSpace + 1);
266 lstrcpyW(pTempPtr, DeviceDriverName);
267 lpDevNames->wDriverOffset = pTempPtr - pDevNamesSpace;
269 pTempPtr += lstrlenW(DeviceDriverName) + 1;
270 lstrcpyW(pTempPtr, DeviceName);
271 lpDevNames->wDeviceOffset = pTempPtr - pDevNamesSpace;
273 pTempPtr += lstrlenW(DeviceName) + 1;
274 lstrcpyW(pTempPtr, OutputPort);
275 lpDevNames->wOutputOffset = pTempPtr - pDevNamesSpace;
277 GetDefaultPrinterW(bufW, &dwBufLen);
278 lpDevNames->wDefault = (lstrcmpW(bufW, DeviceName) == 0) ? 1 : 0;
279 GlobalUnlock(*hmem);
280 return TRUE;
283 /***********************************************************************
284 * PRINTDLG_UpdatePrintDlg [internal]
287 * updates the PrintDlg structure for return values.
289 * RETURNS
290 * FALSE if user is not allowed to close (i.e. wrong nTo or nFrom values)
291 * TRUE if successful.
293 static BOOL PRINTDLG_UpdatePrintDlgA(HWND hDlg,
294 PRINT_PTRA* PrintStructures)
296 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
297 PDEVMODEA lpdm = PrintStructures->lpDevMode;
298 LPPRINTER_INFO_2A pi = PrintStructures->lpPrinterInfo;
301 if(!lpdm) {
302 FIXME("No lpdm ptr?\n");
303 return FALSE;
307 if(!(lppd->Flags & PD_PRINTSETUP)) {
308 /* check whether nFromPage and nToPage are within range defined by
309 * nMinPage and nMaxPage
311 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
312 WORD nToPage;
313 WORD nFromPage;
314 BOOL translated;
315 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
316 nToPage = GetDlgItemInt(hDlg, edt2, &translated, FALSE);
318 /* if no ToPage value is entered, use the FromPage value */
319 if(!translated) nToPage = nFromPage;
321 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
322 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
323 WCHAR resourcestr[256];
324 WCHAR resultstr[256];
325 LoadStringW(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE, resourcestr, 255);
326 wsprintfW(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
327 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE, resourcestr, 255);
328 MessageBoxW(hDlg, resultstr, resourcestr, MB_OK | MB_ICONWARNING);
329 return FALSE;
331 lppd->nFromPage = nFromPage;
332 lppd->nToPage = nToPage;
333 lppd->Flags |= PD_PAGENUMS;
335 else
336 lppd->Flags &= ~PD_PAGENUMS;
338 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) /* Selection */
339 lppd->Flags |= PD_SELECTION;
340 else
341 lppd->Flags &= ~PD_SELECTION;
343 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
344 static char file[] = "FILE:";
345 lppd->Flags |= PD_PRINTTOFILE;
346 pi->pPortName = file;
349 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
350 FIXME("Collate lppd not yet implemented as output\n");
353 /* set PD_Collate and nCopies */
354 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
355 /* The application doesn't support multiple copies or collate...
357 lppd->Flags &= ~PD_COLLATE;
358 lppd->nCopies = 1;
359 /* if the printer driver supports it... store info there
360 * otherwise no collate & multiple copies !
362 if (lpdm->dmFields & DM_COLLATE)
363 lpdm->dmCollate =
364 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
365 if (lpdm->dmFields & DM_COPIES)
366 lpdm->u1.s1.dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
367 } else {
368 /* Application is responsible for multiple copies */
369 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
370 lppd->Flags |= PD_COLLATE;
371 else
372 lppd->Flags &= ~PD_COLLATE;
373 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
374 /* multiple copies already included in the document. Driver must print only one copy */
375 lpdm->u1.s1.dmCopies = 1;
378 /* Print quality, PrintDlg16 */
379 if(GetDlgItem(hDlg, cmb1))
381 HWND hQuality = GetDlgItem(hDlg, cmb1);
382 int Sel = SendMessageA(hQuality, CB_GETCURSEL, 0, 0);
384 if(Sel != CB_ERR)
386 LONG dpi = SendMessageA(hQuality, CB_GETITEMDATA, Sel, 0);
387 lpdm->dmFields |= DM_PRINTQUALITY | DM_YRESOLUTION;
388 lpdm->u1.s1.dmPrintQuality = LOWORD(dpi);
389 lpdm->dmYResolution = HIWORD(dpi);
393 return TRUE;
396 static BOOL PRINTDLG_UpdatePrintDlgW(HWND hDlg,
397 PRINT_PTRW* PrintStructures)
399 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
400 PDEVMODEW lpdm = PrintStructures->lpDevMode;
401 LPPRINTER_INFO_2W pi = PrintStructures->lpPrinterInfo;
404 if(!lpdm) {
405 FIXME("No lpdm ptr?\n");
406 return FALSE;
410 if(!(lppd->Flags & PD_PRINTSETUP)) {
411 /* check whether nFromPage and nToPage are within range defined by
412 * nMinPage and nMaxPage
414 if (IsDlgButtonChecked(hDlg, rad3) == BST_CHECKED) { /* Pages */
415 WORD nToPage;
416 WORD nFromPage;
417 BOOL translated;
418 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
419 nToPage = GetDlgItemInt(hDlg, edt2, &translated, FALSE);
421 /* if no ToPage value is entered, use the FromPage value */
422 if(!translated) nToPage = nFromPage;
424 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
425 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage) {
426 WCHAR resourcestr[256];
427 WCHAR resultstr[256];
428 LoadStringW(COMDLG32_hInstance, PD32_INVALID_PAGE_RANGE,
429 resourcestr, 255);
430 wsprintfW(resultstr,resourcestr, lppd->nMinPage, lppd->nMaxPage);
431 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,
432 resourcestr, 255);
433 MessageBoxW(hDlg, resultstr, resourcestr,
434 MB_OK | MB_ICONWARNING);
435 return FALSE;
437 lppd->nFromPage = nFromPage;
438 lppd->nToPage = nToPage;
439 lppd->Flags |= PD_PAGENUMS;
441 else
442 lppd->Flags &= ~PD_PAGENUMS;
444 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) /* Selection */
445 lppd->Flags |= PD_SELECTION;
446 else
447 lppd->Flags &= ~PD_SELECTION;
449 if (IsDlgButtonChecked(hDlg, chx1) == BST_CHECKED) {/* Print to file */
450 static WCHAR file[] = {'F','I','L','E',':',0};
451 lppd->Flags |= PD_PRINTTOFILE;
452 pi->pPortName = file;
455 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED) { /* Collate */
456 FIXME("Collate lppd not yet implemented as output\n");
459 /* set PD_Collate and nCopies */
460 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
461 /* The application doesn't support multiple copies or collate...
463 lppd->Flags &= ~PD_COLLATE;
464 lppd->nCopies = 1;
465 /* if the printer driver supports it... store info there
466 * otherwise no collate & multiple copies !
468 if (lpdm->dmFields & DM_COLLATE)
469 lpdm->dmCollate =
470 (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED);
471 if (lpdm->dmFields & DM_COPIES)
472 lpdm->u1.s1.dmCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
473 } else {
474 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
475 lppd->Flags |= PD_COLLATE;
476 else
477 lppd->Flags &= ~PD_COLLATE;
478 lppd->nCopies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
481 return TRUE;
484 static BOOL PRINTDLG_PaperSizeW(
485 PRINTDLGW *pdlga,const WCHAR *PaperSize,LPPOINT size
487 DEVNAMES *dn;
488 DEVMODEW *dm;
489 LPWSTR devname,portname;
490 int i;
491 INT NrOfEntries,ret;
492 WCHAR *Names = NULL;
493 POINT *points = NULL;
494 BOOL retval = FALSE;
496 dn = GlobalLock(pdlga->hDevNames);
497 dm = GlobalLock(pdlga->hDevMode);
498 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
499 portname = ((WCHAR*)dn)+dn->wOutputOffset;
502 NrOfEntries = DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,NULL,dm);
503 if (!NrOfEntries) {
504 FIXME("No papernames found for %s/%s\n",debugstr_w(devname),debugstr_w(portname));
505 goto out;
507 if (NrOfEntries == -1) {
508 ERR("Hmm ? DeviceCapabilities() DC_PAPERNAMES failed, ret -1 !\n");
509 goto out;
512 Names = HeapAlloc(GetProcessHeap(),0,sizeof(WCHAR)*NrOfEntries*64);
513 if (NrOfEntries != (ret=DeviceCapabilitiesW(devname,portname,DC_PAPERNAMES,Names,dm))) {
514 FIXME("Number of returned vals %d is not %d\n",NrOfEntries,ret);
515 goto out;
517 for (i=0;i<NrOfEntries;i++)
518 if (!lstrcmpW(PaperSize,Names+(64*i)))
519 break;
520 if (i==NrOfEntries) {
521 FIXME("Papersize %s not found in list?\n",debugstr_w(PaperSize));
522 goto out;
524 points = HeapAlloc(GetProcessHeap(),0,sizeof(points[0])*NrOfEntries);
525 if (NrOfEntries!=(ret=DeviceCapabilitiesW(devname,portname,DC_PAPERSIZE,(LPWSTR)points,dm))) {
526 FIXME("Number of returned sizes %d is not %d?\n",NrOfEntries,ret);
527 goto out;
529 /* this is _10ths_ of a millimeter */
530 size->x=points[i].x;
531 size->y=points[i].y;
532 retval = TRUE;
533 out:
534 GlobalUnlock(pdlga->hDevNames);
535 GlobalUnlock(pdlga->hDevMode);
536 HeapFree(GetProcessHeap(),0,Names);
537 HeapFree(GetProcessHeap(),0,points);
538 return retval;
542 /************************************************************************
543 * PRINTDLG_SetUpPaperComboBox
545 * Initialize either the papersize or inputslot combos of the Printer Setup
546 * dialog. We store the associated word (eg DMPAPER_A4) as the item data.
547 * We also try to re-select the old selection.
549 static BOOL PRINTDLG_SetUpPaperComboBoxA(HWND hDlg,
550 int nIDComboBox,
551 char* PrinterName,
552 char* PortName,
553 LPDEVMODEA dm)
555 int i;
556 int NrOfEntries;
557 char* Names;
558 WORD* Words;
559 DWORD Sel;
560 WORD oldWord = 0;
561 int NamesSize;
562 int fwCapability_Names;
563 int fwCapability_Words;
565 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",PrinterName,PortName,nIDComboBox);
567 /* query the dialog box for the current selected value */
568 Sel = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
569 if(Sel != CB_ERR) {
570 /* we enter here only if a different printer is selected after
571 * the Print Setup dialog is opened. The current settings are
572 * stored into the newly selected printer.
574 oldWord = SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA,
575 Sel, 0);
576 if (dm) {
577 if (nIDComboBox == cmb2)
578 dm->u1.s1.dmPaperSize = oldWord;
579 else
580 dm->u1.s1.dmDefaultSource = oldWord;
583 else {
584 /* we enter here only when the Print setup dialog is initially
585 * opened. In this case the settings are restored from when
586 * the dialog was last closed.
588 if (dm) {
589 if (nIDComboBox == cmb2)
590 oldWord = dm->u1.s1.dmPaperSize;
591 else
592 oldWord = dm->u1.s1.dmDefaultSource;
596 if (nIDComboBox == cmb2) {
597 NamesSize = 64;
598 fwCapability_Names = DC_PAPERNAMES;
599 fwCapability_Words = DC_PAPERS;
600 } else {
601 nIDComboBox = cmb3;
602 NamesSize = 24;
603 fwCapability_Names = DC_BINNAMES;
604 fwCapability_Words = DC_BINS;
607 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
608 fwCapability_Names, NULL, dm);
609 if (NrOfEntries == 0)
610 WARN("no Name Entries found!\n");
611 else if (NrOfEntries < 0)
612 return FALSE;
614 if(DeviceCapabilitiesA(PrinterName, PortName, fwCapability_Words, NULL, dm)
615 != NrOfEntries) {
616 ERR("Number of caps is different\n");
617 NrOfEntries = 0;
620 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(char)*NamesSize);
621 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
622 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
623 fwCapability_Names, Names, dm);
624 NrOfEntries = DeviceCapabilitiesA(PrinterName, PortName,
625 fwCapability_Words, (LPSTR)Words, dm);
627 /* reset any current content in the combobox */
628 SendDlgItemMessageA(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
630 /* store new content */
631 for (i = 0; i < NrOfEntries; i++) {
632 DWORD pos = SendDlgItemMessageA(hDlg, nIDComboBox, CB_ADDSTRING, 0,
633 (LPARAM)(&Names[i*NamesSize]) );
634 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
635 Words[i]);
638 /* Look for old selection - can't do this is previous loop since
639 item order will change as more items are added */
640 Sel = 0;
641 for (i = 0; i < NrOfEntries; i++) {
642 if(SendDlgItemMessageA(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
643 oldWord) {
644 Sel = i;
645 break;
648 SendDlgItemMessageA(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
650 HeapFree(GetProcessHeap(),0,Words);
651 HeapFree(GetProcessHeap(),0,Names);
652 return TRUE;
655 static BOOL PRINTDLG_SetUpPaperComboBoxW(HWND hDlg,
656 int nIDComboBox,
657 const WCHAR* PrinterName,
658 const WCHAR* PortName,
659 LPDEVMODEW dm)
661 int i;
662 int NrOfEntries;
663 WCHAR* Names;
664 WORD* Words;
665 DWORD Sel;
666 WORD oldWord = 0;
667 int NamesSize;
668 int fwCapability_Names;
669 int fwCapability_Words;
671 TRACE(" Printer: %s, Port: %s, ComboID: %d\n",debugstr_w(PrinterName),debugstr_w(PortName),nIDComboBox);
673 /* query the dialog box for the current selected value */
674 Sel = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETCURSEL, 0, 0);
675 if(Sel != CB_ERR) {
676 /* we enter here only if a different printer is selected after
677 * the Print Setup dialog is opened. The current settings are
678 * stored into the newly selected printer.
680 oldWord = SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA,
681 Sel, 0);
682 if (dm) {
683 if (nIDComboBox == cmb2)
684 dm->u1.s1.dmPaperSize = oldWord;
685 else
686 dm->u1.s1.dmDefaultSource = oldWord;
689 else {
690 /* we enter here only when the Print setup dialog is initially
691 * opened. In this case the settings are restored from when
692 * the dialog was last closed.
694 if (dm) {
695 if (nIDComboBox == cmb2)
696 oldWord = dm->u1.s1.dmPaperSize;
697 else
698 oldWord = dm->u1.s1.dmDefaultSource;
702 if (nIDComboBox == cmb2) {
703 NamesSize = 64;
704 fwCapability_Names = DC_PAPERNAMES;
705 fwCapability_Words = DC_PAPERS;
706 } else {
707 nIDComboBox = cmb3;
708 NamesSize = 24;
709 fwCapability_Names = DC_BINNAMES;
710 fwCapability_Words = DC_BINS;
713 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
714 fwCapability_Names, NULL, dm);
715 if (NrOfEntries == 0)
716 WARN("no Name Entries found!\n");
717 else if (NrOfEntries < 0)
718 return FALSE;
720 if(DeviceCapabilitiesW(PrinterName, PortName, fwCapability_Words, NULL, dm)
721 != NrOfEntries) {
722 ERR("Number of caps is different\n");
723 NrOfEntries = 0;
726 Names = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WCHAR)*NamesSize);
727 Words = HeapAlloc(GetProcessHeap(),0, NrOfEntries*sizeof(WORD));
728 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
729 fwCapability_Names, Names, dm);
730 NrOfEntries = DeviceCapabilitiesW(PrinterName, PortName,
731 fwCapability_Words, Words, dm);
733 /* reset any current content in the combobox */
734 SendDlgItemMessageW(hDlg, nIDComboBox, CB_RESETCONTENT, 0, 0);
736 /* store new content */
737 for (i = 0; i < NrOfEntries; i++) {
738 DWORD pos = SendDlgItemMessageW(hDlg, nIDComboBox, CB_ADDSTRING, 0,
739 (LPARAM)(&Names[i*NamesSize]) );
740 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETITEMDATA, pos,
741 Words[i]);
744 /* Look for old selection - can't do this is previous loop since
745 item order will change as more items are added */
746 Sel = 0;
747 for (i = 0; i < NrOfEntries; i++) {
748 if(SendDlgItemMessageW(hDlg, nIDComboBox, CB_GETITEMDATA, i, 0) ==
749 oldWord) {
750 Sel = i;
751 break;
754 SendDlgItemMessageW(hDlg, nIDComboBox, CB_SETCURSEL, Sel, 0);
756 HeapFree(GetProcessHeap(),0,Words);
757 HeapFree(GetProcessHeap(),0,Names);
758 return TRUE;
762 /***********************************************************************
763 * PRINTDLG_UpdatePrinterInfoTexts [internal]
765 static void PRINTDLG_UpdatePrinterInfoTextsA(HWND hDlg, const PRINTER_INFO_2A *pi)
767 char StatusMsg[256];
768 char ResourceString[256];
769 int i;
771 /* Status Message */
772 StatusMsg[0]='\0';
774 /* add all status messages */
775 for (i = 0; i < 25; i++) {
776 if (pi->Status & (1<<i)) {
777 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
778 ResourceString, 255);
779 strcat(StatusMsg,ResourceString);
782 /* append "ready" */
783 /* FIXME: status==ready must only be appended if really so.
784 but how to detect? */
785 LoadStringA(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
786 ResourceString, 255);
787 strcat(StatusMsg,ResourceString);
788 SetDlgItemTextA(hDlg, stc12, StatusMsg);
790 /* set all other printer info texts */
791 SetDlgItemTextA(hDlg, stc11, pi->pDriverName);
793 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
794 SetDlgItemTextA(hDlg, stc14, pi->pLocation);
795 else
796 SetDlgItemTextA(hDlg, stc14, pi->pPortName);
797 SetDlgItemTextA(hDlg, stc13, pi->pComment ? pi->pComment : "");
798 return;
801 static void PRINTDLG_UpdatePrinterInfoTextsW(HWND hDlg, const PRINTER_INFO_2W *pi)
803 WCHAR StatusMsg[256];
804 WCHAR ResourceString[256];
805 static const WCHAR emptyW[] = {0};
806 int i;
808 /* Status Message */
809 StatusMsg[0]='\0';
811 /* add all status messages */
812 for (i = 0; i < 25; i++) {
813 if (pi->Status & (1<<i)) {
814 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_PAUSED+i,
815 ResourceString, 255);
816 lstrcatW(StatusMsg,ResourceString);
819 /* append "ready" */
820 /* FIXME: status==ready must only be appended if really so.
821 but how to detect? */
822 LoadStringW(COMDLG32_hInstance, PD32_PRINTER_STATUS_READY,
823 ResourceString, 255);
824 lstrcatW(StatusMsg,ResourceString);
825 SetDlgItemTextW(hDlg, stc12, StatusMsg);
827 /* set all other printer info texts */
828 SetDlgItemTextW(hDlg, stc11, pi->pDriverName);
829 if (pi->pLocation != NULL && pi->pLocation[0] != '\0')
830 SetDlgItemTextW(hDlg, stc14, pi->pLocation);
831 else
832 SetDlgItemTextW(hDlg, stc14, pi->pPortName);
833 SetDlgItemTextW(hDlg, stc13, pi->pComment ? pi->pComment : emptyW);
837 /*******************************************************************
839 * PRINTDLG_ChangePrinter
842 BOOL PRINTDLG_ChangePrinterA(HWND hDlg, char *name,
843 PRINT_PTRA *PrintStructures)
845 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
846 LPDEVMODEA lpdm = NULL;
847 LONG dmSize;
848 DWORD needed;
849 HANDLE hprn;
851 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
852 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
853 if(!OpenPrinterA(name, &hprn, NULL)) {
854 ERR("Can't open printer %s\n", name);
855 return FALSE;
857 GetPrinterA(hprn, 2, NULL, 0, &needed);
858 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
859 GetPrinterA(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
860 &needed);
861 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
862 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
863 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
864 needed, &needed)) {
865 ERR("GetPrinterDriverA failed for %s, fix your config!\n",PrintStructures->lpPrinterInfo->pPrinterName);
866 return FALSE;
868 ClosePrinter(hprn);
870 PRINTDLG_UpdatePrinterInfoTextsA(hDlg, PrintStructures->lpPrinterInfo);
872 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
873 PrintStructures->lpDevMode = NULL;
875 dmSize = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
876 if(dmSize == -1) {
877 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
878 return FALSE;
880 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
881 dmSize = DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, NULL,
882 DM_OUT_BUFFER);
883 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
884 !lstrcmpA( (LPSTR) lpdm->dmDeviceName,
885 (LPSTR) PrintStructures->lpDevMode->dmDeviceName)) {
886 /* Supplied devicemode matches current printer so try to use it */
887 DocumentPropertiesA(0, 0, name, PrintStructures->lpDevMode, lpdm,
888 DM_OUT_BUFFER | DM_IN_BUFFER);
890 if(lpdm)
891 GlobalUnlock(lppd->hDevMode);
893 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
895 if(!(lppd->Flags & PD_PRINTSETUP)) {
896 /* Print range (All/Range/Selection) */
897 if(lppd->nFromPage != 0xffff)
898 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
899 if(lppd->nToPage != 0xffff)
900 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
902 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
903 if (lppd->Flags & PD_NOSELECTION)
904 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
905 else
906 if (lppd->Flags & PD_SELECTION)
907 CheckRadioButton(hDlg, rad1, rad3, rad2);
908 if (lppd->Flags & PD_NOPAGENUMS) {
909 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
910 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
911 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
912 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
913 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
914 } else {
915 if (lppd->Flags & PD_PAGENUMS)
916 CheckRadioButton(hDlg, rad1, rad3, rad3);
919 /* Collate pages
921 * FIXME: The ico3 is not displayed for some reason. I don't know why.
923 if (lppd->Flags & PD_COLLATE) {
924 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
925 (LPARAM)PrintStructures->hCollateIcon);
926 CheckDlgButton(hDlg, chx2, 1);
927 } else {
928 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
929 (LPARAM)PrintStructures->hNoCollateIcon);
930 CheckDlgButton(hDlg, chx2, 0);
933 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
934 /* if printer doesn't support it: no Collate */
935 if (!(lpdm->dmFields & DM_COLLATE)) {
936 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
937 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
941 /* nCopies */
943 INT copies;
944 if (lppd->hDevMode == 0)
945 copies = lppd->nCopies;
946 else
947 copies = lpdm->u1.s1.dmCopies;
948 if(copies == 0) copies = 1;
949 else if(copies < 0) copies = MAX_COPIES;
950 SetDlgItemInt(hDlg, edt3, copies, FALSE);
953 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
954 /* if printer doesn't support it: no nCopies */
955 if (!(lpdm->dmFields & DM_COPIES)) {
956 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
957 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
961 /* print to file */
962 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
963 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
964 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
965 if (lppd->Flags & PD_HIDEPRINTTOFILE)
966 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
968 /* Fill print quality combo, PrintDlg16 */
969 if(GetDlgItem(hDlg, cmb1))
971 DWORD numResolutions = DeviceCapabilitiesA(PrintStructures->lpPrinterInfo->pPrinterName,
972 PrintStructures->lpPrinterInfo->pPortName,
973 DC_ENUMRESOLUTIONS, NULL, lpdm);
975 if(numResolutions != -1)
977 HWND hQuality = GetDlgItem(hDlg, cmb1);
978 LONG* Resolutions;
979 char buf[255];
980 DWORD i;
981 int dpiX, dpiY;
982 HDC hPrinterDC = CreateDCA(PrintStructures->lpPrinterInfo->pDriverName,
983 PrintStructures->lpPrinterInfo->pPrinterName,
984 0, lpdm);
986 Resolutions = HeapAlloc(GetProcessHeap(), 0, numResolutions*sizeof(LONG)*2);
987 DeviceCapabilitiesA(PrintStructures->lpPrinterInfo->pPrinterName,
988 PrintStructures->lpPrinterInfo->pPortName,
989 DC_ENUMRESOLUTIONS, (LPSTR)Resolutions, lpdm);
991 dpiX = GetDeviceCaps(hPrinterDC, LOGPIXELSX);
992 dpiY = GetDeviceCaps(hPrinterDC, LOGPIXELSY);
993 DeleteDC(hPrinterDC);
995 SendMessageA(hQuality, CB_RESETCONTENT, 0, 0);
996 for(i = 0; i < (numResolutions * 2); i += 2)
998 BOOL IsDefault = FALSE;
999 LRESULT Index;
1001 if(Resolutions[i] == Resolutions[i+1])
1003 if(dpiX == Resolutions[i])
1004 IsDefault = TRUE;
1005 sprintf(buf, "%d dpi", Resolutions[i]);
1006 } else
1008 if(dpiX == Resolutions[i] && dpiY == Resolutions[i+1])
1009 IsDefault = TRUE;
1010 sprintf(buf, "%d dpi x %d dpi", Resolutions[i], Resolutions[i+1]);
1013 Index = SendMessageA(hQuality, CB_ADDSTRING, 0, (LPARAM)buf);
1015 if(IsDefault)
1016 SendMessageA(hQuality, CB_SETCURSEL, Index, 0);
1018 SendMessageA(hQuality, CB_SETITEMDATA, Index, MAKELONG(dpiX,dpiY));
1020 HeapFree(GetProcessHeap(), 0, Resolutions);
1023 } else { /* PD_PRINTSETUP */
1024 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1026 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb2,
1027 PrintStructures->lpPrinterInfo->pPrinterName,
1028 PrintStructures->lpPrinterInfo->pPortName,
1029 lpdm);
1030 PRINTDLG_SetUpPaperComboBoxA(hDlg, cmb3,
1031 PrintStructures->lpPrinterInfo->pPrinterName,
1032 PrintStructures->lpPrinterInfo->pPortName,
1033 lpdm);
1034 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1035 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1036 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1037 PrintStructures->hLandscapeIcon));
1041 /* help button */
1042 if ((lppd->Flags & PD_SHOWHELP)==0) {
1043 /* hide if PD_SHOWHELP not specified */
1044 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1046 return TRUE;
1049 static BOOL PRINTDLG_ChangePrinterW(HWND hDlg, WCHAR *name,
1050 PRINT_PTRW *PrintStructures)
1052 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1053 LPDEVMODEW lpdm = NULL;
1054 LONG dmSize;
1055 DWORD needed;
1056 HANDLE hprn;
1058 HeapFree(GetProcessHeap(),0, PrintStructures->lpPrinterInfo);
1059 HeapFree(GetProcessHeap(),0, PrintStructures->lpDriverInfo);
1060 if(!OpenPrinterW(name, &hprn, NULL)) {
1061 ERR("Can't open printer %s\n", debugstr_w(name));
1062 return FALSE;
1064 GetPrinterW(hprn, 2, NULL, 0, &needed);
1065 PrintStructures->lpPrinterInfo = HeapAlloc(GetProcessHeap(),0,needed);
1066 GetPrinterW(hprn, 2, (LPBYTE)PrintStructures->lpPrinterInfo, needed,
1067 &needed);
1068 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
1069 PrintStructures->lpDriverInfo = HeapAlloc(GetProcessHeap(),0,needed);
1070 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)PrintStructures->lpDriverInfo,
1071 needed, &needed)) {
1072 ERR("GetPrinterDriverA failed for %s, fix your config!\n",debugstr_w(PrintStructures->lpPrinterInfo->pPrinterName));
1073 return FALSE;
1075 ClosePrinter(hprn);
1077 PRINTDLG_UpdatePrinterInfoTextsW(hDlg, PrintStructures->lpPrinterInfo);
1079 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
1080 PrintStructures->lpDevMode = NULL;
1082 dmSize = DocumentPropertiesW(0, 0, name, NULL, NULL, 0);
1083 if(dmSize == -1) {
1084 ERR("DocumentProperties fails on %s\n", debugstr_w(name));
1085 return FALSE;
1087 PrintStructures->lpDevMode = HeapAlloc(GetProcessHeap(), 0, dmSize);
1088 dmSize = DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, NULL,
1089 DM_OUT_BUFFER);
1090 if(lppd->hDevMode && (lpdm = GlobalLock(lppd->hDevMode)) &&
1091 !lstrcmpW(lpdm->dmDeviceName,
1092 PrintStructures->lpDevMode->dmDeviceName)) {
1093 /* Supplied devicemode matches current printer so try to use it */
1094 DocumentPropertiesW(0, 0, name, PrintStructures->lpDevMode, lpdm,
1095 DM_OUT_BUFFER | DM_IN_BUFFER);
1097 if(lpdm)
1098 GlobalUnlock(lppd->hDevMode);
1100 lpdm = PrintStructures->lpDevMode; /* use this as a shortcut */
1102 if(!(lppd->Flags & PD_PRINTSETUP)) {
1103 /* Print range (All/Range/Selection) */
1104 if(lppd->nFromPage != 0xffff)
1105 SetDlgItemInt(hDlg, edt1, lppd->nFromPage, FALSE);
1106 if(lppd->nToPage != 0xffff)
1107 SetDlgItemInt(hDlg, edt2, lppd->nToPage, FALSE);
1109 CheckRadioButton(hDlg, rad1, rad3, rad1); /* default */
1110 if (lppd->Flags & PD_NOSELECTION)
1111 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
1112 else
1113 if (lppd->Flags & PD_SELECTION)
1114 CheckRadioButton(hDlg, rad1, rad3, rad2);
1115 if (lppd->Flags & PD_NOPAGENUMS) {
1116 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
1117 EnableWindow(GetDlgItem(hDlg, stc2),FALSE);
1118 EnableWindow(GetDlgItem(hDlg, edt1), FALSE);
1119 EnableWindow(GetDlgItem(hDlg, stc3),FALSE);
1120 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
1121 } else {
1122 if (lppd->Flags & PD_PAGENUMS)
1123 CheckRadioButton(hDlg, rad1, rad3, rad3);
1126 /* Collate pages
1128 * FIXME: The ico3 is not displayed for some reason. I don't know why.
1130 if (lppd->Flags & PD_COLLATE) {
1131 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1132 (LPARAM)PrintStructures->hCollateIcon);
1133 CheckDlgButton(hDlg, chx2, 1);
1134 } else {
1135 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1136 (LPARAM)PrintStructures->hNoCollateIcon);
1137 CheckDlgButton(hDlg, chx2, 0);
1140 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1141 /* if printer doesn't support it: no Collate */
1142 if (!(lpdm->dmFields & DM_COLLATE)) {
1143 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1144 EnableWindow(GetDlgItem(hDlg, ico3), FALSE);
1148 /* nCopies */
1150 INT copies;
1151 if (lppd->hDevMode == 0)
1152 copies = lppd->nCopies;
1153 else
1154 copies = lpdm->u1.s1.dmCopies;
1155 if(copies == 0) copies = 1;
1156 else if(copies < 0) copies = MAX_COPIES;
1157 SetDlgItemInt(hDlg, edt3, copies, FALSE);
1160 if (lppd->Flags & PD_USEDEVMODECOPIESANDCOLLATE) {
1161 /* if printer doesn't support it: no nCopies */
1162 if (!(lpdm->dmFields & DM_COPIES)) {
1163 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
1164 EnableWindow(GetDlgItem(hDlg, stc5), FALSE);
1168 /* print to file */
1169 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
1170 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
1171 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
1172 if (lppd->Flags & PD_HIDEPRINTTOFILE)
1173 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
1175 } else { /* PD_PRINTSETUP */
1176 BOOL bPortrait = (lpdm->u1.s1.dmOrientation == DMORIENT_PORTRAIT);
1178 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb2,
1179 PrintStructures->lpPrinterInfo->pPrinterName,
1180 PrintStructures->lpPrinterInfo->pPortName,
1181 lpdm);
1182 PRINTDLG_SetUpPaperComboBoxW(hDlg, cmb3,
1183 PrintStructures->lpPrinterInfo->pPrinterName,
1184 PrintStructures->lpPrinterInfo->pPortName,
1185 lpdm);
1186 CheckRadioButton(hDlg, rad1, rad2, bPortrait ? rad1: rad2);
1187 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1188 (LPARAM)(bPortrait ? PrintStructures->hPortraitIcon :
1189 PrintStructures->hLandscapeIcon));
1193 /* help button */
1194 if ((lppd->Flags & PD_SHOWHELP)==0) {
1195 /* hide if PD_SHOWHELP not specified */
1196 ShowWindow(GetDlgItem(hDlg, pshHelp), SW_HIDE);
1198 return TRUE;
1201 /***********************************************************************
1202 * check_printer_setup [internal]
1204 static LRESULT check_printer_setup(HWND hDlg)
1206 DWORD needed,num;
1207 WCHAR resourcestr[256],resultstr[256];
1209 EnumPrintersW(PRINTER_ENUM_LOCAL, NULL, 2, NULL, 0, &needed, &num);
1210 if(needed == 0)
1212 EnumPrintersW(PRINTER_ENUM_CONNECTIONS, NULL, 2, NULL, 0, &needed, &num);
1214 if(needed > 0)
1215 return TRUE;
1216 else
1218 LoadStringW(COMDLG32_hInstance, PD32_NO_DEVICES,resultstr, 255);
1219 LoadStringW(COMDLG32_hInstance, PD32_PRINT_TITLE,resourcestr, 255);
1220 MessageBoxW(hDlg, resultstr, resourcestr,MB_OK | MB_ICONWARNING);
1221 return FALSE;
1225 /***********************************************************************
1226 * PRINTDLG_WMInitDialog [internal]
1228 static LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam,
1229 PRINT_PTRA* PrintStructures)
1231 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1232 DEVNAMES *pdn;
1233 DEVMODEA *pdm;
1234 char *name = NULL;
1235 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1237 /* load Collate ICONs */
1238 /* We load these with LoadImage because they are not a standard
1239 size and we don't want them rescaled */
1240 PrintStructures->hCollateIcon =
1241 LoadImageA(COMDLG32_hInstance, "PD32_COLLATE", IMAGE_ICON, 0, 0, 0);
1242 PrintStructures->hNoCollateIcon =
1243 LoadImageA(COMDLG32_hInstance, "PD32_NOCOLLATE", IMAGE_ICON, 0, 0, 0);
1245 /* These can be done with LoadIcon */
1246 PrintStructures->hPortraitIcon =
1247 LoadIconA(COMDLG32_hInstance, "PD32_PORTRAIT");
1248 PrintStructures->hLandscapeIcon =
1249 LoadIconA(COMDLG32_hInstance, "PD32_LANDSCAPE");
1251 /* display the collate/no_collate icon */
1252 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1253 (LPARAM)PrintStructures->hNoCollateIcon);
1255 if(PrintStructures->hCollateIcon == 0 ||
1256 PrintStructures->hNoCollateIcon == 0 ||
1257 PrintStructures->hPortraitIcon == 0 ||
1258 PrintStructures->hLandscapeIcon == 0) {
1259 ERR("no icon in resourcefile\n");
1260 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1261 EndDialog(hDlg, FALSE);
1265 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1266 * must be registered and the Help button must be shown.
1268 if (lppd->Flags & PD_SHOWHELP) {
1269 if((PrintStructures->HelpMessageID =
1270 RegisterWindowMessageA(HELPMSGSTRINGA)) == 0) {
1271 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1272 return FALSE;
1274 } else
1275 PrintStructures->HelpMessageID = 0;
1277 if(!(lppd->Flags &PD_PRINTSETUP)) {
1278 PrintStructures->hwndUpDown =
1279 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1280 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1281 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1282 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1283 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1286 /* FIXME: I allow more freedom than either Win95 or WinNT,
1287 * which do not agree to what errors should be thrown or not
1288 * in case nToPage or nFromPage is out-of-range.
1290 if (lppd->nMaxPage < lppd->nMinPage)
1291 lppd->nMaxPage = lppd->nMinPage;
1292 if (lppd->nMinPage == lppd->nMaxPage)
1293 lppd->Flags |= PD_NOPAGENUMS;
1294 if (lppd->nToPage < lppd->nMinPage)
1295 lppd->nToPage = lppd->nMinPage;
1296 if (lppd->nToPage > lppd->nMaxPage)
1297 lppd->nToPage = lppd->nMaxPage;
1298 if (lppd->nFromPage < lppd->nMinPage)
1299 lppd->nFromPage = lppd->nMinPage;
1300 if (lppd->nFromPage > lppd->nMaxPage)
1301 lppd->nFromPage = lppd->nMaxPage;
1303 /* if we have the combo box, fill it */
1304 if (GetDlgItem(hDlg,comboID)) {
1305 /* Fill Combobox
1307 pdn = GlobalLock(lppd->hDevNames);
1308 pdm = GlobalLock(lppd->hDevMode);
1309 if(pdn)
1310 name = (char*)pdn + pdn->wDeviceOffset;
1311 else if(pdm)
1312 name = (char*)pdm->dmDeviceName;
1313 PRINTDLG_SetUpPrinterListComboA(hDlg, comboID, name);
1314 if(pdm) GlobalUnlock(lppd->hDevMode);
1315 if(pdn) GlobalUnlock(lppd->hDevNames);
1317 /* Now find selected printer and update rest of dlg */
1318 name = HeapAlloc(GetProcessHeap(),0,256);
1319 if (GetDlgItemTextA(hDlg, comboID, name, 255))
1320 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1321 HeapFree(GetProcessHeap(),0,name);
1322 } else {
1323 /* else use default printer */
1324 char name[200];
1325 DWORD dwBufLen = sizeof(name);
1326 BOOL ret = GetDefaultPrinterA(name, &dwBufLen);
1328 if (ret)
1329 PRINTDLG_ChangePrinterA(hDlg, name, PrintStructures);
1330 else
1331 FIXME("No default printer found, expect problems!\n");
1333 return TRUE;
1336 static LRESULT PRINTDLG_WMInitDialogW(HWND hDlg, WPARAM wParam,
1337 PRINT_PTRW* PrintStructures)
1339 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1340 DEVNAMES *pdn;
1341 DEVMODEW *pdm;
1342 WCHAR *name = NULL;
1343 UINT comboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1345 /* load Collate ICONs */
1346 /* We load these with LoadImage because they are not a standard
1347 size and we don't want them rescaled */
1348 PrintStructures->hCollateIcon =
1349 LoadImageW(COMDLG32_hInstance, pd32_collateW, IMAGE_ICON, 0, 0, 0);
1350 PrintStructures->hNoCollateIcon =
1351 LoadImageW(COMDLG32_hInstance, pd32_nocollateW, IMAGE_ICON, 0, 0, 0);
1353 /* These can be done with LoadIcon */
1354 PrintStructures->hPortraitIcon =
1355 LoadIconW(COMDLG32_hInstance, pd32_portraitW);
1356 PrintStructures->hLandscapeIcon =
1357 LoadIconW(COMDLG32_hInstance, pd32_landscapeW);
1359 /* display the collate/no_collate icon */
1360 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1361 (LPARAM)PrintStructures->hNoCollateIcon);
1363 if(PrintStructures->hCollateIcon == 0 ||
1364 PrintStructures->hNoCollateIcon == 0 ||
1365 PrintStructures->hPortraitIcon == 0 ||
1366 PrintStructures->hLandscapeIcon == 0) {
1367 ERR("no icon in resourcefile\n");
1368 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
1369 EndDialog(hDlg, FALSE);
1373 * if lppd->Flags PD_SHOWHELP is specified, a HELPMESGSTRING message
1374 * must be registered and the Help button must be shown.
1376 if (lppd->Flags & PD_SHOWHELP) {
1377 if((PrintStructures->HelpMessageID =
1378 RegisterWindowMessageW(HELPMSGSTRINGW)) == 0) {
1379 COMDLG32_SetCommDlgExtendedError(CDERR_REGISTERMSGFAIL);
1380 return FALSE;
1382 } else
1383 PrintStructures->HelpMessageID = 0;
1385 if(!(lppd->Flags &PD_PRINTSETUP)) {
1386 PrintStructures->hwndUpDown =
1387 CreateUpDownControl(WS_CHILD | WS_VISIBLE | WS_BORDER |
1388 UDS_NOTHOUSANDS | UDS_ARROWKEYS |
1389 UDS_ALIGNRIGHT | UDS_SETBUDDYINT, 0, 0, 0, 0,
1390 hDlg, UPDOWN_ID, COMDLG32_hInstance,
1391 GetDlgItem(hDlg, edt3), MAX_COPIES, 1, 1);
1394 /* FIXME: I allow more freedom than either Win95 or WinNT,
1395 * which do not agree to what errors should be thrown or not
1396 * in case nToPage or nFromPage is out-of-range.
1398 if (lppd->nMaxPage < lppd->nMinPage)
1399 lppd->nMaxPage = lppd->nMinPage;
1400 if (lppd->nMinPage == lppd->nMaxPage)
1401 lppd->Flags |= PD_NOPAGENUMS;
1402 if (lppd->nToPage < lppd->nMinPage)
1403 lppd->nToPage = lppd->nMinPage;
1404 if (lppd->nToPage > lppd->nMaxPage)
1405 lppd->nToPage = lppd->nMaxPage;
1406 if (lppd->nFromPage < lppd->nMinPage)
1407 lppd->nFromPage = lppd->nMinPage;
1408 if (lppd->nFromPage > lppd->nMaxPage)
1409 lppd->nFromPage = lppd->nMaxPage;
1411 /* if we have the combo box, fill it */
1412 if (GetDlgItem(hDlg,comboID)) {
1413 /* Fill Combobox
1415 pdn = GlobalLock(lppd->hDevNames);
1416 pdm = GlobalLock(lppd->hDevMode);
1417 if(pdn)
1418 name = (WCHAR*)pdn + pdn->wDeviceOffset;
1419 else if(pdm)
1420 name = pdm->dmDeviceName;
1421 PRINTDLG_SetUpPrinterListComboW(hDlg, comboID, name);
1422 if(pdm) GlobalUnlock(lppd->hDevMode);
1423 if(pdn) GlobalUnlock(lppd->hDevNames);
1425 /* Now find selected printer and update rest of dlg */
1426 /* ansi is ok here */
1427 name = HeapAlloc(GetProcessHeap(),0,256*sizeof(WCHAR));
1428 if (GetDlgItemTextW(hDlg, comboID, name, 255))
1429 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1430 HeapFree(GetProcessHeap(),0,name);
1431 } else {
1432 /* else use default printer */
1433 WCHAR name[200];
1434 DWORD dwBufLen = sizeof(name) / sizeof(WCHAR);
1435 BOOL ret = GetDefaultPrinterW(name, &dwBufLen);
1437 if (ret)
1438 PRINTDLG_ChangePrinterW(hDlg, name, PrintStructures);
1439 else
1440 FIXME("No default printer found, expect problems!\n");
1442 return TRUE;
1445 /***********************************************************************
1446 * PRINTDLG_WMCommand [internal]
1448 LRESULT PRINTDLG_WMCommandA(HWND hDlg, WPARAM wParam,
1449 LPARAM lParam, PRINT_PTRA* PrintStructures)
1451 LPPRINTDLGA lppd = PrintStructures->lpPrintDlg;
1452 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1453 LPDEVMODEA lpdm = PrintStructures->lpDevMode;
1455 switch (LOWORD(wParam)) {
1456 case IDOK:
1457 TRACE(" OK button was hit\n");
1458 if (!PRINTDLG_UpdatePrintDlgA(hDlg, PrintStructures)) {
1459 FIXME("Update printdlg was not successful!\n");
1460 return(FALSE);
1462 EndDialog(hDlg, TRUE);
1463 return(TRUE);
1465 case IDCANCEL:
1466 TRACE(" CANCEL button was hit\n");
1467 EndDialog(hDlg, FALSE);
1468 return(FALSE);
1470 case pshHelp:
1471 TRACE(" HELP button was hit\n");
1472 SendMessageA(lppd->hwndOwner, PrintStructures->HelpMessageID,
1473 (WPARAM) hDlg, (LPARAM) lppd);
1474 break;
1476 case chx2: /* collate pages checkbox */
1477 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1478 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1479 (LPARAM)PrintStructures->hCollateIcon);
1480 else
1481 SendDlgItemMessageA(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1482 (LPARAM)PrintStructures->hNoCollateIcon);
1483 break;
1484 case edt1: /* from page nr editbox */
1485 case edt2: /* to page nr editbox */
1486 if (HIWORD(wParam)==EN_CHANGE) {
1487 WORD nToPage;
1488 WORD nFromPage;
1489 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1490 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1491 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1492 CheckRadioButton(hDlg, rad1, rad3, rad3);
1494 break;
1496 case edt3:
1497 if(HIWORD(wParam) == EN_CHANGE) {
1498 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1499 if(copies <= 1)
1500 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1501 else
1502 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1504 break;
1506 #if 0
1507 case psh1: /* Print Setup */
1509 PRINTDLG16 pdlg;
1511 if (!PrintStructures->dlg.lpPrintDlg16) {
1512 FIXME("The 32bit print dialog does not have this button!?\n");
1513 break;
1516 memcpy(&pdlg,PrintStructures->dlg.lpPrintDlg16,sizeof(pdlg));
1517 pdlg.Flags |= PD_PRINTSETUP;
1518 pdlg.hwndOwner = HWND_16(hDlg);
1519 if (!PrintDlg16(&pdlg))
1520 break;
1522 break;
1523 #endif
1524 case psh2: /* Properties button */
1526 HANDLE hPrinter;
1527 char PrinterName[256];
1529 GetDlgItemTextA(hDlg, PrinterComboID, PrinterName, 255);
1530 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
1531 FIXME(" Call to OpenPrinter did not succeed!\n");
1532 break;
1534 DocumentPropertiesA(hDlg, hPrinter, PrinterName,
1535 PrintStructures->lpDevMode,
1536 PrintStructures->lpDevMode,
1537 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1538 ClosePrinter(hPrinter);
1539 break;
1542 case rad1: /* Paperorientation */
1543 if (lppd->Flags & PD_PRINTSETUP)
1545 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1546 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1547 (LPARAM)(PrintStructures->hPortraitIcon));
1549 break;
1551 case rad2: /* Paperorientation */
1552 if (lppd->Flags & PD_PRINTSETUP)
1554 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1555 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1556 (LPARAM)(PrintStructures->hLandscapeIcon));
1558 break;
1560 case cmb1: /* Printer Combobox in PRINT SETUP, quality combobox in PRINT16 */
1561 if (PrinterComboID != LOWORD(wParam)) {
1562 break;
1564 /* FALLTHROUGH */
1565 case cmb4: /* Printer combobox */
1566 if (HIWORD(wParam)==CBN_SELCHANGE) {
1567 char PrinterName[256];
1568 GetDlgItemTextA(hDlg, LOWORD(wParam), PrinterName, 255);
1569 PRINTDLG_ChangePrinterA(hDlg, PrinterName, PrintStructures);
1571 break;
1573 case cmb2: /* Papersize */
1575 DWORD Sel = SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1576 if(Sel != CB_ERR)
1577 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageA(hDlg, cmb2,
1578 CB_GETITEMDATA,
1579 Sel, 0);
1581 break;
1583 case cmb3: /* Bin */
1585 DWORD Sel = SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1586 if(Sel != CB_ERR)
1587 lpdm->u1.s1.dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,
1588 CB_GETITEMDATA, Sel,
1591 break;
1593 if(lppd->Flags & PD_PRINTSETUP) {
1594 switch (LOWORD(wParam)) {
1595 case rad1: /* orientation */
1596 case rad2:
1597 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1598 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1599 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1600 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1601 (WPARAM)IMAGE_ICON,
1602 (LPARAM)PrintStructures->hPortraitIcon);
1603 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1604 (WPARAM)IMAGE_ICON,
1605 (LPARAM)PrintStructures->hPortraitIcon);
1607 } else {
1608 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1609 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1610 SendDlgItemMessageA(hDlg, stc10, STM_SETIMAGE,
1611 (WPARAM)IMAGE_ICON,
1612 (LPARAM)PrintStructures->hLandscapeIcon);
1613 SendDlgItemMessageA(hDlg, ico1, STM_SETIMAGE,
1614 (WPARAM)IMAGE_ICON,
1615 (LPARAM)PrintStructures->hLandscapeIcon);
1618 break;
1621 return FALSE;
1624 static LRESULT PRINTDLG_WMCommandW(HWND hDlg, WPARAM wParam,
1625 LPARAM lParam, PRINT_PTRW* PrintStructures)
1627 LPPRINTDLGW lppd = PrintStructures->lpPrintDlg;
1628 UINT PrinterComboID = (lppd->Flags & PD_PRINTSETUP) ? cmb1 : cmb4;
1629 LPDEVMODEW lpdm = PrintStructures->lpDevMode;
1631 switch (LOWORD(wParam)) {
1632 case IDOK:
1633 TRACE(" OK button was hit\n");
1634 if (!PRINTDLG_UpdatePrintDlgW(hDlg, PrintStructures)) {
1635 FIXME("Update printdlg was not successful!\n");
1636 return(FALSE);
1638 EndDialog(hDlg, TRUE);
1639 return(TRUE);
1641 case IDCANCEL:
1642 TRACE(" CANCEL button was hit\n");
1643 EndDialog(hDlg, FALSE);
1644 return(FALSE);
1646 case pshHelp:
1647 TRACE(" HELP button was hit\n");
1648 SendMessageW(lppd->hwndOwner, PrintStructures->HelpMessageID,
1649 (WPARAM) hDlg, (LPARAM) lppd);
1650 break;
1652 case chx2: /* collate pages checkbox */
1653 if (IsDlgButtonChecked(hDlg, chx2) == BST_CHECKED)
1654 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1655 (LPARAM)PrintStructures->hCollateIcon);
1656 else
1657 SendDlgItemMessageW(hDlg, ico3, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1658 (LPARAM)PrintStructures->hNoCollateIcon);
1659 break;
1660 case edt1: /* from page nr editbox */
1661 case edt2: /* to page nr editbox */
1662 if (HIWORD(wParam)==EN_CHANGE) {
1663 WORD nToPage;
1664 WORD nFromPage;
1665 nFromPage = GetDlgItemInt(hDlg, edt1, NULL, FALSE);
1666 nToPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
1667 if (nFromPage != lppd->nFromPage || nToPage != lppd->nToPage)
1668 CheckRadioButton(hDlg, rad1, rad3, rad3);
1670 break;
1672 case edt3:
1673 if(HIWORD(wParam) == EN_CHANGE) {
1674 INT copies = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
1675 if(copies <= 1)
1676 EnableWindow(GetDlgItem(hDlg, chx2), FALSE);
1677 else
1678 EnableWindow(GetDlgItem(hDlg, chx2), TRUE);
1680 break;
1682 case psh1: /* Print Setup */
1684 ERR("psh1 is called from 16bit code only, we should not get here.\n");
1686 break;
1687 case psh2: /* Properties button */
1689 HANDLE hPrinter;
1690 WCHAR PrinterName[256];
1692 if (!GetDlgItemTextW(hDlg, PrinterComboID, PrinterName, 255)) break;
1693 if (!OpenPrinterW(PrinterName, &hPrinter, NULL)) {
1694 FIXME(" Call to OpenPrinter did not succeed!\n");
1695 break;
1697 DocumentPropertiesW(hDlg, hPrinter, PrinterName,
1698 PrintStructures->lpDevMode,
1699 PrintStructures->lpDevMode,
1700 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
1701 ClosePrinter(hPrinter);
1702 break;
1705 case rad1: /* Paperorientation */
1706 if (lppd->Flags & PD_PRINTSETUP)
1708 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1709 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1710 (LPARAM)(PrintStructures->hPortraitIcon));
1712 break;
1714 case rad2: /* Paperorientation */
1715 if (lppd->Flags & PD_PRINTSETUP)
1717 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1718 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE, (WPARAM) IMAGE_ICON,
1719 (LPARAM)(PrintStructures->hLandscapeIcon));
1721 break;
1723 case cmb1: /* Printer Combobox in PRINT SETUP */
1724 /* FALLTHROUGH */
1725 case cmb4: /* Printer combobox */
1726 if (HIWORD(wParam)==CBN_SELCHANGE) {
1727 WCHAR PrinterName[256];
1728 GetDlgItemTextW(hDlg, LOWORD(wParam), PrinterName, 255);
1729 PRINTDLG_ChangePrinterW(hDlg, PrinterName, PrintStructures);
1731 break;
1733 case cmb2: /* Papersize */
1735 DWORD Sel = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
1736 if(Sel != CB_ERR)
1737 lpdm->u1.s1.dmPaperSize = SendDlgItemMessageW(hDlg, cmb2,
1738 CB_GETITEMDATA,
1739 Sel, 0);
1741 break;
1743 case cmb3: /* Bin */
1745 DWORD Sel = SendDlgItemMessageW(hDlg, cmb3, CB_GETCURSEL, 0, 0);
1746 if(Sel != CB_ERR)
1747 lpdm->u1.s1.dmDefaultSource = SendDlgItemMessageW(hDlg, cmb3,
1748 CB_GETITEMDATA, Sel,
1751 break;
1753 if(lppd->Flags & PD_PRINTSETUP) {
1754 switch (LOWORD(wParam)) {
1755 case rad1: /* orientation */
1756 case rad2:
1757 if (IsDlgButtonChecked(hDlg, rad1) == BST_CHECKED) {
1758 if(lpdm->u1.s1.dmOrientation != DMORIENT_PORTRAIT) {
1759 lpdm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
1760 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1761 (WPARAM)IMAGE_ICON,
1762 (LPARAM)PrintStructures->hPortraitIcon);
1763 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1764 (WPARAM)IMAGE_ICON,
1765 (LPARAM)PrintStructures->hPortraitIcon);
1767 } else {
1768 if(lpdm->u1.s1.dmOrientation != DMORIENT_LANDSCAPE) {
1769 lpdm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
1770 SendDlgItemMessageW(hDlg, stc10, STM_SETIMAGE,
1771 (WPARAM)IMAGE_ICON,
1772 (LPARAM)PrintStructures->hLandscapeIcon);
1773 SendDlgItemMessageW(hDlg, ico1, STM_SETIMAGE,
1774 (WPARAM)IMAGE_ICON,
1775 (LPARAM)PrintStructures->hLandscapeIcon);
1778 break;
1781 return FALSE;
1784 /***********************************************************************
1785 * PrintDlgProcA [internal]
1787 static INT_PTR CALLBACK PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
1788 LPARAM lParam)
1790 PRINT_PTRA* PrintStructures;
1791 INT_PTR res = FALSE;
1793 if (uMsg!=WM_INITDIALOG) {
1794 PrintStructures = GetPropW(hDlg, printdlg_prop);
1795 if (!PrintStructures)
1796 return FALSE;
1797 } else {
1798 PrintStructures = (PRINT_PTRA*) lParam;
1799 SetPropW(hDlg, printdlg_prop, PrintStructures);
1800 if(!check_printer_setup(hDlg))
1802 EndDialog(hDlg,FALSE);
1803 return FALSE;
1805 res = PRINTDLG_WMInitDialog(hDlg, wParam, PrintStructures);
1807 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1808 res = PrintStructures->lpPrintDlg->lpfnPrintHook(
1809 hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg
1811 return res;
1814 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1815 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam,
1816 lParam);
1817 if(res) return res;
1820 switch (uMsg) {
1821 case WM_COMMAND:
1822 return PRINTDLG_WMCommandA(hDlg, wParam, lParam, PrintStructures);
1824 case WM_DESTROY:
1825 DestroyIcon(PrintStructures->hCollateIcon);
1826 DestroyIcon(PrintStructures->hNoCollateIcon);
1827 DestroyIcon(PrintStructures->hPortraitIcon);
1828 DestroyIcon(PrintStructures->hLandscapeIcon);
1829 if(PrintStructures->hwndUpDown)
1830 DestroyWindow(PrintStructures->hwndUpDown);
1831 return FALSE;
1833 return res;
1836 static INT_PTR CALLBACK PrintDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam,
1837 LPARAM lParam)
1839 PRINT_PTRW* PrintStructures;
1840 INT_PTR res = FALSE;
1842 if (uMsg!=WM_INITDIALOG) {
1843 PrintStructures = GetPropW(hDlg, printdlg_prop);
1844 if (!PrintStructures)
1845 return FALSE;
1846 } else {
1847 PrintStructures = (PRINT_PTRW*) lParam;
1848 SetPropW(hDlg, printdlg_prop, PrintStructures);
1849 if(!check_printer_setup(hDlg))
1851 EndDialog(hDlg,FALSE);
1852 return FALSE;
1854 res = PRINTDLG_WMInitDialogW(hDlg, wParam, PrintStructures);
1856 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK)
1857 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg, uMsg, wParam, (LPARAM)PrintStructures->lpPrintDlg);
1858 return res;
1861 if(PrintStructures->lpPrintDlg->Flags & PD_ENABLEPRINTHOOK) {
1862 res = PrintStructures->lpPrintDlg->lpfnPrintHook(hDlg,uMsg,wParam, lParam);
1863 if(res) return res;
1866 switch (uMsg) {
1867 case WM_COMMAND:
1868 return PRINTDLG_WMCommandW(hDlg, wParam, lParam, PrintStructures);
1870 case WM_DESTROY:
1871 DestroyIcon(PrintStructures->hCollateIcon);
1872 DestroyIcon(PrintStructures->hNoCollateIcon);
1873 DestroyIcon(PrintStructures->hPortraitIcon);
1874 DestroyIcon(PrintStructures->hLandscapeIcon);
1875 if(PrintStructures->hwndUpDown)
1876 DestroyWindow(PrintStructures->hwndUpDown);
1877 return FALSE;
1879 return res;
1882 /************************************************************
1884 * PRINTDLG_GetDlgTemplate
1887 static HGLOBAL PRINTDLG_GetDlgTemplateA(const PRINTDLGA *lppd)
1889 HRSRC hResInfo;
1890 HGLOBAL hDlgTmpl;
1892 if (lppd->Flags & PD_PRINTSETUP) {
1893 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1894 hDlgTmpl = lppd->hSetupTemplate;
1895 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1896 hResInfo = FindResourceA(lppd->hInstance,
1897 lppd->lpSetupTemplateName, (LPSTR)RT_DIALOG);
1898 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1899 } else {
1900 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32_SETUP",
1901 (LPSTR)RT_DIALOG);
1902 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1904 } else {
1905 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1906 hDlgTmpl = lppd->hPrintTemplate;
1907 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1908 hResInfo = FindResourceA(lppd->hInstance,
1909 lppd->lpPrintTemplateName,
1910 (LPSTR)RT_DIALOG);
1911 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1912 } else {
1913 hResInfo = FindResourceA(COMDLG32_hInstance, "PRINT32",
1914 (LPSTR)RT_DIALOG);
1915 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1918 return hDlgTmpl;
1921 static HGLOBAL PRINTDLG_GetDlgTemplateW(const PRINTDLGW *lppd)
1923 HRSRC hResInfo;
1924 HGLOBAL hDlgTmpl;
1925 static const WCHAR xpsetup[] = { 'P','R','I','N','T','3','2','_','S','E','T','U','P',0};
1926 static const WCHAR xprint[] = { 'P','R','I','N','T','3','2',0};
1928 if (lppd->Flags & PD_PRINTSETUP) {
1929 if(lppd->Flags & PD_ENABLESETUPTEMPLATEHANDLE) {
1930 hDlgTmpl = lppd->hSetupTemplate;
1931 } else if(lppd->Flags & PD_ENABLESETUPTEMPLATE) {
1932 hResInfo = FindResourceW(lppd->hInstance,
1933 lppd->lpSetupTemplateName, (LPWSTR)RT_DIALOG);
1934 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1935 } else {
1936 hResInfo = FindResourceW(COMDLG32_hInstance, xpsetup, (LPWSTR)RT_DIALOG);
1937 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1939 } else {
1940 if(lppd->Flags & PD_ENABLEPRINTTEMPLATEHANDLE) {
1941 hDlgTmpl = lppd->hPrintTemplate;
1942 } else if(lppd->Flags & PD_ENABLEPRINTTEMPLATE) {
1943 hResInfo = FindResourceW(lppd->hInstance,
1944 lppd->lpPrintTemplateName,
1945 (LPWSTR)RT_DIALOG);
1946 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
1947 } else {
1948 hResInfo = FindResourceW(COMDLG32_hInstance, xprint, (LPWSTR)RT_DIALOG);
1949 hDlgTmpl = LoadResource(COMDLG32_hInstance, hResInfo);
1952 return hDlgTmpl;
1955 /***********************************************************************
1957 * PRINTDLG_CreateDC
1960 static BOOL PRINTDLG_CreateDCA(LPPRINTDLGA lppd)
1962 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1963 DEVMODEA *pdm = GlobalLock(lppd->hDevMode);
1965 if(lppd->Flags & PD_RETURNDC) {
1966 lppd->hDC = CreateDCA((char*)pdn + pdn->wDriverOffset,
1967 (char*)pdn + pdn->wDeviceOffset,
1968 (char*)pdn + pdn->wOutputOffset,
1969 pdm );
1970 } else if(lppd->Flags & PD_RETURNIC) {
1971 lppd->hDC = CreateICA((char*)pdn + pdn->wDriverOffset,
1972 (char*)pdn + pdn->wDeviceOffset,
1973 (char*)pdn + pdn->wOutputOffset,
1974 pdm );
1976 GlobalUnlock(lppd->hDevNames);
1977 GlobalUnlock(lppd->hDevMode);
1978 return lppd->hDC ? TRUE : FALSE;
1981 static BOOL PRINTDLG_CreateDCW(LPPRINTDLGW lppd)
1983 DEVNAMES *pdn = GlobalLock(lppd->hDevNames);
1984 DEVMODEW *pdm = GlobalLock(lppd->hDevMode);
1986 if(lppd->Flags & PD_RETURNDC) {
1987 lppd->hDC = CreateDCW((WCHAR*)pdn + pdn->wDriverOffset,
1988 (WCHAR*)pdn + pdn->wDeviceOffset,
1989 (WCHAR*)pdn + pdn->wOutputOffset,
1990 pdm );
1991 } else if(lppd->Flags & PD_RETURNIC) {
1992 lppd->hDC = CreateICW((WCHAR*)pdn + pdn->wDriverOffset,
1993 (WCHAR*)pdn + pdn->wDeviceOffset,
1994 (WCHAR*)pdn + pdn->wOutputOffset,
1995 pdm );
1997 GlobalUnlock(lppd->hDevNames);
1998 GlobalUnlock(lppd->hDevMode);
1999 return lppd->hDC ? TRUE : FALSE;
2002 /***********************************************************************
2003 * PrintDlgA (COMDLG32.@)
2005 * Displays the PRINT dialog box, which enables the user to specify
2006 * specific properties of the print job.
2008 * PARAMS
2009 * lppd [IO] ptr to PRINTDLG32 struct
2011 * RETURNS
2012 * nonzero if the user pressed the OK button
2013 * zero if the user cancelled the window or an error occurred
2015 * BUGS
2016 * PrintDlg:
2017 * * The Collate Icons do not display, even though they are in the code.
2018 * * The Properties Button(s) should call DocumentPropertiesA().
2021 BOOL WINAPI PrintDlgA(LPPRINTDLGA lppd)
2023 BOOL bRet = FALSE;
2024 LPVOID ptr;
2025 HINSTANCE hInst;
2027 if (!lppd)
2029 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
2030 return FALSE;
2033 hInst = (HINSTANCE)GetWindowLongPtrA( lppd->hwndOwner, GWLP_HINSTANCE );
2034 if(TRACE_ON(commdlg)) {
2035 char flagstr[1000] = "";
2036 const struct pd_flags *pflag = pd_flags;
2037 for( ; pflag->name; pflag++) {
2038 if(lppd->Flags & pflag->flag)
2039 strcat(flagstr, pflag->name);
2041 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2042 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2043 "flags %08x (%s)\n",
2044 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2045 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2046 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2049 if(lppd->lStructSize != sizeof(PRINTDLGA)) {
2050 WARN("structure size failure !!!\n");
2051 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2052 return FALSE;
2055 if(lppd->Flags & PD_RETURNDEFAULT) {
2056 PRINTER_INFO_2A *pbuf;
2057 DRIVER_INFO_3A *dbuf;
2058 HANDLE hprn;
2059 DWORD needed;
2061 if(lppd->hDevMode || lppd->hDevNames) {
2062 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2063 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2064 return FALSE;
2066 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2067 WARN("Can't find default printer\n");
2068 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2069 return FALSE;
2072 GetPrinterA(hprn, 2, NULL, 0, &needed);
2073 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2074 GetPrinterA(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2076 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2077 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2078 if (!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2079 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2080 GetLastError(),pbuf->pPrinterName);
2081 HeapFree(GetProcessHeap(), 0, dbuf);
2082 HeapFree(GetProcessHeap(), 0, pbuf);
2083 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2084 return FALSE;
2086 ClosePrinter(hprn);
2088 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2089 dbuf->pDriverPath,
2090 pbuf->pPrinterName,
2091 pbuf->pPortName);
2092 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2093 pbuf->pDevMode->dmDriverExtra);
2094 ptr = GlobalLock(lppd->hDevMode);
2095 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2096 pbuf->pDevMode->dmDriverExtra);
2097 GlobalUnlock(lppd->hDevMode);
2098 HeapFree(GetProcessHeap(), 0, pbuf);
2099 HeapFree(GetProcessHeap(), 0, dbuf);
2100 bRet = TRUE;
2101 } else {
2102 HGLOBAL hDlgTmpl;
2103 PRINT_PTRA *PrintStructures;
2105 /* load Dialog resources,
2106 * depending on Flags indicates Print32 or Print32_setup dialog
2108 hDlgTmpl = PRINTDLG_GetDlgTemplateA(lppd);
2109 if (!hDlgTmpl) {
2110 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2111 return FALSE;
2113 ptr = LockResource( hDlgTmpl );
2114 if (!ptr) {
2115 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2116 return FALSE;
2119 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2120 sizeof(PRINT_PTRA));
2121 PrintStructures->lpPrintDlg = lppd;
2123 /* and create & process the dialog .
2124 * -1 is failure, 0 is broken hwnd, everything else is ok.
2126 bRet = (0<DialogBoxIndirectParamA(hInst, ptr, lppd->hwndOwner,
2127 PrintDlgProcA,
2128 (LPARAM)PrintStructures));
2130 if(bRet) {
2131 DEVMODEA *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2132 PRINTER_INFO_2A *pi = PrintStructures->lpPrinterInfo;
2133 DRIVER_INFO_3A *di = PrintStructures->lpDriverInfo;
2135 if (lppd->hDevMode == 0) {
2136 TRACE(" No hDevMode yet... Need to create my own\n");
2137 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2138 lpdm->dmSize + lpdm->dmDriverExtra);
2139 } else {
2140 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2141 lpdm->dmSize + lpdm->dmDriverExtra,
2142 GMEM_MOVEABLE);
2144 lpdmReturn = GlobalLock(lppd->hDevMode);
2145 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2147 PRINTDLG_CreateDevNames(&(lppd->hDevNames),
2148 di->pDriverPath,
2149 pi->pPrinterName,
2150 pi->pPortName
2152 GlobalUnlock(lppd->hDevMode);
2154 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2155 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2156 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2157 HeapFree(GetProcessHeap(), 0, PrintStructures);
2159 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2160 bRet = PRINTDLG_CreateDCA(lppd);
2162 TRACE("exit! (%d)\n", bRet);
2163 return bRet;
2166 /***********************************************************************
2167 * PrintDlgW (COMDLG32.@)
2169 * See PrintDlgA.
2171 BOOL WINAPI PrintDlgW(LPPRINTDLGW lppd)
2173 BOOL bRet = FALSE;
2174 LPVOID ptr;
2175 HINSTANCE hInst;
2177 if (!lppd)
2179 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
2180 return FALSE;
2183 hInst = (HINSTANCE)GetWindowLongPtrW( lppd->hwndOwner, GWLP_HINSTANCE );
2184 if(TRACE_ON(commdlg)) {
2185 char flagstr[1000] = "";
2186 const struct pd_flags *pflag = pd_flags;
2187 for( ; pflag->name; pflag++) {
2188 if(lppd->Flags & pflag->flag)
2189 strcat(flagstr, pflag->name);
2191 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
2192 "pp. %d-%d, min p %d, max p %d, copies %d, hinst %p\n"
2193 "flags %08x (%s)\n",
2194 lppd, lppd->hwndOwner, lppd->hDevMode, lppd->hDevNames,
2195 lppd->nFromPage, lppd->nToPage, lppd->nMinPage, lppd->nMaxPage,
2196 lppd->nCopies, lppd->hInstance, lppd->Flags, flagstr);
2199 if(lppd->lStructSize != sizeof(PRINTDLGW)) {
2200 WARN("structure size failure !!!\n");
2201 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
2202 return FALSE;
2205 if(lppd->Flags & PD_RETURNDEFAULT) {
2206 PRINTER_INFO_2W *pbuf;
2207 DRIVER_INFO_3W *dbuf;
2208 HANDLE hprn;
2209 DWORD needed;
2211 if(lppd->hDevMode || lppd->hDevNames) {
2212 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
2213 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2214 return FALSE;
2216 if(!PRINTDLG_OpenDefaultPrinter(&hprn)) {
2217 WARN("Can't find default printer\n");
2218 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
2219 return FALSE;
2222 GetPrinterW(hprn, 2, NULL, 0, &needed);
2223 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
2224 GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
2226 GetPrinterDriverW(hprn, NULL, 3, NULL, 0, &needed);
2227 dbuf = HeapAlloc(GetProcessHeap(),0,needed);
2228 if (!GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed)) {
2229 ERR("GetPrinterDriverA failed, le %d, fix your config for printer %s!\n",
2230 GetLastError(),debugstr_w(pbuf->pPrinterName));
2231 HeapFree(GetProcessHeap(), 0, dbuf);
2232 HeapFree(GetProcessHeap(), 0, pbuf);
2233 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
2234 return FALSE;
2236 ClosePrinter(hprn);
2238 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2239 dbuf->pDriverPath,
2240 pbuf->pPrinterName,
2241 pbuf->pPortName);
2242 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
2243 pbuf->pDevMode->dmDriverExtra);
2244 ptr = GlobalLock(lppd->hDevMode);
2245 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
2246 pbuf->pDevMode->dmDriverExtra);
2247 GlobalUnlock(lppd->hDevMode);
2248 HeapFree(GetProcessHeap(), 0, pbuf);
2249 HeapFree(GetProcessHeap(), 0, dbuf);
2250 bRet = TRUE;
2251 } else {
2252 HGLOBAL hDlgTmpl;
2253 PRINT_PTRW *PrintStructures;
2255 /* load Dialog resources,
2256 * depending on Flags indicates Print32 or Print32_setup dialog
2258 hDlgTmpl = PRINTDLG_GetDlgTemplateW(lppd);
2259 if (!hDlgTmpl) {
2260 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2261 return FALSE;
2263 ptr = LockResource( hDlgTmpl );
2264 if (!ptr) {
2265 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
2266 return FALSE;
2269 PrintStructures = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
2270 sizeof(PRINT_PTRW));
2271 PrintStructures->lpPrintDlg = lppd;
2273 /* and create & process the dialog .
2274 * -1 is failure, 0 is broken hwnd, everything else is ok.
2276 bRet = (0<DialogBoxIndirectParamW(hInst, ptr, lppd->hwndOwner,
2277 PrintDlgProcW,
2278 (LPARAM)PrintStructures));
2280 if(bRet) {
2281 DEVMODEW *lpdm = PrintStructures->lpDevMode, *lpdmReturn;
2282 PRINTER_INFO_2W *pi = PrintStructures->lpPrinterInfo;
2283 DRIVER_INFO_3W *di = PrintStructures->lpDriverInfo;
2285 if (lppd->hDevMode == 0) {
2286 TRACE(" No hDevMode yet... Need to create my own\n");
2287 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE,
2288 lpdm->dmSize + lpdm->dmDriverExtra);
2289 } else {
2290 WORD locks;
2291 if((locks = (GlobalFlags(lppd->hDevMode) & GMEM_LOCKCOUNT))) {
2292 WARN("hDevMode has %d locks on it. Unlocking it now\n", locks);
2293 while(locks--) {
2294 GlobalUnlock(lppd->hDevMode);
2295 TRACE("Now got %d locks\n", locks);
2298 lppd->hDevMode = GlobalReAlloc(lppd->hDevMode,
2299 lpdm->dmSize + lpdm->dmDriverExtra,
2300 GMEM_MOVEABLE);
2302 lpdmReturn = GlobalLock(lppd->hDevMode);
2303 memcpy(lpdmReturn, lpdm, lpdm->dmSize + lpdm->dmDriverExtra);
2305 if (lppd->hDevNames != 0) {
2306 WORD locks;
2307 if((locks = (GlobalFlags(lppd->hDevNames) & GMEM_LOCKCOUNT))) {
2308 WARN("hDevNames has %d locks on it. Unlocking it now\n", locks);
2309 while(locks--)
2310 GlobalUnlock(lppd->hDevNames);
2313 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
2314 di->pDriverPath,
2315 pi->pPrinterName,
2316 pi->pPortName
2318 GlobalUnlock(lppd->hDevMode);
2320 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDevMode);
2321 HeapFree(GetProcessHeap(), 0, PrintStructures->lpPrinterInfo);
2322 HeapFree(GetProcessHeap(), 0, PrintStructures->lpDriverInfo);
2323 HeapFree(GetProcessHeap(), 0, PrintStructures);
2325 if(bRet && (lppd->Flags & PD_RETURNDC || lppd->Flags & PD_RETURNIC))
2326 bRet = PRINTDLG_CreateDCW(lppd);
2328 TRACE("exit! (%d)\n", bRet);
2329 return bRet;
2332 /***********************************************************************
2334 * PageSetupDlg
2335 * rad1 - portrait
2336 * rad2 - landscape
2337 * cmb1 - printer select (not in standard dialog template)
2338 * cmb2 - paper size
2339 * cmb3 - source (tray?)
2340 * edt4 - border left
2341 * edt5 - border top
2342 * edt6 - border right
2343 * edt7 - border bottom
2344 * psh3 - "Printer..."
2347 typedef struct {
2348 LPPAGESETUPDLGA dlga; /* Handler to user defined struct */
2349 HWND hDlg; /* Page Setup dialog handler */
2350 RECT rtDrawRect; /* Drawing rect for page */
2351 } PageSetupDataA;
2353 typedef struct {
2354 LPPAGESETUPDLGW dlgw;
2355 PRINTDLGW pdlg;
2356 PAGESETUPDLGW curdlg; /* Current dialog state */
2357 } PageSetupDataW;
2360 static HGLOBAL PRINTDLG_GetPGSTemplateA(const PAGESETUPDLGA *lppd)
2362 HRSRC hResInfo;
2363 HGLOBAL hDlgTmpl;
2365 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2366 hDlgTmpl = lppd->hPageSetupTemplate;
2367 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2368 hResInfo = FindResourceA(lppd->hInstance,
2369 lppd->lpPageSetupTemplateName, (LPSTR)RT_DIALOG);
2370 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2371 } else {
2372 hResInfo = FindResourceA(COMDLG32_hInstance,(LPCSTR)PAGESETUPDLGORD,(LPSTR)RT_DIALOG);
2373 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2375 return hDlgTmpl;
2378 static HGLOBAL PRINTDLG_GetPGSTemplateW(const PAGESETUPDLGW *lppd)
2380 HRSRC hResInfo;
2381 HGLOBAL hDlgTmpl;
2383 if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATEHANDLE) {
2384 hDlgTmpl = lppd->hPageSetupTemplate;
2385 } else if(lppd->Flags & PSD_ENABLEPAGESETUPTEMPLATE) {
2386 hResInfo = FindResourceW(lppd->hInstance,
2387 lppd->lpPageSetupTemplateName, (LPWSTR)RT_DIALOG);
2388 hDlgTmpl = LoadResource(lppd->hInstance, hResInfo);
2389 } else {
2390 hResInfo = FindResourceW(COMDLG32_hInstance,(LPCWSTR)PAGESETUPDLGORD,(LPWSTR)RT_DIALOG);
2391 hDlgTmpl = LoadResource(COMDLG32_hInstance,hResInfo);
2393 return hDlgTmpl;
2396 static inline BOOL is_metric(const PageSetupDataA *pda)
2398 return pda->dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS;
2401 static DWORD
2402 _c_10mm2size(PAGESETUPDLGA *dlga,DWORD size) {
2403 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2404 return 10*size*100/254;
2405 return 10*size;
2409 static DWORD
2410 _c_inch2size(PAGESETUPDLGA *dlga,DWORD size) {
2411 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2412 return size;
2413 else
2414 return (size*254)/100;
2417 static void size2str(const PageSetupDataA *pda, DWORD size, LPWSTR strout)
2419 static const WCHAR metric_format[] = {'%','d',0};
2420 static const WCHAR imperial_format[] = {'%','d','i','n',0};
2422 if (is_metric(pda))
2423 wsprintfW(strout, metric_format, size / 100);
2424 else
2425 wsprintfW(strout, imperial_format, size / 1000);
2428 static void
2429 _c_size2strW(PageSetupDataW *pdw,DWORD size,LPWSTR strout) {
2430 static const char mm_fmt[] = "%.2f mm";
2431 static const char in_fmt[] = "%.2f in";
2432 char buf[20];
2433 if (pdw->dlgw->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2434 sprintf(buf, mm_fmt, (size * 1.0) / 100.0);
2435 } else if (pdw->dlgw->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2436 sprintf(buf, in_fmt, (size * 1.0) / 1000.0);
2437 } else {
2438 pdw->dlgw->Flags |= PSD_INHUNDREDTHSOFMILLIMETERS;
2439 sprintf(buf, mm_fmt, (size * 1.0) / 100.0);
2442 MultiByteToWideChar(CP_ACP, 0, buf, -1, strout, 20);
2445 static DWORD
2446 _c_str2sizeA(const PAGESETUPDLGA *dlga, LPCSTR strin) {
2447 float val;
2448 char rest[200];
2450 rest[0]='\0';
2451 if (!sscanf(strin,"%f%s",&val,rest))
2452 return 0;
2454 if (!strcmp(rest,"in") || !strcmp(rest,"inch")) {
2455 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES)
2456 return 1000*val;
2457 else
2458 return val*25.4*100;
2460 if (!strcmp(rest,"cm")) { rest[0]='m'; val = val*10.0; }
2461 if (!strcmp(rest,"m")) { strcpy(rest,"mm"); val = val*1000.0; }
2463 if (!strcmp(rest,"mm")) {
2464 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS)
2465 return 100*val;
2466 else
2467 return 1000.0*val/25.4;
2469 if (rest[0]=='\0') {
2470 /* use application supplied default */
2471 if (dlga->Flags & PSD_INHUNDREDTHSOFMILLIMETERS) {
2472 /* 100*mm */
2473 return 100.0*val;
2475 if (dlga->Flags & PSD_INTHOUSANDTHSOFINCHES) {
2476 /* 1000*inch */
2477 return 1000.0*val;
2480 ERR("Did not find a conversion for type '%s'!\n",rest);
2481 return 0;
2485 static DWORD
2486 _c_str2sizeW(const PAGESETUPDLGW *dlga, LPCWSTR strin) {
2487 char buf[200];
2489 /* this W -> A transition is OK */
2490 /* we need a unicode version of sscanf to avoid it */
2491 WideCharToMultiByte(CP_ACP, 0, strin, -1, buf, sizeof(buf), NULL, NULL);
2492 return _c_str2sizeA((const PAGESETUPDLGA *)dlga, buf);
2495 static inline BOOL is_default_metric(void)
2497 DWORD system;
2498 GetLocaleInfoW(LOCALE_USER_DEFAULT, LOCALE_IMEASURE | LOCALE_RETURN_NUMBER,
2499 (LPWSTR)&system, sizeof(system));
2500 return system == 0;
2503 /**********************************************
2504 * rotate_rect
2505 * Cyclically permute the four members of rc
2506 * If sense is TRUE l -> t -> r -> b
2507 * otherwise l <- t <- r <- b
2509 static inline void rotate_rect(RECT *rc, BOOL sense)
2511 INT tmp;
2512 if(sense)
2514 tmp = rc->bottom;
2515 rc->bottom = rc->right;
2516 rc->right = rc->top;
2517 rc->top = rc->left;
2518 rc->left = tmp;
2520 else
2522 tmp = rc->left;
2523 rc->left = rc->top;
2524 rc->top = rc->right;
2525 rc->right = rc->bottom;
2526 rc->bottom = tmp;
2530 static BOOL pagesetup_papersizeA(PAGESETUPDLGA *dlg, const WORD paperword, LPPOINT size)
2532 DEVNAMES *dn;
2533 DEVMODEA *dm;
2534 LPSTR devname, portname;
2535 int i, num;
2536 WORD *words = NULL;
2537 POINT *points = NULL;
2538 BOOL retval = FALSE;
2540 dn = GlobalLock(dlg->hDevNames);
2541 dm = GlobalLock(dlg->hDevMode);
2542 devname = ((char*)dn)+dn->wDeviceOffset;
2543 portname = ((char*)dn)+dn->wOutputOffset;
2545 num = DeviceCapabilitiesA(devname, portname, DC_PAPERS, NULL, dm);
2546 if (num <= 0)
2548 FIXME("No papernames found for %s/%s\n", devname, portname);
2549 goto end;
2552 words = HeapAlloc(GetProcessHeap(), 0, num * sizeof(WORD));
2553 points = HeapAlloc(GetProcessHeap(), 0, num * sizeof(POINT));
2555 if (num != DeviceCapabilitiesA(devname, portname, DC_PAPERS, (LPSTR)words, dm))
2557 FIXME("Number of returned words is not %d\n", num);
2558 goto end;
2561 if (num != DeviceCapabilitiesA(devname, portname, DC_PAPERSIZE, (LPSTR)points, dm))
2563 FIXME("Number of returned sizes is not %d\n",num);
2564 goto end;
2567 for (i = 0; i < num; i++)
2568 if (words[i] == paperword)
2569 break;
2571 if (i == num)
2573 FIXME("Papersize %d not found in list?\n", paperword);
2574 goto end;
2577 /* this is _10ths_ of a millimeter */
2578 size->x = _c_10mm2size(dlg, points[i].x);
2579 size->y = _c_10mm2size(dlg, points[i].y);
2580 retval = TRUE;
2582 end:
2583 HeapFree(GetProcessHeap(), 0, words);
2584 HeapFree(GetProcessHeap(), 0, points);
2585 GlobalUnlock(dlg->hDevNames);
2586 GlobalUnlock(dlg->hDevMode);
2587 return retval;
2590 static BOOL
2591 PRINTDLG_PS_UpdateDlgStructW(HWND hDlg, PageSetupDataW *pdw) {
2592 DEVNAMES *dn;
2593 DEVMODEW *dm;
2594 LPWSTR devname,portname;
2595 WCHAR papername[64];
2596 WCHAR buf[200];
2598 dn = GlobalLock(pdw->pdlg.hDevNames);
2599 dm = GlobalLock(pdw->pdlg.hDevMode);
2600 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2601 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2603 /* Save paper size into device context */
2604 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2605 /* Save paper source into device context */
2606 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2608 if (GetDlgItemTextW(hDlg,cmb2,papername,sizeof(papername)/sizeof(papername[0]))>0) {
2609 PRINTDLG_PaperSizeW(&(pdw->pdlg),papername,&(pdw->dlgw->ptPaperSize));
2610 pdw->dlgw->ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pdw->dlgw,pdw->dlgw->ptPaperSize.x);
2611 pdw->dlgw->ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pdw->dlgw,pdw->dlgw->ptPaperSize.y);
2612 } else
2613 FIXME("could not get dialog text for papersize cmbbox?\n");
2614 #define GETVAL(id,val) if (GetDlgItemTextW(hDlg,id,buf,sizeof(buf)/sizeof(buf[0]))>0) { val = _c_str2sizeW(pdw->dlgw,buf); } else { FIXME("could not get dlgitemtextw for %x\n",id); }
2615 GETVAL(edt4,pdw->dlgw->rtMargin.left);
2616 GETVAL(edt5,pdw->dlgw->rtMargin.top);
2617 GETVAL(edt6,pdw->dlgw->rtMargin.right);
2618 GETVAL(edt7,pdw->dlgw->rtMargin.bottom);
2619 #undef GETVAL
2621 /* If we are in landscape, swap x and y of page size */
2622 if (IsDlgButtonChecked(hDlg, rad2)) {
2623 DWORD tmp;
2624 tmp = pdw->dlgw->ptPaperSize.x;
2625 pdw->dlgw->ptPaperSize.x = pdw->dlgw->ptPaperSize.y;
2626 pdw->dlgw->ptPaperSize.y = tmp;
2629 /* Save orientation */
2630 if (pdw->dlgw->ptPaperSize.x > pdw->dlgw->ptPaperSize.y)
2631 dm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2632 else
2633 dm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2635 GlobalUnlock(pdw->pdlg.hDevNames);
2636 GlobalUnlock(pdw->pdlg.hDevMode);
2637 return TRUE;
2640 /**********************************************************************************************
2641 * PRINTDLG_PS_ChangeActivePrinerA
2643 * Redefines hDevMode and hDevNames HANDLES and initialises it.
2645 * PARAMS
2646 * name [in] Name of a printer for activation
2647 * pda [in/out] ptr to PageSetupDataA structure
2649 * RETURN
2650 * TRUE if success
2651 * FALSE if fail
2653 static BOOL
2654 PRINTDLG_PS_ChangeActivePrinterA(LPSTR name, PageSetupDataA *pda){
2655 HANDLE hprn;
2656 DWORD needed;
2657 LPPRINTER_INFO_2A lpPrinterInfo;
2658 LPDRIVER_INFO_3A lpDriverInfo;
2659 DEVMODEA *pDevMode, *dm;
2661 if(!OpenPrinterA(name, &hprn, NULL)){
2662 ERR("Can't open printer %s\n", name);
2663 return FALSE;
2665 GetPrinterA(hprn, 2, NULL, 0, &needed);
2666 lpPrinterInfo = HeapAlloc(GetProcessHeap(), 0, needed);
2667 GetPrinterA(hprn, 2, (LPBYTE)lpPrinterInfo, needed, &needed);
2668 GetPrinterDriverA(hprn, NULL, 3, NULL, 0, &needed);
2669 lpDriverInfo = HeapAlloc(GetProcessHeap(), 0, needed);
2670 if(!GetPrinterDriverA(hprn, NULL, 3, (LPBYTE)lpDriverInfo, needed, &needed)) {
2671 ERR("GetPrinterDriverA failed for %s, fix your config!\n", lpPrinterInfo->pPrinterName);
2672 HeapFree(GetProcessHeap(), 0, lpDriverInfo);
2673 HeapFree(GetProcessHeap(), 0, lpPrinterInfo);
2674 return FALSE;
2676 ClosePrinter(hprn);
2678 needed = DocumentPropertiesA(0, 0, name, NULL, NULL, 0);
2679 if(needed == -1) {
2680 ERR("DocumentProperties fails on %s\n", debugstr_a(name));
2681 HeapFree(GetProcessHeap(), 0, lpDriverInfo);
2682 HeapFree(GetProcessHeap(), 0, lpPrinterInfo);
2683 return FALSE;
2685 pDevMode = HeapAlloc(GetProcessHeap(), 0, needed);
2686 DocumentPropertiesA(0, 0, name, pDevMode, NULL, DM_OUT_BUFFER);
2688 pda->dlga->hDevMode = GlobalReAlloc(pda->dlga->hDevMode,
2689 pDevMode->dmSize + pDevMode->dmDriverExtra,
2690 GMEM_MOVEABLE);
2691 dm = GlobalLock(pda->dlga->hDevMode);
2692 memcpy(dm, pDevMode, pDevMode->dmSize + pDevMode->dmDriverExtra);
2694 PRINTDLG_CreateDevNames(&(pda->dlga->hDevNames),
2695 lpDriverInfo->pDriverPath,
2696 lpPrinterInfo->pPrinterName,
2697 lpPrinterInfo->pPortName);
2699 GlobalUnlock(pda->dlga->hDevMode);
2700 HeapFree(GetProcessHeap(), 0, pDevMode);
2701 HeapFree(GetProcessHeap(), 0, lpPrinterInfo);
2702 HeapFree(GetProcessHeap(), 0, lpDriverInfo);
2703 return TRUE;
2706 /****************************************************************************************
2707 * PRINTDLG_PS_ChangePrinterA
2709 * Fills Printers, Paper and Source combo
2711 * RETURNS
2712 * TRUE
2714 static BOOL
2715 PRINTDLG_PS_ChangePrinterA(HWND hDlg, PageSetupDataA *pda) {
2716 DEVNAMES *dn;
2717 DEVMODEA *dm;
2718 LPSTR devname,portname;
2720 dn = GlobalLock(pda->dlga->hDevNames);
2721 dm = GlobalLock(pda->dlga->hDevMode);
2722 devname = ((char*)dn)+dn->wDeviceOffset;
2723 portname = ((char*)dn)+dn->wOutputOffset;
2724 PRINTDLG_SetUpPrinterListComboA(hDlg, cmb1, devname);
2725 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb2,devname,portname,dm);
2726 PRINTDLG_SetUpPaperComboBoxA(hDlg,cmb3,devname,portname,dm);
2727 GlobalUnlock(pda->dlga->hDevNames);
2728 GlobalUnlock(pda->dlga->hDevMode);
2729 return TRUE;
2732 static void PRINTDLG_PS_SetOrientationW(HWND hDlg, PageSetupDataW* pdw)
2734 WCHAR PaperName[64];
2736 GetDlgItemTextW(hDlg, cmb2, PaperName, sizeof(PaperName)/sizeof(WCHAR));
2737 PRINTDLG_PaperSizeW(&pdw->pdlg, PaperName, &pdw->curdlg.ptPaperSize);
2738 pdw->curdlg.ptPaperSize.x = _c_10mm2size((LPPAGESETUPDLGA)pdw->dlgw, pdw->curdlg.ptPaperSize.x);
2739 pdw->curdlg.ptPaperSize.y = _c_10mm2size((LPPAGESETUPDLGA)pdw->dlgw, pdw->curdlg.ptPaperSize.y);
2741 if(IsDlgButtonChecked(hDlg, rad2))
2743 DWORD tmp = pdw->curdlg.ptPaperSize.x;
2744 pdw->curdlg.ptPaperSize.x = pdw->curdlg.ptPaperSize.y;
2745 pdw->curdlg.ptPaperSize.y = tmp;
2749 static void PRINTDLG_PS_UpdatePrintDlgW(PageSetupDataW* pdw, HWND hDlg)
2751 DEVMODEW* dm;
2752 DWORD sel;
2754 dm = GlobalLock(pdw->pdlg.hDevMode);
2756 if(!dm)
2757 return;
2759 if(pdw->curdlg.ptPaperSize.y > pdw->curdlg.ptPaperSize.x)
2760 dm->u1.s1.dmOrientation = DMORIENT_PORTRAIT;
2761 else
2762 dm->u1.s1.dmOrientation = DMORIENT_LANDSCAPE;
2764 sel = SendDlgItemMessageW(hDlg, cmb2, CB_GETCURSEL, 0, 0);
2766 if(sel != CB_ERR)
2767 dm->u1.s1.dmPaperSize = SendDlgItemMessageW(hDlg, cmb2, CB_GETITEMDATA, sel, 0);
2769 GlobalUnlock(pdw->pdlg.hDevMode);
2772 static BOOL
2773 PRINTDLG_PS_ChangePrinterW(HWND hDlg, PageSetupDataW *pdw) {
2774 DEVNAMES *dn;
2775 DEVMODEW *dm;
2776 LPWSTR devname,portname;
2778 dn = GlobalLock(pdw->pdlg.hDevNames);
2779 dm = GlobalLock(pdw->pdlg.hDevMode);
2780 devname = ((WCHAR*)dn)+dn->wDeviceOffset;
2781 portname = ((WCHAR*)dn)+dn->wOutputOffset;
2782 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb2,devname,portname,dm);
2783 PRINTDLG_SetUpPaperComboBoxW(hDlg,cmb3,devname,portname,dm);
2785 /* Landscape orientation */
2786 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE)
2787 CheckRadioButton(hDlg, rad1, rad2, rad2);
2788 else /* this is default if papersize is not set */
2789 CheckRadioButton(hDlg, rad1, rad2, rad1);
2791 GlobalUnlock(pdw->pdlg.hDevNames);
2792 GlobalUnlock(pdw->pdlg.hDevMode);
2794 PRINTDLG_PS_SetOrientationW(hDlg, pdw);
2796 return TRUE;
2799 /******************************************************************************************
2800 * PRINTDLG_PS_ChangePaperPrev
2802 * Changes paper preview size / position
2804 * PARAMS:
2805 * pda [i] Pointer for current PageSetupDataA structure
2807 * RETURNS:
2808 * always - TRUE
2810 static BOOL
2811 PRINTDLG_PS_ChangePaperPrev(const PageSetupDataA *pda)
2813 LONG width, height, x, y;
2814 RECT rtTmp;
2816 if(pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y) {
2817 width = pda->rtDrawRect.right - pda->rtDrawRect.left;
2818 height = pda->dlga->ptPaperSize.y * width / pda->dlga->ptPaperSize.x;
2819 } else {
2820 height = pda->rtDrawRect.bottom - pda->rtDrawRect.top;
2821 width = pda->dlga->ptPaperSize.x * height / pda->dlga->ptPaperSize.y;
2823 x = (pda->rtDrawRect.right + pda->rtDrawRect.left - width) / 2;
2824 y = (pda->rtDrawRect.bottom + pda->rtDrawRect.top - height) / 2;
2825 TRACE("rtDrawRect(%d, %d, %d, %d) x=%d, y=%d, w=%d, h=%d\n",
2826 pda->rtDrawRect.left, pda->rtDrawRect.top, pda->rtDrawRect.right, pda->rtDrawRect.bottom,
2827 x, y, width, height);
2829 #define SHADOW 4
2830 MoveWindow(GetDlgItem(pda->hDlg, rct2), x+width, y+SHADOW, SHADOW, height, FALSE);
2831 MoveWindow(GetDlgItem(pda->hDlg, rct3), x+SHADOW, y+height, width, SHADOW, FALSE);
2832 MoveWindow(GetDlgItem(pda->hDlg, rct1), x, y, width, height, FALSE);
2833 rtTmp = pda->rtDrawRect;
2834 rtTmp.right += SHADOW;
2835 rtTmp.bottom += SHADOW;
2836 #undef SHADOW
2838 InvalidateRect(pda->hDlg, &rtTmp, TRUE);
2839 return TRUE;
2842 #define GETVAL(idc,val) \
2843 if(msg == EN_CHANGE){ \
2844 if (GetDlgItemTextA(hDlg,idc,buf,sizeof(buf)) > 0)\
2845 val = _c_str2sizeA(pda->dlga,buf); \
2846 else\
2847 FIXME("could not get dlgitemtexta for %x\n",id); \
2850 static void update_margin_edits(HWND hDlg, const PageSetupDataA *pda)
2852 WCHAR str[100];
2854 size2str(pda, pda->dlga->rtMargin.left, str);
2855 SetDlgItemTextW(hDlg, edt4, str);
2856 size2str(pda, pda->dlga->rtMargin.top, str);
2857 SetDlgItemTextW(hDlg, edt5, str);
2858 size2str(pda, pda->dlga->rtMargin.right, str);
2859 SetDlgItemTextW(hDlg, edt6, str);
2860 size2str(pda, pda->dlga->rtMargin.bottom, str);
2861 SetDlgItemTextW(hDlg, edt7, str);
2864 /********************************************************************************
2865 * PRINTDLG_PS_WMCommandA
2866 * process WM_COMMAND message for PageSetupDlgA
2868 * PARAMS
2869 * hDlg [in] Main dialog HANDLE
2870 * wParam [in] WM_COMMAND wParam
2871 * lParam [in] WM_COMMAND lParam
2872 * pda [in/out] ptr to PageSetupDataA
2875 static BOOL
2876 PRINTDLG_PS_WMCommandA(
2877 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataA *pda
2879 WORD msg = HIWORD(wParam);
2880 WORD id = LOWORD(wParam);
2881 char buf[200];
2883 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
2884 LOWORD(lParam),wParam,lParam);
2885 switch (id) {
2886 case IDOK:
2887 EndDialog(hDlg, TRUE);
2888 return TRUE ;
2890 case IDCANCEL:
2891 EndDialog(hDlg, FALSE);
2892 return FALSE ;
2894 case psh3:
2896 PRINTDLGA prnt;
2897 memset(&prnt, 0, sizeof(prnt));
2898 prnt.lStructSize = sizeof(prnt);
2899 prnt.Flags = 0;
2900 prnt.hwndOwner = hDlg;
2901 prnt.hDevNames = pda->dlga->hDevNames;
2902 prnt.hDevMode = pda->dlga->hDevMode;
2903 if (PrintDlgA(&prnt))
2905 pda->dlga->hDevNames = prnt.hDevNames;
2906 pda->dlga->hDevMode = prnt.hDevMode;
2907 PRINTDLG_PS_ChangePrinterA(hDlg,pda);
2909 return TRUE;
2911 case rad1:
2912 case rad2:
2913 if((id == rad1 && pda->dlga->ptPaperSize.x > pda->dlga->ptPaperSize.y) ||
2914 (id == rad2 && pda->dlga->ptPaperSize.y > pda->dlga->ptPaperSize.x))
2916 DWORD tmp = pda->dlga->ptPaperSize.x;
2917 DEVMODEA *dm = GlobalLock(pda->dlga->hDevMode);
2919 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
2920 pda->dlga->ptPaperSize.y = tmp;
2922 dm->u1.s1.dmOrientation = (id == rad1) ? DMORIENT_PORTRAIT : DMORIENT_LANDSCAPE;
2923 GlobalUnlock(pda->dlga->hDevMode);
2925 rotate_rect(&pda->dlga->rtMargin, (id == rad2));
2926 update_margin_edits(hDlg, pda);
2928 PRINTDLG_PS_ChangePaperPrev(pda);
2930 break;
2931 case cmb1: /* Printer combo */
2932 if(msg == CBN_SELCHANGE){
2933 char crPrinterName[256];
2934 GetDlgItemTextA(hDlg, id, crPrinterName, 255);
2935 PRINTDLG_PS_ChangeActivePrinterA(crPrinterName, pda);
2936 PRINTDLG_PS_ChangePrinterA(hDlg, pda);
2938 break;
2939 case cmb2: /* Paper combo */
2940 if(msg == CBN_SELCHANGE){
2941 DWORD paperword = SendDlgItemMessageA(hDlg,cmb2,CB_GETITEMDATA,
2942 SendDlgItemMessageA(hDlg, cmb2, CB_GETCURSEL, 0, 0), 0);
2943 if (paperword != CB_ERR)
2945 DEVMODEA *dm = GlobalLock(pda->dlga->hDevMode);
2946 dm->u1.s1.dmPaperSize = paperword;
2947 GlobalUnlock(pda->dlga->hDevMode);
2948 pagesetup_papersizeA(pda->dlga, paperword, &(pda->dlga->ptPaperSize));
2949 if (IsDlgButtonChecked(hDlg, rad2)) {
2950 DWORD tmp = pda->dlga->ptPaperSize.x;
2951 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
2952 pda->dlga->ptPaperSize.y = tmp;
2954 PRINTDLG_PS_ChangePaperPrev(pda);
2955 } else
2956 FIXME("could not get dialog text for papersize cmbbox?\n");
2958 break;
2959 case cmb3:
2960 if(msg == CBN_SELCHANGE){
2961 DEVMODEA *dm = GlobalLock(pda->dlga->hDevMode);
2962 dm->u1.s1.dmDefaultSource = SendDlgItemMessageA(hDlg, cmb3,CB_GETITEMDATA,
2963 SendDlgItemMessageA(hDlg, cmb3, CB_GETCURSEL, 0, 0), 0);
2964 GlobalUnlock(pda->dlga->hDevMode);
2966 break;
2967 case psh2: /* Printer Properties button */
2969 HANDLE hPrinter;
2970 char PrinterName[256];
2971 DEVMODEA *dm;
2972 LRESULT count;
2973 int i;
2975 GetDlgItemTextA(hDlg, cmb1, PrinterName, 255);
2976 if (!OpenPrinterA(PrinterName, &hPrinter, NULL)) {
2977 FIXME("Call to OpenPrinter did not succeed!\n");
2978 break;
2980 dm = GlobalLock(pda->dlga->hDevMode);
2981 DocumentPropertiesA(hDlg, hPrinter, PrinterName, dm, dm,
2982 DM_IN_BUFFER | DM_OUT_BUFFER | DM_IN_PROMPT);
2983 ClosePrinter(hPrinter);
2984 /* Changing paper */
2985 pagesetup_papersizeA(pda->dlga, dm->u1.s1.dmPaperSize, &(pda->dlga->ptPaperSize));
2986 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE){
2987 DWORD tmp = pda->dlga->ptPaperSize.x;
2988 pda->dlga->ptPaperSize.x = pda->dlga->ptPaperSize.y;
2989 pda->dlga->ptPaperSize.y = tmp;
2990 CheckRadioButton(hDlg, rad1, rad2, rad2);
2992 else
2993 CheckRadioButton(hDlg, rad1, rad2, rad1);
2994 /* Changing paper preview */
2995 PRINTDLG_PS_ChangePaperPrev(pda);
2996 /* Selecting paper in combo */
2997 count = SendDlgItemMessageA(hDlg, cmb2, CB_GETCOUNT, 0, 0);
2998 if(count != CB_ERR){
2999 for(i=0; i<count; ++i){
3000 if(SendDlgItemMessageA(hDlg, cmb2, CB_GETITEMDATA, i, 0) == dm->u1.s1.dmPaperSize) {
3001 SendDlgItemMessageA(hDlg, cmb2, CB_SETCURSEL, i, 0);
3002 break;
3007 GlobalUnlock(pda->dlga->hDevMode);
3008 break;
3010 case edt4:
3011 GETVAL(id, pda->dlga->rtMargin.left);
3012 break;
3013 case edt5:
3014 GETVAL(id, pda->dlga->rtMargin.top);
3015 break;
3016 case edt6:
3017 GETVAL(id, pda->dlga->rtMargin.right);
3018 break;
3019 case edt7:
3020 GETVAL(id, pda->dlga->rtMargin.bottom);
3021 break;
3023 InvalidateRect(GetDlgItem(hDlg, rct1), NULL, TRUE);
3024 return FALSE;
3026 #undef GETVAL
3028 static BOOL
3029 PRINTDLG_PS_WMCommandW(
3030 HWND hDlg, WPARAM wParam, LPARAM lParam, PageSetupDataW *pdw
3032 TRACE("loword (lparam) %d, wparam 0x%lx, lparam %08lx\n",
3033 LOWORD(lParam),wParam,lParam);
3034 switch (LOWORD(wParam)) {
3035 case IDOK:
3036 if (!PRINTDLG_PS_UpdateDlgStructW(hDlg, pdw))
3037 return(FALSE);
3038 EndDialog(hDlg, TRUE);
3039 return TRUE ;
3041 case IDCANCEL:
3042 EndDialog(hDlg, FALSE);
3043 return FALSE ;
3045 case rad1:
3046 case rad2:
3047 if((LOWORD(wParam) == rad1 && pdw->curdlg.ptPaperSize.x > pdw->curdlg.ptPaperSize.y) ||
3048 (LOWORD(wParam) == rad2 && pdw->curdlg.ptPaperSize.y > pdw->curdlg.ptPaperSize.x))
3050 WCHAR tmpText[25];
3051 WCHAR tmpText2[25];
3052 DWORD tmp = pdw->curdlg.ptPaperSize.y;
3054 pdw->curdlg.ptPaperSize.y = pdw->curdlg.ptPaperSize.x;
3055 pdw->curdlg.ptPaperSize.x = tmp;
3057 GetDlgItemTextW(hDlg, edt4, tmpText, sizeof(tmpText)/sizeof(WCHAR));
3058 GetDlgItemTextW(hDlg, edt5, tmpText2, sizeof(tmpText2)/sizeof(WCHAR));
3059 SetDlgItemTextW(hDlg, edt5, tmpText);
3060 SetDlgItemTextW(hDlg, edt4, tmpText2);
3062 GetDlgItemTextW(hDlg, edt6, tmpText, sizeof(tmpText)/sizeof(WCHAR));
3063 GetDlgItemTextW(hDlg, edt7, tmpText2, sizeof(tmpText2)/sizeof(WCHAR));
3064 SetDlgItemTextW(hDlg, edt7, tmpText);
3065 SetDlgItemTextW(hDlg, edt6, tmpText2);
3067 break;
3069 case psh3: {
3070 pdw->pdlg.Flags = 0;
3071 pdw->pdlg.hwndOwner = hDlg;
3072 PRINTDLG_PS_UpdatePrintDlgW(pdw, hDlg);
3073 if (PrintDlgW(&(pdw->pdlg)))
3074 PRINTDLG_PS_ChangePrinterW(hDlg,pdw);
3075 return TRUE;
3078 return FALSE;
3082 /***********************************************************************
3083 * DefaultPagePaintHook
3084 * Default hook paint procedure that receives WM_PSD_* messages from the dialog box
3085 * whenever the sample page is redrawn.
3088 static UINT_PTR
3089 PRINTDLG_DefaultPagePaintHook(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam,
3090 const PageSetupDataA *pda)
3092 LPRECT lprc = (LPRECT) lParam;
3093 HDC hdc = (HDC) wParam;
3094 HPEN hpen, holdpen;
3095 LOGFONTW lf;
3096 HFONT hfont, holdfont;
3097 INT oldbkmode;
3098 TRACE("uMsg: WM_USER+%d\n",uMsg-WM_USER);
3099 /* Call user paint hook if enable */
3100 if (pda->dlga->Flags & PSD_ENABLEPAGEPAINTHOOK)
3101 if (pda->dlga->lpfnPagePaintHook(hwndDlg, uMsg, wParam, lParam))
3102 return TRUE;
3104 switch (uMsg) {
3105 /* LPPAGESETUPDLG in lParam */
3106 case WM_PSD_PAGESETUPDLG:
3107 /* Inform about the sample page rectangle */
3108 case WM_PSD_FULLPAGERECT:
3109 /* Inform about the margin rectangle */
3110 case WM_PSD_MINMARGINRECT:
3111 return FALSE;
3113 /* Draw dashed rectangle showing margins */
3114 case WM_PSD_MARGINRECT:
3115 hpen = CreatePen(PS_DASH, 1, GetSysColor(COLOR_3DSHADOW));
3116 holdpen = SelectObject(hdc, hpen);
3117 Rectangle(hdc, lprc->left, lprc->top, lprc->right, lprc->bottom);
3118 DeleteObject(SelectObject(hdc, holdpen));
3119 return TRUE;
3120 /* Draw the fake document */
3121 case WM_PSD_GREEKTEXTRECT:
3122 /* select a nice scalable font, because we want the text really small */
3123 SystemParametersInfoW(SPI_GETICONTITLELOGFONT, sizeof(lf), &lf, 0);
3124 lf.lfHeight = 6; /* value chosen based on visual effect */
3125 hfont = CreateFontIndirectW(&lf);
3126 holdfont = SelectObject(hdc, hfont);
3128 /* if text not loaded, then do so now */
3129 if (wszFakeDocumentText[0] == '\0')
3130 LoadStringW(COMDLG32_hInstance,
3131 IDS_FAKEDOCTEXT,
3132 wszFakeDocumentText,
3133 sizeof(wszFakeDocumentText)/sizeof(wszFakeDocumentText[0]));
3135 oldbkmode = SetBkMode(hdc, TRANSPARENT);
3136 DrawTextW(hdc, wszFakeDocumentText, -1, lprc, DT_TOP|DT_LEFT|DT_NOPREFIX|DT_WORDBREAK);
3137 SetBkMode(hdc, oldbkmode);
3139 DeleteObject(SelectObject(hdc, holdfont));
3140 return TRUE;
3142 /* Envelope stamp */
3143 case WM_PSD_ENVSTAMPRECT:
3144 /* Return address */
3145 case WM_PSD_YAFULLPAGERECT:
3146 FIXME("envelope/stamp is not implemented\n");
3147 return FALSE;
3148 default:
3149 FIXME("Unknown message %x\n",uMsg);
3150 return FALSE;
3152 return TRUE;
3155 /***********************************************************************
3156 * PagePaintProc
3157 * The main paint procedure for the PageSetupDlg function.
3158 * The Page Setup dialog box includes an image of a sample page that shows how
3159 * the user's selections affect the appearance of the printed output.
3160 * The image consists of a rectangle that represents the selected paper
3161 * or envelope type, with a dotted-line rectangle representing
3162 * the current margins, and partial (Greek text) characters
3163 * to show how text looks on the printed page.
3165 * The following messages in the order sends to user hook procedure:
3166 * WM_PSD_PAGESETUPDLG Draw the contents of the sample page
3167 * WM_PSD_FULLPAGERECT Inform about the bounding rectangle
3168 * WM_PSD_MINMARGINRECT Inform about the margin rectangle (min margin?)
3169 * WM_PSD_MARGINRECT Draw the margin rectangle
3170 * WM_PSD_GREEKTEXTRECT Draw the Greek text inside the margin rectangle
3171 * If any of first three messages returns TRUE, painting done.
3173 * PARAMS:
3174 * hWnd [in] Handle to the Page Setup dialog box
3175 * uMsg [in] Received message
3177 * TODO:
3178 * WM_PSD_ENVSTAMPRECT Draw in the envelope-stamp rectangle (for envelopes only)
3179 * WM_PSD_YAFULLPAGERECT Draw the return address portion (for envelopes and other paper sizes)
3181 * RETURNS:
3182 * FALSE if all done correctly
3187 static LRESULT CALLBACK
3188 PRINTDLG_PagePaintProc(HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam)
3190 PAINTSTRUCT ps;
3191 RECT rcClient, rcMargin;
3192 HPEN hpen, holdpen;
3193 HDC hdc;
3194 HBRUSH hbrush, holdbrush;
3195 PageSetupDataA *pda;
3196 int papersize=0, orientation=0; /* FIXME: set this values for user paint hook */
3197 double scalx, scaly;
3198 #define CALLPAINTHOOK(msg,lprc) PRINTDLG_DefaultPagePaintHook( hWnd, msg, (WPARAM)hdc, (LPARAM)lprc, pda)
3200 if (uMsg != WM_PAINT)
3201 return CallWindowProcA(lpfnStaticWndProc, hWnd, uMsg, wParam, lParam);
3203 /* Processing WM_PAINT message */
3204 pda = GetPropW(hWnd, pagesetupdlg_prop);
3205 if (!pda) {
3206 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3207 return FALSE;
3209 if (PRINTDLG_DefaultPagePaintHook(hWnd, WM_PSD_PAGESETUPDLG, MAKELONG(papersize, orientation), (LPARAM)pda->dlga, pda))
3210 return FALSE;
3212 hdc = BeginPaint(hWnd, &ps);
3213 GetClientRect(hWnd, &rcClient);
3215 scalx = rcClient.right / (double)pda->dlga->ptPaperSize.x;
3216 scaly = rcClient.bottom / (double)pda->dlga->ptPaperSize.y;
3217 rcMargin = rcClient;
3219 rcMargin.left += pda->dlga->rtMargin.left * scalx;
3220 rcMargin.top += pda->dlga->rtMargin.top * scalx;
3221 rcMargin.right -= pda->dlga->rtMargin.right * scaly;
3222 rcMargin.bottom -= pda->dlga->rtMargin.bottom * scaly;
3224 /* if the space is too small then we make sure to not draw anything */
3225 rcMargin.left = min(rcMargin.left, rcMargin.right);
3226 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3228 if (!CALLPAINTHOOK(WM_PSD_FULLPAGERECT, &rcClient) &&
3229 !CALLPAINTHOOK(WM_PSD_MINMARGINRECT, &rcMargin) )
3231 /* fill background */
3232 hbrush = GetSysColorBrush(COLOR_3DHIGHLIGHT);
3233 FillRect(hdc, &rcClient, hbrush);
3234 holdbrush = SelectObject(hdc, hbrush);
3236 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DSHADOW));
3237 holdpen = SelectObject(hdc, hpen);
3239 /* paint left edge */
3240 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3241 LineTo(hdc, rcClient.left, rcClient.bottom-1);
3243 /* paint top edge */
3244 MoveToEx(hdc, rcClient.left, rcClient.top, NULL);
3245 LineTo(hdc, rcClient.right, rcClient.top);
3247 hpen = CreatePen(PS_SOLID, 1, GetSysColor(COLOR_3DDKSHADOW));
3248 DeleteObject(SelectObject(hdc, hpen));
3250 /* paint right edge */
3251 MoveToEx(hdc, rcClient.right-1, rcClient.top, NULL);
3252 LineTo(hdc, rcClient.right-1, rcClient.bottom);
3254 /* paint bottom edge */
3255 MoveToEx(hdc, rcClient.left, rcClient.bottom-1, NULL);
3256 LineTo(hdc, rcClient.right, rcClient.bottom-1);
3258 DeleteObject(SelectObject(hdc, holdpen));
3259 DeleteObject(SelectObject(hdc, holdbrush));
3261 CALLPAINTHOOK(WM_PSD_MARGINRECT, &rcMargin);
3263 /* give text a bit of a space from the frame */
3264 rcMargin.left += 2;
3265 rcMargin.top += 2;
3266 rcMargin.right -= 2;
3267 rcMargin.bottom -= 2;
3269 /* if the space is too small then we make sure to not draw anything */
3270 rcMargin.left = min(rcMargin.left, rcMargin.right);
3271 rcMargin.top = min(rcMargin.top, rcMargin.bottom);
3273 CALLPAINTHOOK(WM_PSD_GREEKTEXTRECT, &rcMargin);
3276 EndPaint(hWnd, &ps);
3277 return FALSE;
3278 #undef CALLPAINTHOOK
3281 /***********************************************************************
3282 * PRINTDLG_PageDlgProcA
3283 * Message handler for PageSetupDlgA
3285 static INT_PTR CALLBACK
3286 PRINTDLG_PageDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3288 DEVMODEA *dm;
3289 PageSetupDataA *pda;
3290 INT_PTR res = FALSE;
3291 HWND hDrawWnd;
3293 if (uMsg == WM_INITDIALOG) { /*Init dialog*/
3294 pda = (PageSetupDataA*)lParam;
3295 pda->hDlg = hDlg; /* saving handle to main window to PageSetupDataA structure */
3297 hDrawWnd = GetDlgItem(hDlg, rct1);
3298 TRACE("set property to %p\n", pda);
3299 SetPropW(hDlg, pagesetupdlg_prop, pda);
3300 SetPropW(hDrawWnd, pagesetupdlg_prop, pda);
3301 GetWindowRect(hDrawWnd, &pda->rtDrawRect); /* Calculating rect in client coordinates where paper draws */
3302 ScreenToClient(hDlg, (LPPOINT)&pda->rtDrawRect);
3303 ScreenToClient(hDlg, (LPPOINT)(&pda->rtDrawRect.right));
3304 lpfnStaticWndProc = (WNDPROC)SetWindowLongPtrW(
3305 hDrawWnd,
3306 GWLP_WNDPROC,
3307 (ULONG_PTR)PRINTDLG_PagePaintProc);
3309 /* FIXME: Paint hook. Must it be at begin of initialization or at end? */
3310 res = TRUE;
3311 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3312 if (!pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pda->dlga))
3313 FIXME("Setup page hook failed?\n");
3316 /* if printer button disabled */
3317 if (pda->dlga->Flags & PSD_DISABLEPRINTER)
3318 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3319 /* if margin edit boxes disabled */
3320 if (pda->dlga->Flags & PSD_DISABLEMARGINS) {
3321 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3322 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3323 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3324 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3326 /* Set orientation radiobutton properly */
3327 if(pda->dlga->hDevMode)
3329 dm = GlobalLock(pda->dlga->hDevMode);
3330 if (dm->u1.s1.dmOrientation == DMORIENT_LANDSCAPE)
3331 CheckRadioButton(hDlg, rad1, rad2, rad2);
3332 else /* this is default if papersize is not set */
3333 CheckRadioButton(hDlg, rad1, rad2, rad1);
3334 GlobalUnlock(pda->dlga->hDevMode);
3337 /* if orientation disabled */
3338 if (pda->dlga->Flags & PSD_DISABLEORIENTATION) {
3339 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3340 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3343 /* We fill them out enabled or not */
3344 if (!(pda->dlga->Flags & PSD_MARGINS))
3346 /* default is 1 inch */
3347 DWORD size = _c_inch2size(pda->dlga,1000);
3348 pda->dlga->rtMargin.left = size;
3349 pda->dlga->rtMargin.top = size;
3350 pda->dlga->rtMargin.right = size;
3351 pda->dlga->rtMargin.bottom = size;
3353 update_margin_edits(hDlg, pda);
3355 /* if paper disabled */
3356 if (pda->dlga->Flags & PSD_DISABLEPAPER) {
3357 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3358 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3360 /* filling combos: printer, paper, source. selecting current printer (from DEVMODEA) */
3361 PRINTDLG_PS_ChangePrinterA(hDlg, pda);
3362 dm = GlobalLock(pda->dlga->hDevMode);
3363 if(dm){
3364 dm->u1.s1.dmDefaultSource = 15; /*FIXME: Automatic select. Does it always 15 at start? */
3365 pagesetup_papersizeA(pda->dlga, dm->u1.s1.dmPaperSize, &pda->dlga->ptPaperSize);
3366 GlobalUnlock(pda->dlga->hDevMode);
3367 if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) { /* Landscape orientation */
3368 DWORD tmp = pda->dlga->ptPaperSize.y;
3369 pda->dlga->ptPaperSize.y = pda->dlga->ptPaperSize.x;
3370 pda->dlga->ptPaperSize.x = tmp;
3372 } else
3373 WARN("GlobalLock(pda->dlga->hDevMode) fail? hDevMode=%p\n", pda->dlga->hDevMode);
3374 /* Drawing paper prev */
3375 PRINTDLG_PS_ChangePaperPrev(pda);
3376 return TRUE;
3377 } else {
3378 pda = GetPropW(hDlg, pagesetupdlg_prop);
3379 if (!pda) {
3380 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3381 return FALSE;
3383 if (pda->dlga->Flags & PSD_ENABLEPAGESETUPHOOK) {
3384 res = pda->dlga->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3385 if (res) return res;
3388 switch (uMsg) {
3389 case WM_COMMAND:
3390 return PRINTDLG_PS_WMCommandA(hDlg, wParam, lParam, pda);
3392 return FALSE;
3395 static INT_PTR CALLBACK
3396 PageDlgProcW(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
3398 PageSetupDataW *pdw;
3399 BOOL res = FALSE;
3401 if (uMsg==WM_INITDIALOG) {
3402 res = TRUE;
3403 pdw = (PageSetupDataW*)lParam;
3404 pdw->curdlg = *pdw->dlgw;
3405 SetPropW(hDlg, pagesetupdlg_prop, pdw);
3406 if (pdw->dlgw->Flags & PSD_ENABLEPAGESETUPHOOK) {
3407 res = pdw->dlgw->lpfnPageSetupHook(hDlg,uMsg,wParam,(LPARAM)pdw->dlgw);
3408 if (!res) {
3409 FIXME("Setup page hook failed?\n");
3410 res = TRUE;
3414 if (pdw->dlgw->Flags & PSD_ENABLEPAGEPAINTHOOK) {
3415 FIXME("PagePaintHook not yet implemented!\n");
3417 if (pdw->dlgw->Flags & PSD_DISABLEPRINTER)
3418 EnableWindow(GetDlgItem(hDlg, psh3), FALSE);
3419 if (pdw->dlgw->Flags & PSD_DISABLEMARGINS) {
3420 EnableWindow(GetDlgItem(hDlg, edt4), FALSE);
3421 EnableWindow(GetDlgItem(hDlg, edt5), FALSE);
3422 EnableWindow(GetDlgItem(hDlg, edt6), FALSE);
3423 EnableWindow(GetDlgItem(hDlg, edt7), FALSE);
3426 PRINTDLG_PS_ChangePrinterW(hDlg,pdw);
3428 if (pdw->dlgw->Flags & PSD_DISABLEORIENTATION) {
3429 EnableWindow(GetDlgItem(hDlg,rad1),FALSE);
3430 EnableWindow(GetDlgItem(hDlg,rad2),FALSE);
3432 /* We fill them out enabled or not */
3433 if (pdw->dlgw->Flags & PSD_MARGINS) {
3434 WCHAR str[100];
3435 _c_size2strW(pdw,pdw->dlgw->rtMargin.left,str);
3436 SetDlgItemTextW(hDlg,edt4,str);
3437 _c_size2strW(pdw,pdw->dlgw->rtMargin.top,str);
3438 SetDlgItemTextW(hDlg,edt5,str);
3439 _c_size2strW(pdw,pdw->dlgw->rtMargin.right,str);
3440 SetDlgItemTextW(hDlg,edt6,str);
3441 _c_size2strW(pdw,pdw->dlgw->rtMargin.bottom,str);
3442 SetDlgItemTextW(hDlg,edt7,str);
3443 } else {
3444 /* default is 1 inch */
3445 DWORD size = _c_inch2size((LPPAGESETUPDLGA)pdw->dlgw,1000);
3446 WCHAR str[20];
3447 _c_size2strW(pdw,size,str);
3448 SetDlgItemTextW(hDlg,edt4,str);
3449 SetDlgItemTextW(hDlg,edt5,str);
3450 SetDlgItemTextW(hDlg,edt6,str);
3451 SetDlgItemTextW(hDlg,edt7,str);
3454 if (pdw->dlgw->Flags & PSD_DISABLEPAPER) {
3455 EnableWindow(GetDlgItem(hDlg,cmb2),FALSE);
3456 EnableWindow(GetDlgItem(hDlg,cmb3),FALSE);
3459 return TRUE;
3460 } else {
3461 pdw = GetPropW(hDlg, pagesetupdlg_prop);
3462 if (!pdw) {
3463 WARN("__WINE_PAGESETUPDLGDATA prop not set?\n");
3464 return FALSE;
3466 if (pdw->dlgw->Flags & PSD_ENABLEPAGESETUPHOOK) {
3467 res = pdw->dlgw->lpfnPageSetupHook(hDlg,uMsg,wParam,lParam);
3468 if (res) return res;
3471 switch (uMsg) {
3472 case WM_COMMAND:
3473 return PRINTDLG_PS_WMCommandW(hDlg, wParam, lParam, pdw);
3475 return FALSE;
3478 /***********************************************************************
3479 * PageSetupDlgA (COMDLG32.@)
3481 * Displays the PAGE SETUP dialog box, which enables the user to specify
3482 * specific properties of a printed page such as
3483 * size, source, orientation and the width of the page margins.
3485 * PARAMS
3486 * setupdlg [IO] PAGESETUPDLGA struct
3488 * RETURNS
3489 * TRUE if the user pressed the OK button
3490 * FALSE if the user cancelled the window or an error occurred
3492 * NOTES
3493 * The values of hDevMode and hDevNames are filled on output and can be
3494 * changed in PAGESETUPDLG when they are passed in PageSetupDlg.
3498 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
3499 HGLOBAL hDlgTmpl;
3500 LPVOID ptr;
3501 BOOL bRet;
3502 PageSetupDataA *pda;
3504 if (setupdlg == NULL) {
3505 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
3506 return FALSE;
3509 /* TRACE */
3510 if(TRACE_ON(commdlg)) {
3511 char flagstr[1000] = "";
3512 const struct pd_flags *pflag = psd_flags;
3513 for( ; pflag->name; pflag++) {
3514 if(setupdlg->Flags & pflag->flag) {
3515 strcat(flagstr, pflag->name);
3516 strcat(flagstr, "|");
3519 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3520 "hinst %p, flags %08x (%s)\n",
3521 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3522 setupdlg->hDevNames,
3523 setupdlg->hInstance, setupdlg->Flags, flagstr);
3526 /* Checking setupdlg structure */
3527 if(setupdlg->lStructSize != sizeof(PAGESETUPDLGA)) {
3528 COMDLG32_SetCommDlgExtendedError(CDERR_STRUCTSIZE);
3529 return FALSE;
3531 if ((setupdlg->Flags & PSD_ENABLEPAGEPAINTHOOK) &&
3532 (setupdlg->lpfnPagePaintHook == NULL)) {
3533 COMDLG32_SetCommDlgExtendedError(CDERR_NOHOOK);
3534 return FALSE;
3537 if(!(setupdlg->Flags & (PSD_INTHOUSANDTHSOFINCHES | PSD_INHUNDREDTHSOFMILLIMETERS)))
3538 setupdlg->Flags |= is_default_metric() ?
3539 PSD_INHUNDREDTHSOFMILLIMETERS : PSD_INTHOUSANDTHSOFINCHES;
3541 /* Initialize default printer struct. If no printer device info is specified
3542 retrieve the default printer data. */
3543 if (!setupdlg->hDevMode || !setupdlg->hDevNames)
3545 PRINTDLGA pdlg;
3546 memset(&pdlg, 0, sizeof(pdlg));
3547 pdlg.lStructSize = sizeof(pdlg);
3548 pdlg.Flags = PD_RETURNDEFAULT;
3549 bRet = PrintDlgA(&pdlg);
3550 if (!bRet)
3552 if (!(setupdlg->Flags & PSD_NOWARNING)) {
3553 WCHAR errstr[256];
3554 LoadStringW(COMDLG32_hInstance, PD32_NO_DEFAULT_PRINTER, errstr, 255);
3555 MessageBoxW(setupdlg->hwndOwner, errstr, 0, MB_OK | MB_ICONERROR);
3557 return FALSE;
3559 setupdlg->hDevMode = pdlg.hDevMode;
3560 setupdlg->hDevNames = pdlg.hDevNames;
3563 /* short cut exit, just return default values */
3564 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3565 DEVMODEA *dm;
3566 dm = GlobalLock(setupdlg->hDevMode);
3567 pagesetup_papersizeA(setupdlg, dm->u1.s1.dmPaperSize, &setupdlg->ptPaperSize);
3568 GlobalUnlock(setupdlg->hDevMode);
3569 return TRUE;
3572 /* get dialog template */
3573 hDlgTmpl = PRINTDLG_GetPGSTemplateA(setupdlg);
3574 if (!hDlgTmpl) {
3575 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3576 return FALSE;
3578 ptr = LockResource( hDlgTmpl );
3579 if (!ptr) {
3580 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3581 return FALSE;
3584 pda = HeapAlloc(GetProcessHeap(),0,sizeof(*pda));
3585 pda->dlga = setupdlg;
3587 bRet = (0<DialogBoxIndirectParamW(
3588 setupdlg->hInstance,
3589 ptr,
3590 setupdlg->hwndOwner,
3591 PRINTDLG_PageDlgProcA,
3592 (LPARAM)pda)
3595 HeapFree(GetProcessHeap(),0,pda);
3596 return bRet;
3598 /***********************************************************************
3599 * PageSetupDlgW (COMDLG32.@)
3601 * See PageSetupDlgA.
3603 BOOL WINAPI PageSetupDlgW(LPPAGESETUPDLGW setupdlg) {
3604 HGLOBAL hDlgTmpl;
3605 LPVOID ptr;
3606 BOOL bRet;
3607 PageSetupDataW *pdw;
3608 PRINTDLGW pdlg;
3610 FIXME("Unicode implementation is not done yet\n");
3612 if (setupdlg == NULL) {
3613 COMDLG32_SetCommDlgExtendedError(CDERR_INITIALIZATION);
3614 return FALSE;
3617 if(TRACE_ON(commdlg)) {
3618 char flagstr[1000] = "";
3619 const struct pd_flags *pflag = psd_flags;
3620 for( ; pflag->name; pflag++) {
3621 if(setupdlg->Flags & pflag->flag) {
3622 strcat(flagstr, pflag->name);
3623 strcat(flagstr, "|");
3626 TRACE("(%p): hwndOwner = %p, hDevMode = %p, hDevNames = %p\n"
3627 "hinst %p, flags %08x (%s)\n",
3628 setupdlg, setupdlg->hwndOwner, setupdlg->hDevMode,
3629 setupdlg->hDevNames,
3630 setupdlg->hInstance, setupdlg->Flags, flagstr);
3633 /* Initialize default printer struct. If no printer device info is specified
3634 retrieve the default printer data. */
3635 memset(&pdlg,0,sizeof(pdlg));
3636 pdlg.lStructSize = sizeof(pdlg);
3637 if (setupdlg->hDevMode && setupdlg->hDevNames) {
3638 pdlg.hDevMode = setupdlg->hDevMode;
3639 pdlg.hDevNames = setupdlg->hDevNames;
3640 } else {
3641 pdlg.Flags = PD_RETURNDEFAULT;
3642 bRet = PrintDlgW(&pdlg);
3643 if (!bRet){
3644 if (!(setupdlg->Flags & PSD_NOWARNING)) {
3645 WCHAR errstr[256];
3646 LoadStringW(COMDLG32_hInstance, PD32_NO_DEFAULT_PRINTER, errstr, 255);
3647 MessageBoxW(setupdlg->hwndOwner, errstr, 0, MB_OK | MB_ICONERROR);
3649 return FALSE;
3653 /* short cut exit, just return default values */
3654 if (setupdlg->Flags & PSD_RETURNDEFAULT) {
3655 static const WCHAR a4[] = {'A','4',0};
3656 setupdlg->hDevMode = pdlg.hDevMode;
3657 setupdlg->hDevNames = pdlg.hDevNames;
3658 /* FIXME: Just return "A4" for now. */
3659 PRINTDLG_PaperSizeW(&pdlg,a4,&setupdlg->ptPaperSize);
3660 setupdlg->ptPaperSize.x=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.x);
3661 setupdlg->ptPaperSize.y=_c_10mm2size((LPPAGESETUPDLGA)setupdlg,setupdlg->ptPaperSize.y);
3662 return TRUE;
3664 hDlgTmpl = PRINTDLG_GetPGSTemplateW(setupdlg);
3665 if (!hDlgTmpl) {
3666 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3667 return FALSE;
3669 ptr = LockResource( hDlgTmpl );
3670 if (!ptr) {
3671 COMDLG32_SetCommDlgExtendedError(CDERR_LOADRESFAILURE);
3672 return FALSE;
3674 pdw = HeapAlloc(GetProcessHeap(),0,sizeof(*pdw));
3675 pdw->dlgw = setupdlg;
3676 pdw->pdlg = pdlg;
3678 bRet = (0<DialogBoxIndirectParamW(
3679 setupdlg->hInstance,
3680 ptr,
3681 setupdlg->hwndOwner,
3682 PageDlgProcW,
3683 (LPARAM)pdw)
3685 return bRet;
3688 /***********************************************************************
3689 * PrintDlgExA (COMDLG32.@)
3691 * See PrintDlgExW.
3693 * BUGS
3694 * Only a Stub
3697 HRESULT WINAPI PrintDlgExA(LPPRINTDLGEXA lppd)
3700 FIXME("(%p) stub\n", lppd);
3701 if ((lppd == NULL) || (lppd->lStructSize != sizeof(PRINTDLGEXA))) {
3702 return E_INVALIDARG;
3705 if (!IsWindow(lppd->hwndOwner)) {
3706 return E_HANDLE;
3709 return E_NOTIMPL;
3712 /***********************************************************************
3713 * PrintDlgExW (COMDLG32.@)
3715 * Display the property sheet style PRINT dialog box
3717 * PARAMS
3718 * lppd [IO] ptr to PRINTDLGEX struct
3720 * RETURNS
3721 * Success: S_OK
3722 * Failure: One of the following COM error codes:
3723 * E_OUTOFMEMORY Insufficient memory.
3724 * E_INVALIDARG One or more arguments are invalid.
3725 * E_POINTER Invalid pointer.
3726 * E_HANDLE Invalid handle.
3727 * E_FAIL Unspecified error.
3729 * NOTES
3730 * This Dialog enables the user to specify specific properties of the print job.
3731 * The property sheet can also have additional application-specific and
3732 * driver-specific property pages.
3734 * BUGS
3735 * Not fully implemented
3738 HRESULT WINAPI PrintDlgExW(LPPRINTDLGEXW lppd)
3740 DWORD ret = E_FAIL;
3741 LPVOID ptr;
3743 FIXME("(%p) not fully implemented\n", lppd);
3745 if ((lppd == NULL) || (lppd->lStructSize != sizeof(PRINTDLGEXW))) {
3746 return E_INVALIDARG;
3749 if (!IsWindow(lppd->hwndOwner)) {
3750 return E_HANDLE;
3753 if (lppd->Flags & PD_RETURNDEFAULT) {
3754 PRINTER_INFO_2W *pbuf;
3755 DRIVER_INFO_2W *dbuf;
3756 HANDLE hprn;
3757 DWORD needed = 1024;
3758 BOOL bRet;
3760 if (lppd->hDevMode || lppd->hDevNames) {
3761 WARN("hDevMode or hDevNames non-zero for PD_RETURNDEFAULT\n");
3762 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
3763 return E_INVALIDARG;
3765 if (!PRINTDLG_OpenDefaultPrinter(&hprn)) {
3766 WARN("Can't find default printer\n");
3767 COMDLG32_SetCommDlgExtendedError(PDERR_NODEFAULTPRN);
3768 return E_FAIL;
3771 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
3772 bRet = GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
3773 if (!bRet && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
3774 HeapFree(GetProcessHeap(), 0, pbuf);
3775 pbuf = HeapAlloc(GetProcessHeap(), 0, needed);
3776 bRet = GetPrinterW(hprn, 2, (LPBYTE)pbuf, needed, &needed);
3778 if (!bRet) {
3779 HeapFree(GetProcessHeap(), 0, pbuf);
3780 ClosePrinter(hprn);
3781 return E_FAIL;
3784 needed = 1024;
3785 dbuf = HeapAlloc(GetProcessHeap(), 0, needed);
3786 bRet = GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed);
3787 if (!bRet && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) {
3788 HeapFree(GetProcessHeap(), 0, dbuf);
3789 dbuf = HeapAlloc(GetProcessHeap(), 0, needed);
3790 bRet = GetPrinterDriverW(hprn, NULL, 3, (LPBYTE)dbuf, needed, &needed);
3792 if (!bRet) {
3793 ERR("GetPrinterDriverW failed, last error %d, fix your config for printer %s!\n",
3794 GetLastError(), debugstr_w(pbuf->pPrinterName));
3795 HeapFree(GetProcessHeap(), 0, dbuf);
3796 HeapFree(GetProcessHeap(), 0, pbuf);
3797 COMDLG32_SetCommDlgExtendedError(PDERR_RETDEFFAILURE);
3798 ClosePrinter(hprn);
3799 return E_FAIL;
3801 ClosePrinter(hprn);
3803 PRINTDLG_CreateDevNamesW(&(lppd->hDevNames),
3804 dbuf->pDriverPath,
3805 pbuf->pPrinterName,
3806 pbuf->pPortName);
3807 lppd->hDevMode = GlobalAlloc(GMEM_MOVEABLE, pbuf->pDevMode->dmSize +
3808 pbuf->pDevMode->dmDriverExtra);
3809 if (lppd->hDevMode) {
3810 ptr = GlobalLock(lppd->hDevMode);
3811 if (ptr) {
3812 memcpy(ptr, pbuf->pDevMode, pbuf->pDevMode->dmSize +
3813 pbuf->pDevMode->dmDriverExtra);
3814 GlobalUnlock(lppd->hDevMode);
3815 ret = S_OK;
3818 HeapFree(GetProcessHeap(), 0, pbuf);
3819 HeapFree(GetProcessHeap(), 0, dbuf);
3821 return ret;
3824 return E_NOTIMPL;