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