Added some Czech resources.
[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 #define UNICODE
24
25 #include <assert.h>
26 #include <stdio.h>
27 #include <windows.h>
28 #include <commdlg.h>
29
30 #include "main.h"
31 #include "license.h"
32 #include "dialog.h"
33
34 static const WCHAR helpfileW[] = { 'n','o','t','e','p','a','d','.','h','l','p',0 };
35
36 static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
37
38 VOID ShowLastError(void)
39 {
40     DWORD error = GetLastError();
41     if (error != NO_ERROR)
42     {
43         LPWSTR lpMsgBuf;
44         WCHAR szTitle[MAX_STRING_LEN];
45
46         LoadString(Globals.hInstance, STRING_ERROR, szTitle, SIZEOF(szTitle));
47         FormatMessage(
48             FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
49             NULL, error, 0,
50             (LPTSTR) &lpMsgBuf, 0, NULL);
51         MessageBox(NULL, lpMsgBuf, szTitle, MB_OK | MB_ICONERROR);
52         LocalFree(lpMsgBuf);
53     }
54 }
55
56 /**
57  * Sets the caption of the main window according to Globals.szFileTitle:
58  *    Notepad - (untitled)      if no file is open
59  *    Notepad - [filename]      if a file is given
60  */
61 static void UpdateWindowCaption(void)
62 {
63   WCHAR szCaption[MAX_STRING_LEN];
64   WCHAR szUntitled[MAX_STRING_LEN];
65
66   LoadString(Globals.hInstance, STRING_NOTEPAD, szCaption, SIZEOF(szCaption));
67
68   if (Globals.szFileTitle[0] != '\0') {
69       static const WCHAR bracket_lW[] = { ' ','-',' ','[',0 };
70       static const WCHAR bracket_rW[] = { ']',0 };
71       lstrcat(szCaption, bracket_lW);
72       lstrcat(szCaption, Globals.szFileTitle);
73       lstrcat(szCaption, bracket_rW);
74   }
75   else
76   {
77       static const WCHAR hyphenW[] = { ' ','-',' ',0 };
78       LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, SIZEOF(szUntitled));
79       lstrcat(szCaption, hyphenW);
80       lstrcat(szCaption, szUntitled);
81   }
82
83   SetWindowText(Globals.hMainWnd, szCaption);
84 }
85
86 static void AlertFileNotFound(LPCWSTR szFileName)
87 {
88    WCHAR szMessage[MAX_STRING_LEN];
89    WCHAR szResource[MAX_STRING_LEN];
90
91    /* Load and format szMessage */
92    LoadString(Globals.hInstance, STRING_NOTFOUND, szResource, SIZEOF(szResource));
93    wsprintf(szMessage, szResource, szFileName);
94
95    /* Load szCaption */
96    LoadString(Globals.hInstance, STRING_ERROR,  szResource, SIZEOF(szResource));
97
98    /* Display Modal Dialog */
99    MessageBox(Globals.hMainWnd, szMessage, szResource, MB_ICONEXCLAMATION);
100 }
101
102 static int AlertFileNotSaved(LPCWSTR szFileName)
103 {
104    WCHAR szMessage[MAX_STRING_LEN];
105    WCHAR szResource[MAX_STRING_LEN];
106    WCHAR szUntitled[MAX_STRING_LEN];
107
108    LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, SIZEOF(szUntitled));
109
110    /* Load and format Message */
111    LoadString(Globals.hInstance, STRING_NOTSAVED, szResource, SIZEOF(szResource));
112    wsprintf(szMessage, szResource, szFileName[0] ? szFileName : szUntitled);
113
114    /* Load Caption */
115    LoadString(Globals.hInstance, STRING_ERROR, szResource, SIZEOF(szResource));
116
117    /* Display modal */
118    return MessageBox(Globals.hMainWnd, szMessage, szResource, MB_ICONEXCLAMATION|MB_YESNOCANCEL);
119 }
120
121 /**
122  * Returns:
123  *   TRUE  - if file exists
124  *   FALSE - if file does not exist
125  */
126 BOOL FileExists(LPCWSTR szFilename)
127 {
128    WIN32_FIND_DATA entry;
129    HANDLE hFile;
130
131    hFile = FindFirstFile(szFilename, &entry);
132    FindClose(hFile);
133
134    return (hFile != INVALID_HANDLE_VALUE);
135 }
136
137
138 static VOID DoSaveFile(VOID)
139 {
140     HANDLE hFile;
141     DWORD dwNumWrite;
142     LPSTR pTemp;
143     DWORD size;
144
145     hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
146                        NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
147     if(hFile == INVALID_HANDLE_VALUE)
148     {
149         ShowLastError();
150         return;
151     }
152
153     size = GetWindowTextLengthA(Globals.hEdit) + 1;
154     pTemp = HeapAlloc(GetProcessHeap(), 0, size);
155     if (!pTemp)
156     {
157         CloseHandle(hFile);
158         ShowLastError();
159         return;
160     }
161     size = GetWindowTextA(Globals.hEdit, pTemp, size);
162
163     if (!WriteFile(hFile, pTemp, size, &dwNumWrite, NULL))
164         ShowLastError();
165
166     CloseHandle(hFile);
167     HeapFree(GetProcessHeap(), 0, pTemp);
168 }
169
170 /**
171  * Returns:
172  *   TRUE  - User agreed to close (both save/don't save)
173  *   FALSE - User cancelled close by selecting "Cancel"
174  */
175 BOOL DoCloseFile(void)
176 {
177     int nResult;
178     static const WCHAR empty_strW[] = { 0 };
179
180     if (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0))
181     {
182         /* prompt user to save changes */
183         nResult = AlertFileNotSaved(Globals.szFileName);
184         switch (nResult) {
185             case IDYES:     DIALOG_FileSave();
186                             break;
187
188             case IDNO:      break;
189
190             case IDCANCEL:  return(FALSE);
191                             break;
192
193             default:        return(FALSE);
194                             break;
195         } /* switch */
196     } /* if */
197
198     SetFileName(empty_strW);
199
200     UpdateWindowCaption();
201     return(TRUE);
202 }
203
204
205 void DoOpenFile(LPCWSTR szFileName)
206 {
207     HANDLE hFile;
208     LPSTR pTemp;
209     DWORD size;
210     DWORD dwNumRead;
211
212     /* Close any files and prompt to save changes */
213     if (!DoCloseFile())
214         return;
215
216     hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
217         OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
218     if(hFile == INVALID_HANDLE_VALUE)
219     {
220         ShowLastError();
221         return;
222     }
223
224     size = GetFileSize(hFile, NULL);
225     if (size == INVALID_FILE_SIZE)
226     {
227         CloseHandle(hFile);
228         ShowLastError();
229         return;
230     }
231     size++;
232
233     pTemp = HeapAlloc(GetProcessHeap(), 0, size);
234     if (!pTemp)
235     {
236         CloseHandle(hFile);
237         ShowLastError();
238         return;
239     }
240
241     if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL))
242     {
243         CloseHandle(hFile);
244         HeapFree(GetProcessHeap(), 0, pTemp);
245         ShowLastError();
246         return;
247     }
248
249     CloseHandle(hFile);
250     pTemp[dwNumRead] = 0;
251
252     if (IsTextUnicode(pTemp, dwNumRead, NULL))
253     {
254         LPWSTR p = (LPWSTR)pTemp;
255         /* We need to strip BOM Unicode character, SetWindowTextW won't do it for us. */
256         if (*p == 0xFEFF || *p == 0xFFFE) p++;
257         SetWindowTextW(Globals.hEdit, p);
258     }
259     else
260         SetWindowTextA(Globals.hEdit, pTemp);
261
262     HeapFree(GetProcessHeap(), 0, pTemp);
263
264     SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
265     SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
266     SetFocus(Globals.hEdit);
267
268     SetFileName(szFileName);
269     UpdateWindowCaption();
270 }
271
272 VOID DIALOG_FileNew(VOID)
273 {
274     static const WCHAR empty_strW[] = { 0 };
275
276     /* Close any files and promt to save changes */
277     if (DoCloseFile()) {
278         SetWindowText(Globals.hEdit, empty_strW);
279         SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
280         SetFocus(Globals.hEdit);
281     }
282 }
283
284 VOID DIALOG_FileOpen(VOID)
285 {
286     OPENFILENAME openfilename;
287     WCHAR szPath[MAX_PATH];
288     WCHAR szDir[MAX_PATH];
289     static const WCHAR szDefaultExt[] = { 't','x','t',0 };
290     static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
291
292     ZeroMemory(&openfilename, sizeof(openfilename));
293
294     GetCurrentDirectory(SIZEOF(szDir), szDir);
295     lstrcpy(szPath, txt_files);
296
297     openfilename.lStructSize       = sizeof(openfilename);
298     openfilename.hwndOwner         = Globals.hMainWnd;
299     openfilename.hInstance         = Globals.hInstance;
300     openfilename.lpstrFilter       = Globals.szFilter;
301     openfilename.lpstrFile         = szPath;
302     openfilename.nMaxFile          = SIZEOF(szPath);
303     openfilename.lpstrInitialDir   = szDir;
304     openfilename.Flags             = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST |
305         OFN_HIDEREADONLY;
306     openfilename.lpstrDefExt       = szDefaultExt;
307
308
309     if (GetOpenFileName(&openfilename)) {
310         if (FileExists(openfilename.lpstrFile))
311             DoOpenFile(openfilename.lpstrFile);
312         else
313             AlertFileNotFound(openfilename.lpstrFile);
314     }
315 }
316
317
318 VOID DIALOG_FileSave(VOID)
319 {
320     if (Globals.szFileName[0] == '\0')
321         DIALOG_FileSaveAs();
322     else
323         DoSaveFile();
324 }
325
326 VOID DIALOG_FileSaveAs(VOID)
327 {
328     OPENFILENAME saveas;
329     WCHAR szPath[MAX_PATH];
330     WCHAR szDir[MAX_PATH];
331     static const WCHAR szDefaultExt[] = { 't','x','t',0 };
332     static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
333
334     ZeroMemory(&saveas, sizeof(saveas));
335
336     GetCurrentDirectory(SIZEOF(szDir), szDir);
337     lstrcpy(szPath, txt_files);
338
339     saveas.lStructSize       = sizeof(OPENFILENAME);
340     saveas.hwndOwner         = Globals.hMainWnd;
341     saveas.hInstance         = Globals.hInstance;
342     saveas.lpstrFilter       = Globals.szFilter;
343     saveas.lpstrFile         = szPath;
344     saveas.nMaxFile          = SIZEOF(szPath);
345     saveas.lpstrInitialDir   = szDir;
346     saveas.Flags             = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT |
347         OFN_HIDEREADONLY;
348     saveas.lpstrDefExt       = szDefaultExt;
349
350     if (GetSaveFileName(&saveas)) {
351         SetFileName(szPath);
352         UpdateWindowCaption();
353         DoSaveFile();
354     }
355 }
356
357 VOID DIALOG_FilePrint(VOID)
358 {
359     DOCINFO di;
360     PRINTDLG printer;
361     SIZE szMetric;
362     int cWidthPels, cHeightPels, border;
363     int xLeft, yTop, pagecount, dopage, copycount;
364     unsigned int i;
365     LOGFONT hdrFont;
366     HFONT font, old_font=0;
367     DWORD size;
368     LPWSTR pTemp;
369     static const WCHAR times_new_romanW[] = { 'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n',0 };
370
371     /* Get a small font and print some header info on each page */
372     hdrFont.lfHeight = 100;
373     hdrFont.lfWidth = 0;
374     hdrFont.lfEscapement = 0;
375     hdrFont.lfOrientation = 0;
376     hdrFont.lfWeight = FW_BOLD;
377     hdrFont.lfItalic = 0;
378     hdrFont.lfUnderline = 0;
379     hdrFont.lfStrikeOut = 0;
380     hdrFont.lfCharSet = ANSI_CHARSET;
381     hdrFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
382     hdrFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
383     hdrFont.lfQuality = PROOF_QUALITY;
384     hdrFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
385     lstrcpy(hdrFont.lfFaceName, times_new_romanW);
386     
387     font = CreateFontIndirect(&hdrFont);
388     
389     /* Get Current Settings */
390     ZeroMemory(&printer, sizeof(printer));
391     printer.lStructSize           = sizeof(printer);
392     printer.hwndOwner             = Globals.hMainWnd;
393     printer.hInstance             = Globals.hInstance;
394     
395     /* Set some default flags */
396     printer.Flags                 = PD_RETURNDC;
397     printer.nFromPage             = 0;
398     printer.nMinPage              = 1;
399     /* we really need to calculate number of pages to set nMaxPage and nToPage */
400     printer.nToPage               = 0;
401     printer.nMaxPage              = -1;
402
403     /* Let commdlg manage copy settings */
404     printer.nCopies               = (WORD)PD_USEDEVMODECOPIES;
405
406     if (!PrintDlg(&printer)) return;
407
408     assert(printer.hDC != 0);
409
410     /* initialize DOCINFO */
411     di.cbSize = sizeof(DOCINFO);
412     di.lpszDocName = Globals.szFileTitle;
413     di.lpszOutput = NULL;
414     di.lpszDatatype = NULL;
415     di.fwType = 0; 
416
417     if (StartDoc(printer.hDC, &di) <= 0) return;
418     
419     /* Get the page dimensions in pixels. */
420     cWidthPels = GetDeviceCaps(printer.hDC, HORZRES);
421     cHeightPels = GetDeviceCaps(printer.hDC, VERTRES);
422
423     /* Get the file text */
424     size = GetWindowTextLength(Globals.hEdit) + 1;
425     pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
426     if (!pTemp)
427     {
428         ShowLastError();
429         return;
430     }
431     size = GetWindowText(Globals.hEdit, pTemp, size);
432     
433     border = 150;
434     for (copycount=1; copycount <= printer.nCopies; copycount++) {
435         i = 0;
436         pagecount = 1;
437         do {
438             static const WCHAR letterM[] = { 'M',0 };
439
440             if (pagecount >= printer.nFromPage &&
441     /*          ((printer.Flags & PD_PAGENUMS) == 0 ||  pagecount <= printer.nToPage))*/
442             pagecount <= printer.nToPage)
443                 dopage = 1;
444             else
445                 dopage = 0;
446             
447             old_font = SelectObject(printer.hDC, font);
448             GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric);
449                 
450             if (dopage) {
451                 if (StartPage(printer.hDC) <= 0) {
452                     static const WCHAR failedW[] = { 'S','t','a','r','t','P','a','g','e',' ','f','a','i','l','e','d',0 };
453                     static const WCHAR errorW[] = { 'P','r','i','n','t',' ','E','r','r','o','r',0 };
454                     MessageBox(Globals.hMainWnd, failedW, errorW, MB_ICONEXCLAMATION);
455                     return;
456                 }
457                 /* Write a rectangle and header at the top of each page */
458                 Rectangle(printer.hDC, border, border, cWidthPels-border, border+szMetric.cy*2);
459                 /* I don't know what's up with this TextOut command. This comes out
460                 kind of mangled.
461                 */
462                 TextOut(printer.hDC, border*2, border+szMetric.cy/2, Globals.szFileTitle, lstrlen(Globals.szFileTitle));
463             }
464             
465             /* The starting point for the main text */
466             xLeft = border*2;
467             yTop = border+szMetric.cy*4;
468             
469             SelectObject(printer.hDC, old_font);
470             GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric); 
471             
472             /* Since outputting strings is giving me problems, output the main
473             text one character at a time.
474             */
475             do {
476                 if (pTemp[i] == '\n') {
477                     xLeft = border*2;
478                     yTop += szMetric.cy;
479                 }
480                 else if (pTemp[i] != '\r') {
481                     if (dopage)
482                         TextOut(printer.hDC, xLeft, yTop, &pTemp[i], 1);
483                     xLeft += szMetric.cx;
484                 }
485             } while (i++<size && yTop<(cHeightPels-border*2));
486             
487             if (dopage)
488                 EndPage(printer.hDC);
489             pagecount++;
490         } while (i<size);
491     }
492
493     EndDoc(printer.hDC);
494     DeleteDC(printer.hDC);
495     HeapFree(GetProcessHeap(), 0, pTemp);
496 }
497
498 VOID DIALOG_FilePrinterSetup(VOID)
499 {
500     PRINTDLG printer;
501
502     ZeroMemory(&printer, sizeof(printer));
503     printer.lStructSize         = sizeof(printer);
504     printer.hwndOwner           = Globals.hMainWnd;
505     printer.hInstance           = Globals.hInstance;
506     printer.Flags               = PD_PRINTSETUP;
507     printer.nCopies             = 1;
508
509     PrintDlg(&printer);
510 }
511
512 VOID DIALOG_FileExit(VOID)
513 {
514     PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0l);
515 }
516
517 VOID DIALOG_EditUndo(VOID)
518 {
519     SendMessage(Globals.hEdit, EM_UNDO, 0, 0);
520 }
521
522 VOID DIALOG_EditCut(VOID)
523 {
524     SendMessage(Globals.hEdit, WM_CUT, 0, 0);
525 }
526
527 VOID DIALOG_EditCopy(VOID)
528 {
529     SendMessage(Globals.hEdit, WM_COPY, 0, 0);
530 }
531
532 VOID DIALOG_EditPaste(VOID)
533 {
534     SendMessage(Globals.hEdit, WM_PASTE, 0, 0);
535 }
536
537 VOID DIALOG_EditDelete(VOID)
538 {
539     SendMessage(Globals.hEdit, WM_CLEAR, 0, 0);
540 }
541
542 VOID DIALOG_EditSelectAll(VOID)
543 {
544     SendMessage(Globals.hEdit, EM_SETSEL, 0, (LPARAM)-1);
545 }
546
547 VOID DIALOG_EditTimeDate(VOID)
548 {
549     SYSTEMTIME   st;
550     WCHAR        szDate[MAX_STRING_LEN];
551     static const WCHAR spaceW[] = { ' ',0 };
552
553     GetLocalTime(&st);
554
555     GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, szDate, MAX_STRING_LEN);
556     SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
557
558     SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)spaceW);
559
560     GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, szDate, MAX_STRING_LEN);
561     SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
562 }
563
564 VOID DIALOG_EditWrap(VOID)
565 {
566     Globals.bWrapLongLines = !Globals.bWrapLongLines;
567     CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
568         MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
569 }
570
571 VOID DIALOG_SelectFont(VOID)
572 {
573     CHOOSEFONT cf;
574     LOGFONT lf=Globals.lfFont;
575
576     ZeroMemory( &cf, sizeof(cf) );
577     cf.lStructSize=sizeof(cf);
578     cf.hwndOwner=Globals.hMainWnd;
579     cf.lpLogFont=&lf;
580     cf.Flags=CF_SCREENFONTS;
581
582     if( ChooseFont(&cf) )
583     {
584         HFONT currfont=Globals.hFont;
585
586         Globals.hFont=CreateFontIndirect( &lf );
587         Globals.lfFont=lf;
588         SendMessage( Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)TRUE );
589         if( currfont!=NULL )
590             DeleteObject( currfont );
591     }
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    = 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     /* FIXME: Search Next */
614     DIALOG_Search();
615 }
616
617 VOID DIALOG_HelpContents(VOID)
618 {
619     WinHelp(Globals.hMainWnd, helpfileW, HELP_INDEX, 0);
620 }
621
622 VOID DIALOG_HelpSearch(VOID)
623 {
624         /* Search Help */
625 }
626
627 VOID DIALOG_HelpHelp(VOID)
628 {
629     WinHelp(Globals.hMainWnd, helpfileW, HELP_HELPONHELP, 0);
630 }
631
632 VOID DIALOG_HelpLicense(VOID)
633 {
634         WineLicense(Globals.hMainWnd);
635 }
636
637 VOID DIALOG_HelpNoWarranty(VOID)
638 {
639         WineWarranty(Globals.hMainWnd);
640 }
641
642 VOID DIALOG_HelpAboutWine(VOID)
643 {
644     static const WCHAR notepadW[] = { 'N','o','t','e','p','a','d','\n',0 };
645     WCHAR szNotepad[MAX_STRING_LEN];
646
647     LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad));
648     ShellAbout(Globals.hMainWnd, szNotepad, notepadW, 0);
649 }
650
651
652 /***********************************************************************
653  *
654  *           DIALOG_FilePageSetup
655  */
656 VOID DIALOG_FilePageSetup(void)
657 {
658   DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP),
659             Globals.hMainWnd, DIALOG_PAGESETUP_DlgProc);
660 }
661
662
663 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
664  *
665  *           DIALOG_PAGESETUP_DlgProc
666  */
667
668 static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
669 {
670
671    switch (msg)
672     {
673     case WM_COMMAND:
674       switch (wParam)
675         {
676         case IDOK:
677           /* save user input and close dialog */
678           GetDlgItemText(hDlg, 0x141, Globals.szHeader, SIZEOF(Globals.szHeader));
679           GetDlgItemText(hDlg, 0x143, Globals.szFooter, SIZEOF(Globals.szFooter));
680           GetDlgItemText(hDlg, 0x14A, Globals.szMarginTop, SIZEOF(Globals.szMarginTop));
681           GetDlgItemText(hDlg, 0x150, Globals.szMarginBottom, SIZEOF(Globals.szMarginBottom));
682           GetDlgItemText(hDlg, 0x147, Globals.szMarginLeft, SIZEOF(Globals.szMarginLeft));
683           GetDlgItemText(hDlg, 0x14D, Globals.szMarginRight, SIZEOF(Globals.szMarginRight));
684           EndDialog(hDlg, IDOK);
685           return TRUE;
686
687         case IDCANCEL:
688           /* discard user input and close dialog */
689           EndDialog(hDlg, IDCANCEL);
690           return TRUE;
691
692         case IDHELP:
693         {
694           /* FIXME: Bring this to work */
695           static const WCHAR sorryW[] = { 'S','o','r','r','y',',',' ','n','o',' ','h','e','l','p',' ','a','v','a','i','l','a','b','l','e',0 };
696           static const WCHAR helpW[] = { 'H','e','l','p',0 };
697           MessageBox(Globals.hMainWnd, sorryW, helpW, MB_ICONEXCLAMATION);
698           return TRUE;
699         }
700
701         default:
702             break;
703         }
704       break;
705
706     case WM_INITDIALOG:
707        /* fetch last user input prior to display dialog */
708        SetDlgItemText(hDlg, 0x141, Globals.szHeader);
709        SetDlgItemText(hDlg, 0x143, Globals.szFooter);
710        SetDlgItemText(hDlg, 0x14A, Globals.szMarginTop);
711        SetDlgItemText(hDlg, 0x150, Globals.szMarginBottom);
712        SetDlgItemText(hDlg, 0x147, Globals.szMarginLeft);
713        SetDlgItemText(hDlg, 0x14D, Globals.szMarginRight);
714        break;
715     }
716
717   return FALSE;
718 }