winex11.drv: Fix the regression caused by a previous change.
[wine.git] / programs / notepad / dialog.c
blobc72e01f6f0fcc5f748883eb4d30fd4699ea39e4d
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
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.
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.
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
23 #define UNICODE
25 #include <assert.h>
26 #include <stdio.h>
27 #include <windows.h>
28 #include <commdlg.h>
29 #include <shlwapi.h>
31 #include "main.h"
32 #include "dialog.h"
34 #define SPACES_IN_TAB 8
35 #define PRINT_LEN_MAX 120
37 static const WCHAR helpfileW[] = { 'n','o','t','e','p','a','d','.','h','l','p',0 };
39 static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam);
41 VOID ShowLastError(void)
43 DWORD error = GetLastError();
44 if (error != NO_ERROR)
46 LPWSTR lpMsgBuf;
47 WCHAR szTitle[MAX_STRING_LEN];
49 LoadString(Globals.hInstance, STRING_ERROR, szTitle, SIZEOF(szTitle));
50 FormatMessage(
51 FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
52 NULL, error, 0,
53 (LPTSTR) &lpMsgBuf, 0, NULL);
54 MessageBox(NULL, lpMsgBuf, szTitle, MB_OK | MB_ICONERROR);
55 LocalFree(lpMsgBuf);
59 /**
60 * Sets the caption of the main window according to Globals.szFileTitle:
61 * Untitled - Notepad if no file is open
62 * filename - Notepad if a file is given
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 lstrcpy(szCaption, Globals.szFileTitle);
72 else
73 LoadString(Globals.hInstance, STRING_UNTITLED, szCaption, SIZEOF(szCaption));
75 LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad));
76 lstrcat(szCaption, hyphenW);
77 lstrcat(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 wnsprintf(szMessage, SIZEOF(szMessage), szResource, szString);
91 /* Load szCaption */
92 if ((dwFlags & MB_ICONMASK) == MB_ICONEXCLAMATION)
93 LoadString(Globals.hInstance, STRING_ERROR, szResource, SIZEOF(szResource));
94 else
95 LoadString(Globals.hInstance, STRING_NOTEPAD, szResource, SIZEOF(szResource));
97 /* Display Modal Dialog */
98 if (hParent == NULL)
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);
118 * Returns:
119 * TRUE - if file exists
120 * FALSE - if file does not exist
122 BOOL FileExists(LPCWSTR szFilename)
124 WIN32_FIND_DATA entry;
125 HANDLE hFile;
127 hFile = FindFirstFile(szFilename, &entry);
128 FindClose(hFile);
130 return (hFile != INVALID_HANDLE_VALUE);
134 static VOID DoSaveFile(VOID)
136 HANDLE hFile;
137 DWORD dwNumWrite;
138 LPSTR pTemp;
139 DWORD size;
141 hFile = CreateFile(Globals.szFileName, GENERIC_WRITE, FILE_SHARE_WRITE,
142 NULL, OPEN_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL);
143 if(hFile == INVALID_HANDLE_VALUE)
145 ShowLastError();
146 return;
149 size = GetWindowTextLengthA(Globals.hEdit) + 1;
150 pTemp = HeapAlloc(GetProcessHeap(), 0, size);
151 if (!pTemp)
153 CloseHandle(hFile);
154 ShowLastError();
155 return;
157 size = GetWindowTextA(Globals.hEdit, pTemp, size);
159 if (!WriteFile(hFile, pTemp, size, &dwNumWrite, NULL))
160 ShowLastError();
161 else
162 SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
164 SetEndOfFile(hFile);
165 CloseHandle(hFile);
166 HeapFree(GetProcessHeap(), 0, pTemp);
170 * Returns:
171 * TRUE - User agreed to close (both save/don't save)
172 * FALSE - User cancelled close by selecting "Cancel"
174 BOOL DoCloseFile(void)
176 int nResult;
177 static const WCHAR empty_strW[] = { 0 };
179 if (SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0))
181 /* prompt user to save changes */
182 nResult = AlertFileNotSaved(Globals.szFileName);
183 switch (nResult) {
184 case IDYES: DIALOG_FileSave();
185 break;
187 case IDNO: break;
189 case IDCANCEL: return(FALSE);
190 break;
192 default: return(FALSE);
193 break;
194 } /* switch */
195 } /* if */
197 SetFileName(empty_strW);
199 UpdateWindowCaption();
200 return(TRUE);
204 void DoOpenFile(LPCWSTR szFileName)
206 static const WCHAR dotlog[] = { '.','L','O','G',0 };
207 HANDLE hFile;
208 LPSTR pTemp;
209 DWORD size;
210 DWORD dwNumRead;
211 WCHAR log[5];
213 /* Close any files and prompt to save changes */
214 if (!DoCloseFile())
215 return;
217 hFile = CreateFile(szFileName, GENERIC_READ, FILE_SHARE_READ, NULL,
218 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
219 if(hFile == INVALID_HANDLE_VALUE)
221 ShowLastError();
222 return;
225 size = GetFileSize(hFile, NULL);
226 if (size == INVALID_FILE_SIZE)
228 CloseHandle(hFile);
229 ShowLastError();
230 return;
232 size++;
234 pTemp = HeapAlloc(GetProcessHeap(), 0, size);
235 if (!pTemp)
237 CloseHandle(hFile);
238 ShowLastError();
239 return;
242 if (!ReadFile(hFile, pTemp, size, &dwNumRead, NULL))
244 CloseHandle(hFile);
245 HeapFree(GetProcessHeap(), 0, pTemp);
246 ShowLastError();
247 return;
250 CloseHandle(hFile);
251 pTemp[dwNumRead] = 0;
253 if (IsTextUnicode(pTemp, dwNumRead, NULL))
255 LPWSTR p = (LPWSTR)pTemp;
256 /* We need to strip BOM Unicode character, SetWindowTextW won't do it for us. */
257 if (*p == 0xFEFF || *p == 0xFFFE) p++;
258 SetWindowTextW(Globals.hEdit, p);
260 else
261 SetWindowTextA(Globals.hEdit, pTemp);
263 HeapFree(GetProcessHeap(), 0, pTemp);
265 SendMessage(Globals.hEdit, EM_SETMODIFY, FALSE, 0);
266 SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
267 SetFocus(Globals.hEdit);
269 /* If the file starts with .LOG, add a time/date at the end and set cursor after
270 * See http://support.microsoft.com/?kbid=260563
272 if (GetWindowTextW(Globals.hEdit, log, sizeof(log)/sizeof(log[0])) && !lstrcmp(log, dotlog))
274 static const WCHAR lfW[] = { '\r','\n',0 };
275 SendMessage(Globals.hEdit, EM_SETSEL, GetWindowTextLength(Globals.hEdit), -1);
276 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lfW);
277 DIALOG_EditTimeDate();
278 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)lfW);
281 SetFileName(szFileName);
282 UpdateWindowCaption();
285 VOID DIALOG_FileNew(VOID)
287 static const WCHAR empty_strW[] = { 0 };
289 /* Close any files and promt to save changes */
290 if (DoCloseFile()) {
291 SetWindowText(Globals.hEdit, empty_strW);
292 SendMessage(Globals.hEdit, EM_EMPTYUNDOBUFFER, 0, 0);
293 SetFocus(Globals.hEdit);
297 VOID DIALOG_FileOpen(VOID)
299 OPENFILENAME openfilename;
300 WCHAR szPath[MAX_PATH];
301 WCHAR szDir[MAX_PATH];
302 static const WCHAR szDefaultExt[] = { 't','x','t',0 };
303 static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
305 ZeroMemory(&openfilename, sizeof(openfilename));
307 GetCurrentDirectory(SIZEOF(szDir), szDir);
308 lstrcpy(szPath, txt_files);
310 openfilename.lStructSize = sizeof(openfilename);
311 openfilename.hwndOwner = Globals.hMainWnd;
312 openfilename.hInstance = Globals.hInstance;
313 openfilename.lpstrFilter = Globals.szFilter;
314 openfilename.lpstrFile = szPath;
315 openfilename.nMaxFile = SIZEOF(szPath);
316 openfilename.lpstrInitialDir = szDir;
317 openfilename.Flags = OFN_FILEMUSTEXIST | OFN_PATHMUSTEXIST |
318 OFN_HIDEREADONLY;
319 openfilename.lpstrDefExt = szDefaultExt;
322 if (GetOpenFileName(&openfilename)) {
323 if (FileExists(openfilename.lpstrFile))
324 DoOpenFile(openfilename.lpstrFile);
325 else
326 AlertFileNotFound(openfilename.lpstrFile);
331 VOID DIALOG_FileSave(VOID)
333 if (Globals.szFileName[0] == '\0')
334 DIALOG_FileSaveAs();
335 else
336 DoSaveFile();
339 VOID DIALOG_FileSaveAs(VOID)
341 OPENFILENAME saveas;
342 WCHAR szPath[MAX_PATH];
343 WCHAR szDir[MAX_PATH];
344 static const WCHAR szDefaultExt[] = { 't','x','t',0 };
345 static const WCHAR txt_files[] = { '*','.','t','x','t',0 };
347 ZeroMemory(&saveas, sizeof(saveas));
349 GetCurrentDirectory(SIZEOF(szDir), szDir);
350 lstrcpy(szPath, txt_files);
352 saveas.lStructSize = sizeof(OPENFILENAME);
353 saveas.hwndOwner = Globals.hMainWnd;
354 saveas.hInstance = Globals.hInstance;
355 saveas.lpstrFilter = Globals.szFilter;
356 saveas.lpstrFile = szPath;
357 saveas.nMaxFile = SIZEOF(szPath);
358 saveas.lpstrInitialDir = szDir;
359 saveas.Flags = OFN_PATHMUSTEXIST | OFN_OVERWRITEPROMPT |
360 OFN_HIDEREADONLY;
361 saveas.lpstrDefExt = szDefaultExt;
363 if (GetSaveFileName(&saveas)) {
364 SetFileName(szPath);
365 UpdateWindowCaption();
366 DoSaveFile();
370 VOID DIALOG_FilePrint(VOID)
372 DOCINFO di;
373 PRINTDLG printer;
374 SIZE szMetric;
375 int cWidthPels, cHeightPels, border;
376 int xLeft, yTop, pagecount, dopage, copycount;
377 unsigned int i;
378 LOGFONT hdrFont;
379 HFONT font, old_font=0;
380 DWORD size;
381 LPWSTR pTemp;
382 WCHAR cTemp[PRINT_LEN_MAX];
383 static const WCHAR print_fontW[] = { 'C','o','u','r','i','e','r',0 };
384 static const WCHAR letterM[] = { 'M',0 };
386 /* Get a small font and print some header info on each page */
387 hdrFont.lfHeight = -35;
388 hdrFont.lfWidth = 0;
389 hdrFont.lfEscapement = 0;
390 hdrFont.lfOrientation = 0;
391 hdrFont.lfWeight = FW_BOLD;
392 hdrFont.lfItalic = 0;
393 hdrFont.lfUnderline = 0;
394 hdrFont.lfStrikeOut = 0;
395 hdrFont.lfCharSet = ANSI_CHARSET;
396 hdrFont.lfOutPrecision = OUT_DEFAULT_PRECIS;
397 hdrFont.lfClipPrecision = CLIP_DEFAULT_PRECIS;
398 hdrFont.lfQuality = PROOF_QUALITY;
399 hdrFont.lfPitchAndFamily = VARIABLE_PITCH | FF_ROMAN;
400 lstrcpy(hdrFont.lfFaceName, print_fontW);
402 font = CreateFontIndirect(&hdrFont);
404 /* Get Current Settings */
405 ZeroMemory(&printer, sizeof(printer));
406 printer.lStructSize = sizeof(printer);
407 printer.hwndOwner = Globals.hMainWnd;
408 printer.hDevMode = Globals.hDevMode;
409 printer.hDevNames = Globals.hDevNames;
410 printer.hInstance = Globals.hInstance;
412 /* Set some default flags */
413 printer.Flags = PD_RETURNDC | PD_NOSELECTION;
414 printer.nFromPage = 0;
415 printer.nMinPage = 1;
416 /* we really need to calculate number of pages to set nMaxPage and nToPage */
417 printer.nToPage = 0;
418 printer.nMaxPage = -1;
419 /* Let commdlg manage copy settings */
420 printer.nCopies = (WORD)PD_USEDEVMODECOPIES;
422 if (!PrintDlg(&printer)) return;
424 Globals.hDevMode = printer.hDevMode;
425 Globals.hDevNames = printer.hDevNames;
427 assert(printer.hDC != 0);
429 /* initialize DOCINFO */
430 di.cbSize = sizeof(DOCINFO);
431 di.lpszDocName = Globals.szFileTitle;
432 di.lpszOutput = NULL;
433 di.lpszDatatype = NULL;
434 di.fwType = 0;
436 if (StartDoc(printer.hDC, &di) <= 0) return;
438 /* Get the page dimensions in pixels. */
439 cWidthPels = GetDeviceCaps(printer.hDC, HORZRES);
440 cHeightPels = GetDeviceCaps(printer.hDC, VERTRES);
442 /* Get the file text */
443 size = GetWindowTextLength(Globals.hEdit) + 1;
444 pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
445 if (!pTemp)
447 ShowLastError();
448 return;
450 size = GetWindowText(Globals.hEdit, pTemp, size);
452 border = 150;
453 old_font = SelectObject(printer.hDC, Globals.hFont);
454 GetTextExtentPoint32(printer.hDC, letterM, 1, &szMetric);
455 for (copycount=1; copycount <= printer.nCopies; copycount++) {
456 i = 0;
457 pagecount = 1;
458 do {
459 if (printer.Flags & PD_PAGENUMS) {
460 /* a specific range of pages is selected, so
461 * skip pages that are not to be printed
463 if (pagecount > printer.nToPage)
464 break;
465 else if (pagecount >= printer.nFromPage)
466 dopage = 1;
467 else
468 dopage = 0;
470 else
471 dopage = 1;
473 if (dopage) {
474 if (StartPage(printer.hDC) <= 0) {
475 static const WCHAR failedW[] = { 'S','t','a','r','t','P','a','g','e',' ','f','a','i','l','e','d',0 };
476 static const WCHAR errorW[] = { 'P','r','i','n','t',' ','E','r','r','o','r',0 };
477 MessageBox(Globals.hMainWnd, failedW, errorW, MB_ICONEXCLAMATION);
478 return;
480 /* Write a rectangle and header at the top of each page */
481 SelectObject(printer.hDC, font);
482 Rectangle(printer.hDC, border, border, cWidthPels-border, border+szMetric.cy*2);
483 TextOut(printer.hDC, border*2, border+szMetric.cy/2, Globals.szFileTitle, lstrlen(Globals.szFileTitle));
486 SelectObject(printer.hDC, Globals.hFont);
487 /* The starting point for the main text */
488 xLeft = border;
489 yTop = border+szMetric.cy*4;
491 do {
492 int k=0, m;
493 /* find the end of the line */
494 while (i < size && pTemp[i] != '\n' && pTemp[i] != '\r') {
495 if (pTemp[i] == '\t') {
496 /* replace tabs with spaces */
497 for (m=0; m<SPACES_IN_TAB; m++) {
498 if (k < PRINT_LEN_MAX)
499 cTemp[k++] = ' ';
502 else if (k < PRINT_LEN_MAX)
503 cTemp[k++] = pTemp[i];
504 i++;
506 if (dopage)
507 TextOut(printer.hDC, xLeft, yTop, cTemp, k);
508 /* find the next line */
509 while (i < size && (pTemp[i] == '\n' || pTemp[i] == '\r')) {
510 if (pTemp[i] == '\n')
511 yTop += szMetric.cy;
512 i++;
514 } while (i<size && yTop<(cHeightPels-border*2));
516 if (dopage)
517 EndPage(printer.hDC);
518 pagecount++;
519 } while (i<size);
521 SelectObject(printer.hDC, old_font);
523 EndDoc(printer.hDC);
524 DeleteDC(printer.hDC);
525 HeapFree(GetProcessHeap(), 0, pTemp);
528 VOID DIALOG_FilePrinterSetup(VOID)
530 PRINTDLG printer;
532 ZeroMemory(&printer, sizeof(printer));
533 printer.lStructSize = sizeof(printer);
534 printer.hwndOwner = Globals.hMainWnd;
535 printer.hDevMode = Globals.hDevMode;
536 printer.hDevNames = Globals.hDevNames;
537 printer.hInstance = Globals.hInstance;
538 printer.Flags = PD_PRINTSETUP;
539 printer.nCopies = 1;
541 PrintDlg(&printer);
543 Globals.hDevMode = printer.hDevMode;
544 Globals.hDevNames = printer.hDevNames;
547 VOID DIALOG_FileExit(VOID)
549 PostMessage(Globals.hMainWnd, WM_CLOSE, 0, 0l);
552 VOID DIALOG_EditUndo(VOID)
554 SendMessage(Globals.hEdit, EM_UNDO, 0, 0);
557 VOID DIALOG_EditCut(VOID)
559 SendMessage(Globals.hEdit, WM_CUT, 0, 0);
562 VOID DIALOG_EditCopy(VOID)
564 SendMessage(Globals.hEdit, WM_COPY, 0, 0);
567 VOID DIALOG_EditPaste(VOID)
569 SendMessage(Globals.hEdit, WM_PASTE, 0, 0);
572 VOID DIALOG_EditDelete(VOID)
574 SendMessage(Globals.hEdit, WM_CLEAR, 0, 0);
577 VOID DIALOG_EditSelectAll(VOID)
579 SendMessage(Globals.hEdit, EM_SETSEL, 0, (LPARAM)-1);
582 VOID DIALOG_EditTimeDate(VOID)
584 SYSTEMTIME st;
585 WCHAR szDate[MAX_STRING_LEN];
586 static const WCHAR spaceW[] = { ' ',0 };
588 GetLocalTime(&st);
590 GetTimeFormat(LOCALE_USER_DEFAULT, 0, &st, NULL, szDate, MAX_STRING_LEN);
591 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
593 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)spaceW);
595 GetDateFormat(LOCALE_USER_DEFAULT, DATE_LONGDATE, &st, NULL, szDate, MAX_STRING_LEN);
596 SendMessage(Globals.hEdit, EM_REPLACESEL, TRUE, (LPARAM)szDate);
599 VOID DIALOG_EditWrap(VOID)
601 BOOL modify = FALSE;
602 static const WCHAR editW[] = { 'e','d','i','t',0 };
603 DWORD dwStyle = WS_CHILD | WS_VISIBLE | WS_BORDER | WS_VSCROLL |
604 ES_AUTOVSCROLL | ES_MULTILINE;
605 RECT rc;
606 DWORD size;
607 LPWSTR pTemp;
609 size = GetWindowTextLength(Globals.hEdit) + 1;
610 pTemp = HeapAlloc(GetProcessHeap(), 0, size * sizeof(WCHAR));
611 if (!pTemp)
613 ShowLastError();
614 return;
616 GetWindowText(Globals.hEdit, pTemp, size);
617 modify = SendMessage(Globals.hEdit, EM_GETMODIFY, 0, 0);
618 DestroyWindow(Globals.hEdit);
619 GetClientRect(Globals.hMainWnd, &rc);
620 if( Globals.bWrapLongLines ) dwStyle |= WS_HSCROLL | ES_AUTOHSCROLL;
621 Globals.hEdit = CreateWindowEx(WS_EX_CLIENTEDGE, editW, NULL, dwStyle,
622 0, 0, rc.right, rc.bottom, Globals.hMainWnd,
623 NULL, Globals.hInstance, NULL);
624 SendMessage(Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)FALSE);
625 SetWindowTextW(Globals.hEdit, pTemp);
626 SendMessage(Globals.hEdit, EM_SETMODIFY, (WPARAM)modify, 0);
627 SetFocus(Globals.hEdit);
628 HeapFree(GetProcessHeap(), 0, pTemp);
630 Globals.bWrapLongLines = !Globals.bWrapLongLines;
631 CheckMenuItem(GetMenu(Globals.hMainWnd), CMD_WRAP,
632 MF_BYCOMMAND | (Globals.bWrapLongLines ? MF_CHECKED : MF_UNCHECKED));
635 VOID DIALOG_SelectFont(VOID)
637 CHOOSEFONT cf;
638 LOGFONT lf=Globals.lfFont;
640 ZeroMemory( &cf, sizeof(cf) );
641 cf.lStructSize=sizeof(cf);
642 cf.hwndOwner=Globals.hMainWnd;
643 cf.lpLogFont=&lf;
644 cf.Flags=CF_SCREENFONTS | CF_INITTOLOGFONTSTRUCT;
646 if( ChooseFont(&cf) )
648 HFONT currfont=Globals.hFont;
650 Globals.hFont=CreateFontIndirect( &lf );
651 Globals.lfFont=lf;
652 SendMessage( Globals.hEdit, WM_SETFONT, (WPARAM)Globals.hFont, (LPARAM)TRUE );
653 if( currfont!=NULL )
654 DeleteObject( currfont );
658 VOID DIALOG_Search(VOID)
660 ZeroMemory(&Globals.find, sizeof(Globals.find));
661 Globals.find.lStructSize = sizeof(Globals.find);
662 Globals.find.hwndOwner = Globals.hMainWnd;
663 Globals.find.hInstance = Globals.hInstance;
664 Globals.find.lpstrFindWhat = Globals.szFindText;
665 Globals.find.wFindWhatLen = SIZEOF(Globals.szFindText);
666 Globals.find.Flags = FR_DOWN|FR_HIDEWHOLEWORD;
668 /* We only need to create the modal FindReplace dialog which will */
669 /* notify us of incoming events using hMainWnd Window Messages */
671 Globals.hFindReplaceDlg = FindText(&Globals.find);
672 assert(Globals.hFindReplaceDlg !=0);
675 VOID DIALOG_SearchNext(VOID)
677 if (Globals.lastFind.lpstrFindWhat == NULL)
678 DIALOG_Search();
679 else /* use the last find data */
680 NOTEPAD_DoFind(&Globals.lastFind);
683 VOID DIALOG_HelpContents(VOID)
685 WinHelp(Globals.hMainWnd, helpfileW, HELP_INDEX, 0);
688 VOID DIALOG_HelpSearch(VOID)
690 /* Search Help */
693 VOID DIALOG_HelpHelp(VOID)
695 WinHelp(Globals.hMainWnd, helpfileW, HELP_HELPONHELP, 0);
698 VOID DIALOG_HelpLicense(VOID)
700 TCHAR cap[20], text[1024];
701 LoadString(Globals.hInstance, IDS_LICENSE, text, 1024);
702 LoadString(Globals.hInstance, IDS_LICENSE_CAPTION, cap, 20);
703 MessageBox(Globals.hMainWnd, text, cap, MB_ICONINFORMATION | MB_OK);
706 VOID DIALOG_HelpNoWarranty(VOID)
708 TCHAR cap[20], text[1024];
709 LoadString(Globals.hInstance, IDS_WARRANTY, text, 1024);
710 LoadString(Globals.hInstance, IDS_WARRANTY_CAPTION, cap, 20);
711 MessageBox(Globals.hMainWnd, text, cap, MB_ICONEXCLAMATION | MB_OK);
714 VOID DIALOG_HelpAboutWine(VOID)
716 static const WCHAR notepadW[] = { 'N','o','t','e','p','a','d','\n',0 };
717 WCHAR szNotepad[MAX_STRING_LEN];
719 LoadString(Globals.hInstance, STRING_NOTEPAD, szNotepad, SIZEOF(szNotepad));
720 ShellAbout(Globals.hMainWnd, szNotepad, notepadW, 0);
724 /***********************************************************************
726 * DIALOG_FilePageSetup
728 VOID DIALOG_FilePageSetup(void)
730 DialogBox(Globals.hInstance, MAKEINTRESOURCE(DIALOG_PAGESETUP),
731 Globals.hMainWnd, DIALOG_PAGESETUP_DlgProc);
735 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
737 * DIALOG_PAGESETUP_DlgProc
740 static INT_PTR WINAPI DIALOG_PAGESETUP_DlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
743 switch (msg)
745 case WM_COMMAND:
746 switch (wParam)
748 case IDOK:
749 /* save user input and close dialog */
750 GetDlgItemText(hDlg, 0x141, Globals.szHeader, SIZEOF(Globals.szHeader));
751 GetDlgItemText(hDlg, 0x143, Globals.szFooter, SIZEOF(Globals.szFooter));
752 GetDlgItemText(hDlg, 0x14A, Globals.szMarginTop, SIZEOF(Globals.szMarginTop));
753 GetDlgItemText(hDlg, 0x150, Globals.szMarginBottom, SIZEOF(Globals.szMarginBottom));
754 GetDlgItemText(hDlg, 0x147, Globals.szMarginLeft, SIZEOF(Globals.szMarginLeft));
755 GetDlgItemText(hDlg, 0x14D, Globals.szMarginRight, SIZEOF(Globals.szMarginRight));
756 EndDialog(hDlg, IDOK);
757 return TRUE;
759 case IDCANCEL:
760 /* discard user input and close dialog */
761 EndDialog(hDlg, IDCANCEL);
762 return TRUE;
764 case IDHELP:
766 /* FIXME: Bring this to work */
767 static const WCHAR sorryW[] = { 'S','o','r','r','y',',',' ','n','o',' ','h','e','l','p',' ','a','v','a','i','l','a','b','l','e',0 };
768 static const WCHAR helpW[] = { 'H','e','l','p',0 };
769 MessageBox(Globals.hMainWnd, sorryW, helpW, MB_ICONEXCLAMATION);
770 return TRUE;
773 default:
774 break;
776 break;
778 case WM_INITDIALOG:
779 /* fetch last user input prior to display dialog */
780 SetDlgItemText(hDlg, 0x141, Globals.szHeader);
781 SetDlgItemText(hDlg, 0x143, Globals.szFooter);
782 SetDlgItemText(hDlg, 0x14A, Globals.szMarginTop);
783 SetDlgItemText(hDlg, 0x150, Globals.szMarginBottom);
784 SetDlgItemText(hDlg, 0x147, Globals.szMarginLeft);
785 SetDlgItemText(hDlg, 0x14D, Globals.szMarginRight);
786 break;
789 return FALSE;