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