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