Fixed MessageBox() usage.
[wine] / programs / notepad / dialog.c
1 /*
2  *  Notepad (dialog.c)
3  *
4  *  Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch>
5  *  To be distributed under the Wine License
6  */
7
8 #include <assert.h>
9 #include <stdio.h>
10 #include <windows.h>
11 #include <commdlg.h>
12 #include <winerror.h>
13
14 #include "main.h"
15 #include "license.h"
16 #include "language.h"
17 #include "dialog.h"
18
19 #ifdef LCC
20   #define LCC_HASASSERT
21   #include "lcc.h"
22 #else
23   #include "version.h"
24   #include "winnls.h"
25 #endif
26
27 static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
28
29
30
31 int AlertIDS(UINT ids_message, UINT ids_caption, WORD type) {
32   /*
33    * Given some ids strings, this acts as a language-aware wrapper for 
34    * "MessageBox"
35    */
36    CHAR szMessage[MAX_STRING_LEN];
37    CHAR szCaption[MAX_STRING_LEN];
38    
39    LoadString(Globals.hInstance, ids_message, szMessage, sizeof(szMessage));
40    LoadString(Globals.hInstance, ids_caption, szCaption, sizeof(szCaption));
41    
42    return (MessageBox(Globals.hMainWnd, szMessage, szCaption, type));
43 }
44
45 void AlertFileNotFound(LPSTR szFileName) {
46
47    int nResult;
48    CHAR szMessage[MAX_STRING_LEN];
49    CHAR szRessource[MAX_STRING_LEN];
50
51    /* Load and format szMessage */
52    LoadString(Globals.hInstance, IDS_NOTFOUND, szRessource, sizeof(szRessource));
53    wsprintf(szMessage, szRessource, szFileName);
54    
55    /* Load szCaption */
56    LoadString(Globals.hInstance, IDS_ERROR,  szRessource, sizeof(szRessource));
57
58    /* Display Modal Dialog */
59    nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION);
60
61 }
62
63 int AlertFileNotSaved(LPSTR szFileName) {
64
65    int nResult;
66    CHAR szMessage[MAX_STRING_LEN];
67    CHAR szRessource[MAX_STRING_LEN];
68
69    /* Load and format Message */
70
71    LoadString(Globals.hInstance, IDS_NOTSAVED, szRessource, sizeof(szRessource));
72    wsprintf(szMessage, szRessource, szFileName);
73    
74    /* Load Caption */
75
76    LoadString(Globals.hInstance, IDS_ERROR,  szRessource, sizeof(szRessource));
77
78    /* Display modal */
79    nResult = MessageBox(Globals.hMainWnd, szMessage, szRessource, MB_ICONEXCLAMATION|MB_YESNOCANCEL);
80    return(nResult);
81 }
82
83
84 VOID AlertOutOfMemory(void) {
85    int nResult;
86    
87    nResult = AlertIDS(IDS_OUT_OF_MEMORY, IDS_ERROR, MB_ICONEXCLAMATION);
88    PostQuitMessage(1);
89 }
90
91
92 BOOL ExistFile(LPCSTR szFilename) {
93 /*
94  *  Returns: TRUE  - if "szFileName" exists
95  *           FALSE - if it does not
96  */
97    WIN32_FIND_DATA entry;
98    HANDLE hFile;
99    
100    hFile = FindFirstFile(szFilename, &entry);
101    
102    return (hFile!=INVALID_HANDLE_VALUE);
103 }
104
105 VOID DoSaveFile(VOID) {
106
107     /* FIXME: Really Save the file */
108     /* ... (Globals.szFileName); */
109 }
110
111
112 BOOL DoCloseFile(void) {
113 /* Return value: TRUE  - User agreed to close (both save/don't save) */
114 /*               FALSE - User cancelled close by selecting "Cancel" */
115
116     int nResult;
117    
118     if (strlen(Globals.szFileName)>0) {
119         /* prompt user to save changes */
120         nResult = AlertFileNotSaved(Globals.szFileName);
121         switch (nResult) {
122             case IDYES:     DoSaveFile();
123                             break;
124
125             case IDNO:      break;
126
127             case IDCANCEL:  return(FALSE);
128                             break;
129                       
130             default:        return(FALSE);
131                             break;
132         } /* switch */
133     } /* if */
134   
135     /* Forget file name  */
136     lstrcpy(Globals.szFileName, "");
137     LANGUAGE_UpdateWindowCaption();
138     return(TRUE);
139 }
140
141
142 void DoOpenFile(LPCSTR szFileName) {
143
144     /* Close any files and prompt to save changes */
145     if (DoCloseFile()) {
146         GetFileTitle(szFileName, Globals.szFileName, sizeof(Globals.szFileName));
147         LANGUAGE_UpdateWindowCaption();
148
149         LoadBufferFromFile(szFileName);
150     }
151 }
152
153
154 VOID DIALOG_FileNew(VOID)
155 {
156     /* Close any files and promt to save changes */
157     if (DoCloseFile()) {
158         TrashBuffer();
159     }
160 }
161
162 VOID DIALOG_FileOpen(VOID)
163 {
164         OPENFILENAME openfilename;
165         CHAR szPath[MAX_PATHNAME_LEN];
166         CHAR szDir[MAX_PATHNAME_LEN];
167         CHAR szzFilter[2 * MAX_STRING_LEN + 100];
168         CHAR szDefaultExt[4];
169         LPSTR p = szzFilter;
170
171         lstrcpy(szDefaultExt, "txt");
172
173         LoadString(Globals.hInstance, IDS_TEXT_FILES_TXT, p, MAX_STRING_LEN);
174         p += strlen(p) + 1;
175         lstrcpy(p, "*.txt");
176         p += strlen(p) + 1;
177         LoadString(Globals.hInstance, IDS_ALL_FILES, p, MAX_STRING_LEN);
178         p += strlen(p) + 1;
179         lstrcpy(p, "*.*");
180         p += strlen(p) + 1;
181         *p = '\0';
182
183         GetCurrentDirectory(sizeof(szDir), szDir);
184         lstrcpy(szPath,"*.txt");
185
186         openfilename.lStructSize       = sizeof(OPENFILENAME);
187         openfilename.hwndOwner         = Globals.hMainWnd;
188         openfilename.hInstance         = Globals.hInstance;
189         openfilename.lpstrFilter       = szzFilter;
190         openfilename.lpstrCustomFilter = 0;
191         openfilename.nMaxCustFilter    = 0;
192         openfilename.nFilterIndex      = 0;
193         openfilename.lpstrFile         = szPath;
194         openfilename.nMaxFile          = sizeof(szPath);
195         openfilename.lpstrFileTitle    = 0;
196         openfilename.nMaxFileTitle     = 0;
197         openfilename.lpstrInitialDir   = szDir;
198         openfilename.lpstrTitle        = 0;
199         openfilename.Flags             = OFN_FILEMUSTEXIST + OFN_PATHMUSTEXIST;
200         openfilename.nFileOffset       = 0;
201         openfilename.nFileExtension    = 0;
202         openfilename.lpstrDefExt       = szDefaultExt;
203         openfilename.lCustData         = 0;
204         openfilename.lpfnHook          = 0;
205         openfilename.lpTemplateName    = 0;
206
207         if (GetOpenFileName(&openfilename)) {
208                 
209                 if (ExistFile(openfilename.lpstrFile))
210                     DoOpenFile(openfilename.lpstrFile);
211                 else 
212                     AlertFileNotFound(openfilename.lpstrFile);
213                     
214         }
215 }
216
217 VOID DIALOG_FileSave(VOID)
218 {
219         /* FIXME: Save File */
220
221         DIALOG_FileSaveAs();
222 }
223
224 VOID DIALOG_FileSaveAs(VOID)
225 {
226         OPENFILENAME saveas;
227         CHAR szPath[MAX_PATHNAME_LEN];
228         CHAR szDir[MAX_PATHNAME_LEN];
229         CHAR szDefaultExt[4];
230         CHAR szzFilter[2 * MAX_STRING_LEN + 100];
231        
232         LPSTR p = szzFilter;
233
234         lstrcpy(szDefaultExt, "txt");
235
236         LoadString(Globals.hInstance, IDS_TEXT_FILES_TXT, p, MAX_STRING_LEN);
237         p += strlen(p) + 1;
238         lstrcpy(p, "*.txt");
239         p += strlen(p) + 1;
240         LoadString(Globals.hInstance, IDS_ALL_FILES, p, MAX_STRING_LEN);
241         p += strlen(p) + 1;
242         lstrcpy(p, "*.*");
243         p += strlen(p) + 1;
244         *p = '\0';
245
246         lstrcpy(szPath,"*.*");
247
248         GetCurrentDirectory(sizeof(szDir), szDir);
249
250         saveas.lStructSize       = sizeof(OPENFILENAME);
251         saveas.hwndOwner         = Globals.hMainWnd;
252         saveas.hInstance         = Globals.hInstance;
253         saveas.lpstrFilter       = szzFilter;
254         saveas.lpstrCustomFilter = 0;
255         saveas.nMaxCustFilter    = 0;
256         saveas.nFilterIndex      = 0;
257         saveas.lpstrFile         = szPath;
258         saveas.nMaxFile          = sizeof(szPath);
259         saveas.lpstrFileTitle    = 0;
260         saveas.nMaxFileTitle     = 0;
261         saveas.lpstrInitialDir   = szDir;
262         saveas.lpstrTitle        = 0;
263         saveas.Flags             = OFN_PATHMUSTEXIST + OFN_OVERWRITEPROMPT + OFN_HIDEREADONLY;
264         saveas.nFileOffset       = 0;
265         saveas.nFileExtension    = 0;
266         saveas.lpstrDefExt       = szDefaultExt;
267         saveas.lCustData         = 0;
268         saveas.lpfnHook          = 0;
269         saveas.lpTemplateName    = 0;
270
271         if (GetSaveFileName(&saveas)) {
272             lstrcpy(Globals.szFileName, saveas.lpstrFile);
273             LANGUAGE_UpdateWindowCaption();
274             DIALOG_FileSave();
275         }
276 }
277
278 VOID DIALOG_FilePrint(VOID)
279 {
280         LONG bFlags, nBase;
281         WORD nOffset;
282         DOCINFO di;
283         int nResult;
284         HDC hContext;
285         PRINTDLG printer;
286
287         CHAR szDocumentName[MAX_STRING_LEN]; /* Name of document */
288         CHAR szPrinterName[MAX_STRING_LEN];  /* Name of the printer */
289         CHAR szDeviceName[MAX_STRING_LEN];   /* Name of the printer device */
290         CHAR szOutput[MAX_STRING_LEN];       /* in which file/device to print */
291
292 /*        LPDEVMODE  hDevMode;   */
293 /*        LPDEVNAMES hDevNames; */
294
295 /*        hDevMode  = GlobalAlloc(GMEM_MOVEABLE + GMEM_ZEROINIT, sizeof(DEVMODE)); */
296 /*        hDevNames = GlobalAlloc(GMEM_MOVEABLE + GMEM_ZEROINIT, sizeof(DEVNAMES)); */
297
298         /* Get Current Settings */
299
300         printer.lStructSize           = sizeof(PRINTDLG);
301         printer.hwndOwner             = Globals.hMainWnd;
302         printer.hInstance             = Globals.hInstance;
303
304         /* Let PrintDlg create a DEVMODE structure */
305         printer.hDevMode              = 0;
306         printer.hDevNames             = 0;
307         printer.hDC                   = 0;
308         printer.Flags                 = PD_RETURNDEFAULT;
309         printer.nFromPage             = 0;
310         printer.nToPage               = 0;
311         printer.nMinPage              = 0;
312         printer.nMaxPage              = 0;
313         printer.nCopies               = 0;
314         printer.lCustData             = 0;
315         printer.lpfnPrintHook         = 0;
316         printer.lpfnSetupHook         = 0;
317         printer.lpPrintTemplateName   = 0;
318         printer.lpSetupTemplateName   = 0;
319         printer.hPrintTemplate        = 0;
320         printer.hSetupTemplate        = 0;
321
322         nResult = PrintDlg(&printer);
323
324 /*        hContext = CreateDC(, szDeviceName, "TEST.TXT", 0); */
325
326         /* Congratulations to those Microsoft Engineers responsable */
327         /* for the following pointer acrobatics */
328
329         assert(printer.hDevNames!=0);
330
331         nBase = (LONG)(printer.hDevNames);
332
333         nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wDriverOffset;
334         lstrcpy(szPrinterName, (LPCSTR) (nBase + nOffset));
335
336         nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wDeviceOffset;
337         lstrcpy(szDeviceName, (LPCSTR) (nBase + nOffset));
338
339         nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wOutputOffset;
340         lstrcpy(szOutput, (LPCSTR) (nBase + nOffset));
341
342         MessageBox(Globals.hMainWnd, szPrinterName, "Printer Name", MB_ICONEXCLAMATION);
343         MessageBox(Globals.hMainWnd, szDeviceName,  "Device Name",  MB_ICONEXCLAMATION);
344         MessageBox(Globals.hMainWnd, szOutput,      "Output",       MB_ICONEXCLAMATION);
345
346         /* Set some default flags */
347
348         bFlags = PD_RETURNDC + PD_SHOWHELP;
349
350         if (TRUE) {
351              /* Remove "Print Selection" if there is no selection */
352              bFlags = bFlags + PD_NOSELECTION;
353         } 
354
355         printer.Flags                 = bFlags;
356 /*
357         printer.nFromPage             = 0;
358         printer.nToPage               = 0;
359         printer.nMinPage              = 0;
360         printer.nMaxPage              = 0;
361 */
362
363         /* Let commdlg manage copy settings */
364         printer.nCopies               = (WORD)PD_USEDEVMODECOPIES;
365
366         if (PrintDlg(&printer)) {
367
368             /* initialize DOCINFO */
369             di.cbSize = sizeof(DOCINFO);
370             lstrcpy((LPSTR)di.lpszDocName, szDocumentName);
371             lstrcpy((LPSTR)di.lpszOutput,  szOutput);
372
373             hContext = printer.hDC;
374             assert(hContext!=0);
375             assert( (int) hContext!=PD_RETURNDC);
376
377             SetMapMode(hContext, MM_LOMETRIC);
378 /*          SetViewPortExExt(hContext, 10, 10, 0); */
379             SetBkMode(hContext, OPAQUE);
380
381             nResult = TextOut(hContext, 0, 0, " ", 1);
382             assert(nResult != 0);
383
384             nResult = StartDoc(hContext, &di);
385             assert(nResult != SP_ERROR);
386
387             nResult = StartPage(hContext);
388             assert(nResult >0);
389
390             /* FIXME: actually print */
391
392             nResult = EndPage(hContext);
393
394             switch (nResult) {
395                case SP_ERROR:
396                        MessageBox(Globals.hMainWnd, "Generic Error", "Print Engine Error", MB_ICONEXCLAMATION);
397                        break;
398                case SP_APPABORT:
399                        MessageBox(Globals.hMainWnd, "The print job was aborted.", "Print Engine Error", MB_ICONEXCLAMATION);
400                        break;
401                case SP_USERABORT:
402                        MessageBox(Globals.hMainWnd, "The print job was aborted using the Print Manager ", "Print Engine Error", MB_ICONEXCLAMATION);
403                        break;
404                case SP_OUTOFDISK:
405                        MessageBox(Globals.hMainWnd, "Out of disk space", "Print Engine Error", MB_ICONEXCLAMATION);
406                        break;
407                case SP_OUTOFMEMORY:
408                        AlertOutOfMemory();
409                        break;
410                default:
411                        MessageBox(Globals.hMainWnd, "Default", "Print", MB_ICONEXCLAMATION); 
412             } /* switch */
413             nResult = EndDoc(hContext);
414             assert(nResult>=0);
415             nResult = DeleteDC(hContext);
416             assert(nResult!=0);
417         } /* if */
418
419 /*       GlobalFree(hDevNames); */
420 /*       GlobalFree(hDevMode); */
421 }
422
423 VOID DIALOG_FilePageSetup(VOID)
424 {
425         DIALOG_PageSetup();
426 }
427
428 VOID DIALOG_FilePrinterSetup(VOID)
429 {
430         PRINTDLG printer;
431
432         printer.lStructSize          = sizeof(PRINTDLG);
433         printer.hwndOwner            = Globals.hMainWnd;
434         printer.hInstance            = Globals.hInstance;
435         printer.hDevMode             = 0;
436         printer.hDevNames            = 0;
437         printer.hDC                  = 0;
438         printer.Flags                = PD_PRINTSETUP;
439         printer.nFromPage            = 0;
440         printer.nToPage              = 0;
441         printer.nMinPage             = 0;
442         printer.nMaxPage             = 0;
443         printer.nCopies              = 1;
444         printer.lCustData            = 0;
445         printer.lpfnPrintHook        = 0;
446         printer.lpfnSetupHook        = 0;
447         printer.lpPrintTemplateName  = 0;
448         printer.lpSetupTemplateName  = 0;
449         printer.hPrintTemplate       = 0;
450         printer.hSetupTemplate       = 0;
451         
452         if (PrintDlg(&printer)) {
453             /* do nothing */
454         };
455
456 }
457
458 VOID DIALOG_FileExit(VOID)
459 {
460         if (DoCloseFile()) {
461                PostQuitMessage(0);
462         }
463 }
464
465 VOID DIALOG_EditUndo(VOID)
466 {
467    MessageBox(Globals.hMainWnd, "Undo", "Debug", MB_ICONEXCLAMATION);
468         /* undo */
469 }
470
471 VOID DIALOG_EditCut(VOID)
472 {
473     HANDLE hMem;
474
475     hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
476
477     OpenClipboard(Globals.hMainWnd);
478     EmptyClipboard();
479
480     /* FIXME: Get text */
481     lstrcpy((CHAR *)hMem, "Hello World");
482
483     SetClipboardData(CF_TEXT, hMem);
484     CloseClipboard();
485
486     GlobalFree(hMem);
487 }
488
489 VOID DIALOG_EditCopy(VOID)
490 {
491     HANDLE hMem;
492
493     hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
494
495     OpenClipboard(Globals.hMainWnd);
496     EmptyClipboard();
497
498     /* FIXME: Get text */
499     lstrcpy((CHAR *)hMem, "Hello World");
500
501     SetClipboardData(CF_TEXT, hMem);
502     CloseClipboard();
503
504     GlobalFree(hMem);
505 }
506
507 VOID DIALOG_EditPaste(VOID)
508 {
509     HANDLE hClipText;
510
511     if (IsClipboardFormatAvailable(CF_TEXT)) {
512         OpenClipboard(Globals.hMainWnd);
513         hClipText = GetClipboardData(CF_TEXT);
514         CloseClipboard();
515         MessageBox(Globals.hMainWnd, (CHAR *)hClipText, "PASTE", MB_ICONEXCLAMATION);
516     }
517 }
518
519 VOID DIALOG_EditDelete(VOID)
520 {
521         /* Delete */
522 }
523
524 VOID DIALOG_EditSelectAll(VOID)
525 {
526         /* Select all */
527 }
528
529 VOID DIALOG_EditTimeDate(VOID)
530 {
531     SYSTEMTIME   st;
532     LPSYSTEMTIME lpst = &st;
533     CHAR         szDate[MAX_STRING_LEN];
534     LPSTR        date = szDate;
535     
536     GetLocalTime(&st);
537     GetDateFormat(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, lpst, NULL, date, MAX_STRING_LEN);
538     GetTimeFormat(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, lpst, NULL, date, MAX_STRING_LEN);
539
540 }
541
542 VOID DIALOG_EditWrap(VOID)
543 {
544         Globals.bWrapLongLines = !Globals.bWrapLongLines;
545         CheckMenuItem(Globals.hEditMenu, NP_EDIT_WRAP, MF_BYCOMMAND | 
546         (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
547 }
548
549 VOID DIALOG_Search(VOID)
550 {
551         Globals.find.lStructSize      = sizeof(Globals.find);
552         Globals.find.hwndOwner        = Globals.hMainWnd;
553         Globals.find.hInstance        = Globals.hInstance;
554         Globals.find.lpstrFindWhat    = (CHAR *) &Globals.szFindText;
555         Globals.find.wFindWhatLen     = sizeof(Globals.szFindText);
556         Globals.find.lpstrReplaceWith = 0;
557         Globals.find.wReplaceWithLen  = 0;
558         Globals.find.Flags            = FR_DOWN;
559         Globals.find.lCustData        = 0;
560         Globals.find.lpfnHook         = 0;
561         Globals.find.lpTemplateName   = 0;
562
563         /* We only need to create the modal FindReplace dialog which will */
564         /* notify us of incoming events using hMainWnd Window Messages    */
565
566         Globals.hFindReplaceDlg = FindText(&Globals.find);
567         assert(Globals.hFindReplaceDlg !=0);
568 }
569
570 VOID DIALOG_SearchNext(VOID)
571 {
572         /* Search Next */
573 }
574
575 VOID DIALOG_HelpContents(VOID)
576 {
577         WinHelp(Globals.hMainWnd, HELPFILE, HELP_INDEX, 0);
578 }
579
580 VOID DIALOG_HelpSearch(VOID)
581 {
582         /* Search Help */
583 }
584
585 VOID DIALOG_HelpHelp(VOID)
586 {
587         WinHelp(Globals.hMainWnd, HELPFILE, HELP_HELPONHELP, 0);
588 }
589
590 VOID DIALOG_HelpLicense(VOID)
591 {
592         WineLicense(Globals.hMainWnd);
593 }
594
595 VOID DIALOG_HelpNoWarranty(VOID)
596 {
597         WineWarranty(Globals.hMainWnd);
598 }
599
600 VOID DIALOG_HelpAboutWine(VOID)
601 {
602         CHAR szNotepad[MAX_STRING_LEN];
603
604         LoadString(Globals.hInstance, IDS_NOTEPAD, szNotepad, sizeof(szNotepad));
605         ShellAbout(Globals.hMainWnd, szNotepad, "Notepad\n" WINE_RELEASE_INFO, 0);
606 }
607
608 /***********************************************************************
609  *
610  *           DIALOG_PageSetup
611  */
612
613 VOID DIALOG_PageSetup(VOID)
614 {
615   WNDPROC lpfnDlg;
616
617   lpfnDlg = MakeProcInstance(DIALOG_PAGESETUP_DlgProc, Globals.hInstance);
618   DialogBox(Globals.hInstance, STRING_PAGESETUP_Xx, Globals.hMainWnd, (DLGPROC)lpfnDlg);
619   FreeProcInstance(lpfnDlg);
620 }
621
622
623 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
624  *
625  *           DIALOG_PAGESETUP_DlgProc
626  */
627
628 static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
629 {
630
631    switch (msg)
632     {
633     case WM_COMMAND:
634       switch (wParam)
635         {
636         case IDOK:
637           /* save user input and close dialog */
638           GetDlgItemText(hDlg, NP_PAGESETUP_HEAD,   Globals.szHeader,       sizeof(Globals.szHeader));
639           GetDlgItemText(hDlg, NP_PAGESETUP_TAIL,   Globals.szFooter,       sizeof(Globals.szFooter));
640           GetDlgItemText(hDlg, NP_PAGESETUP_TOP,    Globals.szMarginTop,    sizeof(Globals.szMarginTop));
641           GetDlgItemText(hDlg, NP_PAGESETUP_BOTTOM, Globals.szMarginBottom, sizeof(Globals.szMarginBottom));
642           GetDlgItemText(hDlg, NP_PAGESETUP_LEFT,   Globals.szMarginLeft,   sizeof(Globals.szMarginLeft));
643           GetDlgItemText(hDlg, NP_PAGESETUP_RIGHT,  Globals.szMarginRight,  sizeof(Globals.szMarginRight));
644           EndDialog(hDlg, IDOK);
645           return TRUE;
646
647         case IDCANCEL:
648           /* discard user input and close dialog */
649           EndDialog(hDlg, IDCANCEL);
650           return TRUE;
651
652         case IDHELP:
653           /* FIXME: Bring this to work */
654           MessageBox(Globals.hMainWnd, "Sorry, no help available", "Help", MB_ICONEXCLAMATION);
655           return TRUE;
656         }
657       break;
658
659     case WM_INITDIALOG:
660        /* fetch last user input prior to display dialog */
661        SetDlgItemText(hDlg, NP_PAGESETUP_HEAD,   Globals.szHeader);
662        SetDlgItemText(hDlg, NP_PAGESETUP_TAIL,   Globals.szFooter);
663        SetDlgItemText(hDlg, NP_PAGESETUP_TOP,    Globals.szMarginTop);
664        SetDlgItemText(hDlg, NP_PAGESETUP_BOTTOM, Globals.szMarginBottom);
665        SetDlgItemText(hDlg, NP_PAGESETUP_LEFT,   Globals.szMarginLeft);
666        SetDlgItemText(hDlg, NP_PAGESETUP_RIGHT,  Globals.szMarginRight);
667        break;
668     }
669
670   return FALSE;
671 }