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
25 static const TCHAR helpfile
[] = _T("notepad.hlp");
26 static const TCHAR empty_str
[] = _T("");
27 static const TCHAR szDefaultExt
[] = _T("txt");
28 static const TCHAR txt_files
[] = _T("*.txt");
30 static INT_PTR WINAPI
DIALOG_PAGESETUP_DlgProc(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
33 static LPSTR
ConvertToASCII(LPSTR pszText
)
36 LPWSTR pszTextW
= (LPWSTR
)pszText
;
38 /* default return value */
41 /* query about requested size for conversion */
42 sz
= WideCharToMultiByte(CP_ACP
, 0, pszTextW
, -1, NULL
, 0, NULL
, NULL
);
46 /* get space for ASCII buffer */
47 pszText
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, sz
);
51 /* if previous diagnostic call worked fine,
52 * then this one will work too,
53 * so no need to test return value here
55 WideCharToMultiByte(CP_ACP
, 0, pszTextW
, -1, pszText
, sz
, NULL
, NULL
);
58 HeapFree(GetProcessHeap(), 0, pszTextW
);
62 static LPWSTR
ConvertToUNICODE(LPSTR pszText
, DWORD
*pdwSize
)
65 LPWSTR pszTextW
= NULL
;
68 /* query about requested size for conversion */
69 sz
= MultiByteToWideChar(CP_ACP
, 0, pszText
, -1, NULL
, 0);
73 /* get space for UNICODE buffer */
74 pszTextW
= HeapAlloc(GetProcessHeap(), 0, sz
*sizeof(WCHAR
));
78 /* if previous diagnostic call worked fine,
79 * then this one will work too,
80 * so no need to test return value here
82 MultiByteToWideChar(CP_ACP
, 0, pszText
, -1, pszTextW
, sz
);
84 /* report the new size of the text to the caller */
88 HeapFree(GetProcessHeap(), 0, pszText
);
93 VOID
ShowLastError(void)
95 DWORD error
= GetLastError();
96 if (error
!= NO_ERROR
)
98 LPTSTR lpMsgBuf
= NULL
;
99 TCHAR szTitle
[MAX_STRING_LEN
];
101 LoadString(Globals
.hInstance
, STRING_ERROR
, szTitle
, SIZEOF(szTitle
));
103 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
105 (LPTSTR
) &lpMsgBuf
, 0, NULL
);
106 MessageBox(NULL
, lpMsgBuf
, szTitle
, MB_OK
| MB_ICONERROR
);
112 * Sets the caption of the main window according to Globals.szFileTitle:
113 * Notepad - (untitled) if no file is open
114 * Notepad - [filename] if a file is given
116 static void UpdateWindowCaption(void)
118 TCHAR szCaption
[MAX_STRING_LEN
];
119 TCHAR szUntitled
[MAX_STRING_LEN
];
121 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szCaption
, SIZEOF(szCaption
));
123 if (Globals
.szFileTitle
[0] != '\0') {
124 static const TCHAR bracket_l
[] = _T(" - [");
125 static const TCHAR bracket_r
[] = _T("]");
126 _tcscat(szCaption
, bracket_l
);
127 _tcscat(szCaption
, Globals
.szFileTitle
);
128 _tcscat(szCaption
, bracket_r
);
132 static const TCHAR hyphen
[] = _T(" - ");
133 LoadString(Globals
.hInstance
, STRING_UNTITLED
, szUntitled
, SIZEOF(szUntitled
));
134 _tcscat(szCaption
, hyphen
);
135 _tcscat(szCaption
, szUntitled
);
138 SetWindowText(Globals
.hMainWnd
, szCaption
);
141 static void AlertFileNotFound(LPCTSTR szFileName
)
143 TCHAR szMessage
[MAX_STRING_LEN
];
144 TCHAR szResource
[MAX_STRING_LEN
];
146 /* Load and format szMessage */
147 LoadString(Globals
.hInstance
, STRING_NOTFOUND
, szResource
, SIZEOF(szResource
));
148 wsprintf(szMessage
, szResource
, szFileName
);
151 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szResource
, SIZEOF(szResource
));
153 /* Display Modal Dialog */
154 MessageBox(Globals
.hMainWnd
, szMessage
, szResource
, MB_ICONEXCLAMATION
);
157 static int AlertFileNotSaved(LPCTSTR szFileName
)
159 TCHAR szMessage
[MAX_STRING_LEN
];
160 TCHAR szResource
[MAX_STRING_LEN
];
161 TCHAR szUntitled
[MAX_STRING_LEN
];
163 LoadString(Globals
.hInstance
, STRING_UNTITLED
, szUntitled
, SIZEOF(szUntitled
));
165 /* Load and format Message */
166 LoadString(Globals
.hInstance
, STRING_NOTSAVED
, szResource
, SIZEOF(szResource
));
167 wsprintf(szMessage
, szResource
, szFileName
[0] ? szFileName
: szUntitled
);
170 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szResource
, SIZEOF(szResource
));
173 return MessageBox(Globals
.hMainWnd
, szMessage
, szResource
, MB_ICONEXCLAMATION
|MB_YESNOCANCEL
);
178 * TRUE - if file exists
179 * FALSE - if file does not exist
181 BOOL
FileExists(LPCTSTR szFilename
)
183 WIN32_FIND_DATA entry
;
186 hFile
= FindFirstFile(szFilename
, &entry
);
189 return (hFile
!= INVALID_HANDLE_VALUE
);
193 BOOL
HasFileExtension(LPCTSTR szFilename
)
197 s
= _tcsrchr(szFilename
, _T('\\'));
200 return _tcsrchr(szFilename
, _T('.')) != NULL
;
204 static VOID
DoSaveFile(VOID
)
210 hFile
= CreateFile(Globals
.szFileName
, GENERIC_WRITE
, FILE_SHARE_WRITE
,
211 NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
212 if(hFile
== INVALID_HANDLE_VALUE
)
218 size
= GetWindowTextLength(Globals
.hEdit
) + 1;
219 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(*pTemp
));
226 size
= GetWindowText(Globals
.hEdit
, pTemp
, size
);
229 pTemp
= (LPTSTR
)ConvertToUNICODE(pTemp
, &size
);
231 /* original "pTemp" already freed */
238 if (!WriteText(hFile
, (LPWSTR
)pTemp
, size
, Globals
.iEncoding
, Globals
.iEoln
))
241 SendMessage(Globals
.hEdit
, EM_SETMODIFY
, FALSE
, 0);
244 HeapFree(GetProcessHeap(), 0, pTemp
);
249 * TRUE - User agreed to close (both save/don't save)
250 * FALSE - User cancelled close by selecting "Cancel"
252 BOOL
DoCloseFile(void)
256 if (SendMessage(Globals
.hEdit
, EM_GETMODIFY
, 0, 0))
258 /* prompt user to save changes */
259 nResult
= AlertFileNotSaved(Globals
.szFileName
);
261 case IDYES
: DIALOG_FileSave();
266 case IDCANCEL
: return(FALSE
);
269 default: return(FALSE
);
274 SetFileName(empty_str
);
276 UpdateWindowCaption();
280 void DoOpenFile(LPCTSTR szFileName
)
282 static const TCHAR dotlog
[] = _T(".LOG");
288 /* Close any files and prompt to save changes */
292 hFile
= CreateFile(szFileName
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
293 OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
294 if (hFile
== INVALID_HANDLE_VALUE
)
300 if (!ReadText(hFile
, (LPWSTR
*)&pszText
, &dwTextLen
, &Globals
.iEncoding
, &Globals
.iEoln
))
306 pszText
= ConvertToASCII(pszText
);
307 if (pszText
== NULL
) {
312 SetWindowText(Globals
.hEdit
, pszText
);
314 SendMessage(Globals
.hEdit
, EM_SETMODIFY
, FALSE
, 0);
315 SendMessage(Globals
.hEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
316 SetFocus(Globals
.hEdit
);
318 /* If the file starts with .LOG, add a time/date at the end and set cursor after
319 * See http://support.microsoft.com/?kbid=260563
321 if (GetWindowText(Globals
.hEdit
, log
, SIZEOF(log
)) && !_tcscmp(log
, dotlog
))
323 static const TCHAR lf
[] = _T("\r\n");
324 SendMessage(Globals
.hEdit
, EM_SETSEL
, GetWindowTextLength(Globals
.hEdit
), -1);
325 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)lf
);
326 DIALOG_EditTimeDate();
327 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)lf
);
330 SetFileName(szFileName
);
331 UpdateWindowCaption();
332 NOTEPAD_EnableSearchMenu();
334 if (hFile
!= INVALID_HANDLE_VALUE
)
337 HeapFree(GetProcessHeap(), 0, pszText
);
340 VOID
DIALOG_FileNew(VOID
)
342 /* Close any files and prompt to save changes */
344 SetWindowText(Globals
.hEdit
, empty_str
);
345 SendMessage(Globals
.hEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
346 SetFocus(Globals
.hEdit
);
347 NOTEPAD_EnableSearchMenu();
351 VOID
DIALOG_FileOpen(VOID
)
353 OPENFILENAME openfilename
;
354 TCHAR szDir
[MAX_PATH
];
355 TCHAR szPath
[MAX_PATH
];
357 ZeroMemory(&openfilename
, sizeof(openfilename
));
359 GetCurrentDirectory(SIZEOF(szDir
), szDir
);
360 if (Globals
.szFileName
[0] == 0)
361 _tcscpy(szPath
, txt_files
);
363 _tcscpy(szPath
, Globals
.szFileName
);
365 openfilename
.lStructSize
= sizeof(openfilename
);
366 openfilename
.hwndOwner
= Globals
.hMainWnd
;
367 openfilename
.hInstance
= Globals
.hInstance
;
368 openfilename
.lpstrFilter
= Globals
.szFilter
;
369 openfilename
.lpstrFile
= szPath
;
370 openfilename
.nMaxFile
= SIZEOF(szPath
);
371 openfilename
.lpstrInitialDir
= szDir
;
372 openfilename
.Flags
= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
|
374 openfilename
.lpstrDefExt
= szDefaultExt
;
377 if (GetOpenFileName(&openfilename
)) {
378 if (FileExists(openfilename
.lpstrFile
))
379 DoOpenFile(openfilename
.lpstrFile
);
381 AlertFileNotFound(openfilename
.lpstrFile
);
386 VOID
DIALOG_FileSave(VOID
)
388 if (Globals
.szFileName
[0] == '\0')
394 static UINT_PTR CALLBACK
DIALOG_FileSaveAs_Hook(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
400 UNREFERENCED_PARAMETER(wParam
);
405 hCombo
= GetDlgItem(hDlg
, ID_ENCODING
);
407 LoadString(Globals
.hInstance
, STRING_ANSI
, szText
, SIZEOF(szText
));
408 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
410 LoadString(Globals
.hInstance
, STRING_UNICODE
, szText
, SIZEOF(szText
));
411 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
413 LoadString(Globals
.hInstance
, STRING_UNICODE_BE
, szText
, SIZEOF(szText
));
414 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
416 LoadString(Globals
.hInstance
, STRING_UTF8
, szText
, SIZEOF(szText
));
417 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
419 SendMessage(hCombo
, CB_SETCURSEL
, Globals
.iEncoding
, 0);
421 hCombo
= GetDlgItem(hDlg
, ID_EOLN
);
423 LoadString(Globals
.hInstance
, STRING_CRLF
, szText
, SIZEOF(szText
));
424 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
426 LoadString(Globals
.hInstance
, STRING_LF
, szText
, SIZEOF(szText
));
427 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
429 LoadString(Globals
.hInstance
, STRING_CR
, szText
, SIZEOF(szText
));
430 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
432 SendMessage(hCombo
, CB_SETCURSEL
, Globals
.iEoln
, 0);
436 if (((NMHDR
*) lParam
)->code
== CDN_FILEOK
)
438 pNotify
= (OFNOTIFY
*) lParam
;
440 hCombo
= GetDlgItem(hDlg
, ID_ENCODING
);
442 Globals
.iEncoding
= (int) SendMessage(hCombo
, CB_GETCURSEL
, 0, 0);
444 hCombo
= GetDlgItem(hDlg
, ID_EOLN
);
446 Globals
.iEoln
= (int) SendMessage(hCombo
, CB_GETCURSEL
, 0, 0);
453 VOID
DIALOG_FileSaveAs(VOID
)
456 TCHAR szDir
[MAX_PATH
];
457 TCHAR szPath
[MAX_PATH
];
459 ZeroMemory(&saveas
, sizeof(saveas
));
461 GetCurrentDirectory(SIZEOF(szDir
), szDir
);
462 if (Globals
.szFileName
[0] == 0)
463 _tcscpy(szPath
, txt_files
);
465 _tcscpy(szPath
, Globals
.szFileName
);
467 saveas
.lStructSize
= sizeof(OPENFILENAME
);
468 saveas
.hwndOwner
= Globals
.hMainWnd
;
469 saveas
.hInstance
= Globals
.hInstance
;
470 saveas
.lpstrFilter
= Globals
.szFilter
;
471 saveas
.lpstrFile
= szPath
;
472 saveas
.nMaxFile
= SIZEOF(szPath
);
473 saveas
.lpstrInitialDir
= szDir
;
474 saveas
.Flags
= OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
|
475 OFN_HIDEREADONLY
| OFN_EXPLORER
| OFN_ENABLETEMPLATE
| OFN_ENABLEHOOK
;
476 saveas
.lpstrDefExt
= szDefaultExt
;
477 saveas
.lpTemplateName
= MAKEINTRESOURCE(DIALOG_ENCODING
);
478 saveas
.lpfnHook
= (LPOFNHOOKPROC
)DIALOG_FileSaveAs_Hook
;
480 if (GetSaveFileName(&saveas
)) {
482 UpdateWindowCaption();
487 VOID
DIALOG_FilePrint(VOID
)
492 int cWidthPels
, cHeightPels
, border
;
493 int xLeft
, yTop
, pagecount
, dopage
, copycount
;
496 HFONT font
, old_font
=0;
499 static const TCHAR times_new_roman
[] = _T("Times New Roman");
501 /* Get a small font and print some header info on each page */
502 ZeroMemory(&hdrFont
, sizeof(hdrFont
));
503 hdrFont
.lfHeight
= 100;
504 hdrFont
.lfWeight
= FW_BOLD
;
505 hdrFont
.lfCharSet
= ANSI_CHARSET
;
506 hdrFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
507 hdrFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
508 hdrFont
.lfQuality
= PROOF_QUALITY
;
509 hdrFont
.lfPitchAndFamily
= VARIABLE_PITCH
| FF_ROMAN
;
510 _tcscpy(hdrFont
.lfFaceName
, times_new_roman
);
512 font
= CreateFontIndirect(&hdrFont
);
514 /* Get Current Settings */
515 ZeroMemory(&printer
, sizeof(printer
));
516 printer
.lStructSize
= sizeof(printer
);
517 printer
.hwndOwner
= Globals
.hMainWnd
;
518 printer
.hInstance
= Globals
.hInstance
;
520 /* Set some default flags */
521 printer
.Flags
= PD_RETURNDC
;
522 printer
.nFromPage
= 0;
523 printer
.nMinPage
= 1;
524 /* we really need to calculate number of pages to set nMaxPage and nToPage */
526 printer
.nMaxPage
= (WORD
) -1;
528 /* Let commdlg manage copy settings */
529 printer
.nCopies
= (WORD
)PD_USEDEVMODECOPIES
;
531 if (!PrintDlg(&printer
)) return;
533 assert(printer
.hDC
!= 0);
535 /* initialize DOCINFO */
536 di
.cbSize
= sizeof(DOCINFO
);
537 di
.lpszDocName
= Globals
.szFileTitle
;
538 di
.lpszOutput
= NULL
;
539 di
.lpszDatatype
= NULL
;
542 if (StartDoc(printer
.hDC
, &di
) <= 0) return;
544 /* Get the page dimensions in pixels. */
545 cWidthPels
= GetDeviceCaps(printer
.hDC
, HORZRES
);
546 cHeightPels
= GetDeviceCaps(printer
.hDC
, VERTRES
);
548 /* Get the file text */
549 size
= GetWindowTextLength(Globals
.hEdit
) + 1;
550 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(TCHAR
));
556 size
= GetWindowText(Globals
.hEdit
, pTemp
, size
);
559 for (copycount
=1; copycount
<= printer
.nCopies
; copycount
++) {
563 static const TCHAR letterM
[] = _T("M");
565 if (pagecount
>= printer
.nFromPage
&&
566 /* ((printer.Flags & PD_PAGENUMS) == 0 || pagecount <= printer.nToPage))*/
567 pagecount
<= printer
.nToPage
)
572 old_font
= SelectObject(printer
.hDC
, font
);
573 GetTextExtentPoint32(printer
.hDC
, letterM
, 1, &szMetric
);
576 if (StartPage(printer
.hDC
) <= 0) {
577 static const TCHAR failed
[] = _T("StartPage failed");
578 static const TCHAR error
[] = _T("Print Error");
579 MessageBox(Globals
.hMainWnd
, failed
, error
, MB_ICONEXCLAMATION
);
582 /* Write a rectangle and header at the top of each page */
583 Rectangle(printer
.hDC
, border
, border
, cWidthPels
-border
, border
+szMetric
.cy
*2);
584 /* I don't know what's up with this TextOut command. This comes out
587 TextOut(printer
.hDC
, border
*2, border
+szMetric
.cy
/2, Globals
.szFileTitle
, lstrlen(Globals
.szFileTitle
));
590 /* The starting point for the main text */
592 yTop
= border
+szMetric
.cy
*4;
594 SelectObject(printer
.hDC
, old_font
);
595 GetTextExtentPoint32(printer
.hDC
, letterM
, 1, &szMetric
);
597 /* Since outputting strings is giving me problems, output the main
598 text one character at a time.
601 if (pTemp
[i
] == '\n') {
605 else if (pTemp
[i
] != '\r') {
607 TextOut(printer
.hDC
, xLeft
, yTop
, &pTemp
[i
], 1);
608 xLeft
+= szMetric
.cx
;
610 } while (i
++<size
&& yTop
<(cHeightPels
-border
*2));
613 EndPage(printer
.hDC
);
619 DeleteDC(printer
.hDC
);
620 HeapFree(GetProcessHeap(), 0, pTemp
);
623 VOID
DIALOG_FilePrinterSetup(VOID
)
627 ZeroMemory(&printer
, sizeof(printer
));
628 printer
.lStructSize
= sizeof(printer
);
629 printer
.hwndOwner
= Globals
.hMainWnd
;
630 printer
.hInstance
= Globals
.hInstance
;
631 printer
.Flags
= PD_PRINTSETUP
;
637 VOID
DIALOG_FileExit(VOID
)
639 PostMessage(Globals
.hMainWnd
, WM_CLOSE
, 0, 0l);
642 VOID
DIALOG_EditUndo(VOID
)
644 SendMessage(Globals
.hEdit
, EM_UNDO
, 0, 0);
647 VOID
DIALOG_EditCut(VOID
)
649 SendMessage(Globals
.hEdit
, WM_CUT
, 0, 0);
652 VOID
DIALOG_EditCopy(VOID
)
654 SendMessage(Globals
.hEdit
, WM_COPY
, 0, 0);
657 VOID
DIALOG_EditPaste(VOID
)
659 SendMessage(Globals
.hEdit
, WM_PASTE
, 0, 0);
662 VOID
DIALOG_EditDelete(VOID
)
664 SendMessage(Globals
.hEdit
, WM_CLEAR
, 0, 0);
667 VOID
DIALOG_EditSelectAll(VOID
)
669 SendMessage(Globals
.hEdit
, EM_SETSEL
, 0, (LPARAM
)-1);
672 VOID
DIALOG_EditTimeDate(VOID
)
675 TCHAR szDate
[MAX_STRING_LEN
];
676 static const TCHAR space
[] = _T(" ");
680 GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &st
, NULL
, szDate
, MAX_STRING_LEN
);
681 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)szDate
);
683 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)space
);
685 GetDateFormat(LOCALE_USER_DEFAULT
, DATE_LONGDATE
, &st
, NULL
, szDate
, MAX_STRING_LEN
);
686 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)szDate
);
689 VOID
DIALOG_EditWrap(VOID
)
691 static const TCHAR edit
[] = _T("edit");
697 Globals
.bWrapLongLines
= !Globals
.bWrapLongLines
;
699 size
= GetWindowTextLength(Globals
.hEdit
) + 1;
700 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(WCHAR
));
706 GetWindowText(Globals
.hEdit
, pTemp
, size
);
707 DestroyWindow(Globals
.hEdit
);
708 GetClientRect(Globals
.hMainWnd
, &rc
);
709 dwStyle
= Globals
.bWrapLongLines
? EDIT_STYLE_WRAP
: EDIT_STYLE
;
710 EnableMenuItem(GetMenu(Globals
.hMainWnd
), CMD_STATUSBAR
,
711 MF_BYCOMMAND
| (Globals
.bWrapLongLines
? MF_DISABLED
| MF_GRAYED
: MF_ENABLED
));
712 if ( Globals
.hStatusBar
)
714 if ( Globals
.bWrapLongLines
)
715 ShowWindow(Globals
.hStatusBar
, SW_HIDE
);
716 else if ( Globals
.bShowStatusBar
)
718 GetClientRect(Globals
.hStatusBar
, &rcstatus
);
719 rc
.bottom
-= (rcstatus
.bottom
- rcstatus
.top
);
720 ShowWindow(Globals
.hStatusBar
, SW_SHOW
);
723 Globals
.hEdit
= CreateWindowEx(WS_EX_CLIENTEDGE
, edit
, NULL
, dwStyle
,
724 0, 0, rc
.right
, rc
.bottom
, Globals
.hMainWnd
,
725 NULL
, Globals
.hInstance
, NULL
);
726 SendMessage(Globals
.hEdit
, WM_SETFONT
, (WPARAM
)Globals
.hFont
, (LPARAM
)FALSE
);
727 SendMessage(Globals
.hEdit
, EM_LIMITTEXT
, 0, 0);
728 SetWindowText(Globals
.hEdit
, pTemp
);
729 SetFocus(Globals
.hEdit
);
730 HeapFree(GetProcessHeap(), 0, pTemp
);
731 DrawMenuBar(Globals
.hMainWnd
);
734 VOID
DIALOG_SelectFont(VOID
)
737 LOGFONT lf
=Globals
.lfFont
;
739 ZeroMemory( &cf
, sizeof(cf
) );
740 cf
.lStructSize
=sizeof(cf
);
741 cf
.hwndOwner
=Globals
.hMainWnd
;
743 cf
.Flags
=CF_SCREENFONTS
| CF_INITTOLOGFONTSTRUCT
;
745 if( ChooseFont(&cf
) )
747 HFONT currfont
=Globals
.hFont
;
749 Globals
.hFont
=CreateFontIndirect( &lf
);
751 SendMessage( Globals
.hEdit
, WM_SETFONT
, (WPARAM
)Globals
.hFont
, (LPARAM
)TRUE
);
753 DeleteObject( currfont
);
757 typedef HWND (WINAPI
*FINDPROC
)(LPFINDREPLACE lpfr
);
759 static VOID
DIALOG_SearchDialog(FINDPROC pfnProc
)
761 ZeroMemory(&Globals
.find
, sizeof(Globals
.find
));
762 Globals
.find
.lStructSize
= sizeof(Globals
.find
);
763 Globals
.find
.hwndOwner
= Globals
.hMainWnd
;
764 Globals
.find
.hInstance
= Globals
.hInstance
;
765 Globals
.find
.lpstrFindWhat
= Globals
.szFindText
;
766 Globals
.find
.wFindWhatLen
= SIZEOF(Globals
.szFindText
);
767 Globals
.find
.lpstrReplaceWith
= Globals
.szReplaceText
;
768 Globals
.find
.wReplaceWithLen
= SIZEOF(Globals
.szReplaceText
);
769 Globals
.find
.Flags
= FR_DOWN
;
771 /* We only need to create the modal FindReplace dialog which will */
772 /* notify us of incoming events using hMainWnd Window Messages */
774 Globals
.hFindReplaceDlg
= pfnProc(&Globals
.find
);
775 assert(Globals
.hFindReplaceDlg
!=0);
778 VOID
DIALOG_Search(VOID
)
780 DIALOG_SearchDialog(FindText
);
783 VOID
DIALOG_SearchNext(VOID
)
785 if (Globals
.find
.lpstrFindWhat
!= NULL
)
786 NOTEPAD_FindNext(&Globals
.find
, FALSE
, TRUE
);
791 VOID
DIALOG_Replace(VOID
)
793 DIALOG_SearchDialog(ReplaceText
);
796 static INT_PTR CALLBACK
DIALOG_GoTo_DialogProc(HWND hwndDialog
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
798 BOOL bResult
= FALSE
;
804 hTextBox
= GetDlgItem(hwndDialog
, ID_LINENUMBER
);
805 _sntprintf(szText
, SIZEOF(szText
), _T("%d"), lParam
);
806 SetWindowText(hTextBox
, szText
);
809 if (HIWORD(wParam
) == BN_CLICKED
)
811 if (LOWORD(wParam
) == IDOK
)
813 hTextBox
= GetDlgItem(hwndDialog
, ID_LINENUMBER
);
814 GetWindowText(hTextBox
, szText
, SIZEOF(szText
));
815 EndDialog(hwndDialog
, _ttoi(szText
));
818 else if (LOWORD(wParam
) == IDCANCEL
)
820 EndDialog(hwndDialog
, 0);
830 VOID
DIALOG_GoTo(VOID
)
835 DWORD dwStart
, dwEnd
;
837 nLength
= GetWindowTextLength(Globals
.hEdit
);
838 pszText
= (LPTSTR
) HeapAlloc(GetProcessHeap(), 0, (nLength
+ 1) * sizeof(*pszText
));
842 /* Retrieve current text */
843 GetWindowText(Globals
.hEdit
, pszText
, nLength
+ 1);
844 SendMessage(Globals
.hEdit
, EM_GETSEL
, (WPARAM
) &dwStart
, (LPARAM
) &dwEnd
);
847 for (i
= 0; pszText
[i
] && (i
< (int) dwStart
); i
++)
849 if (pszText
[i
] == '\n')
853 nLine
= DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(DIALOG_GOTO
),
854 Globals
.hMainWnd
, DIALOG_GoTo_DialogProc
, nLine
);
858 for (i
= 0; pszText
[i
] && (nLine
> 1) && (i
< nLength
- 1); i
++)
860 if (pszText
[i
] == '\n')
863 SendMessage(Globals
.hEdit
, EM_SETSEL
, i
, i
);
864 SendMessage(Globals
.hEdit
, EM_SCROLLCARET
, 0, 0);
866 HeapFree(GetProcessHeap(), 0, pszText
);
869 VOID
DIALOG_StatusBarUpdateCaretPos(VOID
)
875 TCHAR buff
[MAX_PATH
];
878 line
= (int) SendMessage(Globals
.hEdit
, EM_LINEFROMCHAR
, (WPARAM
)-1, (LPARAM
)0);
879 ccol
= (int) SendMessage(Globals
.hEdit
, EM_CHARFROMPOS
, (WPARAM
)0, (LPARAM
)MAKELPARAM(point
.x
, point
.y
));
881 col
= ccol
- (int) SendMessage(Globals
.hEdit
, EM_LINEINDEX
, (WPARAM
)line
, (LPARAM
)0);
883 _stprintf(buff
, TEXT("%S %d, %S %d"), Globals
.szStatusBarLine
, line
+1, Globals
.szStatusBarCol
, col
+1);
884 SendMessage(Globals
.hStatusBar
, SB_SETTEXT
, (WPARAM
) SB_SIMPLEID
, (LPARAM
)buff
);
887 VOID
DIALOG_ViewStatusBar(VOID
)
892 Globals
.bShowStatusBar
= !Globals
.bShowStatusBar
;
893 if ( !Globals
.hStatusBar
)
895 Globals
.hStatusBar
= CreateStatusWindow(WS_CHILD
| WS_VISIBLE
| WS_EX_STATICEDGE
, TEXT("test"), Globals
.hMainWnd
, CMD_STATUSBAR_WND_ID
);
896 LoadString(Globals
.hInstance
, STRING_LINE
, Globals
.szStatusBarLine
, MAX_PATH
-1);
897 LoadString(Globals
.hInstance
, STRING_COLUMN
, Globals
.szStatusBarCol
, MAX_PATH
-1);
898 SendMessage(Globals
.hStatusBar
, SB_SIMPLE
, (WPARAM
)TRUE
, (LPARAM
)0);
900 CheckMenuItem(GetMenu(Globals
.hMainWnd
), CMD_STATUSBAR
,
901 MF_BYCOMMAND
| (Globals
.bShowStatusBar
? MF_CHECKED
: MF_UNCHECKED
));
902 DrawMenuBar(Globals
.hMainWnd
);
903 GetClientRect(Globals
.hMainWnd
, &rc
);
904 GetClientRect(Globals
.hStatusBar
, &rcstatus
);
905 if ( Globals
.bShowStatusBar
)
906 rc
.bottom
-= (rcstatus
.bottom
- rcstatus
.top
);
908 MoveWindow(Globals
.hEdit
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, TRUE
);
909 ShowWindow(Globals
.hStatusBar
, Globals
.bShowStatusBar
);
910 DIALOG_StatusBarUpdateCaretPos();
913 VOID
DIALOG_HelpContents(VOID
)
915 WinHelp(Globals
.hMainWnd
, helpfile
, HELP_INDEX
, 0);
918 VOID
DIALOG_HelpSearch(VOID
)
923 VOID
DIALOG_HelpHelp(VOID
)
925 WinHelp(Globals
.hMainWnd
, helpfile
, HELP_HELPONHELP
, 0);
929 #pragma warning(disable : 4100)
932 AboutDialogProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
934 HWND hLicenseEditWnd
;
941 hLicenseEditWnd
= GetDlgItem(hDlg
, IDC_LICENSE
);
943 /* 0x1000 should be enought */
944 strLicense
= (TCHAR
*)_alloca(0x1000);
945 LoadString(GetModuleHandle(NULL
), STRING_LICENSE
, strLicense
, 0x1000);
947 SetWindowText(hLicenseEditWnd
, strLicense
);
953 if ((LOWORD(wParam
) == IDOK
) || (LOWORD(wParam
) == IDCANCEL
))
955 EndDialog(hDlg
, LOWORD(wParam
));
967 VOID
DIALOG_HelpAboutWine(VOID
)
969 static const TCHAR notepad
[] = _T("Notepad\n");
970 TCHAR szNotepad
[MAX_STRING_LEN
];
972 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szNotepad
, SIZEOF(szNotepad
));
973 ShellAbout(Globals
.hMainWnd
, szNotepad
, notepad
, 0);
977 /***********************************************************************
979 * DIALOG_FilePageSetup
981 VOID
DIALOG_FilePageSetup(void)
983 DialogBox(Globals
.hInstance
, MAKEINTRESOURCE(DIALOG_PAGESETUP
),
984 Globals
.hMainWnd
, DIALOG_PAGESETUP_DlgProc
);
988 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
990 * DIALOG_PAGESETUP_DlgProc
993 static INT_PTR WINAPI
DIALOG_PAGESETUP_DlgProc(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
999 if (HIWORD(wParam
) == BN_CLICKED
)
1001 switch (LOWORD(wParam
))
1004 /* save user input and close dialog */
1005 GetDlgItemText(hDlg
, 0x141, Globals
.szHeader
, SIZEOF(Globals
.szHeader
));
1006 GetDlgItemText(hDlg
, 0x143, Globals
.szFooter
, SIZEOF(Globals
.szFooter
));
1007 GetDlgItemText(hDlg
, 0x14A, Globals
.szMarginTop
, SIZEOF(Globals
.szMarginTop
));
1008 GetDlgItemText(hDlg
, 0x150, Globals
.szMarginBottom
, SIZEOF(Globals
.szMarginBottom
));
1009 GetDlgItemText(hDlg
, 0x147, Globals
.szMarginLeft
, SIZEOF(Globals
.szMarginLeft
));
1010 GetDlgItemText(hDlg
, 0x14D, Globals
.szMarginRight
, SIZEOF(Globals
.szMarginRight
));
1011 EndDialog(hDlg
, IDOK
);
1015 /* discard user input and close dialog */
1016 EndDialog(hDlg
, IDCANCEL
);
1021 /* FIXME: Bring this to work */
1022 static const TCHAR sorry
[] = _T("Sorry, no help available");
1023 static const TCHAR help
[] = _T("Help");
1024 MessageBox(Globals
.hMainWnd
, sorry
, help
, MB_ICONEXCLAMATION
);
1035 /* fetch last user input prior to display dialog */
1036 SetDlgItemText(hDlg
, 0x141, Globals
.szHeader
);
1037 SetDlgItemText(hDlg
, 0x143, Globals
.szFooter
);
1038 SetDlgItemText(hDlg
, 0x14A, Globals
.szMarginTop
);
1039 SetDlgItemText(hDlg
, 0x150, Globals
.szMarginBottom
);
1040 SetDlgItemText(hDlg
, 0x147, Globals
.szMarginLeft
);
1041 SetDlgItemText(hDlg
, 0x14D, Globals
.szMarginRight
);