Updated (prepare|unprepare)header functions to allow correct callback
[wine/testsucceed.git] / dlls / commdlg / printdlg.c
blob57112d2e4cd4a7b4a326fae1f6089dc8600f1ad0
1 /*
2 * COMMDLG - Print Dialog
4 * Copyright 1994 Martin Ayotte
5 * Copyright 1996 Albrecht Kleine
6 * Copyright 1999 Klaas van Gend
7 */
9 #include <ctype.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include "winbase.h"
13 #include "wine/winbase16.h"
14 #include "wine/winuser16.h"
15 #include "win.h"
16 #include "message.h"
17 #include "commdlg.h"
18 #include "resource.h"
19 #include "dialog.h"
20 #include "dlgs.h"
21 #include "module.h"
22 #include "debug.h"
23 #include "winproc.h"
24 #include "cderr.h"
26 /***********************************************************************
27 * PrintDlg16 (COMMDLG.20)
29 BOOL16 WINAPI PrintDlg16( SEGPTR printdlg )
31 HANDLE16 hInst;
32 BOOL16 bRet = FALSE;
33 LPCVOID template;
34 HWND hwndDialog;
35 LPPRINTDLG16 lpPrint = (LPPRINTDLG16)PTR_SEG_TO_LIN(printdlg);
37 TRACE(commdlg,"(%p) -- Flags=%08lX\n", lpPrint, lpPrint->Flags );
39 if (lpPrint->Flags & PD_RETURNDEFAULT)
40 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
41 return TRUE;
43 if (lpPrint->Flags & PD_PRINTSETUP)
44 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT_SETUP );
45 else
46 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT );
48 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
49 hwndDialog = DIALOG_CreateIndirect( hInst, template, TRUE,
50 lpPrint->hwndOwner,
51 (DLGPROC16)((lpPrint->Flags & PD_PRINTSETUP) ?
52 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
53 MODULE_GetWndProcEntry16("PrintDlgProc")),
54 printdlg, WIN_PROC_16 );
55 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpPrint->hwndOwner);
56 return bRet;
61 /***********************************************************************
62 * PrintDlgA (COMDLG32.17)
64 * Displays the the PRINT dialog box, which enables the user to specify
65 * specific properties of the print job.
67 * (Note: according to the MS Platform SDK, this call was in the past
68 * also used to display some PRINT SETUP dialog. As this is superseded
69 * by PageSetupDlg, this now results in an error!)
71 * RETURNS
72 * nonzero if the user pressed the OK button
73 * zero if the user cancelled the window or an error occurred
75 * BUGS
76 * The function is a stub only, returning TRUE to allow more programs
77 * to function.
79 BOOL WINAPI PrintDlgA(
80 LPPRINTDLGA lppd /* ptr to PRINTDLG32 struct */
83 /* My implementing strategy:
85 * step 1: display the dialog and implement the layout-flags
86 * step 2: enter valid information in the fields (e.g. real printers)
87 * step 3: fix the RETURN-TRUE-ALWAYS Fixme by checking lppd->Flags for
88 * PD_RETURNDEFAULT
89 * step 4: implement all other specs
90 * step 5: allow customisation of the dialog box
92 * current implementation is in step 1.
93 */
95 HWND hwndDialog;
96 BOOL bRet = FALSE;
97 LPCVOID ptr = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT32 );
98 HINSTANCE hInst = WIN_GetWindowInstance( lppd->hwndOwner );
100 FIXME(commdlg, "KVG (%p): stub\n", lppd);
103 * FIXME : Should respond to TEMPLATE and HOOK flags here
104 * For now, only the standard dialog works.
106 if (lppd->Flags & (PD_ENABLEPRINTHOOK | PD_ENABLEPRINTTEMPLATE |
107 PD_ENABLEPRINTTEMPLATEHANDLE | PD_ENABLESETUPHOOK |
108 PD_ENABLESETUPTEMPLATE|PD_ENABLESETUPTEMPLATEHANDLE))
109 FIXME(commdlg, ": unimplemented flag (ignored)\n");
112 * if lppd->Flags PD_RETURNDEFAULT is specified, the PrintDlg function
113 * does not display the dialog box, but returns with valid entries
114 * for hDevMode and hDevNames .
116 * Currently the flag is recognised, but we return empty hDevMode and
117 * and hDevNames. This will be fixed when I am in step 3.
119 if (lppd->Flags & PD_RETURNDEFAULT)
121 WARN(commdlg, ": PrintDlg was requested to return printer info only."
122 "\n The return value currently does NOT provide these.\n");
123 COMDLG32_SetCommDlgExtendedError(PDERR_NODEVICES);
124 /* return TRUE, thus never checked! */
125 return(TRUE);
128 if (lppd->Flags & PD_PRINTSETUP)
130 FIXME(commdlg, ": PrintDlg was requested to display PrintSetup box.\n");
131 COMDLG32_SetCommDlgExtendedError(PDERR_INITFAILURE);
132 return(FALSE);
135 hwndDialog= DIALOG_CreateIndirect(hInst, ptr, TRUE, lppd->hwndOwner,
136 (DLGPROC16)PrintDlgProcA, (LPARAM)lppd, WIN_PROC_32A );
137 if (hwndDialog)
138 bRet = DIALOG_DoDialogBox(hwndDialog, lppd->hwndOwner);
139 return bRet;
146 /***********************************************************************
147 * PrintDlg32W (COMDLG32.18)
149 BOOL WINAPI PrintDlgW( LPPRINTDLGW printdlg )
151 FIXME(commdlg, "A really empty stub\n" );
152 return FALSE;
157 /***********************************************************************
158 * PRINTDLG_WMInitDialog [internal]
160 LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
161 LPPRINTDLGA lppd)
163 SetWindowLongA(hDlg, DWL_USER, lParam);
164 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
166 if (lppd->lStructSize != sizeof(PRINTDLGA))
168 FIXME(commdlg,"structure size failure !!!\n");
169 /* EndDialog (hDlg, 0);
170 return FALSE;
171 */ }
173 /* Flag processing to set the according buttons on/off and
174 * Initialise the various values
177 /* Print range (All/Range/Selection) */
178 if (lppd->nMinPage == lppd->nMaxPage)
179 lppd->Flags &= ~PD_NOPAGENUMS;
180 /* FIXME: I allow more freedom than either Win95 or WinNT,
181 * as officially we should return error if
182 * ToPage or FromPage is out-of-range
184 if (lppd->nToPage < lppd->nMinPage)
185 lppd->nToPage = lppd->nMinPage;
186 if (lppd->nToPage > lppd->nMaxPage)
187 lppd->nToPage = lppd->nMaxPage;
188 if (lppd->nFromPage < lppd->nMinPage)
189 lppd->nFromPage = lppd->nMinPage;
190 if (lppd->nFromPage > lppd->nMaxPage)
191 lppd->nFromPage = lppd->nMaxPage;
192 SetDlgItemInt(hDlg, edt2, lppd->nFromPage, FALSE);
193 SetDlgItemInt(hDlg, edt3, lppd->nToPage, FALSE);
194 CheckRadioButton(hDlg, rad1, rad3, rad1);
195 if (lppd->Flags & PD_NOSELECTION)
196 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
197 else
198 if (lppd->Flags & PD_SELECTION)
199 CheckRadioButton(hDlg, rad1, rad3, rad3);
200 if (lppd->Flags & PD_NOPAGENUMS)
202 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
203 EnableWindow(GetDlgItem(hDlg, stc10),FALSE);
204 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
205 EnableWindow(GetDlgItem(hDlg, stc11),FALSE);
206 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
208 else
210 if (lppd->Flags & PD_PAGENUMS)
211 CheckRadioButton(hDlg, rad1, rad3, rad2);
213 /* FIXME: in Win95, the radiobutton "All" is displayed as
214 * "Print all xxx pages"... This is not done here (yet?)
217 /* Collate pages */
218 if (lppd->Flags & PD_COLLATE)
219 FIXME(commdlg, "PD_COLLATE not implemented yet\n");
221 /* print to file */
222 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
223 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
224 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
225 if (lppd->Flags & PD_HIDEPRINTTOFILE)
226 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
228 /* status */
230 TRACE(commdlg, "succesful!\n");
231 return TRUE;
235 /***********************************************************************
236 * PRINTDLG_ValidateAndDuplicateSettings [internal]
238 BOOL PRINTDLG_ValidateAndDuplicateSettings(HWND hDlg, LPPRINTDLGA lppd)
240 WORD nToPage;
241 WORD nFromPage;
242 char TempBuffer[256];
244 /* check whether nFromPage and nToPage are within range defined by
245 * nMinPage and nMaxPage
247 /* FIXMNo checking on rad2 is performed now, because IsDlgButtonCheck
248 * currently doesn't seem to know a state BST_CHECKED
250 /* if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) */
252 nFromPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
253 nToPage = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
254 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
255 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage)
257 FIXME(commdlg, "The MessageBox is not internationalised.");
258 sprintf(TempBuffer, "This value lies not within Page range\n"
259 "Please enter a value between %d and %d",
260 lppd->nMinPage, lppd->nMaxPage);
261 MessageBoxA(hDlg, TempBuffer, "Print", MB_OK | MB_ICONWARNING);
262 return(FALSE);
264 lppd->nFromPage = nFromPage;
265 lppd->nToPage = nToPage;
268 return(TRUE);
273 /***********************************************************************
274 * PRINTDLG_WMCommand [internal]
276 static LRESULT PRINTDLG_WMCommand(HWND hDlg, WPARAM wParam,
277 LPARAM lParam, LPPRINTDLGA lppd)
279 switch (wParam)
281 case IDOK:
282 if (PRINTDLG_ValidateAndDuplicateSettings(hDlg, lppd) != TRUE)
283 return(FALSE);
284 MessageBoxA(hDlg, "OK was hit!", NULL, MB_OK);
285 DestroyWindow(hDlg);
286 return(TRUE);
287 case IDCANCEL:
288 MessageBoxA(hDlg, "CANCEL was hit!", NULL, MB_OK);
289 EndDialog(hDlg, FALSE);
290 /* DestroyWindow(hDlg); */
291 return(FALSE);
293 return FALSE;
298 /***********************************************************************
299 * PrintDlgProcA [internal]
301 LRESULT WINAPI PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
302 LPARAM lParam)
304 LPPRINTDLGA lppd;
305 LRESULT res=FALSE;
306 if (uMsg!=WM_INITDIALOG)
308 lppd=(LPPRINTDLGA)GetWindowLongA(hDlg, DWL_USER);
309 if (!lppd)
310 return FALSE;
312 else
314 lppd=(LPPRINTDLGA)lParam;
315 if (!PRINTDLG_WMInitDialog(hDlg, wParam, lParam, lppd))
317 TRACE(commdlg, "PRINTDLG_WMInitDialog returned FALSE\n");
318 return FALSE;
320 MessageBoxA(hDlg,"Warning: this dialog has no functionality yet!",
321 NULL, MB_OK);
323 switch (uMsg)
325 case WM_COMMAND:
326 return PRINTDLG_WMCommand(hDlg, wParam, lParam, lppd);
327 case WM_DESTROY:
328 return FALSE;
331 return res;
340 /***********************************************************************
341 * PrintDlgProc16 (COMMDLG.21)
343 LRESULT WINAPI PrintDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
344 LPARAM lParam)
346 switch (wMsg)
348 case WM_INITDIALOG:
349 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
350 ShowWindow16(hWnd, SW_SHOWNORMAL);
351 return (TRUE);
352 case WM_COMMAND:
353 switch (wParam)
355 case IDOK:
356 EndDialog(hWnd, TRUE);
357 return(TRUE);
358 case IDCANCEL:
359 EndDialog(hWnd, FALSE);
360 return(TRUE);
362 return(FALSE);
364 return FALSE;
368 /***********************************************************************
369 * PrintSetupDlgProc (COMMDLG.22)
371 LRESULT WINAPI PrintSetupDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
372 LPARAM lParam)
374 switch (wMsg)
376 case WM_INITDIALOG:
377 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
378 ShowWindow16(hWnd, SW_SHOWNORMAL);
379 return (TRUE);
380 case WM_COMMAND:
381 switch (wParam) {
382 case IDOK:
383 EndDialog(hWnd, TRUE);
384 return(TRUE);
385 case IDCANCEL:
386 EndDialog(hWnd, FALSE);
387 return(TRUE);
389 return(FALSE);
391 return FALSE;
397 /***********************************************************************
398 * PageSetupDlgA (COMDLG32.15)
400 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
401 FIXME(commdlg,"(%p), stub!\n",setupdlg);
402 return FALSE;