Korean: Use SUBLANG_NEUTRAL in Korean 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., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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 "dialog.h"
32
33 #define SPACES_IN_TAB 8
34 #define PRINT_LEN_MAX 120
35
36 static const WCHAR helpfileW[] = { 'n','o','t','e','p','a','d','.','h','l','p',0 };
37
38 static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
39
40 VOID ShowLastError(void)
41 {
42     DWORD error = GetLastError();
43     if (error != NO_ERROR)
44     {
45         LPWSTR lpMsgBuf;
46         WCHAR szTitle[MAX_STRING_LEN];
47
48         LoadString(Globals.hInstance, STRING_ERROR, szTitle, SIZEOF(szTitle));
49         FormatMessage(
50             FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
51             NULL, error, 0,
52             (LPTSTR) &lpMsgBuf, 0, NULL);
53         MessageBox(NULL, lpMsgBuf, szTitle, MB_OK | MB_ICONERROR);
54         LocalFree(lpMsgBuf);
55     }
56 }
57
58 /**
59  * Sets the caption of the main window according to Globals.szFileTitle:
60  *    Untitled - Notepad        if no file is open
61  *    filename - Notepad        if a file is given
62  */
63 static void UpdateWindowCaption(void)
64 {
65   WCHAR szCaption[MAX_STRING_LEN];
66   WCHAR szNotepad[MAX_STRING_LEN];
67   static const WCHAR hyphenW[] = { ' ','-',' ',0 };
68
69   if (Globals.szFileTitle[0] != '\0')
70       lstrcpy(szCaption, Globals.szFileTitle);
71   else
72       LoadString(Globals.hInstance, STRING_UNTITLED, szCaption, SIZEOF(szCaption));
73
74   LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad));
75   lstrcat(szCaption, hyphenW);
76   lstrcat(szCaption, szNotepad);
77
78   SetWindowText(Globals.hMainWnd, szCaption);
79 }
80
81 static void AlertFileNotFound(LPCWSTR szFileName)
82 {
83    WCHAR szMessage[MAX_STRING_LEN];
84    WCHAR szResource[MAX_STRING_LEN];
85
86    /* Load and format szMessage */
87    LoadString(Globals.hInstance, STRING_NOTFOUND, szResource, SIZEOF(szResource));
88    wsprintf(szMessage, szResource, szFileName);
89
90    /* Load szCaption */
91    LoadString(Globals.hInstance, STRING_ERROR,  szResource, SIZEOF(szResource));
92
93    /* Display Modal Dialog */
94    MessageBox(Globals.hMainWnd, szMessage, szResource, MB_ICONEXCLAMATION);
95 }
96
97 static int AlertFileNotSaved(LPCWSTR szFileName)
98 {
99    WCHAR szMessage[MAX_STRING_LEN];
100    WCHAR szResource[MAX_STRING_LEN];
101    WCHAR szUntitled[MAX_STRING_LEN];
102
103    LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, SIZEOF(szUntitled));
104
105    /* Load and format Message */
106    LoadString(Globals.hInstance, STRING_NOTSAVED, szResource, SIZEOF(szResource));
107    wsprintf(szMessage, szResource, szFileName[0] ? szFileName : szUntitled);
108
109    /* Load Caption */
110    LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, SIZEOF(szResource));
111
112    /* Display modal */
113    return MessageBox(Globals.hMainWnd, szMessage, szResource, MB_ICONEXCLAMATION|MB_YESNOCANCEL);
114 }
115
116 /**
117  * Returns:
118  *   TRUE  - if file exists
119  *   FALSE - if file does not exist
120  */
121 BOOL FileExists(LPCWSTR szFilename)
122 {
123    WIN32_FIND_DATA entry;
124    HANDLE hFile;
125
126    hFile = FindFirstFile(szFilename, &entry);
127    FindClose(hFile);
128
129    return (hFile != INVALID_HANDLE_VALUE);
130 }
131
132
133 static VOID DoSaveFile(VOID)
134 {
135     HANDLE hFile;
136     DWORD dwNumWrite;
137     LPSTR pTemp;
138     DWORD size;
139
140     hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
141                        NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
142     if(hFile == INVALID_HANDLE_VALUE)
143     {
144         ShowLastError();
145         return;
146     }
147
148     size = GetWindowTextLengthA(Globals.hEdit) + 1;
149     pTemp = HeapAlloc(GetProcessHeap(), 0, size);
150     if (!pTemp)
151     {
152         CloseHandle(hFile);
153         ShowLastError();
154         return;
155     }
156     size = GetWindowTextA(Globals.hEdit, pTemp, size);
157
158     if (!WriteFile(hFile, pTemp, size, &dwNumWrite, NULL))
159         ShowLastError();
160     else
161         SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
162
163     SetEndOfFile(hFile);
164     CloseHandle(hFile);
165     HeapFree(GetProcessHeap(), 0, pTemp);
166 }
167
168 /**
169  * Returns:
170  *   TRUE  - User agreed to close (both save/don't save)
171  *   FALSE - User cancelled close by selecting "Cancel"
172  */
173 BOOL DoCloseFile(void)
174 {
175     int nResult;
176     static const WCHAR empty_strW[] = { 0 };
177
178     if (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0))
179     {
180         /* prompt user to save changes */
181         nResult = AlertFileNotSaved(Globals.szFileName);
182         switch (nResult) {
183             case IDYES:     DIALOG_FileSave();
184                             break;
185
186             case IDNO:      break;
187
188             case IDCANCEL:  return(FALSE);
189                             break;
190
191             default:        return(FALSE);
192                             break;
193         } /* switch */
194     } /* if */
195
196     SetFileName(empty_strW);
197
198     UpdateWindowCaption();
199     return(TRUE);
200 }
201
202
203 void DoOpenFile(LPCWSTR szFileName)
204 {
205     static const WCHAR dotlog[] = { '.','L','O','G',0 };
206     HANDLE hFile;
207     LPSTR pTemp;
208     DWORD size;
209     DWORD dwNumRead;
210     WCHAR log[5];
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     /*  If the file starts with .LOG, add a time/date at the end and set cursor after
269      *  See http://support.microsoft.com/?kbid=260563
270      */
271     if (GetWindowTextW(Globals.hEdit, log, sizeof(log)/sizeof(log[0])) && !lstrcmp(log, dotlog))
272     {
273         static const WCHAR lfW[] = { '\r','\n',0 };
274         SendMessage(Globals.hEdit, EM_SETSEL, GetWindowTextLength(Globals.hEdit), -1);
275         SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lfW);
276         DIALOG_EditTimeDate();
277         SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lfW);
278     }
279
280     SetFileName(szFileName);
281     UpdateWindowCaption();
282 }
283
284 VOID DIALOG_FileNew(VOID)
285 {
286     static const WCHAR empty_strW[] = { 0 };
287
288     /* Close any files and promt to save changes */
289     if (DoCloseFile()) {
290         SetWindowText(Globals.hEdit, empty_strW);
291         SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
292         SetFocus(Globals.hEdit);
293     }
294 }
295
296 VOID DIALOG_FileOpen(VOID)
297 {
298     OPENFILENAME openfilename;
299     WCHAR szPath[MAX_PATH];
300     WCHAR szDir[MAX_PATH];
301     static const WCHAR szDefaultExt[] = { 't','x','t',0 };
302     static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
303
304     ZeroMemory(&openfilename, sizeof(openfilename));
305
306     GetCurrentDirectory(SIZEOF(szDir), szDir);
307     lstrcpy(szPath, txt_files);
308
309     openfilename.lStructSize       = sizeof(openfilename);
310     openfilename.hwndOwner         = Globals.hMainWnd;
311     openfilename.hInstance         = Globals.hInstance;
312     openfilename.lpstrFilter       = Globals.szFilter;
313     openfilename.lpstrFile         = szPath;
314     openfilename.nMaxFile          = SIZEOF(szPath);
315     openfilename.lpstrInitialDir   = szDir;
316     openfilename.Flags             = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST |
317         OFN_HIDEREADONLY;
318     openfilename.lpstrDefExt       = szDefaultExt;
319
320
321     if (GetOpenFileName(&openfilename)) {
322         if (FileExists(openfilename.lpstrFile))
323             DoOpenFile(openfilename.lpstrFile);
324         else
325             AlertFileNotFound(openfilename.lpstrFile);
326     }
327 }
328
329
330 VOID DIALOG_FileSave(VOID)
331 {
332     if (Globals.szFileName[0] == '\0')
333         DIALOG_FileSaveAs();
334     else
335         DoSaveFile();
336 }
337
338 VOID DIALOG_FileSaveAs(VOID)
339 {
340     OPENFILENAME saveas;
341     WCHAR szPath[MAX_PATH];
342     WCHAR szDir[MAX_PATH];
343     static const WCHAR szDefaultExt[] = { 't','x','t',0 };
344     static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
345
346     ZeroMemory(&saveas, sizeof(saveas));
347
348     GetCurrentDirectory(SIZEOF(szDir), szDir);
349     lstrcpy(szPath, txt_files);
350
351     saveas.lStructSize       = sizeof(OPENFILENAME);
352     saveas.hwndOwner         = Globals.hMainWnd;
353     saveas.hInstance         = Globals.hInstance;
354     saveas.lpstrFilter       = Globals.szFilter;
355     saveas.lpstrFile         = szPath;
356     saveas.nMaxFile          = SIZEOF(szPath);
357     saveas.lpstrInitialDir   = szDir;
358     saveas.Flags             = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT |
359         OFN_HIDEREADONLY;
360     saveas.lpstrDefExt       = szDefaultExt;
361
362     if (GetSaveFileName(&saveas)) {
363         SetFileName(szPath);
364         UpdateWindowCaption();
365         DoSaveFile();
366     }
367 }
368
369 VOID DIALOG_FilePrint(VOID)
370 {
371     DOCINFO di;
372     PRINTDLG printer;
373     SIZE szMetric;
374     int cWidthPels, cHeightPels, border;
375     int xLeft, yTop, pagecount, dopage, copycount;
376     unsigned int i;
377     LOGFONT hdrFont;
378     HFONT font, old_font=0;
379     DWORD size;
380     LPWSTR pTemp;
381     WCHAR cTemp[PRINT_LEN_MAX];
382     static const WCHAR print_fontW[] = { 'C','o','u','r','i','e','r',0 };
383     static const WCHAR letterM[] = { 'M',0 };
384
385     /* Get a small font and print some header info on each page */
386     hdrFont.lfHeight = -35;
387     hdrFont.lfWidth = 0;
388     hdrFont.lfEscapement = 0;
389     hdrFont.lfOrientation = 0;
390     hdrFont.lfWeight = FW_BOLD;
391     hdrFont.lfItalic = 0;
392     hdrFont.lfUnderline = 0;
393     hdrFont.lfStrikeOut = 0;
394     hdrFont.lfCharSet = ANSI_CHARSET;
395     hdrFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
396     hdrFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
397     hdrFont.lfQuality = PROOF_QUALITY;
398     hdrFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
399     lstrcpy(hdrFont.lfFaceName, print_fontW);
400     
401     font = CreateFontIndirect(&hdrFont);
402     
403     /* Get Current Settings */
404     ZeroMemory(&printer, sizeof(printer));
405     printer.lStructSize           = sizeof(printer);
406     printer.hwndOwner             = Globals.hMainWnd;
407     printer.hDevMode              = Globals.hDevMode;
408     printer.hDevNames             = Globals.hDevNames;
409     printer.hInstance             = Globals.hInstance;
410     
411     /* Set some default flags */
412     printer.Flags                 = PD_RETURNDC | PD_NOSELECTION;
413     printer.nFromPage             = 0;
414     printer.nMinPage              = 1;
415     /* we really need to calculate number of pages to set nMaxPage and nToPage */
416     printer.nToPage               = 0;
417     printer.nMaxPage              = -1;
418     /* Let commdlg manage copy settings */
419     printer.nCopies               = (WORD)PD_USEDEVMODECOPIES;
420
421     if (!PrintDlg(&printer)) return;
422
423     Globals.hDevMode = printer.hDevMode;
424     Globals.hDevNames = printer.hDevNames;
425
426     assert(printer.hDC != 0);
427
428     /* initialize DOCINFO */
429     di.cbSize = sizeof(DOCINFO);
430     di.lpszDocName = Globals.szFileTitle;
431     di.lpszOutput = NULL;
432     di.lpszDatatype = NULL;
433     di.fwType = 0; 
434
435     if (StartDoc(printer.hDC, &di) <= 0) return;
436     
437     /* Get the page dimensions in pixels. */
438     cWidthPels = GetDeviceCaps(printer.hDC, HORZRES);
439     cHeightPels = GetDeviceCaps(printer.hDC, VERTRES);
440
441     /* Get the file text */
442     size = GetWindowTextLength(Globals.hEdit) + 1;
443     pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
444     if (!pTemp)
445     {
446         ShowLastError();
447         return;
448     }
449     size = GetWindowText(Globals.hEdit, pTemp, size);
450     
451     border = 150;
452     old_font = SelectObject(printer.hDC, Globals.hFont);
453     GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric);
454     for (copycount=1; copycount <= printer.nCopies; copycount++) {
455         i = 0;
456         pagecount = 1;
457         do {
458             if (printer.Flags & PD_PAGENUMS) {
459                 /* a specific range of pages is selected, so
460                  * skip pages that are not to be printed 
461                  */
462                 if (pagecount > printer.nToPage)
463                     break;
464                 else if (pagecount >= printer.nFromPage)
465                     dopage = 1;
466                 else
467                     dopage = 0;
468             }
469             else
470                 dopage = 1;
471                 
472             if (dopage) {
473                 if (StartPage(printer.hDC) <= 0) {
474                     static const WCHAR failedW[] = { 'S','t','a','r','t','P','a','g','e',' ','f','a','i','l','e','d',0 };
475                     static const WCHAR errorW[] = { 'P','r','i','n','t',' ','E','r','r','o','r',0 };
476                     MessageBox(Globals.hMainWnd, failedW, errorW, MB_ICONEXCLAMATION);
477                     return;
478                 }
479                 /* Write a rectangle and header at the top of each page */
480                 SelectObject(printer.hDC, font);
481                 Rectangle(printer.hDC, border, border, cWidthPels-border, border+szMetric.cy*2);
482                 TextOut(printer.hDC, border*2, border+szMetric.cy/2, Globals.szFileTitle, lstrlen(Globals.szFileTitle));
483             }
484             
485             SelectObject(printer.hDC, Globals.hFont);
486             /* The starting point for the main text */
487             xLeft = border;
488             yTop = border+szMetric.cy*4;
489             
490             do {
491                 int k=0, m;
492                 /* find the end of the line */
493                 while (i < size && pTemp[i] != '\n' && pTemp[i] != '\r') {
494                     if (pTemp[i] == '\t') {
495                         /* replace tabs with spaces */
496                         for (m=0; m<SPACES_IN_TAB; m++) {
497                             if (k <  PRINT_LEN_MAX)
498                                 cTemp[k++] = ' ';
499                         }
500                     }
501                     else if (k <  PRINT_LEN_MAX)
502                         cTemp[k++] = pTemp[i];
503                     i++;
504                 }
505                 if (dopage)
506                     TextOut(printer.hDC, xLeft, yTop, cTemp, k);
507                 /* find the next line */
508                 while (i < size && (pTemp[i] == '\n' || pTemp[i] == '\r')) {
509                     if (pTemp[i] == '\n')
510                         yTop += szMetric.cy;
511                     i++;
512                 }
513             } while (i<size && yTop<(cHeightPels-border*2));
514                 
515             if (dopage)
516                 EndPage(printer.hDC);
517             pagecount++;
518         } while (i<size);
519     }
520     SelectObject(printer.hDC, old_font);
521
522     EndDoc(printer.hDC);
523     DeleteDC(printer.hDC);
524     HeapFree(GetProcessHeap(), 0, pTemp);
525 }
526
527 VOID DIALOG_FilePrinterSetup(VOID)
528 {
529     PRINTDLG printer;
530
531     ZeroMemory(&printer, sizeof(printer));
532     printer.lStructSize         = sizeof(printer);
533     printer.hwndOwner           = Globals.hMainWnd;
534     printer.hDevMode            = Globals.hDevMode;
535     printer.hDevNames           = Globals.hDevNames;
536     printer.hInstance           = Globals.hInstance;
537     printer.Flags               = PD_PRINTSETUP;
538     printer.nCopies             = 1;
539
540     PrintDlg(&printer);
541
542     Globals.hDevMode = printer.hDevMode;
543     Globals.hDevNames = printer.hDevNames;
544 }
545
546 VOID DIALOG_FileExit(VOID)
547 {
548     PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0l);
549 }
550
551 VOID DIALOG_EditUndo(VOID)
552 {
553     SendMessage(Globals.hEdit, EM_UNDO, 0, 0);
554 }
555
556 VOID DIALOG_EditCut(VOID)
557 {
558     SendMessage(Globals.hEdit, WM_CUT, 0, 0);
559 }
560
561 VOID DIALOG_EditCopy(VOID)
562 {
563     SendMessage(Globals.hEdit, WM_COPY, 0, 0);
564 }
565
566 VOID DIALOG_EditPaste(VOID)
567 {
568     SendMessage(Globals.hEdit, WM_PASTE, 0, 0);
569 }
570
571 VOID DIALOG_EditDelete(VOID)
572 {
573     SendMessage(Globals.hEdit, WM_CLEAR, 0, 0);
574 }
575
576 VOID DIALOG_EditSelectAll(VOID)
577 {
578     SendMessage(Globals.hEdit, EM_SETSEL, 0, (LPARAM)-1);
579 }
580
581 VOID DIALOG_EditTimeDate(VOID)
582 {
583     SYSTEMTIME   st;
584     WCHAR        szDate[MAX_STRING_LEN];
585     static const WCHAR spaceW[] = { ' ',0 };
586
587     GetLocalTime(&st);
588
589     GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, szDate, MAX_STRING_LEN);
590     SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
591
592     SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)spaceW);
593
594     GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, szDate, MAX_STRING_LEN);
595     SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
596 }
597
598 VOID DIALOG_EditWrap(VOID)
599 {
600     BOOL modify = FALSE;
601     static const WCHAR editW[] = { 'e','d','i','t',0 };
602     DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL |
603                     ES_AUTOVSCROLL | ES_MULTILINE;
604     RECT rc;
605     DWORD size;
606     LPWSTR pTemp;
607
608     size = GetWindowTextLength(Globals.hEdit) + 1;
609     pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
610     if (!pTemp)
611     {
612         ShowLastError();
613         return;
614     }
615     GetWindowText(Globals.hEdit, pTemp, size);
616     modify = SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0);
617     DestroyWindow(Globals.hEdit);
618     GetClientRect(Globals.hMainWnd, &rc);
619     if( Globals.bWrapLongLines ) dwStyle |= WS_HSCROLL | ES_AUTOHSCROLL;
620     Globals.hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, editW, NULL, dwStyle,
621                          0, 0, rc.right, rc.bottom, Globals.hMainWnd,
622                          NULL, Globals.hInstance, NULL);
623     SendMessage(Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)FALSE);
624     SetWindowTextW(Globals.hEdit, pTemp);
625     SendMessage(Globals.hEdit, EM_SETMODIFY, (WPARAM)modify, 0);
626     SetFocus(Globals.hEdit);
627     HeapFree(GetProcessHeap(), 0, pTemp);
628     
629     Globals.bWrapLongLines = !Globals.bWrapLongLines;
630     CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
631         MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
632 }
633
634 VOID DIALOG_SelectFont(VOID)
635 {
636     CHOOSEFONT cf;
637     LOGFONT lf=Globals.lfFont;
638
639     ZeroMemory( &cf, sizeof(cf) );
640     cf.lStructSize=sizeof(cf);
641     cf.hwndOwner=Globals.hMainWnd;
642     cf.lpLogFont=&lf;
643     cf.Flags=CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT;
644
645     if( ChooseFont(&cf) )
646     {
647         HFONT currfont=Globals.hFont;
648
649         Globals.hFont=CreateFontIndirect( &lf );
650         Globals.lfFont=lf;
651         SendMessage( Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)TRUE );
652         if( currfont!=NULL )
653             DeleteObject( currfont );
654     }
655 }
656
657 VOID DIALOG_Search(VOID)
658 {
659         ZeroMemory(&Globals.find, sizeof(Globals.find));
660         Globals.find.lStructSize      = sizeof(Globals.find);
661         Globals.find.hwndOwner        = Globals.hMainWnd;
662         Globals.find.hInstance        = Globals.hInstance;
663         Globals.find.lpstrFindWhat    = Globals.szFindText;
664         Globals.find.wFindWhatLen     = SIZEOF(Globals.szFindText);
665         Globals.find.Flags            = FR_DOWN;
666
667         /* We only need to create the modal FindReplace dialog which will */
668         /* notify us of incoming events using hMainWnd Window Messages    */
669
670         Globals.hFindReplaceDlg = FindText(&Globals.find);
671         assert(Globals.hFindReplaceDlg !=0);
672 }
673
674 VOID DIALOG_SearchNext(VOID)
675 {
676     /* FIXME: Search Next */
677     DIALOG_Search();
678 }
679
680 VOID DIALOG_HelpContents(VOID)
681 {
682     WinHelp(Globals.hMainWnd, helpfileW, HELP_INDEX, 0);
683 }
684
685 VOID DIALOG_HelpSearch(VOID)
686 {
687         /* Search Help */
688 }
689
690 VOID DIALOG_HelpHelp(VOID)
691 {
692     WinHelp(Globals.hMainWnd, helpfileW, HELP_HELPONHELP, 0);
693 }
694
695 VOID DIALOG_HelpLicense(VOID)
696 {
697     TCHAR cap[20], text[1024];
698     LoadString(Globals.hInstance, IDS_LICENSE, text, 1024);
699     LoadString(Globals.hInstance, IDS_LICENSE_CAPTION, cap, 20);
700     MessageBox(Globals.hMainWnd, text, cap, MB_ICONINFORMATION | MB_OK);
701 }
702
703 VOID DIALOG_HelpNoWarranty(VOID)
704 {
705     TCHAR cap[20], text[1024];
706     LoadString(Globals.hInstance, IDS_WARRANTY, text, 1024);
707     LoadString(Globals.hInstance, IDS_WARRANTY_CAPTION, cap, 20);
708     MessageBox(Globals.hMainWnd, text, cap, MB_ICONEXCLAMATION | MB_OK);
709 }
710
711 VOID DIALOG_HelpAboutWine(VOID)
712 {
713     static const WCHAR notepadW[] = { 'N','o','t','e','p','a','d','\n',0 };
714     WCHAR szNotepad[MAX_STRING_LEN];
715
716     LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad));
717     ShellAbout(Globals.hMainWnd, szNotepad, notepadW, 0);
718 }
719
720
721 /***********************************************************************
722  *
723  *           DIALOG_FilePageSetup
724  */
725 VOID DIALOG_FilePageSetup(void)
726 {
727   DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP),
728             Globals.hMainWnd, DIALOG_PAGESETUP_DlgProc);
729 }
730
731
732 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
733  *
734  *           DIALOG_PAGESETUP_DlgProc
735  */
736
737 static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
738 {
739
740    switch (msg)
741     {
742     case WM_COMMAND:
743       switch (wParam)
744         {
745         case IDOK:
746           /* save user input and close dialog */
747           GetDlgItemText(hDlg, 0x141, Globals.szHeader, SIZEOF(Globals.szHeader));
748           GetDlgItemText(hDlg, 0x143, Globals.szFooter, SIZEOF(Globals.szFooter));
749           GetDlgItemText(hDlg, 0x14A, Globals.szMarginTop, SIZEOF(Globals.szMarginTop));
750           GetDlgItemText(hDlg, 0x150, Globals.szMarginBottom, SIZEOF(Globals.szMarginBottom));
751           GetDlgItemText(hDlg, 0x147, Globals.szMarginLeft, SIZEOF(Globals.szMarginLeft));
752           GetDlgItemText(hDlg, 0x14D, Globals.szMarginRight, SIZEOF(Globals.szMarginRight));
753           EndDialog(hDlg, IDOK);
754           return TRUE;
755
756         case IDCANCEL:
757           /* discard user input and close dialog */
758           EndDialog(hDlg, IDCANCEL);
759           return TRUE;
760
761         case IDHELP:
762         {
763           /* FIXME: Bring this to work */
764           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 };
765           static const WCHAR helpW[] = { 'H','e','l','p',0 };
766           MessageBox(Globals.hMainWnd, sorryW, helpW, MB_ICONEXCLAMATION);
767           return TRUE;
768         }
769
770         default:
771             break;
772         }
773       break;
774
775     case WM_INITDIALOG:
776        /* fetch last user input prior to display dialog */
777        SetDlgItemText(hDlg, 0x141, Globals.szHeader);
778        SetDlgItemText(hDlg, 0x143, Globals.szFooter);
779        SetDlgItemText(hDlg, 0x14A, Globals.szMarginTop);
780        SetDlgItemText(hDlg, 0x150, Globals.szMarginBottom);
781        SetDlgItemText(hDlg, 0x147, Globals.szMarginLeft);
782        SetDlgItemText(hDlg, 0x14D, Globals.szMarginRight);
783        break;
784     }
785
786   return FALSE;
787 }