Prevent crash when no URL is specified.
[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     else
166         SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
167
168     CloseHandle(hFile);
169     HeapFree(GetProcessHeap(), 0, pTemp);
170 }
171
172 /**
173  * Returns:
174  *   TRUE  - User agreed to close (both save/don't save)
175  *   FALSE - User cancelled close by selecting "Cancel"
176  */
177 BOOL DoCloseFile(void)
178 {
179     int nResult;
180     static const WCHAR empty_strW[] = { 0 };
181
182     if (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0))
183     {
184         /* prompt user to save changes */
185         nResult = AlertFileNotSaved(Globals.szFileName);
186         switch (nResult) {
187             case IDYES:     DIALOG_FileSave();
188                             break;
189
190             case IDNO:      break;
191
192             case IDCANCEL:  return(FALSE);
193                             break;
194
195             default:        return(FALSE);
196                             break;
197         } /* switch */
198     } /* if */
199
200     SetFileName(empty_strW);
201
202     UpdateWindowCaption();
203     return(TRUE);
204 }
205
206
207 void DoOpenFile(LPCWSTR szFileName)
208 {
209     HANDLE hFile;
210     LPSTR pTemp;
211     DWORD size;
212     DWORD dwNumRead;
213
214     /* Close any files and prompt to save changes */
215     if (!DoCloseFile())
216         return;
217
218     hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
219         OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
220     if(hFile == INVALID_HANDLE_VALUE)
221     {
222         ShowLastError();
223         return;
224     }
225
226     size = GetFileSize(hFile, NULL);
227     if (size == INVALID_FILE_SIZE)
228     {
229         CloseHandle(hFile);
230         ShowLastError();
231         return;
232     }
233     size++;
234
235     pTemp = HeapAlloc(GetProcessHeap(), 0, size);
236     if (!pTemp)
237     {
238         CloseHandle(hFile);
239         ShowLastError();
240         return;
241     }
242
243     if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL))
244     {
245         CloseHandle(hFile);
246         HeapFree(GetProcessHeap(), 0, pTemp);
247         ShowLastError();
248         return;
249     }
250
251     CloseHandle(hFile);
252     pTemp[dwNumRead] = 0;
253
254     if (IsTextUnicode(pTemp, dwNumRead, NULL))
255     {
256         LPWSTR p = (LPWSTR)pTemp;
257         /* We need to strip BOM Unicode character, SetWindowTextW won't do it for us. */
258         if (*p == 0xFEFF || *p == 0xFFFE) p++;
259         SetWindowTextW(Globals.hEdit, p);
260     }
261     else
262         SetWindowTextA(Globals.hEdit, pTemp);
263
264     HeapFree(GetProcessHeap(), 0, pTemp);
265
266     SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
267     SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
268     SetFocus(Globals.hEdit);
269
270     SetFileName(szFileName);
271     UpdateWindowCaption();
272 }
273
274 VOID DIALOG_FileNew(VOID)
275 {
276     static const WCHAR empty_strW[] = { 0 };
277
278     /* Close any files and promt to save changes */
279     if (DoCloseFile()) {
280         SetWindowText(Globals.hEdit, empty_strW);
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     WCHAR szPath[MAX_PATH];
290     WCHAR szDir[MAX_PATH];
291     static const WCHAR szDefaultExt[] = { 't','x','t',0 };
292     static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
293
294     ZeroMemory(&openfilename, sizeof(openfilename));
295
296     GetCurrentDirectory(SIZEOF(szDir), szDir);
297     lstrcpy(szPath, txt_files);
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     WCHAR szPath[MAX_PATH];
332     WCHAR szDir[MAX_PATH];
333     static const WCHAR szDefaultExt[] = { 't','x','t',0 };
334     static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
335
336     ZeroMemory(&saveas, sizeof(saveas));
337
338     GetCurrentDirectory(SIZEOF(szDir), szDir);
339     lstrcpy(szPath, txt_files);
340
341     saveas.lStructSize       = sizeof(OPENFILENAME);
342     saveas.hwndOwner         = Globals.hMainWnd;
343     saveas.hInstance         = Globals.hInstance;
344     saveas.lpstrFilter       = Globals.szFilter;
345     saveas.lpstrFile         = szPath;
346     saveas.nMaxFile          = SIZEOF(szPath);
347     saveas.lpstrInitialDir   = szDir;
348     saveas.Flags             = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT |
349         OFN_HIDEREADONLY;
350     saveas.lpstrDefExt       = szDefaultExt;
351
352     if (GetSaveFileName(&saveas)) {
353         SetFileName(szPath);
354         UpdateWindowCaption();
355         DoSaveFile();
356     }
357 }
358
359 VOID DIALOG_FilePrint(VOID)
360 {
361     DOCINFO di;
362     PRINTDLG printer;
363     SIZE szMetric;
364     int cWidthPels, cHeightPels, border;
365     int xLeft, yTop, pagecount, dopage, copycount;
366     unsigned int i;
367     LOGFONT hdrFont;
368     HFONT font, old_font=0;
369     DWORD size;
370     LPWSTR pTemp;
371     static const WCHAR times_new_romanW[] = { 'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n',0 };
372
373     /* Get a small font and print some header info on each page */
374     hdrFont.lfHeight = 100;
375     hdrFont.lfWidth = 0;
376     hdrFont.lfEscapement = 0;
377     hdrFont.lfOrientation = 0;
378     hdrFont.lfWeight = FW_BOLD;
379     hdrFont.lfItalic = 0;
380     hdrFont.lfUnderline = 0;
381     hdrFont.lfStrikeOut = 0;
382     hdrFont.lfCharSet = ANSI_CHARSET;
383     hdrFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
384     hdrFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
385     hdrFont.lfQuality = PROOF_QUALITY;
386     hdrFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
387     lstrcpy(hdrFont.lfFaceName, times_new_romanW);
388     
389     font = CreateFontIndirect(&hdrFont);
390     
391     /* Get Current Settings */
392     ZeroMemory(&printer, sizeof(printer));
393     printer.lStructSize           = sizeof(printer);
394     printer.hwndOwner             = Globals.hMainWnd;
395     printer.hInstance             = Globals.hInstance;
396     
397     /* Set some default flags */
398     printer.Flags                 = PD_RETURNDC;
399     printer.nFromPage             = 0;
400     printer.nMinPage              = 1;
401     /* we really need to calculate number of pages to set nMaxPage and nToPage */
402     printer.nToPage               = 0;
403     printer.nMaxPage              = -1;
404
405     /* Let commdlg manage copy settings */
406     printer.nCopies               = (WORD)PD_USEDEVMODECOPIES;
407
408     if (!PrintDlg(&printer)) return;
409
410     assert(printer.hDC != 0);
411
412     /* initialize DOCINFO */
413     di.cbSize = sizeof(DOCINFO);
414     di.lpszDocName = Globals.szFileTitle;
415     di.lpszOutput = NULL;
416     di.lpszDatatype = NULL;
417     di.fwType = 0; 
418
419     if (StartDoc(printer.hDC, &di) <= 0) return;
420     
421     /* Get the page dimensions in pixels. */
422     cWidthPels = GetDeviceCaps(printer.hDC, HORZRES);
423     cHeightPels = GetDeviceCaps(printer.hDC, VERTRES);
424
425     /* Get the file text */
426     size = GetWindowTextLength(Globals.hEdit) + 1;
427     pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
428     if (!pTemp)
429     {
430         ShowLastError();
431         return;
432     }
433     size = GetWindowText(Globals.hEdit, pTemp, size);
434     
435     border = 150;
436     for (copycount=1; copycount <= printer.nCopies; copycount++) {
437         i = 0;
438         pagecount = 1;
439         do {
440             static const WCHAR letterM[] = { 'M',0 };
441
442             if (pagecount >= printer.nFromPage &&
443     /*          ((printer.Flags & PD_PAGENUMS) == 0 ||  pagecount <= printer.nToPage))*/
444             pagecount <= printer.nToPage)
445                 dopage = 1;
446             else
447                 dopage = 0;
448             
449             old_font = SelectObject(printer.hDC, font);
450             GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric);
451                 
452             if (dopage) {
453                 if (StartPage(printer.hDC) <= 0) {
454                     static const WCHAR failedW[] = { 'S','t','a','r','t','P','a','g','e',' ','f','a','i','l','e','d',0 };
455                     static const WCHAR errorW[] = { 'P','r','i','n','t',' ','E','r','r','o','r',0 };
456                     MessageBox(Globals.hMainWnd, failedW, errorW, MB_ICONEXCLAMATION);
457                     return;
458                 }
459                 /* Write a rectangle and header at the top of each page */
460                 Rectangle(printer.hDC, border, border, cWidthPels-border, border+szMetric.cy*2);
461                 /* I don't know what's up with this TextOut command. This comes out
462                 kind of mangled.
463                 */
464                 TextOut(printer.hDC, border*2, border+szMetric.cy/2, Globals.szFileTitle, lstrlen(Globals.szFileTitle));
465             }
466             
467             /* The starting point for the main text */
468             xLeft = border*2;
469             yTop = border+szMetric.cy*4;
470             
471             SelectObject(printer.hDC, old_font);
472             GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric); 
473             
474             /* Since outputting strings is giving me problems, output the main
475             text one character at a time.
476             */
477             do {
478                 if (pTemp[i] == '\n') {
479                     xLeft = border*2;
480                     yTop += szMetric.cy;
481                 }
482                 else if (pTemp[i] != '\r') {
483                     if (dopage)
484                         TextOut(printer.hDC, xLeft, yTop, &pTemp[i], 1);
485                     xLeft += szMetric.cx;
486                 }
487             } while (i++<size && yTop<(cHeightPels-border*2));
488             
489             if (dopage)
490                 EndPage(printer.hDC);
491             pagecount++;
492         } while (i<size);
493     }
494
495     EndDoc(printer.hDC);
496     DeleteDC(printer.hDC);
497     HeapFree(GetProcessHeap(), 0, pTemp);
498 }
499
500 VOID DIALOG_FilePrinterSetup(VOID)
501 {
502     PRINTDLG printer;
503
504     ZeroMemory(&printer, sizeof(printer));
505     printer.lStructSize         = sizeof(printer);
506     printer.hwndOwner           = Globals.hMainWnd;
507     printer.hInstance           = Globals.hInstance;
508     printer.Flags               = PD_PRINTSETUP;
509     printer.nCopies             = 1;
510
511     PrintDlg(&printer);
512 }
513
514 VOID DIALOG_FileExit(VOID)
515 {
516     PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0l);
517 }
518
519 VOID DIALOG_EditUndo(VOID)
520 {
521     SendMessage(Globals.hEdit, EM_UNDO, 0, 0);
522 }
523
524 VOID DIALOG_EditCut(VOID)
525 {
526     SendMessage(Globals.hEdit, WM_CUT, 0, 0);
527 }
528
529 VOID DIALOG_EditCopy(VOID)
530 {
531     SendMessage(Globals.hEdit, WM_COPY, 0, 0);
532 }
533
534 VOID DIALOG_EditPaste(VOID)
535 {
536     SendMessage(Globals.hEdit, WM_PASTE, 0, 0);
537 }
538
539 VOID DIALOG_EditDelete(VOID)
540 {
541     SendMessage(Globals.hEdit, WM_CLEAR, 0, 0);
542 }
543
544 VOID DIALOG_EditSelectAll(VOID)
545 {
546     SendMessage(Globals.hEdit, EM_SETSEL, 0, (LPARAM)-1);
547 }
548
549 VOID DIALOG_EditTimeDate(VOID)
550 {
551     SYSTEMTIME   st;
552     WCHAR        szDate[MAX_STRING_LEN];
553     static const WCHAR spaceW[] = { ' ',0 };
554
555     GetLocalTime(&st);
556
557     GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, szDate, MAX_STRING_LEN);
558     SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
559
560     SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)spaceW);
561
562     GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, szDate, MAX_STRING_LEN);
563     SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
564 }
565
566 VOID DIALOG_EditWrap(VOID)
567 {
568     static const WCHAR editW[] = { 'e','d','i','t',0 };
569     DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL |
570                     ES_AUTOVSCROLL | ES_MULTILINE;
571     RECT rc;
572     DWORD size;
573     LPWSTR pTemp;
574
575     size = GetWindowTextLength(Globals.hEdit) + 1;
576     pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
577     if (!pTemp)
578     {
579         ShowLastError();
580         return;
581     }
582     GetWindowText(Globals.hEdit, pTemp, size);
583     DestroyWindow(Globals.hEdit);
584     GetClientRect(Globals.hMainWnd, &rc);
585     if( Globals.bWrapLongLines ) dwStyle |= WS_HSCROLL | ES_AUTOHSCROLL;
586     Globals.hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, editW, NULL, dwStyle,
587                          0, 0, rc.right, rc.bottom, Globals.hMainWnd,
588                          NULL, Globals.hInstance, NULL);
589     SendMessage(Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)FALSE);
590     SetWindowTextW(Globals.hEdit, pTemp);
591     SetFocus(Globals.hEdit);
592     HeapFree(GetProcessHeap(), 0, pTemp);
593     
594     Globals.bWrapLongLines = !Globals.bWrapLongLines;
595     CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
596         MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
597 }
598
599 VOID DIALOG_SelectFont(VOID)
600 {
601     CHOOSEFONT cf;
602     LOGFONT lf=Globals.lfFont;
603
604     ZeroMemory( &cf, sizeof(cf) );
605     cf.lStructSize=sizeof(cf);
606     cf.hwndOwner=Globals.hMainWnd;
607     cf.lpLogFont=&lf;
608     cf.Flags=CF_SCREENFONTS;
609
610     if( ChooseFont(&cf) )
611     {
612         HFONT currfont=Globals.hFont;
613
614         Globals.hFont=CreateFontIndirect( &lf );
615         Globals.lfFont=lf;
616         SendMessage( Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)TRUE );
617         if( currfont!=NULL )
618             DeleteObject( currfont );
619     }
620 }
621
622 VOID DIALOG_Search(VOID)
623 {
624         ZeroMemory(&Globals.find, sizeof(Globals.find));
625         Globals.find.lStructSize      = sizeof(Globals.find);
626         Globals.find.hwndOwner        = Globals.hMainWnd;
627         Globals.find.hInstance        = Globals.hInstance;
628         Globals.find.lpstrFindWhat    = Globals.szFindText;
629         Globals.find.wFindWhatLen     = SIZEOF(Globals.szFindText);
630         Globals.find.Flags            = FR_DOWN;
631
632         /* We only need to create the modal FindReplace dialog which will */
633         /* notify us of incoming events using hMainWnd Window Messages    */
634
635         Globals.hFindReplaceDlg = FindText(&Globals.find);
636         assert(Globals.hFindReplaceDlg !=0);
637 }
638
639 VOID DIALOG_SearchNext(VOID)
640 {
641     /* FIXME: Search Next */
642     DIALOG_Search();
643 }
644
645 VOID DIALOG_HelpContents(VOID)
646 {
647     WinHelp(Globals.hMainWnd, helpfileW, HELP_INDEX, 0);
648 }
649
650 VOID DIALOG_HelpSearch(VOID)
651 {
652         /* Search Help */
653 }
654
655 VOID DIALOG_HelpHelp(VOID)
656 {
657     WinHelp(Globals.hMainWnd, helpfileW, HELP_HELPONHELP, 0);
658 }
659
660 VOID DIALOG_HelpLicense(VOID)
661 {
662         WineLicense(Globals.hMainWnd);
663 }
664
665 VOID DIALOG_HelpNoWarranty(VOID)
666 {
667         WineWarranty(Globals.hMainWnd);
668 }
669
670 VOID DIALOG_HelpAboutWine(VOID)
671 {
672     static const WCHAR notepadW[] = { 'N','o','t','e','p','a','d','\n',0 };
673     WCHAR szNotepad[MAX_STRING_LEN];
674
675     LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad));
676     ShellAbout(Globals.hMainWnd, szNotepad, notepadW, 0);
677 }
678
679
680 /***********************************************************************
681  *
682  *           DIALOG_FilePageSetup
683  */
684 VOID DIALOG_FilePageSetup(void)
685 {
686   DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP),
687             Globals.hMainWnd, DIALOG_PAGESETUP_DlgProc);
688 }
689
690
691 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
692  *
693  *           DIALOG_PAGESETUP_DlgProc
694  */
695
696 static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
697 {
698
699    switch (msg)
700     {
701     case WM_COMMAND:
702       switch (wParam)
703         {
704         case IDOK:
705           /* save user input and close dialog */
706           GetDlgItemText(hDlg, 0x141, Globals.szHeader, SIZEOF(Globals.szHeader));
707           GetDlgItemText(hDlg, 0x143, Globals.szFooter, SIZEOF(Globals.szFooter));
708           GetDlgItemText(hDlg, 0x14A, Globals.szMarginTop, SIZEOF(Globals.szMarginTop));
709           GetDlgItemText(hDlg, 0x150, Globals.szMarginBottom, SIZEOF(Globals.szMarginBottom));
710           GetDlgItemText(hDlg, 0x147, Globals.szMarginLeft, SIZEOF(Globals.szMarginLeft));
711           GetDlgItemText(hDlg, 0x14D, Globals.szMarginRight, SIZEOF(Globals.szMarginRight));
712           EndDialog(hDlg, IDOK);
713           return TRUE;
714
715         case IDCANCEL:
716           /* discard user input and close dialog */
717           EndDialog(hDlg, IDCANCEL);
718           return TRUE;
719
720         case IDHELP:
721         {
722           /* FIXME: Bring this to work */
723           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 };
724           static const WCHAR helpW[] = { 'H','e','l','p',0 };
725           MessageBox(Globals.hMainWnd, sorryW, helpW, MB_ICONEXCLAMATION);
726           return TRUE;
727         }
728
729         default:
730             break;
731         }
732       break;
733
734     case WM_INITDIALOG:
735        /* fetch last user input prior to display dialog */
736        SetDlgItemText(hDlg, 0x141, Globals.szHeader);
737        SetDlgItemText(hDlg, 0x143, Globals.szFooter);
738        SetDlgItemText(hDlg, 0x14A, Globals.szMarginTop);
739        SetDlgItemText(hDlg, 0x150, Globals.szMarginBottom);
740        SetDlgItemText(hDlg, 0x147, Globals.szMarginLeft);
741        SetDlgItemText(hDlg, 0x14D, Globals.szMarginRight);
742        break;
743     }
744
745   return FALSE;
746 }