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 BOOL
HasFileExtension(LPCWSTR szFilename
)
146 s
= wcsrchr(szFilename
, '\\');
149 return wcsrchr(szFilename
, '.') != NULL
;
153 static VOID
DoSaveFile(VOID
)
159 hFile
= CreateFile(Globals
.szFileName
, GENERIC_WRITE
, FILE_SHARE_WRITE
,
160 NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
161 if(hFile
== INVALID_HANDLE_VALUE
)
167 size
= GetWindowTextLengthW(Globals
.hEdit
) + 1;
168 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(*pTemp
));
175 size
= GetWindowTextW(Globals
.hEdit
, pTemp
, size
);
177 if (!WriteText(hFile
, pTemp
, size
, Globals
.iEncoding
, Globals
.iEoln
))
180 SendMessage(Globals
.hEdit
, EM_SETMODIFY
, FALSE
, 0);
183 HeapFree(GetProcessHeap(), 0, pTemp
);
188 * TRUE - User agreed to close (both save/don't save)
189 * FALSE - User cancelled close by selecting "Cancel"
191 BOOL
DoCloseFile(void)
194 static const WCHAR empty_strW
[] = { 0 };
196 if (SendMessage(Globals
.hEdit
, EM_GETMODIFY
, 0, 0))
198 /* prompt user to save changes */
199 nResult
= AlertFileNotSaved(Globals
.szFileName
);
201 case IDYES
: DIALOG_FileSave();
206 case IDCANCEL
: return(FALSE
);
209 default: return(FALSE
);
214 SetFileName(empty_strW
);
216 UpdateWindowCaption();
221 void DoOpenFile(LPCWSTR szFileName
)
223 static const WCHAR dotlog
[] = { '.','L','O','G',0 };
229 /* Close any files and prompt to save changes */
233 hFile
= CreateFile(szFileName
, GENERIC_READ
, FILE_SHARE_READ
, NULL
,
234 OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
235 if (hFile
== INVALID_HANDLE_VALUE
)
241 if (!ReadText(hFile
, &pszText
, &dwTextLen
, &Globals
.iEncoding
, &Globals
.iEoln
))
247 SetWindowTextW(Globals
.hEdit
, pszText
);
249 SendMessage(Globals
.hEdit
, EM_SETMODIFY
, FALSE
, 0);
250 SendMessage(Globals
.hEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
251 SetFocus(Globals
.hEdit
);
253 /* If the file starts with .LOG, add a time/date at the end and set cursor after
254 * See http://support.microsoft.com/?kbid=260563
256 if (GetWindowTextW(Globals
.hEdit
, log
, sizeof(log
)/sizeof(log
[0])) && !lstrcmp(log
, dotlog
))
258 static const WCHAR lfW
[] = { '\r','\n',0 };
259 SendMessage(Globals
.hEdit
, EM_SETSEL
, GetWindowTextLength(Globals
.hEdit
), -1);
260 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)lfW
);
261 DIALOG_EditTimeDate();
262 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)lfW
);
265 SetFileName(szFileName
);
266 UpdateWindowCaption();
269 if (hFile
!= INVALID_HANDLE_VALUE
)
272 HeapFree(GetProcessHeap(), 0, pszText
);
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 SendMessage(Globals
.hEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
283 SetFocus(Globals
.hEdit
);
287 VOID
DIALOG_FileOpen(VOID
)
289 OPENFILENAME openfilename
;
290 WCHAR szDir
[MAX_PATH
];
291 WCHAR szPath
[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 if (Globals
.szFileName
[0] == 0)
299 lstrcpy(szPath
, txt_files
);
301 lstrcpy(szPath
, Globals
.szFileName
);
303 openfilename
.lStructSize
= sizeof(openfilename
);
304 openfilename
.hwndOwner
= Globals
.hMainWnd
;
305 openfilename
.hInstance
= Globals
.hInstance
;
306 openfilename
.lpstrFilter
= Globals
.szFilter
;
307 openfilename
.lpstrFile
= szPath
;
308 openfilename
.nMaxFile
= SIZEOF(szPath
);
309 openfilename
.lpstrInitialDir
= szDir
;
310 openfilename
.Flags
= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
|
312 openfilename
.lpstrDefExt
= szDefaultExt
;
315 if (GetOpenFileName(&openfilename
)) {
316 if (FileExists(openfilename
.lpstrFile
))
317 DoOpenFile(openfilename
.lpstrFile
);
319 AlertFileNotFound(openfilename
.lpstrFile
);
324 VOID
DIALOG_FileSave(VOID
)
326 if (Globals
.szFileName
[0] == '\0')
332 static UINT_PTR CALLBACK
DIALOG_FileSaveAs_Hook(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
341 hCombo
= GetDlgItem(hDlg
, ID_ENCODING
);
343 LoadString(Globals
.hInstance
, STRING_ANSI
, szText
, SIZEOF(szText
));
344 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
346 LoadString(Globals
.hInstance
, STRING_UNICODE
, szText
, SIZEOF(szText
));
347 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
349 LoadString(Globals
.hInstance
, STRING_UNICODE_BE
, szText
, SIZEOF(szText
));
350 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
352 LoadString(Globals
.hInstance
, STRING_UTF8
, szText
, SIZEOF(szText
));
353 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
355 SendMessage(hCombo
, CB_SETCURSEL
, Globals
.iEncoding
, 0);
357 hCombo
= GetDlgItem(hDlg
, ID_EOLN
);
359 LoadString(Globals
.hInstance
, STRING_CRLF
, szText
, SIZEOF(szText
));
360 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
362 LoadString(Globals
.hInstance
, STRING_LF
, szText
, SIZEOF(szText
));
363 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
365 LoadString(Globals
.hInstance
, STRING_CR
, szText
, SIZEOF(szText
));
366 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
368 SendMessage(hCombo
, CB_SETCURSEL
, Globals
.iEoln
, 0);
372 if (((NMHDR
*) lParam
)->code
== CDN_FILEOK
)
374 pNotify
= (OFNOTIFY
*) lParam
;
376 hCombo
= GetDlgItem(hDlg
, ID_ENCODING
);
378 Globals
.iEncoding
= SendMessage(hCombo
, CB_GETCURSEL
, 0, 0);
380 hCombo
= GetDlgItem(hDlg
, ID_EOLN
);
382 Globals
.iEoln
= SendMessage(hCombo
, CB_GETCURSEL
, 0, 0);
389 VOID
DIALOG_FileSaveAs(VOID
)
392 WCHAR szDir
[MAX_PATH
];
393 WCHAR szPath
[MAX_PATH
];
394 static const WCHAR szDefaultExt
[] = { 't','x','t',0 };
395 static const WCHAR txt_files
[] = { '*','.','t','x','t',0 };
397 ZeroMemory(&saveas
, sizeof(saveas
));
399 GetCurrentDirectory(SIZEOF(szDir
), szDir
);
400 if (Globals
.szFileName
[0] == 0)
401 lstrcpy(szPath
, txt_files
);
403 lstrcpy(szPath
, Globals
.szFileName
);
405 saveas
.lStructSize
= sizeof(OPENFILENAME
);
406 saveas
.hwndOwner
= Globals
.hMainWnd
;
407 saveas
.hInstance
= Globals
.hInstance
;
408 saveas
.lpstrFilter
= Globals
.szFilter
;
409 saveas
.lpstrFile
= szPath
;
410 saveas
.nMaxFile
= SIZEOF(szPath
);
411 saveas
.lpstrInitialDir
= szDir
;
412 saveas
.Flags
= OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
|
413 OFN_HIDEREADONLY
| OFN_EXPLORER
| OFN_ENABLETEMPLATE
| OFN_ENABLEHOOK
;
414 saveas
.lpstrDefExt
= szDefaultExt
;
415 saveas
.lpTemplateName
= MAKEINTRESOURCE(DIALOG_ENCODING
);
416 saveas
.lpfnHook
= DIALOG_FileSaveAs_Hook
;
418 if (GetSaveFileName(&saveas
)) {
420 UpdateWindowCaption();
425 VOID
DIALOG_FilePrint(VOID
)
430 int cWidthPels
, cHeightPels
, border
;
431 int xLeft
, yTop
, pagecount
, dopage
, copycount
;
434 HFONT font
, old_font
=0;
437 static const WCHAR times_new_romanW
[] = { 'T','i','m','e','s',' ','N','e','w',' ','R','o','m','a','n',0 };
439 /* Get a small font and print some header info on each page */
440 hdrFont
.lfHeight
= 100;
442 hdrFont
.lfEscapement
= 0;
443 hdrFont
.lfOrientation
= 0;
444 hdrFont
.lfWeight
= FW_BOLD
;
445 hdrFont
.lfItalic
= 0;
446 hdrFont
.lfUnderline
= 0;
447 hdrFont
.lfStrikeOut
= 0;
448 hdrFont
.lfCharSet
= ANSI_CHARSET
;
449 hdrFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
450 hdrFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
451 hdrFont
.lfQuality
= PROOF_QUALITY
;
452 hdrFont
.lfPitchAndFamily
= VARIABLE_PITCH
| FF_ROMAN
;
453 lstrcpy(hdrFont
.lfFaceName
, times_new_romanW
);
455 font
= CreateFontIndirect(&hdrFont
);
457 /* Get Current Settings */
458 ZeroMemory(&printer
, sizeof(printer
));
459 printer
.lStructSize
= sizeof(printer
);
460 printer
.hwndOwner
= Globals
.hMainWnd
;
461 printer
.hInstance
= Globals
.hInstance
;
463 /* Set some default flags */
464 printer
.Flags
= PD_RETURNDC
;
465 printer
.nFromPage
= 0;
466 printer
.nMinPage
= 1;
467 /* we really need to calculate number of pages to set nMaxPage and nToPage */
469 printer
.nMaxPage
= -1;
471 /* Let commdlg manage copy settings */
472 printer
.nCopies
= (WORD
)PD_USEDEVMODECOPIES
;
474 if (!PrintDlg(&printer
)) return;
476 assert(printer
.hDC
!= 0);
478 /* initialize DOCINFO */
479 di
.cbSize
= sizeof(DOCINFO
);
480 di
.lpszDocName
= Globals
.szFileTitle
;
481 di
.lpszOutput
= NULL
;
482 di
.lpszDatatype
= NULL
;
485 if (StartDoc(printer
.hDC
, &di
) <= 0) return;
487 /* Get the page dimensions in pixels. */
488 cWidthPels
= GetDeviceCaps(printer
.hDC
, HORZRES
);
489 cHeightPels
= GetDeviceCaps(printer
.hDC
, VERTRES
);
491 /* Get the file text */
492 size
= GetWindowTextLengthW(Globals
.hEdit
) + 1;
493 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
499 size
= GetWindowTextW(Globals
.hEdit
, pTemp
, size
);
502 for (copycount
=1; copycount
<= printer
.nCopies
; copycount
++) {
506 static const WCHAR letterM
[] = { 'M',0 };
508 if (pagecount
>= printer
.nFromPage
&&
509 /* ((printer.Flags & PD_PAGENUMS) == 0 || pagecount <= printer.nToPage))*/
510 pagecount
<= printer
.nToPage
)
515 old_font
= SelectObject(printer
.hDC
, font
);
516 GetTextExtentPoint32(printer
.hDC
, letterM
, 1, &szMetric
);
519 if (StartPage(printer
.hDC
) <= 0) {
520 static const WCHAR failedW
[] = { 'S','t','a','r','t','P','a','g','e',' ','f','a','i','l','e','d',0 };
521 static const WCHAR errorW
[] = { 'P','r','i','n','t',' ','E','r','r','o','r',0 };
522 MessageBox(Globals
.hMainWnd
, failedW
, errorW
, MB_ICONEXCLAMATION
);
525 /* Write a rectangle and header at the top of each page */
526 Rectangle(printer
.hDC
, border
, border
, cWidthPels
-border
, border
+szMetric
.cy
*2);
527 /* I don't know what's up with this TextOut command. This comes out
530 TextOut(printer
.hDC
, border
*2, border
+szMetric
.cy
/2, Globals
.szFileTitle
, lstrlen(Globals
.szFileTitle
));
533 /* The starting point for the main text */
535 yTop
= border
+szMetric
.cy
*4;
537 SelectObject(printer
.hDC
, old_font
);
538 GetTextExtentPoint32(printer
.hDC
, letterM
, 1, &szMetric
);
540 /* Since outputting strings is giving me problems, output the main
541 text one character at a time.
544 if (pTemp
[i
] == '\n') {
548 else if (pTemp
[i
] != '\r') {
550 TextOut(printer
.hDC
, xLeft
, yTop
, &pTemp
[i
], 1);
551 xLeft
+= szMetric
.cx
;
553 } while (i
++<size
&& yTop
<(cHeightPels
-border
*2));
556 EndPage(printer
.hDC
);
562 DeleteDC(printer
.hDC
);
563 HeapFree(GetProcessHeap(), 0, pTemp
);
566 VOID
DIALOG_FilePrinterSetup(VOID
)
570 ZeroMemory(&printer
, sizeof(printer
));
571 printer
.lStructSize
= sizeof(printer
);
572 printer
.hwndOwner
= Globals
.hMainWnd
;
573 printer
.hInstance
= Globals
.hInstance
;
574 printer
.Flags
= PD_PRINTSETUP
;
580 VOID
DIALOG_FileExit(VOID
)
582 PostMessage(Globals
.hMainWnd
, WM_CLOSE
, 0, 0l);
585 VOID
DIALOG_EditUndo(VOID
)
587 SendMessage(Globals
.hEdit
, EM_UNDO
, 0, 0);
590 VOID
DIALOG_EditCut(VOID
)
592 SendMessage(Globals
.hEdit
, WM_CUT
, 0, 0);
595 VOID
DIALOG_EditCopy(VOID
)
597 SendMessage(Globals
.hEdit
, WM_COPY
, 0, 0);
600 VOID
DIALOG_EditPaste(VOID
)
602 SendMessage(Globals
.hEdit
, WM_PASTE
, 0, 0);
605 VOID
DIALOG_EditDelete(VOID
)
607 SendMessage(Globals
.hEdit
, WM_CLEAR
, 0, 0);
610 VOID
DIALOG_EditSelectAll(VOID
)
612 SendMessage(Globals
.hEdit
, EM_SETSEL
, 0, (LPARAM
)-1);
615 VOID
DIALOG_EditTimeDate(VOID
)
618 WCHAR szDate
[MAX_STRING_LEN
];
619 static const WCHAR spaceW
[] = { ' ',0 };
623 GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &st
, NULL
, szDate
, MAX_STRING_LEN
);
624 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)szDate
);
626 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)spaceW
);
628 GetDateFormat(LOCALE_USER_DEFAULT
, DATE_LONGDATE
, &st
, NULL
, szDate
, MAX_STRING_LEN
);
629 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)szDate
);
632 VOID
DIALOG_EditWrap(VOID
)
634 static const WCHAR editW
[] = { 'e','d','i','t',0 };
640 Globals
.bWrapLongLines
= !Globals
.bWrapLongLines
;
642 size
= GetWindowTextLength(Globals
.hEdit
) + 1;
643 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
649 GetWindowText(Globals
.hEdit
, pTemp
, size
);
650 DestroyWindow(Globals
.hEdit
);
651 GetClientRect(Globals
.hMainWnd
, &rc
);
652 dwStyle
= Globals
.bWrapLongLines
? EDIT_STYLE_WRAP
: EDIT_STYLE
;
653 Globals
.hEdit
= CreateWindowEx(WS_EX_CLIENTEDGE
, editW
, NULL
, dwStyle
,
654 0, 0, rc
.right
, rc
.bottom
, Globals
.hMainWnd
,
655 NULL
, Globals
.hInstance
, NULL
);
656 SendMessage(Globals
.hEdit
, WM_SETFONT
, (WPARAM
)Globals
.hFont
, (LPARAM
)FALSE
);
657 SendMessage(Globals
.hEdit
, EM_LIMITTEXT
, 0, 0);
658 SetWindowTextW(Globals
.hEdit
, pTemp
);
659 SetFocus(Globals
.hEdit
);
660 HeapFree(GetProcessHeap(), 0, pTemp
);
663 VOID
DIALOG_SelectFont(VOID
)
666 LOGFONT lf
=Globals
.lfFont
;
668 ZeroMemory( &cf
, sizeof(cf
) );
669 cf
.lStructSize
=sizeof(cf
);
670 cf
.hwndOwner
=Globals
.hMainWnd
;
672 cf
.Flags
=CF_SCREENFONTS
;
674 if( ChooseFont(&cf
) )
676 HFONT currfont
=Globals
.hFont
;
678 Globals
.hFont
=CreateFontIndirect( &lf
);
680 SendMessage( Globals
.hEdit
, WM_SETFONT
, (WPARAM
)Globals
.hFont
, (LPARAM
)TRUE
);
682 DeleteObject( currfont
);
686 typedef HWND (WINAPI
*FINDPROC
)(LPFINDREPLACE lpfr
);
688 static VOID
DIALOG_SearchDialog(FINDPROC pfnProc
)
690 ZeroMemory(&Globals
.find
, sizeof(Globals
.find
));
691 Globals
.find
.lStructSize
= sizeof(Globals
.find
);
692 Globals
.find
.hwndOwner
= Globals
.hMainWnd
;
693 Globals
.find
.hInstance
= Globals
.hInstance
;
694 Globals
.find
.lpstrFindWhat
= Globals
.szFindText
;
695 Globals
.find
.wFindWhatLen
= SIZEOF(Globals
.szFindText
);
696 Globals
.find
.lpstrReplaceWith
= Globals
.szReplaceText
;
697 Globals
.find
.wReplaceWithLen
= SIZEOF(Globals
.szReplaceText
);
698 Globals
.find
.Flags
= FR_DOWN
;
700 /* We only need to create the modal FindReplace dialog which will */
701 /* notify us of incoming events using hMainWnd Window Messages */
703 Globals
.hFindReplaceDlg
= pfnProc(&Globals
.find
);
704 assert(Globals
.hFindReplaceDlg
!=0);
707 VOID
DIALOG_Search(VOID
)
709 DIALOG_SearchDialog(FindText
);
712 VOID
DIALOG_SearchNext(VOID
)
714 /* FIXME: Search Next */
718 VOID
DIALOG_Replace(VOID
)
720 DIALOG_SearchDialog(ReplaceText
);
723 static INT_PTR CALLBACK
DIALOG_GoTo_DialogProc(HWND hwndDialog
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
725 BOOL bResult
= FALSE
;
731 hTextBox
= GetDlgItem(hwndDialog
, ID_LINENUMBER
);
732 _sntprintf(szText
, sizeof(szText
) / sizeof(szText
[0]), _T("%d"), lParam
);
733 SetWindowText(hTextBox
, szText
);
736 if (HIWORD(wParam
) == BN_CLICKED
)
738 if (LOWORD(wParam
) == IDOK
)
740 hTextBox
= GetDlgItem(hwndDialog
, ID_LINENUMBER
);
741 GetWindowText(hTextBox
, szText
, sizeof(szText
) / sizeof(szText
[0]));
742 EndDialog(hwndDialog
, _ttoi(szText
));
745 else if (LOWORD(wParam
) == IDCANCEL
)
747 EndDialog(hwndDialog
, 0);
757 VOID
DIALOG_GoTo(VOID
)
762 DWORD dwStart
, dwEnd
;
764 nLength
= GetWindowTextLength(Globals
.hEdit
);
765 pszText
= (LPTSTR
) HeapAlloc(GetProcessHeap(), 0, (nLength
+ 1) * sizeof(*pszText
));
769 /* Retrieve current text */
770 GetWindowText(Globals
.hEdit
, pszText
, nLength
+ 1);
771 SendMessage(Globals
.hEdit
, EM_GETSEL
, (WPARAM
) &dwStart
, (LPARAM
) &dwEnd
);
774 for (i
= 0; pszText
[i
] && (i
< dwStart
); i
++)
776 if (pszText
[i
] == '\n')
780 nLine
= DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(DIALOG_GOTO
),
781 Globals
.hMainWnd
, DIALOG_GoTo_DialogProc
, nLine
);
785 for (i
= 0; pszText
[i
] && (nLine
> 1) && (i
< nLength
- 1); i
++)
787 if (pszText
[i
] == '\n')
790 SendMessage(Globals
.hEdit
, EM_SETSEL
, i
, i
);
791 SendMessage(Globals
.hEdit
, EM_SCROLLCARET
, 0, 0);
793 HeapFree(GetProcessHeap(), 0, pszText
);
796 VOID
DIALOG_HelpContents(VOID
)
798 WinHelp(Globals
.hMainWnd
, helpfileW
, HELP_INDEX
, 0);
801 VOID
DIALOG_HelpSearch(VOID
)
806 VOID
DIALOG_HelpHelp(VOID
)
808 WinHelp(Globals
.hMainWnd
, helpfileW
, HELP_HELPONHELP
, 0);
811 VOID
DIALOG_HelpLicense(VOID
)
813 WineLicense(Globals
.hMainWnd
);
816 VOID
DIALOG_HelpNoWarranty(VOID
)
818 WineWarranty(Globals
.hMainWnd
);
821 VOID
DIALOG_HelpAboutWine(VOID
)
823 static const WCHAR notepadW
[] = { 'N','o','t','e','p','a','d','\n',0 };
824 WCHAR szNotepad
[MAX_STRING_LEN
];
826 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szNotepad
, SIZEOF(szNotepad
));
827 ShellAbout(Globals
.hMainWnd
, szNotepad
, notepadW
, 0);
831 /***********************************************************************
833 * DIALOG_FilePageSetup
835 VOID
DIALOG_FilePageSetup(void)
837 DialogBox(Globals
.hInstance
, MAKEINTRESOURCE(DIALOG_PAGESETUP
),
838 Globals
.hMainWnd
, DIALOG_PAGESETUP_DlgProc
);
842 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
844 * DIALOG_PAGESETUP_DlgProc
847 static INT_PTR WINAPI
DIALOG_PAGESETUP_DlgProc(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
853 if (HIWORD(wParam
) == BN_CLICKED
)
855 switch (LOWORD(wParam
))
858 /* save user input and close dialog */
859 GetDlgItemText(hDlg
, 0x141, Globals
.szHeader
, SIZEOF(Globals
.szHeader
));
860 GetDlgItemText(hDlg
, 0x143, Globals
.szFooter
, SIZEOF(Globals
.szFooter
));
861 GetDlgItemText(hDlg
, 0x14A, Globals
.szMarginTop
, SIZEOF(Globals
.szMarginTop
));
862 GetDlgItemText(hDlg
, 0x150, Globals
.szMarginBottom
, SIZEOF(Globals
.szMarginBottom
));
863 GetDlgItemText(hDlg
, 0x147, Globals
.szMarginLeft
, SIZEOF(Globals
.szMarginLeft
));
864 GetDlgItemText(hDlg
, 0x14D, Globals
.szMarginRight
, SIZEOF(Globals
.szMarginRight
));
865 EndDialog(hDlg
, IDOK
);
869 /* discard user input and close dialog */
870 EndDialog(hDlg
, IDCANCEL
);
875 /* FIXME: Bring this to work */
876 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 };
877 static const WCHAR helpW
[] = { 'H','e','l','p',0 };
878 MessageBox(Globals
.hMainWnd
, sorryW
, helpW
, MB_ICONEXCLAMATION
);
889 /* fetch last user input prior to display dialog */
890 SetDlgItemText(hDlg
, 0x141, Globals
.szHeader
);
891 SetDlgItemText(hDlg
, 0x143, Globals
.szFooter
);
892 SetDlgItemText(hDlg
, 0x14A, Globals
.szMarginTop
);
893 SetDlgItemText(hDlg
, 0x150, Globals
.szMarginBottom
);
894 SetDlgItemText(hDlg
, 0x147, Globals
.szMarginLeft
);
895 SetDlgItemText(hDlg
, 0x14D, Globals
.szMarginRight
);