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