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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #define _CRT_SECURE_NO_DEPRECATE
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
,
54 (LPTSTR
) &lpMsgBuf
, 0, NULL
);
55 MessageBox(NULL
, lpMsgBuf
, szTitle
, MB_OK
| MB_ICONERROR
);
61 * Sets the caption of the main window according to Globals.szFileTitle:
62 * Notepad - (untitled) if no file is open
63 * Notepad - [filename] if a file is given
65 static void UpdateWindowCaption(void)
67 WCHAR szCaption
[MAX_STRING_LEN
];
68 WCHAR szUntitled
[MAX_STRING_LEN
];
70 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szCaption
, SIZEOF(szCaption
));
72 if (Globals
.szFileTitle
[0] != '\0') {
73 static const WCHAR bracket_lW
[] = { ' ','-',' ','[',0 };
74 static const WCHAR bracket_rW
[] = { ']',0 };
75 lstrcat(szCaption
, bracket_lW
);
76 lstrcat(szCaption
, Globals
.szFileTitle
);
77 lstrcat(szCaption
, bracket_rW
);
81 static const WCHAR hyphenW
[] = { ' ','-',' ',0 };
82 LoadString(Globals
.hInstance
, STRING_UNTITLED
, szUntitled
, SIZEOF(szUntitled
));
83 lstrcat(szCaption
, hyphenW
);
84 lstrcat(szCaption
, szUntitled
);
87 SetWindowText(Globals
.hMainWnd
, szCaption
);
90 static void AlertFileNotFound(LPCWSTR szFileName
)
92 WCHAR szMessage
[MAX_STRING_LEN
];
93 WCHAR szResource
[MAX_STRING_LEN
];
95 /* Load and format szMessage */
96 LoadString(Globals
.hInstance
, STRING_NOTFOUND
, szResource
, SIZEOF(szResource
));
97 wsprintf(szMessage
, szResource
, szFileName
);
100 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szResource
, SIZEOF(szResource
));
102 /* Display Modal Dialog */
103 MessageBox(Globals
.hMainWnd
, szMessage
, szResource
, MB_ICONEXCLAMATION
);
106 static int AlertFileNotSaved(LPCWSTR szFileName
)
108 WCHAR szMessage
[MAX_STRING_LEN
];
109 WCHAR szResource
[MAX_STRING_LEN
];
110 WCHAR szUntitled
[MAX_STRING_LEN
];
112 LoadString(Globals
.hInstance
, STRING_UNTITLED
, szUntitled
, SIZEOF(szUntitled
));
114 /* Load and format Message */
115 LoadString(Globals
.hInstance
, STRING_NOTSAVED
, szResource
, SIZEOF(szResource
));
116 wsprintf(szMessage
, szResource
, szFileName
[0] ? szFileName
: szUntitled
);
119 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szResource
, SIZEOF(szResource
));
122 return MessageBox(Globals
.hMainWnd
, szMessage
, szResource
, MB_ICONEXCLAMATION
|MB_YESNOCANCEL
);
127 * TRUE - if file exists
128 * FALSE - if file does not exist
130 BOOL
FileExists(LPCWSTR szFilename
)
132 WIN32_FIND_DATA entry
;
135 hFile
= FindFirstFile(szFilename
, &entry
);
138 return (hFile
!= INVALID_HANDLE_VALUE
);
142 static VOID
DoSaveFile(VOID
)
148 hFile
= CreateFile(Globals
.szFileName
, GENERIC_WRITE
, FILE_SHARE_WRITE
,
149 NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
150 if(hFile
== INVALID_HANDLE_VALUE
)
156 size
= GetWindowTextLengthW(Globals
.hEdit
) + 1;
157 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(*pTemp
));
164 size
= GetWindowTextW(Globals
.hEdit
, pTemp
, size
);
166 if (!WriteText(hFile
, pTemp
, size
, Globals
.iEncoding
, Globals
.iEoln
))
169 SendMessage(Globals
.hEdit
, EM_SETMODIFY
, FALSE
, 0);
172 HeapFree(GetProcessHeap(), 0, pTemp
);
177 * TRUE - User agreed to close (both save/don't save)
178 * FALSE - User cancelled close by selecting "Cancel"
180 BOOL
DoCloseFile(void)
183 static const WCHAR empty_strW
[] = { 0 };
185 if (SendMessage(Globals
.hEdit
, EM_GETMODIFY
, 0, 0))
187 /* prompt user to save changes */
188 nResult
= AlertFileNotSaved(Globals
.szFileName
);
190 case IDYES
: DIALOG_FileSave();
195 case IDCANCEL
: return(FALSE
);
198 default: return(FALSE
);
203 SetFileName(empty_strW
);
205 UpdateWindowCaption();
210 void DoOpenFile(LPCWSTR szFileName
)
212 static const WCHAR dotlog
[] = { '.','L','O','G',0 };
218 /* Close any files and prompt to save changes */
222 hFile
= CreateFile(szFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
223 OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
224 if (hFile
== INVALID_HANDLE_VALUE
)
230 if (!ReadText(hFile
, &pszText
, &dwTextLen
, &Globals
.iEncoding
, &Globals
.iEoln
))
236 SetWindowTextW(Globals
.hEdit
, pszText
);
238 SendMessage(Globals
.hEdit
, EM_SETMODIFY
, FALSE
, 0);
239 SendMessage(Globals
.hEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
240 SetFocus(Globals
.hEdit
);
242 /* If the file starts with .LOG, add a time/date at the end and set cursor after
243 * See http://support.microsoft.com/?kbid=260563
245 if (GetWindowTextW(Globals
.hEdit
, log
, sizeof(log
)/sizeof(log
[0])) && !lstrcmp(log
, dotlog
))
247 static const WCHAR lfW
[] = { '\r','\n',0 };
248 SendMessage(Globals
.hEdit
, EM_SETSEL
, GetWindowTextLength(Globals
.hEdit
), -1);
249 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)lfW
);
250 DIALOG_EditTimeDate();
251 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)lfW
);
254 SetFileName(szFileName
);
255 UpdateWindowCaption();
258 if (hFile
!= INVALID_HANDLE_VALUE
)
261 HeapFree(GetProcessHeap(), 0, pszText
);
264 VOID
DIALOG_FileNew(VOID
)
266 static const WCHAR empty_strW
[] = { 0 };
268 /* Close any files and prompt to save changes */
270 SetWindowText(Globals
.hEdit
, empty_strW
);
271 SendMessage(Globals
.hEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
272 SetFocus(Globals
.hEdit
);
276 VOID
DIALOG_FileOpen(VOID
)
278 OPENFILENAME openfilename
;
279 WCHAR szDir
[MAX_PATH
];
280 WCHAR szPath
[MAX_PATH
];
281 static const WCHAR szDefaultExt
[] = { 't','x','t',0 };
282 static const WCHAR txt_files
[] = { '*','.','t','x','t',0 };
284 ZeroMemory(&openfilename
, sizeof(openfilename
));
286 GetCurrentDirectory(SIZEOF(szDir
), szDir
);
287 if (Globals
.szFileName
[0] == 0)
288 lstrcpy(szPath
, txt_files
);
290 lstrcpy(szPath
, Globals
.szFileName
);
292 openfilename
.lStructSize
= sizeof(openfilename
);
293 openfilename
.hwndOwner
= Globals
.hMainWnd
;
294 openfilename
.hInstance
= Globals
.hInstance
;
295 openfilename
.lpstrFilter
= Globals
.szFilter
;
296 openfilename
.lpstrFile
= szPath
;
297 openfilename
.nMaxFile
= SIZEOF(szPath
);
298 openfilename
.lpstrInitialDir
= szDir
;
299 openfilename
.Flags
= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
|
301 openfilename
.lpstrDefExt
= szDefaultExt
;
304 if (GetOpenFileName(&openfilename
)) {
305 if (FileExists(openfilename
.lpstrFile
))
306 DoOpenFile(openfilename
.lpstrFile
);
308 AlertFileNotFound(openfilename
.lpstrFile
);
313 VOID
DIALOG_FileSave(VOID
)
315 if (Globals
.szFileName
[0] == '\0')
321 static UINT_PTR CALLBACK
DIALOG_FileSaveAs_Hook(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
330 hCombo
= GetDlgItem(hDlg
, ID_ENCODING
);
332 LoadString(Globals
.hInstance
, STRING_ANSI
, szText
, SIZEOF(szText
));
333 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
335 LoadString(Globals
.hInstance
, STRING_UNICODE
, szText
, SIZEOF(szText
));
336 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
338 LoadString(Globals
.hInstance
, STRING_UNICODE_BE
, szText
, SIZEOF(szText
));
339 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
341 LoadString(Globals
.hInstance
, STRING_UTF8
, szText
, SIZEOF(szText
));
342 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
344 SendMessage(hCombo
, CB_SETCURSEL
, Globals
.iEncoding
, 0);
346 hCombo
= GetDlgItem(hDlg
, ID_EOLN
);
348 LoadString(Globals
.hInstance
, STRING_CRLF
, szText
, SIZEOF(szText
));
349 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
351 LoadString(Globals
.hInstance
, STRING_LF
, szText
, SIZEOF(szText
));
352 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
354 LoadString(Globals
.hInstance
, STRING_CR
, szText
, SIZEOF(szText
));
355 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
357 SendMessage(hCombo
, CB_SETCURSEL
, Globals
.iEoln
, 0);
361 if (((NMHDR
*) lParam
)->code
== CDN_FILEOK
)
363 pNotify
= (OFNOTIFY
*) lParam
;
365 hCombo
= GetDlgItem(hDlg
, ID_ENCODING
);
367 Globals
.iEncoding
= SendMessage(hCombo
, CB_GETCURSEL
, 0, 0);
369 hCombo
= GetDlgItem(hDlg
, ID_EOLN
);
371 Globals
.iEoln
= SendMessage(hCombo
, CB_GETCURSEL
, 0, 0);
378 VOID
DIALOG_FileSaveAs(VOID
)
381 WCHAR szDir
[MAX_PATH
];
382 WCHAR szPath
[MAX_PATH
];
383 static const WCHAR szDefaultExt
[] = { 't','x','t',0 };
384 static const WCHAR txt_files
[] = { '*','.','t','x','t',0 };
386 ZeroMemory(&saveas
, sizeof(saveas
));
388 GetCurrentDirectory(SIZEOF(szDir
), szDir
);
389 if (Globals
.szFileName
[0] == 0)
390 lstrcpy(szPath
, txt_files
);
392 lstrcpy(szPath
, Globals
.szFileName
);
394 saveas
.lStructSize
= sizeof(OPENFILENAME
);
395 saveas
.hwndOwner
= Globals
.hMainWnd
;
396 saveas
.hInstance
= Globals
.hInstance
;
397 saveas
.lpstrFilter
= Globals
.szFilter
;
398 saveas
.lpstrFile
= szPath
;
399 saveas
.nMaxFile
= SIZEOF(szPath
);
400 saveas
.lpstrInitialDir
= szDir
;
401 saveas
.Flags
= OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
|
402 OFN_HIDEREADONLY
| OFN_EXPLORER
| OFN_ENABLETEMPLATE
| OFN_ENABLEHOOK
;
403 saveas
.lpstrDefExt
= szDefaultExt
;
404 saveas
.lpTemplateName
= MAKEINTRESOURCE(DIALOG_ENCODING
);
405 saveas
.lpfnHook
= DIALOG_FileSaveAs_Hook
;
407 if (GetSaveFileName(&saveas
)) {
409 UpdateWindowCaption();
414 VOID
DIALOG_FilePrint(VOID
)
419 int cWidthPels
, cHeightPels
, border
;
420 int xLeft
, yTop
, pagecount
, dopage
, copycount
;
423 HFONT font
, old_font
=0;
426 static const WCHAR times_new_romanW
[] = { 'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n',0 };
428 /* Get a small font and print some header info on each page */
429 hdrFont
.lfHeight
= 100;
431 hdrFont
.lfEscapement
= 0;
432 hdrFont
.lfOrientation
= 0;
433 hdrFont
.lfWeight
= FW_BOLD
;
434 hdrFont
.lfItalic
= 0;
435 hdrFont
.lfUnderline
= 0;
436 hdrFont
.lfStrikeOut
= 0;
437 hdrFont
.lfCharSet
= ANSI_CHARSET
;
438 hdrFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
439 hdrFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
440 hdrFont
.lfQuality
= PROOF_QUALITY
;
441 hdrFont
.lfPitchAndFamily
= VARIABLE_PITCH
| FF_ROMAN
;
442 lstrcpy(hdrFont
.lfFaceName
, times_new_romanW
);
444 font
= CreateFontIndirect(&hdrFont
);
446 /* Get Current Settings */
447 ZeroMemory(&printer
, sizeof(printer
));
448 printer
.lStructSize
= sizeof(printer
);
449 printer
.hwndOwner
= Globals
.hMainWnd
;
450 printer
.hInstance
= Globals
.hInstance
;
452 /* Set some default flags */
453 printer
.Flags
= PD_RETURNDC
;
454 printer
.nFromPage
= 0;
455 printer
.nMinPage
= 1;
456 /* we really need to calculate number of pages to set nMaxPage and nToPage */
458 printer
.nMaxPage
= -1;
460 /* Let commdlg manage copy settings */
461 printer
.nCopies
= (WORD
)PD_USEDEVMODECOPIES
;
463 if (!PrintDlg(&printer
)) return;
465 assert(printer
.hDC
!= 0);
467 /* initialize DOCINFO */
468 di
.cbSize
= sizeof(DOCINFO
);
469 di
.lpszDocName
= Globals
.szFileTitle
;
470 di
.lpszOutput
= NULL
;
471 di
.lpszDatatype
= NULL
;
474 if (StartDoc(printer
.hDC
, &di
) <= 0) return;
476 /* Get the page dimensions in pixels. */
477 cWidthPels
= GetDeviceCaps(printer
.hDC
, HORZRES
);
478 cHeightPels
= GetDeviceCaps(printer
.hDC
, VERTRES
);
480 /* Get the file text */
481 size
= GetWindowTextLengthW(Globals
.hEdit
) + 1;
482 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
488 size
= GetWindowTextW(Globals
.hEdit
, pTemp
, size
);
491 for (copycount
=1; copycount
<= printer
.nCopies
; copycount
++) {
495 static const WCHAR letterM
[] = { 'M',0 };
497 if (pagecount
>= printer
.nFromPage
&&
498 /* ((printer.Flags & PD_PAGENUMS) == 0 || pagecount <= printer.nToPage))*/
499 pagecount
<= printer
.nToPage
)
504 old_font
= SelectObject(printer
.hDC
, font
);
505 GetTextExtentPoint32(printer
.hDC
, letterM
, 1, &szMetric
);
508 if (StartPage(printer
.hDC
) <= 0) {
509 static const WCHAR failedW
[] = { 'S','t','a','r','t','P','a','g','e',' ','f','a','i','l','e','d',0 };
510 static const WCHAR errorW
[] = { 'P','r','i','n','t',' ','E','r','r','o','r',0 };
511 MessageBox(Globals
.hMainWnd
, failedW
, errorW
, MB_ICONEXCLAMATION
);
514 /* Write a rectangle and header at the top of each page */
515 Rectangle(printer
.hDC
, border
, border
, cWidthPels
-border
, border
+szMetric
.cy
*2);
516 /* I don't know what's up with this TextOut command. This comes out
519 TextOut(printer
.hDC
, border
*2, border
+szMetric
.cy
/2, Globals
.szFileTitle
, lstrlen(Globals
.szFileTitle
));
522 /* The starting point for the main text */
524 yTop
= border
+szMetric
.cy
*4;
526 SelectObject(printer
.hDC
, old_font
);
527 GetTextExtentPoint32(printer
.hDC
, letterM
, 1, &szMetric
);
529 /* Since outputting strings is giving me problems, output the main
530 text one character at a time.
533 if (pTemp
[i
] == '\n') {
537 else if (pTemp
[i
] != '\r') {
539 TextOut(printer
.hDC
, xLeft
, yTop
, &pTemp
[i
], 1);
540 xLeft
+= szMetric
.cx
;
542 } while (i
++<size
&& yTop
<(cHeightPels
-border
*2));
545 EndPage(printer
.hDC
);
551 DeleteDC(printer
.hDC
);
552 HeapFree(GetProcessHeap(), 0, pTemp
);
555 VOID
DIALOG_FilePrinterSetup(VOID
)
559 ZeroMemory(&printer
, sizeof(printer
));
560 printer
.lStructSize
= sizeof(printer
);
561 printer
.hwndOwner
= Globals
.hMainWnd
;
562 printer
.hInstance
= Globals
.hInstance
;
563 printer
.Flags
= PD_PRINTSETUP
;
569 VOID
DIALOG_FileExit(VOID
)
571 PostMessage(Globals
.hMainWnd
, WM_CLOSE
, 0, 0l);
574 VOID
DIALOG_EditUndo(VOID
)
576 SendMessage(Globals
.hEdit
, EM_UNDO
, 0, 0);
579 VOID
DIALOG_EditCut(VOID
)
581 SendMessage(Globals
.hEdit
, WM_CUT
, 0, 0);
584 VOID
DIALOG_EditCopy(VOID
)
586 SendMessage(Globals
.hEdit
, WM_COPY
, 0, 0);
589 VOID
DIALOG_EditPaste(VOID
)
591 SendMessage(Globals
.hEdit
, WM_PASTE
, 0, 0);
594 VOID
DIALOG_EditDelete(VOID
)
596 SendMessage(Globals
.hEdit
, WM_CLEAR
, 0, 0);
599 VOID
DIALOG_EditSelectAll(VOID
)
601 SendMessage(Globals
.hEdit
, EM_SETSEL
, 0, (LPARAM
)-1);
604 VOID
DIALOG_EditTimeDate(VOID
)
607 WCHAR szDate
[MAX_STRING_LEN
];
608 static const WCHAR spaceW
[] = { ' ',0 };
612 GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &st
, NULL
, szDate
, MAX_STRING_LEN
);
613 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)szDate
);
615 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)spaceW
);
617 GetDateFormat(LOCALE_USER_DEFAULT
, DATE_LONGDATE
, &st
, NULL
, szDate
, MAX_STRING_LEN
);
618 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)szDate
);
621 VOID
DIALOG_EditWrap(VOID
)
623 static const WCHAR editW
[] = { 'e','d','i','t',0 };
629 Globals
.bWrapLongLines
= !Globals
.bWrapLongLines
;
631 size
= GetWindowTextLength(Globals
.hEdit
) + 1;
632 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
638 GetWindowText(Globals
.hEdit
, pTemp
, size
);
639 DestroyWindow(Globals
.hEdit
);
640 GetClientRect(Globals
.hMainWnd
, &rc
);
641 dwStyle
= Globals
.bWrapLongLines
? EDIT_STYLE_WRAP
: EDIT_STYLE
;
642 Globals
.hEdit
= CreateWindowEx(WS_EX_CLIENTEDGE
, editW
, NULL
, dwStyle
,
643 0, 0, rc
.right
, rc
.bottom
, Globals
.hMainWnd
,
644 NULL
, Globals
.hInstance
, NULL
);
645 SendMessage(Globals
.hEdit
, WM_SETFONT
, (WPARAM
)Globals
.hFont
, (LPARAM
)FALSE
);
646 SendMessage(Globals
.hEdit
, EM_LIMITTEXT
, 0, 0);
647 SetWindowTextW(Globals
.hEdit
, pTemp
);
648 SetFocus(Globals
.hEdit
);
649 HeapFree(GetProcessHeap(), 0, pTemp
);
652 VOID
DIALOG_SelectFont(VOID
)
655 LOGFONT lf
=Globals
.lfFont
;
657 ZeroMemory( &cf
, sizeof(cf
) );
658 cf
.lStructSize
=sizeof(cf
);
659 cf
.hwndOwner
=Globals
.hMainWnd
;
661 cf
.Flags
=CF_SCREENFONTS
;
663 if( ChooseFont(&cf
) )
665 HFONT currfont
=Globals
.hFont
;
667 Globals
.hFont
=CreateFontIndirect( &lf
);
669 SendMessage( Globals
.hEdit
, WM_SETFONT
, (WPARAM
)Globals
.hFont
, (LPARAM
)TRUE
);
671 DeleteObject( currfont
);
675 typedef HWND (STDCALL
*FINDPROC
)(LPFINDREPLACE lpfr
);
677 static VOID
DIALOG_SearchDialog(FINDPROC pfnProc
)
679 ZeroMemory(&Globals
.find
, sizeof(Globals
.find
));
680 Globals
.find
.lStructSize
= sizeof(Globals
.find
);
681 Globals
.find
.hwndOwner
= Globals
.hMainWnd
;
682 Globals
.find
.hInstance
= Globals
.hInstance
;
683 Globals
.find
.lpstrFindWhat
= Globals
.szFindText
;
684 Globals
.find
.wFindWhatLen
= SIZEOF(Globals
.szFindText
);
685 Globals
.find
.lpstrReplaceWith
= Globals
.szReplaceText
;
686 Globals
.find
.wReplaceWithLen
= SIZEOF(Globals
.szReplaceText
);
687 Globals
.find
.Flags
= FR_DOWN
;
689 /* We only need to create the modal FindReplace dialog which will */
690 /* notify us of incoming events using hMainWnd Window Messages */
692 Globals
.hFindReplaceDlg
= pfnProc(&Globals
.find
);
693 assert(Globals
.hFindReplaceDlg
!=0);
696 VOID
DIALOG_Search(VOID
)
698 DIALOG_SearchDialog(FindText
);
701 VOID
DIALOG_SearchNext(VOID
)
703 /* FIXME: Search Next */
707 VOID
DIALOG_Replace(VOID
)
709 DIALOG_SearchDialog(ReplaceText
);
712 static INT_PTR CALLBACK
DIALOG_GoTo_DialogProc(HWND hwndDialog
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
714 BOOL bResult
= FALSE
;
720 hTextBox
= GetDlgItem(hwndDialog
, ID_LINENUMBER
);
721 _sntprintf(szText
, sizeof(szText
) / sizeof(szText
[0]), _T("%d"), lParam
);
722 SetWindowText(hTextBox
, szText
);
725 if (HIWORD(wParam
) == BN_CLICKED
)
727 if (LOWORD(wParam
) == IDOK
)
729 hTextBox
= GetDlgItem(hwndDialog
, ID_LINENUMBER
);
730 GetWindowText(hTextBox
, szText
, sizeof(szText
) / sizeof(szText
[0]));
731 EndDialog(hwndDialog
, _ttoi(szText
));
734 else if (LOWORD(wParam
) == IDCANCEL
)
736 EndDialog(hwndDialog
, 0);
746 VOID
DIALOG_GoTo(VOID
)
751 DWORD dwStart
, dwEnd
;
753 nLength
= GetWindowTextLength(Globals
.hEdit
);
754 pszText
= (LPTSTR
) HeapAlloc(GetProcessHeap(), 0, (nLength
+ 1) * sizeof(*pszText
));
758 /* Retrieve current text */
759 GetWindowText(Globals
.hEdit
, pszText
, nLength
+ 1);
760 SendMessage(Globals
.hEdit
, EM_GETSEL
, (WPARAM
) &dwStart
, (LPARAM
) &dwEnd
);
763 for (i
= 0; pszText
[i
] && (i
< dwStart
); i
++)
765 if (pszText
[i
] == '\n')
769 nLine
= DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(DIALOG_GOTO
),
770 Globals
.hMainWnd
, DIALOG_GoTo_DialogProc
, nLine
);
774 for (i
= 0; pszText
[i
] && (nLine
> 1) && (i
< nLength
- 1); i
++)
776 if (pszText
[i
] == '\n')
779 SendMessage(Globals
.hEdit
, EM_SETSEL
, i
, i
);
780 SendMessage(Globals
.hEdit
, EM_SCROLLCARET
, 0, 0);
782 HeapFree(GetProcessHeap(), 0, pszText
);
785 VOID
DIALOG_HelpContents(VOID
)
787 WinHelp(Globals
.hMainWnd
, helpfileW
, HELP_INDEX
, 0);
790 VOID
DIALOG_HelpSearch(VOID
)
795 VOID
DIALOG_HelpHelp(VOID
)
797 WinHelp(Globals
.hMainWnd
, helpfileW
, HELP_HELPONHELP
, 0);
800 VOID
DIALOG_HelpLicense(VOID
)
802 WineLicense(Globals
.hMainWnd
);
805 VOID
DIALOG_HelpNoWarranty(VOID
)
807 WineWarranty(Globals
.hMainWnd
);
810 VOID
DIALOG_HelpAboutWine(VOID
)
812 static const WCHAR notepadW
[] = { 'N','o','t','e','p','a','d','\n',0 };
813 WCHAR szNotepad
[MAX_STRING_LEN
];
815 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szNotepad
, SIZEOF(szNotepad
));
816 ShellAbout(Globals
.hMainWnd
, szNotepad
, notepadW
, 0);
820 /***********************************************************************
822 * DIALOG_FilePageSetup
824 VOID
DIALOG_FilePageSetup(void)
826 DialogBox(Globals
.hInstance
, MAKEINTRESOURCE(DIALOG_PAGESETUP
),
827 Globals
.hMainWnd
, DIALOG_PAGESETUP_DlgProc
);
831 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
833 * DIALOG_PAGESETUP_DlgProc
836 static INT_PTR WINAPI
DIALOG_PAGESETUP_DlgProc(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
845 /* save user input and close dialog */
846 GetDlgItemText(hDlg
, 0x141, Globals
.szHeader
, SIZEOF(Globals
.szHeader
));
847 GetDlgItemText(hDlg
, 0x143, Globals
.szFooter
, SIZEOF(Globals
.szFooter
));
848 GetDlgItemText(hDlg
, 0x14A, Globals
.szMarginTop
, SIZEOF(Globals
.szMarginTop
));
849 GetDlgItemText(hDlg
, 0x150, Globals
.szMarginBottom
, SIZEOF(Globals
.szMarginBottom
));
850 GetDlgItemText(hDlg
, 0x147, Globals
.szMarginLeft
, SIZEOF(Globals
.szMarginLeft
));
851 GetDlgItemText(hDlg
, 0x14D, Globals
.szMarginRight
, SIZEOF(Globals
.szMarginRight
));
852 EndDialog(hDlg
, IDOK
);
856 /* discard user input and close dialog */
857 EndDialog(hDlg
, IDCANCEL
);
862 /* FIXME: Bring this to work */
863 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 };
864 static const WCHAR helpW
[] = { 'H','e','l','p',0 };
865 MessageBox(Globals
.hMainWnd
, sorryW
, helpW
, MB_ICONEXCLAMATION
);
875 /* fetch last user input prior to display dialog */
876 SetDlgItemText(hDlg
, 0x141, Globals
.szHeader
);
877 SetDlgItemText(hDlg
, 0x143, Globals
.szFooter
);
878 SetDlgItemText(hDlg
, 0x14A, Globals
.szMarginTop
);
879 SetDlgItemText(hDlg
, 0x150, Globals
.szMarginBottom
);
880 SetDlgItemText(hDlg
, 0x147, Globals
.szMarginLeft
);
881 SetDlgItemText(hDlg
, 0x14D, Globals
.szMarginRight
);