Added LGPL standard comment, and copyright notices where necessary.
[wine] / programs / notepad / dialog.c
1 /*
2  *  Notepad (dialog.c)
3  *
4  *  Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch>
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
19  */
20
21 #include <assert.h>
22 #include <stdio.h>
23 #include <windows.h>
24 #include <commdlg.h>
25 #include <winerror.h>
26
27 #include "main.h"
28 #include "license.h"
29 #include "language.h"
30 #include "dialog.h"
31
32 static LRESULT WINAPI 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    wsprintf(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    wsprintf(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 FileExists(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     /* Close any files and prompt to save changes */
150     if (DoCloseFile()) {
151         GetFileTitle(szFileName, Globals.szFileName, sizeof(Globals.szFileName));
152         LANGUAGE_UpdateWindowCaption();
153
154         LoadBufferFromFile(szFileName);
155     }
156 }
157
158
159 VOID DIALOG_FileNew(VOID)
160 {
161     /* Close any files and promt to save changes */
162     if (DoCloseFile()) {
163         TrashBuffer();
164     }
165 }
166
167 VOID DIALOG_FileOpen(VOID)
168 {
169         OPENFILENAME openfilename;
170         CHAR szPath[MAX_PATHNAME_LEN];
171         CHAR szDir[MAX_PATHNAME_LEN];
172         CHAR szzFilter[2 * MAX_STRING_LEN + 100];
173         CHAR szDefaultExt[4];
174         LPSTR p = szzFilter;
175
176         lstrcpy(szDefaultExt, "txt");
177
178         LoadString(Globals.hInstance, IDS_TEXT_FILES_TXT, p, MAX_STRING_LEN);
179         p += strlen(p) + 1;
180         lstrcpy(p, "*.txt");
181         p += strlen(p) + 1;
182         LoadString(Globals.hInstance, IDS_ALL_FILES, p, MAX_STRING_LEN);
183         p += strlen(p) + 1;
184         lstrcpy(p, "*.*");
185         p += strlen(p) + 1;
186         *p = '\0';
187
188         GetCurrentDirectory(sizeof(szDir), szDir);
189         lstrcpy(szPath,"*.txt");
190
191         openfilename.lStructSize       = sizeof(OPENFILENAME);
192         openfilename.hwndOwner         = Globals.hMainWnd;
193         openfilename.hInstance         = Globals.hInstance;
194         openfilename.lpstrFilter       = szzFilter;
195         openfilename.lpstrCustomFilter = 0;
196         openfilename.nMaxCustFilter    = 0;
197         openfilename.nFilterIndex      = 0;
198         openfilename.lpstrFile         = szPath;
199         openfilename.nMaxFile          = sizeof(szPath);
200         openfilename.lpstrFileTitle    = 0;
201         openfilename.nMaxFileTitle     = 0;
202         openfilename.lpstrInitialDir   = szDir;
203         openfilename.lpstrTitle        = 0;
204         openfilename.Flags             = OFN_FILEMUSTEXIST + OFN_PATHMUSTEXIST;
205         openfilename.nFileOffset       = 0;
206         openfilename.nFileExtension    = 0;
207         openfilename.lpstrDefExt       = szDefaultExt;
208         openfilename.lCustData         = 0;
209         openfilename.lpfnHook          = 0;
210         openfilename.lpTemplateName    = 0;
211
212         if (GetOpenFileName(&openfilename)) {
213                 
214                 if (FileExists(openfilename.lpstrFile))
215                     DoOpenFile(openfilename.lpstrFile);
216                 else 
217                     AlertFileNotFound(openfilename.lpstrFile);
218                     
219         }
220 }
221
222 VOID DIALOG_FileSave(VOID)
223 {
224         /* FIXME: Save File */
225
226         DIALOG_FileSaveAs();
227 }
228
229 VOID DIALOG_FileSaveAs(VOID)
230 {
231         OPENFILENAME saveas;
232         CHAR szPath[MAX_PATHNAME_LEN];
233         CHAR szDir[MAX_PATHNAME_LEN];
234         CHAR szDefaultExt[4];
235         CHAR szzFilter[2 * MAX_STRING_LEN + 100];
236        
237         LPSTR p = szzFilter;
238
239         lstrcpy(szDefaultExt, "txt");
240
241         LoadString(Globals.hInstance, IDS_TEXT_FILES_TXT, p, MAX_STRING_LEN);
242         p += strlen(p) + 1;
243         lstrcpy(p, "*.txt");
244         p += strlen(p) + 1;
245         LoadString(Globals.hInstance, IDS_ALL_FILES, p, MAX_STRING_LEN);
246         p += strlen(p) + 1;
247         lstrcpy(p, "*.*");
248         p += strlen(p) + 1;
249         *p = '\0';
250
251         lstrcpy(szPath,"*.*");
252
253         GetCurrentDirectory(sizeof(szDir), szDir);
254
255         saveas.lStructSize       = sizeof(OPENFILENAME);
256         saveas.hwndOwner         = Globals.hMainWnd;
257         saveas.hInstance         = Globals.hInstance;
258         saveas.lpstrFilter       = szzFilter;
259         saveas.lpstrCustomFilter = 0;
260         saveas.nMaxCustFilter    = 0;
261         saveas.nFilterIndex      = 0;
262         saveas.lpstrFile         = szPath;
263         saveas.nMaxFile          = sizeof(szPath);
264         saveas.lpstrFileTitle    = 0;
265         saveas.nMaxFileTitle     = 0;
266         saveas.lpstrInitialDir   = szDir;
267         saveas.lpstrTitle        = 0;
268         saveas.Flags             = OFN_PATHMUSTEXIST + OFN_OVERWRITEPROMPT + OFN_HIDEREADONLY;
269         saveas.nFileOffset       = 0;
270         saveas.nFileExtension    = 0;
271         saveas.lpstrDefExt       = szDefaultExt;
272         saveas.lCustData         = 0;
273         saveas.lpfnHook          = 0;
274         saveas.lpTemplateName    = 0;
275
276         if (GetSaveFileName(&saveas)) {
277             lstrcpy(Globals.szFileName, saveas.lpstrFile);
278             LANGUAGE_UpdateWindowCaption();
279             DIALOG_FileSave();
280         }
281 }
282
283 VOID DIALOG_FilePrint(VOID)
284 {
285         LONG bFlags, nBase;
286         WORD nOffset;
287         DOCINFO di;
288         int nResult;
289         HDC hContext;
290         PRINTDLG printer;
291
292         CHAR szDocumentName[MAX_STRING_LEN]; /* Name of document */
293         CHAR szPrinterName[MAX_STRING_LEN];  /* Name of the printer */
294         CHAR szDeviceName[MAX_STRING_LEN];   /* Name of the printer device */
295         CHAR szOutput[MAX_STRING_LEN];       /* in which file/device to print */
296
297 /*        LPDEVMODE  hDevMode;   */
298 /*        LPDEVNAMES hDevNames; */
299
300 /*        hDevMode  = GlobalAlloc(GMEM_MOVEABLE + GMEM_ZEROINIT, sizeof(DEVMODE)); */
301 /*        hDevNames = GlobalAlloc(GMEM_MOVEABLE + GMEM_ZEROINIT, sizeof(DEVNAMES)); */
302
303         /* Get Current Settings */
304
305         printer.lStructSize           = sizeof(PRINTDLG);
306         printer.hwndOwner             = Globals.hMainWnd;
307         printer.hInstance             = Globals.hInstance;
308
309         /* Let PrintDlg create a DEVMODE structure */
310         printer.hDevMode              = 0;
311         printer.hDevNames             = 0;
312         printer.hDC                   = 0;
313         printer.Flags                 = PD_RETURNDEFAULT;
314         printer.nFromPage             = 0;
315         printer.nToPage               = 0;
316         printer.nMinPage              = 0;
317         printer.nMaxPage              = 0;
318         printer.nCopies               = 0;
319         printer.lCustData             = 0;
320         printer.lpfnPrintHook         = 0;
321         printer.lpfnSetupHook         = 0;
322         printer.lpPrintTemplateName   = 0;
323         printer.lpSetupTemplateName   = 0;
324         printer.hPrintTemplate        = 0;
325         printer.hSetupTemplate        = 0;
326
327         nResult = PrintDlg(&printer);
328
329 /*        hContext = CreateDC(, szDeviceName, "TEST.TXT", 0); */
330
331         /* Congratulations to those Microsoft Engineers responsable */
332         /* for the following pointer acrobatics */
333
334         assert(printer.hDevNames!=0);
335
336         nBase = (LONG)(printer.hDevNames);
337
338         nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wDriverOffset;
339         lstrcpy(szPrinterName, (LPCSTR) (nBase + nOffset));
340
341         nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wDeviceOffset;
342         lstrcpy(szDeviceName, (LPCSTR) (nBase + nOffset));
343
344         nOffset = (WORD)((LPDEVNAMES) printer.hDevNames)->wOutputOffset;
345         lstrcpy(szOutput, (LPCSTR) (nBase + nOffset));
346
347         MessageBox(Globals.hMainWnd, szPrinterName, "Printer Name", MB_ICONEXCLAMATION);
348         MessageBox(Globals.hMainWnd, szDeviceName,  "Device Name",  MB_ICONEXCLAMATION);
349         MessageBox(Globals.hMainWnd, szOutput,      "Output",       MB_ICONEXCLAMATION);
350
351         /* Set some default flags */
352
353         bFlags = PD_RETURNDC + PD_SHOWHELP;
354
355         if (TRUE) {
356              /* Remove "Print Selection" if there is no selection */
357              bFlags = bFlags + PD_NOSELECTION;
358         } 
359
360         printer.Flags                 = bFlags;
361 /*
362         printer.nFromPage             = 0;
363         printer.nToPage               = 0;
364         printer.nMinPage              = 0;
365         printer.nMaxPage              = 0;
366 */
367
368         /* Let commdlg manage copy settings */
369         printer.nCopies               = (WORD)PD_USEDEVMODECOPIES;
370
371         if (PrintDlg(&printer)) {
372
373             /* initialize DOCINFO */
374             di.cbSize = sizeof(DOCINFO);
375             lstrcpy((LPSTR)di.lpszDocName, szDocumentName);
376             lstrcpy((LPSTR)di.lpszOutput,  szOutput);
377
378             hContext = printer.hDC;
379             assert(hContext!=0);
380             assert( (int) hContext!=PD_RETURNDC);
381
382             SetMapMode(hContext, MM_LOMETRIC);
383 /*          SetViewPortExExt(hContext, 10, 10, 0); */
384             SetBkMode(hContext, OPAQUE);
385
386             nResult = TextOut(hContext, 0, 0, " ", 1);
387             assert(nResult != 0);
388
389             nResult = StartDoc(hContext, &di);
390             assert(nResult != SP_ERROR);
391
392             nResult = StartPage(hContext);
393             assert(nResult >0);
394
395             /* FIXME: actually print */
396
397             nResult = EndPage(hContext);
398
399             switch (nResult) {
400                case SP_ERROR:
401                        MessageBox(Globals.hMainWnd, "Generic Error", "Print Engine Error", MB_ICONEXCLAMATION);
402                        break;
403                case SP_APPABORT:
404                        MessageBox(Globals.hMainWnd, "The print job was aborted.", "Print Engine Error", MB_ICONEXCLAMATION);
405                        break;
406                case SP_USERABORT:
407                        MessageBox(Globals.hMainWnd, "The print job was aborted using the Print Manager ", "Print Engine Error", MB_ICONEXCLAMATION);
408                        break;
409                case SP_OUTOFDISK:
410                        MessageBox(Globals.hMainWnd, "Out of disk space", "Print Engine Error", MB_ICONEXCLAMATION);
411                        break;
412                case SP_OUTOFMEMORY:
413                        AlertOutOfMemory();
414                        break;
415                default:
416                        MessageBox(Globals.hMainWnd, "Default", "Print", MB_ICONEXCLAMATION); 
417             } /* switch */
418             nResult = EndDoc(hContext);
419             assert(nResult>=0);
420             nResult = DeleteDC(hContext);
421             assert(nResult!=0);
422         } /* if */
423
424 /*       GlobalFree(hDevNames); */
425 /*       GlobalFree(hDevMode); */
426 }
427
428 VOID DIALOG_FilePageSetup(VOID)
429 {
430         DIALOG_PageSetup();
431 }
432
433 VOID DIALOG_FilePrinterSetup(VOID)
434 {
435         PRINTDLG printer;
436
437         printer.lStructSize          = sizeof(PRINTDLG);
438         printer.hwndOwner            = Globals.hMainWnd;
439         printer.hInstance            = Globals.hInstance;
440         printer.hDevMode             = 0;
441         printer.hDevNames            = 0;
442         printer.hDC                  = 0;
443         printer.Flags                = PD_PRINTSETUP;
444         printer.nFromPage            = 0;
445         printer.nToPage              = 0;
446         printer.nMinPage             = 0;
447         printer.nMaxPage             = 0;
448         printer.nCopies              = 1;
449         printer.lCustData            = 0;
450         printer.lpfnPrintHook        = 0;
451         printer.lpfnSetupHook        = 0;
452         printer.lpPrintTemplateName  = 0;
453         printer.lpSetupTemplateName  = 0;
454         printer.hPrintTemplate       = 0;
455         printer.hSetupTemplate       = 0;
456         
457         if (PrintDlg(&printer)) {
458             /* do nothing */
459         };
460
461 }
462
463 VOID DIALOG_FileExit(VOID)
464 {
465         if (DoCloseFile()) {
466                PostQuitMessage(0);
467         }
468 }
469
470 VOID DIALOG_EditUndo(VOID)
471 {
472    MessageBox(Globals.hMainWnd, "Undo", "Debug", MB_ICONEXCLAMATION);
473         /* undo */
474 }
475
476 VOID DIALOG_EditCut(VOID)
477 {
478     HANDLE hMem;
479
480     hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
481
482     OpenClipboard(Globals.hMainWnd);
483     EmptyClipboard();
484
485     /* FIXME: Get text */
486     lstrcpy((CHAR *)hMem, "Hello World");
487
488     SetClipboardData(CF_TEXT, hMem);
489     CloseClipboard();
490
491     GlobalFree(hMem);
492 }
493
494 VOID DIALOG_EditCopy(VOID)
495 {
496     HANDLE hMem;
497
498     hMem = GlobalAlloc(GMEM_ZEROINIT, 99);
499
500     OpenClipboard(Globals.hMainWnd);
501     EmptyClipboard();
502
503     /* FIXME: Get text */
504     lstrcpy((CHAR *)hMem, "Hello World");
505
506     SetClipboardData(CF_TEXT, hMem);
507     CloseClipboard();
508
509     GlobalFree(hMem);
510 }
511
512 VOID DIALOG_EditPaste(VOID)
513 {
514     HANDLE hClipText;
515
516     if (IsClipboardFormatAvailable(CF_TEXT)) {
517         OpenClipboard(Globals.hMainWnd);
518         hClipText = GetClipboardData(CF_TEXT);
519         CloseClipboard();
520         MessageBox(Globals.hMainWnd, (CHAR *)hClipText, "PASTE", MB_ICONEXCLAMATION);
521     }
522 }
523
524 VOID DIALOG_EditDelete(VOID)
525 {
526         /* Delete */
527 }
528
529 VOID DIALOG_EditSelectAll(VOID)
530 {
531         /* Select all */
532 }
533
534 VOID DIALOG_EditTimeDate(VOID)
535 {
536     SYSTEMTIME   st;
537     LPSYSTEMTIME lpst = &st;
538     CHAR         szDate[MAX_STRING_LEN];
539     LPSTR        date = szDate;
540     
541     GetLocalTime(&st);
542     GetDateFormat(LOCALE_USER_DEFAULT, LOCALE_SLONGDATE, lpst, NULL, date, MAX_STRING_LEN);
543     GetTimeFormat(LOCALE_USER_DEFAULT, LOCALE_STIMEFORMAT, lpst, NULL, date, MAX_STRING_LEN);
544
545 }
546
547 VOID DIALOG_EditWrap(VOID)
548 {
549         Globals.bWrapLongLines = !Globals.bWrapLongLines;
550         CheckMenuItem(Globals.hEditMenu, NP_EDIT_WRAP, MF_BYCOMMAND | 
551         (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
552 }
553
554 VOID DIALOG_Search(VOID)
555 {
556         Globals.find.lStructSize      = sizeof(Globals.find);
557         Globals.find.hwndOwner        = Globals.hMainWnd;
558         Globals.find.hInstance        = Globals.hInstance;
559         Globals.find.lpstrFindWhat    = (CHAR *) &Globals.szFindText;
560         Globals.find.wFindWhatLen     = sizeof(Globals.szFindText);
561         Globals.find.lpstrReplaceWith = 0;
562         Globals.find.wReplaceWithLen  = 0;
563         Globals.find.Flags            = FR_DOWN;
564         Globals.find.lCustData        = 0;
565         Globals.find.lpfnHook         = 0;
566         Globals.find.lpTemplateName   = 0;
567
568         /* We only need to create the modal FindReplace dialog which will */
569         /* notify us of incoming events using hMainWnd Window Messages    */
570
571         Globals.hFindReplaceDlg = FindText(&Globals.find);
572         assert(Globals.hFindReplaceDlg !=0);
573 }
574
575 VOID DIALOG_SearchNext(VOID)
576 {
577         /* Search Next */
578 }
579
580 VOID DIALOG_HelpContents(VOID)
581 {
582         WinHelp(Globals.hMainWnd, HELPFILE, HELP_INDEX, 0);
583 }
584
585 VOID DIALOG_HelpSearch(VOID)
586 {
587         /* Search Help */
588 }
589
590 VOID DIALOG_HelpHelp(VOID)
591 {
592         WinHelp(Globals.hMainWnd, HELPFILE, HELP_HELPONHELP, 0);
593 }
594
595 VOID DIALOG_HelpLicense(VOID)
596 {
597         WineLicense(Globals.hMainWnd);
598 }
599
600 VOID DIALOG_HelpNoWarranty(VOID)
601 {
602         WineWarranty(Globals.hMainWnd);
603 }
604
605 VOID DIALOG_HelpAboutWine(VOID)
606 {
607         CHAR szNotepad[MAX_STRING_LEN];
608
609         LoadString(Globals.hInstance, IDS_NOTEPAD, szNotepad, sizeof(szNotepad));
610         ShellAbout(Globals.hMainWnd, szNotepad, "Notepad\n" WINE_RELEASE_INFO, 0);
611 }
612
613 /***********************************************************************
614  *
615  *           DIALOG_PageSetup
616  */
617
618 VOID DIALOG_PageSetup(VOID)
619 {
620   WNDPROC lpfnDlg;
621
622   lpfnDlg = MakeProcInstance(DIALOG_PAGESETUP_DlgProc, Globals.hInstance);
623   DialogBox(Globals.hInstance, STRING_PAGESETUP_Xx, Globals.hMainWnd, (DLGPROC)lpfnDlg);
624   FreeProcInstance(lpfnDlg);
625 }
626
627
628 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
629  *
630  *           DIALOG_PAGESETUP_DlgProc
631  */
632
633 static LRESULT WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
634 {
635
636    switch (msg)
637     {
638     case WM_COMMAND:
639       switch (wParam)
640         {
641         case IDOK:
642           /* save user input and close dialog */
643           GetDlgItemText(hDlg, NP_PAGESETUP_HEAD,   Globals.szHeader,       sizeof(Globals.szHeader));
644           GetDlgItemText(hDlg, NP_PAGESETUP_TAIL,   Globals.szFooter,       sizeof(Globals.szFooter));
645           GetDlgItemText(hDlg, NP_PAGESETUP_TOP,    Globals.szMarginTop,    sizeof(Globals.szMarginTop));
646           GetDlgItemText(hDlg, NP_PAGESETUP_BOTTOM, Globals.szMarginBottom, sizeof(Globals.szMarginBottom));
647           GetDlgItemText(hDlg, NP_PAGESETUP_LEFT,   Globals.szMarginLeft,   sizeof(Globals.szMarginLeft));
648           GetDlgItemText(hDlg, NP_PAGESETUP_RIGHT,  Globals.szMarginRight,  sizeof(Globals.szMarginRight));
649           EndDialog(hDlg, IDOK);
650           return TRUE;
651
652         case IDCANCEL:
653           /* discard user input and close dialog */
654           EndDialog(hDlg, IDCANCEL);
655           return TRUE;
656
657         case IDHELP:
658           /* FIXME: Bring this to work */
659           MessageBox(Globals.hMainWnd, "Sorry, no help available", "Help", MB_ICONEXCLAMATION);
660           return TRUE;
661         }
662       break;
663
664     case WM_INITDIALOG:
665        /* fetch last user input prior to display dialog */
666        SetDlgItemText(hDlg, NP_PAGESETUP_HEAD,   Globals.szHeader);
667        SetDlgItemText(hDlg, NP_PAGESETUP_TAIL,   Globals.szFooter);
668        SetDlgItemText(hDlg, NP_PAGESETUP_TOP,    Globals.szMarginTop);
669        SetDlgItemText(hDlg, NP_PAGESETUP_BOTTOM, Globals.szMarginBottom);
670        SetDlgItemText(hDlg, NP_PAGESETUP_LEFT,   Globals.szMarginLeft);
671        SetDlgItemText(hDlg, NP_PAGESETUP_RIGHT,  Globals.szMarginRight);
672        break;
673     }
674
675   return FALSE;
676 }