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