kernel32: Invalidate local copy of console input event handle while reallocating...
[wine/multimedia.git] / programs / notepad / dialog.c
blobc21c2d7848423e126ed50c0510f0ed1274218de7
1 /*
2 * Notepad (dialog.c)
4 * Copyright 1998,99 Marcel Baur <mbaur@g26.ethz.ch>
5 * Copyright 2002 Sylvain Petreolle <spetreolle@yahoo.fr>
6 * Copyright 2002 Andriy Palamarchuk
7 * Copyright 2007 Rolf Kalbermatter
9 * This library is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU Lesser General Public
11 * License as published by the Free Software Foundation; either
12 * version 2.1 of the License, or (at your option) any later version.
14 * This library is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * Lesser General Public License for more details.
19 * You should have received a copy of the GNU Lesser General Public
20 * License along with this library; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
24 #define UNICODE
26 #include <assert.h>
27 #include <stdio.h>
28 #include <windows.h>
29 #include <commdlg.h>
30 #include <shlwapi.h>
32 #include "main.h"
33 #include "dialog.h"
35 #define SPACES_IN_TAB 8
36 #define PRINT_LEN_MAX 500
38 static const WCHAR helpfileW[] = { 'n','o','t','e','p','a','d','.','h','l','p',0 };
40 static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
42 VOID ShowLastError(void)
44 DWORD error = GetLastError();
45 if (error != NO_ERROR)
47 LPWSTR lpMsgBuf;
48 WCHAR szTitle[MAX_STRING_LEN];
50 LoadString(Globals.hInstance, STRING_ERROR, szTitle, SIZEOF(szTitle));
51 FormatMessage(
52 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
53 NULL, error, 0,
54 (LPTSTR) &lpMsgBuf, 0, NULL);
55 MessageBox(NULL, lpMsgBuf, szTitle, MB_OK | MB_ICONERROR);
56 LocalFree(lpMsgBuf);
60 /**
61 * Sets the caption of the main window according to Globals.szFileTitle:
62 * Untitled - Notepad if no file is open
63 * filename - Notepad if a file is given
65 static void UpdateWindowCaption(void)
67 WCHAR szCaption[MAX_STRING_LEN];
68 WCHAR szNotepad[MAX_STRING_LEN];
69 static const WCHAR hyphenW[] = { ' ','-',' ',0 };
71 if (Globals.szFileTitle[0] != '\0')
72 lstrcpy(szCaption, Globals.szFileTitle);
73 else
74 LoadString(Globals.hInstance, STRING_UNTITLED, szCaption, SIZEOF(szCaption));
76 LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad));
77 lstrcat(szCaption, hyphenW);
78 lstrcat(szCaption, szNotepad);
80 SetWindowText(Globals.hMainWnd, szCaption);
83 int DIALOG_StringMsgBox(HWND hParent, int formatId, LPCWSTR szString, DWORD dwFlags)
85 WCHAR szMessage[MAX_STRING_LEN];
86 WCHAR szResource[MAX_STRING_LEN];
88 /* Load and format szMessage */
89 LoadString(Globals.hInstance, formatId, szResource, SIZEOF(szResource));
90 wnsprintf(szMessage, SIZEOF(szMessage), szResource, szString);
92 /* Load szCaption */
93 if ((dwFlags & MB_ICONMASK) == MB_ICONEXCLAMATION)
94 LoadString(Globals.hInstance, STRING_ERROR, szResource, SIZEOF(szResource));
95 else
96 LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, SIZEOF(szResource));
98 /* Display Modal Dialog */
99 if (hParent == NULL)
100 hParent = Globals.hMainWnd;
101 return MessageBox(hParent, szMessage, szResource, dwFlags);
104 static void AlertFileNotFound(LPCWSTR szFileName)
106 DIALOG_StringMsgBox(NULL, STRING_NOTFOUND, szFileName, MB_ICONEXCLAMATION|MB_OK);
109 static int AlertFileNotSaved(LPCWSTR szFileName)
111 WCHAR szUntitled[MAX_STRING_LEN];
113 LoadString(Globals.hInstance, STRING_UNTITLED, szUntitled, SIZEOF(szUntitled));
114 return DIALOG_StringMsgBox(NULL, STRING_NOTSAVED, szFileName[0] ? szFileName : szUntitled,
115 MB_ICONQUESTION|MB_YESNOCANCEL);
119 * Returns:
120 * TRUE - if file exists
121 * FALSE - if file does not exist
123 BOOL FileExists(LPCWSTR szFilename)
125 WIN32_FIND_DATA entry;
126 HANDLE hFile;
128 hFile = FindFirstFile(szFilename, &entry);
129 FindClose(hFile);
131 return (hFile != INVALID_HANDLE_VALUE);
135 static VOID DoSaveFile(VOID)
137 HANDLE hFile;
138 DWORD dwNumWrite;
139 LPSTR pTemp;
140 DWORD size;
142 hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
143 NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
144 if(hFile == INVALID_HANDLE_VALUE)
146 ShowLastError();
147 return;
150 size = GetWindowTextLengthA(Globals.hEdit) + 1;
151 pTemp = HeapAlloc(GetProcessHeap(), 0, size);
152 if (!pTemp)
154 CloseHandle(hFile);
155 ShowLastError();
156 return;
158 size = GetWindowTextA(Globals.hEdit, pTemp, size);
160 if (!WriteFile(hFile, pTemp, size, &dwNumWrite, NULL))
161 ShowLastError();
162 else
163 SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
165 SetEndOfFile(hFile);
166 CloseHandle(hFile);
167 HeapFree(GetProcessHeap(), 0, pTemp);
171 * Returns:
172 * TRUE - User agreed to close (both save/don't save)
173 * FALSE - User cancelled close by selecting "Cancel"
175 BOOL DoCloseFile(void)
177 int nResult;
178 static const WCHAR empty_strW[] = { 0 };
180 if (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0))
182 /* prompt user to save changes */
183 nResult = AlertFileNotSaved(Globals.szFileName);
184 switch (nResult) {
185 case IDYES: DIALOG_FileSave();
186 break;
188 case IDNO: break;
190 case IDCANCEL: return(FALSE);
192 default: return(FALSE);
193 } /* switch */
194 } /* if */
196 SetFileName(empty_strW);
198 UpdateWindowCaption();
199 return(TRUE);
203 void DoOpenFile(LPCWSTR szFileName)
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];
212 /* Close any files and prompt to save changes */
213 if (!DoCloseFile())
214 return;
216 hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
217 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
218 if(hFile == INVALID_HANDLE_VALUE)
220 AlertFileNotFound(szFileName);
221 return;
224 size = GetFileSize(hFile, NULL);
225 if (size == INVALID_FILE_SIZE)
227 CloseHandle(hFile);
228 ShowLastError();
229 return;
231 size++;
233 pTemp = HeapAlloc(GetProcessHeap(), 0, size);
234 if (!pTemp)
236 CloseHandle(hFile);
237 ShowLastError();
238 return;
241 if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL))
243 CloseHandle(hFile);
244 HeapFree(GetProcessHeap(), 0, pTemp);
245 ShowLastError();
246 return;
249 CloseHandle(hFile);
250 pTemp[dwNumRead] = 0;
252 if (IsTextUnicode(pTemp, dwNumRead, NULL))
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);
259 else
260 SetWindowTextA(Globals.hEdit, pTemp);
262 HeapFree(GetProcessHeap(), 0, pTemp);
264 SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
265 SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
266 SetFocus(Globals.hEdit);
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
271 if (GetWindowTextW(Globals.hEdit, log, sizeof(log)/sizeof(log[0])) && !lstrcmp(log, dotlog))
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);
280 SetFileName(szFileName);
281 UpdateWindowCaption();
284 VOID DIALOG_FileNew(VOID)
286 static const WCHAR empty_strW[] = { 0 };
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);
296 VOID DIALOG_FileOpen(VOID)
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 };
304 ZeroMemory(&openfilename, sizeof(openfilename));
306 GetCurrentDirectory(SIZEOF(szDir), szDir);
307 lstrcpy(szPath, txt_files);
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;
321 if (GetOpenFileName(&openfilename))
322 DoOpenFile(openfilename.lpstrFile);
326 VOID DIALOG_FileSave(VOID)
328 if (Globals.szFileName[0] == '\0')
329 DIALOG_FileSaveAs();
330 else
331 DoSaveFile();
334 VOID DIALOG_FileSaveAs(VOID)
336 OPENFILENAME saveas;
337 WCHAR szPath[MAX_PATH];
338 WCHAR szDir[MAX_PATH];
339 static const WCHAR szDefaultExt[] = { 't','x','t',0 };
340 static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
342 ZeroMemory(&saveas, sizeof(saveas));
344 GetCurrentDirectory(SIZEOF(szDir), szDir);
345 lstrcpy(szPath, txt_files);
347 saveas.lStructSize = sizeof(OPENFILENAME);
348 saveas.hwndOwner = Globals.hMainWnd;
349 saveas.hInstance = Globals.hInstance;
350 saveas.lpstrFilter = Globals.szFilter;
351 saveas.lpstrFile = szPath;
352 saveas.nMaxFile = SIZEOF(szPath);
353 saveas.lpstrInitialDir = szDir;
354 saveas.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT |
355 OFN_HIDEREADONLY;
356 saveas.lpstrDefExt = szDefaultExt;
358 if (GetSaveFileName(&saveas)) {
359 SetFileName(szPath);
360 UpdateWindowCaption();
361 DoSaveFile();
365 typedef struct {
366 LPWSTR mptr;
367 LPWSTR mend;
368 LPWSTR lptr;
369 DWORD len;
370 } TEXTINFO, *LPTEXTINFO;
372 static int notepad_print_header(HDC hdc, RECT *rc, BOOL dopage, BOOL header, int page, LPWSTR text)
374 SIZE szMetric;
376 if (*text)
378 /* Write the header or footer */
379 GetTextExtentPoint32(hdc, text, lstrlen(text), &szMetric);
380 if (dopage)
381 ExtTextOut(hdc, (rc->left + rc->right - szMetric.cx) / 2,
382 header ? rc->top : rc->bottom - szMetric.cy,
383 ETO_CLIPPED, rc, text, lstrlen(text), NULL);
384 return 1;
386 return 0;
389 static BOOL notepad_print_page(HDC hdc, RECT *rc, BOOL dopage, int page, LPTEXTINFO tInfo)
391 int b, y;
392 TEXTMETRIC tm;
393 SIZE szMetrics;
395 if (dopage)
397 if (StartPage(hdc) <= 0)
399 static const WCHAR failedW[] = { 'S','t','a','r','t','P','a','g','e',' ','f','a','i','l','e','d',0 };
400 static const WCHAR errorW[] = { 'P','r','i','n','t',' ','E','r','r','o','r',0 };
401 MessageBox(Globals.hMainWnd, failedW, errorW, MB_ICONEXCLAMATION);
402 return FALSE;
406 GetTextMetrics(hdc, &tm);
407 y = rc->top + notepad_print_header(hdc, rc, dopage, TRUE, page, Globals.szFileName) * tm.tmHeight;
408 b = rc->bottom - 2 * notepad_print_header(hdc, rc, FALSE, FALSE, page, Globals.szFooter) * tm.tmHeight;
410 do {
411 INT m, n;
413 if (!tInfo->len)
415 /* find the end of the line */
416 while (tInfo->mptr < tInfo->mend && *tInfo->mptr != '\n' && *tInfo->mptr != '\r')
418 if (*tInfo->mptr == '\t')
420 /* replace tabs with spaces */
421 for (m = 0; m < SPACES_IN_TAB; m++)
423 if (tInfo->len < PRINT_LEN_MAX)
424 tInfo->lptr[tInfo->len++] = ' ';
425 else if (Globals.bWrapLongLines)
426 break;
429 else if (tInfo->len < PRINT_LEN_MAX)
430 tInfo->lptr[tInfo->len++] = *tInfo->mptr;
432 if (tInfo->len >= PRINT_LEN_MAX && Globals.bWrapLongLines)
433 break;
435 tInfo->mptr++;
439 /* Find out how much we should print if line wrapping is enabled */
440 if (Globals.bWrapLongLines)
442 GetTextExtentExPoint(hdc, tInfo->lptr, tInfo->len, rc->right - rc->left, &n, NULL, &szMetrics);
443 if (n < tInfo->len && tInfo->lptr[n] != ' ')
445 m = n;
446 /* Don't wrap words unless it's a single word over the entire line */
447 while (m && tInfo->lptr[m] != ' ') m--;
448 if (m > 0) n = m + 1;
451 else
452 n = tInfo->len;
454 if (dopage)
455 ExtTextOut(hdc, rc->left, y, ETO_CLIPPED, rc, tInfo->lptr, n, NULL);
457 tInfo->len -= n;
459 if (tInfo->len)
461 memcpy(tInfo->lptr, tInfo->lptr + n, tInfo->len * sizeof(WCHAR));
462 y += tm.tmHeight + tm.tmExternalLeading;
464 else
466 /* find the next line */
467 while (tInfo->mptr < tInfo->mend && y < b && (*tInfo->mptr == '\n' || *tInfo->mptr == '\r'))
469 if (*tInfo->mptr == '\n')
470 y += tm.tmHeight + tm.tmExternalLeading;
471 tInfo->mptr++;
474 } while (tInfo->mptr < tInfo->mend && y < b);
476 notepad_print_header(hdc, rc, dopage, FALSE, page, Globals.szFooter);
477 if (dopage)
479 EndPage(hdc);
481 return TRUE;
484 VOID DIALOG_FilePrint(VOID)
486 DOCINFO di;
487 PRINTDLG printer;
488 int page, dopage, copy;
489 LOGFONT lfFont;
490 HFONT hTextFont, old_font = 0;
491 DWORD size;
492 BOOL ret = FALSE;
493 RECT rc;
494 LPWSTR pTemp;
495 TEXTINFO tInfo;
496 WCHAR cTemp[PRINT_LEN_MAX];
498 /* Get Current Settings */
499 ZeroMemory(&printer, sizeof(printer));
500 printer.lStructSize = sizeof(printer);
501 printer.hwndOwner = Globals.hMainWnd;
502 printer.hDevMode = Globals.hDevMode;
503 printer.hDevNames = Globals.hDevNames;
504 printer.hInstance = Globals.hInstance;
506 /* Set some default flags */
507 printer.Flags = PD_RETURNDC | PD_NOSELECTION;
508 printer.nFromPage = 0;
509 printer.nMinPage = 1;
510 /* we really need to calculate number of pages to set nMaxPage and nToPage */
511 printer.nToPage = 0;
512 printer.nMaxPage = -1;
513 /* Let commdlg manage copy settings */
514 printer.nCopies = (WORD)PD_USEDEVMODECOPIES;
516 if (!PrintDlg(&printer)) return;
518 Globals.hDevMode = printer.hDevMode;
519 Globals.hDevNames = printer.hDevNames;
521 SetMapMode(printer.hDC, MM_TEXT);
523 /* initialize DOCINFO */
524 di.cbSize = sizeof(DOCINFO);
525 di.lpszDocName = Globals.szFileTitle;
526 di.lpszOutput = NULL;
527 di.lpszDatatype = NULL;
528 di.fwType = 0;
530 /* Get the file text */
531 size = GetWindowTextLength(Globals.hEdit) + 1;
532 pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
533 if (!pTemp)
535 DeleteDC(printer.hDC);
536 ShowLastError();
537 return;
539 size = GetWindowText(Globals.hEdit, pTemp, size);
541 if (StartDoc(printer.hDC, &di) > 0)
543 /* Get the page margins in pixels. */
544 rc.top = MulDiv(Globals.iMarginTop, GetDeviceCaps(printer.hDC, LOGPIXELSY), 2540) -
545 GetDeviceCaps(printer.hDC, PHYSICALOFFSETY);
546 rc.bottom = GetDeviceCaps(printer.hDC, PHYSICALHEIGHT) -
547 MulDiv(Globals.iMarginBottom, GetDeviceCaps(printer.hDC, LOGPIXELSY), 2540);
548 rc.left = MulDiv(Globals.iMarginLeft, GetDeviceCaps(printer.hDC, LOGPIXELSX), 2540) -
549 GetDeviceCaps(printer.hDC, PHYSICALOFFSETX);
550 rc.right = GetDeviceCaps(printer.hDC, PHYSICALWIDTH) -
551 MulDiv(Globals.iMarginRight, GetDeviceCaps(printer.hDC, LOGPIXELSX), 2540);
553 /* Create a font for the printer resolution */
554 lfFont = Globals.lfFont;
555 lfFont.lfHeight = MulDiv(lfFont.lfHeight, GetDeviceCaps(printer.hDC, LOGPIXELSY), get_dpi());
556 /* Make the font a bit lighter */
557 lfFont.lfWeight -= 100;
558 hTextFont = CreateFontIndirect(&lfFont);
559 old_font = SelectObject(printer.hDC, hTextFont);
561 for (copy = 1; copy <= printer.nCopies; copy++)
563 page = 1;
565 tInfo.mptr = pTemp;
566 tInfo.mend = pTemp + size;
567 tInfo.lptr = cTemp;
568 tInfo.len = 0;
570 do {
571 if (printer.Flags & PD_PAGENUMS)
573 /* a specific range of pages is selected, so
574 * skip pages that are not to be printed
576 if (page > printer.nToPage)
577 break;
578 else if (page >= printer.nFromPage)
579 dopage = 1;
580 else
581 dopage = 0;
583 else
584 dopage = 1;
586 ret = notepad_print_page(printer.hDC, &rc, dopage, page, &tInfo);
587 page++;
588 } while (ret && tInfo.mptr < tInfo.mend);
590 if (!ret) break;
592 EndDoc(printer.hDC);
593 SelectObject(printer.hDC, old_font);
594 DeleteObject(hTextFont);
596 DeleteDC(printer.hDC);
597 HeapFree(GetProcessHeap(), 0, pTemp);
600 VOID DIALOG_FilePrinterSetup(VOID)
602 PRINTDLG printer;
604 ZeroMemory(&printer, sizeof(printer));
605 printer.lStructSize = sizeof(printer);
606 printer.hwndOwner = Globals.hMainWnd;
607 printer.hDevMode = Globals.hDevMode;
608 printer.hDevNames = Globals.hDevNames;
609 printer.hInstance = Globals.hInstance;
610 printer.Flags = PD_PRINTSETUP;
611 printer.nCopies = 1;
613 PrintDlg(&printer);
615 Globals.hDevMode = printer.hDevMode;
616 Globals.hDevNames = printer.hDevNames;
619 VOID DIALOG_FileExit(VOID)
621 PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0l);
624 VOID DIALOG_EditUndo(VOID)
626 SendMessage(Globals.hEdit, EM_UNDO, 0, 0);
629 VOID DIALOG_EditCut(VOID)
631 SendMessage(Globals.hEdit, WM_CUT, 0, 0);
634 VOID DIALOG_EditCopy(VOID)
636 SendMessage(Globals.hEdit, WM_COPY, 0, 0);
639 VOID DIALOG_EditPaste(VOID)
641 SendMessage(Globals.hEdit, WM_PASTE, 0, 0);
644 VOID DIALOG_EditDelete(VOID)
646 SendMessage(Globals.hEdit, WM_CLEAR, 0, 0);
649 VOID DIALOG_EditSelectAll(VOID)
651 SendMessage(Globals.hEdit, EM_SETSEL, 0, (LPARAM)-1);
654 VOID DIALOG_EditTimeDate(VOID)
656 SYSTEMTIME st;
657 WCHAR szDate[MAX_STRING_LEN];
658 static const WCHAR spaceW[] = { ' ',0 };
660 GetLocalTime(&st);
662 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, szDate, MAX_STRING_LEN);
663 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
665 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)spaceW);
667 GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, szDate, MAX_STRING_LEN);
668 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
671 VOID DIALOG_EditWrap(VOID)
673 BOOL modify = FALSE;
674 static const WCHAR editW[] = { 'e','d','i','t',0 };
675 DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL |
676 ES_AUTOVSCROLL | ES_MULTILINE;
677 RECT rc;
678 DWORD size;
679 LPWSTR pTemp;
681 size = GetWindowTextLength(Globals.hEdit) + 1;
682 pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
683 if (!pTemp)
685 ShowLastError();
686 return;
688 GetWindowText(Globals.hEdit, pTemp, size);
689 modify = SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0);
690 DestroyWindow(Globals.hEdit);
691 GetClientRect(Globals.hMainWnd, &rc);
692 if( Globals.bWrapLongLines ) dwStyle |= WS_HSCROLL | ES_AUTOHSCROLL;
693 Globals.hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, editW, NULL, dwStyle,
694 0, 0, rc.right, rc.bottom, Globals.hMainWnd,
695 NULL, Globals.hInstance, NULL);
696 SendMessage(Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)FALSE);
697 SetWindowTextW(Globals.hEdit, pTemp);
698 SendMessage(Globals.hEdit, EM_SETMODIFY, (WPARAM)modify, 0);
699 SetFocus(Globals.hEdit);
700 HeapFree(GetProcessHeap(), 0, pTemp);
702 Globals.bWrapLongLines = !Globals.bWrapLongLines;
703 CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
704 MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
707 VOID DIALOG_SelectFont(VOID)
709 CHOOSEFONT cf;
710 LOGFONT lf=Globals.lfFont;
712 ZeroMemory( &cf, sizeof(cf) );
713 cf.lStructSize=sizeof(cf);
714 cf.hwndOwner=Globals.hMainWnd;
715 cf.lpLogFont=&lf;
716 cf.Flags=CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT;
718 if( ChooseFont(&cf) )
720 HFONT currfont=Globals.hFont;
722 Globals.hFont=CreateFontIndirect( &lf );
723 Globals.lfFont=lf;
724 SendMessage( Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)TRUE );
725 if( currfont!=NULL )
726 DeleteObject( currfont );
730 VOID DIALOG_Search(VOID)
732 ZeroMemory(&Globals.find, sizeof(Globals.find));
733 Globals.find.lStructSize = sizeof(Globals.find);
734 Globals.find.hwndOwner = Globals.hMainWnd;
735 Globals.find.hInstance = Globals.hInstance;
736 Globals.find.lpstrFindWhat = Globals.szFindText;
737 Globals.find.wFindWhatLen = SIZEOF(Globals.szFindText);
738 Globals.find.Flags = FR_DOWN|FR_HIDEWHOLEWORD;
740 /* We only need to create the modal FindReplace dialog which will */
741 /* notify us of incoming events using hMainWnd Window Messages */
743 Globals.hFindReplaceDlg = FindText(&Globals.find);
744 assert(Globals.hFindReplaceDlg !=0);
747 VOID DIALOG_SearchNext(VOID)
749 if (Globals.lastFind.lpstrFindWhat == NULL)
750 DIALOG_Search();
751 else /* use the last find data */
752 NOTEPAD_DoFind(&Globals.lastFind);
755 VOID DIALOG_HelpContents(VOID)
757 WinHelp(Globals.hMainWnd, helpfileW, HELP_INDEX, 0);
760 VOID DIALOG_HelpSearch(VOID)
762 /* Search Help */
765 VOID DIALOG_HelpHelp(VOID)
767 WinHelp(Globals.hMainWnd, helpfileW, HELP_HELPONHELP, 0);
770 VOID DIALOG_HelpLicense(VOID)
772 TCHAR cap[20], text[1024];
773 LoadString(Globals.hInstance, IDS_LICENSE, text, 1024);
774 LoadString(Globals.hInstance, IDS_LICENSE_CAPTION, cap, 20);
775 MessageBox(Globals.hMainWnd, text, cap, MB_ICONINFORMATION | MB_OK);
778 VOID DIALOG_HelpNoWarranty(VOID)
780 TCHAR cap[20], text[1024];
781 LoadString(Globals.hInstance, IDS_WARRANTY, text, 1024);
782 LoadString(Globals.hInstance, IDS_WARRANTY_CAPTION, cap, 20);
783 MessageBox(Globals.hMainWnd, text, cap, MB_ICONEXCLAMATION | MB_OK);
786 VOID DIALOG_HelpAboutWine(VOID)
788 static const WCHAR notepadW[] = { 'N','o','t','e','p','a','d','\n',0 };
789 WCHAR szNotepad[MAX_STRING_LEN];
790 HICON icon = LoadIcon(Globals.hInstance, MAKEINTRESOURCE(IDI_NOTEPAD));
792 LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad));
793 ShellAbout(Globals.hMainWnd, szNotepad, notepadW, icon);
797 /***********************************************************************
799 * DIALOG_FilePageSetup
801 VOID DIALOG_FilePageSetup(void)
803 DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP),
804 Globals.hMainWnd, DIALOG_PAGESETUP_DlgProc);
808 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
810 * DIALOG_PAGESETUP_DlgProc
813 static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
816 switch (msg)
818 case WM_COMMAND:
819 switch (wParam)
821 case IDOK:
822 /* save user input and close dialog */
823 GetDlgItemText(hDlg, IDC_PAGESETUP_HEADERVALUE, Globals.szHeader, SIZEOF(Globals.szHeader));
824 GetDlgItemText(hDlg, IDC_PAGESETUP_FOOTERVALUE, Globals.szFooter, SIZEOF(Globals.szFooter));
826 Globals.iMarginTop = GetDlgItemInt(hDlg, IDC_PAGESETUP_TOPVALUE, NULL, FALSE) * 100;
827 Globals.iMarginBottom = GetDlgItemInt(hDlg, IDC_PAGESETUP_BOTTOMVALUE, NULL, FALSE) * 100;
828 Globals.iMarginLeft = GetDlgItemInt(hDlg, IDC_PAGESETUP_LEFTVALUE, NULL, FALSE) * 100;
829 Globals.iMarginRight = GetDlgItemInt(hDlg, IDC_PAGESETUP_RIGHTVALUE, NULL, FALSE) * 100;
830 EndDialog(hDlg, IDOK);
831 return TRUE;
833 case IDCANCEL:
834 /* discard user input and close dialog */
835 EndDialog(hDlg, IDCANCEL);
836 return TRUE;
838 case IDHELP:
840 /* FIXME: Bring this to work */
841 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 };
842 static const WCHAR helpW[] = { 'H','e','l','p',0 };
843 MessageBox(Globals.hMainWnd, sorryW, helpW, MB_ICONEXCLAMATION);
844 return TRUE;
847 default:
848 break;
850 break;
852 case WM_INITDIALOG:
853 /* fetch last user input prior to display dialog */
854 SetDlgItemText(hDlg, IDC_PAGESETUP_HEADERVALUE, Globals.szHeader);
855 SetDlgItemText(hDlg, IDC_PAGESETUP_FOOTERVALUE, Globals.szFooter);
856 SetDlgItemInt(hDlg, IDC_PAGESETUP_TOPVALUE, Globals.iMarginTop / 100, FALSE);
857 SetDlgItemInt(hDlg, IDC_PAGESETUP_BOTTOMVALUE, Globals.iMarginBottom / 100, FALSE);
858 SetDlgItemInt(hDlg, IDC_PAGESETUP_LEFTVALUE, Globals.iMarginLeft / 100, FALSE);
859 SetDlgItemInt(hDlg, IDC_PAGESETUP_RIGHTVALUE, Globals.iMarginRight / 100, FALSE);
860 break;
863 return FALSE;