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