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