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
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)
48 WCHAR szTitle[MAX_STRING_LEN];
50 LoadString(Globals.hInstance, STRING_ERROR, szTitle, SIZEOF(szTitle));
52 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
53 NULL, error, 0, (LPWSTR)&lpMsgBuf, 0, NULL);
54 MessageBox(NULL, lpMsgBuf, szTitle, MB_OK | MB_ICONERROR);
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
64 static void UpdateWindowCaption(void)
66 WCHAR szCaption[MAX_STRING_LEN];
67 WCHAR szNotepad[MAX_STRING_LEN];
68 static const WCHAR hyphenW[] = { ' ','-',' ',0 };
70 if (Globals.szFileTitle[0] != '\0')
71 lstrcpyW(szCaption, Globals.szFileTitle);
73 LoadString(Globals.hInstance, STRING_UNTITLED, szCaption, SIZEOF(szCaption));
75 LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad));
76 lstrcatW(szCaption, hyphenW);
77 lstrcatW(szCaption, szNotepad);
79 SetWindowText(Globals.hMainWnd, szCaption);
82 int DIALOG_StringMsgBox(HWND hParent, int formatId, LPCWSTR szString, DWORD dwFlags)
84 WCHAR szMessage[MAX_STRING_LEN];
85 WCHAR szResource[MAX_STRING_LEN];
87 /* Load and format szMessage */
88 LoadString(Globals.hInstance, formatId, szResource, SIZEOF(szResource));
89 wnsprintfW(szMessage, SIZEOF(szMessage), szResource, szString);
92 if ((dwFlags & MB_ICONMASK) == MB_ICONEXCLAMATION)
93 LoadString(Globals.hInstance, STRING_ERROR, szResource, SIZEOF(szResource));
95 LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, SIZEOF(szResource));
97 /* Display Modal Dialog */
99 hParent = Globals.hMainWnd;
100 return MessageBox(hParent, szMessage, szResource, dwFlags);
103 static void AlertFileNotFound(LPCWSTR szFileName)
105 DIALOG_StringMsgBox(NULL, STRING_NOTFOUND, szFileName, MB_ICONEXCLAMATION|MB_OK);
108 static int AlertFileNotSaved(LPCWSTR szFileName)
110 WCHAR szUntitled[MAX_STRING_LEN];
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);
119 * TRUE - if file exists
120 * FALSE - if file does not exist
122 BOOL FileExists(LPCWSTR szFilename)
124 WIN32_FIND_DATAW entry;
127 hFile = FindFirstFile(szFilename, &entry);
130 return (hFile != INVALID_HANDLE_VALUE);
134 static VOID DoSaveFile(VOID)
141 hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
142 NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
143 if(hFile == INVALID_HANDLE_VALUE)
149 size = GetWindowTextLengthA(Globals.hEdit) + 1;
150 pTemp = HeapAlloc(GetProcessHeap(), 0, size);
157 size = GetWindowTextA(Globals.hEdit, pTemp, size);
159 if (!WriteFile(hFile, pTemp, size, &dwNumWrite, NULL))
162 SendMessageW(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
166 HeapFree(GetProcessHeap(), 0, pTemp);
171 * TRUE - User agreed to close (both save/don't save)
172 * FALSE - User cancelled close by selecting "Cancel"
174 BOOL DoCloseFile(void)
177 static const WCHAR empty_strW[] = { 0 };
179 if (SendMessageW(Globals.hEdit, EM_GETMODIFY, 0, 0))
181 /* prompt user to save changes */
182 nResult = AlertFileNotSaved(Globals.szFileName);
184 case IDYES: return DIALOG_FileSave();
188 case IDCANCEL: return(FALSE);
190 default: return(FALSE);
194 SetFileName(empty_strW);
196 UpdateWindowCaption();
201 void DoOpenFile(LPCWSTR szFileName)
203 static const WCHAR dotlog[] = { '.','L','O','G',0 };
210 /* Close any files and prompt to save changes */
214 hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
215 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
216 if(hFile == INVALID_HANDLE_VALUE)
218 AlertFileNotFound(szFileName);
222 size = GetFileSize(hFile, NULL);
223 if (size == INVALID_FILE_SIZE)
231 pTemp = HeapAlloc(GetProcessHeap(), 0, size);
239 if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL))
242 HeapFree(GetProcessHeap(), 0, pTemp);
248 pTemp[dwNumRead] = 0;
250 if((size -1) >= 2 && (BYTE)pTemp[0] == 0xff && (BYTE)pTemp[1] == 0xfe)
251 SetWindowTextW(Globals.hEdit, (LPWSTR)pTemp + 1);
253 SetWindowTextA(Globals.hEdit, pTemp);
255 HeapFree(GetProcessHeap(), 0, pTemp);
257 SendMessageW(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
258 SendMessageW(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
259 SetFocus(Globals.hEdit);
261 /* If the file starts with .LOG, add a time/date at the end and set cursor after */
262 if (GetWindowTextW(Globals.hEdit, log, sizeof(log)/sizeof(log[0])) && !lstrcmpW(log, dotlog))
264 static const WCHAR lfW[] = { '\r','\n',0 };
265 SendMessageW(Globals.hEdit, EM_SETSEL, GetWindowTextLength(Globals.hEdit), -1);
266 SendMessageW(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lfW);
267 DIALOG_EditTimeDate();
268 SendMessageW(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lfW);
271 SetFileName(szFileName);
272 UpdateWindowCaption();
275 VOID DIALOG_FileNew(VOID)
277 static const WCHAR empty_strW[] = { 0 };
279 /* Close any files and prompt to save changes */
281 SetWindowText(Globals.hEdit, empty_strW);
282 SendMessageW(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
283 SetFocus(Globals.hEdit);
287 VOID DIALOG_FileOpen(VOID)
289 OPENFILENAMEW openfilename;
290 WCHAR szPath[MAX_PATH];
291 WCHAR szDir[MAX_PATH];
292 static const WCHAR szDefaultExt[] = { 't','x','t',0 };
293 static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
295 ZeroMemory(&openfilename, sizeof(openfilename));
297 GetCurrentDirectory(SIZEOF(szDir), szDir);
298 lstrcpyW(szPath, txt_files);
300 openfilename.lStructSize = sizeof(openfilename);
301 openfilename.hwndOwner = Globals.hMainWnd;
302 openfilename.hInstance = Globals.hInstance;
303 openfilename.lpstrFilter = Globals.szFilter;
304 openfilename.lpstrFile = szPath;
305 openfilename.nMaxFile = SIZEOF(szPath);
306 openfilename.lpstrInitialDir = szDir;
307 openfilename.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST |
308 OFN_HIDEREADONLY | OFN_ENABLESIZING;
309 openfilename.lpstrDefExt = szDefaultExt;
312 if (GetOpenFileName(&openfilename))
313 DoOpenFile(openfilename.lpstrFile);
317 BOOL DIALOG_FileSave(VOID)
319 if (Globals.szFileName[0] == '\0')
320 return DIALOG_FileSaveAs();
326 BOOL DIALOG_FileSaveAs(VOID)
328 OPENFILENAMEW saveas;
329 WCHAR szPath[MAX_PATH];
330 WCHAR szDir[MAX_PATH];
331 static const WCHAR szDefaultExt[] = { 't','x','t',0 };
332 static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
334 ZeroMemory(&saveas, sizeof(saveas));
336 GetCurrentDirectory(SIZEOF(szDir), szDir);
337 lstrcpyW(szPath, txt_files);
339 saveas.lStructSize = sizeof(OPENFILENAMEW);
340 saveas.hwndOwner = Globals.hMainWnd;
341 saveas.hInstance = Globals.hInstance;
342 saveas.lpstrFilter = Globals.szFilter;
343 saveas.lpstrFile = szPath;
344 saveas.nMaxFile = SIZEOF(szPath);
345 saveas.lpstrInitialDir = szDir;
346 saveas.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT |
347 OFN_HIDEREADONLY | OFN_ENABLESIZING;
348 saveas.lpstrDefExt = szDefaultExt;
350 if (GetSaveFileName(&saveas)) {
352 UpdateWindowCaption();
364 } TEXTINFO, *LPTEXTINFO;
366 static int notepad_print_header(HDC hdc, RECT *rc, BOOL dopage, BOOL header, int page, LPWSTR text)
372 /* Write the header or footer */
373 GetTextExtentPoint32W(hdc, text, lstrlenW(text), &szMetric);
375 ExtTextOut(hdc, (rc->left + rc->right - szMetric.cx) / 2,
376 header ? rc->top : rc->bottom - szMetric.cy,
377 ETO_CLIPPED, rc, text, lstrlenW(text), NULL);
383 static BOOL notepad_print_page(HDC hdc, RECT *rc, BOOL dopage, int page, LPTEXTINFO tInfo)
391 if (StartPage(hdc) <= 0)
393 static const WCHAR failedW[] = { 'S','t','a','r','t','P','a','g','e',' ','f','a','i','l','e','d',0 };
394 static const WCHAR errorW[] = { 'P','r','i','n','t',' ','E','r','r','o','r',0 };
395 MessageBox(Globals.hMainWnd, failedW, errorW, MB_ICONEXCLAMATION);
400 GetTextMetrics(hdc, &tm);
401 y = rc->top + notepad_print_header(hdc, rc, dopage, TRUE, page, Globals.szFileName) * tm.tmHeight;
402 b = rc->bottom - 2 * notepad_print_header(hdc, rc, FALSE, FALSE, page, Globals.szFooter) * tm.tmHeight;
409 /* find the end of the line */
410 while (tInfo->mptr < tInfo->mend && *tInfo->mptr != '\n' && *tInfo->mptr != '\r')
412 if (*tInfo->mptr == '\t')
414 /* replace tabs with spaces */
415 for (m = 0; m < SPACES_IN_TAB; m++)
417 if (tInfo->len < PRINT_LEN_MAX)
418 tInfo->lptr[tInfo->len++] = ' ';
419 else if (Globals.bWrapLongLines)
423 else if (tInfo->len < PRINT_LEN_MAX)
424 tInfo->lptr[tInfo->len++] = *tInfo->mptr;
426 if (tInfo->len >= PRINT_LEN_MAX && Globals.bWrapLongLines)
433 /* Find out how much we should print if line wrapping is enabled */
434 if (Globals.bWrapLongLines)
436 GetTextExtentExPoint(hdc, tInfo->lptr, tInfo->len, rc->right - rc->left, &n, NULL, &szMetrics);
437 if (n < tInfo->len && tInfo->lptr[n] != ' ')
440 /* Don't wrap words unless it's a single word over the entire line */
441 while (m && tInfo->lptr[m] != ' ') m--;
442 if (m > 0) n = m + 1;
449 ExtTextOut(hdc, rc->left, y, ETO_CLIPPED, rc, tInfo->lptr, n, NULL);
455 memcpy(tInfo->lptr, tInfo->lptr + n, tInfo->len * sizeof(WCHAR));
456 y += tm.tmHeight + tm.tmExternalLeading;
460 /* find the next line */
461 while (tInfo->mptr < tInfo->mend && y < b && (*tInfo->mptr == '\n' || *tInfo->mptr == '\r'))
463 if (*tInfo->mptr == '\n')
464 y += tm.tmHeight + tm.tmExternalLeading;
468 } while (tInfo->mptr < tInfo->mend && y < b);
470 notepad_print_header(hdc, rc, dopage, FALSE, page, Globals.szFooter);
478 VOID DIALOG_FilePrint(VOID)
482 int page, dopage, copy;
484 HFONT hTextFont, old_font = 0;
490 WCHAR cTemp[PRINT_LEN_MAX];
492 /* Get Current Settings */
493 ZeroMemory(&printer, sizeof(printer));
494 printer.lStructSize = sizeof(printer);
495 printer.hwndOwner = Globals.hMainWnd;
496 printer.hDevMode = Globals.hDevMode;
497 printer.hDevNames = Globals.hDevNames;
498 printer.hInstance = Globals.hInstance;
500 /* Set some default flags */
501 printer.Flags = PD_RETURNDC | PD_NOSELECTION;
502 printer.nFromPage = 0;
503 printer.nMinPage = 1;
504 /* we really need to calculate number of pages to set nMaxPage and nToPage */
506 printer.nMaxPage = -1;
507 /* Let commdlg manage copy settings */
508 printer.nCopies = (WORD)PD_USEDEVMODECOPIES;
510 if (!PrintDlg(&printer)) return;
512 Globals.hDevMode = printer.hDevMode;
513 Globals.hDevNames = printer.hDevNames;
515 SetMapMode(printer.hDC, MM_TEXT);
517 /* initialize DOCINFO */
518 di.cbSize = sizeof(DOCINFOW);
519 di.lpszDocName = Globals.szFileTitle;
520 di.lpszOutput = NULL;
521 di.lpszDatatype = NULL;
524 /* Get the file text */
525 size = GetWindowTextLength(Globals.hEdit) + 1;
526 pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
529 DeleteDC(printer.hDC);
533 size = GetWindowText(Globals.hEdit, pTemp, size);
535 if (StartDoc(printer.hDC, &di) > 0)
537 /* Get the page margins in pixels. */
538 rc.top = MulDiv(Globals.iMarginTop, GetDeviceCaps(printer.hDC, LOGPIXELSY), 2540) -
539 GetDeviceCaps(printer.hDC, PHYSICALOFFSETY);
540 rc.bottom = GetDeviceCaps(printer.hDC, PHYSICALHEIGHT) -
541 MulDiv(Globals.iMarginBottom, GetDeviceCaps(printer.hDC, LOGPIXELSY), 2540);
542 rc.left = MulDiv(Globals.iMarginLeft, GetDeviceCaps(printer.hDC, LOGPIXELSX), 2540) -
543 GetDeviceCaps(printer.hDC, PHYSICALOFFSETX);
544 rc.right = GetDeviceCaps(printer.hDC, PHYSICALWIDTH) -
545 MulDiv(Globals.iMarginRight, GetDeviceCaps(printer.hDC, LOGPIXELSX), 2540);
547 /* Create a font for the printer resolution */
548 lfFont = Globals.lfFont;
549 lfFont.lfHeight = MulDiv(lfFont.lfHeight, GetDeviceCaps(printer.hDC, LOGPIXELSY), get_dpi());
550 /* Make the font a bit lighter */
551 lfFont.lfWeight -= 100;
552 hTextFont = CreateFontIndirect(&lfFont);
553 old_font = SelectObject(printer.hDC, hTextFont);
555 for (copy = 1; copy <= printer.nCopies; copy++)
560 tInfo.mend = pTemp + size;
565 if (printer.Flags & PD_PAGENUMS)
567 /* a specific range of pages is selected, so
568 * skip pages that are not to be printed
570 if (page > printer.nToPage)
572 else if (page >= printer.nFromPage)
580 ret = notepad_print_page(printer.hDC, &rc, dopage, page, &tInfo);
582 } while (ret && tInfo.mptr < tInfo.mend);
587 SelectObject(printer.hDC, old_font);
588 DeleteObject(hTextFont);
590 DeleteDC(printer.hDC);
591 HeapFree(GetProcessHeap(), 0, pTemp);
594 VOID DIALOG_FilePrinterSetup(VOID)
598 ZeroMemory(&printer, sizeof(printer));
599 printer.lStructSize = sizeof(printer);
600 printer.hwndOwner = Globals.hMainWnd;
601 printer.hDevMode = Globals.hDevMode;
602 printer.hDevNames = Globals.hDevNames;
603 printer.hInstance = Globals.hInstance;
604 printer.Flags = PD_PRINTSETUP;
609 Globals.hDevMode = printer.hDevMode;
610 Globals.hDevNames = printer.hDevNames;
613 VOID DIALOG_FileExit(VOID)
615 PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0l);
618 VOID DIALOG_EditUndo(VOID)
620 SendMessageW(Globals.hEdit, EM_UNDO, 0, 0);
623 VOID DIALOG_EditCut(VOID)
625 SendMessageW(Globals.hEdit, WM_CUT, 0, 0);
628 VOID DIALOG_EditCopy(VOID)
630 SendMessageW(Globals.hEdit, WM_COPY, 0, 0);
633 VOID DIALOG_EditPaste(VOID)
635 SendMessageW(Globals.hEdit, WM_PASTE, 0, 0);
638 VOID DIALOG_EditDelete(VOID)
640 SendMessageW(Globals.hEdit, WM_CLEAR, 0, 0);
643 VOID DIALOG_EditSelectAll(VOID)
645 SendMessageW(Globals.hEdit, EM_SETSEL, 0, -1);
648 VOID DIALOG_EditTimeDate(VOID)
651 WCHAR szDate[MAX_STRING_LEN];
652 static const WCHAR spaceW[] = { ' ',0 };
656 GetTimeFormat(LOCALE_USER_DEFAULT, TIME_NOSECONDS, &st, NULL, szDate, MAX_STRING_LEN);
657 SendMessageW(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
659 SendMessageW(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)spaceW);
661 GetDateFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, szDate, MAX_STRING_LEN);
662 SendMessageW(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
665 VOID DIALOG_EditWrap(VOID)
668 static const WCHAR editW[] = { 'e','d','i','t',0 };
669 DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL |
670 ES_AUTOVSCROLL | ES_MULTILINE;
675 size = GetWindowTextLength(Globals.hEdit) + 1;
676 pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
682 GetWindowText(Globals.hEdit, pTemp, size);
683 modify = SendMessageW(Globals.hEdit, EM_GETMODIFY, 0, 0);
684 DestroyWindow(Globals.hEdit);
685 GetClientRect(Globals.hMainWnd, &rc);
686 if( Globals.bWrapLongLines ) dwStyle |= WS_HSCROLL | ES_AUTOHSCROLL;
687 Globals.hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, editW, NULL, dwStyle,
688 0, 0, rc.right, rc.bottom, Globals.hMainWnd,
689 NULL, Globals.hInstance, NULL);
690 SendMessageW(Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, FALSE);
691 SetWindowTextW(Globals.hEdit, pTemp);
692 SendMessageW(Globals.hEdit, EM_SETMODIFY, modify, 0);
693 SetFocus(Globals.hEdit);
694 HeapFree(GetProcessHeap(), 0, pTemp);
696 Globals.bWrapLongLines = !Globals.bWrapLongLines;
697 CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
698 MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
701 VOID DIALOG_SelectFont(VOID)
704 LOGFONTW lf=Globals.lfFont;
706 ZeroMemory( &cf, sizeof(cf) );
707 cf.lStructSize=sizeof(cf);
708 cf.hwndOwner=Globals.hMainWnd;
710 cf.Flags=CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT;
712 if( ChooseFont(&cf) )
714 HFONT currfont=Globals.hFont;
716 Globals.hFont=CreateFontIndirect( &lf );
718 SendMessageW( Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, TRUE );
720 DeleteObject( currfont );
724 VOID DIALOG_Search(VOID)
726 /* Allow only one search/replace dialog to open */
727 if(Globals.hFindReplaceDlg != NULL)
729 SetActiveWindow(Globals.hFindReplaceDlg);
733 ZeroMemory(&Globals.find, sizeof(Globals.find));
734 Globals.find.lStructSize = sizeof(Globals.find);
735 Globals.find.hwndOwner = Globals.hMainWnd;
736 Globals.find.hInstance = Globals.hInstance;
737 Globals.find.lpstrFindWhat = Globals.szFindText;
738 Globals.find.wFindWhatLen = SIZEOF(Globals.szFindText);
739 Globals.find.Flags = FR_DOWN|FR_HIDEWHOLEWORD;
741 /* We only need to create the modal FindReplace dialog which will */
742 /* notify us of incoming events using hMainWnd Window Messages */
744 Globals.hFindReplaceDlg = FindText(&Globals.find);
745 assert(Globals.hFindReplaceDlg !=0);
748 VOID DIALOG_SearchNext(VOID)
750 if (Globals.lastFind.lpstrFindWhat == NULL)
752 else /* use the last find data */
753 NOTEPAD_DoFind(&Globals.lastFind);
756 VOID DIALOG_Replace(VOID)
758 /* Allow only one search/replace dialog to open */
759 if(Globals.hFindReplaceDlg != NULL)
761 SetActiveWindow(Globals.hFindReplaceDlg);
765 ZeroMemory(&Globals.find, sizeof(Globals.find));
766 Globals.find.lStructSize = sizeof(Globals.find);
767 Globals.find.hwndOwner = Globals.hMainWnd;
768 Globals.find.hInstance = Globals.hInstance;
769 Globals.find.lpstrFindWhat = Globals.szFindText;
770 Globals.find.wFindWhatLen = SIZEOF(Globals.szFindText);
771 Globals.find.lpstrReplaceWith = Globals.szReplaceText;
772 Globals.find.wReplaceWithLen = SIZEOF(Globals.szReplaceText);
773 Globals.find.Flags = FR_DOWN|FR_HIDEWHOLEWORD;
775 /* We only need to create the modal FindReplace dialog which will */
776 /* notify us of incoming events using hMainWnd Window Messages */
778 Globals.hFindReplaceDlg = ReplaceText(&Globals.find);
779 assert(Globals.hFindReplaceDlg !=0);
782 VOID DIALOG_HelpContents(VOID)
784 WinHelp(Globals.hMainWnd, helpfileW, HELP_INDEX, 0);
787 VOID DIALOG_HelpSearch(VOID)
792 VOID DIALOG_HelpHelp(VOID)
794 WinHelp(Globals.hMainWnd, helpfileW, HELP_HELPONHELP, 0);
797 VOID DIALOG_HelpAboutNotepad(VOID)
799 static const WCHAR notepadW[] = { 'W','i','n','e',' ','N','o','t','e','p','a','d',0 };
800 WCHAR szNotepad[MAX_STRING_LEN];
801 HICON icon = LoadImageW( Globals.hInstance, MAKEINTRESOURCE(IDI_NOTEPAD),
802 IMAGE_ICON, 48, 48, LR_SHARED );
804 LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad));
805 ShellAbout(Globals.hMainWnd, szNotepad, notepadW, icon);
809 /***********************************************************************
811 * DIALOG_FilePageSetup
813 VOID DIALOG_FilePageSetup(void)
815 DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP),
816 Globals.hMainWnd, DIALOG_PAGESETUP_DlgProc);
820 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
822 * DIALOG_PAGESETUP_DlgProc
825 static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
834 /* save user input and close dialog */
835 GetDlgItemText(hDlg, IDC_PAGESETUP_HEADERVALUE, Globals.szHeader, SIZEOF(Globals.szHeader));
836 GetDlgItemText(hDlg, IDC_PAGESETUP_FOOTERVALUE, Globals.szFooter, SIZEOF(Globals.szFooter));
838 Globals.iMarginTop = GetDlgItemInt(hDlg, IDC_PAGESETUP_TOPVALUE, NULL, FALSE) * 100;
839 Globals.iMarginBottom = GetDlgItemInt(hDlg, IDC_PAGESETUP_BOTTOMVALUE, NULL, FALSE) * 100;
840 Globals.iMarginLeft = GetDlgItemInt(hDlg, IDC_PAGESETUP_LEFTVALUE, NULL, FALSE) * 100;
841 Globals.iMarginRight = GetDlgItemInt(hDlg, IDC_PAGESETUP_RIGHTVALUE, NULL, FALSE) * 100;
842 EndDialog(hDlg, IDOK);
846 /* discard user input and close dialog */
847 EndDialog(hDlg, IDCANCEL);
852 /* FIXME: Bring this to work */
853 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 };
854 static const WCHAR helpW[] = { 'H','e','l','p',0 };
855 MessageBox(Globals.hMainWnd, sorryW, helpW, MB_ICONEXCLAMATION);
865 /* fetch last user input prior to display dialog */
866 SetDlgItemText(hDlg, IDC_PAGESETUP_HEADERVALUE, Globals.szHeader);
867 SetDlgItemText(hDlg, IDC_PAGESETUP_FOOTERVALUE, Globals.szFooter);
868 SetDlgItemInt(hDlg, IDC_PAGESETUP_TOPVALUE, Globals.iMarginTop / 100, FALSE);
869 SetDlgItemInt(hDlg, IDC_PAGESETUP_BOTTOMVALUE, Globals.iMarginBottom / 100, FALSE);
870 SetDlgItemInt(hDlg, IDC_PAGESETUP_LEFTVALUE, Globals.iMarginLeft / 100, FALSE);
871 SetDlgItemInt(hDlg, IDC_PAGESETUP_RIGHTVALUE, Globals.iMarginRight / 100, FALSE);