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 Street, Fifth Floor, Boston, MA 02110-1301 USA
25 LRESULT CALLBACK
EDIT_WndProc(HWND hWnd
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
27 static const TCHAR helpfile
[] = _T("notepad.hlp");
28 static const TCHAR empty_str
[] = _T("");
29 static const TCHAR szDefaultExt
[] = _T("txt");
30 static const TCHAR txt_files
[] = _T("*.txt");
32 static INT_PTR WINAPI
DIALOG_PAGESETUP_DlgProc(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
);
35 static LPSTR
ConvertToASCII(LPSTR pszText
)
38 LPWSTR pszTextW
= (LPWSTR
)pszText
;
40 /* default return value */
43 /* query about requested size for conversion */
44 sz
= WideCharToMultiByte(CP_ACP
, 0, pszTextW
, -1, NULL
, 0, NULL
, NULL
);
48 /* get space for ASCII buffer */
49 pszText
= (LPSTR
)HeapAlloc(GetProcessHeap(), 0, sz
);
53 /* if previous diagnostic call worked fine,
54 * then this one will work too,
55 * so no need to test return value here
57 WideCharToMultiByte(CP_ACP
, 0, pszTextW
, -1, pszText
, sz
, NULL
, NULL
);
60 HeapFree(GetProcessHeap(), 0, pszTextW
);
64 static LPWSTR
ConvertToUNICODE(LPSTR pszText
, DWORD
*pdwSize
)
67 LPWSTR pszTextW
= NULL
;
70 /* query about requested size for conversion */
71 sz
= MultiByteToWideChar(CP_ACP
, 0, pszText
, -1, NULL
, 0);
75 /* get space for UNICODE buffer */
76 pszTextW
= HeapAlloc(GetProcessHeap(), 0, sz
*sizeof(WCHAR
));
80 /* if previous diagnostic call worked fine,
81 * then this one will work too,
82 * so no need to test return value here
84 MultiByteToWideChar(CP_ACP
, 0, pszText
, -1, pszTextW
, sz
);
86 /* report the new size of the text to the caller */
90 HeapFree(GetProcessHeap(), 0, pszText
);
95 VOID
ShowLastError(VOID
)
97 DWORD error
= GetLastError();
98 if (error
!= NO_ERROR
)
100 LPTSTR lpMsgBuf
= NULL
;
101 TCHAR szTitle
[MAX_STRING_LEN
];
103 LoadString(Globals
.hInstance
, STRING_ERROR
, szTitle
, SIZEOF(szTitle
));
105 FORMAT_MESSAGE_ALLOCATE_BUFFER
| FORMAT_MESSAGE_FROM_SYSTEM
,
107 (LPTSTR
) &lpMsgBuf
, 0, NULL
);
108 MessageBox(NULL
, lpMsgBuf
, szTitle
, MB_OK
| MB_ICONERROR
);
114 * Sets the caption of the main window according to Globals.szFileTitle:
115 * (untitled) - Notepad if no file is open
116 * [filename] - Notepad if a file is given
118 static void UpdateWindowCaption(void)
120 TCHAR szCaption
[MAX_STRING_LEN
];
121 TCHAR szNotepad
[MAX_STRING_LEN
];
123 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szNotepad
, SIZEOF(szNotepad
));
125 if (Globals
.szFileTitle
[0] != 0)
127 StringCchCopy(szCaption
, SIZEOF(szCaption
), Globals
.szFileTitle
);
131 LoadString(Globals
.hInstance
, STRING_UNTITLED
, szCaption
, SIZEOF(szCaption
));
134 StringCchCat(szCaption
, SIZEOF(szCaption
), _T(" - "));
135 StringCchCat(szCaption
, SIZEOF(szCaption
), szNotepad
);
136 SetWindowText(Globals
.hMainWnd
, szCaption
);
139 static void AlertFileNotFound(LPCTSTR szFileName
)
141 TCHAR szMessage
[MAX_STRING_LEN
];
142 TCHAR szResource
[MAX_STRING_LEN
];
144 /* Load and format szMessage */
145 LoadString(Globals
.hInstance
, STRING_NOTFOUND
, szResource
, SIZEOF(szResource
));
146 wsprintf(szMessage
, szResource
, szFileName
);
149 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szResource
, SIZEOF(szResource
));
151 /* Display Modal Dialog */
152 MessageBox(Globals
.hMainWnd
, szMessage
, szResource
, MB_ICONEXCLAMATION
);
155 static int AlertFileNotSaved(LPCTSTR szFileName
)
157 TCHAR szMessage
[MAX_STRING_LEN
];
158 TCHAR szResource
[MAX_STRING_LEN
];
159 TCHAR szUntitled
[MAX_STRING_LEN
];
161 LoadString(Globals
.hInstance
, STRING_UNTITLED
, szUntitled
, SIZEOF(szUntitled
));
163 /* Load and format Message */
164 LoadString(Globals
.hInstance
, STRING_NOTSAVED
, szResource
, SIZEOF(szResource
));
165 wsprintf(szMessage
, szResource
, szFileName
[0] ? szFileName
: szUntitled
);
168 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szResource
, SIZEOF(szResource
));
171 return MessageBox(Globals
.hMainWnd
, szMessage
, szResource
, MB_ICONEXCLAMATION
|MB_YESNOCANCEL
);
176 * TRUE - if file exists
177 * FALSE - if file does not exist
179 BOOL
FileExists(LPCTSTR szFilename
)
181 WIN32_FIND_DATA entry
;
184 hFile
= FindFirstFile(szFilename
, &entry
);
187 return (hFile
!= INVALID_HANDLE_VALUE
);
190 BOOL
HasFileExtension(LPCTSTR szFilename
)
194 s
= _tcsrchr(szFilename
, _T('\\'));
197 return _tcsrchr(szFilename
, _T('.')) != NULL
;
200 static BOOL
DoSaveFile(VOID
)
207 hFile
= CreateFile(Globals
.szFileName
, GENERIC_WRITE
, FILE_SHARE_WRITE
,
208 NULL
, CREATE_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
209 if(hFile
== INVALID_HANDLE_VALUE
)
215 size
= GetWindowTextLength(Globals
.hEdit
) + 1;
216 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(*pTemp
));
223 size
= GetWindowText(Globals
.hEdit
, pTemp
, size
);
226 pTemp
= (LPTSTR
)ConvertToUNICODE(pTemp
, &size
);
229 /* original "pTemp" already freed */
238 if (!WriteText(hFile
, (LPWSTR
)pTemp
, size
, Globals
.iEncoding
, Globals
.iEoln
))
245 SendMessage(Globals
.hEdit
, EM_SETMODIFY
, FALSE
, 0);
251 HeapFree(GetProcessHeap(), 0, pTemp
);
257 * TRUE - User agreed to close (both save/don't save)
258 * FALSE - User cancelled close by selecting "Cancel"
260 BOOL
DoCloseFile(VOID
)
264 if (SendMessage(Globals
.hEdit
, EM_GETMODIFY
, 0, 0))
266 /* prompt user to save changes */
267 nResult
= AlertFileNotSaved(Globals
.szFileName
);
271 if(!DIALOG_FileSave())
286 SetFileName(empty_str
);
287 UpdateWindowCaption();
292 VOID
DoOpenFile(LPCTSTR szFileName
)
294 static const TCHAR dotlog
[] = _T(".LOG");
296 LPTSTR pszText
= NULL
;
300 /* Close any files and prompt to save changes */
304 hFile
= CreateFile(szFileName
, GENERIC_READ
, FILE_SHARE_READ
| FILE_SHARE_WRITE
, NULL
,
305 OPEN_ALWAYS
, FILE_ATTRIBUTE_NORMAL
, NULL
);
306 if (hFile
== INVALID_HANDLE_VALUE
)
312 if (!ReadText(hFile
, (LPWSTR
*)&pszText
, &dwTextLen
, &Globals
.iEncoding
, &Globals
.iEoln
))
318 pszText
= ConvertToASCII(pszText
);
319 if (pszText
== NULL
) {
324 SetWindowText(Globals
.hEdit
, pszText
);
326 SendMessage(Globals
.hEdit
, EM_SETMODIFY
, FALSE
, 0);
327 SendMessage(Globals
.hEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
328 SetFocus(Globals
.hEdit
);
330 /* If the file starts with .LOG, add a time/date at the end and set cursor after
331 * See http://support.microsoft.com/?kbid=260563
333 if (GetWindowText(Globals
.hEdit
, log
, SIZEOF(log
)) && !_tcscmp(log
, dotlog
))
335 static const TCHAR lf
[] = _T("\r\n");
336 SendMessage(Globals
.hEdit
, EM_SETSEL
, GetWindowTextLength(Globals
.hEdit
), -1);
337 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)lf
);
338 DIALOG_EditTimeDate();
339 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)lf
);
342 SetFileName(szFileName
);
343 UpdateWindowCaption();
344 NOTEPAD_EnableSearchMenu();
346 if (hFile
!= INVALID_HANDLE_VALUE
)
349 HeapFree(GetProcessHeap(), 0, pszText
);
352 VOID
DIALOG_FileNew(VOID
)
354 /* Close any files and prompt to save changes */
356 SetWindowText(Globals
.hEdit
, empty_str
);
357 SendMessage(Globals
.hEdit
, EM_EMPTYUNDOBUFFER
, 0, 0);
358 SetFocus(Globals
.hEdit
);
359 NOTEPAD_EnableSearchMenu();
363 VOID
DIALOG_FileOpen(VOID
)
365 OPENFILENAME openfilename
;
366 TCHAR szDir
[MAX_PATH
];
367 TCHAR szPath
[MAX_PATH
];
369 ZeroMemory(&openfilename
, sizeof(openfilename
));
371 GetCurrentDirectory(SIZEOF(szDir
), szDir
);
372 if (Globals
.szFileName
[0] == 0)
373 _tcscpy(szPath
, txt_files
);
375 _tcscpy(szPath
, Globals
.szFileName
);
377 openfilename
.lStructSize
= sizeof(openfilename
);
378 openfilename
.hwndOwner
= Globals
.hMainWnd
;
379 openfilename
.hInstance
= Globals
.hInstance
;
380 openfilename
.lpstrFilter
= Globals
.szFilter
;
381 openfilename
.lpstrFile
= szPath
;
382 openfilename
.nMaxFile
= SIZEOF(szPath
);
383 openfilename
.lpstrInitialDir
= szDir
;
384 openfilename
.Flags
= OFN_FILEMUSTEXIST
| OFN_PATHMUSTEXIST
|
386 openfilename
.lpstrDefExt
= szDefaultExt
;
389 if (GetOpenFileName(&openfilename
)) {
390 if (FileExists(openfilename
.lpstrFile
))
391 DoOpenFile(openfilename
.lpstrFile
);
393 AlertFileNotFound(openfilename
.lpstrFile
);
398 BOOL
DIALOG_FileSave(VOID
)
400 if (Globals
.szFileName
[0] == 0)
401 return DIALOG_FileSaveAs();
406 static UINT_PTR CALLBACK
DIALOG_FileSaveAs_Hook(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
411 UNREFERENCED_PARAMETER(wParam
);
416 hCombo
= GetDlgItem(hDlg
, ID_ENCODING
);
418 LoadString(Globals
.hInstance
, STRING_ANSI
, szText
, SIZEOF(szText
));
419 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
421 LoadString(Globals
.hInstance
, STRING_UNICODE
, szText
, SIZEOF(szText
));
422 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
424 LoadString(Globals
.hInstance
, STRING_UNICODE_BE
, szText
, SIZEOF(szText
));
425 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
427 LoadString(Globals
.hInstance
, STRING_UTF8
, szText
, SIZEOF(szText
));
428 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
430 SendMessage(hCombo
, CB_SETCURSEL
, Globals
.iEncoding
, 0);
432 hCombo
= GetDlgItem(hDlg
, ID_EOLN
);
434 LoadString(Globals
.hInstance
, STRING_CRLF
, szText
, SIZEOF(szText
));
435 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
437 LoadString(Globals
.hInstance
, STRING_LF
, szText
, SIZEOF(szText
));
438 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
440 LoadString(Globals
.hInstance
, STRING_CR
, szText
, SIZEOF(szText
));
441 SendMessage(hCombo
, CB_ADDSTRING
, 0, (LPARAM
) szText
);
443 SendMessage(hCombo
, CB_SETCURSEL
, Globals
.iEoln
, 0);
447 if (((NMHDR
*) lParam
)->code
== CDN_FILEOK
)
449 hCombo
= GetDlgItem(hDlg
, ID_ENCODING
);
451 Globals
.iEncoding
= (int) SendMessage(hCombo
, CB_GETCURSEL
, 0, 0);
453 hCombo
= GetDlgItem(hDlg
, ID_EOLN
);
455 Globals
.iEoln
= (int) SendMessage(hCombo
, CB_GETCURSEL
, 0, 0);
462 BOOL
DIALOG_FileSaveAs(VOID
)
465 TCHAR szDir
[MAX_PATH
];
466 TCHAR szPath
[MAX_PATH
];
468 ZeroMemory(&saveas
, sizeof(saveas
));
470 GetCurrentDirectory(SIZEOF(szDir
), szDir
);
471 if (Globals
.szFileName
[0] == 0)
472 _tcscpy(szPath
, txt_files
);
474 _tcscpy(szPath
, Globals
.szFileName
);
476 saveas
.lStructSize
= sizeof(OPENFILENAME
);
477 saveas
.hwndOwner
= Globals
.hMainWnd
;
478 saveas
.hInstance
= Globals
.hInstance
;
479 saveas
.lpstrFilter
= Globals
.szFilter
;
480 saveas
.lpstrFile
= szPath
;
481 saveas
.nMaxFile
= SIZEOF(szPath
);
482 saveas
.lpstrInitialDir
= szDir
;
483 saveas
.Flags
= OFN_PATHMUSTEXIST
| OFN_OVERWRITEPROMPT
|
484 OFN_HIDEREADONLY
| OFN_EXPLORER
| OFN_ENABLETEMPLATE
| OFN_ENABLEHOOK
;
485 saveas
.lpstrDefExt
= szDefaultExt
;
486 saveas
.lpTemplateName
= MAKEINTRESOURCE(DIALOG_ENCODING
);
487 saveas
.lpfnHook
= DIALOG_FileSaveAs_Hook
;
489 if (GetSaveFileName(&saveas
))
491 // HACK: Because in ROS, Save-As boxes don't check the validity
492 // of file names and thus, here, szPath can be invalid !! We only
493 // see its validity when we call DoSaveFile()...
497 UpdateWindowCaption();
512 VOID
DIALOG_FilePrint(VOID
)
517 int cWidthPels
, cHeightPels
, border
;
518 int xLeft
, yTop
, pagecount
, dopage
, copycount
;
521 HFONT font
, old_font
=0;
524 static const TCHAR times_new_roman
[] = _T("Times New Roman");
526 /* Get a small font and print some header info on each page */
527 ZeroMemory(&hdrFont
, sizeof(hdrFont
));
528 hdrFont
.lfHeight
= 100;
529 hdrFont
.lfWeight
= FW_BOLD
;
530 hdrFont
.lfCharSet
= ANSI_CHARSET
;
531 hdrFont
.lfOutPrecision
= OUT_DEFAULT_PRECIS
;
532 hdrFont
.lfClipPrecision
= CLIP_DEFAULT_PRECIS
;
533 hdrFont
.lfQuality
= PROOF_QUALITY
;
534 hdrFont
.lfPitchAndFamily
= VARIABLE_PITCH
| FF_ROMAN
;
535 _tcscpy(hdrFont
.lfFaceName
, times_new_roman
);
537 font
= CreateFontIndirect(&hdrFont
);
539 /* Get Current Settings */
540 ZeroMemory(&printer
, sizeof(printer
));
541 printer
.lStructSize
= sizeof(printer
);
542 printer
.hwndOwner
= Globals
.hMainWnd
;
543 printer
.hInstance
= Globals
.hInstance
;
545 /* Set some default flags */
546 printer
.Flags
= PD_RETURNDC
;
547 printer
.nFromPage
= 0;
548 printer
.nMinPage
= 1;
549 /* we really need to calculate number of pages to set nMaxPage and nToPage */
551 printer
.nMaxPage
= (WORD
) -1;
553 /* Let commdlg manage copy settings */
554 printer
.nCopies
= (WORD
)PD_USEDEVMODECOPIES
;
556 if (!PrintDlg(&printer
)) return;
558 assert(printer
.hDC
!= 0);
560 /* initialize DOCINFO */
561 di
.cbSize
= sizeof(DOCINFO
);
562 di
.lpszDocName
= Globals
.szFileTitle
;
563 di
.lpszOutput
= NULL
;
564 di
.lpszDatatype
= NULL
;
567 if (StartDoc(printer
.hDC
, &di
) <= 0) return;
569 /* Get the page dimensions in pixels. */
570 cWidthPels
= GetDeviceCaps(printer
.hDC
, HORZRES
);
571 cHeightPels
= GetDeviceCaps(printer
.hDC
, VERTRES
);
573 /* Get the file text */
574 size
= GetWindowTextLength(Globals
.hEdit
) + 1;
575 pTemp
= HeapAlloc(GetProcessHeap(), 0, size
* sizeof(TCHAR
));
581 size
= GetWindowText(Globals
.hEdit
, pTemp
, size
);
584 for (copycount
=1; copycount
<= printer
.nCopies
; copycount
++) {
588 static const TCHAR letterM
[] = _T("M");
590 if (pagecount
>= printer
.nFromPage
&&
591 /* ((printer.Flags & PD_PAGENUMS) == 0 || pagecount <= printer.nToPage))*/
592 pagecount
<= printer
.nToPage
)
597 old_font
= SelectObject(printer
.hDC
, font
);
598 GetTextExtentPoint32(printer
.hDC
, letterM
, 1, &szMetric
);
601 if (StartPage(printer
.hDC
) <= 0) {
602 static const TCHAR failed
[] = _T("StartPage failed");
603 static const TCHAR error
[] = _T("Print Error");
604 MessageBox(Globals
.hMainWnd
, failed
, error
, MB_ICONEXCLAMATION
);
607 /* Write a rectangle and header at the top of each page */
608 Rectangle(printer
.hDC
, border
, border
, cWidthPels
-border
, border
+szMetric
.cy
*2);
609 /* I don't know what's up with this TextOut command. This comes out
612 TextOut(printer
.hDC
, border
*2, border
+szMetric
.cy
/2, Globals
.szFileTitle
, lstrlen(Globals
.szFileTitle
));
615 /* The starting point for the main text */
617 yTop
= border
+szMetric
.cy
*4;
619 SelectObject(printer
.hDC
, old_font
);
620 GetTextExtentPoint32(printer
.hDC
, letterM
, 1, &szMetric
);
622 /* Since outputting strings is giving me problems, output the main
623 text one character at a time.
626 if (pTemp
[i
] == '\n') {
630 else if (pTemp
[i
] != '\r') {
632 TextOut(printer
.hDC
, xLeft
, yTop
, &pTemp
[i
], 1);
633 xLeft
+= szMetric
.cx
;
635 } while (i
++<size
&& yTop
<(cHeightPels
-border
*2));
638 EndPage(printer
.hDC
);
644 DeleteDC(printer
.hDC
);
645 HeapFree(GetProcessHeap(), 0, pTemp
);
648 VOID
DIALOG_FilePrinterSetup(VOID
)
652 ZeroMemory(&printer
, sizeof(printer
));
653 printer
.lStructSize
= sizeof(printer
);
654 printer
.hwndOwner
= Globals
.hMainWnd
;
655 printer
.hInstance
= Globals
.hInstance
;
656 printer
.Flags
= PD_PRINTSETUP
;
662 VOID
DIALOG_FileExit(VOID
)
664 PostMessage(Globals
.hMainWnd
, WM_CLOSE
, 0, 0l);
667 VOID
DIALOG_EditUndo(VOID
)
669 SendMessage(Globals
.hEdit
, EM_UNDO
, 0, 0);
672 VOID
DIALOG_EditCut(VOID
)
674 SendMessage(Globals
.hEdit
, WM_CUT
, 0, 0);
677 VOID
DIALOG_EditCopy(VOID
)
679 SendMessage(Globals
.hEdit
, WM_COPY
, 0, 0);
682 VOID
DIALOG_EditPaste(VOID
)
684 SendMessage(Globals
.hEdit
, WM_PASTE
, 0, 0);
687 VOID
DIALOG_EditDelete(VOID
)
689 SendMessage(Globals
.hEdit
, WM_CLEAR
, 0, 0);
692 VOID
DIALOG_EditSelectAll(VOID
)
694 SendMessage(Globals
.hEdit
, EM_SETSEL
, 0, (LPARAM
)-1);
697 VOID
DIALOG_EditTimeDate(VOID
)
700 TCHAR szDate
[MAX_STRING_LEN
];
701 TCHAR szText
[MAX_STRING_LEN
* 2 + 2];
705 GetTimeFormat(LOCALE_USER_DEFAULT
, 0, &st
, NULL
, szDate
, MAX_STRING_LEN
);
706 _tcscpy(szText
, szDate
);
707 _tcscat(szText
, _T(" "));
708 GetDateFormat(LOCALE_USER_DEFAULT
, DATE_LONGDATE
, &st
, NULL
, szDate
, MAX_STRING_LEN
);
709 _tcscat(szText
, szDate
);
710 SendMessage(Globals
.hEdit
, EM_REPLACESEL
, TRUE
, (LPARAM
)szText
);
713 VOID
DoCreateStatusBar(VOID
)
717 BOOL bStatusBarVisible
;
719 // Check if status bar object already exists.
720 if (Globals
.hStatusBar
== NULL
)
722 // Try to create the status bar
723 Globals
.hStatusBar
= CreateStatusWindow(
724 WS_CHILD
| WS_VISIBLE
| WS_EX_STATICEDGE
,
727 CMD_STATUSBAR_WND_ID
);
729 if (Globals
.hStatusBar
== NULL
)
735 // Load the string for formatting column/row text output
736 LoadString(Globals
.hInstance
, STRING_LINE_COLUMN
, Globals
.szStatusBarLineCol
, MAX_PATH
-1);
738 // Set the status bar for single-text output
739 SendMessage(Globals
.hStatusBar
, SB_SIMPLE
, (WPARAM
)TRUE
, (LPARAM
)0);
742 // Set status bar visible or not accordind the the settings.
743 if (Globals
.bWrapLongLines
== TRUE
||
744 Globals
.bShowStatusBar
== FALSE
)
746 bStatusBarVisible
= FALSE
;
747 ShowWindow(Globals
.hStatusBar
, SW_HIDE
);
751 bStatusBarVisible
= TRUE
;
752 ShowWindow(Globals
.hStatusBar
, SW_SHOW
);
753 SendMessage(Globals
.hStatusBar
, WM_SIZE
, 0, 0);
756 // Set check state in show status bar item.
757 if (Globals
.bShowStatusBar
== TRUE
)
759 CheckMenuItem(Globals
.hMenu
, CMD_STATUSBAR
, MF_BYCOMMAND
| MF_CHECKED
);
763 CheckMenuItem(Globals
.hMenu
, CMD_STATUSBAR
, MF_BYCOMMAND
| MF_UNCHECKED
);
766 // Update menu mar with the previous changes
767 DrawMenuBar(Globals
.hMainWnd
);
769 // Sefety test is edit control exists
770 if (Globals
.hEdit
!= NULL
)
772 // Retrieve the sizes of the controls
773 GetClientRect(Globals
.hMainWnd
, &rc
);
774 GetClientRect(Globals
.hStatusBar
, &rcstatus
);
776 // If status bar is currently visible, update dimensions of edir control
777 if (bStatusBarVisible
)
778 rc
.bottom
-= (rcstatus
.bottom
- rcstatus
.top
);
780 // Resize edit control to right size.
781 MoveWindow(Globals
.hEdit
, rc
.left
, rc
.top
, rc
.right
- rc
.left
, rc
.bottom
- rc
.top
, TRUE
);
784 // Update content with current row/column text
785 DIALOG_StatusBarUpdateCaretPos();
788 VOID
DoCreateEditWindow(VOID
)
796 // If the edit control already exists, try to save its content
797 if (Globals
.hEdit
!= NULL
)
799 // number of chars currently written into the editor.
800 iSize
= GetWindowTextLength(Globals
.hEdit
);
804 // Allocates temporary buffer.
805 pTemp
= HeapAlloc(GetProcessHeap(), 0, (iSize
+ 1) * sizeof(TCHAR
));
813 // Recover the text into the control.
814 GetWindowText(Globals
.hEdit
, pTemp
, iSize
+ 1);
817 // Restore original window procedure
818 SetWindowLongPtr(Globals
.hEdit
, GWLP_WNDPROC
, (LONG_PTR
)Globals
.EditProc
);
820 // Destroy the edit control
821 DestroyWindow(Globals
.hEdit
);
824 // Update wrap status into the main menu and recover style flags
825 if (Globals
.bWrapLongLines
)
827 dwStyle
= EDIT_STYLE_WRAP
;
828 EnableMenuItem(Globals
.hMenu
, CMD_STATUSBAR
, MF_BYCOMMAND
| MF_DISABLED
| MF_GRAYED
);
830 dwStyle
= EDIT_STYLE
;
831 EnableMenuItem(Globals
.hMenu
, CMD_STATUSBAR
, MF_BYCOMMAND
| MF_ENABLED
);
834 // Update previous changes
835 DrawMenuBar(Globals
.hMainWnd
);
837 // Create the new edit control
838 Globals
.hEdit
= CreateWindowEx(
852 if (Globals
.hEdit
== NULL
)
858 SendMessage(Globals
.hEdit
, WM_SETFONT
, (WPARAM
)Globals
.hFont
, FALSE
);
859 SendMessage(Globals
.hEdit
, EM_LIMITTEXT
, 0, 0);
861 // If some text was previously saved, restore it.
864 SetWindowText(Globals
.hEdit
, pTemp
);
865 HeapFree(GetProcessHeap(), 0, pTemp
);
868 // Sub-class a new window callback for row/column detection.
869 Globals
.EditProc
= (WNDPROC
) SetWindowLongPtr(Globals
.hEdit
, GWLP_WNDPROC
, (LONG_PTR
)EDIT_WndProc
);
871 // Create/update status bar
874 // Finally shows new edit control and set focus into it.
875 ShowWindow(Globals
.hEdit
, SW_SHOW
);
876 SetFocus(Globals
.hEdit
);
879 VOID
DIALOG_EditWrap(VOID
)
881 Globals
.bWrapLongLines
= !Globals
.bWrapLongLines
;
883 DoCreateEditWindow();
886 VOID
DIALOG_SelectFont(VOID
)
889 LOGFONT lf
=Globals
.lfFont
;
891 ZeroMemory( &cf
, sizeof(cf
) );
892 cf
.lStructSize
=sizeof(cf
);
893 cf
.hwndOwner
=Globals
.hMainWnd
;
895 cf
.Flags
=CF_SCREENFONTS
| CF_INITTOLOGFONTSTRUCT
;
897 if( ChooseFont(&cf
) )
899 HFONT currfont
=Globals
.hFont
;
901 Globals
.hFont
=CreateFontIndirect( &lf
);
903 SendMessage( Globals
.hEdit
, WM_SETFONT
, (WPARAM
)Globals
.hFont
, (LPARAM
)TRUE
);
905 DeleteObject( currfont
);
909 typedef HWND (WINAPI
*FINDPROC
)(LPFINDREPLACE lpfr
);
911 static VOID
DIALOG_SearchDialog(FINDPROC pfnProc
)
913 ZeroMemory(&Globals
.find
, sizeof(Globals
.find
));
914 Globals
.find
.lStructSize
= sizeof(Globals
.find
);
915 Globals
.find
.hwndOwner
= Globals
.hMainWnd
;
916 Globals
.find
.hInstance
= Globals
.hInstance
;
917 Globals
.find
.lpstrFindWhat
= Globals
.szFindText
;
918 Globals
.find
.wFindWhatLen
= SIZEOF(Globals
.szFindText
);
919 Globals
.find
.lpstrReplaceWith
= Globals
.szReplaceText
;
920 Globals
.find
.wReplaceWithLen
= SIZEOF(Globals
.szReplaceText
);
921 Globals
.find
.Flags
= FR_DOWN
;
923 /* We only need to create the modal FindReplace dialog which will */
924 /* notify us of incoming events using hMainWnd Window Messages */
926 Globals
.hFindReplaceDlg
= pfnProc(&Globals
.find
);
927 assert(Globals
.hFindReplaceDlg
!=0);
930 VOID
DIALOG_Search(VOID
)
932 DIALOG_SearchDialog(FindText
);
935 VOID
DIALOG_SearchNext(VOID
)
937 if (Globals
.find
.lpstrFindWhat
!= NULL
)
938 NOTEPAD_FindNext(&Globals
.find
, FALSE
, TRUE
);
943 VOID
DIALOG_Replace(VOID
)
945 DIALOG_SearchDialog(ReplaceText
);
948 static INT_PTR CALLBACK
DIALOG_GoTo_DialogProc(HWND hwndDialog
, UINT uMsg
, WPARAM wParam
, LPARAM lParam
)
950 BOOL bResult
= FALSE
;
956 hTextBox
= GetDlgItem(hwndDialog
, ID_LINENUMBER
);
957 _sntprintf(szText
, SIZEOF(szText
), _T("%d"), lParam
);
958 SetWindowText(hTextBox
, szText
);
961 if (HIWORD(wParam
) == BN_CLICKED
)
963 if (LOWORD(wParam
) == IDOK
)
965 hTextBox
= GetDlgItem(hwndDialog
, ID_LINENUMBER
);
966 GetWindowText(hTextBox
, szText
, SIZEOF(szText
));
967 EndDialog(hwndDialog
, _ttoi(szText
));
970 else if (LOWORD(wParam
) == IDCANCEL
)
972 EndDialog(hwndDialog
, 0);
982 VOID
DIALOG_GoTo(VOID
)
987 DWORD dwStart
, dwEnd
;
989 nLength
= GetWindowTextLength(Globals
.hEdit
);
990 pszText
= (LPTSTR
) HeapAlloc(GetProcessHeap(), 0, (nLength
+ 1) * sizeof(*pszText
));
994 /* Retrieve current text */
995 GetWindowText(Globals
.hEdit
, pszText
, nLength
+ 1);
996 SendMessage(Globals
.hEdit
, EM_GETSEL
, (WPARAM
) &dwStart
, (LPARAM
) &dwEnd
);
999 for (i
= 0; pszText
[i
] && (i
< (int) dwStart
); i
++)
1001 if (pszText
[i
] == '\n')
1005 nLine
= DialogBoxParam(Globals
.hInstance
, MAKEINTRESOURCE(DIALOG_GOTO
),
1006 Globals
.hMainWnd
, DIALOG_GoTo_DialogProc
, nLine
);
1010 for (i
= 0; pszText
[i
] && (nLine
> 1) && (i
< nLength
- 1); i
++)
1012 if (pszText
[i
] == '\n')
1015 SendMessage(Globals
.hEdit
, EM_SETSEL
, i
, i
);
1016 SendMessage(Globals
.hEdit
, EM_SCROLLCARET
, 0, 0);
1018 HeapFree(GetProcessHeap(), 0, pszText
);
1021 VOID
DIALOG_StatusBarUpdateCaretPos(VOID
)
1024 TCHAR buff
[MAX_PATH
];
1025 DWORD dwStart
, dwSize
;
1027 SendMessage(Globals
.hEdit
, EM_GETSEL
, (WPARAM
)&dwStart
, (LPARAM
)&dwSize
);
1028 line
= SendMessage(Globals
.hEdit
, EM_LINEFROMCHAR
, (WPARAM
)dwStart
, 0);
1029 col
= dwStart
- SendMessage(Globals
.hEdit
, EM_LINEINDEX
, (WPARAM
)line
, 0);
1031 _stprintf(buff
, Globals
.szStatusBarLineCol
, line
+1, col
+1);
1032 SendMessage(Globals
.hStatusBar
, SB_SETTEXT
, SB_SIMPLEID
, (LPARAM
)buff
);
1035 VOID
DIALOG_ViewStatusBar(VOID
)
1037 Globals
.bShowStatusBar
= !Globals
.bShowStatusBar
;
1039 DoCreateStatusBar();
1042 VOID
DIALOG_HelpContents(VOID
)
1044 WinHelp(Globals
.hMainWnd
, helpfile
, HELP_INDEX
, 0);
1047 VOID
DIALOG_HelpSearch(VOID
)
1052 VOID
DIALOG_HelpHelp(VOID
)
1054 WinHelp(Globals
.hMainWnd
, helpfile
, HELP_HELPONHELP
, 0);
1058 #pragma warning(disable : 4100)
1061 AboutDialogProc(HWND hDlg
, UINT message
, WPARAM wParam
, LPARAM lParam
)
1063 HWND hLicenseEditWnd
;
1070 hLicenseEditWnd
= GetDlgItem(hDlg
, IDC_LICENSE
);
1072 /* 0x1000 should be enought */
1073 strLicense
= (TCHAR
*)_alloca(0x1000);
1074 LoadString(GetModuleHandle(NULL
), STRING_LICENSE
, strLicense
, 0x1000);
1076 SetWindowText(hLicenseEditWnd
, strLicense
);
1082 if ((LOWORD(wParam
) == IDOK
) || (LOWORD(wParam
) == IDCANCEL
))
1084 EndDialog(hDlg
, LOWORD(wParam
));
1096 VOID
DIALOG_HelpAboutWine(VOID
)
1098 TCHAR szNotepad
[MAX_STRING_LEN
];
1099 HICON notepadIcon
= LoadIcon(Globals
.hInstance
, MAKEINTRESOURCE(IDI_NPICON
));
1101 LoadString(Globals
.hInstance
, STRING_NOTEPAD
, szNotepad
, SIZEOF(szNotepad
));
1102 ShellAbout(Globals
.hMainWnd
, szNotepad
, 0, notepadIcon
);
1103 DeleteObject(notepadIcon
);
1107 /***********************************************************************
1109 * DIALOG_FilePageSetup
1111 VOID
DIALOG_FilePageSetup(void)
1113 DialogBox(Globals
.hInstance
, MAKEINTRESOURCE(DIALOG_PAGESETUP
),
1114 Globals
.hMainWnd
, DIALOG_PAGESETUP_DlgProc
);
1118 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
1120 * DIALOG_PAGESETUP_DlgProc
1123 static INT_PTR WINAPI
DIALOG_PAGESETUP_DlgProc(HWND hDlg
, UINT msg
, WPARAM wParam
, LPARAM lParam
)
1129 if (HIWORD(wParam
) == BN_CLICKED
)
1131 switch (LOWORD(wParam
))
1134 /* save user input and close dialog */
1135 GetDlgItemText(hDlg
, 0x141, Globals
.szHeader
, SIZEOF(Globals
.szHeader
));
1136 GetDlgItemText(hDlg
, 0x143, Globals
.szFooter
, SIZEOF(Globals
.szFooter
));
1137 GetDlgItemText(hDlg
, 0x14A, Globals
.szMarginTop
, SIZEOF(Globals
.szMarginTop
));
1138 GetDlgItemText(hDlg
, 0x150, Globals
.szMarginBottom
, SIZEOF(Globals
.szMarginBottom
));
1139 GetDlgItemText(hDlg
, 0x147, Globals
.szMarginLeft
, SIZEOF(Globals
.szMarginLeft
));
1140 GetDlgItemText(hDlg
, 0x14D, Globals
.szMarginRight
, SIZEOF(Globals
.szMarginRight
));
1141 EndDialog(hDlg
, IDOK
);
1145 /* discard user input and close dialog */
1146 EndDialog(hDlg
, IDCANCEL
);
1151 /* FIXME: Bring this to work */
1152 static const TCHAR sorry
[] = _T("Sorry, no help available");
1153 static const TCHAR help
[] = _T("Help");
1154 MessageBox(Globals
.hMainWnd
, sorry
, help
, MB_ICONEXCLAMATION
);
1165 /* fetch last user input prior to display dialog */
1166 SetDlgItemText(hDlg
, 0x141, Globals
.szHeader
);
1167 SetDlgItemText(hDlg
, 0x143, Globals
.szFooter
);
1168 SetDlgItemText(hDlg
, 0x14A, Globals
.szMarginTop
);
1169 SetDlgItemText(hDlg
, 0x150, Globals
.szMarginBottom
);
1170 SetDlgItemText(hDlg
, 0x147, Globals
.szMarginLeft
);
1171 SetDlgItemText(hDlg
, 0x14D, Globals
.szMarginRight
);