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