Authors: Chris Morgan <cmorgan@wpi.edu>, James Abbatiello <abbejy@wpi.edu>
[wine/multimedia.git] / dlls / commdlg / printdlg.c
blob2af55163b5bcb9a198b6d0dc1a95e048f4322980
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 DEFAULT_DEBUG_CHANNEL(commdlg)
28 /***********************************************************************
29 * PrintDlg16 (COMMDLG.20)
31 BOOL16 WINAPI PrintDlg16( SEGPTR printdlg )
33 HANDLE16 hInst;
34 BOOL16 bRet = FALSE;
35 LPCVOID template;
36 HWND hwndDialog;
37 LPPRINTDLG16 lpPrint = (LPPRINTDLG16)PTR_SEG_TO_LIN(printdlg);
39 TRACE(commdlg,"(%p) -- Flags=%08lX\n", lpPrint, lpPrint->Flags );
41 if (lpPrint->Flags & PD_RETURNDEFAULT)
42 /* FIXME: should fill lpPrint->hDevMode and lpPrint->hDevNames here */
43 return TRUE;
45 if (lpPrint->Flags & PD_PRINTSETUP)
46 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT_SETUP );
47 else
48 template = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT );
50 hInst = WIN_GetWindowInstance( lpPrint->hwndOwner );
51 hwndDialog = DIALOG_CreateIndirect( hInst, template, TRUE,
52 lpPrint->hwndOwner,
53 (DLGPROC16)((lpPrint->Flags & PD_PRINTSETUP) ?
54 MODULE_GetWndProcEntry16("PrintSetupDlgProc") :
55 MODULE_GetWndProcEntry16("PrintDlgProc")),
56 printdlg, WIN_PROC_16 );
57 if (hwndDialog) bRet = DIALOG_DoDialogBox( hwndDialog, lpPrint->hwndOwner);
58 return bRet;
63 /***********************************************************************
64 * PrintDlgA (COMDLG32.17)
66 * Displays the the PRINT dialog box, which enables the user to specify
67 * specific properties of the print job.
69 * (Note: according to the MS Platform SDK, this call was in the past
70 * also used to display some PRINT SETUP dialog. As this is superseded
71 * by PageSetupDlg, this now results in an error!)
73 * RETURNS
74 * nonzero if the user pressed the OK button
75 * zero if the user cancelled the window or an error occurred
77 * BUGS
78 * The function is a stub only, returning TRUE to allow more programs
79 * to function.
81 BOOL WINAPI PrintDlgA(
82 LPPRINTDLGA lppd /* ptr to PRINTDLG32 struct */
85 /* My implementing strategy:
87 * step 1: display the dialog and implement the layout-flags
88 * step 2: enter valid information in the fields (e.g. real printers)
89 * step 3: fix the RETURN-TRUE-ALWAYS Fixme by checking lppd->Flags for
90 * PD_RETURNDEFAULT
91 * step 4: implement all other specs
92 * step 5: allow customisation of the dialog box
94 * current implementation is in step 1.
95 */
97 HWND hwndDialog;
98 BOOL bRet = FALSE;
99 LPCVOID ptr = SYSRES_GetResPtr( SYSRES_DIALOG_PRINT32 );
100 HINSTANCE hInst = WIN_GetWindowInstance( lppd->hwndOwner );
102 FIXME(commdlg, "KVG (%p): stub\n", lppd);
105 * FIXME : Should respond to TEMPLATE and HOOK flags here
106 * For now, only the standard dialog works.
108 if (lppd->Flags & (PD_ENABLEPRINTHOOK | PD_ENABLEPRINTTEMPLATE |
109 PD_ENABLEPRINTTEMPLATEHANDLE | PD_ENABLESETUPHOOK |
110 PD_ENABLESETUPTEMPLATE|PD_ENABLESETUPTEMPLATEHANDLE))
111 FIXME(commdlg, ": unimplemented flag (ignored)\n");
114 * if lppd->Flags PD_RETURNDEFAULT is specified, the PrintDlg function
115 * does not display the dialog box, but returns with valid entries
116 * for hDevMode and hDevNames .
118 * Currently the flag is recognised, but we return empty hDevMode and
119 * and hDevNames. This will be fixed when I am in step 3.
121 if (lppd->Flags & PD_RETURNDEFAULT)
123 WARN(commdlg, ": PrintDlg was requested to return printer info only."
124 "\n The return value currently does NOT provide these.\n");
125 COMDLG32_SetCommDlgExtendedError(PDERR_NODEVICES);
126 /* return TRUE, thus never checked! */
127 return(TRUE);
130 if (lppd->Flags & PD_PRINTSETUP)
132 FIXME(commdlg, ": PrintDlg was requested to display PrintSetup box.\n");
133 COMDLG32_SetCommDlgExtendedError(PDERR_INITFAILURE);
134 return(FALSE);
137 hwndDialog= DIALOG_CreateIndirect(hInst, ptr, TRUE, lppd->hwndOwner,
138 (DLGPROC16)PrintDlgProcA, (LPARAM)lppd, WIN_PROC_32A );
139 if (hwndDialog)
140 bRet = DIALOG_DoDialogBox(hwndDialog, lppd->hwndOwner);
141 return bRet;
148 /***********************************************************************
149 * PrintDlg32W (COMDLG32.18)
151 BOOL WINAPI PrintDlgW( LPPRINTDLGW printdlg )
153 FIXME(commdlg, "A really empty stub\n" );
154 return FALSE;
159 /***********************************************************************
160 * PRINTDLG_WMInitDialog [internal]
162 LRESULT PRINTDLG_WMInitDialog(HWND hDlg, WPARAM wParam, LPARAM lParam,
163 LPPRINTDLGA lppd)
165 SetWindowLongA(hDlg, DWL_USER, lParam);
166 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
168 if (lppd->lStructSize != sizeof(PRINTDLGA))
170 FIXME(commdlg,"structure size failure !!!\n");
171 /* EndDialog (hDlg, 0);
172 return FALSE;
173 */ }
175 /* Flag processing to set the according buttons on/off and
176 * Initialise the various values
179 /* Print range (All/Range/Selection) */
180 if (lppd->nMinPage == lppd->nMaxPage)
181 lppd->Flags &= ~PD_NOPAGENUMS;
182 /* FIXME: I allow more freedom than either Win95 or WinNT,
183 * as officially we should return error if
184 * ToPage or FromPage is out-of-range
186 if (lppd->nToPage < lppd->nMinPage)
187 lppd->nToPage = lppd->nMinPage;
188 if (lppd->nToPage > lppd->nMaxPage)
189 lppd->nToPage = lppd->nMaxPage;
190 if (lppd->nFromPage < lppd->nMinPage)
191 lppd->nFromPage = lppd->nMinPage;
192 if (lppd->nFromPage > lppd->nMaxPage)
193 lppd->nFromPage = lppd->nMaxPage;
194 SetDlgItemInt(hDlg, edt2, lppd->nFromPage, FALSE);
195 SetDlgItemInt(hDlg, edt3, lppd->nToPage, FALSE);
196 CheckRadioButton(hDlg, rad1, rad3, rad1);
197 if (lppd->Flags & PD_NOSELECTION)
198 EnableWindow(GetDlgItem(hDlg, rad3), FALSE);
199 else
200 if (lppd->Flags & PD_SELECTION)
201 CheckRadioButton(hDlg, rad1, rad3, rad3);
202 if (lppd->Flags & PD_NOPAGENUMS)
204 EnableWindow(GetDlgItem(hDlg, rad2), FALSE);
205 EnableWindow(GetDlgItem(hDlg, stc10),FALSE);
206 EnableWindow(GetDlgItem(hDlg, edt2), FALSE);
207 EnableWindow(GetDlgItem(hDlg, stc11),FALSE);
208 EnableWindow(GetDlgItem(hDlg, edt3), FALSE);
210 else
212 if (lppd->Flags & PD_PAGENUMS)
213 CheckRadioButton(hDlg, rad1, rad3, rad2);
215 /* FIXME: in Win95, the radiobutton "All" is displayed as
216 * "Print all xxx pages"... This is not done here (yet?)
219 /* Collate pages */
220 if (lppd->Flags & PD_COLLATE)
221 FIXME(commdlg, "PD_COLLATE not implemented yet\n");
223 /* print to file */
224 CheckDlgButton(hDlg, chx1, (lppd->Flags & PD_PRINTTOFILE) ? 1 : 0);
225 if (lppd->Flags & PD_DISABLEPRINTTOFILE)
226 EnableWindow(GetDlgItem(hDlg, chx1), FALSE);
227 if (lppd->Flags & PD_HIDEPRINTTOFILE)
228 ShowWindow(GetDlgItem(hDlg, chx1), SW_HIDE);
230 /* status */
232 TRACE(commdlg, "succesful!\n");
233 return TRUE;
237 /***********************************************************************
238 * PRINTDLG_ValidateAndDuplicateSettings [internal]
240 BOOL PRINTDLG_ValidateAndDuplicateSettings(HWND hDlg, LPPRINTDLGA lppd)
242 WORD nToPage;
243 WORD nFromPage;
244 char TempBuffer[256];
246 /* check whether nFromPage and nToPage are within range defined by
247 * nMinPage and nMaxPage
249 /* FIXMNo checking on rad2 is performed now, because IsDlgButtonCheck
250 * currently doesn't seem to know a state BST_CHECKED
252 /* if (IsDlgButtonChecked(hDlg, rad2) == BST_CHECKED) */
254 nFromPage = GetDlgItemInt(hDlg, edt2, NULL, FALSE);
255 nToPage = GetDlgItemInt(hDlg, edt3, NULL, FALSE);
256 if (nFromPage < lppd->nMinPage || nFromPage > lppd->nMaxPage ||
257 nToPage < lppd->nMinPage || nToPage > lppd->nMaxPage)
259 FIXME(commdlg, "The MessageBox is not internationalised.");
260 sprintf(TempBuffer, "This value lies not within Page range\n"
261 "Please enter a value between %d and %d",
262 lppd->nMinPage, lppd->nMaxPage);
263 MessageBoxA(hDlg, TempBuffer, "Print", MB_OK | MB_ICONWARNING);
264 return(FALSE);
266 lppd->nFromPage = nFromPage;
267 lppd->nToPage = nToPage;
270 return(TRUE);
275 /***********************************************************************
276 * PRINTDLG_WMCommand [internal]
278 static LRESULT PRINTDLG_WMCommand(HWND hDlg, WPARAM wParam,
279 LPARAM lParam, LPPRINTDLGA lppd)
281 switch (wParam)
283 case IDOK:
284 if (PRINTDLG_ValidateAndDuplicateSettings(hDlg, lppd) != TRUE)
285 return(FALSE);
286 MessageBoxA(hDlg, "OK was hit!", NULL, MB_OK);
287 DestroyWindow(hDlg);
288 return(TRUE);
289 case IDCANCEL:
290 MessageBoxA(hDlg, "CANCEL was hit!", NULL, MB_OK);
291 EndDialog(hDlg, FALSE);
292 /* DestroyWindow(hDlg); */
293 return(FALSE);
295 return FALSE;
300 /***********************************************************************
301 * PrintDlgProcA [internal]
303 LRESULT WINAPI PrintDlgProcA(HWND hDlg, UINT uMsg, WPARAM wParam,
304 LPARAM lParam)
306 LPPRINTDLGA lppd;
307 LRESULT res=FALSE;
308 if (uMsg!=WM_INITDIALOG)
310 lppd=(LPPRINTDLGA)GetWindowLongA(hDlg, DWL_USER);
311 if (!lppd)
312 return FALSE;
314 else
316 lppd=(LPPRINTDLGA)lParam;
317 if (!PRINTDLG_WMInitDialog(hDlg, wParam, lParam, lppd))
319 TRACE(commdlg, "PRINTDLG_WMInitDialog returned FALSE\n");
320 return FALSE;
322 MessageBoxA(hDlg,"Warning: this dialog has no functionality yet!",
323 NULL, MB_OK);
325 switch (uMsg)
327 case WM_COMMAND:
328 return PRINTDLG_WMCommand(hDlg, wParam, lParam, lppd);
329 case WM_DESTROY:
330 return FALSE;
333 return res;
342 /***********************************************************************
343 * PrintDlgProc16 (COMMDLG.21)
345 LRESULT WINAPI PrintDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
346 LPARAM lParam)
348 switch (wMsg)
350 case WM_INITDIALOG:
351 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
352 ShowWindow16(hWnd, SW_SHOWNORMAL);
353 return (TRUE);
354 case WM_COMMAND:
355 switch (wParam)
357 case IDOK:
358 EndDialog(hWnd, TRUE);
359 return(TRUE);
360 case IDCANCEL:
361 EndDialog(hWnd, FALSE);
362 return(TRUE);
364 return(FALSE);
366 return FALSE;
370 /***********************************************************************
371 * PrintSetupDlgProc (COMMDLG.22)
373 LRESULT WINAPI PrintSetupDlgProc16(HWND16 hWnd, UINT16 wMsg, WPARAM16 wParam,
374 LPARAM lParam)
376 switch (wMsg)
378 case WM_INITDIALOG:
379 TRACE(commdlg,"WM_INITDIALOG lParam=%08lX\n", lParam);
380 ShowWindow16(hWnd, SW_SHOWNORMAL);
381 return (TRUE);
382 case WM_COMMAND:
383 switch (wParam) {
384 case IDOK:
385 EndDialog(hWnd, TRUE);
386 return(TRUE);
387 case IDCANCEL:
388 EndDialog(hWnd, FALSE);
389 return(TRUE);
391 return(FALSE);
393 return FALSE;
399 /***********************************************************************
400 * PageSetupDlgA (COMDLG32.15)
402 BOOL WINAPI PageSetupDlgA(LPPAGESETUPDLGA setupdlg) {
403 FIXME(commdlg,"(%p), stub!\n",setupdlg);
404 return FALSE;